Add StockManager + Multiple minor Fix
This commit is contained in:
parent
1360a3f978
commit
4f99687ae2
10 changed files with 182 additions and 42 deletions
|
@ -10,7 +10,15 @@ public class Production_workshop : Workshop
|
|||
public string product_name;
|
||||
public int product_value;
|
||||
public Sprite product_sprite;
|
||||
public int stock = 5; //Stock of product
|
||||
public int initial_stock = 5;
|
||||
private int stock; //Current stock
|
||||
public int Stock{ //stock property
|
||||
get{return stock;}
|
||||
set{
|
||||
StockManager.Instance.updateStock(product_name, value-stock);
|
||||
stock = Mathf.Abs(value);
|
||||
}
|
||||
} //Stock of product
|
||||
|
||||
//Handle objects interactions w/ Workshop
|
||||
//Return wether the object is taken from tavernkeeper
|
||||
|
@ -23,7 +31,7 @@ public class Production_workshop : Workshop
|
|||
if(userObject.tag=="Grabable" && currentMug is null) //Try to stock Mug into workshop
|
||||
{
|
||||
Mug mug = userObject.GetComponent<Mug>();
|
||||
if (mug!= null && mug.content is null && !mug.dirty && stock>0) //Mug clean & empty + remaining stock in workshop
|
||||
if (mug!= null && mug.content is null && !mug.dirty && Stock>0) //Mug clean & empty + remaining stock in workshop
|
||||
{
|
||||
Debug.Log(userObject.name+ " stocked in "+gameObject.name);
|
||||
currentMug=userObject;
|
||||
|
@ -40,7 +48,7 @@ public class Production_workshop : Workshop
|
|||
}
|
||||
else
|
||||
{
|
||||
Debug.Log(userObject.name+" cannot be filled with "+product_name+ " -stock:"+stock);
|
||||
Debug.Log(userObject.name+" cannot be filled with "+product_name+ " -stock:"+Stock);
|
||||
}
|
||||
}
|
||||
else if(userObject.tag=="Player" && prepTimer<prepTime && currentMug != null) //Prepare currentMug
|
||||
|
@ -56,7 +64,7 @@ public class Production_workshop : Workshop
|
|||
Debug.Log(gameObject.name+" give "+currentMug.name+" filled with "+product_name+" to "+userObject.name);
|
||||
//Fill mug
|
||||
mug.fill(new Consumable(product_name,product_value,product_sprite));
|
||||
stock--;
|
||||
Stock--;
|
||||
UIPrepTimer.gameObject.SetActive(false); //Turn off UI prep timer
|
||||
|
||||
//Give mug
|
||||
|
@ -70,4 +78,27 @@ public class Production_workshop : Workshop
|
|||
|
||||
return false; //Object not taken
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
protected override void Start()
|
||||
{
|
||||
base.Start(); //Call workshop Start
|
||||
stock = initial_stock; //Using stock instead of Stock to skip set property
|
||||
StockManager.Instance.registerWorkshop(this);
|
||||
}
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
StockManager.Instance.registerWorkshop(this);
|
||||
}
|
||||
|
||||
void OnDisable()
|
||||
{
|
||||
StockManager.Instance.removeWorkshop(this);
|
||||
}
|
||||
|
||||
void OnDestroy()
|
||||
{
|
||||
StockManager.Instance.removeWorkshop(this);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue