Advertisement
dsiver144

DSI Unit System

Jan 27th, 2018
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 56.64 KB | None | 0 0
  1. #==============================================================================
  2. # DSI Unit System
  3. # -- Last Updated: 2018.1.27
  4. # -- Author: dsiver144
  5. # -- Level: Hard
  6. # -- Requires: n/a
  7. #==============================================================================
  8. $imported = {} if $imported.nil?
  9. $imported["DSI-UnitSystem"] = true
  10. #==============================================================================
  11. # + Updates
  12. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  13. # 2018.1.16 - Finish first version.
  14. # 2018.1.17 - Update more script call, notetags.
  15. # 2018.1.18 - Update more script call, notetags.
  16. # 2018.1.27 - Fix graphical bug.
  17. #==============================================================================
  18. # + Instructions
  19. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  20. # To install this script, open up your script editor and copy/paste this script
  21. # to an open slot below ▼Materials but above ▼Main. Remember to save.
  22. #==============================================================================
  23. # Enemy Notetag: <enemy unit> : For the game know that enemy is a unit
  24. #==============================================================================
  25. # Actor Notetags:
  26. # Example:
  27. # <unit actor>
  28. # battler: Skull Demon
  29. # battler offset: 0, 0
  30. # battler trans: Skull Demon 2
  31. # skill set: 17, 18, 19
  32. # passive: 29, 512 # State ID, Skill ID
  33. # transform state id: 29
  34. # attack skill id: 1
  35. # spawn common event id: 34
  36. # die common event id: 35
  37. # disable command: attack, skill, transform (* new)
  38. # transform animation: 4 ( * new )
  39. #
  40. # unit trans effect: learn_skill 10 ( * new )
  41. # unit trans effect: mhp 10 ( * new )
  42. # unit trans effect: new_passive 25 522 ( * new )
  43. # unit trans effect: enable attack skill ( * new )
  44. # unit trans effect: disable transform ( * new )
  45. # unit trans effect: new_attack_skill 1 ( * new )
  46. # unit trans effect: mmp 5 ( * new )
  47. #
  48. # transform call common event: true, 36 ( * new )
  49. #
  50. # <end unit actor>
  51. # ----------------------------------------------------------------------------
  52. # Script Call:
  53. # enable_unit_slot(slot_id) -> To Unlock Slot from being locked
  54. # disable_unit_slot(slot_id) -> To lock a slot.
  55. # * New Script calls:
  56. # - random_summon_unit(unit_id)
  57. # - summon_unit(unit_id, slot_id)
  58. # * Conditional Script Call:
  59. # - has_player_unit_on_slotX?(slot_id)
  60. # - unit_has_skill?(slot_id, skill_id)
  61. # - unit_has_state?(slot_id, state_id)
  62. # - force_transform(slot_id, tp_cost = 0, enable_transform_in_turn = false) ( * new )
  63. # - destroy_unit(slot_id, return_card = true)
  64. # eg: destroy_unit(4) # Destroy Unit on slot 4
  65. # - destroy_all_unit(return_card = true)
  66. # eg: destroy_all_unit(true) # Destroy all player units. If there was no unit
  67. # being destroyed then return the card to player hand.
  68. # - inflict_state_unit(slot_id, state_id, return_card = true)
  69. # - inflict_state_all_unit(state_id, return_card = true)
  70. # Conditional Branches Script call:
  71. # - lastest_unit_placement?(type) : type = :offense , :defense
  72. # eg: lastest_unit_placement?(:offense) # Check if lastest placement is offense slot
  73. # eg: lastest_unit_placement?(:defense) # Check if lastest placement is defense slot
  74. # -----------------------------------------------------------------------------
  75. # Skill Notetag: <summon unit: unit_id> -> Summon a certain unit to battle.
  76. # Force target to transform if target is player unit and unit is
  77. # not transform.
  78. # <force unit transform: tp_cost, enable_more_than_1_summon_rule, return_card>
  79. # eg: <force unit transform: 0, true, true>
  80. # -> This will force target unit transform. You can still transform another
  81. # units in this turn. If the target was transformed then return the card to
  82. # player hand.
  83. # - <refresh unit attack> : Refresh Unit Attack/Skill Command if disabled.
  84. #===============================================================================
  85. module DSIVER144
  86. module UNIT_SYSTEM
  87.  
  88. SLOT_COORDINATES = {}
  89. SLOT_COORDINATES[:player] = {}
  90. SLOT_COORDINATES[:player][1] = [301 + 40,252]
  91. SLOT_COORDINATES[:player][2] = [301 + 40,251 + 25]
  92. SLOT_COORDINATES[:player][3] = [301 + 40,250 + 25*2]
  93. SLOT_COORDINATES[:player][4] = [300,252]
  94. SLOT_COORDINATES[:player][5] = [300,251 + 25]
  95. SLOT_COORDINATES[:player][6] = [300,250 + 25*2]
  96.  
  97.  
  98. SLOT_DISABLE_SWITCHES = {}
  99. SLOT_DISABLE_SWITCHES[1] = 81
  100. SLOT_DISABLE_SWITCHES[2] = 82
  101. SLOT_DISABLE_SWITCHES[3] = 83
  102. SLOT_DISABLE_SWITCHES[4] = 84
  103. SLOT_DISABLE_SWITCHES[5] = 85
  104. SLOT_DISABLE_SWITCHES[6] = 86
  105.  
  106. UNIT_CONFIG = {}
  107. UNIT_CONFIG[5] = {}
  108. UNIT_CONFIG[5][:transform] = {} #Shade Man
  109. UNIT_CONFIG[5][:transform][:desc] = "Max HP +2, Max MP +2, Attack does 2 more DMG."
  110. UNIT_CONFIG[5][:transform][:desc_offset] = [0, -10]
  111. UNIT_CONFIG[6] = {}
  112. UNIT_CONFIG[6][:transform] = {} #Pulsar Bat
  113. UNIT_CONFIG[6][:transform][:desc] = "Max HP +2, Max MP +2, Attack does 1 more DMG."
  114. UNIT_CONFIG[6][:transform][:desc_offset] = [0, -10]
  115. UNIT_CONFIG[7] = {}
  116. UNIT_CONFIG[7][:transform] = {} #Skull Demon
  117. UNIT_CONFIG[7][:transform][:desc] = "Max HP +4, Max MP +2, Attack does 2 more DMG."
  118. UNIT_CONFIG[7][:transform][:desc_offset] = [0, -10]
  119. UNIT_CONFIG[8] = {}
  120. UNIT_CONFIG[8][:transform] = {} #Laser Man
  121. UNIT_CONFIG[8][:transform][:desc] = "Max HP +2, Max MP +2, Attack does 1 more DMG."
  122. UNIT_CONFIG[8][:transform][:desc_offset] = [0, -10]
  123. UNIT_CONFIG[9] = {}
  124. UNIT_CONFIG[9][:transform] = {} #Protecto
  125. UNIT_CONFIG[9][:transform][:desc] = "Max HP +3, Max MP +3."
  126. UNIT_CONFIG[9][:transform][:desc_offset] = [0, -10]
  127. UNIT_CONFIG[10] = {}
  128. UNIT_CONFIG[10][:transform] = {} #Coffin
  129. UNIT_CONFIG[10][:transform][:desc] = "???"
  130. UNIT_CONFIG[10][:transform][:desc_offset] = [0, -10]
  131. UNIT_CONFIG[11] = {}
  132. UNIT_CONFIG[11][:transform] = {} #The Count
  133. UNIT_CONFIG[11][:transform][:desc] = "Max HP +2, Max MP +2, Attack does 2 more DMG."
  134. UNIT_CONFIG[11][:transform][:desc_offset] = [0, -10]
  135.  
  136. DEFAULT_UNIT_APPEAR_COMMON_EVENT_ID = 6
  137. DEFAULT_UNIT_DISAPPEAR_COMMON_EVENT_ID = 7
  138.  
  139. end # UNIT_SYSTEM
  140. end # DSIVER144
  141.  
  142. class Game_Party
  143.  
  144. attr_accessor :can_perform_transform
  145. attr_accessor :battle_units
  146. attr_accessor :units_order
  147. attr_accessor :passives
  148. attr_accessor :lastest_unit
  149.  
  150. #---------------------------------------------------------------------------
  151. # * alias method: initialize
  152. #---------------------------------------------------------------------------
  153. alias_method(:initialize_dsi_unit_system, :initialize)
  154. def initialize
  155. initialize_dsi_unit_system
  156. init_battle_units
  157. end
  158. #---------------------------------------------------------------------------
  159. # * alias method: battle_members
  160. #---------------------------------------------------------------------------
  161. alias_method(:dsi_unit_system_battle_members, :battle_members)
  162. def battle_members
  163. dsi_unit_system_battle_members + (@battle_units ? @battle_units.values : [])
  164. end
  165. #--------------------------------------------------------------------------
  166. # * Processing at Start of Battle
  167. #--------------------------------------------------------------------------
  168. alias_method(:dsi_unit_system_on_battle_start, :on_battle_start)
  169. def on_battle_start
  170. @battle_units ||= {}
  171. @units_order ||= []
  172. @can_perform_transform = true
  173. dsi_unit_system_on_battle_start
  174. end
  175. #---------------------------------------------------------------------------
  176. # * new method: not_unit_members
  177. #---------------------------------------------------------------------------
  178. def not_unit_members
  179. battle_members - (@battle_units ? @battle_units.values : [])
  180. end
  181. #--------------------------------------------------------------------------
  182. # * Get Members
  183. #--------------------------------------------------------------------------
  184. def members(include_unit = false)
  185. if !include_unit
  186. in_battle ? not_unit_members : all_members
  187. else
  188. in_battle ? battle_members : all_members
  189. end
  190. end
  191. #---------------------------------------------------------------------------
  192. # * new method: initialize
  193. #---------------------------------------------------------------------------
  194. def init_battle_units
  195. @battle_units = {}
  196. @units_order = []
  197. @can_perform_transform = true
  198. @lastest_unit = nil
  199. end
  200. #--------------------------------------------------------------------------
  201. # * Processing at End of Battle
  202. #--------------------------------------------------------------------------
  203. alias_method(:dsi_unit_system_on_battle_end, :on_battle_end)
  204. def on_battle_end
  205. dsi_unit_system_on_battle_end
  206. @battle_units.clear
  207. @units_order.clear
  208. @can_perform_transform = true
  209. @lastest_unit = nil
  210. end
  211. #---------------------------------------------------------------------------
  212. # * new method: reset_units
  213. #---------------------------------------------------------------------------
  214. def reset_units
  215. @can_perform_transform = true
  216. @battle_units.values.each do |unit|
  217. unit.can_attack = true
  218. unit.on_turn_end
  219. end
  220. end
  221. #---------------------------------------------------------------------------
  222. # * new method: summon_unit
  223. #---------------------------------------------------------------------------
  224. def summon_unit(actor_id, slot_id)
  225. if @battle_units.has_key?(slot_id)
  226. return false
  227. end
  228. new_unit = Game_ActorUnit.new(actor_id)
  229. new_unit.slot_id = slot_id
  230. new_unit.load_unit_passive
  231. new_unit.load_attack_skill
  232. new_unit.load_unit_disable_commands
  233. new_unit.add_state(new_unit.passives[0])
  234. new_unit.can_attack = true
  235. new_unit.can_transform = true
  236. @battle_units[slot_id] = new_unit
  237. @units_order << new_unit
  238. @lastest_unit = new_unit
  239. return true
  240. end
  241. #--------------------------------------------------------------------------
  242. # * Get Maximum Number of Battle Units
  243. #--------------------------------------------------------------------------
  244. def max_units
  245. return 6
  246. end
  247. #--------------------------------------------------------------------------
  248. # * Get Array of Living Members including alive unit
  249. #--------------------------------------------------------------------------
  250. def alive_members
  251. members.select {|member| member.alive? } + @battle_units.values.select {|unit| unit.alive? }
  252. end
  253. #--------------------------------------------------------------------------
  254. # * Determine Everyone is Dead
  255. #--------------------------------------------------------------------------
  256. def all_dead?
  257. (alive_members - @battle_units.values.select {|unit| unit.alive?}).empty?
  258. end
  259.  
  260. end # Game_Troop
  261.  
  262. class Game_ActorUnit < Game_Actor
  263. include DSIVER144::UNIT_SYSTEM
  264. attr_accessor :battle_unit_flag
  265. attr_accessor :can_attack
  266. attr_accessor :can_transform
  267. attr_accessor :transformed
  268. attr_accessor :unit_attack_skill_id
  269. attr_accessor :slot_id
  270. attr_accessor :passives
  271. attr_accessor :on_finish_collapse_method
  272. attr_accessor :disable_commands
  273. #---------------------------------------------------------------------------
  274. # * new method: reset_turn
  275. #---------------------------------------------------------------------------
  276. def reset_turn
  277. @can_attack = true
  278. end
  279. #---------------------------------------------------------------------------
  280. # * new method: load_attack_skill
  281. #---------------------------------------------------------------------------
  282. def load_attack_skill
  283. @unit_attack_skill_id = actor.unit_attack_skill_id
  284. end
  285. #---------------------------------------------------------------------------
  286. # * new method: load_unit_passive
  287. #---------------------------------------------------------------------------
  288. def load_unit_passive
  289. @passives = []
  290. return unless actor.unit_passive
  291. @passives = actor.unit_passive.clone
  292. end
  293. #---------------------------------------------------------------------------
  294. # * new method: load_unit_disable_commands
  295. #---------------------------------------------------------------------------
  296. def load_unit_disable_commands
  297. @disable_commands = {}
  298. return unless actor.unit_disable_commands
  299. @disable_commands = actor.unit_disable_commands.clone
  300. end
  301. #---------------------------------------------------------------------------
  302. # * new method: can_target?
  303. #---------------------------------------------------------------------------
  304. def can_target?
  305. return true
  306. end
  307. #---------------------------------------------------------------------------
  308. # * overwrite method: battler_name
  309. #---------------------------------------------------------------------------
  310. def battler_name
  311. return actor.unit_battler if !@transformed
  312. return actor.unit_trans_battler if @transformed
  313. end
  314. #---------------------------------------------------------------------------
  315. # * overwrite method: screen_x
  316. #---------------------------------------------------------------------------
  317. def screen_x
  318. return SLOT_COORDINATES[:player][slot_id][0] + actor.unit_battler_offset[0]
  319. end
  320. #---------------------------------------------------------------------------
  321. # * overwrite method: screen_y
  322. #---------------------------------------------------------------------------
  323. def screen_y
  324. return SLOT_COORDINATES[:player][slot_id][1] + actor.unit_battler_offset[1]
  325. end
  326. #--------------------------------------------------------------------------
  327. # * Execute Collapse Effect
  328. #--------------------------------------------------------------------------
  329. def perform_collapse_effect
  330. if $game_party.in_battle
  331. @on_finish_collapse_method = method(:remove_unit)
  332. @sprite_effect_type = :collapse
  333. Sound.play_actor_collapse
  334. end
  335. end
  336. #--------------------------------------------------------------------------
  337. # * new method: remove_unit
  338. #--------------------------------------------------------------------------
  339. def remove_unit
  340. $game_party.battle_units.delete(@slot_id)
  341. $game_party.units_order.delete(self)
  342. $game_temp.reserve_common_event(actor.unit_off_common_ev_id)
  343. SceneManager.scene.process_death_unit_common_event
  344. @on_finish_collapse_method = nil
  345. end
  346. #---------------------------------------------------------------------------
  347. # * new method: is_battle_unit?
  348. #---------------------------------------------------------------------------
  349. def is_battle_unit?
  350. return actor.note.include?("<battle_unit>")
  351. end
  352. #--------------------------------------------------------------------------
  353. # * Use Skill/Item
  354. # Called for the acting side and applies the effect to other than the user.
  355. #--------------------------------------------------------------------------
  356. def use_item(item)
  357. pay_skill_cost(item) if item.is_a?(RPG::Skill)
  358. item.effects.each {|effect| item_global_effect_apply(effect) }
  359. end
  360. #--------------------------------------------------------------------------
  361. # * Check Usability Conditions for Skill
  362. #--------------------------------------------------------------------------
  363. def skill_conditions_met?(skill)
  364. skill_cost_payable?(skill)
  365. end
  366. #--------------------------------------------------------------------------
  367. # * Force Action
  368. #--------------------------------------------------------------------------
  369. def force_skill(skill_id, target_index = -1, force = true)
  370. clear_actions
  371. action = Game_Action.new(self, force)
  372. action.set_skill(skill_id)
  373. @actions.push(action)
  374. action.target_index = target_index
  375. end
  376. #--------------------------------------------------------------------------
  377. # * Use Sprite
  378. #--------------------------------------------------------------------------
  379. def use_sprite?
  380. return true
  381. end
  382. end # Game_BattleUnit
  383.  
  384. #===============================================================================
  385. # Window_ActorCommand
  386. #===============================================================================
  387.  
  388. class Window_ActorCommand < Window_Command
  389. #--------------------------------------------------------------------------
  390. # Add units command
  391. #--------------------------------------------------------------------------
  392. def add_unit_command
  393. add_command("Units", :units, unit_command_enable?)
  394. end
  395. #--------------------------------------------------------------------------
  396. # Check if unit command is enable
  397. #--------------------------------------------------------------------------
  398. def unit_command_enable?
  399. return $game_party.battle_units.values.size > 0 && $game_party.battle_units.values.any? {|unit| unit.can_attack == true}
  400. end
  401. #--------------------------------------------------------------------------
  402. # Make new command List (overwrite)
  403. #--------------------------------------------------------------------------
  404. def make_command_list
  405. return unless @actor
  406. add_attack_command if PC27::CG::USE_ATTACK
  407. add_guard_command if PC27::CG::USE_GUARD
  408. add_skill_commands
  409. add_item_command if PC27::CG::USE_ITEMS
  410. add_unit_command
  411. add_look_at_grave_command
  412. add_turn_end_command
  413. end
  414. end
  415.  
  416. #===============================================================================
  417. # Scene_Battle
  418. #===============================================================================
  419. class Scene_Battle < Scene_Base
  420. include DSIVER144::UNIT_SYSTEM
  421. #--------------------------------------------------------------------------
  422. # * Create Actor Window [Overwrite]
  423. #--------------------------------------------------------------------------
  424. def create_actor_window
  425. @actor_window = Window_DSIBattleActor.new(0,0)
  426. @actor_window.set_handler(:ok, method(:on_actor_ok))
  427. @actor_window.set_handler(:cancel, method(:on_actor_cancel))
  428. end
  429. alias_method(:dsi_unit_system_create_all_windows, :create_all_windows)
  430. #--------------------------------------------------------------------------
  431. # * Create All Windows
  432. #--------------------------------------------------------------------------
  433. def create_all_windows
  434. dsi_unit_system_create_all_windows()
  435. create_unit_command_window
  436. create_unit_list
  437. create_unit_skill_help_window
  438. create_unit_skill_list
  439. create_summon_window
  440. create_transform_window
  441. end
  442. #--------------------------------------------------------------------------
  443. # * Create Transform Window
  444. #--------------------------------------------------------------------------
  445. def create_transform_window
  446. @transform_window = Window_UnitTransform.new
  447. @transform_window.y -= 60
  448. @transform_prompt = Window_TransformPrompt.new(@transform_window.x, @transform_window.y + 150)
  449. @transform_prompt.set_handler(:ok, method(:on_trans_ok))
  450. @transform_prompt.set_handler(:cancel, method(:on_trans_cancel))
  451. @transform_prompt.hide.deactivate
  452. @transform_window.hide
  453. end
  454. #--------------------------------------------------------------------------
  455. # * new method: create_summon_window
  456. #--------------------------------------------------------------------------
  457. def create_summon_window
  458. @summon_window = Window_SummonCommand.new(0,0)
  459. @summon_window.x = (Graphics.width - @summon_window.width) * 0.5
  460. @summon_window.y = (Graphics.height - @summon_window.height) * 0.5
  461. @summon_window.set_handler(:ok, method(:on_summon_ok))
  462. @summon_window.set_handler(:cancel, method(:on_summon_cancel))
  463. @summon_window.refresh
  464. @summon_window.hide.deactivate
  465. end
  466. #--------------------------------------------------------------------------
  467. # * new method: create_unit_list
  468. #--------------------------------------------------------------------------
  469. def create_unit_list
  470. @unit_list = Window_ActiveUnits.new
  471. @unit_list.x = @party_command_window.x
  472. @unit_list.y = @info_viewport.rect.y - @unit_list.height
  473. @unit_list.set_handler(:unit_command, method(:on_unit_ok))
  474. @unit_list.set_handler(:cancel, method(:on_unit_list_cancel))
  475. @unit_list.deactivate
  476. @unit_list.status_window = @status_window
  477. end
  478. #--------------------------------------------------------------------------
  479. # * new method: create_unit_skill_help_window
  480. #--------------------------------------------------------------------------
  481. def create_unit_skill_help_window
  482. @help_window2 = Window_DSIHelp.new(2)
  483. @help_window2.x = 0
  484. @help_window2.y = 0
  485. @help_window2.visible = false
  486. end
  487. #--------------------------------------------------------------------------
  488. # * new method: create_unit_skill_list
  489. #--------------------------------------------------------------------------
  490. def create_unit_skill_list
  491. wx = 0
  492. wy = @unit_list.y
  493. ww = 320
  494. @unit_skill_list = Window_UnitSkillList.new(wx,wy,ww)
  495. @unit_skill_list.hide.deactivate
  496. @unit_skill_list.set_handler(:ok, method(:on_unit_skill_ok))
  497. @unit_skill_list.set_handler(:cancel, method(:on_unit_skill_list_cancel))
  498. @unit_skill_list.help_window = @help_window2
  499. end
  500. #--------------------------------------------------------------------------
  501. # * new method:
  502. #--------------------------------------------------------------------------
  503. def on_unit_skill_ok
  504. @unit_skill = @unit_skill_list.item
  505. @current_unit.last_skill.object = @unit_skill
  506. @return_flag = nil
  507. if @unit_skill
  508. if !@unit_skill.need_selection?
  509. @unit_skill_list.hide.deactivate
  510. unit_use_skill
  511. elsif @unit_skill.for_opponent?
  512. select_enemy_selection
  513. else
  514. select_actor_selection
  515. end
  516. end
  517. end
  518. #--------------------------------------------------------------------------
  519. # * Actor [Cancel]
  520. #--------------------------------------------------------------------------
  521. alias_method(:on_actor_cancel_dsi_unit_system, :on_actor_cancel)
  522. def on_actor_cancel
  523. if @unit_skill
  524. @unit_skill_list.hide.deactivate
  525. @actor_window.hide
  526. @unit_commnad_window.activate
  527. @unit_skill = nil
  528. else
  529. on_actor_cancel_dsi_unit_system
  530. end
  531. end
  532. #--------------------------------------------------------------------------
  533. # * Actor [OK]
  534. #--------------------------------------------------------------------------
  535. alias_method(:on_actor_ok_dsi_unit_system, :on_actor_ok)
  536. def on_actor_ok
  537. if @unit_skill
  538. @unit_skill_list.hide.deactivate
  539. @actor_window.hide
  540. @unit_skill_list.hide.deactivate
  541. @current_unit.force_skill(@unit_skill.id, @actor_window.index)
  542. @unit_skill = nil
  543. use_item_unit
  544. @subject = nil
  545. @current_unit.can_attack = false
  546. command_unit_cancel
  547. else
  548. on_actor_ok_dsi_unit_system
  549. end
  550. @unit_skill = nil
  551. end
  552. #--------------------------------------------------------------------------
  553. # * new method: on_unit_skill_list_cancel
  554. #--------------------------------------------------------------------------
  555. def on_unit_skill_list_cancel
  556. @unit_skill_list.hide.deactivate
  557. @unit_commnad_window.show.activate
  558. end
  559. #--------------------------------------------------------------------------
  560. # * new method: unit_use_skill
  561. #--------------------------------------------------------------------------
  562. def unit_use_skill
  563. @current_unit.force_skill(@unit_skill.id, nil, false)
  564. use_item_unit
  565. @current_unit.can_attack = false
  566. command_unit_cancel
  567. end
  568. #--------------------------------------------------------------------------
  569. # * Create Message Window [Overwrite]
  570. #--------------------------------------------------------------------------
  571. alias_method(:dsi_unit_system_create_message_window, :create_message_window)
  572. def create_message_window
  573. dsi_unit_system_create_message_window
  574. @message_window.z = 300
  575. end
  576. #--------------------------------------------------------------------------
  577. # * new method: on_unit_ok
  578. #--------------------------------------------------------------------------
  579. def on_unit_ok
  580. @unit_list.hide.deactivate
  581. @current_unit = $game_party.battle_units[@unit_list.current_slot_id]
  582. @status_window.current_unit = @current_unit
  583. @unit_commnad_window.setup(@current_unit)
  584. @actor_command_window.hide
  585. @unit_commnad_window.show.activate
  586. end
  587. #--------------------------------------------------------------------------
  588. # * new method: create_unit_command_window
  589. #--------------------------------------------------------------------------
  590. def create_unit_command_window
  591. @unit_commnad_window = Window_UnitCommand.new
  592. @unit_commnad_window.viewport = @info_viewport
  593. @unit_commnad_window.set_handler(:attack, method(:command_unit_attack))
  594. @unit_commnad_window.set_handler(:skill, method(:command_unit_skill))
  595. @unit_commnad_window.set_handler(:transform, method(:command_unit_transform))
  596. @unit_commnad_window.set_handler(:cancel, method(:command_unit_cancel))
  597. @unit_commnad_window.deactivate
  598. @unit_commnad_window.hide
  599. @unit_commnad_window.x = Graphics.width
  600. end
  601. #--------------------------------------------------------------------------
  602. # * Enemy [OK]
  603. #--------------------------------------------------------------------------
  604. def on_enemy_ok
  605. if @current_unit
  606. @enemy_window.hide
  607. if @unit_skill
  608. @unit_skill_list.hide.deactivate
  609. @current_unit.force_skill(@unit_skill.id, @enemy_window.enemy.index)
  610. @unit_skill = nil
  611. end
  612. use_item_unit
  613. @subject = nil
  614. @current_unit.can_attack = false
  615. command_unit_cancel
  616. else
  617. BattleManager.actor.input.target_index = @enemy_window.enemy.index
  618. @enemy_window.hide
  619. @skill_window.hide
  620. @item_window.hide
  621. next_command
  622. end
  623. end
  624. #--------------------------------------------------------------------------
  625. # * Enemy [Cancel]
  626. #--------------------------------------------------------------------------
  627. def on_enemy_cancel
  628. @enemy_window.hide
  629. if @return_flag && @return_flag == :unit_command_window
  630. @unit_commnad_window.activate
  631. @return_flag = nil
  632. return
  633. end
  634. if @unit_skill
  635. @unit_skill_list.refresh
  636. @unit_skill_list.activate
  637. @unit_skill = nil
  638. else
  639. case @actor_command_window.current_symbol
  640. when :attack
  641. @actor_command_window.activate
  642. when :skill
  643. @skill_window.activate
  644. when :item
  645. @item_window.activate
  646. end
  647. end
  648. end
  649. #--------------------------------------------------------------------------
  650. # * new method: command_unit_attack
  651. #--------------------------------------------------------------------------
  652. def command_unit_attack
  653. @subject = @current_unit
  654. @unit_skill = $data_skills[@subject.unit_attack_skill_id]
  655. @return_flag = :unit_command_window
  656. select_enemy_selection
  657. end
  658. #--------------------------------------------------------------------------
  659. # * new method: command_unit_skill
  660. #--------------------------------------------------------------------------
  661. def command_unit_skill
  662. @subject = @current_unit
  663. @unit_skill_list.unit = @current_unit
  664. @unit_skill_list.refresh
  665. @unit_skill_list.show.activate
  666. @unit_skill_list.select_last
  667. end
  668. #--------------------------------------------------------------------------
  669. # * new method: on_trans_ok
  670. #--------------------------------------------------------------------------
  671. def on_trans_ok
  672. @transform_window.hide
  673. @transform_prompt.hide.deactivate
  674. 10.times do
  675. update_for_wait
  676. end
  677. run_common_event_flag = false
  678. @subject = @current_unit
  679. @subject.animation_id = @subject.actor.unit_trans_animation_id
  680. @subject.transformed = true
  681. @log_window.display_unit_transform(@subject)
  682. @subject.add_state(@subject.actor.unit_transform_state_id)
  683. if @subject.actor.unit_transform_effects.size > 0
  684. @subject.actor.unit_transform_effects.each do |effect|
  685. if effect[0] == :mhp
  686. @subject.add_param(0, effect[1])
  687. @subject.hp += effect[1]
  688. end
  689. if effect[0] == :mmp
  690. @subject.add_param(1, effect[1])
  691. @subject.mp += effect[1]
  692. end
  693. if effect[0] == :learn_skill
  694. @subject.learn_skill(effect[1])
  695. end
  696. if effect[0] == :new_passive
  697. @subject.remove_state(@subject.passives[0])
  698. @subject.passives = [effect[1], effect[2]]
  699. @subject.add_state(@subject.passives[0])
  700. end
  701. if effect[0] == :enable
  702. for i in 1...effect.size
  703. @subject.disable_commands.delete(effect[i])
  704. end
  705. end
  706. if effect[0] == :disable
  707. for i in 1...effect.size
  708. @subject.disable_commands[effect[i]] = true
  709. end
  710. end
  711. if effect[0] == :new_attack_skill
  712. @subject.unit_attack_skill_id = effect[1]
  713. end
  714. if effect[0] == :common_event
  715. $game_temp.reserve_common_event(effect[1])
  716. run_common_event_flag = true
  717. end
  718. end
  719. else
  720. if UNIT_CONFIG[@subject.actor.id]
  721. effects = UNIT_CONFIG[@subject.actor.id][:transform][:effects]
  722. effects.each do |effect|
  723. if effect[0] == :mhp
  724. @subject.add_param(0, effect[1])
  725. @subject.hp += effect[1]
  726. end
  727. if effect[0] == :mmp
  728. @subject.add_param(1, effect[1])
  729. @subject.mp += effect[1]
  730. end
  731. if effect[0] == :learn_skill
  732. @subject.learn_skill(effect[1])
  733. end
  734. if effect[0] == :new_passive
  735. @subject.remove_state(@subject.passives[0])
  736. @subject.passives = [effect[1], effect[2]]
  737. @subject.add_state(@subject.passives[0])
  738. end
  739. if effect[0] == :new_attack_skill
  740. @subject.unit_attack_skill_id = effect[1]
  741. end
  742. if effect[0] == :common_event
  743. $game_temp.reserve_common_event(effect[1])
  744. run_common_event_flag = true
  745. end
  746. end
  747. end
  748. end
  749. refresh_status
  750. BattleManager.actor.tp -= 1
  751. @current_unit.can_transform = false
  752. $game_party.can_perform_transform = false
  753. @log_window.wait_and_clear
  754. process_event if run_common_event_flag
  755. @unit_commnad_window.refresh
  756. @unit_commnad_window.activate
  757. @subject = nil
  758. end
  759. #--------------------------------------------------------------------------
  760. # * new method: transform_unit
  761. #--------------------------------------------------------------------------
  762. def transform_unit(unit, tp_lose = 1, disable_cm = true, runCME = true)
  763. run_common_event_flag = false
  764. @transform_unit = unit
  765. @transform_unit.animation_id = @transform_unit.actor.unit_trans_animation_id
  766. @transform_unit.transformed = true
  767. @log_window.display_unit_transform(@transform_unit)
  768. wait_for_effect
  769. @transform_unit.add_state(@transform_unit.actor.unit_transform_state_id)
  770. if @transform_unit.actor.unit_transform_effects.size > 0
  771. @transform_unit.actor.unit_transform_effects.each do |effect|
  772. if effect[0] == :mhp
  773. @transform_unit.add_param(0, effect[1])
  774. @transform_unit.hp += effect[1]
  775. end
  776. if effect[0] == :mmp
  777. @transform_unit.add_param(1, effect[1])
  778. @transform_unit.mp += effect[1]
  779. end
  780. if effect[0] == :learn_skill
  781. @transform_unit.learn_skill(effect[1])
  782. end
  783. if effect[0] == :new_passive
  784. @transform_unit.remove_state(@transform_unit.passives[0])
  785. @transform_unit.passives = [effect[1], effect[2]]
  786. @transform_unit.add_state(@transform_unit.passives[0])
  787. end
  788. if effect[0] == :enable
  789. for i in 1...effect.size
  790. @transform_unit.disable_commands.delete(effect[i])
  791. end
  792. end
  793. if effect[0] == :disable
  794. for i in 1...effect.size
  795. @transform_unit.disable_commands[effect[i]] = true
  796. end
  797. end
  798. if effect[0] == :new_attack_skill
  799. @transform_unit.unit_attack_skill_id = effect[1]
  800. end
  801. if effect[0] == :common_event
  802. $game_temp.reserve_common_event(effect[1])
  803. run_common_event_flag = true
  804. end
  805. end
  806. else
  807. if UNIT_CONFIG[@transform_unit.actor.id]
  808. effects = UNIT_CONFIG[@transform_unit.actor.id][:transform][:effects]
  809. effects.each do |effect|
  810. if effect[0] == :mhp
  811. @transform_unit.add_param(0, effect[1])
  812. @transform_unit.hp += effect[1]
  813. end
  814. if effect[0] == :mmp
  815. @transform_unit.add_param(1, effect[1])
  816. @transform_unit.mp += effect[1]
  817. end
  818. if effect[0] == :learn_skill
  819. @transform_unit.learn_skill(effect[1])
  820. end
  821. if effect[0] == :new_passive
  822. @transform_unit.remove_state(@transform_unit.passives[0])
  823. @transform_unit.passives = [effect[1], effect[2]]
  824. @transform_unit.add_state(@transform_unit.passives[0])
  825. end
  826. if effect[0] == :new_attack_skill
  827. @transform_unit.unit_attack_skill_id = effect[1]
  828. end
  829. if effect[0] == :common_event
  830. $game_temp.reserve_common_event(effect[1])
  831. run_common_event_flag = true
  832. end
  833. end
  834. end
  835. end
  836. refresh_status
  837. $game_party.members[0].tp -= tp_lose
  838. @transform_unit.can_transform = false
  839. $game_party.can_perform_transform = disable_cm
  840. @transform_unit = nil
  841. process_event if run_common_event_flag && runCME
  842. end
  843. #--------------------------------------------------------------------------
  844. # * new method: on_trans_cancel
  845. #--------------------------------------------------------------------------
  846. def on_trans_cancel
  847. @transform_window.unit = nil
  848. @transform_window.hide
  849. @transform_prompt.hide.deactivate
  850. @unit_commnad_window.refresh
  851. @unit_commnad_window.activate
  852. @subject = nil
  853. end
  854. #--------------------------------------------------------------------------
  855. # * new method: command_unit_transform
  856. #--------------------------------------------------------------------------
  857. def command_unit_transform
  858. @transform_window.unit = @current_unit
  859. @transform_window.show
  860. @transform_prompt.show.activate
  861. end
  862. #--------------------------------------------------------------------------
  863. # * new method: command_unit_cancel
  864. #--------------------------------------------------------------------------
  865. def command_unit_cancel
  866. return if $game_troop.all_dead?
  867. @unit_list.refresh
  868. @unit_commnad_window.hide.deactivate
  869. @unit_list.show.activate
  870. @actor_command_window.show
  871. @current_unit = nil
  872. @unit_skill = nil
  873. end
  874. #--------------------------------------------------------------------------
  875. # * new method: on_unit_list_cancel
  876. #--------------------------------------------------------------------------
  877. def on_unit_list_cancel
  878. @unit_list.hide.deactivate
  879. @actor_command_window.refresh
  880. @status_window.current_unit = nil
  881. @actor_command_window.activate
  882. end
  883. #--------------------------------------------------------------------------
  884. # Add end turn command and remove prior command (overwrite)
  885. #--------------------------------------------------------------------------
  886. def create_actor_command_window
  887. @actor_command_window = Window_ActorCommand.new
  888. @actor_command_window.viewport = @info_viewport
  889. @actor_command_window.set_handler(:skill, method(:command_skill))
  890. @actor_command_window.set_handler(:guard, method(:command_guard))
  891. @actor_command_window.set_handler(:item, method(:command_item))
  892. @actor_command_window.set_handler(:look_grave, method(:command_look_grave))
  893. @actor_command_window.set_handler(:end_turn, method(:command_end_turn))
  894. @actor_command_window.set_handler(:units, method(:command_units))
  895. @actor_command_window.x = Graphics.width
  896. end
  897. alias_method(:dsi_unit_system_command_end_turn, :command_end_turn)
  898. #--------------------------------------------------------------------------
  899. # Clears actions and ends the actors turn
  900. #--------------------------------------------------------------------------
  901. def command_end_turn
  902. dsi_unit_system_command_end_turn
  903. $game_party.reset_units
  904. end
  905. #--------------------------------------------------------------------------
  906. # * new method: command_units
  907. #--------------------------------------------------------------------------
  908. def command_units
  909. @unit_list.refresh
  910. @unit_list.show.activate
  911. @unit_list.select(0)
  912. @unit_list.refresh_status_window
  913. @actor_command_window.deactivate
  914. @unit_commnad_window.deactivate
  915. end
  916. #--------------------------------------------------------------------------
  917. # * Use Skill for Unit
  918. #--------------------------------------------------------------------------
  919. def use_item_unit
  920. item = @subject.current_action.item
  921. @log_window.display_use_item(@subject, item)
  922. @subject.use_item(item)
  923. refresh_status
  924. targets = @subject.current_action.make_targets.compact
  925. show_animation(targets, item.animation_id)
  926. targets.each {|target| item.repeats.times { invoke_item(target, item) } }
  927. @subject.remove_current_action
  928. process_action_end
  929. process_event
  930. end
  931. #--------------------------------------------------------------------------
  932. # * Wait Until Animation Display has Finished
  933. #--------------------------------------------------------------------------
  934. def wait_for_summoning
  935. update_for_wait
  936. update_for_wait while @summon_window.active
  937. end
  938. #--------------------------------------------------------------------------
  939. # * On Summon OK
  940. #--------------------------------------------------------------------------
  941. def on_summon_ok
  942. @summon_window.hide.deactivate
  943. slot_id = @summon_window.current_data[:slot_id]
  944. $game_party.summon_unit(@summon_unit_id, slot_id)
  945. unit = $game_party.battle_units[slot_id]
  946. $game_temp.reserve_common_event(unit.actor.unit_on_common_ev_id)
  947. @summon_unit_id = nil
  948. end
  949. #--------------------------------------------------------------------------
  950. # * On Summon Cancel
  951. #--------------------------------------------------------------------------
  952. def on_summon_cancel
  953. @summon_window.hide.deactivate
  954. @summon_unit_id = nil
  955. if @actor_stack
  956. BattleManager.actor.hand += @actor_stack
  957. @actor_stack.each do |card|
  958. BattleManager.actor.grave.delete_at(BattleManager.actor.grave.index(card))
  959. end
  960. @actor_stack = nil
  961. end
  962. end
  963. #--------------------------------------------------------------------------
  964. # * new method: process_death_unit_common_event
  965. #--------------------------------------------------------------------------
  966. def process_death_unit_common_event
  967. process_common_event
  968. end
  969. #--------------------------------------------------------------------------
  970. # * Return Card To Player Hand
  971. #--------------------------------------------------------------------------
  972. def return_card_to_player_hand
  973. if @actor_stack
  974. BattleManager.actor.hand += @actor_stack
  975. @actor_stack.each do |card|
  976. BattleManager.actor.grave.delete_at(BattleManager.actor.grave.index(card))
  977. end
  978. @actor_stack = nil
  979. end
  980. end
  981. #--------------------------------------------------------------------------
  982. # * Use Skill/Item
  983. #--------------------------------------------------------------------------
  984. alias_method(:dsi_unit_system_use_item, :use_item)
  985. def use_item
  986. @actor_stack = BattleManager.actor.stack.clone if BattleManager.actor
  987. skill = @subject.current_action.item
  988. my_targets = @subject.current_action.make_targets.compact.clone
  989. dsi_unit_system_use_item
  990. if skill && skill.is_a?(RPG::Skill)
  991. if skill.summon_unit_id
  992. @summon_unit_id = skill.summon_unit_id
  993. @summon_window.refresh
  994. @summon_window.show.activate
  995. wait_for_summoning
  996. @log_window.wait_and_clear
  997. process_common_event
  998. end
  999. if skill.unit_refresh_attack
  1000. attack_flag = false
  1001. my_targets.each do |target|
  1002. if target.is_a?(Game_ActorUnit) && !target.can_attack
  1003. attack_flag = true
  1004. target.can_attack = true
  1005. end
  1006. end
  1007. return_card_to_player_hand if attack_flag == false
  1008. end # skill.unit_refresh_attack
  1009. if skill.unit_force_transform
  1010. setting = skill.unit_force_transform
  1011. trans_flag = false
  1012. my_targets.each do |target|
  1013. if target.is_a?(Game_ActorUnit) && !target.transformed
  1014. target.result.success = true
  1015. transform_unit(target, setting[:tp], setting[:disable_trans])
  1016. trans_flag = true
  1017. end
  1018. end
  1019. if trans_flag == false
  1020. if setting[:return_card]
  1021. return_card_to_player_hand
  1022. end
  1023. end
  1024. end # end skill.unit_force_transform
  1025. end
  1026. end
  1027.  
  1028. end
  1029.  
  1030. class Spriteset_Battle
  1031. #--------------------------------------------------------------------------
  1032. # * Get Enemy and Actor Sprites
  1033. #--------------------------------------------------------------------------
  1034. def battler_sprites
  1035. @enemy_sprites + @actor_sprites + @unit_sprites
  1036. end
  1037. alias_method(:dsi_create_actors_unit_system, :create_actors)
  1038. #--------------------------------------------------------------------------
  1039. # * Create Actor Sprites
  1040. #--------------------------------------------------------------------------
  1041. def create_actors
  1042. dsi_create_actors_unit_system
  1043. @unit_sprites = Array.new(6) { Sprite_Unit.new(@viewport1) }
  1044. end
  1045. #--------------------------------------------------------------------------
  1046. # * Update Unit Sprite
  1047. #--------------------------------------------------------------------------
  1048. def update_units
  1049. @unit_sprites.each_with_index do |sprite, i|
  1050. sprite.battler = $game_party.battle_units[i + 1]
  1051. sprite.update
  1052. end
  1053. end
  1054. alias_method(:dsi_update_actors_unit_system, :update_actors)
  1055. #--------------------------------------------------------------------------
  1056. # * Update Actor Sprite
  1057. #--------------------------------------------------------------------------
  1058. def update_actors
  1059. dsi_update_actors_unit_system
  1060. update_units
  1061. end
  1062. end # Spriteset_Battle
  1063.  
  1064. class RPG::Actor
  1065. include DSIVER144::UNIT_SYSTEM
  1066. attr_accessor :unit_battler
  1067. attr_accessor :unit_skill_ids
  1068. attr_accessor :unit_battler_offset
  1069. attr_accessor :unit_passive
  1070. attr_accessor :unit_trans_battler
  1071. attr_accessor :unit_attack_skill_id
  1072. attr_accessor :unit_transform_state_id
  1073. attr_accessor :unit_on_common_ev_id
  1074. attr_accessor :unit_off_common_ev_id
  1075. attr_accessor :unit_disable_commands
  1076. attr_accessor :unit_transform_effects
  1077. attr_accessor :unit_trans_animation_id
  1078.  
  1079. def load_unit_notetag
  1080. @read_unit = false
  1081. @unit_attack_skill_id = nil
  1082. @unit_transform_state_id = nil
  1083. @unit_battler = ""
  1084. @unit_skill_ids = []
  1085. @unit_trans_battler = ""
  1086. @unit_battler_offset = [0,0]
  1087. @unit_passive = nil
  1088. @unit_disable_commands = nil
  1089. @unit_transform_effects = []
  1090. @unit_trans_animation_id = 4
  1091. @unit_on_common_ev_id = DEFAULT_UNIT_APPEAR_COMMON_EVENT_ID
  1092. @unit_off_common_ev_id = DEFAULT_UNIT_DISAPPEAR_COMMON_EVENT_ID
  1093. self.note.split(/[\r\n]+/).each do |line|
  1094. if line =~ /<unit actor>/i
  1095. @read_unit = true
  1096. end
  1097. if line =~ /<end unit actor>/i
  1098. @read_unit = false
  1099. end
  1100. if @read_unit
  1101. if line =~ /battler:\s*(.+)/i
  1102. @unit_battler = $1
  1103. end
  1104. if line =~ /battler trans:\s*(.+)/i
  1105. @unit_trans_battler = $1
  1106. end
  1107. if line =~ /skill set:\s*(.+)/i
  1108. @unit_skill_ids = $1.split(",").map {|id| id.to_i}
  1109. end
  1110. if line =~ /battler offset:\s*(.+)/i
  1111. @unit_battler_offset = $1.split(",").map {|id| id.to_i}
  1112. end
  1113. if line =~ /passive:\s*(.+)/i
  1114. @unit_passive = $1.split(",").map {|id| id.to_i}
  1115. end
  1116. if line =~ /transform state id:\s*(\d+)/i
  1117. @unit_transform_state_id = $1.to_i
  1118. end
  1119. if line =~ /attack skill id:\s*(\d+)/i
  1120. @unit_attack_skill_id = $1.to_i
  1121. end
  1122. if line =~ /spawn common event id:\s*(\d+)/i
  1123. @unit_on_common_ev_id = $1.to_i
  1124. end
  1125. if line =~ /die common event id:\s*(\d+)/i
  1126. @unit_off_common_ev_id = $1.to_i
  1127. end
  1128. if line =~ /transform animation:\s*(\d+)/i
  1129. @unit_trans_animation_id = $1.to_i
  1130. end
  1131. if line =~ /transform call common event:\s*(.+)/i
  1132. array = $1.split(",").map {|id| id.delete(" ")}
  1133. if array[0] == "true"
  1134. @unit_transform_effects += [[:common_event, array[1].to_i]]
  1135. @unit_transform_effects.uniq!
  1136. end
  1137. end
  1138. if line =~ /disable command:\s*(.+)/i
  1139. @unit_disable_commands ||= {}
  1140. $1.split(",").map {|id| id.delete(" ").to_sym}.each do |key|
  1141. @unit_disable_commands[key] = true
  1142. end
  1143. end
  1144. if line =~ /unit trans effect:\s*(.+)/i
  1145. array = $1.split(" ")
  1146. array[0] = array[0].to_sym
  1147. if [:enable, :disable].include?(array[0])
  1148. for i in 1...array.size
  1149. array[i] = array[i].to_sym
  1150. end
  1151. else
  1152. for i in 1...array.size
  1153. array[i] = array[i].to_i
  1154. end
  1155. end
  1156. @unit_transform_effects += [array]
  1157. @unit_transform_effects.uniq!
  1158. end
  1159. end
  1160. end
  1161. end
  1162.  
  1163. end # RPG::Actor
  1164.  
  1165. class RPG::Skill
  1166.  
  1167. attr_accessor :summon_unit_id
  1168. attr_accessor :unit_passive
  1169. attr_accessor :unit_slot_lock
  1170. attr_accessor :unit_force_transform
  1171. attr_accessor :unit_refresh_attack
  1172.  
  1173. def load_unit_notetag
  1174. @summon_unit_id = nil
  1175. @unit_passive = false
  1176. @unit_force_transform = nil
  1177. @unit_refresh_attack = nil
  1178. self.note.split(/[\r\n]+/).each do |line|
  1179. if line =~ /<summon unit:\s*(\d+)>/i
  1180. @summon_unit_id = $1.to_i
  1181. end
  1182. if line =~ /<unit passive>/i
  1183. @unit_passive = true
  1184. end
  1185. if line =~ /<lock a slot>/i
  1186. @unit_slot_lock = true
  1187. end
  1188. if line =~ /<refresh unit attack>/i
  1189. @unit_refresh_attack = true
  1190. end
  1191. if line =~ /<force unit transform:\s*(.+)>/i
  1192. array = $1.split(",").map {|param| param.delete(" ")}
  1193. @unit_force_transform ||= {}
  1194. @unit_force_transform[:tp] = array[0].to_i
  1195. @unit_force_transform[:disable_trans] = array[1] == "true"
  1196. @unit_force_transform[:return_card] = array[2] == "true"
  1197. end
  1198. end
  1199. end
  1200.  
  1201. end # RPG::Actor
  1202.  
  1203. class RPG::Enemy
  1204. attr_accessor :unit_flag
  1205. attr_accessor :stats_offset
  1206. attr_accessor :custom_offset
  1207. def load_unit_notetag
  1208. @unit_flag = false
  1209. @stats_offset = nil
  1210. @custom_offset = {}
  1211. self.note.split(/[\r\n]+/i).each do |line|
  1212. if line =~ /<enemy unit>/i
  1213. @unit_flag = true
  1214. end
  1215. if line =~ /<stat offset:\s*(.+)>/i
  1216. @stats_offset = $1.split(",").map {|id| id.to_i}
  1217. end
  1218. if line =~ /<hp offset:\s*(.+)>/i
  1219. @custom_offset[:hp] = $1.split(",").map {|id| id.to_i}
  1220. end
  1221. if line =~ /<mp offset:\s*(.+)>/i
  1222. @custom_offset[:mp] = $1.split(",").map {|id| id.to_i}
  1223. end
  1224. if line =~ /<tp offset:\s*(.+)>/i
  1225. @custom_offset[:tp] = $1.split(",").map {|id| id.to_i}
  1226. end
  1227. if line =~ /<shield offset:\s*(.+)>/i
  1228. @custom_offset[:shp] = $1.split(",").map {|id| id.to_i}
  1229. end
  1230. end
  1231. end
  1232. end
  1233.  
  1234. class Game_Troop
  1235. #--------------------------------------------------------------------------
  1236. # * Get Enemy Units
  1237. #--------------------------------------------------------------------------
  1238. def enemy_units
  1239. alive_members.select {|e| e.enemy.unit_flag}
  1240. end
  1241. #--------------------------------------------------------------------------
  1242. # * Determine Everyone is Dead
  1243. #--------------------------------------------------------------------------
  1244. def all_dead?
  1245. (alive_members - enemy_units).empty?
  1246. end
  1247. end
  1248.  
  1249. #==============================================================================
  1250. # ** DataManager
  1251. #==============================================================================
  1252. module DataManager
  1253. class << self
  1254. alias unit_system_load_database load_database
  1255. alias unit_system_init init
  1256. end
  1257. #----------------------------------------------------------------------------
  1258. # * alias method: init
  1259. #----------------------------------------------------------------------------
  1260. def self.init
  1261. unit_system_init
  1262. load_notetags_unit_system
  1263. end
  1264. #----------------------------------------------------------------------------
  1265. # * alias method: load_database
  1266. #----------------------------------------------------------------------------
  1267. def self.load_database
  1268. unit_system_load_database
  1269. end
  1270. #----------------------------------------------------------------------------
  1271. # * new method: load_notetags_unit_system
  1272. #----------------------------------------------------------------------------
  1273. def self.load_notetags_unit_system
  1274. groups = [$data_actors, $data_skills, $data_enemies]
  1275. for group in groups
  1276. for obj in group
  1277. next if obj.nil?
  1278. next if obj.name == ""
  1279. obj.load_unit_notetag
  1280. end
  1281. end
  1282. end
  1283. end # DataManager
  1284.  
  1285. class Game_Party
  1286. #-----------------------------------------------------------------------------
  1287. # New. Return an array of battlers that can be targeted
  1288. #-----------------------------------------------------------------------------
  1289. def targetable_members
  1290. battle_members.select {|member| member.can_target? }
  1291. end
  1292. #--------------------------------------------------------------------------
  1293. # * Smooth Selection of Target
  1294. #--------------------------------------------------------------------------
  1295. def smooth_target(index)
  1296. member = battle_members[index]
  1297. (member && member.alive?) ? member : alive_members[0]
  1298. end
  1299. end
  1300.  
  1301. class String
  1302. #----------------------------------------------------------------------------
  1303. # * Delete All Part of sub string in string
  1304. #----------------------------------------------------------------------------
  1305. def delete!(sub)
  1306. while self.include?(sub)
  1307. self.sub!(sub, "")
  1308. end
  1309. return self
  1310. end
  1311. end # String
  1312.  
  1313. class Game_Interpreter
  1314. include DSIVER144::UNIT_SYSTEM
  1315. #--------------------------------------------------------------------------
  1316. # * Actor Iterator (ID)
  1317. # param : If 1 or more, ID. If 0, all
  1318. #--------------------------------------------------------------------------
  1319. def iterate_actor_id(param)
  1320. if param == 0
  1321. $game_party.members(true).each {|actor| yield actor }
  1322. else
  1323. actor = $game_actors[param]
  1324. yield actor if actor
  1325. end
  1326. end
  1327. #----------------------------------------------------------------------------
  1328. # * Disable Unit Slot
  1329. #----------------------------------------------------------------------------
  1330. def disable_unit_slot(slot_id)
  1331. $game_switches[SLOT_DISABLE_SWITCHES[slot_id]] = true
  1332. end
  1333. #----------------------------------------------------------------------------
  1334. # * Enable Unit Slot
  1335. #----------------------------------------------------------------------------
  1336. def enable_unit_slot(slot_id)
  1337. $game_switches[SLOT_DISABLE_SWITCHES[slot_id]] = false
  1338. end
  1339. #----------------------------------------------------------------------------
  1340. # * Summon Certain Unit to certain slot in battle.
  1341. #----------------------------------------------------------------------------
  1342. def summon_unit(unit_id, slot_id)
  1343. if $game_party.summon_unit(unit_id, slot_id)
  1344. unit = $game_party.battle_units[slot_id]
  1345. $game_temp.reserve_common_event(unit.actor.unit_on_common_ev_id)
  1346. end
  1347. end
  1348. #----------------------------------------------------------------------------
  1349. # * Random Summon a Unit to certain slot in battle.
  1350. #----------------------------------------------------------------------------
  1351. def random_summon_unit(unit_id)
  1352. slot_id = ([1,2,3,4,5,6] - $game_party.battle_units.keys).shuffle[0]
  1353. if slot_id
  1354. summon_unit(unit_id, slot_id)
  1355. return true
  1356. end
  1357. SceneManager.scene.return_card_to_player_hand
  1358. return false
  1359. end
  1360. #----------------------------------------------------------------------------
  1361. # * Check if there is a player unit on certain slot.
  1362. #----------------------------------------------------------------------------
  1363. def has_player_unit_on_slotX?(slot_id)
  1364. return false unless SceneManager.scene_is?(Scene_Battle)
  1365. return $game_party.battle_units.has_key?(slot_id)
  1366. end
  1367. #----------------------------------------------------------------------------
  1368. # * Check if a unit in slot id has certain skill.
  1369. #----------------------------------------------------------------------------
  1370. def unit_has_skill?(slot_id, skill_id)
  1371. return false unless SceneManager.scene_is?(Scene_Battle)
  1372. skill = $data_skills[skill_id]
  1373. return $game_party.battle_units[slot_id].skills.include?(skill)
  1374. end
  1375. #----------------------------------------------------------------------------
  1376. # * Check if a unit in slot id has certain state.
  1377. #----------------------------------------------------------------------------
  1378. def unit_has_state?(slot_id, state_id)
  1379. return false unless SceneManager.scene_is?(Scene_Battle)
  1380. return $game_party.battle_units[slot_id].state?(state_id)
  1381. end
  1382. #----------------------------------------------------------------------------
  1383. # * Check if a unit in slot can transform.
  1384. #----------------------------------------------------------------------------
  1385. def force_transform(slot_id, tp = 0, disable_cm = false)
  1386. return false unless SceneManager.scene_is?(Scene_Battle)
  1387. return false if !$game_party.battle_units.has_key?(slot_id)
  1388. return false if $game_party.battle_units[slot_id].transformed
  1389. unit = $game_party.battle_units[slot_id]
  1390. SceneManager.scene.transform_unit(unit, tp, disable_cm, false)
  1391. end
  1392. #----------------------------------------------------------------------------
  1393. # * Destroy Player Unit in specific Slot
  1394. #----------------------------------------------------------------------------
  1395. def destroy_unit(slot_id, return_card = true)
  1396. unit = $game_party.battle_units[slot_id]
  1397. if SceneManager.scene_is?(Scene_Battle) && unit
  1398. unit.die
  1399. unit.refresh
  1400. unit.perform_collapse_effect
  1401. return true
  1402. end
  1403. SceneManager.scene.return_card_to_player_hand if return_card
  1404. return false
  1405. end
  1406. #----------------------------------------------------------------------------
  1407. # * Destroy All Unit
  1408. #----------------------------------------------------------------------------
  1409. def destroy_all_unit(return_card = true)
  1410. check = false
  1411. for slot_id in 1..6
  1412. if destroy_unit(slot_id, false)
  1413. check = true
  1414. end
  1415. end
  1416. if !check
  1417. SceneManager.scene.return_card_to_player_hand if return_card
  1418. end
  1419. end
  1420. #----------------------------------------------------------------------------
  1421. # * Inflict State to Unit on Specific Slot
  1422. #----------------------------------------------------------------------------
  1423. def inflict_state_unit(slot_id, state_id, return_card = true)
  1424. unit = $game_party.battle_units[slot_id]
  1425. if SceneManager.scene_is?(Scene_Battle) && unit
  1426. unit.add_state(state_id)
  1427. unit.perform_collapse_effect if unit.dead?
  1428. return true
  1429. end
  1430. SceneManager.scene.return_card_to_player_hand if return_card
  1431. return false
  1432. end
  1433. #----------------------------------------------------------------------------
  1434. # * Destroy All Unit
  1435. #----------------------------------------------------------------------------
  1436. def inflict_state_all_unit(state_id, return_card = true)
  1437. check = false
  1438. for slot_id in 1..6
  1439. if inflict_state_unit(slot_id, state_id, false)
  1440. check = true
  1441. end
  1442. end
  1443. if !check
  1444. SceneManager.scene.return_card_to_player_hand if return_card
  1445. end
  1446. end
  1447. #----------------------------------------------------------------------------
  1448. # * Check Lastest Unit Placement
  1449. #----------------------------------------------------------------------------
  1450. def lastest_unit_placement?(type)
  1451. if $game_party.lastest_unit
  1452. check = :defense if [1,2,3].include?($game_party.lastest_unit.slot_id)
  1453. check = :offense if [4,5,6].include?($game_party.lastest_unit.slot_id)
  1454. return type == check
  1455. end
  1456. return -1
  1457. end
  1458. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement