Exemplo n.º 1
0
        /// <inheritdoc />
        public void Show <TResponse>(EntityId player, IDialog <TResponse> dialog, Action <TResponse> responseHandler)
            where TResponse : struct
        {
            if (!player.IsOfType(SampEntities.PlayerType))
            {
                throw new InvalidEntityArgumentException(nameof(player), SampEntities.PlayerType);
            }

            if (dialog == null)
            {
                throw new ArgumentNullException(nameof(dialog));
            }

            _entityManager.Destroy <VisibleDialog>(player);

            var native = _entityManager.GetComponent <NativePlayer>(player);

            native.ShowPlayerDialog(DialogId, (int)dialog.Style, dialog.Caption ?? string.Empty,
                                    dialog.Content ?? string.Empty, dialog.Button1 ?? string.Empty, dialog.Button2);


            void Handler(DialogResult result)
            {
                // Destroy the visible dialog component before the dialog handler might replace it with a new dialog.
                _entityManager.Destroy <VisibleDialog>(player);

                var translated = dialog.Translate(result);

                responseHandler?.Invoke(translated);
            }

            _entityManager.AddComponent <VisibleDialog>(player, dialog, (Action <DialogResult>)Handler);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        public object Invoke(EventContext context, IEntityManager entityManager)
        {
            var entity = SampEntities.GetPlayerId((int)context.Arguments[0]);

            if (!entityManager.Exists(entity))
            {
                return(null);
            }

            context.Arguments[0] = entity;

            var result = _next(context);

            entityManager.Destroy(entity);

            return(result);
        }
Exemplo n.º 4
0
        public async void RearCommand(Player player, IEntityManager entityManager, IWorldService worldService,
                                      IVehicleInfoService vehicleInfoService)
        {
            var labels = new List <EntityId>();

            foreach (var vehicle in entityManager.GetComponents <Vehicle>())
            {
                var model = vehicle.Model;

                var size   = vehicleInfoService.GetModelInfo(model, VehicleModelInfoType.Size);
                var bumper = vehicleInfoService.GetModelInfo(model, VehicleModelInfoType.RearBumperZ);
                var offset = new Vector3(0, -size.Y / 2, bumper.Z);

                var rotation = vehicle.RotationQuaternion;

                var mRotation =
                    rotation.LengthSquared >
                    10000 // Unoccupied vehicle updates corrupt the internal vehicle world matrix
                        ? Matrix.CreateRotationZ(MathHelper.ToRadians(vehicle.Angle))
                        : Matrix.CreateFromQuaternion(rotation);

                var matrix = Matrix.CreateTranslation(offset) *
                             mRotation *
                             Matrix.CreateTranslation(vehicle.Position);

                var point = matrix.Translation;

                var label = worldService.CreateTextLabel("[x]", Color.Blue, point, 100, 0, false);
                labels.Add(label.Entity);
            }

            player.SendClientMessage("Points added");

            await Task.Delay(10000);

            foreach (var l in labels)
            {
                entityManager.Destroy(l);
            }

            player.SendClientMessage("Points removed");
        }