Advertisement
roninator2

Kid Friendly Basic Quest - Spell Groups

Dec 14th, 2024
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 11.50 KB | None | 0 0
  1. # ╔═════════════════════════════════════╦════════════════════╗
  2. # ║ Title: KFBQ Spell Groups & Uses     ║  Version: 1.00     ║
  3. # ║ Author: Roninator2                  ║                    ║
  4. # ╠═════════════════════════════════════╬════════════════════╣
  5. # ║ Function:                           ║   Date Created     ║
  6. # ║                                     ╠════════════════════╣
  7. # ║   FFMQ Style spell use              ║    09 Mar 2023     ║
  8. # ╚═════════════════════════════════════╩════════════════════╝
  9. # ╔══════════════════════════════════════════════════════════╗
  10. # ║ Instructions:                                            ║
  11. # ║                                                          ║
  12. # ║  Set the note tag on spells to indicate what group       ║
  13. # ║  the spell belongs in  <spell group: white>              ║
  14. # ║      Other options include black and wizard              ║
  15. # ║  Set the note tag on the actors to indicate the rate     ║
  16. # ║  at which the player will gain new spell uses            ║
  17. # ║      <spell growth: white, 5, 1, 2>                      ║
  18. # ║  Numbers - 5 starting points, 1 gained every 2 levels    ║
  19. # ║  So <spell growth: black, 2, 1, 3>                       ║
  20. # ║     is start with 2 and gain 1 every 3 levels            ║
  21. # ╚══════════════════════════════════════════════════════════╝
  22. # ╔══════════════════════════════════════════════════════════╗
  23. # ║ Terms of use:                                            ║
  24. # ║ Free for all uses in RPG Maker - Except nudity           ║
  25. # ╚══════════════════════════════════════════════════════════╝
  26. #==============================================================================
  27. # * Module R2 Spell
  28. #==============================================================================
  29.  
  30. module R2_Spell_Group
  31.   # Skill notetag
  32.   # <spell group: white>
  33.   SpellGroup = /<spell[ -_]group:[ -_](\w*)>/i
  34.  
  35.   # Actor notetag
  36.   # <spell growth: spell group, starting number, gain amount, every # levels)
  37.   # <spell growth:    white,           3,            1,            3)
  38.   # <spell growth: white, 3, 1, 1)
  39.   # <spell growth: black, 1, 1, 2)
  40.   # <spell growth: wizard, 0, 1, 4)
  41.  
  42.   # non gaining characters can simply be set to 0 for the gain amount
  43.   # <spell growth: white, 5, 0, 0)
  44.   SpellGrowth = /<spell[ -_]growth:[ ](\w*),[ -_](\d+),[ -_](\d+),[ -_](\d+)>/i
  45. end
  46.  
  47. #==============================================================================
  48. # * DataManager
  49. #==============================================================================
  50. module DataManager
  51.   #--------------------------------------------------------------------------
  52.   # alias method: load_database
  53.   #--------------------------------------------------------------------------
  54.   class <<self; alias load_database_spellgroup load_database; end
  55.   def self.load_database
  56.     load_database_spellgroup
  57.     initialize_spellgroup
  58.   end
  59.   #--------------------------------------------------------------------------
  60.   # new method: initialize_spellgroup
  61.   #--------------------------------------------------------------------------
  62.   def self.initialize_spellgroup
  63.     groups = [$data_actors, $data_skills]
  64.     for group in groups
  65.       for obj in group
  66.         next if obj.nil?
  67.           obj.initialize_spellgroup
  68.       end
  69.     end
  70.   end
  71. end
  72.  
  73. #==============================================================================
  74. # * RPG::BaseItem
  75. #==============================================================================
  76. class RPG::BaseItem
  77.   attr_reader :spellgroup
  78.   attr_reader :actorspells
  79.   attr_accessor :actorwhitecount
  80.   attr_accessor :actorblackcount
  81.   attr_accessor :actorwizardcount
  82.   #--------------------------------------------------------------------------
  83.   # new method: initialize_spellgroup
  84.   #--------------------------------------------------------------------------
  85.   def initialize_spellgroup
  86.     @spellgroup = :none
  87.     @actorspells = {}
  88.     @actorwhitecount = 0
  89.     @actorblackcount = 0
  90.     @actorwizardcount = 0
  91.     self.note.split(/[\r\n]+/).each { |line|
  92.       case line
  93.       when R2_Spell_Group::SpellGroup
  94.         @spellgroup = $1.to_sym
  95.       when R2_Spell_Group::SpellGrowth
  96.         @actorspells[$1.to_sym] = [$2.to_i, $3.to_i, $4.to_i]
  97.         case $1.to_sym.downcase
  98.         when :white
  99.           @actorwhitecount = $2.to_i
  100.         when :black
  101.           @actorblackcount = $2.to_i
  102.         when :wizard
  103.           @actorwizardcount = $2.to_i
  104.         end
  105.       end
  106.     }
  107.   end
  108.   #--------------------------------------------------------------------------
  109.   # new method: is_spellgroup?
  110.   #--------------------------------------------------------------------------
  111.   def is_spellgroup?
  112.     @spellgroup != :none
  113.   end
  114. end
  115.  
  116. #==============================================================================
  117. # * Game_BattlerBase
  118. #==============================================================================
  119. class Game_BattlerBase
  120.   #--------------------------------------------------------------------------
  121.   # * Determine if Cost of Using Skill Can Be Paid
  122.   #--------------------------------------------------------------------------
  123.   def skill_cost_payable?(skill)
  124.     if self.is_a?(Game_Enemy)
  125.       return true
  126.     elsif skill.id == 0 || 1
  127.       return true
  128.     else
  129.       spellgrp = skill.spellgroup
  130.       case spellgrp
  131.       when :white
  132.         return true if self.whitespells > 0
  133.       when :black
  134.         return true if self.blackspells > 0
  135.       when :wizard
  136.         return true if self.wizardspells > 0
  137.       else
  138.         return false
  139.       end
  140.     end
  141.   end
  142.   #--------------------------------------------------------------------------
  143.   # * Pay Cost of Using Skill
  144.   #--------------------------------------------------------------------------
  145.   def pay_skill_cost(skill)
  146.     if self.is_a?(Game_Enemy)
  147.       return
  148.     else
  149.       spellgrp = skill.spellgroup
  150.       self.pay_spells(spellgrp)
  151.     end
  152.   end
  153. end
  154.  
  155. #==============================================================================
  156. # * Game_Battler
  157. #==============================================================================
  158. class Game_Battler < Game_BattlerBase
  159.   #--------------------------------------------------------------------------
  160.   # * Determine if Cost of Using Skill Can Be Paid
  161.   #--------------------------------------------------------------------------
  162.   def skill_cost_payable?(skill)
  163.     if self.is_a?(Game_Actor)
  164.       case skill.stype_id
  165.       when 1
  166.         return true if self.whitespells > 0
  167.         return false
  168.       when 2
  169.         return true if self.blackspells > 0
  170.         return false
  171.       when 3
  172.         return true if self.wizardspells > 0
  173.         return false
  174.       else
  175.         return true
  176.       end
  177.     else
  178.       tp >= skill_tp_cost(skill) && mp >= skill_mp_cost(skill)
  179.     end
  180.   end
  181.   #--------------------------------------------------------------------------
  182.   # * Pay Cost of Using Skill
  183.   #--------------------------------------------------------------------------
  184.   def pay_skill_cost(skill)
  185.     if self.is_a?(Game_Actor)
  186.       case skill.stype_id
  187.       when 1
  188.         self.pay_spells(:white)
  189.       when 2
  190.         self.pay_spells(:black)
  191.       when 3
  192.         self.pay_spells(:wizard)
  193.       else
  194.         self.mp -= skill_mp_cost(skill)
  195.         self.tp -= skill_tp_cost(skill)
  196.       end
  197.     else
  198.       self.mp -= skill_mp_cost(skill)
  199.       self.tp -= skill_tp_cost(skill)
  200.     end
  201.   end
  202. end
  203.  
  204. #==============================================================================
  205. # ** Game_Actor
  206. #==============================================================================
  207. class Game_Actor < Game_Battler
  208.   #--------------------------------------------------------------------------
  209.   # * Public Instance Variables
  210.   #--------------------------------------------------------------------------
  211.   attr_reader :actorspells
  212.   attr_reader :whitespells
  213.   attr_reader :blackspells
  214.   attr_reader :wizardspells
  215.   #--------------------------------------------------------------------------
  216.   # * Alias Actor Initialize
  217.   #--------------------------------------------------------------------------
  218.   alias r2_actor_setup  setup
  219.   def setup(i)
  220.     r2_actor_setup(i)
  221.     add_spells
  222.   end
  223.   #--------------------------------------------------------------------------
  224.   # * Add Actor Spell Counts
  225.   #--------------------------------------------------------------------------
  226.   def add_spells
  227.     @actorspells = actor.actorspells
  228.     @whitespells = actor.actorwhitecount
  229.     @blackspells = actor.actorblackcount
  230.     @wizardspells = actor.actorwizardcount
  231.   end
  232.   #--------------------------------------------------------------------------
  233.   # * Add Actor Spell Counts
  234.   #--------------------------------------------------------------------------
  235.   def pay_spells(type)
  236.     case type
  237.     when :white
  238.       @whitespells -= 1
  239.     when :black
  240.       @blackspells -= 1
  241.     when :wizard
  242.       @wizardspells -= 0
  243.     end
  244.   end
  245.   #--------------------------------------------------------------------------
  246.   # * Recover All
  247.   #--------------------------------------------------------------------------
  248.   alias r2_actor_spells_recover recover_all
  249.   def recover_all
  250.     r2_actor_spells_recover
  251.     refresh_spells
  252.   end
  253.   #--------------------------------------------------------------------------
  254.   # * Add Actor Spell Counts
  255.   #--------------------------------------------------------------------------
  256.   def refresh_spells
  257.     @whitespells = actor.actorwhitecount
  258.     @blackspells = actor.actorblackcount
  259.     @wizardspells = actor.actorwizardcount
  260.   end
  261.   #--------------------------------------------------------------------------
  262.   # * Level Up
  263.   #--------------------------------------------------------------------------
  264.   alias r2_spell_level_up level_up
  265.   def level_up
  266.     r2_spell_level_up
  267.     spells_up
  268.   end
  269.   #--------------------------------------------------------------------------
  270.   # * Increase Spell Count
  271.   #--------------------------------------------------------------------------
  272.   def spells_up
  273.     white = @actorspells[:white]
  274.     black = @actorspells[:black]
  275.     wizard = @actorspells[:wizard]
  276.     @actorspells.each do |group|
  277.       sym = group[0]
  278.       base = group[1][0]
  279.       incr = group[1][1]
  280.       levl = group[1][2]
  281.       gain = ((@level - 1) / levl).to_i
  282.       spell_up = (gain * incr) + base
  283.       spell_up - 1 if levl == 1
  284.       case sym
  285.       when :white
  286.         actor.actorwhitecount = spell_up
  287.       when :black
  288.         actor.actorblackcount = spell_up
  289.       when :wizard
  290.         actor.actorwizardcount = spell_up
  291.       end
  292.     end
  293.   end
  294. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement