Esempio n. 1
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);
        }
    }
Esempio n. 2
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);
            }
        }
    }
Esempio n. 3
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);
            }
        }
    }