Ejemplo n.º 1
1
  public Location getFaceLocationFromMe(Location location) {
    try {
      // citizens - https://github.com/fullwall/Citizens
      Location loc = this.getBukkitEntity().getLocation();
      double xDiff = location.getX() - loc.getX();
      double yDiff = location.getY() - loc.getY();
      double zDiff = location.getZ() - loc.getZ();

      double DistanceXZ = Math.sqrt(xDiff * xDiff + zDiff * zDiff);
      double DistanceY = Math.sqrt(DistanceXZ * DistanceXZ + yDiff * yDiff);
      double yaw = (Math.acos(xDiff / DistanceXZ) * 180 / Math.PI);
      double pitch = (Math.acos(yDiff / DistanceY) * 180 / Math.PI) - 90;
      if (zDiff < 0.0) {
        yaw = yaw + (Math.abs(180 - yaw) * 2);
      }
      Location finalloc =
          new Location(
              loc.getWorld(), loc.getX(), loc.getY(), loc.getZ(), (float) yaw - 90, (float) pitch);
      return finalloc;

    } catch (Exception e) {
      e.printStackTrace();
      return null;
    }
  }
Ejemplo n.º 2
0
  public void onNpcVsNpcDamage(myNPC anpc) {

    this.setFollow(anpc.npc.getBukkitEntity());
    this.setAggro(anpc.npc.getBukkitEntity());

    try {
      // default npcvsnpc dmg
      int dmgdone = 30;
      this.hp = this.hp - dmgdone;
      this.parent.requipArmour();

      if (this.hp < 1) {
        anpc.npc.setFollow(null);
        anpc.npc.setAggro(null);

        // System.out.println("I just died!!");
        this.onDeathFromNPC(anpc.npc.getBukkitEntity());
        this.parent.parent.onNPCDeath(this);
      }
    } catch (Exception e) {
      this.setFollow(null);
      this.setAggro(null);
      e.printStackTrace();
    }
  }
Ejemplo n.º 3
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();
    }
  }