Package games.stendhal.server.entity

Examples of games.stendhal.server.entity.Entity


    // get source and check it
 
 
    logger.debug("Getting entity name");
    // is the entity unbound or bound to the right player?
    final Entity entity = source.getEntity();
    final String itemName = source.getEntityName();
 
    logger.debug("Checking if entity is bound");
    if (entity instanceof Item) {
      final Item item = (Item) entity;
      if (item.isBound() && !player.isBoundTo(item)) {
        player.sendPrivateText("This " + itemName
            + " is a special reward for " + item.getBoundTo()
            + ". You do not deserve to use it.");
        return;
      }
     
    }
 
    logger.debug("Checking destination");
    // get destination and check it
    final DestinationObject dest = new DestinationObject(action, player);
    if (dest.isInvalidMoveable(player, EquipActionConsts.MAXDISTANCE, validContainerClassesList)) {
      // destination is not valid
      logger.debug("Destination is not valid");
      return;
    }
 
    logger.debug("Equip action agreed");
 
    // looks good
    if (source.moveTo(dest, player)) {
      int amount = 1;
      if (entity instanceof StackableItem) {
        amount = ((StackableItem) entity).getQuantity();
      }

      // players sometimes accidentally drop items into corpses, so inform about all drops into a corpse
      // which aren't just a movement from one corpse to another.
      // we could of course specifically preclude dropping into corpses, but that is undesirable.
      if (dest.isContainerCorpse() && !source.isContainerCorpse()) {
          player.sendPrivateText("For your information, you just dropped "
              + Grammar.quantityplnounWithHash(amount,entity.getTitle()) + " into a corpse next to you.");
      }
     
      if(source.isLootingRewardable()) {
        if(entity instanceof Item) {
          ((Item) entity).setFromCorpse(false);
        }
        player.incLootForItem(entity.getTitle(), amount);
        SingletonRepository.getAchievementNotifier().onItemLoot(player);
      }
     
      new GameEvent(player.getName(), "equip", itemName, source.getSlot(), dest.getSlot(), Integer.toString(amount)).raise();
 
View Full Code Here


       
        if (!zone.collides(player, x, y)) {
          final EntityFactory factory = new EntityFactory(player) {
            @Override
            void found(final String type, final Entity entity) {
               final Entity entityToBePlaced;
              if (manager.isCreature(type)) { 
                entityToBePlaced = new RaidCreature((Creature) entity);
                if (((Creature) entity).isRare() && System.getProperty("stendhal.testserver") == null) {
                  // Rare creatures should not be summoned even in raids
                  // Require parameter -Dstendhal.testserver=junk
View Full Code Here

     * Create the named entity (creature, pet or sheep) of type 'type'.
     *
     * @param type
     */
    private void createEntity(final String type) {
        final Entity entity = manager.getEntity(type);

        if (entity != null) {
        found(type, entity);
      } else if ("cat".equals(type)) {
        if (player.hasPet()) {
View Full Code Here

    if (action.has("quantity")) {
      quantity = action.getInt("quantity");
    }
    final StendhalRPZone zone = player.getZone();

    final Entity object = EntityHelper.entityFromZoneByID(targetObject, zone);
    if (!(object instanceof PassiveEntity)) {
      return;
    }

    final int x = action.getInt(X);
View Full Code Here

  protected abstract void perform(Player player, RPAction action);

  protected final Entity getTargetAnyZone(final Player player, final RPAction action) {

    Entity entity = EntityHelper.entityFromSlot(player, action);

    if (entity == null) {
      entity = EntityHelper.entityFromTargetNameAnyZone(action.get(Actions.TARGET), player);
    }
View Full Code Here

   * @param player
   * @param action
   * @return the Entity or null if it does not exist
   */
  protected final Entity getTarget(final Player player, final RPAction action) {
    Entity entity = EntityHelper.entityFromSlot(player, action);

    if (entity == null) {
      entity = EntityHelper.entityFromTargetName(action.get(Actions.TARGET), player);
    }
   
View Full Code Here

  public Entity getEntity(final String clazz) {
    if (clazz == null) {
      throw new IllegalArgumentException("entity class is null");
    }

    Entity entity;
    // Lookup the id in the creature table
    entity = getCreature(clazz);
    if (entity != null) {
      return entity;
    }
View Full Code Here

  }

  @Override
  public void perform(final Player player, final RPAction action) {
    if (hasNeededAttributes(action)) {
      final Entity changed = getTargetAnyZone(player, action);

      if (changed == null) {
        logger.debug("Entity not found");
        player.sendPrivateText("Entity not found");
        return;
      }

      final String stat = action.get(STAT);

      if ("name".equals(stat) && (changed instanceof Player)) {
        logger.error("DENIED: Admin " + player.getName() + " trying to change player " + action.get(TARGET)
            + "'s name");
        player.sendPrivateText("Sorry, name cannot be changed.");
        return;
      }

      if (ADMINLEVEL.equals(stat)) {
        player.sendPrivateText("Use #/adminlevel #<playername> #[<newlevel>] to display or change adminlevel.");
        return;
      }

      if (TITLE.equals(stat) && (changed instanceof Player)) {
        player.sendPrivateText("The title attribute may not be changed directly.");
        return;
      }

      final RPClass clazz = changed.getRPClass();


      final Definition type = clazz.getDefinition(DefinitionClass.ATTRIBUTE, stat);
      if (type == null) {
        player.sendPrivateText("Attribute you are altering is not defined in RPClass("
            + changed.getRPClass().getName() + ")");
        return;
      } else {
        final String value = action.get(VALUE);
        final String mode = action.get(MODE);

        if ((mode.length() > 0) && !mode.equalsIgnoreCase(ADD)
            && !mode.equalsIgnoreCase(SUB) && !mode.equalsIgnoreCase(SET) && !mode.equalsIgnoreCase(UNSET)) {
          player.sendPrivateText("Please issue one of the modes 'add', 'sub', 'set' or 'unset'.");
          return;
        }

        if (isParsableByInteger(type)) {
          int numberValue;

          try {
            numberValue = Integer.parseInt(value);
          } catch (final NumberFormatException e) {
            player.sendPrivateText("Please issue a numeric value instead of '" + value + "'");
            return;
          }

          if (mode.equalsIgnoreCase(ADD)) {
            numberValue = changed.getInt(stat) + numberValue;
          }

          if (mode.equalsIgnoreCase(SUB)) {
            numberValue = changed.getInt(stat) - numberValue;
          }

          if (ATTR_HP.equals(stat) && (changed.getInt("base_hp") < numberValue)) {
            logger.info("Admin " + player.getName() + " trying to set entity "
                + Grammar.suffix_s(action.get(TARGET)) + " HP over its Base HP, "
                + "we instead restored entity " + action.get(TARGET) + " to full health.");
            numberValue = changed.getInt("base_hp");
          }

          if (ATTR_HP.equals(stat) && (numberValue <= 0)) {
            logger.error("DENIED: Admin " + player.getName() + " trying to set entity "
                + Grammar.suffix_s(action.get(TARGET)) + " HP to 0, making it so unkillable.");
            return;
          }

          switch (type.getType()) {
          case BYTE:
            if ((numberValue > Byte.MAX_VALUE)
                || (numberValue < Byte.MIN_VALUE)) {
              return;
            }
            break;
          case SHORT:
            if ((numberValue > Short.MAX_VALUE)
                || (numberValue < Short.MIN_VALUE)) {
              return;
            }
            break;
          case INT:
            /*
             * as numberValue is currently of type integer, this is
             * pointless: if ((numberValue > Integer.MAX_VALUE) ||
             * (numberValue < Integer.MIN_VALUE)) { return; }
             */
            break;
          default:
              // we switch over an enum
              break;
          }
         
          new GameEvent(player.getName(), ALTER, action.get(TARGET), stat, Integer.toString(numberValue)).raise();
          changed.put(stat, numberValue);
        } else {
          // If value is not a number, only SET and UNSET can be used
          if (mode.equalsIgnoreCase(SET)) {
            new GameEvent(player.getName(), ALTER, action.get(TARGET), stat, action.get(VALUE)).raise();
            changed.put(stat, action.get(VALUE));

          } else if (mode.equalsIgnoreCase(UNSET)) {
            if (type.getType() != Type.FLAG) {
              player.sendPrivateText("Attribute to be unset is not of type 'flag'.");
              return;
            }
            new GameEvent(player.getName(), ALTER, action.get(TARGET), stat, "unset").raise();
            changed.remove(stat);
          }
        }

        changed.update();
        changed.notifyWorldAboutChanges();
      }
    }
  }
View Full Code Here

  }

  @Override
  public void perform(final Player player, final RPAction action) {

    final Entity target = getTargetAnyZone(player, action);

    if (target == null) {
      final String text = "Entity not found for action" + action;
      player.sendPrivateText(text);
      return;
    }

    final StringBuilder st = new StringBuilder();

    if (target instanceof RPEntity) {
      final RPEntity inspected = (RPEntity) target;

      // display type and name/title of the entity if they are available

      final String type = inspected.get("type");
      st.append("Inspected ");
      if (type != null) {
        st.append(type);
      } else {
        st.append("entity");
      }
      st.append(" is ");

      String name = inspected.getName();
      if (name == null) {
        name = inspected.getTitle();
      }
      if (name != null) {
        st.append("called \"");
        st.append(name);
        st.append("\"");
      } else {
        st.append("unnamed");
      }

      st.append(" and has the following attributes:");

      // st.append(target.toString());
      // st.append("\n===========================\n");
      st.append("\nID: " + action.get("target") + " in " + inspected.getZone().getName() + " at (" + + inspected.getX() + ", " + + inspected.getY()+")");
      st.append("\nATK:    " + inspected.getAtk() + "("
          + inspected.getAtkXP() + ")");
      st.append("\nDEF:    " + inspected.getDef() + "("
          + inspected.getDefXP() + ")");
      st.append("\nHP:     " + inspected.getHP() + " / "
          + inspected.getBaseHP());
      st.append("\nXP:     " + inspected.getXP());
      st.append("\nLevel:  " + inspected.getLevel());
      st.append("\nKarma:  " + inspected.getKarma());
      st.append("\nequips");
     
      for (final RPSlot slot : inspected.slots()) {
        // showing these is either irrelevant, private, or spams too much
        if (slot.getName().equals("!buddy")
          || slot.getName().equals("!ignore")
          || slot.getName().equals("!visited")
          || slot.getName().equals("!tutorial")
          || slot.getName().equals("skills")
          || slot.getName().equals("spells")
          || slot.getName().equals("!kills")) {
          continue;
        }
        st.append("\n    Slot " + slot.getName() + ": ");

        if (slot.getName().startsWith("!")) {
          if("!quests".equals(slot.getName())) {
            st.append(SingletonRepository.getStendhalQuestSystem().listQuestsStates((Player) inspected));
          } else {
            for (final RPObject object : slot) {
              st.append(object);
            }
          }
        } else {
          for (final RPObject object : slot) {
            if (!(object instanceof Item)) {
              continue;
            }

            String item = object.get("type");

            if (object.has("name")) {
              item = object.get("name");
            }
            if (object instanceof StackableItem) {
              st.append("[" + item + " Q="
                  + object.get("quantity") + "], ");
            } else {
              st.append("[" + item + "], ");
            }
          }
        }
      }
    } else {
      st.append("Inspected entity has id " + action.get("target")
          + " and has attributes:\r\n");
      st.append(target.toString());
    }

    player.sendPrivateText(st.toString());
  }
View Full Code Here

   *
   * @param action RPAction
   */
  private void fillByGroundSource(RPAction action) {
    int itemid = action.getInt(EquipActionConsts.BASE_ITEM);
    Entity entity = (Entity) zone.get(new RPObject.ID(itemid, zone.getID()));
    if (entity instanceof Item) {
      item = (Item) entity;
    }
    slot = new GroundSlot(zone, item);
  }
View Full Code Here

TOP

Related Classes of games.stendhal.server.entity.Entity

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.