Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "ScriptPCH.h"
- #include "ScriptMgr.h"
- #include "GameEventMgr.h"
- #include "ObjectMgr.h"
- #include "PoolMgr.h"
- #include "MapManager.h"
- #include "Chat.h"
- // #include "Chat.h"
- struct GOMove_Data
- {
- GameObject* pGob;bool Face;uint32 Entry;float x;float y;float z;float o;float scale;uint32 Phase;
- };
- static std::map<uint64, GOMove_Data> GOMove;
- static std::map<uint64, GameObject*> GOSaved;
- static std::map<uint64, bool> GOSpawned;
- class GOMove_commandscript : public CommandScript
- {
- public:
- GOMove_commandscript() : CommandScript("GOMove_commandscript") { }
- ChatCommand* GetCommands() const
- {
- static ChatCommand GOMoveCommandTable[] =
- {
- { "gomove", SEC_GAMEMASTER, true, &GOMove_Command, "", NULL },
- { NULL, 0, false, NULL, "", NULL }
- };
- return GOMoveCommandTable;
- }
- static bool GO(uint64 GUID,uint32 e,float x,float y,float z,float o,uint32 p,Player* pPlayer,GameObject* OLD,ChatHandler* handler)
- {
- if(GUID == 0)
- return false;
- if(GOMove[GUID].Face) // Face north
- pPlayer->SetOrientation(0);
- if(!OLD) // create a new object totally
- {
- handler->PSendSysMessage("CREATED NEW");
- if(e == 0 || p == 0)
- return false;
- // Getting gameobject info and checking if the object exists
- const GameObjectTemplate* objectInfo = sObjectMgr->GetGameObjectTemplate(e);
- if (!objectInfo)
- {
- handler->PSendSysMessage(LANG_GAMEOBJECT_NOT_EXIST, e);
- handler->SetSentErrorMessage(true);
- return false;
- }
- if (objectInfo->displayId && !sGameObjectDisplayInfoStore.LookupEntry(objectInfo->displayId))
- {
- sLog->outErrorDb("Gameobject (Entry %u GoType: %u) have invalid displayId (%u), not spawned.", e, objectInfo->type, objectInfo->displayId);
- handler->PSendSysMessage(LANG_GAMEOBJECT_HAVE_INVALID_DATA, e);
- handler->SetSentErrorMessage(true);
- return false;
- }
- Map* map = pPlayer->GetMap();
- GameObject* object = new GameObject;
- uint32 guidLow = sObjectMgr->GenerateLowGuid(HIGHGUID_GAMEOBJECT);
- if (!object->Create(guidLow, objectInfo->entry, map, p, x, y, z, o, 0.0f, 0.0f, 0.0f, 0.0f, 0, GO_STATE_READY))
- {
- delete object;
- return false;
- }
- // fill the gameobject data and save to the db
- object->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), pPlayer->GetPhaseMaskForSpawn());
- // this will generate a new guid if the object is in an instance
- if (!object->LoadGameObjectFromDB(guidLow, map))
- {
- delete object;
- return false;
- }
- sObjectMgr->AddGameobjectToGrid(guidLow, sObjectMgr->GetGOData(guidLow));
- handler->PSendSysMessage(LANG_GAMEOBJECT_ADD, e, objectInfo->name.c_str(), guidLow, x, y, z);
- GOSaved[object->GetGUID()] = object;
- GOMove[GUID].pGob = object;
- return true;
- }
- else // move the old object
- {
- uint64 OGuid = OLD->GetGUID();
- if (!MapManager::IsValidMapCoord(OLD->GetMapId(), x, y, z))
- {
- handler->PSendSysMessage(LANG_INVALID_TARGET_COORD, x, y, OLD->GetMapId());
- handler->SetSentErrorMessage(true);
- return false;
- }
- // OLD->LoadFromDB();
- OLD->RemoveFromWorld();
- float rot2 = sin(o/2);
- float rot3 = cos(o/2);
- GOSaved[OGuid]->Relocate(x, y, z, o);
- if(p != 0 && p != NULL)
- GOSaved[OGuid]->SetPhaseMask(p, true);
- GOSaved[OGuid]->SaveToDB();
- GameObject* NEW = pPlayer->SummonGameObject(OLD->GetEntry(), x, y, z, o, 0, 0, rot2, rot3, 300); // phase?
- GOSaved[NEW->GetGUID()] = GOSaved[OGuid];
- GOSaved.erase(OGuid);
- GOMove[GUID].pGob = NEW;
- //OLD->SetRespawnTime(0); // not save respawn time
- //OLD->Delete();
- /*
- if (!MapManager::IsValidMapCoord(OLD->GetMapId(), x, y, z))
- {
- handler->PSendSysMessage(LANG_INVALID_TARGET_COORD, x, y, OLD->GetMapId());
- handler->SetSentErrorMessage(true);
- return false;
- }
- OLD->Relocate(x, y, z, o);
- if(p != 0 && p != NULL)
- OLD->SetPhaseMask(p, true);
- OLD->SaveToDB();
- */
- }
- return true;
- }
- static bool GOMove_Command(ChatHandler* handler, const char* args)
- {
- // GO(GUID, entry, pPlayer->GetPositionX(), pPlayer->GetPositionY(), pPlayer->GetPositionZ(), pPlayer->GetOrientation(), pPlayer->GetPhaseMask(), pPlayer, pOld, handler);
- enum eEnums
- {
- TEST = 0 ,
- SELECTNEAR = 1 ,
- DELET = 2 ,
- X = 3 ,
- Y = 4 ,
- Z = 5 ,
- O = 6 ,
- SPAWN = 7 ,
- NORTH = 8 ,
- EAST = 9 ,
- SOUTH = 10 ,
- WEST = 11 ,
- NORTHEAST = 12 ,
- NORTHWEST = 13 ,
- SOUTHEAST = 14 ,
- SOUTHWEST = 15 ,
- UP = 16 ,
- DOWN = 17 ,
- LEFT = 18 ,
- RIGHT = 19 ,
- };
- WorldSession* Session = handler->GetSession();
- Player* pPlayer = Session->GetPlayer();
- uint64 GUID = pPlayer->GetGUID();
- if(!args)
- return false;
- char* ID_t = strtok((char*)args, " "); // change (char*)args incase of a crash
- if(!ID_t)
- return false;
- uint32 ID = atoi(ID_t);
- char* ARG_t = strtok(NULL, " ");
- uint32 ARG = 0;
- if(ARG_t)
- ARG = atoi(ARG_t);
- if(GOMove.find(GUID) == GOMove.end())
- GOMove[GUID].Face = false;
- if(ARG == 0 && ID <= 6) // no args
- {
- switch(ID)
- {
- case TEST:
- {
- Session->SendAreaTriggerMessage(pPlayer->GetName());
- }
- break;
- case SELECTNEAR:
- {
- QueryResult& result = WorldDatabase.PQuery("SELECT gameobject.guid, id, position_x, position_y, position_z, orientation, map, phaseMask, "
- "(POW(position_x - %f, 2) + POW(position_y - %f, 2) + POW(position_z - %f, 2)) AS order_ FROM gameobject "
- "WHERE map = '%i' ORDER BY order_ ASC LIMIT 10",
- handler->GetSession()->GetPlayer()->GetPositionX(), handler->GetSession()->GetPlayer()->GetPositionY(), handler->GetSession()->GetPlayer()->GetPositionZ(),
- handler->GetSession()->GetPlayer()->GetMapId());
- if (!result)
- {
- handler->SendSysMessage(LANG_COMMAND_TARGETOBJNOTFOUND);
- return true;
- }
- bool found = false;
- uint32 guidLow, id,poolId;
- do
- {
- Field* fields = result->Fetch();
- guidLow = fields[0].GetUInt32();
- id = fields[1].GetUInt32();
- poolId = sPoolMgr->IsPartOfAPool<GameObject>(guidLow);
- if (!poolId || sPoolMgr->IsSpawnedObject<GameObject>(guidLow))
- found = true;
- } while (result->NextRow() && !found);
- if (!found)
- {
- handler->PSendSysMessage(LANG_GAMEOBJECT_NOT_EXIST, id);
- return true;
- }
- GameObject * Target = pPlayer->GetMap()->GetGameObject(MAKE_NEW_GUID(guidLow, id, HIGHGUID_GAMEOBJECT));
- GOMove[GUID].pGob = Target;
- if(GOSaved.find(Target->GetGUID()) == GOSaved.end())
- GOSaved[Target->GetGUID()] = Target;
- // SEND_USED(pPlayer, str)
- Session->SendAreaTriggerMessage("Selected %s", Target->GetName());
- }
- break;
- case DELET:
- {
- if(GOMove[GUID].pGob)
- {
- GameObject* Target = GOMove[GUID].pGob;
- uint64 ownerGuid = Target->GetOwnerGUID();
- if (ownerGuid)
- {
- Unit* owner = ObjectAccessor::GetUnit(*handler->GetSession()->GetPlayer(), ownerGuid);
- if (!owner || !IS_PLAYER_GUID(ownerGuid))
- {
- handler->PSendSysMessage(LANG_COMMAND_DELOBJREFERCREATURE, GUID_LOPART(ownerGuid), Target->GetGUIDLow());
- handler->SetSentErrorMessage(true);
- return false;
- }
- owner->RemoveGameObject(Target, false);
- }
- Target->SetRespawnTime(0); // not save respawn time
- Target->Delete();
- Target->DeleteFromDB();
- handler->PSendSysMessage(LANG_COMMAND_DELOBJMESSAGE, Target->GetGUIDLow());
- GOMove[GUID].pGob = NULL;
- }
- else
- Session->SendNotification("No object selected");
- }
- break;
- case X:
- {
- if(GOMove[GUID].pGob)
- {
- GameObject* Target = GOMove[GUID].pGob;
- float x,y,z,o;
- Target->GetPosition(x,y,z,o);
- GO(GUID,NULL,pPlayer->GetPositionX(),y,z,o,0,pPlayer,Target, handler);
- }
- else
- Session->SendNotification("No object selected");
- }
- break;
- case Y:
- {
- if(GOMove[GUID].pGob)
- {
- GameObject* Target = GOMove[GUID].pGob;
- float x,y,z,o;
- Target->GetPosition(x,y,z,o);
- GO(GUID,NULL,x,pPlayer->GetPositionY(),z,o,0,pPlayer,Target, handler);
- }
- else
- Session->SendNotification("No object selected");
- }
- break;
- case Z:
- {
- if(GOMove[GUID].pGob)
- {
- GameObject* Target = GOMove[GUID].pGob;
- float x,y,z,o;
- Target->GetPosition(x,y,z,o);
- GO(GUID,NULL,x,y,pPlayer->GetPositionZ(),o,0,pPlayer,Target, handler);
- }
- else
- Session->SendNotification("No object selected");
- }
- break;
- case O:
- {
- if(GOMove[GUID].pGob)
- {
- GameObject* Target = GOMove[GUID].pGob;
- float x,y,z,o;
- Target->GetPosition(x,y,z,o);
- GO(GUID,NULL,x,y,z,pPlayer->GetOrientation(),0,pPlayer,Target, handler);
- }
- else
- Session->SendNotification("No object selected");
- }
- break;
- default:
- {
- Session->SendNotification("ID not found: or ID, argument combination was wrong: %u, %u", ID, ARG);
- }
- }
- return true;
- }
- else if(ARG != 0 && ID >= 7)
- {
- switch(ID)
- {
- case SPAWN:
- {
- bool Sel = GO(GUID, ARG, pPlayer->GetPositionX(), pPlayer->GetPositionY(), pPlayer->GetPositionZ(), pPlayer->GetOrientation(), pPlayer->GetPhaseMaskForSpawn(), pPlayer, NULL, handler);
- if(!Sel)
- Session->SendNotification("No gameobject found with entry %u", ARG);
- else
- {
- Session->SendAreaTriggerMessage("%s spawned", GOMove[GUID].pGob->GetName());
- // SEND_USED(pPlayer, str)
- }
- }
- break;
- case NORTH:
- {
- if(GOMove[GUID].pGob)
- {
- GameObject* Target = GOMove[GUID].pGob;
- float x,y,z,o;
- Target->GetPosition(x,y,z,o);
- GO(GUID,NULL,x+(ARG/100),y,z,o,0,pPlayer,Target, handler);
- std::string test;
- test += (ARG/100);
- Session->SendNotification(test.c_str());
- }
- else
- Session->SendNotification("No object selected");
- }
- break;
- case EAST: // Move east
- {
- if(GOMove[GUID].pGob)
- {
- GameObject* Target = GOMove[GUID].pGob;
- float x,y,z,o;
- Target->GetPosition(x,y,z,o);
- GO(GUID,NULL,x,y-(ARG/100),z,o,0,pPlayer,Target, handler);
- }
- else
- Session->SendNotification("No object selected");
- }
- break;
- case SOUTH: // Move south
- {
- if(GOMove[GUID].pGob)
- {
- GameObject* Target = GOMove[GUID].pGob;
- float x,y,z,o;
- Target->GetPosition(x,y,z,o);
- GO(GUID,NULL,x-(ARG/100),y,z,o,0,pPlayer,Target, handler);
- }
- else
- Session->SendNotification("No object selected");
- }
- break;
- case WEST: // Move west
- {
- if(GOMove[GUID].pGob)
- {
- GameObject* Target = GOMove[GUID].pGob;
- float x,y,z,o;
- Target->GetPosition(x,y,z,o);
- GO(GUID,NULL,x,y+(ARG/100),z,o,0,pPlayer,Target, handler);
- }
- else
- Session->SendNotification("No object selected");
- }
- break;
- case NORTHEAST: // Move Northeast
- {
- if(GOMove[GUID].pGob)
- {
- GameObject* Target = GOMove[GUID].pGob;
- float x,y,z,o;
- Target->GetPosition(x,y,z,o);
- GO(GUID,NULL,x+(ARG/100),y-(ARG/100),z,o,0,pPlayer,Target, handler);
- }
- else
- Session->SendNotification("No object selected");
- }
- break;
- case SOUTHEAST: // Move southeast
- {
- if(GOMove[GUID].pGob)
- {
- GameObject* Target = GOMove[GUID].pGob;
- float x,y,z,o;
- Target->GetPosition(x,y,z,o);
- GO(GUID,NULL,x-(ARG/100),y-(ARG/100),z,o,0,pPlayer,Target, handler);
- }
- else
- Session->SendNotification("No object selected");
- }
- break;
- case SOUTHWEST: // Move southwest
- {
- if(GOMove[GUID].pGob)
- {
- GameObject* Target = GOMove[GUID].pGob;
- float x,y,z,o;
- Target->GetPosition(x,y,z,o);
- GO(GUID,NULL,x-(ARG/100),y+(ARG/100),z,o,0,pPlayer,Target, handler);
- }
- else
- Session->SendNotification("No object selected");
- }
- break;
- case NORTHWEST: // Move northwest
- {
- if(GOMove[GUID].pGob)
- {
- GameObject* Target = GOMove[GUID].pGob;
- float x,y,z,o;
- Target->GetPosition(x,y,z,o);
- GO(GUID,NULL,x+(ARG/100),y+(ARG/100),z,o,0,pPlayer,Target, handler);
- }
- else
- Session->SendNotification("No object selected");
- }
- break;
- case UP: // Move up
- {
- if(GOMove[GUID].pGob)
- {
- GameObject* Target = GOMove[GUID].pGob;
- float x,y,z,o;
- Target->GetPosition(x,y,z,o);
- GO(GUID,NULL,x,y,z+(ARG/100),o,0,pPlayer,Target, handler);
- }
- else
- Session->SendNotification("No object selected");
- }
- break;
- case DOWN: // Move down
- {
- if(GOMove[GUID].pGob)
- {
- GameObject* Target = GOMove[GUID].pGob;
- float x,y,z,o;
- Target->GetPosition(x,y,z,o);
- GO(GUID,NULL,x,y,z-(ARG/100),o,0,pPlayer,Target, handler);
- }
- else
- Session->SendNotification("No object selected");
- }
- break;
- case RIGHT:
- {
- if(GOMove[GUID].pGob)
- {
- GameObject* Target = GOMove[GUID].pGob;
- float x,y,z,o;
- Target->GetPosition(x,y,z,o);
- GO(GUID,NULL,x,y,z,o-(ARG/100),0,pPlayer,Target, handler);
- }
- else
- Session->SendNotification("No object selected");
- }
- break;
- case LEFT:
- {
- if(GOMove[GUID].pGob)
- {
- GameObject* Target = GOMove[GUID].pGob;
- float x,y,z,o;
- Target->GetPosition(x,y,z,o);
- GO(GUID,NULL,x,y,z,o+(ARG/100),0,pPlayer,Target, handler);
- }
- else
- Session->SendNotification("No object selected");
- }
- break;
- default:
- {
- Session->SendNotification("ID not found: or ID, argument combination was wrong: %u, %u", ID, ARG);
- }
- }
- return true;
- }
- return false;
- }
- };
- void AddSC_GOMove_commandscript()
- {
- new GOMove_commandscript();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement