-
Notifications
You must be signed in to change notification settings - Fork 0
/
zz_AIvsDS3_navigation.lua
496 lines (382 loc) · 15.8 KB
/
zz_AIvsDS3_navigation.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
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
-- GOAL_ShitbirdMovement_27482 = 27482;
local nav = "nav"; -- lazy, for logging
COORDINATE_TYPE_PlungeReady = 120;
COORDINATE_TYPE_GreetsReady = 119;
COORDINATE_TYPE_Waiting = 118;
COORDINATE_TYPE_CelebrationReady = 117;
RegisterTableGoal(GOAL_ShitbirdMovement_27482, "GOAL_ShitbirdMovement_27482");
REGISTER_GOAL_NO_SUB_GOAL( GOAL_ShitbirdMovement_27482, true );
local Shitbird = Goal;
-- to determine if we're on the cliff
local cliffRegion = 5500301;
local offLimitsRegion = 5500302; -- can't go here, pathfinding too crap
Shitbird.moveTargets = {
{ 5500000, true },
{ 5500001, true },
{ 5500002, true },
{ 5500003, true },
{ 5500004, true },
{ 5500005, true },
{ 4002805, true },
};
function Shitbird:Initialize( ai, goal, changeBattleStateNum ) end
-- can't use the usual Initialize func cos we want to operate regardless of battle state
function Shitbird:Init( ai, goal )
self.battleGoal = g_GoalTable[ GOAL_ShitbirdBattle_27481 ];
ai:SetStringIndexedNumber( "moveTarget", 1 ); -- index of moveTargets table entry to which we want to go
ai:SetStringIndexedNumber( "state", 0 ); -- our state defines which action we do
ai:SetStringIndexedNumber( "battleType", 0 ); -- how do we engage enemies
-- disable logging this
log:setState( nav, true );
log:setState( "nav_interrupt", false );
-- log:setThinkId( ai:GetNpcThinkParamID() ); -- whichever is initialized first
ai:SetEventMoveTarget( 4000202 );
log:clearEx( ai, nav );
log:clearEx( ai, "nav_interrupt" );
log( ai, nav, "Test distance = ", ai:GetDist( POINT_EVENT ) );
log( ai, nav, "Navigation init" );
log( ai, nav, "moveTarget = ", ai:GetStringIndexedNumber( "moveTarget" ), " state = ", ai:GetStringIndexedNumber( "state" ) );
log:section( ai, nav );
end
function Shitbird:Activate( ai, goal )
local state = ai:GetStringIndexedNumber( "state" );
-- boss fight state we do nothing else
if ( state == 5 ) then
log( ai, nav, "I am state 5 = ", ai:GetStringIndexedNumber( "state" ) );
if (ai:GetEventRequest(0) == 90) then
ai:SetStringIndexedNumber( "state", 7 );
return true;
end
if ( ai:GetNpcThinkParamID() == 27481 ) then
goal:AddSubGoal( GOAL_ShitbirdGundyr_27483, 10 );
else
self:GundyrFightInit_Act08( ai, goal );
end
return true;
end
-- init if we haven't yet
if ( ai:GetStringIndexedNumber( "MovementInitialized" ) == 0 ) then
ai:SetStringIndexedNumber( "MovementInitialized", 1 );
self:Init( ai, goal );
end
if ( ai:GetNumber(3) ~= 0 and ai:IsFinishTimer(3) ) then
ai:SetNumber( 3, 0 );
ai:DeleteTeamReacor( COORDINATE_TYPE_GreetsReady );
ai:DeleteTeamReacor( COORDINATE_TYPE_Waiting );
end
if ( ai:GetNumber(4) ~= 0 and ai:IsFinishTimer(4) ) then
ai:SetNumber( 4, 0 );
ai:AddTeamRecord( COORDINATE_TYPE_CelebrationReady, TARGET_NONE, 0 );
end
if ( not ai:IsBothHandMode( TARGET_SELF ) ) then
goal:AddSubGoal( GOAL_COMMON_Attack, 10, NPC_ATK_ButtonTriangle, TARGET_SELF, 999, 0, 0 );
end
-- init if we haven't yet
if ( ai:GetStringIndexedNumber( "MovementInitialized" ) == 0 ) then
ai:SetStringIndexedNumber( "MovementInitialized", 1 );
self:Init( ai, goal );
end
-- do battle if need to do battle
if ( ai:IsBattleState() and ai:GetStringIndexedNumber( "battleType" ) ~= 2 and not ai:IsInsideTargetRegion( TARGET_ENE_0, offLimitsRegion ) and state < 3 ) then
goal:AddSubGoal( GOAL_ShitbirdBattle_27481, 10 );
end
local eventNo = ai:GetEventRequest(0); -- poll event to see if we're inside boss room
-- event request to get into boss fight positions
if ( eventNo == 98 ) then
ai:SetStringIndexedNumber( "state", 3 );
-- boss fight has begun
elseif ( eventNo == 97 ) then
ai:SetStringIndexedNumber( "state", 4 );
end
local moveTarget = ai:GetStringIndexedNumber( "moveTarget" );
-- check if we're on cliff and should not attack anything
if ( moveTarget == 6 and ai:IsInsideTargetRegion( TARGET_SELF, cliffRegion ) ) then
ai:SetStringIndexedNumber( "battleType", 2 );
log( ai, nav, "On the cliff, switching battleType to 2" );
end
-- if we haven't finished our path yet
if ( moveTarget <= table.getn( self.moveTargets ) ) then
-- make sure target is always set before we try to use it
Birdteam:SetMoveTarget( ai, self.moveTargets[ moveTarget ][1], moveTarget );
local pointDist = ai:GetDist( POINT_EVENT );
if (pointDist <= 1.5) then
log( ai, nav, "Point reached (dist=", pointDist, ") moveTarget = ", moveTarget, " pointId = ", self.moveTargets[ moveTarget ][1] );
-- we've arrived, set next point target
ai:SetStringIndexedNumber( "moveTarget", 1 + moveTarget );
-- we're at the cliff
if ( moveTarget == 3 ) then
ai:SetStringIndexedNumber( "battleType", 1 ); -- we now gang on enemies
elseif ( moveTarget == 6 ) then
log( ai, nav, "State change to 1, plunge cliff" );
ai:SetStringIndexedNumber( "state", 1 );
-- we've reached the fog door
elseif ( moveTarget == table.getn( self.moveTargets ) ) then
log( ai, nav, "State change to 2, fog door" );
ai:SetStringIndexedNumber( "state", 2 );
end
end
end
-- update state
state = ai:GetStringIndexedNumber( "state" );
moveTarget = ai:GetStringIndexedNumber( "moveTarget" );
-- ################################
-- is friend too far
if ( moveTarget < 4 and state == 0 ) then
if ( ai:GetDist( TARGET_FRI_0 ) >= 10 ) then
if ( Birdteam:ShouldIWait( ai ) ) then
-- wait state
ai:SetStringIndexedNumber( "state", 99 );
Birdteam:SetState( ai, 99 );
else
-- catch up state
ai:SetStringIndexedNumber( "state", 98 );
Birdteam:SetState( ai, 98 );
end
elseif ( ai:GetDist( TARGET_FRI_0 ) >= 4 and ai:GetTeamRecordCount( COORDINATE_TYPE_Attack, TARGET_ENE_0, 0 ) == 0 and state < 98 ) then
-- dash catch up state
if ( not Birdteam:ShouldIWait( ai ) and not ai:IsBattleState() ) then
ai:SetStringIndexedNumber( "state", 97 );
end
end
end
-- state 0 means we can move
if ( state == 0 ) then
self:Progress_Act01( ai, goal );
-- state 1 means we reached the cliff and should walk off of it
elseif ( state == 1 ) then
self:PlungeCliff_Act02( ai, goal );
-- state 2 means we want to enter the fog arena
elseif ( state == 2 ) then
ai:SetEventMoveTarget( 4002805 );
goal:AddSubGoal( GOAL_COMMON_ApproachTarget, 2, POINT_EVENT, 0.3, TARGET_SELF, false, -1 );
-- state 3 means we've entered the boss arena
elseif ( state == 3 ) then
self:WakeTheGundyr_Act03( ai, goal );
-- boss fight initialization
elseif ( state == 4 ) then
self:GundyrFightInit_Act08( ai, goal );
-- post boss fight
elseif ( state == 7 ) then
self:PostGundyr_Act09( ai, goal );
-- claw celebration
elseif ( state == 8 ) then
self:ClawCelebration_Act10( ai, goal );
-- waiting for a friend
elseif ( state == 99 ) then
self:Wait4Friend_Act04( ai, goal );
-- coming to waiting friend
elseif ( state == 98 ) then
self:ComeToFriend_Act05( ai, goal );
-- sprinting to nonwaiting friend
elseif ( state == 97 ) then
self:DashToFriend_Act06( ai, goal );
-- greet each other with Call over gesture
elseif ( state == 96 ) then
self:CallOverFriend_Act07( ai, goal );
end
return true;
end
-- simply move towards next target
function Shitbird:Progress_Act01(ai, goal)
local moveTarget = ai:GetStringIndexedNumber( "moveTarget" );
log( ai, nav, "Progress_Act01, moving to ", moveTarget, " id ", self.moveTargets[ moveTarget ][1] );
Birdteam:SetMoveTarget( ai, self.moveTargets[ moveTarget ][1], moveTarget );
goal:AddSubGoal( GOAL_COMMON_ApproachTarget, 2, POINT_EVENT, 1.5, TARGET_SELF, false, -1 );
end
-- do a plunging attack
function Shitbird:PlungeCliff_Act02( ai, goal )
local moveTarget = ai:GetStringIndexedNumber( "moveTarget" );
Birdteam:SetMoveTarget( ai, self.moveTargets[ moveTarget ][1], moveTarget );
-- tell the team that we're waiting at the cliff
ai:AddTeamRecord( COORDINATE_TYPE_PlungeReady, TARGET_EVENT, 0 );
log( ai, nav, "PlungeCliff_Act02 adding team record, num = ", ai:GetTeamRecordCount( COORDINATE_TYPE_PlungeReady, TARGET_EVENT, 0 ) );
-- when both are ready - plunge
if ( ai:GetTeamRecordCount( COORDINATE_TYPE_PlungeReady, TARGET_EVENT, 0 ) >= 2 ) then
goal:ClearSubGoal();
-- turn and plunge
-- ai:RequestEmergencyQuickTurn();
-- ai:TurnTo( TARGET_EVENT );
local plunge = goal:AddSubGoal( GOAL_WalkAndPlunge, 10, TARGET_EVENT, ai:GetDistYSigned(TARGET_EVENT) + 2 );
-- if plunge goal is over we return to normal state
-- if ( plunge:GetLastResult() == GOAL_RESULT_Success or plunge:GetLastResult() == GOAL_RESULT_Failed ) then
log( ai, nav, "PlungeCliff_Act02 after, result=", plunge:GetLastResult(), ", state=", ai:GetStringIndexedNumber( "state" ) );
end
log( ai, nav, "Dist = ", ai:GetDistY( POINT_EVENT ) )
if ( ai:GetDistY( POINT_EVENT ) <= 1 ) then
ai:SetStringIndexedNumber( "state", 0 );
ai:SetStringIndexedNumber( "battleType", 1 );
end
end
function Shitbird:WakeTheGundyr_Act03( ai, goal )
-- this one will wake the gundyr
if ( ai:GetNpcThinkParamID() == 27481 ) then
ai:SetEventMoveTarget( 5500007 );
local dist = ai:GetDist( POINT_EVENT );
-- move to pulling pos and let emevd handle the rest
if ( dist >= 1 ) then
goal:AddSubGoal( GOAL_COMMON_ApproachTarget, 2, POINT_EVENT, 1, TARGET_SELF, false, -1 );
end
-- this one will do the anim
else
ai:SetEventMoveTarget( 5500006 );
local dist = ai:GetDist( POINT_EVENT );
-- sprint to position
if ( dist >= 2 ) then
goal:AddSubGoal( GOAL_COMMON_DashTarget, 1, POINT_EVENT, 0.5, TARGET_SELF, -1, 1, 1 );
-- stretch out
else
goal:AddSubGoal( GOAL_COMMON_ComboRepeat, 10, NPC_ATK_Gesture23, TARGET_SELF, 999, 0, 0 );
end
end
end
function Shitbird:Wait4Friend_Act04( ai, goal )
ai:AddTeamRecord( COORDINATE_TYPE_Waiting, TARGET_NONE, 0 );
-- if both waiting for some reason make one approach
if ( ai:GetTeamRecordCount( COORDINATE_TYPE_Waiting, TARGET_NONE, 0 ) >= 2 ) then
ai:DeleteTeamReacor( COORDINATE_TYPE_Waiting );
goal:AddSubGoal( GOAL_COMMON_ApproachTarget, 2, TARGET_FRI_0, 0, TARGET_SELF, false, -1 );
else
goal:AddSubGoal( GOAL_COMMON_Turn, 0.5, TARGET_FRI_0, 15 );
end
-- if we're close enough end this and reset state
if ( ai:GetDist( TARGET_FRI_0 ) <= 2 ) then
goal:ClearSubGoal();
Birdteam:SyncMoveTargets( ai );
ai:SetStringIndexedNumber( "state", 96 ); -- call over
Birdteam:SetState( ai, 96 );
else
ai:TurnTo( TARGET_FRI_0 );
end
end
-- friend is waiting, we just approach no rush
function Shitbird:ComeToFriend_Act05( ai, goal )
-- run to friend
goal:AddSubGoal( GOAL_COMMON_ApproachTarget, 2, TARGET_FRI_0, 0, TARGET_SELF, false, -1 );
-- if we're close enough stop, resync and reset state
if ( ai:GetDist( TARGET_FRI_0 ) <= 2 ) then
goal:ClearSubGoal();
Birdteam:SyncMoveTargets( ai );
ai:SetStringIndexedNumber( "state", 96 ); -- call over
Birdteam:SetState( ai, 96 );
-- this wait makes sure friend isn't stuck in a gesture animation while we run off, causing this to loop forever
-- goal:AddSubGoal( GOAL_COMMON_Wait, 3, TARGET_SELF );
end
end
-- friend is not waiting, we must dash to catch up
function Shitbird:DashToFriend_Act06( ai, goal )
-- dash to friend
goal:AddSubGoal( GOAL_COMMON_DashTarget, 1, TARGET_FRI_0, 2, TARGET_FRI_0, -1, 1, 1 );
-- if we're close enough stop, resync and reset state
if ( ai:GetDist( TARGET_FRI_0 ) <= 2 ) then
goal:ClearSubGoal();
Birdteam:SyncMoveTargets( ai );
ai:SetStringIndexedNumber( "state", 0 );
end
end
-- greet each other with call over
function Shitbird:CallOverFriend_Act07( ai, goal )
ai:AddTeamRecord( COORDINATE_TYPE_Waiting, TARGET_NONE, 0 );
-- if both waiting for some reason make one approach
if ( ai:GetTeamRecordCount( COORDINATE_TYPE_Waiting, TARGET_NONE, 0 ) >= 2 and ai:GetDist( TARGET_FRI_0 ) > 2 ) then
ai:DeleteTeamReacor( COORDINATE_TYPE_Waiting );
goal:AddSubGoal( GOAL_COMMON_ApproachTarget, 0.5, TARGET_FRI_0, 1, TARGET_SELF, false, -1 );
return;
end
log ( ai, nav, "angle = ", ai:GetToTargetAngle( TARGET_FRI_0 ) );
-- turn if we need to
if not ( ai:IsLookToTarget( TARGET_FRI_0, 25 ) ) then
goal:AddSubGoal( GOAL_COMMON_TurnAround, 1, TARGET_FRI_0, AI_DIR_TYPE_CENTER, 15, true, true, -1 );
else
log( ai, nav, "looking at it - ", ai:GetTeamRecordCount( COORDINATE_TYPE_GreetsReady, TARGET_NONE, 0 ) );
-- tell team we're ready
ai:AddTeamRecord( COORDINATE_TYPE_GreetsReady, TARGET_NONE, 0 );
-- if both ready - call over
if ( ai:GetTeamRecordCount( COORDINATE_TYPE_GreetsReady, TARGET_NONE, 0 ) >= 2 ) then
goal:ClearSubGoal();
goal:AddSubGoal( GOAL_COMMON_Attack, 10, NPC_ATK_Gesture24, TARGET_FRI_0, 999, 0, 0 );
-- if attack is done - reset state
-- if ( ai:IsStartAttack() and ai:IsFinishAttack() ) then
ai:SetStringIndexedNumber( "state", 0 );
-- end
ai:SetNumber( 3, 1 );
ai:SetTimer( 3, 1 );
Birdteam:SetState( ai, nil );
end
end
end
function Shitbird:GundyrFightInit_Act08( ai, goal )
goal:ClearSubGoal();
-- one of them was stretching out, backstep out of it
if ( ai:GetNpcThinkParamID() == 27480 ) then
-- get up and move to entrance, emevd shall handle the rest
ai:SetEventMoveTarget( 5500008 );
if ( ai:GetDist( POINT_EVENT ) > 1 ) then
goal:AddSubGoal( GOAL_COMMON_ApproachTarget, 6, POINT_EVENT, 1, TARGET_SELF, false, -1 ):SetLifeEndSuccess( true );
else
goal:AddSubGoal( GOAL_COMMON_Wait, 2, TARGET_SELF );
end
end
ai:SetStringIndexedNumber( "state", 5 );
end
function Shitbird:PostGundyr_Act09( ai, goal )
local dist = ai:GetDist( TARGET_EVENT );
log ( ai, lname, "dist = ", dist );
if ( ai:GetNpcThinkParamID() == 27480 ) then
if ( dist <= 2 ) then
-- applause
goal:ClearSubGoal();
-- goal:AddSubGoal( GOAL_COMMON_Wait, 1, TARGET_SELF ):SetLifeEndSuccess( true );
goal:AddSubGoal( GOAL_COMMON_ComboRepeat, 5, NPC_ATK_Gesture28, TARGET_EVENT, 999, 0, 0 ):SetLifeEndSuccess( true );
ai:SetTimer( 4, 4 );
ai:SetNumber( 4, 1 );
ai:SetStringIndexedNumber( "state", 8 );
end
else
-- come over
if ( dist > 2 ) then
goal:AddSubGoal( GOAL_COMMON_ApproachTarget, 5, TARGET_EVENT, 0, TARGET_SELF, false, -1 );
else
ai:AddTeamRecord( COORDINATE_TYPE_CelebrationReady, TARGET_NONE, 0 );
ai:SetStringIndexedNumber( "state", 8 );
end
end
end
function Shitbird:ClawCelebration_Act10( ai, goal )
if ( ai:GetTeamRecordCount( COORDINATE_TYPE_CelebrationReady, TARGET_NONE, 0 ) >= 2 ) then
goal:AddSubGoal( GOAL_COMMON_ComboRepeat, 10, NPC_ATK_L1, TARGET_EVENT, 3, 0 );
end
end
function Shitbird:Update( ai, goal )
return Update_Default_NoSubGoal( self, ai, goal );
end
function Shitbird:Interrupt( ai, goal )
for i = INTERUPT_First, INTERUPT_Last do
if (ai:IsInterupt( i )) then
log( ai, "nav_interrupt", i );
end
end
return false;
end
function Shitbird:Interrupt_CANNOT_MOVE( ai, goal )
local state = ai:GetStringIndexedNumber( "state" )
-- if we got stuck trying to get to an ally
if ( state == 98 or state == 97 ) then
goal:ClearSubGoal();
goal:AddSubGoal( GOAL_COMMON_ApproachTarget, 2, TARGET_FRI_0, 0, TARGET_SELF, false, -1 );
return true;
end
return false;
end
-- try to dodge bolts
function Shitbird:Interrupt_Shoot( ai, goal )
-- need this so we don't try to handle gundyr's boulders outside of his goal
local state = ai:GetStringIndexedNumber( "state" )
if ( state >= 5 ) then
return false;
end
goal:ClearSubGoal();
self.battleGoal:Dodge_Act22( ai, goal );
return true;
end
function Shitbird:Terminate( ai, goal )
end