예제 #1
0
  @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);
    }
  }
예제 #2
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;
 }
  @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;
  }
예제 #4
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);
     }
   }
 }
예제 #5
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);
 }
예제 #6
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();
   }
 }
예제 #7
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()));
 }
예제 #8
0
 @Override
 public void shutdown() {
   if (activeminion != null) {
     SkeletalMeshComponent skelcomp = activeminion.getComponent(SkeletalMeshComponent.class);
     if (skelcomp != null) {
       skelcomp.material = Assets.getMaterial("OreoMinions:OreonSkin");
     }
   }
 }
 @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);
 }
예제 #10
0
  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);
    }
  }
예제 #11
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;
 }
예제 #12
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;
 }
예제 #13
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;
 }
예제 #14
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;
 }
예제 #15
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;
 }