@Test public void testCheckLegalityAfterBrawlVictory() { World world = new WorldImpl(10, 10, null, null); world.addListener(new BrawlListener()); WorldObject villagersOrganization = createVillagersOrganization(world); WorldObject performer = TestUtils.createSkilledWorldObject( 2, Constants.GROUP, new IdList().add(villagersOrganization)); MockMetaInformation.setMetaInformation(performer, Goals.BRAWL_GOAL); WorldObject actionTarget = TestUtils.createSkilledWorldObject( 3, Constants.GROUP, new IdList().add(villagersOrganization)); world.addWorldObject(performer); world.addWorldObject(actionTarget); world.addWorldObject(TestUtils.createIntelligentWorldObject(4, "observer")); villagersOrganization = createVillagersOrganization(world); BrawlPropertyUtils.startBrawl(performer, actionTarget, 20); actionTarget.setProperty(Constants.HIT_POINTS, 1); new OperationInfo(performer, actionTarget, Args.EMPTY, Actions.NON_LETHAL_MELEE_ATTACK_ACTION) .perform(world); assertEquals(1, performer.getProperty(Constants.GROUP).size()); assertEquals(true, BrawlPropertyUtils.isBrawling(performer)); assertEquals(true, BrawlPropertyUtils.isBrawling(actionTarget)); BrawlPropertyUtils.completelyEndBrawling(performer); BrawlPropertyUtils.completelyEndBrawling(actionTarget); assertEquals(false, BrawlPropertyUtils.isBrawling(performer)); assertEquals(false, BrawlPropertyUtils.isBrawling(actionTarget)); }
@Test public void testAlterRelationships() { World world = new WorldImpl(1, 1, null, null); WorldObject performer = TestUtils.createIntelligentWorldObject(1, Constants.GENDER, "male"); WorldObject actionTarget = TestUtils.createIntelligentWorldObject(2, Constants.GROUP, new IdList()); world.addWorldObject(performer); world.addWorldObject(actionTarget); WorldObject villagersOrganization = createVillagersOrganization(world); performer.setProperty(Constants.GROUP, new IdList().add(villagersOrganization)); DefaultGoalObstructedHandler.alterRelationships( performer, actionTarget, actionTarget, null, Actions.MELEE_ATTACK_ACTION, world, -10, performer, actionTarget); assertEquals(-10, performer.getProperty(Constants.RELATIONSHIPS).getValue(actionTarget)); assertEquals(-10, actionTarget.getProperty(Constants.RELATIONSHIPS).getValue(performer)); assertEquals(true, actionTarget.getProperty(Constants.GROUP).getIds().isEmpty()); }
@Test public void testHasAnyoneSeenActionNoWitnesses() { World world = new WorldImpl(10, 10, null, null); WorldObject performer = TestUtils.createIntelligentWorldObject(1, Constants.GROUP, new IdList().add(1)); WorldObject actionTarget = TestUtils.createWorldObject(2, 2, 1, 1, Constants.ID, 2); world.addWorldObject(performer); world.addWorldObject(actionTarget); performer.setProperty(Constants.X, 1); performer.setProperty(Constants.Y, 1); assertEquals( false, DefaultGoalObstructedHandler.hasAnyoneSeenAction( performer, actionTarget, Actions.TALK_ACTION, Args.EMPTY, world)); }
@Test public void testIsLegalAttackOtherVillager() { World world = new WorldImpl(1, 1, null, null); WorldObject villagersOrganization = createVillagersOrganization(world); WorldObject performer = TestUtils.createIntelligentWorldObject( 2, Constants.GROUP, new IdList().add(villagersOrganization)); WorldObject actionTarget = TestUtils.createIntelligentWorldObject( 3, Constants.GROUP, new IdList().add(villagersOrganization)); world.addWorldObject(performer); world.addWorldObject(actionTarget); assertEquals( false, DefaultGoalObstructedHandler.isLegal( performer, actionTarget, Actions.FIRE_BOLT_ATTACK_ACTION, Args.EMPTY, world)); }
@Test public void testIsLegalAttackTree() { World world = new WorldImpl(10, 10, null, null); WorldObject villagersOrganization = createVillagersOrganization(world); WorldObject performer = TestUtils.createIntelligentWorldObject( 2, Constants.GROUP, new IdList().add(villagersOrganization)); int targetId = PlantGenerator.generateTree(0, 0, world); WorldObject actionTarget = world.findWorldObjectById(targetId); world.addWorldObject(performer); world.addWorldObject(TestUtils.createIntelligentWorldObject(3, "observer")); villagersOrganization = createVillagersOrganization(world); assertEquals( true, DefaultGoalObstructedHandler.isLegal( performer, actionTarget, Actions.FIRE_BOLT_ATTACK_ACTION, Args.EMPTY, world)); }
@Test public void testCalculateTargetDisguised() { World world = new WorldImpl(10, 10, null, null); WorldObject performer = TestUtils.createIntelligentWorldObject(2, "performer"); WorldObject target = TestUtils.createIntelligentWorldObject(3, "target"); WorldObject disguise = TestUtils.createIntelligentWorldObject(4, "disguise"); world.addWorldObject(disguise); FacadeUtils.disguise(target, disguise.getProperty(Constants.ID), world); performer.setProperty(Constants.KNOWLEDGE_MAP, new KnowledgeMap()); assertEquals(disguise, DefaultGoalObstructedHandler.calculateTarget(performer, target, world)); }
@Test public void testCheckLegality() { World world = new WorldImpl(10, 10, null, null); WorldObject villagersOrganization = createVillagersOrganization(world); WorldObject performer = TestUtils.createIntelligentWorldObject( 2, Constants.GROUP, new IdList().add(villagersOrganization)); MockMetaInformation.setMetaInformation(performer, Goals.BRAWL_GOAL); WorldObject actionTarget = TestUtils.createIntelligentWorldObject( 3, Constants.GROUP, new IdList().add(villagersOrganization)); world.addWorldObject(performer); world.addWorldObject(TestUtils.createIntelligentWorldObject(3, "observer")); villagersOrganization = createVillagersOrganization(world); new DefaultGoalObstructedHandler() .checkLegality(performer, actionTarget, Actions.FIRE_BOLT_ATTACK_ACTION, Args.EMPTY, world); assertEquals(200, BountyPropertyUtils.getBounty(performer, world)); assertEquals(0, performer.getProperty(Constants.GROUP).size()); }
@Test public void testLogToBackground() { World world = new WorldImpl(1, 1, null, null); WorldObject performer = TestUtils.createIntelligentWorldObject(1, Constants.GENDER, "male"); WorldObject actionTarget = TestUtils.createIntelligentWorldObject(2, Constants.GROUP, new IdList()); world.addWorldObject(performer); world.addWorldObject(actionTarget); actionTarget.setProperty(Constants.BACKGROUND, new BackgroundImpl()); DefaultGoalObstructedHandler.logToBackground( Goals.PROTECT_ONE_SELF_GOAL, actionTarget, actionTarget, Actions.MELEE_ATTACK_ACTION, Args.EMPTY, performer, world); List<String> angryReasons = actionTarget.getProperty(Constants.BACKGROUND).getAngryReasons(true, 2, performer, world); assertEquals(1, angryReasons.size()); }
@Test public void testHasAnyoneSeenActionInvisible() { World world = new WorldImpl(1, 1, null, null); WorldObject performer = TestUtils.createIntelligentWorldObject(1, Constants.GROUP, new IdList().add(1)); WorldObject actionTarget = TestUtils.createIntelligentWorldObject(2, Constants.GROUP, new IdList().add(1)); world.addWorldObject(performer); world.addWorldObject(actionTarget); Conditions.add(performer, Condition.INVISIBLE_CONDITION, 8, world); performer.setProperty(Constants.X, 1); performer.setProperty(Constants.Y, 1); actionTarget.setProperty(Constants.X, 2); actionTarget.setProperty(Constants.Y, 2); assertEquals( false, DefaultGoalObstructedHandler.hasAnyoneSeenAction( performer, actionTarget, Actions.TALK_ACTION, Args.EMPTY, world)); }
private WorldObject createVillagersOrganization(World world) { WorldObject organization = GroupPropertyUtils.createVillagersOrganization(world); organization.setProperty(Constants.ID, 1); world.addWorldObject(organization); return organization; }