@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 testActionTargetIsCriminal() {
    World world = new WorldImpl(10, 10, null, null);
    WorldObject organization = createVillagersOrganization(world);

    WorldObject performer =
        TestUtils.createIntelligentWorldObject(1, Constants.GROUP, new IdList());
    assertEquals(true, DefaultGoalObstructedHandler.actionTargetIsCriminal(performer, world));

    performer.getProperty(Constants.GROUP).add(organization);
    assertEquals(false, DefaultGoalObstructedHandler.actionTargetIsCriminal(performer, 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 testAreBrawlingItemEquiped() {
    WorldObject performer =
        TestUtils.createIntelligentWorldObject(1, Constants.BRAWL_OPPONENT_ID, 2);
    WorldObject actionTarget =
        TestUtils.createIntelligentWorldObject(2, Constants.BRAWL_OPPONENT_ID, 1);

    performer.setProperty(Constants.LEFT_HAND_EQUIPMENT, Item.IRON_CLAYMORE.generate(1f));

    assertEquals(
        false,
        DefaultGoalObstructedHandler.areBrawling(
            performer, actionTarget, Actions.NON_LETHAL_MELEE_ATTACK_ACTION));
  }
Esempio n. 5
0
  @Override
  public void pulse(int deltaTime) {
    if (timerBuffPulse == null) {
      timerBuffPulse = new TickTimer();
      timerBuffPulse.start(getTime(), BuffManager.INTERVAL_PULSE);
    }
    if (timerStatePulse == null) {
      timerStatePulse = new TickTimer();
      timerStatePulse.start(getTime(), 100);
    }
    super.pulse(deltaTime);

    // 单元移动了
    pulseMove(timeCurr);

    // 周期到了,则更新身上的buff
    if (timerBuffPulse.isPeriod(timeCurr)) {
      BuffManager.inst().pulse(this, timeCurr);
    }

    // 施放可以施放的有前摇的技能
    updateSkill(timeCurr);

    // 更新各种状态
    updateState(timeCurr);
  }
  @Test
  public void testPerformerAttacksAnimal() {
    World world = new WorldImpl(10, 10, null, null);
    WorldObject performer = TestUtils.createIntelligentWorldObject(2, "performer");

    CreatureGenerator creatureGenerator =
        new CreatureGenerator(TestUtils.createIntelligentWorldObject(1, "cow"));
    int cowId = creatureGenerator.generateCow(0, 0, world);
    WorldObject cow = world.findWorldObjectById(cowId);

    assertEquals(false, cow.getProperty(Constants.ANIMAL_ENEMIES).contains(performer));

    DefaultGoalObstructedHandler.performerAttacksAnimal(performer, cow);

    assertEquals(true, cow.getProperty(Constants.ANIMAL_ENEMIES).contains(performer));
  }
  @Test
  public void testCalculateTargetMaskedIllusion() {
    World world = new WorldImpl(10, 10, null, null);
    WorldObject performer = TestUtils.createIntelligentWorldObject(2, "performer");
    WorldObject target =
        TestUtils.createIntelligentWorldObject(3, Constants.ILLUSION_CREATOR_ID, 7);
    target.setProperty(Constants.X, 1);
    target.setProperty(Constants.Y, 1);

    WorldObject realTarget = TestUtils.createIntelligentWorldObject(3, "realTarget");
    realTarget.setProperty(Constants.X, 1);
    realTarget.setProperty(Constants.Y, 1);

    assertEquals(
        realTarget, DefaultGoalObstructedHandler.calculateTarget(performer, target, world));
  }
  @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 testAreBrawlingNoBrawlOpponentId() {
    WorldObject performer =
        TestUtils.createIntelligentWorldObject(1, Constants.BRAWL_OPPONENT_ID, null);
    WorldObject actionTarget =
        TestUtils.createIntelligentWorldObject(2, Constants.BRAWL_OPPONENT_ID, null);

    assertEquals(
        true,
        DefaultGoalObstructedHandler.areBrawling(
            performer, actionTarget, Actions.NON_LETHAL_MELEE_ATTACK_ACTION));

    performer.removeProperty(Constants.BRAWL_OPPONENT_ID);
    actionTarget.removeProperty(Constants.BRAWL_OPPONENT_ID);
    assertEquals(
        false,
        DefaultGoalObstructedHandler.areBrawling(
            performer, actionTarget, Actions.NON_LETHAL_MELEE_ATTACK_ACTION));
  }
  @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 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());
  }
Esempio n. 12
0
  public WorldObject create(DialogSession session, Map<String, String> properties) {
    String type = properties.get(WorldObject.FIELD_TYPE);
    if (type == null) {
      // throw new IllegalArgumentException("Missing type property!");
      logger.warn("Missing type property in " + properties);
    }

    WorldObject worldObject;
    if (type == null || !typeRegistry.containsKey(type)) {
      if (type != null) {
        logger.warn("Unknown type: " + type);
      }

      worldObject = new DefaultWorldObject(type);

    } else {
      Class<? extends WorldObject> typeClass = typeRegistry.get(type);
      Constructor<? extends WorldObject> constructor;
      try {
        constructor = typeClass.getConstructor();
      } catch (NoSuchMethodException | SecurityException e) {
        throw new RuntimeException(
            "Cannot access constructor " + typeClass.getSimpleName() + "(DialogSession, Map)", e);
      }

      try {
        worldObject = constructor.newInstance();
      } catch (InstantiationException
          | IllegalAccessException
          | IllegalArgumentException
          | InvocationTargetException e) {
        throw new RuntimeException("Could not create an instance of class " + typeClass, e);
      }
    }

    worldObject.init(session, properties);

    return worldObject;
  }
  @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));
  }
  @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());
  }
Esempio n. 15
0
 @Override
 public void writeTo(OutputStream out) throws IOException {
   super.writeTo(out);
   out.write(teamBundleID);
   out.write(order);
 }
 private WorldObject createVillagersOrganization(World world) {
   WorldObject organization = GroupPropertyUtils.createVillagersOrganization(world);
   organization.setProperty(Constants.ID, 1);
   world.addWorldObject(organization);
   return organization;
 }
Esempio n. 17
0
 @Override
 public void readFrom(InputStream in) throws IOException {
   super.readFrom(in);
   teamBundleID = in.read();
   order = in.read();
 }