This commit is contained in:
Sofia 2017-05-16 15:21:42 +03:00
parent 6ac11277d6
commit 8e533220f0
2 changed files with 32 additions and 1 deletions

View File

@ -28,6 +28,9 @@ namespace Cyber.Entities.SyncBases {
/// </summary>
public Character Character;
/// <summary>
/// The <see cref="InventoryActionHandler"/> which handles inventory actions properly.
/// </summary>
public InventoryActionHandler ActionHandler;
/// <summary>

View File

@ -2,32 +2,60 @@
using Cyber.Entities.SyncBases;
using Cyber.Networking.Clientside;
using Cyber.Networking.Messages;
using UnityEngine;
namespace Cyber.Items {
/// <summary>
/// Handles InventoryActions, building them on the client when needed and running them.
/// </summary>
public class InventoryActionHandler {
private Inventory Inventory;
private Character Character;
/// <summary>
/// Creates an <see cref="InventoryActionHandler"/>
/// </summary>
/// <param name="inventory"></param>
/// <param name="character"></param>
public InventoryActionHandler(Inventory inventory, Character character) {
Inventory = inventory;
Character = character;
}
/// <summary>
/// Builds a <see cref="InventoryAction.Use"/> packet.
/// </summary>
/// <param name="slot">The equipped slot to use.</param>
/// <returns></returns>
public InventoryActionPkt BuildUseItem(EquipSlot slot) {
return new InventoryActionPkt(InventoryAction.Use, (int) slot);
}
/// <summary>
/// Builds a <see cref="InventoryAction.Unequip"/> packet.
/// </summary>
/// <param name="slot">The equipped slot to clear.</param>
/// <returns></returns>
public InventoryActionPkt BuildClearSlot(EquipSlot slot) {
return new InventoryActionPkt(InventoryAction.Unequip, (int) slot);
}
/// <summary>
/// Builds a <see cref="InventoryAction.Equip"/> packet.
/// </summary>
/// <param name="itemID">The item ID to equip.</param>
/// <returns></returns>
public InventoryActionPkt BuildEquipItem(int itemID) {
return new InventoryActionPkt(InventoryAction.Equip, itemID);
}
/// <summary>
/// Handles an <see cref="InventoryActionPkt"/> to handle. Ran on server and client.
/// </summary>
/// <param name="action">The <see cref="InventoryAction"/> to run</param>
/// <param name="relatedInt">The item related to the action.</param>
/// <returns>Weather the action failed or not.</returns>
public bool HandleAction(InventoryAction action, int relatedInt) {
switch (action) {
case InventoryAction.Equip: