Exemplo n.º 1
0
void NeoFanjianCard::onEffect(const CardEffectStruct &effect) const{
    ServerPlayer *zhouyu = effect.from;
    ServerPlayer *target = effect.to;
    Room *room = zhouyu->getRoom();

    room->broadcastSkillInvoke("fanjian");
    const Card *card = Sanguosha->getCard(getSubcards().first());
    int card_id = card->getEffectiveId();
    Card::Suit suit = room->askForSuit(target, "neofanjian");

    LogMessage log;
    log.type = "#ChooseSuit";
    log.from = target;
    log.arg = Card::Suit2String(suit);
    room->sendLog(log);

    room->getThread()->delay();
    target->obtainCard(this);
    room->showCard(target, card_id);

    if(card->getSuit() != suit){
        DamageStruct damage;
        damage.card = NULL;
        damage.from = zhouyu;
        damage.to = target;

        room->damage(damage);
    }
}
Exemplo n.º 2
0
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;
}
Exemplo n.º 3
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);
}
Exemplo n.º 4
0
UINT LWChangeNameHandler::Execute(LWChangeName* pPacket, Player* pPlayer )
{
__ENTER_FUNCTION
	
	TID CurrentThreadID = MyGetCurrentThreadID();

	if(CurrentThreadID == g_pServerManager->m_ThreadID)
	{

		Assert(pPacket);
		
		ServerPlayer* pServerPlayer  = (ServerPlayer*)pPlayer;
		
		Assert(pServerPlayer);

		pServerPlayer->SendPacket(pPacket);
	}
	else
	{
		AssertEx(FALSE,"LWChangeNameHandler 线程资源执行错误!");
	}
	g_pLog->FastSaveLog(LOG_FILE_0,"LWChangeNameHandler::Execute() ....OK");

	return PACKET_EXE_CONTINUE;

__LEAVE_FUNCTION

	return PACKET_EXE_ERROR;
}
Exemplo n.º 5
0
void QuhuCard::use(Room *room, ServerPlayer *xunyu, QList<ServerPlayer *> &targets) const{
    ServerPlayer *tiger = targets.first();

    room->broadcastSkillInvoke("quhu", 1);

    bool success = xunyu->pindian(tiger, "quhu", NULL);
    if (success) {
        room->broadcastSkillInvoke("quhu", 2);

        QList<ServerPlayer *> players = room->getOtherPlayers(tiger), wolves;
        foreach (ServerPlayer *player, players) {
            if (tiger->inMyAttackRange(player))
                wolves << player;
        }

        if (wolves.isEmpty()) {
            LogMessage log;
            log.type = "#QuhuNoWolf";
            log.from = xunyu;
            log.to << tiger;
            room->sendLog(log);

            return;
        }

        ServerPlayer *wolf = room->askForPlayerChosen(xunyu, wolves, "quhu", QString("@quhu-damage:%1").arg(tiger->objectName()));
        room->damage(DamageStruct("quhu", tiger, wolf));
    } else {
Exemplo n.º 6
0
void EquipCard::use(Room *room, ServerPlayer *source, const QList<ServerPlayer *> &targets) const{
    const EquipCard *equipped = NULL;
    ServerPlayer *target = targets.value(0, source);
    
    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(equipped)
        room->throwCard(equipped, source);
    int tmpId = -1;
    if(getId() > -1)
        tmpId = getId();
    else if(!getSubcards().empty())
       tmpId = this->getSubcards().first();
    if(this->objectName() == "gale-shell" || room->getCardOwner(tmpId)->objectName() == target->objectName()){
        LogMessage log;
        log.from = target;
        log.type = "$Install";
        log.card_str = QString::number(tmpId);
        room->sendLog(log);
        room->moveCardTo(this, target, Player::Equip, true);
    }
}
Exemplo n.º 7
0
void HuangtianCard::use(Room *room, ServerPlayer *source, QList<ServerPlayer *> &targets) const
{
    ServerPlayer *zhangjiao = targets.first();
    if (zhangjiao->hasLordSkill("huangtian")) {
        room->setPlayerFlag(zhangjiao, "HuangtianInvoked");

        if (!zhangjiao->isLord() && zhangjiao->hasSkill("weidi"))
            room->broadcastSkillInvoke("weidi");
        else {
            int index = qrand() % 2 + 1;
            if (Player::isNostalGeneral(zhangjiao, "zhangjiao"))
                index += 2;
            room->broadcastSkillInvoke("huangtian", index);
        }

        room->notifySkillInvoked(zhangjiao, "huangtian");
        CardMoveReason reason(CardMoveReason::S_REASON_GIVE, source->objectName(), zhangjiao->objectName(), "huangtian", QString());
        room->obtainCard(zhangjiao, this, reason);
        QList<ServerPlayer *> zhangjiaos;
        QList<ServerPlayer *> players = room->getOtherPlayers(source);
        foreach (ServerPlayer *p, players) {
            if (p->hasLordSkill("huangtian") && !p->hasFlag("HuangtianInvoked"))
                zhangjiaos << p;
        }
        if (zhangjiaos.isEmpty())
            room->setPlayerFlag(source, "ForbidHuangtian");
    }
Exemplo n.º 8
0
UINT    LBAskAuthHandler::Execute(LBAskAuth* pPacket, Player* pPlayer )
{
    __ENTER_FUNCTION
        
        TID CurrentThreadID = MyGetCurrentThreadID();
        
        if(CurrentThreadID == g_pServerManager->m_ThreadID)
        {
            Assert(pPacket);

            ServerPlayer* pServerPlayer  = (ServerPlayer*)pPlayer;

            Assert(pServerPlayer);

            pServerPlayer->SendPacket(pPacket);
        }
        else
        {
            AssertEx(FALSE,"LBAskAuthHandler 线程资源执行错误!");
        }
        
        Log::SaveLog(LOGIN_LOGFILE,"LBAskAuthHandler::Execute() ....OK");

        return PACKET_EXE_CONTINUE;

    __LEAVE_FUNCTION

        return PACKET_EXE_ERROR;
}
Exemplo n.º 9
0
 virtual QStringList triggerable(TriggerEvent, Room *, ServerPlayer *simayi, QVariant &data, ServerPlayer * &) const {
     if (MasochismSkill::triggerable(simayi)) {
         ServerPlayer *from = data.value<DamageStruct>().from;
         return (from && !from->isNude()) ? QStringList(objectName()) : QStringList();
     }
     return QStringList();
 }
Exemplo n.º 10
0
bool ServerManager::ProcessCommands( )
{
	bool ret = false;

	if(m_MinFD == INVALID_SOCKET && m_MaxFD == INVALID_SOCKET)
	{
		return true;
	}

	for(int i=SCENE_PLAYER_ID; i<=BILLING_PLAYER_ID; i++)
	{
		ServerPlayer*	pPlayer = GetServerPlayer(i);
		if(!pPlayer) continue;

		if(pPlayer->IsValid())
		{
			if(pPlayer->GetSocket()->isSockError() )
			{
				RemoveServer(i);
			}
			else
			{
				ret = pPlayer->ProcessCommand(false);
				if(!ret)
				{
					RemoveServer( i );
				}
			}
		}
	}

	return true;
}
Exemplo n.º 11
0
uint GWHeartBeatHandler::Execute( GWHeartBeat* pPacket, Player* pPlayer )
{
	__ENTER_FUNCTION

	ServerPlayer* pServerPlayer = (ServerPlayer*)pPlayer ;

	GUID_t sGUID = pPacket->GetGUID() ;

	USER* pUser = g_pOnlineUser->FindUser( sGUID ) ;
	if( pUser==NULL )
	{
		WGNotifyUser Msg ;
		Msg.SetGUID( sGUID ) ;
		Msg.SetStatus( WGNotifyUser::NUS_REMOVE ) ;

		pServerPlayer->SendPacket( &Msg ) ;
		
		Log::SaveLog( WORLD_LOGFILE, "GWHeartBeatHandler...User GUID=%X not find! Notify server!", 
			sGUID ) ;

		return PACKET_EXE_CONTINUE ;
	}

	pUser->ResetKickTime() ;

	Log::SaveLog( WORLD_LOGFILE, "GWHeartBeatHandler...User GUID=%X Status=%d!", 
		sGUID, pUser->UserStatus() ) ;
	
	return PACKET_EXE_CONTINUE ;

	__LEAVE_FUNCTION

		return PACKET_EXE_ERROR ;
}
Exemplo n.º 12
0
bool ServerManager::ProcessExceptions( )
{
	if(m_MinFD == INVALID_SOCKET && m_MaxFD == INVALID_SOCKET)
	{
		return true;
	}

	for(int i=SCENE_PLAYER_ID; i<=BILLING_PLAYER_ID; i++)
	{
		ServerPlayer*	pPlayer = GetServerPlayer(i);
		if(!pPlayer) continue;

		if(pPlayer->IsValid())
		{
			SOCKET s = pPlayer->GetSocket()->getSOCKET();
			if(FD_ISSET( s, &m_ExceptFDs[SELECT_USE]) )
			{
				g_pLog->log_debug("%u,%u,ProcessException......",pPlayer->PlayerID(),0);
				RemoveServer(i);
			}
		}
	}

	return true;
}
void CustomServerNetworkHandler::onDisconnect(ServerNetworkHandler *real, const RakNet::RakNetGUID &guid, const std::string &message)
{
	for (SMPlayer *player : ServerManager::getOnlinePlayers())
	{
		if (player->getHandle()->guid == guid)
		{
			real->level->getLevelStorage()->save(*player->getHandle());

			PlayerQuitEvent quitEvent(player, "§e%multiplayer.player.left", { player->getName() });
			ServerManager::getPluginManager()->callEvent(quitEvent);

			TextPacket pk;
			pk.type = TextPacket::TYPE_TRANSLATION;
			pk.message = quitEvent.getQuitMessage();
			pk.params = quitEvent.getQuitParams();
			real->sender->send(pk);

			ServerManager::getServer()->removePlayer(player);

			ServerPlayer *serverPlayer = (ServerPlayer *)player->getHandle();
			serverPlayer->disconnect();
			serverPlayer->remove();

			real->raknet->announceServer(ServerManager::getServerName());
			break;
		}
	}
}
Exemplo n.º 14
0
// 给该玩家发送某好友下线的信息
VOID USER::SendRelationOfflineMsg(USER* pUser)
{
__ENTER_FUNCTION

    Assert( pUser );

    if( UserStatus() != US_NORMAL )
    {
        return;
    }

    ServerPlayer* pServerPlayer = g_pServerManager->GetServerPlayer( GetServerID() );
    if( pServerPlayer == NULL )
    {
        Assert( pServerPlayer );
        return;
    }

    WGRelation Msg;

    WG_RELATION* pRelation = Msg.GetRelation();

    pRelation->SetPlayerID( GetPlayerID() );
    pRelation->m_Type = RET_RELATIONOFFLINE;
    pRelation->m_RelationGUID.SetTargetGUID( pUser->GetGUID() );

    pServerPlayer->SendPacket( &Msg );

__LEAVE_FUNCTION
}
Exemplo n.º 15
0
void LeijiCard::onEffect(const CardEffectStruct &effect) const{
    ServerPlayer *zhangjiao = effect.from;
    ServerPlayer *target = effect.to;

    Room *room = zhangjiao->getRoom();
    room->setEmotion(target, "bad");

    JudgeStruct judge;
    judge.pattern = QRegExp("(.*):(spade):(.*)");
    judge.good = false;
    judge.reason = "leiji";
    judge.who = target;

    room->judge(judge);

    if(judge.isBad()){
        DamageStruct damage;
        damage.card = NULL;
        damage.damage = 2;
        damage.from = zhangjiao;
        damage.to = target;
        damage.nature = DamageStruct::Thunder;

        room->damage(damage);
    }else
        room->setEmotion(zhangjiao, "bad");
}
UINT GWCityCloseSuccessHandler::Execute( GWCityCloseSuccess* pPacket, Player* pPlayer )
{
    __ENTER_FUNCTION

        ServerPlayer* pServerPlayer = (ServerPlayer*)pPlayer;
        _CITY_GUID    CityGuid = pPacket->GetCityGuid();

        City* pDelCity = g_pCityManager->GetCityByGuid(CityGuid);
        if(!pDelCity->IsLock())
        {//已经有人在删除此城市了
            Assert(FALSE);
            return PACKET_EXE_CONTINUE ;
        }

        SceneID_t CitySceneID = pDelCity->GetSceneID();

        GUID_t PlayerGuid = pDelCity->GetApplicantGuid();
        g_pCityManager->DelCityByGuid(CityGuid);

        WGCityCloseSuccess MsgToServer;
        MsgToServer.SetPlayerGuid(PlayerGuid);
        MsgToServer.SetSceneID(CitySceneID);
        pServerPlayer->SendPacket(&MsgToServer);
        
        return PACKET_EXE_CONTINUE ;

    __LEAVE_FUNCTION

        return PACKET_EXE_ERROR ;
}
Exemplo n.º 17
0
void HuangtianCard::use(Room *room, ServerPlayer *, const QList<ServerPlayer *> &targets) const{
    ServerPlayer *zhangjiao = targets.first();
    if(zhangjiao->hasSkill("huangtian")){
        zhangjiao->obtainCard(this);
        room->setEmotion(zhangjiao, "good");
    }
}
Exemplo n.º 18
0
void QuhuCard::use(Room *room, ServerPlayer *xunyu, const QList<ServerPlayer *> &targets) const{
    ServerPlayer *tiger = targets.first();

    room->playSkillEffect("quhu", 1);

    bool success = xunyu->pindian(tiger, this);
    if(success){
        room->playSkillEffect("quhu", 2);

        QList<ServerPlayer *> players = room->getOtherPlayers(tiger), wolves;
        foreach(ServerPlayer *player, players){
            if(tiger->inMyAttackRange(player))
                wolves << player;
        }

        if(wolves.isEmpty())
            return;

        room->playSkillEffect("#tunlang");
        ServerPlayer *wolf = room->askForPlayerChosen(xunyu, wolves, "quhu");

        DamageStruct damage;
        damage.from = tiger;
        damage.to = wolf;

        room->damage(damage);        

    }else{
Exemplo n.º 19
0
UINT GWCallOfHumanHandler::Execute( GWCallOfHuman* pPacket, Player* pPlayer )
{
__ENTER_FUNCTION

    USER* pUser = g_pOnlineUser->FindUser( pPacket->GetCallOfTargetGUID() ) ;
    if( pUser==NULL )
    {
        Assert(FALSE) ;
        return PACKET_EXE_CONTINUE ;
    }

    ID_t ServerID = pUser->GetServerID() ;
    ServerPlayer* pServerPlayer = g_pServerManager->GetServerPlayer( ServerID ) ;
    if( pServerPlayer==NULL )
    {
        Assert(FALSE) ;
        return PACKET_EXE_CONTINUE ;
    }

    WGCallOfHuman msgCallOfHuman;
    msgCallOfHuman.SetCallOfTargetPlayerID(pUser->GetPlayerID());
    msgCallOfHuman.SetCallOfInfo(pPacket->GetCallOfInfo());
    msgCallOfHuman.SetGUID(pPacket->GetCallOfTargetGUID());
    pServerPlayer->SendPacket(&msgCallOfHuman);

    Log::SaveLog( WORLD_LOGFILE, "GWCallOfHumanHandler" );

    return PACKET_EXE_CONTINUE ;

__LEAVE_FUNCTION

    return PACKET_EXE_ERROR ;
}
Exemplo n.º 20
0
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);
}
Exemplo n.º 21
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;
        }

        if(clubs.isEmpty())
            return false;

        ServerPlayer *caozhi = room->findPlayerBySkillName(objectName());
        if(caozhi && caozhi->askForSkillInvoke(objectName(), data)){
            foreach(const Card *club, clubs)
                caozhi->obtainCard(club);
        }
Exemplo n.º 22
0
    virtual bool onPhaseChange(ServerPlayer *zhangliang) const{
        Room *room = zhangliang->getRoom();

        if(zhangliang->getPhase() != Player::Draw)
            return false;

        QList<ServerPlayer *> players = room->getOtherPlayers(zhangliang);
        foreach(ServerPlayer *p, players){
            if(p->isKongcheng())
                players.removeOne(p);
        }

        if(players.isEmpty() || !zhangliang->askForSkillInvoke(objectName()))
            return false;

        room->playSkillEffect(objectName());

        ServerPlayer *rengonger = room->askForPlayerChosen(zhangliang, players, objectName());
        QList<int> handcards = rengonger->handCards();

        room->fillAG(handcards, zhangliang);
        int card_id = room->askForAG(zhangliang, handcards, false, objectName());
        room->moveCardTo(Sanguosha->getCard(card_id), zhangliang, Player::Hand, false);
        room->broadcastInvoke("clearAG");

        return true;
    }
Exemplo n.º 23
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);
                }
            }
    bool trigger(TriggerEvent triggerEvent, Room *room, ServerPlayer *player, QVariant &data) const
    {
        if (triggerEvent == TurnStart) {
            room->setPlayerMark(player, "@hengjiang", 0);
        } else if (triggerEvent == CardsMoveOneTime) {
            CardsMoveOneTimeStruct move = data.value<CardsMoveOneTimeStruct>();
            if (move.from && player == move.from && player->getPhase() == Player::Discard
                && (move.reason.m_reason & CardMoveReason::S_MASK_BASIC_REASON) == CardMoveReason::S_REASON_DISCARD)
                player->setFlags("HengjiangDiscarded");
        } else if (triggerEvent == EventPhaseChanging) {
            PhaseChangeStruct change = data.value<PhaseChangeStruct>();
            if (change.to != Player::NotActive) return false;
            ServerPlayer *zangba = room->findPlayerBySkillName("hengjiang");
            if (!zangba) return false;
            if (player->getMark("@hengjiang") > 0) {
                bool invoke = false;
                if (!player->hasFlag("HengjiangDiscarded")) {
                    LogMessage log;
                    log.type = "#HengjiangDraw";
                    log.from = player;
                    log.to << zangba;
                    log.arg = "hengjiang";
                    room->sendLog(log);

                    invoke = true;
                }
                player->setFlags("-HengjiangDiscarded");
                room->setPlayerMark(player, "@hengjiang", 0);
                if (invoke) zangba->drawCards(1, objectName());
            }
        }
        return false;
    }
Exemplo n.º 25
0
    virtual bool trigger(TriggerEvent , ServerPlayer *player, QVariant &data) const{
        if(player->isNude())
            return false;

        Room *room = player->getRoom();
        ServerPlayer *caopi = room->findPlayerBySkillName(objectName());
        if(caopi && caopi->isAlive() && room->askForSkillInvoke(caopi, objectName(), data)){
            if(player->isCaoCao()){
                room->playSkillEffect(objectName(), 3);
            }else if(player->getGeneral()->isMale())
                room->playSkillEffect(objectName(), 1);
            else
                room->playSkillEffect(objectName(), 2);

            caopi->obtainCard(player->getWeapon());
            caopi->obtainCard(player->getArmor());
            caopi->obtainCard(player->getDefensiveHorse());
            caopi->obtainCard(player->getOffensiveHorse());

            DummyCard *all_cards = player->wholeHandCards();
            if(all_cards){
                room->moveCardTo(all_cards, caopi, Player::Hand, false);
                delete all_cards;
            }
        }

        return false;
    }
Exemplo n.º 26
0
UINT LWAskDeleteCharHandler::Execute(LWAskDeleteChar* pPacket, Player* pPlayer )
{
	__ENTER_FUNCTION
	
	Assert(pPacket);
	
	ServerPlayer* pServerPlayer = (ServerPlayer*)pPlayer ;
	Assert(pServerPlayer);

	WLRetDeleteChar Msg;
	Msg.SetAccount( pPacket->GetAccount() );
	Msg.SetPlayerGUID( pPacket->GetPlayerGUID() );
	Msg.SetPlayerID( pPacket->GetPlayerID() );

	USER* pUser = g_pOnlineUser->FindUser( pPacket->GetPlayerGUID() );
	if( pUser )
	{
		Msg.SetResult( ASKDELETECHAR_ONLINE );
		Log::SaveLog( WORLD_LOGFILE, "LWAskDeleteCharHandler...Cannot Delete User, CharGUID = %X",pPacket->GetPlayerGUID()) ;
	}
	else
	{
		Msg.SetResult( ASKDELETECHAR_SUCCESS );
		Log::SaveLog( WORLD_LOGFILE, "LWAskDeleteCharHandler...Can Delete User, CharGUID = %X",pPacket->GetPlayerGUID()) ;
	}

	pServerPlayer->SendPacket(&Msg);


	return PACKET_EXE_CONTINUE;

	__LEAVE_FUNCTION

	return PACKET_EXE_ERROR;
}
Exemplo n.º 27
0
    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;
    }
Exemplo n.º 28
0
    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);
            }
        }
    }
Exemplo n.º 29
0
QString TrustAI::askForKingdom() {
    QString role;
    ServerPlayer *lord = room->getLord();
    QStringList kingdoms = Sanguosha->getKingdoms();
    kingdoms.removeOne("god");
    if (!lord) return kingdoms.at(qrand() % kingdoms.length());

    switch(self->getRoleEnum()) {
    case Player::Lord: role = kingdoms.at(qrand() % kingdoms.length()); break;
    case Player::Renegade:
    case Player::Rebel: {
            if ((lord->hasLordSkill("xueyi") && self->getRoleEnum() == Player::Rebel) || lord->hasLordSkill("shichou"))
                role = "wei";
            else
                role = lord->getKingdom();
            break;
    }
    case Player::Loyalist: {
            if (lord->getGeneral()->isLord())
                role = lord->getKingdom();
            else if (lord->getGeneral2() && lord->getGeneral2()->isLord())
                role = lord->getGeneral2()->getKingdom();
            else {
                if (lord->hasSkill("yongsi")) kingdoms.removeOne(lord->getKingdom());
                role = kingdoms.at(qrand() % kingdoms.length());
            }
            break;
        }
    default:
            break;
    }

    return role;
}
Exemplo n.º 30
0
UINT CLAskLoginHandler::Execute( CLAskLogin* pPacket, Player* pPlayer)
{
	printf("#CLAskLoginHandler-------------account:%s,password:%s,version:%u",pPacket->GetAccount(),pPacket->GetPassWord(),pPacket->GetVersion());

	GatewayPlayer* pGatewayPlayer = static_cast<GatewayPlayer*>(pPlayer);
	Assert(pGatewayPlayer);

	/*if(pGatewayPlayer->GetPlayerStatus() != PS_LOGIN_STATUS)
	{
		return PACKET_EXE_ERROR;
	}
	*/

	ServerPlayer*	pServerPlayer = g_pServerManager->GetServerPlayer(SCENE_PLAYER_ID);
	if(pServerPlayer==NULL)
	{
		Assert(false);
		return PACKET_EXE_CONTINUE;
	}

	imxGSConnect msg;
	msg.SetAccount(pPacket->GetAccount());
	msg.SetPlayerID(pPlayer->PlayerID());
	pServerPlayer->SendPacket(&msg);

	/*LCRetLogin msg1;
	msg1.SetAccount(pPacket->GetAccount());
	msg1.SetResult(LOGINR_SUCCESS);
	pGatewayPlayer->SendPacket(&msg1);*/

	return PACKET_EXE_CONTINUE;
}