/// <summary>
        /// 创建诺手
        /// TODO 后期需要改,应该是一个通用的创建英雄接口,只需要提供Id,然后自动索引其所需要的数据(比如技能数据,英雄数据)
        /// </summary>
        /// <returns></returns>
        public static Unit CreateDarius()
        {
            //创建战斗单位
            Unit unit = CreateUnitBase();

            unit.AddComponent <ChildrenUnitComponent>();
            //增加移动组件
            unit.AddComponent <MoveComponent>();
            //增加寻路相关组件
            unit.AddComponent <UnitPathComponent>();

            //增加碰撞体管理组件
            unit.AddComponent <B2S_UnitColliderManagerComponent>();

            unit.GetComponent <B2S_UnitColliderManagerComponent>().CreateCollider(unit,
                                                                                  Game.Scene.GetComponent <ConfigComponent>().Get <Server_B2SCollisionRelationConfig>(10001).B2S_CollisionRelationId, 10006);
            unit.AddComponent <B2S_RoleCastComponent>().RoleCast = RoleCast.Friendly;

            unit.AddComponent <HeroDataComponent, long>(10001);

            unit.AddComponent <BuffManagerComponent>();
            unit.AddComponent <NP_RuntimeTreeManager>();
            unit.AddComponent <SkillCanvasManagerComponent>();

            ConfigComponent configComponent = Game.Scene.GetComponent <ConfigComponent>();

            //Log.Info("开始创建行为树");
            NP_RuntimeTreeFactory.CreateSkillNpRuntimeTree(unit, configComponent.Get <Server_SkillCanvasConfig>(10001).NPBehaveId,
                                                           configComponent.Get <Server_SkillCanvasConfig>(10001).BelongToSkillId)
            .Start();

            NP_RuntimeTreeFactory.CreateSkillNpRuntimeTree(unit, configComponent.Get <Server_SkillCanvasConfig>(10002).NPBehaveId,
                                                           configComponent.Get <Server_SkillCanvasConfig>(10002).BelongToSkillId)
            .Start();

            //默认升一级技能
            unit.GetComponent <SkillCanvasManagerComponent>().AddSkillLevel(configComponent.Get <Server_SkillCanvasConfig>(10002).BelongToSkillId);
            //Log.Info("行为树创建完成");

            //添加栈式状态机组件
            unit.AddComponent <StackFsmComponent>();
            unit.AddComponent <CommonAttackComponent>();

            //设置英雄位置
            unit.Position = new Vector3(-10, 0, -10);
            return(unit);
        }
Beispiel #2
0
        /// <summary>
        /// 创建假人,需要传入一个父UnitId
        /// </summary>
        /// <returns></returns>
        public static Unit CreateSpiling(long parentId)
        {
            Unit unit = CreateUnitBase();

            //Log.Info($"服务端响应木桩请求,父id为{message.ParentUnitId}");
            UnitComponent.Instance.Get(parentId).GetComponent <ChildrenUnitComponent>().AddUnit(unit);
            //Log.Info("确认找到了请求的父实体");
            //为Unit附加碰撞体
            CreateColliderUnit(unit, Game.Scene.GetComponent <ConfigComponent>().Get <Server_B2SCollisionRelationConfig>(10001).B2S_CollisionRelationId,
                               10006);
            unit.AddComponent <NumericComponent>();
            unit.AddComponent <HeroDataComponent, long>(10001);
            unit.AddComponent <ReceiveDamageComponent>();
            unit.AddComponent <CastDamageComponent>();
            unit.AddComponent <DataModifierComponent>();

            unit.AddComponent <OperatesComponent>();

            //增加移动组件
            unit.AddComponent <MoveComponent>();
            unit.AddComponent <BuffManagerComponent>();
            unit.AddComponent <B2S_RoleCastComponent>();

            Game.Scene.GetComponent <CampAllocManagerComponent>().AllocRoleCamp(unit);

            //添加栈式状态机组件
            unit.AddComponent <StackFsmComponent>();
            unit.AddComponent <UnitPathComponent>();

            unit.AddComponent <NP_RuntimeTreeManager>();

            ConfigComponent configComponent = Game.Scene.GetComponent <ConfigComponent>();

            if (RandomHelper.RandomNumber(0, 2) == 0)
            {
                //Log.Info("开始创建行为树");
                NP_RuntimeTreeFactory.CreateNpRuntimeTree(unit, configComponent.Get <Server_AICanvasConfig>(10001).NPBehaveId)
                .Start();
            }

            return(unit);
        }
Beispiel #3
0
        protected override async ETTask Run(ETModel.Session session, M2C_CreateUnits message)
        {
            foreach (UnitInfo unitInfo in message.Units)
            {
                //TODO 暂时先忽略除英雄之外的Unit(如技能碰撞体),后期需要配表来解决这一块的逻辑,并且需要在协议里指定Unit的类型Id(注意不是运行时的Id,是Excel表中的类型Id)
                //TODO 诺手UnitTypeId暂定10001
                if (UnitComponent.Instance.Get(unitInfo.UnitId) != null || unitInfo.UnitTypeId != 10001)
                {
                    continue;
                }

                //根据不同名称和ID,创建英雄
                Unit unit = UnitFactory.CreateHero(unitInfo.UnitId, "NuoKe", (RoleCamp)unitInfo.RoleCamp);
                //因为血条需要,创建热更层unit
                HotfixUnit hotfixUnit = HotfixUnitFactory.CreateHotfixUnit(unit, true);

                hotfixUnit.AddComponent <FallingFontComponent>();

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

                //添加英雄数据
                M2C_GetHeroDataResponse M2C_GetHeroDataResponse = await Game.Scene.GetComponent <SessionComponent>()
                                                                  .Session.Call(new C2M_GetHeroDataRequest()
                {
                    UnitID = unitInfo.UnitId
                }) as M2C_GetHeroDataResponse;

                UnitComponent.Instance.Get(unitInfo.UnitId)
                .AddComponent <HeroDataComponent, long>(M2C_GetHeroDataResponse.HeroDataID);

                unit.AddComponent <NP_RuntimeTreeManager>();

                //Log.Info("开始创建行为树");
                ConfigComponent configComponent = Game.Scene.GetComponent <ConfigComponent>();
                NP_RuntimeTreeFactory.CreateSkillNpRuntimeTree(unit, configComponent.Get <Client_SkillCanvasConfig>(10001).NPBehaveId,
                                                               configComponent.Get <Client_SkillCanvasConfig>(10001).BelongToSkillId).Start();
                NP_RuntimeTreeFactory.CreateSkillNpRuntimeTree(unit, configComponent.Get <Client_SkillCanvasConfig>(10002).NPBehaveId,
                                                               configComponent.Get <Client_SkillCanvasConfig>(10002).BelongToSkillId).Start();
                NP_RuntimeTreeFactory.CreateSkillNpRuntimeTree(unit, configComponent.Get <Client_SkillCanvasConfig>(10003).NPBehaveId,
                                                               configComponent.Get <Client_SkillCanvasConfig>(10003).BelongToSkillId).Start();
                NP_RuntimeTreeFactory.CreateSkillNpRuntimeTree(unit, configComponent.Get <Client_SkillCanvasConfig>(10004).NPBehaveId,
                                                               configComponent.Get <Client_SkillCanvasConfig>(10004).BelongToSkillId).Start();
                //Log.Info("行为树创建完成");

                // 创建头顶Bar
                Game.EventSystem.Run(EventIdType.CreateHeadBar, unitInfo.UnitId);
                // 挂载头顶Bar
                hotfixUnit.AddComponent <HeroHeadBarComponent, Unit, FUI>(unit,
                                                                          Game.Scene.GetComponent <FUIComponent>().Get(unitInfo.UnitId));
            }

            if (UnitComponent.Instance.MyUnit == null)
            {
                // 给自己的Unit添加引用
                UnitComponent.Instance.MyUnit =
                    UnitComponent.Instance.Get(PlayerComponent.Instance.MyPlayer.UnitId);
                UnitComponent.Instance.MyUnit
                .AddComponent <CameraComponent, Unit>(UnitComponent.Instance.MyUnit);

                UnitComponent.Instance.MyUnit.AddComponent <OutLineComponent>();

                Game.Scene.GetComponent <M5V5GameComponent>().GetHotfixUnit(PlayerComponent.Instance.MyPlayer.UnitId).AddComponent <PlayerHeroControllerComponent>();

                Game.EventSystem.Run(EventIdType.EnterMapFinish);
            }

            //ETModel.Log.Info($"{DateTime.UtcNow}完成一次创建Unit");
            await ETTask.CompletedTask;
        }
Beispiel #4
0
        /// <summary>
        /// 创建诺手
        /// TODO 后期需要改,应该是一个通用的创建英雄接口,只需要提供Id,然后自动索引其所需要的数据(比如技能数据,英雄数据)
        /// </summary>
        /// <returns></returns>
        public static Unit CreateDarius()
        {
            //创建战斗单位
            Unit unit = CreateUnitBase();

            unit.AddComponent <ChildrenUnitComponent>();

            //增加寻路相关组件
            unit.AddComponent <UnitPathComponent>();

            //为Unit附加碰撞体
            CreateColliderUnit(unit, Game.Scene.GetComponent <ConfigComponent>().Get <Server_B2SCollisionRelationConfig>(10001).B2S_CollisionRelationId,
                               10006);

            unit.AddComponent <B2S_RoleCastComponent>();

            Game.Scene.GetComponent <CampAllocManagerComponent>().AllocRoleCamp(unit);

            unit.AddComponent <NumericComponent>();
            unit.AddComponent <HeroDataComponent, long>(10001);
            unit.AddComponent <ReceiveDamageComponent>();
            unit.AddComponent <CastDamageComponent>();
            unit.AddComponent <DataModifierComponent>();
            //增加移动组件
            unit.AddComponent <MoveComponent>();

            unit.AddComponent <OperatesComponent>();

            unit.AddComponent <BuffManagerComponent>();
            unit.AddComponent <NP_RuntimeTreeManager>();
            unit.AddComponent <SkillCanvasManagerComponent>();

            ConfigComponent configComponent = Game.Scene.GetComponent <ConfigComponent>();

            //Log.Info("开始创建行为树");
            NP_RuntimeTreeFactory.CreateSkillNpRuntimeTree(unit, configComponent.Get <Server_SkillCanvasConfig>(10001).NPBehaveId,
                                                           configComponent.Get <Server_SkillCanvasConfig>(10001).BelongToSkillId)
            .Start();

            NP_RuntimeTreeFactory.CreateSkillNpRuntimeTree(unit, configComponent.Get <Server_SkillCanvasConfig>(10002).NPBehaveId,
                                                           configComponent.Get <Server_SkillCanvasConfig>(10002).BelongToSkillId)
            .Start();

            NP_RuntimeTreeFactory.CreateSkillNpRuntimeTree(unit, configComponent.Get <Server_SkillCanvasConfig>(10004).NPBehaveId,
                                                           configComponent.Get <Server_SkillCanvasConfig>(10004).BelongToSkillId)
            .Start();

            NP_RuntimeTreeFactory.CreateSkillNpRuntimeTree(unit, configComponent.Get <Server_SkillCanvasConfig>(10005).NPBehaveId,
                                                           configComponent.Get <Server_SkillCanvasConfig>(10005).BelongToSkillId)
            .Start();

            //Log.Info("行为树创建完成");

            //添加栈式状态机组件
            unit.AddComponent <StackFsmComponent>();
            unit.AddComponent <CommonAttackComponent>();

            //设置英雄位置
            unit.Position = new Vector3(-10, 0, -10);
            return(unit);
        }
Beispiel #5
0
        /// <summary>
        /// 创建一次一定要同步一次
        /// </summary>
        /// <param name="a">释放者unit Id</param>
        /// <param name="b">碰撞关系数据载体Id(Excel表中的)</param>
        /// <param name="c">碰撞关系数据载体中的Node的Id</param>
        /// <param name="d">目标行为树数据载体Id(Excel表中的)</param>
        public override void Run(long a, int b, long c, int d)
        {
            Unit            unit            = UnitComponent.Instance.Get(a);
            ConfigComponent configComponent = Game.Scene.GetComponent <ConfigComponent>();

            B2S_ColliderComponent colliderComponent = UnitFactory
                                                      .CreateColliderUnit(unit, configComponent.Get <Server_B2SCollisionRelationConfig>(b).B2S_CollisionRelationId, c)
                                                      .GetComponent <B2S_ColliderComponent>();

            //这里直接默认以英雄当前位置作为碰撞体生成的位置,如需提前指定位置,请在抛事件那里传参
            colliderComponent.SyncBody();
            //Log.Info("生成技能碰撞体");

            //根据传过来的行为树Id来给这个碰撞Unit加上行为树
            NP_RuntimeTreeFactory.CreateSkillNpRuntimeTree(colliderComponent.Entity as Unit,
                                                           configComponent.Get <Server_SkillCanvasConfig>(d).NPBehaveId, configComponent.Get <Server_SkillCanvasConfig>(d).BelongToSkillId)
            .Start();

            //下面这一部分是Debug用的,稳定后请去掉
            {
                //广播碰撞体信息
                foreach (var VARIABLE in colliderComponent.Body.FixtureList)
                {
                    switch (VARIABLE.ShapeType)
                    {
                    case ShapeType.Polygon:     //多边形
                        M2C_B2S_Debugger_Polygon test = new M2C_B2S_Debugger_Polygon()
                        {
                            Id = unit.Id, SustainTime = 2000,
                        };
                        foreach (var VARIABLE1 in ((PolygonShape)VARIABLE.Shape).Vertices)
                        {
                            Vector2 worldPoint = colliderComponent.Body.GetWorldPoint(VARIABLE1);
                            test.Vects.Add(new M2C_B2S_VectorBase()
                            {
                                X = worldPoint.X, Y = worldPoint.Y
                            });
                        }

                        MessageHelper.Broadcast(test);
                        break;

                    case ShapeType.Circle:     //圆形
                        CircleShape             myShape = (CircleShape)VARIABLE.Shape;
                        M2C_B2S_Debugger_Circle test1   = new M2C_B2S_Debugger_Circle()
                        {
                            Id          = unit.Id,
                            SustainTime = 2000,
                            Radius      = myShape.Radius,
                            Pos         = new M2C_B2S_VectorBase()
                            {
                                X = colliderComponent.Body.GetWorldPoint(myShape.Position).X,
                                Y = colliderComponent.Body.GetWorldPoint(myShape.Position).Y
                            },
                        };
                        MessageHelper.Broadcast(test1);
                        //Log.Info($"是圆形,并且已经朝客户端发送绘制数据,半径为{myShape.Radius}");
                        break;
                    }
                }
            }
        }