diff --git a/Assets/Prefabs/NPC.prefab b/Assets/Prefabs/NPC.prefab index 4240e1f..ceb28ff 100644 --- a/Assets/Prefabs/NPC.prefab +++ b/Assets/Prefabs/NPC.prefab @@ -507,6 +507,7 @@ MonoBehaviour: MovementSpeed: 5 InteractionDistance: 2 CharacterController: {fileID: 143753897266899886} + Inventory: {fileID: 114934786006823366} Head: {fileID: 4900355877646882} --- !u!114 &114629890146295716 MonoBehaviour: diff --git a/Assets/Prefabs/PC.prefab b/Assets/Prefabs/PC.prefab index 8ceb6db..a199dee 100644 --- a/Assets/Prefabs/PC.prefab +++ b/Assets/Prefabs/PC.prefab @@ -5067,6 +5067,7 @@ MonoBehaviour: MovementSpeed: 5 InteractionDistance: 2 CharacterController: {fileID: 143869468979164672} + Inventory: {fileID: 114702404122310282} Head: {fileID: 4883048021777868} --- !u!114 &114599527678381310 MonoBehaviour: diff --git a/Assets/Scripts/Controls/InventoryInterface.cs b/Assets/Scripts/Controls/InventoryInterface.cs index 3f0ad03..42f5548 100644 --- a/Assets/Scripts/Controls/InventoryInterface.cs +++ b/Assets/Scripts/Controls/InventoryInterface.cs @@ -182,13 +182,13 @@ namespace Cyber.Controls { IconExplainerText.SetTextProperties(Props); - IconInventory.material.SetColor("_EmissionColor", new Color(IconInventoryColor.r * InvBrightness, + IconInventory.material.SetColor("_EmissionColor", new Color(IconInventoryColor.r * InvBrightness, IconInventoryColor.g * InvBrightness, IconInventoryColor.b * InvBrightness)); - IconStatus.material.SetColor("_EmissionColor", new Color(IconStatusColor.r * StsBrightness, + IconStatus.material.SetColor("_EmissionColor", new Color(IconStatusColor.r * StsBrightness, IconStatusColor.g * StsBrightness, IconStatusColor.b * StsBrightness)); - IconSocial.material.SetColor("_EmissionColor", new Color(IconSocialColor.r * SclBrightness, + IconSocial.material.SetColor("_EmissionColor", new Color(IconSocialColor.r * SclBrightness, IconSocialColor.g * SclBrightness, IconSocialColor.b * SclBrightness)); - IconMap.material.SetColor("_EmissionColor", new Color(IconMapColor.r * MapBrightness, + IconMap.material.SetColor("_EmissionColor", new Color(IconMapColor.r * MapBrightness, IconMapColor.g * MapBrightness, IconMapColor.b * MapBrightness)); } } else { @@ -243,8 +243,8 @@ namespace Cyber.Controls { if ((ItemGridSelector.position - ItemGridCells[i].position).magnitude < 0.01f) { ItemGridSelector.position = ItemGridCells[i].position; } else { - ItemGridSelector.position = - Vector3.Lerp(ItemGridSelector.position, + ItemGridSelector.position = + Vector3.Lerp(ItemGridSelector.position, ItemGridCells[i].position, 20f * Time.deltaTime); } Vector3 NewRot = ItemGridSelector.localEulerAngles; @@ -318,4 +318,4 @@ namespace Cyber.Controls { toFix.transform.localScale = new Vector3(Scale, Scale, Scale); } } -} \ No newline at end of file +} diff --git a/Assets/Scripts/Controls/PlayerController.cs b/Assets/Scripts/Controls/PlayerController.cs index 6ff8cbf..7e13868 100644 --- a/Assets/Scripts/Controls/PlayerController.cs +++ b/Assets/Scripts/Controls/PlayerController.cs @@ -6,6 +6,7 @@ using Cyber.Networking; using Cyber.Networking.Messages; using Cyber.Entities; using Cyber.Util; +using Cyber.Items; namespace Cyber.Controls { @@ -49,15 +50,18 @@ namespace Cyber.Controls { } // Interactions + bool Interacted = false; GameObject LookedAtObject = CameraUtil.GetLookedAtGameObject(Camera, Character.InteractionDistance); if (LookedAtObject != null) { Interactable LookingAt = LookedAtObject.GetComponent(); if (LookingAt != null && (LookingAt.transform.position - Character.GetPosition()).magnitude < Character.InteractionDistance) { if (Input.GetButtonDown("Activate")) { InteractWith(LookingAt, InteractionType.Activate); + Interacted = true; } if (Input.GetButtonUp("Activate")) { InteractWith(LookingAt, InteractionType.Deactivate); + Interacted = true; } if (LookedAtObject != LastLookedAt) { InteractWith(LookingAt, InteractionType.Enter); @@ -71,6 +75,20 @@ namespace Cyber.Controls { InteractWith(LastLookedAt.GetComponent(), InteractionType.Exit); LastLookedAt = null; } + + // Equipment actions + if (!Interacted) { + // Don't use equipment if you're interacting with something + // (ie. don't shoot at the buttons) + if (Input.GetButtonDown("Use Item (R)")) { + Character.UseItemInSlot(EquipSlot.RightHand); + Client.Send(PktType.InventoryAction, new InventoryActionPkt(InventoryAction.Use, (int) EquipSlot.RightHand)); + } + if (Input.GetButtonDown("Use Item (L)")) { + Character.UseItemInSlot(EquipSlot.LeftHand); + Client.Send(PktType.InventoryAction, new InventoryActionPkt(InventoryAction.Use, (int) EquipSlot.LeftHand)); + } + } } else if (Character.Moving()) { // The debug console is open, stop the player. Character.Stop(); diff --git a/Assets/Scripts/Entities/SyncBases/Character.cs b/Assets/Scripts/Entities/SyncBases/Character.cs index 1d090f4..e988eb3 100644 --- a/Assets/Scripts/Entities/SyncBases/Character.cs +++ b/Assets/Scripts/Entities/SyncBases/Character.cs @@ -2,6 +2,7 @@ using UnityEngine; using UnityEngine.Networking; using Cyber.Networking.Clientside; +using Cyber.Items; namespace Cyber.Entities.SyncBases { @@ -25,6 +26,11 @@ namespace Cyber.Entities.SyncBases { /// public CharacterController CharacterController; + /// + /// The inventory of this player. + /// + public Inventory Inventory; + /// /// The head transform for looking around. /// @@ -55,6 +61,16 @@ namespace Cyber.Entities.SyncBases { } } + /// + /// Uses the item in the left hand if something is equipped. + /// + public void UseItemInSlot(EquipSlot slot) { + Item Equipped = Inventory.Equipped.GetItem(slot); + if (Equipped != null && Equipped.Action != null) { + Equipped.Action(this); + } + } + /// /// Sets the character's rotation. /// diff --git a/Assets/Scripts/Entities/SyncBases/Inventory.cs b/Assets/Scripts/Entities/SyncBases/Inventory.cs index 0b5d888..458e207 100644 --- a/Assets/Scripts/Entities/SyncBases/Inventory.cs +++ b/Assets/Scripts/Entities/SyncBases/Inventory.cs @@ -33,6 +33,7 @@ namespace Cyber.Entities.SyncBases { if (Server.IsRunning()) { Drive.AddItem(ItemDB.Singleton.Get(0)); Drive.AddItem(ItemDB.Singleton.Get(1)); + Drive.AddItem(ItemDB.Singleton.Get(2)); } } diff --git a/Assets/Scripts/Items/InventoryAction.cs b/Assets/Scripts/Items/InventoryAction.cs index 874d84b..8a66bf9 100644 --- a/Assets/Scripts/Items/InventoryAction.cs +++ b/Assets/Scripts/Items/InventoryAction.cs @@ -2,18 +2,23 @@ namespace Cyber.Items { /// - /// Represents an inventory action + /// Represents an inventory action. /// public enum InventoryAction : byte { /// - /// Equip an item, given int is the ID of the item equipping + /// Equip an item, given int is the ID of the item equipping. /// Equip, /// /// Unequip the given slot, removing anything that was inside of it. /// - Unequip + Unequip, + + /// + /// Use the item in the given slot. + /// + Use } } diff --git a/Assets/Scripts/Items/Item.cs b/Assets/Scripts/Items/Item.cs index cf5fae1..08f0d0a 100644 --- a/Assets/Scripts/Items/Item.cs +++ b/Assets/Scripts/Items/Item.cs @@ -1,10 +1,12 @@ - +using Cyber.Entities.SyncBases; + namespace Cyber.Items { /// /// An item, containing itemmy information. /// public class Item { + public delegate void ItemAction(Character host); /// /// ID of the item, used in . @@ -36,6 +38,11 @@ namespace Cyber.Items { /// public EquipSlot Slot; + /// + /// The function that is ran when the item is used. + /// + public ItemAction Action; + /// /// Creates an item. This should technically be only called by ItemDB, but it's public because of "reasons". /// @@ -45,13 +52,14 @@ namespace Cyber.Items { /// The Weight of the item. /// The equip slot of the item. /// The description of the item. - public Item(int id, int modelId, string name, float weight, EquipSlot slot, string description) { + public Item(int id, int modelId, string name, float weight, EquipSlot slot, string description, ItemAction action = null) { ID = id; ModelID = modelId; Name = name; Weight = weight; Slot = slot; Description = description; + Action = action; } /// @@ -59,7 +67,7 @@ namespace Cyber.Items { /// /// public Item Clone() { - return new Item(ID, ModelID, Name, Weight, Slot, Description); + return new Item(ID, ModelID, Name, Weight, Slot, Description, Action); } } } diff --git a/Assets/Scripts/Items/ItemDB.cs b/Assets/Scripts/Items/ItemDB.cs index 6c5a634..07a77d5 100644 --- a/Assets/Scripts/Items/ItemDB.cs +++ b/Assets/Scripts/Items/ItemDB.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using Cyber.Console; namespace Cyber.Items { @@ -20,7 +21,8 @@ namespace Cyber.Items { /// public ItemDB() { AddItem(new Item(Counter++, 0, "Very Long Item Name", 1.5f, EquipSlot.Hat, "This item is a rare piece of the \"way too long of a name\" technology, invented by space goblins in ancient times.")); - AddItem(new Item(Counter++, 1, "Outworldly spherical tube", .5f, EquipSlot.RightHand, "It's so spherical and smooth that it seems like it's not even from this world!")); + AddItem(new Item(Counter++, 1, "Outworldly Spherical Tube", .5f, EquipSlot.RightHand, "It's so spherical and smooth that it seems like it's not even from this world!")); + AddItem(new Item(Counter++, 0, "Cube Of Debuggery", 1.5f, EquipSlot.LeftHand, "Does some debuggery when you poke it.", (host) => { Term.Println("*DEBUGGERY*"); })); } /// diff --git a/Assets/Scripts/Networking/Clientside/Client.cs b/Assets/Scripts/Networking/Clientside/Client.cs index abd5326..f444c64 100644 --- a/Assets/Scripts/Networking/Clientside/Client.cs +++ b/Assets/Scripts/Networking/Clientside/Client.cs @@ -288,6 +288,17 @@ namespace Cyber.Networking.Clientside { EquipSlot Slot = (EquipSlot) InventoryActionPkt.RelatedInt; Inventory.Equipped.ClearSlot(Slot); break; + case InventoryAction.Use: + EquipSlot UseSlot = (EquipSlot) InventoryActionPkt.RelatedInt; + Item UseItem = Inventory.Equipped.GetItem(UseSlot); + Character Character = CurrSyncBase.GetComponent(); + if (UseItem != null && UseItem.Action != null && Character != null && + Player.Character != Character) { + // Item exists, it has an action, and the character + // isn't controlled by the client (no double-actions). + UseItem.Action(Character); + } + break; } break; default: diff --git a/ProjectSettings/InputManager.asset b/ProjectSettings/InputManager.asset index 01b8764..02a8d87 100644 --- a/ProjectSettings/InputManager.asset +++ b/ProjectSettings/InputManager.asset @@ -53,6 +53,38 @@ InputManager: type: 0 axis: 0 joyNum: 0 + - serializedVersion: 3 + m_Name: Use Item (R) + descriptiveName: + descriptiveNegativeName: + negativeButton: + positiveButton: left ctrl + altNegativeButton: + altPositiveButton: mouse 0 + gravity: 1000 + dead: 0.001 + sensitivity: 1000 + snap: 0 + invert: 0 + type: 0 + axis: 0 + joyNum: 0 + - serializedVersion: 3 + m_Name: Use Item (L) + descriptiveName: + descriptiveNegativeName: + negativeButton: + positiveButton: left alt + altNegativeButton: + altPositiveButton: mouse 1 + gravity: 1000 + dead: 0.001 + sensitivity: 1000 + snap: 0 + invert: 0 + type: 0 + axis: 0 + joyNum: 0 - serializedVersion: 3 m_Name: Equip descriptiveName: