-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.lua
317 lines (240 loc) · 8.73 KB
/
main.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
--StartDebug()
local hiding = RegisterMod("the-hiding-of-isaac", 1)
local headInABag = Isaac.GetItemIdByName("Head in a bag")
knifeDamageReduction = 0.25
Character = {
myStealthDamageBonus = 0.0
}
function Character:Reset()
Character.myStealthDamageBonus = 0.0
end
-- Current Room
CurrentRoom = {
myRoomIndex = 0,
myRoomInitialEnemyCount = 0,
myClosestEnemyDistance = 9000.0,
myHasIsaacBeenSeen = false,
myIsBossRoom = false,
myIsHeadInABagActive = false
}
function CurrentRoom:Reset()
CurrentRoom.myClosestEnemyDistance = 9000.0
CurrentRoom.myHasIsaacBeenSeen = false
CurrentRoom.myIsBossRoom = false
CurrentRoom.myIsHeadInABagActive = false
end
function CurrentRoom:IsNewRoom(aLevel)
local oldRoomIndex = CurrentRoom.myRoomIndex
CurrentRoom.myRoomIndex = aLevel:GetCurrentRoomIndex()
return oldRoomIndex ~= CurrentRoom.myRoomIndex
end
-- Current Floor
CurrentFloor = {
myStageIndex = LevelStage.STAGE_NULL
}
function CurrentFloor:Reset()
CurrentRoom.myStageIndex = LevelStage.STAGE_NULL
end
function CurrentFloor:IsNewFloor(aLevel)
local oldStageIndex = CurrentRoom.myStageIndex
CurrentRoom.myStageIndex = aLevel:GetAbsoluteStage()
return oldStageIndex ~= CurrentRoom.myStageIndex
end
local rng = RNG()
local roomsClearedHidden = 0
function DoExpensiveAction(aPlayer)
return aPlayer.FrameCount % 10 == 0
end
function OpenNormalDoor(aDoor)
if aDoor ~= nil and aDoor:IsRoomType(RoomType.ROOM_DEFAULT) and not aDoor:IsOpen() then
aDoor:Open()
end
end
function CloseNormalDoor(aDoor)
if aDoor ~= nil and aDoor:IsRoomType(RoomType.ROOM_DEFAULT) and aDoor:IsOpen() then
aDoor:Close(false)
end
end
function OpenNormalDoors(aRoom)
for i = 0, DoorSlot.NUM_DOOR_SLOTS - 1 do
OpenNormalDoor(aRoom:GetDoor(i))
end
end
function CloseNormalDoors(aRoom)
for i = 0, DoorSlot.NUM_DOOR_SLOTS - 1 do
CloseNormalDoor(aRoom:GetDoor(i))
end
end
function IsBossInRoom(aRoom)
local entities = Isaac.GetRoomEntities()
for i = 1, #entities do
if entities[i]:IsActiveEnemy() and entities[i]:IsBoss() then
return true
end
end
return false
end
function DistanceFromPlayer(aPlayer, aEntity)
return aPlayer.Position:Distance(aEntity.Position)
end
function GetCostumeItem(aCollectibleType)
local player = Isaac.GetPlayer(0)
player:GetEffects():AddCollectibleEffect(aCollectibleType, true)
local effect = player:GetEffects():GetCollectibleEffect(aCollectibleType)
if effect ~= nil then
return effect.Item
end
return nil
end
local robesCostume = nil
local sackCostume = nil
local transendCostume = nil
local hasSpawnedBag = false
function hiding:PlayerInit(aConstPlayer)
local game = Game()
local level = game:GetLevel()
local player = Isaac.GetPlayer(0)
local room = game:GetRoom()
Character:Reset()
roomsClearedHidden = 0
hasSpawnedBag = false
player:AddCacheFlags(CacheFlag.CACHE_DAMAGE)
player:AddCollectible(headInABag, 1, false)
player:AddMaxHearts(-7, true)
player:AddBlackHearts(2)
Character:Reset()
CurrentFloor:Reset()
CurrentRoom:Reset()
CurrentRoom.myRoomInitialEnemyCount = room:GetAliveEnemiesCount()
robesCostume = GetCostumeItem(CollectibleType.COLLECTIBLE_CEREMONIAL_ROBES)
sackCostume = GetCostumeItem(CollectibleType.COLLECTIBLE_SACK_HEAD)
transendCostume = GetCostumeItem(CollectibleType.COLLECTIBLE_TRANSCENDENCE)
end
function hiding:Text()
local roomsClearedHiddenText = "Stealth: " .. tostring(roomsClearedHidden)
Isaac.RenderText(roomsClearedHiddenText, 5.0, 215.0, 1.0, 1.0, 1.0, 1.0)
end
function hiding:TakeDamage(aEntity)
end
function hiding:PostUpdate()
end
function hiding:PostPEffectUpdate(aConstPlayer)
local player = Isaac.GetPlayer(0)
local game = Game()
local room = game:GetRoom()
local level = game:GetLevel()
if CurrentFloor:IsNewFloor(level) then
level:AddCurse(LevelCurse.CURSE_OF_DARKNESS, false)
end
if CurrentRoom:IsNewRoom(level) then
CurrentRoom:Reset()
CurrentRoom.myRoomInitialEnemyCount = room:GetAliveEnemiesCount()
level:AddCurse(LevelCurse.CURSE_OF_DARKNESS, false)
OpenNormalDoors(room)
if IsBossInRoom(room) then
CurrentRoom.myIsBossRoom = true
end
end
if not hasSpawnedBag then
hasSpawnedBag = true
local pos = Isaac.GetFreeNearPosition(player.Position, 80)
Isaac.Spawn(EntityType.ENTITY_PICKUP, PickupVariant.PICKUP_COLLECTIBLE, headInABag, pos, Vector(0, 0), player)
local pos2 = Isaac.GetFreeNearPosition(player.Position, 80)
Isaac.Spawn(EntityType.ENTITY_PICKUP, PickupVariant.PICKUP_COLLECTIBLE, CollectibleType.COLLECTIBLE_MOMS_KNIFE, pos2, Vector(0, 0), player)
end
if not CurrentRoom.myHasIsaacBeenSeen and CurrentRoom.myRoomInitialEnemyCount ~= 0 and room:GetAliveEnemiesCount() == 0 then
roomsClearedHidden = roomsClearedHidden + 1
CurrentRoom.myRoomInitialEnemyCount = 0
Character.myStealthDamageBonus = Character.myStealthDamageBonus + 0.05
player:AddCacheFlags(CacheFlag.CACHE_DAMAGE)
player:EvaluateItems()
end
if not DoExpensiveAction(player) then
return
end
local oldHasIsaacBeenSeen = CurrentRoom.myHasIsaacBeenSeen
local entities = Isaac.GetRoomEntities()
local isBossInRoom = false
for i = 1, #entities do
if entities[i]:IsActiveEnemy() then
if entities[i]:IsBoss() then
isBossInRoom = true
end
local distance = DistanceFromPlayer(player, entities[i])
if distance < CurrentRoom.myClosestEnemyDistance then
CurrentRoom.myClosestEnemyDistance = distance
end
if not CurrentRoom.myIsHeadInABagActive and CurrentRoom.myClosestEnemyDistance < 110 then
CurrentRoom.myHasIsaacBeenSeen = true
level:RemoveCurse(LevelCurse.CURSE_OF_DARKNESS)
end
if not CurrentRoom.myHasIsaacBeenSeen and not entities[i]:IsBoss() then
entities[i]:AddEntityFlags(EntityFlag.FLAG_CONFUSION)
entities[i]:AddEntityFlags(EntityFlag.FLAG_SLOW)
else
entities[i]:ClearEntityFlags(EntityFlag.FLAG_CONFUSION)
entities[i]:ClearEntityFlags(EntityFlag.FLAG_SLOW)
end
end
end
if oldHasIsaacBeenSeen ~= CurrentRoom.myHasIsaacBeenSeen then
CloseNormalDoors(room)
end
end
function hiding:NpcUpdate(aNpc)
local game = Game()
local room = game:GetRoom()
local level = game:GetLevel()
if aNpc:IsBoss() then
CloseNormalDoors(room)
level:RemoveCurse(LevelCurse.CURSE_OF_DARKNESS)
end
end
function hiding:PostRender()
local player = Isaac.GetPlayer(0)
if robesCostume ~= nil and not CurrentRoom.myIsBossRoom and not CurrentRoom.myHasIsaacBeenSeen and not CurrentRoom.myIsHeadInABagActive then
player:RemoveCostume(robesCostume)
player:AddCostume(robesCostume, false)
end
if transendCostume ~= nil and sackCostume ~= nil and robesCostume ~= nil and (CurrentRoom.myHasIsaacBeenSeen or CurrentRoom.myIsBossRoom) then
player:RemoveCostume(robesCostume)
player:RemoveCostume(transendCostume)
player:RemoveCostume(sackCostume)
end
if transendCostume ~= nil and sackCostume ~= nil and not CurrentRoom.myIsHeadInABagActive then
player:RemoveCostume(transendCostume)
player:RemoveCostume(sackCostume)
end
end
function hiding:EvaluateCache(aEntityPlayer, aCacheFlag)
if aCacheFlag == CacheFlag.CACHE_DAMAGE and aEntityPlayer:HasCollectible(CollectibleType.COLLECTIBLE_MOMS_KNIFE) then
aEntityPlayer.Damage = aEntityPlayer.Damage * knifeDamageReduction
end
if aCacheFlag == CacheFlag.CACHE_DAMAGE then
aEntityPlayer.Damage = aEntityPlayer.Damage + Character.myStealthDamageBonus
end
end
function hiding:UseHeadInABag(aFoo, aBar)
if robesCostume ~= nil and transendCostume ~= nil and sackCostume ~= nil then
local game = Game()
local room = game:GetRoom()
local level = game:GetLevel()
local player = Isaac.GetPlayer(0)
player:RemoveCostume(robesCostume)
player:AddCostume(transendCostume, false)
player:AddCostume(sackCostume, false)
CurrentRoom.myIsHeadInABagActive = true
CurrentRoom.myHasIsaacBeenSeen = false
level:AddCurse(LevelCurse.CURSE_OF_DARKNESS, false)
OpenNormalDoors(room)
end
end
hiding:AddCallback(ModCallbacks.MC_POST_PLAYER_INIT, hiding.PlayerInit)
hiding:AddCallback(ModCallbacks.MC_POST_RENDER, hiding.Text)
hiding:AddCallback(ModCallbacks.MC_ENTITY_TAKE_DMG, hiding.TakeDamage)
hiding:AddCallback(ModCallbacks.MC_POST_UPDATE, hiding.PostUpdate)
hiding:AddCallback(ModCallbacks.MC_POST_PEFFECT_UPDATE, hiding.PostPEffectUpdate)
hiding:AddCallback(ModCallbacks.MC_POST_RENDER, hiding.PostRender)
hiding:AddCallback(ModCallbacks.MC_NPC_UPDATE, hiding.NpcUpdate)
hiding:AddCallback(ModCallbacks.MC_EVALUATE_CACHE, hiding.EvaluateCache)
hiding:AddCallback(ModCallbacks.MC_USE_ITEM, hiding.UseHeadInABag, headInABag);