-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
* Basic Inventory Management * Equip and use Glider/Vehicle hotkeys * Remove redundant code, minor changes. * Refactor Equip methods * Send Partial Inventory * Minor cleanup
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
using GameServer.Extensions; | ||
using GameServer.Packets; | ||
using Serilog; | ||
using LoadoutVisualType = AeroMessages.GSS.V66.Character.LoadoutConfig_Visual.LoadoutVisualType; | ||
|
||
namespace GameServer.Controllers.Character; | ||
|
||
|
@@ -407,4 +408,43 @@ public void PerformTextChat(INetworkClient client, IPlayer player, ulong entityI | |
var shard = player.CharacterEntity.Shard; | ||
shard.Chat.CharacterPerformTextChat(client, character, query); | ||
} | ||
|
||
[MessageID((byte)Commands.SlotGearRequest)] | ||
public void SlotGearRequest(INetworkClient client, IPlayer player, ulong entityId, GamePacket packet) | ||
{ | ||
var request = packet.Unpack<SlotGearRequest>(); | ||
|
||
player.CharacterEntity.EquipItemByGUID(request.LoadoutId, (LoadoutSlotType) request.SlotIdx, request.ItemGUID); | ||
Check warning on line 417 in UdpHosts/GameServer/Controllers/Character/BaseController.cs GitHub Actions / Linux .NET 8
Check warning on line 417 in UdpHosts/GameServer/Controllers/Character/BaseController.cs GitHub Actions / Windows VS2022 .NET 8
Check warning on line 417 in UdpHosts/GameServer/Controllers/Character/BaseController.cs GitHub Actions / macOS .NET 8
|
||
|
||
var response = new SlotGearResponse() | ||
{ | ||
ItemGUID = request.ItemGUID, | ||
SlotIdx = request.SlotIdx, | ||
LoadoutId = request.LoadoutId, | ||
Unk1 = request.Unk, | ||
Result = 1, | ||
}; | ||
|
||
client.NetChannels[ChannelType.ReliableGss].SendIAero(response, entityId); | ||
client.NetChannels[ChannelType.ReliableGss].SendIAero(player.CharacterEntity.Character_EquipmentView, entityId); | ||
} | ||
|
||
[MessageID((byte)Commands.SlotVisualRequest)] | ||
public void SlotVisualRequest(INetworkClient client, IPlayer player, ulong entityId, GamePacket packet) | ||
{ | ||
var request = packet.Unpack<SlotVisualRequest>(); | ||
|
||
player.CharacterEntity.EquipVisualBySdbId(request.LoadoutId, (LoadoutVisualType) request.SlotIdx1, (LoadoutSlotType) request.SlotIdx2, request.ItemSdbId); | ||
Check warning on line 437 in UdpHosts/GameServer/Controllers/Character/BaseController.cs GitHub Actions / Linux .NET 8
Check warning on line 437 in UdpHosts/GameServer/Controllers/Character/BaseController.cs GitHub Actions / Linux .NET 8
Check warning on line 437 in UdpHosts/GameServer/Controllers/Character/BaseController.cs GitHub Actions / Windows VS2022 .NET 8
Check warning on line 437 in UdpHosts/GameServer/Controllers/Character/BaseController.cs GitHub Actions / Windows VS2022 .NET 8
Check warning on line 437 in UdpHosts/GameServer/Controllers/Character/BaseController.cs GitHub Actions / macOS .NET 8
Check warning on line 437 in UdpHosts/GameServer/Controllers/Character/BaseController.cs GitHub Actions / macOS .NET 8
|
||
|
||
var response = new SlotVisualResponse() | ||
{ | ||
ConfigId = 1, | ||
SlotIdx = request.SlotIdx2, | ||
LoadoutId = (int) request.LoadoutId, | ||
Check warning on line 443 in UdpHosts/GameServer/Controllers/Character/BaseController.cs GitHub Actions / Linux .NET 8
Check warning on line 443 in UdpHosts/GameServer/Controllers/Character/BaseController.cs GitHub Actions / Windows VS2022 .NET 8
Check warning on line 443 in UdpHosts/GameServer/Controllers/Character/BaseController.cs GitHub Actions / macOS .NET 8
|
||
Result = 1, | ||
}; | ||
|
||
client.NetChannels[ChannelType.ReliableGss].SendIAero(response, entityId); | ||
client.NetChannels[ChannelType.ReliableGss].SendIAero(player.CharacterEntity.Character_ObserverView, entityId); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
using AeroMessages.GSS.V66.Character; | ||
using AeroMessages.GSS.V66.Character.Controller; | ||
using System; | ||
Check warning on line 3 in UdpHosts/GameServer/Data/CharacterInventory.cs GitHub Actions / Linux .NET 8
Check warning on line 3 in UdpHosts/GameServer/Data/CharacterInventory.cs GitHub Actions / macOS .NET 8
|
||
using System.Collections.Generic; | ||
Check warning on line 4 in UdpHosts/GameServer/Data/CharacterInventory.cs GitHub Actions / Linux .NET 8
Check warning on line 4 in UdpHosts/GameServer/Data/CharacterInventory.cs GitHub Actions / macOS .NET 8
|
||
using System.Linq; | ||
Check warning on line 5 in UdpHosts/GameServer/Data/CharacterInventory.cs GitHub Actions / Linux .NET 8
Check warning on line 5 in UdpHosts/GameServer/Data/CharacterInventory.cs GitHub Actions / macOS .NET 8
|
||
|
@@ -6,6 +8,7 @@ | |
using GameServer.Data.SDB.Records.dbcharacter; | ||
using GameServer.Entities.Character; | ||
using GameServer.Enums; | ||
using LoadoutVisualType = AeroMessages.GSS.V66.Character.LoadoutConfig_Visual.LoadoutVisualType; | ||
|
||
namespace GameServer.Data; | ||
|
||
|
@@ -84,7 +87,7 @@ public LoadoutReferenceData GetLoadoutReferenceData(uint loadoutId) | |
var refData = new LoadoutReferenceData() | ||
{ | ||
LoadoutId = loadoutId, | ||
ChassisId = loadout.ChassisID, | ||
ChassisId = loadout.ChassisID | ||
}; | ||
|
||
var pveConfig = loadout.LoadoutConfigs[0]; | ||
|
@@ -307,6 +310,44 @@ public void SendResourceUpdate(uint sdbId) | |
_player.NetChannels[ChannelType.ReliableGss].SendIAero(update, _character.EntityId); | ||
} | ||
|
||
public void SendEquipmentChanges(ulong oldItemGuid, ulong newItemGuid) | ||
{ | ||
if (!EnablePartialUpdates) | ||
{ | ||
return; | ||
} | ||
|
||
var itemChanges = new Item[] {}; | ||
if (oldItemGuid != 0) | ||
{ | ||
var oldItem = _items[oldItemGuid]; | ||
itemChanges = itemChanges.Append(oldItem).ToArray(); | ||
} | ||
Check warning on line 325 in UdpHosts/GameServer/Data/CharacterInventory.cs GitHub Actions / Linux .NET 8
Check warning on line 325 in UdpHosts/GameServer/Data/CharacterInventory.cs GitHub Actions / Windows VS2022 .NET 8
Check warning on line 325 in UdpHosts/GameServer/Data/CharacterInventory.cs GitHub Actions / macOS .NET 8
|
||
if (newItemGuid != 0) | ||
{ | ||
var newItem = _items[newItemGuid]; | ||
itemChanges = itemChanges.Append(newItem).ToArray(); | ||
} | ||
|
||
var update = new InventoryUpdate() | ||
{ | ||
ClearExistingData = 0, | ||
ItemsPart1Length = (byte) itemChanges.Length, | ||
Check warning on line 335 in UdpHosts/GameServer/Data/CharacterInventory.cs GitHub Actions / Windows VS2022 .NET 8
|
||
ItemsPart1 = itemChanges, | ||
ItemsPart2Length = 0, | ||
ItemsPart2 = Array.Empty<Item>(), | ||
ItemsPart3Length = 0, | ||
ItemsPart3 = Array.Empty<Item>(), | ||
Resources = Array.Empty<Resource>(), | ||
Loadouts = _loadouts.Values.ToArray(), | ||
Unk = 1, | ||
SecondItems = Array.Empty<Item>(), | ||
SecondResources = Array.Empty<Resource>() | ||
}; | ||
|
||
_player.NetChannels[ChannelType.ReliableGss].SendIAero(update, _character.EntityId); | ||
} | ||
|
||
private byte GetInventoryTypeByItemTypeId(uint sdbId) | ||
{ | ||
var itemInfo = SDBInterface.GetRootItem(sdbId); | ||
|
@@ -368,4 +409,79 @@ private byte GetInventoryTypeByItemType(byte itemType) | |
|
||
return (byte)result; | ||
} | ||
|
||
public void EquipItemByGUID(int loadoutId, LoadoutSlotType slot, ulong guid) | ||
{ | ||
ulong changedOldItemGUID = 0; | ||
ulong changedNewItemGUID = guid; | ||
|
||
// Unequip old Item (if any) | ||
if (_loadouts[(uint)loadoutId].LoadoutConfigs[0].Items.Any((e) => e.SlotIndex == (byte)slot)) | ||
{ | ||
// Set Item to unequipped | ||
var oldItemGUID = _loadouts[(uint)loadoutId].LoadoutConfigs[0].Items.First((e) => e.SlotIndex == (byte) slot).ItemGUID; | ||
Check warning on line 422 in UdpHosts/GameServer/Data/CharacterInventory.cs GitHub Actions / Windows VS2022 .NET 8
|
||
changedOldItemGUID = oldItemGUID; | ||
var oldItem = _items[oldItemGUID]; | ||
oldItem.DynamicFlags = (byte) ((oldItem.DynamicFlags) ^ (byte)ItemDynamicFlags.IsEquipped); | ||
Check warning on line 425 in UdpHosts/GameServer/Data/CharacterInventory.cs GitHub Actions / Linux .NET 8
Check warning on line 425 in UdpHosts/GameServer/Data/CharacterInventory.cs GitHub Actions / Windows VS2022 .NET 8
Check warning on line 425 in UdpHosts/GameServer/Data/CharacterInventory.cs GitHub Actions / macOS .NET 8
|
||
_items[oldItemGUID] = oldItem; | ||
|
||
// Update CurrentLoadout | ||
_character.CurrentLoadout.SlottedItems[slot] = 0; | ||
|
||
// Update LoadoutConfigs | ||
_loadouts[(uint)loadoutId].LoadoutConfigs[0].Items = _loadouts[(uint)loadoutId].LoadoutConfigs[0].Items | ||
.Where(e => e.SlotIndex != (byte)slot).ToArray(); | ||
} | ||
|
||
// Equip new item (if any) | ||
if (guid != 0) | ||
{ | ||
// Update Item to Equipped | ||
var item = _items[guid]; | ||
item.DynamicFlags = (byte) (item.DynamicFlags | (byte) ItemDynamicFlags.IsEquipped); | ||
Check warning on line 441 in UdpHosts/GameServer/Data/CharacterInventory.cs GitHub Actions / Windows VS2022 .NET 8
|
||
_items[guid] = item; | ||
|
||
// Update CurrentLoadout | ||
_character.CurrentLoadout.SlottedItems[slot] = item.SdbId; | ||
|
||
// Update LoadoutConfig | ||
_loadouts[(uint)loadoutId].LoadoutConfigs[0].Items = _loadouts[(uint)loadoutId].LoadoutConfigs[0].Items.Append(new LoadoutConfig_Item() { ItemGUID = guid, SlotIndex = (byte)slot }).ToArray(); | ||
} | ||
|
||
// Update StaticInfo when visuals are changed | ||
var equippedSdbId = (guid != 0) ? _items[guid].SdbId : 0; | ||
switch (slot) | ||
{ | ||
case LoadoutSlotType.Glider: | ||
_character.SetStaticInfo(_character.StaticInfo with { LoadoutGlider = equippedSdbId }); | ||
break; | ||
case LoadoutSlotType.Vehicle: | ||
_character.SetStaticInfo(_character.StaticInfo with { LoadoutVehicle = equippedSdbId }); | ||
break; | ||
} | ||
Check warning on line 461 in UdpHosts/GameServer/Data/CharacterInventory.cs GitHub Actions / Linux .NET 8
Check warning on line 461 in UdpHosts/GameServer/Data/CharacterInventory.cs GitHub Actions / Windows VS2022 .NET 8
Check warning on line 461 in UdpHosts/GameServer/Data/CharacterInventory.cs GitHub Actions / macOS .NET 8
|
||
SendEquipmentChanges(changedOldItemGUID, changedNewItemGUID); | ||
} | ||
|
||
public void EquipVisualBySdbId(uint loadoutId, LoadoutVisualType visual, LoadoutSlotType slot, uint sdb_id) | ||
{ | ||
// Unequip old item (if any) | ||
if (_loadouts[loadoutId].LoadoutConfigs[0].Visuals.Any(i => i.VisualType == visual)) | ||
{ | ||
// Update Visuals | ||
_loadouts[loadoutId].LoadoutConfigs[0].Visuals = _loadouts[loadoutId].LoadoutConfigs[0].Visuals | ||
.Where(e => e.VisualType != visual).ToArray(); | ||
} | ||
|
||
// Equip new item (if any) | ||
if (sdb_id != 0) | ||
{ | ||
// Update Visuals | ||
_loadouts[(uint)loadoutId].LoadoutConfigs[0].Visuals = _loadouts[(uint)loadoutId].LoadoutConfigs[0].Visuals.Append(new LoadoutConfig_Visual() { ItemSdbId = sdb_id, VisualType = visual, Data1 = 0, Data2 = 0, Transform = []}).ToArray(); | ||
var item = _items.First(e => e.Value.SdbId == sdb_id).Value; | ||
|
||
} | ||
|
||
var equippedGUID = (sdb_id != 0) ? _items.First(e => e.Value.SdbId == sdb_id).Value.GUID : 0; | ||
EquipItemByGUID((int) loadoutId, slot, equippedGUID); | ||
} | ||
} |