public void ActionHandle(BuffHandlerVar buffHandlerVar)
    {
        Buff_CostHP_MP cost = (Buff_CostHP_MP)buffHandlerVar.data;

        if (!buffHandlerVar.GetBufferValue(out BufferValue_TargetUnits targetUnits))
        {
            return;
        }
        foreach (var v in targetUnits.targets)
        {
            Unit             target           = v;
            NumericComponent numericComponent = target.GetComponent <NumericComponent>();
            float            updateHp         = -cost.costHp - cost.costHpInPct * numericComponent.GetAsFloat(NumericType.HPMax_Final);
            float            updateMp         = -cost.costMp - cost.costMpInPct * numericComponent.GetAsFloat(NumericType.MPMax_Final);
            if (updateHp != 0)
            {
                Game.EventSystem.Run(EventIdType.NumbericChange, NumericType.HP, target.Id, updateHp);
            }
            if (updateMp != 0)
            {
                Game.EventSystem.Run(EventIdType.NumbericChange, NumericType.MP, target.Id, updateMp);
            }
        }
    }
    public void ActionHandle(BuffHandlerVar buffHandlerVar)
    {
        Buff_UpdateNumeric buff = (Buff_UpdateNumeric)buffHandlerVar.data;

        if (!buffHandlerVar.GetBufferValue(out BufferValue_TargetUnits bufferValue_TargetUnits))
        {
            return;
        }

        NumericComponent numericComponent = buffHandlerVar.source.GetComponent <NumericComponent>();

        if (buff.addValueByNumeric)
        {
            float value = numericComponent.GetAsFloat(buff.sourceNumeric) * buff.coefficient + buff.valueAdd;

            BuffHandlerVar.cacheDatas_float[(buffHandlerVar.source.Id, buff.buffSignal)] = value;
Esempio n. 3
0
    public bool MeetCondition(BaseSkillData.IActiveConditionData data, Unit source)
    {
        SkillActiveCondition_CheckNumeric checkNumeric = data as SkillActiveCondition_CheckNumeric;
        NumericComponent numericComponent = source.GetComponent <NumericComponent>();

        switch (checkNumeric.realtionType)
        {
        case NumericRealtionType.Greater:
            if (numericComponent.GetAsFloat(checkNumeric.numericType) > checkNumeric.aimValue)
            {
                return(true);
            }
            break;

        case NumericRealtionType.Less:
            if (numericComponent.GetAsFloat(checkNumeric.numericType) < checkNumeric.aimValue)
            {
                return(true);
            }
            break;

        case NumericRealtionType.Equal:
            if (numericComponent.GetAsFloat(checkNumeric.numericType) == checkNumeric.aimValue)
            {
                return(true);
            }
            break;

        case NumericRealtionType.NotEqual:
            if (numericComponent.GetAsFloat(checkNumeric.numericType) != checkNumeric.aimValue)
            {
                return(true);
            }
            break;

        case NumericRealtionType.GreaterEqual:
            if (numericComponent.GetAsFloat(checkNumeric.numericType) >= checkNumeric.aimValue)
            {
                return(true);
            }
            break;

        case NumericRealtionType.LessEqual:
            if (numericComponent.GetAsFloat(checkNumeric.numericType) <= checkNumeric.aimValue)
            {
                return(true);
            }
            break;
        }
        return(false);
    }
Esempio n. 4
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);
    }
    public void ActionHandle(BuffHandlerVar buffHandlerVar)
    {
        Buff_GiveRecover buff = (Buff_GiveRecover)buffHandlerVar.data;

        if (!buffHandlerVar.GetBufferValue(out BufferValue_TargetUnits targetUnits))
        {
            return;
        }

        foreach (var v in targetUnits.targets)
        {
            NumericComponent numericComponent = v.GetComponent <NumericComponent>();
            if (buff.hpValue > 0)
            {
                Game.EventSystem.Run(EventIdType.NumbericChange, NumericType.HP, v.Id, buff.hpValue);
            }
            if (buff.hpPct > 0)
            {
                Game.EventSystem.Run(EventIdType.NumbericChange, NumericType.HP, v.Id, numericComponent.GetAsFloat(NumericType.HPMax_Final) * buff.hpPct);
            }
            if (buff.mpValue > 0)
            {
                Game.EventSystem.Run(EventIdType.NumbericChange, NumericType.MP, v.Id, buff.mpValue);
            }
            if (buff.mpPct > 0)
            {
                Game.EventSystem.Run(EventIdType.NumbericChange, NumericType.MP, v.Id, numericComponent.GetAsFloat(NumericType.MPMax_Final) * buff.mpPct);
            }
        }
    }
    public static bool CalFinalDamage(long sourceUnitId, long destUnitId, DamageData skillDamageValue)
    {
        try
        {
            CharacterStateComponent unitState = UnitComponent.Instance.Get(destUnitId).GetComponent <CharacterStateComponent>();
            if (unitState.Get(SpecialStateType.Die))
            {
                return(false);
            }

            if (unitState.Get(SpecialStateType.Invincible))
            {
                //TODO: 提示无敌状态
                return(false);
            }
            NumericComponent sourceUnitNumericCom = UnitComponent.Instance.Get(sourceUnitId).GetComponent <NumericComponent>();
            NumericComponent destUnitNumericCom   = UnitComponent.Instance.Get(destUnitId).GetComponent <NumericComponent>();
            int rateCharge = 0;
            //命中判定
            float hitRate = sourceUnitNumericCom.GetAsFloat(NumericType.HitRate) - destUnitNumericCom.GetAsFloat(NumericType.DodgeRate);
            rateCharge = RandomHelper.RandomNumber(0, 100);
            if (rateCharge / 100.0f > hitRate)
            {
                Game.EventSystem.Run(EventIdType.AttackMissing, destUnitId);
                Log.Debug("Miss!  命中率 " + hitRate);
                return(false);
            }

            //暴击判定
            //可能有技能提升效果
            if (!skillDamageValue.isCritical)
            {
                float criticalRate = sourceUnitNumericCom.GetAsFloat(NumericType.CritRate);
                rateCharge = RandomHelper.RandomNumber(0, 100);
                if (rateCharge / 100.0f <= criticalRate)
                {
                    //暴击判定通过
                    skillDamageValue.isCritical = true;
                }
            }
            if (skillDamageValue.isCritical)
            {
                skillDamageValue.damageValue = Mathf.RoundToInt(skillDamageValue.damageValue * sourceUnitNumericCom.GetAsFloat(NumericType.CritDamagePct));
            }



            NumericType resistType = NumericType.ArmorResist;

            if (skillDamageValue.damageType != DamageType.Physic)
            {
                resistType = NumericType.MagicResist;
            }
            skillDamageValue.damageValue = Mathf.RoundToInt(skillDamageValue.damageValue * (100.0f / (destUnitNumericCom.GetAsInt(resistType) + 100.0f)));

            //预防可能要考虑什么白字红字,黑字粉字等乱七八糟的情况,所以专门用一个List
            DamageData[] array = new DamageData[1];
            array[0] = skillDamageValue;

            //计算最终伤害加成,减免

            for (int i = 0; i < array.Length; i++)
            {
                var damage = array[i];

                float finalDamagePct = 1 + sourceUnitNumericCom.GetAsFloat(NumericType.FinalDamage_AddPct) - destUnitNumericCom.GetAsFloat(NumericType.FinalDamage_ReducePct);

                damage.damageValue = Mathf.RoundToInt(array[i].damageValue * finalDamagePct);
                //限定最小伤害0
                damage.damageValue = Mathf.Clamp(array[i].damageValue, 0, int.MaxValue);
                array[i]           = damage;
            }


            //给予伤害
            Game.EventSystem.Run(EventIdType.GiveDamage, destUnitId, array);

            //给予吸血,吸法
            float xiQu = sourceUnitNumericCom.GetAsFloat(NumericType.HP_LeechRate);
            if (xiQu > 0)
            {
                Game.EventSystem.Run(EventIdType.GiveHealth, sourceUnitId, Mathf.RoundToInt(skillDamageValue.damageValue * xiQu));
            }
            xiQu = sourceUnitNumericCom.GetAsFloat(NumericType.MP_LeechRate);
            if (xiQu > 0)
            {
                Game.EventSystem.Run(EventIdType.GiveMp, sourceUnitId, Mathf.RoundToInt(skillDamageValue.damageValue * xiQu));
            }
            return(true);
        }
        catch (Exception e)
        {
            Debug.LogError(e.ToString());
            return(false);
        }
    }