Beispiel #1
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}");
            }
        }
Beispiel #2
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();
        }
Beispiel #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();
        }
Beispiel #4
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);
        }
Beispiel #5
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();
        }
Beispiel #6
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);
        }
Beispiel #7
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}");
            }
        }
        /// <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
                    });
                }
            }
        }
Beispiel #9
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);
        }
Beispiel #10
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
        }