Пример #1
0
    public override void SetBlock(SimBlock block)
    {
        base.SetBlock(block);

        if (TemBlock != null)
        {
            transform.position = TemBlock.GetCenterPosition();
        }
    }
Пример #2
0
    void InitStateMachine()
    {
        if (IsStateMachineInited)
        {
            return;
        }
        IsStateMachineInited = true;

        m_stateMachine = new AStateMachine <HeroState, LogicEvents> (HeroState.None);

        m_stateMachine.BlindFromEveryState(LogicEvents.PlaceHeroPhase, HeroState.ReadyToPlace);

        m_stateMachine.AddEnter(HeroState.ReadyToPlace, delegate {
            transform.DOMove(oritinalPos, 1f);
        });

        m_stateMachine.AddEnter(HeroState.MoveWithMouse, delegate {
            m_collider.size = new Vector3(0.1f, 0.1f, 1f);
        });

        m_stateMachine.AddUpdate(HeroState.MoveWithMouse, delegate {
            transform.position = InputManager.FocusWorldPos;
        });

        m_stateMachine.AddExit(HeroState.MoveWithMouse, delegate {
            m_collider.size = new Vector3(2.56f, 2.56f, 1f);
        });

        m_stateMachine.AddEnter(HeroState.Prepare, delegate {
            if (TriggerBlock != null)
            {
                TriggerBlock.RegisterHero(this);

                TemBlock = TriggerBlock.BlockInfo;
                LogicManager.Instance.RegisterHero(this);

                transform.DOMove(TriggerBlock.GetCenterPosition(), 0.2f);

                // Disable Collider
                if (m_collider != null)
                {
                    m_collider.enabled = false;
                }
            }
        });

        m_stateMachine.BlindFromEveryState(LogicEvents.StrategyPhase, HeroState.Strategy);
        m_stateMachine.BlindFromEveryState(LogicEvents.AutoBattle, HeroState.Strategy);


        m_stateMachine.AddEnter(HeroState.Strategy, delegate {
            if (TemBlock == null)
            {
                m_stateMachine.State = HeroState.None;
            }
            else
            {
                targetLine.enabled  = false;
                targetArrow.enabled = false;

                if (LogicManager.IsAutoPlay)
                {
                    m_stateMachine.State = HeroState.StrategyAuto;
                }
                else
                {
                    if (!(m_strategy is CustomStrategy))
                    {
                        DestroyImmediate(m_strategy);
                        m_strategy = gameObject.AddComponent <CustomStrategy>();
                        m_strategy.Init(this);
                    }
                    if (m_strategy is CustomStrategy)
                    {
                        ((CustomStrategy)m_strategy).target   = TemSimpleBlock;
                        ((CustomStrategy)m_strategy).isActive = false;
                    }
                }
            }
        });

        m_stateMachine.AddUpdate(HeroState.Strategy, delegate() {
            if (LogicManager.IsAutoPlay)
            {
                m_stateMachine.State = HeroState.StrategyAuto;
            }
        });

        m_stateMachine.BlindStateEventHandler(HeroState.StrategyChoose, delegate(object obj) {
            LogicArg arg = (LogicArg)obj;
            if (arg.type == LogicEvents.ConfirmHero)
            {
//				Block block = (Block)arg.GetMessage(M_Event.BLOCK);
//				if ( TemBlock != null && !TemBlock.Equals(block))
//				{
                m_stateMachine.State = HeroState.Strategy;
//				}
            }
            else if (arg.type == LogicEvents.SelectBlock)
            {
                Block block = (Block)arg.GetMessage(M_Event.BLOCK);

                if (m_move.IsInMoveRange(block.SimpleBlock))
                {
                    ((CustomStrategy)m_strategy).target = block.SimpleBlock;
                    DrawToTarget(block);
                    m_stateMachine.State = HeroState.StrategyDirection;
                }
            }
        });


        m_stateMachine.BlindStateEventHandler(HeroState.StrategyDirection, delegate(object obj) {
            LogicArg arg = (LogicArg)obj;
            if (arg.type == LogicEvents.FingerUp)
            {
                m_stateMachine.State = HeroState.StrategyConfirm;
            }
        });

        m_stateMachine.BlindStateEventHandler(HeroState.StrategyConfirm, delegate(object obj) {
            LogicArg arg = (LogicArg)obj;
            if (arg.type == LogicEvents.ConfirmHero)
            {
                Block block = (Block)arg.GetMessage(M_Event.BLOCK);
                if (TemBlock.Equals(block))
                {
                    m_stateMachine.State = HeroState.StrategyChoose;
                }
            }
            else if (arg.type == LogicEvents.ConfirmMove)
            {
                if (LogicManager.Instance.mode == LogicManager.Mode.SingleBattle)
                {
                    if (arg.sender != this)
                    {
                        m_stateMachine.State = HeroState.Strategy;
                    }
                }
            }
        });

        m_stateMachine.AddEnter(HeroState.StrategyChoose, delegate {
            TemBlock.linkedBlock.visualType = BattleBlock.BlockVisualType.StrategyFocus;
            BattleField.ShowBlock(m_move.GetMoveRange(), BattleBlock.BlockVisualType.StrategyMoveRange);
            BattleField.ShowBlock(new SimBlock[] { TemBlock.SimpleBlock }, BattleBlock.BlockVisualType.StrategyChosenHero, false);
        });

        m_stateMachine.AddEnter(HeroState.StrategyDirection, delegate() {
            targetArrow.enabled = true;
            Block block         = BattleField.GetBlock(((CustomStrategy)m_strategy).target);
            BattleField.ShowBlock(new SimBlock[] { TemBlock.SimpleBlock }, BattleBlock.BlockVisualType.StrategyChosenHero, false);
            targetArrow.transform.position = block.linkedBlock.GetCenterPosition();
        });

        m_stateMachine.AddUpdate(HeroState.StrategyDirection, delegate {
            // set the target arrow to right angle
            Vector3 focusPos = InputManager.FocusWorldPos;
            Block block      = BattleField.GetBlock(((CustomStrategy)m_strategy).target);
            Vector3 toward   = focusPos - block.linkedBlock.GetCenterPosition();
            float angle      = Mathf.Atan2(toward.y, toward.x) * Mathf.Rad2Deg;
            angle            = Mathf.Round((angle) / 90f) * 90f;

            targetArrow.transform.rotation = Quaternion.Euler(0, 0, angle);

            // set the angle of strategy
            ((CustomStrategy)m_strategy).angle = angle;

            // get the direction of the strategy
            Direction direction = ((CustomStrategy)m_strategy).GetDirection();
            BattleField.ShowBlock(m_attack.GetAttackRange(((CustomStrategy)m_strategy).target, direction, GetHeroInfo().AttackRange), BattleBlock.BlockVisualType.StrategyAttackRange);
        });

        m_stateMachine.AddExit(HeroState.StrategyDirection, delegate {
            ((CustomStrategy)m_strategy).isActive = true;
            LogicArg arg = new LogicArg(this);
//			Debug.Log("Fire Confirm Move ");
            M_Event.FireLogicEvent(LogicEvents.ConfirmMove, arg);
        });

        m_stateMachine.AddEnter(HeroState.StrategyConfirm, delegate {
            BattleField.ResetVisualColor(true);
            TemBlock.linkedBlock.visualType = BattleBlock.BlockVisualType.StrategyConfirm;
        });

        m_stateMachine.AddEnter(HeroState.StrategyAuto, delegate() {
            // set up the strategy
            if (!(m_strategy is AIStrategy))
            {
                DestroyImmediate(m_strategy);
                m_strategy = gameObject.AddComponent <AIStrategy>();
                m_strategy.Init(this);
                m_strategy.OnBeforeBattle();
            }
        });

        m_stateMachine.AddEnter(HeroState.BattleMove, delegate {
            targetLine.enabled  = false;
            targetArrow.enabled = false;
        });
    }
Пример #3
0
    void InitStateMachine()
    {
        m_stateMachine = new AStateMachine <HeroState, LogicEvents>(HeroState.None);


        m_stateMachine.BlindStateEventHandler(HeroState.Strategy, delegate(object obj) {
            LogicArg arg = (LogicArg)obj;
            Block block  = (Block)arg.GetMessage(M_Event.BLOCK);
            Debug.Log("Get event" + arg.type);
            if (arg.type == LogicEvents.ConfirmHero)
            {
                Debug.Log("Get Confirm Hero" + block.SimpleBlock + " " + TemBlock.SimpleBlock);
                if (TemBlock != null && TemBlock.Equals(block))
                {
                    m_stateMachine.State = HeroState.StrategyMove;
                }
                else
                {
                    m_stateMachine.State = HeroState.Strategy;
                }
            }
            else if (arg.type == LogicEvents.SelectBlock)
            {
                m_stateMachine.State = HeroState.Strategy;
            }
        });

        m_stateMachine.BlindStateEventHandler(HeroState.StrategyMove, delegate(object obj) {
            LogicArg arg = (LogicArg)obj;
            Block block  = (Block)arg.GetMessage(M_Event.BLOCK);
            if (arg.type == LogicEvents.ConfirmHero)
            {
                if (TemBlock != null && TemBlock.Equals(block))
                {
                    m_stateMachine.State = HeroState.StrategyAttack;
                }
                else
                {
                    m_stateMachine.State = HeroState.Strategy;
                }
            }
            else if (arg.type == LogicEvents.SelectBlock)
            {
                m_stateMachine.State = HeroState.Strategy;
            }
        });

        m_stateMachine.BlindStateEventHandler(HeroState.StrategyAttack, delegate(object obj) {
            LogicArg arg = (LogicArg)obj;
            Block block  = (Block)arg.GetMessage(M_Event.BLOCK);
            if (arg.type == LogicEvents.ConfirmHero)
            {
                if (TemBlock != null && TemBlock.Equals(block))
                {
                    m_stateMachine.State = HeroState.StrategyMove;
                }
                else
                {
                    m_stateMachine.State = HeroState.Strategy;
                }
            }
            else if (arg.type == LogicEvents.SelectBlock)
            {
                m_stateMachine.State = HeroState.Strategy;
            }
        });

        m_stateMachine.AddEnter(HeroState.Strategy, delegate {
            if (m_collider == null)
            {
                m_collider = GetComponent <BoxCollider>();
            }
            if (m_collider != null)
            {
                m_collider.size = new Vector3(2.56f, 2.56f, 1f);
            }
            if (m_collider != null)
            {
                m_collider.enabled = false;
            }
        });

        m_stateMachine.AddEnter(HeroState.StrategyMove, delegate() {
            BattleField.ShowBlock(m_move.GetMoveRange(), BattleBlock.BlockVisualType.MoveRangeEnermy);
        });

        m_stateMachine.AddEnter(HeroState.StrategyAttack, delegate() {
            BattleField.ShowBlock(m_attack.GetAttackRange(), BattleBlock.BlockVisualType.AttackRangeEnermy);
        });

        m_stateMachine.BlindFromEveryState(LogicEvents.StrategyPhase, HeroState.Strategy);

        m_stateMachine.State = HeroState.Strategy;
    }