예제 #1
0
        //点击了技能按钮
        private void OnClickedSkillItem()
        {
            //获取当前点击对象
            string btnName  = EventSystem.current.currentSelectedGameObject.name;
            int    skillIdx = -1;

            if (int.TryParse(btnName.Replace(EGameConstL.STR_SkillBtn, string.Empty), out skillIdx))
            {
                SO_BattleSkill skill = battleUnit.battleUnitAttribute.battleSkills[skillIdx];
                if (skill != null)
                {
                    if (battleUnit.battleUnitAttribute.energy >= skill.energyCost && BattleFieldRenderer.Instance != null)
                    {
                        BattleFieldRenderer.Instance.BattleUnitUseSkill(battleUnit, skill);
                    }
                    else
                    {
                        UtilityHelper.LogWarning(string.Format("能量不足:{0}/{1}", battleUnit.battleUnitAttribute.energy, skill.energyCost));
                    }
                }
                else
                {
                    UtilityHelper.LogError("Skill item error ->" + btnName);
                }
            }
            else
            {
                UtilityHelper.LogError("Skill item name error ->" + btnName);
            }
        }
예제 #2
0
        public BattleHeroSkillResult CalcSingle(BattleUnit from, BattleUnit to, SO_BattleSkill battleSkill)
        {
            BattleHeroSkillResult result = new BattleHeroSkillResult();

            result.battleUnit    = to;
            result.battleSkill   = battleSkill;
            result.syncAttribute = new BattleHeroSyncAttribute();
            //简单计算生命值
            switch (battleSkill.damageType)
            {
            case BattleSkillDamageType.Physical:
            case BattleSkillDamageType.Magic:
                result.syncAttribute.hpChanged = -battleSkill.mainValue;
                break;

            case BattleSkillDamageType.Heal:
                result.syncAttribute.hpChanged = Mathf.Min(battleSkill.mainValue, to.maxHp - to.hp);
                break;

            default:
                break;
            }
            //hp变化
            to.hp += result.syncAttribute.hpChanged;
            to.hp  = Mathf.Clamp(to.hp, 0, to.maxHp);
            //记录变化
            result.syncAttribute.currentHP = to.hp;
            return(result);
        }
예제 #3
0
        //点击了技能按钮
        private void OnClickedSkillItem()
        {
            //获取当前点击对象
            string btnName  = EventSystem.current.currentSelectedGameObject.name;
            int    skillIdx = -1;

            if (int.TryParse(btnName.Replace(EGameConstL.STR_SkillBtn, string.Empty), out skillIdx))
            {
                SO_BattleSkill skill = battleUnit.battleUnitRenderer.battleSkills[skillIdx];
                if (skill != null)
                {
                    if (BattleFieldRenderer.Instance)
                    {
                        BattleFieldRenderer.Instance.BattleUnitUseSkill(battleUnit, skill);
                    }
                }
                else
                {
                    UtilityHelper.LogError("Skill item error ->" + btnName);
                }
            }
            else
            {
                UtilityHelper.LogError("Skill item name error ->" + btnName);
            }
        }
        public int effectedCount;           //这个技能可以影响的人数

        public void Recycle()
        {
            battleSkill      = null;
            targetBattleUnit = null;
            targetGridUnit   = null;
            score            = 0;
            effectedCount    = 0;
        }
예제 #5
0
        public List <BattleUnit> minorReceiver = new List <BattleUnit>(5);  //次要影响

        public void Reset()
        {
            battleSkill = null;
            mainReceiver.Clear();
            minorReceiver.Clear();

            //UtilityHelper.Log("Battle Skill Effect Analysis Reset.", LogColor.BLUE);
        }
        //判断目标是否在某个技能范围内
        private bool WithInSkillReleaseRange(BattleUnit releaser, BattleUnit target, SO_BattleSkill skill)
        {
            if (skill == null || releaser == null || target == null)
            {
                return(false);
            }

            return(releaser.mapGrid.Distance(target.mapGrid) <= skill.MaxReleaseRadiusForCalculate);
        }
예제 #7
0
        /// <summary>
        /// 技能结果推测,用于战斗推算或界面展示
        /// </summary>
        /// <returns></returns>
        public BattleSkillAnalysis AnalyseBattleSkill(BattleUnit battleUnit, SO_BattleSkill battleSkill)
        {
            //分析啦~
            if (battleSkillAnalyses.Analysis(battleUnit, battleSkill))
            {
                return(battleSkillAnalyses);
            }

            return(null);
        }
예제 #8
0
        //重置
        public void Reset()
        {
            releaser    = null;
            battleSkill = null;

            suitableUnits.Clear();
            teamLimit.Clear();
            distanceLimit.Clear();
            battleUnitInvalid.Clear();

            valid = false;
        }
        //重置
        public void Reset()
        {
            releaser    = null;
            battleSkill = null;

            suitableUnits.Clear();
            teamLimit.Clear();
            distanceLimit.Clear();
            battleUnitInvalid.Clear();

            //UtilityHelper.Log("Battle Skill Manual Release Analysisor Reset.", LogColor.BLUE);
        }
예제 #10
0
        //使用技能
        public void UseSkill(BattleUnitAction battleUnitAction, SO_BattleSkill battleSkill, BattleUnit targetBattleUnit = null, GridUnit targetGridUnit = null)
        {
            if (battleSkill == null)
            {
                UtilityHelper.LogError("Use skill error. Battle skill is none.");
                return;
            }
            BattleSkillEffectAnalysis analysis = BattleCalculator.Instance.AnalyseBattleSkillEffect(battleSkill, this, targetBattleUnit, targetGridUnit);

            if (analysis == null)
            {
                UtilityHelper.LogError("Use skill error. Analysis failed:" + battleSkill.skillName);
                return;
            }

            List <BattleUnitSkillResult> skillResults = new List <BattleUnitSkillResult>();

            //主要影响
            for (int i = 0; i < analysis.mainReceiver.Count; ++i)
            {
                skillResults.Add(BattleCalculator.Instance.CalcSingle(this, analysis.mainReceiver[i], battleSkill, true));
            }
            //次要影响
            for (int i = 0; i < analysis.minorReceiver.Count; ++i)
            {
                skillResults.Add(BattleCalculator.Instance.CalcSingle(this, analysis.minorReceiver[i], battleSkill, false));
            }

            //产生使用技能的动作
            if (battleUnitAction != null)
            {
                battleUnitAction.skillAction                  = BattleUnitSkillAction.Get();
                battleUnitAction.skillAction.battleSkill      = battleSkill;
                battleUnitAction.skillAction.skillResult      = skillResults.ToArray();
                battleUnitAction.skillAction.targetBattleUnit = targetBattleUnit;
                battleUnitAction.skillAction.targetGrid       = targetGridUnit;
                battleUnitAction.skillAction.selfAttribute    = BattleSkillCostEnergy(battleSkill);
            }

            //伤害产生效果,计算仇恨
            for (int i = 0; i < skillResults.Count; ++i)
            {
                skillResults[i].battleUnit.AcceptSkillResult(skillResults[i].syncAttribute, battleUnitAction);
                //产生仇恨
                if (battleSkill.damageType != BattleSkillDamageType.Heal && !skillResults[i].battleUnit.Equals(this))
                {
                    skillResults[i].battleUnit.hatredRecorder.RecoredHatred(this.battleUnitID, skillResults[i].syncAttribute.hpChanged < 0 ? -skillResults[i].syncAttribute.hpChanged : skillResults[i].syncAttribute.hpChanged);
                }
            }
        }
예제 #11
0
        private BattleUnitSyncAttribute BattleSkillCostEnergy(SO_BattleSkill skill)
        {
            battleUnitAttribute.energy -= skill.energyCost;
            battleUnitAttribute.energy  = battleUnitAttribute.energy < 0 ? 0 : battleUnitAttribute.energy;

            BattleUnitSyncAttribute attribute = new BattleUnitSyncAttribute();

            attribute.hpChanged     = 0;
            attribute.currentHP     = battleUnitAttribute.hp;
            attribute.energyChanged = -skill.energyCost;
            attribute.currentEnergy = battleUnitAttribute.energy;

            return(attribute);
        }
예제 #12
0
        //初始化技能
        private void InitSkills()
        {
#if UNITY_EDITOR
            string[] files = System.IO.Directory.GetFiles(
                string.Format("{0}/HalfSLG/ScriptableObjects/BattleSkill", Application.dataPath), "*.asset", System.IO.SearchOption.TopDirectoryOnly);
            foreach (var item in files)
            {
                string         file  = UtilityHelper.ConverToRelativePath(item.Replace("\\", "/"));
                SO_BattleSkill skill = UnityEditor.AssetDatabase.LoadAssetAtPath <SO_BattleSkill>(file);
                if (skill != null)
                {
                    dicBattleSkills.Add(skill.skillID, skill);
                }
            }
#endif
        }
예제 #13
0
        //初始化技能
        private void InitSkills()
        {
            Object[] skills = GetAssetsFromBundle("scriptableobjects/battleskill.unity3d", typeof(SO_BattleSkill));
            if (skills != null)
            {
                for (int i = 0; i < skills.Length; ++i)
                {
                    SO_BattleSkill skill = skills[i] as SO_BattleSkill;
                    if (skill == null)
                    {
                        continue;
                    }

                    dicBattleSkills.Add(skill.skillID, skill);
                }
            }
        }
예제 #14
0
        public List <BattleUnit> battleUnitInvalid = new List <BattleUnit>(10); //战斗单位状态异常(无法战斗)

        //分析
        public bool Analysis(BattleUnit battleUnit, SO_BattleSkill skill)
        {
            Reset();

            if (battleUnit == null || skill == null)
            {
                return(false);
            }

            releaser    = battleUnit;
            battleSkill = skill;

            //队伍不符的
            BattleTeam team = battleUnit.battleField.GetBattleTeam(battleUnit, !(skill.damageType == BattleSkillDamageType.Heal));

            teamLimit.AddRange(team.battleUnits);

            //队伍相符的
            team = battleUnit.battleField.GetBattleTeam(battleUnit, skill.damageType == BattleSkillDamageType.Heal);
            for (int i = 0; i < team.battleUnits.Count; ++i)
            {
                //无法行动的
                if (!team.battleUnits[i].CanAction)
                {
                    battleUnitInvalid.Add(team.battleUnits[i]);
                }

                //超出距离的(大于释放距离 + 效果范围)
                else if (team.battleUnits[i].mapGrid.Distance(battleUnit.mapGrid) > skill.releaseRadius + (skill.targetType == BattleSkillTargetType.GridUnit ? skill.rangeRadius : 0))
                {
                    distanceLimit.Add(team.battleUnits[i]);
                }

                //合适的
                else
                {
                    suitableUnits.Add(team.battleUnits[i]);
                }
            }

            valid = true;

            return(true);
        }
        public List <BattleUnit> battleUnitInvalid = new List <BattleUnit>(10); //战斗单位状态异常(无法战斗)

        //分析
        public void Analysis(BattleUnit battleUnit, SO_BattleSkill skill)
        {
            Reset();

            if (battleUnit == null || skill == null)
            {
                return;
            }

            releaser    = battleUnit;
            battleSkill = skill;

            //队伍不符的
            BattleTeam team = battleUnit.battleField.GetBattleTeam(battleUnit, !(skill.damageType == BattleSkillDamageType.Heal));

            teamLimit.AddRange(team.battleUnits);

            //队伍相符的
            team = battleUnit.battleField.GetBattleTeam(battleUnit, skill.damageType == BattleSkillDamageType.Heal);
            for (int i = 0; i < team.battleUnits.Count; ++i)
            {
                //无法行动的
                if (!team.battleUnits[i].CanAction)
                {
                    battleUnitInvalid.Add(team.battleUnits[i]);
                }

                //超出范围的
                else if (team.battleUnits[i].mapGrid.Distance(battleUnit.mapGrid) > skill.GetMaxReleaseRadiusForCalculate(releaser.mapGrid))
                {
                    distanceLimit.Add(team.battleUnits[i]);
                }

                //范围内的
                else
                {
                    suitableUnits.Add(team.battleUnits[i]);
                }
            }
        }
예제 #16
0
        private static void RefreshSkillObject()
        {
            //先保存已有的
            Dictionary <string, SO_BattleSkill> exists = new Dictionary <string, SO_BattleSkill>(System.StringComparer.CurrentCultureIgnoreCase);
            List <string> newList    = new List <string>();
            List <string> removeList = new List <string>();

            string[] existObject = Directory.GetFiles(SO_SkillFolder, "*.asset", SearchOption.AllDirectories).Where(delegate(string filePath)
            {
                if (filePath.ToLower().Contains("meta"))
                {
                    return(false);
                }
                return(true);
            }).ToArray();

            foreach (var item in existObject)
            {
                SO_BattleSkill skillItem = AssetDatabase.LoadAssetAtPath <SO_BattleSkill>(item);
                if (skillItem != null)
                {
                    exists.Add(skillItem.name, skillItem);
                }
            }

            TextAsset textAsset = AssetDatabase.LoadAssetAtPath <TextAsset>(string.Format("{0}/BattleSkill.json", JsonFolder));
            var       items     = JsonMapper.ToObject(textAsset.text);

            if (items.IsArray)
            {
                foreach (var item in items)
                {
                    JsonData itemData = item as JsonData;
                    if (itemData == null)
                    {
                        continue;
                    }

                    string         objName   = ParseFromJson(itemData, "objName", string.Empty);
                    SO_BattleSkill assetItem = null;
                    string         assetPath = string.Format("{0}/{1}.asset", SO_SkillFolder, objName);
                    //尝试从存在的列表中获取
                    if (exists.ContainsKey(objName))
                    {
                        assetItem = exists[objName];
                        //移除,后面要删除没有找到的
                        exists.Remove(objName);
                    }
                    else
                    {
                        assetItem = ScriptableObject.CreateInstance <SO_BattleSkill>();
                        AssetDatabase.CreateAsset(assetItem, assetPath);
                        newList.Add(objName);
                    }

                    assetItem.skillID        = ParseFromJson(itemData, "ID", 0);
                    assetItem.skillName      = ParseFromJson(itemData, "skillName", string.Empty);
                    assetItem.effectRadius   = ParseFromJson(itemData, "effectRadius", 0);
                    assetItem.releaseRadius  = ParseFromJson(itemData, "releaseRadius", 0);
                    assetItem.rageLevel      = ParseFromJson(itemData, "rageLevel", 0f);
                    assetItem.hatredMultiple = ParseFromJson(itemData, "hatredMultiple", 0f);
                    assetItem.energyCost     = ParseFromJson(itemData, "energyCost", 0);
                    assetItem.mainValue      = ParseFromJson(itemData, "mainValue", 0);

                    //类型
                    string targetType = ParseFromJson(itemData, "targetType", string.Empty);
                    if (string.Compare(targetType, "BattleUnit", true) == 0)
                    {
                        assetItem.targetType = BattleSkillTargetType.BattleUnit;
                    }
                    else if (string.Compare(targetType, "GridUnit", true) == 0)
                    {
                        assetItem.targetType = BattleSkillTargetType.GridUnit;
                    }
                    else if (string.Compare(targetType, "Self", true) == 0)
                    {
                        assetItem.targetType = BattleSkillTargetType.Self;
                    }
                    else
                    {
                        Debug.LogError(string.Format("未知的目标类型 => {0} | {1} | {2}", targetType, assetItem.skillID, assetItem.skillName));
                    }

                    //类型
                    string damageType = ParseFromJson(itemData, "damageType", string.Empty);
                    if (string.Compare(damageType, "Physical", true) == 0)
                    {
                        assetItem.damageType = BattleSkillDamageType.Physical;
                    }
                    else if (string.Compare(damageType, "Magic", true) == 0)
                    {
                        assetItem.damageType = BattleSkillDamageType.Magic;
                    }
                    else if (string.Compare(damageType, "Heal", true) == 0)
                    {
                        assetItem.damageType = BattleSkillDamageType.Heal;
                    }
                    else
                    {
                        Debug.LogError(string.Format("未知的伤害类型 => {0} | {1} | {2}", damageType, assetItem.skillID, assetItem.skillName));
                    }

                    EditorUtility.SetDirty(assetItem);
                }
            }

            //需要删除没有的
            if (exists.Count > 0)
            {
                if (EditorUtility.DisplayDialog("警告", string.Format("存在{0}个配置外的技能, 是否删除", exists.Keys.Count), "是", "否"))
                {
                    removeList = new List <string>(exists.Keys);
                    foreach (var item in exists)
                    {
                        AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(item.Value));
                    }
                    exists.Clear();
                }
            }

            System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder();
            stringBuilder.AppendFormat("技能生成结束,新增:{0},删除{1}\n", newList.Count, removeList.Count);
            stringBuilder.AppendFormat("  新增:\n");
            for (int i = 0; i < newList.Count; i++)
            {
                stringBuilder.AppendFormat("    {0}.{1}\n", i, newList[i]);
            }

            stringBuilder.AppendFormat("  删除:\n");
            for (int i = 0; i < removeList.Count; i++)
            {
                stringBuilder.AppendFormat("    {0}.{1}\n", i, removeList[i]);
            }
            Debug.Log(stringBuilder.ToString());
        }
예제 #17
0
 //某个战斗单位点击了使用技能
 public void BattleUnitUseSkill(BattleUnit battleUnit, SO_BattleSkill skill)
 {
     manualOperationHelper.BattleUnitUseSkill(battleUnit, skill);
 }
예제 #18
0
        //某个战斗单位点击了使用技能
        public void BattleUnitUseSkill(BattleUnit battleUnit, SO_BattleSkill skill)
        {
            if (battleUnit == null ||
                battleUnit.battleUnitRenderer == null ||
                !battleUnit.battleUnitRenderer.Equals(manualOperatingBattleUnitRenderer))
            {
                UtilityHelper.LogError("Battle unit use skill failed.");
                UIViewManager.Instance.HideView(UIViewName.BattleFieldPlayerActOption);
                return;
            }

            //获取推算的技能释放结果
            usedManualReleaseAnalysisor = BattleCalculator.Instance.ManualReleaseAnalysisor;

            //分析结果
            usedManualReleaseAnalysisor.Analysis(manualOperatingBattleUnitRenderer.battleUnit, skill);

            //显示技能释放范围
            if (skill.releaseRadius > 0)
            {
                SetCircularRangeRenderStateActive(
                    true,
                    GridRenderType.SkillReleaseRange,
                    battleUnit.mapGrid.row,
                    battleUnit.mapGrid.column,
                    skill.releaseRadius);
            }

            //根据类型判断技能显示状态
            switch (skill.targetType)
            {
            //对单个目标
            case BattleSkillTargetType.BattleUnit:
                //可以被选中的
                for (int i = 0; i < usedManualReleaseAnalysisor.suitableUnits.Count; ++i)
                {
                    usedManualReleaseAnalysisor.suitableUnits[i].battleUnitRenderer.UpdateRenderState(BattleUnitRenderState.Selectable);
                }

                //不可以被选中的
                for (int i = 0; i < usedManualReleaseAnalysisor.distanceLimit.Count; ++i)
                {
                    usedManualReleaseAnalysisor.distanceLimit[i].battleUnitRenderer.UpdateRenderState(BattleUnitRenderState.NotSelectable);
                }

                //队伍不合适的
                for (int i = 0; i < usedManualReleaseAnalysisor.teamLimit.Count; ++i)
                {
                    usedManualReleaseAnalysisor.teamLimit[i].battleUnitRenderer.UpdateRenderState(BattleUnitRenderState.Normal);
                }

                //设定技能操作类型
                skillOperationType = skill.effectRadius > 0 ? SkillOperationType.SurroundBattleUnit : SkillOperationType.SingleBattleUnitTarget;
                break;

            //对范围(某一个位置)目标
            case BattleSkillTargetType.GridUnit:
                skillOperationType = SkillOperationType.GridUnitTarget;
                //如果没有位置可选,则直接打开范围
                if (skill.releaseRadius <= 0)
                {
                    //可以被选中,标记为已被选中
                    for (int i = 0; i < usedManualReleaseAnalysisor.suitableUnits.Count; ++i)
                    {
                        usedManualReleaseAnalysisor.suitableUnits[i].battleUnitRenderer.UpdateRenderState(BattleUnitRenderState.Selected);
                    }

                    //不可以被选中的
                    for (int i = 0; i < usedManualReleaseAnalysisor.distanceLimit.Count; ++i)
                    {
                        usedManualReleaseAnalysisor.distanceLimit[i].battleUnitRenderer.UpdateRenderState(BattleUnitRenderState.NotSelectable);
                    }

                    //队伍不合适的
                    for (int i = 0; i < usedManualReleaseAnalysisor.teamLimit.Count; ++i)
                    {
                        usedManualReleaseAnalysisor.teamLimit[i].battleUnitRenderer.UpdateRenderState(BattleUnitRenderState.Normal);
                    }

                    OnBattleUnitAndGridTouched_StateSkill_GridUnitTarget(battleUnit.mapGrid, null);
                }
                else
                {
                    //需要指定范围,需要点击目标地块
                }
                break;

            //以自身为中心的
            case BattleSkillTargetType.Self:
                //可以被选中,标记为已被选中
                for (int i = 0; i < usedManualReleaseAnalysisor.suitableUnits.Count; ++i)
                {
                    usedManualReleaseAnalysisor.suitableUnits[i].battleUnitRenderer.UpdateRenderState(BattleUnitRenderState.Selected);
                }

                //不可以被选中的
                for (int i = 0; i < usedManualReleaseAnalysisor.distanceLimit.Count; ++i)
                {
                    usedManualReleaseAnalysisor.distanceLimit[i].battleUnitRenderer.UpdateRenderState(BattleUnitRenderState.NotSelectable);
                }

                //队伍不合适的
                for (int i = 0; i < usedManualReleaseAnalysisor.teamLimit.Count; ++i)
                {
                    usedManualReleaseAnalysisor.teamLimit[i].battleUnitRenderer.UpdateRenderState(BattleUnitRenderState.Normal);
                }

                skillOperationType = SkillOperationType.SurroundSelf;

                //省去一步点击操作,直接展示区域
                OnBattleUnitAndGridTouched_StateSkill_SurroundSelf(battleUnit.mapGrid, battleUnit);
                break;

            default:
                break;
            }

            //切换操作状态
            manualOperationState = ManualOperationState.Skill;
            UIViewManager.Instance.HideView(UIViewName.BattleFieldPlayerActOption);
        }
예제 #19
0
        //使用技能
        public void UseSkill(BattleUnitAction battleUnitAction, SO_BattleSkill battleSkill, BattleUnit targetBattleUnit = null, GridUnit targetGridUnit = null)
        {
            if (battleSkill == null)
            {
                UtilityHelper.LogError("Use skill error. Battle skill is none.");
                return;
            }
            BattleSkillEffectAnalysis analysis = BattleCalculator.Instance.AnalyseBattleSkillEffect(battleSkill, this, targetBattleUnit, targetGridUnit);

            if (analysis == null)
            {
                UtilityHelper.LogError("Use skill error. Analysis failed:" + battleSkill.skillName);
                return;
            }

            List <BattleUnitSkillResult> skillResults = new List <BattleUnitSkillResult>();

            //主要影响
            for (int i = 0; i < analysis.mainReceiver.Count; ++i)
            {
                skillResults.Add(BattleCalculator.Instance.CalcSingle(this, analysis.mainReceiver[i], battleSkill, true));
            }
            //次要影响
            for (int i = 0; i < analysis.minorReceiver.Count; ++i)
            {
                skillResults.Add(BattleCalculator.Instance.CalcSingle(this, analysis.minorReceiver[i], battleSkill, false));
            }

            //产生使用技能的动作
            if (battleUnitAction != null)
            {
                battleUnitAction.skillAction                  = BattleUnitSkillAction.Get();
                battleUnitAction.skillAction.battleSkill      = battleSkill;
                battleUnitAction.skillAction.skillResult      = skillResults.ToArray();
                battleUnitAction.skillAction.targetBattleUnit = targetBattleUnit;
                battleUnitAction.skillAction.targetGrid       = targetGridUnit;
                battleUnitAction.skillAction.selfAttribute    = BattleSkillCostEnergy(battleSkill);
            }

            //伤害产生效果,计算仇恨
            for (int i = 0; i < skillResults.Count; ++i)
            {
                //接收伤害,属性变更
                skillResults[i].battleUnit.AcceptSkillResult(skillResults[i].syncAttribute, battleUnitAction);

                //产生仇恨
                if (battleSkill.damageType != BattleSkillDamageType.Heal && !skillResults[i].battleUnit.Equals(this))
                {
                    //新仇记录
                    for (int j = 0; j < enemyTeam.battleUnits.Count; ++j)
                    {
                        if (!enemyTeam.battleUnits[j].CanAction)
                        {
                            continue;
                        }

                        //每个战斗单位都需要知道发生了什么
                        enemyTeam.battleUnits[j].battleBehaviourSystem.RecordSkillResult(this, skillResults[i]);
                    }
                }
            }
        }
예제 #20
0
        public BattleSkillEffectAnalysis AnalyseBattleSkillEffect(SO_BattleSkill battleSkill, BattleUnit releaser = null, BattleUnit targetBattleUnit = null, GridUnit targetGridUnit = null)
        {
            battleSkillEffectAnalysis.Reset();

            if (releaser == null)
            {
                UtilityHelper.LogError("Analyse Battle Skill Effect error.Releaser is none.");
                return(null);
            }

            switch (battleSkill.targetType)
            {
            //对战斗单位
            case BattleSkillTargetType.BattleUnit:
                if (targetBattleUnit == null)
                {
                    return(null);
                }
                else
                {
                    battleSkillEffectAnalysis.battleSkill = battleSkill;
                    //记录主要影响
                    battleSkillEffectAnalysis.mainReceiver.Add(targetBattleUnit);
                    if (battleSkill.effectRadius > 0)
                    {
                        //暂时定为次要目标与主要目标同类
                        BattleTeam battleTeam = targetBattleUnit.battleField.GetBattleTeam(targetBattleUnit, true);
                        if (battleTeam != null)
                        {
                            for (int i = 0; i < battleTeam.battleUnits.Count; ++i)
                            {
                                if (!battleTeam.battleUnits[i].CanAction || battleTeam.battleUnits[i].Equals(targetBattleUnit))
                                {
                                    continue;
                                }
                                //有次要影响
                                if (battleTeam.battleUnits[i].mapGrid.Distance(targetBattleUnit.mapGrid) <= battleSkill.effectRadius)
                                {
                                    battleSkillEffectAnalysis.minorReceiver.Add(battleTeam.battleUnits[i]);
                                }
                            }
                        }
                    }
                }
                break;

            //对自己
            case BattleSkillTargetType.Self:
                battleSkillEffectAnalysis.battleSkill = battleSkill;
                //记录主要影响
                battleSkillEffectAnalysis.mainReceiver.Add(releaser);
                if (battleSkill.effectRadius > 0)
                {
                    //暂时定为次要目标与主要目标同类
                    BattleTeam battleTeam = releaser.battleField.GetBattleTeam(releaser, true);
                    if (battleTeam != null)
                    {
                        for (int i = 0; i < battleTeam.battleUnits.Count; ++i)
                        {
                            if (!battleTeam.battleUnits[i].CanAction || battleTeam.battleUnits[i].Equals(releaser))
                            {
                                continue;
                            }
                            //有次要影响
                            if (battleTeam.battleUnits[i].mapGrid.Distance(releaser.mapGrid) <= battleSkill.effectRadius)
                            {
                                battleSkillEffectAnalysis.minorReceiver.Add(battleTeam.battleUnits[i]);
                            }
                        }
                    }
                }
                break;

            //对某个地点
            case BattleSkillTargetType.GridUnit:
                if (targetGridUnit == null)
                {
                    return(null);
                }
                else
                {
                    battleSkillEffectAnalysis.battleSkill = battleSkill;
                    if (battleSkill.effectRadius > 0)
                    {
                        BattleTeam battleTeam = releaser.battleField.GetBattleTeam(releaser, battleSkill.damageType == BattleSkillDamageType.Heal);
                        if (battleTeam != null)
                        {
                            for (int i = 0; i < battleTeam.battleUnits.Count; ++i)
                            {
                                if (!battleTeam.battleUnits[i].CanAction || battleTeam.battleUnits[i].Equals(releaser))
                                {
                                    continue;
                                }
                                //记录主要影响
                                if (battleTeam.battleUnits[i].mapGrid.Distance(targetGridUnit) <= battleSkill.effectRadius)
                                {
                                    battleSkillEffectAnalysis.mainReceiver.Add(battleTeam.battleUnits[i]);
                                }
                            }
                        }
                    }
                }
                break;

            default:
                break;
            }

            return(battleSkillEffectAnalysis);
        }
예제 #21
0
        /// <summary>
        /// 计算单个效果
        /// </summary>
        /// <param name="releaser">释放者</param>
        /// <param name="target">目标</param>
        /// <param name="battleSkill">技能</param>
        /// <param name="mainEffect">是否主要伤害</param>
        /// <returns>技能结果</returns>
        public BattleUnitSkillResult CalcSingle(BattleUnit releaser, BattleUnit target, SO_BattleSkill battleSkill, bool mainEffect)
        {
            BattleUnitSkillResult result = new BattleUnitSkillResult();

            result.battleUnit    = target;
            result.battleSkill   = battleSkill;
            result.syncAttribute = new BattleUnitSyncAttribute();
            //简单计算生命值
            switch (battleSkill.damageType)
            {
            case BattleSkillDamageType.Physical:
            case BattleSkillDamageType.Magic:
                result.syncAttribute.hpChanged = -(Mathf.Max(0, releaser.battleUnitAttribute.Atk - target.battleUnitAttribute.Def + battleSkill.mainValue));
                //能量不变
                result.syncAttribute.energyChanged = 0;
                result.syncAttribute.currentEnergy = target.battleUnitAttribute.energy;
                break;

            case BattleSkillDamageType.Heal:
                result.syncAttribute.hpChanged = Mathf.Min(battleSkill.mainValue, target.battleUnitAttribute.maxHp - target.battleUnitAttribute.hp);
                //能量不变
                result.syncAttribute.energyChanged = 0;
                result.syncAttribute.currentEnergy = target.battleUnitAttribute.energy;
                break;

            default:
                break;
            }
            //hp变化
            target.battleUnitAttribute.hp += result.syncAttribute.hpChanged;
            target.battleUnitAttribute.hp  = Mathf.Clamp(target.battleUnitAttribute.hp, 0, target.battleUnitAttribute.maxHp);
            //记录变化
            result.syncAttribute.currentHP = target.battleUnitAttribute.hp;
            return(result);
        }