-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
586 lines (481 loc) · 15.3 KB
/
init.lua
File metadata and controls
586 lines (481 loc) · 15.3 KB
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
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
local ASTRO_KIT_VERSION = 1
if AstroKit ~= nil and AstroKit.Version >= ASTRO_KIT_VERSION then
return
end
---@class AstroKit
AstroKit = {}
AstroKit.Version = ASTRO_KIT_VERSION
local mod = RegisterMod("AstroKit", 1)
-- AstroKit.TearModifier = require "astro.utils.tear-modifier"
-- AstroKit.SpringAnimation = require "astro.utils.spring-animation"
--- From isaacscript-common
---
--- Helper function to get the player from a tear, laser, bomb, etc. Returns undefined if the entity
--- does not correspond to any particular player.
---
--- This function works by looking at the `Parent` and the `SpawnerEntity` fields (in that order). As
--- a last resort, it will attempt to use the `Entity.ToPlayer` method on the entity itself.
---@param entity Entity
---@return EntityPlayer | nil
function AstroKit:GetPlayerFromEntity(entity)
if entity == nil then
return nil
end
if entity.Parent ~= nil then
local player = entity.Parent:ToPlayer()
if (player ~= nil) then
return player
end
local familiar = entity.Parent:ToFamiliar()
if familiar ~= nil then
return familiar.Player
end
end
if entity.SpawnerEntity ~= nil then
local player = entity.SpawnerEntity:ToPlayer()
if player ~= nil then
return player
end
local familiar = entity.SpawnerEntity:ToFamiliar()
if familiar ~= nil then
return familiar.Player
end
end
return entity:ToPlayer()
end
---@param id TrinketType
---@param appendText string | table
---@param numbersToMultiply number | table | nil
---@param maxMultiplier number | table | nil
function AstroKit:AddGoldenTrinketDescription(id, appendText, numbersToMultiply, maxMultiplier)
if not EID then return end
local data = EID.GoldenTrinketData[id]
if data then
if type(data) == "number" then
EID:addGoldenTrinketMetadata(id, appendText, numbersToMultiply or data, maxMultiplier)
else
EID:addGoldenTrinketMetadata(id, appendText, numbersToMultiply or data.t, maxMultiplier or data.mult)
end
else
EID:addGoldenTrinketMetadata(id, appendText, numbersToMultiply or 0, maxMultiplier)
end
if maxMultiplier and maxMultiplier > 4 then
EID.GoldenTrinketData[id].mults = {maxMultiplier, maxMultiplier}
end
end
---@generic T
---@param list T[]
---@param target T
---@return boolean
function AstroKit:Contain(list, target)
for _, value in ipairs(list) do
if value == target then
return true
end
end
return false
end
---@param collectibles CollectibleType[]
---@param rng RNG
---@param count integer
---@param ignoreCollectible CollectibleType | CollectibleType[]?
---@param ignoreQuest boolean?
function AstroKit:GetRandomCollectibles(collectibles, rng, count, ignoreCollectible, ignoreQuest)
---@type CollectibleType[]
local list = {}
if ignoreQuest then
local itemConfig = Isaac.GetItemConfig()
for key, value in pairs(collectibles) do
local isIgnore = value == ignoreCollectible
if type(ignoreCollectible) == "table" then
isIgnore = AstroKit:Contain(ignoreCollectible, value)
end
if not isIgnore and itemConfig:GetCollectible(value).Tags & ItemConfig.TAG_QUEST ~= ItemConfig.TAG_QUEST then
table.insert(list, value)
end
end
else
for _, value in ipairs(collectibles) do
table.insert(list, value)
end
end
---@type CollectibleType[]
local result = {}
for _ = 1, count do
if #list == 0 then
break
end
local idx = rng:RandomInt(#list) + 1
table.insert(result, list[idx])
table.remove(list, idx)
end
return result
end
---해당 아이템을 모두 제거합니다. 제거한 아이템의 수를 반환합니다.
---@param player EntityPlayer
---@param type CollectibleType
---@return integer
function AstroKit:RemoveAllCollectible(player, type)
local count = 0
if player:HasCollectible(type) then
for _ = 1, player:GetCollectibleNum(type) do
player:RemoveCollectible(type)
count = count + 1
end
end
return count
end
---@param player EntityPlayer
---@param type TrinketType
function AstroKit:RemoveAllTrinket(player, type)
local limit = 3
local count = 0
while player:HasTrinket(type) and count < limit do
player:TryRemoveTrinket(type)
count = count + 1
end
end
---@param entityType integer
---@param entityVariant integer
---@param entitySubtype integer
---@param position Vector
---@return Entity
function AstroKit:Spawn(entityType, entityVariant, entitySubtype, position)
local currentRoom = Game():GetLevel():GetCurrentRoom()
return Isaac.Spawn(
entityType,
entityVariant,
entitySubtype,
currentRoom:FindFreePickupSpawnPosition(position, 0, true),
Vector.Zero,
nil
)
end
-- ---@param entity Astro.Entity
-- ---@param position Vector
-- ---@return Entity
-- function AstroKit:SpawnEntity(entity, position)
-- local currentRoom = Game():GetLevel():GetCurrentRoom()
-- return Isaac.Spawn(
-- entity.Type,
-- entity.Variant,
-- entity.SubType,
-- currentRoom:FindFreePickupSpawnPosition(position, 0, true),
-- Vector.Zero,
-- nil
-- )
-- end
---@param pillEffect PillEffect
---@param position Vector
---@return EntityPickup
function AstroKit:SpawnPill(pillEffect, position)
local currentRoom = Game():GetLevel():GetCurrentRoom()
local itemPool = Game():GetItemPool()
local pillColor = itemPool:ForceAddPillEffect(pillEffect)
return Isaac.Spawn(
EntityType.ENTITY_PICKUP,
PickupVariant.PICKUP_PILL,
pillColor,
currentRoom:FindFreePickupSpawnPosition(position, 0, true),
Vector.Zero,
nil
):ToPickup()
end
---@param cardType Card
---@param position Vector
---@return EntityPickup
function AstroKit:SpawnCard(cardType, position)
local currentRoom = Game():GetLevel():GetCurrentRoom()
return Isaac.Spawn(
EntityType.ENTITY_PICKUP,
PickupVariant.PICKUP_TAROTCARD,
cardType,
currentRoom:FindFreePickupSpawnPosition(position, 40, true),
Vector.Zero,
nil
):ToPickup()
end
---@param collectibleType CollectibleType
---@param position Vector
---@param optionsPickupIndex integer?
---@param isExactPosition boolean?
---@return EntityPickup
function AstroKit:SpawnCollectible(collectibleType, position, optionsPickupIndex, isExactPosition)
local currentRoom = Game():GetLevel():GetCurrentRoom()
local step = isExactPosition and 0 or 40
local pickup =
Isaac.Spawn(
EntityType.ENTITY_PICKUP,
PickupVariant.PICKUP_COLLECTIBLE,
collectibleType,
currentRoom:FindFreePickupSpawnPosition(position, step, true),
Vector.Zero,
nil
):ToPickup()
if optionsPickupIndex then
pickup.OptionsPickupIndex = optionsPickupIndex
end
return pickup
end
---@param trinketType TrinketType
---@param position Vector
---@return EntityPickup
function AstroKit:SpawnTrinket(trinketType, position)
local currentRoom = Game():GetLevel():GetCurrentRoom()
return Isaac.Spawn(
EntityType.ENTITY_PICKUP,
PickupVariant.PICKUP_TRINKET,
trinketType,
currentRoom:FindFreePickupSpawnPosition(position, 0, true),
Vector.Zero,
nil
):ToPickup()
end
-- AstroKit:AddCallback(
-- ModCallbacks.MC_POST_GAME_STARTED,
-- ---@param isContinued boolean
-- function(_, isContinued)
-- if not isContinued then
-- AstroKit.Data.CollectibleCount = {}
-- end
-- end
-- )
-- ---아이템 최초 획득 시를 체크한다.
-- ---TODO: 추후에 여러번 획득해도 동작하도록 변경할 예정이기 때문에 카운트를 저장한다.
-- ---@param collectibleType CollectibleType
-- ---@return boolean
-- function AstroKit:IsFirstAdded(collectibleType)
-- local count = 0
-- for index, value in ipairs(AstroKit.Data.CollectibleCount) do
-- if value.id == collectibleType then
-- count = value.count + 1
-- AstroKit.Data.CollectibleCount[index].count = count
-- break
-- end
-- end
-- if count == 0 then
-- table.insert(AstroKit.Data.CollectibleCount, { id = collectibleType, count = 1 })
-- count = 1
-- end
-- return count == 1
-- end
--- Credit to Xalum(Retribution), _Kilburn and DeadInfinity
function AstroKit:AddTears(baseFiredelay, tearsUp)
local currentTears = 30 / (baseFiredelay + 1)
local newTears = currentTears + tearsUp
local newFiredelay = math.max((30 / newTears) - 1, -0.75)
return newFiredelay
end
---@param roomType RoomType
function AstroKit:DisplayRoom(roomType)
local level = Game():GetLevel()
local idx = level:QueryRoomTypeIndex(roomType, false, RNG())
local room = level:GetRoomByIdx(idx)
if room.Data.Type == roomType then
room.DisplayFlags = room.DisplayFlags | RoomDescriptor.DISPLAY_BOX | RoomDescriptor.DISPLAY_ICON
level:UpdateVisibility()
end
end
---@param collectible CollectibleType
function AstroKit:HasCollectible(collectible)
for i = 1, Game():GetNumPlayers() do
local player = Isaac.GetPlayer(i - 1)
if player:HasCollectible(collectible) then
return true
end
end
return false
end
---@param collectible CollectibleType
---@return integer
function AstroKit:GetCollectibleNum(collectible)
local count = 0
for i = 1, Game():GetNumPlayers() do
local player = Isaac.GetPlayer(i - 1)
count = count + player:GetCollectibleNum(collectible)
end
return count
end
---@param trinket TrinketType
function AstroKit:HasTrinket(trinket)
for i = 1, Game():GetNumPlayers() do
local player = Isaac.GetPlayer(i - 1)
if player:HasTrinket(trinket) then
return true
end
end
return false
end
---@param currentRoom Room
function AstroKit:CheckFirstVisitFrame(currentRoom)
return currentRoom:GetFrameCount() <= 0 and currentRoom:IsFirstVisit()
end
---@param list any[]
---@param value any
---@return boolean
function AstroKit:Exists(list, value)
return AstroKit:FindIndex(list, value) ~= -1
end
---@param list any[]
---@param value any
---@return integer
function AstroKit:FindIndex(list, value)
for i, v in ipairs(list) do
if v == value then
return i
end
end
return -1
end
---@param index integer
function AstroKit:ConvertRoomIndexToPosition(index)
local x = index % 13
local y = math.floor(index / 13)
return Vector(x, y)
end
---@param position Vector
function AstroKit:ConvertRoomPositionToIndex(position)
if position.X < 0 or position.X > 12 or position.Y < 0 or position.Y > 12 then
return -1
end
return position.Y * 13 + position.X
end
function AstroKit:IsDeathCertificateRoom()
local level = Game():GetLevel()
local roomName = level:GetCurrentRoomDesc().Data.Name
if roomName == "Death Certificate" then
return true
end
return false
end
--- Credit to EID
function AstroKit:IsCollectibleUnlocked(collectibleType)
local itemConfig = Isaac.GetItemConfig()
local item = itemConfig:GetCollectible(collectibleType)
if item == nil then
return false
end
local result = false
if item.AchievementID == -1 or (item.Tags and item.Tags & ItemConfig.TAG_QUEST == ItemConfig.TAG_QUEST) then
result = true
return true
end
if item.Hidden then
result = false
return false
end
if item.IsAvailable then
result = item:IsAvailable()
else
result = true
end
return result
end
---@param value integer
---@param trinket TrinketType
---@return boolean
function AstroKit:CheckTrinket(value, trinket)
if value == trinket or value - AstroKit.GOLDEN_TRINKET_OFFSET == trinket then
return true
end
return false
end
local function RunUpdates(tab) --This is from Fiend Folio
for i = #tab, 1, -1 do
local f = tab[i]
f.Delay = f.Delay - 1
if f.Delay <= 0 then
f.Func()
table.remove(tab, i)
end
end
end
AstroKit.DelayedFuncs = {}
---Scheduled update from Fiend Folio
---@param foo function
---@param delay integer
---@param callback ModCallbacks?
function AstroKit:ScheduleForUpdate(foo, delay, callback)
callback = callback or ModCallbacks.MC_POST_UPDATE
if not AstroKit.DelayedFuncs[callback] then
AstroKit.DelayedFuncs[callback] = {}
mod:AddCallback(
callback,
function()
RunUpdates(AstroKit.DelayedFuncs[callback])
end
)
end
table.insert(AstroKit.DelayedFuncs[callback], {Func = foo, Delay = delay})
end
---@type table<integer, {sprite: Sprite, animationName: string, callback: fun()}>
AstroKit.PendingAnimations = {}
---@param sprite Sprite
function AstroKit:OnAnimationFinished(sprite, animationName, callback)
table.insert(AstroKit.PendingAnimations, {sprite = sprite, animationName = animationName, callback = callback})
end
mod:AddCallback(
ModCallbacks.MC_POST_UPDATE,
function()
for _, animationData in ipairs(AstroKit.PendingAnimations) do
if animationData.sprite:IsFinished(animationData.animationName) then
animationData.callback()
end
end
end
)
---@param worldPosition Vector
---@return Vector
function AstroKit:ToScreen(worldPosition)
local room = Game():GetRoom()
if room:IsMirrorWorld() then
return room:WorldToScreenPosition(Vector(room:GetBottomRightPos().X + 60 - worldPosition.X, worldPosition.Y))
end
return room:WorldToScreenPosition(worldPosition)
end
function AstroKit:IsLatterStage()
local level = Game():GetLevel()
local stage = level:GetStage()
if stage >= LevelStage.STAGE4_3 or (stage == LevelStage.STAGE4_1 and level:GetStageType() == StageType.STAGETYPE_REPENTANCE) or (stage == LevelStage.STAGE4_2 and level:GetStageType() == StageType.STAGETYPE_REPENTANCE) then
return true
end
return false
end
---@generic T
---@param list table<integer, T>
---@param predicate fun(item: T): boolean
---@return table<integer, T>
function AstroKit:Filter(list, predicate)
local result = {}
for _, value in ipairs(list) do
if predicate(value) then
table.insert(result, value)
end
end
return result
end
-- ---@param player EntityPlayer
-- ---@param trinketType TrinketType
-- function AstroLibrary:SmeltTrinket(player, trinketType)
-- isc:smeltTrinket(player, trinketType)
-- end
-- ---@param trinketType TrinketType
-- function AstroLibrary:IsGoldenTrinketType(trinketType)
-- return isc:isGoldenTrinketType(trinketType)
-- end
-- function AstroLibrary:GetDoors()
-- return isc:getDoors()
-- end
---@param rng RNG
function AstroKit:CopyRNG(rng)
return RNG(rng:GetSeed(), 35)
end
-- ---@param player EntityPlayer
-- ---@return integer
-- function AstroLibrary:GetLastPenaltyFrame(player)
-- local data = AstroLibrary:GetPersistentPlayerData(player)
-- if data and data["lastPenaltyFrame"] then
-- return data["lastPenaltyFrame"]
-- end
-- return -108000
-- end