yyl
2025-09-10 6696f835cfba7fd451d7a78342bb56cdc6e2e940
Main/System/Battle/BattleUtility.cs
@@ -4,7 +4,7 @@
using UnityEngine.UI;
using DG.Tweening;
using DG.Tweening.Core;
using System.Linq;
public static class BattleUtility
{
@@ -23,7 +23,7 @@
        var battleField = BattleManager.Instance.storyBattleField;
        if (battleField == null)
        {
            BattleDebug.LogError("BattleManager.storyBattleField 未初始化!");
            Debug.LogError("BattleManager.storyBattleField 未初始化!");
            return;
        }
@@ -119,11 +119,40 @@
    public static string DisplayDamageNum(long num, int attackType)
    {
        // 服务器位数到客户端类型ID的映射
        Dictionary<int, int> serverToClientTypeMap = new Dictionary<int, int>
        {
            { 1, 2 },    // 普通伤血
            { 2, 4 },    // 恢复回血
            { 3, 8 },    // 反弹伤血
            { 4, 16 },   // 持续伤血
            { 5, 32 },   // 格挡
            { 7, 64 },   // 暴击伤害
            { 9, 128 },  // 闪避
            // 其它类型如需补充可继续添加
        };
        int damageTypeValue = 0;
        for (int i = 0; i < 32; i++)
        {
            int flag = 1 << i;
            if ((attackType & flag) != 0)
            {
                // 只处理有映射的类型
                if (serverToClientTypeMap.TryGetValue(i + 1, out int clientTypeId))
                {
                    damageTypeValue += clientTypeId;
                }
            }
        }
        DamageType damageType = (DamageType)damageTypeValue;
        var config = DamageNumConfig.Get(damageTypeValue);
        var basePowerStr = UIHelper.ReplaceLargeArtNum(num);
        var result = string.Empty;
        for (int i = 0; i < basePowerStr.Length; i++)
        {
            var numChar = (char)GetDamageNumKey((DamageType)attackType, basePowerStr[i]);
            var numChar = (char)GetDamageNumKey(config, basePowerStr[i]);
            if (numChar > 0)
            {
                result += numChar;
@@ -132,33 +161,101 @@
        return result;
    }
    public static int GetDamageNumKey(DamageType damageType, int _num)
    public static int GetMainTargetPositionNum(BattleObject caster, List<HB427_tagSCUseSkill.tagSCUseSkillHurt> targetList, SkillConfig skillConfig)
    {
        var config = DamageNumConfig.Get(damageType.ToString());
        //.的ASCII码是46
        if (_num == 46)
        int returnIndex = 0;
        //  根据敌方血量阵营 存活人数来选择
        BattleCamp battleCamp = skillConfig.TagFriendly != 0 ? caster.Camp : caster.GetEnemyCamp();
        List<BattleObject> targetObjList = caster.battleField.battleObjMgr.GetBattleObjList(battleCamp);
        // 瞄准的目标范围,如果目标个数为0则为范围内全部
        // 0    全部范围
        // 1    对位,默认只选1个
        // 2    前排
        // 3    后排
        // 4    纵排,按对位规则选择纵排
        // 5    自己,默认只选自己
        // 6    继承主技能/来源技能目标
        //      一般是额外触发的技能使用,如概率附加某buff
        //      额外触发的技能如果目标与主技能不一致,则重新设定目标即可
        //      或被动触发的技能,可继承触发来源技能的攻防双方关系
        switch (skillConfig.TagAim)
        {
            return config.nums[10];
            case 0:
                //  全部范围
                //全部范围+敌我+目标数量为6
                //就是取敌我站位中的2号位
                returnIndex = 1;
                break;
            case 1:
                returnIndex = caster.teamHero.positionNum;
                //  寻找对位是否有人 没有的话选择最小的
                List<BattleObject> opposite = new List<BattleObject>(from bo in targetObjList where !bo.IsDead() && bo.teamHero.positionNum == returnIndex select bo);
                if (opposite.Count > 0)
                {
                    returnIndex = opposite[0].teamHero.positionNum;
                }
                else
                {
                    opposite = new List<BattleObject>(from bo in targetObjList where !bo.IsDead() select bo);
                    opposite.Sort((a, b) => a.teamHero.positionNum.CompareTo(b.teamHero.positionNum));
                    returnIndex = opposite.Count > 0 ? opposite[0].teamHero.positionNum : returnIndex;
                }
                break;
            case 2:
                //  看看对面前排是否都活着
                List<BattleObject> front = new List<BattleObject>(from bo in targetObjList where !bo.IsDead() && bo.teamHero.positionNum < 3 select bo);
                if (front.Count > 0)
                {
                    returnIndex = 1;
                }
                else
                {
                    returnIndex = 4;
                }
                break;
            case 3:
                //  看看对面后排是否都活着
                List<BattleObject> back = new List<BattleObject>(from bo in targetObjList where !bo.IsDead() && bo.teamHero.positionNum >= 3 select bo);
                if (back.Count > 0)
                {
                    returnIndex = 4;
                }
                else
                {
                    returnIndex = 1;
                }
                break;
            // 4    纵排,按对位规则选择纵排
            case 4:
                List<BattleObject> vertical = new List<BattleObject>(from bo in targetObjList where !bo.IsDead() && (bo.teamHero.positionNum - caster.teamHero.positionNum) % 3 == 0 select bo);
                //  TODO YYL
                break;
            // 5    自己,默认只选自己
            case 5:
                returnIndex = caster.teamHero.positionNum;
                break;
            default:
                break;
        }
        //k的ASCII码是107
        else if (_num == 107)
        return returnIndex;
    }
    public static int GetDamageNumKey(DamageNumConfig config, int _num)
    {
        if (_num == 46)      return config.nums[10]; // '.'
        else if (_num == 107) return config.nums[11]; // 'k'
        else if (_num == 109) return config.nums[12]; // 'm'
        else if (_num == 98)  return config.nums[13]; // 'b'
        else if (_num == 116) return config.nums[14]; // 't'
        int targetNum = _num - 48;
        if (targetNum >= config.nums.Length || targetNum < 0)
        {
            return config.nums[11];
        }
        //m的ASCII码是109
        else if (_num == 109)
        {
            return config.nums[12];
        }
        //b的ASCII码是98
        else if (_num == 98)
        {
            return config.nums[13];
        }
        //t的ASCII码是116
        else if (_num == 116)
        {
            return config.nums[14];
            Debug.LogError("damage config " + config.TypeID + " _num is " +  _num + " out of range");
            return _num;
        }
        return config.nums[_num - 48];
    }