bool WorldCreator::CheckInstanceForObject(Object *obj, MapInfo *pMapinfo) { WorldPacket data(4); Player *_player = NULL; if(obj->GetTypeId() == TYPEID_PLAYER) { _player = static_cast<Player*>(obj); } if(pMapinfo && _player) { switch(pMapinfo->type) { case INSTANCE_NONRAID: case INSTANCE_RAID: case INSTANCE_MULTIMODE: { //instance creation detection types //case 1, player is inside a group aka not soloing //onoes: leader can be inside a instance already and make a group or its a fresh group, noone inside if(_player->InGroup()) //group created, join leader instance. { Group *pGroup = _player->GetGroup(); if(pGroup) { //check if instance already exists(player solo created instance and made group after) MapMgr *pInstance = sWorldCreator.GetInstanceByGroup(pGroup, _player, pMapinfo); if(pInstance) { //INSTANCE_OK if(pInstance->IsCombatInProgress()) { WorldPacket msg; msg.Initialize(SMSG_AREA_TRIGGER_MESSAGE); msg << uint32(0) << "Encounter in progress." << uint8(0) << uint8(0); _player->GetSession()->SendPacket(&msg); return false; } if(pInstance->GetPlayerCount() >= pMapinfo->playerlimit) { data.Initialize(SMSG_TRANSFER_ABORTED); data << uint32(INSTANCE_ABORT_FULL); _player->GetSession()->SendPacket(&data); return false; } _player->SetInstanceID(pInstance->GetInstanceID()); } else { //group leader didnt made any instance yet, create instance for this group. uint32 id = sWorldCreator.CreateInstance(pGroup, pGroup->GetLeader(), pMapinfo->mapid); // again, NULL might not be 0 //if(id != NULL) if(id != 0) { //INSTANCE CREATED _player->SetInstanceID(id); } else { data.Initialize(SMSG_TRANSFER_ABORTED); data << uint32(INSTANCE_ABORT_ERROR); _player->GetSession()->SendPacket(&data); return false; } } } else { data.Initialize(SMSG_TRANSFER_ABORTED); data << uint32(INSTANCE_ABORT_ERROR); _player->GetSession()->SendPacket(&data); return false; } } else { MapMgr *pInstance = sWorldCreator.GetInstanceByCreator(_player, pMapinfo); if(pInstance) { //INSTANCE_OK if(pInstance->IsCombatInProgress()) { WorldPacket msg; msg.Initialize(SMSG_AREA_TRIGGER_MESSAGE); msg << uint32(0) << "Encounter in progress." << uint8(0) << uint8(0); _player->GetSession()->SendPacket(&msg); return false; } if(pInstance->GetPlayerCount() >= pMapinfo->playerlimit) { data.Initialize(SMSG_TRANSFER_ABORTED); data << uint32(INSTANCE_ABORT_FULL); _player->GetSession()->SendPacket(&data); return false; } _player->SetInstanceID(pInstance->GetInstanceID()); } else { uint32 id2 = sWorldCreator.CreateInstance(NULL, _player, pMapinfo->mapid); //if(id2 != NULL) if(id2 != 0) { _player->SetInstanceID(id2); } else { data.Initialize(SMSG_TRANSFER_ABORTED); data << uint32(INSTANCE_ABORT_ERROR); _player->GetSession()->SendPacket(&data); return false; } } } }break; } } return true; }