This repository has been archived by the owner on Dec 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
o_main_new_combat.lua
335 lines (277 loc) · 10.7 KB
/
o_main_new_combat.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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
require('State')
require('o_WayPointEvents')
require('o_onEvent')
require('o_mis')
require("o_Movement")
function CreateStates(self)
Timers = {}
Timers[1] = "blank"
self:SetVar("Timers",Timers)
storeHomePoint(self)
self:SetTetherPoint { tetherPt = self:GetPosition().pos,radius = 0 }
CombatState(self)
if self:GetVar("Set.WayPointSet") ~= nil or self:GetVar("attached_path") ~= nil or self:GetVar("groupID") ~= nil then
UseWayPoints(self)
end
if self:GetVar("Set.Pet_Active") then
SetPetClass(self)
end
if self:GetVar("Set.MovementType") == "Frozen" then
AggroState(self)
end
if self:GetVar("Set.MovementType") == "Guard" then
AggroState(self)
end
if self:GetVar("Set.MovementType") == "Wander" then
MeanderState(self)
end
if self:GetVar("Set.FollowActive") then
FollowState(self)
end
if self:GetVar("Set.Helper") then
SetHelper(self)
end
customState = State.create()
customState.onEnter = function(self)
if (onTemplateCustomStateEnter) and (onTemplateCustomStateEnter(self, msg) == true ) then
return
end
end
customState.onArrived = function(self, msg)
if (onTemplateCustomStateArrived) and (onTemplateCustomStateArrived(self, msg) == true ) then
return
end
end
Idle = State.create()
Idle.onEnter = function(self)
if self:GetVar("Set.Pet_Active") and not self:GetVar("PetLoaded") then
self:SetVar("PetLoaded", true)
setState("PetClass",self)
end
if self:GetVar("RebuildStart") then
storeHomePoint(self)
self:SetVar("inpursuit",true)
GAMEOBJ:GetTimer():AddTimerWithCancel( self:GetVar("Set.Emote_EventDelay") , "rebuildBreak", self )
end
end
AiDisable = State.create()
AiDisable.onEnter = function(self)
self:SetVar("myTarget", nil)
storeHomePoint(self)
self:SetTetherPoint { tetherPt = self:GetPosition().pos,radius = 0 }
CancelTemplateTimers(self)
self:SetVar("AiDisabled", true)
self:StopPathing()
end
AiEnable = State.create()
AiEnable.onEnter = function(self)
self:SetVar("AiDisabled", false)
SetResetState(self)
end
end
Dead = State.create()
Dead.onEnter = function(self)
self:SetVar("CurrentState", "Dead")
if self:GetVar("I_Have_A_Parent") then
local WpSetName = self:GetVar("attached_path")
local myParent = getParent(self)
local sSplit = split(WpSetName,"_")
local xSplit = {}
local xSplit= {alpa=sSplit[1] , num=sSplit[2] }
myParent:SetVar( self:GetVar("SpawnedVar") , "NotSpawned")
setState("DeadChild", myParent)
end
if self:GetVar("Im_A_Child") then
myParent = getParent(self)
for i = 1, getParent(self):GetVar("MaxPet") do
local myidString = self:GetID()
local myfinalID = "|" .. myidString
local Pet = getPetID(myParent,i):GetID()
if Pet == self:GetID() then
myParent:SetVar("StoredPet."..i, "none")
myParent:SetVar("Child_Timer."..i, myfinalID )
GAMEOBJ:GetTimer():AddTimerWithCancel( myParent:GetVar("Set.Pet_Respawn") , myfinalID, myParent )
end
end
end
getVarables(self)
CancelTemplateTimers(self)
end
tether = State.create()
tether.onEnter = function(self)
self:SetVar("aggrotarget",2)
self:SetImmunity{ immunity = true }
self:SetVar("myTarget", nil)
if self:GetVar("Set.tetherSpeed") ~= nil then
local Tspeed = self:GetVar("Set.tetherSpeed")
else
local Tspeed = 1
end
local myPos = getHomePoint(self)
self:GoTo { speed = self:GetVar("Set.tetherSpeed"), target = { x = myPos.x, y = myPos.y, z = myPos.z } }
end
tether.onArrived = function(self,msg)
self:SetVar("CurrentState", "tether")
self:SetVar("aggrotarget",0)
self:SetHealth{ health = self:GetMaxHealth{}.health }
self:SetImmunity{ immunity = false }
getVarables(self)
SetResetState(self)
end
GoHome = State.create()
GoHome.onEnter = function(self)
self:SetVar("CurrentState", "GoHome")
local hpos = getHomePoint(self)
self:GoTo { speed = 1, target = { x =hpos.x ,z =hpos.z ,y =hpos.y } }
end
GoHome.onArrived = function(self)
self:SetRotation(self:GetVar("rot"))
SetResetState(self)
end
function dist(a ,b)
local dx = math.abs(b.x - a.x)
local dy = math.abs(b.y - a.y)
local dz = math.abs(b.z - a.z)
local d = math.sqrt((dx ^ 2) + (dy ^ 2) + (dz ^ 2))
return d
end
function Distance(point1, point2)
local distance = { }
distance.x = (point2.x - point1.x)
distance.y = (point2.y - point1.y)
return distance
end
function AggroState(self)
aggro = State.create()
aggro.onEnter = function(self)
self:SetVar("CurrentState", "aggro")
local INITIAL_ATTACK_TIME = 1
self:SetVar("readyToAttack", false)
GAMEOBJ:GetTimer():AddTimerWithCancel( INITIAL_ATTACK_TIME , "AttackHeartBeat", self )
GAMEOBJ:GetTimer():CancelTimer( "MeanderPause", self )
local myPos = getHomePoint(self)
local target = getObjectByName(self, "AttackingTarget")
if target:IsDead().bDead then
self:SetVar("Aggroed", false)
ProximityPuls(self)
else
if self:GetVar("Set.MovementType") ~= "Frozen" then
self:SetTetherPoint { tetherPt = myPos,radius = self:GetVar("Set.tetherRadius") }
if self:GetVar("Set.AggroDist") ~= nil and self:GetVar("Set.AggroSpeed") ~= nil then
self:FollowTarget { targetID = target, radius = self:GetVar("Set.AggroDist"),speed = self:GetVar("Set.AggroSpeed") * 2 , keepFollowing = true }
self:SetVar("Aggroed", true)
else
self:FollowTarget { targetID = target,radius = 3, speed = 1, keepFollowing = true }
end
end
end
end
aggro.onTimerDone = function(self, msg)
if msg.name == "AttackHeartBeat" then
self:SetVar("readyToAttack", true)
DoAttack(self);
local castTime = self:GetVar("SkillTime")
if (castTime < 1) then
print("castTime", castTime)
end
GAMEOBJ:GetTimer():AddTimerWithCancel( castTime , "AttackHeartBeat", self )
end
if msg.name == "BeetleFlip" then
print "MOVE!"
self:SetHealth{ health = 2 }
self:AddSkill{ skillID = 134 }
end
if msg.name == "BullStun" then
print "Ready to miss again."
self:SetVar("Stunned", 1 )
end
end
aggro.onArrived = function(self, msg)
DoAttack(self)
end
aggro.onExit = function(self)
GAMEOBJ:GetTimer():CancelTimer("AttackHeartBeat", self)
end
aggro.onCancelled = function(self, msg)
self:SetVar("Aggroed", false)
ProximityPuls(self)
end
function DoAttack(self)
if (self:GetVar("readyToAttack") == false) then
return
end
if CanAttackTarget(self) then
self:SetVar("readyToAttack", false)
if self:GetVar("Set.Aggression") == "PassiveAggres" and self:GetVar("AggroOnce") == 0 then
self:SetVar("AggroOnce",1)
end
if self:GetVar("MaxTableSkill") == nil then
for i = 1, table.maxn (self:GetSkills().skills) do
self:SetVar("MaxTableSkill", i )
end
end
local attackSkillID = self:GetSkills().skills[self:GetVar("MaxTableSkill")]
local bOverrideSkill = self:GetVar("Set.OverRideAttackSkill")
local overrideSkillID = self:GetVar("Set.AttackSkill")
if (bOverrideSkill and overrideSkillID and bOverrideSkill == true) then
attackSkillID = overrideSkillID
end
local bUseOptTarget = self:GetVar("Set.UseOptionalTargetOnAttack")
if (bUseOptTarget and bUseOptTarget == true) then
self:CastSkill{skillID = attackSkillID, optionalTargetID = getObjectByName(self, "AttackingTarget") }
else
self:CastSkill{skillID = attackSkillID }
end
end
end
end
function CombatState(self)
combat = State.create()
combat.onEnter = function(self)
GAMEOBJ:GetTimer():CancelTimer( "MeanderPause", self )
self:SetVar("CurrentState", "combat")
end -- function combat.onEnter
end
function CanAttackTarget(self)
local myTarget = getObjectByName(self, "AttackingTarget")
if not myTarget:Exists() or myTarget:IsDead().bDead or not self:IsEnemy{ targetID = myTarget }.enemy then
self:SetVar("AttackingTarget", "NoTarget" )
self:SetVar("Aggroed", false)
ProximityPuls(self)
return false
end
return true
end
function SetStoreTimmer(intTime, Name, self)
if (intTime) and (Name) and (self) then
GAMEOBJ:GetTimer():AddTimerWithCancel( intTime, Name, self )
end
for i = 1, table.maxn(self:GetVar("Timers")) + 1 do
if self:GetVar("Timers."..i) == Name then
break
end
if self:GetVar("Timers."..i) == nil then
self:SetVar("Timers."..i, Name)
end
end
end
function CancelTemplateTimers(self)
for i = 2,table.maxn(self:GetVar("Timers")) do
GAMEOBJ:GetTimer():CancelTimer( self:GetVar("Timers."..i), self )
end
end
onDie = function(self,msg)
if (onTemplateDie) and (onTemplateDie(self, msg) == true ) then
return
end
end
function onTimerDone(self, msg)
if msg.name == "ToggleRobotReady" then
self:SetVar("ICanSee", 1 )
print "I can see again!"
end
if msg.name == "ToggleRobotNotReady" then
self:SetVar("ICantSee", 1 )
print "AGAIN?!"
end
end