예제 #1
0
  public void attackLivingEntity(LivingEntity ent) {
    try {
      // check the ent has some health at least

      if (ent.getHealth() > 0) {
        if ((ent.getHealth() - dmg) <= 0) {
          ent.damage(200);
          setFollow(null);
          setAggro(null);
          if (ent instanceof Player) {
            ((Player) ent)
                .getServer()
                .broadcastMessage(
                    ((Player) ent).getName() + " was slaughtered by " + getName() + ".");
            ((Player) ent).sendMessage("You have been slaughtered by " + getName());
            this.onKilled(ent);

            // mark player dead
            for (myPlayer player : this.parent.parent.universe.players.values()) {
              // deal with player death changes
              if (player.player == ent) {
                // System.out.println("npcx : player about to respawn, assigning them to the dead
                // list");
                player.dead = true;
                ((Player) ent).sendMessage("You have been slaughtered by " + getName());
              }
            }
          }
        } else {
          if (ent instanceof Monster) {

            double myx = this.getBukkitEntity().getLocation().getX();
            double myy = this.getBukkitEntity().getLocation().getY();
            double myz = this.getBukkitEntity().getLocation().getZ();

            double tx = ent.getLocation().getX();
            double ty = ent.getLocation().getY();
            double tz = ent.getLocation().getZ();

            double diffx = myx - tx;
            double diffy = myy - ty;
            double diffz = myz - tz;

            if (diffx < 2 && diffx > -2 && diffy < 2 && diffy > -2 && diffz < 2 && diffz > -2) {

              // System.out.println("Gahh! ");
              this.mcEntity.animateArmSwing();
              ent.damage(dmg);
            }

          } else {
            if (ent instanceof Player) {

              double myx = this.getBukkitEntity().getLocation().getX();
              double myy = this.getBukkitEntity().getLocation().getY();
              double myz = this.getBukkitEntity().getLocation().getZ();

              double tx = ent.getLocation().getX();
              double ty = ent.getLocation().getY();
              double tz = ent.getLocation().getZ();

              double diffx = myx - tx;
              double diffy = myy - ty;
              double diffz = myz - tz;

              if (diffx < 2 && diffx > -2 && diffy < 2 && diffy > -2 && diffz < 2 && diffz > -2) {
                // System.out.println("Processed this as a player "+ent.getClass().toString());
                this.mcEntity.animateArmSwing();
                ent.damage(dmg);
              }
            }
          }
        }
      } else {
        // no health, not worth the effort
        setFollow(null);
        setAggro(null);
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
예제 #2
0
  public void doThinkGreater() {
    if (this.hp > 0) {
      // System.out.println("npcx : think");
      if (this.parent != null) {
        //
        // PLAYER TARGET DISTANCE
        //
        for (myPlayer p : this.parent.parent.universe.players.values()) {
          if (p.target == this) {
            double x1 = p.player.getLocation().getX();
            double y1 = p.player.getLocation().getY();
            double z1 = p.player.getLocation().getZ();

            double x2 = this.getBukkitEntity().getLocation().getX();
            double y2 = this.getBukkitEntity().getLocation().getY();
            double z2 = this.getBukkitEntity().getLocation().getZ();
            int xdist = (int) (x1 - x2);
            int ydist = (int) (y1 - y2);
            int zdist = (int) (z1 - z2);

            if ((xdist < -3 || xdist > 3)
                || (ydist < -3 || ydist > 3)
                || (zdist < -3 || zdist > 3)) {
              Debug(1, "player out of range, removing target");
              p.target = null;
              p.player.sendMessage("You have lost your target");
            }
            // remove target
          }
        }

        // END PLAYER TARGET DISTANCE
      }
      // NPC RETURN TO SPAWN IDLE
      if (this.parent.pathgroup != null) {
        // let them carry on for guard sequences

        // return;
      } else {

        if (getFollow() == null && getAggro() == null) {
          // System.out.println("npcx : moving  ["+ spawnx + "] ["+ spawny + "] ["+ spawnz + "]");
          // Requip my armour
          this.parent.requipArmour();

          // not aggrod or following, time to go home :)
          double x2 = this.getBukkitEntity().getLocation().getX();
          double y2 = this.getBukkitEntity().getLocation().getY();
          double z2 = this.getBukkitEntity().getLocation().getZ();

          if (!(x2 == spawnx && y2 == spawny && z2 == spawnz)) {

            //	System.out.println("Going home");

            Double yaw2 = new Double(spawnyaw);
            Double pitch2 = new Double(spawnpitch);

            Location loc =
                new Location(
                    this.getBukkitEntity().getWorld(),
                    spawnx,
                    spawny,
                    spawnz,
                    yaw2.floatValue(),
                    pitch2.floatValue());

            moveCloserToLocation(loc);
          }
        }
      }

      //
      // NPC FOLLOW
      //

      if (getFollow() instanceof LivingEntity) {
        if (this.getFollow() != null) {
          Debug(
              1,
              this.getName() + ":follow:" + getFollow().toString() + ":" + getFollow().getHealth());
          // lets follow this entity
          if (this.hp == 0 || this.getFollow().getHealth() == 0) {

            // they're dead, stop following
            this.setFollow(null);
            this.setAggro(null);

          } else {
            Location locforface = this.getFaceLocationFromMe(getFollow().getLocation());
            Location modifiedloc =
                new Location(
                    getBukkitEntity().getWorld(),
                    getBukkitEntity().getLocation().getX(),
                    getBukkitEntity().getLocation().getY(),
                    getBukkitEntity().getLocation().getZ(),
                    locforface.getYaw(),
                    locforface.getPitch());
            forceMove(modifiedloc);

            Debug(
                1,
                this.getName()
                    + ":follow:"
                    + getFollow().toString()
                    + ":"
                    + getFollow().getHealth());

            // they're alive lets check distance
            double x1 = this.getFollow().getLocation().getX();
            double y1 = this.getFollow().getLocation().getY();
            double z1 = this.getFollow().getLocation().getZ();

            double x2 = this.getBukkitEntity().getLocation().getX();
            double y2 = this.getBukkitEntity().getLocation().getY();
            double z2 = this.getBukkitEntity().getLocation().getZ();
            int xdist = (int) (x1 - x2);
            int ydist = (int) (y1 - y2);
            int zdist = (int) (z1 - z2);

            if (xdist > -30
                && xdist < 30
                && ydist > -30
                && ydist < 30
                && zdist > -30
                && zdist < 30) {
              // face target
              // this.getFaceLocationFromMe(this.getFollow().getLocation());

              if (isLineOfSight(this.getFollow())) {
                Debug(1, this.getName() + ":Following Entity near to me");
                this.moveCloserToLocation(this.getFollow().getLocation());

              } else {
                Debug(1, this.getName() + ":Stopped following near to me (no line of sight)");
                this.setFollow(null);
                this.setAggro(null);
              }
            } else {
              // too far for me
              Debug(1, this.getName() + ":Stopped following near to me (too far)");
              this.setFollow(null);
              this.setAggro(null);
            }
          }
        }
      }

      //
      // NPC ATTACK
      //

      if (getAggro() instanceof LivingEntity) {
        // lets follow this entity
        if (this.getAggro() != null) {
          if (this.hp == 0) {
            this.setFollow(null);
            this.setAggro(null);
          } else {
            attackLivingEntity(getAggro());
          }
        }
      }
    }
  }