Exemple #1
0
void EquipCard::use(Room *room, ServerPlayer *source, QList<ServerPlayer *> &targets) const
{
    if (targets.isEmpty()) {
        CardMoveReason reason(CardMoveReason::S_REASON_USE, source->objectName(), QString(), this->getSkillName(), QString());
        room->moveCardTo(this, NULL, Player::DiscardPile, reason, true);
    }
    int equipped_id = Card::S_UNKNOWN_CARD_ID;
    ServerPlayer *target = targets.first();
    if (target->getEquip(location()))
        equipped_id = target->getEquip(location())->getEffectiveId();

    QList<CardsMoveStruct> exchangeMove;
    CardsMoveStruct move1(getEffectiveId(), target, Player::PlaceEquip,
        CardMoveReason(CardMoveReason::S_REASON_USE, target->objectName()));
    exchangeMove.push_back(move1);
    if (equipped_id != Card::S_UNKNOWN_CARD_ID) {
        CardsMoveStruct move2(equipped_id, NULL, Player::DiscardPile,
            CardMoveReason(CardMoveReason::S_REASON_CHANGE_EQUIP, target->objectName()));
        exchangeMove.push_back(move2);
    }
    LogMessage log;
    log.from = target;
    log.type = "$Install";
    log.card_str = QString::number(getEffectiveId());
    room->sendLog(log);

    room->moveCardsAtomic(exchangeMove, true);
}
    bool trigger(TriggerEvent, Room *room, ServerPlayer *player, QVariant &data) const{
        PhaseChangeStruct change = data.value<PhaseChangeStruct>();
        if (change.to != Player::NotActive) return false;
        int weapon_id = player->tag.value("DrJiedaoWeapon", -1).toInt();
        player->tag["DrJiedaoWeapon"] = -1;
        if (!player->getWeapon()
            || weapon_id != player->getWeapon()->getEffectiveId())
            return false;
        ServerPlayer *target = NULL;
        foreach (ServerPlayer *p, room->getOtherPlayers(player))
            if (p->hasFlag("DrJiedaoTarget")) {
                p->setFlags("-DrJiedaoTarget");
                target = p;
                break;
            }
        if (target == NULL) {
            room->throwCard(player->getWeapon(), NULL);
        } else {
            QList<CardsMoveStruct> exchangeMove;
            CardsMoveStruct move1(player->getWeapon()->getEffectiveId(), target, Player::PlaceEquip,
                                  CardMoveReason(CardMoveReason::S_REASON_GOTCARD, player->objectName()));
            exchangeMove.push_back(move1);
            if (target->getWeapon() != NULL) {
                CardsMoveStruct move2(target->getWeapon()->getEffectiveId(), NULL, Player::DiscardPile,
                                      CardMoveReason(CardMoveReason::S_REASON_CHANGE_EQUIP, target->objectName()));
                exchangeMove.push_back(move2);
            }
            room->moveCardsAtomic(exchangeMove, true);
        }

        return false;
    }
void EquipCard::use(Room *room, ServerPlayer *, QList<ServerPlayer *> &targets) const{
    int equipped_id = Card::S_UNKNOWN_CARD_ID;
    ServerPlayer *target = targets.first();
    if (target->getEquip(location()))
        equipped_id = target->getEquip(location())->getEffectiveId();

    QList<CardsMoveStruct> exchangeMove;
    CardsMoveStruct move1;
    move1.card_ids << getId();
    move1.to = target;
    move1.to_place = Player::PlaceEquip;
    move1.reason = CardMoveReason(CardMoveReason::S_REASON_USE, target->objectName());
    exchangeMove.push_back(move1);
    if (equipped_id != Card::S_UNKNOWN_CARD_ID) {
         CardsMoveStruct move2;
         move2.card_ids << equipped_id;
         move2.to = NULL;
         move2.to_place = Player::DiscardPile;
         move2.reason = CardMoveReason(CardMoveReason::S_REASON_CHANGE_EQUIP, target->objectName());
         exchangeMove.push_back(move2);
    }
    LogMessage log;
    log.from = target;
    log.type = "$Install";
    log.card_str = QString::number(getEffectiveId());
    room->sendLog(log);

    room->moveCardsAtomic(exchangeMove, true);
}
    virtual bool trigger(TriggerEvent , Room* room, ServerPlayer *player, QVariant &data) const{
        JudgeStar judge = data.value<JudgeStar>();
        if(judge->who != player)
            return false;

        if(player->askForSkillInvoke(objectName(), data)){
            room->playSkillEffect(objectName());

            int card_id = room->drawCard();

            if(room->getCardPlace(judge->card->getEffectiveId()) == Player::TopDrawPile)
                room->throwCard(judge->card, judge->who);

            judge->card = Sanguosha->getCard(card_id);
            room->moveCardTo(judge->card, player, NULL, Player::TopDrawPile,
                             CardMoveReason(CardMoveReason::S_REASON_RETRIAL, player->getGeneralName(), this->objectName(), QString()), true);
            LogMessage log;
            log.type = "$ChangedJudge";
            log.from = player;
            log.to << judge->who;
            log.card_str = judge->card->getEffectIdString();
            room->sendLog(log);

            room->sendJudgeResult(judge);
            room->getThread()->delay(500);
        }
        return false;
    }
void DrJiedaoCard::onEffect(const CardEffectStruct &effect) const{
    if (!effect.to->getWeapon()) return;
    effect.from->tag["DrJiedaoWeapon"] = effect.to->getWeapon()->getEffectiveId();
    effect.to->setFlags("DrJiedaoTarget");

    QList<CardsMoveStruct> exchangeMove;
    CardsMoveStruct move1(effect.to->getWeapon()->getEffectiveId(), effect.from, Player::PlaceEquip,
                          CardMoveReason(CardMoveReason::S_REASON_ROB, effect.from->objectName()));
    exchangeMove.push_back(move1);
    if (effect.from->getWeapon() != NULL) {
        CardsMoveStruct move2(effect.from->getWeapon()->getEffectiveId(), NULL, Player::DiscardPile,
                              CardMoveReason(CardMoveReason::S_REASON_CHANGE_EQUIP, effect.from->objectName()));
        exchangeMove.push_back(move2);
    }
    effect.to->getRoom()->moveCardsAtomic(exchangeMove, true);
}
Exemple #6
0
void EquipCard::use(Room *room, ServerPlayer *source, QList<ServerPlayer *> &targets) const{
    const EquipCard *equipped = NULL;
    ServerPlayer *target = targets.value(0, source);
    if (room->getCardOwner(getId()) != source) return;
    switch(location()){
    case WeaponLocation: equipped = target->getWeapon(); break;
    case ArmorLocation: equipped = target->getArmor(); break;
    case DefensiveHorseLocation: equipped = target->getDefensiveHorse(); break;
    case OffensiveHorseLocation: equipped = target->getOffensiveHorse(); break;
    }

    if (room->getCardPlace(getId()) == Player::PlaceHand)
        {
            QList<CardsMoveStruct> exchangeMove;
            CardsMoveStruct move1;
            move1.card_ids << getId();
            move1.to = target;
            move1.to_place = Player::PlaceEquip;
            move1.reason = CardMoveReason(CardMoveReason::S_REASON_USE, target->objectName());
            exchangeMove.push_back(move1);
            if(equipped)
            {
                CardsMoveStruct move2;
                move2.card_ids << equipped->getId();
                move2.to = NULL;
                move2.to_place = Player::DiscardPile;
                move2.reason = CardMoveReason(CardMoveReason::S_REASON_CHANGE_EQUIP, target->objectName());
                exchangeMove.push_back(move2);
            }
            LogMessage log;
            log.from = target;
            log.type = "$Install";
            log.card_str = QString::number(getEffectiveId());
            room->sendLog(log);

            room->moveCardsAtomic(exchangeMove, true);
        }

}