Пример #1
0
 public override void EndInit()
 {
     for (int i = 0; i < list.Count; i++)
     {
         FormulaConfig config = list[i];
         config.EndInit();
         this.dict.Add(config.Id, config);
     }
     this.AfterEndInit();
 }
Пример #2
0
        /// <summary>
        /// 进入触发器
        /// </summary>
        /// <param name="from"></param>
        /// <param name="to"></param>
        /// <param name="stepPara"></param>
        /// <param name="costId"></param>
        /// <param name="cost"></param>
        /// <param name="config"></param>
        public void OnColliderIn(AOIUnitComponent from, AOIUnitComponent to, SkillStepPara stepPara, List <int> costId,
                                 List <int> cost, SkillConfig config)
        {
            var combatU = to.Parent.GetComponent <CombatUnitComponent>();

            // Log.Info("触发"+type.ToString()+to.Id+"  "+from.Id);
            // Log.Info("触发"+type.ToString()+to.Position+" Dis: "+Vector3.Distance(to.Position,from.Position));
            int formulaId = 0;//公式

            if (stepPara.Paras.Length > 1)
            {
                int.TryParse(stepPara.Paras[1].ToString(), out formulaId);
            }
            float percent = 1;//实际伤害百分比

            if (stepPara.Paras.Length > 2)
            {
                float.TryParse(stepPara.Paras[2].ToString(), out percent);
            }

            int maxNum = 0;

            if (stepPara.Paras.Length > 3)
            {
                int.TryParse(stepPara.Paras[3].ToString(), out maxNum);
            }

            if (maxNum != 0 && stepPara.Count >= maxNum)
            {
                return;                                         //超上限
            }
            stepPara.Count++;

            List <int[]> buffInfo = null;//添加的buff

            if (stepPara.Paras.Length > 4)
            {
                buffInfo = stepPara.Paras[4] as List <int[]>;
                if (buffInfo == null)
                {
                    string[] vs = stepPara.Paras[4].ToString().Split(';');
                    buffInfo = new List <int[]>();
                    for (int i = 0; i < vs.Length; i++)
                    {
                        var   data = vs[i].Split(',');
                        int[] temp = new int[data.Length];
                        for (int j = 0; j < data.Length; j++)
                        {
                            temp[j] = int.Parse(data[i]);
                        }
                        buffInfo.Add(temp);
                    }
                    stepPara.Paras[4] = buffInfo;
                }
            }

            if (buffInfo != null && buffInfo.Count > 0)
            {
                var buffC = combatU.GetComponent <BuffComponent>();

                for (int i = 0; i < buffInfo.Count; i++)
                {
                    buffC.AddBuff(buffInfo[i][0], TimeHelper.ClientNow() + buffInfo[i][1]);
                }
            }

            FormulaConfig formula = FormulaConfigCategory.Instance.Get(formulaId);

            if (formula != null)
            {
                FormulaStringFx  fx    = FormulaStringFx.GetInstance(formula.Formula);
                NumericComponent f     = from.GetParent <Unit>().GetComponent <NumericComponent>();
                NumericComponent t     = to?.GetParent <Unit>().GetComponent <NumericComponent>();
                float            value = fx.GetData(f, t);

                int realValue = (int)value;

                if (realValue != 0)
                {
                    float now = t.GetAsFloat(NumericType.HpBase);
                    Log.Info(now);
                    if (now <= realValue)
                    {
                        t.Set(NumericType.HpBase, 0);
                    }
                    else
                    {
                        t.Set(NumericType.HpBase, now - realValue);
                    }

                    EventSystem.Instance.Publish(new EventType.AfterCombatUnitGetDamage()
                    {
                        From  = from.Parent.GetComponent <CombatUnitComponent>(),
                        Unit  = combatU,
                        Value = realValue
                    });
                }
            }
        }
Пример #3
0
        public void Run(SkillPara para)
        {
#if SERVER
            Log.Info("SkillWatcher_Cost");
            if (para.StepPara[para.CurIndex].Paras.Length != 3)
            {
                Log.Error(para.Ability.SkillConfig.Id + "技能配置消耗属性和公式数量不对");
                return;
            }

            var stepPara = para.StepPara[para.CurIndex];
            var idKey    = stepPara.Paras[0].ToString();
            if (NumericType.Map.TryGetValue(idKey, out int attrId))
            {
                var cost          = 0;
                var costFormulaId = int.Parse(stepPara.Paras[2].ToString());
                var costNum       = int.Parse(stepPara.Paras[1].ToString());
                if (attrId < NumericType.Max)
                {
                    attrId = attrId * 10 + 1;
                }
                FormulaConfig formula = FormulaConfigCategory.Instance.Get(costFormulaId);
                if (formula != null)
                {
                    FormulaStringFx  fx = FormulaStringFx.GetInstance(formula.Formula);
                    NumericComponent f  = para.From.unit.GetComponent <NumericComponent>();
                    NumericComponent t  = para.To?.unit.GetComponent <NumericComponent>();
                    cost = (int)fx.GetData(f, t) + costNum;
                    float now = f.GetAsFloat(attrId);
                    if (cost > 0) //扣
                    {
                        if (now < cost)
                        {
                            f.Set(attrId, 0);
                        }
                        else
                        {
                            f.Set(attrId, now - cost);
                        }
                    }
                    else if (cost < 0)//加
                    {
                        float max = f.GetAsFloat(attrId);
                        if (now + cost >= max)
                        {
                            f.Set(attrId, max);
                        }
                        else
                        {
                            f.Set(attrId, now + cost);
                        }
                    }
                }
                else
                {
                    Log.Error("公式未配置");
                }
                para.Cost.Add(cost);
                para.CostId.Add(attrId);
            }
            else
            {
                Log.Error(idKey + " 未配置");
            }
#endif
        }