Beispiel #1
0
// 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;
}
Beispiel #2
0
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;
}
Beispiel #3
0
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;
}
int LuaGlobalFunctions_PerformIngameSpawn(lua_State * L)
{
	uint32 spawntype = luaL_checkint(L, 1);
	uint32 entry = luaL_checkint(L, 2);
	uint32 map = luaL_checkint(L, 3);
	float x = CHECK_FLOAT(L, 4);
	float y = CHECK_FLOAT(L, 5);
	float z = CHECK_FLOAT(L, 6);
	float o = CHECK_FLOAT(L, 7);
	uint32 faction = luaL_checkint(L, 8); //also scale as percentage
	uint32 duration = luaL_checkint(L, 9);
	uint32 equip1 = luaL_optint(L, 10, 1);
	uint32 equip2 = luaL_optint(L, 11, 1);
	uint32 equip3 = luaL_optint(L, 12, 1);
	//13: instance id
	uint32 save = luaL_optint(L, 14, 0);
	if(x && y && z && entry)
	{
		if (spawntype == 1) //Unit
		{ 
			CreatureProto *p = CreatureProtoStorage.LookupEntry(entry);
			CreatureInfo *i = CreatureNameStorage.LookupEntry(entry);
			if (p == NULL || i == NULL)
				RET_NIL(true);

			MapMgr *mapMgr = sInstanceMgr.GetMapMgr(map);
			if (mapMgr == NULL)
				RET_NIL(true);

			int32 instanceid = luaL_optint(L, 13, mapMgr->GetInstanceID());
			CreatureSpawn * sp = new CreatureSpawn();
			sp->entry = entry;
			sp->id = objmgr.GenerateCreatureSpawnID();
			sp->x = x;
			sp->y = y;
			sp->z = z;
			sp->o = o;
			sp->emote_state = 0;
			sp->flags = 0;
			sp->factionid = faction;
			sp->stand_state = 0;
			sp->phase = 1;
			sp->vehicle = p->vehicle_entry > 0 ? true : false;
			sp->Bytes = NULL;
			sp->ChannelData = NULL;
			sp->MountedDisplay = NULL;

			Creature * pCreature = NULL;
			if(sp->vehicle)
			{
				pCreature = TO_CREATURE(mapMgr->CreateVehicle(entry));
				TO_VEHICLE(pCreature)->Load(sp, mapMgr->iInstanceMode, NULL);
			}
			else
			{
				pCreature = mapMgr->CreateCreature(entry);
				pCreature->Load(sp, mapMgr->iInstanceMode, NULL);
			}

			pCreature->m_loadedFromDB = true;
			pCreature->SetFaction(faction);
			pCreature->SetInstanceID(instanceid);
			pCreature->SetMapId(map);
			pCreature->m_noRespawn = true;
			pCreature->PushToWorld(mapMgr);
			if (duration>0) 
				pCreature->Despawn(duration,0);
			if (save)
				pCreature->SaveToDB();
			Lunar<Unit>::push(L,TO_UNIT(pCreature));
		}
		else if (spawntype == 2) //GO
		{ 
			GameObjectInfo *n = GameObjectNameStorage.LookupEntry(entry);
			if (n == NULL)
				RET_NIL(true);

			MapMgr *mapMgr = sInstanceMgr.GetMapMgr(map);
			if (mapMgr == NULL)
				RET_NIL(true);

			int32 instanceid = luaL_optint(L, 13, mapMgr->GetInstanceID());

			GameObject *go = mapMgr->CreateGameObject(entry);
			go->SetInstanceID(instanceid);
			go->CreateFromProto(entry,map,x,y,z,o);

			// 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->scale = go->GetUInt32Value(OBJECT_FIELD_SCALE_X);
			gs->x = go->GetPositionX();
			gs->y = go->GetPositionY();
			gs->z = go->GetPositionZ();
			gs->state = go->GetByte(GAMEOBJECT_BYTES_1, 0);
			gs->phase = 0;

			go->m_spawn = gs;
			go->PushToWorld(mapMgr);
			if (duration)
				sEventMgr.AddEvent(go,&GameObject::ExpireAndDelete,EVENT_GAMEOBJECT_UPDATE,duration,1,EVENT_FLAG_DO_NOT_EXECUTE_IN_WORLD_CONTEXT);
			if (save)
				go->SaveToDB();
			Lunar<GameObject>::push(L,go);
		}
		else
			RET_NIL(true);
	}
	else
		RET_NIL(true);
	return 1;
}