Пример #1
0
        public static Unit Create(Entity domain, UnitInfo unitInfo)
        {
            Unit unit = EntityFactory.CreateWithId <Unit, int>(domain, unitInfo.UnitId, unitInfo.ConfigId);

            unit.Position = new Vector3(unitInfo.X, unitInfo.Y, unitInfo.Z);

            unit.AddComponent <MoveComponent>();
            NumericComponent numericComponent = unit.AddComponent <NumericComponent>();

            for (int i = 0; i < unitInfo.Ks.Count; ++i)
            {
                numericComponent.Set((NumericType)unitInfo.Ks[i], unitInfo.Vs[i]);
            }

            unit.AddComponent <ObjectWait>();

            unit.AddComponent <XunLuoPathComponent>();

            UnitComponent unitComponent = domain.GetComponent <UnitComponent>();

            unitComponent.Add(unit);

            Game.EventSystem.Publish(new EventType.AfterUnitCreate()
            {
                Unit = unit
            });
            return(unit);
        }
Пример #2
0
        public static DUnit Create(Entity domain, DUnitInfo unitInfo)
        {
            DUnit tower = DUnitFactory.Create(domain, unitInfo.UnitId);

            // 位置信息
            tower.Position = new Vector3(unitInfo.PX, unitInfo.PY, unitInfo.PZ);
            tower.Rotation = new Quaternion(unitInfo.RX, unitInfo.RY, unitInfo.RZ, unitInfo.RW);
            // 类型信息
            tower.AddComponent <UnitTypeComponent, UnitType>(UnitType.UnitTower);
            // 配置信息
            tower.AddComponent <UTowerConfigComponent, int>(unitInfo.ConfigId);
            // 运算者
            tower.AddComponent <OperationerComponent, long>(unitInfo.OperationerId);
            // 阵营信息
            tower.AddComponent <CampComponent, long, CampType>(unitInfo.GamerId, (CampType)unitInfo.Camp);
            // 数值信息
            TowerHelper.InitTowerNumberic(tower);
            // 血量恢复
            NumericComponent numeric = tower.GetComponent <NumericComponent>();

            tower.AddComponent <HPRegainComponent, int>(numeric.GetAsInt(NumericType.HPRegain));

            // 触发创建完成事件
            Game.EventSystem.Publish(new AppEventType.AfterTowerCreate()
            {
                Unit = tower
            }).Coroutine();

            return(tower);
        }
Пример #3
0
        protected override async ETTask Run(Scene scene, G2M_CreateUnit request, M2G_CreateUnit response, Action reply)
        {
            Unit unit = EntityFactory.CreateWithId <Unit, int>(scene, IdGenerater.Instance.GenerateId(), 1001);

            unit.AddComponent <MoveComponent>();
            unit.Position = new Vector3(-10, 0, -10);

            NumericComponent numericComponent = unit.AddComponent <NumericComponent>();

            numericComponent.Set(NumericType.Speed, 6f);             // 速度是6米每秒

            unit.AddComponent <MailBoxComponent>();
            await unit.AddLocation();

            unit.AddComponent <UnitGateComponent, long>(request.GateSessionId);
            scene.GetComponent <UnitComponent>().Add(unit);
            response.UnitId = unit.Id;

            // 把自己广播给周围的人
            M2C_CreateUnits createUnits = new M2C_CreateUnits();

            createUnits.Units.Add(UnitHelper.CreateUnitInfo(unit));
            MessageHelper.Broadcast(unit, createUnits);

            // 把周围的人通知给自己
            createUnits.Units.Clear();
            Unit[] units = scene.GetComponent <UnitComponent>().GetAll();
            foreach (Unit u in units)
            {
                createUnits.Units.Add(UnitHelper.CreateUnitInfo(u));
            }
            MessageHelper.SendActor(unit.GetComponent <UnitGateComponent>().GateSessionActorId, createUnits);

            reply();
        }
Пример #4
0
        public static void Insert(this NumericComponent self, int numericType, long value, bool isPublicEvent = true)
        {
            long oldValue = self.GetByKey(numericType);

            if (oldValue == value)
            {
                return;
            }

            self.NumericDic[numericType] = value;

            if (numericType >= NumericType.Max)
            {
                self.Update(numericType, isPublicEvent);
                return;
            }

            if (isPublicEvent)
            {
                Game.EventSystem.Publish(self.DomainScene(),
                                         new EventType.NumbericChange()
                {
                    Unit = self.GetParent <Unit>(), New = value, Old = oldValue, NumericType = numericType
                });
            }
        }
Пример #5
0
        public static Unit Create(Scene scene, long id, UnitType unitType)
        {
            UnitComponent unitComponent = scene.GetComponent <UnitComponent>();

            switch (unitType)
            {
            case UnitType.Player:
            {
                Unit unit = unitComponent.AddChildWithId <Unit, int>(id, 1001);
                unit.AddComponent <MoveComponent>();
                unit.Position = new Vector3(-10, 0, -10);

                NumericComponent numericComponent = unit.AddComponent <NumericComponent>();
                numericComponent.Set(NumericType.Speed, 6f);     // 速度是6米每秒
                numericComponent.Set(NumericType.AOI, 15000);    // 视野15米

                unitComponent.Add(unit);
                // 加入aoi
                unit.AddComponent <AOIEntity, int, Vector3>(9 * 1000, unit.Position);
                return(unit);
            }

            default:
                throw new Exception($"not such unit type: {unitType}");
            }
        }
Пример #6
0
        public static void Insert(this NumericComponent self, int numericType, long value, bool isPublicEvent = true)
        {
            long oldValue = self.GetByKey(numericType);

            if (oldValue == value)
            {
                return;
            }

            self.NumericDic[numericType] = value;

            if (numericType >= NumericType.Max)
            {
                self.Update(numericType, isPublicEvent);
                return;
            }

            if (isPublicEvent)
            {
                EventType.NumbericChange args = EventType.NumbericChange.Instance;
                args.Parent      = self.Parent;
                args.NumericType = numericType;
                args.Old         = oldValue;
                args.New         = value;
                Game.EventSystem.PublishClass(args);
            }
        }
Пример #7
0
        public static long GetByKey(this NumericComponent self, int key)
        {
            long value = 0;

            self.NumericDic.TryGetValue(key, out value);
            return(value);
        }
Пример #8
0
        protected override async ETTask Run(Scene scene, G2M_CreateUnit request, M2G_CreateUnit response, Action reply)
        {
            UnitComponent unitComponent = scene.GetComponent <UnitComponent>();
            Unit          unit          = unitComponent.AddChildWithId <Unit, int>(IdGenerater.Instance.GenerateId(), 1001);

            unit.AddComponent <MoveComponent>();
            unit.AddComponent <PathfindingComponent, string>("solo");
            unit.Position = new Vector3(-10, 0, -10);

            NumericComponent numericComponent = unit.AddComponent <NumericComponent>();

            numericComponent.Set(NumericType.Speed, 6f);             // 速度是6米每秒
            numericComponent.Set(NumericType.AOI, 15000);            // 视野15米

            unit.AddComponent <MailBoxComponent>();
            await unit.AddLocation();

            unit.AddComponent <UnitGateComponent, long>(request.GateSessionId);
            unitComponent.Add(unit);
            // 加入aoi
            unit.AddComponent <AOIEntity, int, Vector3>(9 * 1000, unit.Position);

            M2C_CreateUnits m2CCreateUnits = new M2C_CreateUnits();

            m2CCreateUnits.Units.Add(UnitHelper.CreateUnitInfo(unit));
            MessageHelper.SendToClient(unit, m2CCreateUnits);

            response.MyId = unit.Id;

            reply();
        }
Пример #9
0
 public static void Set(this NumericComponent self, int nt, long value, bool isRealValue = false)
 {
     if (!isRealValue && self.IsFloat(nt))
     {
         self[nt] = value * 10000;
     }
     else
     {
         self[nt] = value;
     }
 }
Пример #10
0
 public static long GetAsLong(this NumericComponent self, int numericType)
 {
     if (self.IsFloat(numericType))
     {
         return(self.GetByKey(numericType) / 10000);
     }
     else
     {
         return(self.GetByKey(numericType));
     }
 }
Пример #11
0
 public static int GetAsInt(this NumericComponent self, int numericType)
 {
     if (self.IsFloat(numericType))
     {
         return((int)self.GetByKey(numericType) / 10000);
     }
     else
     {
         return((int)self.GetByKey(numericType));
     }
 }
Пример #12
0
        public static void UpdateSkillMaxRadiusTrigger(Skill skill)
        {
            DGameObjectComponent objectcom = skill.GetComponent <DGameObjectComponent>();
            NumericComponent     skillnum  = skill.GetComponent <NumericComponent>();

            float maxradius = skillnum.GetAsFloat(NumericType.MaxRadius);

            ReferenceCollector rc = objectcom.GameObject.GetComponent <ReferenceCollector>();
            GameObject         MaxRadiusTrigger = rc.Get <GameObject>("MaxRadiusTrigger");

            MaxRadiusTrigger.transform.localScale = new Vector3(maxradius, maxradius, maxradius);
        }
Пример #13
0
        public static void Update(this NumericComponent self, int numericType, bool isPublicEvent)
        {
            int final    = (int)numericType / 10;
            int bas      = final * 10 + 1;
            int add      = final * 10 + 2;
            int pct      = final * 10 + 3;
            int finalAdd = final * 10 + 4;
            int finalPct = final * 10 + 5;

            // 一个数值可能会多种情况影响,比如速度,加个buff可能增加速度绝对值100,也有些buff增加10%速度,所以一个值可以由5个值进行控制其最终结果
            // final = (((base + add) * (100 + pct) / 100) + finalAdd) * (100 + finalPct) / 100;
            long result = (long)(((self.GetByKey(bas) + self.GetByKey(add)) * (100 + self.GetAsFloat(pct)) / 100f + self.GetByKey(finalAdd)) * (100 + self.GetAsFloat(finalPct)) / 100f);

            self.Insert(final, result, isPublicEvent);
        }
Пример #14
0
        /// <summary>
        /// 读表判断是取整还是保留小数
        /// </summary>
        /// <param name="numericType"></param>
        /// <returns></returns>
        public static bool IsFloat(this NumericComponent self, int numericType)
        {
            if (numericType > NumericType.Max)
            {
                var flag = numericType % 10;
                if (flag == 3 || flag == 5)
                {
                    return(true);                                       //百分比的是小数,否则看配置表
                }
                numericType /= 10;
            }
            var attr = AttributeConfigCategory.Instance.Get(numericType);

            return(attr.Type == 1);
        }
Пример #15
0
        public static void RefreshUI(this InfoComponent self)
        {
            Unit             parent = self.GetParent <Unit>();
            NumericComponent nc     = parent.GetComponent <NumericComponent>();

            if (nc == null)
            {
                Log.Info("RefreshHP " + parent.Id + " 上没有添加 NumericComponent组件");
                return;
            }
            self.Num.text = nc.GetAsInt(NumericType.Hp).ToString();
            float fCurrentHpPercent = nc.GetAsFloat(NumericType.Hp) / nc.GetAsFloat(NumericType.MaxHp);

            self.HpBg.fillAmount = fCurrentHpPercent;
        }
Пример #16
0
        public static Unit Create(Scene currentScene, UnitInfo unitInfo)
        {
            UnitComponent unitComponent = currentScene.GetComponent <UnitComponent>();
            Unit          unit          = unitComponent.AddChildWithId <Unit, int>(unitInfo.UnitId, unitInfo.ConfigId);

            unitComponent.Add(unit);

            unit.Position = new Vector3(unitInfo.X, unitInfo.Y, unitInfo.Z);
            unit.Forward  = new Vector3(unitInfo.ForwardX, unitInfo.ForwardY, unitInfo.ForwardZ);

            NumericComponent numericComponent = unit.AddComponent <NumericComponent>();

            for (int i = 0; i < unitInfo.Ks.Count; ++i)
            {
                numericComponent.Set(unitInfo.Ks[i], unitInfo.Vs[i]);
            }

            unit.AddComponent <MoveComponent>();
            if (unitInfo.MoveInfo != null)
            {
                if (unitInfo.MoveInfo.X.Count > 0)
                {
                    using (ListComponent <Vector3> list = ListComponent <Vector3> .Create())
                    {
                        list.Add(unit.Position);
                        for (int i = 0; i < unitInfo.MoveInfo.X.Count; ++i)
                        {
                            list.Add(new Vector3(unitInfo.MoveInfo.X[i], unitInfo.MoveInfo.Y[i], unitInfo.MoveInfo.Z[i]));
                        }

                        unit.MoveToAsync(list).Coroutine();
                    }
                }
            }

            unit.AddComponent <ObjectWait>();

            unit.AddComponent <XunLuoPathComponent>();

            Game.EventSystem.Publish(new EventType.AfterUnitCreate()
            {
                Unit = unit
            });
            return(unit);
        }
Пример #17
0
        public static UnitInfo CreateUnitInfo(Unit unit)
        {
            UnitInfo         unitInfo = new UnitInfo();
            NumericComponent nc       = unit.GetComponent <NumericComponent>();

            unitInfo.UnitId   = unit.Id;
            unitInfo.ConfigId = unit.ConfigId;
            unitInfo.Type     = (int)unit.Type;
            Vector3 position = unit.Position;

            unitInfo.X = position.x;
            unitInfo.Y = position.y;
            unitInfo.Z = position.z;
            Vector3 forward = unit.Forward;

            unitInfo.ForwardX = forward.x;
            unitInfo.ForwardY = forward.y;
            unitInfo.ForwardZ = forward.z;

            MoveComponent moveComponent = unit.GetComponent <MoveComponent>();

            if (moveComponent != null)
            {
                if (!moveComponent.IsArrived())
                {
                    unitInfo.MoveInfo = new MoveInfo();
                    for (int i = moveComponent.N; i < moveComponent.Targets.Count; ++i)
                    {
                        Vector3 pos = moveComponent.Targets[i];
                        unitInfo.MoveInfo.X.Add(pos.x);
                        unitInfo.MoveInfo.Y.Add(pos.y);
                        unitInfo.MoveInfo.Z.Add(pos.z);
                    }
                }
            }

            foreach ((int key, long value) in nc.NumericDic)
            {
                unitInfo.Ks.Add(key);
                unitInfo.Vs.Add(value);
            }

            return(unitInfo);
        }
Пример #18
0
        public static void InitProperty(this Skill self)
        {
            // 所属Unit
            self.Self = self.GetParent <SkillComponent>().GetParent <DUnit>();
            // 技能状态初始化
            self.SetSkillState(SkillState.SkillWait);
            // 是否循环使用
            self.SkillLoop = self.SkillConfig.SkillLoop > 0 ? true : false;
            // 技能伤害类型
            self.SkillDamageType = SkillDamageTypeHelper.GetSkillDamageType(self.SkillConfig.DamageType);
            // 目标阵营
            self.TargetCamp = SkillTargetHelper.GetTargetCamp(self.SkillConfig.TargetCamp);
            // 目标类型
            self.TargetType = SkillTargetHelper.GetTargetType(self.SkillConfig.TargetType);

            NumericComponent numeric = self.AddComponent <NumericComponent>();
            SkillConfig      config  = self.SkillConfig;

            // 最大攻击半径
            numeric.Set(NumericType.MaxRadiusBase, config.MaxRadius);

            // 基础技能时长
            numeric.Set(NumericType.SkillTimeBase, config.SkillTime);

            // 伤害范围缩放
            if (self.SkillDamageType != SkillDamageType.Target)
            {
                JsonData damageScale = JsonMapper.ToObject(config.DamageScale);
                numeric.Set(NumericType.ScaleXBase, (float)damageScale["x"]);
                numeric.Set(NumericType.ScaleYBase, (float)damageScale["y"]);
                numeric.Set(NumericType.ScaleZBase, (float)damageScale["z"]);
            }

            // 触发创建完成事件
            Game.EventSystem.Publish(new AppEventType.AfterSkillCreate()
            {
                Skill = self
            }).Coroutine();
        }
Пример #19
0
        public static Unit Create(Scene scene, long id, UnitType unitType)
        {
            UnitComponent unitComponent = scene.GetComponent <UnitComponent>();

            switch (unitType)
            {
            case UnitType.Player:
            {
                Unit unit = unitComponent.AddChildWithId <Unit, int>(id, 1);
                //ChildType测试代码 取消注释 编译Server.hotfix 可发现报错
                //unitComponent.AddChild<Player, string>("Player");
                unit.AddComponent <MoveComponent>();
                unit.Position = new Vector3(-10, 0, -10);

                NumericComponent numericComponent = unit.AddComponent <NumericComponent>();
                numericComponent.Set(NumericType.SpeedBase, 6f);   // 速度是6米每秒
                numericComponent.Set(NumericType.AOIBase, 2);      // 视野2格
                numericComponent.Set(NumericType.HpBase, 1000);    // 生命1000
                numericComponent.Set(NumericType.MaxHpBase, 1000); // 最大生命1000
                numericComponent.Set(NumericType.LvBase, 1);       //1级
                numericComponent.Set(NumericType.ATKBase, 100);    //100攻击
                numericComponent.Set(NumericType.DEFBase, 500);    //500防御
                var SkillIds = new List <int>()
                {
                    1001, 1002, 1003, 1004
                };                                                      //初始技能
                unit.AddComponent <CombatUnitComponent, List <int> >(SkillIds);
                unitComponent.Add(unit);
                // 进入地图再加入aoi

                return(unit);
            }

            default:
                throw new Exception($"not such unit type: {unitType}");
            }
        }
Пример #20
0
        public static void UpdateDamageTrigger(Skill skill)
        {
            DGameObjectComponent objectcom = skill.GetComponent <DGameObjectComponent>();
            ReferenceCollector   rc        = objectcom.GameObject.GetComponent <ReferenceCollector>();

            GameObject trigger = null;

            switch (skill.SkillDamageType)
            {
            case SkillDamageType.TargetArea:
                trigger = rc.Get <GameObject>("TargetAreaTrigger");
                break;

            case SkillDamageType.CasterArea:
                trigger = rc.Get <GameObject>("CasterAreaTrigger");
                break;

            case SkillDamageType.CasterFront:
                trigger = rc.Get <GameObject>("CasterFrontTrigger");
                break;
            }

            if (trigger == null)
            {
                return;
            }

            NumericComponent skillnum = skill.GetComponent <NumericComponent>();

            float scalex = skillnum.GetAsFloat(NumericType.ScaleX);
            float scaley = skillnum.GetAsFloat(NumericType.ScaleY);
            float scalez = skillnum.GetAsFloat(NumericType.ScaleX);

            trigger.SetActive(true);
            trigger.transform.localScale = new Vector3(scalex, scaley, scalez);
        }
Пример #21
0
        public override void Update(HPRegainComponent self)
        {
            if (self.BeStart)
            {
                // 按秒恢复
                long disTime = TimeHelper.ClientNow() - self.StartMilliseconds;
                if (disTime > 1000)
                {
                    DUnit            tower = self.GetParent <DUnit>();
                    NumericComponent nm    = tower.GetComponent <NumericComponent>();
                    int hpMax = nm.GetAsInt(NumericType.MaxHp);
                    int hp    = nm.GetAsInt(NumericType.Hp);
                    // 到最大值,不再恢复
                    if (hp >= hpMax)
                    {
                        return;
                    }

                    // 确认恢复值
                    int hpRegain = ((int)disTime / 1000) * self.HpRegain;
                    if (hp + hpRegain > hpMax)
                    {
                        hpRegain = hpMax - hp;
                    }

                    // 设置增量值
                    int hpAdd = nm.GetAsInt(NumericType.HpAdd) + hpRegain;
                    NumericAction.SetUnitNumericAction(tower, NumericType.HpAdd, hpAdd);

                    // 矫正剩余时间
                    int extTime = (int)disTime % 1000;
                    self.StartMilliseconds = TimeHelper.ClientNow() - extTime;
                }
                return;
            }
        }
Пример #22
0
 public static float GetAsFloat(this NumericComponent self, int numericType)
 {
     return((float)self.GetByKey(numericType) / 10000);
 }
Пример #23
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
        }
Пример #24
0
 public static void SetNoEvent(this NumericComponent self, int numericType, long value)
 {
     self.Insert(numericType, value, false);
 }
Пример #25
0
 public static void Set(this NumericComponent self, int nt, long value)
 {
     self[nt] = value;
 }
Пример #26
0
 public static void Set(this NumericComponent self, int nt, float value)
 {
     self[nt] = (int)(value * 10000);
 }
Пример #27
0
 public static long GetAsLong(this NumericComponent self, int numericType)
 {
     return(self.GetByKey(numericType));
 }
Пример #28
0
 public static int GetAsInt(this NumericComponent self, int numericType)
 {
     return((int)self.GetByKey(numericType));
 }
Пример #29
0
        public static Unit Create(Scene currentScene, UnitInfo unitInfo)
        {
            UnitComponent unitComponent = currentScene.GetComponent <UnitComponent>();
            Unit          unit          = unitComponent.AddChildWithId <Unit, int>(unitInfo.UnitId, unitInfo.ConfigId);

            unitComponent.Add(unit);

            unit.Position = new Vector3(unitInfo.X, unitInfo.Y, unitInfo.Z);
            unit.Forward  = new Vector3(unitInfo.ForwardX, unitInfo.ForwardY, unitInfo.ForwardZ);
            switch (unit.Type)
            {
            case UnitType.Monster:
            case UnitType.Player:
            {
                NumericComponent numericComponent = unit.AddComponent <NumericComponent>();
                for (int i = 0; i < unitInfo.Ks.Count; ++i)
                {
                    if (unitInfo.Ks[i] > NumericType.Max)                 //不需要同步最终值
                    {
                        numericComponent.Set(unitInfo.Ks[i], unitInfo.Vs[i], true);
                    }
                }

                unit.AddComponent <MoveComponent>();
                if (unitInfo.MoveInfo != null)
                {
                    if (unitInfo.MoveInfo.X.Count > 0)
                    {
                        using (ListComponent <Vector3> list = ListComponent <Vector3> .Create())
                        {
                            list.Add(unit.Position);
                            for (int i = 0; i < unitInfo.MoveInfo.X.Count; ++i)
                            {
                                list.Add(new Vector3(unitInfo.MoveInfo.X[i], unitInfo.MoveInfo.Y[i], unitInfo.MoveInfo.Z[i]));
                            }

                            unit.MoveToAsync(list).Coroutine();
                        }
                    }
                }
                unit.AddComponent <AOIUnitComponent, Vector3, Quaternion, UnitType>(unit.Position, unit.Rotation, unit.Type);
                CombatUnitComponent combatU;
                if (unitInfo.SkillIds != null)
                {
                    combatU = unit.AddComponent <CombatUnitComponent, List <int> >(unitInfo.SkillIds);
                }
                else
                {
                    combatU = unit.AddComponent <CombatUnitComponent>();
                }

                if (unitInfo.BuffIds != null && unitInfo.BuffIds.Count > 0)
                {
                    var buffC = combatU.GetComponent <BuffComponent>();
                    buffC.Init(unitInfo.BuffIds, unitInfo.BuffTimestamp);
                }

                unit.AddComponent <ObjectWait>();

                unit.AddComponent <XunLuoPathComponent>();
                break;
            }

            case UnitType.Skill:
            {
                NumericComponent numericComponent = unit.AddComponent <NumericComponent>();
                if (unitInfo.Ks != null && unitInfo.Ks.Count > 0)
                {
                    for (int i = 0; i < unitInfo.Ks.Count; ++i)
                    {
                        if (unitInfo.Ks[i] > NumericType.Max)                         //不需要同步最终值
                        {
                            numericComponent.Set(unitInfo.Ks[i], unitInfo.Vs[i], true);
                        }
                    }
                }
                unit.AddComponent <MoveComponent>();
                if (unitInfo.MoveInfo != null && unitInfo.MoveInfo.X.Count > 0)
                {
                    using (ListComponent <Vector3> list = ListComponent <Vector3> .Create())
                    {
                        list.Add(unit.Position);
                        for (int i = 0; i < unitInfo.MoveInfo.X.Count; ++i)
                        {
                            list.Add(new Vector3(unitInfo.MoveInfo.X[i], unitInfo.MoveInfo.Y[i], unitInfo.MoveInfo.Z[i]));
                        }

                        unit.MoveToAsync(list).Coroutine();
                    }
                }
                unit.AddComponent <AOIUnitComponent, Vector3, Quaternion, UnitType>(unit.Position, unit.Rotation, unit.Type);
                unit.AddComponent <ObjectWait>();
                break;
            }

            default:
            {
                Log.Error("没有处理 " + unit.Type);
                break;
            }
            }
            Game.EventSystem.PublishAsync(new EventType.AfterUnitCreate()
            {
                Unit = unit
            }).Coroutine();
            return(unit);
        }
Пример #30
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
                    });
                }
            }
        }