Advertisement
Guest User

Side-View Battle System

a guest
Jan 11th, 2015
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.74 KB | None | 0 0
  1. #===============================================================================
  2. # Side-View Battle System
  3. # By Jet10985 (Jet)
  4. #===============================================================================
  5. # This script will allow you to have battle where all the actor's sprites are
  6. # display on the right side of the screen.
  7. # This script has: 10 customization options.
  8. #===============================================================================
  9. # Overwritten Methods:
  10. # Scene_Battle: show_attack_animation
  11. # Spriteset_Battle: update_actors
  12. #-------------------------------------------------------------------------------
  13. # Aliased methods:
  14. # Spriteset_Battle: create_actors, create_enemies
  15. # Sprite_Character: initialize, update, dispose, start_new_effect
  16. # Scene_Battle: use_item, next_command, prior_command
  17. # Game_Character: screen_x, screen_y
  18. #===============================================================================
  19.  
  20. module Jet
  21. module Sideview
  22.  
  23. #===========================================================================
  24. # ENEMY OPTIONS
  25. #===========================================================================
  26.  
  27. # These are the attack animations for enemies when they use a regular attack.
  28. # It follows this format: enemy_id => animation_id
  29. ENEMY_ATK_ANIMS = {
  30.  
  31. 1 => 4,
  32. 6 => 2,
  33. 5 => 27
  34.  
  35. }
  36.  
  37. # This is the default enemy attack animation, used when they do not have a
  38. # specific attack animation above.
  39. ENEMY_ATK_ANIMS.default = 0
  40.  
  41. # This is a list of enemies whose portraits should be flipped in battle.
  42. FLIPPED_ENEMIES = [2, 3, 4, 5, 8, 10, 12, 13, 14, 16, 17, 18, 19]
  43.  
  44. #===========================================================================
  45. # ACTOR OPTIONS
  46. #===========================================================================
  47.  
  48. # Should the player sprite have a shadow beneath them?
  49. PLAYER_SHADOW = true
  50.  
  51. # These are sprite changes depending on state infliction.
  52. # It follows this format: state_id => "sprite_appention"
  53. # This means if the state is inflicted, the sprite will look for a graphic
  54. # that is the same name as the character's sprite, plus the appended option.
  55. # EX: Ralph's sprite's name is $ralph. Ralph gets knocked-out. This means
  56. # state 1 was inflicted, and my below config for 1 was: 1 => "_dead"
  57. # Now, his shown sprite will be $ralph_dead. If the sprite does not exist,
  58. # no change will be made.
  59. # The sprite index will be the same as the actor's.
  60. STATE_SPRITES = {
  61.  
  62. 1 => "_dead",
  63. 2 => "_poison",
  64. 3 => "_blind"
  65.  
  66. }
  67.  
  68. #===========================================================================
  69. # GENERAL_OPTIONS
  70. #===========================================================================
  71.  
  72. # This is the animation displayed when a skill is about to be used.
  73. SKILL_ANIMATION = 43
  74.  
  75. # This is the animation displayed when an item is about to be used.
  76. ITEM_ANIMATION = 43
  77.  
  78. # These are the animations played when a state is inflicted.
  79. # It follows this format: state_id => animation_id
  80. STATE_ANIMATIONS = {
  81.  
  82. 1 => 56,
  83. 2 => 50,
  84. 3 => 51
  85.  
  86. }
  87.  
  88. #===========================================================================
  89. # FIELD OPTIONS
  90. #===========================================================================
  91.  
  92. # This is where the line-up begins. [x, y]. The higher the x, the further
  93. # right and the higher the y the further down.
  94. FIELD_POS = [400, 230]
  95.  
  96. # This is how far down, and to the right each player is from the previous
  97. # actor. [x, y]. Same rules as above.
  98. FIELD_SPACING = [12, 50]
  99.  
  100. end
  101. end
  102.  
  103. #===============================================================================
  104. # DON'T EDIT FURTHER UNLESS YOU KNOW WHAT TO DO.
  105. #===============================================================================
  106.  
  107. ($imported ||= {})[:jet] ||= {}
  108. $imported[:jet][:Sideview] = true
  109.  
  110. class Game_Character
  111.  
  112. attr_accessor :step_anime
  113.  
  114. %w[screen_x screen_y].each {|a|
  115. aStr = %Q{
  116. alias jet6372_#{a} #{a}
  117. def #{a}(*args, &block)
  118. $BTEST ? 0 : jet6372_#{a}(*args, &block)
  119. end
  120. }
  121. module_eval(aStr)
  122. }
  123. end
  124.  
  125. class Game_Actor
  126.  
  127. def animation_id=(t)
  128. self.battle_sprite.start_animation($data_animations[t]) rescue nil
  129. end
  130. end
  131.  
  132. class Game_Battler
  133.  
  134. def battle_sprite
  135. return nil unless SceneManager.scene_is?(Scene_Battle)
  136. SceneManager.scene.spriteset.battler_sprites.each {|a|
  137. return a if a.battler == self
  138. }
  139. return nil
  140. end
  141. end
  142.  
  143. class Spriteset_Battle
  144.  
  145. alias jet2847_create_enemies create_enemies
  146. def create_enemies(*args, &block)
  147. jet2847_create_enemies(*args, &block)
  148. @enemy_sprites.each {|a|
  149. a.mirror = Jet::Sideview::FLIPPED_ENEMIES.include?(a.battler.enemy.id)
  150. }
  151. end
  152.  
  153. alias jet3835_create_actors create_actors
  154. def create_actors(*args, &block)
  155. jet3835_create_actors(*args, &block)
  156. @jet_party = $game_party.members
  157. @actor_sprites.each {|a|
  158. a.dispose
  159. }
  160. @actor_sprites = []
  161. $game_party.members.each {|a|
  162. f = Game_Character.new
  163. f.set_graphic(a.character_name, a.character_index)
  164. f.step_anime = true
  165. f.set_direction(4)
  166. n = Sprite_Character.new(@viewport1, f)
  167. n.jet_x = Jet::Sideview::FIELD_POS[0] + a.index * Jet::Sideview::FIELD_SPACING[0]
  168. n.jet_y = Jet::Sideview::FIELD_POS[1] + a.index * Jet::Sideview::FIELD_SPACING[1]
  169. n.battler = a
  170. n.battle_sprite = true
  171. if Jet::Sideview::PLAYER_SHADOW
  172. v = Sprite.new(nil)
  173. v.bitmap = Cache.system("Shadow")
  174. n.shadow_sprite = v
  175. end
  176. @actor_sprites.push(n)
  177. }
  178. end
  179.  
  180. def update_actors
  181. if @jet_party != $game_party.members
  182. @actor_sprites.each {|a|
  183. a.dispose
  184. }
  185. @actor_sprites = []
  186. create_actors
  187. end
  188. @actor_sprites.each {|a| a.update }
  189. end
  190. end
  191.  
  192. class Sprite_Character
  193.  
  194. attr_accessor :battle_sprite, :jet_x, :jet_y, :shadow_sprite, :battler
  195.  
  196. alias jet4646_initialize initialize
  197. def initialize(*args, &block)
  198. @battle_sprite = false
  199. jet4646_initialize(*args, &block)
  200. end
  201.  
  202. alias jet3645_update update
  203. def update(*args, &block)
  204. jet3645_update(*args, &block)
  205. if @battle_sprite
  206. @character.step_anime = !@battler.dead?
  207. @character.update
  208. self.x = @jet_x
  209. self.y = @jet_y
  210. if !@battler.nil?
  211. f = @battler.states.dup
  212. f.sort! {|a, b|
  213. a.priority <=> b.priority
  214. }.reverse!
  215. for i in 0...f.size
  216. a = Jet::Sideview::STATE_SPRITES[f[i].id]
  217. next if a.nil?
  218. b = (Cache.character(@character.character_name + a) rescue false)
  219. next unless b
  220. index = @character.character_index
  221. @character.set_graphic(@character.character_name + a, index)
  222. break
  223. end
  224. end
  225. if !@shadow_sprite.nil?
  226. @shadow_sprite.x = self.x - @shadow_sprite.width / 2
  227. @shadow_sprite.y = self.y - 28
  228. @shadow_sprite.visible = self.visible
  229. @shadow_sprite.viewport = self.viewport
  230. @shadow_sprite.z = self.z - 1
  231. end
  232. end
  233. end
  234.  
  235. alias jet5484_dispose dispose
  236. def dispose(*args, &block)
  237. @shadow_sprite.dispose if !@shadow_sprite.nil?
  238. jet5484_dispose(*args, &block)
  239. end
  240.  
  241. def move_x(times, amount)
  242. i = 0
  243. until i == times
  244. self.jet_x += amount
  245. i += 1
  246. [Graphics, SceneManager.scene.spriteset].each {|a| a.update }
  247. end
  248. end
  249.  
  250. def effect?
  251. false
  252. end
  253. end
  254.  
  255. class Game_Enemy
  256.  
  257. def atk_animation_id1
  258. return Jet::Sideview::ENEMY_ATK_ANIMS[@enemy_id]
  259. end
  260.  
  261. def atk_animation_id2
  262. return 0
  263. end
  264. end
  265.  
  266. class Scene_Battle
  267.  
  268. attr_reader :spriteset
  269.  
  270. alias jet2711_use_item use_item
  271. def use_item(*args, &block)
  272. if @subject.is_a?(Game_Actor)
  273. if !@subject.current_action.guard?
  274. @subject.battle_sprite.move_x(11, -6)
  275. end
  276. end
  277. if !@subject.current_action.guard? && !@subject.current_action.attack?
  278. if @subject.current_action.item.is_a?(RPG::Item)
  279. n = $data_animations[Jet::Sideview::ITEM_ANIMATION]
  280. else
  281. n = $data_animations[Jet::Sideview::SKILL_ANIMATION]
  282. end
  283. @subject.battle_sprite.start_animation(n)
  284. wait_for_animation
  285. end
  286. jet2711_use_item(*args, &block)
  287. if @subject.is_a?(Game_Actor)
  288. if !@subject.current_action.guard?
  289. @subject.battle_sprite.move_x(11, 6)
  290. end
  291. end
  292. end
  293.  
  294. def show_attack_animation(targets)
  295. aid1 = @subject.atk_animation_id1
  296. aid2 = @subject.atk_animation_id2
  297. show_normal_animation(targets, aid1, false)
  298. show_normal_animation(targets, aid2, true)
  299. end
  300.  
  301. %w[next prior].each {|a|
  302. aStr = %Q{
  303. alias jet3734_#{a}_command #{a}_command
  304. def #{a}_command(*args, &block)
  305. f = BattleManager.actor
  306. f.battle_sprite.move_x(6, 6) if f.is_a?(Game_Actor)
  307. jet3734_#{a}_command(*args, &block)
  308. f = BattleManager.actor
  309. f.battle_sprite.move_x(6, -6) if f.is_a?(Game_Actor)
  310. end
  311. }
  312. module_eval(aStr)
  313. }
  314. end
  315.  
  316. class Game_Action
  317.  
  318. def guard?
  319. item == $data_skills[subject.guard_skill_id]
  320. end
  321. end
  322.  
  323. if $imported[:jet][:BattlePopUps]
  324. class Sprite_Character
  325.  
  326. attr_accessor :popups
  327.  
  328. alias jet4758_initialize initialize
  329. def initialize(*args, &block)
  330. @popups = []
  331. @updating_sprites = []
  332. @popup_wait = 0
  333. jet4758_initialize(*args, &block)
  334. end
  335.  
  336. alias jet7467_update update
  337. def update(*args, &block)
  338. jet7467_update(*args, &block)
  339. if @popup_wait == 0
  340. if !@popups.empty?
  341. @updating_sprites.push(@popups.pop)
  342. @popup_wait = 30
  343. end
  344. else
  345. @popup_wait -= 1
  346. end
  347. @updating_sprites.each {|a|
  348. a.visible = true if !a.visible
  349. a.update
  350. @updating_sprites.delete(a) if a.disposed?
  351. }
  352. end
  353.  
  354. alias jet5483_dispose dispose
  355. def dispose(*args, &block)
  356. (@updating_sprites + @popups).each {|a| a.dispose }
  357. jet5483_dispose(*args, &block)
  358. end
  359.  
  360. alias jet3745_setup_new_effect setup_new_effect
  361. def setup_new_effect(*args, &block)
  362. jet3745_setup_new_effect(*args, &block)
  363. do_sprite_popups
  364. end
  365.  
  366. def make_popup(text, color)
  367. @popups.unshift(Sprite_JetPopup.new(text.to_s, color, self))
  368. end
  369.  
  370. def do_sprite_popups
  371. return if @battler.nil?
  372. if @battler_struct.nil?
  373. @battler_struct = Struct.new(:hp, :mp, :tp).new(0, 0, 0)
  374. @battler_struct.hp = @battler.hp
  375. @battler_struct.mp = @battler.mp
  376. @battler_struct.tp = @battler.tp
  377. end
  378. check_success_popup
  379. check_hp_popup
  380. check_mp_popup
  381. check_tp_popup
  382. end
  383.  
  384. def check_success_popup
  385. if @battler.result.success
  386. if @battler.result.critical
  387. make_popup(Jet::BattlePopUps::CRITICAL_TEXT, Jet::BattlePopUps::CRITICAL_COLOR)
  388. elsif @battler.result.missed
  389. make_popup(Jet::BattlePopUps::MISSED_TEXT, Jet::BattlePopUps::MISS_COLOR)
  390. elsif @battler.result.evaded
  391. make_popup(Jet::BattlePopUps::EVADED_TEXT, Jet::BattlePopUps::EVADE_COLOR)
  392. end
  393. @battler.result.clear_hit_flags
  394. end
  395. end
  396.  
  397. def check_hp_popup
  398. if @battler_struct.hp != @battler.hp
  399. f = @battler_struct.hp - @battler.hp
  400. if f > 0
  401. make_popup(Jet::BattlePopUps::HURT_TEXT + f.to_s, Jet::BattlePopUps::HURT_COLOR)
  402. elsif f < 0
  403. make_popup(Jet::BattlePopUps::HEAL_TEXT + f.abs.to_s, Jet::BattlePopUps::HEAL_COLOR)
  404. end
  405. @battler_struct.hp = @battler.hp
  406. end
  407. end
  408.  
  409. def check_mp_popup
  410. if @battler_struct.mp != @battler.mp
  411. f = @battler_struct.mp - @battler.mp
  412. if f > 0
  413. make_popup(Jet::BattlePopUps::HURT_TEXT_MP + f.to_s, Jet::BattlePopUps::HURT_COLOR_MP)
  414. elsif f < 0
  415. make_popup(Jet::BattlePopUps::HEAL_TEXT_MP + f.abs.to_s, Jet::BattlePopUps::HEAL_COLOR_MP)
  416. end
  417. @battler_struct.mp = @battler.mp
  418. end
  419. end
  420.  
  421. def check_tp_popup
  422. if @battler_struct.tp != @battler.tp
  423. f = (@battler_struct.tp - @battler.tp).round
  424. if f > 0
  425. make_popup(Jet::BattlePopUps::HURT_TEXT_TP + f.to_s, Jet::BattlePopUps::HURT_COLOR_TP)
  426. elsif f < 0
  427. make_popup(Jet::BattlePopUps::HEAL_TEXT_TP + f.abs.to_s, Jet::BattlePopUps::HEAL_COLOR_TP)
  428. end
  429. @battler_struct.tp = @battler.tp
  430. end
  431. end
  432. end
  433. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement