Ejemplo n.º 1
0
    void Start()
    {
        Vector3 position = transform.position;

        Trigger = Instantiate <TriggerBlock>(prefab);
        Trigger.transform.position = position;
        this.gameObject.SetActive(false);
    }
Ejemplo n.º 2
0
 // Start is called before the first frame update
 void Start()
 {
     block = transform.parent.gameObject.GetComponent <TriggerBlock>();
     if (block == null)
     {
         throw new System.Exception("no triggerblock on parent:" + transform.parent.gameObject);
     }
 }
Ejemplo n.º 3
0
    public void OnClickAddTrigger(Trigger trigger = null)
    {
        GameObject   new_item        = Instantiate(trigger_prefab);
        TriggerBlock new_item_script = new_item.GetComponent <TriggerBlock>();
        int          id = trigger_list.transform.childCount - 1;

        new_item.transform.SetParent(trigger_list.transform);
        new_item_script.program_menu = this;
        new_item.transform.SetSiblingIndex(id);
        if (trigger != null)
        {
            new_item_script.trigger = trigger;
        }
        //Canvas c = gameObject.GetComponent<Canvas>();
        ResetScroll(1f);
    }
Ejemplo n.º 4
0
    private void DisplayBehaviorForTrigger(TriggerInfo trigger)
    {
        currentBehavior = currentBot.Behaviors.FirstOrDefault(behaviorInfo => behaviorInfo.TriggerId == trigger.ID);

        if (currentBehavior != null)
        {
            var behaviorBlocks = currentBehavior.Blocks.Select(block => block != null ? Block.FromInfo(block) : null);

            foreach (var block in behaviorBlocks.Where(block => block != null))
            {
                AddBlock(block);
            }

            currentTriggerBlock = GetBlockById(currentBehavior.EntryBlockId) as TriggerBlock;
            if (currentTriggerBlock != null)
            {
                currentTriggerBlock.gameObject.transform.SetPositionAndRotation(new Vector2(-6.3f, 4f), Quaternion.Euler(0, 0, 0));
                StartCoroutine(LetStartThen(currentTriggerBlock.PositionConnections));
            }
        }
    }
Ejemplo n.º 5
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;
        });
    }
    }                                                                 //End update

    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.gameObject.tag == "SlowBlock")
        {
            SlowBlock slowBlock = collision.GetComponent <SlowBlock>();
            currentSpeed -= slowBlock.SlowValue;
            SpeedChange();
        }
        if (collision.gameObject.tag == "SpeedBlock")
        {
            SpeedBlock speedBlock = collision.GetComponent <SpeedBlock>();
            currentSpeed += speedBlock.SpeedValue;
            SpeedChange();
        }
        if (collision.gameObject.tag == "Wall")
        {
            Debug.Log("Hit Wall");
            levelControl.LoseLevel();
        }
        if (collision.gameObject.tag == "Trophy")
        {
            Debug.Log("GG");
            trophyCount++;
            Destroy(collision.gameObject);
            if (trophyCount < trophyReq)
            {
                Debug.Log(trophyCount);
            }
            else
            {
                levelControl.WinLevel();
            }
        }
        if (collision.gameObject.tag == "TeleBlock" && canTeleport == 0)
        {
            canTeleport += 2;
            TeleBlock teleBlock = collision.GetComponent <TeleBlock>();
            gameObject.transform.position = teleBlock.Teleport.position;
        }
        if (collision.gameObject.tag == "TriggerBlock")
        {
            TriggerBlock triggerBlock = collision.GetComponent <TriggerBlock>();
            for (int i = 0; i < triggerBlock.toMove.Length; i++)
            {
                if (triggerBlock.toMove[i].GetComponent <Wall>().Moving)
                {
                    triggerBlock.toMove[i].GetComponent <Wall>().Moving = false;
                }
                else
                {
                    triggerBlock.toMove[i].GetComponent <Wall>().Moving = true;
                }
            }
        }

        if (currentSpeed < startingSpeed)
        {
            currentSpeed = startingSpeed;
        }                                                                   //speed cap and minimim
        if (currentSpeed > maxSpeed)
        {
            currentSpeed = maxSpeed;
        }
    }