Пример #1
0
        protected override async void Run(Session session, G2M_CreateUnit message, Action <M2G_CreateUnit> reply)
        {
            M2G_CreateUnit response = new M2G_CreateUnit();

            try
            {
                Unit unit = ComponentFactory.Create <Unit>();

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

                unit.AddComponent <UnitGateComponent, long>(message.GateSessionId);
                Game.Scene.GetComponent <UnitComponent>().Add(unit);
                response.UnitId = unit.Id;

                response.Count = Game.Scene.GetComponent <UnitComponent>().Count;
                reply(response);

                if (response.Count == 2)
                {
                    Actor_CreateUnits actorCreateUnits = new Actor_CreateUnits();
                    Unit[]            units            = Game.Scene.GetComponent <UnitComponent>().GetAll();
                    Unit u;
                    for (int i = 0; i < units.Length; i++)
                    {
                        u = units[i];
                        actorCreateUnits.Units.Add(new UnitInfo(u.Id, (int)(u.Position.X * 1000), (int)(u.Position.Z * 1000), i + 1));
                    }
                    MessageHelper.Broadcast(actorCreateUnits);
                }
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
Пример #2
0
        protected override async ETTask Run(Scene scene, M2M_UnitTransferRequest request, M2M_UnitTransferResponse response, Action reply)
        {
            await ETTask.CompletedTask;
            UnitComponent unitComponent = scene.GetComponent <UnitComponent>();
            Unit          unit          = request.Unit;

            unitComponent.AddChild(unit);
            unitComponent.Add(unit);

            foreach (Entity entity in request.Entitys)
            {
                unit.AddComponent(entity);
            }

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

            unit.AddComponent <MailBoxComponent>();

            // 通知客户端创建My Unit
            M2C_CreateMyUnit m2CCreateUnits = new M2C_CreateMyUnit();

            m2CCreateUnits.Unit = Server.UnitHelper.CreateUnitInfo(unit);
            MessageHelper.SendToClient(unit, m2CCreateUnits);

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

            response.NewInstanceId = unit.InstanceId;

            reply();
        }
Пример #3
0
        /// <summary>
        /// 创建碰撞体
        /// </summary>
        /// <param name="belongToUnit">归属的Unit(施法者Unit)</param>
        /// <param name="collisionRelationId">所处碰撞关系数据载体id</param>
        /// <param name="nodeDataId">碰撞体数据ID(在碰撞关系数据载体中的节点Id)</param>
        /// <returns></returns>
        public static Unit CreateColliderUnit(Unit belongToUnit, long collisionRelationId, long nodeDataId)
        {
            B2S_CollisionsRelationSupport b2SCollisionsRelationSupport = Game.Scene.GetComponent <B2S_CollisionRelationRepositoryComponent>()
                                                                         .GetB2S_CollisionsRelationSupportById(collisionRelationId);

            if (!b2SCollisionsRelationSupport.B2S_CollisionsRelationDic.ContainsKey(nodeDataId))
            {
                Log.Error($"所请求的碰撞关系数据结点不存在,ID为{nodeDataId}");
                return(null);
            }

            //为碰撞体新建一个Unit
            Unit b2sColliderEntity = CreateUnitBase();

            b2sColliderEntity.AddComponent <NP_RuntimeTreeManager>();
            b2sColliderEntity.AddComponent <SkillCanvasManagerComponent>();

            b2sColliderEntity.AddComponent <B2S_ColliderComponent, Unit, B2S_CollisionInstance, long>(belongToUnit,
                                                                                                      b2SCollisionsRelationSupport.B2S_CollisionsRelationDic[nodeDataId],
                                                                                                      nodeDataId);

            //把这个碰撞实体增加到管理者维护 TODO 待优化,目的同B2S_ColliderEntityManagerComponent
            Game.Scene.GetComponent <B2S_WorldColliderManagerComponent>().AddColliderEntity(b2sColliderEntity);
            return(b2sColliderEntity);
        }
Пример #4
0
        protected override async ETTask Run(Session session, G2M_CreateUnit request, M2G_CreateUnit response, Action reply)
        {
            Unit unit = ComponentFactory.CreateWithId <Unit>(IdGenerater.GenerateId());

            unit.Position = new Vector3(-10, 0, -10);

            unit.AddComponent <MoveComponent>();
            unit.AddComponent <UnitPathComponent>();

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

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


            // 广播创建的unit
            M2C_CreateUnits createUnits = new M2C_CreateUnits();

            Unit[] units = Game.Scene.GetComponent <UnitComponent>().GetAll();
            foreach (Unit u in units)
            {
                UnitInfo unitInfo = new UnitInfo();
                unitInfo.X      = u.Position.x;
                unitInfo.Y      = u.Position.y;
                unitInfo.Z      = u.Position.z;
                unitInfo.UnitId = u.Id;
                createUnits.Units.Add(unitInfo);
            }
            MessageHelper.Broadcast(createUnits);

            reply();
        }
Пример #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
        protected override async void Run(Session session, G2M_CreateUnit message, Action <M2G_CreateUnit> reply)
        {
            M2G_CreateUnit response = new M2G_CreateUnit();

            try
            {
                Unit unit = ComponentFactory.Create <Unit>();
                await unit.AddComponent <ActorComponent, IEntityActorHandler>(new MapUnitEntityActorHandler()).AddLocation();

                unit.AddComponent <UnitGateComponent, long>(message.GateSessionId);
                Game.Scene.GetComponent <UnitComponent>().Add(unit);
                response.UnitId = unit.Id;

                response.Count = Game.Scene.GetComponent <UnitComponent>().Count;
                reply(response);

                if (response.Count == 2)
                {
                    Actor_CreateUnits actorCreateUnits = new Actor_CreateUnits();
                    Unit[]            units            = Game.Scene.GetComponent <UnitComponent>().GetAll();
                    foreach (Unit u in units)
                    {
                        actorCreateUnits.Units.Add(new UnitInfo()
                        {
                            UnitId = u.Id, X = (int)(u.Position.X * 1000), Z = (int)(u.Position.Z * 1000)
                        });
                    }
                    MessageHelper.Broadcast(actorCreateUnits);
                }
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
Пример #7
0
        protected override void Run(ETModel.Session session, Actor_CreateUnits message)
        {
            // 加载Unit资源
            ResourcesComponent resourcesComponent = ETModel.Game.Scene.GetComponent <ResourcesComponent>();

            resourcesComponent.LoadBundle($"Unit.unity3d");

            UnitComponent unitComponent = ETModel.Game.Scene.GetComponent <UnitComponent>();

            foreach (UnitInfo unitInfo in message.Units)
            {
                if (unitComponent.Get(unitInfo.UnitId) != null)
                {
                    continue;
                }
                Unit unit = ETModel.ComponentFactory.CreateWithId <Unit>(unitInfo.UnitId);
                unitComponent.Add(unit);
                //Unit unit = UnitFactory.Create(unitInfo.UnitId);
                //unit.Position = new Vector3(unitInfo.X / 1000f, 0, unitInfo.Z / 1000f);
                //unit.IntPos = new VInt3(unitInfo.X, 0, unitInfo.Z);

                if (PlayerComponent.Instance.MyPlayer.Id == unit.Id)
                {
                    unit.AddComponent <UnitEntityComponent, bool>(true);
                    ETModel.Game.Scene.AddComponent <MapGridComponent>();
                }
                else
                {
                    unit.AddComponent <UnitStateComponent>();
                    unit.AddComponent <UnitEntityComponent, bool>(false);
                }
            }

            //Game.Scene.AddComponent<OperaComponent>();
        }
        private static Unit MakeRuleUnit(string ruleID, string pool, IBlackboard blackboard)
        {
            Unit u = new Unit();

            u.AddComponent(new KC_UnitID(ruleID, true));
            u.AddComponent(new KC_ContentPool(pool, true));
            blackboard.AddUnit(u);
            return(u);
        }
Пример #9
0
        protected override void Run(ETModel.Session session, M2C_AddUnits message)
        {
            int unittype = message.UnitType;

            switch (unittype)
            {
            case 0:
                UnitComponent unitComponent = ETModel.Game.Scene.GetComponent <UnitComponent>();
                int           oldcount0     = unitComponent.Count;
                foreach (UnitInfo unitInfo in message.Units)
                {
                    if (unitComponent.Get(unitInfo.UnitId) != null)
                    {
                        continue;
                    }
                    Unit unit0 = UnitFactory.Create(unitInfo.UnitId);
                    unit0.Position = new Vector3(unitInfo.X, unitInfo.Y, unitInfo.Z);

                    unit0.AddComponent <MovePositionComponent>();
                    unit0.AddComponent <UnitPositionComponent>();

                    if (unitInfo.UnitId == PlayerComponent.Instance.MyPlayer.UnitId)
                    {
                        ///20190621//将参数unit 传给组件CameraComponent awake方法
                        ETModel.Game.EventSystem.Awake <Unit>(ETModel.Game.Scene.GetComponent <CameraComponent>(), unit0);
                        unit0.AddComponent <CharacterControllerComponent>().isCanControl = true;

                        ///20190703
                        Game.Scene.AddComponent <OperaComponent>();
                        Game.Scene.AddComponent <RaycastHitComponent>();
                        Game.Scene.AddComponent <KeyboardSkillComponent>();

                        Debug.Log(" M2C_AddUnitHandler-47: " + unit0.Id);
                    }
                }
                Debug.Log(" M2C_AddUnitHandler-42-Player: " + unittype + " : " + oldcount0 + " + " + message.Units.Count + " = " + unitComponent.Count);
                break;

            case 1:
                MonsterUnitComponent enemyunitComponent = ETModel.Game.Scene.GetComponent <MonsterUnitComponent>();
                int oldcount1 = enemyunitComponent.Count;
                foreach (UnitInfo unitInfo in message.Units)
                {
                    if (enemyunitComponent.Get(unitInfo.UnitId) != null)
                    {
                        continue;
                    }
                    Unit unit1 = MonsterUnitFactory.Create(unitInfo.UnitId);
                    unit1.Position = new Vector3(unitInfo.X, unitInfo.Y, unitInfo.Z);
                }
                Debug.Log(" M2C_AddUnitHandler-53-Monster: " + unittype + " : " + oldcount1 + " + " + message.Units.Count + " = " + enemyunitComponent.Count);
                break;

            case 2:
                break;
            }
        }
Пример #10
0
        public static Unit Create(long id, int typeId, UnitData unitData)
        {
            UnitComponent unitComponent = Game.Scene.GetComponent <UnitComponent>();
            Unit          unit          = ComponentFactory.CreateWithId <Unit>(id);
            UnitConfig    unitConfig    = Game.Scene.GetComponent <ConfigComponent>().Get(typeof(UnitConfig), typeId) as UnitConfig;

            unit.AddComponent <NumericComponent, int>(typeId);
            unit.AddComponent <UnitStateComponent>();
            unit.AddComponent <UnitPathComponent>();
            unit.AddComponent <BuffMgrComponent>();
            var activeSkillCom  = unit.AddComponent <ActiveSkillComponent>();
            var passiveSkillCom = unit.AddComponent <PassiveSkillComponent>();

            unit.AddComponent <SkillEffectComponent>();

            //添加碰撞体
            AddCollider(unit, unitData, true, unitConfig.AssetName);
            unit.AddComponent <CharacterStateComponent>();
            unit.AddComponent <CharacterMoveComponent>();
            unit.AddComponent <CalNumericComponent>();


            if (unitConfig.Skills != null && unitConfig.Skills.Length > 0)
            {
                SkillConfigComponent skillConfigComponent = Game.Scene.GetComponent <SkillConfigComponent>();
                foreach (var v in unitConfig.Skills)
                {
                    if (string.IsNullOrEmpty(v))
                    {
                        continue;
                    }
                    var activeSkill = skillConfigComponent.GetActiveSkill(v);
                    if (activeSkill != null)
                    {
                        Log.Debug(string.Format("{0} 添加主动技能 {1} ({2})成功!", typeId, v, activeSkill.skillName));
                        activeSkillCom.AddSkill(v);
                        continue;
                    }
                    var passiveSkill = skillConfigComponent.GetPassiveSkill(v);
                    if (passiveSkill != null)
                    {
                        Log.Debug(string.Format("{0} 添加被动技能 {1} ({2})成功!", typeId, v, passiveSkill.skillName));
                        passiveSkillCom.AddSkill(v);
                        continue;
                    }
                    Log.Error(v + "  这样的技能不存在!");
                }
            }

            //unit.AddComponent<TurnComponent>();

            unitComponent.Add(unit);
            return(unit);
        }
Пример #11
0
        public static Unit CreateEmitObj(long id, UnitData unitData, string key)
        {
            UnitComponent unitComponent = Game.Scene.GetComponent <UnitComponent>();
            Unit          unit          = ComponentFactory.CreateWithId <Unit>(id);

            unit.AddComponent <UnitStateComponent>();
            AddCollider(unit, unitData, true, key);
            unit.AddComponent <EmitObjMoveComponent>();

            return(unit);
        }
Пример #12
0
        protected override async ETTask Run(Scene scene, EventType.AfterUnitCreate args)
        {
            Unit unit = args.Unit;
            // Unit View层
            // 这里可以改成异步加载,demo就不搞了
            GameObject bundleGameObject = (GameObject)ResourcesComponent.Instance.GetAsset("Unit.unity3d", "Unit");
            GameObject prefab           = bundleGameObject.Get <GameObject>("Skeleton");

            GameObject go = UnityEngine.Object.Instantiate(prefab, GlobalComponent.Instance.Unit, true);

            go.transform.position = unit.Position;
            unit.AddComponent <GameObjectComponent>().GameObject = go;
            unit.AddComponent <AnimatorComponent>();
            await ETTask.CompletedTask;
        }
Пример #13
0
        protected override void Execute(object[] boundVars)
        {
            string targetID   = (string)boundVars[TargetIDForDefault];
            Unit   pseudoRule = new Unit();

            pseudoRule.AddComponent(new KC_UnitID(targetID, true));          // Create a pseudo-rule with the targetID
            Unit[] decomp = new Unit[1];                                     // The decomposition of the pseudo-rule will consists of a single node.
            decomp[0] = new Unit();
            decomp[0].AddComponent(new KC_Text("#" + targetID + "#", true)); // The decomposition is a terminal with a tracery-style default exapansion
            pseudoRule.AddComponent(new KC_Decomposition(decomp, true));     // Add the decomposition to the rule.

            // Add the default decomposition to the inputPool.
            pseudoRule.AddComponent(new KC_ContentPool(InputPool, true));
            m_blackboard.AddUnit(pseudoRule);
        }
Пример #14
0
        /*
         * Copy all the units bound by the precondition into the OutputPool adding a KC_EvaluatablePrologExpression and evaluate the expression.
         */
        protected override void Execute(object[] boundVars)
        {
            // Get the units and the prolog KB from the precondition bindings.
            var  units    = (IEnumerable <Unit>)boundVars[FilteredUnits];
            Unit prologKB = (Unit)boundVars[PrologKB];

            // Copy each of the units to the output pool, adding a KC_EvaluatablePrologExpression and evaluating it.
            foreach (var unit in units)
            {
                Unit unitCopy = CopyUnitToOutputPool(unit);

                // fixme: ignoring the name. When the Unit component infrastructure is updated to handle multiple named components, change the call here.
                KC_PrologExpression expToEvaluate = unitCopy.GetComponent <KC_PrologExpression>();

                // Remove the KC_PrologExpression
                unitCopy.RemoveComponent(expToEvaluate);

                // Create a KC_EvaluatablePrologExpression based on expToEvaluate.
                KC_EvaluatablePrologExpression evaluatablePrologExp = new KC_EvaluatablePrologExpression(expToEvaluate);

                // Add the KC_EvaluatablePrologExpression to the Unit
                unitCopy.AddComponent(evaluatablePrologExp);

                /*
                 * Evaluate the prolog expression.
                 * The original unit now being linked (via CopyUnitToOutputPool) to a unit with a matching and evaled KC_EvaluatablePrologExpression
                 * is what will keep this unit from repeatedly matching in the precondition. The precondition is testing !HasLinkToEvaluatedExpression
                 * as a filter condition.
                 */
                evaluatablePrologExp.Evaluate(prologKB.GetComponent <KC_PrologKB>());
            }
        }
Пример #15
0
        public void TestAddDeleteContains()
        {
            IBlackboard blackboard = new Blackboard();
            Unit        u1         = new Unit();

            u1.AddComponent(new KC_UnitID("one", true));

            Unit u2 = new Unit();

            u2.AddComponent(new KC_UnitID("two", true));

            Unit u3 = new Unit();

            u3.AddComponent(new KC_UnitID("three", true));

            blackboard.AddUnit(u1);
            blackboard.AddUnit(u2);
            blackboard.AddUnit(u3);
            Assert.True(blackboard.ContainsUnit(u1));
            Assert.True(blackboard.ContainsUnit(u2));
            Assert.True(blackboard.ContainsUnit(u3));
            blackboard.RemoveUnit(u3);
            Assert.False(blackboard.ContainsUnit(u3));
            Assert.True(blackboard.ContainsUnit(u2));
            Assert.True(blackboard.ContainsUnit(u1));
            blackboard.RemoveUnit(u2);
            Assert.False(blackboard.ContainsUnit(u3));
            Assert.False(blackboard.ContainsUnit(u2));
            Assert.True(blackboard.ContainsUnit(u1));
            blackboard.RemoveUnit(u1);
            Assert.False(blackboard.ContainsUnit(u3));
            Assert.False(blackboard.ContainsUnit(u2));
            Assert.False(blackboard.ContainsUnit(u1));
        }
        protected override async ETTask Run(ETModel.Session session, M2C_CreateSpilings message)
        {
            SpilingInfo spilingInfo = message.Spilings;

            if (spilingInfo == null)
            {
                ETModel.Log.Error("收到的木桩回调信息为空");
            }
            //创建木桩
            Unit unit = UnitFactory.CreateSpiling(spilingInfo.UnitId, spilingInfo.ParentUnitId);

            //因为血条需要,创建热更层unit
            HotfixUnit hotfixUnit = HotfixUnitFactory.CreateHotfixUnit(unit);

            hotfixUnit.AddComponent <FallingFontComponent>();
            unit.Position = new Vector3(spilingInfo.X, spilingInfo.Y, spilingInfo.Z);

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

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

            await ETTask.CompletedTask;
        }
Пример #17
0
        // Deleting and adding elements to a returned set shouldn't change the set in the dictionary
        public void TestManipulatingSet()
        {
            IBlackboard blackboard = new Blackboard();

            Unit u1 = new Unit();

            u1.AddComponent(new KC_UnitID("one", true));

            Unit u2 = new Unit();

            u2.AddComponent(new KC_UnitID("two", true));

            blackboard.AddUnit(u1);
            ISet <Unit> set1 = blackboard.LookupUnits <Unit>();

            Assert.Equal(1, set1.Count);

            set1.Add(u2);
            ISet <Unit> set2 = blackboard.LookupUnits <Unit>();

            Assert.Equal(1, set2.Count);

            set2.Remove(u1);
            ISet <Unit> set3 = blackboard.LookupUnits <Unit>();

            Assert.Equal(1, set3.Count);
        }
Пример #18
0
        /*
         * Called with a object[2] array, where boundVars[UnitToWeight] is the Unit which should be copied to the OutputPool and weighted, while
         * boundVars[UtilitySources] is an IEnumerable<Unit> containing the utility sources to sum to determine the utility (weighting) of the UnitToWeight.
         */
        protected override void Execute(object[] boundVars)
        {
            // Grab the arguments.
            Unit unitToWeight = boundVars[UnitToWeight] as Unit;
            IEnumerable <Unit> utilitySources = boundVars[UtilitySources] as IEnumerable <Unit>;

            // Make a copy of the unitToWeight in the OutputPool.
            Unit unitCopy = CopyUnitToPool(unitToWeight, OutputPool);

            /*
             * If the copy of the unitToWeight doesn't already have a KC_Utility, add one. If it does already have a KC_Utility, then this is an initial weighting
             * that we will be adding to (subtracting from) as we sum our utility sources.
             */
            if (!unitCopy.HasComponent <KC_Utility>())
            {
                unitCopy.AddComponent(new KC_Utility(0));
            }

            /*
             * Sum the utility sources.
             */
            double utilitySum = 0;

            foreach (Unit utilitySource in utilitySources)
            {
                utilitySum += utilitySource.GetUtility();
            }

            // Update the utility of the copy of the unitToWeight.
            unitCopy.SetUtility(unitCopy.GetUtility() + utilitySum);
        }
Пример #19
0
        Unit CreateMap(ResourcesComponent resourcesComponent, string abName, UnitComponent unitComponent,
                       int MapSizeX, int MapSizeY)
        {
            GameObject bundleGameObjectMapGrid =
                (GameObject)resourcesComponent.GetAsset(abName.StringToAB(), "MapGrid");
            // 添加格子
            Unit        mapGridUnit = null;
            MapGridData mapGridData = new MapGridData();

            mapGridData.ABName = abName;
            for (int x = 0; x < MapSizeX; x++)
            {
                for (int y = 0; y < MapSizeY; y++)
                {
                    GameObject gameObjectGrid = UnityEngine.Object.Instantiate(bundleGameObjectMapGrid);
                    gameObjectGrid.name = string.Format("Grid[{0}][{1}]", x, y);
                    // 创建地图格子实体
                    int id = gameObjectGrid.GetHashCode();// x * 1000 + y;
                    Log.Debug("创建地图格子实体:{0} ", id);
                    mapGridUnit = ETModel.ComponentFactory.CreateWithId <ETModel.Unit, GameObject>(
                        id, gameObjectGrid);
                    // 添加地图格子组件
                    mapGridData.GridX  = x;
                    mapGridData.GridY  = y;
                    mapGridData.BgName = "Desert";
                    MapGridComponent mapGridComponent = ETModel.ComponentFactory.CreateWithParent <MapGridComponent, MapGridData>(
                        mapGridUnit, mapGridData);
                    mapGridUnit.AddComponent(mapGridComponent);
                    // add
                    unitComponent.Add(mapGridUnit);
                }
            }
            return(mapGridUnit);
        }
Пример #20
0
        protected override async ETTask Run(Session session, C2G_EnterMap request, G2C_EnterMap response, Action reply)
        {
            Player player = session.GetComponent <SessionPlayerComponent>().GetMyPlayer();



            // 在Gate上动态创建一个Map Scene,把Unit从DB中加载放进来,然后传送到真正的Map中,这样登陆跟传送的逻辑就完全一样了
            GateMapComponent gateMapComponent = player.AddComponent <GateMapComponent>();

            gateMapComponent.Scene = await SceneFactory.Create(gateMapComponent, "GateMap", SceneType.Map);

            Scene scene = gateMapComponent.Scene;

            // 这里可以从DB中加载Unit
            Unit unit = Server.UnitFactory.Create(scene, player.Id, UnitType.Player);

            unit.AddComponent <UnitGateComponent, long>(session.InstanceId);

            StartSceneConfig startSceneConfig = StartSceneConfigCategory.Instance.GetBySceneName(session.DomainZone(), "Map1");

            response.MyId = player.Id;
            reply();

            // 开始传送
            await TransferHelper.Transfer(unit, startSceneConfig.InstanceId, startSceneConfig.Name);
        }
Пример #21
0
        /// <summary>
        /// 创建假人,需要传入一个父UnitId
        /// </summary>
        /// <returns></returns>
        public static Unit CreateSpiling(long parentId)
        {
            Unit unit = CreateUnitBase();

            //Log.Info($"服务端响应木桩请求,父id为{message.ParentUnitId}");
            Game.Scene.GetComponent <UnitComponent>().Get(parentId).GetComponent <ChildrenUnitComponent>().AddUnit(unit);
            //Log.Info("确认找到了请求的父实体");

            unit.AddComponent <B2S_UnitColliderManagerComponent>().CreateCollider(unit,
                                                                                  Game.Scene.GetComponent <ConfigComponent>().Get <Server_B2SCollisionRelationConfig>(10001).B2S_CollisionRelationId, 10006);
            unit.AddComponent <HeroDataComponent, long>(10001);
            unit.AddComponent <BuffManagerComponent>();
            unit.AddComponent <B2S_RoleCastComponent>().RoleCast = RoleCast.Adverse;
            //添加栈式状态机组件
            unit.AddComponent <StackFsmComponent>();
            return(unit);
        }
Пример #22
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(unit.DomainScene(), new EventType.AfterUnitCreate()
            {
                Unit = unit
            });
            return(unit);
        }
Пример #23
0
        protected override void Execute(object[] boundVars)
        {
            Unit nodeToExpandRef = (Unit)boundVars[NodeToExpandRef];
            Unit decomposition   = (Unit)boundVars[Decomposition];
            Unit orderCounter    = (Unit)boundVars[OrderCounter];

            Unit ruleNode = new Unit(decomposition);

            // Remove the KC_Decomposition (not needed) and KC_ContentPool (will cause node to be prematurely cleaned up) components
            ruleNode.RemoveComponent(ruleNode.GetComponent <KC_Decomposition>()); // fixme: consider adding AddSingleComponent<T> and RemoveSingletonComponent<T> to simplify working with this common case
            ruleNode.RemoveComponent(ruleNode.GetComponent <KC_ContentPool>());   // fixme: consider adding AddSingleComponent<T> and RemoveSingletonComponent<T> to simplify working with this common case

            // Add a tree node component with the parent being the node to expand.
            // fixme: consider defining conversion operators so this looks like
            // new KC_TreeNode((KC_TreeNode)nodeToExpand);
            ruleNode.AddComponent(new KC_TreeNode(nodeToExpandRef.GetUnitReference().GetComponent <KC_TreeNode>()));

            // Now that we've used it to add to the tree, remove the nodeToExpandRef from the blackboard
            m_blackboard.RemoveUnit(nodeToExpandRef);

            // fixme: Add an KC_Order to the nodes being added. In the general case may not need this - figure out how to refactor it later when other tree expansion
            // examples exist.
            if (orderCounter != null)
            {
                int order = orderCounter.IncOrderCounter();
                ruleNode.AddComponent(new KC_Order(order, true));
            }

            m_blackboard.AddUnit(ruleNode);

            // For each of the Units in the decomposition, add them to the tree as children of ruleCopy.
            foreach (Unit child in decomposition.GetDecomposition())
            {
                // Make a copy of Unit in the decomposition and add it to the tree.
                Unit childNode = new Unit(child);
                m_blackboard.AddUnit(childNode);
                childNode.AddComponent(new KC_TreeNode(ruleNode.GetComponent <KC_TreeNode>()));
                if (orderCounter != null)
                {
                    int order = orderCounter.IncOrderCounter();
                    childNode.AddComponent(new KC_Order(order, true));
                }
            }
        }
Пример #24
0
        public static Unit CreateNew(Vector3 position, Quaternion rotation)
        {
            Unit     go        = new Unit();
            BCapsule bCylinder = go.AddComponent <BCapsule>();

            CreateNewBase(go, position, rotation);
            bCylinder.BuildMesh();
            go.name = "BCapsule";
            return(go);
        }
 private static void MakeTerminalSingletons(string ruleID, string pool, string[] terminals, IBlackboard blackboard)
 {
     foreach (string terminal in terminals)
     {
         Unit   rule    = MakeRuleUnit(ruleID, pool, blackboard);
         Unit[] ruleRHS = MakeUnitArray(1);
         ruleRHS[0].AddComponent(new KC_Text(terminal, true));
         rule.AddComponent(new KC_Decomposition(ruleRHS, true));
     }
 }
Пример #26
0
        protected async ETVoid RunAsync(Session session, G2M_CreateUnit message, Action <M2G_CreateUnit> reply)
        {
            M2G_CreateUnit response = new M2G_CreateUnit();

            try
            {
                Unit unit = ComponentFactory.CreateWithId <Unit>(IdGenerater.GenerateId());
                unit.AddComponent <MoveComponent>();
                unit.AddComponent <UnitPathComponent>();
                unit.Position = new Vector3(-10, 0, -10);

                //unit的id是key,instanceId是Value,两个值都是Create Unit时随机创建的
                await unit.AddComponent <MailBoxComponent>().AddLocation();

                unit.AddComponent <UnitGateComponent, long>(message.GateSessionId);
                Game.Scene.GetComponent <UnitComponent>().Add(unit);
                response.UnitId = unit.Id;


                // 广播创建的unit
                M2C_CreateUnits createUnits = new M2C_CreateUnits();
                Unit[]          units       = Game.Scene.GetComponent <UnitComponent>().GetAll();
                foreach (Unit u in units)
                {
                    UnitInfo unitInfo = new UnitInfo();
                    unitInfo.X      = u.Position.x;
                    unitInfo.Y      = u.Position.y;
                    unitInfo.Z      = u.Position.z;
                    unitInfo.UnitId = u.Id;
                    createUnits.Units.Add(unitInfo);
                }

                MessageHelper.Broadcast(createUnits);


                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
Пример #27
0
 /// <summary>
 /// 进入房间
 /// </summary>
 /// <param name="self"></param>
 /// <param name="unit"></param>
 /// <returns></returns>
 public static int EnterRoom(this Room self, Unit unit)
 {
     if (self.UnitCount >= CFG.RoomMaxNum)
     {
         return(ErrorCode.ERR_Room_Full);
     }
     self.Units.Add(unit.Id, unit);
     unit.AddComponent <UnitRoomComponent, long>(self.Id);
     Log.Debug("进入房间" + self.Id);
     return(0);
 }
Пример #28
0
        protected override async ETTask Run(Session session, G2M_CreateUnit request, M2G_CreateUnit response, Action reply)
        {
            //并且生成ID 创建Unit实体对象
            Unit unit = ComponentFactory.CreateWithId <Unit>(IdGenerater.GenerateId());

            unit.AddComponent <MoveComponent>();
            unit.AddComponent <UnitPathComponent>();
            //设置实体位置
            unit.Position = new Vector3(-10, 0, -10);

            //添加邮箱
            await unit.AddComponent <MailBoxComponent>().AddLocation();

            //添加单位网关组件 主要是缓存该单位在网关服务器的Session Id
            //GateSessionActorId = request.GateSessionId
            unit.AddComponent <UnitGateComponent, long>(request.GateSessionId);
            //缓存这个单位
            Game.Scene.GetComponent <UnitComponent>().Add(unit);
            //设置响应的字段 UnitId
            response.UnitId = unit.Id;


            // 广播协议:创建unit
            M2C_CreateUnits createUnits = new M2C_CreateUnits();

            //获取所有的玩家 然后进行广播
            Unit[] units = Game.Scene.GetComponent <UnitComponent>().GetAll();
            foreach (Unit u in units)
            {
                UnitInfo unitInfo = new UnitInfo();
                unitInfo.X      = u.Position.x;
                unitInfo.Y      = u.Position.y;
                unitInfo.Z      = u.Position.z;
                unitInfo.UnitId = u.Id;
                createUnits.Units.Add(unitInfo);
            }
            MessageHelper.Broadcast(createUnits);

            //响应网关的请求
            reply();
        }
        /*
         * Experiment with Unit support for deserialization
         */
        private static void UnitDeserializationSupportExperiments()
        {
            Unit u             = new Unit();
            var  contentPool   = new KC_ContentPool("test", true);
            var  utility       = new KC_Utility(1.0);
            var  prologAddList = new KC_PrologFactAddList(new string[] { "one", "two", "three" }, false);
            var  idRequest     = new KC_IDSelectionRequest("foo");

            u.AddComponent(contentPool);
            u.AddComponent(utility);
            u.AddComponent(prologAddList);
            u.AddComponent(idRequest);

            string output = u.SerializeToJson();

            Console.WriteLine(output);

            Unit deserializedUnit = Unit.DeserializeFromJson(output);

            Console.WriteLine(deserializedUnit);
        }
Пример #30
0
        public void TestLookupNotNull()
        {
            IBlackboard blackboard = new Blackboard();

            Unit u1 = new Unit();

            u1.AddComponent(new KC_UnitID("one", true));

            blackboard.AddUnit(u1);

            Assert.NotNull(blackboard.LookupUnits <Unit>());
        }