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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
|
using System.Collections.Generic;
using System.Linq;
using Mundus.Service.Tiles.Items;
namespace Mundus.Service.Crafting {
public class CraftingRecipe {
/// <summary>
/// Item that will be added to the inventory after crafting
/// </summary>
/// <value>The result item.</value>
public ItemTile ResultItem { get; private set; }
/// <summary>
/// Required amount of the first item
/// </summary>
public int Count1 { get; private set; }
/// <summary>
/// Required first item
/// </summary>
public ItemTile ReqItem1 { get; private set; }
/// <summary>
/// Required amount of the second item
/// </summary>
public int Count2 { get; private set; }
/// <summary>
/// Required second item
/// </summary>
public ItemTile ReqItem2 { get; private set; }
/// <summary>
/// Required amount of the third item
/// </summary>
public int Count3 { get; private set; }
/// <summary>
/// Required third item
/// </summary>
public ItemTile ReqItem3 { get; private set; }
/// <summary>
/// Required amount of the fourth item
/// </summary>
public int Count4 { get; private set; }
/// <summary>
/// Required fourth item
/// </summary>
public ItemTile ReqItem4 { get; private set; }
/// <summary>
/// Required amount of the fifth item
/// </summary>
public int Count5 { get; private set; }
/// <summary>
/// Required fifth item
/// </summary>
public ItemTile ReqItem5 { get; private set; }
public CraftingRecipe(ItemTile resultItem, int count1, ItemTile reqItem1) :this(resultItem, count1, reqItem1, 0, null, 0, null, 0, null, 0, null)
{ }
public CraftingRecipe(ItemTile resultItem, int count1, ItemTile reqItem1, int count2, ItemTile reqItem2) : this(resultItem, count1, reqItem1, count2, reqItem2, 0, null, 0, null, 0, null)
{ }
public CraftingRecipe(ItemTile resultItem, int count1, ItemTile reqItem1, int count2, ItemTile reqItem2, int count3, ItemTile reqItem3) : this(resultItem, count1, reqItem1, count2, reqItem2, count3, reqItem3, 0, null, 0, null)
{ }
public CraftingRecipe(ItemTile resultItem, int count1, ItemTile reqItem1, int count2, ItemTile reqItem2, int count3, ItemTile reqItem3, int count4, ItemTile reqItem4) : this(resultItem, count1, reqItem1, count2, reqItem2, count3, reqItem3, count4, reqItem4, 0, null)
{ }
public CraftingRecipe(ItemTile resultItem, int count1, ItemTile reqItem1, int count2, ItemTile reqItem2, int count3, ItemTile reqItem3, int count4, ItemTile reqItem4, int count5, ItemTile reqItem5) {
this.ResultItem = resultItem;
this.Count1 = count1;
this.ReqItem1 = reqItem1;
this.Count2 = count2;
this.ReqItem2 = reqItem2;
this.Count3 = count3;
this.ReqItem3 = reqItem3;
this.Count4 = count4;
this.ReqItem4 = reqItem4;
this.Count5 = count5;
this.ReqItem5 = reqItem5;
}
//ugly af, but will rewrite when I imntegrade data bases
/// <summary>
/// Checks if the parameter has enough of every requried item
/// </summary>
/// <returns><c>true</c>If has enough<c>false</c>otherwise</returns>
/// <param name="itemsAndCounts">Dictionary that has the items and their respective amounts (that will be checked)</param>
public bool HasEnoughItems(Dictionary<ItemTile, int> itemsAndCounts) {
bool hasEnough = true;
if (ReqItem1 != null && hasEnough) {
if (itemsAndCounts.Keys.Any(k => k.stock_id == ReqItem1.stock_id)) {
hasEnough = itemsAndCounts.First(x => x.Key.stock_id == ReqItem1.stock_id).Value >= Count1;
}
else hasEnough = false;
}
if (ReqItem2 != null && hasEnough) {
if (itemsAndCounts.Keys.Any(k => k.stock_id == ReqItem2.stock_id)) {
hasEnough = itemsAndCounts.First(x => x.Key.stock_id == ReqItem2.stock_id).Value >= Count2;
}
else hasEnough = false;
}
if (ReqItem3 != null && hasEnough) {
if (itemsAndCounts.Keys.Any(k => k.stock_id == ReqItem3.stock_id)) {
hasEnough = itemsAndCounts.First(x => x.Key.stock_id == ReqItem3.stock_id).Value >= Count3;
}
else hasEnough = false;
}
if (ReqItem4 != null && hasEnough) {
if (itemsAndCounts.Keys.Any(k => k.stock_id == ReqItem4.stock_id)) {
hasEnough = itemsAndCounts.First(x => x.Key.stock_id == ReqItem4.stock_id).Value >= Count4;
}
else hasEnough = false;
}
if (ReqItem5 != null && hasEnough) {
if (itemsAndCounts.Keys.Any(k => k.stock_id == ReqItem5.stock_id)) {
hasEnough = itemsAndCounts.First(x => x.Key.stock_id == ReqItem5.stock_id).Value >= Count5;
}
else hasEnough = false;
}
return hasEnough;
}
/// <summary>
/// Checks if the given item (and amount) is enough for the recipe
/// </summary>
public bool HasEnoughOfItem(ItemTile item, int count) {
if (ReqItem1.stock_id == item.stock_id) return count >= Count1;
if (ReqItem2.stock_id == item.stock_id) return count >= Count2;
if (ReqItem3.stock_id == item.stock_id) return count >= Count3;
if (ReqItem4.stock_id == item.stock_id) return count >= Count4;
if (ReqItem5.stock_id == item.stock_id) return count >= Count5;
return false;
}
/// <summary>
/// Returns a dictionary of every required item and their respective amount
/// </summary>
public Dictionary<ItemTile, int> GetRequiredItemsAndCounts() {
Dictionary<ItemTile, int> req = new Dictionary<ItemTile, int>();
req.Add(ReqItem1, Count1);
if (ReqItem2 != null) req.Add(ReqItem2, Count2);
if (ReqItem3 != null) req.Add(ReqItem3, Count3);
if (ReqItem4 != null) req.Add(ReqItem4, Count4);
if (ReqItem5 != null) req.Add(ReqItem5, Count5);
return req;
}
}
}
|