@Override public void update() { if (!transmitting) { super.update(); ArrayList deadMonsters = new ArrayList(); Monster monster = null; try { for (String key : monsters.keySet()) { monster = (Monster) monsters.get(key); if (monster != null) { monster.update(); if (monster.getIsDead()) { deadMonsters.add(key); } } } if (deadMonsters.size() > 0) { for (int i = 0; i < deadMonsters.size(); i++) { // EIError.debugMsg((String) deadMonsters.get(i)); monsters.remove((String) deadMonsters.get(i)); } } } catch (ConcurrentModificationException concEx) { // another thread was trying to modify monsters while iterating // we'll continue and the new item can be grabbed on the next update } } }
public Monster getClosestWithinMax(Point p, int r) { Monster monster = null; Monster closestMonster = null; double closestDistance = 0; try { for (String key : monsters.keySet()) { monster = (Monster) monsters.get(key); if (!monster.getName().equals("Pig") && !monster.getName().equals("BlueThorn") && !monster.getName().equals("VineThorn")) { if (monster.getIsInPanel()) { double distance = p.distance(monster.getCenterPoint()); if ((distance < closestDistance || closestDistance == 0) && distance <= r) { closestMonster = monster; closestDistance = distance; } } } } } catch (ConcurrentModificationException concEx) { // another thread was trying to modify monsters while iterating // we'll continue and the new item can be grabbed on the next update } return closestMonster; }
private void removeMonster(String monsterType) { Monster monster = null; ArrayList deadMonsters = new ArrayList(); try { for (String key : monsters.keySet()) { monster = (Monster) monsters.get(key); if (monster.getName().equals(monsterType)) { deadMonsters.add(key); break; } } if (deadMonsters.size() > 0) { for (int i = 0; i < deadMonsters.size(); i++) { // EIError.debugMsg((String) deadMonsters.get(i)); monsters.remove((String) deadMonsters.get(i)); } } } catch (ConcurrentModificationException concEx) { // another thread was trying to modify monsters while iterating // we'll continue and the new item can be grabbed on the next update } }
public boolean handleClick(Player p, Point clickPoint) { Point mousePos = new Point(this.panelToMapX(clickPoint.x), this.panelToMapY(clickPoint.y)); Monster monster = null; try { for (String key : monsters.keySet()) { monster = (Monster) monsters.get(key); if (monster != null) { if (monster.isInside(mousePos) && !monster.getIsHiding()) { if (selectedMob != monster) { SoundClip cl = new SoundClip("Misc/Click"); selectedMob = monster; } return true; } } } } catch (ConcurrentModificationException concEx) { // another thread was trying to modify monsters while iterating // we'll continue and the new item can be grabbed on the next update } return false; }
public void processMonsterUpdateUDP(UDPMonster up) { if (up != null) { if (monsters.containsKey(up.id)) { Monster monster = monsters.get(up.id); if (monster != null) { monster.processUpdate(up); } } } }
public ArrayList<String> attackDamageAndKnockBack( Actor source, Arc2D.Double arc, Point mapPoint, int damage, int knockBackX, int knockBackY, int maxHits, String weaponType) { int dmg = 0; int hits = 0; Monster monster = null; ArrayList<String> monstersHit = new ArrayList<String>(); try { for (String key : monsters.keySet()) { monster = (Monster) monsters.get(key); if (weaponType != null) { if (weaponType.equals("Net")) { damage = 1; } } dmg = monster.attackDamageAndKnockBack( source, arc, mapPoint, damage, knockBackX, knockBackY, weaponType); if (dmg > 0) { if (weaponType != null) { if (weaponType.equals("FangClaw")) { monster.poison(10); } } monstersHit.add(monster.getName()); hits++; } if (hits >= maxHits) { break; } } } catch (ConcurrentModificationException concEx) { // another thread was trying to modify monsters while iterating // we'll continue and the new item can be grabbed on the next update } if (hits == 0) { if (source != null) { SoundClip cl = new SoundClip(registry, "Weapon/Miss", source.getCenterPoint()); } else { SoundClip cl = new SoundClip("Weapon/Miss"); } } return monstersHit; }
public Monster getSelectedMob() { if (selectedMob != null) { if (selectedMob.getIsDead() || selectedMob.isDirty) { selectedMob = null; } else { if (!this.isInPlayerView(selectedMob.getCenterPoint())) { selectedMob = null; } } } return selectedMob; }
public void showGoals(Boolean g) { showGoals = g; Monster monster = null; try { for (String key : monsters.keySet()) { monster = (Monster) monsters.get(key); monster.setShowGoals(g); } } catch (ConcurrentModificationException concEx) { // another thread was trying to modify monsters while iterating // we'll continue and the new item can be grabbed on the next update } }
public void resetAggro() { int count = 0; Monster monster = null; try { for (String key : monsters.keySet()) { monster = (Monster) monsters.get(key); monster.setPlayerDamage(0); } } catch (ConcurrentModificationException concEx) { // another thread was trying to modify monsters while iterating // we'll continue and the new item can be grabbed on the next update } }
public void render(Graphics g) { if (!transmitting) { Monster monster = null; try { for (String key : monsters.keySet()) { monster = (Monster) monsters.get(key); monster.render(g); } } catch (ConcurrentModificationException concEx) { // another thread was trying to modify monsters while iterating // we'll continue and the new item can be grabbed on the next update } } }
@Override public void setTransient(Registry rg) { super.setTransient(rg); spawnCoolDowns = new HashMap<String, Integer>(); try { for (String key : monsters.keySet()) { Monster monster = (Monster) monsters.get(key); monster.setTransient(rg, this); } } catch (ConcurrentModificationException concEx) { // another thread was trying to modify monsters while iterating // we'll continue and the new item can be grabbed on the next update } }
@Override public void updateLong() { if (!transmitting) { if (nextBossOrcSpawn == 0) { // spawn melvin every 10 - 30 min nextBossOrcSpawn = registry.currentTime + Rand.getRange(10 * 60 * 1000, 30 * 60 * 1000); } if (nextSnailRiderSpawn == 0) { // spawn melvin every 10 - 30 min nextSnailRiderSpawn = registry.currentTime + Rand.getRange(10 * 60 * 1000, 30 * 60 * 1000); } Monster monster = null; ArrayList deadMonsters = new ArrayList(); // make sure we have enough bad guys on the map if (gameController.multiplayerMode != gameController.multiplayerMode.CLIENT) { spawnNearPlayers(); spawnNearPlaceable(); } try { for (String key : monsters.keySet()) { monster = (Monster) monsters.get(key); if (!monster.isFeared()) { gameController.checkIfFeared(monster); } gameController.checkPlaceableDamageAgainstMob(monster); monster.updateLong(); if (monster.isDirty()) { deadMonsters.add(key); } } if (deadMonsters.size() > 0) { for (int i = 0; i < deadMonsters.size(); i++) { // EIError.debugMsg((String) deadMonsters.get(i)); monsters.remove((String) deadMonsters.get(i)); } } } catch (ConcurrentModificationException concEx) { // another thread was trying to modify monsters while iterating // we'll continue and the new item can be grabbed on the next update } } }
public Monster getMostAggroInPanel(Point p) { Monster monster = null; Monster mostAggroMonster = null; double mostAggro = 0; try { for (String key : monsters.keySet()) { monster = (Monster) monsters.get(key); if (!monster.getName().equals("Pig") && !monster.getName().equals("BlueThorn") && !monster.getName().equals("VineThorn")) { if (monster.getIsInPanel()) { double distance = p.distance(monster.getCenterPoint()); if (monster.getPlayerDamage() > mostAggro) { mostAggroMonster = monster; mostAggro = monster.getPlayerDamage(); } } } } } catch (ConcurrentModificationException concEx) { // another thread was trying to modify monsters while iterating // we'll continue and the new item can be grabbed on the next update } return mostAggroMonster; }
private int getCountByType(String type) { int count = 0; Monster monster = null; try { for (String key : monsters.keySet()) { monster = (Monster) monsters.get(key); if (monster.getName().equals(type)) { count++; } } } catch (ConcurrentModificationException concEx) { // another thread was trying to modify monsters while iterating // we'll continue and the new item can be grabbed on the next update } return count; }
public Damage getMonsterTouchDamage(Rectangle r, int x) { Damage damage = null; Monster monster = null; try { for (String key : monsters.keySet()) { monster = (Monster) monsters.get(key); damage = monster.getMonsterTouchDamage(r, x); if (damage != null) { break; } } } catch (ConcurrentModificationException concEx) { // another thread was trying to modify monsters while iterating // we'll continue and the new item can be grabbed on the next update } return damage; }
public int getAnimalCount(Rectangle r) { int count = 0; Monster monster = null; try { for (String key : monsters.keySet()) { monster = (Monster) monsters.get(key); if (monster.getName().equals("Pig")) { if (monster.getSpriteRect().intersects(r)) { count++; } } } } catch (ConcurrentModificationException concEx) { // another thread was trying to modify monsters while iterating // we'll continue and the new item can be grabbed on the next update } return count; }
@Override public boolean checkMobParticleHit(Particle p) { if (gameController.multiplayerMode != gameController.multiplayerMode.CLIENT) { Monster monster = null; try { for (String key : monsters.keySet()) { monster = (Monster) monsters.get(key); if (monster.getPerimeter().intersects(p.getRect())) { monster.applyDamage(p.getDamage(), p.getSource(), p.isFromPlaceable(), false); return true; } } } catch (ConcurrentModificationException concEx) { // another thread was trying to modify monsters while iterating // we'll continue and the new item can be grabbed on the next update } } return false; }
public void removeAllMonsters() { Monster monster = null; ArrayList deadMonsters = new ArrayList(); try { for (String key : monsters.keySet()) { monster = (Monster) monsters.get(key); if (!monster.getName().equals("Pig") && !monster.getName().equals("BlueThorn") && !monster.getName().equals("VineThorn")) { deadMonsters.add(key); if (gameController.multiplayerMode == gameController.multiplayerMode.SERVER && registry.getNetworkThread() != null) { if (registry.getNetworkThread().readyForUpdates()) { UpdateMonster um = new UpdateMonster(monster.getId()); um.mapX = monster.getMapX(); um.mapY = monster.getMapY(); um.action = "Die"; registry.getNetworkThread().sendData(um); } } } } if (deadMonsters.size() > 0) { for (int i = 0; i < deadMonsters.size(); i++) { monsters.remove((String) deadMonsters.get(i)); } } } catch (ConcurrentModificationException concEx) { // another thread was trying to modify monsters while iterating // we'll continue and the new item can be grabbed on the next update } }
public void quest() { while (getStage() < 5) { String input = new String(); // input = "This is the input var right now"; // System.out.println(input); Scanner sc = new Scanner(System.in); while (!input.equals("move")) { System.out.println("Make your next move!"); input = sc.nextLine(); } int randNum = (int) (Math.random() * 100); // System.out.println(randNum); Monster m = new Monster(); if (randNum <= 34) { m.koboldTemplate("I am kobold", 1); } else if (randNum <= 67) { m.spiderTemplate("I am spider", 1); } else { m.golemTemplate("I am golem", 1); } m.displayStats(); setStage(getStage() + 1); BaseChar b = new BaseChar(); // basechar should be set to either warrior or mage b.warriorTemplate( "I am warrior"); // this really shouldn't be here. This should be in the Driver and // user-selected b.displayStats(); Battle bat = new Battle(b, m); bat.charAttackMonster(b, m); bat.monsterAttackChar(m, b); } System.out.println("YOU WIN!!!"); }
public void generatePlants() { int passes = 0; int blueThornCount = 0; int vineThornCount = 0; do { blueThornCount = this.getCountByType("BlueThorn"); vineThornCount = this.getCountByType("VineThorn"); spawnPlants(); Monster monster = null; ArrayList deadMonsters = new ArrayList(); try { for (String key : monsters.keySet()) { monster = (Monster) monsters.get(key); if (monster != null) { monster.update(); if (monster.getIsDead()) { deadMonsters.add(key); } } } if (deadMonsters.size() > 0) { for (int i = 0; i < deadMonsters.size(); i++) { // EIError.debugMsg((String) deadMonsters.get(i)); monsters.remove((String) deadMonsters.get(i)); } } } catch (ConcurrentModificationException concEx) { // another thread was trying to modify monsters while iterating // we'll continue and the new item can be grabbed on the next update } passes++; } while ((blueThornCount < 200 || vineThornCount < 200) && passes < 50); int g = 1; }
public String spell(Monster other, String userInput) { if (userInput.equals("1") && thing.nextInt(this.getACC()) > 20) { if ((this.getMP() - 20) < 0) { return ("Not enough mana!"); } else { int damage = 15 + thing.nextInt(11); other.setHP(other.getHP() - damage); this.setMP(this.getMP() - 20); return (this + " shot a fireball at " + other + ". " + other + " lost " + damage + " HP."); } } else if (userInput.equals("2") && thing.nextInt(this.getACC()) > 0) { if ((this.getMP() - 30) < 0) { return ("Not enough mana!"); } else { int damage = 15 + thing.nextInt(11); other.setHP(other.getHP() - damage); this.setMP(this.getMP() - 30); return (this + " electrified " + other + ". " + other + " lost " + damage + " HP."); } } else if (userInput.equals("3") && thing.nextInt(this.getACC()) > 20) { if ((this.getMP() - 40) < 0) { return ("Not enough mana!"); } else { int damage = 25 + thing.nextInt(11); other.setHP(other.getHP() - damage); this.setMP(this.getMP() - 40); return (this + " froze " + other + ". " + other + " lost " + damage + " HP."); } } else { if (userInput.equals("1")) { this.setMP(this.getMP() - 20); return "The spell fizzled and died"; } if (userInput.equals("2")) { this.setMP(this.getMP() - 30); return "The spell fizzled and died"; } if (userInput.equals("3")) { this.setMP(this.getMP() - 40); return "The spell fizzled and died"; } if (userInput.equals("")) { return this.toString() + " did nothing."; } if (this.getMP() < 0) { this.setMP(0); } return ""; } }
public void processMonsterUpdate(UpdateMonster um) { if (um != null) { if (monsters.containsKey(um.id)) { Monster monster = monsters.get(um.id); if (monster != null) { EIError.debugMsg( "Setting " + um.id + " to " + um.mapX + ":" + um.mapY + ", Action: " + um.action); monster.setPosition(um.mapX, um.mapY); if (um.previousGoal != null) { monster.ai.setPreviousGoal(um.previousGoal); } if (um.currentGoal != null) { monster.ai.setCurrentGoal(um.currentGoal); } if (um.action.equals("ApplyDamage")) { monster.applyDamage(um.dataInt, um.actor); } else if (um.action.equals("ApplyKnockBack")) { monster.applyKnockBack(um.dataInt, um.dataInt2); } else if (um.action.equals("Die")) { monster.setHitPoints(0); } else if (um.action.equals("Fear")) { monster.applyKnockBack(um.dataInt, um.dataInt2); monster.fear(um.dataPoint, um.dataLong); } } } else { if (gameController.multiplayerMode == gameController.multiplayerMode.CLIENT && registry.getNetworkThread() != null) { if (registry.getNetworkThread().readyForUpdates()) { EIError.debugMsg("Monster not found - need " + um.id); registry.getNetworkThread().sendData("send monster data: " + um.id); } } } } }
public void spawnNearPlayers() { Monster monster = null; float prob, rand; int count; HashMap<String, Player> players = registry.getPlayerManager().getPlayers(); Player player = null; Integer spawnCoolDown = null; for (String key : players.keySet()) { player = (Player) players.get(key); // check for spawning Melvin if (registry.currentTime >= nextBossOrcSpawn && nextBossOrcSpawn != 0) { // to spawn melvin, player must have 40 AP, be within a range on the map and be on the // surface if (player.getMapX() >= 2000 && player.getMapX() <= 5000 && player.getLevel() >= 10 && player.getMapY() == this.findFloor(player.getMapX())) { spawnBossOrc(player); } } if (spawnCoolDowns.containsKey(key)) { spawnCoolDown = spawnCoolDowns.get(key); } else { spawnCoolDown = new Integer(0); spawnCoolDowns.put(key, spawnCoolDown); } spawnCoolDown--; if (spawnCoolDown < 0) { int x = player.getMapX(); int y = player.getMapY(); int groundLevel = registry.getBlockManager().getLevelByY(y); count = -groundLevel; try { for (String key2 : monsters.keySet()) { monster = (Monster) monsters.get(key2); if (monster.getCenterPoint().distance(player.getCenterPoint()) < MonsterManager.mobSpawnRangeMax * 3 / 2) { if (monster.getTouchDamage() > 0 && !monster.getName().equals("BlueThorn") && !monster.getName().equals("VineThorn")) { count++; } } } } catch (ConcurrentModificationException concEx) { // another thread was trying to modify monsters while iterating // we'll continue and the new item can be grabbed on the next update } if (count < 4) { for (MonsterType monsterType : MonsterType.values()) { if (count < 4) { rand = Rand.getFloat(); prob = getShouldSpawn(monsterType, groundLevel); if (prob > 0.0f) { if ((prob - count * spawnRatioDiff) > 0.005f) { prob += -count * spawnRatioDiff; } else { prob = 0.005f; } } if (rand <= prob) { // System.out.println("spawn near player " + monsterType.name()); spawn(monsterType.name(), "Roaming", x, y); count++; } } } } else { // EIError.debugMsg("too many to spawn"); spawnCoolDown = 20; } } } }
private void spawnPlants() { if (gameController.multiplayerMode != gameController.multiplayerMode.CLIENT) { // Blue Thorns int blueThornCount = this.getCountByType("BlueThorn"); if (blueThornCount < 200) { for (int i = 0; i < 200 - blueThornCount; i++) { boolean canSpawn = true; int level = Rand.getRange(1, 3); Point vinePosition = new Point(); vinePosition.x = Rand.getRange(1, gameController.getMapWidth()); vinePosition.y = Rand.getRange( registry.getBlockManager().getLevelBottom(level), registry.getBlockManager().getLevelTop(level)); vinePosition.y = this.findNextFloor(vinePosition.x, vinePosition.y, 60); if (this.doesRectContainBlocks(vinePosition.x, vinePosition.y + 100, 17, 16)) { Monster monster = null; try { for (String key : monsters.keySet()) { monster = (Monster) monsters.get(key); if (monster.getName().equals("BlueThorn") || monster.getName().equals("VineThorn")) { double distance = vinePosition.distance(monster.getCenterPoint()); if (distance < 750) { canSpawn = false; break; } } } } catch (ConcurrentModificationException concEx) { // another thread was trying to modify monsters while iterating // we'll continue and the new item can be grabbed on the next update } if (canSpawn) { spawn("BlueThorn", "Roaming", vinePosition.x, vinePosition.y); } } } } // Vine Thorns int vineThornCount = this.getCountByType("VineThorn"); if (vineThornCount < 200) { for (int i = 0; i < 200 - vineThornCount; i++) { boolean canSpawn = true; int level = Rand.getRange(1, 3); Point vinePosition = new Point(); vinePosition.x = Rand.getRange(1, gameController.getMapWidth()); vinePosition.y = Rand.getRange( registry.getBlockManager().getLevelBottom(level), registry.getBlockManager().getLevelTop(level)); vinePosition.y = this.findNextFloor(vinePosition.x, vinePosition.y, 60); if (this.doesRectContainBlocks(vinePosition.x, vinePosition.y + 100, 17, 16)) { Monster monster = null; try { for (String key : monsters.keySet()) { monster = (Monster) monsters.get(key); if (monster.getName().equals("BlueThorn") || monster.getName().equals("VineThorn")) { double distance = vinePosition.distance(monster.getCenterPoint()); if (distance < 750) { canSpawn = false; break; } } } } catch (ConcurrentModificationException concEx) { // another thread was trying to modify monsters while iterating // we'll continue and the new item can be grabbed on the next update } if (canSpawn) { spawn("VineThorn", "Roaming", vinePosition.x, vinePosition.y); } } } } } }
public void registerMonster(Monster m) { if (!monsters.containsKey(m.getId())) { monsters.put(m.getId(), m); } }
public void action(String dir) { // try{ // Thread.sleep(650); // } catch(Exception e) {} System.out.print("\033\143"); if (getStage() == 99) { Monster drag = new Monster(); drag.DRAGONTemplate("Ebonmaw, the Wicked Dragon", 1); System.out.print("You enter a room..."); pauseSleep(900); System.out.println(" It seems to be empty..."); pauseSleep(900); System.out.println("~ I am Ebonmaw... ~"); pauseSleep(900); System.out.println("THE DRAGON LORD!"); pauseSleep(500); System.out.println("Ebonmaw, the Wicked Dragon crashed down from the ceiling!"); Battle boss1 = new Battle(player, drag, getStage()); if (drag.health() <= 0) { System.out.println("You have vanquished the Wicked Dragon!"); pauseSleep(1300); System.out.println( "... You look around his fallen body and see his scales lying around... "); pauseSleep(1500); Scanner dragChoice = new Scanner(System.in); System.out.println("What do you make? A sword? A shield? Armor?"); System.out.println("~A helpful sparrow says~ : Enter sword, shield, or armor!"); System.out.println("Sword grants strength! Shield grants dexterity! Armor grants health!"); System.out.println("~The helpful sparrow flies away~"); boolean chosen = false; while (!chosen) { String resp = dragChoice.next(); if (resp.toUpperCase().equals("SWORD")) { player.setStrength(player.strength() + 10); System.out.println("You have gained 10 strength!"); chosen = true; } else if (resp.toUpperCase().equals("SHIELD")) { player.setDexterity(player.dexterity() + 10); System.out.println("You have gained 10 dexterity!"); chosen = true; } else if (resp.toUpperCase().equals("ARMOR")) { player.setMaxHealth(player.maxHealth() + 10); player.setHealth(player.maxHealth()); System.out.println("You have gained 10 health!"); chosen = true; } else { System.out.println("Invalid choice! sword/shield/armor"); } } } setStage(getStage() + 1); } else if (getStage() == 149) { Monster pred = new Monster(); pred.PREDATORTemplate("Rangor, the Esteemed Hunter", 1); System.out.println("*shuffle swish shuffle swoosh*"); pauseSleep(400); System.out.println("... What was that?"); pauseSleep(1000); System.out.println("*swoosh!*"); System.out.println("...!"); pauseSleep(400); System.out.println("A knife barely misses your head!"); pauseSleep(500); System.out.println("I am Rangor... You are my prey..."); pauseSleep(1000); Battle boss2 = new Battle(player, pred, getStage()); System.out.println("You have vanquished Rangor, the Esteemed Hunter..."); pauseSleep(1000); System.out.print("..."); pauseSleep(1500); System.out.println("The head of Rangor begins to glow..."); pauseSleep(1000); System.out.println("He bestows you with the gift of Ferocity:"); System.out.println("+ 10 Strength"); System.out.println("+ 10 Speed"); player.setStrength(player.strength() + 10); player.setSpeed(player.speed() + 10); pauseSleep(1300); setStage(getStage() + 1); } else if (getStage() == 199) { Monster gate = new Monster(); gate.GATEKEEPERTemplate("Zim 'Ann Skior, the Dungeon Master", 1); System.out.println("You dare try to escape MY dungeon?"); pauseSleep(750); System.out.println("Foolish mortal..."); pauseSleep(500); System.out.println("*A beam of light appears!*"); pauseSleep(750); System.out.println("You will never escape..."); pauseSleep(600); Battle boss3 = new Battle(player, gate, getStage()); setStage(getStage() + 1); } else { currRm.move(dir, player); // player.setExperience(player.experience() + 2); // System.out.println("You have gained 2 experience."); } }