-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Core][Inventory] Initial implementation of the inventory system. #1
- Loading branch information
Showing
49 changed files
with
1,257 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace Shared.Game.Enum | ||
{ | ||
public enum Sex : byte | ||
{ | ||
Male, | ||
Female | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,6 @@ public enum ExdDataType | |
Int = 6, | ||
UInt = 7, | ||
Float = 9, | ||
Packed = 11 | ||
ULong = 11 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace Shared.SqPack.GameTable | ||
{ | ||
public class EquipSlotCategoryEntry : Exd.Entry | ||
{ | ||
public IEnumerable<ushort> GetEquipSlots() | ||
{ | ||
for (ushort i = 0; i < Data.Length; i++) | ||
if ((sbyte)Data[i] == 1) | ||
yield return i; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace Shared.SqPack.GameTable | ||
{ | ||
public class ItemUiCategoryEntry : Exd.Entry | ||
{ | ||
public string Name => (string)Data[0]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
|
||
namespace WorldServer.Game.Entity | ||
{ | ||
public class Container | ||
{ | ||
public ContainerType ContainerType { get; } | ||
public ushort Count => (ushort)items.Count(i => i != null); | ||
|
||
private readonly List<Item> items; | ||
|
||
public Container(ContainerType containerType, ushort capacity) | ||
{ | ||
ContainerType = containerType; | ||
items = new List<Item>(new Item[capacity]); | ||
} | ||
|
||
/// <summary> | ||
/// Find all item instances and their current slot by item id. | ||
/// </summary> | ||
public IEnumerable<(ushort Slot, Item Item)> GetItems(uint itemId) | ||
{ | ||
for (ushort i = 0; i < items.Count; i++) | ||
if (items[i]?.Template.Index == itemId) | ||
yield return (i, items[i]); | ||
} | ||
|
||
/// <summary> | ||
/// Find a single item instance by Guid. | ||
/// </summary> | ||
public Item GetItem(ulong guid) | ||
{ | ||
return items.SingleOrDefault(i => i != null && i.Guid == guid); | ||
} | ||
|
||
/// <summary> | ||
/// Find a single item instance by container slot. | ||
/// </summary> | ||
public Item GetItem(ushort slot) | ||
{ | ||
if (slot >= items.Count) | ||
throw new ArgumentException($"Invalid slot {slot}!"); | ||
return items[slot]; | ||
} | ||
|
||
public ushort GetFirstAvailableSlot() | ||
{ | ||
for (ushort i = 0; i < items.Count; i++) | ||
if (items[i] == null) | ||
return i; | ||
|
||
return ushort.MaxValue; | ||
} | ||
|
||
public void AddItem(Item item, ushort slot, bool update = false) | ||
{ | ||
Debug.Assert(item != null); | ||
Debug.Assert(slot < items.Count); | ||
items[slot] = item; | ||
|
||
#if DEBUG | ||
Console.WriteLine($"Adding item {item.Template.Index} to container: {ContainerType}, slot: {slot}"); | ||
#endif | ||
|
||
item.UpdatePosition(ContainerType, slot, update); | ||
} | ||
|
||
public void RemoveItem(Item item) | ||
{ | ||
Debug.Assert(item != null); | ||
items[item.Slot] = null; | ||
|
||
#if DEBUG | ||
Console.WriteLine($"Removing item {item.Template.Index} from container: {ContainerType}, slot: {item.Slot}"); | ||
#endif | ||
|
||
item.UpdatePosition(ContainerType.None, ushort.MaxValue); | ||
} | ||
|
||
/// <summary> | ||
/// Send container item instance information to client, only sent on login. | ||
/// </summary> | ||
public void SendItemSetup(uint index) | ||
{ | ||
items.ForEach(i => i?.SendSetup(index)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
namespace WorldServer.Game.Entity | ||
{ | ||
public enum ContainerEquippedSlot : byte | ||
{ | ||
MainHand, | ||
OffHand, | ||
Head, | ||
Body, | ||
Hands, | ||
Waist, | ||
Legs, | ||
Feet, | ||
Ears, | ||
Neck, | ||
Wrists, | ||
RightRing, | ||
LeftRing, | ||
SoulCrystal | ||
} | ||
} |
Oops, something went wrong.