BotCommands.cpp 27 KB

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