示例#1
0
    /// 计算结果,传入的Dictionary中必须包含所有信息//
    public float GetData(NumericComponent comp, NumericComponent other)
    {
        ListComponent <int> priorityList = ListComponent <int> .Create();

        ListComponent <FormulaNode> tempList = ListComponent <FormulaNode> .Create();

        for (int i = 0; i < formulaNodeList.Count; i++)
        {
            FormulaNode node = new FormulaNode(formulaNodeList[i].Key, formulaNodeList[i].Value, formulaNodeList[i].IsSelf);
            tempList.Add(node);
        }


        for (int i = 0; i < tempList.Count; i++)
        {
            if (!float.TryParse(tempList[i].Value, out _))
            {
                if (NumericType.Map.TryGetValue(tempList[i].Value, out int type))
                {
                    if (tempList[i].IsSelf)
                    {
                        tempList[i].Value = comp.GetAsFloat(type).ToString();
                    }
                    else if (other != null)
                    {
                        tempList[i].Value = other.GetAsFloat(type).ToString();
                    }
                    else
                    {
                        tempList[i].Value = "0";
                        Log.Error("计算伤害未传入目标");
                    }
                }
            }

            if (tempList[i].Key != 0 && !priorityList.Contains(tempList[i].Key))
            {
                priorityList.Add(tempList[i].Key);
            }
        }
        priorityList.Sort();

        while (priorityList.Count > 0)
        {
            int  currentpri = priorityList[priorityList.Count - 1];
            bool hasfind    = false;
            do
            {
                hasfind = false;
                for (int i = 0; i < tempList.Count && tempList.Count >= 3; i++)
                {
                    if (tempList[i].Key == currentpri && GetPriority(tempList[i].Value) != 0)
                    {
                        float final      = GetOperactorFinal(tempList[i - 1].Value, tempList[i].Value, tempList[i + 1].Value);
                        var   newformula = new FormulaNode(tempList[i - 1].Key, final.ToString());
                        tempList.RemoveRange(i - 1, 3);
                        tempList.Insert(i - 1, newformula);
                        hasfind = true;
                        break;
                    }
                }
            } while (hasfind);

            priorityList.RemoveAt(priorityList.Count - 1);
            priorityList.Sort();
        }

        if (tempList.Count == 0)
        {
#if UNITY_EDITOR
            //			UnityEngine.Debug.LogError("FormulaString is Error string = "+ lastFormatString);
#endif
            return(0);
        }
        string outstring = tempList[0].Value;// + formulaNodeList.Count.ToString();
        float  finalnum  = 0;
        if (!float.TryParse(outstring, out finalnum))
        {
#if UNITY_EDITOR
            //			UnityEngine.Debug.Log(outstring);
#endif
            finalnum = 0;
        }
        priorityList.Dispose();
        tempList.Dispose();
        return(finalnum);
    }