bool ChatHandler::HandleDeleteCommand(const char* args, WorldSession *m_session) { uint64 guid = m_session->GetPlayer()->GetSelection(); if(guid == 0) { SystemMessage(m_session, "No selection."); return true; } Creature *unit = m_session->GetPlayer()->GetMapMgr()->GetCreature(GET_LOWGUID_PART(guid)); if(!unit) { SystemMessage(m_session, "You should select a creature."); return true; } if(unit->IsPet()) { SystemMessage(m_session, "You can't delete a pet." ); return true; } sGMLog.writefromsession(m_session, "used npc delete, sqlid %u, creature %s, pos %f %f %f", unit->GetSQL_id(), unit->GetCreatureInfo()->Name, unit->GetPositionX(), unit->GetPositionY(), unit->GetPositionZ()); unit->GetAIInterface()->hideWayPoints( m_session->GetPlayer() ); unit->DeleteFromDB(); if(unit->IsInWorld()) { if(unit->m_spawn) { uint32 cellx = uint32(((_maxX-unit->m_spawn->x)/_cellSize)); uint32 celly = uint32(((_maxY-unit->m_spawn->y)/_cellSize)); if(cellx <= _sizeX && celly <= _sizeY) { CellSpawns * sp = unit->GetMapMgr()->GetBaseMap()->GetSpawnsList(cellx, celly); if( sp != NULL ) { for( CreatureSpawnList::iterator itr = sp->CreatureSpawns.begin(); itr != sp->CreatureSpawns.end(); ++itr ) if( (*itr) == unit->m_spawn ) { sp->CreatureSpawns.erase( itr ); break; } } delete unit->m_spawn; unit->m_spawn = NULL; } } unit->RemoveFromWorld(false,true); } BlueSystemMessage(m_session, "Creature deleted"); return true; }
static bool HandleNpcBotDeleteCommand(ChatHandler* handler, const char* /*args*/) { Player* chr = handler->GetSession()->GetPlayer(); Unit* ubot = chr->GetSelectedUnit(); if (!ubot) { handler->SendSysMessage(".npcbot delete"); handler->SendSysMessage("Deletes selected npcbot spawn from world and DB"); handler->SetSentErrorMessage(true); return false; } Creature* bot = ubot->ToCreature(); if (!bot || !bot->IsNPCBot()) { handler->SendSysMessage("No npcbot selected"); handler->SetSentErrorMessage(true); return false; } if (Player* botowner = bot->GetBotOwner()->ToPlayer()) botowner->GetBotMgr()->RemoveBot(bot->GetGUID(), BOT_REMOVE_DISMISS); uint32 id = bot->GetEntry(); PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_NPCBOT_EQUIP); //"SELECT equipMhEx, equipOhEx, equipRhEx, equipHead, equipShoulders, equipChest, equipWaist, equipLegs, equipFeet, equipWrist, equipHands, equipBack, equipBody, equipFinger1, equipFinger2, equipTrinket1, equipTrinket2, equipNeck //FROM characters_npcbot WHERE entry = ?", CONNECTION_SYNCH stmt->setUInt32(0, id); PreparedQueryResult res = CharacterDatabase.Query(stmt); ASSERT(res); Field* fields = res->Fetch(); for (uint8 i = 0; i != BOT_INVENTORY_SIZE; ++i) { if (fields[i].GetUInt32()) { handler->PSendSysMessage("%s still has eqipment assigned. Please remove equips before deleting bot!", bot->GetName().c_str()); handler->SetSentErrorMessage(true); return false; } } bot->CombatStop(); bot->DeleteFromDB(); bot->AddObjectToRemoveList(); stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_NPCBOT); //"DELETE FROM characters_npcbot WHERE entry = ?", CONNECTION_ASYNC stmt->setUInt32(0, id); CharacterDatabase.Execute(stmt); handler->SendSysMessage("Npcbot successfully deleted."); return true; }
bool ChatHandler::HandleDeleteCommand(const char* args, WorldSession *m_session) { uint64 guid = m_session->GetPlayer()->GetSelection(); if (guid == 0) { SystemMessage(m_session, "No selection."); return true; } Creature *unit = m_session->GetPlayer()->GetMapMgr()->GetCreature(GET_LOWGUID_PART(guid)); if(!unit) { SystemMessage(m_session, "You should select a creature."); return true; } if ( unit->IsPet() ) { SystemMessage(m_session, "You can't delete a pet." ); return true; } sGMLog.writefromsession(m_session, "used npc delete, sqlid %u, creature %s, pos %f %f %f", unit->GetSQL_id(), unit->GetCreatureInfo() ? unit->GetCreatureInfo()->Name : "wtfbbqhax", unit->GetPositionX(), unit->GetPositionY(), unit->GetPositionZ()); if( unit->m_spawn == NULL ) return false; BlueSystemMessage(m_session, "Deleted creature ID %u", unit->spawnid); if(unit->IsInWorld()) { if(unit->m_spawn) { uint32 cellx=float2int32(((_maxX-unit->m_spawn->x)/_cellSize)); uint32 celly=float2int32(((_maxY-unit->m_spawn->y)/_cellSize)); if(cellx <= _sizeX && celly <= _sizeY) { CellSpawns * c = unit->GetMapMgr()->GetBaseMap()->GetSpawnsListAndCreate(cellx, celly); for(CreatureSpawnList::iterator itr = c->CreatureSpawns.begin(); itr != c->CreatureSpawns.end(); ++itr) if((*itr) == unit->m_spawn) { c->CreatureSpawns.erase(itr); break; } delete unit->m_spawn; } } unit->RemoveFromWorld(false,true); } unit->DeleteFromDB(); delete unit; return true; }
static bool HandleNpcDeleteCommand(ChatHandler* handler, const char* args) { Creature* unit = NULL; if (*args) { // number or [name] Shift-click form |color|Hcreature:creature_guid|h[name]|h|r char* cId = handler->extractKeyFromLink((char*) args, "Hcreature"); if (!cId) return false; uint32 lowguid = atoi(cId); if (!lowguid) return false; if (CreatureData const* cr_data = sObjectMgr->GetCreatureData(lowguid)) unit = handler->GetSession()->GetPlayer()->GetMap()->GetCreature( MAKE_NEW_GUID(lowguid, cr_data->id, HIGHGUID_UNIT)); } else unit = handler->getSelectedCreature(); if (!unit || unit->isPet() || unit->isTotem()) { handler->SendSysMessage(LANG_SELECT_CREATURE); handler->SetSentErrorMessage(true); return false; } QueryResult result; result = WorldDatabase.PQuery("SELECT * FROM creature_spawn WHERE guid='%u' AND account='%u'", unit->GetGUIDLow(), handler->GetSession()->GetAccountId()); if (!result) { handler->PSendSysMessage(LANG_CREATURE_ACCOUNT); handler->SetSentErrorMessage(true); return false; } // Delete the creature unit->CombatStop(); unit->DeleteFromDB(); unit->AddObjectToRemoveList(); handler->SendSysMessage(LANG_COMMAND_DELCREATMESSAGE); sLog->outSQLDev("DELETE FROM creature WHERE guid = %u;", unit->GetGUIDLow()); return true; }
bool ChatHandler::HandleDeleteCommand(const char* args) { Creature *unit = getSelectedCreature(); if(!unit) { SendSysMessage(LANG_SELECT_CREATURE); return true; } unit->CombatStop(); unit->DeleteFromDB(); ObjectAccessor::Instance().AddObjectToRemoveList(unit); SendSysMessage("Creature Removed"); return true; }
bool ChatHandler::HandleDeleteCommand(const char* args, WorldSession *m_session) { uint64 guid = m_session->GetPlayer()->GetSelection(); if (guid == 0) { SystemMessage(m_session, "No selection."); return true; } Creature *unit = m_session->GetPlayer()->GetMapMgr()->GetCreature(guid); if(!unit) { SystemMessage(m_session, "You should select a creature."); return true; } sGMLog.writefromsession(m_session, "used npc delete, sqlid %u, creature %s, pos %f %f %f", unit->GetSQL_id(), unit->GetCreatureName()->Name, unit->GetPositionX(), unit->GetPositionY(), unit->GetPositionZ()); if(unit->m_spawn == 0) return false; BlueSystemMessage(m_session, "Deleted creature ID %u", unit->spawnid); if(unit->IsInWorld()) { if(unit->m_spawn) { uint32 cellx=float2int32(((_maxX-unit->m_spawn->x)/_cellSize)); uint32 celly=float2int32(((_maxY-unit->m_spawn->y)/_cellSize)); unit->GetMapMgr()->GetBaseMap()->GetSpawnsListAndCreate(cellx, celly)->CreatureSpawns.erase(unit->m_spawn); } unit->RemoveFromWorld(false); } unit->DeleteFromDB(); delete unit; return true; }
bool ChatHandler::Command_NPC_Delete (const char* args) { // Just in case, clear waypoint indicators Command_WP_Hide (NULL); WorldPacket data; uint64 guid = m_session->GetPlayer()->GetSelection(); if (guid == 0) { m_session->SystemMessage (LANG_CMD_NOSEL); return true; } Creature *unit = objmgr.GetObject<Creature>(guid); if(!unit) { m_session->SystemMessage (LANG_CMD_NOSEL); return true; } data.Initialize (SMSG_DESTROY_OBJECT); data << unit->GetGUID(); m_session->SendPacket (&data); unit->SendMessageToSet (&data, true); if (unit->GetMapCell()) unit->GetMapCell()->RemoveObject (unit); unit->RemoveFromMap(); unit->RemoveFromWorld(); unit->DeleteFromDB(); objmgr.RemoveObject_Free(unit); return true; }
static bool HandleNpcDeleteCommand(ChatHandler* handler, const char* args) { Creature* unit = NULL; if (*args) { // number or [name] Shift-click form |color|Hcreature:creature_guid|h[name]|h|r char* cId = handler->extractKeyFromLink((char*)args,"Hcreature"); if (!cId) return false; uint32 lowguid = atoi(cId); if (!lowguid) return false; if (CreatureData const* cr_data = sObjectMgr->GetCreatureData(lowguid)) unit = handler->GetSession()->GetPlayer()->GetMap()->GetCreature(MAKE_NEW_GUID(lowguid, cr_data->id, HIGHGUID_UNIT)); } else unit = handler->getSelectedCreature(); if (!unit || unit->isPet() || unit->isTotem()) { handler->SendSysMessage(LANG_SELECT_CREATURE); handler->SetSentErrorMessage(true); return false; } // Delete the creature unit->CombatStop(); unit->DeleteFromDB(); unit->AddObjectToRemoveList(); handler->SendSysMessage(LANG_COMMAND_DELCREATMESSAGE); return true; }
static bool HandleWpShowCommand(ChatHandler* handler, const char* args) { if (!*args) return false; // first arg: on, off, first, last char* show_str = strtok((char*)args, " "); if (!show_str) return false; // second arg: GUID (optional, if a creature is selected) char* guid_str = strtok((char*)NULL, " "); uint32 pathid = 0; Creature* target = handler->getSelectedCreature(); // Did player provide a PathID? if (!guid_str) { // No PathID provided // -> Player must have selected a creature if (!target) { handler->SendSysMessage(LANG_SELECT_CREATURE); handler->SetSentErrorMessage(true); return false; } pathid = target->GetWaypointPath(); } else { // PathID provided // Warn if player also selected a creature // -> Creature selection is ignored <- if (target) handler->SendSysMessage(LANG_WAYPOINT_CREATSELECTED); pathid = atoi((char*)guid_str); } std::string show = show_str; uint32 Maxpoint; //handler->PSendSysMessage("wpshow - show: %s", show); // Show info for the selected waypoint if (show == "info") { // Check if the user did specify a visual waypoint if (target->GetEntry() != VISUAL_WAYPOINT) { handler->PSendSysMessage(LANG_WAYPOINT_VP_SELECT); handler->SetSentErrorMessage(true); return false; } QueryResult result = WorldDatabase.PQuery("SELECT id, point, delay, move_flag, action, action_chance FROM waypoint_data WHERE wpguid = %u", target->GetGUIDLow()); if (!result) { handler->SendSysMessage(LANG_WAYPOINT_NOTFOUNDDBPROBLEM); return true; } handler->SendSysMessage("|cff00ffffDEBUG: wp show info:|r"); do { Field* fields = result->Fetch(); pathid = fields[0].GetUInt32(); uint32 point = fields[1].GetUInt32(); uint32 delay = fields[2].GetUInt32(); uint32 flag = fields[3].GetUInt32(); uint32 ev_id = fields[4].GetUInt32(); uint32 ev_chance = fields[5].GetUInt32(); handler->PSendSysMessage("|cff00ff00Show info: for current point: |r|cff00ffff%u|r|cff00ff00, Path ID: |r|cff00ffff%u|r", point, pathid); handler->PSendSysMessage("|cff00ff00Show info: delay: |r|cff00ffff%u|r", delay); handler->PSendSysMessage("|cff00ff00Show info: Move flag: |r|cff00ffff%u|r", flag); handler->PSendSysMessage("|cff00ff00Show info: Waypoint event: |r|cff00ffff%u|r", ev_id); handler->PSendSysMessage("|cff00ff00Show info: Event chance: |r|cff00ffff%u|r", ev_chance); } while (result->NextRow()); return true; } if (show == "on") { QueryResult result = WorldDatabase.PQuery("SELECT point, position_x, position_y, position_z FROM waypoint_data WHERE id = '%u'", pathid); if (!result) { handler->SendSysMessage("|cffff33ffPath no found.|r"); handler->SetSentErrorMessage(true); return false; } handler->PSendSysMessage("|cff00ff00DEBUG: wp on, PathID: |cff00ffff%u|r", pathid); // Delete all visuals for this NPC QueryResult result2 = WorldDatabase.PQuery("SELECT wpguid FROM waypoint_data WHERE id = '%u' and wpguid <> 0", pathid); if (result2) { bool hasError = false; do { Field* fields = result2->Fetch(); uint32 wpguid = fields[0].GetUInt32(); Creature* creature = handler->GetSession()->GetPlayer()->GetMap()->GetCreature(MAKE_NEW_GUID(wpguid, VISUAL_WAYPOINT, HIGHGUID_UNIT)); if (!creature) { handler->PSendSysMessage(LANG_WAYPOINT_NOTREMOVED, wpguid); hasError = true; PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_DEL_CREATURE); stmt->setUInt32(0, wpguid); WorldDatabase.Execute(stmt); } else { creature->CombatStop(); creature->DeleteFromDB(); creature->AddObjectToRemoveList(); } } while (result2->NextRow()); if (hasError) { handler->PSendSysMessage(LANG_WAYPOINT_TOOFAR1); handler->PSendSysMessage(LANG_WAYPOINT_TOOFAR2); handler->PSendSysMessage(LANG_WAYPOINT_TOOFAR3); } } do { Field* fields = result->Fetch(); uint32 point = fields[0].GetUInt32(); float x = fields[1].GetFloat(); float y = fields[2].GetFloat(); float z = fields[3].GetFloat(); uint32 id = VISUAL_WAYPOINT; Player* chr = handler->GetSession()->GetPlayer(); Map* map = chr->GetMap(); float o = chr->GetOrientation(); Creature* wpCreature = new Creature; if (!wpCreature->Create(sObjectMgr->GenerateLowGuid(HIGHGUID_UNIT), map, chr->GetPhaseMaskForSpawn(), id, 0, 0, x, y, z, o)) { handler->PSendSysMessage(LANG_WAYPOINT_VP_NOTCREATED, id); delete wpCreature; return false; } // Set "wpguid" column to the visual waypoint PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_UPD_WAYPOINT_DATA_WPGUID); stmt->setInt32(0, int32(wpCreature->GetGUIDLow())); stmt->setUInt32(1, pathid); stmt->setUInt32(2, point); WorldDatabase.Execute(stmt); wpCreature->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), chr->GetPhaseMaskForSpawn()); // To call _LoadGoods(); _LoadQuests(); CreateTrainerSpells(); if (!wpCreature->LoadCreatureFromDB(wpCreature->GetDBTableGUIDLow(), map)) { handler->PSendSysMessage(LANG_WAYPOINT_VP_NOTCREATED, id); delete wpCreature; return false; } if (target) { wpCreature->SetDisplayId(target->GetDisplayId()); wpCreature->SetFloatValue(OBJECT_FIELD_SCALE_X, 0.5f); wpCreature->SetLevel(point > STRONG_MAX_LEVEL ? STRONG_MAX_LEVEL : point); } } while (result->NextRow()); handler->SendSysMessage("|cff00ff00Showing the current creature's path.|r"); return true; } if (show == "first") { handler->PSendSysMessage("|cff00ff00DEBUG: wp first, GUID: %u|r", pathid); QueryResult result = WorldDatabase.PQuery("SELECT position_x, position_y, position_z FROM waypoint_data WHERE point='1' AND id = '%u'", pathid); if (!result) { handler->PSendSysMessage(LANG_WAYPOINT_NOTFOUND, pathid); handler->SetSentErrorMessage(true); return false; } Field* fields = result->Fetch(); float x = fields[0].GetFloat(); float y = fields[1].GetFloat(); float z = fields[2].GetFloat(); uint32 id = VISUAL_WAYPOINT; Player* chr = handler->GetSession()->GetPlayer(); float o = chr->GetOrientation(); Map* map = chr->GetMap(); Creature* creature = new Creature; if (!creature->Create(sObjectMgr->GenerateLowGuid(HIGHGUID_UNIT), map, chr->GetPhaseMaskForSpawn(), id, 0, 0, x, y, z, o)) { handler->PSendSysMessage(LANG_WAYPOINT_VP_NOTCREATED, id); delete creature; return false; } creature->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), chr->GetPhaseMaskForSpawn()); if (!creature->LoadCreatureFromDB(creature->GetDBTableGUIDLow(), map)) { handler->PSendSysMessage(LANG_WAYPOINT_VP_NOTCREATED, id); delete creature; return false; } if (target) { creature->SetDisplayId(target->GetDisplayId()); creature->SetFloatValue(OBJECT_FIELD_SCALE_X, 0.5f); } return true; } if (show == "last") { handler->PSendSysMessage("|cff00ff00DEBUG: wp last, PathID: |r|cff00ffff%u|r", pathid); QueryResult result = WorldDatabase.PQuery("SELECT MAX(point) FROM waypoint_data WHERE id = '%u'", pathid); if (result) Maxpoint = (*result)[0].GetUInt32(); else Maxpoint = 0; result = WorldDatabase.PQuery("SELECT position_x, position_y, position_z, orientation FROM waypoint_data WHERE point ='%u' AND id = '%u'", Maxpoint, pathid); if (!result) { handler->PSendSysMessage(LANG_WAYPOINT_NOTFOUNDLAST, pathid); handler->SetSentErrorMessage(true); return false; } Field* fields = result->Fetch(); float x = fields[0].GetFloat(); float y = fields[1].GetFloat(); float z = fields[2].GetFloat(); float o = fields[3].GetFloat(); uint32 id = VISUAL_WAYPOINT; Player* chr = handler->GetSession()->GetPlayer(); Map* map = chr->GetMap(); Creature* creature = new Creature; if (!creature->Create(sObjectMgr->GenerateLowGuid(HIGHGUID_UNIT), map, chr->GetPhaseMaskForSpawn(), id, 0, 0, x, y, z, o)) { handler->PSendSysMessage(LANG_WAYPOINT_NOTCREATED, id); delete creature; return false; } creature->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), chr->GetPhaseMaskForSpawn()); if (!creature->LoadCreatureFromDB(creature->GetDBTableGUIDLow(), map)) { handler->PSendSysMessage(LANG_WAYPOINT_NOTCREATED, id); delete creature; return false; } if (target) { creature->SetDisplayId(target->GetDisplayId()); creature->SetFloatValue(OBJECT_FIELD_SCALE_X, 0.5f); } return true; } if (show == "off") { QueryResult result = WorldDatabase.PQuery("SELECT guid FROM creature WHERE id = '%u'", 1); if (!result) { handler->SendSysMessage(LANG_WAYPOINT_VP_NOTFOUND); handler->SetSentErrorMessage(true); return false; } bool hasError = false; do { Field* fields = result->Fetch(); uint32 guid = fields[0].GetUInt32(); Creature* creature = handler->GetSession()->GetPlayer()->GetMap()->GetCreature(MAKE_NEW_GUID(guid, VISUAL_WAYPOINT, HIGHGUID_UNIT)); if (!creature) { handler->PSendSysMessage(LANG_WAYPOINT_NOTREMOVED, guid); hasError = true; PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_DEL_CREATURE); stmt->setUInt32(0, guid); WorldDatabase.Execute(stmt); } else { creature->CombatStop(); creature->DeleteFromDB(); creature->AddObjectToRemoveList(); } } while (result->NextRow()); // set "wpguid" column to "empty" - no visual waypoint spawned PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WOLRD_UPD_ALL_WAYPOINT_DATA_WPGUID); WorldDatabase.Execute(stmt); //WorldDatabase.PExecute("UPDATE creature_movement SET wpguid = '0' WHERE wpguid <> '0'"); if (hasError) { handler->PSendSysMessage(LANG_WAYPOINT_TOOFAR1); handler->PSendSysMessage(LANG_WAYPOINT_TOOFAR2); handler->PSendSysMessage(LANG_WAYPOINT_TOOFAR3); } handler->SendSysMessage(LANG_WAYPOINT_VP_ALLREMOVED); return true; } handler->PSendSysMessage("|cffff33ffDEBUG: wpshow - no valid command found|r"); return true; }
static bool HandleWpModifyCommand(ChatHandler* handler, const char* args) { if (!*args) return false; // first arg: add del text emote spell waittime move char* show_str = strtok((char*)args, " "); if (!show_str) { return false; } std::string show = show_str; // Check // Remember: "show" must also be the name of a column! if ((show != "delay") && (show != "action") && (show != "action_chance") && (show != "move_flag") && (show != "del") && (show != "move") && (show != "wpadd") ) { return false; } // Next arg is: <PATHID> <WPNUM> <ARGUMENT> char* arg_str = NULL; // Did user provide a GUID // or did the user select a creature? // -> variable lowguid is filled with the GUID of the NPC uint32 pathid = 0; uint32 point = 0; uint32 wpGuid = 0; Creature* target = handler->getSelectedCreature(); if (!target || target->GetEntry() != VISUAL_WAYPOINT) { handler->SendSysMessage("|cffff33ffERROR: You must select a waypoint.|r"); return false; } // The visual waypoint wpGuid = target->GetGUIDLow(); // User did select a visual waypoint? // Check the creature QueryResult result = WorldDatabase.PQuery("SELECT id, point FROM waypoint_data WHERE wpguid = %u", wpGuid); if (!result) { handler->PSendSysMessage(LANG_WAYPOINT_NOTFOUNDSEARCH, target->GetGUIDLow()); // Select waypoint number from database // Since we compare float values, we have to deal with // some difficulties. // Here we search for all waypoints that only differ in one from 1 thousand // (0.001) - There is no other way to compare C++ floats with mySQL floats // See also: http://dev.mysql.com/doc/refman/5.0/en/problems-with-float.html const char* maxDIFF = "0.01"; result = WorldDatabase.PQuery("SELECT id, point FROM waypoint_data WHERE (abs(position_x - %f) <= %s) and (abs(position_y - %f) <= %s) and (abs(position_z - %f) <= %s)", target->GetPositionX(), maxDIFF, target->GetPositionY(), maxDIFF, target->GetPositionZ(), maxDIFF); if (!result) { handler->PSendSysMessage(LANG_WAYPOINT_NOTFOUNDDBPROBLEM, wpGuid); return true; } } do { Field* fields = result->Fetch(); pathid = fields[0].GetUInt32(); point = fields[1].GetUInt32(); } while (result->NextRow()); // We have the waypoint number and the GUID of the "master npc" // Text is enclosed in "<>", all other arguments not arg_str = strtok((char*)NULL, " "); // Check for argument if (show != "del" && show != "move" && arg_str == NULL) { handler->PSendSysMessage(LANG_WAYPOINT_ARGUMENTREQ, show_str); return false; } if (show == "del" && target) { handler->PSendSysMessage("|cff00ff00DEBUG: wp modify del, PathID: |r|cff00ffff%u|r", pathid); // wpCreature Creature* wpCreature = NULL; if (wpGuid != 0) { wpCreature = handler->GetSession()->GetPlayer()->GetMap()->GetCreature(MAKE_NEW_GUID(wpGuid, VISUAL_WAYPOINT, HIGHGUID_UNIT)); wpCreature->CombatStop(); wpCreature->DeleteFromDB(); wpCreature->AddObjectToRemoveList(); } PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_DEL_WAYPOINT_DATA); stmt->setUInt32(0, pathid); stmt->setUInt32(1, point); WorldDatabase.Execute(stmt); stmt = WorldDatabase.GetPreparedStatement(WORLD_UPD_WAYPOINT_DATA_POINT); stmt->setUInt32(0, pathid); stmt->setUInt32(1, point); WorldDatabase.Execute(stmt); handler->PSendSysMessage(LANG_WAYPOINT_REMOVED); return true; } // del if (show == "move" && target) { handler->PSendSysMessage("|cff00ff00DEBUG: wp move, PathID: |r|cff00ffff%u|r", pathid); Player* chr = handler->GetSession()->GetPlayer(); Map* map = chr->GetMap(); { // wpCreature Creature* wpCreature = NULL; // What to do: // Move the visual spawnpoint // Respawn the owner of the waypoints if (wpGuid != 0) { wpCreature = handler->GetSession()->GetPlayer()->GetMap()->GetCreature(MAKE_NEW_GUID(wpGuid, VISUAL_WAYPOINT, HIGHGUID_UNIT)); wpCreature->CombatStop(); wpCreature->DeleteFromDB(); wpCreature->AddObjectToRemoveList(); // re-create Creature* wpCreature2 = new Creature; if (!wpCreature2->Create(sObjectMgr->GenerateLowGuid(HIGHGUID_UNIT), map, chr->GetPhaseMaskForSpawn(), VISUAL_WAYPOINT, 0, 0, chr->GetPositionX(), chr->GetPositionY(), chr->GetPositionZ(), chr->GetOrientation())) { handler->PSendSysMessage(LANG_WAYPOINT_VP_NOTCREATED, VISUAL_WAYPOINT); delete wpCreature2; return false; } wpCreature2->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), chr->GetPhaseMaskForSpawn()); // To call _LoadGoods(); _LoadQuests(); CreateTrainerSpells(); //TODO: Should we first use "Create" then use "LoadFromDB"? if (!wpCreature2->LoadCreatureFromDB(wpCreature2->GetDBTableGUIDLow(), map)) { handler->PSendSysMessage(LANG_WAYPOINT_VP_NOTCREATED, VISUAL_WAYPOINT); delete wpCreature2; return false; } //sMapMgr->GetMap(npcCreature->GetMapId())->Add(wpCreature2); } PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_UPD_WAYPOINT_DATA_POSITION); stmt->setFloat(0, chr->GetPositionX()); stmt->setFloat(1, chr->GetPositionY()); stmt->setFloat(2, chr->GetPositionZ()); stmt->setUInt32(3, pathid); stmt->setUInt32(4, point); WorldDatabase.Execute(stmt); handler->PSendSysMessage(LANG_WAYPOINT_CHANGED); } return true; } // move const char *text = arg_str; if (text == 0) { // show_str check for present in list of correct values, no sql injection possible WorldDatabase.PExecute("UPDATE waypoint_data SET %s=NULL WHERE id='%u' AND point='%u'", show_str, pathid, point); // Query can't be a prepared statement } else { // show_str check for present in list of correct values, no sql injection possible std::string text2 = text; WorldDatabase.EscapeString(text2); WorldDatabase.PExecute("UPDATE waypoint_data SET %s='%s' WHERE id='%u' AND point='%u'", show_str, text2.c_str(), pathid, point); // Query can't be a prepared statement } handler->PSendSysMessage(LANG_WAYPOINT_CHANGED_NO, show_str); return true; }
void Spell::Effect_Summon_Pet(uint32 i) { WorldPacket data; if(m_caster->GetUInt64Value(UNIT_FIELD_SUMMON) != 0)//If there is already a summon { Creature *OldSummon = objmgr.GetObject<Creature>(m_caster->GetUInt64Value(UNIT_FIELD_SUMMON)); if(!OldSummon) { m_caster->SetUInt64Value(UNIT_FIELD_SUMMON, 0); sLog.outError("Warning!Old Summon could not be found!"); } else { data.clear(); data.Initialize(SMSG_DESTROY_OBJECT); data << OldSummon->GetGUID(); OldSummon->SendMessageToSet (&data, true); if (OldSummon->GetMapCell()) OldSummon->GetMapCell()->RemoveObject (OldSummon); OldSummon->RemoveFromMap(); OldSummon->RemoveFromWorld(); OldSummon->DeleteFromDB(); objmgr.RemoveObject_Free(OldSummon); } } //Create new summon Creature *NewSummon = new Creature(); CreatureTemplate *SummonInfo = objmgr.GetCreatureTemplate(m_spellInfo->EffectMiscValue[i]); if(SummonInfo == NULL) { sLog.outError("No Minion found for CreatureTemplate %u", m_spellInfo->EffectMiscValue[i]); return; } NewSummon->Create(objmgr.GenerateLowGuid(HIGHGUID_UNIT), SummonInfo->Name.c_str(), m_caster->GetMapId(), m_caster->GetPositionX(), m_caster->GetPositionY(), m_caster->GetPositionZ(), m_caster->GetOrientation()); NewSummon->SetLevel(m_caster->GetLevel()); NewSummon->SetUInt32Value(UNIT_FIELD_DISPLAYID, SummonInfo->Model); NewSummon->SetUInt32Value(UNIT_FIELD_NATIVEDISPLAYID, SummonInfo->Model); NewSummon->SetUInt64Value(UNIT_FIELD_SUMMONEDBY, m_caster->GetGUID()); NewSummon->SetUInt32Value(UNIT_NPC_FLAGS , 0); NewSummon->SetUInt32Value(UNIT_FIELD_HEALTH , 28 + 30 * m_caster->GetLevel()); NewSummon->SetUInt32Value(UNIT_FIELD_MAXHEALTH , 28 + 30 * m_caster->GetLevel()); NewSummon->SetFaction(m_caster->GetFaction()); NewSummon->SetScale( SummonInfo->Size ); NewSummon->SetUInt32Value(UNIT_FIELD_BYTES_0,2048); NewSummon->SetUInt32Value(UNIT_FIELD_FLAGS, UNIT_FLAG_NONE); NewSummon->SetUInt32Value(UNIT_FIELD_BASEATTACKTIME, SummonInfo->Attack[0]); NewSummon->SetUInt32Value(UNIT_FIELD_BASEATTACKTIME+1, SummonInfo->Attack[1]); NewSummon->SetUInt32Value(UNIT_FIELD_BOUNDINGRADIUS, SummonInfo->BoundingRadius); NewSummon->SetUInt32Value(UNIT_FIELD_COMBATREACH, SummonInfo->CombatReach); NewSummon->SetMinDamage((float)SummonInfo->Damage[0]); NewSummon->SetMaxDamage((float)SummonInfo->Damage[1]); NewSummon->SetUInt32Value(UNIT_FIELD_BYTES_1,0); NewSummon->SetUInt32Value(UNIT_FIELD_PETNUMBER, NewSummon->GetGUIDLow()); NewSummon->SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP,5); NewSummon->SetUInt32Value(UNIT_FIELD_PETEXPERIENCE,0); NewSummon->SetUInt32Value(UNIT_FIELD_PETNEXTLEVELEXP,1000); NewSummon->SetUInt32Value(UNIT_CREATED_BY_SPELL, m_spellInfo->Id); NewSummon->SetUInt32Value(UNIT_FIELD_STAT0,22); NewSummon->SetUInt32Value(UNIT_FIELD_STAT1,22); //////////TODO: GET THE RIGHT INFORMATIONS FOR THIS!!! NewSummon->SetUInt32Value(UNIT_FIELD_STAT2,25); NewSummon->SetUInt32Value(UNIT_FIELD_STAT3,28); NewSummon->SetUInt32Value(UNIT_FIELD_STAT4,27); NewSummon->SetUInt32Value(UNIT_FIELD_RESISTANCES+0,0); NewSummon->SetUInt32Value(UNIT_FIELD_RESISTANCES+1,0); NewSummon->SetUInt32Value(UNIT_FIELD_RESISTANCES+2,0); NewSummon->SetUInt32Value(UNIT_FIELD_RESISTANCES+3,0); NewSummon->SetUInt32Value(UNIT_FIELD_RESISTANCES+4,0); NewSummon->SetUInt32Value(UNIT_FIELD_RESISTANCES+5,0); NewSummon->SetUInt32Value(UNIT_FIELD_RESISTANCES+6,0); NewSummon->SetUInt32Value(UNIT_FIELD_ATTACK_POWER,24); NewSummon->SetUInt32Value(UNIT_FIELD_BASE_MANA, SummonInfo->MaxMana); NewSummon->SetUInt32Value(OBJECT_FIELD_ENTRY, SummonInfo->Entry); NewSummon->SetPosition(m_caster->GetPositionX(), m_caster->GetPositionY(), m_caster->GetPositionZ(), m_caster->GetOrientation()); NewSummon->SetZoneId(m_caster->GetZoneId()); NewSummon->SaveToDB(); objmgr.AddObject( NewSummon ); NewSummon->PlaceOnMap(); NewSummon->AddToWorld(); m_caster->SetUInt64Value(UNIT_FIELD_SUMMON, NewSummon->GetGUID()); sLog.outDebug("New Pet has guid %u", NewSummon->GetGUID()); if(objmgr.GetObject<Player>(m_caster->GetGUID()) )//if the caster is a player { data.clear(); data.Initialize(SMSG_PET_SPELLS); data << (uint64)NewSummon->GetGUID() << uint32(0x00000101) << uint32(0x00000000) << uint32(0x07000001) << uint32(0x07000002); data << uint32(0x02000000) << uint32(0x07000000) << uint32(0x04000000) << uint32(0x03000000) << uint32(0x06000002) << uint32(0x05000000); data << uint32(0x06000000) << uint32(0x06000001) << uint8(0x02)/*Number of spells*/ << uint32(3110)/*SpellID1*/ << uint32(6307)/*SpellID2*/; ((Player*)m_caster)->GetSession()->SendPacket(&data); } }
bool ChatHandler::HandleDeleteCommand(const char* args, WorldSession *m_session) { uint64 guid = m_session->GetPlayer()->GetSelection(); if (guid == 0) { SystemMessage(m_session, "No selection."); return true; } Creature* unit = NULL; if(m_session->GetPlayer()->GetMapMgr()->GetVehicle(GET_LOWGUID_PART(guid))) unit = m_session->GetPlayer()->GetMapMgr()->GetVehicle(GET_LOWGUID_PART(guid)); else unit = m_session->GetPlayer()->GetMapMgr()->GetCreature(GET_LOWGUID_PART(guid)); if(!unit) { SystemMessage(m_session, "You should select a creature."); return true; } if( unit->m_spawn != NULL && !m_session->CanUseCommand('z') ) { SystemMessage(m_session, "You do not have permission to do that. Please contact higher staff for removing of saved spawns."); return true; } if(unit->GetAIInterface()) unit->GetAIInterface()->StopMovement(10000); if(unit->IsVehicle()) { Vehicle* veh = TO_VEHICLE(unit); for(int i = 0; i < 8; i++) { if(!veh->GetPassenger(i)) continue; // Remove any players if(veh->GetPassenger(i)->IsPlayer()) veh->RemovePassenger(veh->GetPassenger(i)); else // Remove any units. veh->GetPassenger(i)->RemoveFromWorld(true); } } sGMLog.writefromsession(m_session, "used npc delete, sqlid %u, creature %s, pos %f %f %f", unit->m_spawn ? unit->m_spawn : 0, unit->GetCreatureInfo() ? unit->GetCreatureInfo()->Name : "wtfbbqhax", unit->GetPositionX(), unit->GetPositionY(), unit->GetPositionZ()); BlueSystemMessage(m_session, "Deleted creature ID %u", unit->spawnid); MapMgr* unitMgr = unit->GetMapMgr(); unit->DeleteFromDB(); if(!unit->IsInWorld()) return true; if(unit->m_spawn) { uint32 cellx=float2int32(((_maxX-unit->m_spawn->x)/_cellSize)); uint32 celly=float2int32(((_maxY-unit->m_spawn->y)/_cellSize)); if(cellx <= _sizeX && celly <= _sizeY && unitMgr != NULL) { CellSpawns * c = unitMgr->GetBaseMap()->GetSpawnsList(cellx, celly); if( c != NULL ) { CreatureSpawnList::iterator itr, itr2; for(itr = c->CreatureSpawns.begin(); itr != c->CreatureSpawns.end();) { itr2 = itr; ++itr; if((*itr2) == unit->m_spawn) { c->CreatureSpawns.erase(itr2); delete unit->m_spawn; break; } } } } } unit->RemoveFromWorld(false,true); if(unit->IsVehicle()) TO_VEHICLE(unit)->Destructor(); else unit->Destructor(); return true; }
bool ChatHandler::HandleDeleteCommand(const char* args, WorldSession *m_session) { Creature* unit = getSelectedCreature(m_session, false); if(!unit) { SystemMessage(m_session, "You should select a creature."); return true; } else if(unit->IsPet() || unit->IsSummon()) { SystemMessage(m_session, "You can't delete playerpets."); return true; } if( unit->m_spawn != NULL && !m_session->CanUseCommand('z') ) { SystemMessage(m_session, "You do not have permission to do that. Please contact higher staff for removing of saved spawns."); return true; } if(unit->IsVehicle()) { Vehicle* veh = TO_VEHICLE(unit); for(int i = 0; i < 8; i++) { if(!veh->GetPassenger(i)) continue; // Remove any players if(veh->GetPassenger(i)->IsPlayer()) veh->RemovePassenger(veh->GetPassenger(i)); else // Remove any units. veh->GetPassenger(i)->RemoveFromWorld(true); } } sWorld.LogGM(m_session, "used npc delete, sqlid %u, creature %s, pos %f %f %f", unit->m_spawn ? unit->m_spawn->id : 0, unit->GetCreatureInfo() ? unit->GetCreatureInfo()->Name : "wtfbbqhax", unit->GetPositionX(), unit->GetPositionY(), unit->GetPositionZ()); BlueSystemMessage(m_session, "Deleted creature ID %u", unit->spawnid); unit->DeleteFromDB(); if(!unit->IsInWorld()) return true; MapMgr* unitMgr = unit->GetMapMgr(); if(unit->m_spawn) { uint32 cellx = unitMgr->GetPosX(unit->m_spawn->x); uint32 celly = unitMgr->GetPosX(unit->m_spawn->y); if(cellx <= _sizeX && celly <= _sizeY ) { CellSpawns *c = unitMgr->GetBaseMap()->GetSpawnsList(cellx, celly); if( c != NULL ) { CreatureSpawnList::iterator itr, itr2; for(itr = c->CreatureSpawns.begin(); itr != c->CreatureSpawns.end();) { itr2 = itr++; if((*itr2) == unit->m_spawn) { c->CreatureSpawns.erase(itr2); delete unit->m_spawn; break; } } } } } unit->RemoveFromWorld(false, true); if(unit->IsVehicle()) TO_VEHICLE(unit)->Destruct(); else unit->Destruct(); m_session->GetPlayer()->SetSelection(NULL); return true; }