private void OnLoadChannelsComplete(RealmEventArgs args)
        {
            Validation.IsNotNull(args, "args");
            Validation.IsNotNull(args.Data, "args.Data");

            var data = args.Data.ToDictionaryAtom();

            if (!data.GetBool("success"))
            {
                throw new ProcedureFailureException("Load Failure", GetType());
            }

            var commandResults = data.GetAtom <ListAtom>("commandResult");
            var results        = commandResults.GetEnumerator().Current.CastAs <DictionaryAtom>().GetAtom <ListAtom>("Results");

            using (var it = results.GetEnumerator())
            {
                while (it.MoveNext())
                {
                    var result     = it.Current.CastAs <DictionaryAtom>();
                    var channelDef = (ChannelDef)_staticDataManager.GetStaticData(Globals.SystemTypes.Channel, result.GetInt("ChannelPrimitiveID").ToString());
                    var obj        = _entityManager.Create <Channel>(result.GetInt("ChannelID"), result.GetString("Name"), result, channelDef);
                    if (obj == null)
                    {
                        throw new InstantiationException("Failed to instantiate Channel {0}", result.GetInt("ChannelID"));
                    }

                    obj.OnInit(_entityManager.InitializationAtom);
                    _repository.Add(obj.ID, obj);
                }
            }

            _log.DebugFormat("Loaded {0} channels.", _repository.Count);
            _callback?.Invoke(new RealmEventArgs());
        }
        private static void InvokeVehicleNatives(IEntityManager entityManager, TestingFastNative fastProxy)
        {
            // Call CreateVehicle native
            var testPosition  = new Vector3(65.13f, 123.123f, 555.555f);
            var fastVehicleId = fastProxy.CreateVehicle((int)VehicleModelType.Landstalker, testPosition.X,
                                                        testPosition.Y, testPosition.Z, 15, -1, -1, -1, 0);

            // Create Vehicle entity to verify vehicle position was set properly through the native
            var entity = SampEntities.GetVehicleId(fastVehicleId);

            entityManager.Create(entity);

            entityManager.AddComponent <NativeVehicle>(entity);
            var fastVehicleComp = entityManager.AddComponent <Vehicle>(entity);

            Console.WriteLine(
                $"Created vehicle {fastVehicleId} position {fastVehicleComp.Position}; matches? {(fastVehicleComp.Position == testPosition)}");

            // Call GetVehiclePos
            Console.WriteLine("GOGO GetVehiclePos");
            var ret = fastProxy.GetVehiclePos(fastVehicleId, out var x, out var y, out var z);

            Console.WriteLine("DONE GetVehiclePos");
            var getPos = new Vector3(x, y, z);

            Console.WriteLine($"get pos ({ret}): {getPos} matches? {(testPosition == getPos)}");
        }
示例#3
0
        public T Create <T>(T entity)
        {
            CheckDisposed();
            bool internalCommit = false;

            if (_tx == null)
            {
                internalCommit = true;
                _tx            = _exe.BeginTransaction();
            }
            try
            {
                _mgr.Create(entity);
                if (internalCommit)
                {
                    _tx.Commit();
                }
                return(entity);
            }
            catch
            {
                if (internalCommit)
                {
                    _tx.Rollback();
                }
                throw;
            }
        }
        protected virtual void Handle(ThreadCreated evnt)
        {
            var thread = _entityManager.Build <ThreadEntity>(evnt);

            thread.IsStick   = evnt.StickInfo.IsStick;
            thread.StickDate = evnt.StickInfo.StickDate;
            _entityManager.Create(thread);
        }
示例#5
0
        public void ShouldCreateCheckAndDestroyEntities()
        {
            var lastChangedEntity = IgnisConstants.NonExistingEntityId;

            em.OnEntityCreated   += (s, e) => lastChangedEntity = e.EntityID;
            em.OnEntityDestroyed += (s, e) => lastChangedEntity = e.EntityID;

            em.EntityCount.Should().Be(0);
            em.GetEntityIds().Should().BeEquivalentTo(Enumerable.Empty <int>());

            var firstEntity = em.Create();

            firstEntity.Should().NotBe(IgnisConstants.NonExistingEntityId);
            em.Exists(firstEntity).Should().BeTrue("first entity was created");
            em.EntityCount.Should().Be(1, "one entity was created");
            em.GetEntityIds().Should().BeEquivalentTo(new int[] { firstEntity });
            lastChangedEntity.Should().Be(firstEntity);

            var secondEntity = em.Create();

            secondEntity.Should().NotBe(IgnisConstants.NonExistingEntityId);
            secondEntity.Should().NotBe(firstEntity, "two separate entities");
            em.Exists(secondEntity).Should().BeTrue("second entity was created");
            em.EntityCount.Should().Be(2, "two entities were created");
            em.GetEntityIds().Should().BeEquivalentTo(new int[] { firstEntity, secondEntity });
            lastChangedEntity.Should().Be(secondEntity);

            em.Destroy(firstEntity);
            em.Exists(firstEntity).Should().BeFalse("first entity was destroyed");
            em.EntityCount.Should().Be(1, "one of two entities was destroyed");
            em.GetEntityIds().Should().BeEquivalentTo(new int[] { secondEntity });
            lastChangedEntity.Should().Be(firstEntity);

            em.Destroy(secondEntity);
            em.Exists(secondEntity).Should().BeFalse("second entity was destroyed");
            em.EntityCount.Should().Be(0, "no entities left");
            em.GetEntityIds().Should().BeEquivalentTo(Enumerable.Empty <int>());
            lastChangedEntity.Should().Be(secondEntity);

            em.Destroy(IgnisConstants.NonExistingEntityId);
        }
示例#6
0
        public IActionResult Insert(EntityCreateViewModel EntityViewModel)
        {
            var Entity = EntityViewModel.Entity;

            if (ModelState.IsValid)
            {
                int EntityId = _entityManager.Create(Entity);
                return(RedirectToAction("Details", new { id = EntityId }));
            }

            return(RedirectToAction("Insert"));
        }
        public object Invoke(EventContext context, IEntityManager entityManager)
        {
            // TODO: Parenting to connection
            var entity = SampEntities.GetPlayerId((int)context.Arguments[0]);

            entityManager.Create(entity);
            entityManager.AddComponent <NativePlayer>(entity);
            entityManager.AddComponent <Player>(entity);

            context.Arguments[0] = entity;

            return(_next(context));
        }
        protected virtual void Handle(BookCreated evnt)
        {
            var book = new BookEntity
            {
                Id          = evnt.Id,
                Name        = evnt.BookInfo.Name,
                Description = evnt.BookInfo.Description,
                Author      = evnt.BookInfo.Author,
                ISBN        = evnt.BookInfo.ISBN,
                Publisher   = evnt.BookInfo.Publisher
            };

            _entityManager.Create(book);
        }
        protected virtual void Handle(ForumCreated evnt)
        {
            var forum = new ForumEntity
            {
                Id                 = evnt.Id,
                Name               = evnt.Name,
                TotalThread        = evnt.State.TotalThread,
                TotalPost          = evnt.State.TotalPost,
                LatestThreadId     = evnt.State.LatestThreadId,
                LatestPostAuthorId = evnt.State.LatestPostAuthorId
            };

            _entityManager.Create(forum);
        }
示例#10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="startupSet"></param>
        /// <param name="zoneList"></param>
        public void LoadStartupEntities(BooleanSet startupSet, IEnumerable <int> zoneList)
        {
            Log.DebugFormat("Beginning to load {0} startup entities.", zoneList.Count());

            Validation.IsNotNull(zoneList, "zoneList");

            var count = 0;

            zoneList.ToList().ForEach(id =>
            {
                var def = _staticDataManager.GetStaticData(Globals.SystemTypes.Zone.GetValue(),
                                                           id.ToString(CultureInfo.InvariantCulture));
                if (def == null)
                {
                    throw new InvalidDataException(string.Format(Resources.ERR_ZONE_DEF_NOT_FOUND, id));
                }

                var zoneDef = def.CastAs <ZoneDef>();
                if (zoneDef == null)
                {
                    throw new InvalidDataException(string.Format(Resources.ERR_DEF_WAS_NOT_ZONE_DEF, id));
                }
                Log.DebugFormat("Zone Definition {0} loaded.", zoneDef.ID);

                var obj = _entityManager.Create <Zone>(id, zoneDef.Name, zoneDef);
                if (obj == null)
                {
                    throw new InstantiationException(Resources.ERR_FAILURE_INSTANTIATE, typeof(Zone), id,
                                                     zoneDef.ID);
                }

                Log.DebugFormat("Zone {0} loaded.", id);
                startupSet.AddItem($"Zone{id}");
                obj.OnInit(_initAtom);
                count++;
            });

            Log.InfoFormat(Resources.MSG_ZONE_STARTUP, count);
            EventManager.ThrowEvent <OnStartupEntitiesLoaded>(this, new EventTable {
                { "BooleanSet", startupSet }
            });
        }
示例#11
0
 public static IAiState GetDeadState(this IEntityManager manager, IRegularMob mob)
 {
     return(manager.Create(new AiStateFactoryHelper(), "dead", mob).CastAs <IAiState>());
 }
示例#12
0
        public void OnGameModeInit(IWorldService worldService, IEntityManager entityManager, INativeObjectProxyFactory proxyFactory, ITimerService timerService)
        {
            // Only test FastNative performance if FastNative is not activated
            if (proxyFactory is FastNativeBasedNativeObjectProxyFactory)
            {
                return;
            }

            //timerService.Start(_ => BenchmarkRunTimer(), TimeSpan.FromSeconds(2));
            timerService.Start(_ => BenchmarkRunTimerProxy(), TimeSpan.FromSeconds(2));

            _nativeGetVehicleParamsEx = Interop.FastNativeFind("GetVehicleParamsEx");
            _testVehicleId            = worldService.CreateVehicle(VehicleModelType.BMX, Vector3.One, 0, 0, 0).Entity.Handle;

            var fastFactory = new FastNativeBasedNativeObjectProxyFactory(_client);
            var handleProxy = NativeObjectProxyFactory.CreateInstance <TestingFastNative>();
            var fastProxy   = (TestingFastNative)fastFactory.CreateInstance(typeof(TestingFastNative));

            _fastProxy = fastProxy;

            // Call IsPlayerConnected
            timerService.Start(_ =>
            {
                Console.WriteLine("RequiresInvoke: " + ((ISynchronizationProvider)_client).InvokeRequired);
                Console.WriteLine("IsPlayerConnected fast: " + fastProxy.IsPlayerConnected(0));
                Console.WriteLine("IsPlayerConnected handle: " + handleProxy.IsPlayerConnected(0));

                Task.Run(() =>
                {
                    Console.WriteLine("TASK.RequiresInvoke: " + ((ISynchronizationProvider)_client).InvokeRequired);
                    Console.WriteLine("TASK.IsPlayerConnected fast: " + fastProxy.IsPlayerConnected(0));
                    Console.WriteLine("TASK.IsPlayerConnected handle: " + handleProxy.IsPlayerConnected(0));
                });
            }, TimeSpan.FromSeconds(1));


            // Call CreateVehicle native
            var testPosition  = new Vector3(65.13f, 123.123f, 555.555f);
            var fastVehicleId = fastProxy.CreateVehicle((int)VehicleModelType.Landstalker, testPosition.X,
                                                        testPosition.Y, testPosition.Z, 15, -1, -1, -1, 0);

            // Create Vehicle entity to verify vehicle position was set properly through the native
            var entity = SampEntities.GetVehicleId(fastVehicleId);

            entityManager.Create(entity);

            entityManager.AddComponent <NativeVehicle>(entity);
            var fastVehicleComp = entityManager.AddComponent <Vehicle>(entity);

            Console.WriteLine($"Created vehicle {fastVehicleId} position {fastVehicleComp.Position}; matches? {(fastVehicleComp.Position == testPosition)}");

            // Call GetVehiclePos
            var ret    = fastProxy.GetVehiclePos(fastVehicleId, out var x, out var y, out var z);
            var getPos = new Vector3(x, y, z);

            Console.WriteLine($"get pos ({ret}): {getPos} matches? {(testPosition == getPos)}");

            // Test immediate call to SetGameModeText
            // var nativeSetGameModeText = Interop.FastNativeFind("SetGameModeText");
            // SetGameModeTextCall(nativeSetGameModeText, "TestValue");

            // Test via proxy
            fastProxy.SetGameModeText("TestValueViaProxy");
        }
 public async Task Consume(ConsumeContext <CreateEntityRequest> context)
 {
     var id = _entityManager.Create(context.Message.TypeId);
     await context.RespondAsync <CreateEntityResponse>(new { EntityId = id });
 }
示例#14
0
 private Action CreateCommandAction(List <string> args) => () => _manager.Create();
示例#15
0
 public void Create(T entity)
 {
     em.Create(entity);
 }