-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
* Transfer One (shift) * Moovinf Files (scripts folder)
- Loading branch information
There are no files selected for viewing
Large diffs are not rendered by default.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
using UnityEngine; | ||
using System.Collections; | ||
using System; | ||
|
||
[System.Serializable] | ||
public class Inventory | ||
{ | ||
|
||
public Item[] inventory; | ||
|
||
public int size; | ||
|
||
|
||
public Inventory(int InventorySize) | ||
{ | ||
inventory = new Item[InventorySize]; | ||
this.size = InventorySize; | ||
} | ||
|
||
|
||
public Item Add(Item added) | ||
{ | ||
int size = added.amount; | ||
|
||
foreach (Item item in inventory) | ||
{ | ||
|
||
if (item != null) | ||
{ | ||
|
||
if (item.GetType() == added.GetType()) | ||
{ | ||
Debug.Log(added.GetType()); | ||
|
||
size = AddAmount(added.amount, item); | ||
|
||
Debug.Log("Inventory added: " + item.GetType() + " Amount: " + item.amount); | ||
if (size == 0) | ||
{ | ||
return item; | ||
} | ||
added.amount = size; | ||
} | ||
} | ||
} | ||
|
||
for (int i = 0; i < 10; i++) | ||
{ | ||
if (inventory[i] == null) | ||
{ | ||
inventory[i] = added; | ||
return inventory[i]; | ||
} | ||
} | ||
|
||
return null; | ||
|
||
} | ||
|
||
public void Remove(int i) | ||
{ | ||
inventory[i] = null; | ||
} | ||
|
||
|
||
|
||
public Item Get(int i) | ||
{ | ||
return inventory[i]; | ||
} | ||
|
||
public void TransferItem(Inventory inv, int index) | ||
{ | ||
this.Add(inv.Get(index)); | ||
inv.Remove(index); | ||
} | ||
|
||
public void TransferItemAmount(Inventory Toinv, int Fromindex, int addingAmount) | ||
{ | ||
|
||
|
||
|
||
// Toinv.Add(inventory[Fromindex]); | ||
|
||
//if (inventory[Fromindex].amount == 0) | ||
//{ | ||
// Remove(Fromindex); | ||
//} | ||
|
||
|
||
Debug.Log(inventory[Fromindex]); | ||
|
||
if (inventory[Fromindex].amount - addingAmount < 0) | ||
{ | ||
Item addable = (((Item)Activator.CreateInstance(null, inventory[Fromindex].GetType().ToString()).Unwrap())); | ||
|
||
addable.amount = (addingAmount - inventory[Fromindex].amount); | ||
|
||
Toinv.Add(addable); | ||
|
||
Remove(Fromindex); | ||
|
||
} | ||
else if (inventory[Fromindex].amount - addingAmount == 0) | ||
{ | ||
Item addable = (((Item)Activator.CreateInstance(null, inventory[Fromindex].GetType().ToString()).Unwrap())); | ||
|
||
addable.amount = addingAmount; | ||
|
||
Toinv.Add(addable); | ||
|
||
Remove(Fromindex); | ||
} | ||
else if (inventory[Fromindex].amount - addingAmount > 0) | ||
{ | ||
Item addable = (((Item)Activator.CreateInstance(null, inventory[Fromindex].GetType().ToString()).Unwrap())); | ||
|
||
addable.amount = addingAmount; | ||
|
||
Toinv.Add(addable); | ||
|
||
inventory[Fromindex].amount -= addingAmount; | ||
|
||
//Remove(Fromindex); | ||
} | ||
|
||
|
||
; | ||
|
||
|
||
} | ||
|
||
public int AddAmount(int rAmount, Item i) | ||
{ | ||
if ((i.amount + rAmount) > (i.maxStackSize)) | ||
{ | ||
i.amount = i.maxStackSize; | ||
Debug.Log(i.amount); | ||
return (i.amount + rAmount) - i.maxStackSize; | ||
} | ||
else | ||
{ | ||
i.amount = i.amount + rAmount; | ||
Debug.Log(i.amount); | ||
return 0; | ||
} | ||
|
||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
This file was deleted.
This file was deleted.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
|
||
|
||
public class Item | ||
{ | ||
public int amount; | ||
public int maxStackSize; | ||
|
||
|
||
|
||
|
||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
|
||
public class IronOre:Ore | ||
{ | ||
public string name = "Iron" + "Ore"; | ||
|
||
|
||
} | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.