SHARE
TWEET

CardGame Draw/Play Effects v1.00

PencilCase27 Oct 18th, 2014 (edited) 1,108 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  2. #                           CARDGAME ON DRAW/PLAY EFFECTS
  3. #                               Author: pencilcase27
  4. #                               Version:       v1.00
  5. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  6. #
  7. #                                  Description
  8. #
  9. # This addon allows you to create weapon, armors and stats that heal or damage
  10. # the users hp, mp or tp whenever he uses or draws a card. Actors cannot die
  11. # through this effect.
  12. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  13. #
  14. #                                    Notetags
  15. #
  16. # <on card play: effect_name>
  17. # <on card draw: effect_name>
  18. # Adds the darw or play effects to your card. To define card effects, go to
  19. # "Options" -> EFFECTS and create a new effect.
  20.  
  21. # Example:
  22. # <on card draw: vampiric_sword_1>
  23. # <on card play: vampiric_sword_2>
  24. # Whenever an actor with this equipment draws a card, he heals 25 mp and tp, but
  25. # when he plays a card, he looses 50 hp.
  26. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  27.  
  28. module PC27
  29.   module CG
  30.   #---------------------------------------------------------------------------
  31.   #                                    Options
  32.   #---------------------------------------------------------------------------
  33.    # SE played whenever the effect takes place. If an effect heals one
  34.    # parameter but damages another, both sounds are played. ["name", vol, pitch]
  35.    LOOSE_SE = ["Absorb1", 100, 100]
  36.    GAIN_SE  = ["Absorb2", 100, 100]
  37.    
  38.    # Effect names
  39.    EFFECTS  = {
  40.    
  41.    #  "effect_name"      => { :hp => hp_value,
  42.    #                          :mp => mp_value,
  43.    #                          :tp => tp_value, },
  44.    
  45.       "vampiric_sword_1" => { :hp =>   0,
  46.                               :mp => +25,
  47.                               :tp => +25, },
  48.                              
  49.       "vampiric_sword_2" => { :hp => -50,
  50.                               :mp =>   0,
  51.                               :tp =>   0, },
  52.                              
  53.               } #do not remove this
  54.   #---------------------------------------------------------------------------
  55.   #                                  End Options
  56.   #---------------------------------------------------------------------------
  57.   end
  58. end
  59. #============================================================================
  60. # BaseItem
  61. #============================================================================
  62. class RPG::BaseItem
  63.   #--------------------------------------------------------------------------
  64.   # * Load on card draw notetags
  65.   #--------------------------------------------------------------------------
  66.   def on_card_draw
  67.     return @on_card_draw if @on_card_draw
  68.     self.note.split(/[\r\n]+/).each { |line|
  69.       if /<on[ -_]card[ -_]draw: +(?<ocd>.+)>/i =~ line
  70.         @on_card_draw = PC27::CG::EFFECTS[ocd]
  71.       end
  72.     }
  73.     @on_card_draw = 0 unless @on_card_draw
  74.     return @on_card_draw
  75.   end
  76.   #--------------------------------------------------------------------------
  77.   # * Load on card play notetags
  78.   #--------------------------------------------------------------------------
  79.   def on_card_play
  80.     return @on_card_play if @on_card_play
  81.     self.note.split(/[\r\n]+/).each { |line|
  82.       if /<on[ -_]card[ -_]play: +(?<ocp>.+)>/i =~ line
  83.         @on_card_play = PC27::CG::EFFECTS[ocp]
  84.       end
  85.     }
  86.     @on_card_play = 0 unless @on_card_play
  87.     return @on_card_play
  88.   end
  89. end
  90. #============================================================================
  91. # Game_Actor
  92. #============================================================================
  93. class Game_Actor < Game_Battler
  94.   #--------------------------------------------------------------------------
  95.   # * Alias method draw cards
  96.   #--------------------------------------------------------------------------
  97.   alias draw_cards_state_addon draw_cards
  98.   def draw_cards(n, show = true, sound = true)
  99.     draw_cards_state_addon(n, show, sound)
  100.     change = draw_effect_check_all(n)
  101.     evaluate_on_card_draw_and_play(change)
  102.   end
  103.   #--------------------------------------------------------------------------
  104.   # * Evaluate card draw and play effects
  105.   #--------------------------------------------------------------------------
  106.   def evaluate_on_card_draw_and_play(change)
  107.     unless change[:hp] == 0
  108.       @hp = cage_number(@hp + change[:hp], 1, mhp)
  109.       change[:hp] > 0 ? RPG::SE.new(*PC27::CG::GAIN_SE).play : RPG::SE.new(*PC27::CG::LOOSE_SE).play
  110.     end
  111.     unless change[:mp] == 0
  112.       @mp = cage_number(@mp + change[:mp], 0, mmp)
  113.       change[:mp] > 0 ? RPG::SE.new(*PC27::CG::GAIN_SE).play : RPG::SE.new(*PC27::CG::LOOSE_SE).play
  114.     end
  115.     unless change[:tp] == 0
  116.       @tp = cage_number(@tp + change[:tp], 0, max_tp)
  117.       change[:tp] > 0 ? RPG::SE.new(*PC27::CG::GAIN_SE).play : RPG::SE.new(*PC27::CG::LOOSE_SE).play
  118.     end
  119.   end
  120.   #--------------------------------------------------------------------------
  121.   # * Check for on card draw effects
  122.   #--------------------------------------------------------------------------
  123.   def draw_effect_check_all(n)
  124.     change = {:hp => 0, :mp => 0, :tp => 0}
  125.     # --- check states ---
  126.     for id in @states
  127.       if $data_states[id].on_card_draw != 0
  128.         hash = $data_states[id].on_card_draw
  129.         change[:hp] += hash[:hp] * n
  130.         change[:mp] += hash[:mp] * n
  131.         change[:tp] += hash[:tp] * n
  132.       end
  133.     end
  134.     # --- check armor ---
  135.     for armor in self.armors
  136.       if armor.on_card_draw != 0
  137.         hash = armor.on_card_draw
  138.         change[:hp] += hash[:hp] * n
  139.         change[:mp] += hash[:mp] * n
  140.         change[:tp] += hash[:tp] * n
  141.       end
  142.     end
  143.     # --- check weapons ---
  144.     for weapon in self.weapons
  145.       if weapon.on_card_draw != 0
  146.         hash = weapon.on_card_draw
  147.         change[:hp] += hash[:hp] * n
  148.         change[:mp] += hash[:mp] * n
  149.         change[:tp] += hash[:tp] * n
  150.       end
  151.     end
  152.     return change
  153.   end
  154.   #--------------------------------------------------------------------------
  155.   # * Evaluates play effects from scene battle
  156.   #--------------------------------------------------------------------------
  157.   def evaluate_on_card_play
  158.     change = play_effect_check_all
  159.     evaluate_on_card_draw_and_play(change)
  160.   end
  161.   #--------------------------------------------------------------------------
  162.   # * Check for on card play effects
  163.   #--------------------------------------------------------------------------
  164.   def play_effect_check_all
  165.     change = {:hp => 0, :mp => 0, :tp => 0}
  166.     # --- check states ---
  167.     for id in @states
  168.       if $data_states[id].on_card_play != 0
  169.         hash = $data_states[id].on_card_play
  170.         change[:hp] += hash[:hp]
  171.         change[:mp] += hash[:mp]
  172.         change[:tp] += hash[:tp]
  173.       end
  174.     end
  175.     # --- check armor ---
  176.     for armor in self.armors
  177.       if armor.on_card_play != 0
  178.         hash = armor.on_card_play
  179.         change[:hp] += hash[:hp]
  180.         change[:mp] += hash[:mp]
  181.         change[:tp] += hash[:tp]
  182.       end
  183.     end
  184.     # --- check weapons ---
  185.     for weapon in self.weapons
  186.       if weapon.on_card_play != 0
  187.         hash = weapon.on_card_play
  188.         change[:hp] += hash[:hp]
  189.         change[:mp] += hash[:mp]
  190.         change[:tp] += hash[:tp]
  191.       end
  192.     end
  193.     return change
  194.   end
  195.   #--------------------------------------------------------------------------
  196.   # * Method to cage a number between two values
  197.   #--------------------------------------------------------------------------
  198.   def cage_number(number, min, max)
  199.     x = number
  200.     x = [x, min].max
  201.     x = [x, max].min
  202.     return x
  203.   end
  204. end
  205. #============================================================================
  206. # Scene_Battle
  207. #============================================================================
  208. class Scene_Battle
  209.   #--------------------------------------------------------------------------
  210.   # * Alias Method evaluate item
  211.   #--------------------------------------------------------------------------
  212.   alias evaluate_item_state_addon evaluate_item
  213.   def evaluate_item(actor, item)
  214.     evaluate_item_state_addon(actor, item)
  215.     if item.id != actor.attack_skill_id && item.id != actor.guard_skill_id
  216.       actor.evaluate_on_card_play
  217.     end
  218.   end
  219. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top