Package games.stendhal.server.entity

Examples of games.stendhal.server.entity.Entity


  private void findSlotByObjectIdAndSlotName(RPAction action, String attributeKeyForObject, String attributeKeyForSlot) {
    // get base entity
    int objectId = action.getInt(attributeKeyForObject);
    RPObject.ID id = new RPObject.ID(objectId, zone.getID());
    Entity parent = (Entity) zone.get(id);
    if (parent == null) {
      logger.warn("cannot find " + attributeKeyForObject + " for action " + action);
      return;
    }

    // get slot
    String slotName = action.get(attributeKeyForSlot);
    if (!parent.hasSlot(slotName)) {
      logger.warn("Parent doesn't have slot " + attributeKeyForSlot + " used in: " + action);
      return;
    }
    slot = (EntitySlot) parent.getSlot(slotName);

  }
View Full Code Here


  /**
   * Give a nice message to nearby players when rings get destroyed.
   */
  private void informNearbyPlayers(final WeddingRing ring) {
    try {
      final Entity container = (Entity) ring.getBaseContainer();
      final StendhalRPZone zone = getZone();
     
      if (zone != null) {
        for (final Player player : zone.getPlayers()) {
          if (player.nextTo(container)) {
View Full Code Here

  /**
   * Tests for isObstacle.
   */
  @Test
  public void testIsObstacle() {
    final Entity ent = new Entity() {
      // just a sub class
    };
    ent.setResistance(100);
    assertTrue(player.isObstacle(ent));
    ent.setResistance(95);

    assertFalse(player.isObstacle(ent));
    assertThat(player.getResistance(ent), is(95));
  }
View Full Code Here

    // not doing that will result in an NPE
    Corpse corpse = new Corpse(hasRingGood, "test");

    final PlayerDieer dierWithRingGood = new PlayerDieer(hasRingGood);
    dierWithRingGood.dropItemsOn(corpse);
    dierWithRingGood.onDead(new Entity() {
    });

    final PlayerDieer dierWithRingBad = new PlayerDieer(hasRingBad);
    dierWithRingBad.dropItemsOn(corpse);
    dierWithRingBad.onDead(new Entity() {
    });

    final PlayerDieer dierWithoutRingGood = new PlayerDieer(hasNoRingGood);
    dierWithoutRingGood.dropItemsOn(corpse);
    dierWithoutRingGood.onDead(new Entity() {
    });
    final PlayerDieer dierWithoutRingBad = new PlayerDieer(hasNoRingBad);
    dierWithoutRingBad.dropItemsOn(corpse);
    dierWithoutRingBad.onDead(new Entity() {
    });

    assertTrue(ring.isBroken());
                assertTrue(ring2.isBroken());
   
    assertThat("ring wearer, good loses max 1 percent", hasRingGood.getXP(), greaterThan(9899));
    assertThat("ring wearer, good loses min 0 percent", hasRingGood.getXP(), lessThan(10001));

    assertThat("ring wearer, bad loses max 2 percent", hasRingBad.getXP(), greaterThan(9799));

                assertThat("normal player, good loses max 10 percent", hasNoRingGood.getXP(), greaterThan(8999));
    assertThat("normal player, good loses min 0 percent", hasNoRingGood.getXP(), lessThan(10001));

    assertThat("normal player, bad loses max 20 percent", hasNoRingBad.getXP(), greaterThan(7999));
   
    hasRingGood.setXP(10000);
    dierWithRingGood.onDead(new Entity() {
    });
    assertThat("ring wearer, good, with broken ring, loses max 10 percent", hasRingGood.getXP(), greaterThan(8999));
    assertThat("ring wearer, good, with broken ring, loses min 0 percent", hasRingGood.getXP(), lessThan(10001));
   
  }
View Full Code Here

   *            the attack Action containing the TARGET's name
   */
  public void onAction(final Player player, final RPAction action) {
    if (action.has(TARGET)) {
      // evaluate the target parameter
      final Entity entity = EntityHelper.entityFromTargetName(
          action.get(TARGET), player);

      if (entity instanceof RPEntity) {
        StendhalRPAction.startAttack(player, (RPEntity) entity);
      }
View Full Code Here

  }

  public void onAction(Player player, RPAction action) {
    //base object is always the player sending the action
    action.put("baseobject", player.getID().getObjectID());
    Entity target = EntityHelper.entityFromTargetName(action.get(TARGET), player);
    Spell spell = (Spell) EntityHelper.entityFromSlot(player, action);
    spell.cast(player, target);
  }
View Full Code Here

class BuildSourceFromGround implements PartialBuilder {

  public void build(EquipmentActionData data, Player player, RPAction action) {
    final StendhalRPZone zone = player.getZone();
    final int objectid = action.getInt(BASEITEM);
    final Entity object = EntityHelper.entityFromZoneByID(objectid, zone);
    if (!(object instanceof PassiveEntity)) {
      return;
    }
    data.addSourceItem(object);
    data.addSourceSlot(new GroundSlot(zone, object));
View Full Code Here

  public void onAction(final Player player, final RPAction action) {
    if (!action.has(TARGET)) {
      return;
    }

    final Entity entity = EntityHelper.entityFromTargetName(action.get(TARGET), player);
    if (entity != null) {
      if (!checkEntityIsDomesticAnimal(player, entity)) {
        return;
      }
View Full Code Here

  }

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

    final Entity inspected = getTarget(player, action);

    if (inspected == null) {
      final String text = "Entity not found";

      player.sendPrivateText(text);
      return;
    }

    String clazz = inspected.getRPClass().getName();
    String name = "";

    if (inspected.has(NAME)) {
      name = inspected.get(NAME);
    }

    if (inspected.isContained()) {
      RPObject slot = inspected.getContainer();

      new GameEvent(player.getName(), "removed", name + " " + clazz, slot.getID().toString(), Integer.toString(inspected.getX()), Integer.toString(inspected.getY())).raise();
      // items should be added to itemlog as well, to help tracing problems
      if (inspected instanceof Item) {
//        String slotName = null;
//        if (inspected.getContainerSlot() != null) {
//          slotName = inspected.getContainerSlot().getName();
//        }
//        String quantity = inspected.get("quantity");
//        if (quantity == null) {
//          quantity = "1";
//        }
        new ItemLogger().destroy(player, inspected.getContainerSlot(), inspected, "admin");
      }

      String slotname = inspected.getContainerSlot().getName();
      int objectID = inspected.getID().getObjectID();
      if (null != inspected.getContainerSlot().remove(inspected.getID())) {
        if (slot instanceof Entity) {
          ((Entity) slot).notifyWorldAboutChanges();
        }
        player.sendPrivateText("Removed contained " + name + " " + clazz + " with ID " + objectID + " from " + slotname);
      } else {
        player.sendPrivateText("could not remove contained " + inspected + " " + clazz + " with ID " + objectID + " from " + slotname);
      }
    } else {
      if (inspected instanceof Player) {
        final String text = "You can't remove players";
        player.sendPrivateText(text);
        return;
      }

      if (inspected instanceof SpeakerNPC) {
        final String text = "You can't remove SpeakerNPCs";
        player.sendPrivateText(text);
        return;
      }

      if (inspected instanceof Portal) {
        final String text = "You can't remove portals. Try blocking it with a few of /script AdminSign.class.";
        player.sendPrivateText(text);
        return;
      }

      final StendhalRPZone zone = inspected.getZone();

      if (inspected instanceof RPEntity) {
        if (inspected instanceof Creature) {
          // *destroyed creatures should not drop items
          ((Creature) inspected).clearDropItemList();
        }
        ((RPEntity) inspected).onDead(player);
      } else if ((inspected instanceof Item) || (inspected instanceof FlowerGrower) || (inspected instanceof Blood) || (inspected instanceof Corpse)) {
        // items should be added to itemlog as well, to help tracing problems
        if (inspected instanceof Item) {
          String quantity = inspected.get("quantity");
          if (quantity == null) {
            quantity = "1";
          }
          new ItemLogger().destroy(player, null, inspected, "admin");
        }
        zone.remove(inspected);
      } else {
        player.sendPrivateText("You can't remove this type of entity");
        return;
      }

      if (inspected instanceof TurnListener) {
        TurnListener listener = (TurnListener) inspected;
        TurnNotifier.get().dontNotify(listener);
      }

      new GameEvent(player.getName(), "removed",  name + " " + clazz, zone.getName(), Integer.toString(inspected.getX()), Integer.toString(inspected.getY())).raise();

      player.sendPrivateText("Removed " + name + " " + clazz + " with ID " + action.get(TARGET));
    }
  }
View Full Code Here

   * returns true when this entity and the other is within the given distance.
   */
  @Override
  public boolean checkDistance(final Entity other, final double distance) {
    if (parent != null) {
      Entity base = parent;
      RPObject obj = parent.getBaseContainer();
      if (obj instanceof Entity) {
        base = (Entity) obj;
      }
      return (other.nextTo(base, distance));
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.