This repository has been archived by the owner on Apr 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Materials.cs
143 lines (135 loc) · 5.42 KB
/
Materials.cs
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
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using Buddy.Coroutines;
using ff14bot;
using ff14bot.Helpers;
using ff14bot.Managers;
namespace crafty
{
internal static class Materials
{
private static readonly List<Material> Mats = new List<Material>();
private static void AddMaterial(string itemname, uint qty)
{
for (var i = 0; i < Mats.Count(); i++)
{
//Check for item already existing.
if (Mats[i].Itemname.Equals(itemname))
{
Mats[i].Qtyreq += qty;
return;
}
}
//Add it if it doesn't exist.
Mats.Add(new Material(itemname, qty));
}
public static void ClearList()
{
Mats.Clear();
}
public static Material[] GetList()
{
return Mats.ToArray();
}
public static bool FetchMaterials(uint craftingId, uint qty, bool expand = false)
{
using (Core.Memory.TemporaryCacheState(false))
{
RaptureAtkUnitManager.Update();
GameObjectManager.Update();
//Check to see if we have it selected
var isKnown = (CraftingManager.CurrentRecipeId == (ushort) craftingId);
//Logging.Write(CraftingManager.CurrentRecipeId);
//It's not selected. So try and select it.
if (!isKnown)
{
var coroutine = new Coroutine(() => CraftingManager.SetRecipe(craftingId));
while (!coroutine.IsFinished)
{
Thread.Sleep(33);
coroutine.Resume();
}
}
RaptureAtkUnitManager.Update();
GameObjectManager.Update();
//Check if we've selected it again
isKnown = (CraftingManager.CurrentRecipeId == (ushort) craftingId);
//Logging.Write(isKnown);
//We know it, so we go fetch the materials
if (isKnown)
{
var recipe = CraftingManager.CurrentRecipe;
foreach (var i in recipe.Ingredients)
{
if (i.ItemId != 0) //Keep getting a 0 ID ingredient here for some reason?!
{
var iname = DataManager.GetItem(i.ItemId).EnglishName;
var totalreq = i.TotalNeeded*qty;
if (expand) //Check if we're expanding the recipe
{
var rec = Recipes.Recipes.getRecipe(iname, Core.Me.CurrentJob);
//See if we know it in current job.
if (rec.Id != 0)
{
if (FetchMaterials(rec.Id, totalreq, true))
{
Crafty.OrderForm.AddOrder(rec.Id, rec.Name, totalreq,
Recipes.Recipes.GetJob(rec.Id)); //Add it if we know it!
}
}
else if (Recipes.Recipes.getRecipe(iname).Count > 0)
//Check if we've got it on our other jobs
{
foreach (var r in Recipes.Recipes.getRecipe(iname))
{
if (FetchMaterials(r.Id, totalreq, true))
{
Crafty.OrderForm.AddOrder(r.Id, r.Name, totalreq,
Recipes.Recipes.GetJob(r.Id));
break;
}
}
}
else //Add the material if we don't know how to make it.
{
AddMaterial(iname, totalreq);
}
}
else
{
AddMaterial(iname, totalreq);
}
}
}
return true;
}
return false;
}
}
public static void CountStock()
{
using (Core.Memory.TemporaryCacheState(false))
{
GameObjectManager.Update();
for (var i = 0; i < Mats.Count; i++)
{
Logging.Write("Counting item " + Mats[i].Itemname);
var mat = DataManager.GetItem(Mats[i].Itemname);
Mats[i].Qty = mat.ItemCount() + Crafty.OrderForm.CountOrders(Mats[i].Itemname);
}
}
}
public class Material
{
public readonly string Itemname;
public uint Qty, Qtyreq;
public Material(string name, uint qtyreq)
{
Itemname = name;
Qtyreq = qtyreq;
Qty = 0;
}
}
}
}