hch
1 天以前 a19acb609721b89419fe55785643a0d4f1959368
0312 动态检测战力公式
3个文件已修改
171 ■■■■■ 已修改文件
Main/Core/GameEngine/Launch/ConfigInitTask.cs 155 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Main/System/Main/FightPowerFormula.cs 14 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Main/System/Main/FightPowerManager.cs 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
Main/Core/GameEngine/Launch/ConfigInitTask.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using UnityEngine;
public class ConfigInitTask : LaunchTask
{
@@ -30,7 +31,161 @@
        // TODO YYL
        // OperationLogCollect.Instance.RecordLauchEvent(3);
        // OperationLogCollect.Instance.RecordEvent(3);
#if UNITY_EDITOR
        var config = FuncConfigConfig.Get("HeroAttrFormula");
        var propertyFormula = config.Numerical1;
        var fightPropertyFormula = config.Numerical2;
        var fightPowerFormula = config.Numerical3;
        var skillFightPowerFormula = config.Numerical4;
        //读取文件 FightPowerFormula.cs文件,通过公式字符串生成代码
        var filePath = "Assets/Scripts/Main/System/Main/FightPowerFormula.cs";
        var fileContent = File.ReadAllText(filePath);
        // 生成新的代码内容
        var newContent = GenerateFightPowerFormulaCode(propertyFormula, fightPropertyFormula, fightPowerFormula, skillFightPowerFormula);
        // 如果内容有变化,则写入文件
        if (newContent != fileContent)
        {
            File.WriteAllText(filePath, newContent);
            Debug.LogError("战斗公式有变更 FightPowerFormula.cs 已根据配置公式重新生成, 请提交代码!");
    }
        else
        {
            Debug.Log("FightPowerFormula.cs 内容未变化,无需重新生成");
        }
#endif
    }
#if UNITY_EDITOR
    private string GenerateFightPowerFormulaCode(string propertyFormula, string fightPropertyFormula, string fightPowerFormula, string skillFightPowerFormula)
    {
        // 提取变量名
        var propertyVariables = ExtractVariables(propertyFormula);
        var fightPropertyVariables = ExtractVariables(fightPropertyFormula);
        var fightPowerVariables = ExtractVariables(fightPowerFormula);
        var skillFightPowerVariables = ExtractVariables(skillFightPowerFormula);
        // 处理公式中的类型转换操作符
        var processedPropertyFormula = ProcessTypeConversionOperators(propertyFormula);
        var processedFightPropertyFormula = ProcessTypeConversionOperators(fightPropertyFormula);
        var processedFightPowerFormula = ProcessTypeConversionOperators(fightPowerFormula);
        var processedSkillFightPowerFormula = ProcessTypeConversionOperators(skillFightPowerFormula);
        // 生成代码
        var code = new System.Text.StringBuilder();
        code.AppendLine("using System.Collections.Generic;");
        code.AppendLine();
        code.AppendLine("public class FightPowerFormula");
        code.AppendLine("{");
        // 添加公式注释
        code.AppendLine("    // 基础属性公式");
        code.AppendLine($"    // {propertyFormula}");
        code.AppendLine("    // 战斗属性公式");
        code.AppendLine($"    // {fightPropertyFormula}");
        code.AppendLine("    // 战斗力公式");
        code.AppendLine($"    // {fightPowerFormula}");
        code.AppendLine("    // 技能战斗力公式");
        code.AppendLine($"    // {skillFightPowerFormula}");
        code.AppendLine();
        // 生成基础属性计算方法
        code.AppendLine("    public static double GetBaseAttr(Dictionary<string, double> variables)");
        code.AppendLine("    {");
        foreach (var variable in propertyVariables)
        {
            code.AppendLine($"        double {variable} = variables[\"{variable}\"];");
        }
        code.AppendLine();
        code.AppendLine($"        return {processedPropertyFormula};");
        code.AppendLine("    }");
        code.AppendLine();
        // 生成战斗属性计算方法
        code.AppendLine("    public static double GetFightAttr(Dictionary<string, double> variables)");
        code.AppendLine("    {");
        foreach (var variable in fightPropertyVariables)
        {
            code.AppendLine($"        double {variable} = variables[\"{variable}\"];");
        }
        code.AppendLine();
        code.AppendLine($"        return {processedFightPropertyFormula};");
        code.AppendLine("    }");
        code.AppendLine();
        // 生成战斗力计算方法
        code.AppendLine("    public static double GetFightPower(Dictionary<string, double> variables)");
        code.AppendLine("    {");
        foreach (var variable in fightPowerVariables)
        {
            code.AppendLine($"        double {variable} = variables[\"{variable}\"];");
        }
        code.AppendLine();
        code.AppendLine($"        return {processedFightPowerFormula};");
        code.AppendLine("    }");
        code.AppendLine();
        // 生成技能战斗力计算方法
        code.AppendLine("    public static double GetSkillsFightPower(Dictionary<string, double> variables)");
        code.AppendLine("    {");
        foreach (var variable in skillFightPowerVariables)
        {
            code.AppendLine($"        double {variable} = variables[\"{variable}\"];");
        }
        code.AppendLine();
        code.AppendLine($"        return {processedSkillFightPowerFormula};");
        code.AppendLine("    }");
        code.AppendLine();
        code.AppendLine("}");
        return code.ToString();
    }
    private string ProcessTypeConversionOperators(string formula)
    {
        // 将类型转换操作符转换为加括号的形式
        var processedFormula = formula;
        // 处理 long(expression) 转换为 (long)(expression)
        processedFormula = System.Text.RegularExpressions.Regex.Replace(processedFormula, @"\b(long|int|float|double)\s*\(", "($1)(");
        return processedFormula;
    }
    private List<string> ExtractVariables(string formula)
    {
        var variables = new List<string>();
        var words = formula.Split(new char[] { ' ', '+', '-', '*', '/', '(', ')', ',', '=', '<', '>', '!', '&', '|', '%', ':' }, StringSplitOptions.RemoveEmptyEntries);
        foreach (var word in words)
        {
            // 过滤掉数字、运算符和关键字
            if (!double.TryParse(word, out _) && !IsOperator(word) && !IsKeyword(word) && !variables.Contains(word))
            {
                variables.Add(word);
            }
        }
        return variables;
    }
    private bool IsOperator(string word)
    {
        var operators = new string[] { "if", "else", "min", "max", "long", "int", "float", "double" };
        return operators.Contains(word);
    }
    private bool IsKeyword(string word)
    {
        var keywords = new string[] { "return", "var", "class", "public", "private", "static", "void", "using", "namespace" };
        return keywords.Contains(word);
    }
#endif
    public override void Update()
    {
Main/System/Main/FightPowerFormula.cs
@@ -1,17 +1,18 @@
using System.Collections.Generic;
public class FightPowerFormula
{
    // 基础属性公式
    // (lvValue+equipValue+bookValue+realmValue+gubaoValue+hjgValue+horseValue)*(1+lineupHaloPer+bookPer+realmPer+gubaoPer+hjgPer+horsePer+lineupInitAddPer+lineupLVAddPer+lineupBreakLVAddPer+lineupStarAddPer)*(inheritPer+fetterPer+starTalentPer+breakLVPer+awakeTalentPer)+heroSelfValue
    // 战斗属性公式
    // (lvValue+equipValue+bookValue+realmValue+gubaoValue+hjgValue+horseValue)+(heroSelfValue+lineupHaloValue+starTalentValue+breakLVValue+awakeTalentValue)+fetterValue
    // 战斗力公式
    // long(Atk*AtkRatio+MaxHP*MaxHPRatio+Def*DefRatio+(StunRate*StunRateRatio+SuperHitRate*SuperHitRateRatio+ComboRate*ComboRateRatio+MissRate*MissRateRatio+ParryRate*ParryRateRatio+SuckHPPer*SuckHPPerRatio+StunRateDef*StunRateDefRatio+SuperHitRateDef*SuperHitRateDefRatio+ComboRateDef*ComboRateDefRatio+MissRateDef*MissRateDefRatio+ParryRateDef*ParryRateDefRatio+SuckHPPerDef*SuckHPPerDefRatio+FinalDamPer*FinalDamPerRatio+FinalDamPerDef*FinalDamPerDefRatio+PhyDamPer*PhyDamPerRatio+PhyDamPerDef*PhyDamPerDefRatio+MagDamPer*MagDamPerRatio+MagDamPerDef*MagDamPerDefRatio+NormalSkillPer*NormalSkillPerRatio+NormalSkillPerDef*NormalSkillPerDefRatio+AngerSkillPer*AngerSkillPerRatio+AngerSkillPerDef*AngerSkillPerDefRatio+SuperDamPer*SuperDamPerRatio+SuperDamPerDef*SuperDamPerDefRatio+CurePer*CurePerRatio+CurePerDef*CurePerDefRatio+ShieldPer*ShieldPerRatio+ShieldPerDef*ShieldPerDefRatio+DOTPer*DOTPerRatio+DOTPerDef*DOTPerDefRatio+WeiFinalDamPer*WeiFinalDamPerRatio+WeiFinalDamPerDef*WeiFinalDamPerDefRatio+ShuFinalDamPer*ShuFinalDamPerRatio+ShuFinalDamPerDef*ShuFinalDamPerDefRatio+WuFinalDamPer*WuFinalDamPerRatio+WuFinalDamPerDef*WuFinalDamPerDefRatio+QunFinalDamPer*QunFinalDamPerRatio+QunFinalDamPerDef*QunFinalDamPerDefRatio)/100.0-55000)
    // 技能战斗力公式
    // SkillPower*OfficialLV
    public static double GetBaseAttr(Dictionary<string, double> variables)
    {
        double lvValue = variables["lvValue"];
        double equipValue = variables["equipValue"];
        double bookValue = variables["bookValue"];
@@ -55,7 +56,7 @@
        double awakeTalentValue = variables["awakeTalentValue"];
        double fetterValue = variables["fetterValue"];
        return lvValue + equipValue + bookValue + realmValue + gubaoValue + hjgValue + horseValue + (heroSelfValue + lineupHaloValue + starTalentValue + breakLVValue + awakeTalentValue) + fetterValue;
        return (lvValue+equipValue+bookValue+realmValue+gubaoValue+hjgValue+horseValue)+(heroSelfValue+lineupHaloValue+starTalentValue+breakLVValue+awakeTalentValue)+fetterValue;
    }
    public static double GetFightPower(Dictionary<string, double> variables)
@@ -143,16 +144,15 @@
        double QunFinalDamPerDef = variables["QunFinalDamPerDef"];
        double QunFinalDamPerDefRatio = variables["QunFinalDamPerDefRatio"];
        return Atk * AtkRatio + MaxHP * MaxHPRatio + Def * DefRatio + (StunRate * StunRateRatio + SuperHitRate * SuperHitRateRatio + ComboRate * ComboRateRatio + MissRate * MissRateRatio + ParryRate * ParryRateRatio + SuckHPPer * SuckHPPerRatio + StunRateDef * StunRateDefRatio + SuperHitRateDef * SuperHitRateDefRatio + ComboRateDef * ComboRateDefRatio + MissRateDef * MissRateDefRatio + ParryRateDef * ParryRateDefRatio + SuckHPPerDef * SuckHPPerDefRatio + FinalDamPer * FinalDamPerRatio + FinalDamPerDef * FinalDamPerDefRatio + PhyDamPer * PhyDamPerRatio + PhyDamPerDef * PhyDamPerDefRatio + MagDamPer * MagDamPerRatio + MagDamPerDef * MagDamPerDefRatio + NormalSkillPer * NormalSkillPerRatio + NormalSkillPerDef * NormalSkillPerDefRatio + AngerSkillPer * AngerSkillPerRatio + AngerSkillPerDef * AngerSkillPerDefRatio + SuperDamPer * SuperDamPerRatio + SuperDamPerDef * SuperDamPerDefRatio + CurePer * CurePerRatio + CurePerDef * CurePerDefRatio + ShieldPer * ShieldPerRatio + ShieldPerDef * ShieldPerDefRatio + DOTPer * DOTPerRatio + DOTPerDef * DOTPerDefRatio + WeiFinalDamPer * WeiFinalDamPerRatio + WeiFinalDamPerDef * WeiFinalDamPerDefRatio + ShuFinalDamPer * ShuFinalDamPerRatio + ShuFinalDamPerDef * ShuFinalDamPerDefRatio + WuFinalDamPer * WuFinalDamPerRatio + WuFinalDamPerDef * WuFinalDamPerDefRatio + QunFinalDamPer * QunFinalDamPerRatio + QunFinalDamPerDef * QunFinalDamPerDefRatio) / 100.0 - 55000;
        return (long)(Atk*AtkRatio+MaxHP*MaxHPRatio+Def*DefRatio+(StunRate*StunRateRatio+SuperHitRate*SuperHitRateRatio+ComboRate*ComboRateRatio+MissRate*MissRateRatio+ParryRate*ParryRateRatio+SuckHPPer*SuckHPPerRatio+StunRateDef*StunRateDefRatio+SuperHitRateDef*SuperHitRateDefRatio+ComboRateDef*ComboRateDefRatio+MissRateDef*MissRateDefRatio+ParryRateDef*ParryRateDefRatio+SuckHPPerDef*SuckHPPerDefRatio+FinalDamPer*FinalDamPerRatio+FinalDamPerDef*FinalDamPerDefRatio+PhyDamPer*PhyDamPerRatio+PhyDamPerDef*PhyDamPerDefRatio+MagDamPer*MagDamPerRatio+MagDamPerDef*MagDamPerDefRatio+NormalSkillPer*NormalSkillPerRatio+NormalSkillPerDef*NormalSkillPerDefRatio+AngerSkillPer*AngerSkillPerRatio+AngerSkillPerDef*AngerSkillPerDefRatio+SuperDamPer*SuperDamPerRatio+SuperDamPerDef*SuperDamPerDefRatio+CurePer*CurePerRatio+CurePerDef*CurePerDefRatio+ShieldPer*ShieldPerRatio+ShieldPerDef*ShieldPerDefRatio+DOTPer*DOTPerRatio+DOTPerDef*DOTPerDefRatio+WeiFinalDamPer*WeiFinalDamPerRatio+WeiFinalDamPerDef*WeiFinalDamPerDefRatio+ShuFinalDamPer*ShuFinalDamPerRatio+ShuFinalDamPerDef*ShuFinalDamPerDefRatio+WuFinalDamPer*WuFinalDamPerRatio+WuFinalDamPerDef*WuFinalDamPerDefRatio+QunFinalDamPer*QunFinalDamPerRatio+QunFinalDamPerDef*QunFinalDamPerDefRatio)/100.0-55000);
    }
    public static double GetSkillsFightPower(Dictionary<string, double> variables)
    {
        double SkillPower = variables["SkillPower"];
        double OfficialLV = variables["OfficialLV"];
        return SkillPower * OfficialLV;
    }
}
Main/System/Main/FightPowerManager.cs
@@ -413,7 +413,7 @@
        }
#if UNITY_EDITOR
        // Debug.Log("战力:计算完毕 " + fightPower);
        Debug.Log("战力:计算完毕 " + fightPower);
#endif
        return fightPower;
    }