Ejemplo n.º 1
0
  /** Test a source under another player. */
  @Test
  public void testIsValidNonContainedBelowPlayer() {
    MockStendlRPWorld.get();
    final Player bob = PlayerTestHelper.createPlayer("bob");
    final Player alice = PlayerTestHelper.createPlayer("alice");
    alice.setPosition(0, 1);
    final StendhalRPZone zone = new StendhalRPZone("dropzone");
    final Item dropitem = ItemTestHelper.createItem();
    zone.add(dropitem);
    zone.add(bob);
    zone.add(alice);
    assertNotNull(dropitem.getID().getObjectID());
    final RPAction action = new RPAction();
    action.put(EquipActionConsts.BASE_ITEM, dropitem.getID().getObjectID());
    MockStendlRPWorld.get().addRPZone(zone);
    assertNotNull(bob.getZone());

    SourceObject so = SourceObject.createSourceObject(action, alice);
    assertFalse("Picking an item below another player", so.isValid());

    // Bind it to alice. She should be able to pick it up
    dropitem.setBoundTo("alice");
    so = SourceObject.createSourceObject(action, alice);
    assertTrue("Picking an item belonging to player herself", so.isValid());

    // Sanity check. Should be still valid to bob
    so = SourceObject.createSourceObject(action, bob);
    assertTrue("Accessing bound object below oneself", so.isValid());
    // ... unless it's under alice
    dropitem.setPosition(0, 1);
    so = SourceObject.createSourceObject(action, bob);
    assertFalse("Picking an item below another player", so.isValid());
  }
  /**
   * binds special items to the player.
   *
   * @param player Player
   * @param item Item
   */
  private void boundOldItemsToPlayer(final Player player, final Item item) {
    if (ITEMS_TO_UNBIND.contains(item.getName())) {
      item.setBoundTo(null);
      return;
    }

    item.autobind(player.getName());
  }
Ejemplo n.º 3
0
  /** Test that players susceptibility is calculated correctly */
  @Test
  public void testGetSusceptibility() {
    Player player = PlayerTestHelper.createPlayer("test dummy");
    for (Nature type : Nature.values()) {
      assertThat("Default susceptibility", player.getSusceptibility(type), closeTo(1.0, 0.00001));
    }

    Item armor = new Item("rainbow armor", "armor", "subclass", new HashMap<String, String>());
    player.equip("armor", armor);
    HashMap<Nature, Double> armorMap = new HashMap<Nature, Double>();
    armor.setSusceptibilities(armorMap);

    for (Nature type : Nature.values()) {
      armorMap.put(type, 0.42);
      for (Nature type2 : Nature.values()) {
        if (type == type2) {
          assertThat(player.getSusceptibility(type2), closeTo(0.42, 0.00001));
        } else {
          assertThat(player.getSusceptibility(type2), closeTo(1.0, 0.00001));
        }
      }
      armorMap.remove(type);
    }

    Item legs = new Item("rainbow legs", "legs", "subclass", new HashMap<String, String>());
    player.equip("legs", legs);
    HashMap<Nature, Double> legsMap = new HashMap<Nature, Double>();
    legs.setSusceptibilities(legsMap);
    legsMap.put(Nature.ICE, 0.5);

    for (Nature type : Nature.values()) {
      armorMap.put(type, 0.42);
      for (Nature type2 : Nature.values()) {
        double expected;
        double ice = 1.0;
        if (type2 == Nature.ICE) {
          // Ice effect if we are checking ice resistance
          ice = 0.5;
        }
        if (type == type2) {
          // checking the type we gave resistance 0.42
          expected = ice * 0.42;
        } else {
          // only the ice effect, if any
          expected = ice;
        }

        assertThat(
            "Susceptibility to " + type2,
            player.getSusceptibility(type2),
            closeTo(expected, 0.00001));
      }
      armorMap.remove(type);
    }
  }
Ejemplo n.º 4
0
  /** Tests for isValidStackableDropTooMany. */
  @Test
  public void testIsValidStackableDropTooMany() {
    final Player bob = PlayerTestHelper.createPlayer("bob");
    final StendhalRPZone zone = new StendhalRPZone("dropzone");
    final Item dropitem = ItemTestHelper.createItem("drops", 5);
    zone.add(dropitem);
    zone.add(bob);
    MockStendlRPWorld.get().addRPZone(zone);

    final RPAction action = new RPAction();
    action.put(EquipActionConsts.BASE_ITEM, dropitem.getID().getObjectID());
    action.put(EquipActionConsts.QUANTITY, dropitem.getQuantity() + 3);
    final SourceObject so = SourceObject.createSourceObject(action, bob);
    assertTrue(so.isValid());
    assertEquals("too many are reduced to all", dropitem.getQuantity(), so.getQuantity());
  }
Ejemplo n.º 5
0
  /** Tests for isValidNonContained. */
  @Test
  public void testIsValidNonContained() {
    MockStendlRPWorld.get();
    final Player bob = PlayerTestHelper.createPlayer("bob");
    final StendhalRPZone zone = new StendhalRPZone("dropzone");
    final Item dropitem = ItemTestHelper.createItem();
    zone.add(dropitem);
    zone.add(bob);
    assertNotNull(dropitem.getID().getObjectID());
    final RPAction action = new RPAction();
    action.put(EquipActionConsts.BASE_ITEM, dropitem.getID().getObjectID());
    MockStendlRPWorld.get().addRPZone(zone);
    assertNotNull(bob.getZone());

    final SourceObject so = SourceObject.createSourceObject(action, bob);
    assertTrue(so.isValid());
  }
Ejemplo n.º 6
0
  /** Tests for isValidStackableDropAFew. */
  @Test
  public void testIsValidStackableDropAFew() {
    final Player bob = PlayerTestHelper.createPlayer("bob");
    final StendhalRPZone zone = new StendhalRPZone("dropzone");
    final Item dropitem = ItemTestHelper.createItem("drops", 5);
    zone.add(dropitem);
    zone.add(bob);
    MockStendlRPWorld.get().addRPZone(zone);

    final RPAction action = new RPAction();
    action.put(EquipActionConsts.BASE_ITEM, dropitem.getID().getObjectID());
    final int amounttodrop = 3;
    action.put(EquipActionConsts.QUANTITY, amounttodrop);
    final SourceObject so = SourceObject.createSourceObject(action, bob);
    assertTrue(so.isValid());
    assertEquals("return the amount to be dropped", amounttodrop, so.getQuantity());
  }
Ejemplo n.º 7
0
  /** Tests for isValidStackable. */
  @Test
  public void testIsValidStackable() {
    final Player bob = PlayerTestHelper.createPlayer("bob");
    final StendhalRPZone zone = new StendhalRPZone("dropzone");
    final Item dropitem = ItemTestHelper.createItem("drops", 5);
    zone.add(dropitem);
    zone.add(bob);
    assertNotNull(dropitem.getID().getObjectID());
    final RPAction action = new RPAction();
    action.put(EquipActionConsts.BASE_ITEM, dropitem.getID().getObjectID());
    MockStendlRPWorld.get().addRPZone(zone);
    assertNotNull(bob.getZone());

    final SourceObject so = SourceObject.createSourceObject(action, bob);
    assertTrue(so.isValid());
    assertEquals("stackable returns full quantity", dropitem.getQuantity(), so.getQuantity());
  }
Ejemplo n.º 8
0
  /** Test selling a container item. */
  @Test
  public void testSellContainer() {
    final SpeakerNPC npc = getNPC("Harold");
    final Engine en = npc.getEngine();
    player.addXP(1700);

    Item item = SingletonRepository.getEntityManager().getItem("keyring");
    StackableItem playersMoney =
        (StackableItem) SingletonRepository.getEntityManager().getItem("money");
    Integer price = Integer.valueOf(1500);
    playersMoney.setQuantity(price);
    player.equipToInventoryOnly(item);
    player.equipToInventoryOnly(playersMoney);

    Item key = SingletonRepository.getEntityManager().getItem("dungeon silver key");
    item.getSlot("content").add(key);

    assertTrue(en.step(player, "hello"));
    assertEquals("Welcome to Semos trading center. How can I #help you?", getReply(npc));

    // Try first selling it when it's not empty
    assertTrue(en.step(player, "sell keyring 150000"));
    assertEquals("Please empty your keyring first.", getReply(npc));
    assertTrue(player.isEquipped("keyring"));
    assertTrue(player.isEquipped("dungeon silver key"));

    // Then after emptying it
    item.getSlot("content").clear();
    assertTrue(en.step(player, "sell keyring 150000"));
    assertEquals(
        "Do you want to sell a keyring for 150000 money? It would cost you 1500 money.",
        getReply(npc));

    assertTrue(en.step(player, "yes"));
    assertEquals(
        "I added your offer to the trading center and took the fee of 1500.", getReply(npc));
    assertFalse(player.isEquipped("keyring"));
    assertFalse(player.isEquipped("dungeon silver key"));

    assertTrue(en.step(player, "bye"));
    assertEquals(
        "Visit me again to see available offers, make a new offer or fetch your earnings!",
        getReply(npc));
  }
Ejemplo n.º 9
0
 private void eat(final Item food) {
   if (weight < MAX_WEIGHT) {
     setWeight(weight + 1);
   }
   food.removeOne();
   hunger = START_HUNGER_VALUE;
   if (getHP() < getBaseHP()) {
     // directly increase the pet's health points
     heal(incHP);
   }
 }
Ejemplo n.º 10
0
 /** Test that the damage done by a player is of right type. */
 @Test
 public void testGetDamageType() {
   Player player = PlayerTestHelper.createPlayer("don Quijote");
   assertThat("Default damage type", player.getDamageType(), is(Nature.CUT));
   Item item = new Item("torch", "junk", "subclass", new HashMap<String, String>());
   player.equip("rhand", item);
   for (Nature type : Nature.values()) {
     item.setDamageType(type);
     assertThat(
         "Non weapon items should not change the damage type",
         player.getDamageType(),
         is(Nature.CUT));
   }
   // turn the item in to a weapon
   item.put("class", "club");
   for (Nature type : Nature.values()) {
     item.setDamageType(type);
     assertThat("Damage type should be got from the weapon", player.getDamageType(), is(type));
   }
 }
Ejemplo n.º 11
0
  /** Tests for isValidContained. */
  @Test
  public void testIsValidContained() {
    MockStendlRPWorld.get();
    final Player bob = PlayerTestHelper.createPlayer("bob");
    final StendhalRPZone zone = new StendhalRPZone("dropzone");
    final Item dropitem = SingletonRepository.getEntityManager().getItem("money");
    assertNotNull(dropitem);
    zone.add(bob);
    assertTrue(bob.equipToInventoryOnly(dropitem));
    assertNotNull(dropitem.getID().getObjectID());
    final RPAction action = new RPAction();
    action.put(EquipActionConsts.BASE_ITEM, dropitem.getID().getObjectID());

    action.put(EquipActionConsts.BASE_OBJECT, bob.getID().getObjectID());
    action.put(EquipActionConsts.BASE_SLOT, "bag");
    MockStendlRPWorld.get().addRPZone(zone);
    assertNotNull(bob.getZone());

    final SourceObject so = SourceObject.createSourceObject(action, bob);
    assertTrue("Unreachable slot", so.isValid());
  }
 public int calculatePrice(Item i, Player p) {
   itemToRepair = i;
   return calculatePrice(itemToRepair.getName(), p);
 }
Ejemplo n.º 13
0
  boolean canEat(final Item i) {

    return foodName.contains(i.getName());
  }