Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Mod = RegisterMod("Courage or Cowardice", 1)
- ------------
- -- Global --
- ------------
- -- Global Variables --
- local game = Game()
- local currentRoom = game:GetRoom()
- -- Global Functions --
- -- Global Callbacks --
- -----------
- -- Items --
- -----------
- local ItemScript = {}
- -- Item Variables --
- local ItemId = {
- -- Passive Items --
- RESILIENCE = Isaac.GetItemIdByName("Resilience"),
- -- Active Items --
- -- Trinkets --
- ADRENALINERUSH = Isaac.GetTrinketIdByName("Adrenaline Rush")
- }
- local ItemCostume = {
- -- Passive Items --
- RESILIENCE = Isaac.GetCostumeIdByPath("gfx/characters/Resilience.anm2")
- -- Active Items --
- -- Trinkets --
- }
- local ItemBonus = {
- -- Passive Items --
- RESILIENCE_DAMAGE = 0.5,
- RESILIENCE_MOVE = 0.1,
- RESILIENCE_RANGE = 1,
- -- Active Items --
- -- Trinkets --
- ADRENALINE_DAMAGE = 1.2, -- Multiplier: +20% damage
- ADRENALINE_MOVE = 1.4 -- Multiplier: +40% speed
- }
- local HasItem = {
- -- Passive Items --
- Resilience = false,
- -- Active Items --
- -- Trinkets --
- AdrenalineRush = false
- }
- local ResilienceProc = false
- local ResilienceStacks = 0
- -- Item Functions --
- function UpdateItems(player) -- Sets HasItem booleans for each item to whether the player has the item
- -- Passive Items --
- HasItem.Resilience = player:HasCollectible(ItemId.RESILIENCE)
- -- Active Items --
- -- Trinkets --
- HasItem.AdrenalineRush = player:HasTrinket(ItemId.ADRENALINERUSH)
- end
- function ItemScript:onPlayerInit(player) -- When player is created (game start or continue)
- UpdateItems(player)
- end
- function ItemScript:onPefUpdate(player)
- -- Beginning of run initialization
- if game:GetFrameCount() == 1 then
- if player:HasCollectible(ItemId.RESILIENCE) and not HasItem.Resilience then
- player:AddNullCostume(ItemCostume.RESILIENCE)
- UpdateItems(player)
- end
- end
- if currentRoom:GetFrameCount() == 1 then -- On entry of a room
- player:AddCacheFlags(CacheFlag.CACHE_DAMAGE) -- Set fire delay cache flag for evaluation
- player:AddCacheFlags(CacheFlag.CACHE_SPEED) -- Set speed cache flag for evaluation
- player:AddCacheFlags(CacheFlag.CACHE_RANGE) -- Set range cache flag for evaluation
- player:EvaluateItems() -- Evaluate player items
- ResilienceStacks = 0 -- Set Resilience stacks to 0
- end
- if currentRoom:GetFrameCount() == 180 then -- 180 frames after entry of room
- if HasItem.AdrenalineRush and not HasItem.Resilience then
- player:AddCacheFlags(CacheFlag.CACHE_DAMAGE) -- Set fire delay cache flag for evaluation
- player:AddCacheFlags(CacheFlag.CACHE_SPEED) -- Set speed cache flag for evaluation
- player:EvaluateItems() -- Evaluate player items
- end
- end
- -- Add resilience costume on acquire
- if player:HasCollectible(ItemId.RESILIENCE) and not HasItem.Resilience then
- player:AddNullCostume(ItemCostume.RESILIENCE)
- end
- UpdateItems(player)
- end
- function ItemScript:onDmg(target, dmg, flags, source, countdown)
- for playerNum = 0, game:GetNumPlayers() do
- local player = game:GetPlayer(playerNum)
- if HasItem.Resilience then
- ResilienceProc = true
- ResilienceStacks = ResilienceStacks + 1
- player:AddCacheFlags(CacheFlag.CACHE_DAMAGE)
- player:AddCacheFlags(CacheFlag.CACHE_RANGE)
- player:AddCacheFlags(CacheFlag.CACHE_SPEED)
- player:EvaluateItems()
- ResilienceProc = false
- end
- end
- end
- function ItemScript:onCache(player, cacheFlag) -- When cache is updated
- local defaultDamage = player.Damage -- Set default damage (to damage when cache is evaluated)
- local defaultMove = player.MoveSpeed -- Set default move speed (to tear rate when cache is evaluated)
- if cacheFlag == CacheFlag.CACHE_DAMAGE then -- If cache is fire delay
- if HasItem.AdrenalineRush then -- If player has Blood Rush trinket
- if currentRoom:GetFrameCount() == 1 then -- If current room has only just been entered
- player.Damage = defaultDamage * ItemBonus.ADRENALINE_DAMAGE -- Increase damage by Adrenaline Rush damage (multiplier)
- end
- if currentRoom:GetFrameCount() == 180 and player.MaxFireDelay > defaultDamage then -- If been in room for 180 frames and damage is more than default damage
- player.Damage = defaultDamage -- Set tear rate to default damage
- end
- end
- if HasItem.Resilience then
- if ResilienceProc then
- player.Damage = player.Damage + (ItemBonus.RESILIENCE_DAMAGE * ResilienceStacks)
- end
- if currentRoom:GetFrameCount() == 1 and ResilienceStacks > 0 then
- player.Damage = player.Damage - (ItemBonus.RESILIENCE_DAMAGE * ResilienceStacks)
- end
- end
- end
- if cacheFlag == CacheFlag.CACHE_RANGE then -- If cache is range
- if HasItem.Resilience then
- if ResilienceProc then
- player.TearHeight = player.TearHeight + (ItemBonus.RESILIENCE_RANGE * ResilienceStacks)
- player.TearFallingSpeed = player.TearFallingSpeed + (ItemBonus.RESILIENCE_RANGE * ResilienceStacks)
- end
- if currentRoom:GetFrameCount() == 1 and ResilienceStacks > 0 then
- player.TearHeight = player.TearHeight - (ItemBonus.RESILIENCE_RANGE * ResilienceStacks)
- player.TearFallingSpeed = player.TearFallingSpeed - (ItemBonus.RESILIENCE_RANGE * ResilienceStacks)
- end
- end
- end
- if cacheFlag == CacheFlag.CACHE_SPEED then -- If cache is speed
- if HasItem.AdrenalineRush then -- If player has Blood Rush trinket
- if currentRoom:GetFrameCount() == 1 then -- If current room has only just been entered
- player.MoveSpeed = defaultMove * ItemBonus.ADRENALINE_MOVE -- Increase movement speed by Blood Rush move speed (multiplier)
- end
- if currentRoom:GetFrameCount() == 180 and player.MoveSpeed > defaultMove then -- If been in room for 180 frames and max move speed is higher than default move speed
- player.MoveSpeed = defaultMove -- Set move speed to default move speed
- end
- end
- if HasItem.Resilience then
- if ResilienceProc then
- player.MoveSpeed = player.MoveSpeed + (ItemBonus.RESILIENCE_MOVE * ResilienceStacks)
- end
- if currentRoom:GetFrameCount() == 1 and ResilienceStacks > 0 then
- player.MoveSpeed = player.MoveSpeed - (ItemBonus.RESILIENCE_MOVE * ResilienceStacks)
- end
- end
- end
- end
- -- Item Callbacks --
- Mod:AddCallback(ModCallbacks.MC_POST_PLAYER_INIT, ItemScript.onPlayerInit)
- Mod:AddCallback(ModCallbacks.MC_POST_PEFFECT_UPDATE, ItemScript.onPefUpdate)
- Mod:AddCallback(ModCallbacks.MC_ENTITY_TAKE_DMG, ItemScript.onDmg, EntityType.ENTITY_PLAYER)
- Mod:AddCallback(ModCallbacks.MC_EVALUATE_CACHE, ItemScript.onCache)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement