예제 #1
0
    public void Escape(BasicEnemy enemy)
    {
        BasicEntity entity = enemy.m_entity;
        VoxelBlocks map    = GameObject.Find("Voxel Map").GetComponent <VoxelBlocks> ();

        List <BasicEntity> enemyList = entity.GetComponent <MonitorComponent> ().m_enemy;

        if (AiToInput.CallFriend(entity, enemyList))
        {
            //呼叫成功
            StateComponent state = entity.GetComponent <StateComponent> ();

            state.AnimationStart();

            state.m_actionPoint -= 1;
            state.Invoke("AnimationEnd", 1);
            return;
        }

        Vector3 escapePos = FindPath.GetNearestFriend(entity.GetComponent <BlockInfoComponent> ().m_logicPosition);

        if (escapePos == Vector3.down)
        {
            //无路可走等死
            return;
        }
        else
        {
            AiToInput.Move(entity, escapePos);
        }
        return;
    }
예제 #2
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
            }
        }
    }
예제 #3
0
    public void Attack(BasicEntity entity)
    {
        VoxelBlocks map  = GameObject.Find("Voxel Map").transform.GetComponent <VoxelBlocks> ();
        Vector3     ePos = entity.GetComponent <BlockInfoComponent> ().m_logicPosition;

        Vector3 tPos = target.GetComponent <BlockInfoComponent> ().m_logicPosition;

        if ((Mathf.Abs(ePos.x - tPos.x) <= 1.5f) && (Mathf.Abs(ePos.y - tPos.y) <= 1.5f))
        {
            AiToInput.Attack(entity, tPos);
        }
        else
        {
            target.GetComponent <BlockInfoComponent> ().m_blockType = BlockType.None;
            List <Vector3> path = FindPath.GetPath(ePos, tPos);
            target.GetComponent <BlockInfoComponent> ().m_blockType = BlockType.Player;
            if (path != null)
            {
                path.Remove(tPos);
                tPos = path [path.Count - 1];
                AiToInput.Move(entity, tPos);
            }
            else
            {
                Debug.Log("Fail to Attack");
            }
        }
    }
    public void Survey(BasicEntity entity)
    {
        List <Vector3> voice    = entity.GetComponent <MonitorComponent> ().m_voice;
        Vector3        mPos     = entity.GetComponent <BlockInfoComponent> ().m_logicPosition;
        List <Vector3> newVoice = new List <Vector3> ();
        List <int>     i        = new List <int> ();

        for (int j = 0; j < voice.Count; j++)
        {
            Vector3 pos = voice [j];
            if (mPos != pos && FindPath.GetPathByStep(mPos, pos, 100) != Vector3.down)
            {
                newVoice.Add(pos);
            }
            else
            {
                i.Add(j);
            }
        }
        for (int j = 0; j < i.Count; j++)
        {
            voice.Remove(voice [i [j]]);
        }

        if (newVoice.Count != 0)
        {
            AiToInput.Move(entity, newVoice [newVoice.Count - 1]);
        }
    }
    public override void Execte(T enemyEntity)
    {
        Debug.Log("exec survey!");
        MonitorComponent  monitorComp  = (MonitorComponent)enemyEntity.m_entity.GetSpecicalComponent(ComponentType.Monitor);
        PropertyComponent propertyComp = (PropertyComponent)enemyEntity.m_entity.GetSpecicalComponent(ComponentType.Property);
        DeadComponent     deadComp     = (DeadComponent)enemyEntity.m_entity.GetSpecicalComponent(ComponentType.Dead);

        //发现敌人
        if (monitorComp.m_enemy.Count != 0)
        {
            //倾向攻击攻击
            if (deadComp.hp / propertyComp.HP > 0.2f)
            {
                enemyEntity.ChangeDecision(AIComponent.Decision.Attack);
                return;
            }
            else
            {
                //如果有同伴在旁边,那么就进行攻击
                if (AiToInput.ExistEnemy())
                {
                    enemyEntity.ChangeDecision(AIComponent.Decision.CallSupport);
                    return;
                }
            }
        }
        //如果还是听到声音
        if (monitorComp.m_voice.Count == 0)
        {
            //if (deadComp.hp / propertyComp.HP > 0.2f) {
            //float j = Random.value;
            //float surveyDemage = enemyEntity.m_events.DecisionExpectDemage (AIComponent.Decision.Survey);
            //float patrolDemage = enemyEntity.m_events.DecisionExpectDemage (AIComponent.Decision.Patrol);
            //Debug.Log ("surveyDemage" + surveyDemage + "patrolDemage" + patrolDemage);
            //if (j > surveyDemage / (surveyDemage + patrolDemage)) {
            //如果听到声音,生命充足,且根据历史,直接前去调查可以造成更多的伤害

            enemyEntity.ChangeDecision(AIComponent.Decision.Patrol);
            //		return;
            //	}
            //} else {
            //	float j = Random.value;
            //	float surveyInjure = enemyEntity.m_events.DecisionExpectInjure (AIComponent.Decision.Survey);
            //	float patrolInjeure = enemyEntity.m_events.DecisionExpectInjure (AIComponent.Decision.Patrol);
            //	if (j > patrolInjeure / (surveyInjure + patrolInjeure)) {
            //		//听到声音。生命不足,但是前去调查可以保存更多的生命
            //		enemyEntity.ChangeDecision (AIComponent.Decision.Patrol);
            //		return;
            //	}
            //}
        }

        Debug.Log("run survey!");
        //计算受伤
        enemyEntity.m_events.AddInjure(tmpHp - deadComp.hp);
        tmpHp = deadComp.hp;

        Survey(enemyEntity.m_entity);
        return;
    }
예제 #6
0
    public void CallSupport(BasicEnemy enemy)
    {
        BasicEntity entity = enemy.m_entity;

        List <BasicEntity> enemyList = entity.GetComponent <MonitorComponent> ().m_enemy;

        AiToInput.CallFriend(entity, enemyList);
    }
예제 #7
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);
            }
        }
    }
    public void Patrol(BasicEntity entity)
    {
        //寻找一个坐标进行来回移动
        AIComponent    ai    = entity.GetComponent <AIComponent> ();
        StateComponent state = entity.GetComponent <StateComponent> ();

        List <Vector3> path      = ai.m_patrolPoint;
        Vector3        entityPos = entity.GetComponent <BlockInfoComponent> ().m_logicPosition;

        if (path [0] == entityPos)
        {
            Vector3 t = path [0];
            path.Remove(t);
            path.Add(t);
        }
        AiToInput.Move(entity, path [0]);
    }
예제 #9
0
    public override void Execte(T enemyEntity)
    {
        MonitorComponent  monitorComp       = (MonitorComponent)enemyEntity.m_entity.GetSpecicalComponent(ComponentType.Monitor);
        DeadComponent     deadComp          = (DeadComponent)enemyEntity.m_entity.GetSpecicalComponent(ComponentType.Dead);
        PropertyComponent propertyComponent = (PropertyComponent)enemyEntity.m_entity.GetSpecicalComponent(ComponentType.Property);

        //如果没有敌人
        if (monitorComp.m_enemy.Count == 0)
        {
            enemyEntity.ChangeDecision(AIComponent.Decision.Patrol);
            return;
        }
        else
        {
            //如果遇到了敌人,且敌人的距离足够近
            double threat = FuzzyLogic.DistanceThreat(CalculateDistance(enemyEntity.m_entity), propertyComponent.HP);

            if (threat > 0.4f)
            {
                enemyEntity.ChangeDecision(AIComponent.Decision.Attack);
                return;
            }
        }

        //当队友出现在视野里
        if (AiToInput.FriendInSight(enemyEntity.m_entity))
        {
            enemyEntity.ChangeDecision(AIComponent.Decision.CallSupport);
            return;
        }

        //计算受伤
        enemyEntity.m_events.AddInjure(tmpHp - deadComp.hp);
        tmpHp = deadComp.hp;

        Escape(enemyEntity);
        return;
    }
예제 #10
0
    public override void Execute(List <BasicEntity> entities)
    {
        foreach (BasicEntity entity in entities)
        {
            AbilityComponent ab    = entity.GetComponent <AbilityComponent>();
            InputComponent   input = entity.GetComponent <InputComponent>();
            StateComponent   ap    = entity.GetComponent <StateComponent>();
            CheerUpComponent cu    = entity.GetComponent <CheerUpComponent>();

            int i = AiToInput.GetAbilityCount(entity, M_LinkedType);
            if (i >= ab.m_temporaryAbility.Count || i != input.currentKey)
            {
                continue;
            }
            ap.AnimationStart();

            ap.m_actionPoint += cu.m_addAp;
            if (!ab.m_coldDown.ContainsKey(M_LinkedType))
            {
                ab.m_coldDown.Add(M_LinkedType, cu.m_coldDown);
            }
            ap.Invoke("AnimationEnd", 1);
        }
    }
예제 #11
0
    public override void Execte(T enemyEntity)
    {
        Debug.Log("exec attack!");
        MonitorComponent  monitorComp  = (MonitorComponent)enemyEntity.m_entity.GetSpecicalComponent(ComponentType.Monitor);
        PropertyComponent propertyComp = (PropertyComponent)enemyEntity.m_entity.GetSpecicalComponent(ComponentType.Property);
        DeadComponent     deadComp     = (DeadComponent)enemyEntity.m_entity.GetSpecicalComponent(ComponentType.Dead);

        //生命值不足,且上一个动作不是呼叫朋友
        if (deadComp.hp < 0.1f * propertyComp.HP && enemyEntity.m_events.CurrentDecision() != AIComponent.Decision.CallSupport)
        {
            //同时有朋友存在
            if (AiToInput.ExistEnemy())
            {
                enemyEntity.ChangeDecision(AIComponent.Decision.CallSupport);
                return;
            }
        }

        //如果敌人已经死亡
        if (target == null || target.m_components.Count == 0)
        {
            //如果附近还有敌人
            if (monitorComp.m_enemy.Count != 0)
            {
                target = monitorComp.m_enemy [0];
            }

            if (monitorComp.m_enemy.Count != 0)
            {
                if (deadComp.hp / propertyComp.HP > 0.3f)
                {
                    // 如果有玩家,且敌人的生命值较高的话,切换对象攻击,切换对象会在enter时进行
                    enemyEntity.ChangeDecision(AIComponent.Decision.Attack);
                    return;
                }
                else
                {
                    //有玩家,但是生命值不高,可以逃跑

                    if (AiToInput.ExistEnemy() && enemyEntity.m_events.CurrentDecision() != AIComponent.Decision.CallSupport)
                    {
                        enemyEntity.ChangeDecision(AIComponent.Decision.CallSupport);
                        return;
                    }
                }
            }

            if (monitorComp.m_voice.Count != 0)
            {
                //float i = Random.value;

                //double degreeAttack = FuzzyLogic.AttackBelong (deadComp.hp, propertyComp.HP);
                //double degreeProtect = FuzzyLogic.ProtectBelong (deadComp.hp, propertyComp.HP);

                if (deadComp.hp / propertyComp.HP > 0.2f)
                {
                    //听到声音,生命充足
                    //float j = Random.value;
                    //float surveyDemage = enemyEntity.m_events.DecisionExpectDemage (AIComponent.Decision.Survey);
                    //float patrolDemage = enemyEntity.m_events.DecisionExpectDemage (AIComponent.Decision.Patrol);
                    //Debug.Log ("surveyDemage" + surveyDemage + "patrolDemage" + patrolDemage);
                    //根据历史计算哪种行动造成的伤害更多
                    //if (j >0.3f) {
                    enemyEntity.ChangeDecision(AIComponent.Decision.Survey);
                    return;
                    //} else {
                    //enemyEntity.ChangeDecision (AIComponent.Decision.Patrol);
                    //return;
                    //}
                }
                else
                {
                    //float j = Random.value;
                    //float surveyInjure = enemyEntity.m_events.DecisionExpectInjure (AIComponent.Decision.Survey);
                    //float patrolInjeure = enemyEntity.m_events.DecisionExpectInjure (AIComponent.Decision.Patrol);
                    //if (j > 0.3f) {
                    if (AiToInput.ExistEnemy() && enemyEntity.m_events.CurrentDecision() != AIComponent.Decision.CallSupport)
                    {
                        enemyEntity.ChangeDecision(AIComponent.Decision.CallSupport);
                        return;
                    }

                    //} else {
                    //enemyEntity.ChangeDecision (AIComponent.Decision.Patrol);
                    //return;
                    //}
                }
            }

            //敌人死亡且旁边没有敌人,返回巡逻
            enemyEntity.ChangeDecision(AIComponent.Decision.Patrol);
            return;
        }
        Debug.Log("run attack!");
        //计算受伤
        DeadComponent targetDeadComp = (DeadComponent)target.GetSpecicalComponent(ComponentType.Dead);

        enemyEntity.m_events.AddInjure(tmpHp - deadComp.hp);
        enemyEntity.m_events.AddDemage(tmpTargetHp - targetDeadComp.hp);
        tmpHp       = deadComp.hp;
        tmpTargetHp = targetDeadComp.hp;
        Attack(enemyEntity.m_entity);
        return;
    }
예제 #12
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;
                        }
                    }
                }
            }
        }
    }