Exemplo n.º 1
0
  public void test_0() throws Exception {
    Entity entity = new Entity(3, "jobs");
    String text =
        JSON.toJSONString(entity, SerializerFeature.WriteClassName, SerializerFeature.PrettyFormat);
    System.out.println(text);

    Entity entity2 = (Entity) JSON.parseObject(text, Object.class);

    Assert.assertEquals(entity.getId(), entity2.getId());
    Assert.assertEquals(entity.getName(), entity2.getName());
  }
Exemplo n.º 2
0
 @Override
 public Entity getEntityById(int id) {
   synchronized (entities) {
     for (Entity entity : entities) if (id == entity.getId()) return entity;
     return null;
   }
 }
Exemplo n.º 3
0
 // remove an entity from the controller
 // returns true if an entity was removed
 // returns false if there is no entity with the given id
 public boolean removeEntity(long id) {
   for (Entity e : this.entity_list) {
     if (e.getId() == id) {
       this.removeEntity(e);
     }
   }
   return false;
 }
Exemplo n.º 4
0
  public void test_list_map_none_root() throws Exception {
    JSONPath path = new JSONPath("*");
    Entity entity = new Entity(123, "wenshao");

    List<Object> fieldValues = (List<Object>) path.eval(entity);
    Assert.assertSame(entity.getId(), fieldValues.get(0));
    Assert.assertSame(entity.getName(), fieldValues.get(1));
  }
  @Override
  void steps() {
    Entity c1 = postEntity(new CustomerDetails("ssn1", "name1", 1.0));
    Entity c2 = postEntity(new CustomerDetails("ssn2", "name2", 2.0));
    Entity p1 = postEntity(new Product("111", "name 1", "desc 1", 1.0));
    Entity p2 = postEntity(new Product("222", "name 2", "desc 2", 2.0));

    openApp();
    clickEntityType(CustomerDetails.class);
    checkId(By.id("olist_CustomerDetails"));

    checkTextById("li_" + c1.getId(), "Mask(ssn1) [name1] 1;");
    checkTextById("li_" + c2.getId(), "Mask(ssn2) [name2] 2;");

    openApp();
    clickEntityType(Product.class);
    checkId(By.id("olist_Product"));
    checkTextById("li_" + p1.getId(), "111; [name 1] desc 1/1;");
    checkTextById("li_" + p2.getId(), "222; [name 2] desc 2/2;");
  }
Exemplo n.º 6
0
  public IAuthorizationPrincipal getPrincipalForEntity(Entity entity) {

    // attempt to determine the entity type class for this principal
    Class entityType;
    if (entity.getEntityType().equals(EntityEnum.GROUP.toString())) {
      entityType = IEntityGroup.class;
    } else {
      entityType = EntityEnum.getEntityEnum(entity.getEntityType()).getClazz();
    }

    // construct an authorization principal for this JsonEntityBean
    AuthorizationService authService = AuthorizationService.instance();
    IAuthorizationPrincipal p = authService.newPrincipal(entity.getId(), entityType);
    return p;
  }
Exemplo n.º 7
0
  public void testQueryEntity() throws Exception {
    Database db = _jdo.getDatabase();
    db.begin();

    OQLQuery query =
        db.getOQLQuery("SELECT entity FROM " + Entity.class.getName() + " entity WHERE id = $1");
    query.bind(new Integer(1));
    QueryResults results = query.execute();

    Entity entity = (Entity) results.next();

    assertNotNull(entity);
    assertEquals(new Integer(1), entity.getId());

    db.commit();
    db.close();
  }
Exemplo n.º 8
0
 // Returns a list of non-self targets that intersect with the projectile
 public ArrayList<Entity> collisionCheck() {
   ArrayList<Entity> targets = new ArrayList<Entity>();
   for (Entity e : EntityManager.getInstance().getEntitiesListIteration()) {
     if (!(e.equals(caster))
         && e.isActive()
         && !e.equals(this)
         && e.getCurrentLevel().equals(caster.getCurrentLevel())) {
       if (!hitEntities.contains(e)) {
         if (Intersector.overlaps(e.getAABB(), aabb)) {
           targets.add(e);
           hitEntities.add(e);
           if (Game.getDebugMode()) System.out.println(e.getName() + e.getId() + " was hit");
         }
       }
     }
   }
   return targets;
 }
  public void prepare() {
    Configuration cfg = new Configuration();
    cfg.setProperty(Environment.ENABLE_LAZY_LOAD_NO_TRANS, "true");
    cfg.setProperty(Environment.USE_SECOND_LEVEL_CACHE, "false");
    super.prepare(cfg);

    Session s = getFactory().openSession();
    s.beginTransaction();

    Entity entity = new Entity();
    entity.setDescription("desc");
    s.persist(entity);
    entityId = entity.getId();

    s.getTransaction().commit();
    s.clear();
    s.close();
  }
Exemplo n.º 10
0
 public Entity getEntityById(long id) {
   for (Entity e : this.entity_list) {
     if (e.getId() == id) return e;
   }
   return null;
 }
Exemplo n.º 11
0
  /** To-hit number for the mech to push another mech */
  public static ToHitData toHit(IGame game, int attackerId, Targetable target) {
    final Entity ae = game.getEntity(attackerId);
    int targetId = Entity.NONE;
    Entity te = null;
    if (target.getTargetType() == Targetable.TYPE_ENTITY) {
      te = (Entity) target;
      targetId = target.getTargetId();
    }
    if (ae == null)
      return new ToHitData(ToHitData.IMPOSSIBLE, "You can't attack from a null entity!");
    if (te == null) return new ToHitData(ToHitData.IMPOSSIBLE, "You can't target a null entity!");
    IHex attHex = game.getBoard().getHex(ae.getPosition());
    IHex targHex = game.getBoard().getHex(te.getPosition());
    final int attackerElevation = ae.getElevation() + attHex.getElevation();
    final int targetElevation = target.getElevation() + targHex.getElevation();
    final boolean targetInBuilding = Compute.isInBuilding(game, te);
    Building bldg = null;
    if (targetInBuilding) {
      bldg = game.getBoard().getBuildingAt(te.getPosition());
    }
    ToHitData toHit = null;

    // arguments legal?
    if (ae == null || target == null) {
      throw new IllegalArgumentException("Attacker or target not valid");
    }

    // can't target yourself
    if (ae.equals(te)) {
      return new ToHitData(ToHitData.IMPOSSIBLE, "You can't target yourself");
    }

    // non-mechs can't push
    if (!(ae instanceof Mech)) {
      return new ToHitData(ToHitData.IMPOSSIBLE, "Non-mechs can't push");
    }

    // Quads can't push
    if (ae.entityIsQuad()) {
      return new ToHitData(ToHitData.IMPOSSIBLE, "Attacker is a quad");
    }

    // can't make physical attacks while spotting
    if (ae.isSpotting()) {
      return new ToHitData(ToHitData.IMPOSSIBLE, "Attacker is spotting this turn");
    }

    // Can only push mechs
    if (te != null && !(te instanceof Mech)) {
      return new ToHitData(ToHitData.IMPOSSIBLE, "Target is not a mech");
    }

    // Can't push with flipped arms
    if (ae.getArmsFlipped()) {
      return new ToHitData(ToHitData.IMPOSSIBLE, "Arms are flipped to the rear. Can not push.");
    }

    // Can't target a transported entity.
    if (te != null && Entity.NONE != te.getTransportId()) {
      return new ToHitData(ToHitData.IMPOSSIBLE, "Target is a passenger.");
    }

    // Can't target a entity conducting a swarm attack.
    if (te != null && Entity.NONE != te.getSwarmTargetId()) {
      return new ToHitData(ToHitData.IMPOSSIBLE, "Target is swarming a Mek.");
    }

    // check if both arms are present
    if (ae.isLocationBad(Mech.LOC_RARM) || ae.isLocationBad(Mech.LOC_LARM)) {
      return new ToHitData(ToHitData.IMPOSSIBLE, "Arm missing");
    }

    // check if attacker has fired arm-mounted weapons
    if (ae.weaponFiredFrom(Mech.LOC_RARM) || ae.weaponFiredFrom(Mech.LOC_LARM)) {
      return new ToHitData(ToHitData.IMPOSSIBLE, "Weapons fired from arm this turn");
    }

    // check range
    if (ae.getPosition().distance(target.getPosition()) > 1) {
      return new ToHitData(ToHitData.IMPOSSIBLE, "Target not in range");
    }

    // target must be at same elevation
    if (attackerElevation != targetElevation) {
      return new ToHitData(ToHitData.IMPOSSIBLE, "Target not at same elevation");
    }

    // can't push mech making non-pushing displacement attack
    if (te != null && te.hasDisplacementAttack() && !te.isPushing()) {
      return new ToHitData(ToHitData.IMPOSSIBLE, "Target is making a charge/DFA attack");
    }

    // can't push mech pushing another, different mech
    if (te != null && te.isPushing() && te.getDisplacementAttack().getTargetId() != ae.getId()) {
      return new ToHitData(ToHitData.IMPOSSIBLE, "Target is pushing another mech");
    }

    // can't do anything but counter-push if the target of another attack
    if (ae.isTargetOfDisplacementAttack()
        && ae.findTargetedDisplacement().getEntityId() != target.getTargetId()) {
      return new ToHitData(
          ToHitData.IMPOSSIBLE, "Attacker is the target of another push/charge/DFA");
    }

    // can't attack the target of another displacement attack
    if (te != null
        && te.isTargetOfDisplacementAttack()
        && te.findTargetedDisplacement().getEntityId() != ae.getId()) {
      return new ToHitData(ToHitData.IMPOSSIBLE, "Target is the target of another push/charge/DFA");
    }

    // check facing
    if (!target.getPosition().equals(ae.getPosition().translated(ae.getFacing()))) {
      return new ToHitData(ToHitData.IMPOSSIBLE, "Target not directly ahead of feet");
    }

    // can't push while prone
    if (ae.isProne()) {
      return new ToHitData(ToHitData.IMPOSSIBLE, "Attacker is prone");
    }

    // can't push prone mechs
    if (te != null && te.isProne()) {
      return new ToHitData(ToHitData.IMPOSSIBLE, "Target is prone");
    }

    // Can't target units in buildings (from the outside).
    if (targetInBuilding) {
      if (!Compute.isInBuilding(game, ae)) {
        return new ToHitData(ToHitData.IMPOSSIBLE, "Target is inside building");
      } else if (!game.getBoard().getBuildingAt(ae.getPosition()).equals(bldg)) {
        return new ToHitData(ToHitData.IMPOSSIBLE, "Target is inside differnt building");
      }
    }

    // Attacks against adjacent buildings automatically hit.
    if ((target.getTargetType() == Targetable.TYPE_BUILDING)
        || (target.getTargetType() == Targetable.TYPE_FUEL_TANK)) {
      return new ToHitData(
          ToHitData.IMPOSSIBLE,
          "You can not push a building (well, you can, but it won't do anything).");
    }

    // Can't target woods or ignite a building with a physical.
    if (target.getTargetType() == Targetable.TYPE_BLDG_IGNITE
        || target.getTargetType() == Targetable.TYPE_HEX_CLEAR
        || target.getTargetType() == Targetable.TYPE_HEX_IGNITE) {
      return new ToHitData(ToHitData.IMPOSSIBLE, "Invalid attack");
    }

    // Set the base BTH
    int base = 4;

    if (game.getOptions().booleanOption("maxtech_physical_BTH")) {
      base = ae.getCrew().getPiloting() - 1;
    }

    toHit = new ToHitData(base, "base");

    // attacker movement
    toHit.append(Compute.getAttackerMovementModifier(game, attackerId));

    // target movement
    toHit.append(Compute.getTargetMovementModifier(game, targetId));

    // attacker terrain
    toHit.append(Compute.getAttackerTerrainModifier(game, attackerId));

    // target terrain
    toHit.append(Compute.getTargetTerrainModifier(game, te));

    // damaged or missing actuators
    if (!ae.hasWorkingSystem(Mech.ACTUATOR_SHOULDER, Mech.LOC_RARM)) {
      toHit.addModifier(2, "Right Shoulder destroyed");
    }
    if (!ae.hasWorkingSystem(Mech.ACTUATOR_SHOULDER, Mech.LOC_LARM)) {
      toHit.addModifier(2, "Left Shoulder destroyed");
    }

    // water partial cover?
    if (te.height() > 0
        && te.getElevation() == -1
        && targHex.terrainLevel(Terrains.WATER) == te.height()) {
      toHit.addModifier(3, "target has partial cover");
    }

    // target immobile
    toHit.append(Compute.getImmobileMod(te));

    Compute.modifyPhysicalBTHForAdvantages(ae, te, toHit, game);

    toHit.append(nightModifiers(game, target, null, ae));
    // side and elevation shouldn't matter

    // If it has a torso-mounted cockpit and two head sensor hits or three sensor hits...
    // It gets a =4 penalty for being blind!
    if (((Mech) ae).getCockpitType() == Mech.COCKPIT_TORSO_MOUNTED) {
      int sensorHits =
          ae.getBadCriticals(CriticalSlot.TYPE_SYSTEM, Mech.SYSTEM_SENSORS, Mech.LOC_HEAD);
      int sensorHits2 =
          ae.getBadCriticals(CriticalSlot.TYPE_SYSTEM, Mech.SYSTEM_SENSORS, Mech.LOC_CT);
      if ((sensorHits + sensorHits2) == 3) {
        return new ToHitData(
            ToHitData.IMPOSSIBLE, "Sensors Completely Destroyed for Torso-Mounted Cockpit");
      } else if (sensorHits == 2) {
        toHit.addModifier(4, "Head Sensors Destroyed for Torso-Mounted Cockpit");
      }
    }

    // done!
    return toHit;
  }
 /** Initialisiert ein Entity Event für angegebenes entity mit Subtyp und dazugehörigen Daten. */
 public EntityEvent(Entity entity, SubType sub, Serializable data) {
   this(entity.getId(), sub, data);
 }
Exemplo n.º 13
0
 /**
  * Convenience method that looks up the name of the given group member. Used for person types.
  *
  * @param entity Entity to look up
  * @return groupMember's name or null if there's an error
  */
 public String lookupEntityName(Entity entity) {
   EntityEnum entityEnum = EntityEnum.getEntityEnum(entity.getEntityType());
   return lookupEntityName(entityEnum, entity.getId());
 }