void onDamaged(ServerPlayer *xiahou, const DamageStruct &damage) const
    {
        ServerPlayer *from = damage.from;
        Room *room = xiahou->getRoom();
        QVariant data = QVariant::fromValue(damage);

        if (room->askForSkillInvoke(xiahou, "neoganglie", data)) {
            room->broadcastSkillInvoke("ganglie");

            JudgeStruct judge;
            judge.pattern = ".|heart";
            judge.good = false;
            judge.reason = objectName();
            judge.who = xiahou;

            room->judge(judge);
            if (!from || from->isDead()) return;
            if (judge.isGood()) {
                QStringList choicelist;
                choicelist << "damage";
                if (from->getHandcardNum() > 1)
                    choicelist << "throw";
                QString choice = room->askForChoice(xiahou, objectName(), choicelist.join("+"));
                if (choice == "damage")
                    room->damage(DamageStruct(objectName(), xiahou, from));
                else
                    room->askForDiscard(from, objectName(), 2, 2);
            }
        }
    }
const Card *HuanhuoCard::validate(CardUseStruct &card_use) const
{
	ServerPlayer *yuji = card_use.from;
	Room *room = yuji->getRoom();

	QString to_guhuo = user_string;
	if (user_string == "slash"
		&& Sanguosha->currentRoomState()->getCurrentCardUseReason() == CardUseStruct::CARD_USE_REASON_RESPONSE_USE) {
		QStringList guhuo_list;
		guhuo_list << "slash";
		if (!Config.BanPackages.contains("maneuvering"))
			guhuo_list << "normal_slash" << "thunder_slash" << "fire_slash";
		to_guhuo = room->askForChoice(yuji, "guhuo_slash", guhuo_list.join("+"));
	}
	room->broadcastSkillInvoke("crhuanhuo");

	LogMessage log;
	log.type = card_use.to.isEmpty() ? "#HuanhuoNoTarget" : "#Huanhuo";
	log.from = yuji;
	log.to = card_use.to;
	log.arg = to_guhuo;
	log.arg2 = "crhuanhuo";
	room->sendLog(log);

	QString user_str;
	if (to_guhuo == "normal_slash")
		user_str = "slash";
	else
		user_str = to_guhuo;
	Card *use_card = Sanguosha->cloneCard(user_str, Card::NoSuit, 0);
	use_card->setSkillName("crhuanhuo");
	use_card->deleteLater();
	return use_card;
}
Exemple #3
0
void SPConvertSkill::onGameStart(ServerPlayer *player) const{
    QVariant data = "convert";
    if (player->askForSkillInvoke(objectName(), data)) {
        Room *room = player->getRoom();
        QStringList choicelist;
        foreach (QString to_gen, to_list) {
            const General *gen = Sanguosha->getGeneral(to_gen);
            if (gen && !Config.value("Ban/Roles", "").toStringList().contains(to_gen)
                    && !Sanguosha->getBanPackages().contains(gen->getPackage()))
                choicelist << to_gen;
        }
        QString to_cv = room->askForChoice(player, objectName(), choicelist.join("+"));

        LogMessage log;
        log.type = "#Transfigure";
        log.from = player;
        log.arg = to_cv;
        room->sendLog(log);
        room->setPlayerProperty(player, "general", to_cv);

        const General *general = Sanguosha->getGeneral(to_cv);
        const QString kingdom = general->getKingdom();
        if (kingdom != player->getKingdom())
            room->setPlayerProperty(player, "kingdom", kingdom);
    }
void SPConvertSkill::onGameStart(ServerPlayer *player) const{
    Room *room = player->getRoom();
    QStringList choicelist;
    foreach (QString to_gen, to_list) {
        const General *gen = Sanguosha->getGeneral(to_gen);
        if (gen && !Config.value("Banlist/Roles", "").toStringList().contains(to_gen)
            && !Sanguosha->getBanPackages().contains(gen->getPackage()))
            choicelist << to_gen;
    }
    QString data = choicelist.join("\\,\\");
    if (choicelist.length() >= 2)
        data.replace("\\,\\" + choicelist.last(), "\\or\\" + choicelist.last());
    if (player->askForSkillInvoke(objectName(), data)) {
        QString to_cv;
        AI *ai = player->getAI();
        if (ai)
            to_cv = room->askForChoice(player, objectName(), choicelist.join("+"));
        else
            to_cv = choicelist.length() == 1 ? choicelist.first() : room->askForGeneral(player, choicelist.join("+"));
        bool isSecondaryHero = (player->getGeneralName() != from && player->getGeneral2Name() == from);

        LogMessage log;
        log.type = player->getGeneral2() ? "#TransfigureDual" : "#Transfigure";
        log.from = player;
        log.arg = to_cv;
        log.arg2 = player->getGeneral2() ? (isSecondaryHero ? "GeneralB" : "GeneralA") : QString();
        room->sendLog(log);
        room->setPlayerProperty(player, isSecondaryHero ? "general2" : "general", to_cv);

        const General *general = Sanguosha->getGeneral(to_cv);
        const QString kingdom = general->getKingdom();
        if (!isSecondaryHero && kingdom != "god" && kingdom != player->getKingdom())
            room->setPlayerProperty(player, "kingdom", kingdom);
    }
}
    virtual bool trigger(TriggerEvent, ServerPlayer *caocao, QVariant &data) const{
        QString pattern = data.toString();
        if(pattern != "jink")
            return false;

        Room *room = caocao->getRoom();
        QList<ServerPlayer *> lieges = room->getLieges("wei", caocao);
        if(lieges.isEmpty())
            return false;

        if(!room->askForSkillInvoke(caocao, objectName()))
            return false;

        room->playSkillEffect(objectName());
        foreach(ServerPlayer *liege, lieges){
            QString result = room->askForChoice(liege, objectName(), "accept+ignore");
            if(result == "ignore")
                continue;

            const Card *jink = room->askForCard(liege, "jink", "@hujia-jink:" + caocao->objectName());
            if(jink){
                room->provide(jink);
                return true;
            }
        }
void EOSCard::onEffect(const CardEffectStruct &effect) const{
    ServerPlayer *jinteng = effect.from;
    Room *room = jinteng->getRoom();    

    QString choice = room->askForChoice(effect.from, "EOS", "fangju+fangyuma+jingongma");

    if(choice == "fangju"){
        if(effect.to->hasArmor()){
            room->moveCardTo(this, effect.to, Player::Hand);
            room->moveCardTo(effect.to->getEquip(1), jinteng, Player::Hand);
        }
    }else if(choice == "fangyuma"){
        if(effect.to->hasDefhorse()){
            room->moveCardTo(this, effect.to, Player::Hand);
            room->moveCardTo(effect.to->getEquip(2), jinteng, Player::Hand);
        }
    }else{
        if(effect.to->hasOffhorse()){
            room->moveCardTo(this, effect.to, Player::Hand);
            room->moveCardTo(effect.to->getEquip(3), jinteng, Player::Hand);
        }
    }

    room->playSkillEffect("EOS");

    return;


}
const Card *HuanhuoCard::validateInResponse(ServerPlayer *yuji) const
{
	Room *room = yuji->getRoom();
	room->broadcastSkillInvoke("crhuanhuo");

	QString to_guhuo;
	if (user_string == "peach+analeptic") {
		QStringList guhuo_list;
		guhuo_list << "peach";
		if (!Config.BanPackages.contains("maneuvering"))
			guhuo_list << "analeptic";
		to_guhuo = room->askForChoice(yuji, "crhuanhuo_saveself", guhuo_list.join("+"));
	}
	else if (user_string == "slash") {
		QStringList guhuo_list;
		guhuo_list << "slash";
		if (!Config.BanPackages.contains("maneuvering"))
			guhuo_list << "normal_slash" << "thunder_slash" << "fire_slash";
		to_guhuo = room->askForChoice(yuji, "crhuanhuo_slash", guhuo_list.join("+"));
	}
	else
		to_guhuo = user_string;

	LogMessage log;
	log.type = "#crhuanhuoNoTarget";
	log.from = yuji;
	log.arg = to_guhuo;
	log.arg2 = "crhuanhuo";
	room->sendLog(log);

	QString user_str;
	if (to_guhuo == "normal_slash")
		user_str = "slash";
	else
		user_str = to_guhuo;
	Card *use_card = Sanguosha->cloneCard(user_str, Card::NoSuit, 0);
	use_card->setSkillName("crhuanhuo");
	use_card->deleteLater();
	return use_card;
}
Exemple #8
0
 virtual bool trigger(TriggerEvent , ServerPlayer *player, QVariant &data) const{
     DamageStruct damage = data.value<DamageStruct>();
     Room *room = player->getRoom();
     if(damage.card && damage.card->inherits("Slash")){
     QString choice = room->askForChoice(player, "muramasa", "sky+yks");
     if(choice=="yks")
         damage.from = NULL;
     else {
     QList<ServerPlayer *> players = room->getAllPlayers();
     ServerPlayer *target = room->askForPlayerChosen(player, players, "muramasa");
     damage.from = target;
 }
     if(damage.from==player) return false;
     room->damage(damage);
     return true;
    }
 }
Exemple #9
0
    virtual bool trigger(TriggerEvent event, ServerPlayer *player, QVariant &data) const{
        Room *room = player->getRoom();
        QList<const Card *> clubs;

        if(event == CardUsed){
            CardUseStruct use = data.value<CardUseStruct>();
            const SkillCard *skill_card = qobject_cast<const SkillCard *>(use.card);
            if(skill_card && skill_card->subcardsLength() > 0 && skill_card->willThrow()){
                clubs = getClubs(skill_card);
            }
        }else if(event == CardDiscarded){
            const Card *card = data.value<CardStar>();
            if(card->subcardsLength() == 0)
                return false;

            clubs = getClubs(card);
        }else if(event == FinishJudge){
            JudgeStar judge = data.value<JudgeStar>();
            if(room->getCardPlace(judge->card->getEffectiveId()) == Player::DiscardedPile
               && judge->card->getSuit() == Card::Club)
               clubs << judge->card;
        }

        ServerPlayer *caozhi = room->findPlayerBySkillName(objectName());
        foreach(const Card* card, clubs)
            if(card->objectName() == "shit")
                if(caozhi && room->askForChoice(caozhi, objectName(), "yes+no") == "no")
                    clubs.removeOne(card);

        if(clubs.isEmpty())
            return false;

        if(caozhi && caozhi->askForSkillInvoke(objectName(), data)){
            if(player->getGeneralName() == "zhenji")
                room->playSkillEffect("luoying", 2);
            else
                room->playSkillEffect("luoying", 1);

            foreach(const Card *club, clubs)
                caozhi->obtainCard(club);
        }

        return false;
    }
Exemple #10
0
void DiyShenZhiCard::onEffect(const CardEffectStruct &effect) const{
    Room *room = effect.from->getRoom();
    const Card *card = Sanguosha->getCard(this->subcards.first());
    room->showCard(effect.from, card->getEffectiveId(), effect.to);
    QString choice = room->askForChoice(effect.to, "diyshenzhi", "obtain+reject");
    if(choice == "obtain"){
        room->moveCardTo(card, effect.to, Player::Hand, false);
        effect.to->drawCards(1);
        room->loseHp(effect.to, 1);
        room->playSkillEffect("diyshenzhi", 1);
    }else{
        room->throwCard(this, effect.from);
        int card_id = room->askForCardChosen(effect.from, effect.to, "he", "diyshenzhi");
        const Card *card = Sanguosha->getCard(card_id);
        bool is_public = room->getCardPlace(card_id) != Player::Hand;
        room->moveCardTo(card, effect.from, Player::Hand, is_public ? true : false);
        room->playSkillEffect("diyshenzhi", 2);
    }
}
    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;
                    }
                }
Exemple #12
0
    virtual bool trigger(TriggerEvent , ServerPlayer *player, QVariant &data) const{
        Room *room = player->getRoom();
        SlashEffectStruct effect = data.value<SlashEffectStruct>();
        if(!room->askForSkillInvoke(player, objectName(), data))
            return false;
        JudgeStruct judge;
        judge.pattern = QRegExp("(.*):(heart):(.*)");
        judge.good = false;
        judge.reason = objectName();
        judge.who = player;

        room->judge(judge);
        if(judge.isGood()){
            QStringList natures;
            natures << "normal_nature" << "fire_nature" << "thunder_nature" << "wind_nature";
            QString choice = room->askForChoice(player, objectName(), natures.join("+"));
            if(choice == "normal_nature")
                effect.nature = DamageStruct::Normal;
            else if(choice == "fire_nature")
                effect.nature = DamageStruct::Fire;
            else if(choice == "thunder_nature")
                effect.nature = DamageStruct::Thunder;
            else if(choice == "wind_nature")
                effect.nature = DamageStruct::Wind;

            LogMessage log;
            log.type = "#BaguaSwordLog";
            log.from = player;
            log.arg = choice;
            room->sendLog(log);

            data = QVariant::fromValue(effect);
            return false;
        }else{
            Jink *jink = new Jink(Card::NoSuit, 0);
            room->slashResult(effect, jink);
            return true;
        }
        return false;
    }
Exemple #13
0
    virtual void onDamaged(ServerPlayer *xiahou, const DamageStruct &damage) const{
        ServerPlayer *from = damage.from;
        Room *room = xiahou->getRoom();
        QVariant source = QVariant::fromValue(from);

        if(from && from->isAlive() && room->askForSkillInvoke(xiahou, "neoganglie", source)){
            room->broadcastSkillInvoke("ganglie");

            JudgeStruct judge;
            judge.pattern = QRegExp("(.*):(heart):(.*)");
            judge.good = false;
            judge.reason = objectName();
            judge.who = xiahou;

            room->judge(judge);
            if(judge.isGood()){
                QStringList choicelist;
                choicelist << "damage";
                if (from->getHandcardNum() > 1)
                    choicelist << "throw";
                QString choice;
                if (choicelist.length() == 1)
                    choice = choicelist.first();
                else
                    choice = room->askForChoice(xiahou, "neoganglie", choicelist.join("+"));
                if(choice == "damage"){
                    DamageStruct damage;
                    damage.from = xiahou;
                    damage.to = from;

                    room->setEmotion(xiahou, "good");
                    room->damage(damage);
                }
                else
                     room->askForDiscard(from, objectName(), 2, 2);
            }else
                room->setEmotion(xiahou, "bad");
        }
    }
Exemple #14
0
    virtual bool onPhaseChange(ServerPlayer *wangyi) const{
        if(wangyi->getPhase() == Player::Finish && wangyi->isWounded()){
            Room *room = wangyi->getRoom();
            QStringList choices;
            for(int i = wangyi->getLostHp(); i > 0; i--)
                choices << QString::number(i);
            choices.append("cancel");
            QString choice = room->askForChoice(wangyi, objectName(), choices.join("+"));
            if(choice == "cancel")
                return false;
            int x = choice.toInt();
            wangyi->drawCards(x);
            room->setPlayerMark(wangyi, "miji", x);
            bool used = room->askForUseCard(wangyi, "@@miji!", "@miji:::" + choice);

            if(!used){
                QList<int> to_give = wangyi->handCards().mid(0, x);
                MijiCard *miji_card = new MijiCard;
                foreach(int card_id, to_give)
                    miji_card->addSubcard(card_id);
                QList<ServerPlayer *> targets = room->getOtherPlayers(wangyi);
                miji_card->use(room, wangyi, targets);
                delete miji_card;
            }
Exemple #15
0
    virtual bool trigger(TriggerEvent event, ServerPlayer *jim, QVariant &data) const{
        Room *room = jim->getRoom();

        if(event == Dying){
            if(jim && jim->askForSkillInvoke(objectName(), data)){
                room->playSkillEffect("juesi");
                int x = jim->getMaxHP();
                if(x > 4)
                    x = 4;
                bool has_duplicate = false;
                bool maxhp_increased = false;
                bool has_second_duplicate = false;
                bool survived = false;

                QList<int> card_ids = room->getNCards(x);
                int i, j;
                for(i=0; i < card_ids.length(); i++){
                    for(j=i+1; j < card_ids.length(); j++){
                        const Card *card = Sanguosha->getCard(card_ids.at(i));
                        if(card->sameColorWith( Sanguosha->getCard(card_ids.at(j)) )){
                            has_duplicate = true;
                        }
                    }
                }
                qSort(card_ids.begin(), card_ids.end(), CompareBySuit);
                room->fillAG(card_ids);
                if(has_duplicate)
                    if(room->askForChoice(jim, "juesi", "maxhp+cancel") == "maxhp"){

                        int card_id = room->askForAG(jim, card_ids, false, "juesi");
                        card_ids.removeOne(card_id);
                        room->takeAG(NULL, card_id);

                        int card_id2 = room->askForAG(jim, card_ids, false, "juesi");
                        card_ids.removeOne(card_id2);
                        room->takeAG(NULL, card_id2);

                        if(Sanguosha->getCard(card_id)->sameColorWith(Sanguosha->getCard(card_id2))){
                            room->setPlayerProperty(jim, "maxhp", jim->getMaxHP() + 1);
                            maxhp_increased = true;
                        }
                    }

                for(i=0; i < card_ids.length(); i++){
                    for(j=i+1; j < card_ids.length(); j++){
                        const Card *card = Sanguosha->getCard(card_ids.at(i));
                        if(card->sameColorWith( Sanguosha->getCard(card_ids.at(j)) )){
                            has_second_duplicate = true;
                        }
                    }
                }

                if(maxhp_increased && has_second_duplicate)
                    if(room->askForChoice(jim, "juesi", "hp+cancel") == "hp"){

                        int card_id = room->askForAG(jim, card_ids, false, "juesi");
                        card_ids.removeOne(card_id);
                        room->takeAG(NULL, card_id);

                        int card_id2 = room->askForAG(jim, card_ids, false, "juesi");
                        card_ids.removeOne(card_id2);
                        room->takeAG(NULL, card_id2);

                        if(Sanguosha->getCard(card_id)->sameColorWith(Sanguosha->getCard(card_id2))){
                            RecoverStruct recover;
                            recover.who = jim;
                            room->recover(jim, recover);
                            if(jim->getHp()>0)
                                survived = true;
                        }
                    }

                if(survived){
                    foreach(int card_id, card_ids){
                        room->takeAG(jim, card_id);
                    }
                }else{