示例#1
0
        static void SetParaStep(this SkillPara para, int index)
        {
            if (para.Ability == null)
            {
                return;
            }

            var stepPara = new SkillStepPara();

            stepPara.Index    = index;
            stepPara.Paras    = null;
            stepPara.Interval = 0;
            if (para.Ability.Paras != null && index < para.Ability.Paras.Count)
            {
                stepPara.Paras = para.Ability.Paras[index];
            }
            if (para.Ability.TimeLine != null && index < para.Ability.TimeLine.Count)
            {
                stepPara.Interval = para.Ability.TimeLine[index];
            }
            stepPara.Count = 0;

            para.CurIndex = index;
            para.StepPara.Add(stepPara);
        }
示例#2
0
        public static void Run(this SkillWatcherComponent self, int type, SkillPara para)
        {
            List <ISkillWatcher> list;

            if (!self.allWatchers.TryGetValue(type, out list))
            {
                return;
            }
            for (int i = 0; i < list.Count; i++)
            {
                ISkillWatcher numericWatcher = list[i];
                numericWatcher.Run(para);
            }
        }
示例#3
0
        /// <summary>
        /// 创建技能触发体(单机用)
        /// </summary>
        /// <param name="currentScene"></param>
        /// <param name="configId"></param>
        /// <param name="pos"></param>
        /// <param name="rota"></param>
        /// <param name="para"></param>
        /// <returns></returns>
        public static Unit CreateSkillCollider(Scene currentScene, int configId, Vector3 pos, Quaternion rota, SkillPara para)
        {
            UnitComponent unitComponent = currentScene.GetComponent <UnitComponent>();
            Unit          unit          = unitComponent.AddChild <Unit, int>(configId);

            unit.Position = pos;
            unit.Rotation = rota;
            unit.AddComponent <SkillColliderComponent, SkillPara>(para);
            unit.AddComponent <AOIUnitComponent, Vector3, Quaternion, UnitType>(pos, rota, UnitType.Skill);
            return(unit);
        }
示例#4
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
        }
示例#5
0
        public static Unit CreateSkillCollider(Scene currentScene, int configId, Vector3 pos, Quaternion rota, SkillPara para)
        {
            UnitComponent unitComponent = currentScene.GetComponent <UnitComponent>();
            Unit          unit          = unitComponent.AddChild <Unit, int>(configId);

            unit.Position = pos;
            unit.Rotation = rota;
            var collider = SkillJudgeConfigCategory.Instance.Get(configId);

            if (collider.ColliderType == SkillJudgeType.Target)//朝指定位置方向飞行碰撞体
            {
                var numc = unit.AddComponent <NumericComponent>();

                numc.Set(NumericType.SpeedBase, collider.Speed);
                var moveComp = unit.AddComponent <MoveComponent>();
                Log.Info(pos + " " + pos + (para.Position - pos).normalized * collider.Speed * collider.Time / 1000f);
                List <Vector3> target = new List <Vector3>();
                target.Add(pos);
                target.Add(pos + (para.Position - pos).normalized * collider.Speed * collider.Time / 1000f);
                moveComp.MoveToAsync(target, collider.Speed).Coroutine();
            }
            else if (collider.ColliderType == SkillJudgeType.Aim) //锁定目标飞行
            {
                var numc = unit.AddComponent <NumericComponent>();
                numc.Set(NumericType.SpeedBase, collider.Speed);
                unit.AddComponent <MoveComponent>();
                unit.AddComponent <ZhuiZhuAimComponent, Unit, Action>(para.To.unit, () =>
                {
                    unit.Dispose();
                });
                unit.AddComponent <AIComponent, int, int>(2, 50);
            }
            unit.AddComponent <SkillColliderComponent, SkillPara>(para);
            unit.AddComponent <AOIUnitComponent, Vector3, Quaternion, UnitType>(pos, rota, unit.Type);
            return(unit);
        }
        public void Run(SkillPara para)
        {
            int curIndex = para.CurIndex;
            var stepPara = para.StepPara[curIndex];

#if SERVER
            Log.Info("SkillWatcher_GenerateCollider");
            if (int.TryParse(stepPara.Paras[0].ToString(), out var colliderId))
            {
                SkillJudgeConfig collider = SkillJudgeConfigCategory.Instance.Get(colliderId);
                if (collider != null)
                {
                    var     aoiUnit     = para.From.unit.GetComponent <AOIUnitComponent>();
                    var     scene       = aoiUnit.Scene.GetParent <Scene>();
                    Unit    unit        = null;
                    Vector3 FromUnitPos = para.From.unit.Position;
                    Vector3 ToUnitPos   = Vector3.zero;
                    if (para.To != null)
                    {
                        ToUnitPos = para.To.unit.Position;
                    }

                    #region 创建碰撞体AOIUnit

                    if (collider.ColliderType == SkillJudgeType.FixedPosition)//固定位置碰撞体
                    {
                        if (collider.StartPosType == ColliderStartPosType.Self)
                        {
                            unit = UnitFactory.CreateSkillCollider(scene, colliderId, FromUnitPos, para.Rotation, para);
                        }
                        else if (collider.StartPosType == ColliderStartPosType.Aim && para.To != null)
                        {
                            unit = UnitFactory.CreateSkillCollider(scene, colliderId, ToUnitPos, para.Rotation, para);
                        }
                        else if (collider.StartPosType == ColliderStartPosType.MousePos)
                        {
                            unit = UnitFactory.CreateSkillCollider(scene, colliderId, para.Position, para.Rotation, para);
                        }
                        else
                        {
                            Log.Info("目标未指定,或触发体类型不存在");
                            return;
                        }
                    }
                    else if (collider.ColliderType == SkillJudgeType.FixedRotation)//固定方向碰撞体
                    {
                        var dir = new Vector3(para.Position.x - FromUnitPos.x, para.Position.y - FromUnitPos.y, para.Position.z - FromUnitPos.z).normalized;
                        if (collider.ColliderShape == SkillColliderShapeType.OBB)//立方找到中点
                        {
                            var point = FromUnitPos + dir * collider.ColliderPara[2] / 2;
                            if (collider.StartPosType == ColliderStartPosType.Self)
                            {
                                unit = UnitFactory.CreateSkillCollider(scene, colliderId, point, para.Rotation, para);
                            }
                            else
                            {
                                Log.Info("目标未指定,或触发体类型不存在");
                                return;
                            }
                        }
                        else
                        {
                            Log.Info("目标未指定,或触发体类型不存在");
                            return;
                        }
                    }
                    else if (collider.ColliderType == SkillJudgeType.Target)//朝指定位置方向飞行碰撞体
                    {
                        Vector3 startPos = FromUnitPos;
                        if (collider.StartPosType == ColliderStartPosType.Self)
                        {
                            startPos = FromUnitPos;
                        }
                        else if (collider.StartPosType == ColliderStartPosType.Aim && para.To != null)
                        {
                            startPos = ToUnitPos;
                        }
                        else if (collider.StartPosType == ColliderStartPosType.MousePos)
                        {
                            startPos = para.Position;
                        }
                        else
                        {
                            Log.Info("目标未指定,或触发体类型不存在");
                            return;
                        }
                        unit = UnitFactory.CreateSkillCollider(scene, colliderId, startPos, para.Rotation, para);
                    }
                    else if (collider.ColliderType == SkillJudgeType.Aim)//锁定目标飞行
                    {
                        Vector3 startPos = FromUnitPos;
                        if (collider.StartPosType == ColliderStartPosType.Self && para.To != null)
                        {
                            startPos = FromUnitPos;
                        }
                        else if (collider.StartPosType == ColliderStartPosType.Aim && para.To != null)
                        {
                            startPos = ToUnitPos;
                        }
                        else if (collider.StartPosType == ColliderStartPosType.MousePos && para.To != null)
                        {
                            startPos = para.Position;
                        }
                        else
                        {
                            Log.Info("目标未指定,或触发体类型不存在");
                            return;
                        }
                        unit = UnitFactory.CreateSkillCollider(scene, colliderId, startPos, para.Rotation, para);
                    }
                    else if (collider.ColliderType == SkillJudgeType.Immediate) //立刻结算
                    {
                        if (collider.StartPosType == ColliderStartPosType.Self)
                        {
                            EventSystem.Instance.Publish(new EventType.OnSkillTrigger
                            {
                                From   = aoiUnit,
                                To     = aoiUnit,
                                Para   = stepPara,
                                Type   = AOITriggerType.Enter,
                                Config = para.Ability.SkillConfig,
                                Cost   = para.Cost,
                                CostId = para.CostId,
                            });
                        }
                        else if (collider.StartPosType == ColliderStartPosType.Aim && para.To != null)
                        {
                            EventSystem.Instance.Publish(new EventType.OnSkillTrigger
                            {
                                From   = aoiUnit,
                                To     = para.To.unit.GetComponent <AOIUnitComponent>(),
                                Para   = stepPara,
                                Type   = AOITriggerType.Enter,
                                Config = para.Ability.SkillConfig,
                                Cost   = para.Cost,
                                CostId = para.CostId,
                            });
                        }
                        else if (collider.StartPosType == ColliderStartPosType.MousePos)
                        {
                            Log.Error("立刻结算类型,必须指定目标");
                            return;
                        }
                        else
                        {
                            Log.Info("目标未指定,或触发体类型不存在");
                            return;
                        }
                    }
                    else
                    {
                        Log.Error("碰撞体类型未处理" + collider.ColliderType);
                        return;
                    }
                    #endregion
                }
            }
#endif
        }