Ejemplo n.º 1
0
 private boolean isPotentialTarget(WorldObject performer, WorldObject w, World world) {
   return performer.getProperty(Constants.DEITY) != null
       && w.getProperty(Constants.DEITY) != null
       && performer.getProperty(Constants.DEITY) != w.getProperty(Constants.DEITY)
       && !GroupPropertyUtils.isWorldObjectPotentialEnemy(performer, w)
       && !Conversations.SWITCH_DEITY_CONVERSATION.previousAnswerWasGetLost(performer, w, world);
 }
Ejemplo n.º 2
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;
 }
Ejemplo n.º 3
0
 public static boolean isValidBuildTarget(
     BuildAction buildAction, WorldObject performer, WorldObject target, World world) {
   int x = (Integer) target.getProperty(Constants.X);
   int y = (Integer) target.getProperty(Constants.Y);
   return !target.hasProperty(Constants.ID)
       && GoalUtils.isOpenSpace(x, y, buildAction.getWidth(), buildAction.getHeight(), 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));
 }
Ejemplo n.º 5
0
  private static Map<String, String> generateAdditionalProperties(
      WorldObject inventoryWorldObject) {
    Map<String, String> additionalProperties = new LinkedHashMap<>();

    List<ManagedProperty<?>> propertyKeys = inventoryWorldObject.getPropertyKeys();
    Collections.sort(propertyKeys, new PropertyComparator());

    for (ManagedProperty<?> propertyKey : propertyKeys) {
      String name = propertyKey.getName().toLowerCase();
      if (propertyKey == Constants.DAMAGE
          || propertyKey == Constants.ARMOR
          || propertyKey == Constants.WEIGHT
          || propertyKey == Constants.QUANTITY
          || Constants.isTool(propertyKey)) {
        String value = inventoryWorldObject.getProperty(propertyKey).toString();
        additionalProperties.put(name, value);
      } else if (propertyKey == Constants.EQUIPMENT_HEALTH) {
        String value = inventoryWorldObject.getProperty(propertyKey).toString();
        int intValue = Integer.parseInt(value);
        int percentage = (100 * intValue) / 1000;
        additionalProperties.put(name, percentage + "%");
      } else if (propertyKey == Constants.SELLABLE) {
        Boolean sellable = (Boolean) inventoryWorldObject.getProperty(propertyKey);
        additionalProperties.put(name, sellable ? "yes" : "no");
      } else if (propertyKey == Constants.TWO_HANDED_WEAPON) {
        Boolean twohHanded = (Boolean) inventoryWorldObject.getProperty(propertyKey);
        additionalProperties.put("two handed", twohHanded ? "yes" : "no");
      }
    }

    return additionalProperties;
  }
Ejemplo n.º 6
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));
  }
Ejemplo n.º 10
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 testIsGoalMet() {
    World world = new WorldImpl(10, 10, null, null);
    WorldObject performer = createPerformer(2);

    assertEquals(true, goal.isGoalMet(performer, world));

    performer.getProperty(Constants.INVENTORY).addQuantity(Item.WOOD.generate(1f), 10);
    assertEquals(false, goal.isGoalMet(performer, world));
  }
  @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 testExecute() {
    World world = new WorldImpl(1, 1, null, null);
    WorldObject performer = createPerformer(2);
    WorldObject target = createVotingBox(world);

    Actions.VOTE_FOR_LEADER_ACTION.execute(performer, target, new int[] {7}, world);

    assertEquals(1, target.getProperty(Constants.VOTES).getValue(7));
  }
  @Test
  public void testIsActionPossible() {
    World world = new WorldImpl(1, 1, null, null);
    WorldObject performer = createPerformer(2);
    WorldObject target = createPerformer(3);
    performer.getProperty(Constants.INVENTORY).addQuantity(Item.STONE.generate(1f), 10);

    assertEquals(
        true, Actions.BUILD_ARENA_ACTION.isActionPossible(performer, target, Args.EMPTY, world));
  }
 @Override
 public boolean isConversationAvailable(WorldObject performer, WorldObject target, World world) {
   WorldObject facade = performer.getProperty(Constants.FACADE);
   KnowledgeMap knowledgeMap = target.getProperty(Constants.KNOWLEDGE_MAP);
   boolean targetHasKnowledgeOverFacade =
       knowledgeMap != null ? knowledgeMap.hasProperty(performer, Constants.FACADE) : false;
   return ((facade != null)
       && (!FacadeUtils.performerIsSuccessFullyDisguised(performer))
       && targetHasKnowledgeOverFacade);
 }
  @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 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));
  }
  @Override
  public void execute(WorldObject performer, WorldObject target, int[] args, World world) {
    int x = (Integer) target.getProperty(Constants.X);
    int y = (Integer) target.getProperty(Constants.Y);

    int workbenchId = BuildingGenerator.generateWorkbench(x, y, world, performer);
    SkillUtils.useSkill(
        performer, Constants.CARPENTRY_SKILL, world.getWorldStateChangedListeners());

    performer.getProperty(Constants.INVENTORY).removeQuantity(Constants.STONE, REQUIRED_STONE);
    performer.getProperty(Constants.BUILDINGS).add(workbenchId, BuildingType.WORKBENCH);
  }
Ejemplo n.º 20
0
  @Override
  public void execute(WorldObject performer, WorldObject target, int[] args, World world) {
    WorldObjectContainer inventory = performer.getProperty(Constants.INVENTORY);

    double skillBonus =
        SkillUtils.useSkill(
            performer, Constants.ALCHEMY_SKILL, world.getWorldStateChangedListeners());
    int quantity = target.getProperty(Constants.APOTHECARY_QUALITY);
    inventory.addQuantity(Item.POISON.generate(skillBonus), quantity);

    inventory.removeQuantity(Constants.NIGHT_SHADE, NIGHT_SHADE_REQUIRED);
  }
  @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));
  }
Ejemplo n.º 22
0
 public void addToInventory(
     WorldObject performer,
     WorldObject target,
     SkillProperty skillProperty,
     IntProperty qualityProperty,
     World world) {
   double skillBonus =
       SkillUtils.useSkill(performer, skillProperty, world.getWorldStateChangedListeners());
   int quantity = target.getProperty(qualityProperty);
   WorldObjectContainer inventory = performer.getProperty(Constants.INVENTORY);
   inventory.addQuantity(generate(skillBonus), quantity);
 }
Ejemplo n.º 23
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 testIsActionPossible() {
    World world = new WorldImpl(10, 10, null, null);
    WorldObject performer = createPerformer(2);
    performer.getProperty(Constants.INVENTORY).addQuantity(Item.WOOD.generate(1f), 20);
    performer.getProperty(Constants.INVENTORY).addQuantity(Item.ORE.generate(1f), 20);

    WorldObject target = createSmith(world, performer);

    assertEquals(
        true,
        Actions.CRAFT_IRON_GAUNTLETS_ACTION.isActionPossible(performer, target, Args.EMPTY, world));
  }
Ejemplo n.º 25
0
  @Override
  public Response getReplyPhrase(ConversationContext conversationContext) {
    WorldObject target = conversationContext.getTarget();

    final int replyId;
    if ((target.getProperty(Constants.MATE_ID) != null)
        || (target.getProperty(Constants.CHILDREN).size() > 0)) {
      replyId = YES;
    } else {
      replyId = NO;
    }

    return getReply(getReplyPhrases(conversationContext), replyId);
  }
  @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 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());
  }
Ejemplo n.º 28
0
 public static boolean isClothesEquipment(WorldObject worldObject) {
   Item item = worldObject.getProperty(Constants.ITEM_ID);
   return item == Item.COTTON_BOOTS
       || item == Item.COTTON_GLOVES
       || item == Item.COTTON_HAT
       || item == Item.COTTON_PANTS
       || item == Item.COTTON_SHIRT;
 }
Ejemplo n.º 29
0
 public static boolean isLeatherEquipment(WorldObject worldObject) {
   Item item = worldObject.getProperty(Constants.ITEM_ID);
   return item == Item.LEATHER_BOOTS
       || item == Item.LEATHER_GLOVES
       || item == Item.LEATHER_HAT
       || item == Item.LEATHER_PANTS
       || item == Item.LEATHER_SHIRT;
 }
  @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));
  }