Пример #1
0
    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();
            room->broadcastSkillInvoke(objectName(), 1);
            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();
                wangyi->drawCards(x); //It should be preview, not draw
                ServerPlayer *target = room->askForPlayerChosen(wangyi, room->getAllPlayers(), objectName());

                if (target == wangyi)
                    room->broadcastSkillInvoke(objectName(), 2);
                else if (target->getGeneralName().contains("machao"))
                    room->broadcastSkillInvoke(objectName(), 4);
                else
                    room->broadcastSkillInvoke(objectName(), 3);

                QList<const Card *> miji_cards = wangyi->getHandcards().mid(wangyi->getHandcardNum() - x);
                foreach(const Card *card, miji_cards){
                    CardMoveReason reason(CardMoveReason::S_REASON_GIVE, wangyi->objectName());
                    reason.m_playerId == target->objectName();
                    room->obtainCard(target, card, reason, false);
                }
            }
Пример #2
0
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");
    }
Пример #3
0
    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()){
                room->playSkillEffect(objectName());
                int x = wangyi->getLostHp();
                wangyi->drawCards(x);
                ServerPlayer *target = room->askForPlayerChosen(wangyi, room->getAllPlayers(), objectName());

                QList<const Card *> miji_cards = wangyi->getHandcards().mid(wangyi->getHandcardNum() - x);
                foreach(const Card *card, miji_cards)
                    room->obtainCard(target, card, false);
            }
        }
Пример #4
0
void DelayedTrick::onNullified(ServerPlayer *target) const
{
    Room *room = target->getRoom();
    RoomThread *thread = room->getThread();
    if (movable) {
        QList<ServerPlayer *> players = room->getOtherPlayers(target);
        players << target;
        ServerPlayer *p = NULL;

        foreach (ServerPlayer *player, players) {
            if (player->containsTrick(objectName()))
                continue;

            const ProhibitSkill *skill = room->isProhibited(target, player, this);
            if (skill) {
                if (skill->isVisible()) {
                    LogMessage log;
                    log.type = "#SkillAvoid";
                    log.from = player;
                    log.arg = skill->objectName();
                    log.arg2 = objectName();
                    room->sendLog(log);

                    room->broadcastSkillInvoke(skill->objectName());
                }
                continue;
            }

            CardMoveReason reason(CardMoveReason::S_REASON_TRANSFER, target->objectName(), QString(), this->getSkillName(), QString());
            room->moveCardTo(this, target, player, Player::PlaceDelayedTrick, reason, true);

            if (target == player) break;

            CardUseStruct use;
            use.from = NULL;
            use.to << player;
            use.card = this;
            QVariant data = QVariant::fromValue(use);
            thread->trigger(TargetConfirming, room, player, data);
            CardUseStruct new_use = data.value<CardUseStruct>();
            if (new_use.to.isEmpty()) {
                p = player;
                break;
            }

            foreach(ServerPlayer *p, room->getAllPlayers())
                thread->trigger(TargetConfirmed, room, p, data);
            break;
        }
        if (p)
            onNullified(p);
    } else {
Пример #5
0
    virtual bool onPhaseChange(ServerPlayer *target) const {
        if(target->getPhase() == Player::Finish) {
            Room *room = target->getRoom();
            QList<ServerPlayer *> players = room->getAllPlayers();
            foreach(ServerPlayer *player, players) {
                if(player->hasFlag("jilei")) {

                    player->setFlags("-jilei");
                    player->setFlags("-jileiB");
                    player->setFlags("-jileiE");
                    player->setFlags("-jileiT");

                    player->invoke("jilei");
                }
            }
        }
Пример #6
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;
    }
 }
Пример #7
0
 virtual bool trigger(TriggerEvent , ServerPlayer *player, QVariant &data) const {
     CardUseStruct use = data.value<CardUseStruct>();
     if(use.card->inherits("NeptunianAttack") &&
             ((!use.card->isVirtualCard()) ||
              (use.card->getSubcards().length() == 1 &&
               Bang->getCard(use.card->getSubcards().first())->inherits("NeptunianAttack")))) {
         Room *room = player->getRoom();
         if(room->getCardPlace(use.card->getEffectiveId()) == Player::DiscardPile) {
             QList<ServerPlayer *> players = room->getAllPlayers();
             foreach(ServerPlayer *p, players) {
                 if(p->hasSkill(objectName())) {
                     p->obtainCard(use.card);
                     room->playSkillEffect(objectName());
                     break;
                 }
             }
         }
Пример #8
0
    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;
    }
Пример #9
0
bool GameRule::trigger(TriggerEvent event, ServerPlayer *player, QVariant &data) const{
    Room *room = player->getRoom();

    switch(event){
    case GameStart: {
            if(player->getKingdom() == "god"){
                QString new_kingdom = room->askForKingdom(player);
                if(new_kingdom != "god")
                    room->setPlayerProperty(player, "kingdom", new_kingdom);

                LogMessage log;
                log.type = "#ChooseKingdom";
                log.from = player;
                log.arg = new_kingdom;
                room->sendLog(log);
            }

            player->drawCards(4, false);
            break;
        }

    case PhaseChange: onPhaseChange(player); break;
    case CardUsed: {
            if(data.canConvert<CardUseStruct>()){
                CardUseStruct card_use = data.value<CardUseStruct>();
                const Card *card = card_use.card;

                card_use.from->playCardEffect(card);
                card->use(room, card_use.from, card_use.to);
            }

            break;
        }

    case Dying:{
            DyingStruct dying = data.value<DyingStruct>();
            int got = room->askForPeaches(player, dying.peaches);
            if(got >= dying.peaches)
                room->setPlayerProperty(player, "hp", got - dying.peaches + 1);
            else{
                ServerPlayer *killer = NULL;
                if(dying.damage && dying.damage->from)
                    killer = dying.damage->from;

                room->killPlayer(player, killer);
            }
            break;
        }

    case Predamaged:{
            if(data.canConvert<DamageStruct>()){
                DamageStruct damage = data.value<DamageStruct>();
                room->sendDamageLog(damage);

                int new_hp = player->getHp() - damage.damage;
                room->damage(player, damage.damage);
                if(new_hp <= 0){
                    DyingStruct dying;
                    dying.damage = &damage;
                    dying.peaches = 1 - new_hp;

                    QVariant dying_data = QVariant::fromValue(dying);
                    room->getThread()->trigger(Dying, player, dying_data);
                }

                bool chained = player->isChained();
                if(damage.nature != DamageStruct::Normal && chained){
                    room->setPlayerProperty(player, "chained", false);

                    // iron chain effect
                    QList<ServerPlayer *> chained_players = room->getAllPlayers();
                    chained_players.removeOne(player);

                    foreach(ServerPlayer *chained_player, chained_players){
                        if(chained_player->isChained()){
                            DamageStruct chain_damage = damage;
                            chain_damage.to = chained_player;
                            chain_damage.chain = true;

                            room->setPlayerProperty(chained_player, "chained", false);
                            room->damage(chain_damage);
                        }
                    }
                }
            }

            break;
        }