Advertisement
DarkSoul144

DSI Rune System

Sep 15th, 2021
368
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.00 KB | None | 0 0
  1. #==============================================================================
  2. # > DSI Rune System
  3. # Last Updated: 15/9/2021
  4. # Author: dsiver144
  5. # --------------------------------------------------------------------------
  6. # > Skills Notetags:
  7. # --------------------------------------------------------------------------
  8. # <runes: id1, id2, ..., idn>
  9. # ex: <runes: 1, 12, 13>
  10. # This skill tagged by this note
  11. # will be casted if user input rune #1, #12 and #13
  12. #==============================================================================
  13.  
  14. module DSIVER144
  15. module RUNE_SYSTEM
  16. MAX_SLOTS = 5
  17. end
  18. end
  19.  
  20. class Game_BattlerBase
  21. #--------------------------------------------------------------------------
  22. # * Calculate Skill's MP Cost
  23. #--------------------------------------------------------------------------
  24. def skills_mp_cost(skills)
  25. total_mp = skills.reduce(0) {|a, i| a + i.mp_cost}
  26. (total_mp * mcr).to_i
  27. end
  28. #--------------------------------------------------------------------------
  29. # * Calculate Skill's TP Cost
  30. #--------------------------------------------------------------------------
  31. def skills_tp_cost(skills)
  32. skills.reduce(0) {|a, i| a + i.tp_cost}
  33. end
  34. #--------------------------------------------------------------------------
  35. # * Determine if Cost of Using Skill Can Be Paid
  36. #--------------------------------------------------------------------------
  37. def skills_cost_payable?(skills)
  38. tp >= skills_tp_cost(skills) && mp >= skills_mp_cost(skills)
  39. end
  40. #--------------------------------------------------------------------------
  41. # * Pay Cost of Using Skills
  42. #--------------------------------------------------------------------------
  43. def pay_skills_cost(skills)
  44. self.mp -= skills_mp_cost(skills)
  45. self.tp -= skills_tp_cost(skills)
  46. end
  47. end
  48.  
  49. module DataManager
  50. class << self
  51. alias_method(:dsi_rs_load_database, :load_database)
  52. end
  53. #--------------------------------------------------------------------------
  54. # * Load Database
  55. #--------------------------------------------------------------------------
  56. def self.load_database
  57. dsi_rs_load_database() # Call original method.
  58. load_rune_notetags
  59. end
  60. #--------------------------------------------------------------------------
  61. # * Load Rune Notetags
  62. #--------------------------------------------------------------------------
  63. def self.load_rune_notetags
  64. $data_runes = []
  65. $data_skills.each do |skill|
  66. next unless skill
  67. if skill.note =~ /<runes:(.+)>/i
  68. skill.runes = $1.split(",").map(&:to_i).sort
  69. $data_runes << skill
  70. end
  71. end
  72. end
  73.  
  74. end
  75.  
  76. class RPG::Skill
  77. attr_accessor :runes
  78. end
  79.  
  80. class Window_BattleSkill
  81.  
  82. attr_accessor :rune_skill
  83. alias_method(:dsi_rs_item, :item)
  84. def item
  85. return @rune_skill ? @rune_skill : dsi_rs_item
  86. end
  87. #--------------------------------------------------------------------------
  88. # * Display Skill in Active State?
  89. #--------------------------------------------------------------------------
  90. def enable?(item)
  91. true
  92. end
  93.  
  94. end
  95.  
  96. module Vocab
  97. RuneSuccessful = "%s successfully casted %s"
  98. RuneFail = "%s failed to casted any spell!"
  99. end
  100.  
  101. class Window_BattleLog
  102. #--------------------------------------------------------------------------
  103. # * Display Rune Successful
  104. #--------------------------------------------------------------------------
  105. def display_rune_successful(target, item)
  106. Sound.play_reflection
  107. add_text(sprintf(Vocab::RuneSuccessful, target.name, item.name))
  108. wait
  109. end
  110. #--------------------------------------------------------------------------
  111. # * Display Rune Fail
  112. #--------------------------------------------------------------------------
  113. def display_rune_fail(target)
  114. Sound.play_buzzer
  115. add_text(sprintf(Vocab::RuneFail, target.name))
  116. wait
  117. end
  118. end
  119.  
  120. class Scene_Battle
  121. #--------------------------------------------------------------------------
  122. # * Create Skill Window
  123. #--------------------------------------------------------------------------
  124. alias_method(:dsi_rs_create_skill_window, :create_skill_window)
  125. def create_skill_window
  126. dsi_rs_create_skill_window
  127. @skill_window.set_handler(:ok, method(:on_rune_ok))
  128. create_rune_option_window
  129. end
  130. #--------------------------------------------------------------------------
  131. # * Skill [Cancel]
  132. #--------------------------------------------------------------------------
  133. alias_method(:dsi_rs_on_skill_cancel, :on_skill_cancel)
  134. def on_skill_cancel
  135. dsi_rs_on_skill_cancel
  136. @rune_option_window.clear_runes
  137. end
  138. #--------------------------------------------------------------------------
  139. # * Rune OK
  140. #--------------------------------------------------------------------------
  141. def on_rune_ok
  142. on_add_rune
  143. @rune_option_window.open
  144. @rune_option_window.select(1)
  145. end
  146. #--------------------------------------------------------------------------
  147. # * Create Rune Option Window
  148. #--------------------------------------------------------------------------
  149. def create_rune_option_window
  150. @rune_option_window = Window_RuneOptions.new(0, 0)
  151. @rune_option_window.x = (Graphics.width - @rune_option_window.width) / 2
  152. @rune_option_window.y = (Graphics.height - @rune_option_window.height) / 2
  153. @rune_option_window.deactivate
  154. @rune_option_window.close
  155. @rune_option_window.openness = 0
  156. @rune_option_window.set_handler(:excute, method(:on_exc_rune))
  157. @rune_option_window.set_handler(:clear, method(:on_clear_rune))
  158. @rune_option_window.set_handler(:cancel, method(:on_cancel_rune))
  159. @rune_option_window.set_handler(:ok, method(:on_rune_confirm))
  160. end
  161. #--------------------------------------------------------------------------
  162. # * Add Rune
  163. #--------------------------------------------------------------------------
  164. def on_add_rune
  165. @rune_option_window.add_rune(@skill_window.item.id)
  166. @rune_option_window.refresh
  167. @rune_option_window.activate
  168. end
  169. #--------------------------------------------------------------------------
  170. # * Exc Rune
  171. #--------------------------------------------------------------------------
  172. def on_exc_rune
  173. @skill_window.rune_skill = nil
  174. result = @rune_option_window.excute_runes(@skill_window)
  175. @status_window.refresh
  176. if @skill_window.rune_skill
  177. @rune_option_window.close
  178. @skill_window.hide
  179. @help_window.hide
  180. @log_window.display_rune_successful(BattleManager.actor, @skill_window.rune_skill)
  181. wait(30)
  182. @log_window.clear
  183. on_skill_ok
  184. @skill_window.rune_skill = nil
  185. else
  186. @rune_option_window.close
  187. @skill_window.hide
  188. @help_window.hide
  189. @log_window.display_rune_fail(BattleManager.actor)
  190. wait(30)
  191. @log_window.clear
  192. next_command
  193. end
  194. end
  195. #--------------------------------------------------------------------------
  196. # * Clear Rune
  197. #--------------------------------------------------------------------------
  198. def on_clear_rune
  199. @rune_option_window.clear_runes
  200. @rune_option_window.refresh
  201. on_cancel_rune
  202. end
  203. #--------------------------------------------------------------------------
  204. # * Rune Confirm
  205. #--------------------------------------------------------------------------
  206. def on_rune_confirm
  207. @rune_option_window.close
  208. @skill_window.activate
  209. end
  210. #--------------------------------------------------------------------------
  211. # * Cancel Rune
  212. #--------------------------------------------------------------------------
  213. def on_cancel_rune
  214. @rune_option_window.runes.pop
  215. @rune_option_window.close
  216. @skill_window.activate
  217. end
  218. end
  219.  
  220. class Window_RuneOptions < Window_Command
  221. #--------------------------------------------------------------------------
  222. # * Window Height
  223. #--------------------------------------------------------------------------
  224. def window_height
  225. return fitting_height(6)
  226. end
  227. #--------------------------------------------------------------------------
  228. # * Item Rect
  229. #--------------------------------------------------------------------------
  230. def item_rect(index)
  231. rect = super(index)
  232. rect.y += line_height * 2
  233. rect
  234. end
  235. #--------------------------------------------------------------------------
  236. # * Window Width
  237. #--------------------------------------------------------------------------
  238. def window_width
  239. return 350
  240. end
  241. #--------------------------------------------------------------------------
  242. # * Runes
  243. #--------------------------------------------------------------------------
  244. def runes
  245. @runes ||= []
  246. end
  247. #--------------------------------------------------------------------------
  248. # * Add Rune
  249. #--------------------------------------------------------------------------
  250. def add_rune(id)
  251. return if runes.size >= DSIVER144::RUNE_SYSTEM::MAX_SLOTS
  252. runes << id
  253. end
  254. #--------------------------------------------------------------------------
  255. # * Excute Rune
  256. #--------------------------------------------------------------------------
  257. attr_accessor :excuted_skill
  258. def excute_runes(skill_window)
  259. runes.sort!
  260. @excuted_skill = nil
  261. $data_runes.each do |skill|
  262. if skill.runes.to_s == runes.to_s
  263. @excuted_skill = skill
  264. skill_window.rune_skill = @excuted_skill
  265. end
  266. end
  267. BattleManager.actor.pay_skills_cost(runes.map {|id| $data_skills[id]})
  268. runes.clear
  269. end
  270. #--------------------------------------------------------------------------
  271. # * Clear Runes
  272. #--------------------------------------------------------------------------
  273. def clear_runes
  274. runes.clear
  275. end
  276. #--------------------------------------------------------------------------
  277. # * Make Command List
  278. #--------------------------------------------------------------------------
  279. def make_command_list
  280. used_skills = runes.map {|id| $data_skills[id]}
  281. mp_enabled = false
  282. mp_cost = 0
  283. tp_cost = 0
  284. if BattleManager.actor
  285. mp_enabled = BattleManager.actor && BattleManager.actor.skills_cost_payable?(used_skills)
  286. mp_cost = BattleManager.actor.skills_mp_cost(used_skills)
  287. tp_cost = BattleManager.actor.skills_tp_cost(used_skills)
  288. end
  289. mp_text = mp_enabled ? "" + (mp_cost > 0 ? " #{mp_cost} MP" : "") + (tp_cost > 0 ? " #{tp_cost} TP" : "") : " (Not enough cost!)"
  290. add_command("Execute" + mp_text, :excute, runes.size > 0 && mp_enabled)
  291. add_command("Confirm", :ok)
  292. add_command("Clear All", :clear)
  293. add_command("Clear", :cancel)
  294. end
  295. #--------------------------------------------------------------------------
  296. # * Refresh
  297. #--------------------------------------------------------------------------
  298. def refresh
  299. super
  300. cx = (contents_width - (24 * runes.size)) / 2
  301. runes.each_with_index do |id, index|
  302. icon_index = $data_skills[id].icon_index
  303. draw_icon(icon_index, cx, 12)
  304. cx += 24
  305. end
  306. end
  307. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement