BotCommands.cpp 26 KB

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