Exemplo n.º 1
0
        private void _Show()
        {
            content.SetActive(true);

            if (_entity.Has <IsSceneInactiveComponent>())
            {
                _entity.Del <IsSceneInactiveComponent>();
            }

            _entity.Get <IsSceneActiveComponent>();
            _entity.Get <SceneBecomeActiveComponent>();
        }
Exemplo n.º 2
0
 // unlinks unit from task and notifies unit that task is finished
 private void detachPerformer(EcsEntity task, TaskFinishedComponent component)
 {
     if (task.Has <TaskPerformerComponent>())
     {
         task.Get <TaskPerformerComponent>().performer.Replace(component);
         task.Del <TaskPerformerComponent>();
     }
 }
Exemplo n.º 3
0
        private void _Show()
        {
            if (content != null)
            {
                content.SetActive(true);
            }

            if (_entity.Has <IsSceneInactiveComponent>())
            {
                _entity.Del <IsSceneInactiveComponent>();
            }

            _entity.Get <IsSceneActiveComponent>();

            // sends event scene has been activated
            World.NewEntity().Get <SceneActivatedEvent>().Scene = this;
        }
Exemplo n.º 4
0
 public override Vector3Int?getPosition()
 {
     if (!entity.Has <PositionComponent>())
     {
         Debug.LogWarning("Getting position of entity " + entity + " without PositionComponent");
         return(null);
     }
     return(entity.Get <PositionComponent>().position);
 }
Exemplo n.º 5
0
 // if task was completed, designation is no longer needed
 private void detachDesignation(EcsEntity task, TaskFinishedComponent component)
 {
     if (component.status == TaskStatusEnum.COMPLETE && task.Has <TaskDesignationComponent>())
     {
         // TODO handle workbenches
         task.Get <TaskDesignationComponent>().designation.Replace(component);
         task.Del <TaskDesignationComponent>();
     }
 }
Exemplo n.º 6
0
 public void removeDesignation(EcsEntity designation)
 {
     if (designation.Has <DesignationVisualComponent>())
     {
         Destroy(designation.Get <DesignationVisualComponent>().spriteRenderer.gameObject);
         designation.Del <DesignationVisualComponent>();
     }
     else
     {
         Debug.LogWarning("deleting designation without DesignationVisualComponent");
     }
     designation.Destroy();
 }
        private bool validateEntity(EcsEntity entity)
        {
            if (!entity.Has <PositionComponent>())
            {
                Debug.LogWarning("designation " + entity.Get <DesignationComponent>().type.NAME + " has no PositionComponent");
                return(false);
            }
            DesignationComponent designation = entity.Get <DesignationComponent>();

            if (designation.type.SPRITE_NAME == null)
            {
                Debug.LogWarning("designation " + entity.Get <DesignationComponent>().type.NAME + " has null spriteName");
                return(false);
            }
            return(true);
        }
Exemplo n.º 8
0
    public void OnPointerClick(PointerEventData eventData)
    {
        if (!_entity.Has <AiCharacterComponent>())
        {
            Debug.LogError($"Entity of character {gameObject.name} doesn't have an {nameof(AiCharacterComponent)}.");
            return;
        }

        var character    = _entity.Get <AiCharacterComponent>();
        var upgradeEvent = new UpgradeCharacterEvent()
        {
            Type          = character.Type,
            NewLevelValue = _upgradeService.UpgradeCharacter(character.Level)
        };

        GameManager.Instance.World.NewEntity()
        .Replace(upgradeEvent);
    }
        public void Run()
        {
            bool fullField = _filter.GetEntitiesCount() == 0;

            if (fullField)
            {
                return;
            }

            for (int column = 0; column < _configuration.LevelWidth; column++)
            {
                for (int row = 0; row < _configuration.LevelHeight; row++)
                {
                    Vector2Int position = new Vector2Int(column, row);
                    EcsEntity  cell     = _gameField.Cells[position];

                    if (!cell.Has <EmptySpace>())
                    {
                        continue;
                    }

                    bool emptySpace = true;

                    Vector2Int extenderPosition = position;

                    while (emptySpace)
                    {
                        extenderPosition = extenderPosition + Vector2Int.up;
                        bool hasCellID = _gameField.Cells.ContainsKey(extenderPosition);

                        if (!hasCellID)
                        {
                            break;
                        }

                        emptySpace = _gameField.Cells[extenderPosition].Has <EmptySpace>();
                    }

                    SwapCells(position, extenderPosition);
                }
            }
        }
 public void Run()
 {
     foreach (var i in filter)
     {
         EcsEntity             unit            = filter.GetEntity(i);
         TaskFinishedComponent finishComponent = filter.Get2(i);
         if (unit.Has <TaskComponent>())
         {
             if (finishComponent.status == TaskStatusEnum.FAILED || finishComponent.status == TaskStatusEnum.CANCELED)
             {
                 // TODO handle task cancelling and interruption (do cancel effects of action(drop item, etc))
             }
             detachTask(unit, unit.Get <TaskComponent>().task, finishComponent);
         }
         else
         {
             Debug.LogError("Invalid unit state: no TaskComponent and UnitTaskFinishedComponent");
         }
     }
 }
Exemplo n.º 11
0
 public void Run()
 {
     foreach (var i in filter)
     {
         EcsEntity             designation           = filter.GetEntity(i);
         TaskFinishedComponent taskFinishedComponent = filter.Get2(i);
         // detach task
         if (designation.Has <TaskComponent>())
         {
             designation.Get <TaskComponent>().task.Replace(taskFinishedComponent);
             designation.Del <TaskComponent>();
         }
         designation.Del <TaskFinishedComponent>();
         // remove designation entity, failed will recreate task
         if (taskFinishedComponent.status == TaskStatusEnum.CANCELED || taskFinishedComponent.status == TaskStatusEnum.COMPLETE)
         {
             GameModel.get().designationContainer.removeDesignation(designation);
         }
     }
 }
        // gets any task for unit
        private EcsEntity?getTaskFromContainer(EcsEntity unit)
        {
            if (unit.Has <UnitJobsComponent>())
            {
                UnitJobsComponent jobs = unit.Get <UnitJobsComponent>();
                Debug.Log("enabled jobs: " + jobs.enabledJobs.Count);

                foreach (var enabledJob in jobs.enabledJobs)   // TODO add jobs priorities
                {
                    EcsEntity?task = GameModel.get().taskContainer.getTask(enabledJob, unit.pos());
                    if (task.HasValue)
                    {
                        return(task);
                    }
                }
            }
            else
            {
                Debug.LogError("unit without jobs component attempts to get jobs from container.");
            }
            return(null); // TODO get from task container
        }
Exemplo n.º 13
0
 public bool HasComponent <T>() where T : struct
 {
     return(entityHandle.Has <T>());
 }
Exemplo n.º 14
0
 public static T?get <T>(this EcsEntity entity) where T : struct
 {
     return(entity.Has <T>() ? (T?)entity.Get <T>() : null);
 }
Exemplo n.º 15
0
 public static bool hasPos(this EcsEntity entity)
 {
     return(entity.Has <PositionComponent>());
 }
 public override bool checkItem(EcsEntity item)
 {
     return(item.Has <ItemToolComponent>() && item.Get <ItemToolComponent>().operation == actionName);
 }