Exemplo n.º 1
0
 public void OnInitialized(Level level)
 {
     // Start visuals prematurely
     if (AutoIgnite)
     {
         _turnsUntilDetonate = Delay;
         SoundManager.Instance.Play(IgniteSound);
         Sparks?.Trigger(transform);
     }
     else
     {
         _turnsUntilDetonate = -1;
     }
     UpdateSparksState();
 }
Exemplo n.º 2
0
        public IEnumerable <IChange> Handle(Level level, ICommand command)
        {
            if (command is HitCommand)
            {
                foreach (var entityInTargetPos in level.GetActiveEntitiesAt(_entity.Position))
                {
                    if (entityInTargetPos.ObjectType.ToString() == "Player")
                    {
                        _haloFx.Stop();
                        _revertCollectFx.Stop();
                        _collectFx.Trigger(transform);

                        _entity.Deactivate();

                        if (_disableRenderersWhenInactive != null)
                        {
                            foreach (var rnd in _disableRenderersWhenInactive)
                            {
                                rnd.enabled = false;
                            }
                        }

                        SoundManager.Instance.Play(PickupSound);
                        level.CollectStar();

                        yield return(new Collection(_entity.Id));
                    }
                }
            }
        }
Exemplo n.º 3
0
        public void Revert(Level level, IChange change)
        {
            if (change is DestroyedChange)
            {
                DestroyedFx?.Stop();
                RevertDestroyedFx?.Trigger(transform);
                if (Animator != null)
                {
                    Animator.SetBool(AnimDiedBool, false);
                }


                if (DisableAllRenderersWhenInactive)
                {
                    foreach (var rnd in gameObject.GetComponentsInChildren <Renderer>())
                    {
                        rnd.enabled = true;
                    }
                }

                if (DisableRenderersWhenInactive != null)
                {
                    foreach (var rnd in DisableRenderersWhenInactive)
                    {
                        rnd.enabled = true;
                    }
                }

                SoundManager.Instance.Play(RevertDestroySound);

                _entity.Activate();
            }
        }
Exemplo n.º 4
0
        public IEnumerable <IChange> Handle(Level level, ICommand command)
        {
            if (command is SpawnCommand spawnCommand)
            {
                var entity = level.Spawn(
                    Prefab,
                    _entity.Position + Utils.MoveDelta(_entity.Orientation),
                    _entity.Orientation);

                foreach (var entityInTargetPos in level.GetActiveEntitiesAt(entity.Position))
                {
                    if (entityInTargetPos.Id != entity.Id)
                    {
                        // If current object collides with target object
                        if (CollisionConfig.ObjectsCollide(entity.ObjectType, entityInTargetPos.ObjectType))
                        {
                            level.DispatchEarly(new CollisionEvent(
                                                    target: entityInTargetPos.Id,
                                                    sourceId: entity.Id,
                                                    direction: Utils.AbsoluteDirectionToRelative(Utils.RevertDirection(spawnCommand.Direction), entityInTargetPos.Orientation)));
                            level.DispatchEarly(new CollisionEvent(
                                                    target: entity.Id,
                                                    sourceId: entityInTargetPos.Id,
                                                    direction: Utils.AbsoluteDirectionToRelative(spawnCommand.Direction, entity.Orientation)));
                        }
                        if (CollisionConfig.ObjectsHit(entity.ObjectType, entityInTargetPos.ObjectType))
                        {
                            level.DispatchEarly(new HitCommand(
                                                    target: entityInTargetPos.Id,
                                                    sourceId: entity.Id,
                                                    direction: Utils.AbsoluteDirectionToRelative(Utils.RevertDirection(spawnCommand.Direction), entityInTargetPos.Orientation)));
                            level.DispatchEarly(new HitCommand(
                                                    target: entity.Id,
                                                    sourceId: entityInTargetPos.Id,
                                                    direction: Utils.AbsoluteDirectionToRelative(spawnCommand.Direction, entity.Orientation)));
                        }
                    }
                }

                if (entity != null)
                {
                    if (Animator != null)
                    {
                        Animator.SetTrigger(AnimOnSpawnTrigger);
                    }

                    SoundManager.Instance.Play(SpawnSound);
                    ShootFx?.Trigger(transform);

                    yield return(new SpawnChange(_entity.Id, entity.Id));
                }
            }
        }
Exemplo n.º 5
0
        public IEnumerable <IChange> Handle(Level level, ICommand command)
        {
            if (_entity == null)
            {
                yield break;
            }

            if (command is DestroyCommand)
            {
                RevertDestroyedFx?.Stop();
                DestroyedFx?.Trigger(transform);
                _entity.Deactivate();

                //if(_uiTimerManager != null)
                //_uiTimerManager.DeleteTimer(gameObject);

                if (Animator != null)
                {
                    Animator.SetBool(AnimDiedBool, true);
                }

                if (DisableAllRenderersWhenInactive)
                {
                    foreach (var rnd in gameObject.GetComponentsInChildren <Renderer>())
                    {
                        rnd.enabled = false;
                    }
                }

                if (DisableRenderersWhenInactive != null)
                {
                    foreach (var rnd in DisableRenderersWhenInactive)
                    {
                        rnd.enabled = false;
                    }
                }

                SoundManager.Instance.Play(DestroySound);

                yield return(new DestroyedChange(_entity.Id));
            }
        }
Exemplo n.º 6
0
        public void Revert(Level level, IChange change)
        {
            if (change is Collection)
            {
                SoundManager.Instance.Play(RevertPickupSound);
                _collectFx.Stop();
                _revertCollectFx.Trigger(transform);
                _haloFx.Trigger(transform);
                if (_disableRenderersWhenInactive != null)
                {
                    foreach (var rnd in _disableRenderersWhenInactive)
                    {
                        rnd.enabled = true;
                    }
                }

                _entity.Activate();

                level.LoseStar();
            }
        }
Exemplo n.º 7
0
 public void OnInitialized(Level level)
 {
     _entity = GetComponent <Entity>();
     _haloFx.Trigger(transform);
 }