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(); }
protected override async Task OnAttached() { await base.OnAttached(); AttachedObject.GetComponent <AddressByPartitionKeyComponent>() .KeyChanged += AddressByPartitionKeyChanged; }
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)); }
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 { })); }
Task IHandle <KickPlayer> .Handle(KickPlayer message) { AttachedObject.GetComponent <GameTickComponent>() .Tick -= OnGameTick; _isOnline = false; return(Task.CompletedTask); }
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)); }
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; } }
Task IHandle <BeginLogin> .Handle(BeginLogin message) { AttachedObject.GetComponent <GameTickComponent>() .Tick -= OnGameTick; _isOnline = false; return(Task.CompletedTask); }
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)); }
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); } } } } }
protected override void OnAttached() { _loaded = false; _chunkLoader = GrainFactory.GetGrain <IUserChunkLoader>(AttachedObject.GetPrimaryKey()); AttachedObject.RegisterPropertyChangedHandler(ViewDistanceComponent.ViewDistanceProperty, OnViewDistanceChanged); AttachedObject.GetComponent <GameTickComponent>().Tick += OnGameTick; }
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); }
Task IHandle <PlayerLoggedIn> .Handle(PlayerLoggedIn message) { _keepAliveWaiters.Clear(); _isOnline = true; AttachedObject.GetComponent <GameTickComponent>() .Tick += OnGameTick; return(Task.CompletedTask); }
private void OnEntityHeadYawChanged(object sender, PropertyChangedEventArgs <float> e) { _broadcastComponent = _broadcastComponent ?? AttachedObject.GetComponent <ChunkEventBroadcastComponent>(); _broadcastComponent.GetGenerator(AttachedObject) .EntityHeadLook( AttachedObject.EntityId, GetAngle(e.NewValue)); }
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); }
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); }
protected override void OnAttached() { _windows = new Dictionary <byte, WindowContext> { { 0, new WindowContext { Window = AttachedObject.GetComponent <InventoryComponent>().GetInventoryWindow() } } }; }
protected override void OnAttached() { var tickComponent = AttachedObject.GetComponent <GameTickComponent>(); if (tickComponent != null) { tickComponent.Tick += OnGameTick; } }
public override async UniTask Init(CancellationToken ct) { DetachableFragment = AttachedObject.GetComponent <DetachableFragment>(); if (QSBCore.IsHost) { LeashLength = Random.Range(MeteorManager.WhiteHoleVolume._debrisDistMin, MeteorManager.WhiteHoleVolume._debrisDistMax); } }
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)); }
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); }
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)); }
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); }
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; }
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); }
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); }
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 { } }
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); }