void HulaoguanScenario::assign(QStringList &generals, QStringList &roles) const{ Q_UNUSED(generals); roles << "lord"; int i; for(i=0; i<3; i++) roles << "rebel"; qShuffle(roles); }
void Scenario::assign(QStringList &generals, QStringList &roles) const{ generals << lord << loyalists << rebels << renegades; qShuffle(generals); foreach(QString general, generals){ if(general == lord) roles << "lord"; else if(loyalists.contains(general)) roles << "loyalist"; else if(rebels.contains(general)) roles << "rebel"; else roles << "renegade"; } }
QList<int> ServerPlayer::forceToDiscard(int discard_num, bool include_equip){ QList<int> to_discard; QString flags = "h"; if(include_equip) flags.append("e"); QList<const Card *> all_cards = getCards(flags); qShuffle(all_cards); int i; for(i=0; i<discard_num; i++) to_discard << all_cards.at(i)->getId(); return to_discard; }
void GeneralSelector::calculatePairValues(const ServerPlayer *player, const QStringList &_candidates) { // preference QStringList kingdoms = Sanguosha->getKingdoms(); kingdoms.removeAll("god"); qShuffle(kingdoms); if (qrand() % 2 == 0) { const int index = kingdoms.indexOf("qun"); if (index != -1 && index != kingdoms.size() - 1) qSwap(kingdoms[index], kingdoms[index + 1]); } QStringList candidates = _candidates; if (!player->getGeneralName().isEmpty()) { foreach (const QString &candidate, _candidates) { if (BanPair::isBanned(player->getGeneralName(), candidate)) candidates.removeOne(candidate); } }
virtual bool onPhaseChange(ServerPlayer *target) const{ Room *room = target->getRoom(); if (target->getPhase() == Player::Finish && target->isWounded() && target->askForSkillInvoke(objectName())) { room->broadcastSkillInvoke(objectName(), 1); QStringList draw_num; for (int i = 1; i <= target->getLostHp(); draw_num << QString::number(i++)) {} int num = room->askForChoice(target, "miji_draw", draw_num.join("+")).toInt(); target->drawCards(num, objectName()); if (!target->isKongcheng()) { int n = 0; forever { int original_handcardnum = target->getHandcardNum(); if (n < num && !target->isKongcheng()) { QList<int> handcards = target->handCards(); if (!room->askForYiji(target, handcards, objectName(), false, false, false, num - n)) break; n += original_handcardnum - target->getHandcardNum(); } else { break; } } // give the rest cards randomly if (n < num && !target->isKongcheng()) { int rest_num = num - n; forever { QList<int> handcard_list = target->handCards(); qShuffle(handcard_list); int give = qrand() % rest_num + 1; rest_num -= give; QList<int> to_give = handcard_list.length() < give ? handcard_list : handcard_list.mid(0, give); ServerPlayer *receiver = room->getOtherPlayers(target).at(qrand() % (target->aliveCount() - 1)); DummyCard *dummy = new DummyCard; foreach (int id, to_give) dummy->addSubcard(id); room->obtainCard(receiver, dummy, false); delete dummy; if (rest_num == 0 || target->isKongcheng()) break; } }
virtual bool trigger(TriggerEvent triggerEvent, Room *room, ServerPlayer *target, QVariant &data) const { if (TriggerSkill::triggerable(target) && triggerEvent == EventPhaseStart && target->getPhase() == Player::Finish && target->isWounded() && target->askForSkillInvoke(this)) { room->broadcastSkillInvoke(objectName(), 1); QStringList draw_num; for (int i = 1; i <= target->getLostHp(); draw_num << QString::number(i++)) { } int num = room->askForChoice(target, "miji_draw", draw_num.join("+")).toInt(); target->drawCards(num, objectName()); target->setMark(objectName(), 0); if (!target->isKongcheng()) { forever{ int n = target->getMark(objectName()); if (n < num && !target->isKongcheng()) { QList<int> handcards = target->handCards(); if (!room->askForYiji(target, handcards, objectName(), false, false, false, num - n)) break; } else { break; } } // give the rest cards randomly if (target->getMark(objectName()) < num && !target->isKongcheng()) { int rest_num = num - target->getMark(objectName()); forever{ QList<int> handcard_list = target->handCards(); qShuffle(handcard_list); int give = qrand() % rest_num + 1; rest_num -= give; QList<int> to_give = handcard_list.length() < give ? handcard_list : handcard_list.mid(0, give); ServerPlayer *receiver = room->getOtherPlayers(target).at(qrand() % (target->aliveCount() - 1)); DummyCard *dummy = new DummyCard(to_give); room->obtainCard(receiver, dummy, false); delete dummy; if (rest_num == 0 || target->isKongcheng()) break; } }
foreach(ServerPlayer * sp,players) { room->setPlayerProperty(sp,"role",this->players.at(i)["role"]); QString general = this->players.at(i)["general"]; { QString original = sp->getGeneralName(); if(general == "select") { QStringList available,all,existed; existed = existedGenerals(); all = Sanguosha->getRandomGenerals(Sanguosha->getGeneralCount()); qShuffle(all); for(int i=0;i<5;i++) { sp->setGeneral(NULL); QString choice = sp->findReasonable(all); if(existed.contains(choice)) { all.removeOne(choice); i--; continue; } available << choice; all.removeOne(choice); } general = room->askForGeneral(sp,available); } QString trans = QString("%1:%2").arg(original).arg(general); sp->invoke("transfigure",trans); room->setPlayerProperty(sp,"general",general); } general = this->players.at(i)["general2"]; if(!general.isEmpty()){ if(general == "select") { QStringList available,all,existed; existed = existedGenerals(); all = Sanguosha->getRandomGenerals(Sanguosha->getGeneralCount()); qShuffle(all); for(int i=0;i<5;i++) { room->setPlayerProperty(sp,"general2", QVariant()); QString choice = sp->findReasonable(all); if(existed.contains(choice)) { all.removeOne(choice); i--; continue; } available << choice; all.removeOne(choice); } general = room->askForGeneral(sp,available); } if(general == sp->getGeneralName())general = this->players.at(i)["general3"]; QString trans = QString("%1:%2").arg("sujiang").arg(general); sp->invoke("transfigure",trans); room->setPlayerProperty(sp,"general2",general); } room->setPlayerProperty(sp,"kingdom",sp->getGeneral()->getKingdom()); QString str = this->players.at(i)["maxhp"]; if(str==NULL)str=QString::number(sp->getGeneralMaxHP()); room->setPlayerProperty(sp,"maxhp",str.toInt()); str = this->players.at(i)["hpadj"]; if(str!=NULL) room->setPlayerProperty(sp,"maxhp",sp->getMaxHP()+str.toInt()); str=QString::number(sp->getMaxHP()); QString str2 = this->players.at(i)["hp"]; if(str2 != NULL)str = str2; room->setPlayerProperty(sp,"hp",str.toInt()); str = this->players.at(i)["equip"]; QStringList equips = str.split(","); foreach(QString equip,equips) { bool ok; equip.toInt(&ok); if(!ok)room->installEquip(sp,equip); else room->moveCardTo(Sanguosha->getCard(equip.toInt()),sp,Player::Equip); }