BotCommands.cpp 28 KB

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