Guest User

Untitled

a guest
Sep 24th, 2015
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.46 KB | None | 0 0
  1. #Formation Bonus v1.3
  2. #----------#
  3. #Features: Rearrange actors by rows and make formations, granting bonuses
  4. # based on what row and formation the actors are in.
  5. #
  6. #Usage: Plug and play, customize as needed.
  7. #
  8. #----------#
  9. #-- Script by: V.M of D.T
  10. #
  11. #- Questions or comments can be:
  12. # posted on the thread for the script
  13. # given by email: sumptuaryspade@live.ca
  14. # provided on facebook: http://www.facebook.com/DaimoniousTailsGames
  15. # All my other scripts and projects can be found here: http://daimonioustails.weebly.com/
  16. #
  17. #--- Free to use in any project, commercial or non-commercial, with credit given
  18. # - - Though a donation's always a nice way to say thank you~ (I also accept actual thank you's)
  19.  
  20. #Location for actor sprites in battle:
  21. FORMATION_ROWS = 3
  22. FORMATION_COLS = 3
  23. #Set a number of locations equal to rows * cols
  24. FORMATION_LOCATIONS = [
  25. [375,200],[425,200],[475,200],
  26. [395,230],[445,230],[495,230],
  27. [415,260],[465,260],[515,260]]
  28.  
  29. FORMATION_SX = 20
  30.  
  31. #Icon to be displayed as formation slot in the Formation Changing Scene.
  32. FORMATION_ICON = 430
  33. #Change in damage given/recieved based on row position:
  34. #Front row, middle row, back row
  35. FORMATION_ROW_ATK = [1.0, 0.8, 0.5]
  36. FORMATION_ROW_DEF = [1.0, 0.8, 0.5]
  37. FORMATION_ROW_MAT = [1.0, 1.0, 1.0]
  38. FORMATION_ROW_MDF = [1.0, 1.0, 1.0]
  39. FORMATION_ROW_TGR = [2.0, 1.0, 0.5]
  40.  
  41. #The special Formations actors can be placed in:
  42. # id => { :name => "name of formation", :slots = [slots to be filled], ... }
  43. # Slot ids are:
  44. # 0,1,2
  45. # 3,4,5
  46. # 6,7,8
  47. # Stat options are: :hp, :mp, :atk, :def, :mat, :mdf, :agi, :luk
  48. # Formation bonuses apply to all actors.
  49. # Example:
  50. # 1 => { :name => "Back Row", :slots => [2,5,8], :hp => 20, :mp => 5,}
  51. FORMATION_BONUS = { 0 => {},
  52. 1 => { :name => "One Liner", :slots => [3,4,5], :hp => 20,}
  53. }
  54. class Game_Actor < Game_Battler
  55. attr_accessor :formation_slot
  56. alias formation_init initialize
  57. alias formation_param param
  58. def initialize(actor_id)
  59. formation_init(actor_id)
  60. @formation_slot = -1
  61. end
  62. def screen_x
  63. FORMATION_LOCATIONS[@formation_slot][0]
  64. end
  65. def screen_y
  66. FORMATION_LOCATIONS[@formation_slot][1]
  67. end
  68. def front_row?
  69. array = []
  70. FORMATION_ROWS.times do |i|
  71. array.push(FORMATION_COLS * i)
  72. end
  73. array.include?(@formation_slot)
  74. end
  75. def middle_row?
  76. !front_row? && !back_row?
  77. end
  78. def back_row?
  79. array = []
  80. FORMATION_ROWS.times do |i|
  81. array.push(FORMATION_COLS * i + FORMATION_COLS - 1)
  82. end
  83. array.include?(@formation_slot)
  84. end
  85. def param(param_id)
  86. sym = [:hp,:mp,:atk,:def,:mat,:mdf,:agi,:luk]
  87. value = formation_param(param_id)
  88. if $game_party.short_form[sym[param_id]]
  89. value *= ($game_party.short_form[sym[param_id]] * 0.01 + 1)
  90. end
  91. [[value, param_max(param_id)].min, param_min(param_id)].max.to_i
  92. end
  93. end
  94.  
  95. class Game_Enemy < Game_Battler
  96. def front_row?
  97. true
  98. end
  99. def middle_row?
  100. false
  101. end
  102. def back_row?
  103. false
  104. end
  105. end
  106.  
  107. class Game_Battler
  108. def tgr
  109. return sparam(0) * FORMATION_ROW_TGR[2] if back_row?
  110. return sparam(0) * FORMATION_ROW_TGR[1] if middle_row?
  111. return sparam(0) * FORMATION_ROW_TGR[0]
  112. end
  113. def make_damage_value(user, item)
  114. value = item.damage.eval(user, self, $game_variables)
  115. value *= item_element_rate(user, item)
  116. value *= pdr if item.physical?
  117. value *= mdr if item.magical?
  118. value *= rec if item.damage.recover?
  119. value *= row_defense if item.physical? && !item.damage.recover?
  120. value *= row_attack(user) if item.physical? && !item.damage.recover?
  121. value *= row_magic_attack(user) if item.magical? && !item.damage.recover?
  122. value *= row_magic_defense if item.magical? && !item.damage.recover?
  123. value = apply_critical(value) if @result.critical
  124. value = apply_variance(value, item.damage.variance)
  125. value = apply_guard(value)
  126. @result.make_damage(value.to_i, item)
  127. end
  128. def row_defense
  129. return FORMATION_ROW_DEF[1] if middle_row?
  130. return FORMATION_ROW_DEF[2] if back_row?
  131. return FORMATION_ROW_DEF[0]
  132. end
  133. def row_attack(user)
  134. return FORMATION_ROW_ATK[2] if user.back_row?
  135. return FORMATION_ROW_ATK[1] if user.middle_row?
  136. return FORMATION_ROW_ATK[0]
  137. end
  138. def row_magic_defense
  139. return FORMATION_ROW_MDF[1] if middle_row?
  140. return FORMATION_ROW_MDF[2] if back_row?
  141. return FORMATION_ROW_MDF[0]
  142. end
  143. def row_magic_attack(user)
  144. return FORMATION_ROW_MAT[2] if user.back_row?
  145. return FORMATION_ROW_MAT[1] if user.middle_row?
  146. return FORMATION_ROW_MAT[0]
  147. end
  148. end
  149.  
  150. class Game_Party
  151. attr_accessor :formation_id
  152. def first_available_slot
  153. end
  154. def formation_slot(id)
  155. battle_members.each do |actor|
  156. return actor if actor.formation_slot == id
  157. end
  158. return nil
  159. end
  160. def formation_name
  161. return current_formation[:name] if current_formation
  162. return "-----"
  163. end
  164. def setup_starting_members
  165. @actors = $data_system.party_members.clone
  166. iter = 0
  167. battle_members.each do |actor|
  168. actor.formation_slot = iter
  169. iter += 1
  170. end
  171. current_formation
  172. end
  173. def current_formation
  174. FORMATION_BONUS.each do |sym, form|
  175. next if sym == 0
  176. valid = true
  177. form[:slots].each do |val|
  178. valid = false unless formation_slot(val)
  179. end
  180. next unless valid
  181. @formation_id = sym
  182. return FORMATION_BONUS[sym]
  183. end
  184. @formation_id = 0
  185. return nil
  186. end
  187. def short_form
  188. @formation_id = 0 unless @formation_id
  189. FORMATION_BONUS[@formation_id]
  190. end
  191. def add_actor(actor_id)
  192. return if @actors.include?(actor_id)
  193. @actors.push(actor_id)
  194. (FORMATION_ROWS * FORMATION_COLS).times do |i|
  195. if formation_slot(i).nil?
  196. $game_actors[actor_id].formation_slot = i
  197. break
  198. end
  199. end
  200. $game_player.refresh
  201. $game_map.need_refresh = true
  202. end
  203. def remove_actor(actor_id)
  204. return unless @actors.include?(actor_id)
  205. @actors.delete(actor_id)
  206. $game_actors[actor_id].formation_slot = -1
  207. $game_player.refresh
  208. $game_map.need_refresh = true
  209. end
  210. end
  211.  
  212. class Scene_Formation < Scene_Base
  213. def start
  214. super
  215. @help_window = Window_Help.new(1)
  216. @list_window = Window_FormList.new
  217. @list_window.set_handler(:ok, method(:list_ok))
  218. @list_window.set_handler(:cancel, method(:list_cancel))
  219. @bonus_window = Window_FormBonus.new
  220. @form_window = Window_Formation.new
  221. @form_window.set_handler(:ok, method(:form_ok))
  222. @form_window.set_handler(:cancel, method(:form_cancel))
  223. @stat_window = Window_FormStat.new
  224. @list_window.select(0)
  225. @list_window.activate
  226. end
  227. def update
  228. super
  229. if @list_window.active
  230. @stat_window.set_actor(@list_window.current_item)
  231. elsif @form_window.active
  232. if @form_window.current_item
  233. @stat_window.set_actor(@form_window.current_item)
  234. else
  235. @stat_window.set_actor(@list_window.current_item)
  236. end
  237. end
  238. end
  239. def list_ok
  240. @form_window.select(@list_window.current_item.formation_slot)
  241. @form_window.activate
  242. end
  243. def list_cancel
  244. SceneManager.return
  245. end
  246. def form_ok
  247. index = @form_window.current_index
  248. actor = @list_window.current_item
  249. if $game_party.formation_slot(index)
  250. $game_party.formation_slot(index).formation_slot = actor.formation_slot
  251. end
  252. actor.formation_slot = index
  253. @form_window.refresh
  254. @bonus_window.refresh
  255. @stat_window.refresh
  256. form_cancel
  257. end
  258. def form_cancel
  259. @form_window.select(-1)
  260. @list_window.activate
  261. end
  262. end
  263.  
  264. class Window_FormList < Window_Selectable
  265. def initialize
  266. super(0,48,Graphics.width/5*2,(Graphics.height-48)/2)
  267. refresh
  268. end
  269. def item_max
  270. $game_party.battle_members.size
  271. end
  272. def draw_item(index)
  273. actor = $game_party.battle_members[index]
  274. rect = item_rect(index)
  275. draw_text(rect, actor.name)
  276. draw_text(rect, "Lvl ",2)
  277. draw_text(rect, actor.level,2)
  278. end
  279. def current_item
  280. return $game_party.battle_members[@index] if @index >= 0
  281. return nil
  282. end
  283. end
  284.  
  285. class Window_FormBonus < Window_Base
  286. def initialize
  287. super(Graphics.width/5*2,48+(Graphics.height-48)/3*2,Graphics.width/5*3+3,(Graphics.height-48)/3+2)
  288. refresh
  289. end
  290. def refresh
  291. contents.clear
  292. change_color(system_color)
  293. draw_text(0,0,contents.width,line_height,"Bonuses:")
  294. return unless $game_party.current_formation
  295. change_color(normal_color)
  296. form = $game_party.current_formation
  297. xx = 6;yy = line_height;iter = 1
  298. form.each do |key, val|
  299. next unless [:hp,:mp,:atk,:def,:mat,:mdf,:agi,:luk].include?(key)
  300. case key
  301. when :hp
  302. text = sprintf("%s %+d%", Vocab::hp, val.to_s)
  303. when :mp
  304. text = sprintf("%s %+d%", Vocab::mp, val.to_s)
  305. when :atk
  306. text = sprintf("%s %+d%", Vocab::param(2), val.to_s)
  307. when :def
  308. text = sprintf("%s %+d%", Vocab::param(3), val.to_s)
  309. when :mat
  310. text = sprintf("%s %+d%", Vocab::param(4), val.to_s)
  311. when :mdf
  312. text = sprintf("%s %+d%", Vocab::param(5), val.to_s)
  313. when :agi
  314. text = sprintf("%s %+d%", Vocab::param(6), val.to_s)
  315. when :luk
  316. text = sprintf("%s %+d%", Vocab::param(7), val.to_s)
  317. end
  318. draw_text(xx,yy,contents.width/3,line_height,text)
  319. xx += contents.width/3
  320. if iter % 3 == 0
  321. xx = 5; yy += line_height
  322. end
  323. iter += 1
  324. end
  325. end
  326. end
  327.  
  328. class Window_Formation < Window_Selectable
  329. def initialize
  330. super(Graphics.width/5*2,48,Graphics.width/5*3+3,(Graphics.height-48)/3*2)
  331. refresh
  332. end
  333. def refresh
  334. contents.clear
  335. xx = FORMATION_SX;yy = contents.height/3;iter = 0
  336. FORMATION_ROWS.times do
  337. FORMATION_COLS.times do
  338. draw_icon(FORMATION_ICON,xx,yy,$game_party.formation_slot(iter))
  339. if $game_party.formation_slot(iter)
  340. draw_actor_graphic($game_party.formation_slot(iter),xx-4,yy-16)
  341. end
  342. xx += 50
  343. iter += 1
  344. end
  345. xx -= FORMATION_COLS * 50
  346. yy += 30;xx += 10
  347. end
  348. change_color(system_color)
  349. draw_text(0,0,contents.width,line_height,"Formation: ")
  350. change_color(normal_color)
  351. draw_text(106,0,contents.width,line_height,$game_party.formation_name)
  352. end
  353. def item_rect(index)
  354. xx = FORMATION_SX;yy = contents.height/3
  355. xx += index % col_max * 50
  356. xx += 10 * (index / col_max).to_i
  357. yy += 30 * (index / col_max).to_i
  358. Rect.new(xx,yy,24,24)
  359. end
  360. def col_max; FORMATION_COLS; end
  361. def row_max; FORMATION_ROWS; end
  362. def item_max; FORMATION_COLS * FORMATION_ROWS; end
  363. def current_item
  364. $game_party.formation_slot(@index) ? $game_party.formation_slot(@index) : nil
  365. end
  366. def current_index
  367. @index
  368. end
  369. def draw_actor_graphic(actor,x,y)
  370. new_bitmap = Cache.character(actor.character_name)
  371. next_bitmap = new_bitmap.clone
  372. xx = actor.character_index % 4 * new_bitmap.width/4
  373. yy = actor.character_index / 4 * new_bitmap.height/2
  374. next_bitmap.blt(0,0,next_bitmap,Rect.new(xx,yy,next_bitmap.width/4,next_bitmap.height/2))
  375. contents.blt(x,y,next_bitmap,Rect.new(0,next_bitmap.height/8,next_bitmap.width/12,next_bitmap.height/8))
  376. end
  377. end
  378.  
  379. class Window_FormStat < Window_Base
  380. def initialize
  381. super(0,48+(Graphics.height-48)/2,Graphics.width/5*2,(Graphics.height-48)/2)
  382. refresh
  383. end
  384. def refresh
  385. contents.clear
  386. change_color(system_color)
  387. draw_text(0,line_height,contents.width,line_height,"Class:")
  388. draw_text(0,line_height*2,contents.width/2,line_height,Vocab::hp)
  389. draw_text(contents.width/2,line_height*2,contents.width/2,line_height,Vocab::mp)
  390. draw_text(0,line_height*3,contents.width/2,line_height,Vocab::param(2))
  391. draw_text(contents.width/2,line_height*3,contents.width/2,line_height,Vocab::param(3))
  392. draw_text(0,line_height*4,contents.width/2,line_height,Vocab::param(4))
  393. draw_text(contents.width/2,line_height*4,contents.width/2,line_height,Vocab::param(5))
  394. draw_text(0,line_height*5,contents.width/2,line_height,Vocab::param(6))
  395. draw_text(contents.width/2,line_height*5,contents.width/2,line_height,Vocab::param(7))
  396. contents.fill_rect(contents.width/2-2,line_height*2.5,1,line_height*3,Color.new(155,155,155))
  397. return unless @actor
  398. change_color(normal_color)
  399. draw_actor_graphic(@actor,contents.width/2,32)
  400. draw_text(0,line_height,contents.width,line_height,@actor.class.name,2)
  401. draw_text(0,line_height*2,contents.width/2,line_height,@actor.mhp,2)
  402. draw_text(contents.width/2,line_height*2,contents.width/2,line_height,@actor.mmp,2)
  403. draw_text(0,line_height*3,contents.width/2,line_height,@actor.atk,2)
  404. draw_text(contents.width/2,line_height*3,contents.width/2,line_height,@actor.def,2)
  405. draw_text(0,line_height*4,contents.width/2,line_height,@actor.mat,2)
  406. draw_text(contents.width/2,line_height*4,contents.width/2,line_height,@actor.mdf,2)
  407. draw_text(0,line_height*5,contents.width/2,line_height,@actor.agi,2)
  408. draw_text(contents.width/2,line_height*5,contents.width/2,line_height,@actor.luk,2)
  409. end
  410. def set_actor(actor)
  411. return if @actor == actor
  412. @actor = actor
  413. refresh
  414. end
  415. end
  416.  
  417. #~ class Scene_Menu
  418. #~ def command_formation
  419. #~ SceneManager.call(Scene_Formation)
  420. #~ end
  421. #~ end
  422.  
  423. class Window_MenuCommand < Window_Command
  424.  
  425. alias formation1_command add_original_commands
  426.  
  427. def add_original_commands
  428.  
  429. formation1_command
  430.  
  431. add_command("Formation1", :formation1)
  432.  
  433. end
  434.  
  435. end
  436.  
  437. if $imported["YEA-AceMenuEngine"] #This line is optional only for Yanfly's Menu Engine script
  438.  
  439. class Scene_Menu < Scene_MenuBase
  440.  
  441. alias formation1_menu13211 create_command_window
  442.  
  443. #--------------------------------------------------------------------------
  444.  
  445. # * Create Command Window
  446.  
  447. #--------------------------------------------------------------------------
  448.  
  449. def create_command_window
  450.  
  451. formation1_menu13211()
  452.  
  453. @command_window.set_handler(:formation1, method(:command_formation1))
  454.  
  455. end
  456.  
  457. #--------------------------------------------------------------------------
  458.  
  459. # * New Formation Command
  460.  
  461. #--------------------------------------------------------------------------
  462.  
  463. def command_formation1
  464.  
  465. SceneManager.call(Scene_Formation)
  466.  
  467. end
  468.  
  469. end
  470.  
  471. end #This line is optional only for Yanfly's Menu Engine script
  472.  
  473. class Window_MenuCommand
  474. def formation_enabled
  475. true
  476. end
  477. end
Add Comment
Please, Sign In to add comment