const Card *Card::Parse(const QString &str){ if(str.startsWith(QChar('@'))){ // skill card static QRegExp pattern("@(\\w+)=(.+)"); pattern.indexIn(str); QStringList texts = pattern.capturedTexts(); QString card_name = texts.at(1); QStringList subcard_ids; QString subcard_str = texts.at(2); if(subcard_str != ".") subcard_ids = subcard_str.split("+"); SkillCard *card = Sanguosha->cloneSkillCard(card_name); if(card == NULL) return NULL; foreach(QString subcard_id, subcard_ids) card->addSubcard(subcard_id.toInt()); // skill name QString skill_name = card_name.remove("Card").toLower(); card->setSkillName(skill_name); return card; }else if(str.startsWith(QChar('$'))){ QString copy = str; copy.remove(QChar('$')); QStringList card_strs = copy.split("+"); DummyCard *dummy = new DummyCard; foreach(QString card_str, card_strs){ dummy->addSubcard(card_str.toInt()); }
void ServerPlayer::throwAllEquips(){ QList<const Card *> equips = getEquips(); if(equips.isEmpty()) return; DummyCard *card = new DummyCard; foreach(const Card *equip, equips) card->addSubcard(equip); room->throwCard(card, this); card->deleteLater(); }
void ServerPlayer::throwAllEquips() { QList<const Card *> equips = getEquips(); if (equips.isEmpty()) return; DummyCard *card = new DummyCard; foreach (const Card *equip, equips) { if (!isJilei(card)) card->addSubcard(equip); } if (card->subcardsLength() > 0) room->throwCard(card, this); delete card; }
void ServerPlayer::throwAllCards() { DummyCard *card = isKongcheng() ? new DummyCard : wholeHandCards(); QList<const Card *> equips = getEquips(); foreach (const Card *equip, equips) card->addSubcard(equip); if (card->subcardsLength() != 0) room->throwCard(card, this); delete card; QList<const Card *> tricks = getJudgingArea(); foreach (const Card *trick, tricks) { CardMoveReason reason(CardMoveReason::S_REASON_THROW, this->objectName()); room->throwCard(trick, reason, NULL); }
virtual bool trigger(TriggerEvent, Room *room, ServerPlayer *caopi, QVariant &data) const{ DeathStruct death = data.value<DeathStruct>(); ServerPlayer *player = death.who; if (player->isNude() || caopi == player) return false; if (caopi->isAlive() && room->askForSkillInvoke(caopi, objectName(), data)) { bool isCaoCao = player->getGeneralName().contains("caocao"); room->broadcastSkillInvoke(objectName(), (isCaoCao ? 3 : (player->isMale() ? 1 : 2))); DummyCard *dummy = new DummyCard; QList <const Card *> handcards = player->getHandcards(); foreach (const Card *card, handcards) dummy->addSubcard(card); QList <const Card *> equips = player->getEquips(); foreach (const Card *card, equips) dummy->addSubcard(card); if (dummy->subcardsLength() > 0) { CardMoveReason reason(CardMoveReason::S_REASON_RECYCLE, caopi->objectName()); room->obtainCard(caopi, dummy, reason, false); } delete dummy; }
void ServerPlayer::throwAllEquips(){ QList<const Card *> equips = getEquips(); if(equips.isEmpty()) return; DummyCard *card = new DummyCard; foreach(const Card *equip, equips) card->addSubcard(equip); room->throwCard(card); CardStar card_star = card; QVariant data = QVariant::fromValue(card_star); room->getThread()->trigger(CardDiscarded, this, data); card->deleteLater(); }
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; } }
bool onPhaseChange(ServerPlayer *player) const { if (player->getPhase() == Player::Start) { Room *room = player->getRoom(); player->setMark("juao", 0); LogMessage log; log.type = "#JuaoObtain"; log.from = player; log.arg = objectName(); room->sendLog(log); DummyCard *dummy = new DummyCard; foreach (int card_id, player->getPile("hautain")) { dummy->addSubcard(card_id); } player->obtainCard(dummy, false); delete dummy; player->skip(Player::Draw); }