Advertisement
mrbubble

Homunculus Item

Jul 13th, 2012
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 11.85 KB | None | 0 0
  1. #==============================================================================
  2. # ++ Homunculus Item ++                                         v1.0 (7/13/12)
  3. #==============================================================================
  4. # Script by:
  5. #     Mr. Bubble ( http://mrbubblewand.wordpress.com/ )
  6. # Thanks:
  7. #     Mithran, regexp lessons
  8. #--------------------------------------------------------------------------
  9. # Instant death attacks are a staple in the repertoire of skills featured
  10. # in the SMT series of games by Atlus. Combined with the rule that it is
  11. # game over when the main character dies, players can lose a battle
  12. # instantly they are not wary of these types of skills.
  13. #
  14. # This script provides a protection against instant death attacks by
  15. # implementing the effect of the "Homunculus" item. Homunculus items
  16. # prevent the effects of successful instant death attacks by simply
  17. # being in the party's inventory. This effect is limited to Actors.
  18. #--------------------------------------------------------------------------
  19. #   ++ Changelog ++
  20. #--------------------------------------------------------------------------
  21. # v1.0 : Initial release. (7/13/2012)
  22. #--------------------------------------------------------------------------
  23. #   ++ Installation ++
  24. #--------------------------------------------------------------------------
  25. # Install this script in the Materials section in your project's
  26. # script editor.
  27. #==============================================================================
  28. #   ++ Homunculus Item Notetags ++
  29. #==============================================================================
  30. # Note: Some tags are given shorter tags for typing convenience. You only
  31. #       need to use one <tag> from a given group for a notebox.
  32. #
  33. # The following Notetags are for Actors only:
  34. #
  35. # <homunculus item: id>
  36. # <homun item: id>
  37. #   This tag assigns to an actor a "homunculus item" where id is an item ID
  38. #   number from the database. Homunculus items protect the actor from
  39. #   instant death effects (i.e. attempts to directly apply State ID 1,
  40. #   "Death"). This will not affect damaging attacks that would
  41. #   cause death. When a homunculus item successfully protects the actor,
  42. #   one unit of the item is removed from the party's inventory. Each actor
  43. #   can have a different homunculus item or even share the same one. This
  44. #   effect will only work if there is at least one homunculus item for the
  45. #   actor in the party's inventory.
  46. #--------------------------------------------------------------------------
  47. #   ++ Compatibility ++
  48. #--------------------------------------------------------------------------
  49. # This script aliases the following default VXA methods:
  50. #
  51. #     Game_ActionResult#clear
  52. #
  53. #     Window_BattleLog#display_critical
  54. #
  55. #     Game_Actor#setup
  56. #     Game_Actor#add_state
  57. #    
  58. # There are no default method overwrites.
  59. #
  60. # Requests for compatibility with other scripts are welcome.
  61. #--------------------------------------------------------------------------
  62. #   ++ Terms and Conditions ++
  63. #--------------------------------------------------------------------------
  64. # Please do not repost this script elsewhere without permission.
  65. # Free for non-commercial use. For commercial use, contact me first.
  66. #
  67. # Newest versions of this script can be found at
  68. #                                           http://mrbubblewand.wordpress.com/
  69. #==============================================================================
  70.  
  71. #==========================================================================
  72. # ++ START OF USER CUSTOMIZATION MODULE ++
  73. #==========================================================================
  74. module Bubs
  75.   #==========================================================================
  76.   # ++ Homunculus Item Settings
  77.   #==========================================================================
  78.   module HomunculusItem
  79.   #--------------------------------------------------------------------------
  80.   #   Disable Homunculus Item Switch ID Setting     !! IMPORTANT SETTING !!
  81.   #--------------------------------------------------------------------------
  82.   # This setting defines the switch ID number used to determine if
  83.   # homunculus items are allowed in battle. This is useful for evented
  84.   # battles and such. If the ID is set to 0, no game switch will be used.
  85.   #
  86.   # If the switch is ON, homunculus items are disabled.
  87.   # If the switch is OFF, homunculus items are enabled.
  88.   DISABLE_HOMUNCULUS_SWITCH_ID = 0
  89.   #--------------------------------------------------------------------------
  90.   #   Homunculus Battle Log Text
  91.   #--------------------------------------------------------------------------
  92.   # This setting determines how long HOMUNCULUS_TEXT stays seen
  93.   # in the battle log. Higher values increase the time.
  94.   #
  95.   # %s is automatically replaced by the item's name.
  96.   HOMUNCULUS_TEXT = "The %s sacrificed itself!"
  97.   #--------------------------------------------------------------------------
  98.   #   Homunculus Text Wait
  99.   #--------------------------------------------------------------------------
  100.   # This setting determines how long HOMUNCULUS_TEXT stays seen
  101.   # in the battle log. Higher values increase the time.
  102.   HOMUNCULUS_TEXT_WAIT = 3
  103.  
  104.   #--------------------------------------------------------------------------
  105.   #   Homunculus Item Sound Effect
  106.   #--------------------------------------------------------------------------
  107.   # This setting defines the sound effect used when HOMUNCULUS_TEXT
  108.   # is displayed in-battle.
  109.   #                      "filename", Volume, Pitch
  110.   HOMUNCULUS_TEXT_SE = ["Collapse3",     80,   120]
  111.  
  112.   end # module HomunculusItem
  113. end # module Bubs
  114.  
  115. #==========================================================================
  116. # ++ END OF USER CUSTOMIZATION MODULE ++
  117. #==========================================================================
  118.  
  119.  
  120.  
  121. #==============================================================================
  122. # ++ Sound
  123. #==============================================================================
  124. module Sound
  125.   #--------------------------------------------------------------------------
  126.   # new method : play_homunculus_item_break
  127.   #--------------------------------------------------------------------------
  128.   def self.play_homunculus_item_break
  129.     filename = Bubs::HomunculusItem::HOMUNCULUS_TEXT_SE[0]
  130.     volume = Bubs::HomunculusItem::HOMUNCULUS_TEXT_SE[1]
  131.     pitch = Bubs::HomunculusItem::HOMUNCULUS_TEXT_SE[2]
  132.     Audio.se_play("/Audio/SE/" + filename, volume, pitch)
  133.   end
  134. end # module Sound
  135.  
  136.  
  137. #==============================================================================
  138. # ++ Window_BattleLog
  139. #==============================================================================
  140. class Game_ActionResult
  141.   #--------------------------------------------------------------------------
  142.   # public instance variables
  143.   #--------------------------------------------------------------------------
  144.   attr_accessor :homunculus_item_used        # homun used flag
  145.   #--------------------------------------------------------------------------
  146.   # alias : clear
  147.   #--------------------------------------------------------------------------
  148.   alias clear_bubs_homunculus_item clear
  149.   def clear
  150.     clear_bubs_homunculus_item # alias
  151.    
  152.     @homunculus_item_used = false
  153.   end # def clear
  154.  
  155. end # class Game_ActionResult
  156.  
  157.  
  158. #==============================================================================
  159. # ++ Window_BattleLog
  160. #==============================================================================
  161. class Window_BattleLog < Window_Selectable
  162.   #--------------------------------------------------------------------------
  163.   # alias : display_critical
  164.   #--------------------------------------------------------------------------
  165.   alias display_critical_bubs_homunculus_item display_critical
  166.   def display_critical(target, item)
  167.     display_homunculus_sacrifice(target, item) if target.result.used
  168.  
  169.     display_critical_bubs_homunculus_item(target, item) # alias    
  170.   end # def display_critical
  171.  
  172.   #--------------------------------------------------------------------------
  173.   # new method : display_homunculus_sacrifice
  174.   #--------------------------------------------------------------------------
  175.   def display_homunculus_sacrifice(target, item)
  176.     if target.result.homunculus_item_used
  177.       id = target.homunculus_item_id
  178.       text = sprintf(Bubs::HomunculusItem::HOMUNCULUS_TEXT, $data_items[id].name)
  179.       add_text(text)
  180.       Sound.play_homunculus_item_break
  181.       Bubs::HomunculusItem::HOMUNCULUS_TEXT_WAIT.times do; wait; end
  182.       wait_for_effect
  183.       back_one
  184.     end
  185.   end # def display_homunculus_sacrifice
  186. end # class Window_BattleLog
  187.  
  188.  
  189. #==============================================================================
  190. # ++ Game_Battler
  191. #==============================================================================
  192. class Game_Battler < Game_BattlerBase
  193.   #--------------------------------------------------------------------------
  194.   # new method : homunculus_item_conditions_met?
  195.   #--------------------------------------------------------------------------
  196.   def homunculus_item_conditions_met?(state_id)
  197.     return false
  198.   end
  199. end # class Game_Battler
  200.  
  201.  
  202. #==============================================================================
  203. # ++ Game_Actor
  204. #==============================================================================
  205. class Game_Actor < Game_Battler
  206.   #--------------------------------------------------------------------------
  207.   # public instance variables
  208.   #--------------------------------------------------------------------------
  209.   attr_accessor :homunculus_item_id   # item id
  210.   #--------------------------------------------------------------------------
  211.   # alias : setup
  212.   #--------------------------------------------------------------------------
  213.   alias setup_bubs_homunculus_item setup
  214.   def setup(actor_id)
  215.     setup_bubs_homunculus_item(actor_id) # alias
  216.    
  217.     @homunculus_item_id ||= homunculus_item_noteread
  218.   end # def setup
  219.  
  220.   #--------------------------------------------------------------------------
  221.   # new method : homunculus_item_noteread
  222.   #--------------------------------------------------------------------------
  223.   def homunculus_item_noteread
  224.     actor.note =~ /<(?:HOMUNCULUS|HOMUN)[\s_]?ITEM:\s*(\d+)>/i ? $1.to_i : 0
  225.   end # def homunculus_item_noteread
  226.  
  227.   #--------------------------------------------------------------------------
  228.   # alias : add_state
  229.   #--------------------------------------------------------------------------
  230.   alias add_state_bubs_homunculus_item add_state
  231.   def add_state(state_id)
  232.     if homunculus_item_conditions_met?(state_id)
  233.       use_homunculus_item
  234.     else
  235.       add_state_bubs_homunculus_item(state_id) # alias
  236.     end
  237.   end # def add_state
  238.  
  239.   #--------------------------------------------------------------------------
  240.   # new method : homunculus_item_conditions_met?
  241.   #--------------------------------------------------------------------------
  242.   def homunculus_item_conditions_met?(state_id)
  243.     return false if $game_switches[Bubs::HomunculusItem::DISABLE_HOMUNCULUS_SWITCH_ID]
  244.     return false unless actor?
  245.     return false unless state_id == death_state_id
  246.     return false unless @hp > 0
  247.     return false unless state_addable?(state_id)
  248.     return false unless @homunculus_item_id > 0
  249.     return false unless $game_party.has_item?($data_items[@homunculus_item_id])
  250.     return true
  251.   end # def homunculus_item_conditions_met?
  252.  
  253.   #--------------------------------------------------------------------------
  254.   # new method : use_homunculus_item
  255.   #--------------------------------------------------------------------------
  256.   def use_homunculus_item
  257.     $game_party.lose_item($data_items[@homunculus_item_id], 1)
  258.     @result.homunculus_item_used = true
  259.   end # def use_homunculus_item
  260.  
  261. end # class Game_Actor
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement