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;
    }
Exemple #2
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;
    }