Advertisement
roninator2

Yazik Skill Shop Addon

Dec 8th, 2024
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 10.52 KB | None | 0 0
  1. # ╔═════════════════════════════════════╦════════════════════╗
  2. # ║ Title: Yazik Skill Shop Addon       ║  Version: 1.06     ║
  3. # ║ Author: Roninator2                  ║                    ║
  4. # ╠═════════════════════════════════════╬════════════════════╣
  5. # ║ Function:                           ║   Date Created     ║
  6. # ║   Allow Switches, Variables         ╠════════════════════╣
  7. # ║   and Stat changes in shop          ║    06 Jul 2022     ║
  8. # ╚═════════════════════════════════════╩════════════════════╝
  9. # ╔══════════════════════════════════════════════════════════╗
  10. # ║ Instructions:                                            ║
  11. # ║   Input the settings to your preference. read carefully  ║
  12. # ╚══════════════════════════════════════════════════════════╝
  13. # ╔══════════════════════════════════════════════════════════╗
  14. # ║ Updates:                                                 ║
  15. # ║   2022 07 06 - Initial Publish                           ║
  16. # ║   2022 07 07 - Set switches to only be activated once    ║
  17. # ║                Updated instructions                      ║
  18. # ║   2022 07 09 - Modified variables to be used only once   ║
  19. # ║   2022 07 18 - Fixed Help Text                           ║
  20. # ║   2022 07 20 - Corrected system to have data per actor   ║
  21. # ║   2022 08 25 - Added multi purchase of stats             ║
  22. # ║   2022 08 29 - Reworked code to fix multi purchase       ║
  23. # ╚══════════════════════════════════════════════════════════╝
  24. # ╔══════════════════════════════════════════════════════════╗
  25. # ║ Terms of use:                                            ║
  26. # ║ Free for all uses in RPG Maker except nudity             ║
  27. # ╚══════════════════════════════════════════════════════════╝
  28. #     ShopDatabase = {
  29. #
  30. # Switch item format : [switch_id, price, :switch, "Description", item index],
  31. #   item index for switches and variables and stats is used to pull in
  32. #   an item for drawing an icon and making the code happy.
  33. # Variable item format : [var_id, price, :variable, "Description", item index, amount],
  34. # Stat item format : [stat_id, price, :stat, "Description", item index, amount, multi purchase, change by, subtract amount],
  35. #   stat amount is how much the stat increases
  36. #   Stat_id options are 0, 1, 2, 3, 4, 5, 6, 7
  37. #     MHP, MMP, ATK, DEF, MAT, MDF, AGI, LUK
  38. #   Multi purchase is true or false. False is single purchase
  39. #   Change by is the point which further purchases would reduce the amount gained by the subtract amount
  40.  
  41. class Game_Actor < Game_Battler
  42.   attr_accessor :skill_variables
  43.   attr_accessor :stat_boost_skill
  44.   #--------------------------------------------------------------------------
  45.   # * Setup
  46.   #--------------------------------------------------------------------------
  47.   alias r2_skill_var_sw_setup setup
  48.   def setup(actor_id)
  49.     r2_skill_var_sw_setup(actor_id)
  50.     @skill_variables = []
  51.     @stat_boost_skill = []
  52.   end
  53. end
  54.  
  55. class Window_ShopSkill < Window_SkillList
  56.   def make_item_list
  57.     if @actor
  58.       skills = []
  59.       db = Yazik::SkillShop::ShopDatabase[@actor.id]
  60.       for i in 0...db.size
  61.         if db[i][2] == :state
  62.           state_id = db[i][0]
  63.           if @actor.state_addable?(state_id)
  64.             state = $data_states[state_id]
  65.             skills.push(state)
  66.           end
  67.         elsif db[i][2] == :switch
  68.           switch_id = db[i][0]
  69.           switch = [$game_switches[switch_id], $data_items[db[i][4]], :switch]
  70.           skills.push(switch)
  71.         elsif db[i][2] == :variable
  72.           var_id = db[i][0]
  73.           @actor.skill_variables[var_id] = false if @actor.skill_variables[var_id] == nil
  74.           var = [$game_variables[var_id], $data_items[db[i][4]], :variable, db[i][5], @actor.skill_variables[var_id]]
  75.           skills.push(var)
  76.         elsif db[i][2] == :stat
  77.           @actor.stat_boost_skill[i] = [false,0,db[i][6],db[i][7],db[i][8]] if @actor.stat_boost_skill[i] == nil
  78.           stat = [db[i][0], $data_items[db[i][4]], :stat, db[i][5], @actor.stat_boost_skill[i][0]]
  79.           skills.push(stat)
  80.         else
  81.           skill = $data_skills[db[i][0]]
  82.           if @actor.added_skill_types.include?(skill.stype_id)
  83.             skills.push(skill)
  84.           end
  85.         end
  86.       end
  87.       @data = skills
  88.     else
  89.       @data = []
  90.     end
  91.   end
  92.   def draw_item(index)
  93.     data = @data[index]
  94.     if data
  95.       rect = item_rect(index)
  96.       rect.width -= 4
  97.       if data.class == RPG::Skill
  98.         enabled = @actor.skill_learn?(data)
  99.       elsif data.class ==  RPG::State
  100.         enabled = @actor.state?(data.id)
  101.       elsif data[2] == :switch
  102.         enabled = true if data[0].is_a?(FalseClass)
  103.       elsif data[2] == :variable
  104.         enabled = true if data[4] == false
  105.       elsif data[2] == :stat
  106.         enabled = true if data[4] == false
  107.       end
  108.       draw_skill_icon(index, data, rect.x, rect.y, enabled)
  109.       draw_skill_price(rect, index)
  110.     end
  111.   end
  112.   def draw_skill_icon(index, item, x, y, enabled)
  113.     return unless item
  114.     if item.is_a?(Array)
  115.       draw_icon(item[1].icon_index, x, y, enabled)
  116.     else
  117.       draw_icon(item.icon_index, x, y, enabled)
  118.     end
  119.   end
  120. end
  121.  
  122. class Scene_SkillShop < Scene_Skill
  123.   def on_item_ok
  124.     is_skill = item.class == RPG::Skill
  125.     is_state = item.class == RPG::State
  126.     is_array = item.class == Array
  127.     if (is_skill and !@actor.skill_learn?(item)) or (is_state and !@actor.state?(item.id)) or (is_array)
  128.       db = Yazik::SkillShop::ShopDatabase[@actor.id]
  129.       price = db[@item_window.index][1]
  130.       if db[@item_window.index][2] == :switch
  131.         if ($game_switches[db[@item_window.index][0]] == true) ||
  132.           (price > $game_actors[@actor.id].skill_point)
  133.           Sound.play_buzzer
  134.           @item_window.activate
  135.         else
  136.           @confirm_window.open
  137.           @confirm_window.select(0)
  138.           @confirm_window.activate
  139.         end
  140.       elsif db[@item_window.index][2] == :variable
  141.         if (@actor.skill_variables[db[@item_window.index][0]] == true) ||
  142.           (price > $game_actors[@actor.id].skill_point)
  143.           Sound.play_buzzer
  144.           @item_window.activate
  145.         else
  146.           @confirm_window.open
  147.           @confirm_window.select(0)
  148.           @confirm_window.activate
  149.         end
  150.       elsif db[@item_window.index][2] == :stat
  151.         if (@actor.stat_boost_skill[@item_window.index][0] == true) ||
  152.           (price > $game_actors[@actor.id].skill_point) ||
  153.           Sound.play_buzzer
  154.           @item_window.activate
  155.         else
  156.           @confirm_window.open
  157.           @confirm_window.select(0)
  158.           @confirm_window.activate
  159.         end
  160.       elsif price <= $game_actors[@actor.id].skill_point
  161.         @confirm_window.open
  162.         @confirm_window.select(0)
  163.         @confirm_window.activate
  164.       else
  165.         Sound.play_buzzer
  166.         @item_window.activate
  167.       end
  168.     else
  169.       @item_window.activate
  170.     end
  171.   end
  172.   def buy_item
  173.     db = Yazik::SkillShop::ShopDatabase[@actor.id]
  174.     if db[@item_window.index][2] == :state
  175.       state_id = db[@item_window.index][0]
  176.       state_price = db[@item_window.index][1]
  177.       $game_actors[@actor.id].skill_point -= state_price
  178.       $game_actors[@actor.id].add_state(state_id)
  179.     elsif db[@item_window.index][2] == :switch
  180.       switch_id = db[@item_window.index][0]
  181.       switch_price = db[@item_window.index][1]
  182.       $game_actors[@actor.id].skill_point -= switch_price
  183.       $game_switches[switch_id] = !$game_switches[switch_id]
  184.     elsif db[@item_window.index][2] == :variable
  185.       var_id = db[@item_window.index][0]
  186.       var_price = db[@item_window.index][1]
  187.       var_amount = db[@item_window.index][5]
  188.       $game_actors[@actor.id].skill_point -= var_price
  189.       $game_actors[@actor.id].skill_variables[db[@item_window.index][0]] = true
  190.       $game_variables[var_id] += var_amount
  191.     elsif db[@item_window.index][2] == :stat
  192.       stat_id = db[@item_window.index][0]
  193.       amount = db[@item_window.index][5]
  194.       stat_price = db[@item_window.index][1]
  195.       $game_actors[@actor.id].stat_boost_skill[@item_window.index][0] = true if ($game_actors[@actor.id].stat_boost_skill[@item_window.index][2] == false)
  196.       $game_actors[@actor.id].skill_point -= stat_price
  197.             if ($game_actors[@actor.id].stat_boost_skill[@item_window.index][1] >= $game_actors[@actor.id].stat_boost_skill[@item_window.index][3]) &&
  198.                 ($game_actors[@actor.id].stat_boost_skill[@item_window.index][2] == true)
  199.                 amount = amount - ($game_actors[@actor.id].stat_boost_skill[@item_window.index][4])
  200.                 ($game_actors[@actor.id].stat_boost_skill[@item_window.index][1] += 1)
  201.             end
  202.             @actor.add_param(stat_id, amount)
  203.         else
  204.       skill_id = db[@item_window.index][0]
  205.       skill_price = db[@item_window.index][1]
  206.       $game_actors[@actor.id].skill_point -= skill_price
  207.       $game_actors[@actor.id].learn_skill(skill_id)
  208.     end
  209.     @info_window.refresh
  210.     @confirm_window.close
  211.     @confirm_window.deactivate
  212.     @item_window.refresh
  213.     @item_window.activate
  214.   end
  215. end
  216.  
  217. class Window_ShopHelp < Window_Help
  218.   def set_item(item)
  219.     if item.class == Array
  220.       itemn = item[1]
  221.       set_name(itemn.name)
  222.     else
  223.       set_name(item ? item.name : "")
  224.     end
  225.     if SceneManager.scene_is?(Scene_SkillShop)
  226.       if (item) and ((item.class == RPG::State) or (item.class == Array))
  227.         set_text(SceneManager.scene.database_item[3])
  228.         return
  229.       end
  230.     end
  231.     yazik_ss_set_item(item)
  232.   end
  233. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement