Exemple #1
0
    private boolean entityInRange(BaseEntity entity) {
      switch (TYPE) {
        case 0:
          Player player = (Player) entity;

          return SETTINGS.isEmpty()
              || (SETTINGS.charAt(0) == 'g' && player.isInGroup(SETTINGS.substring(2)))
              || (SETTINGS.charAt(0) == 'p'
                  && player.getName().equalsIgnoreCase(SETTINGS.substring(2)));
        case 1:
        case 2:
          return true;
        case 3:
          if ((entity.isMob() || entity.isAnimal()) && entity instanceof Mob) {
            Mob mob = (Mob) entity;
            if (SETTINGS.isEmpty() || mob.getName().equalsIgnoreCase(SETTINGS)) return true;
          }
          break;
        case 4:
        case 5:
          return true;
      }

      return false;
    }
Exemple #2
0
  public Npc(NPCLoc loc) {
    for (int i : Constants.GameServer.UNDEAD_NPCS) {
      if (loc.getId() == i) {
        this.undead = true;
      }
    }
    for (int i : Constants.GameServer.ARMOR_NPCS) {
      if (loc.getId() == i) {
        this.hasArmor = true;
      }
    }

    def = EntityHandler.getNpcDef(loc.getId());
    curHits = def.getHits();

    this.loc = loc;
    super.setID(loc.getId());
    this.setLocation(Point.location(loc.startX(), loc.startY()), true);
    super.setCombatLevel(
        Formulae.getCombatLevel(def.getAtt(), def.getDef(), def.getStr(), def.getHits(), 0, 0, 0));

    if (this.loc.getId() == 189
        || this.loc.getId() == 53
        || this.loc.getId() == 19) { // this should not be here
      this.def.aggressive = true;
    }
  }
Exemple #3
0
  @Override
  public void update(double t) {

    { // UPDATE TOWERS
      for (Tile[] tiles : getTiles())
        for (Tile tile : tiles) if (tile.hasTower()) tile.getTower().update(t);
    }

    { // UPDATE BULLETS
      final Iterator<Bullet> it = getBullets().iterator();

      while (it.hasNext()) {

        final Bullet b = it.next();

        if (b.update(t)) it.remove();
      }
    }

    { // UPDATE MOBS
      final Iterator<Mob> it = getMobs().iterator();

      while (it.hasNext()) {

        final Mob m = it.next();

        m.update(t);

        if (m.shouldBeRemoved()) {
          m.onRemove(getGame());
          it.remove();
        }
      }
    }
  }
  ArrayList<Mob> getMobs() {
    ArrayList<Mob> realMobs = new ArrayList<Mob>();

    for (JsonMob jm : mobs) {

      Mob xyz = null;

      Class<?> cl;
      try {
        cl = Class.forName(jm.getName());

        Constructor<?> con = cl.getConstructor(float.class, float.class);
        xyz = (Mob) con.newInstance(jm.getX(), jm.getY());
      } catch (ClassNotFoundException e) {
        e.printStackTrace();
      } catch (NoSuchMethodException e) {
        e.printStackTrace();
      } catch (SecurityException e) {
        e.printStackTrace();
      } catch (InstantiationException e) {
        e.printStackTrace();
      } catch (IllegalAccessException e) {
        e.printStackTrace();
      } catch (IllegalArgumentException e) {
        e.printStackTrace();
      } catch (InvocationTargetException e) {
        e.printStackTrace();
      }

      xyz.setID(jm.getID());

      realMobs.add(xyz);
    }
    return realMobs;
  }
Exemple #5
0
  public void moveToTarget() {
    int px = target.getX();
    int py = target.getY();

    int tileSize = World.current.tileSize;

    Vector2 start = new Vector2(getX() / tileSize, getY() / tileSize);
    Vector2 goal = new Vector2(px / tileSize, py / tileSize);

    path = World.current.findPath(start, goal);

    if (path != null) {
      if (path.size() > 0) {

        Vector2 vec = path.get(path.size() - 1).tile;
        if (position.x < (vec.x * tileSize)) {
          move(1, 0);
        }

        if (position.x > (vec.x * tileSize)) {
          move(-1, 0);
        }

        if (position.y < (vec.y * tileSize)) {
          move(0, 1);
        }

        if (position.y > (vec.y * tileSize)) {
          move(0, -1);
        }
      }
    }
  }
Exemple #6
0
  public void setGiveItem(String give_) {
    String elements[] = give_.split(" ");

    if (elements.length < 3) {
      LOGGER.error("Give needs to be [mob] [room] [item] <load percentage>");
      return;
    }

    Mob mob = World.getRoom(elements[1]).getMob(elements[0]);

    if (mob == null) {
      LOGGER.error("Mob was null for id: " + elements[0]);
      return;
    }

    Item item = EntityProvider.createItem(elements[2]);

    if (item == null) {
      LOGGER.error("Item was null for id: " + elements[2]);
      return;
    }

    if (elements.length == 4) {
      item.setLoadPercentage(Integer.parseInt(elements[3]));
    }

    if (item.isLoaded()) {
      mob.getInventory().add(item); // Gives to room mob only.
    }
  }
  public void setMobs(ArrayList<Mob> realMobs) {

    for (Mob m : realMobs) {

      JsonMob jm = new JsonMob(m.getX(), m.getY(), m.getClass().getName());
      jm.setID(m.getID());
      mobs.add(jm);
    }
  }
Exemple #8
0
  protected int countMobs() {
    int counter = 0;

    for (Mob m : VolatileEntities.getMobs()) {
      if (!m.isDead() && !m.getSpawnZone().isNull())
        if ((m != null) && (m.getSpawnZone().equals(this.m))) {
          counter++;
        }
    }

    return counter;
  }
Exemple #9
0
  /**
   * Mob then item space seperated then load percentage for item
   *
   * @param give_
   */
  public void setGive(String give_) {
    String elements[] = give_.split(" ");

    if (elements.length < 2) {
      LOGGER.error("Give needs to be [mob] [item] <load percentage>");
      return;
    }
    Mob mob = World.getMob(elements[0]);
    Item item = EntityProvider.createItem(elements[1]);
    mob.getInventory().add(item); // Gives to template mob only

    if (elements.length == 3) {
      item.setLoadPercentage(Integer.parseInt(elements[2]));
    }
  }
  @Override
  protected boolean act() {
    boolean justAlerted = alerted;
    boolean returnValue = super.act();

    if (justAlerted && (!Dungeon.level.mobs.isEmpty())) {
      for (Mob mob : Dungeon.level.mobs) {
        if ((mob instanceof BrownWolf || mob instanceof GrayWolf) && (mob != this)) {
          mob.beckon(target);
        }
      }
    }

    return returnValue;
  }
Exemple #11
0
  @Override
  public void die(Object cause) {

    Badges.Badge badgeToCheck = null;
    switch (Dungeon.hero.heroClass) {
      case WARRIOR:
        badgeToCheck = Badge.MASTERY_WARRIOR;
        break;
      case MAGE:
        badgeToCheck = Badge.MASTERY_MAGE;
        break;
      case ROGUE:
        badgeToCheck = Badge.MASTERY_ROGUE;
        break;
      case HUNTRESS:
        badgeToCheck = Badge.MASTERY_HUNTRESS;
        break;
    }
    if (!Badges.isUnlocked(badgeToCheck) || Dungeon.hero.subClass != HeroSubClass.NONE) {
      Dungeon.level.drop(new TomeOfMastery(), pos).sprite.drop();
    }

    GameScene.bossSlain();
    Dungeon.level.drop(new SkeletonKey(), pos).sprite.drop();
    super.die(cause);

    Badges.validateBossSlain();

    yell(Game.getVar(R.string.Tengu_Info1));
  }
 @Override
 public void damage(int dmg, Object src) {
   super.damage(dmg, src);
   if (src instanceof ToxicGas) {
     ((ToxicGas) src).clear(pos);
   }
 }
  @Override
  public void die(Object cause) {

    GameScene.bossSlain();
    Dungeon.level.drop(new ArmorKit(), pos).sprite.drop();

    if (Dungeon.gamemode == GameMode.REGULAR) {
      Dungeon.level.drop(new SkeletonKey(Dungeon.depth), pos).sprite.drop();
    } else if (Dungeon.gamemode == GameMode.ARENA) {
      // Level up
      Dungeon.hero.earnExp(Dungeon.hero.maxExp());

      ArenaShopKey key = new ArenaShopKey();
      key.identify();
      Dungeon.level.drop(key, pos).sprite.drop();
    }

    super.die(cause);

    Badges.validateBossSlain();

    LloydsBeacon beacon = Dungeon.hero.belongings.getItem(LloydsBeacon.class);
    if (beacon != null) {
      beacon.upgrade();
      GLog.p("Your beacon grows stronger!");
    }

    yell("You cannot kill me, " + Dungeon.hero.givenName() + "... I am... immortal...");
  }
Exemple #14
0
  private boolean spawnMob() {
    if (myConfig.getDisabledWorlds().contains(world)) return false;
    final int maxHeight = 10;

    int x = this.radius - (int) (Math.random() * this.radius * 2.0D);
    int z = this.radius - (int) (Math.random() * this.radius * 2.0D);
    long d = x * x + z * z;
    if (d >= radius * radius) {
      x *= radius / (2 * d);
      z *= radius / (2 * d);
    }
    Location l1 =
        new Location(
            Bukkit.getWorld(this.world), this.m.getX() + x, this.m.getY(), this.m.getZ() + z);
    int p = l1.getBlock().getType().equals(Material.AIR) ? -1 : 1;
    for (int h = 0; h < maxHeight; h++) {
      l1.setY(this.m.getY() + h * p);
      if ((!l1.getBlock().getType().equals(Material.AIR))
          && (l1.getBlock().getRelative(BlockFace.UP).getType().equals(Material.AIR))) {
        l1.setY(l1.getY() + 2.0D);
        return Mob.spawnEntity(this.mob, l1, this.m) != null;
      }
    }
    return false;
  }
 @Override
 public void move(int step) {
   if (state == FLEEING) {
     GameScene.add(Blob.seed(pos, Random.Int(5, 7), Web.class));
   }
   super.move(step);
 }
    @Override
    public void die(Object cause) {
      super.die(cause);

      if (Dungeon.visible[pos]) {
        Sample.INSTANCE.play(Assets.SND_BONES);
      }
    }
  @Override
  public void die(Object cause) {
    Dungeon.level.drop(new MysteryMeat(), pos).sprite.drop();
    super.die(cause);

    Statistics.piranhasKilled++;
    Badges.validatePiranhasKilled();
  }
  @Override
  public void damage(int dmg, Object src) {

    if (state == PASSIVE) {
      state = HUNTING;
    }

    super.damage(dmg, src);
  }
 @Override
 public void takeHit(int damage, int damageSpecial, int hitDirection) {
   if (!attaquing) {
     super.takeHit(
         damage,
         damageSpecial,
         hitDirection); // To change body of generated methods, choose Tools | Templates.
   }
 }
Exemple #20
0
 public void attemptAttack() {
   if (target != null) {
     if (Vector2.distance(position, target.position) <= 64) {
       switch (textureIndex) {
         case 0:
           target.hurt(1, 0, -30);
           break;
         case 1:
           target.hurt(1, 0, 30);
           break;
         case 2:
           target.hurt(1, 30, 0);
           break;
         case 3:
           target.hurt(1, -30, 0);
           break;
       }
     }
   }
 }
Exemple #21
0
  /**
   * Spawns a mob somewhere on the map. Ensures it doesn't intersect anything and is on a spawn tile
   *
   * @param mob
   * @return
   */
  public boolean spawnMob(Mob mob) {
    float x = mob.getX();
    float y = mob.getY();
    TextureSet textureSet = mob.getWalkingTextureSet();

    // Check mob isn't out of bounds.
    if (x < 0
        || x > getMapWidth() - textureSet.getWidth()
        || y > getMapHeight() - textureSet.getHeight()) {
      return false;
    }

    // Check mob doesn't intersect anything.
    for (Entity entity : entities) {
      if (entity instanceof Character
          && (mob.intersects(entity.getX(), entity.getY(), entity.getWidth(), entity.getHeight())
              || mob.collidesX(0)
              || mob.collidesY(0))) {
        return false;
      }
    }

    if (getSpawnLayer().getCell((int) x / getTileWidth(), (int) y / getTileHeight()) == null) {
      return false;
    }

    entities.add(mob);
    return true;
  }
Exemple #22
0
  @Override
  public void setLocation(Point p, boolean teleported) {
    Area r = Area.getArea(p);
    Area cur = area.get();

    if (cur != r) {
      if (cur != null) {
        cur.removeNpc(this);
      }
      r.addNpc(this);
      area.getAndSet(r);
    }
    super.setLocation(p, teleported);
  }
Exemple #23
0
  /**
   * Creates a mob and adds it to the list of entities, but only if it doesn't intersect with
   * another character.
   *
   * @param x the initial x coordinate
   * @param y the initial y coordinate
   * @param health the initial health of the mob
   * @param textureSet the texture set to use
   * @param speed how fast the mob moves in pixels per second
   * @return true if the mob was successfully added, false if there was an intersection and the mob
   *     wasn't added
   */
  public boolean createMob(
      Mob mob, float x, float y, int health, TextureSet textureSet, int speed) {

    // Check mob isn't out of bounds.
    if (x < 0
        || x > getMapWidth() - textureSet.getWidth()
        || y > getMapHeight() - textureSet.getHeight()) {
      return false;
    }

    // Check mob doesn't intersect anything.
    for (Entity entity : entities) {
      if (entity instanceof Character
          && (mob.intersects(entity.getX(), entity.getY(), entity.getWidth(), entity.getHeight())
              || mob.collidesX(0)
              || mob.collidesY(0))) {
        return false;
      }
    }

    entities.add(mob);
    return true;
  }
Exemple #24
0
  public void updatePosition() {
    long now = GameEngine.getAccurateTimestamp();
    Player victim = findVictim();

    if (!isBusy() && def.isAggressive() && now - getCombatTimer() > 3000 && victim != null) {
      resetPath();

      victim.resetPath();
      victim.resetAll();
      victim.setStatus(Action.FIGHTING_MOB);
      victim.getActionSender().sendSound("underattack");
      victim.getActionSender().sendMessage("You are under attack!");

      if (victim.isSleeping()) {
        victim.getActionSender().sendWakeUp(false, false);
        victim.getActionSender().sendFatigue(victim.getFatigue());
      }

      this.setLocation(victim.getLocation(), true);

      for (Player p : getViewArea().getPlayersInView()) {
        p.removeWatchedNpc(this);
      }

      victim.setBusy(true);
      victim.setSprite(9);
      victim.setOpponent(this);
      victim.setCombatTimer();

      setBusy(true);
      setSprite(8);
      setOpponent(victim);
      setCombatTimer();
      FightEvent fighting = new FightEvent(victim, this, true);
      fighting.setLastRun(0);
      World.getWorld().getDelayedEventHandler().add(fighting);
    }

    if (now - lastMovement > 2200) {
      lastMovement = now;
      int rand = DataConversions.random(0, 1);
      if (!isBusy() && finishedPath() && rand == 1 && !isRemoved()) {
        int newX = DataConversions.random(loc.minX(), loc.maxX());
        int newY = DataConversions.random(loc.minY(), loc.maxY());
        setPath(new Path(getX(), getY(), newX, newY));
      }
    }

    super.updatePosition();
  }
Exemple #25
0
  protected void die() {
    super.die(); // Parent death call

    int count = random.nextInt(2) + 1; // Random amount of cloth to drop from 1 to 2
    for (int i = 0; i < count; i++) { // loops through the count
      level.add(
          new ItemEntity(
              new ResourceItem(Resource.cloth),
              x + random.nextInt(11) - 5,
              y + random.nextInt(11) - 5)); // creates cloth
    }

    if (level.player != null) { // if player is on zombie level
      level.player.score += 50 * lvl; // add score for zombie death
    }
  }
Exemple #26
0
  public void tick() {
    super.tick(); // ticks the Entity.java part of this class

    if (level.player != null
        && randomWalkTime
            == 0) { // checks if player is on zombies level and if there is no time left on timer
      int xd = level.player.x - x; // gets the horizontal distance between the zombie and the player
      int yd = level.player.y - y; // gets the vertical distance between the zombie and the player
      if (xd * xd + yd * yd < 50 * 50) { // more evil distance checker code
        xa = 0; // sets direction to nothing
        ya = 0;
        if (xd < 0)
          xa =
              -1; // if the horizontal difference is smaller than 0, then the x acceleration will be
                  // 1 (negative direction)
        if (xd > 0)
          xa =
              +1; // if the horizontal difference is larger than 0, then the x acceleration will be
                  // 1
        if (yd < 0)
          ya =
              -1; // if the vertical difference is smaller than 0, then the y acceleration will be 1
                  // (negative direction)
        if (yd > 0)
          ya = +1; // if the vertical difference is larger than 0, then the y acceleration will be 1
      }
    }

    // halp david! I have no idea what the & sign does in maths! Unless it's a bit opereator, in
    // which case I'm rusty
    // Calm down, go google "java bitwise AND operator" for information about this. -David
    int speed = tickTime & 1; // Speed is either 0 or 1 depending on the tickTime
    if (!move(xa * speed, ya * speed)
        || random.nextInt(200)
            == 0) { // moves the zombie, doubles as a check to see if it's still moving -OR- random
                    // chance out of 200
      randomWalkTime = 60; // sets the not-so-random walk time to 60
      xa =
          (random.nextInt(3) - 1)
              * random.nextInt(2); // sets the acceleration to random i.e. idling code
      ya =
          (random.nextInt(3) - 1)
              * random.nextInt(2); // sets the acceleration to random i.e. idling code
    }
    if (randomWalkTime > 0) randomWalkTime--; // if walk time is larger than 0, decrement!
  }
Exemple #27
0
  public void update() {
    super.update();

    if (health <= 0) {
      die();
    }

    attackTimer++;

    if (attackTimer % 150 == 0) {
      attemptAttack();
    }
    ArrayList<Player> nearMobs = World.current.getPlayersInRadius(this, World.current.tileSize * 4);

    if (nearMobs.size() > 0) {
      if (target == null) target = nearMobs.get(0);
    }

    if (target != null) {
      moveToTarget();
    } else {
      int changeDir = random.nextInt(100);
      if (changeDir == 5) {
        direction = random.nextInt(5);
      }

      if (direction == 1) {
        move(1, 0);
      } else if (direction == 2) {
        move(-1, 0);
      } else if (direction == 3) {
        move(0, 1);
      } else if (direction == 4) {
        move(0, -1);
      }
    }
  }
  public void run() {
    LivingThing thnStore;
    Mob mobStore;
    Condition cndStore;
    Script scrStore;
    int i, i2;
    while (true) {
      try {
        // 1000 milliseconds(1 second) per tick
        lngPause = 1000L - (System.currentTimeMillis() - lngTime);
        if (lngPause > 0) Thread.currentThread().sleep(lngPause);
        lngTime = System.currentTimeMillis();

        for (i = 0; i < engGame.vctMobs.size(); i++) {
          mobStore = (Mob) engGame.vctMobs.elementAt(i);
          if (mobStore.intLocX == -6) {
            mobStore.hp++;
            if (mobStore.hp > -1) {
              mobStore.changeLocBypass(mobStore.originalX, mobStore.originalY);
              mobStore.hp = mobStore.maxhp;
            }
          } else {
            try {
              if (engGame.blnAI && mobStore.blnCanSeePlayer && (mobStore.fctFaction != null)) {
                mobStore.fctFaction.runAI(mobStore);
              }
            } catch (Exception e) {
              mobStore.blnCanSeePlayer = false;
              engGame.log.printError(
                  "TickThread.run():While trying to runAI for mob \"" + mobStore.strName + "\".",
                  e);
            }
            synchronized (mobStore.vctMovement) {
              if (mobStore.vctMovement.size() > 0) {
                try {
                  String strStore = (String) mobStore.vctMovement.elementAt(0);
                  char charStore = strStore.charAt(0);
                  switch (charStore) {
                    case 'n':
                      mobStore.moveN();
                      break;
                    case 's':
                      mobStore.moveS();
                      break;
                    case 'w':
                      mobStore.moveW();
                      break;
                    case 'e':
                      mobStore.moveE();
                      break;
                  }
                  mobStore.vctMovement.removeElement(mobStore.vctMovement.elementAt(0));
                } catch (Exception e) {
                  engGame.log.printError("TickThread.run():At movement tick for mobs", e);
                }
              }
            }
          }
        }

        for (i = 0; i < engGame.vctCheckConditions.size(); i++) {
          thnStore = (LivingThing) engGame.vctCheckConditions.elementAt(i);
          i2 = 0;
          while (i2 < thnStore.vctConditions.size()) {
            cndStore = (Condition) thnStore.vctConditions.elementAt(i2);
            if (cndStore.intTicksPast >= cndStore.intOccurance) {
              try {
                if (cndStore.strOnOccurance != null) {
                  scrStore = new Script("scripts/" + cndStore.strOnOccurance, engGame, false);
                  scrStore.varVariables.addVariable("trigger", thnStore);
                  scrStore.varVariables.addVariable("condition", cndStore.strName);
                  scrStore.runScript();
                  scrStore.close();
                }
                if (cndStore.intDuration > 0) cndStore.intDuration--;
                if (cndStore.intDuration == 0) {
                  try {
                    if (cndStore.strOnEnd != null) {
                      scrStore = new Script("scripts/" + cndStore.strOnEnd, engGame, false);
                      scrStore.varVariables.addVariable("trigger", thnStore);
                      scrStore.varVariables.addVariable("condition", cndStore.strName);
                      scrStore.runScript();
                      scrStore.close();
                    }
                    thnStore.vctConditions.removeElementAt(i2);
                  } catch (Exception e) {
                  }
                } else i2++;
                cndStore.intTicksPast = 1;
              } catch (Exception e) {
                engGame.log.printError(
                    "ThreadTicks.run():While executing occurance of condition " + cndStore.strName,
                    e);
                i2++;
              }
            } else {
              cndStore.intTicksPast++;
              i2++;
            }
          }
        }

        if (tick > 120) tick = 0;
        tick++;
      } catch (Exception e) {
        engGame.log.printError("ThreadTicks.run()", e);
      }
    }
  }
Exemple #29
0
  @Test
  public void testUnhide() {

    Mob player1Mob = TestHelper.makeDefaultPlayerMob("player1");

    // Teach rescue to player
    Ability ability = new Ability("hide", 100);
    player1Mob.getLearned().add(ability);
    World.add(new BaseSkill("hide"));

    Race human = new Race();
    World.getInstance().addToWorld(human);

    // have test resource file to load in a mob sheep and mob player
    // test files.
    Mob sheepMob = new Mob();
    sheepMob.setNameAndId("sheep");
    sheepMob.setAlias("sheep");
    sheepMob.setHp("2d10+50");

    Room whiteRoom = new Room();

    whiteRoom.add(sheepMob);
    whiteRoom.add(player1Mob);

    Command hide = new Hide();
    hide.execute(player1Mob, player1Mob.getAlias());

    assertEquals("player should be hidden", true, player1Mob.isHidden());

    Command unhide = new Unhide();
    unhide.execute(player1Mob, player1Mob.getAlias());

    assertEquals("player should be unhidden", false, player1Mob.isHidden());

    Command kill = new Kill();

    assertEquals("Check sheep name", "sheep", sheepMob.getName());
    assertNotNull("Check sheep exists in the room", whiteRoom.getMob(sheepMob.getName()));
    assertEquals("Check sheep is in the room", sheepMob, whiteRoom.getMob(sheepMob.getName()));

    World.getInstance(); // Starts time.

    // kill.execute(player1Mob, sheepMob.getName());
    kill.execute(sheepMob, player1Mob.getName());

    // Check they are targeting each other.
    assertEquals("sheep should not target player1", player1Mob, sheepMob.getFight().getTarget());
  }
Exemple #30
0
 @Override
 public void restoreFromBundle(Bundle bundle) {
   super.restoreFromBundle(bundle);
   chainsUsed = bundle.getBoolean(CHAINSUSED);
 }