@Test
  public void testCalculateGoalSell() {
    World world = new WorldImpl(10, 10, null, null);
    WorldObject performer = createPerformer(2);
    WorldObject target = createPerformer(3);

    world.addWorldObject(performer);
    world.addWorldObject(target);

    performer.setProperty(Constants.GOLD, 100);
    performer.getProperty(Constants.INVENTORY).addQuantity(Item.WOOD.generate(1f), 20);

    target.setProperty(Constants.GOLD, 100);
    target.setProperty(Constants.DEMANDS, new PropertyCountMap<>());
    target.getProperty(Constants.DEMANDS).add(Constants.WOOD, 1);

    assertEquals(Actions.SELL_ACTION, goal.calculateGoal(performer, world).getManagedOperation());
    assertEquals(target, goal.calculateGoal(performer, world).getTarget());
  }
  @Test
  public void testIsValidTarget() {
    World world = new WorldImpl(1, 1, null, null);
    WorldObject performer = createPerformer(2);
    WorldObject target = TestUtils.createWorldObject(0, 0, 1, 1);

    assertEquals(true, Actions.PLANT_NIGHT_SHADE_ACTION.isValidTarget(performer, target, world));

    target.setProperty(Constants.ID, 3);
    world.addWorldObject(target);
    assertEquals(false, Actions.PLANT_NIGHT_SHADE_ACTION.isValidTarget(performer, target, world));
  }
  @Test
  public void testExecuteWater() {
    World world =
        new MockWorld(new MockTerrain(TerrainType.WATER), new WorldImpl(10, 10, null, null));
    WorldObject performer = createPerformer(2);
    WorldObject target = createPerformer(3);

    performer.setProperty(Constants.HIT_POINTS, 10);
    performer.setProperty(Constants.HIT_POINTS_MAX, 10);

    target.setProperty(Constants.HIT_POINTS, 10);
    target.setProperty(Constants.HIT_POINTS_MAX, 10);

    world.addWorldObject(performer);
    world.addWorldObject(target);

    Actions.LIGHTNING_BOLT_ATTACK_ACTION.execute(performer, target, Args.EMPTY, world);

    assertEquals(5, performer.getProperty(Constants.HIT_POINTS).intValue());
    assertEquals(0, target.getProperty(Constants.HIT_POINTS).intValue());
  }
Esempio n. 4
0
  @Test
  public void testOnTurn() {
    World world = new WorldImpl(1, 1, null, new DoNothingWorldOnTurn());
    WorldObject performer = TestUtils.createSkilledWorldObject(2);
    performer.setProperty(Constants.DEITY, Deity.APHRODITE);
    performer.setProperty(Constants.CREATURE_TYPE, CreatureType.HUMAN_CREATURE_TYPE);
    world.addWorldObject(performer);

    createVillagersOrganization(world);

    for (int i = 0; i < 20; i++) {
      WorldObject worshipper = TestUtils.createSkilledWorldObject(i + 10);
      worshipper.setProperty(Constants.DEITY, Deity.HADES);
      world.addWorldObject(worshipper);
    }

    for (int i = 0; i < 5000; i++) {
      world.nextTurn();
      deity.onTurn(world, new WorldStateChangedListeners());
    }

    assertEquals(
        CreatureType.WEREWOLF_CREATURE_TYPE, performer.getProperty(Constants.CREATURE_TYPE));
  }
Esempio n. 5
0
  @Test
  public void testFindWorstId() {
    IdMap idMap = new IdToIntegerMap();
    World world = new WorldImpl(1, 1, null, null);

    WorldObject person1 = TestUtils.createIntelligentWorldObject(1, Constants.GOLD, 10);
    WorldObject person2 = TestUtils.createIntelligentWorldObject(2, Constants.GOLD, 0);

    world.addWorldObject(person1);
    world.addWorldObject(person2);

    idMap.incrementValue(person1, 60);
    idMap.incrementValue(person2, 80);

    assertEquals(1, idMap.findWorstId(world));
  }
Esempio n. 6
0
  @Test
  public void testFindBestIdWithComparator() {
    IdMap idMap = new IdToIntegerMap();
    World world = new WorldImpl(1, 1, null, null);

    WorldObject person1 = TestUtils.createIntelligentWorldObject(1, Constants.GOLD, 10);
    WorldObject person2 = TestUtils.createIntelligentWorldObject(2, Constants.GOLD, 0);

    world.addWorldObject(person1);
    world.addWorldObject(person2);

    idMap.incrementValue(person1, 60);
    idMap.incrementValue(person2, 80);

    assertEquals(1, idMap.findBestId(w -> true, new WorldObjectComparator(), world));
    assertEquals(
        1,
        idMap.findBestId(
            w -> w.getProperty(Constants.GOLD) > 0, new WorldObjectComparator(), world));

    person2.setProperty(Constants.GOLD, 100);
    assertEquals(2, idMap.findBestId(w -> true, new WorldObjectComparator(), world));
  }
Esempio n. 7
0
 private WorldObject createVillagersOrganization(World world) {
   WorldObject organization = GroupPropertyUtils.createVillagersOrganization(world);
   organization.setProperty(Constants.ID, 1);
   world.addWorldObject(organization);
   return organization;
 }