Beispiel #1
0
        //自动搓招
        private void AutoUseSkill(BattleUnitAction battleUnitAction, BattleBehaviourSystem.BattleDecision decision)
        {
            if (decision == null)
            {
                return;
            }

            if (decision.battleSkill != null)
            {
                //使用技能
                switch (decision.battleSkill.targetType)
                {
                case BattleSkillTargetType.BattleUnit:
                    UseSkill(battleUnitAction, decision.battleSkill, decision.skillTargetBattleUnit);
                    break;

                case BattleSkillTargetType.GridUnit:
                    UseSkill(battleUnitAction, decision.battleSkill, null, decision.skillTargetGrid);
                    break;

                case BattleSkillTargetType.Self:
                    UseSkill(battleUnitAction, decision.battleSkill);
                    break;

                default:
                    break;
                }
            }
        }
Beispiel #2
0
        //自动
        private HeroActionState AutoAction()
        {
            BattleBehaviourSystem.BattleDecision decision = battleBehaviourSystem.Think();

            if (decision == null)
            {
                BattleUnitWarningAction warningAction = BattleUnitActionEvent.CreateEvent <BattleUnitWarningAction>(BattleUnitActionType.Warning, this);
                battleField.AppendBattleAction(warningAction);
                warningAction.warningLog = "No target:" + ID;
                return(HeroActionState.Normal);
            }

            //判断是否切换目标
            if (decision.targetBattleUnit != null && !decision.targetBattleUnit.Equals(targetBattleUnit))
            {
                BattleUnitChangeTargetAction action = BattleUnitActionEvent.CreateEvent <BattleUnitChangeTargetAction>(BattleUnitActionType.ChangeTarget, this);
                action.lastTargetUnit = targetBattleUnit;
                action.newTargetUnit  = decision.targetBattleUnit;
                battleField.AppendBattleAction(action);

                targetBattleUnit = decision.targetBattleUnit;
            }

            //需要移动
            if (decision.movePath != null && decision.movePath.Length > 0)
            {
                MoveToTargetGrid(targetBattleUnit, decision.movePath[decision.movePath.Length - 1], decision.movePath);
            }

            //自动搓招儿
            AutoUseSkill(decision);

            return(HeroActionState.Normal);
        }
Beispiel #3
0
        //自动
        private HeroActionState AutoAction(BattleUnitAction battleUnitAction)
        {
            BattleBehaviourSystem.BattleDecision decision = battleBehaviourSystem.Think();

            if (decision == null)
            {
                battleUnitAction.warningAction            = BattleUnitWarningAction.Get();
                battleUnitAction.warningAction.logWarning = "No target:" + ID;
                return(HeroActionState.Normal);
            }

            //判断是否切换目标
            if (decision.targetBattleUnit != null && !decision.targetBattleUnit.Equals(targetBattleUnit))
            {
                battleUnitAction.changeTargetAction = BattleUnitChangeTargetAction.Get();
                battleUnitAction.changeTargetAction.lastTargetUnit = targetBattleUnit;
                battleUnitAction.changeTargetAction.newTargetUnit  = decision.targetBattleUnit;
                targetBattleUnit = decision.targetBattleUnit;
            }

            //需要移动
            if (decision.movePath != null && decision.movePath.Length > 0)
            {
                MoveToTargetGrid(battleUnitAction, targetBattleUnit, decision.movePath[decision.movePath.Length - 1], decision.movePath);
            }

            //自动搓招儿
            AutoUseSkill(battleUnitAction, decision);

            return(HeroActionState.Normal);
        }
        //得出决策
        private BattleDecision MakeDecision()
        {
            var skills = baseData.hostBattleUnit.battleUnitAttribute.battleSkills;

            if (skills.Length == 0)
            {
                return(null);
            }

            //遍历每一个行为
            //尝试可释放的每一个技能
            //计算释放这个技能的得分
            //找到最高回报的技能和释放目标
            BattleUnit      target        = null;
            List <GridUnit> movePath      = new List <GridUnit>();
            int             currentPoints = 0; //当前得分
            int             highestPoints = 0; //最高分
            BattleDecision  decision      = null;

            //遍历行为列表
            for (int i = 0; i < behaviourItems.Count; ++i)
            {
                //这个行为的目标对象
                target = behaviourItems[i].targetBattleUnit;
                //遍历技能列表
                for (int j = 0; j < skills.Length; j++)
                {
                    switch (behaviourItems[i].behaviourType)
                    {
                    //如果是伤害或嘲讽行为,则直接忽略治疗技能
                    case BattleBehaviourType.Damage:
                    case BattleBehaviourType.Provoke:
                    {
                        if (skills[j].damageType == BattleSkillDamageType.Heal)
                        {
                            continue;
                        }
                    }
                    break;

                    //如果是治疗行为,则直接忽略伤害技能
                    case BattleBehaviourType.Recovery:
                        if (skills[j].damageType != BattleSkillDamageType.Heal)
                        {
                            continue;
                        }
                        break;

                    default:
                        break;
                    }

                    movePath.Clear();
                    //判断当前目标是否在范围内
                    if (target.mapGrid.Distance(baseData.hostBattleUnit.mapGrid) > skills[j].MaxReleaseRadiusForCalculate)
                    {
                        //不在范围内
                        //判断是否可达
                        bool canCatch = MapNavigator.Instance.Navigate(
                            baseData.battleField.battleMap,
                            baseData.hostBattleUnit.mapGrid,
                            target.mapGrid,
                            movePath,
                            null,
                            baseData.hostBattleUnit.battleUnitAttribute.mobility,
                            skills[j].MaxReleaseRadiusForCalculate
                            );

                        //别考虑这个技能了~
                        if (!canCatch)
                        {
                            continue;
                        }
                    }

                    //到此表示可以释放这个技能是有戏的呢
                    currentPoints = 10;

                    //假定一下移动后的位置
                    GridUnit virtualPosition = movePath.Count > 0 ? movePath[movePath.Count - 1] : baseData.hostBattleUnit.mapGrid;
                    if (target.mapGrid.Distance(virtualPosition) > skills[j].MaxReleaseRadiusForCalculate)
                    {
                        //移动后仍然不在范围内
                        if (currentPoints > highestPoints)
                        {
                            if (decision == null)
                            {
                                decision = BattleDecision.CreateInstance();
                            }

                            decision.Reset();
                            decision.targetBattleUnit = target;
                            decision.movePath         = movePath.Count > 0 ? movePath.ToArray() : null;
                            //目标不在范围,因此无需保存技能
                            decision.battleSkill           = null;
                            decision.skillTargetGrid       = null;
                            decision.skillTargetBattleUnit = null;


                            //记录最高分
                            highestPoints = currentPoints;
                        }
                    }
                    else
                    {
                        //移动后在范围内
                        //计算释放技能的得分
                        var analysisItem = CalculateSkillScore(
                            baseData.hostBattleUnit,
                            virtualPosition,
                            target,
                            skills[j],
                            behaviourItems[i].behaviourType);

                        if (analysisItem == null)
                        {
                            continue;
                        }

                        currentPoints += Mathf.CeilToInt(analysisItem.score);

                        if (currentPoints > highestPoints)
                        {
                            if (decision == null)
                            {
                                decision = BattleDecision.CreateInstance();
                            }

                            decision.Reset();
                            decision.targetBattleUnit      = target;
                            decision.movePath              = movePath.Count > 0 ? movePath.ToArray() : null;
                            decision.battleSkill           = skills[j];
                            decision.skillTargetGrid       = analysisItem.targetGridUnit;
                            decision.skillTargetBattleUnit = analysisItem.targetBattleUnit;

#if UNITY_EDITOR
                            if (DebugHelper.Instance.debugBBSys)
                            {
                                Debug.Log(string.Format("Decision:\nTarget:{0}\nSkill:{1}\nSTargetUnit:{2}\nSGridUnit:{3}\n",
                                                        decision.targetBattleUnit.battleUnitAttribute.battleUnitName,
                                                        decision.battleSkill.skillName,
                                                        decision.skillTargetBattleUnit == null ? "None" : decision.skillTargetBattleUnit.battleUnitAttribute.battleUnitName,
                                                        decision.skillTargetGrid == null ? "None" : decision.skillTargetGrid.ToString()
                                                        ));
                            }
#endif

                            //记录最高分
                            highestPoints = currentPoints;
                        }
                    }
                }
                //有一个可行决策
                if (decision != null)
                {
                    break;
                }
            }

            return(decision);
        }