Ejemplo n.º 1
0
 private void UpdateAllCharactersBeforeRoundStart()
 {
     foreach (var entity in _allCharacters.AsEnumerable())
     {
         entity.isMoved = false;
     }
 }
    protected override void Execute(List <GameEntity> entities)
    {
        var entity = entities.First();

        if (!HasAliveCharacters(CharacterUtils.FindAll(_allCharacters.AsEnumerable(), CharacterType.GoodGuy)))
        {
            PlayerLost(entity);
            return;
        }

        if (!HasAliveCharacters(CharacterUtils.FindAll(_allCharacters.AsEnumerable(), CharacterType.BadGuy)))
        {
            PlayerWon(entity);
        }
    }
Ejemplo n.º 3
0
        protected override void Execute(List <LobbyUiEntity> entities)
        {
            foreach (var warshipEntity in entities)
            {
                WarshipDto warshipDto = warshipEntity.warship.warshipDto;

                string     skinName  = warshipDto.GetCurrentSkinName();
                GameObject prefab    = Resources.Load <GameObject>("Prefabs/" + skinName);
                GameObject warshipGo = Object.Instantiate(prefab, gameViewsParent, false);
                warshipGo.transform.localScale = new Vector3(1.4f, 1.4f, 1.4f);

                LobbyUiEntity oldWarshipEntity = warshipsGroup.AsEnumerable()
                                                 .SingleOrDefault(entity =>
                {
                    return(entity.warship.warshipDto.WarshipTypeEnum == warshipDto.WarshipTypeEnum);
                });

                if (oldWarshipEntity != null)
                {
                    oldWarshipEntity.view.gameObject.Unlink();
                    Object.Destroy(oldWarshipEntity.view.gameObject);
                    oldWarshipEntity.Destroy();
                }

                warshipEntity.AddView(warshipGo);
                warshipGo.Link(warshipEntity);
            }
        }
        public void Execute()
        {
            foreach (var pair in viewAreas)
            {
                var playerId = pair.Key;
                var unhidden = pair.Value.newUnhidden;

                var unhiddenTransforms = withTransforms.AsEnumerable().Where(e => unhidden.Contains(e.id.value)).ToList();
                if (unhiddenTransforms.Count > 0)
                {
                    var positions = unhiddenTransforms.ToDictionary(e => e.id.value,
                                                                    e => new ViewTransform(e.position.value,
                                                                                           e.direction.angle,
                                                                                           e.viewType.id));

                    udpSendUtils.SendPositions(matchId, playerId, positions, true);
                }

                var unhiddenRadiuses = withRadiuses.AsEnumerable().Where(e => unhidden.Contains(e.id.value)).ToList();
                if (unhiddenRadiuses.Count > 0)
                {
                    var radiuses = unhiddenRadiuses.ToDictionary(e => e.id.value, e => Mathf.FloatToHalf(e.circleCollider.radius));
                    udpSendUtils.SendRadiuses(matchId, playerId, radiuses, true);
                }
            }
        }
Ejemplo n.º 5
0
 protected override void Execute(List <LobbyUiEntity> entities)
 {
     log.Info("Старт заполнения списка кораблей");
     FillWarshipsList(warshipsGroup.AsEnumerable()
                      .OrderBy(entity => entity.warship.warshipDto.WarshipTypeEnum)
                      .Select(entity => entity.warship.warshipDto)
                      .ToList());
     log.Info("Заполнение списка кораблей закончено");
 }
Ejemplo n.º 6
0
 public void Execute()
 {
     foreach (var spawnZomby in spawnZombies)
     {
         var randomTile = emptyBlocks.AsEnumerable().PickRandom();
         var position   = randomTile.WorldPosition;
         Object.Instantiate(prefab, position, Quaternion.identity);
     }
 }
Ejemplo n.º 7
0
        public void Execute()
        {
            foreach (var map in maps.GetEntities())
            {
                var cell = grounds.AsEnumerable().PickRandom();
                cell.isHasCoin = true;

                Object.Instantiate(coinPrefab, map.tilemap.value.GetCellCenterWorld(cell.Cell), Quaternion.identity);
            }
        }
    protected override void Execute(List <GameEntity> entities)
    {
        var entity  = entities.SingleEntity();
        var badGuys = CharacterUtils.FindBadGuys(_allCharacters.AsEnumerable());

        foreach (var e in badGuys)
        {
            var targetIndicator = e.view.gameObject.GetComponentInChildren <TargetIndicator>(true);
            targetIndicator.SetActive(entity.isUserInput && e.isCurrentTarget);
        }
    }
    private GameEntity GetTarget(GameEntity entity)
    {
        GameEntity result;

        switch (entity.character.type)
        {
        case CharacterType.GoodGuy:
            var badGuys = CharacterUtils.FindBadGuys(_allCharacters.AsEnumerable());
            result = badGuys.FirstOrDefault(e => e.isCurrentTarget);
            break;

        case CharacterType.BadGuy:
            var goodGuys = CharacterUtils.FindGoodGuys(_allCharacters.AsEnumerable());
            result = CharacterUtils.FirstAliveCharacter(goodGuys);
            break;

        default:
            throw new ArgumentOutOfRangeException();
        }

        return(result);
    }
    protected override void Execute(List <GameEntity> entities)
    {
        entities.ForEach(e => e.isTargetSwitch = false);
        var badGuys = CharacterUtils.FindBadGuys(_allCharacters.AsEnumerable());

        var curTargetIdx = badGuys.FindIndex(entity => entity.isCurrentTarget);

        badGuys.ForEach(entity => entity.isCurrentTarget = false);

        for (int i = 1; i < badGuys.Count; i++)
        {
            var nextEnemy = badGuys[(curTargetIdx + i) % badGuys.Count];
            if (CharacterUtils.IsNotDead(nextEnemy))
            {
                nextEnemy.isCurrentTarget = true;
                return;
            }
        }
    }
    public void Execute()
    {
        // check if all current balloons are stable
        var unstable = _balloons.AsEnumerable().Any(x => !x.isStableBalloon);

        if (Input.GetMouseButtonUp(0) && !unstable)
        {
            foreach (var thrower in _throwers.GetEntities())
            {
                var pEntity = thrower.throwerLoadedProjectile.Value;
                pEntity.ReplaceSpeed(_configuration.ProjectileSpeed);
                pEntity.isLoadedProjectile = false;
                pEntity.isFreeProjectile   = true;
                pEntity.AddProjectileBounceShield(1);

                // remove loaded projectile
                thrower.RemoveThrowerLoadedProjectile();
            }
        }
    }
        public void Execute()
        {
            if (viewAreas.sendAll)
            {
                return;
            }
            if (zone.circleCollider.radius <= visibleAreaRadius)
            {
                viewAreas.sendAll = true;
            }

            removedObjectIdsBuffer.Clear();
            removedObjectIdsBuffer.AddRange(removedObjects.AsEnumerable().Select(e => e.id.value));
            foreach (var player in players)
            {
                var playerId      = player.player.id;
                var viewArea      = viewAreas[playerId];
                var playerVisible = GetVisible(player);

                var last     = viewArea.lastVisible;
                var unhidden = viewArea.newUnhidden;

                unhidden.Clear();
                unhidden.UnionWith(playerVisible);
                unhidden.ExceptWith(removedObjectIdsBuffer);
                unhidden.ExceptWith(last);

                last.ExceptWith(playerVisible);
                last.ExceptWith(removedObjectIdsBuffer);
                if (last.Count > 0)
                {
                    udpSendUtils.SendHides(matchId, playerId, last.ToArray());
                }

                last.Clear();
                last.UnionWith(playerVisible);
                last.ExceptWith(removedObjectIdsBuffer);
            }
        }
Ejemplo n.º 13
0
        protected override void Execute(List <LobbyUiEntity> entities)
        {
            List <LobbyUiEntity> warshipsList = warshipsGroup.GetEntities().ToList();

            // log.Debug($"кол-во кораблей до спавна "+warshipsList.Count);
            foreach (var warshipEntity in entities)
            {
                // log.Debug("Спавн корабля с id = "+warshipEntity.warship.warshipDto.WarshipTypeEnum.ToString());
                WarshipDto warshipDto = warshipEntity.warship.warshipDto;

                string skinName = warshipDto.GetCurrentSkinName();
                // log.Debug("Название скина перед спавном "+skinName);
                GameObject prefab    = Resources.Load <GameObject>("Prefabs/" + skinName);
                GameObject warshipGo = Object.Instantiate(prefab, gameViewsParent, false);
                warshipGo.transform.localScale = new Vector3(1.4f, 1.4f, 1.4f);

                LobbyUiEntity oldWarshipEntity = warshipsGroup.AsEnumerable()
                                                 .SingleOrDefault(entity => entity.warship.warshipDto.WarshipTypeEnum == warshipDto.WarshipTypeEnum);

                if (oldWarshipEntity != null)
                {
                    // log.Debug("Корабль этого типа существует");
                    oldWarshipEntity.view.gameObject.Unlink();
                    Object.Destroy(oldWarshipEntity.view.gameObject);
                    oldWarshipEntity.Destroy();
                    // log.Debug("Корабль этого типа уничтожен");
                }

                // warshipGo.SetActive(false);
                warshipEntity.AddView(warshipGo);
                warshipGo.Link(warshipEntity);
            }


            isWarshipCreationCompleted = true;
        }
Ejemplo n.º 14
0
 public static T Any <T>(this IGroup <T> group) where T : class, IEntity
 {
     return(group.AsEnumerable().DefaultIfEmpty(null).First());
 }
        public void Initialize()
        {
            var playerIds = players.AsEnumerable().Select(player => player.player.id);

            viewAreas.Initialize(playerIds);
        }
Ejemplo n.º 16
0
    void when_created()
    {
        TestEntity eA1 = null;
        TestEntity eA2 = null;

        before = () => {
            _groupA = new Group <TestEntity>(Matcher <TestEntity> .AllOf(CID.ComponentA));
            eA1     = this.CreateEntity().AddComponentA();
            eA2     = this.CreateEntity().AddComponentA();
        };

        context["initial state"] = () => {
            it["doesn't have entities which haven't been added"] = () => {
                _groupA.GetEntities().should_be_empty();
            };

            it["doesn't add entities to buffer"] = () => {
                var buffer = new List <TestEntity>();
                buffer.Add(this.CreateEntity());
                var retBuffer = _groupA.GetEntities(buffer);
                buffer.should_be_empty();
                retBuffer.should_be_same(buffer);
            };

            it["is empty"] = () => {
                _groupA.count.should_be(0);
            };

            it["doesn't contain entity"] = () => {
                _groupA.ContainsEntity(eA1).should_be_false();
            };
        };

        context["when entity is matching"] = () => {
            before = () => {
                handleSilently(eA1);
            };

            it["adds matching entity"] = () => {
                assertContains(eA1);
            };

            it["fills buffer with entities"] = () => {
                var buffer = new List <TestEntity>();
                _groupA.GetEntities(buffer);
                buffer.Count.should_be(1);
                buffer[0].should_be_same(eA1);
            };

            it["clears buffer before filling"] = () => {
                var buffer = new List <TestEntity>();
                buffer.Add(this.CreateEntity());
                buffer.Add(this.CreateEntity());
                _groupA.GetEntities(buffer);
                buffer.Count.should_be(1);
                buffer[0].should_be_same(eA1);
            };

            it["doesn't add same entity twice"] = () => {
                handleSilently(eA1);
                assertContains(eA1);
            };

            it["enumerates group"] = () => {
                var     i = 0;
                IEntity e = null;
                foreach (var entity in _groupA)
                {
                    i++;
                    e = entity;
                }

                i.should_be(1);
                e.should_be_same(eA1);
            };

            it["returns enumerable"] = () => {
                _groupA.AsEnumerable().Single().should_be_same(eA1);
            };

            context["when entity doesn't match anymore"] = () => {
                it["removes entity"] = () => {
                    eA1.RemoveComponentA();
                    handleSilently(eA1);

                    assertContainsNot(eA1);
                };
            };
        };

        context["when entity is not enabled"] = () => {
            it["doesn't add entity"] = () => {
                eA1.InternalDestroy();
                handleSilently(eA1);
                assertContainsNot(eA1);
            };
        };

        it["doesn't add entity when not matching"] = () => {
            var e = this.CreateEntity().AddComponentB();
            handleSilently(e);
            assertContainsNot(e);
        };

        it["gets null when single entity does not exist"] = () => {
            _groupA.GetSingleEntity().should_be_null();
        };

        it["gets single entity"] = () => {
            handleSilently(eA1);
            _groupA.GetSingleEntity().should_be_same(eA1);
        };

        it["throws when attempting to get single entity and multiple matching entities exist"] = expect <GroupSingleEntityException <TestEntity> >(() => {
            handleSilently(eA1);
            handleSilently(eA2);
            _groupA.GetSingleEntity();
        });

        context["events"] = () => {
            var didDispatch = 0;

            before = () => {
                didDispatch = 0;
            };

            it["dispatches OnEntityAdded when matching entity added"] = () => {
                _groupA.OnEntityAdded += (group, entity, index, component) => {
                    didDispatch++;
                    group.should_be_same(_groupA);
                    entity.should_be_same(eA1);
                    index.should_be(CID.ComponentA);
                    component.should_be_same(Component.A);
                };
                _groupA.OnEntityRemoved += delegate { this.Fail(); };
                _groupA.OnEntityUpdated += delegate { this.Fail(); };

                handleAddEA(eA1);
                didDispatch.should_be(1);
            };

            it["doesn't dispatches OnEntityAdded when matching entity already has been added"] = () => {
                handleAddEA(eA1);
                _groupA.OnEntityAdded   += delegate { this.Fail(); };
                _groupA.OnEntityRemoved += delegate { this.Fail(); };
                _groupA.OnEntityUpdated += delegate { this.Fail(); };
                handleAddEA(eA1);
                didDispatch.should_be(0);
            };

            it["doesn't dispatches OnEntityAdded when entity is not matching"] = () => {
                var e = this.CreateEntity().AddComponentB();
                _groupA.OnEntityAdded   += delegate { this.Fail(); };
                _groupA.OnEntityRemoved += delegate { this.Fail(); };
                _groupA.OnEntityUpdated += delegate { this.Fail(); };
                handleAddEB(e);
            };

            it["dispatches OnEntityRemoved when entity got removed"] = () => {
                handleSilently(eA1);
                _groupA.OnEntityRemoved += (group, entity, index, component) => {
                    didDispatch++;
                    group.should_be_same(_groupA);
                    entity.should_be_same(eA1);
                    index.should_be(CID.ComponentA);
                    component.should_be_same(Component.A);
                };
                _groupA.OnEntityAdded   += delegate { this.Fail(); };
                _groupA.OnEntityUpdated += delegate { this.Fail(); };

                eA1.RemoveComponentA();
                handleRemoveEA(eA1, Component.A);

                didDispatch.should_be(1);
            };

            it["doesn't dispatch OnEntityRemoved when entity didn't get removed"] = () => {
                _groupA.OnEntityRemoved += delegate { this.Fail(); };
                eA1.RemoveComponentA();
                handleRemoveEA(eA1, Component.A);
            };

            it["dispatches OnEntityRemoved, OnEntityAdded and OnEntityUpdated when updating"] = () => {
                handleSilently(eA1);

                var removed       = 0;
                var added         = 0;
                var updated       = 0;
                var newComponentA = new ComponentA();

                _groupA.OnEntityRemoved += (group, entity, index, component) => {
                    removed += 1;
                    group.should_be(_groupA);
                    entity.should_be(eA1);
                    index.should_be(CID.ComponentA);
                    component.should_be_same(Component.A);
                };
                _groupA.OnEntityAdded += (group, entity, index, component) => {
                    added += 1;
                    group.should_be(_groupA);
                    entity.should_be(eA1);
                    index.should_be(CID.ComponentA);
                    component.should_be_same(newComponentA);
                };
                _groupA.OnEntityUpdated += (group, entity, index, previousComponent, newComponent) => {
                    updated += 1;
                    group.should_be(_groupA);
                    entity.should_be(eA1);
                    index.should_be(CID.ComponentA);
                    previousComponent.should_be_same(Component.A);
                    newComponent.should_be_same(newComponentA);
                };

                updateEA(eA1, newComponentA);

                removed.should_be(1);
                added.should_be(1);
                updated.should_be(1);
            };

            it["doesn't dispatch OnEntityRemoved and OnEntityAdded when updating when group doesn't contain entity"] = () => {
                _groupA.OnEntityRemoved += delegate { this.Fail(); };
                _groupA.OnEntityAdded   += delegate { this.Fail(); };
                _groupA.OnEntityUpdated += delegate { this.Fail(); };
                updateEA(eA1, new ComponentA());
            };

            it["removes all event handlers"] = () => {
                _groupA.OnEntityAdded   += delegate { this.Fail(); };
                _groupA.OnEntityRemoved += delegate { this.Fail(); };
                _groupA.OnEntityUpdated += delegate { this.Fail(); };

                _groupA.RemoveAllEventHandlers();

                handleAddEA(eA1);

                var cA = eA1.GetComponentA();
                eA1.RemoveComponentA();
                handleRemoveEA(eA1, cA);

                eA1.AddComponentA();
                handleAddEA(eA1);
                updateEA(eA1, Component.A);
            };
        };

        context["internal caching"] = () => {
            context["GetEntities()"] = () => {
                IEntity[] cache = null;

                before = () => {
                    handleSilently(eA1);
                    cache = _groupA.GetEntities();
                };

                it["gets cached entities"] = () => {
                    _groupA.GetEntities().should_be_same(cache);
                };

                it["updates cache when adding a new matching entity"] = () => {
                    handleSilently(eA2);
                    _groupA.GetEntities().should_not_be_same(cache);
                };

                it["doesn't update cache when attempting to add a not matching entity"] = () => {
                    var e = this.CreateEntity();
                    handleSilently(e);
                    _groupA.GetEntities().should_be_same(cache);
                };

                it["updates cache when removing an entity"] = () => {
                    eA1.RemoveComponentA();
                    handleSilently(eA1);
                    _groupA.GetEntities().should_not_be_same(cache);
                };

                it["doesn't update cache when attempting to remove an entity that wasn't added before"] = () => {
                    eA2.RemoveComponentA();
                    handleSilently(eA2);
                    _groupA.GetEntities().should_be_same(cache);
                };

                it["doesn't update cache when updating an entity"] = () => {
                    updateEA(eA1, new ComponentA());
                    _groupA.GetEntities().should_be_same(cache);
                };
            };

            context["SingleEntity()"] = () => {
                IEntity cache = null;

                before = () => {
                    handleSilently(eA1);
                    cache = _groupA.GetSingleEntity();
                };

                it["gets cached singleEntities"] = () => {
                    _groupA.GetSingleEntity().should_be_same(cache);
                };

                it["updates cache when new single entity was added"] = () => {
                    eA1.RemoveComponentA();
                    handleSilently(eA1);
                    handleSilently(eA2);
                    _groupA.GetSingleEntity().should_not_be_same(cache);
                };

                it["updates cache when single entity is removed"] = () => {
                    eA1.RemoveComponentA();
                    handleSilently(eA1);
                    _groupA.GetSingleEntity().should_not_be_same(cache);
                };

                it["doesn't update cache when single entity is updated"] = () => {
                    updateEA(eA1, new ComponentA());
                    _groupA.GetSingleEntity().should_be_same(cache);
                };
            };
        };

        context["reference counting"] = () => {
            it["retains matched entity"] = () => {
                eA1.retainCount.should_be(0);
                handleSilently(eA1);
                eA1.retainCount.should_be(1);
            };

            it["releases removed entity"] = () => {
                handleSilently(eA1);
                eA1.RemoveComponentA();
                handleSilently(eA1);
                eA1.retainCount.should_be(0);
            };

            it["invalidates entitiesCache (silent mode)"] = () => {
                var didExecute = 0;
                eA1.OnEntityReleased += entity => {
                    didExecute += 1;
                    _groupA.GetEntities().Length.should_be(0);
                };
                handleSilently(eA1);
                _groupA.GetEntities();
                eA1.RemoveComponentA();
                handleSilently(eA1);
                didExecute.should_be(1);
            };

            it["invalidates entitiesCache"] = () => {
                var didExecute = 0;
                eA1.OnEntityReleased += entity => {
                    didExecute += 1;
                    _groupA.GetEntities().Length.should_be(0);
                };
                handleAddEA(eA1);
                _groupA.GetEntities();
                eA1.RemoveComponentA();
                handleRemoveEA(eA1, Component.A);
                didExecute.should_be(1);
            };

            it["invalidates singleEntityCache (silent mode)"] = () => {
                var didExecute = 0;
                eA1.OnEntityReleased += entity => {
                    didExecute += 1;
                    _groupA.GetSingleEntity().should_be_null();
                };
                handleSilently(eA1);
                _groupA.GetSingleEntity();
                eA1.RemoveComponentA();
                handleSilently(eA1);
                didExecute.should_be(1);
            };

            it["invalidates singleEntityCache"] = () => {
                var didExecute = 0;
                eA1.OnEntityReleased += entity => {
                    didExecute += 1;
                    _groupA.GetSingleEntity().should_be_null();
                };
                handleAddEA(eA1);
                _groupA.GetSingleEntity();
                eA1.RemoveComponentA();
                handleRemoveEA(eA1, Component.A);
                didExecute.should_be(1);
            };

            it["retains entity until after event handlers were called"] = () => {
                handleAddEA(eA1);
                var didDispatch = 0;
                _groupA.OnEntityRemoved += (group, entity, index, component) => {
                    didDispatch += 1;
                    entity.retainCount.should_be(1);
                };
                eA1.RemoveComponentA();
                handleRemoveEA(eA1, Component.A);

                didDispatch.should_be(1);
                eA1.retainCount.should_be(0);
            };
        };

        it["can ToString"] = () => {
            var m = Matcher <TestEntity> .AllOf(Matcher <TestEntity> .AllOf(0), Matcher <TestEntity> .AllOf(1));

            var group = new Group <TestEntity>(m);
            group.ToString().should_be("Group(AllOf(0, 1))");
        };
    }
        public void Execute()
        {
            foreach (var pair in viewAreas)
            {
                var playerId           = pair.Key;
                var currentKnownMaxHps = knownMaxHps[playerId];
                var visible            = ReactivePlayersVisionSystem.GetVisibleObjects(viewAreas, pair.Value, withMaxHp.AsEnumerable());

                var changed = new Dictionary <ushort, ushort>(visible.Count);
                foreach (var gameEntity in visible)
                {
                    var id    = gameEntity.id.value;
                    var maxHp = (ushort)gameEntity.maxHealthPoints.value;
                    if (currentKnownMaxHps.TryGetValue(id, out var knownMaxHp) && knownMaxHp == maxHp)
                    {
                        continue;
                    }
                    changed.Add(id, maxHp);
                    currentKnownMaxHps[id] = maxHp;
                }
                //TODO: Не отправлять значения по умолчанию
                if (changed.Count == 0)
                {
                    continue;
                }
                udpSendUtils.SendMaxHealthPoints(matchId, playerId, changed);
            }
        }
Ejemplo n.º 18
0
        public void GroupReturnsEnumerable()
        {
            HandleSilently(_entityWithAComponent1);

            Assert.AreEqual(_entityWithAComponent1, _groupA.AsEnumerable().Single());
        }