Ejemplo n.º 1
0
void WorldSession::_HandleAreaTriggerOpcode(uint32 id)
{
	LOG_DEBUG("AreaTrigger: %u", id);

	// Are we REALLY here?
	if(!_player->IsInWorld())
		return;

	// Search quest log, find any exploration quests
	sQuestMgr.OnPlayerExploreArea(GetPlayer(), id);

	AreaTriggerEntry* entry = dbcAreaTrigger.LookupEntryForced(id);
	AreaTrigger* pAreaTrigger = AreaTriggerStorage.LookupEntry(id);

	if(entry == NULL)
	{
		LOG_DEBUG("Missing AreaTrigger: %u", id);
		return;
	}

	Player* pPlayer = GetPlayer();
	sHookInterface.OnAreaTrigger(pPlayer, id);
	CALL_INSTANCE_SCRIPT_EVENT(pPlayer->GetMapMgr(), OnAreaTrigger)(GetPlayer(), id);

#ifdef GM_Z_DEBUG_DIRECTLY
	if(_player->GetSession() && _player->GetSession()->CanUseCommand('z'))
		sChatHandler.BlueSystemMessage(this, "[%sSystem%s] |rEntered areatrigger: %s%u. (%s)", MSG_COLOR_WHITE, MSG_COLOR_LIGHTBLUE, MSG_COLOR_SUBWHITE, id, pAreaTrigger ? pAreaTrigger->Name : "Unknown name");
#endif

	// if in BG handle is triggers
	if(_player->m_bg)
	{
		_player->m_bg->HookOnAreaTrigger(_player, id);
		return;
	}

	if(pAreaTrigger == NULL) return;

	switch(pAreaTrigger->Type)
	{
		case ATTYPE_INSTANCE:
			{
				//only ports if player is out of pendings
				if(GetPlayer()->GetPlayerStatus() == TRANSFER_PENDING)
					break;
				if(sWorld.instance_CheckTriggerPrerequisites)
				{
					uint32 reason = CheckTriggerPrerequisites(pAreaTrigger, this, _player, WorldMapInfoStorage.LookupEntry(pAreaTrigger->Mapid));
					if(reason != AREA_TRIGGER_FAILURE_OK)
					{
						const char* pReason = GetPlayer()->GetSession()->LocalizedWorldSrv(AreaTriggerFailureMessages[reason]);
						char msg[200];
						WorldPacket data(SMSG_AREA_TRIGGER_MESSAGE, 50);
						data << uint32(0);

						switch(reason)
						{
							case AREA_TRIGGER_FAILURE_LEVEL:
								snprintf(msg, 200, pReason, pAreaTrigger->required_level);
								data << msg;
								break;
							case AREA_TRIGGER_FAILURE_NO_ATTUNE_I:
								{
									MapInfo* pMi = WorldMapInfoStorage.LookupEntry(pAreaTrigger->Mapid);
									ItemPrototype* pItem = ItemPrototypeStorage.LookupEntry(pMi->required_item);
									if(pItem)
										snprintf(msg, 200, GetPlayer()->GetSession()->LocalizedWorldSrv(35), pItem->Name1);
									else
										snprintf(msg, 200, "%s", GetPlayer()->GetSession()->LocalizedWorldSrv(36));

									data << msg;
								}
								break;
							case AREA_TRIGGER_FAILURE_NO_ATTUNE_Q:
								{
									MapInfo* pMi = WorldMapInfoStorage.LookupEntry(pAreaTrigger->Mapid);
									Quest* pQuest = NULL;

									if( pPlayer->GetTeam() == TEAM_ALLIANCE )
										pQuest = QuestStorage.LookupEntry(pMi->required_quest_1 );
									else
										pQuest = QuestStorage.LookupEntry(pMi->required_quest_2 );

									if(pQuest)
										snprintf(msg, 200, "You must have finished the quest '%s' to pass through here.", pQuest->title);
									else
										snprintf(msg, 200, "You must have finished the quest '%s' to pass through here.", "UNKNOWN" );

									data << msg;
								}
								break;
							case AREA_TRIGGER_FAILURE_NO_KEY:
								{
									MapInfo* pMi = WorldMapInfoStorage.LookupEntry(pAreaTrigger->Mapid);
									ItemPrototype* pItem = ItemPrototypeStorage.LookupEntry(pMi->heroic_key_1);
									if(pItem)
										snprintf(msg, 200, "You must have the item, `%s` to pass through here.", pItem->Name1);
									else
										snprintf(msg, 200, "You must have the item, UNKNOWN to pass through here.");

									data << msg;
								}
								break;
							case AREA_TRIGGER_FAILURE_LEVEL_HEROIC:
								{
									MapInfo* pMi = WorldMapInfoStorage.LookupEntry(pAreaTrigger->Mapid);
									snprintf(msg, 200, pReason, pMi->minlevel_heroic);
									data << msg;
								}
								break;
							default:
								data << pReason;
								break;
						}

						data << uint8(0);
						SendPacket(&data);
						return;
					}
				}
				GetPlayer()->SaveEntryPoint(pAreaTrigger->Mapid);
				GetPlayer()->SafeTeleport(pAreaTrigger->Mapid, 0, LocationVector(pAreaTrigger->x, pAreaTrigger->y, pAreaTrigger->z, pAreaTrigger->o));
			}
			break;
		case ATTYPE_QUESTTRIGGER:
			{

			} break;
		case ATTYPE_INN:
			{
				// Inn
				if(!GetPlayer()->m_isResting) GetPlayer()->ApplyPlayerRestState(true);
			}
			break;
		case ATTYPE_TELEPORT:
			{
				if(GetPlayer()->GetPlayerStatus() != TRANSFER_PENDING) //only ports if player is out of pendings
				{
					GetPlayer()->SaveEntryPoint(pAreaTrigger->Mapid);
					GetPlayer()->SafeTeleport(pAreaTrigger->Mapid, 0, LocationVector(pAreaTrigger->x, pAreaTrigger->y, pAreaTrigger->z, pAreaTrigger->o));
				}
			}
			break;
		default:
			break;
	}
}
Ejemplo n.º 2
0
void WorldSession::_HandleAreaTriggerOpcode(uint32 id)
{
    LOG_DEBUG("AreaTrigger: %u", id);

    if (!_player->IsInWorld())
        return;

    // Search quest log, find any exploration quests
    sQuestMgr.OnPlayerExploreArea(GetPlayer(), id);

    auto area_trigger_entry = sAreaTriggerStore.LookupEntry(id);
    if (area_trigger_entry == nullptr)
    {
        LOG_DEBUG("Missing AreaTrigger: %u", id);
        return;
    }

    Player* pPlayer = GetPlayer();
    sHookInterface.OnAreaTrigger(pPlayer, id);
    CALL_INSTANCE_SCRIPT_EVENT(pPlayer->GetMapMgr(), OnAreaTrigger)(GetPlayer(), id);

#ifdef GM_Z_DEBUG_DIRECTLY
    if (_player->GetSession() && _player->GetSession()->CanUseCommand('z'))
        sChatHandler.BlueSystemMessage(this, "[%sSystem%s] |rEntered areatrigger: %s%u. (%s)", MSG_COLOR_WHITE, MSG_COLOR_LIGHTBLUE, MSG_COLOR_SUBWHITE, id, pAreaTrigger ? pAreaTrigger->Name : "Unknown name");
#endif

    // if in BG handle is triggers
    if (_player->m_bg)
    {
        _player->m_bg->HookOnAreaTrigger(_player, id);
        return;
    }

    MySQLStructure::AreaTrigger const* pAreaTrigger = sMySQLStore.getAreaTrigger(id);
    if (pAreaTrigger == nullptr)
        return;

    switch (pAreaTrigger->type)
    {
        case ATTYPE_INSTANCE:
        {
            //only ports if player is out of pendings
            if (GetPlayer()->GetPlayerStatus() == TRANSFER_PENDING)
                break;
            if (worldConfig.instance.checkTriggerPrerequisitesOnEnter)
            {
                uint32 reason = CheckTriggerPrerequisites(pAreaTrigger, this, _player, sMySQLStore.getWorldMapInfo(pAreaTrigger->mapId));
                if (reason != AREA_TRIGGER_FAILURE_OK)
                {
                    const char* pReason = GetPlayer()->GetSession()->LocalizedWorldSrv(AreaTriggerFailureMessages[reason]);
                    char msg[200];
                    WorldPacket data(SMSG_AREA_TRIGGER_MESSAGE, 50);
                    data << uint32(0);

                    switch (reason)
                    {
                        case AREA_TRIGGER_FAILURE_LEVEL:
                            snprintf(msg, 200, pReason, pAreaTrigger->requiredLevel);
                            data << msg;
                            break;
                        case AREA_TRIGGER_FAILURE_NO_ATTUNE_I:
                        {
                            MySQLStructure::MapInfo const* pMi = sMySQLStore.getWorldMapInfo(pAreaTrigger->mapId);
                            ItemProperties const* pItem = sMySQLStore.getItemProperties(pMi->required_item);
                            if (pItem)
                                snprintf(msg, 200, GetPlayer()->GetSession()->LocalizedWorldSrv(ServerString::SS_MUST_HAVE_ITEM), pItem->Name.c_str());
                            else
                                snprintf(msg, 200, "%s", GetPlayer()->GetSession()->LocalizedWorldSrv(36));

                            data << msg;
                        }
                        break;
                        case AREA_TRIGGER_FAILURE_NO_ATTUNE_QA:
                        {
                            MySQLStructure::MapInfo const* pMi = sMySQLStore.getWorldMapInfo(pAreaTrigger->mapId);
                            QuestProperties const* pQuest = sMySQLStore.getQuestProperties(pMi->required_quest_A);
                            if (pQuest)
                                snprintf(msg, 200, GetPlayer()->GetSession()->LocalizedWorldSrv(ServerString::SS_MUST_HAVE_QUEST), pQuest->title.c_str());
                            else
                                snprintf(msg, 200, "%s", GetPlayer()->GetSession()->LocalizedWorldSrv(36));

                            data << msg;
                        }
                        break;
                        case AREA_TRIGGER_FAILURE_NO_ATTUNE_QH:
                        {
                            MySQLStructure::MapInfo const* pMi = sMySQLStore.getWorldMapInfo(pAreaTrigger->mapId);
                            QuestProperties const* pQuest = sMySQLStore.getQuestProperties(pMi->required_quest_H);
                            if (pQuest)
                                snprintf(msg, 200, GetPlayer()->GetSession()->LocalizedWorldSrv(ServerString::SS_MUST_HAVE_QUEST), pQuest->title.c_str());
                            else
                                snprintf(msg, 200, "%s", GetPlayer()->GetSession()->LocalizedWorldSrv(36));

                            data << msg;
                        }
                        break;
                        case AREA_TRIGGER_FAILURE_NO_KEY:
                        {
                            MySQLStructure::MapInfo const* pMi = sMySQLStore.getWorldMapInfo(pAreaTrigger->mapId);
                            ItemProperties const* pItem = sMySQLStore.getItemProperties(pMi->heroic_key_1);
                            if (pItem)
                                snprintf(msg, 200, GetPlayer()->GetSession()->LocalizedWorldSrv(ServerString::SS_MUST_HAVE_ITEM), pItem->Name.c_str());
                            else
                                snprintf(msg, 200, "%s", GetPlayer()->GetSession()->LocalizedWorldSrv(36));

                            data << msg;
                        }
                        break;
                        case AREA_TRIGGER_FAILURE_LEVEL_HEROIC:
                        {
                            MySQLStructure::MapInfo const* pMi = sMySQLStore.getWorldMapInfo(pAreaTrigger->mapId);
                            snprintf(msg, 200, pReason, pMi->minlevel_heroic);
                            data << msg;
                        }
                        break;
                        default:
                            data << pReason;
                            break;
                    }

                    data << uint8(0);
                    SendPacket(&data);
                    return;
                }
            }
            GetPlayer()->SaveEntryPoint(pAreaTrigger->mapId);
            GetPlayer()->SafeTeleport(pAreaTrigger->mapId, 0, LocationVector(pAreaTrigger->x, pAreaTrigger->y, pAreaTrigger->z, pAreaTrigger->o));
        }
        break;
        case ATTYPE_QUESTTRIGGER:
        {

        } break;
        case ATTYPE_INN:
        {
            // Inn
            if (!GetPlayer()->m_isResting) GetPlayer()->ApplyPlayerRestState(true);
        }
        break;
        case ATTYPE_TELEPORT:
        {
            if (GetPlayer()->GetPlayerStatus() != TRANSFER_PENDING) //only ports if player is out of pendings
            {
                GetPlayer()->SaveEntryPoint(pAreaTrigger->mapId);
                GetPlayer()->SafeTeleport(pAreaTrigger->mapId, 0, LocationVector(pAreaTrigger->x, pAreaTrigger->y, pAreaTrigger->z, pAreaTrigger->o));
            }
        }
        break;
        default:
            break;
    }
}