Package games.stendhal.server.entity

Examples of games.stendhal.server.entity.Entity


import marauroa.common.game.RPSlot;

class BuildSourceFromOldActionFormat implements PartialBuilder {

  public void build(EquipmentActionData data, Player player, RPAction action) {
    final Entity parent = EquipUtil.getEntityFromId(player, action.getInt(EquipActionConsts.BASE_OBJECT));

    if (parent == null) {
      data.setErrorMessage("");
      return;
    }

    final String slotName = action.get(EquipActionConsts.BASE_SLOT);
    if (!parent.hasSlot(slotName)) {
      data.setErrorMessage("");
      return;
    }
    final RPSlot slot = ((EntitySlot) parent.getSlot(slotName)).getWriteableSlot();
    if (slot == null || !(slot instanceof EntitySlot)) {
      data.setErrorMessage("");
      return;
    }

    final RPObject.ID baseItemId = new RPObject.ID(action.getInt(EquipActionConsts.BASE_ITEM), "");
    if (!slot.has(baseItemId)) {
      data.setErrorMessage("");
      return;
    }
    final Entity entity = (Entity) slot.get(baseItemId);

    data.addSourceItem(entity);
    data.setSourceRoot(parent);
    data.addSourceSlot((EntitySlot) slot);
  }
View Full Code Here


  @Test
  public void testGrowOnFertileGround() throws Exception {
    final FlowerGrower fl = new FlowerGrower();
    fl.setRipeness(0);
    final StendhalRPZone zone = new StendhalRPZone("zone");
    final Entity entity = new Allotment();
    zone.add(entity);
    zone.add(fl);

    assertTrue(fl.isOnFreeFertileGround());
    fl.growNewFruit();
View Full Code Here

  @Test
  public void testGrowOnFertileGround2() throws Exception {
    final FlowerGrower fl = new FlowerGrower();
    fl.setRipeness(0);
    final StendhalRPZone zone = new StendhalRPZone("zone");
    final Entity entity = new Allotment();

    zone.add(fl);
    zone.add(entity);
    assertTrue(fl.isOnFreeFertileGround());
    fl.growNewFruit();
View Full Code Here

  public void build(EquipmentActionData data, Player player, RPAction action) {
    List<String> path = action.getList(EquipActionConsts.SOURCE_PATH);
    Iterator<String> it = path.iterator();

    // get parent
    Entity parent = EquipUtil.getEntityFromId(player, MathHelper.parseInt(it.next()));
    Entity root = parent;
    if (parent == null) {
      data.setErrorMessage("");
      return;
    }

    // Walk the slot path
    Entity entity = parent;
    String slotName = null;
    while (it.hasNext()) {
      slotName = it.next();
      if (!entity.hasSlot(slotName)) {
        data.setErrorMessage("");
        return;
      }

      final RPSlot slot = ((EntitySlot) entity.getSlot(slotName)).getWriteableSlot();
      if (slot == null) {
        data.setErrorMessage("");
        return;
      }
      if (!it.hasNext()) {
        data.setErrorMessage("");
        return;
      }
      final RPObject.ID itemId = new RPObject.ID(MathHelper.parseInt(it.next()), "");
      if (!slot.has(itemId)) {
        data.setErrorMessage("");
        return;
      }

      entity = (Entity) slot.get(itemId);
    }

    // if the item is not contained, the item is on the ground
    if (parent == entity) {
      data.addSourceItem(entity);
      data.addSourceSlot(new GroundSlot(player.getZone(), entity));
    } else {
      data.addSourceItem(entity);
      data.setSourceRoot(root);
      data.addSourceSlot((EntitySlot) entity.getContainerSlot());
    }
  }
View Full Code Here

  @Test
  public void testGrowFertileGroundElsewhere() throws Exception {
    final FlowerGrower fl = new FlowerGrower();
    fl.setRipeness(0);
    final StendhalRPZone zone = new StendhalRPZone("zone");
    final Entity entity = new Allotment();
    entity.setPosition(10, 10);
    zone.add(fl);
    zone.add(entity);
    assertFalse(fl.isOnFreeFertileGround());
   
    // check it withers when grown
View Full Code Here

  public void testGrowOnFreeFertileGroundReserved() throws Exception {
    final FlowerGrower fl = new FlowerGrower();
    final FlowerGrower fl2 = new FlowerGrower();
    fl.setRipeness(0);
    final StendhalRPZone zone = new StendhalRPZone("zone");
    final Entity entity = new Allotment();

    zone.add(fl);
    zone.add(fl2);
    zone.add(entity);
    assertFalse(fl.isOnFreeFertileGround());
View Full Code Here

          + getX() + "," + getY() + "]");
      return;
    }

    try {
      final Entity entity = EntityFactoryHelper.create(classNameTemp,
          getParameters(), getAttributes());

      if (entity == null) {
        LOGGER.warn("Unable to create entity: " + classNameTemp);

        return;
      }

      entity.setPosition(getX(), getY());

      zone.add(entity);
    } catch (final IllegalArgumentException ex) {
      LOGGER.error("Error with entity factory", ex);
    }
View Full Code Here

class BuildTargetFromOldActionFormat implements PartialBuilder {

  public void build(EquipmentActionData data, Player player, RPAction action) {
    // get parent
    Entity parent = EquipUtil.getEntityFromId(player, action.getInt(EquipActionConsts.TARGET_OBJECT));
    if (parent == null) {
      data.setErrorMessage("");
      return;
    }

    // get slot
    String slotName = action.get(EquipActionConsts.TARGET_SLOT);
    if (!parent.hasSlot(slotName)) {
      data.setErrorMessage("");
      return;
    }
    data.setTargetRoot(parent);
    data.setTargetSlot(parent.getEntitySlot(slotName));
  }
View Full Code Here

   *
   * @param player the caller of the action
   * @param action the action to be performed
   */
  public void onAction(final Player player, final RPAction action) {
    Entity entity = EntityHelper.entityFromSlot(player, action);

    if (entity == null) {
      entity = EntityHelper.entityFromTargetName(action.get(TARGET), player);
    }

    if (entity != null) {
      if (entity instanceof Player) {
        if (((Player) entity).isGhost()
            && (player.getAdminLevel() < AdministrationAction.getLevelForCommand("ghostmode"))) {
          return;
        }
      }

      String name = entity.get(TYPE);
      if (entity.has(NAME)) {
        name = entity.get(NAME);
      }
      new GameEvent(player.getName(), LOOK, name).raise();
      final String text = entity.describe();

      if (entity.has(Actions.ACTION) && entity.get(Actions.ACTION).equals(Actions.READ)) {
        player.sendPrivateText(NotificationType.RESPONSE, text);
      } else {
        player.sendPrivateText(text);
      }

View Full Code Here

    return source;
  }

  private static SourceObject createSourceForContainedItem(final RPAction action, final Player player) {
    SourceObject source;
    final Entity parent = EquipUtil.getEntityFromId(player, action.getInt(EquipActionConsts.BASE_OBJECT));

    if (!isValidParent(parent, player)) {
      return invalidSource;
    }

    final String slotName = action.get(EquipActionConsts.BASE_SLOT);

    if (!parent.hasSlot(slotName)) {
      player.sendPrivateText("Source " + slotName + " does not exist");
      logger.error(player.getName() + " tried to use non existing slot " + slotName + " of " + parent
          + " as source. player zone: " + player.getZone() + " object zone: " + parent.getZone());

      return invalidSource;
    }
    final RPSlot baseSlot = ((EntitySlot) parent.getSlot(slotName)).getWriteableSlot();

    if (!isValidBaseSlot(player, baseSlot)) {
      return invalidSource;
    }
    final RPObject.ID baseItemId = new RPObject.ID(action.getInt(EquipActionConsts.BASE_ITEM), "");
    if (!baseSlot.has(baseItemId)) {
      logger.debug("Base item(" + parent + ") doesn't contain item(" + baseItemId + ") on given slot(" + slotName
          + ")");
      // Remove message as discussed on #arianne 2010-04-25
      // player.sendPrivateText("There is no such item in the " + slotName + " of "
        //  + parent.getDescriptionName(true));
      return invalidSource;
    }

    final Entity entity = (Entity) baseSlot.get(baseItemId);
    if (!(entity instanceof Item)) {
      player.sendPrivateText("Oh, that " + entity.getDescriptionName(true)
          + " is not an item and therefore cannot be equipped");
      return invalidSource;
    }

    if (parent instanceof Corpse) {
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.