Exemplo n.º 1
0
    //每帧都会调用对应的实体
    public override void Execute(List <BasicEntity> entities)
    {
        foreach (BasicEntity e in entities)
        {
            AttackComponent  attack = e.GetComponent <AttackComponent> ();
            VoxelBlocks      map    = GameObject.Find("Voxel Map").transform.GetComponent <VoxelBlocks> ();
            AbilityComponent ab     = e.GetComponent <AbilityComponent> ();
            InputComponent   input  = e.GetComponent <InputComponent> ();
            StateComponent   ap     = e.GetComponent <StateComponent> ();

            int i = AiToInput.GetAbilityCount(e, M_LinkedType);
            //检测是否按下攻击键

            if (i >= ab.m_temporaryAbility.Count || i != input.currentKey)
            {
                continue;
            }

            //若无攻击对象则获取周围可攻击对象
            if (attack.enemy == null)
            {
                attack.enemy = GetEnemyAround(e);
                if (attack.enemy == null)
                {
                    return;
                }
            }
            List <Vector3> el = new List <Vector3> ();
            foreach (var enemy in attack.enemy)
            {
                el.Add(enemy.GetComponent <BlockInfoComponent> ().m_logicPosition);
            }
            UISimple ui = GameObject.Find("UI").GetComponent <UISimple> ();
            ui.ShowUI(el, 2);

            //左键攻击
            if (input.leftButtonDown)
            {
                BasicEntity enemy = map.GetBlockByLogicPos(input.currentPos).entity;

                //检测当前选中敌人是否处于攻击范围内
                List <BasicEntity> list = GetEnemyAround(e);
                if (list != null && !list.Contains(enemy))
                {
                    attack.enemy = list;
                    return;
                }
                //扣除敌人HP值
                DeadComponent  dead  = enemy.GetComponent <DeadComponent> ();
                StateComponent state = e.GetComponent <StateComponent> ();
                dead.hp             -= attack.STR;
                state.m_actionPoint -= 1;
                state.Invoke("AnimationEnd", 1);
                state.AnimationStart();
                //播放攻击动画
                //播放敌人受击动画
                //减少AP
            }
        }
    }
Exemplo n.º 2
0
    void Bomb(BasicEntity entity, float mr, float ridus, int demage)
    {
        InputComponent input = entity.GetComponent <InputComponent>();
        VoxelBlocks    map   = GameObject.Find("Voxel Map").GetComponent <VoxelBlocks>();

        //获取鼠标位置与角色位置的距离
        float r = (input.currentPos - entity.GetComponent <BlockInfoComponent>().m_logicPosition).magnitude;

        //若距离大于预设值则退出
        if (r > mr)
        {
            return;
        }
        //获取炸弹投掷后可能影响的范围
        List <Vector3> ar = FindPath.GetArea(input.currentPos, Mathf.FloorToInt(ridus));
        //显示炸弹影响范围
        List <DeadComponent> mc = new List <DeadComponent>();

        UISimple ui = GameObject.Find("UI").GetComponent <UISimple>();

        ui.ShowUI(ar, 3);

        //获取该范围内所有的敌人的生命脚本
        foreach (var pos in ar)
        {
            BlockInfo block = map.GetBlockByLogicPos(pos);
            if (block != null && block.entity != null)
            {
                if (block.entity.GetComponent <BlockInfoComponent>().m_blockType == BlockType.Enemy)
                {
                    mc.Add(block.entity.GetComponent <DeadComponent>());
                }
            }
        }
        //显示可被影响的敌人

        //若按下鼠标左键则扔出炸弹,影响周围敌人。
        if (input.leftButtonDown)
        {
            Debug.Log(mc.Count);
            foreach (var m in mc)
            {
                if (m != null)
                {
                    m.hp -= demage;
                }
            }
            ItemComponent itemComp = entity.GetComponent <ItemComponent>();
            //移除炸弹
            itemComp.item.Remove(ItemType.Bomb);
            entity.GetComponent <ItemComponent>().current = ItemType.Null;
            //使用一次消耗一点行动点
            StateComponent state = entity.GetComponent <StateComponent>();
            state.m_actionPoint -= 1;
            state.AnimationStart();

            state.Invoke("AnimationEnd", 1);
        }
    }
Exemplo n.º 3
0
    public override void Execute(List <BasicEntity> entities)
    {
        foreach (var entity in entities)
        {
            KnockComponent   knock = entity.gameObject.GetComponent <KnockComponent>();
            AbilityComponent ab    = entity.GetComponent <AbilityComponent>();
            InputComponent   input = entity.GetComponent <InputComponent>();
            StateComponent   ap    = entity.GetComponent <StateComponent>();

            int i = AiToInput.GetAbilityCount(entity, M_LinkedType);
            if (i >= ab.m_temporaryAbility.Count || i != input.currentKey)
            {
                knock.m_area = null;
                continue;
            }
            //获取影响范围
            if (knock.m_area == null)
            {
                knock.m_area = FindPath.GetArea(knock.GetComponent <BlockInfoComponent>().m_logicPosition, knock.m_ridus);
            }
            UISimple ui = GameObject.Find("UI").GetComponent <UISimple>();
            ui.ShowUI(knock.m_area, 3);
            VoxelBlocks        map   = GameObject.Find("Voxel Map").GetComponent <VoxelBlocks>();
            List <BasicEntity> enemy = new List <BasicEntity>();


            //获取影响范围内的敌人
            foreach (var pos in knock.m_area)
            {
                var e = map.GetBlockByLogicPos(pos).entity;
                if (e != null)
                {
                    if (e.GetComponent <BlockInfoComponent>().m_blockType == BlockType.Enemy)
                    {
                        enemy.Add(e);
                    }
                }
            }
            //UI显示范围与敌人
            if (input.leftButtonDown)
            {
                foreach (var e in enemy)
                {
                    Debug.Log(e.name);
                    e.GetComponent <MonitorComponent>().m_voice.Add(entity.GetComponent <BlockInfoComponent>().m_logicPosition);
                }
                ui.ShowUI(null, 3);
                StateComponent state = entity.GetComponent <StateComponent>();
                state.m_actionPoint -= 1;
                state.AnimationStart();

                state.Invoke("AnimationEnd", 1);
            }
        }
    }
Exemplo n.º 4
0
    private void Update()
    {
        UISimple   ui    = null;
        GameObject uiObj = GameObject.Find("UI");

        if (ui = uiObj.GetComponent <UISimple>())
        {
            ui.CloseUI();
        }
        foreach (BasicSystem basicSystem in basicSystems)
        {
            //Debug.Log ("Update " + basicSystem.M_LinkedType + " System");
            List <BasicEntity> entities = basicSystem.Fliter(basicSystem.M_LinkedType);
            if (entities != null)
            {
                //Debug.Log ("execute system:" + basicSystem.M_LinkedType + "system");
                basicSystem.Execute(entities);
            }
        }

        //回合制
    }
Exemplo n.º 5
0
    public override void Execute(List <BasicEntity> entities)
    {
        foreach (var e in entities)
        {
            MonitorComponent monitor = e.GetComponent <MonitorComponent>();
            if (monitor == null)
            {
                return;
            }
            //若监视范围为空或者实体进行移动,重置监控范围
            List <BasicEntity> oldEnemy = monitor.m_enemy;
            monitor.m_enemy = new List <BasicEntity>();
            UISimple ui = GameObject.Find("UI").GetComponent <UISimple>();

            VoxelBlocks map = GameObject.Find("Voxel Map").GetComponent <VoxelBlocks>();

            if (monitor.m_view == null || monitor.m_view.Contains(e.GetComponent <BlockInfoComponent>().m_logicPosition))
            {
                List <Vector3> list = FindPath.GetArea(e.GetComponent <BlockInfoComponent>().m_logicPosition, monitor.m_SightArea);
                //获取自身位置
                Vector3 s = e.GetComponent <BlockInfoComponent>().m_logicPosition;
                //初始化视野列表
                monitor.m_view = new List <Vector3>();
                //获取所有能看到的点
                foreach (var pos in list)
                {
                    if (InView(pos, s))
                    {
                        //添加视野点并判断是否为玩家
                        monitor.m_view.Add(pos);
                        BasicEntity entity = map.GetBlockByLogicPos(pos).entity;
                        //判断是否为玩家
                        if (entity != null)
                        {
                            if (entity.GetComponent <BlockInfoComponent>().m_blockType == BlockType.Player && !monitor.m_enemy.Contains(entity))
                            {
                                //添加到敌人列表里
                                monitor.m_enemy.Add(entity);
                            }
                        }
                    }
                }
                //判断视野里是否出现新的敌人
                foreach (BasicEntity enemy in monitor.m_enemy)
                {
                    if (!oldEnemy.Contains(enemy))
                    {
                        monitor.GetComponent <StateComponent>().FindEnemy();
                        break;
                    }
                }
                //ui.ShowWornArea(e);
            }
            else
            {
                //查找所有在视野里的玩家
                foreach (var pos in monitor.m_view)
                {
                    BasicEntity entity = map.GetBlockByLogicPos(pos).entity;
                    //判断是否为玩家
                    if (entity != null)
                    {
                        if (entity.GetComponent <BlockInfoComponent>().m_blockType == BlockType.Player && !monitor.m_enemy.Contains(entity))
                        {
                            //添加到敌人列表里
                            monitor.m_enemy.Add(entity);
                        }
                    }
                }
            }
            foreach (var enemy in oldEnemy)
            {
                if (monitor.m_enemy.Contains(enemy))
                {
                    continue;
                }
                monitor.m_voice.Add(enemy.GetComponent <BlockInfoComponent>().m_logicPosition);
            }
        }
    }
Exemplo n.º 6
0
    public override void Execute(List <BasicEntity> entities)
    {
        foreach (var entity in entities)
        {
            MoveComponent    move      = entity.gameObject.GetComponent <MoveComponent> ();
            AbilityComponent ab        = entity.GetComponent <AbilityComponent> ();
            InputComponent   input     = entity.GetComponent <InputComponent> ();
            StateComponent   ap        = entity.GetComponent <StateComponent> ();
            BlockType        blockType = entity.GetComponent <BlockInfoComponent>().m_blockType;

            int i = AiToInput.GetAbilityCount(entity, M_LinkedType);
            if (i >= ab.m_temporaryAbility.Count || i != input.currentKey)
            {
                continue;
            }
            UISimple ui = GameObject.Find("UI").GetComponent <UISimple>();

            VoxelBlocks map = GameObject.Find("Voxel Map").transform.GetComponent <VoxelBlocks> ();

            if (move.pathList == null)
            {
                move.pathList = new List <Vector3> ();
                move.pathList.Add(entity.GetComponent <BlockInfoComponent> ().m_logicPosition);
            }
            if (move.path == null)
            {
                move.path = FindPath.FindPathInStep(move.pathList [move.pathList.Count - 1], ap.m_actionPoint * move.SPD - move.pathList.Count + 1);
            }
            List <Vector3> a = move.path;
            if (blockType != BlockType.Enemy)
            {
                ui.ShowUI(a, 3);
            }
            if (input.currentPos != null)
            {
                if (a.Count == 0 && input.leftButtonDown)
                {
                    SetPath(move);
                    move.pathList        = null;
                    move.path            = null;
                    input.leftButtonDown = false;
                    return;
                }
                foreach (var bi in a)
                {
                    //判断鼠标停靠位置是否位于可移动范围之内
                    if (bi == input.currentPos)
                    {
                        List <Vector3> path = new List <Vector3> ();
                        path.AddRange(move.pathList);
                        List <Vector3> newPath = FindPath.GetPath(move.pathList [move.pathList.Count - 1], input.currentPos);
                        if (newPath != null)
                        {
                            path.AddRange(newPath);
                        }
                        //调用UI显示路径
                        if (blockType != BlockType.Enemy)
                        {
                            ui.ShowUI(path, 2);
                        }
                        if (input.midButtonDown)
                        {
                            move.pathList = path;
                            move.path     = null;
                        }

                        if (input.rightButtonDown)
                        {
                            move.pathList.Clear();
                            move.path = null;
                        }

                        if (input.leftButtonDown && ap.m_actionPoint != 0)
                        {
                            move.pathList = path;

                            SetPath(move);
                            move.GetComponent <StateComponent>().AnimationStart();

                            move.pathList        = null;
                            move.path            = null;
                            input.leftButtonDown = false;
                            return;
                        }
                    }
                }
            }
        }
    }