Example #1
0
        public static Bullet Create(Tank tank)
        {
            ResourcesComponent resourcesComponent = Game.Scene.GetComponent <ResourcesComponent>();

            Game.Scene.GetComponent <ResourcesComponent>().LoadBundle($"Unit.unity3d");
            GameObject bundleGameObject = (GameObject)resourcesComponent.GetAsset("Unit.unity3d", "Unit");

            Game.Scene.GetComponent <ResourcesComponent>().UnloadBundle($"Unit.unity3d");
            GameObject prefab = bundleGameObject.Get <GameObject>("Bullet");

            BulletComponent bulletComponent = tank.GetComponent <BulletComponent>();


            Bullet bullet = ComponentFactory.CreateWithId <Bullet, Tank>(IdGenerater.GenerateId(), tank);



            bullet.GameObject = resourcesComponent.NewObj(PrefabType.Bullet, prefab);

            GameObject parent = tank.GameObject.FindChildObjectByPath("bullets");

            bullet.GameObject.transform.SetParent(parent.transform, false);

            bulletComponent.Add(bullet);

            BulletCollision bulletCollision = bullet.GameObject.AddComponent <BulletCollision>();

            // 子弹添加飞行
            bulletCollision.BulletFly = bullet.AddComponent <BulletFlyComponent>();


            return(bullet);
        }
Example #2
0
        void GetUsers()
        {
            User user1 = ComponentFactory.CreateWithId <User>(11101);

            user1.Count    = 1;
            user1.Account  = "tumo";
            user1.Password = "******";
            users.Add(user1.Id, user1);

            User user2 = ComponentFactory.CreateWithId <User>(21101);

            user2.Count    = 1;
            user2.Account  = "cost";
            user2.Password = "******";
            users.Add(user2.Id, user2);

            User user3 = ComponentFactory.CreateWithId <User>(31101);

            user3.Count    = 1;
            user3.Account  = "fa";
            user3.Password = "******";
            users.Add(user3.Id, user3);

            User user4 = ComponentFactory.CreateWithId <User>(41101);

            user4.Count    = 1;
            user4.Account  = "song";
            user4.Password = "******";
            users.Add(user4.Id, user4);

            GetPlayersByUsers(users.Values.ToArray());
        }
        public RideRecord CreateRideRecord(long teamId = 0L)
        {
            var rideRecordInfo = ComponentFactory.CreateWithId <RideRecord>(IdGenerater.GenerateId());

            rideRecordInfo.uid              = Uid;
            rideRecordInfo.teamId           = teamId;
            rideRecordInfo.roadConfigId     = (Room?.info?.RoadSettingId).GetValueOrDefault();
            rideRecordInfo.rank             = Rank;
            rideRecordInfo.mileage          = (int)Math.Floor(Info.DistanceTravelled);
            rideRecordInfo.cumulativeSecond = GetCumulativeTime();
            rideRecordInfo.calories         = Calories;
            rideRecordInfo.topSpeed         = GetTopSpeedKMH();
            rideRecordInfo.averageSpeed     = rideRecordInfo.mileage * 3.6f / rideRecordInfo.cumulativeSecond;
            rideRecordInfo.power            = Power;
            rideRecordInfo.createAt         = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
            var roomTeamComponent = Room.GetComponent <RoomTeamComponent>();

            if (roomTeamComponent != null)
            {
                rideRecordInfo.rideType = (int)RideRecord.RideType.Party;
            }
            else
            {
                rideRecordInfo.rideType = (int)RideRecord.RideType.Roam;
            }
            return(rideRecordInfo);
        }
Example #4
0
        void GetPlayers(User user)
        {
            for (int i = 0; i < user.Count; i++)
            {
                Player player = ComponentFactory.CreateWithId <Player>(IdGenerater.GenerateId());
                player.UserId        = user.Id;
                player.Account       = user.Account;
                player.spawnPosition = new Vector3(-40, 0, -20);

                player.AddComponent <NumericComponent>();

                NumericComponent numC = player.GetComponent <NumericComponent>();
                ///20190621
                // 这里初始化base值,给各个数值进行赋值
                // 注意,这两个语句都将触发数值改变组件,只是没有写Max的处理函数,所以会没有反应
                player.GetComponent <NumericComponent>().Set(NumericType.ValuationBase, 40);
                player.GetComponent <NumericComponent>().Set(NumericType.MaxValuationBase, 120);
                //player.GetComponent<NumericComponent>().Set(NumericType.ManageBase, 10);
                //player.GetComponent<NumericComponent>().Set(NumericType.MaxManageBase, 40);
                player.GetComponent <NumericComponent>().Set(NumericType.CaseBase, 14);
                player.GetComponent <NumericComponent>().Set(NumericType.MaxCaseBase, 40);

                player.GetComponent <NumericComponent>().Set(NumericType.LevelBase, 1);
                player.GetComponent <NumericComponent>().Set(NumericType.ExpBase, 1);
                player.GetComponent <NumericComponent>().Set(NumericType.CoinBase, 1);

                player.GetComponent <NumericComponent>().Set(NumericType.ValuationAdd, 140);      // HpAdd 数值,进行赋值
                player.GetComponent <NumericComponent>().Set(NumericType.MaxValuationAdd, 140);   // MaxHpAdd 数值,进行赋值

                players.Add(player.Id, player);
            }
        }
Example #5
0
        public Unit FetchEntityWithId(long Id, string type)
        {
            GameObject gameObject = FetchGameObject(type);
            Unit       unit       = ComponentFactory.CreateWithId <Unit, GameObject>(Id, gameObject);

            return(unit);
        }
Example #6
0
        public static Unit Create(long id)
        {
            ResourcesComponent resourcesComponent = Game.Scene.GetComponent <ResourcesComponent>();
            GameObject         bundleGameObject   = (GameObject)resourcesComponent.GetAsset("Unit.unity3d", "Unit");
            GameObject         prefab             = bundleGameObject.Get <GameObject>("Skeleton");

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

            GameObject go   = UnityEngine.Object.Instantiate(prefab);
            Unit       unit = ComponentFactory.CreateWithId <Unit, GameObject>(id, go);

            unit.AddComponent <AnimatorComponent>();

            SyncType type = Game.Scene.GetComponent <NetSyncComponent>().type;

            if (type == SyncType.Frame)
            {
                unit.AddComponent <FrameMoveComponent>();
            }
            else if (type == SyncType.State)
            {
                unit.AddComponent <MoveComponent>();
                unit.AddComponent <TurnComponent>();
                unit.AddComponent <UnitPathComponent>();
            }


            unitComponent.Add(unit);
            return(unit);
        }
Example #7
0
        public static Monster Create(long id)
        {
            Monster          enemy          = ComponentFactory.CreateWithId <Monster>(id);
            MonsterComponent enemyComponent = Game.Scene.GetComponent <MonsterComponent>();

            enemyComponent.Add(enemy);
            return(enemy);
        }
        public static ETTask <bool> Delete <T>(this DBComponent db, string collectionName, long id) where T : ComponentWithId
        {
            ETTaskCompletionSource <bool> tcs = new ETTaskCompletionSource <bool>();
            DBDeleteTask <T> task             = ComponentFactory.CreateWithId <DBDeleteTask <T>, string, ETTaskCompletionSource <bool> >
                                                    (id, collectionName, tcs);

            db.tasks[(int)((ulong)task.Id % DBComponent.taskCount)].Add(task);
            return(tcs.Task);
        }
Example #9
0
        public ETTask <long> Delete(string collectionName, long id)
        {
            ETTaskCompletionSource <long> tcs = new ETTaskCompletionSource <long>();
            DBDeleteTask dbDeleteTask         = ComponentFactory.CreateWithId <DBDeleteTask, string, ETTaskCompletionSource <long> >(id, collectionName, tcs);

            this.tasks[(int)((ulong)id % taskCount)].Add(dbDeleteTask);

            return(tcs.Task);
        }
        /// <summary>
        /// 刪除
        /// </summary>
        /// <param name="collectionName"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public ETTask <bool> Delete(string collectionName, long id)
        {
            ETTaskCompletionSource <bool> tcs             = new ETTaskCompletionSource <bool>();
            CacheDeleteByIdTask           cacheDeleteTask = ComponentFactory.CreateWithId <CacheDeleteByIdTask, string, ETTaskCompletionSource <bool> >(id, collectionName, tcs);

            this.tasks[(int)((ulong)id % taskCount)].Add(cacheDeleteTask);

            return(tcs.Task);
        }
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="collectionName"></param>
        /// <param name="id"></param>
        /// <param name="jsonData"></param>
        /// <returns></returns>
        public ETTask <ComponentWithId> UpdateById(string collectionName, long id, string jsonData)
        {
            ETTaskCompletionSource <ComponentWithId> tcs = new ETTaskCompletionSource <ComponentWithId>();
            CacheUpdateByIdTask cacheUpdateByIdTask      = ComponentFactory.CreateWithId <CacheUpdateByIdTask, string, string, ETTaskCompletionSource <ComponentWithId> >(id, collectionName, jsonData, tcs);

            this.tasks[(int)((ulong)id % taskCount)].Add(cacheUpdateByIdTask);

            return(tcs.Task);
        }
        /// <summary>
        /// 用主鍵查詢
        /// </summary>
        /// <param name="collectionName"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public ETTask <ComponentWithId> QueryById(string collectionName, long id, List <string> fields = null)
        {
            ETTaskCompletionSource <ComponentWithId> tcs = new ETTaskCompletionSource <ComponentWithId>();
            CacheQueryByIdTask cacheQueryByIdTask        = ComponentFactory.CreateWithId <CacheQueryByIdTask, string, List <string>, ETTaskCompletionSource <ComponentWithId> >(id, collectionName, fields, tcs);

            this.tasks[(int)((ulong)id % taskCount)].Add(cacheQueryByIdTask);

            return(tcs.Task);
        }
Example #13
0
        public void Awake()
        {
            //Skill skill = Game.Scene.GetComponent<SkillComponent>().Get(this.Id);
            Skill skill = ComponentFactory.CreateWithId <Skill>(this.Id);

            this.AddComponent(skill);
            this.AddComponent <ChangeType>();
            this.AddComponent <NumericComponent>();
        }
Example #14
0
        public ETTask <ComponentWithId> Get(string collectionName, long id)
        {
            ETTaskCompletionSource <ComponentWithId> tcs = new ETTaskCompletionSource <ComponentWithId>();
            DBQueryTask dbQueryTask = ComponentFactory.CreateWithId <DBQueryTask, string, ETTaskCompletionSource <ComponentWithId> >(id, collectionName, tcs);

            this.tasks[(int)((ulong)id % taskCount)].Add(dbQueryTask);

            return(tcs.Task);
        }
Example #15
0
        public static Unit CreateStaticObj(GameObject go, UnitData unitData)
        {
            Unit unit = ComponentFactory.CreateWithId <Unit, GameObject>(IdGenerater.GenerateId(), go);

            if (!GlobalConfigComponent.Instance.networkPlayMode)
            {
                AddCollider(unit, unitData, false);
            }
            return(unit);
        }
Example #16
0
        public ActorProxy Get(long id)
        {
            if (this.ActorProxys.TryGetValue(id, out ActorProxy actorProxy))
            {
                return(actorProxy);
            }

            actorProxy           = ComponentFactory.CreateWithId <ActorProxy>(id);
            this.ActorProxys[id] = actorProxy;
            return(actorProxy);
        }
Example #17
0
        public virtual async Task <Session> Accept()
        {
            AChannel channel = await this.Service.AcceptChannel();

            Session session = ComponentFactory.CreateWithId <Session, NetworkComponent, AChannel>(IdGenerater.GenerateId(), this, channel);

            session.Parent         = this;
            channel.ErrorCallback += (c, e) => { this.Remove(session.Id); };
            this.sessions.Add(session.Id, session);
            return(session);
        }
Example #18
0
 void GetEnemys(int count)
 {
     for (int i = 0; i < count; i++)
     {
         ///20190702
         Monster enemy = ComponentFactory.CreateWithId <Monster>(IdGenerater.GenerateId());
         enemy.AddComponent <NumericComponent>();
         enemys.Add(enemy.Id, enemy);
     }
     SetPosition(enemys);
 }
        public ETTask <T> FindOne <T>(long id) where T : ComponentWithId
        {
            var       type  = typeof(T);
            CacheBase cache = null;

            caches.TryGetValue(type, out cache);
            ETTaskCompletionSource <T> tcs  = new ETTaskCompletionSource <T>();
            CacheFindOneTask <T>       task = ComponentFactory.CreateWithId <CacheFindOneTask <T>, CacheBase, ETTaskCompletionSource <T> >(id, cache, tcs);

            this.tasks[(int)((ulong)task.Id % taskCount)].Add(task);
            return(tcs.Task);
        }
Example #20
0
        public ActorMessageSender Get(long id)
        {
            if (this.ActorMessageSenders.TryGetValue(id, out ActorMessageSender actorMessageSender))
            {
                return(actorMessageSender);
            }

            actorMessageSender           = ComponentFactory.CreateWithId <ActorMessageSender>(id);
            actorMessageSender.Parent    = this;
            this.ActorMessageSenders[id] = actorMessageSender;
            return(actorMessageSender);
        }
Example #21
0
        public ActorMessageSender GetWithActorId(long actorId)
        {
            if (this.ActorMessageSenders.TryGetValue(actorId, out ActorMessageSender actorMessageSender))
            {
                return(actorMessageSender);
            }

            actorMessageSender                = ComponentFactory.CreateWithId <ActorMessageSender, long>(actorId, actorId);
            actorMessageSender.Parent         = this;
            this.ActorMessageSenders[actorId] = actorMessageSender;
            return(actorMessageSender);
        }
Example #22
0
        public static Unit CreateEmitObj(long id, GameObject go, UnitData unitData)
        {
            EmitObjUnitComponent unitComponent = Game.Scene.GetComponent <EmitObjUnitComponent>();
            Unit unit = ComponentFactory.CreateWithId <Unit, GameObject>(id, go);

            if (!GlobalConfigComponent.Instance.networkPlayMode)
            {
                AddCollider(unit, unitData, true);
            }
            unit.AddComponent <EmitObjMoveComponent>();
            unitComponent.Add(unit);
            return(unit);
        }
Example #23
0
        public ActorProxy GetWithActorId(long actorId)
        {
            if (this.ActorProxys.TryGetValue(actorId, out ActorProxy actorProxy))
            {
                return(actorProxy);
            }

            actorProxy                = ComponentFactory.CreateWithId <ActorProxy>(actorId);
            actorProxy.ActorId        = actorId;
            actorProxy.MaxFailTimes   = 0;
            this.ActorProxys[actorId] = actorProxy;
            return(actorProxy);
        }
Example #24
0
        public Task <bool> Add(ComponentWithId component, string collectionName = "")
        {
            TaskCompletionSource <bool> tcs = new TaskCompletionSource <bool>();

            if (string.IsNullOrEmpty(collectionName))
            {
                collectionName = component.GetType().Name;
            }
            DBSaveTask task = ComponentFactory.CreateWithId <DBSaveTask, ComponentWithId, string, TaskCompletionSource <bool> >(component.Id, component, collectionName, tcs);

            this.tasks[(int)((ulong)task.Id % taskCount)].Add(task);

            return(tcs.Task);
        }
Example #25
0
        public static async ETTask Add(long uid, ReservationAllData allData)
        {
            if (await IsExist(uid))
            {
                Log.Error($"AddReservationDB 失敗! uid : {uid} 已經存在!");
                return;
            }

            ReservationDB reservationDB = ComponentFactory.CreateWithId <ReservationDB>(IdGenerater.GenerateId());

            reservationDB.uid     = uid;
            reservationDB.allData = new MongoDB.Bson.BsonBinaryData(allData.ToByteArray());

            await dbProxy.Save(reservationDB);
        }
Example #26
0
        public Task <ComponentWithId> Get(string collectionName, long id)
        {
            ComponentWithId component = GetFromCache(collectionName, id);

            if (component != null)
            {
                return(Task.FromResult(component));
            }

            TaskCompletionSource <ComponentWithId> tcs = new TaskCompletionSource <ComponentWithId>();
            DBQueryTask dbQueryTask = ComponentFactory.CreateWithId <DBQueryTask, string, TaskCompletionSource <ComponentWithId> >(id, collectionName, tcs);

            this.tasks[(int)((ulong)id % taskCount)].Add(dbQueryTask);

            return(tcs.Task);
        }
Example #27
0
        public ActorMessageSender Get(long id)
        {
            if (id == 0)
            {
                throw new Exception($"actor id is 0");
            }
            if (this.ActorMessageSenders.TryGetValue(id, out ActorMessageSender actorMessageSender))
            {
                return(actorMessageSender);
            }

            actorMessageSender           = ComponentFactory.CreateWithId <ActorMessageSender>(id);
            actorMessageSender.Parent    = this;
            this.ActorMessageSenders[id] = actorMessageSender;
            return(actorMessageSender);
        }
Example #28
0
 /// <summary>
 /// 创建一个新Session
 /// </summary>
 public virtual Session Create(IPEndPoint ipEndPoint)
 {
     try
     {
         AChannel channel = this.Service.ConnectChannel(ipEndPoint);
         Session  session = ComponentFactory.CreateWithId <Session, NetworkComponent, AChannel>(IdGenerater.GenerateId(), this, channel);
         session.Parent         = this;
         channel.ErrorCallback += (c, e) => { this.Remove(session.Id); };
         this.sessions.Add(session.Id, session);
         return(session);
     }
     catch (Exception e)
     {
         Log.Error(e);
         return(null);
     }
 }
 //获取
 public ActorLocationSender Get(long id)
 {
     if (id == 0)
     {
         throw new Exception($"actor id is 0");
     }
     //如果包含了 就直接返回
     if (this.ActorLocationSenders.TryGetValue(id, out ActorLocationSender actorLocationSender))
     {
         return(actorLocationSender);
     }
     //如果没有包含
     //就创建一个sender组件 并且设置组件的id等于传递进来的Id(单位Id)
     actorLocationSender           = ComponentFactory.CreateWithId <ActorLocationSender>(id);
     actorLocationSender.Parent    = this;
     this.ActorLocationSenders[id] = actorLocationSender;
     return(actorLocationSender);
 }
Example #30
0
        public static Unit Create(long id)
        {
            ResourcesComponent resourcesComponent = Game.Scene.GetComponent <ResourcesComponent>();
            GameObject         bundleGameObject   = (GameObject)resourcesComponent.GetAsset("Unit");
            GameObject         prefab             = bundleGameObject.Get <GameObject>("Skeleton");

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

            GameObject go   = UnityEngine.Object.Instantiate(prefab);
            Unit       unit = ComponentFactory.CreateWithId <Unit, GameObject>(id, go);

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

            unitComponent.Add(unit);
            return(unit);
        }