-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMiracleGrowLight.lua
241 lines (231 loc) · 9.66 KB
/
MiracleGrowLight.lua
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
MiracleGrowLight = {
Settings={
mode={0, 0, 0, 0}
},
version = "1.3.5"
}
local MiracleGrowLight = MiracleGrowLight;
local windowName = "MiracleGrowLight";
local realPlot = 0;
local sinceUpdated = 0;
local modeNames = {
"Automatic",
"Liniments",
"Off",
"First"
}
function MiracleGrowLight.onHover()
local max=GameData.TradeSkillLevels[GameData.TradeSkills.CULTIVATION] or 0;
local currentPlants = L"";
local modes=L"";
Tooltips.CreateTextOnlyTooltip ( SystemData.MouseOverWindow.name )
Tooltips.SetTooltipText( 1, 1, L"Status")
local out={};
for i=1,4 do
local unlocked = 50 * tonumber(i) - 50;
if max > unlocked then
if modes ~= L"" then
modes = modes..L", "
end
modes = modes..towstring(modeNames[MiracleGrowLight.Settings.mode[i] +1])
local plotData = GetCultivationInfo(i)
local currentPlant = plotData["PlantName"]
if currentPlant ~= L"" and currentPlant ~= nil then
if not out[currentPlant] then
out[currentPlant] = 1;
else
out[currentPlant] = out[currentPlant] + 1;
end
end
end
end
for name,amount in pairs(out) do
if currentPlants ~= L"" then
currentPlants = currentPlants..L", "
end
if amount > 1 then
currentPlants = currentPlants..amount..L"x "
end
currentPlants = currentPlants..(name:gsub(L" Seed", L""))
end
Tooltips.SetTooltipText( 2, 1, L"Plots: "..currentPlants)
Tooltips.SetTooltipText( 3, 1, L"Modes: "..modes)
Tooltips.SetTooltipText( 4, 1, L"Cultivation: "..max)
Tooltips.Finalize()
local rootWidth,rootHeight = WindowGetDimensions("Root")
local mglX,mglY = WindowGetScreenPosition(windowName)
local anchor = nil
if mglX*2 > rootWidth then
anchor = { Point = "topleft", RelativeTo = windowName, RelativePoint = "topright", XOffset = -10, YOffset = 0 }
else
anchor = { Point = "topright", RelativeTo = windowName, RelativePoint = "topleft", XOffset = 10, YOffset = 0 }
end
Tooltips.AnchorTooltip( anchor )
end
function MiracleGrowLight.onZone()
if GameData.TradeSkillLevels[GameData.TradeSkills.CULTIVATION] == 0 then
WindowSetShowing(windowName, false)
else
WindowSetShowing(windowName, true)
CultivationWindow.UpdateAllPlots()
end
end
local function getSeed(items, max)
local i=1;
local out={};
local positions = {}
for index,itemdata in pairs(items) do
if itemdata.cultivationType==GameData.CultivationTypes.SPORE or itemdata.cultivationType==GameData.CultivationTypes.SEED then
if max >= itemdata.craftingSkillRequirement then
if positions[itemdata.name] then
out[positions[itemdata.name]].item.stackCount = out[positions[itemdata.name]].item.stackCount + itemdata.stackCount;
else
out[i]={invIndex=index,item=itemdata};
positions[itemdata.name] = i;
i=i+1;
end
end
end
end
table.sort(out, function(a,b)
if a["item"].craftingSkillRequirement == b["item"].craftingSkillRequirement then
return a["item"].stackCount>b["item"].stackCount;
end
return a["item"].craftingSkillRequirement<b["item"].craftingSkillRequirement
end)
return out[1];
end
local function getLiniment(items, max)
if max < 200 then
return nil;
end
local i=1;
local out={};
for index,itemdata in pairs(items) do
if itemdata.cultivationType==GameData.CultivationTypes.SPORE or itemdata.cultivationType==GameData.CultivationTypes.SEED then
if itemdata.rarity >= 4 then -- blue or higher
out[i]={invIndex=index}
i=i+1;
end
end
end
return out[math.random(#out)];
end
local function getFirst(items, max)
for index,itemdata in pairs(items) do
if itemdata.cultivationType==GameData.CultivationTypes.SPORE or itemdata.cultivationType==GameData.CultivationTypes.SEED then
return {invIndex=index}
end
end
return nil;
end
function MiracleGrowLight.OnUpdate(elapsed)
sinceUpdated = sinceUpdated + elapsed
if (sinceUpdated < 0.75) then
return -- update in reasonable steps only
end
sinceUpdated = 0
local max=GameData.TradeSkillLevels[GameData.TradeSkills.CULTIVATION] or 0;
if max == 0 then
return
end
local isSeedless = false
for i=1,4 do
local unlocked = 50 * tonumber(i) - 50;
if unlocked > max then
return
end
local cul = GetCultivationInfo(i);
WindowSetShowing(windowName.."Plant"..i.."Button",true)
WindowSetShowing(windowName.."Plant"..i.."Harvest",false)
LabelSetText(windowName.."Plant"..i.."Time",cul.TotalTimer..L"");
if cul.StageNum==1 then
DynamicImageSetTextureSlice(windowName.."Plant"..i.."ButtonIcon","Dirt");
elseif cul.StageNum==2 then
DynamicImageSetTextureSlice(windowName.."Plant"..i.."ButtonIcon","WaterDrop");
elseif cul.StageNum==3 then
DynamicImageSetTextureSlice(windowName.."Plant"..i.."ButtonIcon","GreenCross");
elseif cul.StageNum==4 then
WindowSetShowing(windowName.."Plant"..i.."Harvest",true)
WindowSetShowing(windowName.."Plant"..i.."Button",false)
DynamicImageSetTextureSlice(windowName.."Plant"..i.."HarvestIcon","Square-4");
elseif cul.StageNum==0 or cul.StageNum == 255 then
DynamicImageSetTextureSlice(windowName.."Plant"..i.."ButtonIcon","Black-Slot");
if MiracleGrowLight.Settings.mode[i] ~= 2 and not isSeedless and GameData.Player.hitPoints.current > 0 then
local items=DataUtils.GetCraftingItems();
local seed=getSeed(items, max);
local liniment = nil
local first = nil
if MiracleGrowLight.Settings.mode[i] == 1 then
liniment=getLiniment(items, max);
elseif MiracleGrowLight.Settings.mode[i] == 3 then
first=getFirst(items, max);
end
if liniment~=nil then
AddCraftingItem( 3, i, liniment.invIndex, EA_Window_Backpack.TYPE_CRAFTING )
elseif first~=nil then
AddCraftingItem( 3, i, first.invIndex, EA_Window_Backpack.TYPE_CRAFTING )
elseif seed~=nil then
AddCraftingItem( 3, i, seed.invIndex, EA_Window_Backpack.TYPE_CRAFTING )
else
isSeedless=true
end
end
end
end
end
function MiracleGrowLight.harvestStart()
realPlot=GameData.Player.Cultivation.CurrentPlot
local mouseWin = SystemData.MouseOverWindow.name
local but = mouseWin:match("^MiracleGrowLightPlant([0-9]).*")
GameData.Player.Cultivation.CurrentPlot = tonumber(but)
MiracleGrowLight.onHover();
end
function MiracleGrowLight.harvestEnd()
GameData.Player.Cultivation.CurrentPlot=realPlot
end
local function setMode(button)
if MiracleGrowLight.Settings.mode[button] == 1 then
LabelSetTextColor(windowName.."Plant"..button.."Time",100,100,255);--Liniments
elseif MiracleGrowLight.Settings.mode[button] == 2 then
LabelSetTextColor(windowName.."Plant"..button.."Time",255,180,100);--Off
elseif MiracleGrowLight.Settings.mode[button] == 3 then
LabelSetTextColor(windowName.."Plant"..button.."Time",100,225,100);--First Avaible Slot
else
MiracleGrowLight.Settings.mode[button] = 0
LabelSetTextColor(windowName.."Plant"..button.."Time",225,225,225);--Automatic
end
TextLogAddEntry("Chat", SystemData.ChatLogFilters.CRAFTING, towstring("Pot "..button.." set to mode "..modeNames[MiracleGrowLight.Settings.mode[button] + 1]))
end
function MiracleGrowLight.switchMode()
local mouseWin = SystemData.MouseOverWindow.name
local but = mouseWin:match("^MiracleGrowLightPlant([0-9]).*")
but = tonumber(but)
MiracleGrowLight.Settings.mode[but] = MiracleGrowLight.Settings.mode[but] + 1
setMode(but)
end
function MiracleGrowLight.switchBackground()
MiracleGrowLight.Settings.background = not MiracleGrowLight.Settings.background
WindowSetShowing(windowName.."Background", MiracleGrowLight.Settings.background)
end
function MiracleGrowLight.Initialize()
CreateWindow(windowName.."Anchor", true)
CreateWindow(windowName, true)
LayoutEditor.RegisterWindow( windowName.."Anchor", towstring(windowName.." Anchor"),L"Planting interface Anchor", false, false, true, nil )
RegisterEventHandler(SystemData.Events.LOADING_END, "MiracleGrowLight.onZone")
if MiracleGrowLight.Settings == nil then
MiracleGrowLight.Settings = {}
end
if MiracleGrowLight.Settings.mode == nil then
MiracleGrowLight.Settings.mode = {0, 0, 0, 0}
end
MiracleGrowLight.Settings.background = not MiracleGrowLight.Settings.background
for i=1,4 do
WindowSetGameActionData(windowName.."Plant"..i.."Harvest",GameData.PlayerActions.PERFORM_CRAFTING,GameData.TradeSkills.CULTIVATION,L"")
DynamicImageSetTextureSlice(windowName.."Plant"..i.."ButtonFrame","IconFrame-1");
DynamicImageSetTextureSlice(windowName.."Plant"..i.."HarvestFrame","IconFrame-1");
setMode(i)
end
MiracleGrowLight.onZone()
MiracleGrowLight.switchBackground()
end