Advertisement
Talonos

Shanghai's Draw Spells

Apr 25th, 2011
1,344
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.33 KB | None | 0 0
  1. #===============================================================================
  2. #
  3. # Shanghai Simple Script - Draw Skills
  4. # Last Date Updated: 2010.06.15
  5. # Level: Normal
  6. #
  7. # Final Fantasy 8 had a unique and interesting mechanic called Draw. It would
  8. # take skills from the enemy unit and actors can then use it. They had a count
  9. # to how many times that skill can be used until it ran out. This script allows
  10. # the possibility to do the same thing and also improves upon it.
  11. #
  12. # Changes from actual Final Fantasy 8 Version
  13. # - Some skills have restrictions on which classes can draw skills from it.
  14. # - Drawing a skill from an enemy will teach the actor that skill.
  15. # - Drawing a skill will give a set amount of charges.
  16. # - Skills won't disappear when all of the charges are used up.
  17. # - Skills will cost their MP amount after all of the charges are used up.
  18. #===============================================================================
  19. # Instructions
  20. # -----------------------------------------------------------------------------
  21. # To install this script, open up your script editor and copy/paste this script
  22. # to an open slot below ▼ Materials but above ▼ Main. Remember to save.
  23. #
  24. # <draw skill>
  25. # <draw skill: x>
  26. # These tags will turn the current skill into a draw skill. Draw skills will
  27. # take skills from enemies. If the second tag is used, then x charges will be
  28. # drawn from the enemy. If the second tag isn't used, then 10 charges are drawn.
  29. #
  30. # <draw class: x>
  31. # <draw class: x, x, x>
  32. # These tags will make it so that the current skill can only be drawn by class x
  33. # and nothing else. If these tags aren't present, the skill can be drawn by all
  34. # classes.
  35. #
  36. # <cannot draw>
  37. # This tag will make the skill undrawable. Used for boss skills that you don't
  38. # want the player to learn.
  39. #===============================================================================
  40.  
  41. $imported = {} if $imported == nil
  42. $imported["DrawSkills"] = true
  43.  
  44. module SSS
  45. # This is the maximum amount of charges you can draw for your skills.
  46. MAXIMUM_DRAW_CHARGES = 255
  47. # This is how the text appears when charges are drawn.
  48. DRAW_CHARGES_MSG = "%s has drawn %d×%s!"
  49. DRAW_CHARGES_TEXT = "×%d"
  50. DRAW_CHARGES_SIZE = 16
  51. end
  52.  
  53. #==============================================================================
  54. # RPG::Skill
  55. #==============================================================================
  56.  
  57. class RPG::Skill < RPG::UsableItem
  58. #--------------------------------------------------------------------------
  59. # # Draw Skill
  60. #--------------------------------------------------------------------------
  61. def draw_skill
  62. return @draw_skill if @draw_skill != nil
  63. @draw_skill = 0
  64. self.note.split(/[\r\n]+/).each { |line|
  65. case line
  66. when /<(?:DRAW_SKILL|draw skill)>/i
  67. @draw_skill = 10
  68. when /<(?:DRAW_SKILL|draw skill):[ ](\d+)>/i
  69. @draw_skill = $1.to_i
  70. end
  71. }
  72. return @draw_skill
  73. end
  74. #--------------------------------------------------------------------------
  75. # # Draw Classes
  76. #--------------------------------------------------------------------------
  77. def draw_classes
  78. return @draw_classes if @draw_classes != nil
  79. @draw_classes = []
  80. self.note.split(/[\r\n]+/).each { |line|
  81. case line
  82. when /<(?:DRAW_CLASS|draw class):[ ](\d+(?:\s*,\s*\d+)*)>/i
  83. $1.scan(/\d+/).each { |num|
  84. @draw_classes.push(num.to_i) if num.to_i > 0 }
  85. end
  86. }
  87. if @draw_classes.empty?
  88. for i in 1..$data_classes.size do @draw_classes.push(i) end
  89. end
  90. return @draw_classes
  91. end
  92. #--------------------------------------------------------------------------
  93. # # Cannot Draw
  94. #--------------------------------------------------------------------------
  95. def cannot_draw
  96. return @cannot_draw if @cannot_draw != nil
  97. @cannot_draw = false
  98. self.note.split(/[\r\n]+/).each { |line|
  99. case line
  100. when /<(?:CANNOT_DRAW|cannot draw)>/i
  101. @cannot_draw = true
  102. end
  103. }
  104. return @cannot_draw
  105. end
  106. end
  107.  
  108. #==============================================================================
  109. # ** Game_Battler
  110. #==============================================================================
  111.  
  112. class Game_Battler
  113. #--------------------------------------------------------------------------
  114. # * Perform Skill Cost
  115. #--------------------------------------------------------------------------
  116. if $imported["BattleEngineMelody"]
  117. alias perform_skill_cost_sss_draw_skills perform_skill_cost unless $@
  118. def perform_skill_cost(skill)
  119. return if skill == nil or !skill.is_a?(RPG::Skill)
  120. if actor? and draw_skill_charges(skill) > 0
  121. use_draw_charge(skill)
  122. else
  123. perform_skill_cost_sss_draw_skills(skill)
  124. end
  125. end
  126. #--------------------------------------------------------------------------
  127. # * Custom Skill Costs
  128. #--------------------------------------------------------------------------
  129. alias custom_skill_costs_sss_draw_skills custom_skill_costs unless $@
  130. def custom_skill_costs(skill, type)
  131. if actor? and draw_skill_charges(skill) > 0
  132. charges = draw_skill_charges(skill)
  133. case type
  134. when :perform; return
  135. when :calc_cost; return charges
  136. when :text_cost; return sprintf(SSS::DRAW_CHARGES_TEXT, charges)
  137. when :can_use; return true
  138. when :use_icon; return 0
  139. when :suffix; return "%s"
  140. when :font_size; return SSS::DRAW_CHARGES_SIZE
  141. when :colour; return 0
  142. end
  143. else
  144. return custom_skill_costs_sss_draw_skills(skill, type)
  145. end
  146. end
  147. else # Imported Battle Engine Melody
  148. #--------------------------------------------------------------------------
  149. # * Calculation of MP Consumed for Skills
  150. #--------------------------------------------------------------------------
  151. alias calc_mp_cost_sss_draw_skills calc_mp_cost unless $@
  152. def calc_mp_cost(skill)
  153. if actor? and draw_skill_charges(skill) > 0
  154. return 0
  155. else
  156. return calc_mp_cost_sss_draw_skills(skill)
  157. end
  158. end
  159. #--------------------------------------------------------------------------
  160. # * Determine Usable Skills
  161. #--------------------------------------------------------------------------
  162. alias skill_can_use_sss_draw_skills skill_can_use? unless $@
  163. def skill_can_use?(skill)
  164. if actor? and draw_skill_charges(skill) > 0
  165. return false unless skill.is_a?(RPG::Skill)
  166. return false unless movable?
  167. return false if silent? and skill.spi_f > 0
  168. if $game_temp.in_battle
  169. return skill.battle_ok?
  170. else
  171. return skill.menu_ok?
  172. end
  173. else
  174. return skill_can_use_sss_draw_skills(skill)
  175. end
  176. end
  177. end
  178. end
  179.  
  180. #==============================================================================
  181. # ** Game_Actor
  182. #==============================================================================
  183.  
  184. class Game_Actor < Game_Battler
  185. #--------------------------------------------------------------------------
  186. # * Draw Skill Charges
  187. #--------------------------------------------------------------------------
  188. def draw_skill_charges(skill)
  189. @draw_skills = {} if @draw_skills.nil?
  190. @draw_skills[skill.id] = 0 if @draw_skills[skill.id].nil?
  191. return @draw_skills[skill.id]
  192. end
  193. #--------------------------------------------------------------------------
  194. # * Acquire Draw Skill
  195. #--------------------------------------------------------------------------
  196. def acquire_draw_skill(skill, charges)
  197. @draw_skills = {} if @draw_skills.nil?
  198. @draw_skills[skill.id] = 0 if @draw_skills[skill.id].nil?
  199. @draw_skills[skill.id] += charges
  200. @draw_skills[skill.id] = [@draw_skills[skill.id], 0].max
  201. maximum = SSS::MAXIMUM_DRAW_CHARGES
  202. @draw_skills[skill.id] = [@draw_skills[skill.id], maximum].min
  203. learn_skill(skill.id)
  204. clear_battle_cache if $imported["BattleEngineMelody"]
  205. end
  206. #--------------------------------------------------------------------------
  207. # * Use Draw Charge
  208. #--------------------------------------------------------------------------
  209. def use_draw_charge(skill)
  210. @draw_skills = {} if @draw_skills.nil?
  211. @draw_skills[skill.id] = 0 if @draw_skills[skill.id].nil?
  212. @draw_skills[skill.id] -= 1
  213. @draw_skills[skill.id] = [@draw_skills[skill.id], 0].max
  214. maximum = SSS::MAXIMUM_DRAW_CHARGES
  215. @draw_skills[skill.id] = [@draw_skills[skill.id], maximum].min
  216. end
  217. #--------------------------------------------------------------------------
  218. # * Determine Usable Skills
  219. #--------------------------------------------------------------------------
  220. def skill_can_use?(skill)
  221. return super(skill)
  222. end
  223. end
  224.  
  225. #==============================================================================
  226. # ** Game_Enemy
  227. #==============================================================================
  228.  
  229. class Game_Enemy < Game_Battler
  230. #--------------------------------------------------------------------------
  231. # * Total Skills
  232. #--------------------------------------------------------------------------
  233. unless method_defined?(:total_skills)
  234. def total_skills
  235. result = []
  236. for action in enemy.actions
  237. next unless action.kind == 1
  238. skill = $data_skills[action.skill_id]
  239. result.push(skill) unless result.include?(skill)
  240. end
  241. result.sort! { |a,b| a.id <=> b.id }
  242. return result.uniq
  243. end
  244. end
  245. end
  246.  
  247. #==============================================================================
  248. # ** Window_Skill
  249. #==============================================================================
  250.  
  251. unless $imported["BattleEngineMelody"]
  252. class Window_Skill < Window_Selectable
  253. #--------------------------------------------------------------------------
  254. # * Draw Item
  255. #--------------------------------------------------------------------------
  256. alias draw_item_sss_draw_skills draw_item unless $@
  257. def draw_item(index)
  258. skill = @data[index]
  259. if skill != nil and @actor.draw_skill_charges(skill) > 0
  260. rect = item_rect(index)
  261. self.contents.clear_rect(rect)
  262. rect.width -= 4
  263. charges = @actor.draw_skill_charges(skill)
  264. self.contents.font.size = Font.default_size
  265. enabled = @actor.skill_can_use?(skill)
  266. draw_item_name(skill, rect.x, rect.y, enabled)
  267. text = sprintf(SSS::DRAW_CHARGES_TEXT, charges)
  268. self.contents.font.size = SSS::DRAW_CHARGES_SIZE
  269. self.contents.draw_text(rect, text, 2)
  270. else
  271. draw_item_sss_draw_skills(index)
  272. end
  273. end
  274. end
  275. end
  276.  
  277. #==============================================================================
  278. # ** Window_Draw_Skill
  279. #==============================================================================
  280.  
  281. class Window_Draw_Skill < Window_Selectable
  282. #--------------------------------------------------------------------------
  283. # * Object Initialization
  284. #--------------------------------------------------------------------------
  285. def initialize(actor, targets, help)
  286. yy = help.y + help.height
  287. super(0, yy, Graphics.width, Graphics.height-yy-128)
  288. @actor = actor
  289. @drawing_skill = @actor.action.skill
  290. @targets = targets
  291. @column_max = 2
  292. self.index = 0
  293. refresh
  294. self.help_window = help
  295. end
  296. #--------------------------------------------------------------------------
  297. # * Get Skill
  298. #--------------------------------------------------------------------------
  299. def skill
  300. return @data[self.index]
  301. end
  302. #--------------------------------------------------------------------------
  303. # * Total Skills
  304. #--------------------------------------------------------------------------
  305. def total_skills
  306. return @data.size
  307. end
  308. #--------------------------------------------------------------------------
  309. # * Object Initialization
  310. #--------------------------------------------------------------------------
  311. def refresh
  312. @data = []
  313. for target in @targets
  314. next if target.actor?
  315. for skill in target.total_skills
  316. @data.push(skill) if include?(skill)
  317. end
  318. end
  319. @item_max = @data.size
  320. create_contents
  321. for i in 0...@item_max
  322. draw_item(i)
  323. end
  324. end
  325. #--------------------------------------------------------------------------
  326. # * Include Skill?
  327. #--------------------------------------------------------------------------
  328. def include?(skill)
  329. return false if skill.cannot_draw
  330. return false if @data.include?(skill)
  331. return false unless skill.draw_classes.include?(@actor.class_id)
  332. return true
  333. end
  334. #--------------------------------------------------------------------------
  335. # * Update Help Text
  336. #--------------------------------------------------------------------------
  337. def update_help
  338. @help_window.set_text(skill == nil ? "" : skill.description)
  339. end
  340. #--------------------------------------------------------------------------
  341. # * Draw Item
  342. # index : item number
  343. #--------------------------------------------------------------------------
  344. def draw_item(index)
  345. rect = item_rect(index)
  346. self.contents.clear_rect(rect)
  347. skill = @data[index]
  348. if skill != nil
  349. rect.width -= 4
  350. self.contents.font.size = Font.default_size
  351. draw_item_name(skill, rect.x, rect.y, true)
  352. charges = @drawing_skill.draw_skill
  353. text = sprintf(SSS::DRAW_CHARGES_TEXT, charges)
  354. self.contents.font.size = SSS::DRAW_CHARGES_SIZE
  355. self.contents.draw_text(rect, text, 2)
  356. end
  357. end
  358. end
  359.  
  360. #==============================================================================
  361. # ** Scene_Skill
  362. #==============================================================================
  363. unless $imported["BattleEngineMelody"]
  364. class Scene_Skill < Scene_Base
  365. #--------------------------------------------------------------------------
  366. # * Use Skill (apply effects to non-ally targets)
  367. #--------------------------------------------------------------------------
  368. alias use_skill_nontarget_sss_draw_skills use_skill_nontarget unless $@
  369. def use_skill_nontarget
  370. @actor.use_draw_charge(@skill) if @actor.draw_skill_charges(@skill) > 0
  371. use_skill_nontarget_sss_draw_skills
  372. end
  373. end
  374. end
  375. #==============================================================================
  376. # ** Scene_Battle
  377. #==============================================================================
  378.  
  379. class Scene_Battle < Scene_Base
  380. #--------------------------------------------------------------------------
  381. # * Execute Battle Action: Skill
  382. #--------------------------------------------------------------------------
  383. alias execute_action_skill_sss_draw_skill execute_action_skill unless $@
  384. def execute_action_skill
  385. skill = @active_battler.action.skill
  386. if $imported["BattleEngineMelody"]
  387. if @active_battler.actor? and skill.draw_skill > 0
  388. execute_action_draw_skill(skill)
  389. else
  390. execute_action_skill_sss_draw_skill
  391. end
  392. else
  393. targets = @active_battler.action.make_targets
  394. execute_action_skill_sss_draw_skill
  395. if @active_battler.actor? and @active_battler.draw_skill_charges(skill) > 0
  396. @active_battler.use_draw_charge(skill)
  397. end
  398. if @active_battler.actor? and skill.draw_skill > 0
  399. perform_draw_skill(skill, targets)
  400. end
  401. end
  402. end
  403. #--------------------------------------------------------------------------
  404. # * Execute Battle Action: Draw Skill
  405. #--------------------------------------------------------------------------
  406. def execute_action_draw_skill(skill)
  407. @scene_skill = skill
  408. targets = @active_battler.action.make_targets
  409. targets = sort_targets(targets, skill)
  410. #--- Setup ---
  411. action_list = skill.setup_action_list
  412. perform_action_list(action_list, targets) unless @chain_action
  413. lunatic_obj_effects(:before, skill)
  414. @active_battler.perform_skill_cost(skill) unless @ignore_cost
  415. @active_battler.action.friends_unit.update_ptb
  416. status_window_refresh
  417. #--- Whole ---
  418. action_list = skill.whole_action_list
  419. perform_action_list(action_list, targets)
  420. #--- Target ---
  421. action_list = skill.target_action_list
  422. for target in targets
  423. next if target.dead? and !skill.for_dead_friend?
  424. perform_action_list(action_list, [target])
  425. end
  426. #--- Follow ---
  427. action_list = skill.follow_action_list
  428. perform_action_list(action_list, targets)
  429. lunatic_obj_effects(:after, skill)
  430. #--- Finish ---
  431. perform_draw_skill(skill, targets)
  432. refresh_ptb_windows unless @ptb_updated
  433. action_list = skill.finish_action_list
  434. perform_action_list(action_list, targets) unless @chain_action
  435. perform_earn_jp(:skill) if $imported["SkillOverhaul"]
  436. readjust_instant_properties if skill.instant
  437. end
  438. #--------------------------------------------------------------------------
  439. # * Perform Draw Skill
  440. #--------------------------------------------------------------------------
  441. def perform_draw_skill(skill, targets)
  442. Graphics.freeze
  443. @help_window = Window_Help.new
  444. @draw_window = Window_Draw_Skill.new(@active_battler, targets, @help_window)
  445. if $imported["BattleEngineMelody"]
  446. @help_window.viewport = @spriteset.viewportC
  447. @draw_window.viewport = @spriteset.viewportC
  448. end
  449. if @draw_window.total_skills == 0
  450. @help_window.dispose
  451. @help_window = nil
  452. @draw_window.dispose
  453. @draw_window = nil
  454. Graphics.transition(0)
  455. return
  456. end
  457. Graphics.transition(10)
  458. loop do
  459. update_basic
  460. @draw_window.update
  461. if Input.trigger?(Input::C)
  462. Sound.play_decision
  463. draw_skill = @draw_window.skill
  464. @active_battler.acquire_draw_skill(draw_skill, skill.draw_skill)
  465. name = @active_battler.name
  466. charges = skill.draw_skill
  467. skill_name = draw_skill.name
  468. text = sprintf(SSS::DRAW_CHARGES_MSG, name, charges, skill_name)
  469. @message_window.add_instant_text(text)
  470. break
  471. elsif Input.trigger?(Input::B)
  472. Sound.play_cancel
  473. break
  474. end
  475. end
  476. Graphics.freeze
  477. @help_window.dispose
  478. @help_window = nil
  479. @draw_window.dispose
  480. @draw_window = nil
  481. Graphics.transition(10)
  482. end
  483. end
  484.  
  485. #===============================================================================
  486. #
  487. # END OF FILE
  488. #
  489. #===============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement