示例#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);
                        UpdateComboNotes(battleUnit.battleUnitAttribute.ComboStatus);
                    }
                    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 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);
        }
        //重置
        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);
        }
示例#4
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;
            attribute.currentBP     = battleUnitAttribute.BP;

            return(attribute);
        }
        //初始化技能
        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);
                }
            }
        }
        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]);
                }
            }
        }
 //某个战斗单位点击了使用技能
 public void BattleUnitUseSkill(BattleUnit battleUnit, SO_BattleSkill skill)
 {
     manualOperationHelper.BattleUnitUseSkill(battleUnit, skill);
 }
示例#8
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.Move:
            case BattleSkillDamageType.Skill:
                float critRatio = releaser.battleUnitAttribute.GetTargetCritRatio(target);              //判断是否暴击
                float critNum   = Random.Range(0.0f, 1.0f);
                if (critNum < critRatio)
                {
                    result.crit = true;
                }
                else
                {
                    result.crit = false;
                }

                float hpChanged = releaser.battleUnitAttribute.power * battleSkill.powerModulus;        //力量补正
                hpChanged += releaser.battleUnitAttribute.speed * battleSkill.speedModulus;             //速度补正
                hpChanged += releaser.battleUnitAttribute.technic * battleSkill.technicModulus;         //技巧补正
                hpChanged += releaser.battleUnitAttribute.power * EGameConstL.PowerCommonModulus;       //力量值附加补正
                hpChanged *= releaser.battleUnitAttribute.AtkUpRatio;                                   //通用攻击力提升
                hpChanged *= releaser.battleUnitAttribute.GetDamageTypeModulus(target);                 //属性克制补正
                hpChanged  = Mathf.Max(0, hpChanged - target.battleUnitAttribute.Def);                  //直接减去目标防御值
                if (result.crit)
                {
                    hpChanged *= 2;                                  //判断是否暴击
                }
                result.syncAttribute.hpChanged = (int)-hpChanged;    //(Mathf.Max(0, releaser.battleUnitAttribute.Atk - target.battleUnitAttribute.Def + battleSkill.mainValue));
                //能量不变
                result.syncAttribute.energyChanged = 0;
                result.syncAttribute.currentEnergy = target.battleUnitAttribute.energy;

                float avoidRatio = releaser.battleUnitAttribute.GetTargetAvoidRatio(target);            //判断是否闪避
                float avoidNum   = Random.Range(0.0f, 1.0f);
                if (!result.crit && avoidNum < avoidRatio)
                {
                    result.syncAttribute.hpChanged = 0;
                    result.avoid = true;
                }
                else
                {
                    result.avoid = false;
                }
                UtilityHelper.LogFormat("Is critical: {0}, Is avoid: {1}", result.crit, result.avoid);
                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);
        }
示例#9
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);
        }
示例#10
0
        //使用技能
        public void UseSkill(SO_BattleSkill battleSkill, BattleUnit targetBattleUnit = null, GridUnit targetGridUnit = null)
        {
            if (battleSkill == null)
            {
                UtilityHelper.LogError("Use skill error. Battle skill is none.");
                return;
            }

            GridUnit temp = targetGridUnit;

            if (temp == null && targetBattleUnit != null)
            {
                temp = targetBattleUnit.mapGrid;
            }
            if (temp != null && mapGrid.Distance(temp) > battleSkill.GetReleaseRadius(mapGrid))
            {
                return;
            }

            BattleSkillEffectAnalysis analysis = BattleCalculator.Instance.AnalyseBattleSkillEffect(battleSkill, this, targetBattleUnit, targetGridUnit);

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

            skillResults.Clear();

            //主要影响
            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));
            }

            //连招combo统计
            if (battleUnitAttribute.manualOperation)
            {
                UtilityHelper.Log("Check combo now");

                //返回真表示连招成立,则调用连招效果
                int comboID = battleUnitAttribute.comboJudge((int)battleSkill.damageType);
                if (comboID != -1)
                {
                    //对于即时生效的技能需要直接改变skillResult
                    ComboEffect(comboID, battleUnitAttribute);
                }
            }

            //产生使用技能的动作
            BattleUnitSkillAction skillAction = BattleUnitActionEvent.CreateEvent <BattleUnitSkillAction>(BattleUnitActionType.UseSkill, this);

            skillAction.battleSkill      = battleSkill;
            skillAction.skillResult      = skillResults.ToArray();
            skillAction.targetBattleUnit = targetBattleUnit;
            skillAction.targetGrid       = targetGridUnit;
            skillAction.selfAttribute    = BattleSkillCostEnergy(battleSkill);
            battleField.AppendBattleAction(skillAction);

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

                //产生仇恨
                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;
                        }

                        //每个战斗单位都需要知道发生了什么
                        if (!enemyTeam.battleUnits[j].battleUnitAttribute.manualOperation)
                        {
                            enemyTeam.battleUnits[j].battleBehaviourSystem.RecordSkillResult(this, skillResults[i]);
                        }
                    }
                }
            }
        }
示例#11
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.");
                HideManualActionList();
                return;
            }

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

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

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

            //根据类型判断技能显示状态
            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.GetReleaseRadius(battleUnit.mapGrid) <= 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;
            HideManualActionList();
        }