Advertisement
LiTTleDRAgo

[RGSS/2/3] Cannibalism

Sep 9th, 2013
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 20.79 KB | None | 0 0
  1. #==============================================================================
  2. # Cannibalism
  3. # Version 1.07
  4. # Author : LiTTleDRAgo
  5. #==============================================================================
  6. #------------------------------------------------------------------------------
  7. #  ▼ INTRODUCTION
  8. #------------------------------------------------------------------------------
  9. #  Based on Cannibalism script by Kread-EX for VX Ace
  10. #  This script allows you to create skills to absorb a fraction of a target
  11. #  parameters if it kills it. The gain is permanent.
  12. #
  13. #------------------------------------------------------------------------------
  14. #  ▼ Notetags Instructions
  15. #------------------------------------------------------------------------------
  16. # For VX and VXA user can use notetags at Enemy Tabs to determine percentage
  17. # of enemy stat which will be absorbed
  18. # (notetags configuration will be prioritized):
  19. #
  20. #------------------------------------------------------------------------------
  21. # ** Notetags for Enemies
  22. #------------------------------------------------------------------------------
  23. #
  24. # <cannibal: maxhp,maxsp,str,dex,agi,int>          # for XP
  25. # <cannibal: maxhp,maxmp,atk,def,spi,agi>          # for VX
  26. # <cannibal: maxhp,maxmp,atk,def,mat,mdf,agi,luk>  # for VXA
  27. #    all parameter must be integer
  28. #
  29. #
  30. # <cannibal devour limit: x> # max limit for devouring that enemy
  31. # <cannibal static>          # use static gain instead of percentage?
  32. #    x must be integer
  33. #
  34. # <cannibal devour limit: x> is necessary to activate the script
  35. #
  36. # This tags below only have meaning if EXCLUDE_IF_DEVOUR is false
  37. #
  38. # <cannibal exclude exp>   # exclude exp if enemy is devoured
  39. # <cannibal exclude gold>  # exclude gold if enemy is devoured
  40. # <cannibal exclude item>  # exclude drop item if enemy is devoured
  41. #
  42. #------------------------------------------------------------------------------
  43. # ** Notetags for Skills
  44. #------------------------------------------------------------------------------
  45. #
  46. #  <cannibal devour skill> # Sets the skill as devour skill
  47. #
  48. #==============================================================================
  49. module LiTTleDRAgo
  50.  
  51. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  52. #                          BEGIN CONFIGURATION
  53. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  54.   CANNIBALIZE = {  # do not delete
  55.   #----------------------------------------------------------------------------
  56.   # Configure enemy ID here, you can set the percentage of enemy stat which
  57.   # will be absorbed,
  58.   # - If you want to use static gain instead of percentage,
  59.   #   change :static into true
  60.   # - For lazy user who wants to set every unconfigured enemy, use 0 as ID.
  61.   # - You can disable devouring some enemies (such as boss) by setting the
  62.   #   :limit to 0
  63.   #----------------------------------------------------------------------------
  64.   #
  65.   #----------------------------------------------------------------------------
  66.   # Delete if you're not using XP
  67.     # For XP (8 args)
  68.     :id    => [:maxhp, :maxsp, :str, :dex, :agi, :int, :limit, :static],
  69.       1    => [    -2,      1,   -1,    0,    0,    1,     15,  true],
  70.   #----------------------------------------------------------------------------
  71.   #----------------------------------------------------------------------------
  72.   # Delete if you're not using VX
  73.     # For VX (8 args)
  74.     :id    => [:maxhp, :maxmp, :atk, :def, :spi, :agi, :limit, :static],
  75.   #   1    => [     0,      0,   -1,    0,    1,    0,     15,  true],
  76.   #   2    => [     2,     -3,    0,    0,    0,    0,     15,  true],
  77.   #   3    => [    -1,      0,    2,    0,    0,    0,     15,  true],
  78.   #----------------------------------------------------------------------------
  79.   #----------------------------------------------------------------------------
  80.   # Just in case, added support for VXA, although I recommend you to get
  81.   # Kread-Ex's version instead.
  82.   # Delete if you're not using VXA
  83.     # For VXA (10 args)
  84.     :id =>[:maxhp, :maxmp, :atk, :def, :mat, :mdf, :agi, :luk, :limit,:static],
  85.   #   0 =>[     0,      0,     0,   0,    0,    0,    0,    0,    999,   true],
  86.   #   4 =>[    10,      0,     2,  -5,    0,    0,    4,    5,     14,   true],
  87.   #----------------------------------------------------------------------------
  88.   #----------------------------------------------------------------------------
  89.   #----------------------------------------------------------------------------
  90.      
  91.       } # do not delete
  92.  
  93.   #----------------------------------------------------------------------------
  94.   # Below you can set which skills that devour the enemy when enemy is dead
  95.   # Enemy will be absorbed only if you kill it with devour skills
  96.   DEVOUR_SKILL = [57]
  97.   #----------------------------------------------------------------------------
  98.  
  99.   #----------------------------------------------------------------------------
  100.   # This feature maybe not working for some CBS'es or some battle addon
  101.   # (ex: Multi Drop, XAS)
  102.   #
  103.   # EXCLUDE_IF_DEVOUR  = [:exp, :gold, :item]
  104.   # :exp  = Enemy will not give exp if devoured?
  105.   # :gold = Enemy will not drop gold if devoured?
  106.   # :item = Enemy will not drop items if devoured?
  107.   EXCLUDE_IF_DEVOUR    = [false, false, false]
  108.   #----------------------------------------------------------------------------
  109.  
  110.   #----------------------------------------------------------------------------
  111.   # Text Related function
  112.   VOCAB_DEVOURED_PLUS = "absorbs"
  113.  
  114.   VOCAB_DEVOURED_MIN  = "loses"
  115.   #----------------------------------------------------------------------------
  116.  
  117. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  118. #                          END CONFIGURATION
  119. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  120.   #----------------------------------------------------------------------------
  121.   # Don't Edit  
  122.   CANNIBAL_TAGS = {
  123.    :cannibal      => /<cannibal:(.+?)\>/i,
  124.    :devour_limit  => /<cannibal[-_ ]?devour[-_ ]?limit:\s*([-]?\d+)\s*>/i,
  125.    :devour_skill  => /<cannibal[-_ ]?devour[-_ ]?skill>/i,
  126.    :exclude_exp   => /<cannibal[-_ ]?exclude[-_ ]?exp>/i,
  127.    :exclude_gold  => /<cannibal[-_ ]?exclude[-_ ]?gold>/i,
  128.    :exclude_item  => /<cannibal[-_ ]?exclude[-_ ]?item>/i,
  129.    :static        => /<cannibal[-_ ]?static>/i,
  130.    }
  131.   #----------------------------------------------------------------------------
  132.  
  133. end
  134.  
  135. ($imported||={})[:drg_cannibalism_xp] = 1.07
  136.  
  137. core_engine = "This script needs Drago - Core Engine ver 1.55 or above"
  138. ($imported[:drg_core_engine] || 0) >= 1.55 || raise(core_engine)
  139. #==============================================================================
  140. # ** Game_Actor
  141. #------------------------------------------------------------------------------
  142. #  This class handles the actor. It's used within the Game_Actors class
  143. #  ($game_actors) and refers to the Game_Party class ($game_party).
  144. #==============================================================================
  145. class Game_Actor < Game_Battler
  146.   #--------------------------------------------------------------------------
  147.   # ● Public Instance Variables
  148.   #--------------------------------------------------------------------------
  149.   attr_sec_accessor :cannibal_bonus, :devoured,  "Array.new(10, 0)"
  150.   #--------------------------------------------------------------------------
  151.   # ● Object Initialize
  152.   #--------------------------------------------------------------------------
  153.   define_pre_alias(:setup) { @cannibal_bonus, @devoured = Array.new(10,0), []}
  154.   #--------------------------------------------------------------------------
  155.   # ● Total Devour <for RMVXA>
  156.   # For XP users, you can use this feature if you place Wecoc's VX Ace Formula
  157.   # (http://forum.chaos-project.com/index.php/topic,14523.0.html)
  158.   #
  159.   # Note : If you want to add this variable into damage formula, do it like
  160.   #        this example (will throws an error if enemy is using it).
  161.   #        a.atk + a.mat * a.total_devour(b.enemy_id) - b.def - b.mdf
  162.   #        a.atk + a.mat * a.total_devour - b.def - b.mdf
  163.   #
  164.   # Using total_devour without any args will result to sum all of the enemy
  165.   # devour count.
  166.   #--------------------------------------------------------------------------
  167.   def total_devour(*id)
  168.     if id.size == 0
  169.       array = devoured.compact
  170.     else
  171.       array = id.collect {|e| e.is_a?(Range) ? e.to_a : e }.flatten
  172.       array.collect! {|e| devoured[e.to_i] ||= 0 }
  173.     end
  174.     array.sum
  175.   end
  176.   #--------------------------------------------------------------------------
  177.   # ● Purge Devour <for RMVXA>
  178.   # For XP users, you can use this feature if you place Wecoc's VX Ace Formula
  179.   # (http://forum.chaos-project.com/index.php/topic,14523.0.html)
  180.   #
  181.   # Similar to total_devour. However, once this syntax is used, it will reset
  182.   # devour count back to 0.
  183.   # If you played Final Fantasy XII, think of Shemhazai's Ultimate Skill,
  184.   # Flame Purge which uses total devoured souls as damage multiplier. Once
  185.   # skill is used, the count resets back to 0.
  186.   # Example : (will throws an error if enemy is using it)
  187.   #        a.atk + a.mat * a.purge_devour(b.enemy_id) - b.def - b.mdf
  188.   #        a.atk + a.mat * a.purge_devour - b.def - b.mdf
  189.   #
  190.   # Using purge_devour without any args will result to sum all of the enemy
  191.   # devour count, and then reset all the devour count to 0.
  192.   #--------------------------------------------------------------------------
  193.   def purge_devour(*id)
  194.     result = total_devour(*id)
  195.     if id.size == 0
  196.       devoured.clean
  197.     else
  198.       array = id.collect {|e| e.is_a?(Range) ? e.to_a : e }.flatten
  199.       array.each {|e| devoured[e.to_i] = nil }
  200.     end
  201.     return result
  202.   end
  203.   #--------------------------------------------------------------------------
  204.   # ● Returns the parameter bonuses
  205.   #--------------------------------------------------------------------------
  206.   if LiTTleDRAgo::VXA
  207.     define_third_method(:param,:drg_cannibal_param) do |param_id|
  208.       drg_cannibal_param(param_id) + cannibal_bonus[param_id]
  209.     end
  210.   else
  211.     (LiTTleDRAgo::VX ? [:maxhp,:maxmp,:atk,:def,:spi,:agi] :
  212.              [:maxhp,:maxsp,:str,:dex,:agi,:int]).each_with_index do |m,i|
  213.       define_third_method(:"#{m}",:"drg190_#{m}") do |*args|
  214.         stat, ex = cannibal_bonus, [0,1].include?(i) ? 9999 : 999
  215.         (send(:"drg190_#{m}",*args) + stat[i]).clamp(1, ex)
  216.       end
  217.     end
  218.   end
  219. end
  220. #==============================================================================
  221. # ** Game_Enemy
  222. #------------------------------------------------------------------------------
  223. #  This class handles enemies. It's used within the Game_Troop class
  224. #  ($game_troop).
  225. #==============================================================================
  226. class Game_Enemy < Game_Battler
  227.   #--------------------------------------------------------------------------
  228.   # ● Class Variables
  229.   #--------------------------------------------------------------------------
  230.   @@prob = method_defined?(:treasure_prob) ? :treasure_prob : :drop_item_rate
  231.   #--------------------------------------------------------------------------
  232.   # ● Public Instance Variables
  233.   #--------------------------------------------------------------------------
  234.   attr_reader     :enemy_id
  235.   attr_sec_reader :devour_limit,  -1
  236.   attr_sec_reader :cannibal_tags, 'LiTTleDRAgo::CANNIBAL_TAGS'
  237.   #--------------------------------------------------------------------------
  238.   # ● Alias Listing
  239.   #--------------------------------------------------------------------------
  240.   alias_sec_method :drg_cannibal_gold, :gold
  241.   alias_sec_method :drg_cannibal_exp,  :exp
  242.   #--------------------------------------------------------------------------
  243.   # ● Object Initialize
  244.   #--------------------------------------------------------------------------
  245.   define_post_alias(:initialize) { load_cannibal_initialize }
  246.   #--------------------------------------------------------------------------
  247.   # ● Gold, Exp
  248.   #--------------------------------------------------------------------------
  249.   define_method(:gold) { |*args|  @gold_replace || drg_cannibal_gold(*args) }
  250.   define_method(:exp)  { |*args|  @exp_replace  || drg_cannibal_exp(*args)  }
  251.   #--------------------------------------------------------------------------
  252.   # * Get Drop Item
  253.   #--------------------------------------------------------------------------
  254.   [:drop_item1,:drop_item2,:"#{@@prob}"].each do |method|
  255.     if method_defined?(:"#{method}")
  256.       define_third_method(:"#{method}",:":drg_cannibal_#{method}") do |*args|
  257.         result = send(:":drg_cannibal_#{method}", *args)
  258.         result.kind = 0 if @drop_replace && result.respond_to?(:kind)
  259.         result = 0      if @drop_replace && result.is_a?(Numeric)
  260.         result
  261.       end
  262.     end
  263.   end
  264.   #--------------------------------------------------------------------------
  265.   # ● load_cannibal_initialize
  266.   #--------------------------------------------------------------------------
  267.   def load_cannibal_initialize
  268.     @devour_ratio_p = Array.new(10, 0)
  269.     @gold_replace = @exp_replace = @drop_replace = nil
  270.     cannibalize   = LiTTleDRAgo::CANNIBALIZE[@enemy_id]
  271.     cannibalize ||= LiTTleDRAgo::CANNIBALIZE[0]
  272.     return if cannibalize.nil?
  273.     param_array = (0..5).to_a
  274.     param_array = (0..7).to_a if LiTTleDRAgo::VXA
  275.     param_array.each do |i|
  276.       if cannibalize[i] != 0 && cannibalize[i].is_a?(Numeric)
  277.         @devour_ratio_p[i] = cannibalize[i]
  278.       end
  279.     end
  280.     note_array = "#{enemy.get_note[cannibal_tags[:cannibal]]}".get_ints
  281.     note_array.each_with_index do |note,index|
  282.       @devour_ratio_p[index] = note if note.is_a?(Numeric)
  283.     end
  284.     @devour_limit = cannibalize[param_array.size] || -1
  285.     @static_gain  = cannibalize[param_array.size + 1] == true
  286.     @devour_limit = $1.to_i  if enemy.get_note =~ cannibal_tags[:devour_limit]
  287.     @static_gain  = true if enemy.get_note =~ cannibal_tags[:static]
  288.   end
  289.   #--------------------------------------------------------------------------
  290.   # ● Determine if the enemy can be eaten
  291.   #--------------------------------------------------------------------------
  292.   def can_devour?
  293.     devour_limit > 0
  294.   end
  295.   #--------------------------------------------------------------------------
  296.   # ● Returns the parameter gain upon eating
  297.   #--------------------------------------------------------------------------
  298.   def devour_param_bonus(param_id)
  299.     if !@static_gain
  300.       if @devour_ratio.not.nil?
  301.         return ((param_base(param_id) * @devour_ratio) / 100.00).round
  302.       end
  303.       return ((param_base(param_id) * @devour_ratio_p[param_id])/100.00).round
  304.     else
  305.       return @devour_ratio if @devour_ratio.not.nil?
  306.       return @devour_ratio_p[param_id]
  307.     end
  308.   end
  309. end
  310.  
  311. #==============================================================================
  312. # ** Game_Battler
  313. #------------------------------------------------------------------------------
  314. #  This class deals with battlers. It's used as a superclass for the Game_Actor
  315. #  and Game_Enemy classes.
  316. #==============================================================================
  317. Klass = LiTTleDRAgo::VXA ? Scene_Battle : Game_Battler
  318. class Klass
  319.   #--------------------------------------------------------------------------
  320.   # ● Public Instance Variables
  321.   #--------------------------------------------------------------------------
  322.   attr_sec_reader :cannibal_tags, 'LiTTleDRAgo::CANNIBAL_TAGS'
  323.   #--------------------------------------------------------------------------
  324.   # ● Param Base
  325.   #--------------------------------------------------------------------------
  326.   define_sec_method(:param_base) do |index|
  327.     vx = LiTTleDRAgo::VX
  328.     return base_maxhp                   if index == 0
  329.     return vx ? base_maxmp : base_maxsp if index == 1
  330.     return vx ? base_atk   : base_str   if index == 2
  331.     return vx ? base_def   : base_dex   if index == 3
  332.     return vx ? base_spi   : base_agi   if index == 4
  333.     return vx ? base_agi   : base_int   if index == 5
  334.     return 0
  335.   end
  336.   #--------------------------------------------------------------------------
  337.   # * Apply Skill Effects
  338.   #--------------------------------------------------------------------------
  339.   define_third_method(LiTTleDRAgo::VXA ? :apply_item_effects : :skill_effect,
  340.                       :drg_sb_aie) do |user, skill, *args|
  341.     result = drg_sb_aie(user, skill, *args)
  342.     devour(user, skill)
  343.     return result
  344.   end
  345.   #--------------------------------------------------------------------------
  346.   # ● Skill can Devour
  347.   #--------------------------------------------------------------------------
  348.   def devour_skill?(skill)
  349.     result = LiTTleDRAgo::DEVOUR_SKILL.include?(skill.id)
  350.     result ||= skill.get_note =~ cannibal_tags[:devour_skill]
  351.     return result
  352.   end
  353.   #--------------------------------------------------------------------------
  354.   # ● Devours the enemy
  355.   #--------------------------------------------------------------------------
  356.   def devour(user, item)
  357.     target, user, devour_ok = self, user, false
  358.     target, user = user, @subject if LiTTleDRAgo::VXA
  359.     if item.is_a?(RPG::Skill) && devour_skill?(item) && user.is_a?(Game_Actor)
  360.       if target.is_a?(Game_Enemy) && target.can_devour? && target.dead?
  361.         if (user.devoured[target.enemy_id] || 0) < target.devour_limit
  362.            exp_is_gone  = LiTTleDRAgo::EXCLUDE_IF_DEVOUR[0]
  363.            gold_is_gone = LiTTleDRAgo::EXCLUDE_IF_DEVOUR[1]
  364.            item_is_gone = LiTTleDRAgo::EXCLUDE_IF_DEVOUR[2]
  365.            gold_is_gone |= target.get_note=~target.cannibal_tags[:exclude_gold]
  366.            exp_is_gone  |= target.get_note=~target.cannibal_tags[:exclude_exp]
  367.            item_is_gone |= target.get_note=~target.cannibal_tags[:exclude_item]
  368.            target.instance_variable_set(:@gold_replace, 0) if gold_is_gone
  369.            target.instance_variable_set(:@exp_replace, 0)  if exp_is_gone
  370.            target.instance_variable_set(:@drop_replace, 0) if item_is_gone
  371.           (0..7).each do |i|
  372.             n = target.devour_param_bonus(i)
  373.             user.cannibal_bonus[i] += n
  374.             if n != 0
  375.               if n > 0
  376.                 text  = "#{user.name} #{LiTTleDRAgo::VOCAB_DEVOURED_PLUS} #{n}"
  377.                 text += " #{$data_system.words.params[i]}."
  378.               else
  379.                 text  = "#{user.name} #{LiTTleDRAgo::VOCAB_DEVOURED_MIN} #{n}"
  380.                 text += " #{$data_system.words.params[i]}."
  381.               end
  382.               devour_ok = true
  383.               if LiTTleDRAgo.scene.is_a?(Scene_Battle) && !LiTTleDRAgo::VXA
  384.                 LiTTleDRAgo.scene.devour_logs << text
  385.               else
  386.                 devour_log(text)
  387.               end
  388.             end
  389.           end
  390.           user.hp = user.hp
  391.           user.respond_to?(:sp) ? (user.sp = user.sp) : (user.mp = user.mp)
  392.           user.devoured[target.enemy_id] ||= 0
  393.           user.devoured[target.enemy_id] += 1 if devour_ok
  394.         end
  395.       end
  396.     end
  397.   end
  398.   #--------------------------------------------------------------------------
  399.   # ● Devour Log
  400.   #--------------------------------------------------------------------------
  401.   def devour_log(text='')
  402.     res = [300,64]
  403.     @devour_window = Window_Help.new
  404.     @devour_window.visible = false
  405.     @devour_window.width = res.at(0)
  406.     @devour_window.height = res.at(1)
  407.     @devour_window.center_window
  408.     @devour_window.contents = Bitmap.new(res.at(0)-32, res.at(1)-32)
  409.     @devour_window.visible = true
  410.     @devour_window.draw_text(0,0,@devour_window.contents.width,
  411.                                  @devour_window.line_height,text,1)
  412.     10.times { [Graphics,@devour_window].update }
  413.     Graphics.wait_for_input
  414.     $game_system.se_play($data_system.decision_se)
  415.     @devour_window.dispose        
  416.     @devour_window = nil
  417.     10.times { [Graphics,Input].update }
  418.   end    
  419. end
  420.  
  421. #==============================================================================
  422. # ** Scene_Battle
  423. #------------------------------------------------------------------------------
  424. #  This class performs battle screen processing.
  425. #==============================================================================
  426. class Scene_Battle
  427.   #--------------------------------------------------------------------------
  428.   # ● Public Instance Variables
  429.   #--------------------------------------------------------------------------
  430.   attr_sec_reader :devour_logs, "Array.new"
  431.   #--------------------------------------------------------------------------
  432.   # ● display_action_effects
  433.   #--------------------------------------------------------------------------
  434.   define_post_alias(LiTTleDRAgo::VX ? :display_action_effects :
  435.                     :update_phase4_step5) do
  436.     devour_logs.each {|text| @active_battler.devour_log(text)}
  437.     devour_logs.clear
  438.   end
  439. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement