Guest User

Untitled

a guest
Jun 23rd, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 30.05 KB | None | 0 0
  1. package client.messages.commands;
  2.  
  3. //import client.MapleInventory;
  4. //import client.MapleInventoryType;
  5. import client.inventory.Item;
  6. import server.RankingWorker;
  7. import client.MapleCharacter;
  8. import constants.ServerConstants.PlayerGMRank;
  9. import client.MapleClient;
  10. import client.MapleStat;
  11. import client.inventory.MapleInventoryType;
  12. import client.messages.commands.CommandExecute.PokemonExecute;
  13. import client.messages.commands.CommandExecute.TradeExecute;
  14. import constants.BattleConstants.PokemonItem;
  15. import constants.GameConstants;
  16. import java.util.Arrays;
  17. import java.util.List;
  18. import scripting.NPCScriptManager;
  19. import server.MapleInventoryManipulator;
  20. import server.MapleItemInformationProvider;
  21. import server.PokemonBattle;
  22. import server.RankingWorker.RankingInformation;
  23. import server.life.MapleMonster;
  24.  
  25.  
  26. import server.maps.MapleMap;
  27. import server.maps.MapleMapObject;
  28. import server.maps.MapleMapObjectType;
  29. import server.maps.SavedLocationType;
  30. import tools.FileoutputUtil;
  31. import tools.MaplePacketCreator;
  32. import tools.StringUtil;
  33.  
  34. /**
  35. *
  36. * @author Emilyx3
  37. */
  38. public class PlayerCommand {
  39.  
  40. public static PlayerGMRank getPlayerLevelRequired() {
  41. return PlayerGMRank.NORMAL;
  42. }
  43.  
  44. public static class STR extends DistributeStatCommands {
  45.  
  46. public STR() {
  47. stat = MapleStat.STR;
  48. }
  49. }
  50.  
  51. public static class DEX extends DistributeStatCommands {
  52.  
  53. public DEX() {
  54. stat = MapleStat.DEX;
  55. }
  56. }
  57.  
  58. public static class INT extends DistributeStatCommands {
  59.  
  60. public INT() {
  61. stat = MapleStat.INT;
  62. }
  63. }
  64.  
  65. public static class LUK extends DistributeStatCommands {
  66.  
  67. public LUK() {
  68. stat = MapleStat.LUK;
  69. }
  70. }
  71.  
  72. public abstract static class DistributeStatCommands extends CommandExecute {
  73.  
  74. protected MapleStat stat = null;
  75. private static int statLim = 999;
  76.  
  77. private void setStat(MapleCharacter player, int amount) {
  78. switch (stat) {
  79. case STR:
  80. player.getStat().setStr((short) amount, player);
  81. player.updateSingleStat(MapleStat.STR, player.getStat().getStr());
  82. break;
  83. case DEX:
  84. player.getStat().setDex((short) amount, player);
  85. player.updateSingleStat(MapleStat.DEX, player.getStat().getDex());
  86. break;
  87. case INT:
  88. player.getStat().setInt((short) amount, player);
  89. player.updateSingleStat(MapleStat.INT, player.getStat().getInt());
  90. break;
  91. case LUK:
  92. player.getStat().setLuk((short) amount, player);
  93. player.updateSingleStat(MapleStat.LUK, player.getStat().getLuk());
  94. break;
  95. }
  96. }
  97.  
  98. private int getStat(MapleCharacter player) {
  99. switch (stat) {
  100. case STR:
  101. return player.getStat().getStr();
  102. case DEX:
  103. return player.getStat().getDex();
  104. case INT:
  105. return player.getStat().getInt();
  106. case LUK:
  107. return player.getStat().getLuk();
  108. default:
  109. throw new RuntimeException(); //Will never happen.
  110. }
  111. }
  112.  
  113. @Override
  114. public int execute(MapleClient c, String[] splitted) {
  115. if (splitted.length < 2) {
  116. c.getPlayer().dropMessage(5, "Invalid number entered.");
  117. return 0;
  118. }
  119. int change = 0;
  120. try {
  121. change = Integer.parseInt(splitted[1]);
  122. } catch (NumberFormatException nfe) {
  123. c.getPlayer().dropMessage(5, "Invalid number entered.");
  124. return 0;
  125. }
  126. if (change <= 0) {
  127. c.getPlayer().dropMessage(5, "You must enter a number greater than 0.");
  128. return 0;
  129. }
  130. if (c.getPlayer().getRemainingAp() < change) {
  131. c.getPlayer().dropMessage(5, "You don't have enough AP for that.");
  132. return 0;
  133. }
  134. if (getStat(c.getPlayer()) + change > statLim) {
  135. c.getPlayer().dropMessage(5, "The stat limit is " + statLim + ".");
  136. return 0;
  137. }
  138. setStat(c.getPlayer(), getStat(c.getPlayer()) + change);
  139. c.getPlayer().setRemainingAp((short) (c.getPlayer().getRemainingAp() - change));
  140. c.getPlayer().updateSingleStat(MapleStat.AVAILABLEAP, c.getPlayer().getRemainingAp());
  141. c.getPlayer().dropMessage(5, StringUtil.makeEnumHumanReadable(stat.name()) + " has been raised by " + change + ".");
  142. return 1;
  143. }
  144. }
  145.  
  146. public static class Mob extends CommandExecute {
  147.  
  148. public int execute(MapleClient c, String[] splitted) {
  149. MapleMonster mob = null;
  150. for (final MapleMapObject monstermo : c.getPlayer().getMap().getMapObjectsInRange(c.getPlayer().getPosition(), 100000, Arrays.asList(MapleMapObjectType.MONSTER))) {
  151. mob = (MapleMonster) monstermo;
  152. if (mob.isAlive()) {
  153. c.getPlayer().dropMessage(6, "Monster " + mob.toString());
  154. break; //only one
  155. }
  156. }
  157. if (mob == null) {
  158. c.getPlayer().dropMessage(6, "No monster was found.");
  159. }
  160. return 1;
  161. }
  162. }
  163.  
  164. public static class Challenge extends CommandExecute {
  165.  
  166. public int execute(MapleClient c, String[] splitted) {
  167. if (splitted.length <= 1) {
  168. c.getPlayer().dropMessage(6, "@challenge [playername OR accept/decline OR block/unblock]");
  169. return 0;
  170. }
  171. if (c.getPlayer().getBattler(0) == null) {
  172. c.getPlayer().dropMessage(6, "You have no monsters!");
  173. return 0;
  174. }
  175. if (splitted[1].equalsIgnoreCase("accept")) {
  176. if (c.getPlayer().getChallenge() > 0) {
  177. final MapleCharacter chr = c.getPlayer().getMap().getCharacterById(c.getPlayer().getChallenge());
  178. if (chr != null) {
  179. if ((c.getPlayer().isInTownMap() || c.getPlayer().isGM() || chr.isInTownMap() || chr.isGM()) && chr.getBattler(0) != null && chr.getChallenge() == c.getPlayer().getId() && chr.getBattle() == null && c.getPlayer().getBattle() == null) {
  180. if (c.getPlayer().getPosition().y != chr.getPosition().y) {
  181. c.getPlayer().dropMessage(6, "Please be near them.");
  182. return 0;
  183. } else if (c.getPlayer().getPosition().distance(chr.getPosition()) > 600.0 || c.getPlayer().getPosition().distance(chr.getPosition()) < 400.0) {
  184. c.getPlayer().dropMessage(6, "Please be at a moderate distance from them.");
  185. return 0;
  186. }
  187. chr.setChallenge(0);
  188. chr.dropMessage(6, c.getPlayer().getName() + " has accepted!");
  189. c.getPlayer().setChallenge(0);
  190. final PokemonBattle battle = new PokemonBattle(chr, c.getPlayer());
  191. chr.setBattle(battle);
  192. c.getPlayer().setBattle(battle);
  193. battle.initiate();
  194. } else {
  195. c.getPlayer().dropMessage(6, "You may only use it in towns, or the other character has no monsters, or something failed.");
  196. }
  197. } else {
  198. c.getPlayer().dropMessage(6, "They do not exist in the map.");
  199. }
  200. } else {
  201. c.getPlayer().dropMessage(6, "You don't have a challenge.");
  202. }
  203. } else if (splitted[1].equalsIgnoreCase("decline")) {
  204. if (c.getPlayer().getChallenge() > 0) {
  205. c.getPlayer().cancelChallenge();
  206. } else {
  207. c.getPlayer().dropMessage(6, "You don't have a challenge.");
  208. }
  209. } else if (splitted[1].equalsIgnoreCase("block")) {
  210. if (c.getPlayer().getChallenge() == 0) {
  211. c.getPlayer().setChallenge(-1);
  212. c.getPlayer().dropMessage(6, "You have blocked challenges.");
  213. } else {
  214. c.getPlayer().dropMessage(6, "You have a challenge or they are already blocked.");
  215. }
  216. } else if (splitted[1].equalsIgnoreCase("unblock")) {
  217. if (c.getPlayer().getChallenge() < 0) {
  218. c.getPlayer().setChallenge(0);
  219. c.getPlayer().dropMessage(6, "You have unblocked challenges.");
  220. } else {
  221. c.getPlayer().dropMessage(6, "You didn't block challenges.");
  222. }
  223. } else {
  224. if (c.getPlayer().getChallenge() == 0) {
  225. final MapleCharacter chr = c.getChannelServer().getPlayerStorage().getCharacterByName(splitted[1]);
  226. if (chr != null && chr.getMap() == c.getPlayer().getMap() && chr.getId() != c.getPlayer().getId()) {
  227. if ((c.getPlayer().isInTownMap() || c.getPlayer().isGM() || chr.isInTownMap() || chr.isGM()) && chr.getBattler(0) != null && chr.getChallenge() == 0 && chr.getBattle() == null && c.getPlayer().getBattle() == null) {
  228. chr.setChallenge(c.getPlayer().getId());
  229. chr.dropMessage(6, c.getPlayer().getName() + " has challenged you! Type @challenge [accept/decline] to answer!");
  230. c.getPlayer().setChallenge(chr.getId());
  231. c.getPlayer().dropMessage(6, "Successfully sent the request.");
  232. } else {
  233. c.getPlayer().dropMessage(6, "You may only use it in towns, or the other character has no monsters, or they have a challenge.");
  234. }
  235. } else {
  236. c.getPlayer().dropMessage(6, splitted[1] + " does not exist in the map.");
  237. }
  238. } else {
  239. c.getPlayer().dropMessage(6, "You have a challenge or you have blocked them.");
  240. }
  241. }
  242. return 1;
  243. }
  244. }
  245.  
  246. public abstract static class OpenNPCCommand extends CommandExecute {
  247.  
  248. protected int npc = -1;
  249. private static int[] npcs = { //Ish yur job to make sure these are in order and correct ;(
  250. 9270035,
  251. 9010017,
  252. 9000000,
  253. 9000030,
  254. 9010000,
  255. 9000085,
  256. 9000018};
  257.  
  258. @Override
  259. public int execute(MapleClient c, String[] splitted) {
  260. if (npc != 6 && npc != 5 && npc != 4 && npc != 3 && npc != 1 && c.getPlayer().getMapId() != 910000000) { //drpcash can use anywhere
  261. if (c.getPlayer().getLevel() < 10 && c.getPlayer().getJob() != 200) {
  262. c.getPlayer().dropMessage(5, "You must be over level 10 to use this command.");
  263. return 0;
  264. }
  265. if (c.getPlayer().isInBlockedMap()) {
  266. c.getPlayer().dropMessage(5, "You may not use this command here.");
  267. return 0;
  268. }
  269. } else if (npc == 1) {
  270. if (c.getPlayer().getLevel() < 70) {
  271. c.getPlayer().dropMessage(5, "You must be over level 70 to use this command.");
  272. return 0;
  273. }
  274. }
  275. if (c.getPlayer().hasBlockedInventory()) {
  276. c.getPlayer().dropMessage(5, "You may not use this command here.");
  277. return 0;
  278. }
  279. NPCScriptManager.getInstance().start(c, npcs[npc]);
  280. return 1;
  281. }
  282. }
  283.  
  284. public static class Npc extends OpenNPCCommand {
  285.  
  286. public Npc() {
  287. npc = 0;
  288. }
  289. }
  290.  
  291. public static class DCash extends OpenNPCCommand {
  292.  
  293. public DCash() {
  294. npc = 1;
  295. }
  296. }
  297.  
  298. public static class Event extends OpenNPCCommand {
  299.  
  300. public Event() {
  301. npc = 2;
  302. }
  303. }
  304.  
  305. public static class CheckDrop extends OpenNPCCommand {
  306.  
  307. public CheckDrop() {
  308. npc = 4;
  309. }
  310. }
  311.  
  312. public static class Pokedex extends OpenNPCCommand {
  313.  
  314. public Pokedex() {
  315. npc = 5;
  316. }
  317. }
  318.  
  319. public static class Pokemon extends OpenNPCCommand {
  320.  
  321. public Pokemon() {
  322. npc = 6;
  323. }
  324. }
  325.  
  326. /*public static class ClearSlot extends CommandExecute {
  327.  
  328. private static MapleInventoryType[] invs = {
  329. MapleInventoryType.EQUIP,
  330. MapleInventoryType.USE,
  331. MapleInventoryType.SETUP,
  332. MapleInventoryType.ETC,
  333. MapleInventoryType.CASH,};
  334.  
  335. @Override
  336. public int execute(MapleClient c, String[] splitted) {
  337. MapleCharacter player = c.getPlayer();
  338. if (splitted.length < 2 || player.hasBlockedInventory()) {
  339. c.getPlayer().dropMessage(5, "@clearslot <eq/use/setup/etc/cash/all>");
  340. return 0;
  341. } else {
  342. MapleInventoryType type;
  343. if (splitted[1].equalsIgnoreCase("eq")) {
  344. type = MapleInventoryType.EQUIP;
  345. } else if (splitted[1].equalsIgnoreCase("use")) {
  346. type = MapleInventoryType.USE;
  347. } else if (splitted[1].equalsIgnoreCase("setup")) {
  348. type = MapleInventoryType.SETUP;
  349. } else if (splitted[1].equalsIgnoreCase("etc")) {
  350. type = MapleInventoryType.ETC;
  351. } else if (splitted[1].equalsIgnoreCase("cash")) {
  352. type = MapleInventoryType.CASH;
  353. } else if (splitted[1].equalsIgnoreCase("all")) {
  354. type = null;
  355. } else {
  356. c.getPlayer().dropMessage(5, "Invalid. @clearslot <eq/use/setup/etc/cash/all>");
  357. return 0;
  358. }
  359. if (type == null) { //All, a bit hacky, but it's okay
  360. for (MapleInventoryType t : invs) {
  361. type = t;
  362. MapleInventory inv = c.getPlayer().getInventory(type);
  363. byte start = -1;
  364. for (byte i = 0; i < inv.getSlotLimit(); i++) {
  365. if (inv.getItem(i) != null) {
  366. start = i;
  367. break;
  368. }
  369. }
  370. if (start == -1) {
  371. c.getPlayer().dropMessage(5, "There are no items in that inventory.");
  372. return 0;
  373. }
  374. int end = 0;
  375. for (byte i = start; i < inv.getSlotLimit(); i++) {
  376. if (inv.getItem(i) != null) {
  377. MapleInventoryManipulator.removeFromSlot(c, type, i, inv.getItem(i).getQuantity(), true);
  378. } else {
  379. end = i;
  380. break;//Break at first empty space.
  381. }
  382. }
  383. c.getPlayer().dropMessage(5, "Cleared slots " + start + " to " + end + ".");
  384. }
  385. } else {
  386. MapleInventory inv = c.getPlayer().getInventory(type);
  387. byte start = -1;
  388. for (byte i = 0; i < inv.getSlotLimit(); i++) {
  389. if (inv.getItem(i) != null) {
  390. start = i;
  391. break;
  392. }
  393. }
  394. if (start == -1) {
  395. c.getPlayer().dropMessage(5, "There are no items in that inventory.");
  396. return 0;
  397. }
  398. byte end = 0;
  399. for (byte i = start; i < inv.getSlotLimit(); i++) {
  400. if (inv.getItem(i) != null) {
  401. MapleInventoryManipulator.removeFromSlot(c, type, i, inv.getItem(i).getQuantity(), true);
  402. } else {
  403. end = i;
  404. break;//Break at first empty space.
  405. }
  406. }
  407. c.getPlayer().dropMessage(5, "Cleared slots " + start + " to " + end + ".");
  408. }
  409. return 1;
  410. }
  411. }
  412. }*/
  413. public static class FM extends CommandExecute {
  414.  
  415. public int execute(MapleClient c, String[] splitted) {
  416. for (int i : GameConstants.blockedMaps) {
  417. if (c.getPlayer().getMapId() == i) {
  418. c.getPlayer().dropMessage(5, "You may not use this command here.");
  419. return 0;
  420. }
  421. }
  422. if (c.getPlayer().getLevel() < 10 && c.getPlayer().getJob() != 200) {
  423. c.getPlayer().dropMessage(5, "You must be over level 10 to use this command.");
  424. return 0;
  425. }
  426. if (c.getPlayer().hasBlockedInventory() || c.getPlayer().getMap().getSquadByMap() != null || c.getPlayer().getEventInstance() != null || c.getPlayer().getMap().getEMByMap() != null || c.getPlayer().getMapId() >= 990000000/* || FieldLimitType.VipRock.check(c.getPlayer().getMap().getFieldLimit())*/) {
  427. c.getPlayer().dropMessage(5, "You may not use this command here.");
  428. return 0;
  429. }
  430. if ((c.getPlayer().getMapId() >= 680000210 && c.getPlayer().getMapId() <= 680000502) || (c.getPlayer().getMapId() / 1000 == 980000 && c.getPlayer().getMapId() != 980000000) || (c.getPlayer().getMapId() / 100 == 1030008) || (c.getPlayer().getMapId() / 100 == 922010) || (c.getPlayer().getMapId() / 10 == 13003000)) {
  431. c.getPlayer().dropMessage(5, "You may not use this command here.");
  432. return 0;
  433. }
  434. c.getPlayer().saveLocation(SavedLocationType.FREE_MARKET, c.getPlayer().getMap().getReturnMap().getId());
  435. MapleMap map = c.getChannelServer().getMapFactory().getMap(910000000);
  436. c.getPlayer().changeMap(map, map.getPortal(0));
  437. return 1;
  438. }
  439. }
  440.  
  441. public static class EA extends CommandExecute {
  442.  
  443. public int execute(MapleClient c, String[] splitted) {
  444. c.removeClickedNPC();
  445. NPCScriptManager.getInstance().dispose(c);
  446. c.getSession().write(MaplePacketCreator.enableActions());
  447. return 1;
  448. }
  449. }
  450.  
  451. public static class TSmega extends CommandExecute {
  452.  
  453. public int execute(MapleClient c, String[] splitted) {
  454. c.getPlayer().setSmega();
  455. return 1;
  456. }
  457. }
  458.  
  459. public static class Ranking extends CommandExecute {
  460.  
  461. public int execute(MapleClient c, String[] splitted) {
  462. if (splitted.length < 4) { //job start end
  463. c.getPlayer().dropMessage(5, "Use @ranking [job] [start number] [end number] where start and end are ranks of the players");
  464. final StringBuilder builder = new StringBuilder("JOBS: ");
  465. for (String b : RankingWorker.getJobCommands().keySet()) {
  466. builder.append(b);
  467. builder.append(" ");
  468. }
  469. c.getPlayer().dropMessage(5, builder.toString());
  470. } else {
  471. int start = 1, end = 20;
  472. try {
  473. start = Integer.parseInt(splitted[2]);
  474. end = Integer.parseInt(splitted[3]);
  475. } catch (NumberFormatException e) {
  476. c.getPlayer().dropMessage(5, "You didn't specify start and end number correctly, the default values of 1 and 20 will be used.");
  477. }
  478. if (end < start || end - start > 20) {
  479. c.getPlayer().dropMessage(5, "End number must be greater, and end number must be within a range of 20 from the start number.");
  480. } else {
  481. final Integer job = RankingWorker.getJobCommand(splitted[1]);
  482. if (job == null) {
  483. c.getPlayer().dropMessage(5, "Please use @ranking to check the job names.");
  484. } else {
  485. final List<RankingInformation> ranks = RankingWorker.getRankingInfo(job.intValue());
  486. if (ranks == null || ranks.size() <= 0) {
  487. c.getPlayer().dropMessage(5, "Please try again later.");
  488. } else {
  489. int num = 0;
  490. for (RankingInformation rank : ranks) {
  491. if (rank.rank >= start && rank.rank <= end) {
  492. if (num == 0) {
  493. c.getPlayer().dropMessage(6, "Rankings for " + splitted[1] + " - from " + start + " to " + end);
  494. c.getPlayer().dropMessage(6, "--------------------------------------");
  495. }
  496. c.getPlayer().dropMessage(6, rank.toString());
  497. num++;
  498. }
  499. }
  500. if (num == 0) {
  501. c.getPlayer().dropMessage(5, "No ranking was returned.");
  502. }
  503. }
  504. }
  505. }
  506. }
  507. return 1;
  508. }
  509. }
  510.  
  511. public static class Check extends CommandExecute {
  512.  
  513. public int execute(MapleClient c, String[] splitted) {
  514. c.getPlayer().dropMessage(6, "You currently have " + c.getPlayer().getCSPoints(1) + " Cash.");
  515. c.getPlayer().dropMessage(6, "You currently have " + c.getPlayer().getPoints() + " donation points.");
  516. c.getPlayer().dropMessage(6, "You currently have " + c.getPlayer().getVPoints() + " voting points.");
  517. c.getPlayer().dropMessage(6, "You currently have " + c.getPlayer().getIntNoRecord(GameConstants.BOSS_PQ) + " Boss Party Quest points.");
  518. c.getPlayer().dropMessage(6, "The time is currently " + FileoutputUtil.CurrentReadable_TimeGMT() + " GMT.");
  519. return 1;
  520. }
  521. }
  522.  
  523. public static class Help extends CommandExecute {
  524.  
  525. public int execute(MapleClient c, String[] splitted) {
  526. c.getPlayer().dropMessage(5, "@str, @dex, @int, @luk <amount to add>");
  527. c.getPlayer().dropMessage(5, "@mob < Information on the closest monster >");
  528. c.getPlayer().dropMessage(5, "@check < Displays various information >");
  529. c.getPlayer().dropMessage(5, "@fm < Warp to FM >");
  530. /*c.getPlayer().dropMessage(5, "@changesecondpass - Change second password, @changesecondpass <current Password> <new password> <Confirm new password> ");*/
  531. c.getPlayer().dropMessage(5, "@npc < Universal Town Warp / Event NPC>");
  532. c.getPlayer().dropMessage(5, "@dcash < Universal Cash Item Dropper >");
  533. /*if (!GameConstants.GMS) {
  534. c.getPlayer().dropMessage(5, "@pokedex < Universal Information >");
  535. c.getPlayer().dropMessage(5, "@pokemon < Universal Monsters Information >");
  536. c.getPlayer().dropMessage(5, "@challenge < playername, or accept/decline or block/unblock >");
  537. }*/
  538. c.getPlayer().dropMessage(5, "@tsmega < Toggle super megaphone on/off >");
  539. c.getPlayer().dropMessage(5, "@ea < If you are unable to attack or talk to NPC >");
  540. /*c.getPlayer().dropMessage(5, "@clearslot < Cleanup that trash in your inventory >");*/
  541. c.getPlayer().dropMessage(5, "@ranking < Use @ranking for more details >");
  542. c.getPlayer().dropMessage(5, "@checkdrop < Use @checkdrop for more details >");
  543. return 1;
  544. }
  545. }
  546.  
  547. public static class TradeHelp extends TradeExecute {
  548.  
  549. public int execute(MapleClient c, String[] splitted) {
  550. c.getPlayer().dropMessage(-2, "[System] : <@offerequip, @offeruse, @offersetup, @offeretc, @offercash> <quantity> <name of the item>");
  551. return 1;
  552. }
  553. }
  554.  
  555. public abstract static class OfferCommand extends TradeExecute {
  556.  
  557. protected int invType = -1;
  558.  
  559. public int execute(MapleClient c, String[] splitted) {
  560. if (splitted.length < 3) {
  561. c.getPlayer().dropMessage(-2, "[Error] : <quantity> <name of item>");
  562. } else if (c.getPlayer().getLevel() < 70) {
  563. c.getPlayer().dropMessage(-2, "[Error] : Only level 70+ may use this command");
  564. } else {
  565. int quantity = 1;
  566. try {
  567. quantity = Integer.parseInt(splitted[1]);
  568. } catch (Exception e) { //swallow and just use 1
  569. }
  570. String search = StringUtil.joinStringFrom(splitted, 2).toLowerCase();
  571. Item found = null;
  572. final MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
  573. for (Item inv : c.getPlayer().getInventory(MapleInventoryType.getByType((byte) invType))) {
  574. if (ii.getName(inv.getItemId()) != null && ii.getName(inv.getItemId()).toLowerCase().contains(search)) {
  575. found = inv;
  576. break;
  577. }
  578. }
  579. if (found == null) {
  580. c.getPlayer().dropMessage(-2, "[Error] : No such item was found (" + search + ")");
  581. return 0;
  582. }
  583. if (GameConstants.isPet(found.getItemId()) || GameConstants.isRechargable(found.getItemId())) {
  584. c.getPlayer().dropMessage(-2, "[Error] : You may not trade this item using this command");
  585. return 0;
  586. }
  587. if (quantity > found.getQuantity() || quantity <= 0 || quantity > ii.getSlotMax(found.getItemId())) {
  588. c.getPlayer().dropMessage(-2, "[Error] : Invalid quantity");
  589. return 0;
  590. }
  591. if (!c.getPlayer().getTrade().setItems(c, found, (byte) -1, quantity)) {
  592. c.getPlayer().dropMessage(-2, "[Error] : This item could not be placed");
  593. return 0;
  594. } else {
  595. c.getPlayer().getTrade().chatAuto("[System] : " + c.getPlayer().getName() + " offered " + ii.getName(found.getItemId()) + " x " + quantity);
  596. }
  597. }
  598. return 1;
  599. }
  600. }
  601.  
  602. public static class OfferEquip extends OfferCommand {
  603.  
  604. public OfferEquip() {
  605. invType = 1;
  606. }
  607. }
  608.  
  609. public static class OfferUse extends OfferCommand {
  610.  
  611. public OfferUse() {
  612. invType = 2;
  613. }
  614. }
  615.  
  616. public static class OfferSetup extends OfferCommand {
  617.  
  618. public OfferSetup() {
  619. invType = 3;
  620. }
  621. }
  622.  
  623. public static class OfferEtc extends OfferCommand {
  624.  
  625. public OfferEtc() {
  626. invType = 4;
  627. }
  628. }
  629.  
  630. public static class OfferCash extends OfferCommand {
  631.  
  632. public OfferCash() {
  633. invType = 5;
  634. }
  635. }
  636.  
  637. public static class BattleHelp extends PokemonExecute {
  638.  
  639. public int execute(MapleClient c, String[] splitted) {
  640. c.getPlayer().dropMessage(-3, "(...I can use @use <attack name> to take down the enemy...)");
  641. c.getPlayer().dropMessage(-3, "(...I can use @info to check out the stats of my battle...)");
  642. c.getPlayer().dropMessage(-3, "(...I can use @ball <basic, great, ultra> to use an ball, but only if I have it...)");
  643. c.getPlayer().dropMessage(-3, "(...I can use @run if I don't want to fight anymore...)");
  644. c.getPlayer().dropMessage(-4, "(...This is a tough choice! What do I do?...)"); //last msg they see
  645. return 1;
  646. }
  647. }
  648.  
  649. public static class Ball extends PokemonExecute {
  650.  
  651. public int execute(MapleClient c, String[] splitted) {
  652. if (c.getPlayer().getBattle().getInstanceId() < 0 || c.getPlayer().getBattle().isTrainerBattle()) {
  653. c.getPlayer().dropMessage(-3, "(...I can't use it in a trainer battle...)");
  654. return 0;
  655. }
  656. if (splitted.length <= 1) {
  657. c.getPlayer().dropMessage(-3, "(...I can use @ball <basic, great, or ultra> if I have the ball...)");
  658. return 0;
  659. }
  660. PokemonItem item = null;
  661. if (splitted[1].equalsIgnoreCase("basic")) {
  662. item = PokemonItem.Basic_Ball;
  663. } else if (splitted[1].equalsIgnoreCase("great")) {
  664. item = PokemonItem.Great_Ball;
  665. } else if (splitted[1].equalsIgnoreCase("ultra")) {
  666. item = PokemonItem.Ultra_Ball;
  667. }
  668. if (item != null) {
  669. if (c.getPlayer().haveItem(item.id, 1)) {
  670. if (c.getPlayer().getBattle().useBall(c.getPlayer(), item)) {
  671. MapleInventoryManipulator.removeById(c, GameConstants.getInventoryType(item.id), item.id, 1, false, false);
  672. } else {
  673. c.getPlayer().dropMessage(-3, "(...The monster is too strong, maybe I don't need it...)");
  674. return 0;
  675. }
  676. } else {
  677. c.getPlayer().dropMessage(-3, "(...I don't have a " + splitted[1] + " ball...)");
  678. return 0;
  679. }
  680. } else {
  681. c.getPlayer().dropMessage(-3, "(...I can use @ball <basic, great, or ultra> if I have the ball...)");
  682. return 0;
  683. }
  684. return 1;
  685. }
  686. }
  687.  
  688. public static class Info extends PokemonExecute {
  689.  
  690. public int execute(MapleClient c, String[] splitted) {
  691. NPCScriptManager.getInstance().start(c, 9000021); //no checks are needed
  692. return 1;
  693. }
  694. }
  695.  
  696. public static class Run extends PokemonExecute {
  697.  
  698. public int execute(MapleClient c, String[] splitted) {
  699. c.getPlayer().getBattle().forfeit(c.getPlayer(), false);
  700. return 1;
  701. }
  702. }
  703.  
  704. public static class Use extends PokemonExecute {
  705.  
  706. public int execute(MapleClient c, String[] splitted) {
  707. if (splitted.length <= 1) {
  708. c.getPlayer().dropMessage(-3, "(...I need an attack name...)");
  709. return 0;
  710. }
  711. if (!c.getPlayer().getBattle().attack(c.getPlayer(), StringUtil.joinStringFrom(splitted, 1))) {
  712. c.getPlayer().dropMessage(-3, "(...I've already selected an action...)");
  713. }
  714. return 1;
  715. }
  716. }
  717. }
Add Comment
Please, Sign In to add comment