warc222

l2jmega autofarm connect interface interlude

Nov 10th, 2023
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ### Eclipse Workspace Patch 1.0
  2. #P L2jMega_Interlude
  3. diff --git java/Base/AutoFarm/AutofarmConstants.java java/Base/AutoFarm/AutofarmConstants.java
  4. new file mode 100644
  5. index 0000000..70e4aef
  6. --- /dev/null
  7. +++ java/Base/AutoFarm/AutofarmConstants.java
  8. @@ -0,0 +1,11 @@
  9. +package Base.AutoFarm;
  10. +
  11. +import java.util.Arrays;
  12. +import java.util.List;
  13. +
  14. +public class AutofarmConstants
  15. +{
  16. +    public final static List<Integer> attackSlots = Arrays.asList(0, 1, 2, 3);
  17. +    public final static List<Integer> chanceSlots = Arrays.asList(4, 5, 6, 7);
  18. +    public final static List<Integer> lowLifeSlots = Arrays.asList(8, 9, 10, 11);
  19. +}
  20. \ No newline at end of file
  21. diff --git java/Base/AutoFarm/AutofarmPlayerRoutine.java java/Base/AutoFarm/AutofarmPlayerRoutine.java
  22. new file mode 100644
  23. index 0000000..68597fc
  24. --- /dev/null
  25. +++ java/Base/AutoFarm/AutofarmPlayerRoutine.java
  26. @@ -0,0 +1,505 @@
  27. +package Base.AutoFarm;
  28. +
  29. +
  30. +
  31. +import com.l2jmega.Config;
  32. +import com.l2jmega.gameserver.geoengine.GeoEngine;
  33. +import com.l2jmega.gameserver.handler.IItemHandler;
  34. +import com.l2jmega.gameserver.handler.ItemHandler;
  35. +import com.l2jmega.gameserver.handler.voicedcommandhandlers.VoicedAutoFarm;
  36. +import com.l2jmega.gameserver.model.L2ShortCut;
  37. +import com.l2jmega.gameserver.model.L2Skill;
  38. +import com.l2jmega.gameserver.model.WorldObject;
  39. +import com.l2jmega.gameserver.model.WorldRegion;
  40. +import com.l2jmega.gameserver.model.actor.Creature;
  41. +import com.l2jmega.gameserver.model.actor.Summon;
  42. +import com.l2jmega.gameserver.model.actor.ai.CtrlEvent;
  43. +import com.l2jmega.gameserver.model.actor.ai.CtrlIntention;
  44. +import com.l2jmega.gameserver.model.actor.ai.NextAction;
  45. +import com.l2jmega.gameserver.model.actor.instance.Chest;
  46. +import com.l2jmega.gameserver.model.actor.instance.Monster;
  47. +import com.l2jmega.gameserver.model.actor.instance.Pet;
  48. +import com.l2jmega.gameserver.model.actor.instance.Player;
  49. +import com.l2jmega.gameserver.model.item.instance.ItemInstance;
  50. +import com.l2jmega.gameserver.network.SystemMessageId;
  51. +import com.l2jmega.gameserver.network.serverpackets.ActionFailed;
  52. +import com.l2jmega.gameserver.network.serverpackets.ExShowScreenMessage;
  53. +import com.l2jmega.gameserver.network.serverpackets.ExShowScreenMessage.SMPOS;
  54. +import com.l2jmega.gameserver.network.serverpackets.SystemMessage;
  55. +import com.l2jmega.gameserver.templates.skills.L2SkillType;
  56. +
  57. +import java.util.ArrayList;
  58. +import java.util.Arrays;
  59. +import java.util.Collections;
  60. +import java.util.List;
  61. +import java.util.concurrent.ScheduledFuture;
  62. +import java.util.function.Function;
  63. +import java.util.stream.Collectors;
  64. +
  65. +import com.l2jmega.commons.concurrent.ThreadPool;
  66. +import com.l2jmega.commons.math.MathUtil;
  67. +import com.l2jmega.commons.random.Rnd;
  68. +
  69. +public class AutofarmPlayerRoutine
  70. +{
  71. +   private final Player player;
  72. +   private ScheduledFuture<?> _task;
  73. +   private Creature committedTarget = null;
  74. +
  75. +   public AutofarmPlayerRoutine(Player player)
  76. +   {
  77. +       this.player = player;
  78. +   }
  79. +
  80. +   public void start()
  81. +   {
  82. +       if (_task == null)
  83. +       {
  84. +           _task = ThreadPool.scheduleAtFixedRate(() -> executeRoutine(), 450, 450);
  85. +          
  86. +           player.sendPacket(new ExShowScreenMessage("Auto Farming Actived...", 5*1000, SMPOS.TOP_CENTER, false));
  87. +           player.sendPacket(new SystemMessage(SystemMessageId.AUTO_FARM_ACTIVATED));
  88. +          
  89. +      
  90. +       }
  91. +   }
  92. +  
  93. +   public void stop()
  94. +   {
  95. +       if (_task != null)
  96. +       {
  97. +           _task.cancel(false);
  98. +           _task = null;
  99. +          
  100. +           player.sendPacket(new ExShowScreenMessage("Auto Farming Deactivated...", 5*1000, SMPOS.TOP_CENTER, false));
  101. +           player.sendPacket(new SystemMessage(SystemMessageId.AUTO_FARM_DESACTIVATED));
  102. +          
  103. +       }
  104. +   }
  105. +  
  106. +   public void executeRoutine()
  107. +   {
  108. +       if (player.isNoBuffProtected() && player.getAllEffects().length <= 8)
  109. +       {
  110. +           player.sendMessage("You don't have buffs to use autofarm.");
  111. +           player.broadcastUserInfo();
  112. +           stop();
  113. +           player.setAutoFarm(false);
  114. +           VoicedAutoFarm.showAutoFarm(player);
  115. +           return;
  116. +       }
  117. +      
  118. +       calculatePotions();
  119. +       checkSpoil();
  120. +       targetEligibleCreature();
  121. +       if (player.isMageClass())
  122. +       {
  123. +           useAppropriateSpell();
  124. +       }
  125. +       else if (shotcutsContainAttack())
  126. +       {
  127. +           attack();
  128. +       }
  129. +       else
  130. +       {
  131. +           useAppropriateSpell();
  132. +       }
  133. +       checkSpoil();
  134. +       useAppropriateSpell();
  135. +   }
  136. +
  137. +   private void attack()
  138. +   {
  139. +       Boolean shortcutsContainAttack = shotcutsContainAttack();
  140. +      
  141. +       if (shortcutsContainAttack)
  142. +           physicalAttack();
  143. +   }
  144. +
  145. +   private void useAppropriateSpell()
  146. +   {
  147. +       L2Skill chanceSkill = nextAvailableSkill(getChanceSpells(), AutofarmSpellType.Chance);
  148. +
  149. +       if (chanceSkill != null)
  150. +       {
  151. +           useMagicSkill(chanceSkill, false);
  152. +           return;
  153. +       }
  154. +
  155. +       L2Skill lowLifeSkill = nextAvailableSkill(getLowLifeSpells(), AutofarmSpellType.LowLife);
  156. +
  157. +       if (lowLifeSkill != null)
  158. +       {
  159. +           useMagicSkill(lowLifeSkill, true);
  160. +           return;
  161. +       }
  162. +
  163. +       L2Skill attackSkill = nextAvailableSkill(getAttackSpells(), AutofarmSpellType.Attack);
  164. +
  165. +       if (attackSkill != null)
  166. +       {
  167. +           useMagicSkill(attackSkill, false);
  168. +           return;
  169. +       }
  170. +   }
  171. +
  172. +   public L2Skill nextAvailableSkill(List<Integer> skillIds, AutofarmSpellType spellType)
  173. +   {
  174. +       for (Integer skillId : skillIds)
  175. +       {
  176. +           L2Skill skill = player.getSkill(skillId);
  177. +
  178. +           if (skill == null)
  179. +               continue;
  180. +          
  181. +           if (skill.getSkillType() == L2SkillType.SIGNET || skill.getSkillType() == L2SkillType.SIGNET_CASTTIME)
  182. +               continue;
  183. +
  184. +           if (!player.checkDoCastConditions(skill))
  185. +               continue;
  186. +
  187. +           if (isSpoil(skillId))
  188. +           {
  189. +               if (monsterIsAlreadySpoiled())
  190. +               {
  191. +                   continue;
  192. +               }
  193. +               return skill;
  194. +           }
  195. +          
  196. +           if (spellType == AutofarmSpellType.Chance && getMonsterTarget() != null)
  197. +           {
  198. +               if (getMonsterTarget().getFirstEffect(skillId) == null)
  199. +                   return skill;
  200. +               continue;
  201. +           }
  202. +
  203. +           if (spellType == AutofarmSpellType.LowLife && getHpPercentage() > player.getHealPercent())
  204. +               break;
  205. +
  206. +           return skill;
  207. +       }
  208. +
  209. +       return null;
  210. +   }
  211. +  
  212. +   private void checkSpoil()
  213. +   {
  214. +       if (canBeSweepedByMe() && getMonsterTarget().isDead())
  215. +       {
  216. +           L2Skill sweeper = player.getSkill(42);
  217. +           if (sweeper == null)
  218. +               return;
  219. +          
  220. +           useMagicSkill(sweeper, false);
  221. +       }
  222. +   }
  223. +
  224. +   private Double getHpPercentage()
  225. +   {
  226. +       return player.getCurrentHp() * 100.0f / player.getMaxHp();
  227. +   }
  228. +
  229. +   private Double percentageMpIsLessThan()
  230. +   {
  231. +       return player.getCurrentMp() * 100.0f / player.getMaxMp();
  232. +   }
  233. +
  234. +   private Double percentageHpIsLessThan()
  235. +   {
  236. +       return player.getCurrentHp() * 100.0f / player.getMaxHp();
  237. +   }
  238. +
  239. +   private List<Integer> getAttackSpells()
  240. +   {
  241. +       return getSpellsInSlots(AutofarmConstants.attackSlots);
  242. +   }
  243. +
  244. +   private List<Integer> getSpellsInSlots(List<Integer> attackSlots)
  245. +   {
  246. +       return Arrays.stream(player.getAllShortCuts()).filter(shortcut -> shortcut.getPage() == player.getPage() && shortcut.getType() == L2ShortCut.TYPE_SKILL && attackSlots.contains(shortcut.getSlot())).map(L2ShortCut::getId).collect(Collectors.toList());
  247. +   }
  248. +
  249. +   private List<Integer> getChanceSpells()
  250. +   {
  251. +       return getSpellsInSlots(AutofarmConstants.chanceSlots);
  252. +   }
  253. +
  254. +   private List<Integer> getLowLifeSpells()
  255. +   {
  256. +       return getSpellsInSlots(AutofarmConstants.lowLifeSlots);
  257. +   }
  258. +
  259. +   private boolean shotcutsContainAttack()
  260. +   {
  261. +       return Arrays.stream(player.getAllShortCuts()).anyMatch(shortcut -> shortcut.getPage() == player.getPage() && shortcut.getType() == L2ShortCut.TYPE_ACTION && (shortcut.getId() == 2 || player.isSummonAttack() && shortcut.getId() == 22));
  262. +   }
  263. +  
  264. +   private boolean monsterIsAlreadySpoiled()
  265. +   {
  266. +       return getMonsterTarget() != null && getMonsterTarget().getSpoilerId() != 0;
  267. +   }
  268. +  
  269. +   private static boolean isSpoil(Integer skillId)
  270. +   {
  271. +       return skillId == 254 || skillId == 302;
  272. +   }
  273. +  
  274. +   private boolean canBeSweepedByMe()
  275. +   {
  276. +       return getMonsterTarget() != null && getMonsterTarget().isDead() && getMonsterTarget().getSpoilerId() == player.getObjectId();
  277. +   }
  278. +  
  279. +   private void castSpellWithAppropriateTarget(L2Skill skill, Boolean forceOnSelf)
  280. +   {
  281. +       if (forceOnSelf)
  282. +       {
  283. +           WorldObject oldTarget = player.getTarget();
  284. +           player.setTarget(player);
  285. +           player.useMagic(skill, false, false);
  286. +           player.setTarget(oldTarget);
  287. +           return;
  288. +       }
  289. +
  290. +       player.useMagic(skill, false, false);
  291. +   }
  292. +
  293. +   private void physicalAttack()
  294. +   {
  295. +       if (!(player.getTarget() instanceof Monster))
  296. +           return;
  297. +
  298. +       Monster target = (Monster) player.getTarget();
  299. +
  300. +       if (!player.isMageClass())
  301. +       {
  302. +           if (target.isAutoAttackable(player) && GeoEngine.getInstance().canSeeTarget(player, target))
  303. +           {
  304. +               if (GeoEngine.getInstance().canSeeTarget(player, target))
  305. +               {
  306. +                   player.getAI().setIntention(CtrlIntention.ATTACK, target);
  307. +                   player.onActionRequest();
  308. +
  309. +                   if (player.isSummonAttack() && player.getPet() != null)
  310. +                   {
  311. +                       // Siege Golem's
  312. +                       if (player.getPet().getNpcId() >= 14702 && player.getPet().getNpcId() <= 14798 || player.getPet().getNpcId() >= 14839 && player.getPet().getNpcId() <= 14869)
  313. +                           return;
  314. +
  315. +                       Summon activeSummon = player.getPet();
  316. +                       activeSummon.setTarget(target);
  317. +                       activeSummon.getAI().setIntention(CtrlIntention.ATTACK, target);
  318. +
  319. +                       int[] summonAttackSkills = {4261, 4068, 4137, 4260, 4708, 4709, 4710, 4712, 5135, 5138, 5141, 5442, 5444, 6095, 6096, 6041, 6044};
  320. +                       if (Rnd.get(100) < player.getSummonSkillPercent())
  321. +                       {
  322. +                           for (int skillId : summonAttackSkills)
  323. +                           {
  324. +                               useMagicSkillBySummon(skillId, target);
  325. +                           }
  326. +                       }
  327. +                   }
  328. +               }
  329. +           }
  330. +           else
  331. +           {
  332. +               if (target.isAutoAttackable(player) && GeoEngine.getInstance().canSeeTarget(player, target))
  333. +               if (GeoEngine.getInstance().canSeeTarget(player, target))
  334. +                   player.getAI().setIntention(CtrlIntention.FOLLOW, target);
  335. +           }
  336. +       }
  337. +       else
  338. +       {
  339. +           if (player.isSummonAttack() && player.getPet() != null)
  340. +           {
  341. +               // Siege Golem's
  342. +               if (player.getPet().getNpcId() >= 14702 && player.getPet().getNpcId() <= 14798 || player.getPet().getNpcId() >= 14839 && player.getPet().getNpcId() <= 14869)
  343. +                   return;
  344. +
  345. +               Summon activeSummon = player.getPet();
  346. +               activeSummon.setTarget(target);
  347. +               activeSummon.getAI().setIntention(CtrlIntention.ATTACK, target);
  348. +
  349. +               int[] summonAttackSkills = {4261, 4068, 4137, 4260, 4708, 4709, 4710, 4712, 5135, 5138, 5141, 5442, 5444, 6095, 6096, 6041, 6044};
  350. +               if (Rnd.get(100) < player.getSummonSkillPercent())
  351. +               {
  352. +                   for (int skillId : summonAttackSkills)
  353. +                   {
  354. +                       useMagicSkillBySummon(skillId, target);
  355. +                   }
  356. +               }
  357. +           }
  358. +       }
  359. +   }
  360. +
  361. +
  362. +   public void targetEligibleCreature() {
  363. +       if (player.getTarget() == null) {
  364. +           selectNewTarget();
  365. +           return;
  366. +       }
  367. +
  368. +       if (committedTarget != null) {
  369. +         if (!committedTarget.isDead() && GeoEngine.getInstance().canSeeTarget(player, committedTarget)) {
  370. +               attack();
  371. +               return;
  372. +           } else if (!GeoEngine.getInstance().canSeeTarget(player, committedTarget)) {
  373. +               committedTarget = null;
  374. +               selectNewTarget();
  375. +               return;
  376. +           }
  377. +           player.getAI().setIntention(CtrlIntention.FOLLOW, committedTarget);
  378. +           committedTarget = null;
  379. +           player.setTarget(null);
  380. +       }
  381. +      
  382. +       if (committedTarget instanceof Summon)
  383. +           return;
  384. +          
  385. +       List<Monster> targets = getKnownMonstersInRadius(player, player.getRadius(), creature -> GeoEngine.getInstance().canMoveToTarget(player.getX(), player.getY(), player.getZ(), creature.getX(), creature.getY(), creature.getZ()) && !player.ignoredMonsterContain(creature.getNpcId()) && !creature.isRaidMinion() && !creature.isRaid() && !creature.isDead() && !(creature instanceof Chest) && !(player.isAntiKsProtected() && creature.getTarget() != null && creature.getTarget() != player && creature.getTarget() != player.getPet()) );
  386. +
  387. +       if (targets.isEmpty())
  388. +           return;
  389. +
  390. +       Monster closestTarget = targets.stream().min((o1, o2) -> Integer.compare((int) Math.sqrt(player.getDistanceSq(o1)), (int) Math.sqrt(player.getDistanceSq(o2)))).get();
  391. +
  392. +       committedTarget = closestTarget;
  393. +       player.setTarget(closestTarget);
  394. +   }
  395. +
  396. +
  397. +  
  398. +
  399. +
  400. +  
  401. +   private void selectNewTarget()
  402. +   {
  403. +       List<Monster> targets = getKnownMonstersInRadius(player, player.getRadius(), creature -> GeoEngine.getInstance().canMoveToTarget(player.getX(), player.getY(), player.getZ(), creature.getX(), creature.getY(), creature.getZ()) && !player.ignoredMonsterContain(creature.getNpcId()) && !creature.isRaidMinion() && !creature.isRaid() && !creature.isDead() && !(creature instanceof Chest) && !(player.isAntiKsProtected() && creature.getTarget() != null && creature.getTarget() != player && creature.getTarget() != player.getPet()) );
  404. +
  405. +       if (targets.isEmpty())
  406. +           return;
  407. +
  408. +       Monster closestTarget = targets.stream().min((o1, o2) -> Integer.compare((int) Math.sqrt(player.getDistanceSq(o1)), (int) Math.sqrt(player.getDistanceSq(o2)))).get();
  409. +
  410. +       committedTarget = closestTarget;
  411. +       player.setTarget(closestTarget);
  412. +   }
  413. +
  414. +
  415. +
  416. +
  417. +   public final static List<Monster> getKnownMonstersInRadius(Player player, int radius, Function<Monster, Boolean> condition)
  418. +   {
  419. +       final WorldRegion region = player.getRegion();
  420. +       if (region == null)
  421. +           return Collections.emptyList();
  422. +
  423. +       final List<Monster> result = new ArrayList<>();
  424. +
  425. +       for (WorldRegion reg : region.getSurroundingRegions())
  426. +       {
  427. +           for (WorldObject obj : reg.getObjects())
  428. +           {
  429. +               if (!(obj instanceof Monster) || !MathUtil.checkIfInRange(radius, player, obj, true) || !condition.apply((Monster) obj))
  430. +                   continue;
  431. +
  432. +               result.add((Monster) obj);
  433. +           }
  434. +       }
  435. +
  436. +       return result;
  437. +   }
  438. +
  439. +   public Monster getMonsterTarget()
  440. +   {
  441. +       if(!(player.getTarget() instanceof Monster))
  442. +       {
  443. +           return null;
  444. +       }
  445. +
  446. +       return (Monster)player.getTarget();
  447. +   }
  448. +
  449. +   private void useMagicSkill(L2Skill skill, Boolean forceOnSelf)
  450. +   {
  451. +       if (skill.getSkillType() == L2SkillType.RECALL && !Config.KARMA_PLAYER_CAN_TELEPORT && player.getKarma() > 0)
  452. +       {
  453. +           player.sendPacket(ActionFailed.STATIC_PACKET);
  454. +           return;
  455. +       }
  456. +
  457. +       if (skill.isToggle() && player.isMounted())
  458. +       {
  459. +           player.sendPacket(ActionFailed.STATIC_PACKET);
  460. +           return;
  461. +       }
  462. +
  463. +       if (player.isOutOfControl())
  464. +       {
  465. +           player.sendPacket(ActionFailed.STATIC_PACKET);
  466. +           return;
  467. +       }
  468. +
  469. +       if (player.isAttackingNow())
  470. +           player.getAI().setNextAction(new NextAction(CtrlEvent.EVT_READY_TO_ACT, CtrlIntention.CAST, () -> castSpellWithAppropriateTarget(skill, forceOnSelf)));
  471. +       else
  472. +           castSpellWithAppropriateTarget(skill, forceOnSelf);
  473. +   }
  474. +  
  475. +   private boolean useMagicSkillBySummon(int skillId, WorldObject target)
  476. +   {
  477. +       // No owner, or owner in shop mode.
  478. +       if (player == null || player.isInStoreMode())
  479. +           return false;
  480. +      
  481. +       final Summon activeSummon = player.getPet();
  482. +       if (activeSummon == null)
  483. +           return false;
  484. +      
  485. +       // Pet which is 20 levels higher than owner.
  486. +       if (activeSummon instanceof Pet && activeSummon.getLevel() - player.getLevel() > 20)
  487. +       {
  488. +           player.sendPacket(SystemMessageId.PET_TOO_HIGH_TO_CONTROL);
  489. +           return false;
  490. +       }
  491. +      
  492. +       // Out of control pet.
  493. +       if (activeSummon.isOutOfControl())
  494. +       {
  495. +           player.sendPacket(SystemMessageId.PET_REFUSING_ORDER);
  496. +           return false;
  497. +       }
  498. +      
  499. +       // Verify if the launched skill is mastered by the summon.
  500. +       final L2Skill skill = activeSummon.getSkill(skillId);
  501. +       if (skill == null)
  502. +           return false;
  503. +      
  504. +       // Can't launch offensive skills on owner.
  505. +       if (skill.isOffensive() && player == target)
  506. +           return false;
  507. +      
  508. +       activeSummon.setTarget(target);
  509. +       return activeSummon.useMagic(skill, false, false);
  510. +   }
  511. +
  512. +   private void calculatePotions()
  513. +   {
  514. +       if (percentageHpIsLessThan() < player.getHpPotionPercentage())
  515. +           forceUseItem(1539);
  516. +
  517. +       if (percentageMpIsLessThan() < player.getMpPotionPercentage())
  518. +           forceUseItem(728);
  519. +   }  
  520. +
  521. +   private void forceUseItem(int itemId)
  522. +   {
  523. +       final ItemInstance potion = player.getInventory().getItemByItemId(itemId);
  524. +       if (potion == null)
  525. +           return;
  526. +
  527. +       final IItemHandler handler = ItemHandler.getInstance().getItemHandler(potion.getEtcItem());
  528. +       if (handler != null)
  529. +           handler.useItem(player, potion, false);
  530. +   }  
  531. +}
  532. \ No newline at end of file
  533. diff --git java/Base/AutoFarm/AutofarmSpell.java java/Base/AutoFarm/AutofarmSpell.java
  534. new file mode 100644
  535. index 0000000..beefc8d
  536. --- /dev/null
  537. +++ java/Base/AutoFarm/AutofarmSpell.java
  538. @@ -0,0 +1,20 @@
  539. +package Base.AutoFarm;
  540. +
  541. +public class AutofarmSpell {
  542. +   private final Integer _skillId;
  543. +   private final AutofarmSpellType _spellType;
  544. +  
  545. +   public AutofarmSpell(Integer skillId, AutofarmSpellType spellType){
  546. +      
  547. +       _skillId = skillId;
  548. +       _spellType = spellType;
  549. +   }
  550. +  
  551. +   public Integer getSkillId() {
  552. +       return _skillId;
  553. +   }
  554. +  
  555. +   public AutofarmSpellType getSpellType() {
  556. +       return _spellType;
  557. +   }
  558. +}
  559. \ No newline at end of file
  560. diff --git java/Base/AutoFarm/AutofarmSpellType.java java/Base/AutoFarm/AutofarmSpellType.java
  561. new file mode 100644
  562. index 0000000..2ec3039
  563. --- /dev/null
  564. +++ java/Base/AutoFarm/AutofarmSpellType.java
  565. @@ -0,0 +1,8 @@
  566. +package Base.AutoFarm;
  567. +
  568. +public enum AutofarmSpellType
  569. +{
  570. +    Attack,
  571. +    Chance,
  572. +    LowLife    
  573. +}
  574. \ No newline at end of file
  575. diff --git java/com/l2jmega/gameserver/handler/VoicedCommandHandler.java java/com/l2jmega/gameserver/handler/VoicedCommandHandler.java
  576. index 7532a04..8463819 100644
  577. --- java/com/l2jmega/gameserver/handler/VoicedCommandHandler.java
  578. +++ java/com/l2jmega/gameserver/handler/VoicedCommandHandler.java
  579. @@ -17,6 +17,7 @@
  580.  import java.util.HashMap;
  581.  import java.util.Map;
  582.  
  583. +import com.l2jmega.gameserver.handler.voicedcommandhandlers.VoicedAutoFarm;
  584.  import com.l2jmega.gameserver.handler.voicedcommandhandlers.VoicedAutoPotion;
  585.  import com.l2jmega.gameserver.handler.voicedcommandhandlers.VoicedBanking;
  586.  import com.l2jmega.gameserver.handler.voicedcommandhandlers.VoicedBossSpawn;
  587. @@ -52,6 +53,7 @@
  588.         registerHandler(new VoicedAutoPotion());
  589.         registerHandler(new VoicedPassword());
  590.         registerHandler(new VoicedEnchant());
  591. +       registerHandler(new VoicedAutoFarm());
  592.        
  593.         registerHandler(new VoicedTrySkin());
  594.         registerHandler(new VoicedRanking());
  595. diff --git java/com/l2jmega/gameserver/handler/voicedcommandhandlers/VoicedAutoFarm.java java/com/l2jmega/gameserver/handler/voicedcommandhandlers/VoicedAutoFarm.java
  596. new file mode 100644
  597. index 0000000..a2c1c4a
  598. --- /dev/null
  599. +++ java/com/l2jmega/gameserver/handler/voicedcommandhandlers/VoicedAutoFarm.java
  600. @@ -0,0 +1,325 @@
  601. +package com.l2jmega.gameserver.handler.voicedcommandhandlers;
  602. +
  603. +import com.l2jmega.gameserver.handler.IVoicedCommandHandler;
  604. +import com.l2jmega.gameserver.model.WorldObject;
  605. +import com.l2jmega.gameserver.model.actor.instance.Monster;
  606. +import com.l2jmega.gameserver.model.actor.instance.Player;
  607. +import com.l2jmega.gameserver.network.SystemMessageId;
  608. +import com.l2jmega.gameserver.network.serverpackets.ExShowScreenMessage;
  609. +import com.l2jmega.gameserver.network.serverpackets.ExShowScreenMessage.SMPOS;
  610. +import com.l2jmega.gameserver.network.serverpackets.NpcHtmlMessage;
  611. +import com.l2jmega.gameserver.network.serverpackets.SystemMessage;
  612. +
  613. +import java.util.StringTokenizer;
  614. +
  615. +import com.l2jmega.commons.lang.StringUtil;
  616. +
  617. +import Base.AutoFarm.AutofarmPlayerRoutine;
  618. +
  619. +
  620. +
  621. +
  622. +
  623. +public class VoicedAutoFarm implements IVoicedCommandHandler
  624. +{
  625. +    private final String[] VOICED_COMMANDS =
  626. +    {
  627. +       "autofarm",
  628. +       "enableAutoFarm",
  629. +       "radiusAutoFarm",
  630. +       "pageAutoFarm",
  631. +       "enableBuffProtect",
  632. +       "healAutoFarm",
  633. +       "hpAutoFarm",
  634. +       "mpAutoFarm",
  635. +       "enableAntiKs",
  636. +       "enableSummonAttack",
  637. +       "summonSkillAutoFarm",
  638. +       "ignoreMonster",
  639. +       "activeMonster"
  640. +   };
  641. +
  642. +    @Override
  643. +    public boolean useVoicedCommand(final String command, final Player activeChar, final String args)
  644. +   {
  645. +       final AutofarmPlayerRoutine bot = activeChar.getBot();
  646. +      
  647. +       if (command.startsWith("autofarm"))
  648. +           showAutoFarm(activeChar);
  649. +      
  650. +       if (command.startsWith("radiusAutoFarm"))
  651. +       {
  652. +           StringTokenizer st = new StringTokenizer(command, " ");
  653. +           st.nextToken();
  654. +           try
  655. +           {
  656. +               String param = st.nextToken();
  657. +
  658. +               if (param.startsWith("inc_radius"))
  659. +               {
  660. +                   activeChar.setRadius(activeChar.getRadius() + 200);
  661. +                   showAutoFarm(activeChar);
  662. +               }
  663. +               else if (param.startsWith("dec_radius"))
  664. +               {
  665. +                   activeChar.setRadius(activeChar.getRadius() - 200);
  666. +                   showAutoFarm(activeChar);
  667. +               }
  668. +               activeChar.saveAutoFarmSettings();
  669. +           }
  670. +           catch (Exception e)
  671. +           {
  672. +               e.printStackTrace();
  673. +           }
  674. +       }
  675. +      
  676. +       if (command.startsWith("pageAutoFarm"))
  677. +       {
  678. +           StringTokenizer st = new StringTokenizer(command, " ");
  679. +           st.nextToken();
  680. +           try
  681. +           {
  682. +               String param = st.nextToken();
  683. +
  684. +               if (param.startsWith("inc_page"))
  685. +               {
  686. +                   activeChar.setPage(activeChar.getPage() + 1);
  687. +                   showAutoFarm(activeChar);
  688. +               }
  689. +               else if (param.startsWith("dec_page"))
  690. +               {
  691. +                   activeChar.setPage(activeChar.getPage() - 1);
  692. +                   showAutoFarm(activeChar);
  693. +               }
  694. +               activeChar.saveAutoFarmSettings();
  695. +           }
  696. +           catch (Exception e)
  697. +           {
  698. +               e.printStackTrace();
  699. +           }
  700. +       }
  701. +      
  702. +       if (command.startsWith("healAutoFarm"))
  703. +       {
  704. +           StringTokenizer st = new StringTokenizer(command, " ");
  705. +           st.nextToken();
  706. +           try
  707. +           {
  708. +               String param = st.nextToken();
  709. +
  710. +               if (param.startsWith("inc_heal"))
  711. +               {
  712. +                   activeChar.setHealPercent(activeChar.getHealPercent() + 10);
  713. +                   showAutoFarm(activeChar);
  714. +               }
  715. +               else if (param.startsWith("dec_heal"))
  716. +               {
  717. +                   activeChar.setHealPercent(activeChar.getHealPercent() - 10);
  718. +                   showAutoFarm(activeChar);
  719. +               }
  720. +               activeChar.saveAutoFarmSettings();
  721. +           }
  722. +           catch (Exception e)
  723. +           {
  724. +               e.printStackTrace();
  725. +           }
  726. +       }
  727. +      
  728. +       if (command.startsWith("hpAutoFarm"))
  729. +       {
  730. +           StringTokenizer st = new StringTokenizer(command, " ");
  731. +           st.nextToken();
  732. +           try
  733. +           {
  734. +               String param = st.nextToken();
  735. +
  736. +               if (param.contains("inc_hp_pot"))
  737. +               {
  738. +                   activeChar.setHpPotionPercentage(activeChar.getHpPotionPercentage() + 5);
  739. +                   showAutoFarm(activeChar);
  740. +               }
  741. +               else if (param.contains("dec_hp_pot"))
  742. +               {
  743. +                   activeChar.setHpPotionPercentage(activeChar.getHpPotionPercentage() - 5);
  744. +                   showAutoFarm(activeChar);
  745. +               }
  746. +               activeChar.saveAutoFarmSettings();
  747. +           }
  748. +           catch (Exception e)
  749. +           {
  750. +               e.printStackTrace();
  751. +           }
  752. +       }
  753. +      
  754. +       if (command.startsWith("mpAutoFarm"))
  755. +       {
  756. +           StringTokenizer st = new StringTokenizer(command, " ");
  757. +           st.nextToken();
  758. +           try
  759. +           {
  760. +               String param = st.nextToken();
  761. +
  762. +               if (param.contains("inc_mp_pot"))
  763. +               {
  764. +                   activeChar.setMpPotionPercentage(activeChar.getMpPotionPercentage() + 5);
  765. +                   showAutoFarm(activeChar);
  766. +               }
  767. +               else if (param.contains("dec_mp_pot"))
  768. +               {
  769. +                   activeChar.setMpPotionPercentage(activeChar.getMpPotionPercentage() - 5);
  770. +                   showAutoFarm(activeChar);
  771. +               }
  772. +               activeChar.saveAutoFarmSettings();
  773. +           }
  774. +           catch (Exception e)
  775. +           {
  776. +               e.printStackTrace();
  777. +           }
  778. +       }
  779. +      
  780. +       if (command.startsWith("enableAutoFarm"))
  781. +       {
  782. +           if (activeChar.isAutoFarm())
  783. +           {
  784. +               bot.stop();
  785. +               activeChar.setAutoFarm(false);
  786. +           }
  787. +           else
  788. +           {
  789. +               bot.start();
  790. +               activeChar.setAutoFarm(true);
  791. +           }
  792. +
  793. +           showAutoFarm(activeChar);
  794. +       }
  795. +      
  796. +       if (command.startsWith("enableBuffProtect"))
  797. +       {
  798. +           activeChar.setNoBuffProtection(!activeChar.isNoBuffProtected());
  799. +           showAutoFarm(activeChar);
  800. +           activeChar.saveAutoFarmSettings();
  801. +       }
  802. +      
  803. +       if (command.startsWith("enableAntiKs"))
  804. +       {
  805. +           activeChar.setAntiKsProtection(!activeChar.isAntiKsProtected());
  806. +          
  807. +           if(activeChar.isAntiKsProtected()) {
  808. +               activeChar.sendPacket(new SystemMessage(SystemMessageId.ACTIVATE_RESPECT_HUNT));
  809. +               activeChar.sendPacket(new ExShowScreenMessage("Respct Hunt On" , 3*1000, SMPOS.TOP_CENTER, false));
  810. +           }else {
  811. +               activeChar.sendPacket(new SystemMessage(SystemMessageId.DESACTIVATE_RESPECT_HUNT));
  812. +               activeChar.sendPacket(new ExShowScreenMessage("Respct Hunt Off" , 3*1000, SMPOS.TOP_CENTER, false));
  813. +           }
  814. +          
  815. +           activeChar.saveAutoFarmSettings();
  816. +           showAutoFarm(activeChar);
  817. +       }
  818. +      
  819. +       if (command.startsWith("enableSummonAttack"))
  820. +       {
  821. +           activeChar.setSummonAttack(!activeChar.isSummonAttack());
  822. +           if(activeChar.isSummonAttack()) {
  823. +               activeChar.sendPacket(new SystemMessage(SystemMessageId.ACTIVATE_SUMMON_ACTACK));
  824. +               activeChar.sendPacket(new ExShowScreenMessage("Auto Farm Summon Attack On" , 3*1000, SMPOS.TOP_CENTER, false));
  825. +           }else {
  826. +               activeChar.sendPacket(new SystemMessage(SystemMessageId.DESACTIVATE_SUMMON_ACTACK));
  827. +               activeChar.sendPacket(new ExShowScreenMessage("Auto Farm Summon Attack Off" , 3*1000, SMPOS.TOP_CENTER, false));
  828. +           }
  829. +           activeChar.saveAutoFarmSettings();
  830. +           showAutoFarm(activeChar);
  831. +       }
  832. +      
  833. +       if (command.startsWith("summonSkillAutoFarm"))
  834. +       {
  835. +           StringTokenizer st = new StringTokenizer(command, " ");
  836. +           st.nextToken();
  837. +           try
  838. +           {
  839. +               String param = st.nextToken();
  840. +
  841. +               if (param.startsWith("inc_summonSkill"))
  842. +               {
  843. +                   activeChar.setSummonSkillPercent(activeChar.getSummonSkillPercent() + 10);
  844. +                   showAutoFarm(activeChar);
  845. +               }
  846. +               else if (param.startsWith("dec_summonSkill"))
  847. +               {
  848. +                   activeChar.setSummonSkillPercent(activeChar.getSummonSkillPercent() - 10);
  849. +                   showAutoFarm(activeChar);
  850. +               }
  851. +               activeChar.saveAutoFarmSettings();
  852. +           }
  853. +           catch (Exception e)
  854. +           {
  855. +               e.printStackTrace();
  856. +           }
  857. +       }
  858. +      
  859. +       if (command.startsWith("ignoreMonster"))
  860. +       {
  861. +           int monsterId = 0;
  862. +           WorldObject target = activeChar.getTarget();
  863. +           if (target instanceof Monster)
  864. +               monsterId = ((Monster) target).getNpcId();
  865. +          
  866. +           if (target == null)
  867. +           {
  868. +               activeChar.sendMessage("You dont have a target");
  869. +               return false;
  870. +           }
  871. +          
  872. +           activeChar.sendMessage(target.getName() + " has been added to the ignore list.");
  873. +           activeChar.ignoredMonster(monsterId);
  874. +       }
  875. +      
  876. +       if (command.startsWith("activeMonster"))
  877. +       {
  878. +           int monsterId = 0;
  879. +           WorldObject target = activeChar.getTarget();
  880. +           if (target instanceof Monster)
  881. +               monsterId = ((Monster) target).getNpcId();
  882. +          
  883. +           if (target == null)
  884. +           {
  885. +               activeChar.sendMessage("You dont have a target");
  886. +               return false;
  887. +           }
  888. +          
  889. +           activeChar.sendMessage(target.getName() + " has been removed from the ignore list.");
  890. +           activeChar.activeMonster(monsterId);
  891. +       }
  892. +      
  893. +        return false;
  894. +    }
  895. +  
  896. +   private static final String ACTIVED = "<font color=00FF00>STARTED</font>";
  897. +   private static final String DESATIVED = "<font color=FF0000>STOPPED</font>";
  898. +   private static final String STOP = "STOP";
  899. +   private static final String START = "START";
  900. +  
  901. +   public static void showAutoFarm(Player activeChar)
  902. +   {
  903. +       NpcHtmlMessage html = new NpcHtmlMessage(0);
  904. +       html.setFile("data/html/mods/menu/AutoFarm.htm");
  905. +       html.replace("%player%", activeChar.getName());
  906. +       html.replace("%page%", StringUtil.formatNumber(activeChar.getPage() + 1));
  907. +       html.replace("%heal%", StringUtil.formatNumber(activeChar.getHealPercent()));
  908. +       html.replace("%radius%", StringUtil.formatNumber(activeChar.getRadius()));
  909. +       html.replace("%summonSkill%", StringUtil.formatNumber(activeChar.getSummonSkillPercent()));
  910. +       html.replace("%hpPotion%", StringUtil.formatNumber(activeChar.getHpPotionPercentage()));
  911. +       html.replace("%mpPotion%", StringUtil.formatNumber(activeChar.getMpPotionPercentage()));
  912. +       html.replace("%noBuff%", activeChar.isNoBuffProtected() ? "back=L2UI.CheckBox_checked fore=L2UI.CheckBox_checked" : "back=L2UI.CheckBox fore=L2UI.CheckBox");
  913. +       html.replace("%summonAtk%", activeChar.isSummonAttack() ? "back=L2UI.CheckBox_checked fore=L2UI.CheckBox_checked" : "back=L2UI.CheckBox fore=L2UI.CheckBox");
  914. +       html.replace("%antiKs%", activeChar.isAntiKsProtected() ? "back=L2UI.CheckBox_checked fore=L2UI.CheckBox_checked" : "back=L2UI.CheckBox fore=L2UI.CheckBox");
  915. +       html.replace("%autofarm%", activeChar.isAutoFarm() ? ACTIVED : DESATIVED);
  916. +       html.replace("%button%", activeChar.isAutoFarm() ? STOP : START);
  917. +       activeChar.sendPacket(html);
  918. +   }
  919. +
  920. +    @Override
  921. +    public String[] getVoicedCommandList()
  922. +    {
  923. +        return VOICED_COMMANDS;
  924. +    }
  925. +}
  926. \ No newline at end of file
  927. diff --git java/com/l2jmega/gameserver/model/actor/instance/Gatekeeper.java java/com/l2jmega/gameserver/model/actor/instance/Gatekeeper.java
  928. index 8a667a8..ec52f89 100644
  929. --- java/com/l2jmega/gameserver/model/actor/instance/Gatekeeper.java
  930. +++ java/com/l2jmega/gameserver/model/actor/instance/Gatekeeper.java
  931. @@ -7,6 +7,8 @@
  932.  import com.l2jmega.commons.math.MathUtil;
  933.  import com.l2jmega.commons.random.Rnd;
  934.  
  935. +import Base.AutoFarm.AutofarmPlayerRoutine;
  936. +
  937.  import com.l2jmega.Config;
  938.  import com.l2jmega.events.ArenaTask;
  939.  import com.l2jmega.gameserver.data.SpawnTable;
  940. @@ -22,6 +24,7 @@
  941.  import com.l2jmega.gameserver.network.SystemMessageId;
  942.  import com.l2jmega.gameserver.network.serverpackets.ActionFailed;
  943.  import com.l2jmega.gameserver.network.serverpackets.NpcHtmlMessage;
  944. +import com.l2jmega.gameserver.network.serverpackets.SystemMessage;
  945.  
  946.  public final class Gatekeeper extends Folk
  947.  {
  948. @@ -48,6 +51,8 @@
  949.             player.sendMessage("You can not do that!");
  950.             return;
  951.         }
  952. +       final AutofarmPlayerRoutine bot = player.getBot();
  953. +      
  954.        
  955.         if (player.isArenaProtection())
  956.         {
  957. @@ -1250,6 +1255,15 @@
  958.                
  959.                 if (player.destroyItemByItemId("Teleport ", (list.isNoble()) ? 6651 : 57, price, this, true))
  960.                     player.teleToLocation(list, 100);
  961. +               player.sendPacket(new SystemMessage(SystemMessageId.WILL_BE_MOVED_INTERFACE));
  962. +          
  963. +          
  964. +           if (player.isAutoFarm())
  965. +           {
  966. +               bot.stop();
  967. +               player.setAutoFarm(false);
  968. +           }
  969. +              
  970.                
  971.                 player.sendPacket(ActionFailed.STATIC_PACKET);
  972.             }
  973. diff --git java/com/l2jmega/gameserver/model/actor/instance/Player.java java/com/l2jmega/gameserver/model/actor/instance/Player.java
  974. index 845f9c1..2921ce9 100644
  975. --- java/com/l2jmega/gameserver/model/actor/instance/Player.java
  976. +++ java/com/l2jmega/gameserver/model/actor/instance/Player.java
  977. @@ -269,6 +269,7 @@
  978.  import com.l2jmega.commons.math.MathUtil;
  979.  import com.l2jmega.commons.random.Rnd;
  980.  
  981. +import Base.AutoFarm.AutofarmPlayerRoutine;
  982.  import phantom.Phantom_Archers;
  983.  import phantom.Phantom_Attack;
  984.  import phantom.Phantom_Farm;
  985. @@ -10285,6 +10286,10 @@
  986.     @Override
  987.     public void deleteMe()
  988.     {
  989. +      
  990. +              
  991. +               _bot.stop();
  992. +              
  993.         cleanup();
  994.         store();
  995.         super.deleteMe();
  996. @@ -10337,6 +10342,8 @@
  997.             // Remove the Player from the world
  998.             decayMe();
  999.            
  1000. +                       _bot.stop();
  1001. +          
  1002.             // If a party is in progress, leave it
  1003.             if (isInParty())
  1004.                 leaveParty();
  1005. @@ -14469,4 +14476,220 @@
  1006.     {
  1007.         _dressMe = val;
  1008.     }
  1009. +  
  1010. +   // ------------
  1011. +   // Autofarm
  1012. +   // ------------
  1013. +
  1014. +   private boolean _autoFarm;
  1015. +  
  1016. +   public void setAutoFarm(boolean comm)
  1017. +   {
  1018. +       _autoFarm = comm;
  1019. +   }
  1020. +
  1021. +   public boolean isAutoFarm()
  1022. +   {
  1023. +       return _autoFarm;
  1024. +   }
  1025. +  
  1026. +   private int autoFarmRadius = 1200;
  1027. +  
  1028. +   public void setRadius(int value)
  1029. +   {
  1030. +       autoFarmRadius = MathUtil.limit(value, 200, 3000);
  1031. +   }
  1032. +  
  1033. +   public int getRadius()
  1034. +   {
  1035. +       return autoFarmRadius;
  1036. +   }
  1037. +  
  1038. +   private int autoFarmShortCut = 9;
  1039. +  
  1040. +   public void setPage(int value)
  1041. +   {
  1042. +       autoFarmShortCut = MathUtil.limit(value, 0, 9);
  1043. +   }
  1044. +  
  1045. +   public int getPage()
  1046. +   {
  1047. +       return autoFarmShortCut;
  1048. +   }
  1049. +  
  1050. +   private int autoFarmHealPercente = 30;
  1051. +  
  1052. +   public void setHealPercent(int value)
  1053. +   {
  1054. +       autoFarmHealPercente = MathUtil.limit(value, 20, 90);
  1055. +   }
  1056. +  
  1057. +   public int getHealPercent()
  1058. +   {
  1059. +       return autoFarmHealPercente;
  1060. +   }
  1061. +  
  1062. +   private boolean autoFarmBuffProtection = false;
  1063. +  
  1064. +   public void setNoBuffProtection(boolean val)
  1065. +   {
  1066. +       autoFarmBuffProtection = val;
  1067. +   }
  1068. +  
  1069. +   public boolean isNoBuffProtected()
  1070. +   {
  1071. +       return autoFarmBuffProtection;
  1072. +   }
  1073. +  
  1074. +   private boolean autoAntiKsProtection = false;
  1075. +  
  1076. +   public void setAntiKsProtection(boolean val)
  1077. +   {
  1078. +       autoAntiKsProtection = val;
  1079. +   }
  1080. +  
  1081. +   public boolean isAntiKsProtected()
  1082. +   {
  1083. +       return autoAntiKsProtection;
  1084. +   }
  1085. +  
  1086. +   private boolean autoFarmSummonAttack = false;
  1087. +  
  1088. +   public void setSummonAttack(boolean val)
  1089. +   {
  1090. +       autoFarmSummonAttack = val;
  1091. +   }
  1092. +  
  1093. +   public boolean isSummonAttack()
  1094. +   {
  1095. +       return autoFarmSummonAttack;
  1096. +   }
  1097. +  
  1098. +   private int autoFarmSummonSkillPercente = 0;
  1099. +  
  1100. +   public void setSummonSkillPercent(int value)
  1101. +   {
  1102. +       autoFarmSummonSkillPercente = MathUtil.limit(value, 0, 90);
  1103. +   }
  1104. +  
  1105. +   public int getSummonSkillPercent()
  1106. +   {
  1107. +       return autoFarmSummonSkillPercente;
  1108. +   }
  1109. +
  1110. +   private int hpPotionPercent = 60;
  1111. +   private int mpPotionPercent = 60;
  1112. +
  1113. +   public void setHpPotionPercentage(int value)
  1114. +   {
  1115. +       hpPotionPercent = MathUtil.limit(value, 0, 100);
  1116. +   }
  1117. +
  1118. +   public int getHpPotionPercentage()
  1119. +   {
  1120. +       return hpPotionPercent;
  1121. +   }
  1122. +
  1123. +   public void setMpPotionPercentage(int value)
  1124. +   {
  1125. +       mpPotionPercent = MathUtil.limit(value, 0, 100);
  1126. +   }
  1127. +
  1128. +   public int getMpPotionPercentage()
  1129. +   {
  1130. +       return mpPotionPercent;
  1131. +   }
  1132. +
  1133. +   private List<Integer> _ignoredMonster = new ArrayList<>();
  1134. +
  1135. +   public void ignoredMonster(Integer npcId)
  1136. +   {
  1137. +       _ignoredMonster.add(npcId);
  1138. +   }
  1139. +
  1140. +   public void activeMonster(Integer npcId)
  1141. +   {
  1142. +       if (_ignoredMonster.contains(npcId))
  1143. +           _ignoredMonster.remove(npcId);
  1144. +   }
  1145. +
  1146. +   public boolean ignoredMonsterContain(int npcId)
  1147. +   {
  1148. +       return _ignoredMonster.contains(npcId);
  1149. +   }
  1150. +
  1151. +   private AutofarmPlayerRoutine _bot = new AutofarmPlayerRoutine(this);
  1152. +  
  1153. +   public AutofarmPlayerRoutine getBot()
  1154. +   {
  1155. +       if (_bot == null)
  1156. +           _bot = new AutofarmPlayerRoutine(this);
  1157. +      
  1158. +       return _bot;
  1159. +   }
  1160. +  
  1161. +  
  1162. +    
  1163. +    public void saveAutoFarmSettings() {
  1164. +        try (Connection con = L2DatabaseFactory.getInstance().getConnection()) {
  1165. +            String updateSql = "REPLACE INTO character_autofarm (char_id, char_name,  radius, short_cut, heal_percent, buff_protection, anti_ks_protection, summon_attack, summon_skill_percent, hp_potion_percent, mp_potion_percent) VALUES (?, ?, ?,  ?, ?, ?, ?, ?, ?, ?, ?)";
  1166. +            try (PreparedStatement updateStatement = con.prepareStatement(updateSql)) {
  1167. +                updateStatement.setInt(1, getObjectId()); // char_id
  1168. +                updateStatement.setString(2, getName()); // char_name
  1169. +              
  1170. +                updateStatement.setInt(3, autoFarmRadius);
  1171. +                updateStatement.setInt(4, autoFarmShortCut);
  1172. +                updateStatement.setInt(5, autoFarmHealPercente);
  1173. +                updateStatement.setBoolean(6, autoFarmBuffProtection);
  1174. +                updateStatement.setBoolean(7, autoAntiKsProtection);
  1175. +                updateStatement.setBoolean(8, autoFarmSummonAttack);
  1176. +                updateStatement.setInt(9, autoFarmSummonSkillPercente);
  1177. +                updateStatement.setInt(10, hpPotionPercent);
  1178. +                updateStatement.setInt(11, mpPotionPercent);
  1179. +                updateStatement.executeUpdate();
  1180. +            }
  1181. +        } catch (SQLException e) {
  1182. +            e.printStackTrace();
  1183. +        }
  1184. +    }
  1185. +
  1186. +    public void loadAutoFarmSettings() {
  1187. +        try (Connection con = L2DatabaseFactory.getInstance().getConnection()) {
  1188. +            String selectSql = "SELECT * FROM character_autofarm WHERE char_id = ?";
  1189. +            try (PreparedStatement selectStatement = con.prepareStatement(selectSql)) {
  1190. +                selectStatement.setInt(1, getObjectId()); // char_id
  1191. +                try (ResultSet resultSet = selectStatement.executeQuery()) {
  1192. +                    if (resultSet.next()) {
  1193. +                      
  1194. +                        autoFarmRadius = resultSet.getInt("radius");
  1195. +                        autoFarmShortCut = resultSet.getInt("short_cut");
  1196. +                        autoFarmHealPercente = resultSet.getInt("heal_percent");
  1197. +                        autoFarmBuffProtection = resultSet.getBoolean("buff_protection");
  1198. +                        autoAntiKsProtection = resultSet.getBoolean("anti_ks_protection");
  1199. +                        autoFarmSummonAttack = resultSet.getBoolean("summon_attack");
  1200. +                        autoFarmSummonSkillPercente = resultSet.getInt("summon_skill_percent");
  1201. +                        hpPotionPercent = resultSet.getInt("hp_potion_percent");
  1202. +                        mpPotionPercent = resultSet.getInt("mp_potion_percent");
  1203. +                    } else {
  1204. +                        
  1205. +                      
  1206. +                        autoFarmRadius = 1200;
  1207. +                        autoFarmShortCut = 9;
  1208. +                        autoFarmHealPercente = 30;
  1209. +                        autoFarmBuffProtection = false;
  1210. +                        autoAntiKsProtection = false;
  1211. +                        autoFarmSummonAttack = false;
  1212. +                        autoFarmSummonSkillPercente = 0;
  1213. +                        hpPotionPercent = 60;
  1214. +                        mpPotionPercent = 60;
  1215. +                    }
  1216. +                }
  1217. +            }
  1218. +        } catch (SQLException e) {
  1219. +            e.printStackTrace();
  1220. +        }
  1221. +    }
  1222. +  
  1223. +  
  1224. +  
  1225.  }
  1226. \ No newline at end of file
  1227. diff --git java/com/l2jmega/gameserver/network/SystemMessageId.java java/com/l2jmega/gameserver/network/SystemMessageId.java
  1228. index 77a5c12..786f21b 100644
  1229. --- java/com/l2jmega/gameserver/network/SystemMessageId.java
  1230. +++ java/com/l2jmega/gameserver/network/SystemMessageId.java
  1231. @@ -6,6 +6,8 @@
  1232.  import java.util.logging.Level;
  1233.  import java.util.logging.Logger;
  1234.  
  1235. +
  1236. +
  1237.  import com.l2jmega.gameserver.network.serverpackets.SystemMessage;
  1238.  
  1239.  /**
  1240. @@ -11800,6 +11802,21 @@
  1241.    
  1242.     public static final SystemMessageId EVENT;
  1243.    
  1244. +   public static final SystemMessageId ACTIVATE_SUMMON_ACTACK;
  1245. +  
  1246. +  
  1247. +  
  1248. +   public static final SystemMessageId WILL_BE_MOVED_INTERFACE;
  1249. +   public static final SystemMessageId DESACTIVATE_SUMMON_ACTACK; 
  1250. +   public static final SystemMessageId ACTIVATE_RESPECT_HUNT;
  1251. +   public static final SystemMessageId DESACTIVATE_RESPECT_HUNT;
  1252. +  
  1253. +   public static final SystemMessageId AUTO_FARM_DESACTIVATED;
  1254. +   public static final SystemMessageId AUTO_FARM_ACTIVATED;
  1255. +  
  1256. +  
  1257. +  
  1258. +  
  1259.     /**
  1260.      * Array containing all SystemMessageIds<br>
  1261.      * Important: Always initialize with a length of the highest SystemMessageId + 1!!!
  1262. @@ -13768,6 +13785,13 @@
  1263.         S1_CANNOT_PARTICIPATE_IN_OLYMPIAD_DURING_TELEPORT = new SystemMessageId(2029);
  1264.         CURRENTLY_LOGGING_IN = new SystemMessageId(2030);
  1265.         PLEASE_WAIT_A_MOMENT = new SystemMessageId(2031);
  1266. +       WILL_BE_MOVED_INTERFACE = new SystemMessageId(2154);
  1267. +       AUTO_FARM_DESACTIVATED = new SystemMessageId(2155);
  1268. +       ACTIVATE_SUMMON_ACTACK = new SystemMessageId(2156);
  1269. +       DESACTIVATE_SUMMON_ACTACK = new SystemMessageId(2157);     
  1270. +       ACTIVATE_RESPECT_HUNT = new SystemMessageId(2158);
  1271. +       DESACTIVATE_RESPECT_HUNT = new SystemMessageId(2159);
  1272. +       AUTO_FARM_ACTIVATED = new SystemMessageId(2160);
  1273.         EVENT = new SystemMessageId(2500);
  1274.        
  1275.         buildFastLookupTable();
  1276. diff --git java/com/l2jmega/gameserver/network/clientpackets/EnterWorld.java java/com/l2jmega/gameserver/network/clientpackets/EnterWorld.java
  1277. index b5006c9..872ac51 100644
  1278. --- java/com/l2jmega/gameserver/network/clientpackets/EnterWorld.java
  1279. +++ java/com/l2jmega/gameserver/network/clientpackets/EnterWorld.java
  1280. @@ -238,6 +238,28 @@
  1281.             }
  1282.         }
  1283.        
  1284. +      
  1285. +       activeChar.loadAutoFarmSettings();
  1286. +      
  1287. +  
  1288. +      
  1289. +      
  1290. +      
  1291. +      
  1292. +      
  1293. +      
  1294. +       if(activeChar.isSummonAttack()) {
  1295. +           activeChar.sendPacket(new SystemMessage(SystemMessageId.ACTIVATE_SUMMON_ACTACK));
  1296. +          
  1297. +       }
  1298. +      
  1299. +       if(activeChar.isAntiKsProtected()) {
  1300. +           activeChar.sendPacket(new SystemMessage(SystemMessageId.ACTIVATE_RESPECT_HUNT));
  1301. +       }
  1302. +      
  1303. +      
  1304. +      
  1305. +      
  1306.         // activeChar.sendPacket(SevenSigns.getInstance().getCurrentPeriod().getMessageId());
  1307.        
  1308.         // if player is DE, check for shadow sense skill at night
  1309. diff --git java/com/l2jmega/gameserver/network/clientpackets/RequestBypassToServer.java java/com/l2jmega/gameserver/network/clientpackets/RequestBypassToServer.java
  1310. index 80e4aae..9564401 100644
  1311. --- java/com/l2jmega/gameserver/network/clientpackets/RequestBypassToServer.java
  1312. +++ java/com/l2jmega/gameserver/network/clientpackets/RequestBypassToServer.java
  1313. @@ -34,6 +34,7 @@
  1314.  import com.l2jmega.gameserver.network.serverpackets.ActionFailed;
  1315.  import com.l2jmega.gameserver.network.serverpackets.CreatureSay;
  1316.  import com.l2jmega.gameserver.network.serverpackets.ExShowScreenMessage;
  1317. +import com.l2jmega.gameserver.network.serverpackets.ExShowScreenMessage.SMPOS;
  1318.  import com.l2jmega.gameserver.network.serverpackets.HennaInfo;
  1319.  import com.l2jmega.gameserver.network.serverpackets.NpcHtmlMessage;
  1320.  import com.l2jmega.gameserver.network.serverpackets.PlaySound;
  1321. @@ -55,6 +56,8 @@
  1322.  import com.l2jmega.commons.lang.StringUtil;
  1323.  import com.l2jmega.commons.random.Rnd;
  1324.  
  1325. +import Base.AutoFarm.AutofarmPlayerRoutine;
  1326. +
  1327.  public final class RequestBypassToServer extends L2GameClientPacket
  1328.  {
  1329.     private static final Logger GMAUDIT_LOG = Logger.getLogger("gmaudit");
  1330. @@ -75,10 +78,14 @@
  1331.         if (!FloodProtectors.performAction(getClient(), Action.SERVER_BYPASS) && !_command.startsWith("voiced_getbuff"))
  1332.             return;
  1333.        
  1334. +      
  1335.         final Player activeChar = getClient().getActiveChar();
  1336.         if (activeChar == null)
  1337.             return;
  1338.        
  1339. +               final AutofarmPlayerRoutine bot = activeChar.getBot();
  1340. +              
  1341. +      
  1342.         if (_command.isEmpty())
  1343.         {
  1344.             _log.info(activeChar.getName() + " sent an empty requestBypass packet.");
  1345. @@ -114,6 +121,106 @@
  1346.                
  1347.                 ach.useAdminCommand(_command, activeChar);
  1348.             }
  1349. +          
  1350. +          
  1351. +           else if (_command.startsWith("_autofarm"))
  1352. +           {
  1353. +               if (activeChar.isAutoFarm())
  1354. +               {
  1355. +                   bot.stop();
  1356. +                   activeChar.setAutoFarm(false);
  1357. +               }
  1358. +               else
  1359. +               {
  1360. +                   bot.start();
  1361. +                   activeChar.setAutoFarm(true);
  1362. +               }
  1363. +              
  1364. +           }
  1365. +          
  1366. +           if (_command.startsWith("_pageAutoFarm"))
  1367. +           {
  1368. +               StringTokenizer st = new StringTokenizer(_command, " ");
  1369. +               st.nextToken();
  1370. +               try
  1371. +               {
  1372. +                   String param = st.nextToken();
  1373. +                  
  1374. +                   if (param.startsWith("inc_page") || param.startsWith("dec_page"))
  1375. +                   {
  1376. +                       int newPage;
  1377. +                      
  1378. +                       if (param.startsWith("inc_page"))
  1379. +                       {
  1380. +                           newPage = activeChar.getPage() + 1;
  1381. +                       }
  1382. +                       else
  1383. +                       {
  1384. +                           newPage = activeChar.getPage() - 1;
  1385. +                       }
  1386. +                      
  1387. +                       if (newPage >= 0 && newPage <= 9)
  1388. +                       {
  1389. +                           String[] pageStrings =
  1390. +                           {
  1391. +                               "F1",
  1392. +                               "F2",
  1393. +                               "F3",
  1394. +                               "F4",
  1395. +                               "F5",
  1396. +                               "F6",
  1397. +                               "F7",
  1398. +                               "F8",
  1399. +                               "F9",
  1400. +                               "F10"
  1401. +                           };
  1402. +                          
  1403. +                           activeChar.setPage(newPage);
  1404. +                           activeChar.sendPacket(new ExShowScreenMessage("Auto Farm Skill Bar " + pageStrings[newPage], 3 * 1000, SMPOS.TOP_CENTER, false));
  1405. +                           activeChar.saveAutoFarmSettings();
  1406. +                          
  1407. +                       }
  1408. +                      
  1409. +                   }
  1410. +                  
  1411. +               }
  1412. +               catch (Exception e)
  1413. +               {
  1414. +                   e.printStackTrace();
  1415. +               }
  1416. +           }
  1417. +          
  1418. +           if (_command.startsWith("_enableBuffProtect"))
  1419. +           {
  1420. +               activeChar.setNoBuffProtection(!activeChar.isNoBuffProtected());
  1421. +               if (activeChar.isNoBuffProtected())
  1422. +               {
  1423. +                   activeChar.sendPacket(new ExShowScreenMessage("Auto Farm Buff Protect On", 3 * 1000, SMPOS.TOP_CENTER, false));
  1424. +               }
  1425. +               else
  1426. +               {
  1427. +                   activeChar.sendPacket(new ExShowScreenMessage("Auto Farm Buff Protect Off", 3 * 1000, SMPOS.TOP_CENTER, false));
  1428. +               }
  1429. +               activeChar.saveAutoFarmSettings();
  1430. +           }
  1431. +           if (_command.startsWith("_enableSummonAttack"))
  1432. +           {
  1433. +               activeChar.setSummonAttack(!activeChar.isSummonAttack());
  1434. +               if (activeChar.isSummonAttack())
  1435. +               {
  1436. +                   activeChar.sendPacket(new SystemMessage(SystemMessageId.ACTIVATE_SUMMON_ACTACK));
  1437. +                   activeChar.sendPacket(new ExShowScreenMessage("Auto Farm Summon Attack On", 3 * 1000, SMPOS.TOP_CENTER, false));
  1438. +               }
  1439. +               else
  1440. +               {
  1441. +                   activeChar.sendPacket(new SystemMessage(SystemMessageId.DESACTIVATE_SUMMON_ACTACK));
  1442. +                   activeChar.sendPacket(new ExShowScreenMessage("Auto Farm Summon Attack Off", 3 * 1000, SMPOS.TOP_CENTER, false));
  1443. +               }
  1444. +               activeChar.saveAutoFarmSettings();
  1445. +           }
  1446. +          
  1447. +          
  1448. +          
  1449.             else if (_command.startsWith("voiced_"))
  1450.             {
  1451.                 String command = _command.split(" ")[0];
  1452. diff --git java/com/l2jmega/gameserver/network/serverpackets/Die.java java/com/l2jmega/gameserver/network/serverpackets/Die.java
  1453. index 10d58c0..889e0fc 100644
  1454. --- java/com/l2jmega/gameserver/network/serverpackets/Die.java
  1455. +++ java/com/l2jmega/gameserver/network/serverpackets/Die.java
  1456. @@ -11,6 +11,10 @@
  1457.  import com.l2jmega.gameserver.model.entity.Siege.SiegeSide;
  1458.  import com.l2jmega.gameserver.model.pledge.Clan;
  1459.  
  1460. +import Base.AutoFarm.AutofarmPlayerRoutine;
  1461. +
  1462. +
  1463. +
  1464.  public class Die extends L2GameServerPacket
  1465.  {
  1466.     private final Creature _activeChar;
  1467. @@ -31,9 +35,17 @@
  1468.         if (cha instanceof Player)
  1469.         {
  1470.             Player player = (Player) cha;
  1471. +           final AutofarmPlayerRoutine bot = player.getBot();
  1472.             _allowFixedRes = player.getAccessLevel().allowFixedRes();
  1473.             _clan = player.getClan();
  1474.             _canEvent = !(((TvT.is_started() || TvT.is_teleport()) && player._inEventTvT) || ((CTF.is_started() || CTF.is_teleport()) && player._inEventCTF) || cha.isInArenaEvent());
  1475. +      
  1476. +          
  1477. +           if (player.isAutoFarm())
  1478. +           {
  1479. +               bot.stop();
  1480. +               player.setAutoFarm(false);
  1481. +           }
  1482.            
  1483.         }
  1484.         else if (cha instanceof Attackable)
  1485.  
Add Comment
Please, Sign In to add comment