BotCommands.cpp 27 KB

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