Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #==============================================================================
- # > DSI Rune System
- # Last Updated: 15/9/2021
- # Author: dsiver144
- # --------------------------------------------------------------------------
- # > Skills Notetags:
- # --------------------------------------------------------------------------
- # <runes: id1, id2, ..., idn>
- # ex: <runes: 1, 12, 13>
- # This skill tagged by this note
- # will be casted if user input rune #1, #12 and #13
- #==============================================================================
- module DSIVER144
- module RUNE_SYSTEM
- MAX_SLOTS = 5
- end
- end
- class Game_BattlerBase
- #--------------------------------------------------------------------------
- # * Calculate Skill's MP Cost
- #--------------------------------------------------------------------------
- def skills_mp_cost(skills)
- total_mp = skills.reduce(0) {|a, i| a + i.mp_cost}
- (total_mp * mcr).to_i
- end
- #--------------------------------------------------------------------------
- # * Calculate Skill's TP Cost
- #--------------------------------------------------------------------------
- def skills_tp_cost(skills)
- skills.reduce(0) {|a, i| a + i.tp_cost}
- end
- #--------------------------------------------------------------------------
- # * Determine if Cost of Using Skill Can Be Paid
- #--------------------------------------------------------------------------
- def skills_cost_payable?(skills)
- tp >= skills_tp_cost(skills) && mp >= skills_mp_cost(skills)
- end
- #--------------------------------------------------------------------------
- # * Pay Cost of Using Skills
- #--------------------------------------------------------------------------
- def pay_skills_cost(skills)
- self.mp -= skills_mp_cost(skills)
- self.tp -= skills_tp_cost(skills)
- end
- end
- module DataManager
- class << self
- alias_method(:dsi_rs_load_database, :load_database)
- end
- #--------------------------------------------------------------------------
- # * Load Database
- #--------------------------------------------------------------------------
- def self.load_database
- dsi_rs_load_database() # Call original method.
- load_rune_notetags
- end
- #--------------------------------------------------------------------------
- # * Load Rune Notetags
- #--------------------------------------------------------------------------
- def self.load_rune_notetags
- $data_runes = []
- $data_skills.each do |skill|
- next unless skill
- if skill.note =~ /<runes:(.+)>/i
- skill.runes = $1.split(",").map(&:to_i).sort
- $data_runes << skill
- end
- end
- end
- end
- class RPG::Skill
- attr_accessor :runes
- end
- class Window_BattleSkill
- attr_accessor :rune_skill
- alias_method(:dsi_rs_item, :item)
- def item
- return @rune_skill ? @rune_skill : dsi_rs_item
- end
- #--------------------------------------------------------------------------
- # * Display Skill in Active State?
- #--------------------------------------------------------------------------
- def enable?(item)
- true
- end
- end
- module Vocab
- RuneSuccessful = "%s successfully casted %s"
- RuneFail = "%s failed to casted any spell!"
- end
- class Window_BattleLog
- #--------------------------------------------------------------------------
- # * Display Rune Successful
- #--------------------------------------------------------------------------
- def display_rune_successful(target, item)
- Sound.play_reflection
- add_text(sprintf(Vocab::RuneSuccessful, target.name, item.name))
- wait
- end
- #--------------------------------------------------------------------------
- # * Display Rune Fail
- #--------------------------------------------------------------------------
- def display_rune_fail(target)
- Sound.play_buzzer
- add_text(sprintf(Vocab::RuneFail, target.name))
- wait
- end
- end
- class Scene_Battle
- #--------------------------------------------------------------------------
- # * Create Skill Window
- #--------------------------------------------------------------------------
- alias_method(:dsi_rs_create_skill_window, :create_skill_window)
- def create_skill_window
- dsi_rs_create_skill_window
- @skill_window.set_handler(:ok, method(:on_rune_ok))
- create_rune_option_window
- end
- #--------------------------------------------------------------------------
- # * Skill [Cancel]
- #--------------------------------------------------------------------------
- alias_method(:dsi_rs_on_skill_cancel, :on_skill_cancel)
- def on_skill_cancel
- dsi_rs_on_skill_cancel
- @rune_option_window.clear_runes
- end
- #--------------------------------------------------------------------------
- # * Rune OK
- #--------------------------------------------------------------------------
- def on_rune_ok
- on_add_rune
- @rune_option_window.open
- @rune_option_window.select(1)
- end
- #--------------------------------------------------------------------------
- # * Create Rune Option Window
- #--------------------------------------------------------------------------
- def create_rune_option_window
- @rune_option_window = Window_RuneOptions.new(0, 0)
- @rune_option_window.x = (Graphics.width - @rune_option_window.width) / 2
- @rune_option_window.y = (Graphics.height - @rune_option_window.height) / 2
- @rune_option_window.deactivate
- @rune_option_window.close
- @rune_option_window.openness = 0
- @rune_option_window.set_handler(:excute, method(:on_exc_rune))
- @rune_option_window.set_handler(:clear, method(:on_clear_rune))
- @rune_option_window.set_handler(:cancel, method(:on_cancel_rune))
- @rune_option_window.set_handler(:ok, method(:on_rune_confirm))
- end
- #--------------------------------------------------------------------------
- # * Add Rune
- #--------------------------------------------------------------------------
- def on_add_rune
- @rune_option_window.add_rune(@skill_window.item.id)
- @rune_option_window.refresh
- @rune_option_window.activate
- end
- #--------------------------------------------------------------------------
- # * Exc Rune
- #--------------------------------------------------------------------------
- def on_exc_rune
- @skill_window.rune_skill = nil
- result = @rune_option_window.excute_runes(@skill_window)
- @status_window.refresh
- if @skill_window.rune_skill
- @rune_option_window.close
- @skill_window.hide
- @help_window.hide
- @log_window.display_rune_successful(BattleManager.actor, @skill_window.rune_skill)
- wait(30)
- @log_window.clear
- on_skill_ok
- @skill_window.rune_skill = nil
- else
- @rune_option_window.close
- @skill_window.hide
- @help_window.hide
- @log_window.display_rune_fail(BattleManager.actor)
- wait(30)
- @log_window.clear
- next_command
- end
- end
- #--------------------------------------------------------------------------
- # * Clear Rune
- #--------------------------------------------------------------------------
- def on_clear_rune
- @rune_option_window.clear_runes
- @rune_option_window.refresh
- on_cancel_rune
- end
- #--------------------------------------------------------------------------
- # * Rune Confirm
- #--------------------------------------------------------------------------
- def on_rune_confirm
- @rune_option_window.close
- @skill_window.activate
- end
- #--------------------------------------------------------------------------
- # * Cancel Rune
- #--------------------------------------------------------------------------
- def on_cancel_rune
- @rune_option_window.runes.pop
- @rune_option_window.close
- @skill_window.activate
- end
- end
- class Window_RuneOptions < Window_Command
- #--------------------------------------------------------------------------
- # * Window Height
- #--------------------------------------------------------------------------
- def window_height
- return fitting_height(6)
- end
- #--------------------------------------------------------------------------
- # * Item Rect
- #--------------------------------------------------------------------------
- def item_rect(index)
- rect = super(index)
- rect.y += line_height * 2
- rect
- end
- #--------------------------------------------------------------------------
- # * Window Width
- #--------------------------------------------------------------------------
- def window_width
- return 350
- end
- #--------------------------------------------------------------------------
- # * Runes
- #--------------------------------------------------------------------------
- def runes
- @runes ||= []
- end
- #--------------------------------------------------------------------------
- # * Add Rune
- #--------------------------------------------------------------------------
- def add_rune(id)
- return if runes.size >= DSIVER144::RUNE_SYSTEM::MAX_SLOTS
- runes << id
- end
- #--------------------------------------------------------------------------
- # * Excute Rune
- #--------------------------------------------------------------------------
- attr_accessor :excuted_skill
- def excute_runes(skill_window)
- runes.sort!
- @excuted_skill = nil
- $data_runes.each do |skill|
- if skill.runes.to_s == runes.to_s
- @excuted_skill = skill
- skill_window.rune_skill = @excuted_skill
- end
- end
- BattleManager.actor.pay_skills_cost(runes.map {|id| $data_skills[id]})
- runes.clear
- end
- #--------------------------------------------------------------------------
- # * Clear Runes
- #--------------------------------------------------------------------------
- def clear_runes
- runes.clear
- end
- #--------------------------------------------------------------------------
- # * Make Command List
- #--------------------------------------------------------------------------
- def make_command_list
- used_skills = runes.map {|id| $data_skills[id]}
- mp_enabled = false
- mp_cost = 0
- tp_cost = 0
- if BattleManager.actor
- mp_enabled = BattleManager.actor && BattleManager.actor.skills_cost_payable?(used_skills)
- mp_cost = BattleManager.actor.skills_mp_cost(used_skills)
- tp_cost = BattleManager.actor.skills_tp_cost(used_skills)
- end
- mp_text = mp_enabled ? "" + (mp_cost > 0 ? " #{mp_cost} MP" : "") + (tp_cost > 0 ? " #{tp_cost} TP" : "") : " (Not enough cost!)"
- add_command("Execute" + mp_text, :excute, runes.size > 0 && mp_enabled)
- add_command("Confirm", :ok)
- add_command("Clear All", :clear)
- add_command("Clear", :cancel)
- end
- #--------------------------------------------------------------------------
- # * Refresh
- #--------------------------------------------------------------------------
- def refresh
- super
- cx = (contents_width - (24 * runes.size)) / 2
- runes.each_with_index do |id, index|
- icon_index = $data_skills[id].icon_index
- draw_icon(icon_index, cx, 12)
- cx += 24
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement