=begin #=============================================================================== Title: Party Member Costs Author: Hime Date: Mar 30, 2015 URL: http://www.himeworks.com/2014/03/21/party-member-costs/ -------------------------------------------------------------------------------- ** Change log Mar 30, 2015 - added support for class party costs Mar 21, 2014 - added extended note-tag - added support for party and troop as variables - Initial release -------------------------------------------------------------------------------- ** Terms of Use * Free to use in non-commercial projects * Contact me for commercial use * No real support. The script is provided as-is * Will do bug fixes, but no compatibility patches * Features may be requested but no guarantees, especially if it is non-trivial * Credits to Hime Works in your project * Preserve this header -------------------------------------------------------------------------------- ** Description This script introduces the concept of "Member Cost", which is the cost to have a member in your unit. The cost to have actors in the party is referred to as "Party Cost". A party has a "Max Party Cost" property that is used to determine whether you can afford to have an actor in the party or not. The "Total Party Cost" is the sum of all costs for each actor. If the total party cost exceeds the max party cost, then actors cannot be added to the party. For example, if the total party cost is 10, the max party cost is 15, and you try to add an actor with a cost of 6 to the party, the actor will not be allowed to join the party because the total cost would then become 16. -------------------------------------------------------------------------------- ** Installation In the script editor, place this script below Materials and above Main -------------------------------------------------------------------------------- ** Usage -- Setting up party costs -- To set the base cost for an actor, note-tag actors or classes with Where the formula is any valid formula that evaluates to a number. If an actor has a party cost and the actor's class also has a party cost, then the game will use the actor's party cost. The following formula variables are available a - current actor p - game party t - game troop s - game switches v - game variables If you need to use multiple lines, you can use the extended note-tag line1 line2 ... -- Changing an actor's party cost -- To change an actor's cost manually, the following script calls are provided: change_party_cost(id, amount) Where `id` is the ID of the actor you want to change. A negative ID will use the party position. So for example, -1 is the leader, -2 is the second member, and so on. The `amount` is how much the cost should change by. This can be a positive or a negative number. -- Setting up max party cost -- You can set a default max value to initialize the party with, and then change it during the game through events. -- Changing max party cost -- To change the max party cost during the game, you can use script calls. change_max_party_cost(amount) This adds the specified amount. To reduce max party cost, you can specify a negative number. set_max_party_cost(amount) This sets the max party cost to the specified amount. -- Party Cost Mode -- There are two ways to calculate total party costs. One is to count only the battle members, the other is to count everyone in the party, regardless whether they can participate in battle or not. In the configuration there is an option to choose this. -------------------------------------------------------------------------------- ** Developers You will likely need to modify your menus to add this cost information. The following properties will be useful: Game_Actor party_cost - returns the actor's party cost Game_Party max_party_cost - returns the max party cost total_party_cost - returns the party cost of all members #=============================================================================== =end $imported = {} if $imported.nil? $imported[:TH_PartyMemberCosts] = true #=============================================================================== # ** Configuration #=============================================================================== module TH module Party_Member_Costs # Variable that the max actor cost will be stored Max_Cost_ID = 10 # Max Party Cost that the party starts with Default_Party_Max = 5 # Should the cost only consider battle members, or every member in the party Battle_Members_Only = true Regex = //i Ext_Regex = /(.*?)<\/party[-_ ]cost>/im #=============================================================================== # ** Rest of script #=============================================================================== end end module RPG class BaseItem def party_cost(actor) load_notetag_party_member_costs unless @party_cost return eval_party_cost(actor) end def load_notetag_party_member_costs @party_cost = "0" res = self.note.match(TH::Party_Member_Costs::Regex) @party_cost = res[1] if res res = self.note.match(TH::Party_Member_Costs::Ext_Regex) @party_cost = res[1] if res end def eval_party_cost(a, p=$game_party, t=$game_troops, s=$game_switches, v=$game_variables) eval(@party_cost) end end end class Game_Actor < Game_Battler attr_reader :party_cost_bonus alias :th_party_member_costs_initialize :initialize def initialize(actor_id) th_party_member_costs_initialize(actor_id) @party_cost_bonus = 0 end #----------------------------------------------------------------------------- # New #----------------------------------------------------------------------------- def party_cost party_cost_base + party_cost_plus end #----------------------------------------------------------------------------- # New. Base party cost for the actor. #----------------------------------------------------------------------------- def party_cost_base cost = actor.party_cost(self) cost = self.class.party_cost(self) if cost == 0 return cost end #----------------------------------------------------------------------------- # New. Any extra party cost modifiers #----------------------------------------------------------------------------- def party_cost_plus @party_cost_bonus end #----------------------------------------------------------------------------- # New. #----------------------------------------------------------------------------- def change_party_cost(amount) @party_cost_bonus = @party_cost_bonus + amount end end class Game_Party < Game_Unit attr_reader :max_party_cost attr_reader :total_party_cost alias :th_party_member_costs_initialize :initialize def initialize @max_party_cost = TH::Party_Member_Costs::Default_Party_Max th_party_member_costs_initialize end alias :th_party_member_costs_add_actor :add_actor def add_actor(actor_id) return unless party_cost_met?(actor_id) th_party_member_costs_add_actor(actor_id) end #----------------------------------------------------------------------------- # Returns true if the party can afford to add the actor to the party #----------------------------------------------------------------------------- def party_cost_met?(actor_id) actor = $game_actors[actor_id] return false if party_cost_exceeded?(actor) return true end #----------------------------------------------------------------------------- # Returns true if total cost is greater than max cost #----------------------------------------------------------------------------- def party_cost_exceeded?(actor) self.total_party_cost + actor.party_cost > self.max_party_cost end #----------------------------------------------------------------------------- # New. Refreshes the total party cost. Usually called whenever the cost # changes #----------------------------------------------------------------------------- def total_party_cost cost_members.inject(0) {|r, mem| r + mem.party_cost} end #----------------------------------------------------------------------------- # New. #----------------------------------------------------------------------------- def cost_members TH::Party_Member_Costs::Battle_Members_Only ? battle_members : members end #----------------------------------------------------------------------------- # #----------------------------------------------------------------------------- def change_max_party_cost(amount) set_max_party_cost(@max_party_cost + amount) end def set_max_party_cost(amount) @max_party_cost = [amount, 0].max end end class Game_Interpreter def change_party_cost(id, amount) if id < 0 actor = $game_party.members[-1*id - 1] else actor = $game_actors[id] end actor.change_party_cost(amount) end def change_max_party_cost(amount) $game_party.change_max_party_cost(amount) end def set_max_party_cost(amount) $game_party.set_max_party_cost(amount) end def party_cost_met?(actor_id) $game_party.party_cost_met?(actor_id) end end