SHOW:
|
|
- or go back to the newest paste.
| 1 | diff --git a/config/CustomMods/AutoFarm.properties b/config/CustomMods/AutoFarm.properties | |
| 2 | new file mode 100644 | |
| 3 | index 0000000..aab9d76 | |
| 4 | --- /dev/null | |
| 5 | +++ b/config/CustomMods/AutoFarm.properties | |
| 6 | @@ -0,0 +1,6 @@ | |
| 7 | +# ================================================================= | |
| 8 | +# Auto Farm | |
| 9 | +# ================================================================= | |
| 10 | +AutoFarmRadius = 800 | |
| 11 | +# 0 = barra 1, 1 = barra = 2 ... 9 = barra 10 | |
| 12 | +AutoFarmBar = 0 | |
| 13 | \ No newline at end of file | |
| 14 | diff --git a/java/Dev/AutoFarm/AutofarmCommand.java b/java/Dev/AutoFarm/AutofarmCommand.java | |
| 15 | new file mode 100644 | |
| 16 | index 0000000..c14df73 | |
| 17 | --- /dev/null | |
| 18 | +++ b/java/Dev/AutoFarm/AutofarmCommand.java | |
| 19 | @@ -0,0 +1,46 @@ | |
| 20 | +package Dev.AutoFarm; | |
| 21 | + | |
| 22 | + | |
| 23 | +import net.sf.l2j.gameserver.handler.IVoicedCommandHandler; | |
| 24 | +import net.sf.l2j.gameserver.model.actor.instance.Player; | |
| 25 | + | |
| 26 | + | |
| 27 | +public class AutofarmCommand implements IVoicedCommandHandler | |
| 28 | +{
| |
| 29 | + | |
| 30 | + @Override | |
| 31 | + public boolean useVoicedCommand(String command, Player activeChar, String params) | |
| 32 | + {
| |
| 33 | + if (activeChar.getInstance().getId() != 0) | |
| 34 | + {
| |
| 35 | + activeChar.sendMessage("You can't use this command inside a Instance!");
| |
| 36 | + return false; | |
| 37 | + } | |
| 38 | + if (!activeChar.isVip()) | |
| 39 | + {
| |
| 40 | + activeChar.sendMessage("Auto farm is only for Vip Players!");
| |
| 41 | + return false; | |
| 42 | + } | |
| 43 | + | |
| 44 | + switch (command) | |
| 45 | + {
| |
| 46 | + case "farm": | |
| 47 | + AutofarmManager.INSTANCE.toggleFarm(activeChar); | |
| 48 | + break; | |
| 49 | + case "farmon": | |
| 50 | + AutofarmManager.INSTANCE.startFarm(activeChar); | |
| 51 | + break; | |
| 52 | + case "farmoff": | |
| 53 | + AutofarmManager.INSTANCE.stopFarm(activeChar); | |
| 54 | + break; | |
| 55 | + } | |
| 56 | + return false; | |
| 57 | + } | |
| 58 | + | |
| 59 | + @Override | |
| 60 | + public String[] getVoicedCommandList() | |
| 61 | + {
| |
| 62 | + return new String[] | |
| 63 | + { "farm", "farmon", "farmoff" };
| |
| 64 | + } | |
| 65 | +} | |
| 66 | diff --git a/java/Dev/AutoFarm/AutofarmConstants.java b/java/Dev/AutoFarm/AutofarmConstants.java | |
| 67 | new file mode 100644 | |
| 68 | index 0000000..eb3c2b9 | |
| 69 | --- /dev/null | |
| 70 | +++ b/java/Dev/AutoFarm/AutofarmConstants.java | |
| 71 | @@ -0,0 +1,23 @@ | |
| 72 | +package Dev.AutoFarm; | |
| 73 | + | |
| 74 | +import java.util.Arrays; | |
| 75 | +import java.util.List; | |
| 76 | + | |
| 77 | +import net.sf.l2j.Config; | |
| 78 | + | |
| 79 | +public class AutofarmConstants | |
| 80 | +{
| |
| 81 | + public static Integer shortcutsPageIndex = Config.AUTO_FARM_BAR; | |
| 82 | + public static Integer targetingRadius = Config.AUTO_FARM_RADIUS; | |
| 83 | + public static Integer lowLifePercentageThreshold = 30; | |
| 84 | + public static Integer useMpPotsPercentageThreshold = 30; | |
| 85 | + public static Integer useHpPotsPercentageThreshold = 30; | |
| 86 | + public static Integer mpPotItemId = 728; | |
| 87 | + public static Integer hpPotItemId = 1539; | |
| 88 | + public static Integer hpPotSkillId = 2037; | |
| 89 | + | |
| 90 | + public static List<Integer> attackSlots = Arrays.asList(0, 1, 2, 3); | |
| 91 | + public static List<Integer> chanceSlots = Arrays.asList(4, 5); | |
| 92 | + public static List<Integer> selfSlots = Arrays.asList(6, 7, 8, 9); | |
| 93 | + public static List<Integer> lowLifeSlots = Arrays.asList(10, 11); | |
| 94 | +} | |
| 95 | diff --git a/java/Dev/AutoFarm/AutofarmManager.java b/java/Dev/AutoFarm/AutofarmManager.java | |
| 96 | new file mode 100644 | |
| 97 | index 0000000..9decb1a | |
| 98 | --- /dev/null | |
| 99 | +++ b/java/Dev/AutoFarm/AutofarmManager.java | |
| 100 | @@ -0,0 +1,84 @@ | |
| 101 | +package Dev.AutoFarm; | |
| 102 | + | |
| 103 | + | |
| 104 | +import java.util.concurrent.ConcurrentHashMap; | |
| 105 | +import java.util.concurrent.ScheduledFuture; | |
| 106 | + | |
| 107 | +import net.sf.l2j.gameserver.ThreadPoolManager; | |
| 108 | +import net.sf.l2j.gameserver.handler.voicedcommandhandlers.VoicedMenu; | |
| 109 | +import net.sf.l2j.gameserver.model.actor.instance.Player; | |
| 110 | + | |
| 111 | +public enum AutofarmManager | |
| 112 | +{
| |
| 113 | + INSTANCE; | |
| 114 | + | |
| 115 | + private final Long iterationSpeedMs = 450L; | |
| 116 | + | |
| 117 | + private final ConcurrentHashMap<Integer, AutofarmPlayerRoutine> activeFarmers = new ConcurrentHashMap<>(); | |
| 118 | + private final ScheduledFuture<?> onUpdateTask = ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(onUpdate(), 1000, iterationSpeedMs); | |
| 119 | + | |
| 120 | + private Runnable onUpdate() | |
| 121 | + {
| |
| 122 | + return () -> activeFarmers.forEach((integer, autofarmPlayerRoutine) -> autofarmPlayerRoutine.executeRoutine()); | |
| 123 | + } | |
| 124 | + | |
| 125 | + public void startFarm(Player player) | |
| 126 | + {
| |
| 127 | + if (isAutofarming(player)) | |
| 128 | + {
| |
| 129 | + player.sendMessage("You are already autofarming");
| |
| 130 | + return; | |
| 131 | + } | |
| 132 | + | |
| 133 | + activeFarmers.put(player.getObjectId(), new AutofarmPlayerRoutine(player)); | |
| 134 | + player.sendMessage("Autofarming activated");
| |
| 135 | + } | |
| 136 | + | |
| 137 | + public void stopFarm(Player player) | |
| 138 | + {
| |
| 139 | + if (!isAutofarming(player)) | |
| 140 | + {
| |
| 141 | + player.sendMessage("You are not autofarming");
| |
| 142 | + return; | |
| 143 | + } | |
| 144 | + | |
| 145 | + activeFarmers.remove(player.getObjectId()); | |
| 146 | + player.sendMessage("Autofarming deactivated");
| |
| 147 | + } | |
| 148 | + | |
| 149 | + public void toggleFarm(Player player) | |
| 150 | + {
| |
| 151 | + if (isAutofarming(player)) | |
| 152 | + {
| |
| 153 | + stopFarm(player); | |
| 154 | + VoicedMenu.sendVipWindow(player); | |
| 155 | + return; | |
| 156 | + } | |
| 157 | + | |
| 158 | + startFarm(player); | |
| 159 | + VoicedMenu.sendVipWindow(player); | |
| 160 | + } | |
| 161 | + | |
| 162 | + public Boolean isAutofarming(Player player) | |
| 163 | + {
| |
| 164 | + return activeFarmers.containsKey(player.getObjectId()); | |
| 165 | + } | |
| 166 | + | |
| 167 | + public void onPlayerLogout(Player player) | |
| 168 | + {
| |
| 169 | + stopFarm(player); | |
| 170 | + } | |
| 171 | + | |
| 172 | + public void onDeath(Player player) | |
| 173 | + {
| |
| 174 | + if (isAutofarming(player)) | |
| 175 | + {
| |
| 176 | + activeFarmers.remove(player.getObjectId()); | |
| 177 | + } | |
| 178 | + } | |
| 179 | + | |
| 180 | + public ScheduledFuture<?> getOnUpdateTask() | |
| 181 | + {
| |
| 182 | + return onUpdateTask; | |
| 183 | + } | |
| 184 | +} | |
| 185 | \ No newline at end of file | |
| 186 | diff --git a/java/Dev/AutoFarm/AutofarmPlayerRoutine.java b/java/Dev/AutoFarm/AutofarmPlayerRoutine.java | |
| 187 | new file mode 100644 | |
| 188 | index 0000000..1bea3cf | |
| 189 | --- /dev/null | |
| 190 | +++ b/java/Dev/AutoFarm/AutofarmPlayerRoutine.java | |
| 191 | @@ -0,0 +1,578 @@ | |
| 192 | +package Dev.AutoFarm; | |
| 193 | + | |
| 194 | + | |
| 195 | +import java.util.ArrayList; | |
| 196 | +import java.util.Arrays; | |
| 197 | +import java.util.Collections; | |
| 198 | +import java.util.List; | |
| 199 | +import java.util.function.Function; | |
| 200 | +import java.util.stream.Collectors; | |
| 201 | + | |
| 202 | +import net.sf.l2j.commons.math.MathUtil; | |
| 203 | + | |
| 204 | +import net.sf.l2j.Config; | |
| 205 | +import net.sf.l2j.gameserver.ThreadPoolManager; | |
| 206 | +import net.sf.l2j.gameserver.data.SkillTable; | |
| 207 | +import net.sf.l2j.gameserver.geoengine.GeoEngine; | |
| 208 | +import net.sf.l2j.gameserver.handler.IItemHandler; | |
| 209 | +import net.sf.l2j.gameserver.handler.ItemHandler; | |
| 210 | +import net.sf.l2j.gameserver.model.L2ShortCut; | |
| 211 | +import net.sf.l2j.gameserver.model.L2Skill; | |
| 212 | +import net.sf.l2j.gameserver.model.WorldObject; | |
| 213 | +import net.sf.l2j.gameserver.model.WorldRegion; | |
| 214 | +import net.sf.l2j.gameserver.model.actor.Creature; | |
| 215 | +import net.sf.l2j.gameserver.model.actor.Summon; | |
| 216 | +import net.sf.l2j.gameserver.model.actor.ai.CtrlEvent; | |
| 217 | +import net.sf.l2j.gameserver.model.actor.ai.CtrlIntention; | |
| 218 | +import net.sf.l2j.gameserver.model.actor.ai.NextAction; | |
| 219 | +import net.sf.l2j.gameserver.model.actor.instance.Monster; | |
| 220 | +import net.sf.l2j.gameserver.model.actor.instance.Pet; | |
| 221 | +import net.sf.l2j.gameserver.model.actor.instance.Player; | |
| 222 | +import net.sf.l2j.gameserver.model.holder.IntIntHolder; | |
| 223 | +import net.sf.l2j.gameserver.model.item.instance.ItemInstance; | |
| 224 | +import net.sf.l2j.gameserver.model.item.kind.Item; | |
| 225 | +import net.sf.l2j.gameserver.model.item.type.ActionType; | |
| 226 | +import net.sf.l2j.gameserver.model.item.type.EtcItemType; | |
| 227 | +import net.sf.l2j.gameserver.model.item.type.WeaponType; | |
| 228 | +import net.sf.l2j.gameserver.model.itemcontainer.Inventory; | |
| 229 | +import net.sf.l2j.gameserver.network.SystemMessageId; | |
| 230 | +import net.sf.l2j.gameserver.network.serverpackets.ActionFailed; | |
| 231 | +import net.sf.l2j.gameserver.network.serverpackets.ItemList; | |
| 232 | +import net.sf.l2j.gameserver.network.serverpackets.PetItemList; | |
| 233 | +import net.sf.l2j.gameserver.network.serverpackets.SystemMessage; | |
| 234 | +import net.sf.l2j.gameserver.scripting.Quest; | |
| 235 | +import net.sf.l2j.gameserver.scripting.QuestState; | |
| 236 | +import net.sf.l2j.gameserver.templates.skills.L2SkillType; | |
| 237 | + | |
| 238 | +public class AutofarmPlayerRoutine | |
| 239 | +{
| |
| 240 | + private final Player player; | |
| 241 | + private Creature committedTarget = null; | |
| 242 | + | |
| 243 | + public AutofarmPlayerRoutine(Player player) | |
| 244 | + {
| |
| 245 | + this.player = player; | |
| 246 | + } | |
| 247 | + | |
| 248 | + public void executeRoutine() | |
| 249 | + {
| |
| 250 | + checkSpoil(); | |
| 251 | + targetEligibleCreature(); | |
| 252 | + checkManaPots(); | |
| 253 | + checkHealthPots(); | |
| 254 | + attack(); | |
| 255 | + checkSpoil(); | |
| 256 | + } | |
| 257 | + | |
| 258 | + private void attack() | |
| 259 | + {
| |
| 260 | + boolean shortcutsContainAttack = shotcutsContainAttack(); | |
| 261 | + if (shortcutsContainAttack) | |
| 262 | + {
| |
| 263 | + physicalAttack(); | |
| 264 | + } | |
| 265 | + | |
| 266 | + useAppropriateSpell(); | |
| 267 | + | |
| 268 | + if (shortcutsContainAttack) | |
| 269 | + {
| |
| 270 | + physicalAttack(); | |
| 271 | + } | |
| 272 | + } | |
| 273 | + | |
| 274 | + private void useAppropriateSpell() | |
| 275 | + {
| |
| 276 | + | |
| 277 | + L2Skill chanceSkill = nextAvailableSkill(getChanceSpells(), AutofarmSpellType.Chance); | |
| 278 | + | |
| 279 | + if (chanceSkill != null) | |
| 280 | + {
| |
| 281 | + useMagicSkill(chanceSkill, false); | |
| 282 | + return; | |
| 283 | + } | |
| 284 | + | |
| 285 | + L2Skill lowLifeSkill = nextAvailableSkill(getLowLifeSpells(), AutofarmSpellType.LowLife); | |
| 286 | + | |
| 287 | + if (lowLifeSkill != null) | |
| 288 | + {
| |
| 289 | + useMagicSkill(lowLifeSkill, false); | |
| 290 | + return; | |
| 291 | + } | |
| 292 | + | |
| 293 | + L2Skill selfSkills = nextAvailableSkill(getSelfSpells(), AutofarmSpellType.Self); | |
| 294 | + | |
| 295 | + if (selfSkills != null) | |
| 296 | + {
| |
| 297 | + useMagicSkill(selfSkills, true); | |
| 298 | + return; | |
| 299 | + } | |
| 300 | + | |
| 301 | + L2Skill attackSkill = nextAvailableSkill(getAttackSpells(), AutofarmSpellType.Attack); | |
| 302 | + | |
| 303 | + if (attackSkill != null) | |
| 304 | + {
| |
| 305 | + useMagicSkill(attackSkill, false); | |
| 306 | + return; | |
| 307 | + } | |
| 308 | + } | |
| 309 | + | |
| 310 | + public L2Skill nextAvailableSkill(List<Integer> skillIds, AutofarmSpellType spellType) | |
| 311 | + {
| |
| 312 | + for (Integer skillId : skillIds) | |
| 313 | + {
| |
| 314 | + L2Skill skill = player.getSkill(skillId); | |
| 315 | + | |
| 316 | + if (skill == null) | |
| 317 | + continue; | |
| 318 | + | |
| 319 | + if (!player.checkDoCastConditions(skill)) | |
| 320 | + continue; | |
| 321 | + | |
| 322 | + if (spellType == AutofarmSpellType.Chance && getMonsterTarget() != null) | |
| 323 | + {
| |
| 324 | + if (isSpoil(skillId)) | |
| 325 | + {
| |
| 326 | + if (monsterIsAlreadySpoiled()) | |
| 327 | + {
| |
| 328 | + continue; | |
| 329 | + } | |
| 330 | + else | |
| 331 | + {
| |
| 332 | + return skill; | |
| 333 | + } | |
| 334 | + } | |
| 335 | + | |
| 336 | + if (getMonsterTarget().getFirstEffect(skillId) == null) | |
| 337 | + {
| |
| 338 | + return skill; | |
| 339 | + } | |
| 340 | + else | |
| 341 | + {
| |
| 342 | + continue; | |
| 343 | + } | |
| 344 | + } | |
| 345 | + | |
| 346 | + if (spellType == AutofarmSpellType.LowLife && getMonsterTarget() != null && getHpPercentage() > AutofarmConstants.lowLifePercentageThreshold) | |
| 347 | + {
| |
| 348 | + break; | |
| 349 | + } | |
| 350 | + | |
| 351 | + if (spellType == AutofarmSpellType.Self) | |
| 352 | + {
| |
| 353 | + if (skill.isToggle() && player.getFirstEffect(skillId) == null) | |
| 354 | + return skill; | |
| 355 | + | |
| 356 | + if (player.getFirstEffect(skillId) == null) | |
| 357 | + {
| |
| 358 | + return skill; | |
| 359 | + } | |
| 360 | + | |
| 361 | + continue; | |
| 362 | + } | |
| 363 | + | |
| 364 | + return skill; | |
| 365 | + } | |
| 366 | + | |
| 367 | + return null; | |
| 368 | + } | |
| 369 | + | |
| 370 | + private void checkHealthPots() | |
| 371 | + {
| |
| 372 | + if (getHpPercentage() <= AutofarmConstants.useHpPotsPercentageThreshold) | |
| 373 | + {
| |
| 374 | + if (player.getFirstEffect(AutofarmConstants.hpPotSkillId) != null) | |
| 375 | + {
| |
| 376 | + return; | |
| 377 | + } | |
| 378 | + | |
| 379 | + ItemInstance hpPots = player.getInventory().getItemByItemId(AutofarmConstants.hpPotItemId); | |
| 380 | + if (hpPots != null) | |
| 381 | + {
| |
| 382 | + useItem(hpPots); | |
| 383 | + } | |
| 384 | + } | |
| 385 | + } | |
| 386 | + | |
| 387 | + private void checkManaPots() | |
| 388 | + {
| |
| 389 | + | |
| 390 | + if (getMpPercentage() <= AutofarmConstants.useMpPotsPercentageThreshold) | |
| 391 | + {
| |
| 392 | + ItemInstance mpPots = player.getInventory().getItemByItemId(AutofarmConstants.mpPotItemId); | |
| 393 | + if (mpPots != null) | |
| 394 | + {
| |
| 395 | + useItem(mpPots); | |
| 396 | + } | |
| 397 | + } | |
| 398 | + } | |
| 399 | + | |
| 400 | + private void checkSpoil() | |
| 401 | + {
| |
| 402 | + if (canBeSweepedByMe() && getMonsterTarget().isDead()) | |
| 403 | + {
| |
| 404 | + L2Skill sweeper = player.getSkill(42); | |
| 405 | + if (sweeper == null) | |
| 406 | + return; | |
| 407 | + | |
| 408 | + useMagicSkill(sweeper, false); | |
| 409 | + } | |
| 410 | + } | |
| 411 | + | |
| 412 | + private Double getHpPercentage() | |
| 413 | + {
| |
| 414 | + return player.getCurrentHp() * 100.0f / player.getMaxHp(); | |
| 415 | + } | |
| 416 | + | |
| 417 | + private Double getMpPercentage() | |
| 418 | + {
| |
| 419 | + return player.getCurrentMp() * 100.0f / player.getMaxMp(); | |
| 420 | + } | |
| 421 | + | |
| 422 | + private boolean canBeSweepedByMe() | |
| 423 | + {
| |
| 424 | + return getMonsterTarget() != null && getMonsterTarget().isDead() && getMonsterTarget().getSpoilerId() == player.getObjectId(); | |
| 425 | + } | |
| 426 | + | |
| 427 | + private boolean monsterIsAlreadySpoiled() | |
| 428 | + {
| |
| 429 | + return getMonsterTarget() != null && getMonsterTarget().getSpoilerId() != 0; | |
| 430 | + } | |
| 431 | + | |
| 432 | + private static boolean isSpoil(Integer skillId) | |
| 433 | + {
| |
| 434 | + return skillId == 254 || skillId == 302; | |
| 435 | + } | |
| 436 | + | |
| 437 | + private List<Integer> getAttackSpells() | |
| 438 | + {
| |
| 439 | + return getSpellsInSlots(AutofarmConstants.attackSlots); | |
| 440 | + } | |
| 441 | + | |
| 442 | + | |
| 443 | + private List<Integer> getSpellsInSlots(List<Integer> attackSlots) | |
| 444 | + {
| |
| 445 | + return Arrays.stream(player.getAllShortCuts()).filter(shortcut -> shortcut.getPage() == AutofarmConstants.shortcutsPageIndex && shortcut.getType() == L2ShortCut.TYPE_SKILL && attackSlots.contains(shortcut.getSlot())).map(L2ShortCut::getId).collect(Collectors.toList()); | |
| 446 | + } | |
| 447 | + | |
| 448 | + private List<Integer> getChanceSpells() | |
| 449 | + {
| |
| 450 | + return getSpellsInSlots(AutofarmConstants.chanceSlots); | |
| 451 | + } | |
| 452 | + | |
| 453 | + private List<Integer> getSelfSpells() | |
| 454 | + {
| |
| 455 | + return getSpellsInSlots(AutofarmConstants.selfSlots); | |
| 456 | + } | |
| 457 | + | |
| 458 | + private List<Integer> getLowLifeSpells() | |
| 459 | + {
| |
| 460 | + return getSpellsInSlots(AutofarmConstants.lowLifeSlots); | |
| 461 | + } | |
| 462 | + | |
| 463 | + private boolean shotcutsContainAttack() | |
| 464 | + {
| |
| 465 | + return Arrays.stream(player.getAllShortCuts()).anyMatch(shortcut -> | |
| 466 | + /* shortcut.getPage() == 0 && */shortcut.getType() == L2ShortCut.TYPE_ACTION && shortcut.getId() == 2); | |
| 467 | + } | |
| 468 | + | |
| 469 | + private void castSpellWithAppropriateTarget(L2Skill skill, Boolean forceOnSelf) | |
| 470 | + {
| |
| 471 | + if (forceOnSelf) | |
| 472 | + {
| |
| 473 | + WorldObject oldTarget = player.getTarget(); | |
| 474 | + player.setTarget(player); | |
| 475 | + player.useMagic(skill, false, false); | |
| 476 | + player.setTarget(oldTarget); | |
| 477 | + return; | |
| 478 | + } | |
| 479 | + | |
| 480 | + player.useMagic(skill, false, false); | |
| 481 | + } | |
| 482 | + | |
| 483 | + private void physicalAttack() | |
| 484 | + {
| |
| 485 | + | |
| 486 | + if (!(player.getTarget() instanceof Monster)) | |
| 487 | + {
| |
| 488 | + return; | |
| 489 | + } | |
| 490 | + | |
| 491 | + Creature target = (Monster) player.getTarget(); | |
| 492 | + | |
| 493 | + if (target.isAutoAttackable(player)) | |
| 494 | + {
| |
| 495 | + if (GeoEngine.getInstance().canSeeTarget(player, target)) | |
| 496 | + {
| |
| 497 | + player.getAI().setIntention(CtrlIntention.ATTACK, target); | |
| 498 | + player.onActionRequest(); | |
| 499 | + } | |
| 500 | + } | |
| 501 | + else | |
| 502 | + {
| |
| 503 | + player.sendPacket(ActionFailed.STATIC_PACKET); | |
| 504 | + | |
| 505 | + if (GeoEngine.getInstance().canSeeTarget(player, target)) | |
| 506 | + player.getAI().setIntention(CtrlIntention.FOLLOW, target); | |
| 507 | + } | |
| 508 | + } | |
| 509 | + | |
| 510 | + public void targetEligibleCreature() | |
| 511 | + {
| |
| 512 | + if (committedTarget != null) | |
| 513 | + {
| |
| 514 | + if (!committedTarget.isDead() && GeoEngine.getInstance().canSeeTarget(player, committedTarget)/* && !player.isMoving() */) | |
| 515 | + {
| |
| 516 | + return; | |
| 517 | + } | |
| 518 | + committedTarget = null; | |
| 519 | + player.setTarget(null); | |
| 520 | + } | |
| 521 | + | |
| 522 | + List<Monster> targets = getKnownMonstersInRadius(player, Config.AUTO_FARM_RADIUS, creature -> GeoEngine.getInstance().canMoveToTarget(player.getX(), player.getY(), player.getZ(), creature.getX(), creature.getY(), creature.getZ()) && !creature.isDead()); | |
| 523 | + | |
| 524 | + if (targets.isEmpty()) | |
| 525 | + {
| |
| 526 | + return; | |
| 527 | + } | |
| 528 | + | |
| 529 | + Creature closestTarget = targets.stream().min((o1, o2) -> (int) MathUtil.calculateDistance(o1, o2, false)).get(); | |
| 530 | + // CreatuL2Character = targets.get(Rnd.get(targets.size())); | |
| 531 | + committedTarget = closestTarget; | |
| 532 | + player.setTarget(closestTarget); | |
| 533 | + } | |
| 534 | + | |
| 535 | + @SuppressWarnings("static-method")
| |
| 536 | + public final List<Monster> getKnownMonstersInRadius(Player player, int radius, Function<Monster, Boolean> condition) | |
| 537 | + {
| |
| 538 | + final WorldRegion region = player.getRegion(); | |
| 539 | + if (region == null) | |
| 540 | + return Collections.emptyList(); | |
| 541 | + | |
| 542 | + final List<Monster> result = new ArrayList<>(); | |
| 543 | + | |
| 544 | + for (WorldRegion reg : region.getSurroundingRegions()) | |
| 545 | + {
| |
| 546 | + for (WorldObject obj : reg.getObjects()) | |
| 547 | + {
| |
| 548 | + if (!(obj instanceof Monster) || !MathUtil.checkIfInRange(radius, player, obj, true) || !condition.apply((Monster) obj)) | |
| 549 | + continue; | |
| 550 | + | |
| 551 | + result.add((Monster) obj); | |
| 552 | + } | |
| 553 | + } | |
| 554 | + | |
| 555 | + return result; | |
| 556 | + } | |
| 557 | + | |
| 558 | + public Monster getMonsterTarget() | |
| 559 | + {
| |
| 560 | + if (!(player.getTarget() instanceof Monster)) | |
| 561 | + {
| |
| 562 | + return null; | |
| 563 | + } | |
| 564 | + | |
| 565 | + return (Monster) player.getTarget(); | |
| 566 | + } | |
| 567 | + | |
| 568 | + private void useMagicSkill(L2Skill skill, Boolean forceOnSelf) | |
| 569 | + {
| |
| 570 | + if (skill.getSkillType() == L2SkillType.RECALL && !Config.KARMA_PLAYER_CAN_TELEPORT && player.getKarma() > 0) | |
| 571 | + {
| |
| 572 | + player.sendPacket(ActionFailed.STATIC_PACKET); | |
| 573 | + return; | |
| 574 | + } | |
| 575 | + | |
| 576 | + if (skill.isToggle() && player.isMounted()) | |
| 577 | + {
| |
| 578 | + player.sendPacket(ActionFailed.STATIC_PACKET); | |
| 579 | + return; | |
| 580 | + } | |
| 581 | + | |
| 582 | + if (player.isOutOfControl()) | |
| 583 | + {
| |
| 584 | + player.sendPacket(ActionFailed.STATIC_PACKET); | |
| 585 | + return; | |
| 586 | + } | |
| 587 | + | |
| 588 | + if (player.isAttackingNow()) | |
| 589 | + player.getAI().setNextAction(new NextAction(CtrlEvent.EVT_READY_TO_ACT, CtrlIntention.CAST, () -> castSpellWithAppropriateTarget(skill, forceOnSelf))); | |
| 590 | + else | |
| 591 | + {
| |
| 592 | + castSpellWithAppropriateTarget(skill, forceOnSelf); | |
| 593 | + } | |
| 594 | + } | |
| 595 | + | |
| 596 | + public void useItem(ItemInstance item) | |
| 597 | + {
| |
| 598 | + if (player.isInStoreMode()) | |
| 599 | + {
| |
| 600 | + player.sendPacket(SystemMessageId.ITEMS_UNAVAILABLE_FOR_STORE_MANUFACTURE); | |
| 601 | + return; | |
| 602 | + } | |
| 603 | + | |
| 604 | + if (player.getActiveTradeList() != null) | |
| 605 | + {
| |
| 606 | + player.sendPacket(SystemMessageId.CANNOT_PICKUP_OR_USE_ITEM_WHILE_TRADING); | |
| 607 | + return; | |
| 608 | + } | |
| 609 | + | |
| 610 | + if (item == null) | |
| 611 | + return; | |
| 612 | + | |
| 613 | + if (item.getItem().getType2() == Item.TYPE2_QUEST) | |
| 614 | + {
| |
| 615 | + player.sendPacket(SystemMessageId.CANNOT_USE_QUEST_ITEMS); | |
| 616 | + return; | |
| 617 | + } | |
| 618 | + | |
| 619 | + if (player.isAlikeDead() || player.isStunned() || player.isSleeping() || player.isParalyzed() || player.isAfraid()) | |
| 620 | + return; | |
| 621 | + | |
| 622 | + if (!Config.KARMA_PLAYER_CAN_TELEPORT && player.getKarma() > 0) | |
| 623 | + {
| |
| 624 | + final IntIntHolder[] sHolders = item.getItem().getSkills(); | |
| 625 | + if (sHolders != null) | |
| 626 | + {
| |
| 627 | + for (IntIntHolder sHolder : sHolders) | |
| 628 | + {
| |
| 629 | + final L2Skill skill = sHolder.getSkill(); | |
| 630 | + if (skill != null && (skill.getSkillType() == L2SkillType.TELEPORT || skill.getSkillType() == L2SkillType.RECALL)) | |
| 631 | + return; | |
| 632 | + } | |
| 633 | + } | |
| 634 | + } | |
| 635 | + | |
| 636 | + if (player.isFishing() && item.getItem().getDefaultAction() != ActionType.fishingshot) | |
| 637 | + {
| |
| 638 | + player.sendPacket(SystemMessageId.CANNOT_DO_WHILE_FISHING_3); | |
| 639 | + return; | |
| 640 | + } | |
| 641 | + | |
| 642 | + if (item.isPetItem()) | |
| 643 | + {
| |
| 644 | + if (!player.hasPet()) | |
| 645 | + {
| |
| 646 | + player.sendPacket(SystemMessageId.CANNOT_EQUIP_PET_ITEM); | |
| 647 | + return; | |
| 648 | + } | |
| 649 | + | |
| 650 | + final Summon pet = (player.getPet()); | |
| 651 | + | |
| 652 | + /*if (!pet.canWear(item.getItem())) | |
| 653 | + {
| |
| 654 | + player.sendPacket(SystemMessageId.PET_CANNOT_USE_ITEM); | |
| 655 | + return; | |
| 656 | + }*/ | |
| 657 | + | |
| 658 | + if (pet.isDead()) | |
| 659 | + {
| |
| 660 | + player.sendPacket(SystemMessageId.CANNOT_GIVE_ITEMS_TO_DEAD_PET); | |
| 661 | + return; | |
| 662 | + } | |
| 663 | + | |
| 664 | + if (!pet.getInventory().validateCapacity(item)) | |
| 665 | + {
| |
| 666 | + player.sendPacket(SystemMessageId.YOUR_PET_CANNOT_CARRY_ANY_MORE_ITEMS); | |
| 667 | + return; | |
| 668 | + } | |
| 669 | + | |
| 670 | + if (!pet.getInventory().validateWeight(item, 1)) | |
| 671 | + {
| |
| 672 | + player.sendPacket(SystemMessageId.UNABLE_TO_PLACE_ITEM_YOUR_PET_IS_TOO_ENCUMBERED); | |
| 673 | + return; | |
| 674 | + } | |
| 675 | + | |
| 676 | + player.transferItem("Transfer", item.getObjectId(), 1, pet.getInventory(), pet);
| |
| 677 | + | |
| 678 | + if (item.isEquipped()) | |
| 679 | + {
| |
| 680 | + pet.getInventory().unEquipItemInSlot(item.getLocationSlot()); | |
| 681 | + player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.PET_TOOK_OFF_S1).addItemName(item)); | |
| 682 | + } | |
| 683 | + else | |
| 684 | + {
| |
| 685 | + pet.getInventory().equipPetItem(item); | |
| 686 | + player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.PET_PUT_ON_S1).addItemName(item)); | |
| 687 | + } | |
| 688 | + | |
| 689 | + player.sendPacket(new PetItemList((Pet) pet)); | |
| 690 | + pet.updateAndBroadcastStatus(1); | |
| 691 | + return; | |
| 692 | + } | |
| 693 | + | |
| 694 | + if (!item.isEquipped()) | |
| 695 | + {
| |
| 696 | + if (!item.getItem().checkCondition(player, player, true)) | |
| 697 | + return; | |
| 698 | + } | |
| 699 | + | |
| 700 | + if (item.isEquipable()) | |
| 701 | + {
| |
| 702 | + if (player.isCastingNow() || player.isCastingSimultaneouslyNow()) | |
| 703 | + {
| |
| 704 | + player.sendPacket(SystemMessageId.CANNOT_USE_ITEM_WHILE_USING_MAGIC); | |
| 705 | + return; | |
| 706 | + } | |
| 707 | + | |
| 708 | + switch (item.getItem().getBodyPart()) | |
| 709 | + {
| |
| 710 | + case Item.SLOT_LR_HAND: | |
| 711 | + case Item.SLOT_L_HAND: | |
| 712 | + case Item.SLOT_R_HAND: | |
| 713 | + {
| |
| 714 | + if (player.isMounted()) | |
| 715 | + {
| |
| 716 | + player.sendPacket(SystemMessageId.CANNOT_EQUIP_ITEM_DUE_TO_BAD_CONDITION); | |
| 717 | + return; | |
| 718 | + } | |
| 719 | + | |
| 720 | + if (player.isCursedWeaponEquipped()) | |
| 721 | + return; | |
| 722 | + | |
| 723 | + break; | |
| 724 | + } | |
| 725 | + } | |
| 726 | + | |
| 727 | + if (player.isCursedWeaponEquipped() && item.getItemId() == 6408) | |
| 728 | + return; | |
| 729 | + | |
| 730 | + if (player.isAttackingNow()) | |
| 731 | + ThreadPoolManager.getInstance().scheduleGeneral(() -> {
| |
| 732 | + final ItemInstance itemToTest = player.getInventory().getItemByObjectId(item.getObjectId()); | |
| 733 | + if (itemToTest == null) | |
| 734 | + return; | |
| 735 | + | |
| 736 | + player.useEquippableItem(itemToTest, false); | |
| 737 | + }, player.getAttackEndTime() - System.currentTimeMillis()); | |
| 738 | + else | |
| 739 | + player.useEquippableItem(item, true); | |
| 740 | + } | |
| 741 | + else | |
| 742 | + {
| |
| 743 | + if (player.isCastingNow() && !(item.isPotion() || item.isElixir())) | |
| 744 | + return; | |
| 745 | + | |
| 746 | + if (player.getAttackType() == WeaponType.FISHINGROD && item.getItem().getItemType() == EtcItemType.LURE) | |
| 747 | + {
| |
| 748 | + player.getInventory().setPaperdollItem(Inventory.PAPERDOLL_LHAND, item); | |
| 749 | + player.broadcastUserInfo(); | |
| 750 | + | |
| 751 | + player.sendPacket(new ItemList(player, false)); | |
| 752 | + return; | |
| 753 | + } | |
| 754 | + | |
| 755 | + final IItemHandler handler = ItemHandler.getInstance().getItemHandler(item.getEtcItem()); | |
| 756 | + if (handler != null) | |
| 757 | + handler.useItem(player, item, false); | |
| 758 | + | |
| 759 | + for (Quest quest : item.getQuestEvents()) | |
| 760 | + {
| |
| 761 | + QuestState state = player.getQuestState(quest.getName()); | |
| 762 | + if (state == null || !state.isStarted()) | |
| 763 | + continue; | |
| 764 | + | |
| 765 | + quest.notifyItemUse(item, player, player.getTarget()); | |
| 766 | + } | |
| 767 | + } | |
| 768 | + } | |
| 769 | +} | |
| 770 | diff --git a/java/Dev/AutoFarm/AutofarmSpell.java b/java/Dev/AutoFarm/AutofarmSpell.java | |
| 771 | new file mode 100644 | |
| 772 | index 0000000..e4e86a7 | |
| 773 | --- /dev/null | |
| 774 | +++ b/java/Dev/AutoFarm/AutofarmSpell.java | |
| 775 | @@ -0,0 +1,24 @@ | |
| 776 | +package Dev.AutoFarm; | |
| 777 | + | |
| 778 | +public class AutofarmSpell | |
| 779 | +{
| |
| 780 | + private final Integer _skillId; | |
| 781 | + private final AutofarmSpellType _spellType; | |
| 782 | + | |
| 783 | + public AutofarmSpell(Integer skillId, AutofarmSpellType spellType) | |
| 784 | + {
| |
| 785 | + | |
| 786 | + _skillId = skillId; | |
| 787 | + _spellType = spellType; | |
| 788 | + } | |
| 789 | + | |
| 790 | + public Integer getSkillId() | |
| 791 | + {
| |
| 792 | + return _skillId; | |
| 793 | + } | |
| 794 | + | |
| 795 | + public AutofarmSpellType getSpellType() | |
| 796 | + {
| |
| 797 | + return _spellType; | |
| 798 | + } | |
| 799 | +} | |
| 800 | \ No newline at end of file | |
| 801 | diff --git a/java/Dev/AutoFarm/AutofarmSpellType.java b/java/Dev/AutoFarm/AutofarmSpellType.java | |
| 802 | new file mode 100644 | |
| 803 | index 0000000..81a4d8b | |
| 804 | --- /dev/null | |
| 805 | +++ b/java/Dev/AutoFarm/AutofarmSpellType.java | |
| 806 | @@ -0,0 +1,10 @@ | |
| 807 | +package Dev.AutoFarm; | |
| 808 | + | |
| 809 | + | |
| 810 | +public enum AutofarmSpellType | |
| 811 | +{
| |
| 812 | + Attack, | |
| 813 | + Chance, | |
| 814 | + Self, | |
| 815 | + LowLife | |
| 816 | +} | |
| 817 | \ No newline at end of file | |
| 818 | diff --git a/java/Dev/Instance/Instance.java b/java/Dev/Instance/Instance.java | |
| 819 | new file mode 100644 | |
| 820 | index 0000000..612cb6e | |
| 821 | --- /dev/null | |
| 822 | +++ b/java/Dev/Instance/Instance.java | |
| 823 | @@ -0,0 +1,45 @@ | |
| 824 | +package Dev.Instance; | |
| 825 | + | |
| 826 | +import java.util.ArrayList; | |
| 827 | +import java.util.List; | |
| 828 | + | |
| 829 | +import net.sf.l2j.gameserver.model.actor.instance.Door; | |
| 830 | + | |
| 831 | +public class Instance | |
| 832 | +{
| |
| 833 | + private int id; | |
| 834 | + private List<Door> doors; | |
| 835 | + | |
| 836 | + public Instance(int id) | |
| 837 | + {
| |
| 838 | + this.id = id; | |
| 839 | + doors = new ArrayList<>(); | |
| 840 | + } | |
| 841 | + | |
| 842 | + public void openDoors() | |
| 843 | + {
| |
| 844 | + for (Door door : doors) | |
| 845 | + door.openMe(); | |
| 846 | + } | |
| 847 | + | |
| 848 | + public void closeDoors() | |
| 849 | + {
| |
| 850 | + for (Door door : doors) | |
| 851 | + door.closeMe(); | |
| 852 | + } | |
| 853 | + | |
| 854 | + public void addDoor(Door door) | |
| 855 | + {
| |
| 856 | + doors.add(door); | |
| 857 | + } | |
| 858 | + | |
| 859 | + public List<Door> getDoors() | |
| 860 | + {
| |
| 861 | + return doors; | |
| 862 | + } | |
| 863 | + | |
| 864 | + public int getId() | |
| 865 | + {
| |
| 866 | + return id; | |
| 867 | + } | |
| 868 | +} | |
| 869 | diff --git a/java/Dev/Instance/InstanceIdFactory.java b/java/Dev/Instance/InstanceIdFactory.java | |
| 870 | new file mode 100644 | |
| 871 | index 0000000..14f4e23 | |
| 872 | --- /dev/null | |
| 873 | +++ b/java/Dev/Instance/InstanceIdFactory.java | |
| 874 | @@ -0,0 +1,13 @@ | |
| 875 | +package Dev.Instance; | |
| 876 | + | |
| 877 | +import java.util.concurrent.atomic.AtomicInteger; | |
| 878 | + | |
| 879 | +public final class InstanceIdFactory | |
| 880 | +{
| |
| 881 | + private static AtomicInteger nextAvailable = new AtomicInteger(1); | |
| 882 | + | |
| 883 | + public synchronized static int getNextAvailable() | |
| 884 | + {
| |
| 885 | + return nextAvailable.getAndIncrement(); | |
| 886 | + } | |
| 887 | +} | |
| 888 | diff --git a/java/Dev/Instance/InstanceManager.java b/java/Dev/Instance/InstanceManager.java | |
| 889 | new file mode 100644 | |
| 890 | index 0000000..42d4f25 | |
| 891 | --- /dev/null | |
| 892 | +++ b/java/Dev/Instance/InstanceManager.java | |
| 893 | @@ -0,0 +1,59 @@ | |
| 894 | +package Dev.Instance; | |
| 895 | + | |
| 896 | +import java.util.Map; | |
| 897 | +import java.util.concurrent.ConcurrentHashMap; | |
| 898 | + | |
| 899 | +import net.sf.l2j.gameserver.model.actor.instance.Door; | |
| 900 | + | |
| 901 | + | |
| 902 | +public class InstanceManager | |
| 903 | +{
| |
| 904 | + private Map<Integer, Instance> instances; | |
| 905 | + | |
| 906 | + protected InstanceManager() | |
| 907 | + {
| |
| 908 | + instances = new ConcurrentHashMap<>(); | |
| 909 | + instances.put(0, new Instance(0)); | |
| 910 | + } | |
| 911 | + | |
| 912 | + public void addDoor(int id, Door door) | |
| 913 | + {
| |
| 914 | + if (!instances.containsKey(id) || id == 0) | |
| 915 | + return; | |
| 916 | + | |
| 917 | + instances.get(id).addDoor(door); | |
| 918 | + } | |
| 919 | + | |
| 920 | + public void deleteInstance(int id) | |
| 921 | + {
| |
| 922 | + if (id == 0) | |
| 923 | + {
| |
| 924 | + System.out.println("Attempt to delete instance with id 0.");
| |
| 925 | + return; | |
| 926 | + } | |
| 927 | + | |
| 928 | + // delete doors | |
| 929 | + } | |
| 930 | + | |
| 931 | + public synchronized Instance createInstance() | |
| 932 | + {
| |
| 933 | + Instance instance = new Instance(InstanceIdFactory.getNextAvailable()); | |
| 934 | + instances.put(instance.getId(), instance); | |
| 935 | + return instance; | |
| 936 | + } | |
| 937 | + | |
| 938 | + public Instance getInstance(int id) | |
| 939 | + {
| |
| 940 | + return instances.get(id); | |
| 941 | + } | |
| 942 | + | |
| 943 | + public static InstanceManager getInstance() | |
| 944 | + {
| |
| 945 | + return SingletonHolder.instance; | |
| 946 | + } | |
| 947 | + | |
| 948 | + private static final class SingletonHolder | |
| 949 | + {
| |
| 950 | + protected static final InstanceManager instance = new InstanceManager(); | |
| 951 | + } | |
| 952 | +} | |
| 953 | diff --git a/java/net/sf/l2j/Config.java b/java/net/sf/l2j/Config.java | |
| 954 | index 742fe1a..07efedc 100644 | |
| 955 | --- a/java/net/sf/l2j/Config.java | |
| 956 | +++ b/java/net/sf/l2j/Config.java | |
| 957 | @@ -50,6 +50,7 @@ | |
| 958 | public static final String ENCHANTCONFIG = "./config/Custom/Enchant.properties"; | |
| 959 | public static final String SKIN_FILE = "./config/Custom/Skin.properties"; | |
| 960 | public static final String DONATE_FILE = "./config/Custom/Donate.properties"; | |
| 961 | + public static final String AUTO_FARM = "./config/Custom/AutoFarm.properties"; | |
| 962 | public static final String COMMANDS_FILE = "./config/Custom/Commands.properties"; | |
| 963 | public static final String LASTHITBOSS = "./config/Custom/Events/LastHitBossEvent.properties"; | |
| 964 | public static final String CHAMPION_EVENT = "./config/Custom/Events/ChampionEvent.properties"; | |
| 965 | @@ -781,6 +782,11 @@ | |
| 966 | public static int SKIN_GLOVES_RMAGICIAN; | |
| 967 | public static int SKIN_LEGS_RMAGICIAN; | |
| 968 | ||
| 969 | + | |
| 970 | + /** Auto Farm Variaveis */ | |
| 971 | + public static Integer AUTO_FARM_BAR; | |
| 972 | + public static int AUTO_FARM_RADIUS; | |
| 973 | + | |
| 974 | /** Donate Settings */ | |
| 975 | public static boolean ALLOW_VIP_NCOLOR; | |
| 976 | public static int VIP_NCOLOR; | |
| 977 | @@ -1794,6 +1800,15 @@ | |
| 978 | ||
| 979 | } | |
| 980 | ||
| 981 | + /** | |
| 982 | + * Loads AutoFarm Settings.<br> | |
| 983 | + */ | |
| 984 | + private static final void loadAutoFarm() | |
| 985 | + {
| |
| 986 | + final ExProperties farm = initProperties(AUTO_FARM); | |
| 987 | + AUTO_FARM_RADIUS = farm.getProperty("AutoFarmRadius", 600);
| |
| 988 | + AUTO_FARM_BAR = farm.getProperty("AutoFarmBar", 0);
| |
| 989 | + } | |
| 990 | ||
| 991 | /** | |
| 992 | * Loads Donate Settings.<br> | |
| 993 | @@ -3222,6 +3237,9 @@ | |
| 994 | // Donate Settings | |
| 995 | loadDonate(); | |
| 996 | ||
| 997 | + // Auto Farm Settings | |
| 998 | + loadAutoFarm(); | |
| 999 | + | |
| 1000 | // Commands Settings | |
| 1001 | loadCommands(); | |
| 1002 | ||
| 1003 | diff --git a/java/net/sf/l2j/gameserver/GameServer.java b/java/net/sf/l2j/gameserver/GameServer.java | |
| 1004 | index 64d9bc4..21815ed 100644 | |
| 1005 | --- a/java/net/sf/l2j/gameserver/GameServer.java | |
| 1006 | +++ b/java/net/sf/l2j/gameserver/GameServer.java | |
| 1007 | @@ -120,6 +120,7 @@ | |
| 1008 | import Dev.Events.PartyFarm.InitialPartyFarm; | |
| 1009 | import Dev.Events.PartyFarm.PartyFarm; | |
| 1010 | import Dev.Events.PartyFarm.PartyZoneReward; | |
| 1011 | +import Dev.Instance.InstanceManager; | |
| 1012 | import Dev.SpecialMods.RaidBossInfoManager; | |
| 1013 | ||
| 1014 | public class GameServer | |
| 1015 | @@ -249,6 +250,9 @@ | |
| 1016 | SkillTable.getInstance(); | |
| 1017 | SkillTreeData.getInstance(); | |
| 1018 | ||
| 1019 | + StringUtil.printSection("Instance Manager");
| |
| 1020 | + InstanceManager.getInstance(); | |
| 1021 | + | |
| 1022 | StringUtil.printSection("Items");
| |
| 1023 | ItemTable.getInstance(); | |
| 1024 | SummonItemData.getInstance(); | |
| 1025 | diff --git a/java/net/sf/l2j/gameserver/handler/AdminCommandHandler.java b/java/net/sf/l2j/gameserver/handler/AdminCommandHandler.java | |
| 1026 | index 27d69c1..6076be5 100644 | |
| 1027 | --- a/java/net/sf/l2j/gameserver/handler/AdminCommandHandler.java | |
| 1028 | +++ b/java/net/sf/l2j/gameserver/handler/AdminCommandHandler.java | |
| 1029 | @@ -26,6 +26,7 @@ | |
| 1030 | import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminGmChat; | |
| 1031 | import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminHeal; | |
| 1032 | import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminHelpPage; | |
| 1033 | +import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminInstance; | |
| 1034 | import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminInvul; | |
| 1035 | import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminKick; | |
| 1036 | import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminKnownlist; | |
| 1037 | @@ -63,6 +64,7 @@ | |
| 1038 | ||
| 1039 | protected AdminCommandHandler() | |
| 1040 | {
| |
| 1041 | + registerAdminCommandHandler(new AdminInstance()); | |
| 1042 | registerAdminCommandHandler(new AdminCTFEngine()); | |
| 1043 | registerAdminCommandHandler(new AdminTvTEngine()); | |
| 1044 | registerAdminCommandHandler(new AdminCrazyRates()); | |
| 1045 | diff --git a/java/net/sf/l2j/gameserver/handler/VoicedCommandHandler.java b/java/net/sf/l2j/gameserver/handler/VoicedCommandHandler.java | |
| 1046 | index 642b176..75a928c 100644 | |
| 1047 | --- a/java/net/sf/l2j/gameserver/handler/VoicedCommandHandler.java | |
| 1048 | +++ b/java/net/sf/l2j/gameserver/handler/VoicedCommandHandler.java | |
| 1049 | @@ -16,6 +16,8 @@ | |
| 1050 | import net.sf.l2j.gameserver.handler.voicedcommandhandlers.VoicedRanking; | |
| 1051 | import net.sf.l2j.gameserver.handler.voicedcommandhandlers.VoicedVipFree; | |
| 1052 | ||
| 1053 | +import Dev.AutoFarm.AutofarmCommand; | |
| 1054 | + | |
| 1055 | public class VoicedCommandHandler | |
| 1056 | {
| |
| 1057 | private final Map<Integer, IVoicedCommandHandler> _datatable = new HashMap<>(); | |
| 1058 | @@ -27,6 +29,7 @@ | |
| 1059 | ||
| 1060 | protected VoicedCommandHandler() | |
| 1061 | {
| |
| 1062 | + registerHandler(new AutofarmCommand()); | |
| 1063 | registerHandler(new EventCMD()); | |
| 1064 | // coloque aqui os comandos | |
| 1065 | if(Config.ENABLE_VOICED_DONATE) | |
| 1066 | diff --git a/java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminInstance.java b/java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminInstance.java | |
| 1067 | new file mode 100644 | |
| 1068 | index 0000000..8c9fe50 | |
| 1069 | --- /dev/null | |
| 1070 | +++ b/java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminInstance.java | |
| 1071 | @@ -0,0 +1,72 @@ | |
| 1072 | +package net.sf.l2j.gameserver.handler.admincommandhandlers; | |
| 1073 | + | |
| 1074 | +import java.util.StringTokenizer; | |
| 1075 | + | |
| 1076 | +import net.sf.l2j.gameserver.handler.IAdminCommandHandler; | |
| 1077 | +import net.sf.l2j.gameserver.model.World; | |
| 1078 | +import net.sf.l2j.gameserver.model.actor.instance.Player; | |
| 1079 | + | |
| 1080 | +import Dev.Instance.InstanceManager; | |
| 1081 | + | |
| 1082 | +public class AdminInstance implements IAdminCommandHandler {
| |
| 1083 | + | |
| 1084 | + @Override | |
| 1085 | + public boolean useAdminCommand(String command, Player activeChar) {
| |
| 1086 | + if (command.startsWith("admin_resetmyinstance"))
| |
| 1087 | + {
| |
| 1088 | + activeChar.setInstance(InstanceManager.getInstance().getInstance(0), false); | |
| 1089 | + activeChar.sendMessage("Your instance is now default");
| |
| 1090 | + } | |
| 1091 | + else if (command.startsWith("admin_instanceid"))
| |
| 1092 | + {
| |
| 1093 | + StringTokenizer st = new StringTokenizer(command, " "); | |
| 1094 | + st.nextToken(); // skip command | |
| 1095 | + | |
| 1096 | + if(!st.hasMoreTokens()) | |
| 1097 | + {
| |
| 1098 | + activeChar.sendMessage("Write the name.");
| |
| 1099 | + return false; | |
| 1100 | + } | |
| 1101 | + | |
| 1102 | + String target_name = st.nextToken(); | |
| 1103 | + Player player = World.getInstance().getPlayer(target_name); | |
| 1104 | + if(player == null) | |
| 1105 | + {
| |
| 1106 | + activeChar.sendMessage("Player is offline");
| |
| 1107 | + return false; | |
| 1108 | + } | |
| 1109 | + | |
| 1110 | + activeChar.sendMessage(""+target_name+ " instance id: " + player.getInstance().getId());
| |
| 1111 | + } | |
| 1112 | + else if (command.startsWith("admin_getinstance"))
| |
| 1113 | + {
| |
| 1114 | + StringTokenizer st = new StringTokenizer(command, " "); | |
| 1115 | + st.nextToken(); // skip command | |
| 1116 | + | |
| 1117 | + if(!st.hasMoreTokens()) | |
| 1118 | + {
| |
| 1119 | + activeChar.sendMessage("Write the name.");
| |
| 1120 | + return false; | |
| 1121 | + } | |
| 1122 | + | |
| 1123 | + String target_name = st.nextToken(); | |
| 1124 | + Player player = World.getInstance().getPlayer(target_name); | |
| 1125 | + if(player == null) | |
| 1126 | + {
| |
| 1127 | + activeChar.sendMessage("Player is offline");
| |
| 1128 | + return false; | |
| 1129 | + } | |
| 1130 | + | |
| 1131 | + activeChar.setInstance(player.getInstance(), false); | |
| 1132 | + activeChar.sendMessage("You are with the same instance of player "+target_name);
| |
| 1133 | + } | |
| 1134 | + return false; | |
| 1135 | + } | |
| 1136 | + | |
| 1137 | + @Override | |
| 1138 | + public String[] getAdminCommandList() {
| |
| 1139 | + | |
| 1140 | + return new String [] {"admin_resetmyinstance","admin_getinstance","admin_instanceid"};
| |
| 1141 | + } | |
| 1142 | + | |
| 1143 | +} | |
| 1144 | diff --git a/java/net/sf/l2j/gameserver/handler/voicedcommandhandlers/VoicedMenu.java b/java/net/sf/l2j/gameserver/handler/voicedcommandhandlers/VoicedMenu.java | |
| 1145 | index b853fcc..964f0e7 100644 | |
| 1146 | --- a/java/net/sf/l2j/gameserver/handler/voicedcommandhandlers/VoicedMenu.java | |
| 1147 | +++ b/java/net/sf/l2j/gameserver/handler/voicedcommandhandlers/VoicedMenu.java | |
| 1148 | @@ -30,6 +30,8 @@ | |
| 1149 | import net.sf.l2j.gameserver.network.serverpackets.ExShowScreenMessage; | |
| 1150 | import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage; | |
| 1151 | ||
| 1152 | +import Dev.AutoFarm.AutofarmManager; | |
| 1153 | + | |
| 1154 | public class VoicedMenu implements IVoicedCommandHandler | |
| 1155 | {
| |
| 1156 | private static final String[] VOICED_COMMANDS = | |
| 1157 | @@ -70,6 +72,14 @@ | |
| 1158 | else if (command.equals("info_pt"))
| |
| 1159 | showInfoPtHtml(activeChar); | |
| 1160 | ||
| 1161 | + else if (command.equals("vip"))
| |
| 1162 | + {
| |
| 1163 | + if (activeChar.isVip()) | |
| 1164 | + sendVipWindow(activeChar); | |
| 1165 | + else if(!activeChar.isVip()) | |
| 1166 | + activeChar.sendMessage("You are not VIP member.");
| |
| 1167 | + } | |
| 1168 | + | |
| 1169 | else if (command.equals("info_sp"))
| |
| 1170 | showInfoSpHtml(activeChar); | |
| 1171 | else if (command.equals("setxpnot"))
| |
| 1172 | @@ -1433,7 +1443,16 @@ | |
| 1173 | html.replace("%pet_food_rate%", String.valueOf(Config.PET_FOOD_RATE));
| |
| 1174 | activeChar.sendPacket(html); | |
| 1175 | } | |
| 1176 | - | |
| 1177 | + public static void sendVipWindow(Player activeChar) | |
| 1178 | + { String autofarmOn= "<button width=38 height=38 back=\"L2UI_NewTex.AutomaticPlay.CombatBTNOff_Over\" fore=\"L2UI_NewTex.AutomaticPlay.CombatBTNON_Normal\" action=\"bypass voiced_farm\" value=\"\">";
| |
| 1179 | + String autofarmOff= "<button width=38 height=38 back=\"L2UI_NewTex.AutomaticPlay.CombatBTNON_Over\" fore=\"L2UI_NewTex.AutomaticPlay.CombatBTNOff_Normal\" action=\"bypass voiced_farm\" value=\"\">"; | |
| 1180 | + | |
| 1181 | + NpcHtmlMessage html = new NpcHtmlMessage(0); | |
| 1182 | + html.setFile("data/html/mods/menu/AutoFarm.htm");
| |
| 1183 | + html.replace("%AutoFarmActived%", AutofarmManager.INSTANCE.isAutofarming(activeChar) ? "<img src=\"panel.online\" width=\"16\" height=\"16\">" : "<img src=\"panel.offline\" width=\"16\" height=\"16\">");
| |
| 1184 | + html.replace("%autoFarmButton%", AutofarmManager.INSTANCE.isAutofarming(activeChar) ? autofarmOn : autofarmOff);
| |
| 1185 | + activeChar.sendPacket(html); | |
| 1186 | + } | |
| 1187 | private static void showInfoSpHtml(Player activeChar) | |
| 1188 | {
| |
| 1189 | NpcHtmlMessage html = new NpcHtmlMessage(0); | |
| 1190 | diff --git a/java/net/sf/l2j/gameserver/model/WorldObject.java b/java/net/sf/l2j/gameserver/model/WorldObject.java | |
| 1191 | index 70ba6c6..4a698d3 100644 | |
| 1192 | --- a/java/net/sf/l2j/gameserver/model/WorldObject.java | |
| 1193 | +++ b/java/net/sf/l2j/gameserver/model/WorldObject.java | |
| 1194 | @@ -19,6 +19,9 @@ | |
| 1195 | import net.sf.l2j.gameserver.model.zone.ZoneId; | |
| 1196 | import net.sf.l2j.gameserver.network.serverpackets.ActionFailed; | |
| 1197 | ||
| 1198 | +import Dev.Instance.Instance; | |
| 1199 | +import Dev.Instance.InstanceManager; | |
| 1200 | + | |
| 1201 | /** | |
| 1202 | * Mother class of all interactive objects in the world (PC, NPC, Item...) | |
| 1203 | */ | |
| 1204 | @@ -442,7 +445,24 @@ | |
| 1205 | ||
| 1206 | return result; | |
| 1207 | } | |
| 1208 | + /** instance system */ | |
| 1209 | + private Instance _instance = InstanceManager.getInstance().getInstance(0); | |
| 1210 | ||
| 1211 | + public void setInstance(Instance instance, boolean silent) | |
| 1212 | + {
| |
| 1213 | + _instance = instance; | |
| 1214 | + | |
| 1215 | + if(!silent) | |
| 1216 | + {
| |
| 1217 | + decayMe(); | |
| 1218 | + spawnMe(); | |
| 1219 | + } | |
| 1220 | + } | |
| 1221 | + | |
| 1222 | + public Instance getInstance() | |
| 1223 | + {
| |
| 1224 | + return _instance; | |
| 1225 | + } | |
| 1226 | /** | |
| 1227 | * Return the known list of given object type within specified radius. | |
| 1228 | * @param <A> : Object type must be instance of {@link WorldObject}.
| |
| 1229 | ||
| 1230 | result.add((A) obj); | |
| 1231 | diff --git a/java/net/sf/l2j/gameserver/model/actor/Attackable.java b/java/net/sf/l2j/gameserver/model/actor/Attackable.java | |
| 1232 | index 368fe2d..8f9e154 100644 | |
| 1233 | --- a/java/net/sf/l2j/gameserver/model/actor/Attackable.java | |
| 1234 | +++ b/java/net/sf/l2j/gameserver/model/actor/Attackable.java | |
| 1235 | @@ -1274,6 +1274,7 @@ | |
| 1236 | {
| |
| 1237 | // Init the dropped ItemInstance and add it in the world as a visible object at the position where mob was last | |
| 1238 | item = ItemTable.getInstance().createItem("Loot", holder.getId(), holder.getValue(), mainDamageDealer, this);
| |
| 1239 | + item.setInstance(getInstance(), false); | |
| 1240 | item.dropMe(this, getX() + Rnd.get(-70, 70), getY() + Rnd.get(-70, 70), Math.max(getZ(), mainDamageDealer.getZ()) + 20); | |
| 1241 | ||
| 1242 | // If stackable, end loop as entire count is included in 1 instance of item | |
| 1243 | diff --git a/java/net/sf/l2j/gameserver/model/actor/Summon.java b/java/net/sf/l2j/gameserver/model/actor/Summon.java | |
| 1244 | index 9c37a1e..5aa110b 100644 | |
| 1245 | --- a/java/net/sf/l2j/gameserver/model/actor/Summon.java | |
| 1246 | +++ b/java/net/sf/l2j/gameserver/model/actor/Summon.java | |
| 1247 | @@ -55,7 +55,7 @@ | |
| 1248 | public Summon(int objectId, NpcTemplate template, Player owner) | |
| 1249 | {
| |
| 1250 | super(objectId, template); | |
| 1251 | - | |
| 1252 | + setInstance(owner.getInstance(), true); | |
| 1253 | for (L2Skill skill : template.getSkills(SkillType.PASSIVE)) | |
| 1254 | addStatFuncs(skill.getStatFuncs(this)); | |
| 1255 | ||
| 1256 | diff --git a/java/net/sf/l2j/gameserver/model/actor/instance/Player.java b/java/net/sf/l2j/gameserver/model/actor/instance/Player.java | |
| 1257 | index ebd8bb6..a83a7ea 100644 | |
| 1258 | --- a/java/net/sf/l2j/gameserver/model/actor/instance/Player.java | |
| 1259 | +++ b/java/net/sf/l2j/gameserver/model/actor/instance/Player.java | |
| 1260 | @@ -2633,7 +2633,7 @@ | |
| 1261 | ||
| 1262 | return false; | |
| 1263 | } | |
| 1264 | + item.setInstance(getInstance(), true); // True because Drop me will spawn it | |
| 1265 | item.dropMe(this, getX() + Rnd.get(-25, 25), getY() + Rnd.get(-25, 25), getZ() + 20); | |
| 1266 | ||
| 1267 | // Send inventory update packet | |
| 1268 | @@ -2865,7 +2865,7 @@ | |
| 1269 | } | |
| 1270 | ||
| 1271 | @Override | |
| 1272 | - protected boolean checkDoCastConditions(L2Skill skill) | |
| 1273 | + public boolean checkDoCastConditions(L2Skill skill) | |
| 1274 | {
| |
| 1275 | if (!super.checkDoCastConditions(skill)) | |
| 1276 | return false; | |
| 1277 | diff --git a/java/net/sf/l2j/gameserver/skills/l2skills/L2SkillSummon.java b/java/net/sf/l2j/gameserver/skills/l2skills/L2SkillSummon.java | |
| 1278 | index d06f799..3a090c1 100644 | |
| 1279 | --- a/java/net/sf/l2j/gameserver/skills/l2skills/L2SkillSummon.java | |
| 1280 | +++ b/java/net/sf/l2j/gameserver/skills/l2skills/L2SkillSummon.java | |
| 1281 | @@ -213,6 +213,7 @@ | |
| 1282 | summon.setCurrentHp(summon.getMaxHp()); | |
| 1283 | summon.setCurrentMp(summon.getMaxMp()); | |
| 1284 | summon.setHeading(activeChar.getHeading()); | |
| 1285 | + summon.setInstance(activeChar.getInstance(), true); | |
| 1286 | summon.setRunning(); | |
| 1287 | activeChar.setPet(summon); | |
| 1288 | ||
| 1289 | ||
| 1290 | ||
| 1291 | HTML Auto Farm | |
| 1292 | ||
| 1293 | <html imgsrc="Ressurge.bkg"><title>L2jserver - VIP</title><body><center> | |
| 1294 | <center> | |
| 1295 | <br> | |
| 1296 | <table width=250> | |
| 1297 | <tr> | |
| 1298 | ||
| 1299 | <td width=20><font color="00FF00"> ACESSO VIP EXCLUSIVO</font></td> | |
| 1300 | ||
| 1301 | </tr> | |
| 1302 | </table> | |
| 1303 | </center> | |
| 1304 | <br> | |
| 1305 | <img src="L2UI.SquareBlank" width=300 height=1> | |
| 1306 | <table width=305 bgcolor="000000"> | |
| 1307 | <tr> | |
| 1308 | <td><center><font color="LEVEL"> Buscamos entregar o melhor Lineage II Player Solo</font></center></td></tr><br1> | |
| 1309 | </table> | |
| 1310 | <br> | |
| 1311 | <center><table align=center> | |
| 1312 | <tr> | |
| 1313 | ||
| 1314 | <td><button value="SKINS ACTIVED" action="bypass voiced_skins" width=120 height=21 back="lineagenppc.y120" fore="lineagenppc.y120" over="lineagenppc.y120"></td> | |
| 1315 | ||
| 1316 | </tr> | |
| 1317 | </table></center> | |
| 1318 | <center><table align=center> | |
| 1319 | <tr> | |
| 1320 | ||
| 1321 | <td><button value="CONSUMABLES VIP" action="bypass voiced_multisell consumables-vip-custom" width=120 height=21 back="lineagenppc.g120" fore="lineagenppc.g120" over="lineagenppc.g120"></td> | |
| 1322 | ||
| 1323 | </tr> | |
| 1324 | </table></center><br> | |
| 1325 | <table width=130> | |
| 1326 | <tr> | |
| 1327 | <td width=20><img src="l2UI_Valhalla_3.24Hz_DF_ChannelControlBtn_Next" width=18 height=18></td> | |
| 1328 | <td width=20><font color="FF0000"> Auto Farm </font></td> | |
| 1329 | <td width=20><img src="l2UI_Valhalla_3.24Hz_DF_ChannelControlBtn_Pre" width=18 height=18></td> | |
| 1330 | </tr> | |
| 1331 | </table> | |
| 1332 | <br><br><br><br><br><br> | |
| 1333 | <table cellspacing=-39 cellpadding=0> | |
| 1334 | <tr> <!-- Botão Back --> | |
| 1335 | <td align=center> | |
| 1336 | <img src="L2UI_NewTex.AutomaticPlay.AutoPlaySlotON_BG_Over" width=97 height=95> | |
| 1337 | </td> | |
| 1338 | </tr> | |
| 1339 | </table> | |
| 1340 | <table cellspacing=-38 cellpadding=2> | |
| 1341 | <tr> <!-- Botão Back --> | |
| 1342 | <td align=center> | |
| 1343 | <button width=61 height=62 back="L2UI_NewTex.AutomaticPlay.AutoPlaySlotIconTarget" fore="L2UI_NewTex.AutomaticPlay.AutoPlaySlotIconTargetON" action="bypass voiced_farm" value=""> | |
| 1344 | </td> | |
| 1345 | </tr> | |
| 1346 | </table> | |
| 1347 | <table cellspacing=-42 cellpadding=0> | |
| 1348 | <tr> <!-- Botão Back --> | |
| 1349 | <td align=center> | |
| 1350 | <button width=85 height=70 back="L2UI_NewTex.AutomaticPlay.AutoPlayONAni_001" fore="L2UI_NewTex.AutomaticPlay.AutoPlayONAni_001" action="" value=""> | |
| 1351 | </td> | |
| 1352 | </tr> | |
| 1353 | </table> | |
| 1354 | <table cellspacing=-36 cellpadding=-23> | |
| 1355 | <tr> <!-- Botão Back --> | |
| 1356 | <td align=center> | |
| 1357 | <img src="L2UI_NewTex.AutomaticPlay.AutoCircleFrame" width=120 height=128> | |
| 1358 | </td> | |
| 1359 | </tr> | |
| 1360 | </table> | |
| 1361 | <br> | |
| 1362 | <br> | |
| 1363 | <br> | |
| 1364 | <img src="L2UI.SquareBlank" width=300 height=2> | |
| 1365 | <table width=21 cellspacing=0 cellpadding=-25> | |
| 1366 | <tr> <!-- Botão Back --> | |
| 1367 | <td align=right> | |
| 1368 | <font color="LEVEL">%AutoFarmActived%</font> | |
| 1369 | </td> | |
| 1370 | </tr> | |
| 1371 | </table> | |
| 1372 | ||
| 1373 | ||
| 1374 | ||
| 1375 | <br><br> | |
| 1376 | ||
| 1377 | ||
| 1378 | ||
| 1379 | ||
| 1380 | ||
| 1381 | ||
| 1382 | <br><br><br><br> | |
| 1383 | <tr> | |
| 1384 | <td><button value="Voltar" action="bypass voiced_menu" width=75 height=22 back="L2UI_CH3.Btn1_normalDisable" fore="L2UI_CH3.Btn1_normal" over="L2UI_CH3.Btn1_normal_over"></td> | |
| 1385 | </tr> | |
| 1386 | ||
| 1387 | ||
| 1388 | ||
| 1389 | ||
| 1390 | ||
| 1391 | ||
| 1392 | ||
| 1393 | ||
| 1394 | ||
| 1395 | ||
| 1396 | ||
| 1397 | ||
| 1398 | </body></html> | |
| 1399 |