virtual bool onPhaseChange(ServerPlayer *zhangliang) const{ Room *room = zhangliang->getRoom(); if(zhangliang->getPhase() != Player::Draw) return false; QList<ServerPlayer *> players = room->getOtherPlayers(zhangliang); foreach(ServerPlayer *p, players){ if(p->isKongcheng()) players.removeOne(p); } if(players.isEmpty() || !zhangliang->askForSkillInvoke(objectName())) return false; room->playSkillEffect(objectName()); ServerPlayer *rengonger = room->askForPlayerChosen(zhangliang, players, objectName()); QList<int> handcards = rengonger->handCards(); room->fillAG(handcards, zhangliang); int card_id = room->askForAG(zhangliang, handcards, false, objectName()); room->moveCardTo(Sanguosha->getCard(card_id), zhangliang, Player::Hand, false); room->broadcastInvoke("clearAG"); return true; }
bool MiniSceneRule::trigger(TriggerEvent event, ServerPlayer *player, QVariant &data) const { Room* room = player->getRoom(); if(event == PhaseChange) { if(player->getPhase()==Player::Start && this->players.first()["beforeNext"] != NULL ) { if(player->tag["playerHasPlayed"].toBool()) room->gameOver(this->players.first()["beforeNext"]); else player->tag["playerHasPlayed"] = true; } if(player->getPhase() != Player::NotActive)return false; if(player->getState() == "robot" || this->players.first()["singleTurn"] == NULL) return false; room->gameOver(this->players.first()["singleTurn"]); } if(player->getRoom()->getTag("WaitForPlayer").toBool()) return true; QList<ServerPlayer*> players = room->getAllPlayers(); while(players.first()->getState() == "robot") players.append(players.takeFirst()); QStringList cards= setup.split(","); foreach(QString id,cards) { room->moveCardTo(Sanguosha->getCard(id.toInt()),NULL,Player::Special,true); room->moveCardTo(Sanguosha->getCard(id.toInt()),NULL,Player::DrawPile,true); room->broadcastInvoke("addHistory","pushPile"); }
void Crisp::onEffect(const CardEffectStruct &effect) const{ Room *room = effect.to->getRoom(); // do animation QString who = effect.to->objectName(); QString animation_str = QString("crisp:%1:%2").arg(who).arg(who); room->broadcastInvoke("animate", animation_str); LogMessage log; log.type = "#Crisp"; log.from = effect.to; room->sendLog(log); room->setPlayerFlag(effect.to, "crisp"); }
void Peach::onEffect(const CardEffectStruct &effect) const{ Room *room = effect.to->getRoom(); // do animation room->broadcastInvoke("animate", QString("peach:%1:%2") .arg(effect.from->objectName()) .arg(effect.to->objectName())); // recover hp RecoverStruct recover; recover.card = this; recover.who = effect.from; room->recover(effect.to, recover); }
virtual bool onPhaseChange(ServerPlayer *wangyi) const{ if(!wangyi->isWounded()) return false; if(wangyi->getPhase() == Player::Start || wangyi->getPhase() == Player::Finish){ if(!wangyi->askForSkillInvoke(objectName())) return false; Room *room = wangyi->getRoom(); JudgeStruct judge; judge.pattern = QRegExp("(.*):(club|spade):(.*)"); judge.good = true; judge.reason = objectName(); judge.who = wangyi; room->judge(judge); if(judge.isGood()){ int x = wangyi->getLostHp(); LogMessage log; log.type = "#WatchNCards"; log.from = wangyi; log.arg = QString::number(x); room->sendLog(log); room->playSkillEffect(objectName()); QList<int> miji_cards = room->getNCards(x, false); room->fillAG(miji_cards, wangyi); room->askForAG(wangyi, miji_cards, true, objectName()); room->broadcastInvoke("clearAG"); room->addToDrawPile(miji_cards); ServerPlayer *target = room->askForPlayerChosen(wangyi, room->getAllPlayers(), objectName()); log.type = "#Miji"; log.arg = objectName(); log.to << target; room->sendLog(log); target->drawCards(x, false); } } return false; }
void Analeptic::onEffect(const CardEffectStruct &effect) const{ Room *room = effect.to->getRoom(); if(effect.to->hasFlag("dying")){ // do animation QString who = effect.to->objectName(); QString animation_str = QString("analeptic:%1:%2").arg(who).arg(who); room->broadcastInvoke("animate", animation_str); // recover hp RecoverStruct recover; recover.card = this; recover.who = effect.from; room->recover(effect.to, recover); }else{ LogMessage log; log.type = "#Drank"; log.from = effect.from; room->sendLog(log); room->setPlayerFlag(effect.to, "drank"); } }
void Peach::onEffect(const CardEffectStruct &effect) const{ Room *room = effect.to->getRoom(); QString who = effect.to->objectName(); room->broadcastInvoke("animate", QString("peach:%1:%2").arg(who).arg(who)); room->recover(effect.to); }
void GameRule::onPhaseChange(ServerPlayer *player) const{ Room *room = player->getRoom(); switch(player->getPhase()){ case Player::Start: { player->setMark("SlashCount", 0); break; } case Player::Judge: { QStack<const DelayedTrick *> tricks = player->delayedTricks(); while(!tricks.isEmpty() && player->isAlive()){ const DelayedTrick *trick = tricks.pop(); bool on_effect = room->cardEffect(trick, NULL, player); if(!on_effect) trick->onNullified(player); } break; } case Player::Draw: { QVariant num = 2; room->getThread()->trigger(DrawNCards, player, num); int n = num.toInt(); if(n > 0) player->drawCards(n, false); break; } case Player::Play: { while(player->isAlive()){ CardUseStruct card_use; room->activate(player, card_use); if(card_use.isValid()) room->useCard(card_use); else break; } break; } case Player::Discard:{ int discard_num = player->getHandcardNum() - player->getMaxCards(); if(player->hasFlag("jilei")){ QList<const Card *> jilei_cards; QList<const Card *> handcards = player->getHandcards(); foreach(const Card *card, handcards){ if(card->inherits("BasicCard")){ if(player->hasFlag("jileiB")) jilei_cards << card; }else if(card->inherits("EquipCard")){ if(player->hasFlag("jileiE")) jilei_cards << card; }else if(card->inherits("TrickCard")){ if(player->hasFlag("jileiT")) jilei_cards << card; } } if(jilei_cards.length() > player->getMaxCards()){ // show all his cards QStringList handcards_str; foreach(const Card *card, handcards) handcards_str << QString::number(card->getId()); QString gongxin_str = QString("%1!:%2").arg(player->objectName()).arg(handcards_str.join("+")); room->broadcastInvoke("doGongxin", gongxin_str, player); QList<const Card *> other_cards = handcards.toSet().subtract(jilei_cards.toSet()).toList(); foreach(const Card *card, other_cards){ room->throwCard(card); } return; } }