Josh64

ToySkull final version

May 13th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.21 KB | None | 0 0
  1. <items gfxroot="gfx/items/" version="1">
  2.  
  3.     <passive cache="luck" description="What's hidden inside?" name="Toy Skull" gfx="toyskull.png" />
  4.  
  5. </items>
  6.  
  7.  
  8.  
  9. ______________________________________
  10.  
  11.  
  12.  
  13. <ItemPools>
  14.  
  15.     <Pool Name="treasure">
  16.  
  17.         <Item Name="Toy Skull" Weight="1" DecreasedBy="0,5" RemoveOn="0,1" />
  18.  
  19.     </Pool>
  20.  
  21. </ItemPools>
  22.  
  23.  
  24.  
  25. ______________________________________________
  26.  
  27.  
  28.  
  29. <costumes anm2root="gfx/charaters/">
  30.  
  31.     <costume anm2path="toySkull.anm2" type="none" />
  32.  
  33. </costumes>
  34.  
  35.  
  36.  
  37. ___________________________________
  38.  
  39.  
  40.  
  41. local ToySkullMod = RegisterMod("ToySkull", 1)
  42.  
  43. local game = Game()
  44.  
  45.  
  46.  
  47. -- reference item, costume, luck boost, Shell Game Beggar and beggar states
  48.  
  49.  
  50.  
  51. ToySkullMod.COLLECTIBLE_TOYSKULL = Isaac.GetItemIdByName("Toy Skull")
  52.  
  53. ToySkullMod.COSTUME_TOYSKULL = Isaac.GetCostumeIdByPath("gfx/characters/toySkull.anm2")
  54.  
  55. Skull.LUCK_TOYSKULL = 2
  56.  
  57. Shell.SKULL_BEGGAR = Isaac.GetEntityVariantByName ("Shell Game Beggar")
  58.  
  59. BeggarState = {
  60.  
  61.     PAYPRIZE = 3,
  62.  
  63.     PRIZE = 4
  64.  
  65. }
  66.  
  67.  
  68.  
  69. function ToySkullMod:onUpdate(player)
  70.  
  71.     if game:GetFrameCount() == 1 then
  72.  
  73.         ToySkullMod.HasToySkull = false
  74.  
  75.         -- Isaac.Spawn(EntityType.ENTITY_PICKUP, PickupVariant.PICKUP_COLLECTIBLE, ToySkullMod.COLLECTIBLE_TOYSKULL, Vector(320, 300), Vector(0,0), player) -- spawn in if necessary
  76.  
  77.     end
  78.  
  79.     if not ToySkullMod.HasToySkull and player:HasCollectible(ToySkullMod.COLLECTIBLE_TOYSKULL) then
  80.  
  81.         player:AddNullCostume(ToySkullMod.COSTUME_TOYSKULL)
  82.  
  83.         ToySkullMod.HasToySkull = true
  84.  
  85.     end
  86.  
  87. end
  88.  
  89. ToySkullMod:AddCallback(ModCallbacks.MC_POST_PEFFECT_UPDATE, ToySkullMod.onUpdate)
  90.  
  91.  
  92.  
  93. -- update the cache/luck
  94.  
  95.  
  96.  
  97. function ToySkullMod:onCache(player, cacheFlag)
  98.  
  99.     if cacheFlag == CacheFlag.CACHE_LUCK then
  100.  
  101.         if player:HasCollectible(ToySkullMod.COLLECTIBLE_TOYSKULL) then
  102.  
  103.             player.Luck = player.Luck + Skull.LUCK_TOYSKULL
  104.  
  105.         end
  106.  
  107.     end
  108.  
  109. end
  110.  
  111. ToySkullMod:AddCallback(ModCallbacks.MC_EVALUATE_CACHE, ToySkullMod.onCache)
  112.  
  113.  
  114.  
  115. -- Toy Skull functionality
  116.  
  117.  
  118.  
  119. function ToySkullMod:onBeggarPayout(entity)
  120.  
  121.     local player = Isaac.GetPlayer(0)
  122.  
  123.     local entities = Isaac.GetRoomEntities()
  124.  
  125.     if player:HasCollectible(ToySkullMod.COLLECTIBLE_TOYSKULL) then
  126. if entity.State == BeggarState.PAYPRIZE then -- check the state of the beggar. Does he pay out?
  127. if entity.StateFrame == 0 then -- check at the beginn of the state
  128. for j = 1, #entities do -- check all enities in the room
  129. if entities[j].Type == EntityType.ENTITY_PICKUP -- is the entity a pickup?
  130. and entities[j].Variant == PickupVariant.PICKUP_COIN -- is it a coin?
  131. and entities[j].SubType == CoinSubType.COIN_PENNY then -- and a penny?
  132. if entities[j].FrameCount == 1 then -- is it new?
  133. entities[j]:ToPickup():Morph(EntityType.ENTITY_PICKUP, PickupVariant.PICKUP_GRAB_BAG, 0, true) -- change the penny into a sack
  134. end
  135. end
  136. if entities[j].Type == EntityType.ENTITY_PICKUP -- do the same for normal keys
  137. and entities[j].Variant == PickupVariant.PICKUP_KEY
  138. and entities[j].SubType == KeySubType.KEY_NORMAL then
  139. if entities[j].FrameCount == 1 then
  140. local rng = Isaac.GetCollectibleRNG(ToySkullMod.COLLECTIBLE_TOYSKULL)
  141. local pillRandom = rng:RandomInt(NUM_PILL_EFFECTS) -- gives you a random pill id
  142. entities[j]:ToPickup():Morph(EntityType.ENTITY_PICKUP, PickupVarint.PICKUP_PILL, pillRandom, true) -- change the normal key into a random pill
  143. end
  144. end
  145. if entities[j].Type == EntityType.ENTITY_PICKUP -- do the same for normal bombs
  146. and entities[j].Variant == PickupVariant.PICKUP_BOMB
  147. and entities[j].SubType == BombSubType.BOMB_NORMAL then
  148. if entities[j].FrameCount == 1 then
  149. local rng = Isaac.GetCollectibleRNG(ToySkullMod.COLLECTIBLE_TOYSKULL)
  150. local runeRandom = rng:RandomInt(100)
  151. if runeRandom < 10 then
  152. entities[j]:ToPickup():Morph(EntityType.ENTITY_PICKUP, PickupVariant.PICKUP_TAROTCARD, Card.RUNE_HAGALAZ, true)
  153. elseif runeRandom < 20 then
  154. entities[j]:ToPickup():Morph(EntityType.ENTITY_PICKUP, PickupVariant.PICKUP_TAROTCARD, Card.RUNE_JERA, true)
  155. elseif runeRandom < 30 then
  156. entities[j]:ToPickup():Morph(EntityType.ENTITY_PICKUP, PickupVariant.PICKUP_TAROTCARD, Card.RUNE_EHWAZ, true)
  157. elseif runeRandom < 40 then
  158. entities[j]:ToPickup():Morph(EntityType.ENTITY_PICKUP, PickupVariant.PICKUP_TAROTCARD, Card.RUNE_DAGAZ, true)
  159. elseif runeRandom < 50 then
  160. entities[j]:ToPickup():Morph(EntityType.ENTITY_PICKUP, PickupVariant.PICKUP_TAROTCARD, Card.RUNE_ANSUZ, true)
  161. elseif runeRandom < 60 then
  162. entities[j]:ToPickup():Morph(EntityType.ENTITY_PICKUP, PickupVariant.PICKUP_TAROTCARD, Card.RUNE_PERTHRO, true)
  163. elseif runeRandom < 70 then
  164. entities[j]:ToPickup():Morph(EntityType.ENTITY_PICKUP, PickupVariant.PICKUP_TAROTCARD, Card.RUNE_BERKANO, true)
  165. elseif runeRandom < 80 then
  166. entities[j]:ToPickup():Morph(EntityType.ENTITY_PICKUP, PickupVariant.PICKUP_TAROTCARD, Card.RUNE_ALGIZ, true)
  167. elseif runeRandom < 90 then
  168. entities[j]:ToPickup():Morph(EntityType.ENTITY_PICKUP, PickupVariant.PICKUP_TAROTCARD, Card.RUNE_BLANK, true)
  169. else
  170. entities[j]:ToPickup():Morph(EntityType.ENTITY_PICKUP, PickupVariant.PICKUP_TAROTCARD, Card.RUNE_BLACK, true)
  171. end
  172. end
  173. end
  174. end
  175. end
  176. end
  177.     end
  178.  
  179. -- the Shell Game Beggar "item pool"
  180.  
  181. if not player:HasCollectible(ToySkullMod.COLLECTIBLE_TOYSKULL) then -- only works if you dont have the Toy Skull
  182. if entity.State == BeggarState.PRIZE then -- check the beggar state
  183. if entity.StateFrame == 0 then -- at the beginn of the state
  184. for j = 1, #entities do -- check all room entities again
  185. if entities[j].Type == EntityType.ENTITY_PICKUP -- check for Skatole
  186. and entities[j].Variant == PickupVariant.PICKUP_COLLECTIBLE
  187. and entities[j].SubType == CollectibleType.COLLECTIBLE_SKATOLE then
  188. if entities[j].FrameCount == 1 then
  189. local rng = Isaac.GetCollectibleRNG(ToySkullMod.COLLECTIBLE_TOYSKULL)
  190. local skullRandom = rng:RandomInt(100)
  191. if skullRandom < 50 then -- 50% chance to get the Toy Skull
  192. entities[j]:ToPickup():Morph(EntityType.ENTITY_PICKUP, PickupVariant.PICKUP_COLLECTIBLE, ToySkullMod.COLLECTIBLE_TOYSKULL, true)
  193. esle
  194. entities[j]:ToPickup():Morph(EntityType.ENTITY_PICKUP, PickupVariant.PICKUP_COLLECTIBLE, CollectibleType.COLLECTIBLE_SKATOLE, true)
  195. end
  196. end
  197. end
  198. end
  199. end
  200. end
  201. end
  202.  
  203. end
  204. ToySkullMod:AddCallback(ModCallbacks.MC_NPC_UPDATE, ToySkullMod.onBeggarPayout, Shell.SKULL_BEGGAR)
Add Comment
Please, Sign In to add comment