-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFactory.cs
More file actions
68 lines (58 loc) · 1.77 KB
/
Copy pathFactory.cs
File metadata and controls
68 lines (58 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using System;
using System.Collections.Generic;
using UnityEngine;
[Serializable]
public class Factory
{
private Inventory _inventory = null;
public List<string> charactersIds = new List<string>();
// this is a factory example
// so we have a set list of goods which we work on
// to test this, you are gonna have to register your own scriptableObject using Item.cs
public List<InventoryItem> goods = new List<InventoryItem>();
private List<CraftingEntry> productionQueu = new List<CraftingEntry>();
public int maxQueueSize = 3;
private int lastGoodIndex = -1;
public Factory(Inventory inventory)
{
_inventory = inventory;
productionQueu = new();
}
public void Init(Inventory inventory)
{
_inventory = inventory;
productionQueu = new();
}
public void AddWorker(string id)
{
charactersIds.Add(id);
}
public void Work()
{
if(_inventory == null)
{
return;
}
if (productionQueu.Count < maxQueueSize)
{
lastGoodIndex = (lastGoodIndex + 1) % goods.Count;
if(!_inventory.HaveEnough(goods[lastGoodIndex]))
{
if(Craft.Can(1, goods[lastGoodIndex].item.Id, _inventory))
{
CraftingEntry craftingEntry = Craft.Start(goods[lastGoodIndex].item.Id, _inventory);
productionQueu.Add(craftingEntry);
}
}
}
foreach (var craft in productionQueu)
{
if (craft.Completed())
{
InventoryItem result = Craft.Complete(craft);
_inventory.AddItem(result);
}
}
productionQueu.RemoveAll(x => x.Completed());
}
}