Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2011
714
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 11.78 KB | None | 0 0
  1. #===============================================================================
  2. #
  3. # Shanghai Simple Script - Hospital Fees
  4. # Last Date Updated: 2010.05.13
  5. # Level: Normal
  6. #
  7. # Not every hero lives in Europe. Hospitals have fees, too, you know.
  8. #===============================================================================
  9. # Instructions
  10. # -----------------------------------------------------------------------------
  11. # To install this script, open up your script editor and copy/paste this script
  12. # to an open slot below ▼ Materials but above ▼ Main. Remember to save.
  13. #
  14. # To launch the hospital scene, have a script call in an event with
  15. #    $scene = Scene_Hospital.new
  16. #
  17. # <hospital fee: x>
  18. # To change the cost of healing certain states, put this in the state's notebox
  19. # with x as the fee.
  20. #===============================================================================
  21.  
  22. $imported = {} if $imported == nil
  23. $imported["HospitalFees"] = true
  24.  
  25. module SSS
  26.   # This is how much gold the hospital charges for each HP and MP lost per
  27.   # party member.
  28.   HOSPITAL_HP_COST = 1
  29.   HOSPITAL_MP_COST = 3
  30.   # This is the default state removal hospital fee. However, the death state
  31.   # costs slightly more than usual.
  32.   HOSPITAL_STATE_REMOVAL = 100
  33.   HOSPITAL_STATE_REVIVAL = 1000
  34.   # This is the text that appears at the very top in the help window.
  35.   HOSPITAL_HELP_TEXT = "Heal all party members for %sG."
  36.   HOSPITAL_HELP_HEALTHY = "All members are healthy."
  37.   # This sets the commands for the command window.
  38.   HOSPITAL_HEAL_ONE  = "Heal One"
  39.   HOSPITAL_HEAL_ALL  = "Heal All"
  40.   HOSPITAL_EXIT      = "Exit"
  41.   # This sets the categories for the hospital columns.
  42.   HOSPITAL_NAME_COL  = "Name"
  43.   HOSPITAL_COST_COL  = "Cost"
  44. end
  45.  
  46. #==============================================================================
  47. # ** RPG::State
  48. #==============================================================================
  49.  
  50. class RPG::State
  51.   #--------------------------------------------------------------------------
  52.   # hospital_fee
  53.   #--------------------------------------------------------------------------
  54.   def hospital_fee
  55.     return @hospital_fee if @hospital_fee != nil
  56.     @hospital_fee = SSS::HOSPITAL_STATE_REMOVAL
  57.     @hospital_fee = SSS::HOSPITAL_STATE_REVIVAL if self.id == 1
  58.     self.note.split(/[\r\n]+/).each { |line|
  59.       case line
  60.       when /<(?:HOSPITAL_FEE|hospital fee):[ ]*(\d+)>/i
  61.         @hospital_fee = $1.to_i
  62.       end
  63.     }
  64.     return @hospital_fee
  65.   end
  66. end
  67.  
  68. #==============================================================================
  69. # ** Game_Actor
  70. #==============================================================================
  71.  
  72. class Game_Actor < Game_Battler
  73.   #--------------------------------------------------------------------------
  74.   # * Heal Cost
  75.   #--------------------------------------------------------------------------
  76.   def heal_cost
  77.     cost = 0
  78.     cost += (self.maxhp-self.hp)*SSS::HOSPITAL_HP_COST
  79.     cost += (self.maxmp-self.mp)*SSS::HOSPITAL_MP_COST
  80.     for state in states
  81.       next if state.nil?
  82.       cost += state.hospital_fee
  83.     end
  84.     return cost
  85.   end
  86. end
  87. #==============================================================================
  88. # ** Game_Party
  89. #==============================================================================
  90.  
  91. class Game_Party < Game_Unit
  92.   #--------------------------------------------------------------------------
  93.   # * Heal Cost
  94.   #--------------------------------------------------------------------------
  95.   def heal_cost
  96.     cost = 0
  97.     for i in @actors
  98.       next if $game_actors[i].nil?
  99.       cost += $game_actors[i].heal_cost
  100.     end
  101.     return cost
  102.   end
  103. end
  104.  
  105. #==============================================================================
  106. # ** Window_Hospital
  107. #==============================================================================
  108.  
  109. class Window_Hospital < Window_Selectable
  110.   #--------------------------------------------------------------------------
  111.   # * Object Initialization
  112.   #--------------------------------------------------------------------------
  113.   def initialize(x, y)
  114.     super(x, y, Graphics.width, Graphics.height - y)
  115.     refresh
  116.     self.active = false
  117.     self.back_opacity = 0
  118.     self.opacity = 0
  119.   end
  120.   #--------------------------------------------------------------------------
  121.   # * Actor
  122.   #--------------------------------------------------------------------------
  123.   def actor
  124.     return @data[self.index]
  125.   end
  126.   #--------------------------------------------------------------------------
  127.   # * Refresh
  128.   #--------------------------------------------------------------------------
  129.   def refresh
  130.     @data = $game_party.members
  131.     @item_max = @data.size
  132.     create_contents
  133.     for i in 0...@item_max
  134.       draw_item(i)
  135.     end
  136.   end
  137.   #--------------------------------------------------------------------------
  138.   # * Draw Item
  139.   #--------------------------------------------------------------------------
  140.   def draw_item(index)
  141.     rect = item_rect(index)
  142.     self.contents.clear_rect(rect)
  143.     actor = @data[index]
  144.     if actor != nil
  145.       rect.width -= 4
  146.       draw_actor_name(actor, rect.x+4, rect.y)
  147.       draw_actor_state(actor, rect.x+108, rect.y, 48)
  148.       draw_actor_hp(actor, rect.x+156, rect.y, 120)
  149.       draw_actor_mp(actor, rect.x+280, rect.y, 120)
  150.       draw_actor_heal_cost(actor, rect.x+404, rect.y)
  151.     end
  152.   end
  153.   #--------------------------------------------------------------------------
  154.   # * Draw Actor Heal Cost
  155.   #--------------------------------------------------------------------------
  156.   def draw_actor_heal_cost(actor, x, y)
  157.     if actor != nil
  158.       text = sprintf("%d%s", actor.heal_cost, Vocab.gold)
  159.       align = 2
  160.       if text == sprintf("%d%s", 0, Vocab.gold)
  161.         text = "-----"
  162.         align = 1
  163.       end
  164.       enabled = $game_party.gold >= actor.heal_cost
  165.       self.contents.font.color.alpha = enabled ? 255 : 128
  166.       self.contents.draw_text(x, y, 104, WLH, text, align)
  167.     end
  168.   end
  169. end
  170.  
  171. #==============================================================================
  172. # ** Window_HospitalBack
  173. #==============================================================================
  174.  
  175. class Window_HospitalBack < Window_Base
  176.   #--------------------------------------------------------------------------
  177.   # * Object Initialization
  178.   #--------------------------------------------------------------------------
  179.   def initialize(x, y)
  180.     super(x, y, Graphics.width, Graphics.height - y)
  181.     refresh
  182.   end
  183.   #--------------------------------------------------------------------------
  184.   # * Refresh
  185.   #--------------------------------------------------------------------------
  186.   def refresh
  187.     self.contents.clear
  188.     self.contents.font.color = normal_color
  189.     self.contents.draw_text(4, 0, 152, WLH, SSS::HOSPITAL_NAME_COL, 1)
  190.     self.contents.draw_text(156, 0, 124, WLH, Vocab.hp, 1)
  191.     self.contents.draw_text(280, 0, 124, WLH, Vocab.mp, 1)
  192.     self.contents.draw_text(404, 0, 104, WLH, SSS::HOSPITAL_COST_COL, 1)
  193.   end
  194. end
  195.  
  196. #==============================================================================
  197. # ** Scene_Hospital
  198. #==============================================================================
  199.  
  200. class Scene_Hospital < Scene_Base
  201.   #--------------------------------------------------------------------------
  202.   # * Start processing
  203.   #--------------------------------------------------------------------------
  204.   def start
  205.     super
  206.     create_menu_background
  207.     @help_window = Window_Help.new
  208.     text = sprintf(SSS::HOSPITAL_HELP_TEXT, $game_party.heal_cost)
  209.     text = SSS::HOSPITAL_HELP_HEALTHY if $game_party.heal_cost == 0
  210.     @help_window.set_text(text, 1)
  211.     create_command_window
  212.     @gold_window = Window_Gold.new(Graphics.width - 160, @help_window.height)
  213.     @back_window = Window_HospitalBack.new(0, @help_window.height + 56)
  214.     @hospital_window = Window_Hospital.new(0, @help_window.height + 80)
  215.   end
  216.   #--------------------------------------------------------------------------
  217.   # * Termination Processing
  218.   #--------------------------------------------------------------------------
  219.   def terminate
  220.     super
  221.     dispose_menu_background
  222.     @help_window.dispose
  223.     @command_window.dispose
  224.     @gold_window.dispose
  225.     @back_window.dispose
  226.     @hospital_window.dispose
  227.   end
  228.   #--------------------------------------------------------------------------
  229.   # * Create Command Window
  230.   #--------------------------------------------------------------------------
  231.   def create_command_window
  232.     s1 = SSS::HOSPITAL_HEAL_ONE
  233.     s2 = SSS::HOSPITAL_HEAL_ALL
  234.     s3 = SSS::HOSPITAL_EXIT
  235.     @command_window = Window_Command.new(Graphics.width - 160, [s1, s2, s3], 3)
  236.     @command_window.y = @help_window.height
  237.   end
  238.   #--------------------------------------------------------------------------
  239.   # * Frame Update
  240.   #--------------------------------------------------------------------------
  241.   def update
  242.     super
  243.     update_menu_background
  244.     if @command_window.active
  245.       update_command_selection
  246.     elsif @hospital_window.active
  247.       update_hospital_selection
  248.     end
  249.   end
  250.   #--------------------------------------------------------------------------
  251.   # * Update Command Selection
  252.   #--------------------------------------------------------------------------
  253.   def update_command_selection
  254.     @command_window.update
  255.     if Input.trigger?(Input::B)
  256.       Sound.play_cancel
  257.       $scene = Scene_Map.new
  258.     elsif Input.trigger?(Input::C)
  259.       case @command_window.index
  260.       when 0
  261.         Sound.play_decision
  262.         @command_window.active = false
  263.         @hospital_window.active = true
  264.         @hospital_window.index = 0 if @hospital_window.index < 0
  265.       when 1
  266.         if $game_party.gold < $game_party.heal_cost or $game_party.heal_cost == 0
  267.           Sound.play_buzzer
  268.         else
  269.           Sound.play_recovery
  270.           $game_party.lose_gold($game_party.heal_cost)
  271.           @gold_window.refresh
  272.           for actor in $game_party.members
  273.             for state in actor.states
  274.               actor.remove_state(state.id)
  275.             end
  276.             actor.hp = actor.maxhp
  277.             actor.mp = actor.maxmp
  278.           end
  279.           @hospital_window.refresh
  280.           text = sprintf(SSS::HOSPITAL_HELP_TEXT, $game_party.heal_cost)
  281.           text = SSS::HOSPITAL_HELP_HEALTHY if $game_party.heal_cost == 0
  282.           @help_window.set_text(text, 1)
  283.         end
  284.       when 2
  285.         Sound.play_decision
  286.         $scene = Scene_Map.new
  287.       end
  288.     end
  289.   end
  290.   #--------------------------------------------------------------------------
  291.   # * Update Hospital Selection
  292.   #--------------------------------------------------------------------------
  293.   def update_hospital_selection
  294.     @hospital_window.update
  295.     if Input.trigger?(Input::B)
  296.       Sound.play_cancel
  297.       @command_window.active = true
  298.       @hospital_window.active = false
  299.     elsif Input.trigger?(Input::C)
  300.       actor = @hospital_window.actor
  301.       if $game_party.gold < actor.heal_cost or actor.heal_cost == 0
  302.         Sound.play_buzzer
  303.       else
  304.         Sound.play_recovery
  305.         $game_party.lose_gold(actor.heal_cost)
  306.         @gold_window.refresh
  307.         for state in actor.states
  308.           actor.remove_state(state.id)
  309.         end
  310.         actor.hp = actor.maxhp
  311.         actor.mp = actor.maxmp
  312.         @hospital_window.draw_item(@hospital_window.index)
  313.         text = sprintf(SSS::HOSPITAL_HELP_TEXT, $game_party.heal_cost)
  314.         text = SSS::HOSPITAL_HELP_HEALTHY if $game_party.heal_cost == 0
  315.         @help_window.set_text(text, 1)
  316.       end
  317.     end
  318.   end
  319. end
  320.  
  321. #===============================================================================
  322. #
  323. # END OF FILE
  324. #
  325. #===============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement