Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modular building rework #351

Merged
merged 9 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions Uchu.World/Enums/BuildMode.cs

This file was deleted.

3 changes: 2 additions & 1 deletion Uchu.World/Enums/ComponentId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public enum ComponentId
CombatMediatorComponent = 101,
RailActivator = 104,
Component107 = 107,
Possesable = 108
Possesable = 108,
BuildBorder = 114
}
}
34 changes: 24 additions & 10 deletions Uchu.World/Handlers/GameMessages/InventoryHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void ItemMovementHandler(MoveItemInInventoryMessage message, Player playe
var inventoryManager = message.Item.Inventory.ManagerComponent;
if (inventoryManager.GameObject != player)
return;

var destinationInventory = message.DestinationInventoryType == InventoryType.Invalid
? message.CurrentInventoryType
: message.DestinationInventoryType;
Expand All @@ -36,15 +36,15 @@ public void ItemMovementHandler(MoveItemInInventoryMessage message, Player playe
{
itemToSwap.Slot = message.Item.Slot;
}
message.Item.Slot = (uint) message.NewSlot;

message.Item.Slot = (uint)message.NewSlot;
}

[PacketHandler]
public async Task ItemMoveBetweenInventoriesHandler(MoveItemBetweenInventoryTypesMessage message, Player player)
{
var inventory = player.GetComponent<InventoryManagerComponent>();

// Sometimes an explicit item is provided, if it is available we prefer to use that to mimic the move of
// the supplied slot, otherwise we find the first item that matches the criteria and move that
if (message.Item == null)
Expand All @@ -64,18 +64,18 @@ public async Task RemoveItemHandler(RemoveItemFromInventoryMessage message, Play
{
if (!message.Confirmed || message.Item == default)
return;

await player.GetComponent<InventoryManagerComponent>()
.RemoveItemAsync(message.Item, message.Item.Count - message.TotalItems,
.RemoveItemAsync(message.Item, message.Item.Count - message.TotalItems,
message.InventoryType, true);

// Disassemble item
if (player.TryGetComponent<InventoryManagerComponent>(out var inventory)
&& message.Item.Settings.TryGetValue("assemblyPartLOTs", out var list))
{
foreach (var part in (LegoDataList) list)
foreach (var part in (LegoDataList)list)
{
await inventory.AddLotAsync((int) part, 1);
await inventory.AddLotAsync((int)part, 1);
}
}
}
Expand All @@ -92,11 +92,25 @@ public async Task EquipItemHandler(EquipItemMessage message, Player player)
public async Task UnEquipItemHandler(UnEquipItemMessage message, Player player)
{
if (message.ItemToUnEquip == null) return;

await message.ItemToUnEquip.UnEquipAsync();

if (message.ReplacementItem != null)
await message.ReplacementItem.EquipAsync();
}

[PacketHandler]
public void PopEquippedItemsStateHandler(PopEquippedItemsStateMessage message, Player player)
{
var inventory = player.GetComponent<InventoryComponent>();
inventory.PopEquippedItemState();

var destroyable = player.GetComponent<DestroyableComponent>();
destroyable.Health = destroyable.MaxHealth;
destroyable.Armor = destroyable.MaxArmor;
destroyable.Imagination = destroyable.MaxImagination;

GameObject.Serialize(player);
}
}
}
72 changes: 32 additions & 40 deletions Uchu.World/Handlers/GameMessages/ModularBuildingHandler.cs
Original file line number Diff line number Diff line change
@@ -1,81 +1,73 @@
using System;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Uchu.Core;

namespace Uchu.World.Handlers.GameMessages
{
public class ModularBuildingHandler : HandlerGroup
{
[PacketHandler]
public async Task StartBuildingHandler(StartBuildingWithItemMessage message, Player player)
{
await player.GetComponent<ModularBuilderComponent>().StartBuildingAsync(message);
}
// These Handlers are in the order in which the packets come in. Also see BuildBorderComponent

// Is sent when the player interacts with the build border
[PacketHandler]
public async Task ModularBuildFinishHandler(ModularBuildFinishMessage message, Player player)
public void StartBuildingWithItemHandler(StartBuildingWithItemMessage message, Player player)
{
await player.GetComponent<ModularBuilderComponent>().FinishBuilding(message.Modules);
Logger.Debug("[MOD_BUILD] StartBuildingWithItem");
player.GetComponent<ModularBuilderComponent>().StartBuild(message);
}

// Is sent directly after StartBuildingWithItem
[PacketHandler]
public void DoneArrangingHandler(DoneArrangingWithItemMessage message, Player player)
public void SetBuildModeHandler(SetBuildModeMessage message, Player player)
{
player.GetComponent<ModularBuilderComponent>().DoneArranging(message);
Logger.Debug("[MOD_BUILD] SetBuildMode");
player.GetComponent<ModularBuilderComponent>().SetBuildMode(message);
}

// Is sent directly after SetBuildMode to acknowledge that the build mode was set
[PacketHandler]
public async Task PickupModelHandler(ModularBuildMoveAndEquipMessage message, Player player)
public void BuildModeSetHandler(BuildModeSetMessage message, Player player)
{
await player.GetComponent<ModularBuilderComponent>().Pickup(message.Lot);
Logger.Debug("[MOD_BUILD] BuildModeSet");
Logger.Debug($"Build mode set to {message.ModeValue}");
}

// Is sent after putting a model into the blueprint
[PacketHandler]
public async Task ModelPrefabHandler(StartArrangingWithModelMessage message, Player player)
public async Task StartArrangingWithModelHandler(StartArrangingWithModelMessage message, Player player)
{
await player.GetComponent<ModularBuilderComponent>().StartBuildingWithModel(message.Item);
Logger.Debug("[MOD_BUILD] ModelPrefab");
await player.GetComponent<ModularBuilderComponent>().ModelAdded(message);
}

// Is sent after picking up a part from the blueprint or equiping a part
[PacketHandler]
public async Task BuildExitConfirmationHandler(BuildExitConfirmationMessage message, Player player)
public void ModularBuildMoveAndEquipHandler(ModularBuildMoveAndEquipMessage message, Player player)
{
await player.GetComponent<ModularBuilderComponent>().ConfirmFinish();
Logger.Debug("[MOD_BUILD] ModelPrefab");
player.GetComponent<ModularBuilderComponent>().MoveAndEquip(message);
}

// Is sent if the player finishes the build
[PacketHandler]
public void SetLastCustomBuildHandler(SetLastCustomBuildMessage message, Player player)
public async Task ModularBuildFinishHandler(ModularBuildFinishMessage message, Player player)
{
if (player.TryGetComponent<CharacterComponent>(out var characterComponent))
characterComponent.Rocket = message.Tokens;
Logger.Debug("[MOD_BUILD] ModularBuildFinish");
await player.GetComponent<ModularBuilderComponent>().FinishBuild(message);
}

// Is sent after the player has exited the build
[PacketHandler]
public void SetBuildModeHandler(SetBuildModeMessage message, Player player)
public void BuildExitConfirmationHandler(BuildExitConfirmationMessage message, Player player)
{
player.Message(new SetBuildModeConfirmedMessage
{
Associate = message.Associate,
ModePaused = message.ModePaused,
ModeValue = message.ModeValue,
Player = player,
Start = message.Start,
StartPosition = message.StartPosition
});
Logger.Debug("[MOD_BUILD] BuildExitConfirmation");
player.GetComponent<ModularBuilderComponent>().ConfirmExitBuild(message);
}

// Unknown
[PacketHandler]
public void ModuleAssemblyQueryDataHandler(ModuleAssemblyQueryDataMessage message, Player player)
public void DoneArrangingHandler(DoneArrangingWithItemMessage message, Player player)
{
if (!message.Associate.TryGetComponent<ModuleAssemblyComponent>(out var moduleAssembly))
Logger.Error($"assembly data requested for {message.Associate} but no module assembly component exists");
player.Zone.BroadcastMessage(new ModuleAssemblyDBDataForClientMessage
{
AssemblyId = GameObject.InvalidObject, // todo subkey? i think
// chassis wheels engine frontbumper rearpanel rearbumper sides
Blob = moduleAssembly.GetAssembly(),
Associate = message.Associate,
});
Logger.Debug("[MOD_BUILD] DoneArranging");
}
}
}
Loading
Loading