forked from emartinezgh/gw2minion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwt_core_state_repair.lua
229 lines (196 loc) · 7.93 KB
/
wt_core_state_repair.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
-- The vendoring State
-- Walking towards nearest Merchant n sell and buy stuff
-- We inherit from wt_core_state, which gives us: function wt_core_state:run(), function wt_core_state:add( kelement ) and function wt_core_state:register()
wt_core_state_repair = inheritsFrom(wt_core_state)
wt_core_state_repair.name = "Repairing"
wt_core_state_repair.kelement_list = { }
wt_core_state_repair.repaired = false
wt_core_state_repair.repaircount = 0
------------------------------------------------------------------------------
-- Search for RepairMerchant Cause & Effect
local c_revendorcheck = inheritsFrom(wt_cause)
local e_revendor = inheritsFrom(wt_effect)
function c_revendorcheck:evaluate()
if (wt_global_information.RepairMerchant == 0) then
c_revendorcheck.objects = MapObjectList("onmesh,nearest,type="..GW2.MAPOBJECTTYPE.RepairMerchant)
if ( TableSize(c_revendorcheck.objects) > 0 ) then
return true
else
wt_global_information.RepairMerchant = nil
end
end
return false
end
function e_revendor:execute()
if ( TableSize(c_revendorcheck.objects) > 0 ) then
nextMerchant , E = next(c_revendorcheck.objects)
if (nextMerchant ~= nil) then
wt_debug("New RepairMerchant found..ID: "..E.characterID)
wt_global_information.RepairMerchant = nextMerchant
end
end
end
------------------------------------------------------------------------------
-- VendorCheck Cause & Effect
local c_renovendorcheck = inheritsFrom(wt_cause)
local e_renovendor = inheritsFrom(wt_effect)
function c_renovendorcheck:evaluate()
if (wt_global_information.RepairMerchant == nil) then
return true
end
return false
end
function e_renovendor:execute()
wt_debug("WARNING:No RepairMerchant on the NavMesh !")
wt_core_state_repair.repaircount = 0
wt_core_controller.requestStateChange(wt_core_state_idle)
end
------------------------------------------------------------------------------
-- MoveTo Vendor Cause & Effect
local c_removetovendorcheck = inheritsFrom(wt_cause)
local e_removetovendor = inheritsFrom(wt_effect)
function c_removetovendorcheck:evaluate()
if (wt_global_information.RepairMerchant ~= nil and wt_global_information.RepairMerchant ~= 0) then
local vendor = MapObjectList:Get(wt_global_information.RepairMerchant)
if ( vendor ~= nil ) then
e_removetovendor.vpos = vendor.pos
local ppos = Player.pos
distance = Distance3D(e_removetovendor.vpos.x,e_removetovendor.vpos.y,e_removetovendor.vpos.z,ppos.x,ppos.y,ppos.z)
wt_debug("Vendordist : "..distance)
if (distance >= 80) then
return true
end
else
wt_global_information.RepairMerchant = nil
end
end
return false
end
e_removetovendor.throttle = 250
function e_removetovendor:execute()
if ( wt_global_information.RepairMerchant ~= nil and wt_global_information.RepairMerchant ~= 0) then
Player:MoveTo(e_removetovendor.vpos.x,e_removetovendor.vpos.y,e_removetovendor.vpos.z,40)
else
wt_global_information.RepairMerchant = 0
end
end
------------------------------------------------------------------------------
-- Open Vendor Cause & Effect
local c_reopenvendor = inheritsFrom(wt_cause)
local e_reopenvendor = inheritsFrom(wt_effect)
function c_reopenvendor:evaluate()
if (wt_global_information.RepairMerchant ~= nil and wt_global_information.RepairMerchant ~= 0) then
local vendor = MapObjectList:Get(wt_global_information.RepairMerchant)
if ( vendor ~= nil ) then
e_removetovendor.vpos = vendor.pos
local ppos = Player.pos
distance = Distance3D(e_removetovendor.vpos.x,e_removetovendor.vpos.y,e_removetovendor.vpos.z,ppos.x,ppos.y,ppos.z)
if (distance < 80) then
Player:StopMoving()
if( Player:GetTarget() ~= vendor.characterID) then
Player:SetTarget(vendor.characterID)
end
if ( not Player:IsConversationOpen()) then
return true
end
end
else
wt_global_information.RepairMerchant = nil
end
end
return false
end
e_reopenvendor.throttle = math.random(1500,2500)
e_reopenvendor.delay = math.random(1500,3500)
function e_reopenvendor:execute()
wt_debug("Opening Vendor.. ")
c_revendorcheck.objects = MapObjectList("onmesh,nearest,type="..GW2.MAPOBJECTTYPE.RepairMerchant)
if ( TableSize(c_revendorcheck.objects) > 0 ) then
nextMerchant , E = next(c_revendorcheck.objects)
if (nextMerchant ~= nil) then
Player:Interact(E.characterID)
end
else
wt_core_state_repair.repaired = false
wt_global_information.RepairMerchant = 0
wt_core_state_repair.repaircount = 0
wt_core_controller.requestStateChange(wt_core_state_idle)
end
end
------------------------------------------------------------------------------
-- Do Conversation with Vendor Cause & Effect
local c_reconversation = inheritsFrom(wt_cause)
local e_reconversation = inheritsFrom(wt_effect)
function c_reconversation:evaluate()
-- IsEquippmentDamaged() is defined in /gw2lib/wt_utility.lua
if ( not IsEquippmentDamaged() ) then
wt_core_state_repair.repaired = true
end
if (wt_global_information.RepairMerchant ~= nil and wt_global_information.RepairMerchant ~= 0 and Player:IsConversationOpen() and not wt_core_state_repair.repaired ) then
return true
end
return false
end
e_reconversation.throttle = math.random(1500,2500)
e_reconversation.delay = math.random(2500,3500)
function e_reconversation:execute()
wt_debug("Chatting with Vendor...")
if ( Player:IsConversationOpen()) then
local options = Player:GetConversationOptions()
nextOption , entry = next(options)
while (nextOption ~=nil and wt_core_state_repair.repaircount < 3) do
if(entry == GW2.CONVERSATIONOPTIONS.Repair) then
wt_debug("TWO")
wt_core_state_repair.repaircount = wt_core_state_repair.repaircount + 1
Player:SelectConversationOption(GW2.CONVERSATIONOPTIONS.Repair)
break
elseif(entry == GW2.CONVERSATIONOPTIONS.Continue) then
Player:SelectConversationOption(GW2.CONVERSATIONOPTIONS.Continue)
break
end
nextOption , entry = next(options,nextOption)
end
end
end
------------------------------------------------------------------------------
-- VendorDone Cause & Effect
local c_revendordone = inheritsFrom(wt_cause)
local e_revendordone = inheritsFrom(wt_effect)
function c_revendordone:evaluate()
if (wt_global_information.RepairMerchant ~= nil and wt_global_information.RepairMerchant ~= 0 and ( wt_core_state_repair.repaired or wt_core_state_repair.repaircount > 2)) then
return true
end
return false
end
function e_revendordone:execute()
if ( IsEquippmentDamaged() == true )then
wt_debug("WARNING: Equipment was not repaired..bug?")
end
wt_core_state_repair.repaired = false
wt_global_information.RepairMerchant = 0
wt_core_controller.requestStateChange(wt_core_state_idle)
end
function wt_core_state_repair:initialize()
local ke_died = wt_kelement:create("Died",c_died,e_died, wt_effect.priorities.interrupt )
wt_core_state_repair:add(ke_died)
local ke_aggro = wt_kelement:create("AggroCheck",c_aggro,e_aggro, 100 )
wt_core_state_repair:add(ke_aggro)
local ke_rest = wt_kelement:create("Rest",c_rest,e_rest,75)
wt_core_state_repair:add(ke_rest)
local ke_revendorsearch = wt_kelement:create("Vendorsearch",c_revendorcheck,e_revendor,60)
wt_core_state_repair:add(ke_revendorsearch)
local ke_renovendor = wt_kelement:create("NoVendorFound",c_renovendorcheck,e_renovendor,50)
wt_core_state_repair:add(ke_renovendor)
local ke_removetovendor = wt_kelement:create("MoveToVendor",c_removetovendorcheck,e_removetovendor,40)
wt_core_state_repair:add(ke_removetovendor)
local ke_reopenvendor = wt_kelement:create("OpenVendor",c_reopenvendor,e_reopenvendor,30)
wt_core_state_repair:add(ke_reopenvendor)
local ke_doconversation = wt_kelement:create("Conversation",c_reconversation,e_reconversation,25)
wt_core_state_repair:add(ke_doconversation)
local ke_revendordone = wt_kelement:create("VendorDone",c_revendordone,e_revendordone,10)
wt_core_state_repair:add(ke_revendordone)
end
-- setup kelements for the state
wt_core_state_repair:initialize()
-- register the State with the system
wt_core_state_repair:register()