Exemplo n.º 1
0
        async Task IHandle <PlayerLoggedIn> .Handle(PlayerLoggedIn message)
        {
            var generator = AttachedObject.GetComponent <ClientboundPacketComponent>().GetGenerator();

            // PositionAndLook
            var position      = AttachedObject.GetEntityWorldPosition();
            var lookComponent = AttachedObject.GetComponent <EntityLookComponent>();
            await generator.PositionAndLook(position.X, position.Y, position.Z, lookComponent.Yaw, lookComponent.Pitch, 0, AttachedObject.GetComponent <TeleportComponent>().StartNew());

            // Health
            var healthComponent = AttachedObject.GetComponent <HealthComponent>();
            var foodComponent   = AttachedObject.GetComponent <FoodComponent>();
            await generator.UpdateHealth(healthComponent.Health, healthComponent.MaxHealth, foodComponent.Food, foodComponent.MaxFood, foodComponent.FoodSaturation);

            // Experience
            var expComponent = AttachedObject.GetComponent <ExperienceComponent>();
            await generator.SetExperience(expComponent.ExperienceBar, expComponent.Level, expComponent.TotalExperience);

            // Inventory
            var slots = await AttachedObject.GetComponent <InventoryComponent>().GetInventoryWindow().GetSlots(AttachedObject);

            await generator.WindowItems(0, slots);

            InstallPropertyChangedHandlers();
        }
Exemplo n.º 2
0
        protected override async Task OnAttached()
        {
            await base.OnAttached();

            AttachedObject.GetComponent <AddressByPartitionKeyComponent>()
            .KeyChanged += AddressByPartitionKeyChanged;
        }
Exemplo n.º 3
0
        private void OnEntityWorldPositionChanged(object sender, PropertyChangedEventArgs <EntityWorldPos> e)
        {
            var generator = AttachedObject.GetComponent <ClientboundPacketComponent>().GetGenerator();

            // Update Collider
            var pos = e.NewValue;
            var box = new Cuboid(new Point3d(pos.X, pos.Z, pos.Y), new Size(0.6f, 0.6f, 1.75f));

            AttachedObject.SetLocalValue(ColliderComponent.ColliderShapeProperty, box);

            // Check if we need to send UpdateViewPosition packet. If the player walk cross chunk borders, send it.
            var oldChunkPos = e.OldValue.ToChunkWorldPos();
            var newChunkPos = e.NewValue.ToChunkWorldPos();

            if (oldChunkPos != newChunkPos)
            {
                generator.UpdateViewPosition(newChunkPos.X, newChunkPos.Z);
            }

            // Broadcast to trackers
            _broadcastComponent = _broadcastComponent ?? AttachedObject.GetComponent <ChunkEventBroadcastComponent>();
            _broadcastComponent.GetGenerator(AttachedObject)
            .EntityRelativeMove(
                AttachedObject.EntityId,
                GetDelta(e.OldValue.X, e.NewValue.X),
                GetDelta(e.OldValue.Y, e.NewValue.Y),
                GetDelta(e.OldValue.Z, e.NewValue.Z),
                AttachedObject.GetValue(EntityOnGroundComponent.IsOnGroundProperty));
        }
Exemplo n.º 4
0
        protected override Task SendSpawnPacket(ClientPlayPacketGenerator generator)
        {
            MobType type = AttachedObject.GetComponent <MobTypeComponent>().MobType;

            return(generator.SpawnMob(AttachedObject.EntityId, AttachedObject.UUID, (byte)type, AttachedObject.Position, AttachedObject.Pitch, AttachedObject.Yaw, new EntityMetadata.Entity {
            }));
        }
Exemplo n.º 5
0
 Task IHandle <KickPlayer> .Handle(KickPlayer message)
 {
     AttachedObject.GetComponent <GameTickComponent>()
     .Tick    -= OnGameTick;
     _isOnline = false;
     return(Task.CompletedTask);
 }
Exemplo n.º 6
0
        public Task Teleport(EntityWorldPos position, float yaw, float pitch)
        {
            var  generator  = AttachedObject.GetComponent <ClientboundPacketComponent>().GetGenerator();
            uint teleportId = AttachedObject.GetComponent <TeleportComponent>().StartNew();

            return(generator.PositionAndLook(position.X, position.Y, position.Z, yaw, pitch, 0, teleportId));
        }
Exemplo n.º 7
0
 protected override void OnAttached()
 {
     AttachedObject.GetComponent <AddressByPartitionKeyComponent>()
     .KeyChanged += AddressByPartitionKeyChanged;
     AttachedObject.RegisterPropertyChangedHandler(IsEnabledComponent.IsEnabledProperty, OnIsEnabledChanged);
     AttachedObject.QueueOperation(TrySubscribe);
 }
        private async Task DispatchPacket(PlayerDigging packet)
        {
            var face      = ConvertDiggingFace(packet.Face);
            var component = AttachedObject.GetComponent <DiggingComponent>();

            switch (packet.Status)
            {
            case PlayerDiggingStatus.StartedDigging:
                await component.StartDigging(packet.Location, face);

                break;

            case PlayerDiggingStatus.CancelledDigging:
                await component.CancelDigging(packet.Location, face);

                break;

            case PlayerDiggingStatus.FinishedDigging:
                await component.FinishDigging(packet.Location, face);

                break;

            default:
                Logger.LogWarning($"Not implemented digging status: {packet.Status}");
                break;
            }
        }
Exemplo n.º 9
0
 Task IHandle <BeginLogin> .Handle(BeginLogin message)
 {
     AttachedObject.GetComponent <GameTickComponent>()
     .Tick    -= OnGameTick;
     _isOnline = false;
     return(Task.CompletedTask);
 }
Exemplo n.º 10
0
        private void OnHeadYawChanged(object sender, PropertyChangedEventArgs <float> e)
        {
            uint eid     = AttachedObject.GetValue(EntityIdComponent.EntityIdProperty);
            byte headyaw = (byte)(AttachedObject.GetValue(EntityLookComponent.HeadYawProperty) / 360 * 255);

            AttachedObject.QueueOperation(() => AttachedObject.GetComponent <ChunkEventBroadcastComponent>().GetGenerator().EntityHeadLook(eid, headyaw));
        }
Exemplo n.º 11
0
        public async Task PlaceBlock(BlockWorldPos location, EntityInteractHand hand, PlayerDiggingFace face, Vector3 cursorPosition)
        {
            if (face != PlayerDiggingFace.Special)
            {
                var world      = AttachedObject.GetWorld();
                var blockState = await world.GetBlockState(GrainFactory, location);

                var blockHandler = BlockHandler.Create((BlockId)blockState.Id);
                if (blockHandler.IsUsable)
                {
                    await blockHandler.UseBy(AttachedObject, GrainFactory, world, location, cursorPosition);
                }
                else
                {
                    var heldItem = await AttachedObject.GetComponent <HeldItemComponent>().GetHeldItem();

                    if (!heldItem.slot.IsEmpty)
                    {
                        var itemHandler = ItemHandler.Create((uint)heldItem.slot.BlockId);
                        if (itemHandler.IsPlaceable)
                        {
                            var inventory = AttachedObject.GetComponent <InventoryComponent>().GetInventoryWindow();
                            await itemHandler.PlaceBy(AttachedObject, GrainFactory, world, location, inventory, heldItem.index, face, cursorPosition);
                        }
                    }
                }
            }
        }
Exemplo n.º 12
0
 protected override void OnAttached()
 {
     _loaded      = false;
     _chunkLoader = GrainFactory.GetGrain <IUserChunkLoader>(AttachedObject.GetPrimaryKey());
     AttachedObject.RegisterPropertyChangedHandler(ViewDistanceComponent.ViewDistanceProperty, OnViewDistanceChanged);
     AttachedObject.GetComponent <GameTickComponent>().Tick += OnGameTick;
 }
Exemplo n.º 13
0
        private async Task SendPlayerListAddPlayer(IReadOnlyList <IPlayer> players)
        {
            var desc = await Task.WhenAll(from p in players
                                          select p.Ask(AskPlayerDescription.Default));

            await AttachedObject.GetComponent <ClientboundPacketComponent>().GetGenerator()
            .PlayerListItemAddPlayer(desc);
        }
Exemplo n.º 14
0
 Task IHandle <PlayerLoggedIn> .Handle(PlayerLoggedIn message)
 {
     _keepAliveWaiters.Clear();
     _isOnline = true;
     AttachedObject.GetComponent <GameTickComponent>()
     .Tick += OnGameTick;
     return(Task.CompletedTask);
 }
Exemplo n.º 15
0
 private void OnEntityHeadYawChanged(object sender, PropertyChangedEventArgs <float> e)
 {
     _broadcastComponent = _broadcastComponent ?? AttachedObject.GetComponent <ChunkEventBroadcastComponent>();
     _broadcastComponent.GetGenerator(AttachedObject)
     .EntityHeadLook(
         AttachedObject.EntityId,
         GetAngle(e.NewValue));
 }
Exemplo n.º 16
0
 private Task DispatchPacket(PlayerPosition packet)
 {
     AttachedObject.GetComponent <EntityWorldPositionComponent>()
     .SetPosition(new EntityWorldPos((float)packet.X, (float)packet.FeetY, (float)packet.Z));
     AttachedObject.GetComponent <EntityOnGroundComponent>()
     .SetIsOnGround(packet.OnGround);
     return(Task.CompletedTask);
 }
Exemplo n.º 17
0
        public async Task ClickWindow(byte windowId, short slot, ClickAction clickAction, short actionNumber, Slot clickedItem)
        {
            var window = GetWindow(windowId);
            await window.Window.Click(AttachedObject, slot, clickAction, clickedItem);

            await AttachedObject.GetComponent <ClientboundPacketComponent>().GetGenerator()
            .ConfirmTransaction(windowId, window.ActionNumber++, true);
        }
Exemplo n.º 18
0
 protected override void OnAttached()
 {
     _windows = new Dictionary <byte, WindowContext>
     {
         { 0, new WindowContext {
               Window = AttachedObject.GetComponent <InventoryComponent>().GetInventoryWindow()
           } }
     };
 }
Exemplo n.º 19
0
        protected override void OnAttached()
        {
            var tickComponent = AttachedObject.GetComponent <GameTickComponent>();

            if (tickComponent != null)
            {
                tickComponent.Tick += OnGameTick;
            }
        }
Exemplo n.º 20
0
        public override async UniTask Init(CancellationToken ct)
        {
            DetachableFragment = AttachedObject.GetComponent <DetachableFragment>();

            if (QSBCore.IsHost)
            {
                LeashLength = Random.Range(MeteorManager.WhiteHoleVolume._debrisDistMin, MeteorManager.WhiteHoleVolume._debrisDistMax);
            }
        }
Exemplo n.º 21
0
        private void OnPositionChanged(object sender, PropertyChangedEventArgs <EntityWorldPos> e)
        {
            uint  eid        = AttachedObject.GetValue(EntityIdComponent.EntityIdProperty);
            short x          = (short)((e.NewValue.X - e.OldValue.X) * 32 * 128);
            short y          = (short)((e.NewValue.Y - e.OldValue.Y) * 32 * 128);
            short z          = (short)((e.NewValue.Z - e.OldValue.Z) * 32 * 128);
            bool  isOnGround = AttachedObject.GetValue(EntityOnGroundComponent.IsOnGroundProperty);

            AttachedObject.QueueOperation(() => AttachedObject.GetComponent <ChunkEventBroadcastComponent>().GetGenerator().EntityRelativeMove(eid, x, y, z, isOnGround));
        }
Exemplo n.º 22
0
        Task IHandle <SpawnEntity> .Handle(SpawnEntity message)
        {
            AttachedObject.GetComponent <WorldComponent>().SetWorld(message.World);
            AttachedObject.GetComponent <EntityWorldPositionComponent>().SetPosition(message.Position);
            var lookComponent = AttachedObject.GetComponent <EntityLookComponent>();

            lookComponent.SetPitch(message.Pitch);
            lookComponent.SetYaw(message.Yaw);
            return(Task.CompletedTask);
        }
Exemplo n.º 23
0
        private void OnPitchChanged(object sender, PropertyChangedEventArgs <float> e)
        {
            uint eid      = AttachedObject.GetValue(EntityIdComponent.EntityIdProperty);
            byte yaw      = (byte)(AttachedObject.GetValue(EntityLookComponent.YawProperty) / 360 * 255);
            byte pitch    = (byte)(AttachedObject.GetValue(EntityLookComponent.PitchProperty) / 360 * 255);
            bool onGround = AttachedObject.GetValue(EntityOnGroundComponent.IsOnGroundProperty);

            // return AttachedObject.GetComponent<ChunkEventBroadcastComponent>().GetGenerator().EntityLook(eid, yaw, pitch, onGround);
            AttachedObject.QueueOperation(() => AttachedObject.GetComponent <ChunkEventBroadcastComponent>().GetGenerator().EntityLookAndRelativeMove(eid, 0, 0, 0, yaw, pitch, onGround));
        }
Exemplo n.º 24
0
        private Task DispatchPacket(PlayerLook packet)
        {
            var lookComponent = AttachedObject.GetComponent <EntityLookComponent>();

            lookComponent.SetPitch(packet.Pitch);
            lookComponent.SetYaw(packet.Yaw);
            AttachedObject.GetComponent <EntityOnGroundComponent>()
            .SetIsOnGround(packet.OnGround);
            return(Task.CompletedTask);
        }
Exemplo n.º 25
0
        async Task IHandle <BindToUser> .Handle(BindToUser message)
        {
            AttachedObject.GetComponent <SlotContainerComponent>().SlotChanged -= InventorySlotChanged;

            _user = message.User;
            AttachedObject.GetComponent <NameComponent>().SetName(await message.User.GetName());
            AttachedObject.GetComponent <SlotContainerComponent>().SetSlots(await message.User.GetInventorySlots());

            AttachedObject.GetComponent <SlotContainerComponent>().SlotChanged += InventorySlotChanged;
        }
Exemplo n.º 26
0
        protected override Task SendLookPacket(ClientPlayPacketGenerator generator)
        {
            uint eid      = AttachedObject.GetComponent <EntityIdComponent>().EntityId;
            byte yaw      = (byte)(AttachedObject.GetComponent <EntityLookComponent>().Yaw / 360 * 255);
            byte pitch    = (byte)(AttachedObject.GetComponent <EntityLookComponent>().Pitch / 360 * 255);
            bool onGround = AttachedObject.GetComponent <EntityOnGroundComponent>().IsOnGround;

            generator.EntityLook(eid, yaw, pitch, onGround);
            return(Task.CompletedTask);
        }
        Task IHandle <DestroyEntity> .Handle(DestroyEntity message)
        {
            if (AttachedObject.EntityId != 0)
            {
                return(AttachedObject.GetComponent <ChunkEventBroadcastComponent>().GetGenerator()
                       .DestroyEntities(new[] { AttachedObject.EntityId }));
            }

            return(Task.CompletedTask);
        }
Exemplo n.º 28
0
        protected override Task SendLookPacket(ClientPlayPacketGenerator generator)
        {
            uint  eid      = AttachedObject.GetComponent <EntityIdComponent>().EntityId;
            float yaw      = AttachedObject.GetComponent <EntityLookComponent>().Yaw;
            float pitch    = AttachedObject.GetComponent <EntityLookComponent>().Pitch;
            bool  onGround = AttachedObject.GetComponent <EntityOnGroundComponent>().IsOnGround;

            // TODO player look
            // generator.;
            return(Task.CompletedTask);
        }
Exemplo n.º 29
0
 private async Task DispatchPacket(ClickWindow packet)
 {
     try
     {
         await AttachedObject.GetComponent <WindowManagerComponent>()
         .ClickWindow(packet.WindowId, packet.Slot, ToClickAction(packet.Button, packet.Mode, packet.Slot), packet.ActionNumber, packet.ClickedItem);
     }
     catch
     {
     }
 }
Exemplo n.º 30
0
        async Task IHandle <SpawnEntity> .Handle(SpawnEntity message)
        {
            await AttachedObject.GetComponent <WorldComponent>().SetWorld(message.World);

            await AttachedObject.GetComponent <EntityWorldPositionComponent>().SetPosition(message.Position);

            var lookComponent = AttachedObject.GetComponent <EntityLookComponent>();
            await lookComponent.SetPitch(message.Pitch);

            await lookComponent.SetYaw(message.Yaw);
        }