mirror of
https://github.com/Leahnaya/TheKingsRace.git
synced 2026-08-24 19:34:38 -05:00
Inventory is a dictionary
Inventory Networking
This commit is contained in:
@@ -386,7 +386,7 @@ public class dPlayerMovement : NetworkBehaviour
|
||||
}
|
||||
|
||||
//Ragdoll Functions
|
||||
private void getHit(Vector3 dir, float force){
|
||||
private void GetHit(Vector3 dir, float force){
|
||||
if(firstHit == false){
|
||||
EnableRagdoll();
|
||||
dir.Normalize();
|
||||
|
||||
@@ -14,10 +14,19 @@ public class InventoryManager : MonoBehaviour
|
||||
set{ itemList = value; }
|
||||
}
|
||||
|
||||
//Item Dictionary
|
||||
private Dictionary<string, Item> itemDict = new Dictionary<string, Item>();
|
||||
public Dictionary<string, Item> ItemDict{
|
||||
get{ return itemDict; }
|
||||
}
|
||||
|
||||
void Awake(){
|
||||
//Gets Items in Resource Folder
|
||||
allItems = Resources.LoadAll<Item>("ItemObjects");
|
||||
itemList = new List<Item>(allItems);
|
||||
|
||||
foreach(Item item in itemList){
|
||||
itemDict.Add(item.name, item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,66 +7,78 @@ public class PlayerInventory : NetworkBehaviour
|
||||
{
|
||||
|
||||
//List of items
|
||||
[SerializeField] List<Item> items;
|
||||
[SerializeField] private Dictionary<string, Item> playerItemDict = new Dictionary<string, Item>();
|
||||
public Dictionary<string, Item> PlayerItemDict{
|
||||
get{ return playerItemDict; }
|
||||
}
|
||||
|
||||
[SerializeField] private List<string> networkItemList = new List<string>();
|
||||
public List<string> NetworkItemList{
|
||||
get{ return networkItemList; }
|
||||
}
|
||||
//Scripts
|
||||
public PlayerStats pStats;
|
||||
public InventoryManager invMan;
|
||||
|
||||
void Awake(){
|
||||
pStats = GetComponent<PlayerStats>();
|
||||
pStats = GetComponent<PlayerStats>();
|
||||
invMan = FindObjectOfType<InventoryManager>();
|
||||
}
|
||||
|
||||
public void UpdateInventory(Item item, bool ableToAdd){
|
||||
if(!items.Contains(item) && ableToAdd){
|
||||
//Adds player Item to a dictionary
|
||||
void AddItem(Item item){
|
||||
playerItemDict.Add(item.name, item);
|
||||
item.Equip(pStats, this.gameObject);
|
||||
}
|
||||
|
||||
//Add item to player Inventory
|
||||
public void UpdateItemNetwork(string itemName, int add){
|
||||
|
||||
if(add == 0) networkItemList.Remove(itemName);
|
||||
|
||||
else if(add == 1 )networkItemList.Add(itemName);
|
||||
|
||||
else Debug.Log("Nothing updated");
|
||||
}
|
||||
|
||||
//Remove Item player inv
|
||||
public void RemoveItem(Item item){
|
||||
if(playerItemDict.Remove(item.name)){
|
||||
item.Unequip(pStats, this.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
//Updates Inventory to Add item to player list
|
||||
public int UpdateInventory(Item item, bool ableToAdd){
|
||||
if(!playerItemDict.ContainsKey(item.name) && ableToAdd){
|
||||
Debug.Log("Item Added");
|
||||
AddItem(item);
|
||||
return 1;
|
||||
}
|
||||
else if(!ableToAdd && !items.Contains(item)){
|
||||
else if(!ableToAdd && !playerItemDict.ContainsKey(item.name)){
|
||||
//Item cannot be added
|
||||
Debug.Log("Item Cannot Be Added");
|
||||
return -1;
|
||||
}
|
||||
else{
|
||||
//If player already has the item it removes it
|
||||
Debug.Log("Item Removed");
|
||||
RemoveItem(item);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
//Equips All items in list at start of next scene
|
||||
public void UpdateEquips(){
|
||||
foreach(Item item in items){
|
||||
item.Equip(pStats, this.gameObject);
|
||||
if(invMan != null){
|
||||
foreach(string itemName in networkItemList){
|
||||
invMan.ItemDict[itemName].Equip(pStats, this.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Add item to player Inventory
|
||||
public void AddItem(Item item){
|
||||
|
||||
//Adds and equips Item if it can
|
||||
items.Add(item);
|
||||
|
||||
item.Equip(pStats, this.gameObject);
|
||||
|
||||
}
|
||||
|
||||
//Add item to player Inventory
|
||||
public void AddItemNetwork(Item item){
|
||||
|
||||
//Adds and equips Item if it can
|
||||
items.Add(item);
|
||||
|
||||
}
|
||||
|
||||
//Remove Item player inv
|
||||
public void RemoveItem(Item item){
|
||||
if(items.Remove(item)){
|
||||
item.Unequip(pStats, this.gameObject);
|
||||
else{
|
||||
Debug.Log("invMan is currently not set or disabled");
|
||||
}
|
||||
}
|
||||
|
||||
//GetItems
|
||||
public List<Item> GetItems(){
|
||||
return items;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -370,7 +370,7 @@ public class PlayerMovement : NetworkBehaviour
|
||||
}
|
||||
|
||||
//Ragdoll Functions
|
||||
private void getHit(Vector3 dir, float force){
|
||||
private void GetHit(Vector3 dir, float force){
|
||||
if(firstHit == false){
|
||||
EnableRagdoll();
|
||||
dir.Normalize();
|
||||
|
||||
Reference in New Issue
Block a user