예제 #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);
 }
  @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 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));
 }
예제 #4
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;
  }
 @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);
 }
예제 #6
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);
  }
예제 #7
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);
 }
  @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);
  }
예제 #9
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 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 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));
  }
  @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 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));
  }
예제 #14
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);
 }
예제 #15
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;
 }
예제 #16
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;
 }
 @Override
 public List<Goal> getPriorities(WorldObject performer, World world) {
   Goal givenOrder = performer.getProperty(Constants.GIVEN_ORDER);
   if (givenOrder != null) {
     return Arrays.asList(givenOrder, Goals.KILL_OUTSIDERS_GOAL, Goals.IDLE_GOAL);
   } else {
     return Arrays.asList(Goals.KILL_OUTSIDERS_GOAL, Goals.IDLE_GOAL);
   }
 }
  @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));
  }
  private static int calculateRelationshipIncrease(WorldObject target, IntProperty property) {
    int relationshipBonus;

    if (target.getProperty(Constants.INVENTORY).getQuantityFor(property) > 0) {
      relationshipBonus = 5;
    } else {
      relationshipBonus = 10;
    }
    return relationshipBonus;
  }
  @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 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());
  }
 public static List<WorldObject> getOwnedCattle(WorldObject performer, World world) {
   int id = performer.getProperty(Constants.ID);
   List<WorldObject> ownedCattle =
       world.findWorldObjectsByProperty(
           Constants.MEAT_SOURCE,
           w ->
               w.getProperty(Constants.CATTLE_OWNER_ID) != null
                   && w.getProperty(Constants.CATTLE_OWNER_ID).intValue() == id);
   return ownedCattle;
 }
예제 #23
0
 public static boolean hasEnoughResources(
     WorldObject performer, IntProperty property, int quantity) {
   WorldObjectContainer inventory = performer.getProperty(Constants.INVENTORY);
   int inventoryQuantity = inventory.getQuantityFor(property);
   if (inventoryQuantity < quantity) {
     return false;
   } else {
     return true;
   }
 }
  @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 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));
  }
예제 #26
0
 public static boolean hasEnoughResources(
     WorldObject performer, int woodQuantity, int oreQuantity) {
   WorldObjectContainer inventory = performer.getProperty(Constants.INVENTORY);
   int wood = inventory.getQuantityFor(Constants.WOOD);
   int ore = inventory.getQuantityFor(Constants.ORE);
   if ((wood < woodQuantity) || (ore < oreQuantity)) {
     return false;
   } else {
     return true;
   }
 }
  @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());
  }
  private YesNoResponse getYesNoResponse(WorldObject target, World world) {
    StringBuilder responseBuilder = new StringBuilder(", ");
    int numberOfYesResponses = 0;
    if (target.getProperty(Constants.MATE_ID) != null) {
      int mateId = target.getProperty(Constants.MATE_ID);
      WorldObject mate = world.findWorldObjectById(mateId);
      responseBuilder.append("I have a mate named ").append(mate.getProperty(Constants.NAME));
      numberOfYesResponses++;
    } else {
      responseBuilder.append("I don't have a mate");
    }
    if (target.getProperty(Constants.CHILDREN).size() == 1) {
      responseBuilder.append(" and I have 1 child");
      numberOfYesResponses++;
    } else if (target.getProperty(Constants.CHILDREN).size() > 0) {
      responseBuilder
          .append(" and I have ")
          .append(target.getProperty(Constants.CHILDREN).size())
          .append(" children");
      numberOfYesResponses++;
    } else {
      responseBuilder.append(" and I don't have children");
    }

    if (numberOfYesResponses > 0) {
      return new YesNoResponse(responseBuilder.toString(), "");
    } else {
      return new YesNoResponse("", responseBuilder.toString());
    }
  }
  @Override
  public void execute(WorldObject performer, WorldObject target, int[] args, World world) {
    WorldObjectContainer inventory = performer.getProperty(Constants.INVENTORY);

    double skillBonus =
        SkillUtils.useSkill(
            performer, Constants.SMITHING_SKILL, world.getWorldStateChangedListeners());
    int quantity = SmithPropertyUtils.calculateSmithingQuantity(performer, target);
    inventory.addQuantity(Item.IRON_HELMET.generate(skillBonus), quantity);

    inventory.removeQuantity(Constants.WOOD, WOOD_REQUIRED);
    inventory.removeQuantity(Constants.ORE, ORE_REQUIRED);
  }
예제 #30
0
 private List<WorldObject> getNonMembersSellingItems(WorldObject performer, World world) {
   List<WorldObject> organizations =
       GroupPropertyUtils.findOrganizationsUsingLeader(performer, world);
   Profession profession = performer.getProperty(Constants.PROFESSION);
   if (profession != null) {
     List<Item> itemsSoldByProfession = profession.getSellItems();
     for (WorldObject organization : organizations) {
       return world.findWorldObjectsByProperty(
           Constants.STRENGTH, w -> nonMemberSoldItem(organization, w, itemsSoldByProfession));
     }
   }
   return new ArrayList<>();
 }