SHOW:
|
|
- or go back to the newest paste.
1 | ### Eclipse Workspace Patch 1.0 | |
2 | #P aCis_gameserver | |
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 | index e69de29..bb24adb 100644 | |
23 | --- java/Base/AutoFarm/AutofarmPlayerRoutine.java | |
24 | +++ java/Base/AutoFarm/AutofarmPlayerRoutine.java | |
25 | @@ -0,0 +1,669 @@ | |
26 | +package Base.AutoFarm; | |
27 | + | |
28 | +import net.sf.l2j.Config; | |
29 | + | |
30 | + | |
31 | +import net.sf.l2j.commons.math.MathUtil; | |
32 | +import net.sf.l2j.commons.pool.ConnectionPool; | |
33 | +import net.sf.l2j.commons.pool.ThreadPool; | |
34 | +import net.sf.l2j.commons.random.Rnd; | |
35 | + | |
36 | +import net.sf.l2j.gameserver.enums.ShortcutType; | |
37 | +import net.sf.l2j.gameserver.enums.TeamType; | |
38 | +import net.sf.l2j.gameserver.enums.skills.SkillTargetType; | |
39 | +import net.sf.l2j.gameserver.enums.skills.SkillType; | |
40 | +import net.sf.l2j.gameserver.geoengine.GeoEngine; | |
41 | +import net.sf.l2j.gameserver.handler.IItemHandler; | |
42 | +import net.sf.l2j.gameserver.handler.ItemHandler; | |
43 | +import net.sf.l2j.gameserver.handler.voicedcommandhandlers.AutoFarm; | |
44 | +import net.sf.l2j.gameserver.model.Shortcut; | |
45 | +import net.sf.l2j.gameserver.model.WorldObject; | |
46 | +import net.sf.l2j.gameserver.model.WorldRegion; | |
47 | + | |
48 | +import net.sf.l2j.gameserver.model.actor.Creature; | |
49 | +import net.sf.l2j.gameserver.model.actor.Player; | |
50 | +import net.sf.l2j.gameserver.model.actor.Summon; | |
51 | + | |
52 | +import net.sf.l2j.gameserver.model.actor.instance.Chest; | |
53 | +import net.sf.l2j.gameserver.model.actor.instance.Monster; | |
54 | +import net.sf.l2j.gameserver.model.item.instance.ItemInstance; | |
55 | +import net.sf.l2j.gameserver.network.SystemMessageId; | |
56 | +import net.sf.l2j.gameserver.network.serverpackets.ActionFailed; | |
57 | +import net.sf.l2j.gameserver.network.serverpackets.ExShowScreenMessage; | |
58 | +import net.sf.l2j.gameserver.network.serverpackets.SystemMessage; | |
59 | +import net.sf.l2j.gameserver.skills.AbstractEffect; | |
60 | +import net.sf.l2j.gameserver.skills.L2Skill; | |
61 | +import net.sf.l2j.gameserver.network.serverpackets.ExShowScreenMessage.SMPOS; | |
62 | + | |
63 | +import java.sql.Connection; | |
64 | +import java.sql.PreparedStatement; | |
65 | +import java.sql.ResultSet; | |
66 | +import java.sql.SQLException; | |
67 | +import java.util.ArrayList; | |
68 | +import java.util.Arrays; | |
69 | +import java.util.Collections; | |
70 | +import java.util.List; | |
71 | +import java.util.concurrent.ScheduledFuture; | |
72 | +import java.util.function.Function; | |
73 | +import java.util.stream.Collectors; | |
74 | + | |
75 | +public class AutofarmPlayerRoutine | |
76 | +{ | |
77 | + private final Player player; | |
78 | + private ScheduledFuture<?> _task; | |
79 | + private Creature committedTarget = null; | |
80 | + | |
81 | + public AutofarmPlayerRoutine(Player player) | |
82 | + { | |
83 | + this.player = player; | |
84 | + } | |
85 | + | |
86 | + public void start() | |
87 | + { | |
88 | + if (_task == null) | |
89 | + { | |
90 | + | |
91 | + | |
92 | + if (isIpAllowed(player.getIP())) { | |
93 | + player.sendMessage("Solo puedes usar Auto Farm con una IP a la vez."); | |
94 | + return; | |
95 | + }else { | |
96 | + _task = ThreadPool.scheduleAtFixedRate(() -> executeRoutine(), 450, 450); | |
97 | + | |
98 | + player.sendPacket(new ExShowScreenMessage("Auto Farming Actived...", 5*1000, SMPOS.TOP_CENTER, false)); | |
99 | + player.sendPacket(new SystemMessage(SystemMessageId.AUTO_FARM_ACTIVATED)); | |
100 | + player.setTeam(player.isMageClass() ? TeamType.BLUE : TeamType.RED); | |
101 | + insertIpEntry(player.getObjectId(), player.getIP()); | |
102 | + player.broadcastUserInfo(); | |
103 | + } | |
104 | + | |
105 | + | |
106 | + | |
107 | + | |
108 | + | |
109 | + | |
110 | + | |
111 | + } | |
112 | + } | |
113 | + | |
114 | + public void stop() | |
115 | + { | |
116 | + if (_task != null) | |
117 | + { | |
118 | + | |
119 | + removeIpEntry(player.getObjectId()); | |
120 | + _task.cancel(false); | |
121 | + _task = null; | |
122 | + | |
123 | + player.sendPacket(new ExShowScreenMessage("Auto Farming Deactivated...", 5*1000, SMPOS.TOP_CENTER, false)); | |
124 | + player.sendPacket(new SystemMessage(SystemMessageId.AUTO_FARM_DESACTIVATED)); | |
125 | + player.setTeam(TeamType.NONE); | |
126 | + player.broadcastUserInfo(); | |
127 | + | |
128 | + } | |
129 | + } | |
130 | + | |
131 | + | |
132 | + // Método para insertar la IP del jugador en la tabla Auto_Farm_Ip | |
133 | + private void insertIpEntry(int charId, String ip) { | |
134 | + try (Connection con = ConnectionPool.getConnection()) { | |
135 | + String insertSql = "INSERT INTO Auto_Farm_Ip (char_id, ip) VALUES (?, ?)"; | |
136 | + try (PreparedStatement insertStatement = con.prepareStatement(insertSql)) { | |
137 | + insertStatement.setInt(1, charId); | |
138 | + insertStatement.setString(2, ip); | |
139 | + insertStatement.executeUpdate(); | |
140 | + } | |
141 | + } catch (SQLException e) { | |
142 | + e.printStackTrace(); | |
143 | + } | |
144 | + } | |
145 | + | |
146 | + public static boolean isIpAllowed( String ip) { | |
147 | + try (Connection con = ConnectionPool.getConnection()) { | |
148 | + String selectSql = "SELECT * FROM Auto_Farm_Ip WHERE ip = ?"; | |
149 | + try (PreparedStatement selectStatement = con.prepareStatement(selectSql)) { | |
150 | + | |
151 | + selectStatement.setString(1, ip); | |
152 | + try (ResultSet result = selectStatement.executeQuery()) { | |
153 | + return result.next(); | |
154 | + } | |
155 | + } | |
156 | + } catch (SQLException e) { | |
157 | + e.printStackTrace(); | |
158 | + } | |
159 | + return false; // En caso de error o si no hay coincidencia | |
160 | + } | |
161 | + | |
162 | + // Método para eliminar la entrada del jugador en la tabla Auto_Farm_Ip | |
163 | + public static void removeIpEntry(int charId) { | |
164 | + try (Connection con = ConnectionPool.getConnection()) { | |
165 | + String deleteSql = "DELETE FROM Auto_Farm_Ip WHERE char_id = ?"; | |
166 | + try (PreparedStatement deleteStatement = con.prepareStatement(deleteSql)) { | |
167 | + deleteStatement.setInt(1, charId); | |
168 | + deleteStatement.executeUpdate(); | |
169 | + } | |
170 | + } catch (SQLException e) { | |
171 | + e.printStackTrace(); | |
172 | + } | |
173 | + } | |
174 | + | |
175 | + | |
176 | + | |
177 | + public void executeRoutine() | |
178 | + { | |
179 | + if (player.isNoBuffProtected() && player.getAllEffects().length <= 8) | |
180 | + { | |
181 | + player.sendMessage("You don't have buffs to use autofarm."); | |
182 | + player.broadcastUserInfo(); | |
183 | + stop(); | |
184 | + player.setAutoFarm(false); | |
185 | + AutoFarm.showAutoFarm(player); | |
186 | + return; | |
187 | + } | |
188 | + | |
189 | + calculatePotions(); | |
190 | + checkSpoil(); | |
191 | + targetEligibleCreature(); | |
192 | + if (player.isMageClass()) | |
193 | + { | |
194 | + useAppropriateSpell(); // Prioriza el uso de hechizos para los magos | |
195 | + } | |
196 | + else if (shotcutsContainAttack()) | |
197 | + { | |
198 | + attack(); // Si es una clase no maga y tiene la acción de ataque en los shortcuts | |
199 | + } | |
200 | + else | |
201 | + { | |
202 | + useAppropriateSpell(); // Si es una clase no maga y no tiene la acción de ataque, usa hechizos | |
203 | + } | |
204 | + checkSpoil(); | |
205 | + useAppropriateSpell(); | |
206 | + } | |
207 | + | |
208 | + private void attack() | |
209 | + { | |
210 | + Boolean shortcutsContainAttack = shotcutsContainAttack(); | |
211 | + | |
212 | + if (shortcutsContainAttack) | |
213 | + physicalAttack(); | |
214 | + } | |
215 | + | |
216 | + private void useAppropriateSpell() | |
217 | + { | |
218 | + L2Skill chanceSkill = nextAvailableSkill(getChanceSpells(), AutofarmSpellType.Chance); | |
219 | + | |
220 | + if (chanceSkill != null) | |
221 | + { | |
222 | + doSkill(chanceSkill, false); | |
223 | + return; | |
224 | + } | |
225 | + | |
226 | + L2Skill lowLifeSkill = nextAvailableSkill(getLowLifeSpells(), AutofarmSpellType.LowLife); | |
227 | + | |
228 | + if (lowLifeSkill != null) | |
229 | + { | |
230 | + doSkill(lowLifeSkill, true); | |
231 | + return; | |
232 | + } | |
233 | + | |
234 | + L2Skill attackSkill = nextAvailableSkill(getAttackSpells(), AutofarmSpellType.Attack); | |
235 | + | |
236 | + if (attackSkill != null) | |
237 | + { | |
238 | + doSkill(attackSkill, false); | |
239 | + return; | |
240 | + } | |
241 | + } | |
242 | + | |
243 | + public L2Skill nextAvailableSkill(List<Integer> skillIds, AutofarmSpellType spellType) | |
244 | + { | |
245 | + for (Integer skillId : skillIds) | |
246 | + { | |
247 | + L2Skill skill = player.getSkill(skillId); | |
248 | + | |
249 | + if (skill == null) | |
250 | + continue; | |
251 | + | |
252 | + if (skill.getSkillType() == SkillType.SIGNET || skill.getSkillType() == SkillType.SIGNET_CASTTIME) | |
253 | + continue; | |
254 | + | |
255 | + if (player.isSkillDisabled(skill)) | |
256 | + continue; | |
257 | + | |
258 | + if (isSpoil(skillId)) | |
259 | + { | |
260 | + if (monsterIsAlreadySpoiled()) | |
261 | + { | |
262 | + continue; | |
263 | + } | |
264 | + return skill; | |
265 | + } | |
266 | + | |
267 | + if (spellType == AutofarmSpellType.Chance && getMonsterTarget() != null) | |
268 | + { | |
269 | + if (getMonsterTarget().getFirstEffect(skillId) == null) | |
270 | + return skill; | |
271 | + continue; | |
272 | + } | |
273 | + | |
274 | + if (spellType == AutofarmSpellType.LowLife && getHpPercentage() > player.getHealPercent()) | |
275 | + break; | |
276 | + | |
277 | + return skill; | |
278 | + } | |
279 | + | |
280 | + return null; | |
281 | + } | |
282 | + | |
283 | + private void checkSpoil() | |
284 | + { | |
285 | + if (canBeSweepedByMe() && getMonsterTarget().isDead()) | |
286 | + { | |
287 | + L2Skill sweeper = player.getSkill(42); | |
288 | + if (sweeper == null) | |
289 | + return; | |
290 | + | |
291 | + doSkill(sweeper, false); | |
292 | + } | |
293 | + } | |
294 | + | |
295 | + private Double getHpPercentage() | |
296 | + { | |
297 | + return player.getStatus().getHp() * 100.0f / player.getStatus().getMaxHp(); | |
298 | + } | |
299 | + | |
300 | + private Double percentageMpIsLessThan() | |
301 | + { | |
302 | + return player.getStatus().getMp() * 100.0f / player.getStatus().getMaxMp(); | |
303 | + } | |
304 | + | |
305 | + private Double percentageHpIsLessThan() | |
306 | + { | |
307 | + return player.getStatus().getHp() * 100.0f / player.getStatus().getMaxHp(); | |
308 | + } | |
309 | + | |
310 | + private List<Integer> getAttackSpells() | |
311 | + { | |
312 | + return getSpellsInSlots(AutofarmConstants.attackSlots); | |
313 | + } | |
314 | + | |
315 | + private List<Integer> getSpellsInSlots(List<Integer> attackSlots) | |
316 | + { | |
317 | + return Arrays.stream(player.getShortcutList().getShortcuts()).filter(shortcut -> shortcut.getPage() == player.getPage() && shortcut.getType() == ShortcutType.SKILL && attackSlots.contains(shortcut.getSlot())).map(Shortcut::getId).collect(Collectors.toList()); | |
318 | + } | |
319 | + | |
320 | + private List<Integer> getChanceSpells() | |
321 | + { | |
322 | + return getSpellsInSlots(AutofarmConstants.chanceSlots); | |
323 | + } | |
324 | + | |
325 | + private List<Integer> getLowLifeSpells() | |
326 | + { | |
327 | + return getSpellsInSlots(AutofarmConstants.lowLifeSlots); | |
328 | + } | |
329 | + | |
330 | + private boolean shotcutsContainAttack() | |
331 | + { | |
332 | + return Arrays.stream(player.getShortcutList().getShortcuts()).anyMatch(shortcut -> shortcut.getPage() == player.getPage() && shortcut.getType() == ShortcutType.ACTION && (shortcut.getId() == 2 || player.isSummonAttack() && shortcut.getId() == 22)); | |
333 | + } | |
334 | + | |
335 | + | |
336 | + | |
337 | + | |
338 | + private boolean monsterIsAlreadySpoiled() | |
339 | + { | |
340 | + return getMonsterTarget() != null && getMonsterTarget().getSpoilState().isSpoiled(); | |
341 | + } | |
342 | + | |
343 | + private static boolean isSpoil(Integer skillId) | |
344 | + { | |
345 | + return skillId == 254 || skillId == 302; | |
346 | + } | |
347 | + | |
348 | + private boolean canBeSweepedByMe() | |
349 | + { | |
350 | + return getMonsterTarget() != null && getMonsterTarget().isDead() && getMonsterTarget().getSpoilState().isSweepable(); | |
351 | + } | |
352 | + | |
353 | + | |
354 | + | |
355 | + private void doSkill(L2Skill skill, boolean isSelfSkill) | |
356 | + { | |
357 | + final WorldObject target = player.getTarget(); | |
358 | + if (skill == null || !(target instanceof Creature)) | |
359 | + return; | |
360 | + | |
361 | + if (skill.getSkillType() == SkillType.RECALL && !Config.KARMA_PLAYER_CAN_TELEPORT && player.getKarma() > 0) | |
362 | + { | |
363 | + player.sendPacket(ActionFailed.STATIC_PACKET); | |
364 | + return; | |
365 | + } | |
366 | + | |
367 | + if (skill.isToggle() && player.isMounted()) | |
368 | + { | |
369 | + player.sendPacket(ActionFailed.STATIC_PACKET); | |
370 | + return; | |
371 | + } | |
372 | + | |
373 | + if (player.isOutOfControl()) | |
374 | + { | |
375 | + player.sendPacket(ActionFailed.STATIC_PACKET); | |
376 | + return; | |
377 | + } | |
378 | + | |
379 | + | |
380 | + | |
381 | + | |
382 | + | |
383 | + if (isNecessarySkill(skill)) | |
384 | + player.getAI().tryToCast(isSelfSkill ? player : (Creature) target, skill); | |
385 | + } | |
386 | + | |
387 | + | |
388 | + private boolean isNecessarySkill(L2Skill skill) | |
389 | + { | |
390 | + if (skill == null) | |
391 | + return false; | |
392 | + | |
393 | + final WorldObject target = player.getTarget(); | |
394 | + if (target instanceof Monster) | |
395 | + { | |
396 | + final Monster monster = (Monster) target; | |
397 | + if (skill.getSkillType() == SkillType.SPOIL && monster.getSpoilState().isSpoiled()) | |
398 | + return false; | |
399 | + | |
400 | + List<AbstractEffect> effects = Arrays.stream(monster.getAllEffects()).filter(e -> e.getSkill().isDebuff()).collect(Collectors.toList()); | |
401 | + if (effects != null && !effects.isEmpty() && effects.stream().anyMatch(e -> e.getSkill().getId() == skill.getId())) | |
402 | + return false; | |
403 | + | |
404 | + if (!monster.isDead() && skill.getTargetType() == SkillTargetType.CORPSE_MOB) | |
405 | + return false; | |
406 | + | |
407 | + return true; | |
408 | + } | |
409 | + return false; | |
410 | + } | |
411 | + | |
412 | + private void physicalAttack() | |
413 | + { | |
414 | + if (!(player.getTarget() instanceof Monster)) | |
415 | + return; | |
416 | + | |
417 | + Monster target = (Monster) player.getTarget(); | |
418 | + | |
419 | + if (!player.isMageClass()) | |
420 | + { | |
421 | + if (target.canAutoAttack(player) && GeoEngine.getInstance().canSeeTarget(player, target)) | |
422 | + { | |
423 | + if (GeoEngine.getInstance().canSeeTarget(player, target)) | |
424 | + { | |
425 | + player.getAI().tryToAttack(target); | |
426 | + player.onActionRequest(); | |
427 | + | |
428 | + if (player.isSummonAttack() && player.getSummon() != null) | |
429 | + { | |
430 | + // Siege Golem's | |
431 | + if (player.getSummon().getNpcId() >= 14702 && player.getSummon().getNpcId() <= 14798 || player.getSummon().getNpcId() >= 14839 && player.getSummon().getNpcId() <= 14869) | |
432 | + return; | |
433 | + | |
434 | + Summon activeSummon = player.getSummon(); | |
435 | + activeSummon.setTarget(target); | |
436 | + activeSummon.getAI().tryToAttack(target); | |
437 | + | |
438 | + int[] summonAttackSkills = {4261, 4068, 4137, 4260, 4708, 4709, 4710, 4712, 5135, 5138, 5141, 5442, 5444, 6095, 6096, 6041, 6044}; | |
439 | + if (Rnd.get(100) < player.getSummonSkillPercent()) | |
440 | + { | |
441 | + for (int skillId : summonAttackSkills) | |
442 | + { | |
443 | + useMagicSkillBySummon(skillId, target); | |
444 | + } | |
445 | + } | |
446 | + } | |
447 | + } | |
448 | + } | |
449 | + else | |
450 | + { | |
451 | + if (target.canAutoAttack(player) && GeoEngine.getInstance().canSeeTarget(player, target)) | |
452 | + if (GeoEngine.getInstance().canSeeTarget(player, target)) | |
453 | + player.getAI().tryToFollow(target, false); | |
454 | + } | |
455 | + } | |
456 | + else | |
457 | + { | |
458 | + if (player.isSummonAttack() && player.getSummon() != null) | |
459 | + { | |
460 | + // Siege Golem's | |
461 | + if (player.getSummon().getNpcId() >= 14702 && player.getSummon().getNpcId() <= 14798 || player.getSummon().getNpcId() >= 14839 && player.getSummon().getNpcId() <= 14869) | |
462 | + return; | |
463 | + | |
464 | + Summon activeSummon = player.getSummon(); | |
465 | + activeSummon.setTarget(target); | |
466 | + activeSummon.getAI().tryToAttack(target); | |
467 | + | |
468 | + int[] summonAttackSkills = {4261, 4068, 4137, 4260, 4708, 4709, 4710, 4712, 5135, 5138, 5141, 5442, 5444, 6095, 6096, 6041, 6044}; | |
469 | + if (Rnd.get(100) < player.getSummonSkillPercent()) | |
470 | + { | |
471 | + for (int skillId : summonAttackSkills) | |
472 | + { | |
473 | + useMagicSkillBySummon(skillId, target); | |
474 | + } | |
475 | + } | |
476 | + } | |
477 | + } | |
478 | + } | |
479 | + | |
480 | + private void useMagicSkillBySummon(int skillId, WorldObject target) | |
481 | + { | |
482 | + // No owner, or owner in shop mode. | |
483 | + if (player == null || player.isInStoreMode()) | |
484 | + return; | |
485 | + | |
486 | + final Summon activeSummon = player.getSummon(); | |
487 | + if (activeSummon == null) | |
488 | + return; | |
489 | + | |
490 | + // Pet which is 20 levels higher than owner. | |
491 | + if (activeSummon instanceof Pet && activeSummon.getStatus().getLevel() - player.getStatus().getLevel() > 20) | |
492 | + { | |
493 | + player.sendPacket(SystemMessageId.PET_TOO_HIGH_TO_CONTROL); | |
494 | + return; | |
495 | + } | |
496 | + | |
497 | + // Out of control pet. | |
498 | + if (activeSummon.isOutOfControl()) | |
499 | + { | |
500 | + player.sendPacket(SystemMessageId.PET_REFUSING_ORDER); | |
501 | + return; | |
502 | + } | |
503 | + | |
504 | + // Verify if the launched skill is mastered by the summon. | |
505 | + final L2Skill skill = activeSummon.getSkill(skillId); | |
506 | + if (skill == null) | |
507 | + return; | |
508 | + | |
509 | + // Can't launch offensive skills on owner. | |
510 | + if (skill.isOffensive() && player == target) | |
511 | + return; | |
512 | + | |
513 | + activeSummon.setTarget(target); | |
514 | + activeSummon.getAI().tryToCast(committedTarget, skill); | |
515 | + } | |
516 | + | |
517 | + | |
518 | + | |
519 | + public void targetEligibleCreature() { | |
520 | + if (player.getTarget() == null) { | |
521 | + selectNewTarget(); // Llamada a selectNewTarget si el jugador no tiene un objetivo | |
522 | + return; | |
523 | + } | |
524 | + | |
525 | + if (committedTarget != null) { | |
526 | + if (/*!isSameInstance(player, committedTarget) ||*/ (committedTarget.isDead() && GeoEngine.getInstance().canSeeTarget(player, committedTarget))) { | |
527 | + committedTarget = null; | |
528 | + selectNewTarget(); // Llamada a selectNewTarget después de que el objetivo actual muere o es de otra instancia | |
529 | + return; | |
530 | + } else if (!committedTarget.isDead() && GeoEngine.getInstance().canSeeTarget(player, committedTarget)) { | |
531 | + attack(); | |
532 | + return; | |
533 | + } else if (!GeoEngine.getInstance().canSeeTarget(player, committedTarget)) { | |
534 | + committedTarget = null; | |
535 | + selectNewTarget(); // Buscar otro objetivo si el jugador no puede ver al objetivo actual | |
536 | + return; | |
537 | + } | |
538 | + player.getAI().tryToFollow(committedTarget, false); | |
539 | + committedTarget = null; | |
540 | + player.setTarget(null); | |
541 | + } | |
542 | + | |
543 | + if (committedTarget instanceof Summon) | |
544 | + return; | |
545 | + | |
546 | + 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.isRaidRelated() && !creature.isRaidBoss() && !creature.isDead() && !(creature instanceof Chest) && !(player.isAntiKsProtected() && creature.getTarget() != null && creature.getTarget() != player && creature.getTarget() != player.getSummon()) /*&& isSameInstance(player, creature)*/); | |
547 | + | |
548 | + if (targets.isEmpty()) | |
549 | + return; | |
550 | + | |
551 | + Monster closestTarget = targets.stream().min((o1, o2) -> Integer.compare((int) Math.sqrt(player.distance2D(o1)), (int) Math.sqrt(player.distance2D(o2)))).get(); | |
552 | + | |
553 | + committedTarget = closestTarget; | |
554 | + player.setTarget(closestTarget); | |
555 | + } | |
556 | + | |
557 | + | |
558 | + // Función para verificar si dos objetos pertenecen a la misma instancia | |
559 | +/* private static boolean isSameInstance(WorldObject obj1, WorldObject obj2) | |
560 | + { | |
561 | + return obj1.getInstanceId2() == obj2.getInstanceId2(); | |
562 | + }*/ | |
563 | + | |
564 | + // Función para seleccionar un nuevo objetivo | |
565 | + private void selectNewTarget() | |
566 | + { | |
567 | + 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.isRaidRelated() && !creature.isRaidBoss() && !creature.isDead() && !(creature instanceof Chest) && !(player.isAntiKsProtected() && creature.getTarget() != null && creature.getTarget() != player && creature.getTarget() != player.getSummon()) /*&& isSameInstance(player, creature)*/); | |
568 | + | |
569 | + if (targets.isEmpty()) | |
570 | + return; | |
571 | + | |
572 | + Monster closestTarget = targets.stream().min((o1, o2) -> Integer.compare((int) Math.sqrt(player.distance2D(o1)), (int) Math.sqrt(player.distance2D(o2)))).get(); | |
573 | + | |
574 | + committedTarget = closestTarget; | |
575 | + player.setTarget(closestTarget); | |
576 | + } | |
577 | + | |
578 | + | |
579 | + | |
580 | + | |
581 | + public final static List<Monster> getKnownMonstersInRadius(Player player, int radius, Function<Monster, Boolean> condition) | |
582 | + { | |
583 | + final WorldRegion region = player.getRegion(); | |
584 | + if (region == null) | |
585 | + return Collections.emptyList(); | |
586 | + | |
587 | + final List<Monster> result = new ArrayList<>(); | |
588 | + | |
589 | + for (WorldRegion reg : region.getSurroundingRegions()) | |
590 | + { | |
591 | + for (WorldObject obj : reg.getObjects()) | |
592 | + { | |
593 | + if (!(obj instanceof Monster) || !MathUtil.checkIfInRange(radius, player, obj, true) || !condition.apply((Monster) obj)) | |
594 | + continue; | |
595 | + | |
596 | + result.add((Monster) obj); | |
597 | + } | |
598 | + } | |
599 | + | |
600 | + return result; | |
601 | + } | |
602 | + | |
603 | + public Monster getMonsterTarget() | |
604 | + { | |
605 | + if(!(player.getTarget() instanceof Monster)) | |
606 | + { | |
607 | + return null; | |
608 | + } | |
609 | + | |
610 | + return (Monster)player.getTarget(); | |
611 | + } | |
612 | + | |
613 | + | |
614 | + | |
615 | + private void calculatePotions() | |
616 | + { | |
617 | + if (percentageHpIsLessThan() < player.getHpPotionPercentage()) | |
618 | + forceUseItem(1539); | |
619 | + | |
620 | + if (percentageMpIsLessThan() < player.getMpPotionPercentage()) | |
621 | + forceUseItem(728); | |
622 | + } | |
623 | + | |
624 | + private void forceUseItem(int itemId) | |
625 | + { | |
626 | + final ItemInstance potion = player.getInventory().getItemByItemId(itemId); | |
627 | + if (potion == null) | |
628 | + return; | |
629 | + | |
630 | + final IItemHandler handler = ItemHandler.getInstance().getHandler(potion.getEtcItem()); | |
631 | + if (handler != null) | |
632 | + handler.useItem(player, potion, false); | |
633 | + } | |
634 | +} | |
635 | \ No newline at end of file | |
636 | diff --git java/Base/AutoFarm/AutofarmSpell.java java/Base/AutoFarm/AutofarmSpell.java | |
637 | new file mode 100644 | |
638 | index 0000000..beefc8d | |
639 | --- /dev/null | |
640 | +++ java/Base/AutoFarm/AutofarmSpell.java | |
641 | @@ -0,0 +1,20 @@ | |
642 | +package Base.AutoFarm; | |
643 | + | |
644 | +public class AutofarmSpell { | |
645 | + private final Integer _skillId; | |
646 | + private final AutofarmSpellType _spellType; | |
647 | + | |
648 | + public AutofarmSpell(Integer skillId, AutofarmSpellType spellType){ | |
649 | + | |
650 | + _skillId = skillId; | |
651 | + _spellType = spellType; | |
652 | + } | |
653 | + | |
654 | + public Integer getSkillId() { | |
655 | + return _skillId; | |
656 | + } | |
657 | + | |
658 | + public AutofarmSpellType getSpellType() { | |
659 | + return _spellType; | |
660 | + } | |
661 | +} | |
662 | \ No newline at end of file | |
663 | diff --git java/Base/AutoFarm/AutofarmSpellType.java java/Base/AutoFarm/AutofarmSpellType.java | |
664 | new file mode 100644 | |
665 | index 0000000..2ec3039 | |
666 | --- /dev/null | |
667 | +++ java/Base/AutoFarm/AutofarmSpellType.java | |
668 | @@ -0,0 +1,8 @@ | |
669 | +package Base.AutoFarm; | |
670 | + | |
671 | +public enum AutofarmSpellType | |
672 | +{ | |
673 | + Attack, | |
674 | + Chance, | |
675 | + LowLife | |
676 | +} | |
677 | \ No newline at end of file | |
678 | diff --git java/net/sf/l2j/gameserver/handler/VoicedCommandHandler.java java/net/sf/l2j/gameserver/handler/VoicedCommandHandler.java | |
679 | index 6e1e2ac..7dc1b59 100644 | |
680 | --- java/net/sf/l2j/gameserver/handler/VoicedCommandHandler.java | |
681 | +++ java/net/sf/l2j/gameserver/handler/VoicedCommandHandler.java | |
682 | @@ -3,6 +3,7 @@ | |
683 | import java.util.HashMap; | |
684 | import java.util.Map; | |
685 | ||
686 | +import net.sf.l2j.gameserver.handler.voicedcommandhandlers.AutoFarm; | |
687 | import net.sf.l2j.gameserver.handler.voicedcommandhandlers.Epic; | |
688 | import net.sf.l2j.gameserver.handler.voicedcommandhandlers.EventCommand; | |
689 | import net.sf.l2j.gameserver.handler.voicedcommandhandlers.Menu; | |
690 | @@ -18,6 +19,7 @@ | |
691 | ||
692 | protected VoicedCommandHandler() | |
693 | { | |
694 | + registerHandler(new AutoFarm()); | |
695 | registerHandler(new Epic()); | |
696 | registerHandler(new Online()); | |
697 | registerHandler(new Menu()); | |
698 | diff --git java/net/sf/l2j/gameserver/handler/voicedcommandhandlers/AutoFarm.java java/net/sf/l2j/gameserver/handler/voicedcommandhandlers/AutoFarm.java | |
699 | new file mode 100644 | |
700 | index 0000000..3e10933 | |
701 | --- /dev/null | |
702 | +++ java/net/sf/l2j/gameserver/handler/voicedcommandhandlers/AutoFarm.java | |
703 | @@ -0,0 +1,324 @@ | |
704 | +package net.sf.l2j.gameserver.handler.voicedcommandhandlers; | |
705 | + | |
706 | +import java.util.StringTokenizer; | |
707 | + | |
708 | +import net.sf.l2j.commons.lang.StringUtil; | |
709 | + | |
710 | +import net.sf.l2j.gameserver.handler.IVoicedCommandHandler; | |
711 | +import net.sf.l2j.gameserver.model.WorldObject; | |
712 | +import net.sf.l2j.gameserver.model.actor.Player; | |
713 | +import net.sf.l2j.gameserver.model.actor.instance.Monster; | |
714 | + | |
715 | +import net.sf.l2j.gameserver.network.SystemMessageId; | |
716 | +import net.sf.l2j.gameserver.network.serverpackets.ExShowScreenMessage; | |
717 | +import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage; | |
718 | +import net.sf.l2j.gameserver.network.serverpackets.SystemMessage; | |
719 | + | |
720 | +import Base.AutoFarm.AutofarmPlayerRoutine; | |
721 | + | |
722 | +import net.sf.l2j.gameserver.network.serverpackets.ExShowScreenMessage.SMPOS; | |
723 | + | |
724 | +public class AutoFarm implements IVoicedCommandHandler | |
725 | +{ | |
726 | + private final String[] VOICED_COMMANDS = | |
727 | + { | |
728 | + "autofarm", | |
729 | + "enableAutoFarm", | |
730 | + "radiusAutoFarm", | |
731 | + "pageAutoFarm", | |
732 | + "enableBuffProtect", | |
733 | + "healAutoFarm", | |
734 | + "hpAutoFarm", | |
735 | + "mpAutoFarm", | |
736 | + "enableAntiKs", | |
737 | + "enableSummonAttack", | |
738 | + "summonSkillAutoFarm", | |
739 | + "ignoreMonster", | |
740 | + "activeMonster" | |
741 | + }; | |
742 | + | |
743 | + @Override | |
744 | + public boolean useVoicedCommand(final String command, final Player activeChar, final String args) | |
745 | + { | |
746 | + final AutofarmPlayerRoutine bot = activeChar.getBot(); | |
747 | + | |
748 | + if (command.startsWith("autofarm")) | |
749 | + showAutoFarm(activeChar); | |
750 | + | |
751 | + if (command.startsWith("radiusAutoFarm")) | |
752 | + { | |
753 | + StringTokenizer st = new StringTokenizer(command, " "); | |
754 | + st.nextToken(); | |
755 | + try | |
756 | + { | |
757 | + String param = st.nextToken(); | |
758 | + | |
759 | + if (param.startsWith("inc_radius")) | |
760 | + { | |
761 | + activeChar.setRadius(activeChar.getRadius() + 200); | |
762 | + showAutoFarm(activeChar); | |
763 | + } | |
764 | + else if (param.startsWith("dec_radius")) | |
765 | + { | |
766 | + activeChar.setRadius(activeChar.getRadius() - 200); | |
767 | + showAutoFarm(activeChar); | |
768 | + } | |
769 | + activeChar.saveAutoFarmSettings(); | |
770 | + } | |
771 | + catch (Exception e) | |
772 | + { | |
773 | + e.printStackTrace(); | |
774 | + } | |
775 | + } | |
776 | + | |
777 | + if (command.startsWith("pageAutoFarm")) | |
778 | + { | |
779 | + StringTokenizer st = new StringTokenizer(command, " "); | |
780 | + st.nextToken(); | |
781 | + try | |
782 | + { | |
783 | + String param = st.nextToken(); | |
784 | + | |
785 | + if (param.startsWith("inc_page")) | |
786 | + { | |
787 | + activeChar.setPage(activeChar.getPage() + 1); | |
788 | + showAutoFarm(activeChar); | |
789 | + } | |
790 | + else if (param.startsWith("dec_page")) | |
791 | + { | |
792 | + activeChar.setPage(activeChar.getPage() - 1); | |
793 | + showAutoFarm(activeChar); | |
794 | + } | |
795 | + activeChar.saveAutoFarmSettings(); | |
796 | + } | |
797 | + catch (Exception e) | |
798 | + { | |
799 | + e.printStackTrace(); | |
800 | + } | |
801 | + } | |
802 | + | |
803 | + if (command.startsWith("healAutoFarm")) | |
804 | + { | |
805 | + StringTokenizer st = new StringTokenizer(command, " "); | |
806 | + st.nextToken(); | |
807 | + try | |
808 | + { | |
809 | + String param = st.nextToken(); | |
810 | + | |
811 | + if (param.startsWith("inc_heal")) | |
812 | + { | |
813 | + activeChar.setHealPercent(activeChar.getHealPercent() + 10); | |
814 | + showAutoFarm(activeChar); | |
815 | + } | |
816 | + else if (param.startsWith("dec_heal")) | |
817 | + { | |
818 | + activeChar.setHealPercent(activeChar.getHealPercent() - 10); | |
819 | + showAutoFarm(activeChar); | |
820 | + } | |
821 | + activeChar.saveAutoFarmSettings(); | |
822 | + } | |
823 | + catch (Exception e) | |
824 | + { | |
825 | + e.printStackTrace(); | |
826 | + } | |
827 | + } | |
828 | + | |
829 | + if (command.startsWith("hpAutoFarm")) | |
830 | + { | |
831 | + StringTokenizer st = new StringTokenizer(command, " "); | |
832 | + st.nextToken(); | |
833 | + try | |
834 | + { | |
835 | + String param = st.nextToken(); | |
836 | + | |
837 | + if (param.contains("inc_hp_pot")) | |
838 | + { | |
839 | + activeChar.setHpPotionPercentage(activeChar.getHpPotionPercentage() + 5); | |
840 | + showAutoFarm(activeChar); | |
841 | + } | |
842 | + else if (param.contains("dec_hp_pot")) | |
843 | + { | |
844 | + activeChar.setHpPotionPercentage(activeChar.getHpPotionPercentage() - 5); | |
845 | + showAutoFarm(activeChar); | |
846 | + } | |
847 | + activeChar.saveAutoFarmSettings(); | |
848 | + } | |
849 | + catch (Exception e) | |
850 | + { | |
851 | + e.printStackTrace(); | |
852 | + } | |
853 | + } | |
854 | + | |
855 | + if (command.startsWith("mpAutoFarm")) | |
856 | + { | |
857 | + StringTokenizer st = new StringTokenizer(command, " "); | |
858 | + st.nextToken(); | |
859 | + try | |
860 | + { | |
861 | + String param = st.nextToken(); | |
862 | + | |
863 | + if (param.contains("inc_mp_pot")) | |
864 | + { | |
865 | + activeChar.setMpPotionPercentage(activeChar.getMpPotionPercentage() + 5); | |
866 | + showAutoFarm(activeChar); | |
867 | + } | |
868 | + else if (param.contains("dec_mp_pot")) | |
869 | + { | |
870 | + activeChar.setMpPotionPercentage(activeChar.getMpPotionPercentage() - 5); | |
871 | + showAutoFarm(activeChar); | |
872 | + } | |
873 | + activeChar.saveAutoFarmSettings(); | |
874 | + } | |
875 | + catch (Exception e) | |
876 | + { | |
877 | + e.printStackTrace(); | |
878 | + } | |
879 | + } | |
880 | + | |
881 | + if (command.startsWith("enableAutoFarm")) | |
882 | + { | |
883 | + if (activeChar.isAutoFarm()) | |
884 | + { | |
885 | + bot.stop(); | |
886 | + activeChar.setAutoFarm(false); | |
887 | + } | |
888 | + else | |
889 | + { | |
890 | + bot.start(); | |
891 | + activeChar.setAutoFarm(true); | |
892 | + } | |
893 | + | |
894 | + showAutoFarm(activeChar); | |
895 | + } | |
896 | + | |
897 | + if (command.startsWith("enableBuffProtect")) | |
898 | + { | |
899 | + activeChar.setNoBuffProtection(!activeChar.isNoBuffProtected()); | |
900 | + showAutoFarm(activeChar); | |
901 | + activeChar.saveAutoFarmSettings(); | |
902 | + } | |
903 | + | |
904 | + if (command.startsWith("enableAntiKs")) | |
905 | + { | |
906 | + activeChar.setAntiKsProtection(!activeChar.isAntiKsProtected()); | |
907 | + | |
908 | + if(activeChar.isAntiKsProtected()) { | |
909 | + activeChar.sendPacket(new SystemMessage(SystemMessageId.ACTIVATE_RESPECT_HUNT)); | |
910 | + activeChar.sendPacket(new ExShowScreenMessage("Respct Hunt On" , 3*1000, SMPOS.TOP_CENTER, false)); | |
911 | + }else { | |
912 | + activeChar.sendPacket(new SystemMessage(SystemMessageId.DESACTIVATE_RESPECT_HUNT)); | |
913 | + activeChar.sendPacket(new ExShowScreenMessage("Respct Hunt Off" , 3*1000, SMPOS.TOP_CENTER, false)); | |
914 | + } | |
915 | + | |
916 | + activeChar.saveAutoFarmSettings(); | |
917 | + showAutoFarm(activeChar); | |
918 | + } | |
919 | + | |
920 | + if (command.startsWith("enableSummonAttack")) | |
921 | + { | |
922 | + activeChar.setSummonAttack(!activeChar.isSummonAttack()); | |
923 | + if(activeChar.isSummonAttack()) { | |
924 | + activeChar.sendPacket(new SystemMessage(SystemMessageId.ACTIVATE_SUMMON_ACTACK)); | |
925 | + activeChar.sendPacket(new ExShowScreenMessage("Auto Farm Summon Attack On" , 3*1000, SMPOS.TOP_CENTER, false)); | |
926 | + }else { | |
927 | + activeChar.sendPacket(new SystemMessage(SystemMessageId.DESACTIVATE_SUMMON_ACTACK)); | |
928 | + activeChar.sendPacket(new ExShowScreenMessage("Auto Farm Summon Attack Off" , 3*1000, SMPOS.TOP_CENTER, false)); | |
929 | + } | |
930 | + activeChar.saveAutoFarmSettings(); | |
931 | + showAutoFarm(activeChar); | |
932 | + } | |
933 | + | |
934 | + if (command.startsWith("summonSkillAutoFarm")) | |
935 | + { | |
936 | + StringTokenizer st = new StringTokenizer(command, " "); | |
937 | + st.nextToken(); | |
938 | + try | |
939 | + { | |
940 | + String param = st.nextToken(); | |
941 | + | |
942 | + if (param.startsWith("inc_summonSkill")) | |
943 | + { | |
944 | + activeChar.setSummonSkillPercent(activeChar.getSummonSkillPercent() + 10); | |
945 | + showAutoFarm(activeChar); | |
946 | + } | |
947 | + else if (param.startsWith("dec_summonSkill")) | |
948 | + { | |
949 | + activeChar.setSummonSkillPercent(activeChar.getSummonSkillPercent() - 10); | |
950 | + showAutoFarm(activeChar); | |
951 | + } | |
952 | + activeChar.saveAutoFarmSettings(); | |
953 | + } | |
954 | + catch (Exception e) | |
955 | + { | |
956 | + e.printStackTrace(); | |
957 | + } | |
958 | + } | |
959 | + | |
960 | + if (command.startsWith("ignoreMonster")) | |
961 | + { | |
962 | + int monsterId = 0; | |
963 | + WorldObject target = activeChar.getTarget(); | |
964 | + if (target instanceof Monster) | |
965 | + monsterId = ((Monster) target).getNpcId(); | |
966 | + | |
967 | + if (target == null) | |
968 | + { | |
969 | + activeChar.sendMessage("You dont have a target"); | |
970 | + return false; | |
971 | + } | |
972 | + | |
973 | + activeChar.sendMessage(target.getName() + " has been added to the ignore list."); | |
974 | + activeChar.ignoredMonster(monsterId); | |
975 | + } | |
976 | + | |
977 | + if (command.startsWith("activeMonster")) | |
978 | + { | |
979 | + int monsterId = 0; | |
980 | + WorldObject target = activeChar.getTarget(); | |
981 | + if (target instanceof Monster) | |
982 | + monsterId = ((Monster) target).getNpcId(); | |
983 | + | |
984 | + if (target == null) | |
985 | + { | |
986 | + activeChar.sendMessage("You dont have a target"); | |
987 | + return false; | |
988 | + } | |
989 | + | |
990 | + activeChar.sendMessage(target.getName() + " has been removed from the ignore list."); | |
991 | + activeChar.activeMonster(monsterId); | |
992 | + } | |
993 | + | |
994 | + return false; | |
995 | + } | |
996 | + | |
997 | + private static final String ACTIVED = "<font color=00FF00>STARTED</font>"; | |
998 | + private static final String DESATIVED = "<font color=FF0000>STOPPED</font>"; | |
999 | + private static final String STOP = "STOP"; | |
1000 | + private static final String START = "START"; | |
1001 | + | |
1002 | + public static void showAutoFarm(Player activeChar) | |
1003 | + { | |
1004 | + NpcHtmlMessage html = new NpcHtmlMessage(0); | |
1005 | + | |
1006 | + html.setFile(activeChar.getLocale(), "html/mods/menu/AutoFarm.htm"); | |
1007 | + html.replace("%player%", activeChar.getName()); | |
1008 | + html.replace("%page%", StringUtil.formatNumber(activeChar.getPage() + 1)); | |
1009 | + html.replace("%heal%", StringUtil.formatNumber(activeChar.getHealPercent())); | |
1010 | + html.replace("%radius%", StringUtil.formatNumber(activeChar.getRadius())); | |
1011 | + html.replace("%summonSkill%", StringUtil.formatNumber(activeChar.getSummonSkillPercent())); | |
1012 | + html.replace("%hpPotion%", StringUtil.formatNumber(activeChar.getHpPotionPercentage())); | |
1013 | + html.replace("%mpPotion%", StringUtil.formatNumber(activeChar.getMpPotionPercentage())); | |
1014 | + html.replace("%noBuff%", activeChar.isNoBuffProtected() ? "back=L2UI.CheckBox_checked fore=L2UI.CheckBox_checked" : "back=L2UI.CheckBox fore=L2UI.CheckBox"); | |
1015 | + html.replace("%summonAtk%", activeChar.isSummonAttack() ? "back=L2UI.CheckBox_checked fore=L2UI.CheckBox_checked" : "back=L2UI.CheckBox fore=L2UI.CheckBox"); | |
1016 | + html.replace("%antiKs%", activeChar.isAntiKsProtected() ? "back=L2UI.CheckBox_checked fore=L2UI.CheckBox_checked" : "back=L2UI.CheckBox fore=L2UI.CheckBox"); | |
1017 | + html.replace("%autofarm%", activeChar.isAutoFarm() ? ACTIVED : DESATIVED); | |
1018 | + html.replace("%button%", activeChar.isAutoFarm() ? STOP : START); | |
1019 | + activeChar.sendPacket(html); | |
1020 | + } | |
1021 | + | |
1022 | + @Override | |
1023 | + public String[] getVoicedCommandList() | |
1024 | + { | |
1025 | + return VOICED_COMMANDS; | |
1026 | + } | |
1027 | +} | |
1028 | \ No newline at end of file | |
1029 | diff --git java/net/sf/l2j/gameserver/model/actor/Npc.java java/net/sf/l2j/gameserver/model/actor/Npc.java | |
1030 | index 75120d5..40051ec 100644 | |
1031 | --- java/net/sf/l2j/gameserver/model/actor/Npc.java | |
1032 | +++ java/net/sf/l2j/gameserver/model/actor/Npc.java | |
1033 | @@ -81,6 +81,8 @@ | |
1034 | import net.sf.l2j.gameserver.taskmanager.AiTaskManager; | |
1035 | import net.sf.l2j.gameserver.taskmanager.DecayTaskManager; | |
1036 | ||
1037 | +import Base.AutoFarm.AutofarmPlayerRoutine; | |
1038 | + | |
1039 | /** | |
1040 | * An instance type extending {@link Creature}, which represents a Non Playable Character (or NPC) in the world. | |
1041 | */ | |
1042 | @@ -1366,7 +1368,7 @@ | |
1043 | { | |
1044 | if (!isTeleportAllowed(player)) | |
1045 | return; | |
1046 | - | |
1047 | + final AutofarmPlayerRoutine bot = player.getBot(); | |
1048 | final List<Location> teleports = InstantTeleportData.getInstance().getTeleports(getNpcId()); | |
1049 | if (teleports == null || index > teleports.size()) | |
1050 | return; | |
1051 | @@ -1376,6 +1378,11 @@ | |
1052 | return; | |
1053 | ||
1054 | player.teleportTo(teleport, 20); | |
1055 | + if (player.isAutoFarm()) | |
1056 | + { | |
1057 | + bot.stop(); | |
1058 | + player.setAutoFarm(false); | |
1059 | + } | |
1060 | } | |
1061 | ||
1062 | /** | |
1063 | @@ -1398,6 +1405,9 @@ | |
1064 | if (teleport == null) | |
1065 | return; | |
1066 | ||
1067 | + | |
1068 | + final AutofarmPlayerRoutine bot = player.getBot(); | |
1069 | + | |
1070 | if (teleport.getCastleId() > 0) | |
1071 | { | |
1072 | final Castle castle = CastleManager.getInstance().getCastleById(teleport.getCastleId()); | |
1073 | @@ -1411,6 +1421,12 @@ | |
1074 | if (Config.FREE_TELEPORT && player.getStatus().getLevel() <= Config.LVL_FREE_TELEPORT || teleport.getPriceCount() == 0 || player.destroyItemByItemId("InstantTeleport", teleport.getPriceId(), teleport.getCalculatedPriceCount(player), this, true)) | |
1075 | player.teleportTo(teleport, 20); | |
1076 | ||
1077 | + if (player.isAutoFarm()) | |
1078 | + { | |
1079 | + bot.stop(); | |
1080 | + player.setAutoFarm(false); | |
1081 | + } | |
1082 | + | |
1083 | player.sendPacket(ActionFailed.STATIC_PACKET); | |
1084 | } | |
1085 | ||
1086 | diff --git java/net/sf/l2j/gameserver/model/actor/Player.java java/net/sf/l2j/gameserver/model/actor/Player.java | |
1087 | index df09dcb..ddfcb84 100644 | |
1088 | --- java/net/sf/l2j/gameserver/model/actor/Player.java | |
1089 | +++ java/net/sf/l2j/gameserver/model/actor/Player.java | |
1090 | @@ -34,7 +34,9 @@ | |
1091 | import net.sf.l2j.commons.util.ArraysUtil; | |
1092 | ||
1093 | import net.sf.l2j.Config; | |
1094 | + | |
1095 | import net.sf.l2j.gameserver.LoginServerThread; | |
1096 | + | |
1097 | import net.sf.l2j.gameserver.communitybbs.CommunityBoard; | |
1098 | import net.sf.l2j.gameserver.communitybbs.model.Forum; | |
1099 | import net.sf.l2j.gameserver.data.SkillTable; | |
1100 | @@ -240,6 +242,8 @@ | |
1101 | import net.sf.l2j.gameserver.taskmanager.ShadowItemTaskManager; | |
1102 | import net.sf.l2j.gameserver.taskmanager.WaterTaskManager; | |
1103 | ||
1104 | +import Base.AutoFarm.AutofarmPlayerRoutine; | |
1105 | + | |
1106 | /** | |
1107 | * This class represents a player in the world.<br> | |
1108 | * There is always a client-thread connected to this (except if a player-store is activated upon logout). | |
1109 | @@ -6386,6 +6390,8 @@ | |
1110 | { | |
1111 | super.deleteMe(); | |
1112 | ||
1113 | + _bot.stop(); | |
1114 | + | |
1115 | if (getMountType() == 2 && isInsideZone(ZoneId.NO_LANDING)) | |
1116 | teleportTo(RestartType.TOWN); | |
1117 | ||
1118 | @@ -6457,6 +6463,8 @@ | |
1119 | // Remove the Player from the world | |
1120 | decayMe(); | |
1121 | ||
1122 | + _bot.stop(); | |
1123 | + | |
1124 | // If a party is in progress, leave it | |
1125 | if (_party != null) | |
1126 | _party.removePartyMember(this, MessageType.DISCONNECTED); | |
1127 | @@ -7738,4 +7746,228 @@ | |
1128 | { | |
1129 | return _selectedBlocksList; | |
1130 | } | |
1131 | + | |
1132 | + | |
1133 | + // ------------ | |
1134 | + // Autofarm | |
1135 | + // ------------ | |
1136 | + | |
1137 | + private boolean _autoFarm; | |
1138 | + | |
1139 | + public void setAutoFarm(boolean comm) | |
1140 | + { | |
1141 | + _autoFarm = comm; | |
1142 | + } | |
1143 | + | |
1144 | + public boolean isAutoFarm() | |
1145 | + { | |
1146 | + return _autoFarm; | |
1147 | + } | |
1148 | + | |
1149 | + private int autoFarmRadius = 1200; | |
1150 | + | |
1151 | + public void setRadius(int value) | |
1152 | + { | |
1153 | + autoFarmRadius = MathUtil.limit(value, 200, 3000); | |
1154 | + } | |
1155 | + | |
1156 | + public int getRadius() | |
1157 | + { | |
1158 | + return autoFarmRadius; | |
1159 | + } | |
1160 | + | |
1161 | + private int autoFarmShortCut = 9; | |
1162 | + | |
1163 | + public void setPage(int value) | |
1164 | + { | |
1165 | + autoFarmShortCut = MathUtil.limit(value, 0, 9); | |
1166 | + } | |
1167 | + | |
1168 | + public int getPage() | |
1169 | + { | |
1170 | + return autoFarmShortCut; | |
1171 | + } | |
1172 | + | |
1173 | + private int autoFarmHealPercente = 30; | |
1174 | + | |
1175 | + public void setHealPercent(int value) | |
1176 | + { | |
1177 | + autoFarmHealPercente = MathUtil.limit(value, 20, 90); | |
1178 | + } | |
1179 | + | |
1180 | + public int getHealPercent() | |
1181 | + { | |
1182 | + return autoFarmHealPercente; | |
1183 | + } | |
1184 | + | |
1185 | + private boolean autoFarmBuffProtection = false; | |
1186 | + | |
1187 | + public void setNoBuffProtection(boolean val) | |
1188 | + { | |
1189 | + autoFarmBuffProtection = val; | |
1190 | + } | |
1191 | + | |
1192 | + public boolean isNoBuffProtected() | |
1193 | + { | |
1194 | + return autoFarmBuffProtection; | |
1195 | + } | |
1196 | + | |
1197 | + private boolean autoAntiKsProtection = false; | |
1198 | + | |
1199 | + public void setAntiKsProtection(boolean val) | |
1200 | + { | |
1201 | + autoAntiKsProtection = val; | |
1202 | + } | |
1203 | + | |
1204 | + public boolean isAntiKsProtected() | |
1205 | + { | |
1206 | + return autoAntiKsProtection; | |
1207 | + } | |
1208 | + | |
1209 | + private boolean autoFarmSummonAttack = false; | |
1210 | + | |
1211 | + public void setSummonAttack(boolean val) | |
1212 | + { | |
1213 | + autoFarmSummonAttack = val; | |
1214 | + } | |
1215 | + | |
1216 | + public boolean isSummonAttack() | |
1217 | + { | |
1218 | + return autoFarmSummonAttack; | |
1219 | + } | |
1220 | + | |
1221 | + private int autoFarmSummonSkillPercente = 0; | |
1222 | + | |
1223 | + public void setSummonSkillPercent(int value) | |
1224 | + { | |
1225 | + autoFarmSummonSkillPercente = MathUtil.limit(value, 0, 90); | |
1226 | + } | |
1227 | + | |
1228 | + public int getSummonSkillPercent() | |
1229 | + { | |
1230 | + return autoFarmSummonSkillPercente; | |
1231 | + } | |
1232 | + | |
1233 | + private int hpPotionPercent = 60; | |
1234 | + private int mpPotionPercent = 60; | |
1235 | + | |
1236 | + public void setHpPotionPercentage(int value) | |
1237 | + { | |
1238 | + hpPotionPercent = MathUtil.limit(value, 0, 100); | |
1239 | + } | |
1240 | + | |
1241 | + public int getHpPotionPercentage() | |
1242 | + { | |
1243 | + return hpPotionPercent; | |
1244 | + } | |
1245 | + | |
1246 | + public void setMpPotionPercentage(int value) | |
1247 | + { | |
1248 | + mpPotionPercent = MathUtil.limit(value, 0, 100); | |
1249 | + } | |
1250 | + | |
1251 | + public int getMpPotionPercentage() | |
1252 | + { | |
1253 | + return mpPotionPercent; | |
1254 | + } | |
1255 | + | |
1256 | + private List<Integer> _ignoredMonster = new ArrayList<>(); | |
1257 | + | |
1258 | + public void ignoredMonster(Integer npcId) | |
1259 | + { | |
1260 | + _ignoredMonster.add(npcId); | |
1261 | + } | |
1262 | + | |
1263 | + public void activeMonster(Integer npcId) | |
1264 | + { | |
1265 | + if (_ignoredMonster.contains(npcId)) | |
1266 | + _ignoredMonster.remove(npcId); | |
1267 | + } | |
1268 | + | |
1269 | + public boolean ignoredMonsterContain(int npcId) | |
1270 | + { | |
1271 | + return _ignoredMonster.contains(npcId); | |
1272 | + } | |
1273 | + | |
1274 | + private AutofarmPlayerRoutine _bot = new AutofarmPlayerRoutine(this); | |
1275 | + | |
1276 | + public AutofarmPlayerRoutine getBot() | |
1277 | + { | |
1278 | + if (_bot == null) | |
1279 | + _bot = new AutofarmPlayerRoutine(this); | |
1280 | + | |
1281 | + return _bot; | |
1282 | + } | |
1283 | + | |
1284 | + | |
1285 | + public String getIP() | |
1286 | + { | |
1287 | + if (getClient().getConnection() == null) | |
1288 | + return "N/A IP"; | |
1289 | + return getClient().getConnection().getInetAddress().getHostAddress(); | |
1290 | + } | |
1291 | + | |
1292 | + | |
1293 | + | |
1294 | + // Función para guardar los valores del autofarm en la base de datos | |
1295 | + public void saveAutoFarmSettings() { | |
1296 | + try (Connection con = ConnectionPool.getConnection()) { | |
1297 | + 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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; | |
1298 | + try (PreparedStatement updateStatement = con.prepareStatement(updateSql)) { | |
1299 | + updateStatement.setInt(1, getObjectId()); // char_id | |
1300 | + updateStatement.setString(2, getName()); // char_name | |
1301 | + | |
1302 | + updateStatement.setInt(3, autoFarmRadius); | |
1303 | + updateStatement.setInt(4, autoFarmShortCut); | |
1304 | + updateStatement.setInt(5, autoFarmHealPercente); | |
1305 | + updateStatement.setBoolean(6, autoFarmBuffProtection); | |
1306 | + updateStatement.setBoolean(7, autoAntiKsProtection); | |
1307 | + updateStatement.setBoolean(8, autoFarmSummonAttack); | |
1308 | + updateStatement.setInt(9, autoFarmSummonSkillPercente); | |
1309 | + updateStatement.setInt(10, hpPotionPercent); | |
1310 | + updateStatement.setInt(11, mpPotionPercent); | |
1311 | + updateStatement.executeUpdate(); | |
1312 | + } | |
1313 | + } catch (SQLException e) { | |
1314 | + e.printStackTrace(); | |
1315 | + } | |
1316 | + } | |
1317 | + | |
1318 | + public void loadAutoFarmSettings() { | |
1319 | + try (Connection con = ConnectionPool.getConnection()) { | |
1320 | + String selectSql = "SELECT * FROM character_autofarm WHERE char_id = ?"; | |
1321 | + try (PreparedStatement selectStatement = con.prepareStatement(selectSql)) { | |
1322 | + selectStatement.setInt(1, getObjectId()); // char_id | |
1323 | + try (ResultSet resultSet = selectStatement.executeQuery()) { | |
1324 | + if (resultSet.next()) { | |
1325 | + | |
1326 | + autoFarmRadius = resultSet.getInt("radius"); | |
1327 | + autoFarmShortCut = resultSet.getInt("short_cut"); | |
1328 | + autoFarmHealPercente = resultSet.getInt("heal_percent"); | |
1329 | + autoFarmBuffProtection = resultSet.getBoolean("buff_protection"); | |
1330 | + autoAntiKsProtection = resultSet.getBoolean("anti_ks_protection"); | |
1331 | + autoFarmSummonAttack = resultSet.getBoolean("summon_attack"); | |
1332 | + autoFarmSummonSkillPercente = resultSet.getInt("summon_skill_percent"); | |
1333 | + hpPotionPercent = resultSet.getInt("hp_potion_percent"); | |
1334 | + mpPotionPercent = resultSet.getInt("mp_potion_percent"); | |
1335 | + } else { | |
1336 | + // Si no se encontraron registros, cargar valores predeterminados | |
1337 | + | |
1338 | + autoFarmRadius = 1200; | |
1339 | + autoFarmShortCut = 9; | |
1340 | + autoFarmHealPercente = 30; | |
1341 | + autoFarmBuffProtection = false; | |
1342 | + autoAntiKsProtection = false; | |
1343 | + autoFarmSummonAttack = false; | |
1344 | + autoFarmSummonSkillPercente = 0; | |
1345 | + hpPotionPercent = 60; | |
1346 | + mpPotionPercent = 60; | |
1347 | + } | |
1348 | + } | |
1349 | + } | |
1350 | + } catch (SQLException e) { | |
1351 | + e.printStackTrace(); | |
1352 | + } | |
1353 | + } | |
1354 | + | |
1355 | } | |
1356 | \ No newline at end of file | |
1357 | diff --git java/net/sf/l2j/gameserver/network/SystemMessageId.java java/net/sf/l2j/gameserver/network/SystemMessageId.java | |
1358 | index 3e0e45e..12cf8b2 100644 | |
1359 | --- java/net/sf/l2j/gameserver/network/SystemMessageId.java | |
1360 | +++ java/net/sf/l2j/gameserver/network/SystemMessageId.java | |
1361 | @@ -11796,6 +11796,17 @@ | |
1362 | */ | |
1363 | public static final SystemMessageId PLEASE_WAIT_A_MOMENT; | |
1364 | ||
1365 | + public static final SystemMessageId DESACTIVATE_SUMMON_ACTACK; | |
1366 | + public static final SystemMessageId ACTIVATE_RESPECT_HUNT; | |
1367 | + public static final SystemMessageId DESACTIVATE_RESPECT_HUNT; | |
1368 | + public static final SystemMessageId ACTIVATE_SUMMON_ACTACK; | |
1369 | + public static final SystemMessageId AUTO_FARM_DESACTIVATED; | |
1370 | + public static final SystemMessageId AUTO_FARM_ACTIVATED; | |
1371 | + | |
1372 | + | |
1373 | + | |
1374 | + | |
1375 | + | |
1376 | /** | |
1377 | * Array containing all SystemMessageIds<br> | |
1378 | * Important: Always initialize with a length of the highest SystemMessageId + 1!!! | |
1379 | @@ -13766,6 +13777,13 @@ | |
1380 | CURRENTLY_LOGGING_IN = new SystemMessageId(2030); | |
1381 | PLEASE_WAIT_A_MOMENT = new SystemMessageId(2031); | |
1382 | ||
1383 | + AUTO_FARM_DESACTIVATED = new SystemMessageId(2155); | |
1384 | + ACTIVATE_SUMMON_ACTACK = new SystemMessageId(2156); | |
1385 | + DESACTIVATE_SUMMON_ACTACK = new SystemMessageId(2157); | |
1386 | + ACTIVATE_RESPECT_HUNT = new SystemMessageId(2158); | |
1387 | + DESACTIVATE_RESPECT_HUNT = new SystemMessageId(2159); | |
1388 | + AUTO_FARM_ACTIVATED = new SystemMessageId(2160); | |
1389 | + | |
1390 | buildFastLookupTable(); | |
1391 | } | |
1392 | ||
1393 | diff --git java/net/sf/l2j/gameserver/network/clientpackets/EnterWorld.java java/net/sf/l2j/gameserver/network/clientpackets/EnterWorld.java | |
1394 | index 10b5aa1..c16bd46 100644 | |
1395 | --- java/net/sf/l2j/gameserver/network/clientpackets/EnterWorld.java | |
1396 | +++ java/net/sf/l2j/gameserver/network/clientpackets/EnterWorld.java | |
1397 | @@ -64,6 +64,8 @@ | |
1398 | import net.sf.l2j.gameserver.skills.L2Skill; | |
1399 | import net.sf.l2j.gameserver.taskmanager.GameTimeTaskManager; | |
1400 | ||
1401 | +import Base.AutoFarm.AutofarmPlayerRoutine; | |
1402 | + | |
1403 | public class EnterWorld extends L2GameClientPacket | |
1404 | { | |
1405 | @Override | |
1406 | @@ -257,6 +259,18 @@ | |
1407 | LMEvent.onLogin(player); | |
1408 | TvTEvent.onLogin(player); | |
1409 | ||
1410 | + | |
1411 | + | |
1412 | + if(AutofarmPlayerRoutine.isIpAllowed(player.getIP())) { | |
1413 | + AutofarmPlayerRoutine.removeIpEntry(player.getObjectId()); | |
1414 | + } | |
1415 | + | |
1416 | + | |
1417 | + player.loadAutoFarmSettings(); | |
1418 | + | |
1419 | + if(player.isSummonAttack()) { | |
1420 | + player.sendPacket(new SystemMessage(SystemMessageId.ACTIVATE_SUMMON_ACTACK)); | |
1421 | + | |
1422 | + } | |
1423 | + | |
1424 | + if(player.isAntiKsProtected()) { | |
1425 | + player.sendPacket(new SystemMessage(SystemMessageId.ACTIVATE_RESPECT_HUNT)); | |
1426 | + } | |
1427 | + | |
1428 | + | |
1429 | // If the Player is a Dark Elf, check for Shadow Sense at night. | |
1430 | if (player.getRace() == ClassRace.DARK_ELF && player.hasSkill(L2Skill.SKILL_SHADOW_SENSE)) | |
1431 | player.sendPacket(SystemMessage.getSystemMessage((GameTimeTaskManager.getInstance().isNight()) ? SystemMessageId.NIGHT_S1_EFFECT_APPLIES : SystemMessageId.DAY_S1_EFFECT_DISAPPEARS).addSkillName(L2Skill.SKILL_SHADOW_SENSE)); | |
1432 | diff --git java/net/sf/l2j/gameserver/network/clientpackets/Logout.java java/net/sf/l2j/gameserver/network/clientpackets/Logout.java | |
1433 | index fc35889..7e45882 100644 | |
1434 | --- java/net/sf/l2j/gameserver/network/clientpackets/Logout.java | |
1435 | +++ java/net/sf/l2j/gameserver/network/clientpackets/Logout.java | |
1436 | @@ -12,6 +12,8 @@ | |
1437 | import net.sf.l2j.gameserver.network.serverpackets.ActionFailed; | |
1438 | import net.sf.l2j.gameserver.taskmanager.AttackStanceTaskManager; | |
1439 | ||
1440 | +import Base.AutoFarm.AutofarmPlayerRoutine; | |
1441 | + | |
1442 | public final class Logout extends L2GameClientPacket | |
1443 | { | |
1444 | @Override | |
1445 | @@ -39,6 +41,9 @@ | |
1446 | return; | |
1447 | } | |
1448 | ||
1449 | + | |
1450 | + | |
1451 | + | |
1452 | if (AttackStanceTaskManager.getInstance().isInAttackStance(player) && !player.isGM()) | |
1453 | { | |
1454 | player.sendPacket(SystemMessageId.CANT_LOGOUT_WHILE_FIGHTING); | |
1455 | @@ -59,6 +64,17 @@ | |
1456 | LMEvent.onLogout(player); | |
1457 | TvTEvent.onLogout(player); | |
1458 | ||
1459 | + if (player.isAutoFarm()) | |
1460 | + { | |
1461 | + if(AutofarmPlayerRoutine.isIpAllowed(player.getIP())) { | |
1462 | + AutofarmPlayerRoutine.removeIpEntry(player.getObjectId()); | |
1463 | + } | |
1464 | + | |
1465 | + | |
1466 | + } | |
1467 | + | |
1468 | + | |
1469 | + | |
1470 | player.removeFromBossZone(); | |
1471 | AntiFeedManager.getInstance().onDisconnect(player.getClient()); | |
1472 | player.logout(true); | |
1473 | diff --git java/net/sf/l2j/gameserver/network/clientpackets/RequestBypassToServer.java java/net/sf/l2j/gameserver/network/clientpackets/RequestBypassToServer.java | |
1474 | index 5f8debc..78fa84c 100644 | |
1475 | --- java/net/sf/l2j/gameserver/network/clientpackets/RequestBypassToServer.java | |
1476 | +++ java/net/sf/l2j/gameserver/network/clientpackets/RequestBypassToServer.java | |
1477 | @@ -45,11 +45,16 @@ | |
1478 | import net.sf.l2j.gameserver.model.spawn.ASpawn; | |
1479 | import net.sf.l2j.gameserver.network.SystemMessageId; | |
1480 | import net.sf.l2j.gameserver.network.serverpackets.ActionFailed; | |
1481 | +import net.sf.l2j.gameserver.network.serverpackets.ExShowScreenMessage; | |
1482 | +import net.sf.l2j.gameserver.network.serverpackets.ExShowScreenMessage.SMPOS; | |
1483 | import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage; | |
1484 | +import net.sf.l2j.gameserver.network.serverpackets.SystemMessage; | |
1485 | import net.sf.l2j.gameserver.scripting.QuestState; | |
1486 | import net.sf.l2j.gameserver.skills.AbstractEffect; | |
1487 | import net.sf.l2j.gameserver.skills.L2Skill; | |
1488 | ||
1489 | +import Base.AutoFarm.AutofarmPlayerRoutine; | |
1490 | + | |
1491 | public final class RequestBypassToServer extends L2GameClientPacket | |
1492 | { | |
1493 | private static final Logger GMAUDIT_LOG = Logger.getLogger("gmaudit"); | |
1494 | @@ -75,9 +80,11 @@ | |
1495 | return; | |
1496 | ||
1497 | final Player player = getClient().getPlayer(); | |
1498 | + | |
1499 | + | |
1500 | if (player == null) | |
1501 | return; | |
1502 | - | |
1503 | + final AutofarmPlayerRoutine bot = player.getBot(); | |
1504 | if (_command.startsWith("admin_")) | |
1505 | { | |
1506 | String command = _command.split(" ")[0]; | |
1507 | @@ -130,6 +137,119 @@ | |
1508 | html.disableValidation(); | |
1509 | player.sendPacket(html); | |
1510 | } | |
1511 | + | |
1512 | + | |
1513 | + | |
1514 | + else if (_command.startsWith("_infosettings")) | |
1515 | + { | |
1516 | + showAutoFarm(player); | |
1517 | + } | |
1518 | + | |
1519 | + | |
1520 | + | |
1521 | + else if (_command.startsWith("_autofarm")) | |
1522 | + { | |
1523 | + if (player.isAutoFarm()) | |
1524 | + { | |
1525 | + bot.stop(); | |
1526 | + player.setAutoFarm(false); | |
1527 | + } | |
1528 | + else | |
1529 | + { | |
1530 | + bot.start(); | |
1531 | + player.setAutoFarm(true); | |
1532 | + } | |
1533 | + | |
1534 | + } | |
1535 | + | |
1536 | + if (_command.startsWith("_pageAutoFarm")) | |
1537 | + { | |
1538 | + StringTokenizer st = new StringTokenizer(_command, " "); | |
1539 | + st.nextToken(); | |
1540 | + try | |
1541 | + { | |
1542 | + String param = st.nextToken(); | |
1543 | + | |
1544 | + if (param.startsWith("inc_page") || param.startsWith("dec_page")) | |
1545 | + { | |
1546 | + int newPage; | |
1547 | + | |
1548 | + if (param.startsWith("inc_page")) | |
1549 | + { | |
1550 | + newPage = player.getPage() + 1; | |
1551 | + } | |
1552 | + else | |
1553 | + { | |
1554 | + newPage = player.getPage() - 1; | |
1555 | + } | |
1556 | + | |
1557 | + if (newPage >= 0 && newPage <= 9) | |
1558 | + { | |
1559 | + String[] pageStrings = | |
1560 | + { | |
1561 | + "F1", | |
1562 | + "F2", | |
1563 | + "F3", | |
1564 | + "F4", | |
1565 | + "F5", | |
1566 | + "F6", | |
1567 | + "F7", | |
1568 | + "F8", | |
1569 | + "F9", | |
1570 | + "F10" | |
1571 | + }; | |
1572 | + | |
1573 | + player.setPage(newPage); | |
1574 | + player.sendPacket(new ExShowScreenMessage("Auto Farm Skill Bar " + pageStrings[newPage], 3 * 1000, SMPOS.TOP_CENTER, false)); | |
1575 | + player.saveAutoFarmSettings(); | |
1576 | + | |
1577 | + } | |
1578 | + | |
1579 | + } | |
1580 | + | |
1581 | + } | |
1582 | + catch (Exception e) | |
1583 | + { | |
1584 | + e.printStackTrace(); | |
1585 | + } | |
1586 | + } | |
1587 | + | |
1588 | + if (_command.startsWith("_enableBuffProtect")) | |
1589 | + { | |
1590 | + player.setNoBuffProtection(!player.isNoBuffProtected()); | |
1591 | + if (player.isNoBuffProtected()) | |
1592 | + { | |
1593 | + player.sendPacket(new ExShowScreenMessage("Auto Farm Buff Protect On", 3 * 1000, SMPOS.TOP_CENTER, false)); | |
1594 | + } | |
1595 | + else | |
1596 | + { | |
1597 | + player.sendPacket(new ExShowScreenMessage("Auto Farm Buff Protect Off", 3 * 1000, SMPOS.TOP_CENTER, false)); | |
1598 | + } | |
1599 | + player.saveAutoFarmSettings(); | |
1600 | + } | |
1601 | + if (_command.startsWith("_enableSummonAttack")) | |
1602 | + { | |
1603 | + player.setSummonAttack(!player.isSummonAttack()); | |
1604 | + if (player.isSummonAttack()) | |
1605 | + { | |
1606 | + player.sendPacket(new SystemMessage(SystemMessageId.ACTIVATE_SUMMON_ACTACK)); | |
1607 | + player.sendPacket(new ExShowScreenMessage("Auto Farm Summon Attack On", 3 * 1000, SMPOS.TOP_CENTER, false)); | |
1608 | + } | |
1609 | + else | |
1610 | + { | |
1611 | + player.sendPacket(new SystemMessage(SystemMessageId.DESACTIVATE_SUMMON_ACTACK)); | |
1612 | + player.sendPacket(new ExShowScreenMessage("Auto Farm Summon Attack Off", 3 * 1000, SMPOS.TOP_CENTER, false)); | |
1613 | + } | |
1614 | + player.saveAutoFarmSettings(); | |
1615 | + } | |
1616 | + | |
1617 | + | |
1618 | + | |
1619 | + | |
1620 | + if (_command.startsWith("_enableRespectHunt")) | |
1621 | + { | |
1622 | + | |
1623 | + player.setAntiKsProtection(!player.isAntiKsProtected()); | |
1624 | + if (player.isAntiKsProtected()) | |
1625 | + { | |
1626 | + player.sendPacket(new SystemMessage(SystemMessageId.ACTIVATE_RESPECT_HUNT)); | |
1627 | + player.sendPacket(new ExShowScreenMessage("Respct Hunt On", 3 * 1000, SMPOS.TOP_CENTER, false)); | |
1628 | + } | |
1629 | + else | |
1630 | + { | |
1631 | + player.sendPacket(new SystemMessage(SystemMessageId.DESACTIVATE_RESPECT_HUNT)); | |
1632 | + player.sendPacket(new ExShowScreenMessage("Respct Hunt Off", 3 * 1000, SMPOS.TOP_CENTER, false)); | |
1633 | + } | |
1634 | + player.saveAutoFarmSettings(); | |
1635 | + | |
1636 | + } | |
1637 | + | |
1638 | + | |
1639 | + if (_command.startsWith("_radiusAutoFarm")) | |
1640 | + { | |
1641 | + StringTokenizer st = new StringTokenizer(_command, " "); | |
1642 | + st.nextToken(); | |
1643 | + try | |
1644 | + { | |
1645 | + String param = st.nextToken(); | |
1646 | + | |
1647 | + if (param.startsWith("inc_radius")) | |
1648 | + { | |
1649 | + player.setRadius(player.getRadius() + 200); | |
1650 | + player.sendPacket(new ExShowScreenMessage("Auto Farm Range: " + player.getRadius(), 3 * 1000, SMPOS.TOP_CENTER, false)); | |
1651 | + | |
1652 | + } | |
1653 | + else if (param.startsWith("dec_radius")) | |
1654 | + { | |
1655 | + player.setRadius(player.getRadius() - 200); | |
1656 | + player.sendPacket(new ExShowScreenMessage("Auto Farm Range: " + player.getRadius(), 3 * 1000, SMPOS.TOP_CENTER, false)); | |
1657 | + | |
1658 | + } | |
1659 | + player.saveAutoFarmSettings(); | |
1660 | + } | |
1661 | + catch (Exception e) | |
1662 | + { | |
1663 | + e.printStackTrace(); | |
1664 | + } | |
1665 | + } | |
1666 | + | |
1667 | + | |
1668 | + | |
1669 | else if (_command.startsWith("npc_")) | |
1670 | { | |
1671 | if (!player.validateBypass(_command)) | |
1672 | @@ -582,4 +702,33 @@ | |
1673 | ||
1674 | html.replace("%content%", sb.toString()); | |
1675 | } | |
1676 | + | |
1677 | + | |
1678 | + | |
1679 | + private static final String ACTIVED = "<font color=00FF00>STARTED</font>"; | |
1680 | + private static final String DESATIVED = "<font color=FF0000>STOPPED</font>"; | |
1681 | + private static final String STOP = "STOP"; | |
1682 | + private static final String START = "START"; | |
1683 | + | |
1684 | + public static void showAutoFarm(Player activeChar) | |
1685 | + { | |
1686 | + NpcHtmlMessage html = new NpcHtmlMessage(0); | |
1687 | + html.setFile(activeChar.getLocale(),"html/mods/menu/AutoFarm.htm"); | |
1688 | + html.replace("%player%", activeChar.getName()); | |
1689 | + html.replace("%page%", StringUtil.formatNumber(activeChar.getPage() + 1)); | |
1690 | + html.replace("%heal%", StringUtil.formatNumber(activeChar.getHealPercent())); | |
1691 | + html.replace("%radius%", StringUtil.formatNumber(activeChar.getRadius())); | |
1692 | + html.replace("%summonSkill%", StringUtil.formatNumber(activeChar.getSummonSkillPercent())); | |
1693 | + html.replace("%hpPotion%", StringUtil.formatNumber(activeChar.getHpPotionPercentage())); | |
1694 | + html.replace("%mpPotion%", StringUtil.formatNumber(activeChar.getMpPotionPercentage())); | |
1695 | + html.replace("%noBuff%", activeChar.isNoBuffProtected() ? "back=L2UI.CheckBox_checked fore=L2UI.CheckBox_checked" : "back=L2UI.CheckBox fore=L2UI.CheckBox"); | |
1696 | + html.replace("%summonAtk%", activeChar.isSummonAttack() ? "back=L2UI.CheckBox_checked fore=L2UI.CheckBox_checked" : "back=L2UI.CheckBox fore=L2UI.CheckBox"); | |
1697 | + html.replace("%antiKs%", activeChar.isAntiKsProtected() ? "back=L2UI.CheckBox_checked fore=L2UI.CheckBox_checked" : "back=L2UI.CheckBox fore=L2UI.CheckBox"); | |
1698 | + html.replace("%autofarm%", activeChar.isAutoFarm() ? ACTIVED : DESATIVED); | |
1699 | + html.replace("%button%", activeChar.isAutoFarm() ? STOP : START); | |
1700 | + activeChar.sendPacket(html); | |
1701 | + } | |
1702 | + | |
1703 | + | |
1704 | + | |
1705 | } | |
1706 | \ No newline at end of file | |
1707 | diff --git java/net/sf/l2j/gameserver/network/clientpackets/RequestRestart.java java/net/sf/l2j/gameserver/network/clientpackets/RequestRestart.java | |
1708 | index 00a37d4..e95b67d 100644 | |
1709 | --- java/net/sf/l2j/gameserver/network/clientpackets/RequestRestart.java | |
1710 | +++ java/net/sf/l2j/gameserver/network/clientpackets/RequestRestart.java | |
1711 | @@ -11,6 +11,8 @@ | |
1712 | import net.sf.l2j.gameserver.network.serverpackets.RestartResponse; | |
1713 | import net.sf.l2j.gameserver.taskmanager.AttackStanceTaskManager; | |
1714 | ||
1715 | +import Base.AutoFarm.AutofarmPlayerRoutine; | |
1716 | + | |
1717 | public final class RequestRestart extends L2GameClientPacket | |
1718 | { | |
1719 | @Override | |
1720 | @@ -38,6 +40,16 @@ | |
1721 | return; | |
1722 | } | |
1723 | ||
1724 | + if (player.isAutoFarm()) | |
1725 | + { | |
1726 | + if(AutofarmPlayerRoutine.isIpAllowed(player.getIP())) { | |
1727 | + AutofarmPlayerRoutine.removeIpEntry(player.getObjectId()); | |
1728 | + } | |
1729 | + | |
1730 | + | |
1731 | + } | |
1732 | + | |
1733 | + | |
1734 | if (AttackStanceTaskManager.getInstance().isInAttackStance(player) && !player.isGM()) | |
1735 | { | |
1736 | player.sendPacket(SystemMessageId.CANT_RESTART_WHILE_FIGHTING); | |
1737 | diff --git java/net/sf/l2j/gameserver/network/serverpackets/Die.java java/net/sf/l2j/gameserver/network/serverpackets/Die.java | |
1738 | index b332215..b1d2328 100644 | |
1739 | --- java/net/sf/l2j/gameserver/network/serverpackets/Die.java | |
1740 | +++ java/net/sf/l2j/gameserver/network/serverpackets/Die.java | |
1741 | @@ -14,6 +14,8 @@ | |
1742 | import net.sf.l2j.gameserver.model.residence.castle.Siege; | |
1743 | import net.sf.l2j.gameserver.model.residence.clanhall.ClanHallSiege; | |
1744 | ||
1745 | +import Base.AutoFarm.AutofarmPlayerRoutine; | |
1746 | + | |
1747 | public class Die extends L2GameServerPacket | |
1748 | { | |
1749 | private final Creature _creature; | |
1750 | @@ -34,9 +36,16 @@ | |
1751 | ||
1752 | if (creature instanceof Player player) | |
1753 | { | |
1754 | + final AutofarmPlayerRoutine bot = player.getBot(); | |
1755 | _allowFixedRes = player.getAccessLevel().allowFixedRes(); | |
1756 | _clan = player.getClan(); | |
1757 | ||
1758 | + if (player.isAutoFarm()) | |
1759 | + { | |
1760 | + bot.stop(); | |
1761 | + player.setAutoFarm(false); | |
1762 | + } | |
1763 | + | |
1764 | } | |
1765 | else if (creature instanceof Monster monster) | |
1766 | _sweepable = monster.getSpoilState().isSweepable(); | |
1767 | diff --git java/net/sf/l2j/gameserver/network/serverpackets/SystemMessage.java java/net/sf/l2j/gameserver/network/serverpackets/SystemMessage.java | |
1768 | index 19bebb0..6760dfb 100644 | |
1769 | --- java/net/sf/l2j/gameserver/network/serverpackets/SystemMessage.java | |
1770 | +++ java/net/sf/l2j/gameserver/network/serverpackets/SystemMessage.java | |
1771 | @@ -29,7 +29,7 @@ | |
1772 | private SMParam[] _params; | |
1773 | private int _paramIndex; | |
1774 | ||
1775 | - private SystemMessage(final SystemMessageId smId) | |
1776 | + public SystemMessage(final SystemMessageId smId) | |
1777 | { | |
1778 | final int paramCount = smId.getParamCount(); | |
1779 | _smId = smId; | |
1780 |