From e818a7e9041306e67dc3603251e025b95993eacf Mon Sep 17 00:00:00 2001 From: dginovker Date: Sat, 21 Mar 2020 17:15:51 -0400 Subject: [PATCH] Manual merge of Ethan's work --- .../game/node/entity/player/ai/AIPlayer.java | 923 +++++++++--------- .../quest/witchs_house/NoraTHaggNPC.java | 23 +- 2 files changed, 460 insertions(+), 486 deletions(-) diff --git a/Server/src/org/crandor/game/node/entity/player/ai/AIPlayer.java b/Server/src/org/crandor/game/node/entity/player/ai/AIPlayer.java index 53cd758dd..893f6dbb0 100644 --- a/Server/src/org/crandor/game/node/entity/player/ai/AIPlayer.java +++ b/Server/src/org/crandor/game/node/entity/player/ai/AIPlayer.java @@ -31,540 +31,521 @@ import org.crandor.tools.StringUtils; /** * Represents an Artificial Intelligent Player. + * * @author Emperor */ public class AIPlayer extends Player { - /** - * The current UID. - */ - private static int currentUID = 0x1; + /** + * The current UID. + */ + private static int currentUID = 0x1; - /** - * The active Artificial intelligent players mapping. - */ - private static final Map botMapping = new HashMap<>(); + /** + * The active Artificial intelligent players mapping. + */ + private static final Map botMapping = new HashMap<>(); - /** - * The aip control dialogue. - */ - private static final AIPControlDialogue CONTROL_DIAL = new AIPControlDialogue(); + /** + * The aip control dialogue. + */ + private static final AIPControlDialogue CONTROL_DIAL = new AIPControlDialogue(); - /** - * A line of data from namesandarmor.txt that will be used to generate the appearance - * Data in format: - * //name:cblevel:helmet:cape:neck:weapon:chest:shield:unknown:legs:unknown:gloves:boots: - */ - private static String OSRScopyLine; + /** + * A line of data from namesandarmor.txt that will be used to generate the appearance + * Data in format: + * //name:cblevel:helmet:cape:neck:weapon:chest:shield:unknown:legs:unknown:gloves:boots: + */ + private static String OSRScopyLine; - /** - * The AIP's UID. - */ - private final int uid; + /** + * The AIP's UID. + */ + private final int uid; - /** - * The start location of the AIP. - */ - private final Location startLocation; + /** + * The start location of the AIP. + */ + private final Location startLocation; - /** - * The username. - */ - private String username; + /** + * The username. + */ + private String username; - /** - * The player controlling this AIP. - */ - private Player controler; + /** + * The player controlling this AIP. + */ + private Player controler; - /** - * Constructs a new {@code AIPlayer} {@code Object}. - * - * @param l The location. - */ - public AIPlayer(Location l) { - this(retrieveRandomName(), l, null); - } + /** + * Constructs a new {@code AIPlayer} {@code Object}. + * + * @param l The location. + */ + public AIPlayer(Location l) { + this(retrieveRandomName(), l, null); + } - public AIPlayer(String fileName, Location l) { - this(retrieveRandomName(fileName), l, null); - } + public AIPlayer(String fileName, Location l) { + this(retrieveRandomName(fileName), l, null); + } - @SuppressWarnings("deprecation") - private AIPlayer(String name, Location l, String ignored) { - super(new PlayerDetails("/aip" + (currentUID + 1) + ":" + name)); - super.setLocation(startLocation = l); - super.artificial = true; - super.getDetails().setSession(ArtificialSession.getSingleton()); - Repository.getPlayers().add(this); - this.username = StringUtils.formatDisplayName(name + (currentUID + 1)); - this.uid = currentUID++; - this.updateRandomValues(); - this.init(); - } + @SuppressWarnings("deprecation") + private AIPlayer(String name, Location l, String ignored) { + super(new PlayerDetails("/aip" + (currentUID + 1) + ":" + name)); + super.setLocation(startLocation = l); + super.artificial = true; + super.getDetails().setSession(ArtificialSession.getSingleton()); + Repository.getPlayers().add(this); + this.username = StringUtils.formatDisplayName(name + (currentUID + 1)); + this.uid = currentUID++; + this.updateRandomValues(); + this.init(); + } - /** - * Generates bot stats/equipment/etc based on OSRScopyLine - */ - public void updateRandomValues() { - this.getAppearance().setGender(RandomFunction.random(5) == 1 ? Gender.FEMALE : Gender.MALE); + /** + * Generates bot stats/equipment/etc based on OSRScopyLine + */ + public void updateRandomValues() { + this.getAppearance().setGender(RandomFunction.random(5) == 1 ? Gender.FEMALE : Gender.MALE); - setLevels(); - giveArmor(); + setLevels(); + giveArmor(); - this.setDirection(Direction.values()[new Random().nextInt(Direction.values().length)]); //Random facing dir - this.getSkills().updateCombatLevel(); - this.getAppearance().sync(); - } + this.setDirection(Direction.values()[new Random().nextInt(Direction.values().length)]); //Random facing dir + this.getSkills().updateCombatLevel(); + this.getAppearance().sync(); + } - private void setLevels() { - //Create realistic player stats - int maxLevel = RandomFunction.random(1, Math.min(parseOSRS(1), 99)); - for (int i = 0; i < Skills.NUM_SKILLS; i++) { - this.getSkills().setStaticLevel(i, RandomFunction.linearDecreaseRand(maxLevel)); - } - int combatLevelsLeft = parseOSRS(1); - int hitpoints = Math.max(RandomFunction.random(10, Math.min(maxLevel, combatLevelsLeft*4)), 10); - combatLevelsLeft -= 0.25*hitpoints; - int prayer = combatLevelsLeft > 0 ? RandomFunction.random(Math.min(maxLevel, combatLevelsLeft*8)) : 1; - combatLevelsLeft -= 0.125*prayer; - int defence = combatLevelsLeft > 0 ? RandomFunction.random(Math.min(maxLevel, combatLevelsLeft*4)) : 1; - combatLevelsLeft -= 0.25*defence; + private void setLevels() { + //Create realistic player stats + int maxLevel = RandomFunction.random(1, Math.min(parseOSRS(1), 99)); + for (int i = 0; i < Skills.NUM_SKILLS; i++) { + this.getSkills().setStaticLevel(i, RandomFunction.linearDecreaseRand(maxLevel)); + } + int combatLevelsLeft = parseOSRS(1); + int hitpoints = Math.max(RandomFunction.random(10, Math.min(maxLevel, combatLevelsLeft * 4)), 10); + combatLevelsLeft -= 0.25 * hitpoints; + int prayer = combatLevelsLeft > 0 ? RandomFunction.random(Math.min(maxLevel, combatLevelsLeft * 8)) : 1; + combatLevelsLeft -= 0.125 * prayer; + int defence = combatLevelsLeft > 0 ? RandomFunction.random(Math.min(maxLevel, combatLevelsLeft * 4)) : 1; + combatLevelsLeft -= 0.25 * defence; - combatLevelsLeft = Math.min(combatLevelsLeft, 199); + combatLevelsLeft = Math.min(combatLevelsLeft, 199); - int attack = combatLevelsLeft > 0 ? RandomFunction.normalRandDist(Math.min(maxLevel, combatLevelsLeft*3)) : 1; - int strength = combatLevelsLeft > 0 ? combatLevelsLeft*3 - attack : 1; + int attack = combatLevelsLeft > 0 ? RandomFunction.normalRandDist(Math.min(maxLevel, combatLevelsLeft * 3)) : 1; + int strength = combatLevelsLeft > 0 ? combatLevelsLeft * 3 - attack : 1; - this.getSkills().setStaticLevel(Skills.HITPOINTS, hitpoints); - this.getSkills().setStaticLevel(Skills.PRAYER, prayer); - this.getSkills().setStaticLevel(Skills.DEFENCE, defence); - this.getSkills().setStaticLevel(Skills.ATTACK, attack); - this.getSkills().setStaticLevel(Skills.STRENGTH, strength); - this.getSkills().setStaticLevel(Skills.RANGE, combatLevelsLeft/2); - this.getSkills().setStaticLevel(Skills.MAGIC, combatLevelsLeft/2); - } + this.getSkills().setStaticLevel(Skills.HITPOINTS, hitpoints); + this.getSkills().setStaticLevel(Skills.PRAYER, prayer); + this.getSkills().setStaticLevel(Skills.DEFENCE, defence); + this.getSkills().setStaticLevel(Skills.ATTACK, attack); + this.getSkills().setStaticLevel(Skills.STRENGTH, strength); + this.getSkills().setStaticLevel(Skills.RANGE, combatLevelsLeft / 2); + this.getSkills().setStaticLevel(Skills.MAGIC, combatLevelsLeft / 2); + } - private void giveArmor() { - //name:cblevel:helmet2:cape3:neck4:weapon5:chest6:shield7:unknown8:legs9:unknown10:gloves11:boots12: - //sicriona:103:1163: 1023: 1725 :1333: 1127 :1201 :0: 1079 :0: 2922: 1061:0: - equipIfExists(new Item(parseOSRS(2)), EquipmentContainer.SLOT_HAT); - equipIfExists(new Item(parseOSRS(3)), EquipmentContainer.SLOT_CAPE); - equipIfExists(new Item(parseOSRS(4)), EquipmentContainer.SLOT_AMULET); - equipIfExists(new Item(parseOSRS(5)), EquipmentContainer.SLOT_WEAPON); - equipIfExists(new Item(parseOSRS(6)), EquipmentContainer.SLOT_CHEST); - equipIfExists(new Item(parseOSRS(7)), EquipmentContainer.SLOT_SHIELD); - equipIfExists(new Item(parseOSRS(9)), EquipmentContainer.SLOT_LEGS); - equipIfExists(new Item(parseOSRS(11)), EquipmentContainer.SLOT_HANDS); - equipIfExists(new Item(parseOSRS(12)), EquipmentContainer.SLOT_FEET); - } + private void giveArmor() { + //name:cblevel:helmet2:cape3:neck4:weapon5:chest6:shield7:unknown8:legs9:unknown10:gloves11:boots12: + //sicriona:103:1163: 1023: 1725 :1333: 1127 :1201 :0: 1079 :0: 2922: 1061:0: + equipIfExists(new Item(parseOSRS(2)), EquipmentContainer.SLOT_HAT); + equipIfExists(new Item(parseOSRS(3)), EquipmentContainer.SLOT_CAPE); + equipIfExists(new Item(parseOSRS(4)), EquipmentContainer.SLOT_AMULET); + equipIfExists(new Item(parseOSRS(5)), EquipmentContainer.SLOT_WEAPON); + equipIfExists(new Item(parseOSRS(6)), EquipmentContainer.SLOT_CHEST); + equipIfExists(new Item(parseOSRS(7)), EquipmentContainer.SLOT_SHIELD); + equipIfExists(new Item(parseOSRS(9)), EquipmentContainer.SLOT_LEGS); + equipIfExists(new Item(parseOSRS(11)), EquipmentContainer.SLOT_HANDS); + equipIfExists(new Item(parseOSRS(12)), EquipmentContainer.SLOT_FEET); + } - private int parseOSRS(int index) { - return Integer.parseInt(OSRScopyLine.split(":")[index]); - } + private int parseOSRS(int index) { + return Integer.parseInt(OSRScopyLine.split(":")[index]); + } - private void equipIfExists(Item e, int slot) { - if (e.getId() != 0) - getEquipment().replace(e, slot); - } + private void equipIfExists(Item e, int slot) { + if (e.getName().equalsIgnoreCase("null")) { + return; + } + if (e.getId() != 0) + getEquipment().replace(e, slot); + } - /** - * Get a bot content - */ - public static void updateRandomOSRScopyLine(String fileName) { - Random rand = new Random(); - int n = 0; - try { - for (Scanner sc = new Scanner(new File("./data/botdata/" + fileName)); sc.hasNext(); ) { - ++n; - String line = sc.nextLine(); - if (rand.nextInt(n) == 0) { //Chance of overwriting line is lower and lower - OSRScopyLine = line; - if (line.length() < 3) //probably an empty line - { - System.out.println("Something went wrong reading line [" + line + "] from /data/botdata/" + fileName); - updateRandomOSRScopyLine(fileName); - } - } - } - } catch (FileNotFoundException e) { - System.out.println("Missing " + fileName); - e.printStackTrace(); - } - } + /** + * Get a bot content + */ + public static void updateRandomOSRScopyLine(String fileName) { + Random rand = new Random(); + int n = 0; + try { + for (Scanner sc = new Scanner(new File("./data/botdata/" + fileName)); sc.hasNext(); ) { + ++n; + String line = sc.nextLine(); + if (rand.nextInt(n) == 0) { //Chance of overwriting line is lower and lower + OSRScopyLine = line; + if (line.length() < 3) //probably an empty line + { + System.out.println("Something went wrong reading line [" + line + "] from /data/botdata/" + fileName); + updateRandomOSRScopyLine(fileName); + } + } + } + } catch (FileNotFoundException e) { + System.out.println("Missing " + fileName); + e.printStackTrace(); + } + } - private static String retrieveRandomName(String fileName) { - updateRandomOSRScopyLine(fileName); - return OSRScopyLine.split(":")[0]; - } + private static String retrieveRandomName(String fileName) { + updateRandomOSRScopyLine(fileName); + return OSRScopyLine.split(":")[0]; + } - private static String retrieveRandomName() { - return retrieveRandomName("namesandarmor.txt"); - } + private static String retrieveRandomName() { + return retrieveRandomName("namesandarmor.txt"); + } - @Override - public void init() { - getProperties().setSpawnLocation(startLocation); - getInterfaceManager().openDefaultTabs(); - getSession().setObject(this); - botMapping.put(uid, this); - super.init(); - getSettings().setRunToggled(true); + @Override + public void init() { + getProperties().setSpawnLocation(startLocation); + getInterfaceManager().openDefaultTabs(); + getSession().setObject(this); + botMapping.put(uid, this); + super.init(); + getSettings().setRunToggled(true); CharacterDesign.randomize(this, false); - getInteraction().set(new Option("Control", 7).setHandler(new OptionHandler() { - @Override - public Plugin newInstance(Object arg) throws Throwable { - return null; - } + getInteraction().set(new Option("Control", 7).setHandler(new OptionHandler() { + @Override + public Plugin newInstance(Object arg) throws Throwable { + return null; + } - @Override - public boolean handle(Player p, Node node, String option) { - DialoguePlugin dial = CONTROL_DIAL.newInstance(p); - if (dial != null && dial.open(AIPlayer.this)) { - p.getDialogueInterpreter().setDialogue(dial); - } - return true; - } + @Override + public boolean handle(Player p, Node node, String option) { + DialoguePlugin dial = CONTROL_DIAL.newInstance(p); + if (dial != null && dial.open(AIPlayer.this)) { + p.getDialogueInterpreter().setDialogue(dial); + } + return true; + } - @Override - public boolean isWalk() { - return false; - } + @Override + public boolean isWalk() { + return false; + } - })); + })); - } + } - /** - * Handles the following. - * @param e The entity to follow. - */ - public void follow(final Entity e) { - getPulseManager().run(new MovementPulse(this, e, DestinationFlag.FOLLOW_ENTITY) { - @Override - public boolean pulse() { - face(e); - return false; - } - }, "movement"); - } + /** + * Handles the following. + * + * @param e The entity to follow. + */ + public void follow(final Entity e) { + getPulseManager().run(new MovementPulse(this, e, DestinationFlag.FOLLOW_ENTITY) { + @Override + public boolean pulse() { + face(e); + return false; + } + }, "movement"); + } - public void randomWalkAroundPoint(Location point, int radius) - { - Pathfinder.find(this, point.transform(RandomFunction.random(radius, (radius * -1)), RandomFunction.random(radius, (radius * -1)), 0), true, Pathfinder.SMART).walk(this); - } + public void randomWalkAroundPoint(Location point, int radius) { + Pathfinder.find(this, point.transform(RandomFunction.random(radius, (radius * -1)), RandomFunction.random(radius, (radius * -1)), 0), true, Pathfinder.SMART).walk(this); + } - public void randomWalk(int radiusX, int radiusY) - { - Pathfinder.find(this, this.getLocation().transform(RandomFunction.random(radiusX, (radiusX * -1)), RandomFunction.random(radiusY, (radiusY * -1)), 0), false, Pathfinder.SMART).walk(this); - } + public void randomWalk(int radiusX, int radiusY) { + Pathfinder.find(this, this.getLocation().transform(RandomFunction.random(radiusX, (radiusX * -1)), RandomFunction.random(radiusY, (radiusY * -1)), 0), false, Pathfinder.SMART).walk(this); + } - public void walkToPosSmart(int x, int y) - { - walkToPosSmart(new Location(x, y)); - } + public void walkToPosSmart(int x, int y) { + walkToPosSmart(new Location(x, y)); + } - public void walkToPosSmart(Location loc) { - Pathfinder.find(this, loc, true, Pathfinder.SMART).walk(this); - } + public void walkToPosSmart(Location loc) { + Pathfinder.find(this, loc, true, Pathfinder.SMART).walk(this); + } - public void walkPos(int x, int y) - { - Pathfinder.find(this, new Location(x, y)); - } + public void walkPos(int x, int y) { + Pathfinder.find(this, new Location(x, y)); + } - public boolean checkVictimIsPlayer() - { - if (this.getProperties().getCombatPulse().getVictim() != null) - if (this.getProperties().getCombatPulse().getVictim().isPlayer()) - return true; - return false; - } + public boolean checkVictimIsPlayer() { + if (this.getProperties().getCombatPulse().getVictim() != null) + if (this.getProperties().getCombatPulse().getVictim().isPlayer()) + return true; + return false; + } - public Item getItemById(int id) - { - for (int i = 0; i < 28; i++) - { - Item item = this.getInventory().get(i); - if (item != null) - { - if (item.getId() == id) - return item; - } - } - return null; - } + public Item getItemById(int id) { + for (int i = 0; i < 28; i++) { + Item item = this.getInventory().get(i); + if (item != null) { + if (item.getId() == id) + return item; + } + } + return null; + } - private ArrayList getNodeInRange(int range, int entry) - { - int meX = this.getLocation().getX(); - int meY = this.getLocation().getY(); - ArrayList nodes = new ArrayList(); - for (NPC npc : RegionManager.getLocalNpcs(this, range)) { - if (npc.getId() == entry) - nodes.add(npc); - } - for (int x = 0; x < range; x++) - { - for (int y = 0; y < range - x; y++) - { - Node node = RegionManager.getObject(0, meX + x, meY + y); - if (node != null) - if (node.getId() == entry) - nodes.add(node); - Node node2 = RegionManager.getObject(0, meX + x, meY - y); - if (node2 != null) - if (node2.getId() == entry) - nodes.add(node2); - Node node3 = RegionManager.getObject(0, meX - x, meY + y); - if (node3 != null) - if (node3.getId() == entry) - nodes.add(node3); - Node node4 = RegionManager.getObject(0, meX - x, meY - y); - if (node4 != null) - if (node4.getId() == entry) - nodes.add(node4); - } - } - return nodes; - } + private ArrayList getNodeInRange(int range, int entry) { + int meX = this.getLocation().getX(); + int meY = this.getLocation().getY(); + ArrayList nodes = new ArrayList(); + for (NPC npc : RegionManager.getLocalNpcs(this, range)) { + if (npc.getId() == entry) + nodes.add(npc); + } + for (int x = 0; x < range; x++) { + for (int y = 0; y < range - x; y++) { + Node node = RegionManager.getObject(0, meX + x, meY + y); + if (node != null) + if (node.getId() == entry) + nodes.add(node); + Node node2 = RegionManager.getObject(0, meX + x, meY - y); + if (node2 != null) + if (node2.getId() == entry) + nodes.add(node2); + Node node3 = RegionManager.getObject(0, meX - x, meY + y); + if (node3 != null) + if (node3.getId() == entry) + nodes.add(node3); + Node node4 = RegionManager.getObject(0, meX - x, meY - y); + if (node4 != null) + if (node4.getId() == entry) + nodes.add(node4); + } + } + return nodes; + } - private ArrayList getNodeInRange(int range, List entrys) - { - int meX = this.getLocation().getX(); - int meY = this.getLocation().getY(); - //int meX2 = this.getLocation().getX(); - //System.out.println("local " + meX + " real x? " + meX2 ); - ArrayList nodes = new ArrayList(); - for (NPC npc : RegionManager.getLocalNpcs(this, range)) { - if (entrys.contains(npc.getId())) - nodes.add(npc); - } - for (int x = 0; x < range; x++) - { - for (int y = 0; y < range - x; y++) - { - Node node = RegionManager.getObject(0, meX + x, meY + y); - if (node != null) - if (entrys.contains(node.getId())) - nodes.add(node); - Node node2 = RegionManager.getObject(0, meX + x, meY - y); - if (node2 != null) - if (entrys.contains(node2.getId())) - nodes.add(node2); - Node node3 = RegionManager.getObject(0, meX - x, meY + y); - if (node3 != null) - if (entrys.contains(node3.getId())) - nodes.add(node3); - Node node4 = RegionManager.getObject(0, meX - x, meY - y); - if (node4 != null) - if (entrys.contains(node4.getId())) - nodes.add(node4); - } - } - return nodes; - } + private ArrayList getNodeInRange(int range, List entrys) { + int meX = this.getLocation().getX(); + int meY = this.getLocation().getY(); + //int meX2 = this.getLocation().getX(); + //System.out.println("local " + meX + " real x? " + meX2 ); + ArrayList nodes = new ArrayList(); + for (NPC npc : RegionManager.getLocalNpcs(this, range)) { + if (entrys.contains(npc.getId())) + nodes.add(npc); + } + for (int x = 0; x < range; x++) { + for (int y = 0; y < range - x; y++) { + Node node = RegionManager.getObject(0, meX + x, meY + y); + if (node != null) + if (entrys.contains(node.getId())) + nodes.add(node); + Node node2 = RegionManager.getObject(0, meX + x, meY - y); + if (node2 != null) + if (entrys.contains(node2.getId())) + nodes.add(node2); + Node node3 = RegionManager.getObject(0, meX - x, meY + y); + if (node3 != null) + if (entrys.contains(node3.getId())) + nodes.add(node3); + Node node4 = RegionManager.getObject(0, meX - x, meY - y); + if (node4 != null) + if (entrys.contains(node4.getId())) + nodes.add(node4); + } + } + return nodes; + } - public Node getClosestNodeWithEntryAndDirection(int range, int entry, Direction direction) - { - ArrayList nodeList = getNodeInRange(range, entry); - if (nodeList.isEmpty()) - { - //System.out.println("nodelist empty"); - return null; - } - Node node = getClosestNodeinNodeListWithDirection(nodeList, direction); - return node; - } + public Node getClosestNodeWithEntryAndDirection(int range, int entry, Direction direction) { + ArrayList nodeList = getNodeInRange(range, entry); + if (nodeList.isEmpty()) { + //System.out.println("nodelist empty"); + return null; + } + Node node = getClosestNodeinNodeListWithDirection(nodeList, direction); + return node; + } - public Node getClosestNodeWithEntry(int range, int entry) - { - ArrayList nodeList = getNodeInRange(range, entry); - if (nodeList.isEmpty()) - { - //System.out.println("nodelist empty"); - return null; - } - Node node = getClosestNodeinNodeList(nodeList); - return node; - } + public Node getClosestNodeWithEntry(int range, int entry) { + ArrayList nodeList = getNodeInRange(range, entry); + if (nodeList.isEmpty()) { + //System.out.println("nodelist empty"); + return null; + } + Node node = getClosestNodeinNodeList(nodeList); + return node; + } - public Node getClosestNodeWithEntry(int range, List entrys) - { - ArrayList nodeList = getNodeInRange(range, entrys); - if (nodeList.isEmpty()) - { - //System.out.println("nodelist empty"); - return null; - } - Node node = getClosestNodeinNodeList(nodeList); - return node; - } + public Node getClosestNodeWithEntry(int range, List entrys) { + ArrayList nodeList = getNodeInRange(range, entrys); + if (nodeList.isEmpty()) { + //System.out.println("nodelist empty"); + return null; + } + Node node = getClosestNodeinNodeList(nodeList); + return node; + } - public Node getClosesCreature(int radius) { - int distance = radius + 1; - Node npcReturn = null; - for (NPC npc : RegionManager.getLocalNpcs(this, radius)) { - double distanceToNpc = npc.getLocation().getDistance(this.getLocation()); - if ((distanceToNpc) < distance) { - distance = (int) distanceToNpc; - npcReturn = npc; - } - } - return npcReturn; - } + public Node getClosesCreature(int radius) { + int distance = radius + 1; + Node npcReturn = null; + for (NPC npc : RegionManager.getLocalNpcs(this, radius)) { + double distanceToNpc = npc.getLocation().getDistance(this.getLocation()); + if ((distanceToNpc) < distance) { + distance = (int) distanceToNpc; + npcReturn = npc; + } + } + return npcReturn; + } - public Node getClosesCreature(int radius, int entry) { - int distance = radius + 1; - Node npcReturn = null; - for (NPC npc : RegionManager.getLocalNpcs(this, radius)) { - double distanceToNpc = npc.getLocation().getDistance(this.getLocation()); - if (npc.getId() == entry) { - if ((distanceToNpc) < distance) { - distance = (int) distanceToNpc; - npcReturn = npc; - } - } - } - return npcReturn; - } + public Node getClosesCreature(int radius, int entry) { + int distance = radius + 1; + Node npcReturn = null; + for (NPC npc : RegionManager.getLocalNpcs(this, radius)) { + double distanceToNpc = npc.getLocation().getDistance(this.getLocation()); + if (npc.getId() == entry) { + if ((distanceToNpc) < distance) { + distance = (int) distanceToNpc; + npcReturn = npc; + } + } + } + return npcReturn; + } - public Node getClosesCreature(int radius, ArrayList entrys) { - int distance = radius + 1; - Node npcReturn = null; - for (NPC npc : RegionManager.getLocalNpcs(this, radius)) { - double distanceToNpc = npc.getLocation().getDistance(this.getLocation()); - if (entrys.contains(npc.getId())) { - if ((distanceToNpc) < distance) { - distance = (int) distanceToNpc; - npcReturn = npc; - } - } - } - return npcReturn; - } + public Node getClosesCreature(int radius, ArrayList entrys) { + int distance = radius + 1; + Node npcReturn = null; + for (NPC npc : RegionManager.getLocalNpcs(this, radius)) { + double distanceToNpc = npc.getLocation().getDistance(this.getLocation()); + if (entrys.contains(npc.getId())) { + if ((distanceToNpc) < distance) { + distance = (int) distanceToNpc; + npcReturn = npc; + } + } + } + return npcReturn; + } - private Node getClosestNodeinNodeListWithDirection(ArrayList nodes, Direction direction) - { - if (nodes.isEmpty()) - { - //System.out.println("nodelist empty"); - return null; - } + private Node getClosestNodeinNodeListWithDirection(ArrayList nodes, Direction direction) { + if (nodes.isEmpty()) { + //System.out.println("nodelist empty"); + return null; + } - double distance = 0; - Node nodeReturn = null; - for (Node node : nodes) - { - double nodeDistance = this.getLocation().getDistance(node.getLocation()); - if ((nodeReturn == null || nodeDistance < distance) && node.getDirection() == direction) - { - distance = nodeDistance; - nodeReturn = node; - } - } - return nodeReturn; - } + double distance = 0; + Node nodeReturn = null; + for (Node node : nodes) { + double nodeDistance = this.getLocation().getDistance(node.getLocation()); + if ((nodeReturn == null || nodeDistance < distance) && node.getDirection() == direction) { + distance = nodeDistance; + nodeReturn = node; + } + } + return nodeReturn; + } - private Node getClosestNodeinNodeList(ArrayList nodes) - { - if (nodes.isEmpty()) - { - //System.out.println("nodelist empty"); - return null; - } + private Node getClosestNodeinNodeList(ArrayList nodes) { + if (nodes.isEmpty()) { + //System.out.println("nodelist empty"); + return null; + } - double distance = 0; - Node nodeReturn = null; - for (Node node : nodes) - { - double nodeDistance = this.getLocation().getDistance(node.getLocation()); - if (nodeReturn == null || nodeDistance < distance) - { - distance = nodeDistance; - nodeReturn = node; - } - } - return nodeReturn; - } + double distance = 0; + Node nodeReturn = null; + for (Node node : nodes) { + double nodeDistance = this.getLocation().getDistance(node.getLocation()); + if (nodeReturn == null || nodeDistance < distance) { + distance = nodeDistance; + nodeReturn = node; + } + } + return nodeReturn; + } - @Override - public void clear() { - botMapping.remove(uid); - super.clear(true); - } + @Override + public void clear() { + botMapping.remove(uid); + super.clear(true); + } - @Override - public void reset() { - if (getPlayerFlags().isUpdateSceneGraph()) { - getPlayerFlags().setLastSceneGraph(getLocation()); - } - super.reset(); - } + @Override + public void reset() { + if (getPlayerFlags().isUpdateSceneGraph()) { + getPlayerFlags().setLastSceneGraph(getLocation()); + } + super.reset(); + } - /** - * Gets the UID. - * @return the UID. - */ - public int getUid() { - return uid; - } + /** + * Gets the UID. + * + * @return the UID. + */ + public int getUid() { + return uid; + } - /** - * Deregisters an AIP. - * @param uid The player's UID. - */ - public static void deregister(int uid) { - AIPlayer player = botMapping.get(uid); - if (player != null) { - player.clear(); - Repository.getPlayers().remove(player); - return; - } - System.err.println("Could not deregister AIP#" + uid + ": UID not added to the mapping!"); - } + /** + * Deregisters an AIP. + * + * @param uid The player's UID. + */ + public static void deregister(int uid) { + AIPlayer player = botMapping.get(uid); + if (player != null) { + player.clear(); + Repository.getPlayers().remove(player); + return; + } + System.err.println("Could not deregister AIP#" + uid + ": UID not added to the mapping!"); + } - @Override - public String getUsername() { - return username; - } + @Override + public String getUsername() { + return username; + } - /** - * Gets the AIP for the given UID. - * @param uid The UID. - * @return The AIPlayer. - */ - public static AIPlayer get(int uid) { - return botMapping.get(uid); - } + /** + * Gets the AIP for the given UID. + * + * @param uid The UID. + * @return The AIPlayer. + */ + public static AIPlayer get(int uid) { + return botMapping.get(uid); + } - /** - * @return the startLocation. - */ - public Location getStartLocation() { - return startLocation; - } + /** + * @return the startLocation. + */ + public Location getStartLocation() { + return startLocation; + } - /** - * Gets the controler. - * @return The controler. - */ - public Player getControler() { - return controler; - } + /** + * Gets the controler. + * + * @return The controler. + */ + public Player getControler() { + return controler; + } - /** - * Sets the controler. - * @param controler The controler to set. - */ - public void setControler(Player controler) { - this.controler = controler; - } + /** + * Sets the controler. + * + * @param controler The controler to set. + */ + public void setControler(Player controler) { + this.controler = controler; + } - public void interact(Node n) - { - InteractionPacket.handleObjectInteraction(this, 0, n.getLocation(), n.getId()); - } + public void interact(Node n) { + InteractionPacket.handleObjectInteraction(this, 0, n.getLocation(), n.getId()); + } } \ No newline at end of file diff --git a/Server/src/plugin/quest/witchs_house/NoraTHaggNPC.java b/Server/src/plugin/quest/witchs_house/NoraTHaggNPC.java index e9fba5016..49f021fda 100644 --- a/Server/src/plugin/quest/witchs_house/NoraTHaggNPC.java +++ b/Server/src/plugin/quest/witchs_house/NoraTHaggNPC.java @@ -11,7 +11,6 @@ import org.crandor.game.world.GameWorld; import org.crandor.game.world.map.Direction; import org.crandor.game.world.map.Location; import org.crandor.game.world.map.path.Pathfinder; -import org.crandor.game.world.map.path.SmartPathfinder; import org.crandor.game.world.update.flag.context.Animation; import org.crandor.game.world.update.flag.context.Graphics; import org.crandor.net.packet.PacketRepository; @@ -31,17 +30,18 @@ import java.util.List; @InitializablePlugin public final class NoraTHaggNPC extends AbstractNPC { + private static final Location[] MOVEMENT_PATH = {Location.create(2904, 3463, 0), Location.create(2908, 3463, 0), Location.create(2912, 3463, 0), Location.create(2916, 3463, 0), Location.create(2920, 3463, 0), Location.create(2924, 3463, 0), Location.create(2930, 3463, 0)}; private int tilesIndex = 0; public NoraTHaggNPC() { super(896, Location.create(2904, 3463, 0)); } - public NoraTHaggNPC(int id, Location location) { + private NoraTHaggNPC(int id, Location location) { super(id, location); } - public boolean canTeleport(Entity t) { + private boolean canTeleport(Entity t) { int playerX = t.getLocation().getX(); int npcX = getLocation().getX(); int[] sectors = { 2904, 2907, 2910, 2914, 2918, 2922, 2926, 2928 }; @@ -61,7 +61,9 @@ public final class NoraTHaggNPC extends AbstractNPC { @Override public void configure() { super.configure(); -// configureMovementPath(Location.create(2904, 3463, 0), Location.create(2930, 3463, 0)); +// if (isWalks()) { +// configureMovementPath(MOVEMENT_PATH); +// } // setWalks(true); } @@ -75,14 +77,10 @@ public final class NoraTHaggNPC extends AbstractNPC { return new int[] { 896 }; } - public Location getRespawnLocation() { + private Location getRespawnLocation() { return Location.create(2901, 3466, 0); } - public int getTilesIndex() { - return tilesIndex; - } - @Override public int getWalkRadius() { return 50; @@ -112,7 +110,7 @@ public final class NoraTHaggNPC extends AbstractNPC { return super.newInstance(arg); } - public void sendTeleport(final Player player) { + private void sendTeleport(final Player player) { player.lock(); GameWorld.submit(new Pulse(1) { int delay = 0; @@ -140,10 +138,5 @@ public final class NoraTHaggNPC extends AbstractNPC { }); } - public void setTilesIndex(int tilesIndex) { - this.tilesIndex = tilesIndex; - } - - }