@Test public void testExecute() { World world = new WorldImpl(1, 1, null, null); WorldObject performer = createPerformer(2); WorldObject target = createPerformer(3); Actions.PLANT_NIGHT_SHADE_ACTION.execute(performer, target, Args.EMPTY, world); assertEquals(1, world.getWorldObjects().size()); assertEquals("nightshade", world.getWorldObjects().get(0).getProperty(Constants.NAME)); }
@Test public void testExecute() { World world = new WorldImpl(20, 20, null, null); WorldObject performer = createPerformer(2); WorldObject target = createPerformer(3); Actions.BUILD_ARENA_ACTION.execute(performer, target, Args.EMPTY, world); assertEquals(6, world.getWorldObjects().size()); assertEquals("Arena vertical", world.getWorldObjects().get(0).getProperty(Constants.NAME)); }
@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)); }
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; }
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()); } }
@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 testGiveBirth() { World world = new WorldImpl(10, 10, null, new DoNothingWorldOnTurn()); WorldObject organization = GroupPropertyUtils.create(null, "TestOrg", world); WorldObject fish = createFish(world, organization); assertEquals(2, world.getWorldObjects().size()); world = new MockWorld(new MockTerrain(TerrainType.WATER), world); for (int i = 0; i < 300; i++) { world.nextTurn(); fish.onTurn(world, new WorldStateChangedListeners()); } assertEquals(3, world.getWorldObjects().size()); }
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; }
@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 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()); }
@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); }
@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); }
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) { 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); }
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<>(); }
@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)); }
@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)); }
@Override public OperationInfo calculateGoal(WorldObject performer, World world) { for (WorldObject nonMember : getNonMembersSellingItems(performer, world)) { boolean actionAlreadyPerformed = world .getHistory() .findHistoryItems( performer, nonMember, Conversations.createArgs(Conversations.STOP_SELLING_CONVERSATION), Actions.TALK_ACTION) .size() > 0; if (!actionAlreadyPerformed) { return new OperationInfo( performer, nonMember, Conversations.createArgs(Conversations.STOP_SELLING_CONVERSATION), Actions.TALK_ACTION); } } return null; }
private WorldObject createVillagersOrganization(World world) { WorldObject organization = GroupPropertyUtils.createVillagersOrganization(world); organization.setProperty(Constants.ID, 1); world.addWorldObject(organization); return organization; }
private WorldObject createVotingBox(World world) { int id = BuildingGenerator.generateVotingBox(0, 0, world); WorldObject target = world.findWorldObjectById(id); return target; }
private WorldObject createFish(World world, WorldObject organization) { int fishId = new CreatureGenerator(organization).generateFish(0, 0, world); WorldObject fish = world.findWorldObjectById(fishId); return fish; }
private WorldObject createSmith(World world, WorldObject performer) { int smithId = BuildingGenerator.generateSmith(0, 0, world, performer); WorldObject target = world.findWorldObjectById(smithId); return target; }