1. #==============================================================================
  2. # ** Game_Party
  3. #------------------------------------------------------------------------------
  4. # This class handles parties. Information such as gold and items is included.
  5. # Instances of this class are referenced by $game_party.
  6. #==============================================================================
  7. class Game_Party < Game_Unit
  8. #--------------------------------------------------------------------------
  9. # * Constants
  10. #--------------------------------------------------------------------------
  11. ABILITY_ENCOUNTER_HALF = 0 # halve encounters
  12. ABILITY_ENCOUNTER_NONE = 1 # disable encounters
  13. ABILITY_CANCEL_SURPRISE = 2 # disable surprise
  14. ABILITY_RAISE_PREEMPTIVE = 3 # increase preemptive strike rate
  15. ABILITY_GOLD_DOUBLE = 4 # double money earned
  16. ABILITY_DROP_ITEM_DOUBLE = 5 # double item acquisition rate
  17. #--------------------------------------------------------------------------
  18. # * Public Instance Variables
  19. #--------------------------------------------------------------------------
  20. attr_reader :gold # party's gold
  21. attr_reader :steps # number of steps
  22. attr_reader :last_item # for cursor memorization: item
  23. #--------------------------------------------------------------------------
  24. # * Object Initialization
  25. #--------------------------------------------------------------------------
  26. def initialize
  27. super
  28. @gold = 0
  29. @steps = 0
  30. @last_item = Game_BaseItem.new
  31. @menu_actor_id = 0
  32. @target_actor_id = 0
  33. @actors = []
  34. init_all_items
  35. end
  36. #--------------------------------------------------------------------------
  37. # * Initialize All Item Lists
  38. #--------------------------------------------------------------------------
  39. def init_all_items
  40. @items = {}
  41. @weapons = {}
  42. @armors = {}
  43. end
  44. #--------------------------------------------------------------------------
  45. # * Determine Existence
  46. #--------------------------------------------------------------------------
  47. def exists
  48. !@actors.empty?
  49. end
  50. #--------------------------------------------------------------------------
  51. # * Get Members
  52. #--------------------------------------------------------------------------
  53. def members
  54. in_battle ? battle_members : all_members
  55. end
  56. #--------------------------------------------------------------------------
  57. # * Get All Members
  58. #--------------------------------------------------------------------------
  59. def all_members
  60. @actors.collect {|id| $game_actors[id] }
  61. end
  62. #--------------------------------------------------------------------------
  63. # * Get Battle Members
  64. #--------------------------------------------------------------------------
  65. def battle_members
  66. all_members[0, max_battle_members].select {|actor| actor.exist? }
  67. end
  68. #--------------------------------------------------------------------------
  69. # * Get Maximum Number of Battle Members
  70. #--------------------------------------------------------------------------
  71. def max_battle_members
  72. return 4
  73. end
  74. #--------------------------------------------------------------------------
  75. # * Get Leader
  76. #--------------------------------------------------------------------------
  77. def leader
  78. battle_members[0]
  79. end
  80. #--------------------------------------------------------------------------
  81. # * Get Item Object Array
  82. #--------------------------------------------------------------------------
  83. def items
  84. @items.keys.sort.collect {|id| $data_items[id] }
  85. end
  86. #--------------------------------------------------------------------------
  87. # * Get Weapon Object Array
  88. #--------------------------------------------------------------------------
  89. def weapons
  90. @weapons.keys.sort.collect {|id| $data_weapons[id] }
  91. end
  92. #--------------------------------------------------------------------------
  93. # * Get Armor Object Array
  94. #--------------------------------------------------------------------------
  95. def armors
  96. @armors.keys.sort.collect {|id| $data_armors[id] }
  97. end
  98. #--------------------------------------------------------------------------
  99. # * Get Array of All Equipment Objects
  100. #--------------------------------------------------------------------------
  101. def equip_items
  102. weapons + armors
  103. end
  104. #--------------------------------------------------------------------------
  105. # * Get Array of All Item Objects
  106. #--------------------------------------------------------------------------
  107. def all_items
  108. items + equip_items
  109. end
  110. #--------------------------------------------------------------------------
  111. # * Get Container Object Corresponding to Item Class
  112. #--------------------------------------------------------------------------
  113. def item_container(item_class)
  114. return @items if item_class == RPG::Item
  115. return @weapons if item_class == RPG::Weapon
  116. return @armors if item_class == RPG::Armor
  117. return nil
  118. end
  119. #--------------------------------------------------------------------------
  120. # * Initial Party Setup
  121. #--------------------------------------------------------------------------
  122. def setup_starting_members
  123. @actors = $data_system.party_members.clone
  124. end
  125. #--------------------------------------------------------------------------
  126. # * Get Party Name
  127. # If there is only one, returns the actor's name.
  128. # If there are more, returns "XX's Party".
  129. #--------------------------------------------------------------------------
  130. def name
  131. return "" if battle_members.size == 0
  132. return leader.name if battle_members.size == 1
  133. return sprintf(Vocab::PartyName, leader.name)
  134. end
  135. #--------------------------------------------------------------------------
  136. # * Set Up Battle Test
  137. #--------------------------------------------------------------------------
  138. def setup_battle_test
  139. setup_battle_test_members
  140. setup_battle_test_items
  141. end
  142. #--------------------------------------------------------------------------
  143. # * Battle Test Party Setup
  144. #--------------------------------------------------------------------------
  145. def setup_battle_test_members
  146. $data_system.test_battlers.each do |battler|
  147. actor = $game_actors[battler.actor_id]
  148. actor.change_level(battler.level, false)
  149. actor.init_equips(battler.equips)
  150. actor.recover_all
  151. add_actor(actor.id)
  152. end
  153. end
  154. #--------------------------------------------------------------------------
  155. # * Set Up Items for Battle Test
  156. #--------------------------------------------------------------------------
  157. def setup_battle_test_items
  158. $data_items.each do |item|
  159. gain_item(item, max_item_number(item)) if item && !item.name.empty?
  160. end
  161. end
  162. #--------------------------------------------------------------------------
  163. # * Get Highest Level of Party Members
  164. #--------------------------------------------------------------------------
  165. def highest_level
  166. lv = members.collect {|actor| actor.level }.max
  167. end
  168. #--------------------------------------------------------------------------
  169. # * Add an Actor
  170. #--------------------------------------------------------------------------
  171. def add_actor(actor_id)
  172. @actors.push(actor_id) unless @actors.include?(actor_id)
  173. $game_player.refresh
  174. $game_map.need_refresh = true
  175. end
  176. #--------------------------------------------------------------------------
  177. # * Remove Actor
  178. #--------------------------------------------------------------------------
  179. def remove_actor(actor_id)
  180. @actors.delete(actor_id)
  181. $game_player.refresh
  182. $game_map.need_refresh = true
  183. end
  184. #--------------------------------------------------------------------------
  185. # * Increase Gold
  186. #--------------------------------------------------------------------------
  187. def gain_gold(amount)
  188. @gold = [[@gold + amount, 0].max, max_gold].min
  189. end
  190. #--------------------------------------------------------------------------
  191. # * Decrease Gold
  192. #--------------------------------------------------------------------------
  193. def lose_gold(amount)
  194. gain_gold(-amount)
  195. end
  196. #--------------------------------------------------------------------------
  197. # * Get Maximum Value of Gold
  198. #--------------------------------------------------------------------------
  199. def max_gold
  200. return 99999999
  201. end
  202. #--------------------------------------------------------------------------
  203. # * Increase Steps
  204. #--------------------------------------------------------------------------
  205. def increase_steps
  206. @steps += 1
  207. end
  208. #--------------------------------------------------------------------------
  209. # * Get Number of Items Possessed
  210. #--------------------------------------------------------------------------
  211. def item_number(item)
  212. container = item_container(item.class)
  213. container ? container[item.id] || 0 : 0
  214. end
  215. #--------------------------------------------------------------------------
  216. # * Get Maximum Number of Items Possessed
  217. #--------------------------------------------------------------------------
  218. def max_item_number(item)
  219. return 99
  220. end
  221. #--------------------------------------------------------------------------
  222. # * Determine if Maximum Number of Items Are Possessed
  223. #--------------------------------------------------------------------------
  224. def item_max?(item)
  225. item_number(item) >= max_item_number(item)
  226. end
  227. #--------------------------------------------------------------------------
  228. # * Determine Item Possession Status
  229. # include_equip : Include equipped items
  230. #--------------------------------------------------------------------------
  231. def has_item?(item, include_equip = false)
  232. return true if item_number(item) > 0
  233. return include_equip ? members_equip_include?(item) : false
  234. end
  235. #--------------------------------------------------------------------------
  236. # * Determine if Specified Item Is Included in Members' Equipment
  237. #--------------------------------------------------------------------------
  238. def members_equip_include?(item)
  239. members.any? {|actor| actor.equips.include?(item) }
  240. end
  241. #--------------------------------------------------------------------------
  242. # * Increase/Decrease Items
  243. # include_equip : Include equipped items
  244. #--------------------------------------------------------------------------
  245. def gain_item(item, amount, include_equip = false)
  246. container = item_container(item.class)
  247. return unless container
  248. last_number = item_number(item)
  249. new_number = last_number + amount
  250. container[item.id] = [[new_number, 0].max, max_item_number(item)].min
  251. container.delete(item.id) if container[item.id] == 0
  252. if include_equip && new_number < 0
  253. discard_members_equip(item, -new_number)
  254. end
  255. $game_map.need_refresh = true
  256. end
  257. #--------------------------------------------------------------------------
  258. # * Discard Members' Equipment
  259. #--------------------------------------------------------------------------
  260. def discard_members_equip(item, amount)
  261. n = amount
  262. members.each do |actor|
  263. while n > 0 && actor.equips.include?(item)
  264. actor.discard_equip(item)
  265. n -= 1
  266. end
  267. end
  268. end
  269. #--------------------------------------------------------------------------
  270. # * Lose Items
  271. # include_equip : Include equipped items
  272. #--------------------------------------------------------------------------
  273. def lose_item(item, amount, include_equip = false)
  274. gain_item(item, -amount, include_equip)
  275. end
  276. #--------------------------------------------------------------------------
  277. # * Consume Items
  278. # If the specified object is a consumable item, the number in investory
  279. # will be reduced by 1.
  280. #--------------------------------------------------------------------------
  281. def consume_item(item)
  282. lose_item(item, 1) if item.is_a?(RPG::Item) && item.consumable
  283. end
  284. #--------------------------------------------------------------------------
  285. # * Determine Skill/Item Usability
  286. #--------------------------------------------------------------------------
  287. def usable?(item)
  288. members.any? {|actor| actor.usable?(item) }
  289. end
  290. #--------------------------------------------------------------------------
  291. # * Determine Command Inputability During Battle
  292. #--------------------------------------------------------------------------
  293. def inputable?
  294. members.any? {|actor| actor.inputable? }
  295. end
  296. #--------------------------------------------------------------------------
  297. # * Determine if Everyone is Dead
  298. #--------------------------------------------------------------------------
  299. def all_dead?
  300. super && ($game_party.in_battle || members.size > 0)
  301. end
  302. #--------------------------------------------------------------------------
  303. # * Processing Performed When Player Takes 1 Step
  304. #--------------------------------------------------------------------------
  305. def on_player_walk
  306. members.each {|actor| actor.on_player_walk }
  307. end
  308. #--------------------------------------------------------------------------
  309. # * Get Actor Selected on Menu Screen
  310. #--------------------------------------------------------------------------
  311. def menu_actor
  312. $game_actors[@menu_actor_id] || members[0]
  313. end
  314. #--------------------------------------------------------------------------
  315. # * Set Actor Selected on Menu Screen
  316. #--------------------------------------------------------------------------
  317. def menu_actor=(actor)
  318. @menu_actor_id = actor.id
  319. end
  320. #--------------------------------------------------------------------------
  321. # * Select Next Actor on Menu Screen
  322. #--------------------------------------------------------------------------
  323. def menu_actor_next
  324. index = members.index(menu_actor) || -1
  325. index = (index + 1) % members.size
  326. self.menu_actor = members[index]
  327. end
  328. #--------------------------------------------------------------------------
  329. # * Select Previous Actor on Menu Screen
  330. #--------------------------------------------------------------------------
  331. def menu_actor_prev
  332. index = members.index(menu_actor) || 1
  333. index = (index + members.size - 1) % members.size
  334. self.menu_actor = members[index]
  335. end
  336. #--------------------------------------------------------------------------
  337. # * Get Actor Targeted by Skill/Item Use
  338. #--------------------------------------------------------------------------
  339. def target_actor
  340. $game_actors[@target_actor_id] || members[0]
  341. end
  342. #--------------------------------------------------------------------------
  343. # * Set Actor Targeted by Skill/Item Use
  344. #--------------------------------------------------------------------------
  345. def target_actor=(actor)
  346. @target_actor_id = actor.id
  347. end
  348. #--------------------------------------------------------------------------
  349. # * Change Order
  350. #--------------------------------------------------------------------------
  351. def swap_order(index1, index2)
  352. @actors[index1], @actors[index2] = @actors[index2], @actors[index1]
  353. $game_player.refresh
  354. end
  355. #--------------------------------------------------------------------------
  356. # * Character Image Information for Save File Display
  357. #--------------------------------------------------------------------------
  358. def characters_for_savefile
  359. battle_members.collect do |actor|
  360. [actor.character_name, actor.character_index]
  361. end
  362. end
  363. #--------------------------------------------------------------------------
  364. # * Determine Party Ability
  365. #--------------------------------------------------------------------------
  366. def party_ability(ability_id)
  367. battle_members.any? {|actor| actor.party_ability(ability_id) }
  368. end
  369. #--------------------------------------------------------------------------
  370. # * Halve Encounters?
  371. #--------------------------------------------------------------------------
  372. def encounter_half?
  373. party_ability(ABILITY_ENCOUNTER_HALF)
  374. end
  375. #--------------------------------------------------------------------------
  376. # * Disable Encounters?
  377. #--------------------------------------------------------------------------
  378. def encounter_none?
  379. party_ability(ABILITY_ENCOUNTER_NONE)
  380. end
  381. #--------------------------------------------------------------------------
  382. # * Disable Surprise?
  383. #--------------------------------------------------------------------------
  384. def cancel_surprise?
  385. party_ability(ABILITY_CANCEL_SURPRISE)
  386. end
  387. #--------------------------------------------------------------------------
  388. # * Increase Preemptive Strike Rate?
  389. #--------------------------------------------------------------------------
  390. def raise_preemptive?
  391. party_ability(ABILITY_RAISE_PREEMPTIVE)
  392. end
  393. #--------------------------------------------------------------------------
  394. # * Double Money Earned?
  395. #--------------------------------------------------------------------------
  396. def gold_double?
  397. party_ability(ABILITY_GOLD_DOUBLE)
  398. end
  399. #--------------------------------------------------------------------------
  400. # * Double Item Acquisition Rate?
  401. #--------------------------------------------------------------------------
  402. def drop_item_double?
  403. party_ability(ABILITY_DROP_ITEM_DOUBLE)
  404. end
  405. #--------------------------------------------------------------------------
  406. # * Calculate Probability of Preemptive Attack
  407. #--------------------------------------------------------------------------
  408. def rate_preemptive(troop_agi)
  409. (agi >= troop_agi ? 0.05 : 0.03) * (raise_preemptive? ? 4 : 1)
  410. end
  411. #--------------------------------------------------------------------------
  412. # * Calculate Probability of Surprise
  413. #--------------------------------------------------------------------------
  414. def rate_surprise(troop_agi)
  415. cancel_surprise? ? 0 : (agi >= troop_agi ? 0.03 : 0.05)
  416. end
  417. end
Comments powered by Disqus