Esempio n. 1
0
 private void processRandomWalk() {
   if (!World.getInstance().getRegions().regionLoaded(this.getCurrentTile().getRegionID())) {
     return; // Don't walk unless players are already in the region
   }
   if (Math.random() * 1000.0 > 10.0) {
     return; // Only process 1/100 of the time
   }
   int stepsX = (int) Math.round(Math.random() * 10.0 - 5.0);
   int stepsY = (int) Math.round(Math.random() * 10.0 - 5.0);
   if (stepsX != 0 || stepsY != 0) {
     int destX = getCurrentTile().getX() + stepsX;
     int destY = getCurrentTile().getY() + stepsY;
     int spawnX = spawnCoords.getX();
     int spawnY = spawnCoords.getY();
     if (destX > spawnX + walkRange) {
       destX = spawnX + walkRange;
     } else if (destX < spawnX - walkRange) {
       destX = spawnX - walkRange;
     }
     if (destY > spawnY + walkRange) {
       destY = spawnY + walkRange;
     } else if (destY < spawnY - walkRange) {
       destY = spawnY - walkRange;
     }
     this.queueUpdateBlock(new FaceEntityBlock(null));
     this.getMovement().moveTo(destX, destY);
   }
 }
Esempio n. 2
0
 /**
  * Handles the NPC drops
  *
  * @param visibleTo The player who can see the drops by default (other players can see them after
  *     a period of time)
  */
 public void sendDrop(Entity killer) {
   Region region =
       World.getInstance().getRegions().getRegionByID(this.getCurrentTile().getRegionID());
   if (region != null && region.isLoaded()) {
     for (NpcDrops loot : NpcDropParser.forID(this.getID()).getLootChance(0)) {
       if (itemDropCalls.contains(loot.getItemID())) {
         World.getInstance()
             .sendBroadcast(
                 api.getName(killer)
                     + " has received "
                     + api.getItemType(loot.getItemID()).name.toString()
                     + " drop!");
       }
       region.dropItem(
           loot.getItemID(),
           loot.getRandomNumberFrom(loot.getMinAmount(), loot.getMaxAmount()),
           null,
           this.getCurrentTile());
     }
   }
 }
Esempio n. 3
0
 public void destroy() {
   setExists(false);
   if (this.getIndex() != -1) {
     World.getInstance().removeNPC(this);
   }
 }
Esempio n. 4
0
  /**
   * Handles an interaction with this ground item
   *
   * @param player The player interacting with the object
   * @param option The option selected
   * @return True if the interaction was successful, false otherwise
   */
  public boolean interact(Player player, OptionButton option) {
    if (owner != null && owner.getUserHash() != player.getUserHash()) {
      logger.warn(
          "Player "
              + player.getName()
              + " attempted to interact with item "
              + this.getId()
              + ", which is currently only visible to "
              + owner.getName());
      return true;
    }
    if (OptionButton.SIX.equals(option)) {
      this.examine(player);
      return true;
    }
    ScriptEventType eventType;
    switch (option) {
      case ONE:
        eventType = ScriptEventType.OPOBJ1;
        break;
      case TWO:
        eventType = ScriptEventType.OPOBJ2;
        break;
      case THREE:
        eventType = ScriptEventType.OPOBJ3;
        break;
      case FOUR:
        eventType = ScriptEventType.OPOBJ4;
        break;
      case FIVE:
        eventType = ScriptEventType.OPOBJ5;
        break;
      default:
        eventType = null;
        break;
    }
    ScriptManager scripts = Virtue.getInstance().getScripts();
    if (eventType != null && scripts.hasBinding(eventType, this.getId())) {
      Map<String, Object> args = new HashMap<>();
      args.put("player", player);
      args.put("item", this);
      args.put("coords", tile);
      scripts.invokeScriptChecked(eventType, this.getId(), args);
      return true;
    }

    if (OptionButton.THREE.equals(option)
        && "Take".equalsIgnoreCase(this.getType().op[2])) { // Take
      if (player.getInvs().getContainer(ContainerState.BACKPACK).freeSlots() > 0) {
        Region region = World.getInstance().getRegions().getRegionByID(tile.getRegionID());
        if (region != null) {
          GroundItem oldItem = region.removeItem(tile, this.getId());
          if (oldItem != null) {
            player.getInvs().addBackpackItem(new Item(oldItem));
            return true;
          }
        }
      }
    }
    return false;
  }