@ReceiveEvent(components = {FenceGateComponent.class})
  public void onActivate(ActivateEvent event, EntityRef entity) {
    FenceGateComponent fenceGateComponent = entity.getComponent(FenceGateComponent.class);
    fenceGateComponent.isClosed = !fenceGateComponent.isClosed;
    entity.saveComponent(fenceGateComponent);

    BlockComponent blockComp = entity.getComponent(BlockComponent.class);
    if (blockComp == null) {
      event.cancel();
      return;
    }

    Vector3i primePos = new Vector3i(blockComp.getPosition());
    Block primeBlock = worldProvider.getBlock(primePos);

    Block newBlock = null;
    if (fenceGateComponent.isClosed) {
      newBlock =
          BlockManager.getInstance()
              .getBlockFamily("fences:FenceGateClosed")
              .getBlockForPlacing(worldProvider, primePos, primeBlock.getDirection(), Side.FRONT);
    } else {
      newBlock =
          BlockManager.getInstance()
              .getBlockFamily("fences:FenceGateOpen")
              .getBlockForPlacing(worldProvider, primePos, primeBlock.getDirection(), Side.FRONT);
    }

    if (newBlock != null) {
      blockEntityRegistry.setBlock(primePos, newBlock, primeBlock, entity);
    }
  }
Beispiel #2
0
 /**
  * adds a new zone to the corresponding zone list
  *
  * @param zone the zone to be added
  */
 public static void addZone(Zone zone) {
   ZoneListComponent zonelistcomp = zonelist.getComponent(ZoneListComponent.class);
   switch (zone.zonetype) {
     case Gather:
       {
         zonelistcomp.Gatherzones.add(zone);
         break;
       }
     case Work:
       {
         zonelistcomp.Workzones.add(zone);
         break;
       }
     case Terraform:
       {
         zonelistcomp.Terrazones.add(zone);
         break;
       }
     case Storage:
       {
         zonelistcomp.Storagezones.add(zone);
         break;
       }
     case OreonFarm:
       {
         zonelistcomp.OreonFarmzones.add(zone);
         break;
       }
   }
   zonelist.saveComponent(zonelistcomp);
 }
  private EntityData.Entity serializeEntityDelta(EntityRef entityRef, Prefab prefab) {
    EntityData.Entity.Builder entity = EntityData.Entity.newBuilder();
    entity.setId(entityRef.getId());
    entity.setParentPrefab(prefab.getName());
    for (Component component : entityRef.iterateComponents()) {
      if (component.getClass().equals(EntityInfoComponent.class)) continue;

      Component prefabComponent = prefab.getComponent(component.getClass());
      EntityData.Component componentData;
      if (prefabComponent == null) {
        componentData = serializeComponent(component);
      } else {
        componentData = serializeComponent(prefabComponent, component);
      }

      if (componentData != null) {
        entity.addComponent(componentData);
      }
    }
    for (Component prefabComponent : prefab.listComponents()) {
      if (!entityRef.hasComponent(prefabComponent.getClass())) {
        entity.addRemovedComponent(ComponentUtil.getComponentClassName(prefabComponent.getClass()));
      }
    }
    return entity.build();
  }
Beispiel #4
0
 /** creates a zonelist component used to save all zones (persist) */
 private static void createZoneList() {
   zonelist = CoreRegistry.get(EntityManager.class).create();
   ZoneListComponent zonecomp = new ZoneListComponent();
   zonelist.addComponent(zonecomp);
   zonelist.setPersisted(true);
   zonelist.saveComponent(zonecomp);
 }
Beispiel #5
0
 /**
  * destroys a minion at the end of their dying animation this implies that setting their animation
  * to die will destroy them.
  */
 @ReceiveEvent(components = {SkeletalMeshComponent.class, AnimationComponent.class})
 public void onAnimationEnd(AnimEndEvent event, EntityRef entity) {
   AnimationComponent animcomp = entity.getComponent(AnimationComponent.class);
   if (animcomp != null && event.getAnimation().equals(animcomp.dieAnim)) {
     entity.destroy();
   }
 }
Beispiel #6
0
 @JsonSerialize(include = Inclusion.NON_NULL)
 public List<UUID> getIds() {
   if (ids != null) {
     return ids;
   }
   /*
    * if (connectionTypeAndEntityTypeToEntityIdMap != null) { ids = new
    * ArrayList<UUID>(); Set<UUID> entitySet = new LinkedHashSet<UUID>();
    * for (String ctype : connectionTypeAndEntityTypeToEntityIdMap
    * .keySet()) { Map<String, List<UUID>> m =
    * connectionTypeAndEntityTypeToEntityIdMap .get(ctype); for (String
    * etype : m.keySet()) { List<UUID> l = m.get(etype); for (UUID id : l)
    * { if (!entitySet.contains(id)) { ids.add(id); } } } } return ids; }
    */
   if (connections != null) {
     ids = new ArrayList<UUID>();
     for (ConnectionRef connection : connections) {
       if (forwardConnections) {
         ConnectedEntityRef c = connection.getConnectedEntity();
         if (c != null) {
           ids.add(c.getUuid());
         }
       } else {
         EntityRef c = connection.getConnectingEntity();
         if (c != null) {
           ids.add(c.getUuid());
         }
       }
     }
     return ids;
   }
   if ((entities != null)
   /* || (connectionTypeAndEntityTypeToEntityMap != null) */ ) {
     // getEntities();
     ids = new ArrayList<UUID>();
     for (Entity entity : entities) {
       ids.add(entity.getUuid());
     }
     return ids;
   }
   if (refs != null) {
     ids = new ArrayList<UUID>();
     for (EntityRef ref : refs) {
       ids.add(ref.getUuid());
     }
     return ids;
   }
   if (id != null) {
     ids = new ArrayList<UUID>();
     ids.add(id);
     return ids;
   }
   if (entity != null) {
     ids = new ArrayList<UUID>();
     ids.add(entity.getUuid());
     return ids;
   }
   return new ArrayList<UUID>();
 }
Beispiel #7
0
  @Test
  public void testEntityManager() throws Exception {
    LOG.info("EntityManagerIT.testEntityManagerTest");

    UUID applicationId = setup.createApplication("testOrganization", "testEntityManagerTest");
    assertNotNull(applicationId);

    EntityManager em = setup.getEmf().getEntityManager(applicationId);
    assertNotNull(em);

    Map<String, Object> properties = new LinkedHashMap<String, Object>();
    properties.put("username", "edanuff");
    properties.put("email", "*****@*****.**");

    Entity user = em.create("user", properties);
    assertNotNull(user);

    user = em.get(user);
    assertNotNull(user);
    assertEquals("user.username not expected value", "edanuff", user.getProperty("username"));
    assertEquals("user.email not expected value", "*****@*****.**", user.getProperty("email"));

    EntityRef userRef = em.getAlias(applicationId, "user", "edanuff");
    assertNotNull(userRef);
    assertEquals("userRef.id not expected value", user.getUuid(), userRef.getUuid());
    assertEquals("userRef.type not expected value", "user", userRef.getType());

    LOG.info("user.username: "******"username"));
    LOG.info("user.email: " + user.getProperty("email"));

    Results results =
        em.searchCollection(
            em.getApplicationRef(), "users", new Query().addEqualityFilter("username", "edanuff"));
    assertNotNull(results);
    assertEquals(1, results.size());
    user = results.getEntity();
    assertNotNull(user);
    assertEquals("user.username not expected value", "edanuff", user.getProperty("username"));
    assertEquals("user.email not expected value", "*****@*****.**", user.getProperty("email"));

    LOG.info("user.username: "******"username"));
    LOG.info("user.email: " + user.getProperty("email"));

    results =
        em.searchCollection(
            em.getApplicationRef(),
            "users",
            new Query().addEqualityFilter("email", "*****@*****.**"));
    assertNotNull(results);
    assertEquals(1, results.size());
    user = results.getEntity();
    assertNotNull(user);
    assertEquals("user.username not expected value", "edanuff", user.getProperty("username"));
    assertEquals("user.email not expected value", "*****@*****.**", user.getProperty("email"));

    LOG.info("user.username: "******"username"));
    LOG.info("user.email: " + user.getProperty("email"));
  }
Beispiel #8
0
 /**
  * Ugly way to retrieve a name from a prefab
  *
  * @return a ":" seperated string, with name and flavor text.
  */
 public static String getName() {
   PrefabManager prefMan = CoreRegistry.get(PrefabManager.class);
   Prefab prefab = prefMan.getPrefab("miniion:nameslist");
   EntityRef namelist = CoreRegistry.get(EntityManager.class).create(prefab);
   namelist.hasComponent(namesComponent.class);
   namesComponent namecomp = namelist.getComponent(namesComponent.class);
   Random rand = new Random();
   return namecomp.namelist.get(rand.nextInt(namecomp.namelist.size()));
 }
Beispiel #9
0
 /**
  * triggered when a block was destroyed and dropped in the world used to intercept gathering by
  * minions and sending the block to their inventory the droppedblock in the world then gets
  * destroyed, possible duplication exploit
  */
 @ReceiveEvent(components = {MinionComponent.class})
 public void onBlockDropped(BlockDroppedEvent event, EntityRef entity) {
   if (entity.hasComponent(MinionComponent.class)) {
     EntityRef item;
     if (event.getOldBlock().getEntityMode() == BlockEntityMode.PERSISTENT) {
       item = blockItemFactory.newInstance(event.getOldBlock().getBlockFamily(), entity);
     } else {
       item = blockItemFactory.newInstance(event.getOldBlock().getBlockFamily());
     }
     entity.send(new ReceiveItemEvent(item));
     event.getDroppedBlock().destroy();
   }
 }
  private EntityData.Entity serializeEntityFull(EntityRef entityRef) {
    EntityData.Entity.Builder entity = EntityData.Entity.newBuilder();
    entity.setId(entityRef.getId());
    for (Component component : entityRef.iterateComponents()) {
      if (component.getClass().equals(EntityInfoComponent.class)) continue;

      EntityData.Component componentData = serializeComponent(component);
      if (componentData != null) {
        entity.addComponent(componentData);
      }
    }
    return entity.build();
  }
Beispiel #11
0
 /**
  * The active minion, to be commanded by the minion command item etc uses a slightly different
  * texture to indicate selection
  *
  * @param minion : the new active minion entity
  */
 public static void setActiveMinion(EntityRef minion) {
   SkeletalMeshComponent skelcomp;
   if (activeminion != null) {
     skelcomp = activeminion.getComponent(SkeletalMeshComponent.class);
     if (skelcomp != null) {
       skelcomp.material = Assets.getMaterial("OreoMinions:OreonSkin");
     }
   }
   skelcomp = minion.getComponent(SkeletalMeshComponent.class);
   if (skelcomp != null) {
     skelcomp.material = Assets.getMaterial("OreoMinions:OreonSkinSelected");
   }
   activeminion = minion;
 }
Beispiel #12
0
 @Override
 public void shutdown() {
   if (activeminion != null) {
     SkeletalMeshComponent skelcomp = activeminion.getComponent(SkeletalMeshComponent.class);
     if (skelcomp != null) {
       skelcomp.material = Assets.getMaterial("OreoMinions:OreonSkin");
     }
   }
 }
Beispiel #13
0
 @JsonSerialize(include = Inclusion.NON_NULL)
 public Map<UUID, EntityRef> getRefsMap() {
   if (refsMap != null) {
     return refsMap;
   }
   getEntitiesMap();
   if (entitiesMap != null) {
     refsMap = cast(entitiesMap);
     return refsMap;
   }
   getRefs();
   if (refs != null) {
     refsMap = new LinkedHashMap<UUID, EntityRef>();
     for (EntityRef ref : refs) {
       refsMap.put(ref.getUuid(), ref);
     }
   }
   return refsMap;
 }
 @Override
 public EntityData.Entity serializeEntity(EntityRef entityRef) {
   EntityInfoComponent entityInfo = entityRef.getComponent(EntityInfoComponent.class);
   if (entityInfo != null) {
     if (entityInfo.parentPrefab != null && prefabManager.exists(entityInfo.parentPrefab)) {
       return serializeEntityDelta(entityRef, prefabManager.getPrefab(entityInfo.parentPrefab));
     }
   }
   return serializeEntityFull(entityRef);
 }
Beispiel #15
0
 /**
  * This will invoke the <code>ContentHandler.skippedEntity</code> callback when an entity
  * reference is encountered.
  *
  * @param entity <code>EntityRef</code>.
  */
 private void entityRef(EntityRef entity) throws JDOMException {
   if (entity != null) {
     try {
       // No need to worry about appending a '%' character as
       // we do not support parameter entities
       contentHandler.skippedEntity(entity.getName());
     } catch (SAXException se) {
       throw new JDOMException("Exception in entityRef", se);
     }
   }
 }
  @Override
  public EntityRef deserializeEntity(EntityData.Entity entityData) {
    EntityRef entity = entityManager.createEntityRefWithId(entityData.getId());
    if (entityData.hasParentPrefab()
        && !entityData.getParentPrefab().isEmpty()
        && prefabManager.exists(entityData.getParentPrefab())) {
      Prefab prefab = prefabManager.getPrefab(entityData.getParentPrefab());
      for (Component component : prefab.listComponents()) {
        String componentName = ComponentUtil.getComponentClassName(component.getClass());
        if (!containsIgnoreCase(componentName, entityData.getRemovedComponentList())) {
          entity.addComponent(componentLibrary.copy(component));
        }
      }
      entity.addComponent(new EntityInfoComponent(entityData.getParentPrefab()));
    }
    for (EntityData.Component componentData : entityData.getComponentList()) {
      Class<? extends Component> componentClass = getComponentClass(componentData);
      if (componentClass == null) continue;

      if (!entity.hasComponent(componentClass)) {
        entity.addComponent(deserializeComponent(componentData));
      } else {
        deserializeComponentOnto(entity.getComponent(componentClass), componentData);
      }
    }
    return entity;
  }
Beispiel #17
0
 /** order the minions by id and return the previous one, or the first if none were active! */
 public static void getPreviousMinion(boolean deleteactive) {
   EntityManager entman = CoreRegistry.get(EntityManager.class);
   List<Integer> sortedlist = new ArrayList<Integer>();
   for (EntityRef minion : entman.iteratorEntities(MinionComponent.class)) {
     if (!minion.getComponent(MinionComponent.class).dying) {
       sortedlist.add(minion.getId());
     }
   }
   if (sortedlist.size() == 0) {
     return;
   } else if (deleteactive && sortedlist.size() == 1) {
     activeminion = null;
     return;
   }
   Collections.sort(sortedlist);
   int index = 0;
   if (activeminion != null) {
     index = sortedlist.indexOf(activeminion.getId());
   }
   if (index == 0) {
     index = sortedlist.size() - 1;
   } else {
     index--;
   }
   index = sortedlist.get(index);
   for (EntityRef minion : entman.iteratorEntities(MinionComponent.class)) {
     if (minion.getId() == index) {
       setActiveMinion(minion);
     }
   }
 }
  public void update(float delta) {
    /* GUI */
    updateUserInterface();

    for (UpdateSubscriberSystem updater : _componentSystemManager.iterateUpdateSubscribers()) {
      PerformanceMonitor.startActivity(updater.getClass().getSimpleName());
      updater.update(delta);
    }

    if (_worldRenderer != null && shouldUpdateWorld()) _worldRenderer.update(delta);

    if (!screenHasFocus()) _localPlayerSys.updateInput();

    if (screenHasFocus() || !shouldUpdateWorld()) {
      if (Mouse.isGrabbed()) {
        Mouse.setGrabbed(false);
        Mouse.setCursorPosition(Display.getWidth() / 2, Display.getHeight() / 2);
      }
    } else {
      if (!Mouse.isGrabbed()) Mouse.setGrabbed(true);
    }

    // TODO: This seems a little off - plus is more of a UI than single player game state concern.
    // Move somewhere
    // more appropriate?
    boolean dead = true;
    for (EntityRef entity : _entityManager.iteratorEntities(LocalPlayerComponent.class)) {
      dead = entity.getComponent(LocalPlayerComponent.class).isDead;
    }
    if (dead) {
      _statusScreen.setVisible(true);
      _statusScreen.updateStatus("Sorry! Seems like you have died. :-(");
    } else {
      _statusScreen.setVisible(false);
    }
  }
Beispiel #19
0
 @JsonSerialize(include = Inclusion.NON_NULL)
 public UUID getId() {
   if (id != null) {
     return id;
   }
   if (entity != null) {
     id = entity.getUuid();
     return id;
   }
   if ((ids != null) && (ids.size() > 0)) {
     id = ids.get(0);
     return id;
   }
   if ((entities != null) && (entities.size() > 0)) {
     entity = entities.get(0);
     id = entity.getUuid();
     return id;
   }
   if ((refs != null) && (refs.size() > 0)) {
     EntityRef ref = refs.get(0);
     id = ref.getUuid();
   }
   return id;
 }
Beispiel #20
0
 public Results startingFrom(UUID entityId) {
   if (entities != null) {
     for (int i = 0; i < entities.size(); i++) {
       Entity entity = entities.get(i);
       if (entityId.equals(entity.getUuid())) {
         if (i == 0) {
           return this;
         }
         return Results.fromEntities(entities.subList(i, entities.size()));
       }
     }
   }
   if (refs != null) {
     for (int i = 0; i < refs.size(); i++) {
       EntityRef entityRef = refs.get(i);
       if (entityId.equals(entityRef.getUuid())) {
         if (i == 0) {
           return this;
         }
         return Results.fromRefList(refs.subList(i, refs.size()));
       }
     }
   }
   if (ids != null) {
     for (int i = 0; i < ids.size(); i++) {
       UUID uuid = ids.get(i);
       if (entityId.equals(uuid)) {
         if (i == 0) {
           return this;
         }
         return Results.fromIdList(ids.subList(i, ids.size()));
       }
     }
   }
   return this;
 }
Beispiel #21
0
 /**
  * returns a list with all Oreon farm zones
  *
  * @return a list with all Oreon farm zones
  */
 public static List<Zone> getOreonFarmZoneList() {
   if (zonelist == null) {
     return null;
   }
   return zonelist.getComponent(ZoneListComponent.class).OreonFarmzones;
 }
Beispiel #22
0
 /**
  * returns a list with all terraform zones
  *
  * @return a list with all terraform zones
  */
 public static List<Zone> getTerraformZoneList() {
   if (zonelist == null) {
     return null;
   }
   return zonelist.getComponent(ZoneListComponent.class).Terrazones;
 }
Beispiel #23
0
 /**
  * returns a list with all work zones
  *
  * @return a list with all work zones
  */
 public static List<Zone> getWorkZoneList() {
   if (zonelist == null) {
     return null;
   }
   return zonelist.getComponent(ZoneListComponent.class).Workzones;
 }
Beispiel #24
0
 /**
  * returns a list with all storage zones
  *
  * @return a list with all storage zones
  */
 public static List<Zone> getStorageZoneList() {
   if (zonelist == null) {
     return null;
   }
   return zonelist.getComponent(ZoneListComponent.class).Storagezones;
 }
Beispiel #25
0
 /**
  * returns a list with all gather zones
  *
  * @return a list with all gather zones
  */
 public static List<Zone> getGatherZoneList() {
   if (zonelist == null) {
     return null;
   }
   return zonelist.getComponent(ZoneListComponent.class).Gatherzones;
 }