예제 #1
0
        private void createToggles(GameObject row, EcsEntity unit)
        {
            GameObject    togglePrefab = Resources.Load <GameObject>(togglePath);
            RectTransform unitName     = row.transform.GetChild(0).GetComponent <RectTransform>();
            float         startX       = unitName.rect.width + unitName.localPosition.x;
            float         iconWidth    = togglePrefab.GetComponent <RectTransform>().rect.width;

            for (var i = 0; i < JobsEnum.jobs.Length; i++)
            {
                Job        job    = JobsEnum.jobs[i];
                GameObject toggle = Instantiate(togglePrefab, row.transform, false);
                toggle.transform.localPosition = new Vector3(startX + iconWidth * i, 0, 0);
                Toggle toggleComponent = toggle.GetComponentInChildren <Toggle>();
                toggleComponent.isOn = unit.Get <UnitJobsComponent>().enabledJobs.Contains(job.name);
                toggleComponent.onValueChanged.AddListener(value => {
                    if (value)
                    {
                        unit.Get <UnitJobsComponent>().enabledJobs.Add(job.name);
                    }
                    else
                    {
                        unit.Get <UnitJobsComponent>().enabledJobs.Remove(job.name);
                    }
                });
            }
        }
예제 #2
0
    protected override void CreateEntity()
    {
        EcsEntity flyingEnemyEntity = SingleTone.mainworld.NewEntity();

        flyingEnemyEntity.Get <Enemy>();
        flyingEnemyEntity.Get <Flying>();

        ref Defence        DefenceComponent        = ref flyingEnemyEntity.Get <Defence>();
 public static void AddDefaultUnitComponents(this EcsEntity unitEntity, GameObject unitObject, int health)
 {
     unitEntity.Set <AttackComponent>().InitializeComponent(unitEntity.Get <UnitComponent>().Tag.ToString().ToUnitType());
     //unitEntity.Set<DefenseComponent>().InitializeComponent(UnitType.Warrior);
     unitEntity.Set <HealthComponent>().InitializeComponent(health);
     unitEntity.Set <HealthBarComponent>().InitializeComponent(unitObject);
     unitEntity.Set <MovementComponent>().InitializeComponent(unitObject);
     unitEntity.Set <NavMeshComponent>();
     unitEntity.Get <NavMeshComponent>().Agent = unitObject.GetComponent <NavMeshAgent>();
 }
예제 #4
0
        private void _Show()
        {
            content.SetActive(true);

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

            _entity.Get <IsSceneActiveComponent>();
            _entity.Get <SceneBecomeActiveComponent>();
        }
    protected override void CreateEntity()
    {
        EcsEntity bulletTowerEntity = SingleTone.mainworld.NewEntity();

        bulletTowerEntity.Get <CanShootFlying>();
        bulletTowerEntity.Get <CanShootWalking>();
        bulletTowerEntity.Get <Tower>();
        if (SingleTone.IsMouseOccupied)
        {
            bulletTowerEntity.Get <Unplaced>();
        }

        ref Shooter      ShooterComponent      = ref bulletTowerEntity.Get <Shooter>();
예제 #6
0
        private void ChangeToActionState()
        {
            SpawnImmunity = -1f;

            if (Type != CharacterType.Player)
            {
                return;
            }

            var player = Entity.Get <Player>();

            player.HeadFacing = HeadFacing.Center;             //don't need to send this to client, they will assume it resets
        }
예제 #7
0
        public static void CreateDropResourcesEvent(EcsEntity deliverEntity, EcsWorld world)
        {
            var deliverComponent = deliverEntity.Get <ResourceDeliverComponent>();
            var resources        = deliverComponent.Resources;
            var position         = deliverEntity.Get <MovementComponent>().CurrentPosition;

            foreach (var resource in resources)
            {
                resource.Position = position + randomFactor * Random.value;
            }

            world.NewEntityWith <ResourceDropEvent>(out var resourceDropEvent);
            resourceDropEvent.Resources = resources;
        }
예제 #8
0
        public void Run()
        {
            foreach (int i in _takenFoods)
            {
                EcsEntity playerEntity  = _takenFoods.Get2[i].PlayerEntity;
                var       player        = playerEntity.Get <PlayerComponent>();
                var       moveComponent = playerEntity.Get <MoveComponent>();

                player.Scores       += _takenFoods.Get1[i].Scores;
                moveComponent.Speed -= _takenFoods.Get1[i].SpeedPenalty;

                _ecsWorld.NewEntityWith(out UpdateScoreTableEvent _);
            }
        }
        public override void EntityInit(EcsEntity ecsEntity, EcsWorld world, bool OnScene)
        {
            var points = new Vector3[lengthOfLineRenderer];

            points[0] = ecsEntity.Get <LineConnection>().PositionA;
            points[1] = ecsEntity.Get <LineConnection>().PositionB;
            _root.SetPositions(points);

            ecsEntity.Set <LineRendererRoot>().LineRenderer = this._root;
            if (OnScene)
            {
                Destroy(this);
            }
        }
예제 #10
0
    bool CreateObject(char type, out EcsEntity entity)
    {
        switch (type)
        {
        case 'o':
        {
            entity = _world.NewEntity();
            entity.Replace(new ObjectType
                {
                    Value = GameObjectEnum.Wall
                });
            return(true);
        }

        case 's':
        {
            entity = _world.NewEntity();
            entity.Get <PlayerTag>();
            entity.Replace(new ObjectType
                {
                    Value = GameObjectEnum.Player
                });
            return(true);
        }

        default:
        {
            entity = default;
            return(false);
        }
        }
    }
예제 #11
0
        public void MovePlayerMap(ref EcsEntity entity, Character character, string mapName, Position newPosition)
        {
            character.IsActive = false;
            character.Map.RemoveEntity(ref entity, CharacterRemovalReason.OutOfSight);

            character.ResetState();
            character.Position = newPosition;

            if (!mapIdLookup.TryGetValue(mapName, out var mapId))
            {
                ServerLogger.LogWarning($"Map {mapName} does not exist! Could not move player.");
                return;
            }

            var map = Maps[mapId];


            if (newPosition == Position.Zero)
            {
                map.FindPositionInRange(map.MapBounds, out var p);
                character.Position = newPosition;
            }


            map.AddEntity(ref entity);

            var player = entity.Get <Player>();

            player.Connection.LastKeepAlive = Time.ElapsedTime;             //reset tick time so they get 2 mins to load the map

            CommandBuilder.SendChangeMap(character, player);
        }
        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);
        }
예제 #13
0
    // Start is called before the first frame update

    // Update is called once per frame
    protected override void CreateEntity()
    {
        EcsEntity cityEnity = SingleTone.mainworld.NewEntity();

        cityEnity.Get <Client.City>();

        ref Health healthComponent = ref cityEnity.Get <Health>();
예제 #14
0
        private void UpdateKeyboardInput()
        {
            var result     = new float2(0, 0);
            var inputExist = false;

            if (Input.GetKey(KeyCode.A))
            {
                result.x  -= 1;
                inputExist = true;
            }
            if (Input.GetKey(KeyCode.D))
            {
                result.x  += 1;
                inputExist = true;
            }
            if (Input.GetKey(KeyCode.W))
            {
                result.y  += 1;
                inputExist = true;
            }
            if (Input.GetKey(KeyCode.S))
            {
                result.y  -= 1;
                inputExist = true;
            }

            if (inputExist)
            {
                result = math.normalize(result);
            }

            _moveEventEntity.Get <MoveEventComponent>().Value = result;
        }
예제 #15
0
        public void AddEntity(ref EcsEntity entity, CharacterType type)
        {
#if DEBUG
            //sanity check
            var character = entity.Get <Character>();
            var chunkX    = character.Position.X / 8;
            var chunkY    = character.Position.Y / 8;
            if (X != chunkX || Y != chunkY)
            {
                throw new Exception("Sanity check failed: Entity added to incorrect chunk?");
            }
#endif
            switch (type)
            {
            case CharacterType.Player:
                Players.Add(ref entity);
                break;

            case CharacterType.Monster:
                Monsters.Add(ref entity);
                break;

            default:
                throw new Exception("Unhandled character type: " + type);
            }
        }
예제 #16
0
 public ActionConditionStatusEnum addPreAction(Action action)
 {
     Debug.Log("adding pre action");
     task.Get <TaskComponents.TaskActionsComponent>().addFirstPreAction(action);
     action.task = task;
     return(ActionConditionStatusEnum.NEW);
 }
예제 #17
0
        void IInputCommand.Execute(EcsEntity entity)
        {
            var c1 = entity.Get <GameObjectComponent>();

            if (vertical > 0)
            {
                goalPosition = new Vector2(c1.Transform.position.x, c1.Transform.position.y + 1);
            }

            if (vertical < 0)
            {
                goalPosition = new Vector2(c1.Transform.position.x, c1.Transform.position.y - 1);
            }

            if (horizontal > 0)
            {
                goalPosition = new Vector2(c1.Transform.position.x + 1, c1.Transform.position.y);
            }

            if (horizontal < 0)
            {
                goalPosition = new Vector2(c1.Transform.position.x - 1, c1.Transform.position.y);
            }

            var c = entity.Set <ActionMoveComponent>();

            c.GoalPosition = goalPosition.ToInt2();
        }
예제 #18
0
        void IEcsRunSystem.Run()
        {
            if (!_moveFilter.IsEmpty())
            {
                List <GameObject> squaresToMove = _moveFilter.Get1(0).SquaresToMove;
                List <Vector3>    dstPos        = _moveFilter.Get1(0).DstPos;
                Direction         moveDirection = _moveFilter.Get1(0).Direction;

                Vector2Int moveDirectionInt = Const.DirToVecI(moveDirection);
                Vector3    moveDirectionF   = Const.DirToVecF(moveDirection);


                foreach (GameObject o in _moveFilter.Get1(0).SquaresToMove)
                {
                    float d = Const.MoveSpeed * Time.deltaTime;
                    if (d > 9)
                    {
                        d = 9;
                    }
                    o.transform.position += moveDirectionF * d;
                }


                for (int i = 0; i < _moveFilter.Get1(0).SquaresToMove.Count; i++)
                {
                    if (Vector3.Distance(squaresToMove[i].transform.position, dstPos[i]) < 10)
                    {
                        squaresToMove[i].transform.position = dstPos[i];


                        if (_globalData.GameField[_moveFilter.Get1(0).DstPosInts[i].x,
                                                  _moveFilter.Get1(0).DstPosInts[i].y].ChangeDirection != Direction.None)
                        {
                            squaresToMove[i].GetComponent <SquareScript>().SetDirection(_globalData.GameField[_moveFilter.Get1(0).DstPosInts[i].x, _moveFilter.Get1(0).DstPosInts[i].y].ChangeDirection);
                        }


                        GameObject o = _globalData.GameField[_moveFilter.Get1(0).SrcPosInts[i].x, _moveFilter.Get1(0).SrcPosInts[i].y].Obj;
                        _globalData.GameField[_moveFilter.Get1(0).SrcPosInts[i].x, _moveFilter.Get1(0).SrcPosInts[i].y].Obj = null;
                        _globalData.GameField[_moveFilter.Get1(0).DstPosInts[i].x, _moveFilter.Get1(0).DstPosInts[i].y].Obj = o;

                        _moveFilter.Get1(0).SquaresToMove.RemoveAt(i);
                        _moveFilter.Get1(0).DstPos.RemoveAt(i);
                        _moveFilter.Get1(0).SrcPosInts.RemoveAt(i);
                        _moveFilter.Get1(0).DstPosInts.RemoveAt(i);
                        i--;
                    }
                }


                if (_moveFilter.Get1(0).SquaresToMove.Count == 0)
                {
                    _moveFilter.GetEntity(0).Destroy();

                    EcsEntity ent1 = _world.NewEntity();
                    ent1.Get <CheckFinishComponent>();
                }
            }
        }
예제 #19
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>();
     }
 }
예제 #20
0
 public static Vector3Int pos(this EcsEntity entity)
 {
     if (entity.hasPos())
     {
         return(entity.Get <PositionComponent>().position);
     }
     throw new ArgumentException("entity has no PositionComponent!");
 }
예제 #21
0
        private void _InitEntity()
        {
            _entity = World.NewEntity();
            _entity.Get <SceneComponent>().Scene = this;

            // sends create event
            World.NewEntity().Get <SceneCreatedEvent>().Scene = this;
        }
예제 #22
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;
        }
예제 #23
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);
 }
        public static void RLSetMaxHealth(this EcsEntity entity, int value)
        {
            var c = entity.Get <NPCDataSheetComponent>();

            if (c != null)
            {
                c.Stats.MaxHealthPoint = value;
            }
        }
예제 #25
0
        public void OnRecalculateStats(EcsEntity entity)
        {
            var shieldComponent = entity.Get <DefenceComponent>();

            if (shieldComponent != null)
            {
                shieldComponent.BonusValue += Values[Level];
            }
        }
예제 #26
0
        public virtual void OnSpawn(EcsEntity entity)
        {
            entity.Set <UnityView>();
            UnityView view = entity.Get <UnityView>();

            view.GameObject = this.gameObject;
            view.id         = id;
            view.Transform  = transform;
        }
예제 #27
0
        public void OnRecalculateStats(EcsEntity entity)
        {
            var damageComponent = entity.Get <DamageComponent>();

            if (damageComponent != null)
            {
                damageComponent.BonusValue += Values[Level];
            }
        }
예제 #28
0
 private void OnTriggerEnter(Collider other)
 {
     if (Entity.IsNull())
     {
         Debug.LogError("Entity is null on coin");
         return;
     }
     Entity.Get <CollisionEvent>().Type = CollisionType.Obstacle;
 }
예제 #29
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>();
     }
 }
예제 #30
0
        private void UpdateMouseInput()
        {
            var offset     = new Vector2(Screen.width / 2f, Screen.height / 2f);
            var mousePoint = ((Vector2)Input.mousePosition - offset).normalized;
            var angle      = -Vector2.SignedAngle(Vector2.up, mousePoint);

            angle = angle < 0 ? 360 + angle : angle;
            _rotateEventEntity.Get <RotateEventComponent>().Value = angle;
        }