/* - return the right instance for the object, based on its InstanceId - create the instance if it's not created already - the player is not actually added to the instance (only in InstanceMap::Add) */ Map* MapInstanced::CreateInstance(const uint32 mapId, Player* player) { if (GetId() != mapId || !player) return NULL; Map* map = NULL; uint32 NewInstanceId = 0; // instanceId of the resulting map if (IsBattlegroundOrArena()) { // instantiate or find existing bg map for player // the instance id is set in battlegroundid NewInstanceId = player->GetBattlegroundId(); if (!NewInstanceId) return NULL; map = _FindMap(NewInstanceId); if (!map) if (Battleground* NewBattleground = player->GetBattleground()) map = CreateBattleground(NewInstanceId, NewBattleground); } else { InstancePlayerBind* pBind = player->GetBoundInstance(GetId(), player->GetDifficulty(IsRaid())); InstanceSave* pSave = pBind ? pBind->save : NULL; // the player's permanent player bind is taken into consideration first // then the player's group bind and finally the solo bind. if (!pBind || !pBind->perm) { InstanceGroupBind* groupBind = NULL; Group* group = player->GetGroup(); // use the player's difficulty setting (it may not be the same as the group's) if (group) { groupBind = group->GetBoundInstance(this); if (groupBind) pSave = groupBind->save; } } if (pSave) { // solo/perm/group NewInstanceId = pSave->GetInstanceId(); map = _FindMap(NewInstanceId); // it is possible that the save exists but the map doesn't if (!map) map = CreateInstance(NewInstanceId, pSave, pSave->GetDifficulty()); } else { // if no instanceId via group members or instance saves is found // the instance will be created for the first time NewInstanceId = sMapMgr->GenerateInstanceId(); Difficulty diff = player->GetGroup() ? player->GetGroup()->GetDifficulty(IsRaid()) : player->GetDifficulty(IsRaid()); map = CreateInstance(NewInstanceId, NULL, diff); } } return map; }
void WorldSession::HandleCalendarGetCalendar(WorldPacket &recv_data) { sLog.outDebug("WORLD: CMSG_CALENDAR_GET_CALENDAR"); recv_data.hexlike(); time_t cur_time = time(NULL); WorldPacket data(SMSG_CALENDAR_SEND_CALENDAR,4+4*0+4+4*0+4+4); // TODO: calendar invite event output data << (uint32) 0; //invite node count // TODO: calendar event output data << (uint32) 0; //event count data << (uint32) 0; //wtf?? data << (uint32) secsToTimeBitFields(cur_time); // current time uint32 counter = 0; size_t p_counter = data.wpos(); data << uint32(counter); // instance save count for(int i = 0; i < TOTAL_DIFFICULTIES; ++i) { for (Player::BoundInstancesMap::const_iterator itr = _player->m_boundInstances[i].begin(); itr != _player->m_boundInstances[i].end(); ++itr) { if(itr->second.perm) { InstanceSave *save = itr->second.save; data << uint32(save->GetMapId()); data << uint32(save->GetDifficulty()); data << uint32(save->GetResetTime() - cur_time); data << uint64(save->GetInstanceId()); // instance save id as unique instance copy id ++counter; } } } data.put<uint32>(p_counter,counter); data << (uint32) 1135753200; //wtf?? (28.12.2005 12:00) data << (uint32) 0; // unk counter 4 data << (uint32) 0; // unk counter 5 //sLog.outDebug("Sending calendar"); //data.hexlike(); SendPacket(&data); }
static bool HandleInstanceListBindsCommand(ChatHandler* handler, char const* /*args*/) { Player* player = handler->getSelectedPlayer(); if (!player) player = handler->GetSession()->GetPlayer(); uint32 counter = 0; for (uint8 i = 0; i < MAX_DIFFICULTY; ++i) { Player::BoundInstancesMap &binds = player->GetBoundInstances(Difficulty(i)); for (Player::BoundInstancesMap::const_iterator itr = binds.begin(); itr != binds.end(); ++itr) { InstanceSave* save = itr->second.save; std::string timeleft = GetTimeString(save->GetResetTime() - time(NULL)); handler->PSendSysMessage(LANG_COMMAND_LIST_BIND_INFO, itr->first, save->GetInstanceId(), itr->second.perm ? "yes" : "no", save->GetDifficultyID(), save->CanReset() ? "yes" : "no", timeleft.c_str()); counter++; } } handler->PSendSysMessage(LANG_COMMAND_LIST_BIND_PLAYER_BINDS, counter); counter = 0; if (Group* group = player->GetGroup()) { for (uint8 i = 0; i < MAX_DIFFICULTY; ++i) { Group::BoundInstancesMap &binds = group->GetBoundInstances(Difficulty(i)); for (Group::BoundInstancesMap::const_iterator itr = binds.begin(); itr != binds.end(); ++itr) { InstanceSave* save = itr->second.save; std::string timeleft = GetTimeString(save->GetResetTime() - time(NULL)); handler->PSendSysMessage(LANG_COMMAND_LIST_BIND_INFO, itr->first, save->GetInstanceId(), itr->second.perm ? "yes" : "no", save->GetDifficultyID(), save->CanReset() ? "yes" : "no", timeleft.c_str()); counter++; } } } handler->PSendSysMessage(LANG_COMMAND_LIST_BIND_GROUP_BINDS, counter); return true; }
static bool HandleInstanceListBindsCommand(ChatHandler* handler, char const* /*args*/) { Player* player = handler->getSelectedPlayer(); if (!player) player = handler->GetSession()->GetPlayer(); uint32 counter = 0; for (uint8 i = 0; i < 15; ++i) { Player::BoundInstancesMap &binds = player->GetBoundInstances(DifficultyID(i)); for (Player::BoundInstancesMap::const_iterator itr = binds.begin(); itr != binds.end(); ++itr) { InstanceSave* save = itr->second.save; std::string timeleft = GetTimeString(save->GetResetTime() - time(NULL)); handler->PSendSysMessage("map: %d inst: %d perm: %s diff: %d canReset: %s TTR: %s", itr->first, save->GetInstanceId(), itr->second.perm ? "yes" : "no", save->GetDifficulty(), save->CanReset() ? "yes" : "no", timeleft.c_str()); counter++; } } handler->PSendSysMessage("player binds: %d", counter); counter = 0; if (Group* group = player->GetGroup()) { for (uint8 i = 0; i < 15; ++i) { Group::BoundInstancesMap &binds = group->GetBoundInstances(DifficultyID(i)); for (Group::BoundInstancesMap::const_iterator itr = binds.begin(); itr != binds.end(); ++itr) { InstanceSave* save = itr->second.save; std::string timeleft = GetTimeString(save->GetResetTime() - time(NULL)); handler->PSendSysMessage("map: %d inst: %d perm: %s diff: %d canReset: %s TTR: %s", itr->first, save->GetInstanceId(), itr->second.perm ? "yes" : "no", save->GetDifficulty(), save->CanReset() ? "yes" : "no", timeleft.c_str()); counter++; } } } handler->PSendSysMessage("group binds: %d", counter); return true; }
static bool HandleInstanceUnbindCommand(ChatHandler* handler, char const* args) { if (!*args) return false; Player* player = handler->getSelectedPlayer(); if (!player) player = handler->GetSession()->GetPlayer(); char* map = strtok((char*)args, " "); char* pDiff = strtok(NULL, " "); int8 diff = -1; if (pDiff) diff = atoi(pDiff); uint16 counter = 0; uint16 MapId = 0; if (strcmp(map, "all")) { MapId = uint16(atoi(map)); if (!MapId) return false; } for (uint8 i = 0; i < 15; ++i) { Player::BoundInstancesMap &binds = player->GetBoundInstances(DifficultyID(i)); for (Player::BoundInstancesMap::iterator itr = binds.begin(); itr != binds.end();) { InstanceSave* save = itr->second.save; if (itr->first != player->GetMapId() && (!MapId || MapId == itr->first) && (diff == -1 || diff == save->GetDifficulty())) { std::string timeleft = GetTimeString(save->GetResetTime() - time(NULL)); handler->PSendSysMessage("unbinding map: %d inst: %d perm: %s diff: %d canReset: %s TTR: %s", itr->first, save->GetInstanceId(), itr->second.perm ? "yes" : "no", save->GetDifficulty(), save->CanReset() ? "yes" : "no", timeleft.c_str()); player->UnbindInstance(itr, DifficultyID(i)); counter++; } else ++itr; } } handler->PSendSysMessage("instances unbound: %d", counter); return true; }
void WorldSession::HandleCalendarGetCalendar(WorldPacket & /*recv_data*/) { sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: CMSG_CALENDAR_GET_CALENDAR"); // empty time_t cur_time = time(NULL); WorldPacket data(SMSG_CALENDAR_SEND_CALENDAR, 4+4*0+4+4*0+4+4); data << uint32(0); // invite count /* for (;;) { uint64 inviteId; uint64 unkGuid0; uint8 unk1, unk2, unk3; uint64 creatorGuid; } */ data << uint32(0); // event count /* for (;;) { uint64 eventId; std::string title; // 128 chars uint32 type; uint32 occurrenceTime; uint32 flags; uint32 unk4; -- possibly mapid for dungeon/raid uint64 creatorGuid; } */ data << uint32(0); // unk data << uint32(secsToTimeBitFields(cur_time)); // current time uint32 counter = 0; size_t p_counter = data.wpos(); data << uint32(counter); // instance save count for (int i = 0; i < MAX_DIFFICULTY; ++i) { for (Player::BoundInstancesMap::const_iterator itr = _player->m_boundInstances[i].begin(); itr != _player->m_boundInstances[i].end(); ++itr) { if (itr->second.perm) { InstanceSave *save = itr->second.save; data << uint32(save->GetMapId()); data << uint32(save->GetDifficulty()); data << uint32(save->GetResetTime() - cur_time); data << uint64(save->GetInstanceId()); // instance save id as unique instance copy id ++counter; } } } data.put<uint32>(p_counter, counter); data << uint32(1135753200); // unk (28.12.2005 12:00) counter = 0; p_counter = data.wpos(); data << uint32(counter); // raid reset count ResetTimeByMapDifficultyMap const& resets = sInstanceSaveMgr->GetResetTimeMap(); for (ResetTimeByMapDifficultyMap::const_iterator itr = resets.begin(); itr != resets.end(); ++itr) { uint32 mapid = PAIR32_LOPART(itr->first); MapEntry const* mapEnt = sMapStore.LookupEntry(mapid); if (!mapEnt || !mapEnt->IsRaid()) continue; data << uint32(mapid); data << uint32(itr->second - cur_time); data << uint32(mapEnt->unk_time); ++counter; } data.put<uint32>(p_counter, counter); data << uint32(0); // holiday count? /* for (;;) { uint32 unk5, unk6, unk7, unk8, unk9; for (uint32 j = 0; j < 26; ++j) { uint32 unk10; } for (uint32 j = 0; j < 10; ++j) { uint32 unk11; } for (uint32 j = 0; j < 10; ++j) { uint32 unk12; } std::string holidayName; // 64 chars } */ sLog->outDebug(LOG_FILTER_NETWORKIO, "Sending calendar"); data.hexlike(); SendPacket(&data); }
/* - return the right instance for the object, based on its InstanceId - create the instance if it's not created already - the player is not actually added to the instance (only in InstanceMap::Add) */ Map* MapInstanced::CreateInstanceForPlayer(const uint32 mapId, Player* player, uint32 loginInstanceId) { if (GetId() != mapId || !player) return nullptr; Map* map = nullptr; uint32 newInstanceId = 0; // instanceId of the resulting map if (IsBattlegroundOrArena()) { // instantiate or find existing bg map for player // the instance id is set in battlegroundid newInstanceId = player->GetBattlegroundId(); if (!newInstanceId) return nullptr; map = sMapMgr->FindMap(mapId, newInstanceId); if (!map) { if (Battleground* bg = player->GetBattleground()) map = CreateBattleground(newInstanceId, bg); else { player->TeleportToBGEntryPoint(); return nullptr; } } } else { InstancePlayerBind* pBind = player->GetBoundInstance(GetId(), player->GetDifficulty(IsRaid())); InstanceSave* pSave = pBind ? pBind->save : nullptr; // priority: // 1. player's permanent bind // 2. player's current instance id if this is at login // 3. group's current bind // 4. player's current bind if (!pBind || !pBind->perm) { if (loginInstanceId) // if the player has a saved instance id on login, we either use this instance or relocate him out (return null) { map = FindInstanceMap(loginInstanceId); return (map && map->GetId() == GetId()) ? map : nullptr; // is this check necessary? or does MapInstanced only find instances of itself? } InstanceGroupBind* groupBind = nullptr; Group* group = player->GetGroup(); // use the player's difficulty setting (it may not be the same as the group's) if (group) { groupBind = group->GetBoundInstance(this); if (groupBind) { // solo saves should be reset when entering a group's instance player->UnbindInstance(GetId(), player->GetDifficulty(IsRaid())); pSave = groupBind->save; } } } if (pSave) { // solo/perm/group newInstanceId = pSave->GetInstanceId(); map = FindInstanceMap(newInstanceId); // it is possible that the save exists but the map doesn't if (!map) map = CreateInstance(newInstanceId, pSave, pSave->GetDifficulty()); } else { // if no instanceId via group members or instance saves is found // the instance will be created for the first time newInstanceId = sMapMgr->GenerateInstanceId(); Difficulty diff = player->GetGroup() ? player->GetGroup()->GetDifficulty(IsRaid()) : player->GetDifficulty(IsRaid()); //Seems it is now possible, but I do not know if it should be allowed //ASSERT(!FindInstanceMap(NewInstanceId)); map = FindInstanceMap(newInstanceId); if (!map) map = CreateInstance(newInstanceId, NULL, diff); } } return map; }
/* - return the right instance for the object, based on its InstanceId - create the instance if it's not created already - the player is not actually added to the instance (only in InstanceMap::Add) */ Map* MapInstanced::CreateInstanceForPlayer(const uint32 mapId, Player* player) { if (GetId() != mapId || !player) return NULL; Map* map = NULL; uint32 newInstanceId = 0; // instanceId of the resulting map. if (IsBattlegroundOrArena()) { // Instantiate or find existing bg map for player. The instance id is set in battlegroundid. newInstanceId = player->GetBattlegroundId(); if (!newInstanceId) return NULL; map = sMapMgr->FindMap(mapId, newInstanceId); if (!map) { if (Battleground* bg = player->GetBattleground()) map = CreateBattleground(newInstanceId, bg); else { player->TeleportToBGEntryPoint(); return NULL; } } } else { InstancePlayerBind* pBind = player->GetBoundInstance(GetId(), player->GetDifficulty(IsRaid())); InstanceSave* pSave = pBind ? pBind->save : NULL; // The player's permanent player bind is taken into consideration first, then the player's group bind and finally the solo bind. if (!pBind || !pBind->perm) { InstanceGroupBind* groupBind = NULL; Group* group = player->GetGroup(); // Use the player's difficulty setting (it may not be the same as the group's). if (group) { groupBind = group->GetBoundInstance(this); if (groupBind) pSave = groupBind->save; } } if (pSave) { // Solo / permanent / group lock exists. newInstanceId = pSave->GetInstanceId(); map = FindInstanceMap(newInstanceId); if (IsRaid()) { if (player->IsOnDynamicDifficultyMap()) { // Dynamic Difficulty lock: create an instance that matches the difficulty the player changes to. if (player->GetDifficulty(IsRaid()) != pSave->GetDifficulty() || map && map->GetSpawnMode() != player->GetDifficulty(IsRaid())) map = CreateInstance(newInstanceId, pSave, player->GetDifficulty(IsRaid())); } else { // Shared locks: create an instance to match the current player raid difficulty, if the save and player difficulties don't match. // We must check for save difficulty going original diff -> new one, and map spawn mode going new -> original, to make sure all cases are handled. // Although Heroic 10 / 25 Man also theoretically share a cooldown, if you kill a boss on 10 / 25 Heroic you cannot enter any other Heroic size version of the raid (cannot switch). // Heroic size switching is already handled with no checks needed. The map is created on the save difficulty and you can only switch difficulty dynamically, from inside. if (pSave->GetDifficulty() == RAID_DIFFICULTY_10MAN_NORMAL || pSave->GetDifficulty() == RAID_DIFFICULTY_25MAN_NORMAL) { // Normal. The map is created on the player difficulty. if (player->GetDifficulty(IsRaid()) != pSave->GetDifficulty() || map && map->GetSpawnMode() != player->GetDifficulty(IsRaid())) map = CreateInstance(newInstanceId, pSave, player->GetDifficulty(IsRaid())); } } } // It is possible that the save exists but the map doesn't, create it. if (!map) map = CreateInstance(newInstanceId, pSave, pSave->GetDifficulty()); } else { // If no instanceId via group members or instance saves is found, the instance will be created for the first time. newInstanceId = sMapMgr->GenerateInstanceId(); Difficulty diff = player->GetGroup() ? player->GetGroup()->GetDifficulty(IsRaid()) : player->GetDifficulty(IsRaid()); map = FindInstanceMap(newInstanceId); if (!map) map = CreateInstance(newInstanceId, NULL, diff); } } return map; }
/* - return the right instance for the object, based on its InstanceId - create the instance if it's not created already - the player is not actually added to the instance (only in InstanceMap::Add) */ Map* MapInstanced::CreateInstanceForPlayer(const uint32 mapId, Player* player) { if (GetId() != mapId || !player) return NULL; Map* map = NULL; uint32 newInstanceId = 0; // instanceId of the resulting map if (IsBattlegroundOrArena()) { // instantiate or find existing bg map for player // the instance id is set in battlegroundid newInstanceId = player->GetBattlegroundId(); if (!newInstanceId) return NULL; map = sMapMgr->FindMap(mapId, newInstanceId); if (!map) { if (Battleground* bg = player->GetBattleground()) map = CreateBattleground(newInstanceId, bg); else { player->TeleportToBGEntryPoint(); return NULL; } } } else if (!IsGarrison()) { InstancePlayerBind* pBind = player->GetBoundInstance(GetId(), player->GetDifficultyID(GetEntry())); InstanceSave* pSave = pBind ? pBind->save : NULL; // the player's permanent player bind is taken into consideration first // then the player's group bind and finally the solo bind. if (!pBind || !pBind->perm) { InstanceGroupBind* groupBind = NULL; Group* group = player->GetGroup(); // use the player's difficulty setting (it may not be the same as the group's) if (group) { groupBind = group->GetBoundInstance(this); if (groupBind) pSave = groupBind->save; } } if (pSave) { // solo/perm/group newInstanceId = pSave->GetInstanceId(); map = FindInstanceMap(newInstanceId); // it is possible that the save exists but the map doesn't if (!map) map = CreateInstance(newInstanceId, pSave, pSave->GetDifficultyID()); } else { // if no instanceId via group members or instance saves is found // the instance will be created for the first time newInstanceId = sMapMgr->GenerateInstanceId(); Difficulty diff = player->GetGroup() ? player->GetGroup()->GetDifficultyID(GetEntry()) : player->GetDifficultyID(GetEntry()); //Seems it is now possible, but I do not know if it should be allowed //ASSERT(!FindInstanceMap(NewInstanceId)); map = FindInstanceMap(newInstanceId); if (!map) map = CreateInstance(newInstanceId, NULL, diff); } } else { newInstanceId = player->GetGUID().GetCounter(); map = FindInstanceMap(newInstanceId); if (!map) map = CreateGarrison(newInstanceId, player); } return map; }
/* - return the right instance for the object, based on its InstanceId - create the instance if it's not created already - the player is not actually added to the instance (only in InstanceMap::Add) */ Map* MapInstanced::GetInstance(const WorldObject* obj) { uint32 CurInstanceId = obj->GetInstanceId(); Map* map = NULL; if (obj->GetMapId() == GetId() && CurInstanceId != 0) { // the object wants to be put in a certain instance of this map map = _FindMap(CurInstanceId); if(!map) { // For players if the instanceId is set, it's assumed they are already in a map, // hence the map must be loaded. For Creatures, GameObjects etc the map must exist // prior to calling GetMap, they are not allowed to create maps for themselves. sLog.outError("GetInstance: object %s(%d), typeId %d, in world %d, should be in map %d,%d but that's not loaded yet.", obj->GetName(), obj->GetGUIDLow(), obj->GetTypeId(), obj->IsInWorld(), obj->GetMapId(), obj->GetInstanceId()); assert(false); } return(map); } else { // instance not specified, find an existing or create a new one if(obj->GetTypeId() != TYPEID_PLAYER) { sLog.outError("MAPINSTANCED: WorldObject '%u' (Entry: %u TypeID: %u) is in map %d,%d and requested base map instance of map %d, this must not happen", obj->GetGUIDLow(), obj->GetEntry(), obj->GetTypeId(), obj->GetMapId(), obj->GetInstanceId(), GetId()); assert(false); return NULL; } else { uint32 NewInstanceId = 0; // instanceId of the resulting map Player* player = (Player*)obj; // TODO: battlegrounds and arenas InstancePlayerBind *pBind = player->GetBoundInstance(GetId(), player->GetDifficulty()); InstanceSave *pSave = pBind ? pBind->save : NULL; // the player's permanet player bind is taken into consideration first // then the player's group bind and finally the solo bind. if(!pBind || !pBind->perm) { InstanceGroupBind *groupBind = NULL; Group *group = player->GetGroup(); // use the player's difficulty setting (it may not be the same as the group's) if(group && (groupBind = group->GetBoundInstance(GetId(), player->GetDifficulty()))) pSave = groupBind->save; } if(pSave) { // solo/perm/group NewInstanceId = pSave->GetInstanceId(); map = _FindMap(NewInstanceId); // it is possible that the save exists but the map doesn't if(!map) map = CreateInstance(NewInstanceId, pSave, pSave->GetDifficulty()); return map; } else { // if no instanceId via group members or instance saves is found // the instance will be created for the first time NewInstanceId = MapManager::Instance().GenerateInstanceId(); return CreateInstance(NewInstanceId, NULL, player->GetDifficulty()); } } } }
static bool HandleInstanceUnbindCommand(ChatHandler* handler, char const* args) { if (!*args) return false; Player* player = handler->getSelectedPlayer(); if (!player) player = handler->GetSession()->GetPlayer(); char* map = strtok((char*)args, " "); char* pDiff = strtok(NULL, " "); int8 diff = -1; if (pDiff) diff = atoi(pDiff); uint16 counter = 0; uint16 MapId = 0; if (strcmp(map, "all")) { MapId = uint16(atoi(map)); if (!MapId) return false; } for (uint8 i = 0; i < MAX_DIFFICULTY; ++i) { BoundInstancesMap const& m_boundInstances = sInstanceSaveMgr->PlayerGetBoundInstances(player->GetGUIDLow(), Difficulty(i)); for (BoundInstancesMap::const_iterator itr = m_boundInstances.begin(); itr != m_boundInstances.end();) { InstanceSave* save = itr->second.save; if (itr->first != player->GetMapId() && (!MapId || MapId == itr->first) && (diff == -1 || diff == save->GetDifficulty())) { uint32 resetTime = itr->second.extended ? save->GetExtendedResetTime() : save->GetResetTime(); uint32 ttr = (resetTime >= time(NULL) ? resetTime - time(NULL) : 0); std::string timeleft = GetTimeString(ttr); handler->PSendSysMessage("unbinding map: %d, inst: %d, perm: %s, diff: %d, canReset: %s, TTR: %s%s", itr->first, save->GetInstanceId(), itr->second.perm ? "yes" : "no", save->GetDifficulty(), save->CanReset() ? "yes" : "no", timeleft.c_str(), (itr->second.extended ? " (extended)" : "")); sInstanceSaveMgr->PlayerUnbindInstance(player->GetGUIDLow(), itr->first, Difficulty(i), true, player); itr = m_boundInstances.begin(); counter++; } else ++itr; } } handler->PSendSysMessage("instances unbound: %d", counter); return true; }
static bool HandleInstanceListBindsCommand(ChatHandler* handler, char const* /*args*/) { Player* player = handler->getSelectedPlayer(); if (!player) player = handler->GetSession()->GetPlayer(); uint32 counter = 0; for (uint8 i = 0; i < MAX_DIFFICULTY; ++i) { BoundInstancesMap const& m_boundInstances = sInstanceSaveMgr->PlayerGetBoundInstances(player->GetGUIDLow(), Difficulty(i)); for (BoundInstancesMap::const_iterator itr = m_boundInstances.begin(); itr != m_boundInstances.end(); ++itr) { InstanceSave* save = itr->second.save; uint32 resetTime = itr->second.extended ? save->GetExtendedResetTime() : save->GetResetTime(); uint32 ttr = (resetTime >= time(NULL) ? resetTime - time(NULL) : 0); std::string timeleft = GetTimeString(ttr); handler->PSendSysMessage("map: %d, inst: %d, perm: %s, diff: %d, canReset: %s, TTR: %s%s", itr->first, save->GetInstanceId(), itr->second.perm ? "yes" : "no", save->GetDifficulty(), save->CanReset() ? "yes" : "no", timeleft.c_str(), (itr->second.extended ? " (extended)" : "")); counter++; } } handler->PSendSysMessage("player binds: %d", counter); return true; }
bool OnUse(Player* player, Item* item, SpellCastTargets const& /*targets*/) { if(!player) return false; uint16 counter = 0; uint16 MapId = 0; int8 diff = -1; for(uint8 i = 0; i < MAX_DIFFICULTY; ++i) { Player::BoundInstancesMap &binds = player->GetBoundInstances(Difficulty(i)); for(Player::BoundInstancesMap::iterator itr = binds.begin(); itr != binds.end();) { InstanceSave *save = itr->second.save; if(itr->first != player->GetMapId() && (!MapId || MapId == itr->first) && (diff == -1 || diff == save->GetDifficulty())) { std::string timeleft = GetTimeStringA(save->GetResetTime() - time(NULL)); sLog->outDetail("unbinding map: %d inst: %d perm: %s diff: %d canReset: %s TTR: %s", itr->first, save->GetInstanceId(), itr->second.perm ? "yes" : "no", save->GetDifficulty(), save->CanReset() ? "yes" : "no", timeleft.c_str()); player->UnbindInstance(itr, Difficulty(i)); counter++; } else ++itr; } } sLog->outDetail("instances unbound: %d", counter); if(counter) player->DestroyItemCount(item->GetEntry(),1,true); return true; }
/* - return the right instance for the object, based on its InstanceId - create the instance if it's not created already - the player is not actually added to the instance (only in InstanceMap::Add) */ Map* MapInstanced::GetInstance(const WorldObject* obj) { uint32 CurInstanceId = obj->GetInstanceId(); Map* map = NULL; if (obj->GetMapId() == GetId() && CurInstanceId != 0) { // the object wants to be put in a certain instance of this map map = _FindMap(CurInstanceId); if(!map) { // For players if the instanceId is set, it's assumed they are already in a map, // hence the map must be loaded. For Creatures, GameObjects etc the map must exist // prior to calling GetMap, they are not allowed to create maps for themselves. sLog.outError("GetInstance: object %s(%d), typeId %d, in world %d, should be in map %d,%d but that's not loaded yet.", obj->GetName(), obj->GetGUIDLow(), obj->GetTypeId(), obj->IsInWorld(), obj->GetMapId(), obj->GetInstanceId()); assert(false); } return(map); } else { // instance not specified, find an existing or create a new one if(obj->GetTypeId() != TYPEID_PLAYER) { sLog.outError("MAPINSTANCED: WorldObject '%u' (Entry: %u TypeID: %u) is in map %d,%d and requested base map instance of map %d, this must not happen", obj->GetGUIDLow(), obj->GetEntry(), obj->GetTypeId(), obj->GetMapId(), obj->GetInstanceId(), GetId()); assert(false); return NULL; } else { uint32 NewInstanceId = 0; // instanceId of the resulting map Player* player = (Player*)obj; if(IsBattleGroundOrArena()) { // instantiate or find existing bg map for player // the instance id is set in battlegroundid NewInstanceId = player->GetBattleGroundId(); if(!NewInstanceId) { if(player->GetSession()->PlayerLoading()) return NULL; else assert(NewInstanceId); } map = _FindMap(NewInstanceId); if(!map) { map = CreateBattleGround(NewInstanceId); ((BattleGroundMap*)map)->SetBG(player->GetBattleGround()); } if(!((BattleGroundMap*)map)->GetBG()) { sLog.outError("The bg-class couldn't be assigned (very early) to the battlegroundmap, it's possible, that some db-spawned creatures are now not handled right this is related to battleground alterac valley (av) - please post bugreport, and add information how this bg was created (if you don't have information, report it also) Player: %s (%u) in map:%u requested map:%u", player->GetName(), player->GetGUIDLow(), player->GetMapId(), GetId()); if(player->GetBattleGround()) { sLog.outError("somehow the battleground was found, but please report also - i end this bg now.."); ((BattleGroundMap*)map)->SetBG(player->GetBattleGround()); player->GetBattleGround()->EndBattleGround(0); //to avoid the assert } //assert(false); } return map; } InstancePlayerBind *pBind = player->GetBoundInstance(GetId(), player->GetDifficulty()); InstanceSave *pSave = pBind ? pBind->save : NULL; // the player's permanet player bind is taken into consideration first // then the player's group bind and finally the solo bind. if(!pBind || !pBind->perm) { InstanceGroupBind *groupBind = NULL; Group *group = player->GetGroup(); // use the player's difficulty setting (it may not be the same as the group's) if(group && (groupBind = group->GetBoundInstance(GetId(), player->GetDifficulty()))) pSave = groupBind->save; } if(pSave) { // solo/perm/group NewInstanceId = pSave->GetInstanceId(); map = _FindMap(NewInstanceId); // it is possible that the save exists but the map doesn't if(!map) map = CreateInstance(NewInstanceId, pSave, pSave->GetDifficulty()); return map; } else { // if no instanceId via group members or instance saves is found // the instance will be created for the first time NewInstanceId = MapManager::Instance().GenerateInstanceId(); return CreateInstance(NewInstanceId, NULL, player->GetDifficulty()); } } } }