예제 #1
0
        public void SetTrapState(TrapComponent comp, TrapState state)
        {
            SmartEntity       smartEntity  = (SmartEntity)comp.Entity;
            TrapViewComponent trapViewComp = smartEntity.TrapViewComp;
            TrapState         currentState = comp.CurrentState;

            if (currentState != state)
            {
                comp.CurrentState = state;
                IState currentState2 = Service.Get <GameStateMachine>().CurrentState;
                if (TrapUtils.IsCurrentPlayerInDefensiveBattle(currentState2))
                {
                    smartEntity.BuildingComp.BuildingTO.CurrentStorage = ((state == TrapState.Armed) ? 1 : 0);
                }
                Service.Get <TrapViewController>().UpdateTrapVisibility((SmartEntity)comp.Entity);
                switch (state)
                {
                case TrapState.Spent:
                    Service.Get <EventManager>().SendEvent(EventId.TrapDisarmed, comp);
                    break;

                case TrapState.Active:
                    Service.Get <EventManager>().SendEvent(EventId.TrapTriggered, comp);
                    break;

                case TrapState.Destroyed:
                    comp.CurrentState = TrapState.Spent;
                    Service.Get <EventManager>().SendEvent(EventId.TrapDestroyed, comp);
                    break;
                }
            }
            Service.Get <TrapViewController>().SetTrapViewState(trapViewComp, state);
        }
예제 #2
0
        public void UpdateTrapVisibility(SmartEntity entity)
        {
            if (entity.TrapViewComp == null)
            {
                return;
            }
            TrapViewComponent trapViewComp = entity.TrapViewComp;
            IState            currentState = Service.GameStateMachine.CurrentState;
            bool flag  = currentState is BattleStartState || currentState is BattlePlayState || currentState is BattlePlaybackState || currentState is BattleEndState;
            bool flag2 = GameUtils.IsVisitingBase();
            bool flag3 = TrapUtils.IsCurrentPlayerInDefensiveBattle(currentState);
            bool flag4 = (flag && !flag3) || flag2;

            trapViewComp.Anim.SetLayerWeight(1, (float)((!flag4) ? 1 : 0));
            trapViewComp.Anim.SetLayerWeight(0, (float)((!flag4) ? 0 : 1));
            bool active = false;

            if (!flag2)
            {
                switch (entity.TrapComp.CurrentState)
                {
                case TrapState.Spent:
                    active = (!flag || flag3 || entity.TrapComp.PreviousState == TrapState.Active);
                    break;

                case TrapState.Armed:
                    active = (!flag || flag3);
                    break;

                case TrapState.Active:
                    active = true;
                    break;

                case TrapState.Destroyed:
                    active = flag;
                    break;
                }
            }
            trapViewComp.Contents.SetActive(active);
        }
예제 #3
0
        public void SetTrapState(TrapComponent comp, TrapState state)
        {
            SmartEntity       smartEntity  = (SmartEntity)comp.Entity;
            TrapViewComponent trapViewComp = smartEntity.TrapViewComp;
            TrapState         currentState = comp.CurrentState;

            if (currentState != state)
            {
                comp.CurrentState = state;
                IState currentState2 = Service.GameStateMachine.CurrentState;
                if (TrapUtils.IsCurrentPlayerInDefensiveBattle(currentState2))
                {
                    smartEntity.BuildingComp.BuildingTO.CurrentStorage = ((state != TrapState.Armed) ? 0 : 1);
                }
                Service.TrapViewController.UpdateTrapVisibility((SmartEntity)comp.Entity);
                if (state != TrapState.Active)
                {
                    if (state != TrapState.Spent)
                    {
                        if (state == TrapState.Destroyed)
                        {
                            comp.CurrentState = TrapState.Spent;
                            Service.EventManager.SendEvent(EventId.TrapDestroyed, comp);
                        }
                    }
                    else
                    {
                        Service.EventManager.SendEvent(EventId.TrapDisarmed, comp);
                    }
                }
                else
                {
                    Service.EventManager.SendEvent(EventId.TrapTriggered, comp);
                }
            }
            Service.TrapViewController.SetTrapViewState(trapViewComp, state);
        }