BotCommands.cpp 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823
  1. #include "../Commands/Commands.h"
  2. #include "../WorldDatabase.h"
  3. #include "../classes.h"
  4. #include "../races.h"
  5. #include "../Bots/Bot.h"
  6. #include "../../common/Log.h"
  7. #include "../Trade.h"
  8. #include "../PlayerGroups.h"
  9. #include "../World.h"
  10. #include "../../common/GlobalHeaders.h"
  11. extern WorldDatabase database;
  12. extern ConfigReader configReader;
  13. extern World world;
  14. extern MasterSpellList master_spell_list;
  15. void Commands::Command_Bot(Client* client, Seperator* sep) {
  16. if (sep && sep->IsSet(0)) {
  17. if (strncasecmp("camp", sep->arg[0], 4) == 0) {
  18. if (!client->GetPlayer()->GetTarget() || !client->GetPlayer()->GetTarget()->IsBot()) {
  19. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You must target a bot");
  20. return;
  21. }
  22. Bot* bot = (Bot*)client->GetPlayer()->GetTarget();
  23. if (bot->GetOwner() != client->GetPlayer()) {
  24. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You can only camp your own bots.");
  25. return;
  26. }
  27. bot->Camp();
  28. return;
  29. }
  30. else if (strncasecmp("attack", sep->arg[0], 6) == 0) {
  31. if (client->GetPlayer()->GetTarget() && client->GetPlayer()->GetTarget()->IsEntity() && client->GetPlayer()->GetTarget()->Alive()) {
  32. Entity* target = (Entity*)client->GetPlayer()->GetTarget();
  33. if (client->GetPlayer()->GetDistance(target) <= 50) {
  34. if (client->GetPlayer()->AttackAllowed(target)) {
  35. GroupMemberInfo* gmi = client->GetPlayer()->GetGroupMemberInfo();
  36. if (gmi) {
  37. PlayerGroup* group = world.GetGroupManager()->GetGroup(gmi->group_id);
  38. if (group)
  39. {
  40. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  41. deque<GroupMemberInfo*>* members = group->GetMembers();
  42. deque<GroupMemberInfo*>::iterator itr;
  43. if(!members)
  44. return;
  45. for (itr = members->begin(); itr != members->end(); itr++) {
  46. if ((*itr)->member->IsBot() && ((Bot*)(*itr)->member)->GetOwner() == client->GetPlayer()) {
  47. ((Bot*)(*itr)->member)->SetCombatTarget(target->GetID());
  48. }
  49. }
  50. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  51. }
  52. }
  53. }
  54. else
  55. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You can not attack that target.");
  56. }
  57. else
  58. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "Target is to far away.");
  59. }
  60. else
  61. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "Not a valid target.");
  62. return;
  63. }
  64. else if (strncasecmp("spells", sep->arg[0], 6) == 0) {
  65. if (client->GetPlayer()->GetTarget() && client->GetPlayer()->GetTarget()->IsBot()) {
  66. Bot* bot = (Bot*)client->GetPlayer()->GetTarget();
  67. map<int32, int8>* spells = bot->GetBotSpells();
  68. map<int32, int8>::iterator itr;
  69. string output;
  70. for (itr = spells->begin(); itr != spells->end(); itr++) {
  71. Spell* spell = master_spell_list.GetSpell(itr->first, itr->second);
  72. if (spell) {
  73. output += spell->GetName();
  74. output += "\n";
  75. }
  76. }
  77. client->SimpleMessage(CHANNEL_COLOR_YELLOW, output.c_str());
  78. return;
  79. }
  80. }
  81. else if (strncasecmp("maintank", sep->arg[0], 8) == 0) {
  82. if (!client->GetPlayer()->GetTarget() || !client->GetPlayer()->GetTarget()->IsEntity()) {
  83. client->SimpleMessage(CHANNEL_COMMAND_TEXT, "Not a valid target.");
  84. return;
  85. }
  86. GroupMemberInfo* gmi = client->GetPlayer()->GetGroupMemberInfo();
  87. if (!gmi) {
  88. client->SimpleMessage(CHANNEL_COMMAND_TEXT, "You are not in a group.");
  89. return;
  90. }
  91. Entity* target = (Entity*)client->GetPlayer()->GetTarget();
  92. if (!world.GetGroupManager()->IsInGroup(gmi->group_id, target)) {
  93. client->SimpleMessage(CHANNEL_COMMAND_TEXT, "Target is not in your group.");
  94. return;
  95. }
  96. PlayerGroup* group = world.GetGroupManager()->GetGroup(gmi->group_id);
  97. if (group)
  98. {
  99. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  100. deque<GroupMemberInfo*>* members = group->GetMembers();
  101. if(!members)
  102. return;
  103. for (int8 i = 0; i < members->size(); i++) {
  104. GroupMemberInfo* gmi2 = members->at(i);
  105. if (gmi2->member->IsBot() && ((Bot*)gmi2->member)->GetOwner() == client->GetPlayer()) {
  106. ((Bot*)gmi2->member)->SetMainTank(target);
  107. client->Message(CHANNEL_COMMAND_TEXT, "Setting main tank for %s to %s", gmi2->member->GetName(), target->GetName());
  108. }
  109. }
  110. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  111. }
  112. return;
  113. }
  114. else if (strncasecmp("delete", sep->arg[0], 6) == 0) {
  115. if (sep->IsSet(1) && sep->IsNumber(1)) {
  116. int32 index = atoi(sep->arg[1]);
  117. // Check if bot is currently spawned and if so camp it out
  118. if (client->GetPlayer()->SpawnedBots.count(index) > 0) {
  119. Spawn* bot = client->GetCurrentZone()->GetSpawnByID(client->GetPlayer()->SpawnedBots[index]);
  120. if (bot && bot->IsBot())
  121. ((Bot*)bot)->Camp();
  122. }
  123. database.DeleteBot(client->GetCharacterID(), index);
  124. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "Bot has been deleted.");
  125. return;
  126. }
  127. else {
  128. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You must give the id (from /bot list) to delete a bot");
  129. return;
  130. }
  131. }
  132. else if (strncasecmp("follow", sep->arg[0], 6) == 0) {
  133. if (sep->IsSet(1) && sep->IsNumber(1)) {
  134. int32 index = atoi(sep->arg[1]);
  135. // Check if bot is currently spawned and if so camp it out
  136. if (client->GetPlayer()->SpawnedBots.count(index) > 0) {
  137. Spawn* bot = client->GetCurrentZone()->GetSpawnByID(client->GetPlayer()->SpawnedBots[index]);
  138. if (bot && bot->IsBot())
  139. ((Bot*)bot)->SetFollowTarget(client->GetPlayer(), 5);
  140. }
  141. return;
  142. }
  143. else {
  144. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You must give the id (from /bot list) to have a bot follow you");
  145. return;
  146. }
  147. }
  148. else if (strncasecmp("stopfollow", sep->arg[0], 10) == 0) {
  149. if (sep->IsSet(1) && sep->IsNumber(1)) {
  150. int32 index = atoi(sep->arg[1]);
  151. // Check if bot is currently spawned and if so camp it out
  152. if (client->GetPlayer()->SpawnedBots.count(index) > 0) {
  153. Spawn* bot = client->GetCurrentZone()->GetSpawnByID(client->GetPlayer()->SpawnedBots[index]);
  154. if (bot && bot->IsBot())
  155. ((Bot*)bot)->SetFollowTarget(nullptr);
  156. }
  157. return;
  158. }
  159. else {
  160. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You must give the id (from /bot list) to stop a following bot");
  161. return;
  162. }
  163. }
  164. else if (strncasecmp("summon", sep->arg[0], 6) == 0) {
  165. if (sep->IsSet(1) && strncasecmp("group", sep->arg[1], 5) == 0) {
  166. GroupMemberInfo* gmi = client->GetPlayer()->GetGroupMemberInfo();
  167. if (gmi) {
  168. Player* player = client->GetPlayer();
  169. PlayerGroup* group = world.GetGroupManager()->GetGroup(gmi->group_id);
  170. if (group)
  171. {
  172. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  173. deque<GroupMemberInfo*>* members = group->GetMembers();
  174. for (int8 i = 0; i < members->size(); i++) {
  175. Entity* member = members->at(i)->member;
  176. if(!member)
  177. continue;
  178. if (member->IsBot() && ((Bot*)member)->GetOwner() == player) {
  179. member->appearance.pos.grid_id = player->appearance.pos.grid_id;
  180. member->SetX(player->GetX());
  181. member->SetY(player->GetY());
  182. member->SetZ(player->GetZ());
  183. client->Message(CHANNEL_COLOR_YELLOW, "Summoning %s.", member->GetName());
  184. }
  185. }
  186. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  187. }
  188. return;
  189. }
  190. else {
  191. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You are not in a group.");
  192. return;
  193. }
  194. }
  195. else {
  196. if (client->GetPlayer()->GetTarget() && client->GetPlayer()->GetTarget()->IsBot()) {
  197. Bot* bot = (Bot*)client->GetPlayer()->GetTarget();
  198. Player* player = client->GetPlayer();
  199. if (bot && bot->GetOwner() == player) {
  200. bot->appearance.pos.grid_id = player->appearance.pos.grid_id;
  201. bot->SetX(player->GetX());
  202. bot->SetY(player->GetY());
  203. bot->SetZ(player->GetZ());
  204. client->Message(CHANNEL_COLOR_YELLOW, "Summoning %s.", bot->GetName());
  205. return;
  206. }
  207. else {
  208. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You can only summon your own bots.");
  209. return;
  210. }
  211. }
  212. else {
  213. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You must target a bot.");
  214. return;
  215. }
  216. }
  217. }
  218. else if (strncasecmp("test", sep->arg[0], 4) == 0) {
  219. if (client->GetPlayer()->GetTarget() && client->GetPlayer()->GetTarget()->IsBot()) {
  220. ((Bot*)client->GetPlayer()->GetTarget())->MessageGroup("Test message");
  221. return;
  222. }
  223. }
  224. }
  225. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "BotCommands:");
  226. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "/bot create [race] [gender] [class] [name]");
  227. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "/bot customize - customize the appearance of the bot");
  228. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "/bot list - list all the bots you have created with this character");
  229. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "/bot spawn [id] - spawns a bot into the world, id obtained from /bot list");
  230. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "/bot inv [give/list/remove] - manage bot equipment, for remove a slot must be provided");
  231. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "/bot settings [helm/hood/cloak/taunt] [0/1] - Turn setting on (1) or off(0)");
  232. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "/bot camp - removes the bot from your group and despawns them");
  233. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "/bot attack - commands your bots to attack your target");
  234. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "/bot spells - lists bot spells, not fully implemented yet");
  235. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "/bot maintank - sets targeted group member as the main tank for your bots");
  236. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "/bot delete [id] - deletes the bot with the given id (obtained from /bot list)");
  237. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "/bot help");
  238. }
  239. void Commands::Command_Bot_Create(Client* client, Seperator* sep) {
  240. int8 race = BARBARIAN;
  241. int8 gender = 0;
  242. int8 advClass = GUARDIAN;
  243. string name;
  244. if (sep) {
  245. if (sep->IsSet(0) && sep->IsNumber(0))
  246. race = atoi(sep->arg[0]);
  247. else {
  248. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "First param of \"/bot create\" needs to be a number");
  249. return;
  250. }
  251. if (sep->IsSet(1) && sep->IsNumber(1))
  252. gender = atoi(sep->arg[1]);
  253. else {
  254. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "Second param of \"/bot create\" needs to be a number");
  255. return;
  256. }
  257. if (sep->IsSet(2) && sep->IsNumber(2))
  258. advClass = atoi(sep->arg[2]);
  259. else {
  260. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "Third param of \"/bot create\" needs to be a number");
  261. return;
  262. }
  263. if (sep->IsSet(3)) {
  264. name = string(sep->arg[3]);
  265. transform(name.begin(), name.begin() + 1, name.begin(), ::toupper);
  266. transform(name.begin() + 1, name.end(), name.begin() + 1, ::tolower);
  267. }
  268. else {
  269. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "Fourth param (name) of \"/bot create\" is required");
  270. return;
  271. }
  272. }
  273. else {
  274. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "Syntax: /bot create [race ID] [Gender ID] [class ID] [name]");
  275. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "All parameters are required. /bot help race or /bot help class for ID's.");
  276. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "Gender ID's: 0 = Female, 1 = Male");
  277. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "Ex: /bot create 0 0 3 Botty");
  278. return;
  279. }
  280. int8 result = database.CheckNameFilter(name.c_str());
  281. if (result == BADNAMELENGTH_REPLY) {
  282. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "Name length is invalid, must be greater then 3 characters and less then 16.");
  283. return;
  284. }
  285. else if (result == NAMEINVALID_REPLY) {
  286. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "Name is invalid, can only contain letters.");
  287. return;
  288. }
  289. else if (result == NAMETAKEN_REPLY) {
  290. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "Name is already taken, please choose another.");
  291. return;
  292. }
  293. else if (result == NAMEFILTER_REPLY) {
  294. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "Name failed the filter check.");
  295. return;
  296. }
  297. else if (result == UNKNOWNERROR_REPLY) {
  298. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "Unknown error while checking the name.");
  299. return;
  300. }
  301. string race_string;
  302. switch (race) {
  303. case BARBARIAN:
  304. race_string = "/barbarian/barbarian";
  305. break;
  306. case DARK_ELF:
  307. race_string = "/darkelf/darkelf";
  308. break;
  309. case DWARF:
  310. race_string = "/dwarf/dwarf";
  311. break;
  312. case ERUDITE:
  313. race_string = "/erudite/erudite";
  314. break;
  315. case FROGLOK:
  316. race_string = "/froglok/froglok";
  317. break;
  318. case GNOME:
  319. race_string = "/gnome/gnome";
  320. break;
  321. case HALF_ELF:
  322. race_string = "/halfelf/halfelf";
  323. break;
  324. case HALFLING:
  325. race_string = "/halfling/halfling";
  326. break;
  327. case HIGH_ELF:
  328. race_string = "/highelf/highelf";
  329. break;
  330. case HUMAN:
  331. race_string = "/human/human";
  332. break;
  333. case IKSAR:
  334. race_string = "/iksar/iksar";
  335. break;
  336. case KERRA:
  337. race_string = "/kerra/kerra";
  338. break;
  339. case OGRE:
  340. race_string = "/ogre/ogre";
  341. break;
  342. case RATONGA:
  343. race_string = "/ratonga/ratonga";
  344. break;
  345. case TROLL:
  346. race_string = "/troll/troll";
  347. break;
  348. case WOOD_ELF:
  349. race_string = "/woodelf/woodelf";
  350. break;
  351. case FAE:
  352. race_string = "/fae/fae_light";
  353. break;
  354. case ARASAI:
  355. race_string = "/fae/fae_dark";
  356. break;
  357. case SARNAK:
  358. gender == 1 ? race_string = "01/sarnak_male/sarnak" : race_string = "01/sarnak_female/sarnak";
  359. break;
  360. case VAMPIRE:
  361. race_string = "/vampire/vampire";
  362. break;
  363. case AERAKYN:
  364. race_string = "/aerakyn/aerakyn";
  365. break;
  366. }
  367. if (race_string.length() > 0) {
  368. string gender_string;
  369. Bot* bot = 0;
  370. gender == 1 ? gender_string = "male" : gender_string = "female";
  371. vector<int16>* id_list = database.GetAppearanceIDsLikeName("ec/pc" + race_string + "_" + gender_string);
  372. if (id_list) {
  373. bot = new Bot();
  374. memset(&bot->appearance, 0, sizeof(bot->appearance));
  375. bot->appearance.pos.collision_radius = 32;
  376. bot->secondary_command_list_id = 0;
  377. bot->primary_command_list_id = 0;
  378. bot->appearance.display_name = 1;
  379. bot->appearance.show_level = 1;
  380. bot->appearance.attackable = 1;
  381. bot->appearance.show_command_icon = 1;
  382. bot->appearance.targetable = 1;
  383. bot->appearance.race = race;
  384. bot->appearance.gender = gender;
  385. bot->SetID(Spawn::NextID());
  386. bot->SetX(client->GetPlayer()->GetX());
  387. bot->SetY(client->GetPlayer()->GetY());
  388. bot->SetZ(client->GetPlayer()->GetZ());
  389. bot->SetHeading(client->GetPlayer()->GetHeading());
  390. bot->SetSpawnOrigX(bot->GetX());
  391. bot->SetSpawnOrigY(bot->GetY());
  392. bot->SetSpawnOrigZ(bot->GetZ());
  393. bot->SetSpawnOrigHeading(bot->GetHeading());
  394. bot->appearance.pos.grid_id = client->GetPlayer()->appearance.pos.grid_id;
  395. bot->SetInitialState(16512);
  396. bot->SetModelType(id_list->at(0));
  397. bot->SetAdventureClass(advClass);
  398. bot->SetLevel(client->GetPlayer()->GetLevel());
  399. bot->SetName(name.c_str());
  400. bot->SetEncounterLevel(6);
  401. bot->size = 32;
  402. if (bot->GetTotalHP() == 0) {
  403. bot->SetTotalHP(25 * bot->GetLevel() + 1);
  404. bot->SetHP(25 * bot->GetLevel() + 1);
  405. }
  406. if (bot->GetTotalPower() == 0) {
  407. bot->SetTotalPower(25 * bot->GetLevel() + 1);
  408. bot->SetPower(25 * bot->GetLevel() + 1);
  409. }
  410. bot->SetOwner(client->GetPlayer());
  411. bot->GetNewSpells();
  412. client->GetCurrentZone()->AddSpawn(bot);
  413. int32 index;
  414. int32 bot_id = database.CreateNewBot(client->GetCharacterID(), name, race, advClass, gender, id_list->at(0), index);
  415. if (bot_id == 0) {
  416. LogWrite(PLAYER__ERROR, 0, "Player", "Error saving bot to DB. Bot was not saved!");
  417. client->SimpleMessage(CHANNEL_ERROR, "Error saving bot to DB. Bot was not saved!");
  418. }
  419. else {
  420. bot->BotID = bot_id;
  421. bot->BotIndex = index;
  422. client->GetPlayer()->SpawnedBots[bot->BotIndex] = bot->GetID();
  423. // Add Items
  424. database.SetBotStartingItems(bot, advClass, race);
  425. }
  426. }
  427. else {
  428. client->SimpleMessage(CHANNEL_COLOR_RED, "Error finding the id list for your race, please verify the race id.");
  429. }
  430. safe_delete(id_list);
  431. }
  432. else
  433. client->SimpleMessage(CHANNEL_COLOR_RED, "Error finding the race string, please verify the race id.");
  434. }
  435. void Commands::Command_Bot_Customize(Client* client, Seperator* sep) {
  436. Bot* bot = 0;
  437. if (client->GetPlayer()->GetTarget() && client->GetPlayer()->GetTarget()->IsBot())
  438. bot = (Bot*)client->GetPlayer()->GetTarget();
  439. if (bot && bot->GetOwner() == client->GetPlayer()) {
  440. PacketStruct* packet = configReader.getStruct("WS_OpenCharCust", client->GetVersion());
  441. if (packet) {
  442. AppearanceData* botApp = &bot->appearance;
  443. CharFeatures* botFeatures = &bot->features;
  444. AppearanceData* playerApp = &client->GetPlayer()->appearance;
  445. CharFeatures* playerFeatures = &client->GetPlayer()->features;
  446. memcpy(&client->GetPlayer()->SavedApp, playerApp, sizeof(AppearanceData));
  447. memcpy(&client->GetPlayer()->SavedFeatures, playerFeatures, sizeof(CharFeatures));
  448. client->GetPlayer()->custNPC = true;
  449. client->GetPlayer()->custNPCTarget = bot;
  450. memcpy(playerApp, botApp, sizeof(AppearanceData));
  451. memcpy(playerFeatures, botFeatures, sizeof(CharFeatures));
  452. client->GetPlayer()->changed = true;
  453. client->GetPlayer()->info_changed = true;
  454. client->GetCurrentZone()->SendSpawnChanges(client->GetPlayer(), client);
  455. packet->setDataByName("race_id", 255);
  456. client->QueuePacket(packet->serialize());
  457. }
  458. }
  459. }
  460. void Commands::Command_Bot_Spawn(Client* client, Seperator* sep) {
  461. if (sep && sep->IsSet(0) && sep->IsNumber(0)) {
  462. int32 bot_id = atoi(sep->arg[0]);
  463. if (client->GetPlayer()->SpawnedBots.count(bot_id) > 0) {
  464. client->Message(CHANNEL_COLOR_YELLOW, "The bot with id %u is already spawned.", bot_id);
  465. return;
  466. }
  467. Bot* bot = new Bot();
  468. memset(&bot->appearance, 0, sizeof(bot->appearance));
  469. if (database.LoadBot(client->GetCharacterID(), bot_id, bot)) {
  470. bot->SetFollowTarget(client->GetPlayer(), 5);
  471. bot->appearance.pos.collision_radius = 32;
  472. bot->secondary_command_list_id = 0;
  473. bot->primary_command_list_id = 0;
  474. bot->appearance.display_name = 1;
  475. bot->appearance.show_level = 1;
  476. bot->appearance.attackable = 1;
  477. bot->appearance.show_command_icon = 1;
  478. bot->appearance.targetable = 1;
  479. bot->SetID(Spawn::NextID());
  480. bot->SetX(client->GetPlayer()->GetX());
  481. bot->SetY(client->GetPlayer()->GetY());
  482. bot->SetZ(client->GetPlayer()->GetZ());
  483. bot->SetHeading(client->GetPlayer()->GetHeading());
  484. bot->SetSpawnOrigX(bot->GetX());
  485. bot->SetSpawnOrigY(bot->GetY());
  486. bot->SetSpawnOrigZ(bot->GetZ());
  487. bot->SetSpawnOrigHeading(bot->GetHeading());
  488. bot->appearance.pos.grid_id = client->GetPlayer()->appearance.pos.grid_id;
  489. bot->SetInitialState(16512);
  490. bot->SetLevel(client->GetPlayer()->GetLevel());
  491. bot->SetEncounterLevel(6);
  492. bot->size = 32;
  493. if (bot->GetTotalHP() == 0) {
  494. bot->SetTotalHP(25 * bot->GetLevel() + 1);
  495. bot->SetHP(25 * bot->GetLevel() + 1);
  496. }
  497. if (bot->GetTotalPower() == 0) {
  498. bot->SetTotalPower(25 * bot->GetLevel() + 1);
  499. bot->SetPower(25 * bot->GetLevel() + 1);
  500. }
  501. bot->SetOwner(client->GetPlayer());
  502. bot->ChangePrimaryWeapon();
  503. bot->CalculateBonuses();
  504. bot->GetNewSpells();
  505. client->GetCurrentZone()->AddSpawn(bot);
  506. if (sep->IsSet(1) && sep->IsNumber(1) && atoi(sep->arg[1]) == 1) {
  507. client->GetCurrentZone()->SendSpawn(bot, client);
  508. int8 result = world.GetGroupManager()->Invite(client->GetPlayer(), bot);
  509. if (result == 0)
  510. client->Message(CHANNEL_COMMANDS, "You invite %s to group with you.", bot->GetName());
  511. else if (result == 1)
  512. client->SimpleMessage(CHANNEL_COMMANDS, "That player is already in a group.");
  513. else if (result == 2)
  514. client->SimpleMessage(CHANNEL_COMMANDS, "That player has been invited to another group.");
  515. else if (result == 3)
  516. client->SimpleMessage(CHANNEL_COMMANDS, "Your group is already full.");
  517. else if (result == 4)
  518. client->SimpleMessage(CHANNEL_COMMANDS, "You have a pending invitation, cancel it first.");
  519. else if (result == 5)
  520. client->SimpleMessage(CHANNEL_COMMANDS, "You cannot invite yourself!");
  521. else if (result == 6)
  522. client->SimpleMessage(CHANNEL_COMMANDS, "Could not locate the player.");
  523. else
  524. client->SimpleMessage(CHANNEL_COMMANDS, "Group invite failed, unknown error!");
  525. }
  526. client->GetPlayer()->SpawnedBots[bot_id] = bot->GetID();
  527. }
  528. else {
  529. client->Message(CHANNEL_ERROR, "Error spawning bot (%u)", bot_id);
  530. }
  531. }
  532. else {
  533. Command_Bot(client, sep);
  534. }
  535. }
  536. void Commands::Command_Bot_List(Client* client, Seperator* sep) {
  537. string bot_list;
  538. bot_list = database.GetBotList(client->GetCharacterID());
  539. if (!bot_list.empty())
  540. client->SimpleMessage(CHANNEL_COLOR_YELLOW, bot_list.c_str());
  541. }
  542. void Commands::Command_Bot_Inv(Client* client, Seperator* sep) {
  543. if (sep && sep->IsSet(0)) {
  544. if (strncasecmp("give", sep->arg[0], 4) == 0) {
  545. if (client->GetPlayer()->trade) {
  546. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You are already trading.");
  547. return;
  548. }
  549. if (!client->GetPlayer()->GetTarget() || !client->GetPlayer()->GetTarget()->IsBot()) {
  550. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You must target a bot");
  551. return;
  552. }
  553. Bot* bot = (Bot*)client->GetPlayer()->GetTarget();
  554. if (bot->trade) {
  555. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "Bot is already in a trade...");
  556. return;
  557. }
  558. if (bot->GetOwner() != client->GetPlayer()) {
  559. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You can only trade with your own bot.");
  560. return;
  561. }
  562. Trade* trade = new Trade(client->GetPlayer(), bot);
  563. client->GetPlayer()->trade = trade;
  564. bot->trade = trade;
  565. }
  566. else if (strncasecmp("list", sep->arg[0], 4) == 0) {
  567. if (!client->GetPlayer()->GetTarget() || !client->GetPlayer()->GetTarget()->IsBot()) {
  568. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You must target a bot");
  569. return;
  570. }
  571. Bot* bot = (Bot*)client->GetPlayer()->GetTarget();
  572. if (bot->GetOwner() != client->GetPlayer()) {
  573. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You can only see the inventory of your own bot.");
  574. return;
  575. }
  576. string item_list = "Bot Items:\nSlot\tName\n";
  577. for (int8 i = 0; i < NUM_SLOTS; i++) {
  578. Item* item = bot->GetEquipmentList()->GetItem(i);
  579. if (item) {
  580. //\\aITEM %u %u:%s\\/a
  581. item_list += to_string(i) + ":\t" + item->CreateItemLink(client->GetVersion(), true) + "\n";
  582. }
  583. }
  584. client->SimpleMessage(CHANNEL_COLOR_YELLOW, item_list.c_str());
  585. }
  586. else if (strncasecmp("remove", sep->arg[0], 6) == 0) {
  587. if (sep->IsSet(1) && sep->IsNumber(1)) {
  588. int8 slot = atoi(sep->arg[1]);
  589. if (slot >= NUM_SLOTS) {
  590. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "Invalid slot");
  591. return;
  592. }
  593. if (!client->GetPlayer()->GetTarget() || !client->GetPlayer()->GetTarget()->IsBot()) {
  594. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You must target a bot.");
  595. return;
  596. }
  597. Bot* bot = (Bot*)client->GetPlayer()->GetTarget();
  598. if (bot->GetOwner() != client->GetPlayer()) {
  599. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You can only remove items from your own bot.");
  600. return;
  601. }
  602. if (client->GetPlayer()->trade) {
  603. Trade* trade = client->GetPlayer()->trade;
  604. if (trade->GetTradee(client->GetPlayer()) != bot) {
  605. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You are already in a trade.");
  606. return;
  607. }
  608. bot->AddItemToTrade(slot);
  609. }
  610. else {
  611. if (bot->trade) {
  612. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "Your bot is already trading...");
  613. return;
  614. }
  615. Trade* trade = new Trade(client->GetPlayer(), bot);
  616. client->GetPlayer()->trade = trade;
  617. bot->trade = trade;
  618. bot->AddItemToTrade(slot);
  619. }
  620. }
  621. }
  622. else
  623. Command_Bot(client, sep);
  624. }
  625. else
  626. Command_Bot(client, sep);
  627. }
  628. void Commands::Command_Bot_Settings(Client* client, Seperator* sep) {
  629. if (sep && sep->IsSet(0) && sep->IsSet(1) && sep->IsNumber(1)) {
  630. if (client->GetPlayer()->GetTarget() && client->GetPlayer()->GetTarget()->IsBot()) {
  631. Bot* bot = (Bot*)client->GetPlayer()->GetTarget();
  632. if (bot->GetOwner() == client->GetPlayer()) {
  633. if (strncasecmp("helm", sep->arg[0], 4) == 0) {
  634. bot->ShowHelm = (atoi(sep->arg[1]) == 1) ? true : false;
  635. bot->info_changed = true;
  636. bot->changed = true;
  637. bot->GetZone()->SendSpawnChanges(bot);
  638. }
  639. else if (strncasecmp("cloak", sep->arg[0], 5) == 0) {
  640. bot->ShowCloak = (atoi(sep->arg[1]) == 1) ? true : false;
  641. bot->info_changed = true;
  642. bot->changed = true;
  643. bot->GetZone()->SendSpawnChanges(bot);
  644. }
  645. else if (strncasecmp("taunt", sep->arg[0], 5) == 0) {
  646. bot->CanTaunt = (atoi(sep->arg[1]) == 1) ? true : false;
  647. }
  648. else if (strncasecmp("hood", sep->arg[0], 4) == 0) {
  649. bot->SetHideHood((atoi(sep->arg[0]) == 1) ? 0 : 1);
  650. }
  651. else
  652. Command_Bot(client, sep);
  653. }
  654. else
  655. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You can only change settings on your own bot.");
  656. }
  657. else
  658. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You must target a bot.");
  659. }
  660. else
  661. Command_Bot(client, sep);
  662. }
  663. void Commands::Command_Bot_Help(Client* client, Seperator* sep) {
  664. if (sep && sep->IsSet(0)) {
  665. if (strncasecmp("race", sep->arg[0], 4) == 0) {
  666. string title = "Race ID's";
  667. string details;
  668. details += "0\tBarbarian\n";
  669. details += "1\tDark Elf\n";
  670. details += "2\tDwarf\n";
  671. details += "3\tErudite\n";
  672. details += "4\tFroglok\n";
  673. details += "5\tGnome\n";
  674. details += "6\tHalf Elf\n";
  675. details += "7\tHalfling\n";
  676. details += "8\tHigh Elf\n";
  677. details += "9\tHuman\n";
  678. details += "10\tIksar\n";
  679. details += "11\tKerra\n";
  680. details += "12\tOgre\n";
  681. details += "13\tRatonga\n";
  682. details += "14\tTroll\n";
  683. details += "15\tWood Elf\n";
  684. details += "16\tFae\n";
  685. details += "17\tArasai\n";
  686. details += "18\tSarnak\n";
  687. details += "19\tVampire\n";
  688. details += "20\tAerakyn\n";
  689. client->SendShowBook(client->GetPlayer(), title, 1, details);
  690. return;
  691. }
  692. else if (strncasecmp("class", sep->arg[0], 5) == 0) {
  693. string title = "Class ID's";
  694. string details;
  695. details += "0\tCOMMONER\n";
  696. details += "1\tFIGHTER\n";
  697. details += "2\tWARRIOR\n";
  698. details += "3\tGUARDIAN\n";
  699. details += "4\tBERSERKER\n";
  700. details += "5\tBRAWLER\n";
  701. details += "6\tMONK\n";
  702. details += "7\tBRUISER\n";
  703. details += "8\tCRUSADER\n";
  704. details += "9\tSHADOWKNIGHT\n";
  705. details += "10\tPALADIN\n";
  706. details += "11\tPRIEST\n";
  707. details += "12\tCLERIC\n";
  708. details += "13\tTEMPLAR\n";
  709. details += "14\tINQUISITOR\n";
  710. details += "15\tDRUID\n";
  711. details += "16\tWARDEN\n";
  712. details += "17\tFURY\n";
  713. details += "18\tSHAMAN\n";
  714. details += "19\tMYSTIC\n";
  715. details += "20\tDEFILER\n";
  716. string details2 = "21\tMAGE\n";
  717. details2 += "22\tSORCERER\n";
  718. details2 += "23\tWIZARD\n";
  719. details2 += "24\tWARLOCK\n";
  720. details2 += "25\tENCHANTER\n";
  721. details2 += "26\tILLUSIONIST\n";
  722. details2 += "27\tCOERCER\n";
  723. details2 += "28\tSUMMONER\n";
  724. details2 += "29\tCONJUROR\n";
  725. details2 += "30\tNECROMANCER\n";
  726. details2 += "31\tSCOUT\n";
  727. details2 += "32\tROGUE\n";
  728. details2 += "33\tSWASHBUCKLER\n";
  729. details2 += "34\tBRIGAND\n";
  730. details2 += "35\tBARD\n";
  731. details2 += "36\tTROUBADOR\n";
  732. details2 += "37\tDIRGE\n";
  733. details2 += "38\tPREDATOR\n";
  734. details2 += "39\tRANGER\n";
  735. details2 += "40\tASSASSIN\n";
  736. string details3 = "\\#FF0000Following aren't implemented yet.\\#000000\n";
  737. details3 += "41\tANIMALIST\n";
  738. details3 += "42\tBEASTLORD\n";
  739. details3 += "43\tSHAPER\n";
  740. details3 += "44\tCHANNELER\n";
  741. client->SendShowBook(client->GetPlayer(), title, 3, details, details2, details3);
  742. return;
  743. }
  744. }
  745. else {
  746. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "Bot help is WIP.");
  747. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "/bot help race - race id list");
  748. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "/bot help class - class id list");
  749. }
  750. }