@Test
  public void testGetReplyPhrase() {
    World world = new WorldImpl(1, 1, null, null);
    WorldObject performer =
        TestUtils.createIntelligentWorldObject(1, Constants.RELATIONSHIPS, new IdRelationshipMap());
    WorldObject target =
        TestUtils.createIntelligentWorldObject(2, Constants.RELATIONSHIPS, new IdRelationshipMap());
    WorldObject organization = GroupPropertyUtils.create(null, "OrgName", world);

    target.getProperty(Constants.RELATIONSHIPS).incrementValue(performer, -2000);

    ConversationContext context =
        new ConversationContext(performer, target, organization, null, world, 0);
    assertEquals(-999, conversation.getReplyPhrase(context).getId());

    target.getProperty(Constants.RELATIONSHIPS).incrementValue(performer, 2000);
    target.setProperty(Constants.GOLD, 0);
    assertEquals(1, conversation.getReplyPhrase(context).getId());

    target.setProperty(Constants.GOLD, 200);
    assertEquals(0, conversation.getReplyPhrase(context).getId());

    target.setProperty(Constants.GOLD, 50);
    assertEquals(2, conversation.getReplyPhrase(context).getId());
  }
  @Test
  public void testGetQuestionPhrases() {
    WorldObject performer =
        TestUtils.createIntelligentWorldObject(1, Constants.GROUP, new IdList());
    WorldObject target =
        TestUtils.createIntelligentWorldObject(2, Constants.GROUP, new IdList().add(0));

    List<Question> questions = conversation.getQuestionPhrases(performer, target, null, null, null);
    assertEquals(1, questions.size());
    assertEquals("Can you give me 100 gold?", questions.get(0).getQuestionPhrase());
  }
Exemplo n.º 3
0
  @Test
  public void testRemoveId() {
    IdMap idMap = new IdRelationshipMap();
    WorldObject person = TestUtils.createIntelligentWorldObject(1, Constants.RELATIONSHIPS, idMap);
    idMap.incrementValue(6, 2);
    WorldObject person2 = TestUtils.createWorldObject(1, "Test2");

    assertEquals(2, idMap.getValue(6));
    idMap.remove(person, Constants.RELATIONSHIPS, 6);
    assertEquals(0, idMap.getValue(6));
    assertEquals(false, idMap.contains(person2));
  }
Exemplo n.º 4
0
  @Test
  public void testGetIdsWithoutTarget() {
    IdMap idMap = new IdToIntegerMap();
    WorldObject person1 = TestUtils.createWorldObject(1, "Test1");
    WorldObject person2 = TestUtils.createWorldObject(2, "Test2");

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

    assertEquals(Arrays.asList(2), idMap.getIdsWithoutTarget(person1));
    assertEquals(Arrays.asList(1), idMap.getIdsWithoutTarget(person2));
  }
Exemplo n.º 5
0
  @Test
  public void testWorship() {
    World world = new WorldImpl(1, 1, null, null);
    WorldObject performer = TestUtils.createIntelligentWorldObject(2, "performer");
    WorldObject target = TestUtils.createIntelligentWorldObject(3, "target");

    assertEquals(0, performer.getProperty(Constants.ARCHERY_SKILL).getLevel(performer));
    deity.worship(performer, target, 4, world);
    assertEquals(0, performer.getProperty(Constants.ARCHERY_SKILL).getLevel(performer));
    deity.worship(performer, target, 5, world);

    assertEquals(2, performer.getProperty(Constants.ARCHERY_SKILL).getLevel(performer));
  }
  @Test
  public void testHandleResponseMinus999() {
    World world = new WorldImpl(1, 1, null, null);
    WorldObject performer =
        TestUtils.createIntelligentWorldObject(1, Constants.RELATIONSHIPS, new IdRelationshipMap());
    WorldObject target =
        TestUtils.createIntelligentWorldObject(2, Constants.RELATIONSHIPS, new IdRelationshipMap());

    ConversationContext context = new ConversationContext(performer, target, null, null, world, 0);

    conversation.handleResponse(-999, context);
    assertEquals(-50, performer.getProperty(Constants.RELATIONSHIPS).getValue(target));
    assertEquals(-50, target.getProperty(Constants.RELATIONSHIPS).getValue(performer));
  }
  @Test
  public void testGetReplyPhrases() {
    WorldObject performer =
        TestUtils.createIntelligentWorldObject(1, Constants.RELATIONSHIPS, new IdRelationshipMap());
    WorldObject target =
        TestUtils.createIntelligentWorldObject(2, Constants.RELATIONSHIPS, new IdRelationshipMap());

    ConversationContext context = new ConversationContext(performer, target, null, null, null, 0);
    List<Response> replyPhrases = conversation.getReplyPhrases(context);
    assertEquals(true, replyPhrases.size() == 4);
    assertEquals("Get lost", replyPhrases.get(0).getResponsePhrase());
    assertEquals("I'll give you the money", replyPhrases.get(1).getResponsePhrase());
    assertEquals("No", replyPhrases.get(2).getResponsePhrase());
    assertEquals("I can only spare a bit of gold", replyPhrases.get(3).getResponsePhrase());
  }
Exemplo n.º 8
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));
  }
 @Test
 public void testIsValidTarget() {
   World world = new WorldImpl(10, 10, null, null);
   WorldObject performer = createPerformer(2);
   WorldObject target = TestUtils.createWorldObject(0, 0, 1, 1);
   assertEquals(true, Actions.BUILD_ARENA_ACTION.isValidTarget(performer, target, world));
 }
 @Test
 public void testSetTwoHandedWeapons() {
   WorldObject performer = TestUtils.createSkilledWorldObject(1);
   MeleeDamagePropertyUtils.setTwoHandedWeapons(performer, Constants.LEFT_HAND_EQUIPMENT);
   assertEquals(null, performer.getProperty(Constants.LEFT_HAND_EQUIPMENT));
   assertEquals(null, performer.getProperty(Constants.RIGHT_HAND_EQUIPMENT));
 }
 private WorldObject createPerformer(int id) {
   WorldObject performer =
       TestUtils.createSkilledWorldObject(id, Constants.INVENTORY, new WorldObjectContainer());
   performer.setProperty(Constants.X, 0);
   performer.setProperty(Constants.Y, 0);
   performer.setProperty(Constants.WIDTH, 1);
   performer.setProperty(Constants.HEIGHT, 1);
   return performer;
 }
Exemplo n.º 12
0
  @Test
  public void testGetReasonIndex() {
    World world = new WorldImpl(1, 1, null, null);
    WorldObject performer = TestUtils.createSkilledWorldObject(2);

    assertEquals(-1, deity.getReasonIndex(performer, world));

    performer.setProperty(Constants.PROFESSION, Professions.PRIEST_PROFESSION);
    assertEquals(0, deity.getReasonIndex(performer, world));
  }
 private WorldObject createPerformer(int id) {
   WorldObject performer =
       TestUtils.createSkilledWorldObject(id, Constants.CONDITIONS, new Conditions());
   performer.setProperty(Constants.X, 0);
   performer.setProperty(Constants.Y, 0);
   performer.setProperty(Constants.WIDTH, 1);
   performer.setProperty(Constants.HEIGHT, 1);
   performer.setProperty(Constants.ENERGY, 1000);
   return performer;
 }
  @Test
  public void testExecute() {
    World world = new WorldImpl(10, 10, null, null);
    WorldObject performer =
        TestUtils.createSkilledWorldObject(2, Constants.INVENTORY, new WorldObjectContainer());
    WorldObject target = createSmith(world, performer);
    Actions.CRAFT_IRON_GAUNTLETS_ACTION.execute(performer, target, Args.EMPTY, world);

    assertEquals(1, performer.getProperty(Constants.INVENTORY).getQuantityFor(Constants.ARMOR));
  }
  @Test
  public void testCalculateMeleeDamageIronGauntlets() {
    WorldObject performer = TestUtils.createSkilledWorldObject(1);

    assertEquals(
        2 * Item.COMBAT_MULTIPLIER, MeleeDamagePropertyUtils.calculateMeleeDamage(performer));

    performer.setProperty(Constants.ARMS_EQUIPMENT, Item.IRON_GAUNTLETS.generate(1f));
    assertEquals(
        7 * Item.COMBAT_MULTIPLIER, MeleeDamagePropertyUtils.calculateMeleeDamage(performer));
  }
  @Test
  public void testCalculateMeleeDamageDualWielding() {
    WorldObject performer = TestUtils.createSkilledWorldObject(1);

    assertEquals(
        2 * Item.COMBAT_MULTIPLIER, MeleeDamagePropertyUtils.calculateMeleeDamage(performer));

    performer.setProperty(Constants.LEFT_HAND_EQUIPMENT, Item.IRON_CLAYMORE.generate(1f));
    performer.setProperty(Constants.RIGHT_HAND_EQUIPMENT, Item.IRON_CLAYMORE.generate(1f));
    assertEquals(
        24 * Item.COMBAT_MULTIPLIER, MeleeDamagePropertyUtils.calculateMeleeDamage(performer));
  }
  @Test
  public void testIsValidTarget() {
    World world = new WorldImpl(10, 10, null, null);
    WorldObject performer =
        TestUtils.createSkilledWorldObject(2, Constants.INVENTORY, new WorldObjectContainer());

    WorldObject target = createSmith(world, performer);

    assertEquals(
        false, Actions.CRAFT_IRON_GAUNTLETS_ACTION.isValidTarget(performer, performer, world));
    assertEquals(true, Actions.CRAFT_IRON_GAUNTLETS_ACTION.isValidTarget(performer, target, world));
  }
  @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 testSetTwoHandedWeaponsRemoveTwoHandedWeapon() {
    WorldObject performer = TestUtils.createSkilledWorldObject(1);

    WorldObject twoHandedGreatsword = Item.IRON_GREATSWORD.generate(1f);
    WorldObject oneHandedClaymore = Item.IRON_CLAYMORE.generate(1f);
    oneHandedClaymore.setProperty(Constants.ID, 3);
    performer.setProperty(Constants.LEFT_HAND_EQUIPMENT, oneHandedClaymore);
    performer.setProperty(Constants.RIGHT_HAND_EQUIPMENT, twoHandedGreatsword);

    MeleeDamagePropertyUtils.setTwoHandedWeapons(performer, Constants.LEFT_HAND_EQUIPMENT);
    assertEquals(oneHandedClaymore, performer.getProperty(Constants.LEFT_HAND_EQUIPMENT));
    assertEquals(null, performer.getProperty(Constants.RIGHT_HAND_EQUIPMENT));
  }
Exemplo n.º 20
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));
  }
Exemplo n.º 21
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));
  }
  @Test
  public void testCalculateMeleeDamage() {
    WorldObject performer = TestUtils.createSkilledWorldObject(1);

    assertEquals(
        2 * Item.COMBAT_MULTIPLIER, MeleeDamagePropertyUtils.calculateMeleeDamage(performer));

    performer.setProperty(Constants.LEFT_HAND_EQUIPMENT, Item.IRON_CLAYMORE.generate(1f));
    assertEquals(
        12 * Item.COMBAT_MULTIPLIER, MeleeDamagePropertyUtils.calculateMeleeDamage(performer));

    WorldObject twoHandedGreatsword = Item.IRON_GREATSWORD.generate(1f);
    performer.setProperty(Constants.LEFT_HAND_EQUIPMENT, twoHandedGreatsword);
    performer.setProperty(Constants.RIGHT_HAND_EQUIPMENT, twoHandedGreatsword);
    assertEquals(
        24 * Item.COMBAT_MULTIPLIER, MeleeDamagePropertyUtils.calculateMeleeDamage(performer));
  }