Esempio n. 1
0
 public static WorldObject generateKey(int structureToLockId, World world) {
   WorldObject key = Item.KEY.generate(1f);
   WorldObject structureToLock = world.findWorldObjectById(structureToLockId);
   key.setProperty(Constants.NAME, getKeyName(structureToLock));
   key.setProperty(Constants.LOCK_ID, structureToLockId);
   return key;
 }
  @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());
  }
Esempio n. 3
0
 public static WorldObject generateNewsPaper(
     List<Knowledge> knowledgeList, int[] knowledgeIndices, World world) {
   WorldObject newsPaper = Item.NEWS_PAPER.generate(1f);
   String newsPaperText = generateNewsPaperText(knowledgeList, knowledgeIndices, world);
   newsPaper.setProperty(Constants.TEXT, newsPaperText);
   newsPaper.setProperty(Constants.KNOWLEDGE_MAP, new KnowledgeMap(knowledgeList));
   return newsPaper;
 }
 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;
 }
 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 testHasRequiredEnergy() {
    WorldObject performer = createPerformer(2);

    performer.setProperty(Constants.ENERGY, 1000);
    assertEquals(true, Actions.LIGHTNING_BOLT_ATTACK_ACTION.hasRequiredEnergy(performer));

    performer.setProperty(Constants.ENERGY, 0);
    assertEquals(false, Actions.LIGHTNING_BOLT_ATTACK_ACTION.hasRequiredEnergy(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 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));
  }
  @Test
  public void testExecute() {
    World world =
        new MockWorld(new MockTerrain(TerrainType.GRASLAND), new WorldImpl(10, 10, null, null));
    WorldObject performer = createPerformer(2);
    WorldObject target = createPerformer(3);

    target.setProperty(Constants.HIT_POINTS, 10 * Item.COMBAT_MULTIPLIER);
    target.setProperty(Constants.HIT_POINTS_MAX, 10 * Item.COMBAT_MULTIPLIER);

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

    assertEquals(5 * Item.COMBAT_MULTIPLIER, target.getProperty(Constants.HIT_POINTS).intValue());
  }
  @Test
  public void testIsActionPossible() {
    World world = new WorldImpl(1, 1, null, null);
    WorldObject performer = createPerformer(2);
    WorldObject target = createVotingBox(world);
    WorldObject organization =
        GroupPropertyUtils.createProfessionOrganization(
            performer.getProperty(Constants.ID), "", Professions.FARMER_PROFESSION, world);
    target.setProperty(Constants.ORGANIZATION_ID, organization.getProperty(Constants.ID));
    target.setProperty(Constants.TURN_COUNTER, 450);

    assertEquals(
        true,
        Actions.VOTE_FOR_LEADER_ACTION.isActionPossible(performer, target, Args.EMPTY, world));
  }
  @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));
  }
  @Test
  public void testIsValidTarget() {
    World world =
        new MockWorld(new MockTerrain(TerrainType.GRASLAND), new WorldImpl(10, 10, null, null));
    WorldObject performer = createPerformer(2);
    WorldObject target = createPerformer(3);

    assertEquals(
        false, Actions.LIGHTNING_BOLT_ATTACK_ACTION.isValidTarget(performer, target, world));

    performer.setProperty(
        Constants.KNOWN_SPELLS, Arrays.asList(Actions.LIGHTNING_BOLT_ATTACK_ACTION));
    target.setProperty(Constants.HIT_POINTS, 10);
    target.setProperty(Constants.ARMOR, 10);

    assertEquals(
        true, Actions.LIGHTNING_BOLT_ATTACK_ACTION.isValidTarget(performer, target, world));
  }
  @Test
  public void testHandleResponse2() {
    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());
    performer.setProperty(Constants.GOLD, 50);
    target.setProperty(Constants.GOLD, 50);

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

    conversation.handleResponse(2, context);
    assertEquals(20, performer.getProperty(Constants.RELATIONSHIPS).getValue(target));
    assertEquals(-5, target.getProperty(Constants.RELATIONSHIPS).getValue(performer));
    assertEquals(100, performer.getProperty(Constants.GOLD).intValue());
    assertEquals(0, target.getProperty(Constants.GOLD).intValue());
  }
  @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());
  }
Esempio n. 15
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));
  }
  @Test
  public void testIsValidTarget() {
    World world = new WorldImpl(1, 1, null, null);
    WorldObject performer = createPerformer(2);
    WorldObject target = createVotingBox(world);
    target.setProperty(Constants.ORGANIZATION_ID, 7);

    assertEquals(true, Actions.VOTE_FOR_LEADER_ACTION.isValidTarget(performer, target, world));
    assertEquals(false, Actions.VOTE_FOR_LEADER_ACTION.isValidTarget(performer, performer, world));
  }
  @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 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());
  }
  @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));
  }
Esempio n. 20
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. 21
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. 22
0
 public WorldObject generate(double skillBonus) {
   WorldObject item = ITEMS.get(this).apply(skillBonus);
   item.setProperty(Constants.ITEM_ID, this);
   return item;
 }
Esempio n. 23
0
 public static WorldObject generateMiniatureChest(WorldObject chest) {
   WorldObject miniatureChest = Item.MINIATURE_CHEST.generate(1f);
   miniatureChest.setProperty(Constants.CHEST_ID, chest.getProperty(Constants.ID));
   return miniatureChest;
 }
Esempio n. 24
0
 private WorldObject createVillagersOrganization(World world) {
   WorldObject organization = GroupPropertyUtils.createVillagersOrganization(world);
   organization.setProperty(Constants.ID, 1);
   world.addWorldObject(organization);
   return organization;
 }
Esempio n. 25
0
 public static WorldObject generateSpellBook(MagicSpell magicSpell) {
   WorldObject spellBook = Item.SPELLBOOK.generate(1f);
   spellBook.setProperty(Constants.MAGIC_SPELL, magicSpell);
   return spellBook;
 }