public void Run()
 {
     if (_filter.GetEntitiesCount() > 0)
     {
         _sceneData.ScoreView.SetScore(_playerState.Score);
     }
 }
Beispiel #2
0
        public void Run()
        {
            if (camera is null)
            {
                camera = Camera.current;
                return;
            }

            ray = camera.ScreenPointToRay(Input.mousePosition);

            if (Input.GetMouseButtonDown(0))
            {
                for (var i = 0; i < buttons.GetEntitiesCount(); i++)
                {
                    if (btnClicks.GetEntitiesCount() > 0 || EventSystem.current.IsPointerOverGameObject())
                    {
                        return;
                    }
                }

                for (var i = 0; i < buildings.GetEntitiesCount(); i++)
                {
                    if (buildings.Entities[i].Get <BuildingComponent>().Object.GetComponent <Collider>().Raycast(ray, out hitInfo, 400))
                    {
                        buildings.Entities[i].Get <BuildingComponent>().InBuildCanvas.enabled = true;
                    }
                    else
                    {
                        buildings.Entities[i].Get <BuildingComponent>().InBuildCanvas.enabled = false;
                    }
                }
            }
        }
Beispiel #3
0
        public void Run()
        {
            foreach (var index in _filter)
            {
                Debug.Log(_filter.GetEntitiesCount());
                ref var tempoEvent = ref _filter.Get1(index);
                //Debug.Log($"{Time.time} - {tempoEvent.soundEvent}");
                var(x, y) = LowerHeightValue();

                var tileView = _tilesPool.Get();
                tileView.transform.position = InitialPosition;

                var targetXPosition = SpawnPositionsX[x];
                var targetZPosition = TargetPositionsZ[y];
                var targetYPosition = SpawnPositionY + _gameState.towerHeightWarm[targetXPosition - 2, Math.Abs(targetZPosition + 2)]++;

                var spawnPosition  = new Vector3(targetXPosition, SpawnPositionZ, targetZPosition);
                var targetPosition = new Vector3(targetXPosition, targetYPosition, targetZPosition);

                tileView.movingTile.localPosition = spawnPosition;
                tileView.targetTile.localPosition = targetPosition;

                var tileEntity = _world.NewEntity();
                tileEntity.Replace(new Tile
                {
                    SpawnPosition  = spawnPosition,
                    TargetPosition = targetPosition,
                    ReleaseTime    = tempoEvent.ReleaseTime,
                    FinalTime      = tempoEvent.MidiEvent.TimeInSeconds,
                    TileView       = tileView.GetComponent <TileView>(),
                });

                tileView.Entity = tileEntity;
                tileView.gameObject.SetActive(true);
            }
        private void TakeResources()
        {
            var takeResourcesEntities = takeResources.Entities
                                        .Take(takeResources.GetEntitiesCount());
            var playerResourcesComponent = playerResources.Entities
                                           .First().Get <PlayerResourcesComponent>();

            foreach (var takeResourceEntity in takeResourcesEntities)
            {
                var resources = takeResourceEntity.Get <TakeResourcesFromDeliverEvent>().Resources;

                foreach (var resource in resources)
                {
                    switch (resource.Tag)
                    {
                    case ResourceTag.Money:
                    {
                        playerResourcesComponent.Cash += resource.ResourceCount;
                        break;
                    }

                    case ResourceTag.Semki:
                    {
                        playerResourcesComponent.Semki += resource.ResourceCount;
                        break;
                    }
                    }
                }

                resources.Clear();
                takeResourceEntity.Unset <TakeResourcesFromDeliverEvent>();
            }
        }
Beispiel #5
0
 public void Run()
 {
     for (int i = 0, iMax = _filter.GetEntitiesCount(); i < iMax; i++)
     {
         _filter.Get3(i).Value += (_filter.Get1(i).Value + _filter.Get2(i).Value) * Time;
     }
 }
        private void FindNearDeliversToTakeResources()
        {
            var deliversEntities = delivers.Entities
                                   .Take(delivers.GetEntitiesCount());
            var baseEntities = baseComponents.Entities
                               .Take(baseComponents.GetEntitiesCount());

            foreach (var deliverEntity in deliversEntities)
            {
                var deliverComponent = deliverEntity.Get <ResourceDeliverComponent>();
                var deliverPosition  = deliverEntity.Get <MovementComponent>().CurrentPosition;

                foreach (var baseEntity in baseEntities)
                {
                    var basePosition = baseEntity.Get <MovementComponent>().CurrentPosition;

                    if (BaseTakeResourcesHelpers.CanTakeResourcesFromDeliver(
                            deliverComponent,
                            deliverPosition,
                            basePosition))
                    {
                        BaseTakeResourcesHelpers.CreateTakeResourcesFromDeliverEvent(deliverEntity, baseEntity);
                    }
                }
            }
        }
 public static bool AllEntitiesEquals <T>(this EcsFilter filter)
     where T : struct
 {
     for (int i = 0; i < filter.GetEntitiesCount() - 1; i++)
     {
         ref var currentEntity = ref filter.GetEntity(i).Get <T>();
         ref var nextEntity    = ref filter.GetEntity(i + 1).Get <T>();
Beispiel #8
0
        private void FindAvailableToTakeResources()
        {
            var takenResourcesGuids = new List <Guid>();
            var deliversEntities    = delivers.Entities
                                      .Take(delivers.GetEntitiesCount());
            var resourcesEntities = resources.Entities
                                    .Take(resources.GetEntitiesCount());

            foreach (var deliverEntity in deliversEntities)
            {
                var deliverPosition = deliverEntity.Get <MovementComponent>().CurrentPosition;
                foreach (var resourceEntity in resourcesEntities)
                {
                    var resourceGuid = resourceEntity.Get <ResourceComponent>().Guid;
                    if (takenResourcesGuids.Contains(resourceGuid))
                    {
                        continue;
                    }

                    var resourcePosition = resourceEntity.Get <ResourceComponent>().Position;
                    if (Vector3.Distance(resourcePosition, deliverPosition) <= minTakingDistance)
                    {
                        if (TakeResourceHelpers.CanBeTaken(deliverEntity))
                        {
                            TakeResourceHelpers.CreateTakeEvent(deliverEntity, resourceEntity);
                            ResourceDestroyHelpers.CreateDestroyEvent(resourceEntity);
                            takenResourcesGuids.Add(resourceGuid);
                        }
                        break;
                    }
                }
            }
        }
 internal static void BlockAllClick(EcsFilter <ClickEvent> events, int buttonNumer)
 {
     for (var i = 0; i < events.GetEntitiesCount(); i++)
     {
         events.Get1[i].IsBlocked = true;
     }
 }
Beispiel #10
0
    private void Attack()
    {
        var attackingUnitsEntities = attackingUnits.Entities
                                     .Where(u => u.IsNotNullAndAlive())
                                     .Take(attackingUnits.GetEntitiesCount());

        foreach (var unit in attackingUnitsEntities)
        {
            var attackingComponent    = unit.Get <AttackingComponent>();
            var unitAttackComponent   = unit.Get <AttackComponent>();
            var unitMovementComponent = unit.Get <MovementComponent>();

            var targetUnit = attackingComponent.TargetEntity;
            if (!targetUnit.IsNotNullAndAlive())
            {
                AttackHelper.StopAttack(unit);
                return;
            }

            var targetMovementComponent = targetUnit.Get <MovementComponent>();

            if (targetMovementComponent == null || !targetMovementComponent.IsObjectAlive)
            {
                AttackHelper.StopAttack(unit);
                return;
            }


            if (attackingComponent.TargetEntity.Get <UnitComponent>() != null &&
                AttackHelper.CanAttack(unitAttackComponent, unitMovementComponent, targetMovementComponent))
            {
                unitAttackComponent.LastAttackTime = DateTime.Now;
                ServerClient.Communication.AttackSender.attacks.Add(
                    new AttackInfo(
                        unit.Get <UnitComponent>().Guid,
                        attackingComponent.TargetEntity.Get <UnitComponent>().Guid,
                        (int)unitAttackComponent.AttackDamage));
            }
            if (attackingComponent.TargetEntity.Get <BuildingComponent>() != null)
            {
                var enemyBuildTransform = attackingComponent.TargetEntity.Get <BuildingComponent>().Object.transform;
                var attackRange         = Math.Max(enemyBuildTransform.lossyScale.x, enemyBuildTransform.lossyScale.z) * 5;
                if (attackingComponent.TargetEntity.Get <BuildingComponent>().Tag == BuildingTag.Base)
                {
                    attackRange *= 6;
                }

                if (AttackHelper.CanBuildingAttack(unitAttackComponent,
                                                   unitMovementComponent,
                                                   targetMovementComponent,
                                                   (int)attackRange))
                {
                    unitAttackComponent.LastAttackTime = DateTime.Now;
                    ServerClient.Communication.AttackSender.attacks.Add(new AttackInfo(unit.Get <UnitComponent>().Guid,
                                                                                       attackingComponent.TargetEntity.Get <BuildingComponent>().Guid,
                                                                                       (int)unitAttackComponent.AttackDamage));
                }
            }
        }
    }
 public void Run()
 {
     for (int i = 0, iMax = _filter.GetEntitiesCount(); i < iMax; i++)
     {
         ++_filter.Get1(i).Value;
     }
 }
        public void Run()
        {
            var realTimeSinceStartup = _timeFilter.Get1[0].RealTimeSinceStartup;

            for (var i = 0; i < _movementStateFilter.GetEntitiesCount(); i++)
            {
                var movementState = _movementStateFilter.Get1[i];
                if (movementState.FinishMovementStateTime <= realTimeSinceStartup)
                {
                    float   delta;
                    ref var entity   = ref _movementStateFilter.Entities[i];
                    var     movement = entity.Get <MovementComponent>();
                    if (movement != null)
                    {
                        entity.Unset <MovementComponent>();
                        delta = _data.WaitTimeRange.GetRandom();
                    }
                    else
                    {
                        var speed     = _data.SpeedRange.GetRandom();
                        var direction = Helpers.GetRandomAndNormalizeVector3();
                        movement           = entity.Set <MovementComponent>();
                        movement.Direction = direction;
                        movement.Speed     = speed;
                        delta = _data.MovementTimeRange.GetRandom();
                    }
                    movementState.FinishMovementStateTime = realTimeSinceStartup + delta;
                }
            }
Beispiel #13
0
 void IEcsRunSystem.Run()
 {
     if (filter.GetEntitiesCount() == 0)
     {
         scoreService.Result += 0.2f;
     }
 }
Beispiel #14
0
        void IEcsRunSystem.Run()
        {
            if (_selected.GetEntitiesCount() < 2)
            {
                return;
            }

            var mismatch = false;

            var value = _selected.Get2(0).Value;

            foreach (var i in _selected)
            {
                if (_selected.Get2(i).Value != value)
                {
                    mismatch = true;
                    break;
                }
            }

            foreach (var i in _selected)
            {
                var entity = _selected.GetEntity(i);
                if (mismatch)
                {
                    entity.Get <Mismatched>();
                }
                else
                {
                    entity.Get <Matched>();
                }
                entity.Del <Selected>();
            }
        }
 void IEcsRunSystem.Run()
 {
     if (_canTurnEntities.GetEntitiesCount() == 0 && (_enemyEntities.GetEntitiesCount() > 0 || _playerEntities.GetEntitiesCount() > 0))
     {
         NewRoundQueue();
     }
 }
Beispiel #16
0
        public int IfCirclesCountLessOneThenEntityMustBeDeleted(int circlesCount)
        {
            var document = new DxfDocument();

            for (var i = 0; i < circlesCount; i++)
            {
                document.AddEntity(new Circle());
            }
            var entity = World.NewEntity();

            entity.Get <DxfFileDefinition>().path     = "C:\\tmp\\dxf_file.dxf";
            entity.Get <DxfFileContent>().dfxDocument = document;

            System.Run();

            return(dxfFileContentFilter.GetEntitiesCount());
        }
Beispiel #17
0
 public void Run()
 {
     for (int idx = 0, idxMax = _movables.GetEntitiesCount(); idx < idxMax; idx++)
     {
         ref var movable = ref _movables.Get1(idx);
         movable.Position          += _lss.MoveVector;
         movable.View.localPosition = movable.Position;
     }
        void IEcsRunSystem.Run()
        {
            var countMobs = _filterMobsAbroad.GetEntitiesCount();

            foreach (var i in _filterPlayers)
            {
                ref var entity = ref _filterPlayers.GetEntity(i);
                entity.Get <MakeDamageRequest>().Damage = countMobs;
            }
        void IEcsRunSystem.Run()
        {
            if (_filter.IsEmpty())
            {
                return;
            }

            _filter.GetEntity(_filter.GetEntitiesCount() - 1).Get <Last>();
        }
Beispiel #20
0
            public void Run()
            {
                for (int i = 0, iMax = _filter.GetEntitiesCount(); i < iMax; i++)
                {
                    LeoSpeed        speed    = _filter.Get1(i);
                    ref LeoPosition position = ref _filter.Get2(i);

                    position.X += speed.X * Time;
                    position.Y += speed.Y * Time;
                }
        internal static bool IsPressClick(EcsFilter <ClickEvent> events, int buttonNumer)
        {
            var isPress = false;

            for (var i = 0; i < events.GetEntitiesCount(); i++)
            {
                isPress = isPress || events.Get1[i].ButtonNumber == buttonNumer;
            }

            return(isPress);
        }
        internal static bool IsBlockedClick(EcsFilter <ClickEvent> events, int buttonNumer)
        {
            var isBlock = false;

            for (var i = 0; i < events.GetEntitiesCount(); i++)
            {
                isBlock = isBlock || (events.Get1[i].ButtonNumber == buttonNumer && events.Get1[i].IsBlocked);
            }

            return(isBlock);
        }
Beispiel #23
0
        public void Run()
        {
            if (filter.GetEntitiesCount() == 0)
            {
                return;
            }

            var targetFollow = filter.Get1(0);

            RunCamera(ref targetFollow);
        }
        private void DropResources()
        {
            var deliversEntities = delivers.Entities
                                   .Take(delivers.GetEntitiesCount())
                                   .Where(e => e.Get <MovementComponent>().IsObjectAlive);

            foreach (var deliverEntity in deliversEntities)
            {
                DropResourceHelpers.CreateDropResourcesEvent(deliverEntity, world);
            }
        }
 void IEcsRunSystem.Run()
 {
     if (_canTurnEntities.GetEntitiesCount() > 0 &&
         _inputPhaseEntities.GetEntitiesCount() == 0 &&
         _actionPhaseEntities.GetEntitiesCount() == 0 &&
         _environmentPhaseEntities.GetEntitiesCount() == 0 &&
         _modificationPhaseEntities.GetEntitiesCount() == 0)
     {
         nextEntity();
     }
 }
        void IEcsRunSystem.Run()
        {
            if (_tiles.GetEntitiesCount() < 2)
            {
                return;
            }

            foreach (var i in _tiles)
            {
                _tiles.GetEntity(i).Del <Selected>();
            }
        }
Beispiel #27
0
        public void Run()
        {
            if (_runtimeData.GameState.State != State.Game)
            {
                return;
            }

            if (_cellsCount == _cubes.GetEntitiesCount() || !_onGameTimerFinishedEvent.IsEmpty())
            {
                _runtimeData.GameState.State = State.GameOver;
            }
        }
Beispiel #28
0
        public void DxfFileDefinitionComponentsAreCreatedForEachFile()
        {
            FileSystemServiceStub.FilesInWorkingDirectory.Add("C:\\tmp\\file1.dxf");
            FileSystemServiceStub.FilesInWorkingDirectory.Add("C:\\tmp\\file2.dxf");

            System.Run();

            Assert.That(dxfFileDefinitionFilter.GetEntitiesCount(), Is.EqualTo(2));
            foreach (var idx in dxfFileDefinitionFilter)
            {
                ref var dxfFileDefinition = ref dxfFileDefinitionFilter.Get1(idx);
                Assert.That(dxfFileDefinition.path, Is.EqualTo(FileSystemServiceStub.FilesInWorkingDirectory[idx]));
            }
        void IEcsRunSystem.Run()
        {
            if (keysKeeperFilter.GetEntitiesCount() < 1)
            {
                world.NewEntityWith(out PressedKeysKeeperComponent keysKeeper);
            }

            foreach (var keysKeeperId in keysKeeperFilter)
            {
                MouseHandle(keysKeeperFilter.Get1[keysKeeperId]);
                KeyboardHandle(keysKeeperFilter.Get1[keysKeeperId]);
            }
        }
Beispiel #30
0
    private void StartAttack()
    {
        var startAttackUnitsEntities = startAttackingUnits.Entities
                                       .Take(startAttackingUnits.GetEntitiesCount());

        foreach (var unit in startAttackUnitsEntities)
        {
            var startAttackEvent = unit.Get <StartAttackEvent>();
            unit.Set <AttackingComponent>().TargetEntity = startAttackEvent.TargetEntity;

            unit.Unset <StartAttackEvent>();
        }
    }