Exemplo n.º 1
0
        //自动搓招
        private void AutoUseSkill(BattleUnitAction battleUnitAction)
        {
            //计算每个技能对目标单位的使用得分
            BattleCalculator.Instance.AutoReleaseAnalysisor.Ananlysis(this, targetBattleUnit, battleUnitAttribute.battleSkills);
            //获取得分最高的技能
            BattleSkillAutoReleaseAnalysisItem analysisResult = BattleCalculator.Instance.AutoReleaseAnalysisor.GetResult();

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

                case BattleSkillTargetType.GridUnit:
                    UseSkill(battleUnitAction, analysisResult.battleSkill, null, analysisResult.targetGridUnit);
                    break;

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

                default:
                    break;
                }
            }
            //重置分析器
            BattleCalculator.Instance.AutoReleaseAnalysisor.Reset();
        }
        //分析结果
        public void Ananlysis(BattleUnit releaser, BattleUnit target, SO_BattleSkill[] skills)
        {
            Reset();

            if (releaser == null || target == null || skills == null)
            {
                return;
            }

            this.releaser = releaser;
            this.target   = target;

            //有效技能数
            int validSkillCount = 0;

            for (int i = 0; i < skills.Length; ++i)
            {
                //判断能量是否够
                if (skills[i].energyCost > releaser.battleUnitAttribute.energy)
                {
                    continue;
                }

                //技能都不在释放范围内,考虑你妹啊
                if (!WithInSkillReleaseRange(releaser, target, skills[i]))
                {
                    continue;
                }

                //释放这个技能的主要影响目标和次要影响目标
                BattleSkillEffectAnalysis effectAnalysis = null;
                //捎带手保存一下释放技能的地点
                GridUnit targetGridUnit = null;

                switch (skills[i].targetType)
                {
                //对目标单位
                case BattleSkillTargetType.BattleUnit:
                    effectAnalysis = BattleCalculator.Instance.AnalyseBattleSkillEffect(
                        skills[i],
                        releaser,
                        target);
                    break;

                case BattleSkillTargetType.Self:
                    effectAnalysis = BattleCalculator.Instance.AnalyseBattleSkillEffect(
                        skills[i],
                        releaser);
                    break;

                case BattleSkillTargetType.GridUnit:
                    analysisTempGrids.Clear();
                    //如果目标在范围内
                    if (skills[i].releaseRadius > 0 && releaser.mapGrid.Distance(target.mapGrid) <= skills[i].releaseRadius)
                    {
                        effectAnalysis = BattleCalculator.Instance.AnalyseBattleSkillEffect(
                            skills[i],
                            releaser,
                            null,
                            target.mapGrid);

                        //以地块为目标的技能,保存一下目标地块
                        targetGridUnit = target.mapGrid;
                    }
                    //自身为中心
                    else if (skills[i].releaseRadius <= 0 && releaser.mapGrid.Distance(target.mapGrid) <= skills[i].effectRadius)
                    {
                        effectAnalysis = BattleCalculator.Instance.AnalyseBattleSkillEffect(
                            skills[i],
                            releaser,
                            null,
                            releaser.mapGrid);

                        //以地块为目标的技能,保存一下目标地块
                        targetGridUnit = releaser.mapGrid;
                    }
                    else
                    {
                        //这个最麻烦,对某个位置
                        target.battleField.battleMap.GetCircularGrids(
                            releaser.mapGrid.row, releaser.mapGrid.column,
                            skills[i].releaseRadius, 0, true,
                            analysisTempGrids,
                            delegate(GridUnit grid)
                        {
                            return(grid.Distance(target.mapGrid) <= skills[i].effectRadius);
                        }
                            );
                        //如果有可以使用技能的位置
                        if (analysisTempGrids.Count > 0)
                        {
                            targetGridUnit = analysisTempGrids[Random.Range(0, analysisTempGrids.Count)];
                            //随机一个位置作为释放目标点
                            effectAnalysis = BattleCalculator.Instance.AnalyseBattleSkillEffect(
                                skills[i],
                                releaser,
                                null,
                                targetGridUnit);

                            analysisTempGrids.Clear();
                        }
                    }
                    break;
                }

                //没有分析结果或者技能释放也不会有效果
                if (effectAnalysis == null ||
                    (effectAnalysis.mainReceiver.Count == 0 && effectAnalysis.minorReceiver.Count == 0))
                {
                    continue;
                }

                //起码可以释放
                ++validSkillCount;
                //计算释放这个技能的得分
                BattleSkillAutoReleaseAnalysisItem analysisItem = skillReleaseAnalysisItem.Get();
                analysisItem.battleSkill      = skills[i];
                analysisItem.targetBattleUnit = target;
                analysisItem.targetGridUnit   = targetGridUnit;

                //主要影响
                for (int j = 0; j < effectAnalysis.mainReceiver.Count; ++j)
                {
                    analysisItem.score += analysisItem.battleSkill.mainValue;
                    ++analysisItem.effectedCount;
                }

                //次要影响
                for (int j = 0; j < effectAnalysis.minorReceiver.Count; ++j)
                {
                    analysisItem.score += analysisItem.battleSkill.mainValue;
                    ++analysisItem.effectedCount;
                }

                analysisItem.score = Mathf.CeilToInt(1000 * analysisItem.score / analysisItem.battleSkill.energyCost);
            }

            //排序
            skillReleaseAnalysisItem.Sort(LiteSingleton <BattleSkillReleaseAnalysisItemComparer> .Instance);
        }