// Spawns the object too, without which you can not interact with the object GameObject* MapMgr::CreateAndSpawnGameObject(uint32 entryID, float x, float y, float z, float o, float scale) { GameObjectInfo* goi = GameObjectNameStorage.LookupEntry(entryID); if(!goi) { LOG_DEBUG("Error looking up entry in CreateAndSpawnGameObject"); return NULL; } LOG_DEBUG("CreateAndSpawnGameObject: By Entry '%u'", entryID); GameObject* go = CreateGameObject(entryID); //Player *chr = m_session->GetPlayer(); uint32 mapid = GetMapId(); // Setup game object go->CreateFromProto(entryID, mapid, x, y, z, o); go->SetScale(scale); go->InitAI(); go->PushToWorld(this); // Create spawn instance GOSpawn* gs = new GOSpawn; gs->entry = go->GetEntry(); gs->facing = go->GetOrientation(); gs->faction = go->GetFaction(); gs->flags = go->GetUInt32Value(GAMEOBJECT_FLAGS); gs->id = objmgr.GenerateGameObjectSpawnID(); gs->o = 0.0f; gs->o1 = go->GetParentRotation(0); gs->o2 = go->GetParentRotation(2); gs->o3 = go->GetParentRotation(3); gs->scale = go->GetScale(); gs->x = go->GetPositionX(); gs->y = go->GetPositionY(); gs->z = go->GetPositionZ(); gs->state = go->GetByte(GAMEOBJECT_BYTES_1, 0); //gs->stateNpcLink = 0; gs->overrides = go->GetOverrides(); uint32 cx = GetPosX(x); uint32 cy = GetPosY(y); GetBaseMap()->GetSpawnsListAndCreate(cx, cy)->GOSpawns.push_back(gs); go->m_spawn = gs; MapCell* mCell = GetCell(cx, cy); if(mCell != NULL) mCell->SetLoaded(); return go; }
bool ChatHandler::HandleGOInfo(const char* args, WorldSession* m_session) { GameObjectInfo* GOInfo = NULL; GameObject* GObj = m_session->GetPlayer()->GetSelectedGo(); if(!GObj) { RedSystemMessage(m_session, "No selected GameObject..."); return true; } SystemMessage(m_session, "%s Information:", MSG_COLOR_SUBWHITE); SystemMessage(m_session, "%s SpawnID:%s%u", MSG_COLOR_GREEN, MSG_COLOR_LIGHTBLUE, GObj->m_spawn != NULL ? GObj->m_spawn->id : 0); SystemMessage(m_session, "%s Entry:%s%u", MSG_COLOR_GREEN, MSG_COLOR_LIGHTBLUE, GObj->GetEntry()); SystemMessage(m_session, "%s Model:%s%u", MSG_COLOR_GREEN, MSG_COLOR_LIGHTBLUE, GObj->GetUInt32Value(GAMEOBJECT_DISPLAYID)); SystemMessage(m_session, "%s State:%s%u", MSG_COLOR_GREEN, MSG_COLOR_LIGHTBLUE, GObj->GetByte(GAMEOBJECT_BYTES_1, 0)); SystemMessage(m_session, "%s flags:%s%u", MSG_COLOR_GREEN, MSG_COLOR_LIGHTBLUE, GObj->GetUInt32Value(GAMEOBJECT_FLAGS)); SystemMessage(m_session, "%s dynflags:%s%u", MSG_COLOR_GREEN, MSG_COLOR_LIGHTBLUE, GObj->GetUInt32Value(GAMEOBJECT_DYNAMIC)); SystemMessage(m_session, "%s faction:%s%u", MSG_COLOR_GREEN, MSG_COLOR_LIGHTBLUE, GObj->GetFaction()); SystemMessage(m_session, "%s phase:%s%u", MSG_COLOR_GREEN, MSG_COLOR_LIGHTBLUE, GObj->GetPhase()); char gotypetxt[50]; switch(GObj->GetType()) { case GAMEOBJECT_TYPE_DOOR: strcpy(gotypetxt, "Door"); break; case GAMEOBJECT_TYPE_BUTTON: strcpy(gotypetxt, "Button"); break; case GAMEOBJECT_TYPE_QUESTGIVER: strcpy(gotypetxt, "Quest Giver"); break; case GAMEOBJECT_TYPE_CHEST: strcpy(gotypetxt, "Chest"); break; case GAMEOBJECT_TYPE_BINDER: strcpy(gotypetxt, "Binder"); break; case GAMEOBJECT_TYPE_GENERIC: strcpy(gotypetxt, "Generic"); break; case GAMEOBJECT_TYPE_TRAP: strcpy(gotypetxt, "Trap"); break; case GAMEOBJECT_TYPE_CHAIR: strcpy(gotypetxt, "Chair"); break; case GAMEOBJECT_TYPE_SPELL_FOCUS: strcpy(gotypetxt, "Spell Focus"); break; case GAMEOBJECT_TYPE_TEXT: strcpy(gotypetxt, "Text"); break; case GAMEOBJECT_TYPE_GOOBER: strcpy(gotypetxt, "Goober"); break; case GAMEOBJECT_TYPE_TRANSPORT: strcpy(gotypetxt, "Transport"); break; case GAMEOBJECT_TYPE_AREADAMAGE: strcpy(gotypetxt, "Area Damage"); break; case GAMEOBJECT_TYPE_CAMERA: strcpy(gotypetxt, "Camera"); break; case GAMEOBJECT_TYPE_MAP_OBJECT: strcpy(gotypetxt, "Map Object"); break; case GAMEOBJECT_TYPE_MO_TRANSPORT: strcpy(gotypetxt, "Mo Transport"); break; case GAMEOBJECT_TYPE_DUEL_ARBITER: strcpy(gotypetxt, "Duel Arbiter"); break; case GAMEOBJECT_TYPE_FISHINGNODE: strcpy(gotypetxt, "Fishing Node"); break; case GAMEOBJECT_TYPE_RITUAL: strcpy(gotypetxt, "Ritual"); break; case GAMEOBJECT_TYPE_MAILBOX: strcpy(gotypetxt, "Mailbox"); break; case GAMEOBJECT_TYPE_AUCTIONHOUSE: strcpy(gotypetxt, "Auction House"); break; case GAMEOBJECT_TYPE_GUARDPOST: strcpy(gotypetxt, "Guard Post"); break; case GAMEOBJECT_TYPE_SPELLCASTER: strcpy(gotypetxt, "Spell Caster"); break; case GAMEOBJECT_TYPE_MEETINGSTONE: strcpy(gotypetxt, "Meeting Stone"); break; case GAMEOBJECT_TYPE_FLAGSTAND: strcpy(gotypetxt, "Flag Stand"); break; case GAMEOBJECT_TYPE_FISHINGHOLE: strcpy(gotypetxt, "Fishing Hole"); break; case GAMEOBJECT_TYPE_FLAGDROP: strcpy(gotypetxt, "Flag Drop"); break; case GAMEOBJECT_TYPE_DESTRUCTIBLE_BUILDING: strcpy(gotypetxt, "Destructible Building"); break; default: strcpy(gotypetxt, "Unknown."); break; } SystemMessage(m_session, "%s Type:%s%u -- %s", MSG_COLOR_GREEN, MSG_COLOR_LIGHTBLUE, GObj->GetType(), gotypetxt); SystemMessage(m_session, "%s Distance:%s%f", MSG_COLOR_GREEN, MSG_COLOR_LIGHTBLUE, GObj->CalcDistance(m_session->GetPlayer())); GOInfo = GameObjectNameStorage.LookupEntry(GObj->GetEntry()); if(!GOInfo) { RedSystemMessage(m_session, "This GameObject doesn't have template, you won't be able to get some information nor to spawn a GO with this entry."); return true; } if(GOInfo->Name) SystemMessage(m_session, "%s Name:%s%s", MSG_COLOR_GREEN, MSG_COLOR_LIGHTBLUE, GOInfo->Name); SystemMessage(m_session, "%s Size:%s%f", MSG_COLOR_GREEN, MSG_COLOR_LIGHTBLUE, GObj->GetScale()); SystemMessage(m_session, "%s Parent Rotation O1:%s%f", MSG_COLOR_GREEN, MSG_COLOR_LIGHTBLUE, GObj->GetParentRotation(1)); SystemMessage(m_session, "%s Parent Rotation O2:%s%f", MSG_COLOR_GREEN, MSG_COLOR_LIGHTBLUE, GObj->GetParentRotation(2)); SystemMessage(m_session, "%s Parent Rotation O3:%s%f", MSG_COLOR_GREEN, MSG_COLOR_LIGHTBLUE, GObj->GetParentRotation(3)); if( GOInfo->Type == GAMEOBJECT_TYPE_DESTRUCTIBLE_BUILDING ){ SystemMessage(m_session, "%s HP:%s%u/%u", MSG_COLOR_GREEN, MSG_COLOR_LIGHTBLUE, GObj->GetHP(), GObj->GetMaxHP() ); } return true; }
bool ChatHandler::HandleGOSpawn(const char* args, WorldSession* m_session) { std::stringstream sstext; char* pEntryID = strtok((char*)args, " "); if(!pEntryID) return false; uint32 EntryID = atoi(pEntryID); bool Save = false; char* pSave = strtok(NULL, " "); if(pSave) Save = (atoi(pSave) > 0 ? true : false); GameObjectInfo* goi = GameObjectNameStorage.LookupEntry(EntryID); if(!goi) { sstext << "GameObject Info '" << EntryID << "' Not Found" << '\0'; SystemMessage(m_session, sstext.str().c_str()); return true; } LOG_DEBUG("Spawning GameObject By Entry '%u'", EntryID); sstext << "Spawning GameObject By Entry '" << EntryID << "'" << '\0'; SystemMessage(m_session, sstext.str().c_str()); Player* chr = m_session->GetPlayer(); GameObject* go = chr->GetMapMgr()->CreateGameObject(EntryID); uint32 mapid = chr->GetMapId(); float x = chr->GetPositionX(); float y = chr->GetPositionY(); float z = chr->GetPositionZ(); float o = chr->GetOrientation(); go->CreateFromProto(EntryID, mapid, x, y, z, o); go->PushToWorld(chr->GetMapMgr()); go->Phase(PHASE_SET, chr->GetPhase()); // Create spawn instance GOSpawn* gs = new GOSpawn; gs->entry = go->GetEntry(); gs->facing = go->GetOrientation(); gs->faction = go->GetFaction(); gs->flags = go->GetUInt32Value(GAMEOBJECT_FLAGS); gs->id = objmgr.GenerateGameObjectSpawnID(); gs->o = 0.0f; gs->o1 = go->GetParentRotation(0); gs->o2 = go->GetParentRotation(2); gs->o3 = go->GetParentRotation(3); gs->scale = go->GetScale(); gs->x = go->GetPositionX(); gs->y = go->GetPositionY(); gs->z = go->GetPositionZ(); gs->state = go->GetByte(GAMEOBJECT_BYTES_1, 0); //gs->stateNpcLink = 0; gs->phase = go->GetPhase(); gs->overrides = go->GetOverrides(); uint32 cx = chr->GetMapMgr()->GetPosX(chr->GetPositionX()); uint32 cy = chr->GetMapMgr()->GetPosY(chr->GetPositionY()); chr->GetMapMgr()->GetBaseMap()->GetSpawnsListAndCreate(cx, cy)->GOSpawns.push_back(gs); go->m_spawn = gs; MapCell* mCell = chr->GetMapMgr()->GetCell(cx, cy); if(mCell != NULL) mCell->SetLoaded(); if(Save == true) { // If we're saving, create template and add index go->SaveToDB(); go->m_loadedFromDB = true; } sGMLog.writefromsession(m_session, "spawned gameobject %s, entry %u at %u %f %f %f%s", GameObjectNameStorage.LookupEntry(gs->entry)->Name, gs->entry, chr->GetMapId(), gs->x, gs->y, gs->z, Save ? ", saved in DB" : ""); return true; }