Beispiel #1
0
 public override void onCollide(BasicSprite collided)
 {
     base.onCollide(collided);
     // The Gentleman picked up the key
     if (collided.ToString() == "KeysToInsanity.Code.TheGentleman")
     {
         container.Remove(this);
         hud.addKey(this);
         onHUD = true;
         double angle = Math.Atan2(5 - spritePos.Y, 745 - spritePos.X) * 180.0 / Math.PI;
         velocity = Velocity.FromDirection((float)angle, 10.0f);
         timer.Start();
     }
 }
Beispiel #2
0
        internal void BroadcastPlayerDig(PlayerDiggingStore store)
        {
            var digging = store.Packet;

            var b = this.World.GetBlock(digging.Position);

            if (b is null)
            {
                return;
            }
            var block = (Block)b;

            var player = this.OnlinePlayers.GetValueOrDefault(store.Player);

            switch (digging.Status)
            {
            case DiggingStatus.DropItem:
            {
                var droppedItem = player.GetHeldItem();

                if (droppedItem is null || droppedItem.Type == Material.Air)
                {
                    return;
                }

                var loc = new VectorF(player.Position.X, (float)player.HeadY - 0.3f, player.Position.Z);

                var item = new ItemEntity
                {
                    EntityId = player + this.World.TotalLoadedEntities() + 1,
                    Count    = 1,
                    Id       = droppedItem.GetItem().Id,
                    Glowing  = true,
                    World    = this.World,
                    Position = loc
                };

                this.TryAddEntity(player.World, item);

                var lookDir = player.GetLookDirection();

                var vel = Velocity.FromDirection(loc, lookDir);        //TODO properly shoot the item towards the direction the players looking at

                this.BroadcastPacketWithoutQueue(new SpawnEntity
                    {
                        EntityId = item.EntityId,
                        Uuid     = item.Uuid,
                        Type     = EntityType.Item,
                        Position = item.Position,
                        Pitch    = 0,
                        Yaw      = 0,
                        Data     = 1,
                        Velocity = vel
                    });
                this.BroadcastPacketWithoutQueue(new EntityMetadata
                    {
                        EntityId = item.EntityId,
                        Entity   = item
                    });

                player.client.SendPacket(new SetSlot
                    {
                        Slot = player.CurrentSlot,

                        WindowId = 0,

                        SlotData = player.Inventory.GetItem(player.CurrentSlot) - 1
                    });

                player.Inventory.RemoveItem(player.CurrentSlot);
                break;
            }

            case DiggingStatus.StartedDigging:
            {
                this.BroadcastPacketWithoutQueue(new AcknowledgePlayerDigging
                    {
                        Position   = digging.Position,
                        Block      = block.Id,
                        Status     = digging.Status,
                        Successful = true
                    });

                if (player.Gamemode == Gamemode.Creative)
                {
                    this.BroadcastPacketWithoutQueue(new BlockChange(digging.Position, 0));

                    this.World.SetBlock(digging.Position, Block.Air);
                }
            }
            break;

            case DiggingStatus.CancelledDigging:
                break;

            case DiggingStatus.FinishedDigging:
            {
                this.BroadcastPacketWithoutQueue(new AcknowledgePlayerDigging
                    {
                        Position   = digging.Position,
                        Block      = block.Id,
                        Status     = digging.Status,
                        Successful = true
                    });
                this.BroadcastPacketWithoutQueue(new BlockBreakAnimation
                    {
                        EntityId     = player,
                        Position     = digging.Position,
                        DestroyStage = -1
                    });

                this.BroadcastPacketWithoutQueue(new BlockChange(digging.Position, 0));

                this.World.SetBlock(digging.Position, Block.Air);

                var droppedItem = Registry.GetItem(block.Material);

                if (droppedItem.Id == 0)
                {
                    break;
                }

                var item = new ItemEntity
                {
                    EntityId = player + this.World.TotalLoadedEntities() + 1,
                    Count    = 1,
                    Id       = droppedItem.Id,
                    Glowing  = true,
                    World    = this.World,
                    Position = digging.Position,
                    Server   = this
                };

                this.TryAddEntity(player.World, item);

                this.BroadcastPacketWithoutQueue(new SpawnEntity
                    {
                        EntityId = item.EntityId,
                        Uuid     = item.Uuid,
                        Type     = EntityType.Item,
                        Position = item.Position,
                        Pitch    = 0,
                        Yaw      = 0,
                        Data     = 1,
                        Velocity = Velocity.FromVector(digging.Position + new VectorF(
                                                           (Globals.Random.NextFloat() * 0.5f) + 0.25f,
                                                           (Globals.Random.NextFloat() * 0.5f) + 0.25f,
                                                           (Globals.Random.NextFloat() * 0.5f) + 0.25f))
                    });

                this.BroadcastPacketWithoutQueue(new EntityMetadata
                    {
                        EntityId = item.EntityId,
                        Entity   = item
                    });
                break;
            }
            }
        }
Beispiel #3
0
    public async ValueTask HandleAsync(Server server, Player player)
    {
        var container = player.OpenedContainer ?? player.Inventory;

        var(slot, forPlayer) = container.GetDifference(ClickedSlot);

        if (this.IsPlayerInventory || forPlayer)
        {
            container = player.Inventory;
        }

        switch (Mode)
        {
        case InventoryOperationMode.MouseClick:
            await HandleMouseClick(container, server, player, slot);

            break;

        case InventoryOperationMode.ShiftMouseClick:
        {
            if (ClickedItem == null)
            {
                return;
            }

            //TODO implement shift click

            break;
        }

        case InventoryOperationMode.NumberKeys:
        {
            var localSlot = Button + 36;

            var currentItem = player.Inventory.GetItem(localSlot);

            if (currentItem.IsAir() && ClickedItem != null)
            {
                container.RemoveItem(slot);

                player.Inventory.SetItem(localSlot, ClickedItem);
            }
            else if (!currentItem.IsAir() && ClickedItem != null)
            {
                container.SetItem(slot, currentItem);

                player.Inventory.SetItem(localSlot, ClickedItem);
            }
            else
            {
                container.SetItem(slot, currentItem);

                player.Inventory.RemoveItem(localSlot);
            }

            break;
        }

        case InventoryOperationMode.MiddleMouseClick:
            break;

        case InventoryOperationMode.Drop:
        {
            if (ClickedSlot != Outsideinventory)
            {
                ItemStack?removedItem;
                if (Button == 0)
                {
                    container.RemoveItem(slot, 1, out removedItem);
                }
                else
                {
                    container.RemoveItem(slot, 64, out removedItem);
                }

                if (removedItem == null)
                {
                    return;
                }

                var loc = new VectorF(player.Position.X, (float)player.HeadY - 0.3f, player.Position.Z);

                var item = new ItemEntity
                {
                    EntityId = player + player.World.GetTotalLoadedEntities() + 1,
                    Count    = 1,
                    Id       = removedItem.AsItem().Id,
                    Glowing  = true,
                    World    = player.World,
                    Position = loc
                };

                var lookDir = player.GetLookDirection();
                var vel     = Velocity.FromDirection(loc, lookDir);

                //TODO Get this shooting out from the player properly.
                server.BroadcastPacket(new SpawnEntityPacket
                    {
                        EntityId = item.EntityId,
                        Uuid     = item.Uuid,
                        Type     = EntityType.Item,
                        Position = item.Position,
                        Pitch    = 0,
                        Yaw      = 0,
                        Data     = 1,
                        Velocity = vel
                    });
                server.BroadcastPacket(new EntityMetadata
                    {
                        EntityId = item.EntityId,
                        Entity   = item
                    });
            }
            break;
        }

        case InventoryOperationMode.MouseDrag:
            HandleDragClick(container, player, slot);
            break;

        case InventoryOperationMode.DoubleClick:
        {
            if (ClickedItem == null || ClickedItem.Count >= 64)
            {
                return;
            }

            TakeFromContainer(container, player.Inventory);
            break;
        }
        }

        if (container is IBlockEntity tileEntityContainer)
        {
            var blockEntity = await player.World.GetBlockEntityAsync(tileEntityContainer.BlockPosition);

            if (blockEntity is null)
            {
                return;
            }

            if (blockEntity.TryGetTag("Items", out var list))
            {
                var items = list as NbtList;

                var itemsToBeRemoved = new HashSet <int>();
                var itemsToBeUpdated = new HashSet <NbtCompound>();

                items !.Clear();

                this.FillNbtList(items, container);
            }
            else
            {
                var items = new NbtList(NbtTagType.Compound, "Items");

                this.FillNbtList(items, container);

                blockEntity.Add(items);
            }
        }
    }