virtual bool onPhaseChange(ServerPlayer *target) const{
        if (target->getPhase() == Player::Draw){
            Room *room = target->getRoom();

            int qunplayers = 0;
            foreach(ServerPlayer *p, room->getAlivePlayers())
                if (p->getKingdom() == "qun")
                    ++qunplayers;

            if (qunplayers <= 1)
                return false;

            if (qunplayers > 0 && target->askForSkillInvoke(objectName())){
                QList<int> guanxing_cards = room->getNCards(qunplayers);
                room->askForGuanxing(target, guanxing_cards, Room::GuanxingUpOnly);
            }

            if (target->getPile("skysoldier").length() == 0){
                Room *room = target->getRoom();

                int qunplayers = 0;
                foreach(ServerPlayer *p, room->getAlivePlayers())
                    if (p->getKingdom() == "qun")
                        ++qunplayers;

                if (qunplayers == 0)
                    return false;

                QList<int> skill2cards = room->getNCards(qunplayers);
                CardMoveReason reason(CardMoveReason::S_REASON_TURNOVER, target->objectName(), objectName(), QString());
                CardsMoveStruct move(skill2cards, NULL, Player::PlaceTable, reason);
                room->moveCardsAtomic(move, true);
                room->getThread()->delay();
                room->getThread()->delay();

                target->addToPile("skysoldier", skill2cards, true);

            }
예제 #2
0
void DelayedTrick::onEffect(const CardEffectStruct &effect) const
{
    Room *room = effect.to->getRoom();

    CardMoveReason reason(CardMoveReason::S_REASON_USE, effect.to->objectName(), getSkillName(), QString());
    room->moveCardTo(this, NULL, Player::PlaceTable, reason, true);

    LogMessage log;
    log.from = effect.to;
    log.type = "#DelayedTrick";
    log.arg = effect.card->objectName();
    room->sendLog(log);

    JudgeStruct judge_struct = judge;
    judge_struct.who = effect.to;
    room->judge(judge_struct);

    if (judge_struct.negative == judge_struct.isBad()) {
        if (effect.to->isAlive())
            takeEffect(effect.to);
        if (room->getCardOwner(getEffectiveId()) == NULL) {
            CardMoveReason reason(CardMoveReason::S_REASON_NATURAL_ENTER, QString());
            room->throwCard(this, reason, NULL);
        }
    } else if (movable) {
        onNullified(effect.to);
    } else if (returnable && effect.to->isAlive()) {
        if (room->getCardOwner(getEffectiveId()) == NULL) {
            if (isVirtualCard()) {
                Card *delayTrick = Sanguosha->cloneCard(objectName());
                WrappedCard *vs_card = Sanguosha->getWrappedCard(getEffectiveId());
                vs_card->setSkillName(getSkillName());
                vs_card->takeOver(delayTrick);
                room->broadcastUpdateCard(room->getAlivePlayers(), vs_card->getId(), vs_card);
            }
           
            CardsMoveStruct move;
            move.card_ids << getEffectiveId();
            move.to = effect.to;
            move.to_place = Player::PlaceDelayedTrick;
            room->moveCardsAtomic(move, true);
        }
    }
    else {
        if (room->getCardOwner(getEffectiveId()) == NULL) {
            CardMoveReason reason(CardMoveReason::S_REASON_NATURAL_ENTER, QString());
            room->throwCard(this, reason, NULL);
        }
    }
}
예제 #3
0
AI::Relation AI::GetRelation(const ServerPlayer *a, const ServerPlayer *b) {
    if (a == b) return Friend;
    static RoleMapping map, map_good, map_bad;
    if (map.isEmpty()) {
        map.set("lord", "lord", Friend);
        map.set("lord", "rebel", Enemy);
        map.set("lord", "loyalist", Friend);
        map.set("lord", "renegade", Neutrality);

        map.set("loyalist", "loyalist", Friend);
        map.set("loyalist", "lord", Friend);
        map.set("loyalist", "rebel", Enemy);
        map.set("loyalist", "renegade", Neutrality);

        map.set("rebel", "rebel", Friend);
        map.set("rebel", "lord", Enemy);
        map.set("rebel", "loyalist", Enemy);
        map.set("rebel", "renegade", Neutrality);

        map.set("renegade", "lord", Friend);
        map.set("renegade", "loyalist", Neutrality);
        map.set("renegade", "rebel", Neutrality);
        map.set("renegade", "renegade", Neutrality);

        map_good = map;
        map_good.set("renegade", "loyalist", Enemy, false);
        map_good.set("renegade", "lord", Neutrality, true);
        map_good.set("renegade", "rebel", Friend, false);

        map_bad = map;
        map_bad.set("renegade", "loyalist", Neutrality, true);
        map_bad.set("renegade", "rebel", Enemy, true);
    }

    if (a->aliveCount() == 2) {
        return Enemy;
    }

    QString roleA = a->getRole();
    QString roleB = b->getRole();
    
    Room *room = a->getRoom();
    
    int good = 0, bad = 0;
    QList<ServerPlayer *> players = room->getAlivePlayers();
    foreach (ServerPlayer *player, players) {
        switch (player->getRoleEnum()) {
        case Player::Lord:
        case Player::Loyalist: good++; break;
        case Player::Rebel: bad++; break;
        case Player::Renegade: good++; break;
        }
    }

    if (bad > good)
        return map_bad.get(roleA, roleB);
    else if (good > bad)
        return map_good.get(roleA, roleB);
    else 
        return map.get(roleA, roleB);
}
예제 #4
0
파일: wind.cpp 프로젝트: yuanshu/QSanguosha
 virtual void onGameStart(ServerPlayer *zhangjiao) const{
     Room *room = zhangjiao->getRoom();
     QList<ServerPlayer *> players = room->getAlivePlayers();
     foreach(ServerPlayer *player, players){
         room->attachSkillToPlayer(player, "huangtianv");
     }