Package games.stendhal.server.entity

Examples of games.stendhal.server.entity.RPEntity


  @Test
  public void testCanAttackNow() {
    final HandToHand hth = new HandToHand();
    final Creature creature = new Creature();
    assertFalse("no target yet", hth.canAttackNow(creature));
    final RPEntity victim = new RPEntity() {

      @Override
      protected void dropItemsOn(final Corpse corpse) {

      }

      @Override
      public void logic() {

      }
    };
    victim.put("id", 1);
    creature.setTarget(victim);
    assertTrue("new ones stand on same positon", hth.canAttackNow(creature));
    victim.setPosition(10, 10);
    assertFalse("too far away", hth.canAttackNow(creature));

  }
View Full Code Here


    assertNotNull(creature);
    assertThat(creature.getWidth(), is(6.0));
    assertThat(creature.getHeight(), is(6.0));
    creature.setPosition(10, 10);
    assertFalse("no target yet", hth.canAttackNow(creature));
    final RPEntity victim = PlayerTestHelper.createPlayer("bob");
    victim.setHP(1);
    zone.add(creature);
    zone.add(victim);
    creature.setTarget(victim);

    for (int i = 9; i < 12; i++) {
      for (int j = 9; j < 13; j++) {
        victim.setPosition(i, j);
        assertTrue(creature.nextTo(victim));
        assertTrue(victim.nextTo(creature));
        assertTrue("can attack now (" + i + "," + j + ")", hth.canAttackNow(creature));
      }
    }

    victim.setPosition(8, 13);
    assertFalse(creature.nextTo(victim));
    assertFalse(victim.nextTo(creature));
    assertFalse("can attack now ", hth.canAttackNow(creature));

  }
View Full Code Here

  @Test
  public void testUseGateNotNExtTo() throws Exception {
    final Gate gate = new Gate();
    gate.setPosition(5, 5);
    assertFalse(gate.isOpen());
    final RPEntity user = new RPEntity() {

      @Override
      protected void dropItemsOn(final Corpse corpse) {

      }
View Full Code Here

   */
  @Test
  public void testIsObstacle() throws Exception {
    final Gate gate = new Gate();

    final RPEntity user = new RPEntity() {

      @Override
      protected void dropItemsOn(final Corpse corpse) {

      }
View Full Code Here

  public void testhasValidTargetDifferentZones() {

    StendhalRPZone zoneA = new StendhalRPZone("A");
    StendhalRPZone zoneB = new StendhalRPZone("B");

    RPEntity victim = createMock(RPEntity.class);
    expect(victim.isInvisibleToCreatures()).andReturn(false);
    expect(victim.getZone()).andReturn(zoneA);

    Creature attacker = createMock(Creature.class);
    expect(attacker.isAttacking()).andReturn(true);
    expect(attacker.getAttackTarget()).andReturn(victim);
View Full Code Here

  public void testhasValidTargetvisibleVictim() {
    ID id = new RPObject.ID(1, "zone");
    StendhalRPZone zone = createMock(StendhalRPZone.class);
    expect(zone.has(id)).andReturn(false);

    RPEntity victim = createMock(RPEntity.class);
    expect(victim.isInvisibleToCreatures()).andReturn(false);
    expect(victim.getZone()).andReturn(zone);
    expect(victim.getID()).andReturn(id);

    Creature attacker = createMock(Creature.class);
    expect(attacker.isAttacking()).andReturn(true);
    expect(attacker.getAttackTarget()).andReturn(victim);
View Full Code Here

    final StendhalRPZone zone = new StendhalRPZone("hthtest");

    final HandToHand hth = new HandToHand();
    final Creature creature = new Creature();
    assertFalse("is not attacking", hth.hasValidTarget(creature));
    final RPEntity victim = new RPEntity() {

      @Override
      public boolean isInvisibleToCreatures() {
        return mockinvisible;
      }

      @Override
      protected void dropItemsOn(final Corpse corpse) {

      }

      @Override
      public void logic() {

      }
    };
    victim.put("id", 1);
    creature.setTarget(victim);
    mockinvisible = true;
    assertTrue(victim.isInvisibleToCreatures());
    assertFalse("victim is invisible", hth.hasValidTarget(creature));
    mockinvisible = false;
    assertFalse(victim.isInvisibleToCreatures());
    zone.add(victim);
    assertFalse("not in same zone", hth.hasValidTarget(creature));
    zone.add(creature);
    assertFalse("in same zone, on same spot and dead", hth.hasValidTarget(creature));

    creature.setTarget(victim);
    victim.setHP(1);
    assertTrue("in same zone, on same spot", hth.hasValidTarget(creature));

    victim.setPosition(12, 0);
    assertTrue("in same zone, not too far away", hth.hasValidTarget(creature));
    victim.setPosition(13, 0);
    assertFalse("in same zone, too far away", hth.hasValidTarget(creature));
  }
View Full Code Here

        distances.put(enemy, squaredDistance);
      }
    }

    // now choose the nearest enemy for which there is a path
    RPEntity chosen = null;
    while ((chosen == null) && (distances.size() > 0)) {
      double shortestDistance = Double.MAX_VALUE;
      for (final Map.Entry<RPEntity, Double> enemy : distances.entrySet()) {
        final double distance = enemy.getValue();
        if (distance < shortestDistance) {
View Full Code Here

   * @throws NullPointerException if attacktarget is null
   */

  public void tryToPoison() {

    final RPEntity entity = getAttackTarget();
    if (poisoner.attack(entity)) {
      new GameEvent(getName(), "poison", entity.getName()).raise();
      entity.sendPrivateText("You have been poisoned by " + Grammar.a_noun(getName()));
    }
  }
View Full Code Here

  @Override
  public boolean attack() {
    boolean res = super.attack();

    // count hits for corpse protection
    final RPEntity defender = this.getAttackTarget();
    if (defender instanceof Player) {
      if (hitPlayers == null) {
        hitPlayers = new CounterMap<String>();
      }
      hitPlayers.add(defender.getName());
    }

    return res;
  }
View Full Code Here

TOP

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

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.