Support For Loadouts And ItemSlots
Introduction
In this article, we will explore the new features added to support loadouts and item slots in a game. The changes include multiple loadouts for characters and stashes, items stored in a repository identified by their IDs, and item slots to manage equipment. We will delve into the code changes, explaining the new classes and methods added to support these features.
Loadouts and Item Slots
The introduction of loadouts and item slots allows for more flexibility in character and stash management. Characters and stashes now have multiple loadouts, enabling players to switch between different equipment configurations.
[Serializable]
public class EquipmentStateWrapper
{
+ public IList<EquipmentState> LoadoutStates { get; set; }
+ public IList<bool> LoadoutUnlocks { get; set; }
+ public int SelectedLoadout { get; set; }
public EquipmentState EquipmentState { get; set; }
}
The EquipmentStateWrapper
class now includes a list of LoadoutStates
, a list of LoadoutUnlocks
, and a SelectedLoadout
property. This allows players to switch between different loadouts and manage their equipment.
Items and Item Slots
Items are now stored in a repository identified by their IDs. This change enables efficient management of items and their corresponding item slots.
[Serializable]
public class EquipmentState
{
public IList<Item> Items { get; set; }
+ public IList<ItemSlot> ItemSlots { get; set; }
}
[Serializable]
public class LibraryState
{
public int Width { get; set; }
public int Height { get; set; }
public IList<Item> Items { get; set; }
+ public IList<ItemSlot> ItemSlots { get; set; }
}
[Serializable]
public class BackpackState
{
public int Width { get; set; }
public int Height { get; set; }
public IList<Item> Items { get; set; }
+ public IList<ItemSlot> ItemSlots { get; set; }
}
The EquipmentState
, LibraryState
, and BackpackState
classes now include a list of ItemSlots
. This allows for efficient management of item slots and their corresponding items.
Item Slot Class
The ItemSlot
class represents an item slot, which can be empty or occupied by an item.
[Serializable]
public class ItemSlot
{
public bool IsEmpty { get; set; }
public Id Id { get; set; }
}
The ItemSlot
class has two properties: IsEmpty
and Id
. The IsEmpty
property indicates whether the item slot is empty or occupied, and the Id
property represents the ID of the item slot.
RepoState Class
The RepoState
class represents the state of the repository, including the last ID used and a list of entries.
[Serializable]
public class RepoState
{
public Id LastId { get; set; }
public IList<Entry> Entries { get; set; }
public Item? GetItemById(Id id)
{
var item = Entries.FirstOrDefault(x => x.Id._value == id._value);
return item?.Item;
}
}
The RepoState
class has two properties: LastId
and Entries
. The LastId
property represents the last ID used in the repository, and the Entries
property represents a list of entries in the repository. The GetItemById
method allows for efficient retrieval of items by their IDs.
Extracting Equipped Items
Extracting equipped items from the repository is a bit more convoluted due to the introduction of loadouts and item slots.
public IEnumerable<Item> GetEquippedItems(string charecterCode)
{
var charEquipped = this.InventoryData.Where(x => x.CharacterCode == charecterCode).FirstOrDefault();
var res = JsonConvert.DeserializeObject<EquipmentStateWrapper>(charEquipped.Json);
+
+ var loadout = res.LoadoutStates[res.SelectedLoadout];
+ var itemSlots = loadout.ItemSlots;
+ var playerRepo = this.PlayerRepoState;
+ var items = itemSlots.Select(x => playerRepo.GetItemById(x.Id)).ToList();
+ return items;
- return res.EquipmentState.Items;
}
The GetEquippedItems
method now takes into account the selected loadout and item slots to retrieve the equipped items. It first deserializes the EquipmentStateWrapper
from the JSON data, then selects the current loadout and item slots. It then uses the GetItemById
method of the RepoState
class to retrieve the items corresponding to the item slots.
Conclusion
In conclusion, the introduction of loadouts and item slots has significantly improved the management of characters and stashes in the game. The new features allow for more flexibility and efficiency in equipment management, making the game more enjoyable for players. The code changes have been explained in detail, highlighting the new classes and methods added to support these features.
Introduction
In our previous article, we explored the new features added to support loadouts and item slots in a game. In this article, we will answer some frequently asked questions about these features.
Q: What is a loadout?
A: A loadout is a set of equipment that a character or stash can use. It allows players to switch between different equipment configurations.
Q: How do I switch between loadouts?
A: To switch between loadouts, you need to select a different loadout from the list of available loadouts. This can be done by accessing the loadout menu and selecting a new loadout.
Q: What is an item slot?
A: An item slot is a container that can hold an item. It can be empty or occupied by an item.
Q: How do I manage item slots?
A: You can manage item slots by accessing the item slot menu and selecting an item to place in the slot. You can also remove an item from a slot by selecting the item and clicking the "Remove" button.
Q: How do I retrieve equipped items?
A: To retrieve equipped items, you need to use the GetEquippedItems
method, which takes into account the selected loadout and item slots.
Q: What is the RepoState
class?
A: The RepoState
class represents the state of the repository, including the last ID used and a list of entries.
Q: How do I use the GetItemById
method?
A: The GetItemById
method allows you to retrieve an item by its ID. You can use this method to retrieve an item from the repository.
Q: What is the difference between EquipmentStateWrapper
and EquipmentState
?
A: The EquipmentStateWrapper
class is a wrapper around the EquipmentState
class. It includes additional properties such as loadout states and selected loadout.
Q: How do I deserialize the EquipmentStateWrapper
class?
A: You can deserialize the EquipmentStateWrapper
class using the JsonConvert.DeserializeObject
method.
Q: What is the purpose of the Id
class?
A: The Id
class represents an ID, which is used to identify items and item slots.
Q: How do I use the ItemSlot
class?
A: You can use the ItemSlot
class to represent an item slot, which can be empty or occupied by an item.
Q: What is the difference between ItemSlot
and Entry
?
A: The ItemSlot
class represents an item slot, while the Entry
class represents an entry in the repository.
Conclusion
In conclusion, the new features added to support loadouts and item slots have improved the management of characters and stashes in the game. The Q&A section has answered some frequently asked questions about these features, providing a better understanding of how they work.
Additional Resources
For more information about loadouts and item slots, please refer to the following resources: