#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
# Item Weight
# Author: ForeverZer0
# Date: 4.15.2012
# Version: 1.0
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
# VERSION HISTORY
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
# v.1.0
# - Original release
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
#
# Explanation:
# This system provides your game with an inventory "weight" feature. Every
# item and piece of equipment can be configured with an individual weight that
# provides a different dynamic to collecting items, since the player will have
# to manage their inventories instead of just collecting everything in sight.
# Settings for can be made for managing it on a "per actor basis", and various
# states can be applied when a character/party is "overweight".
#
# Features:
# - States can be applied to the whole party or individual actor basis
# - Every item, weapon, and armor can have a unique weight
# - Unlimited number of states
# - Can us a dynamic weight capacity that grows with actor power, or static
# capacity that you can control yourself via simple script calls
# - Automcatic setting of game variables that are equal to the party's current
# weight and total capacity
# - Configurable modifier that allows for defining the rate of dynamic weight
# capacity based off actor strength
# - Automatic adding of weight to item descriptions if desired so that the
# player is always aware of each item's weight
# - Configuration for allowing or not items to be picked up by party or
# equipped by actors if weight would exceed capacity
#
# Instructions:
# - Place script below default scripts, and above "Main"
# - See below and find the "Weight" module. There are a few simple settings
# that can be made with detailed descriptions of each
# - Configure item weights in the RPG::Item, RPG::Weapon, and RPG::Armor
# classes found below
# - When using STATIC_CAPACITY and you would like to change an actor's
# carrying capacity, use these script calls:
#
# $game_party.actors[ACTOR_INDEX].weight_capacity = VALUE
# OR
# $game_actors[ACTOR_ID].weight_capacity = VALUE
#
#
#
# Compatibility:
# - Custom CMS's (specifically the equip part of it), could possibly cause
# problems, and would require minor edits to ensure that items that are too
# heavy could not be equipped when OVERWEIGHT_ACTOR is false.
#
# Credits/Thanks:
# - ForeverZer0, for the script
# - Bigfoot, for requesting it
#
# Author's Notes:
# - Please report any bugs/issues to www.chaos-project.com or via email:
# foreverzer0@chaos-project.com
#
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
# BEGIN CONFIGURATION
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
#===============================================================================
# Weight
#-------------------------------------------------------------------------------
# Module for configuring various weight settings
#===============================================================================
module Weight
# Set to true/false if actor weight capacity grows with the actor's
# strength, or remains a fixed number (can be changed via script call)
DYNAMIC_CAPACITY = false
# Define the modifier for the DYNAMIC_CAPACITY. This value will be multiplied
# by the actor's strength to determine their carrying capacity. Ignore this
# setting if DYNAMIC_CAPACITY is false.
DYNAMIC_MODIFIER = 1.5
# Define the static carrying capacity that actors begin with. This value can
# only be changed via script call, and will not grow with the actor's power.
# Ignore this setting if DYNAMIC_CAPACITY is true.
STATIC_CAPACITY = 4.0
# Include the IDs of any states that will be applied when
#cweight exceeds maximum capacity.
OVERWEIGHT_STATES = [2, 3]
# Set to true/false if individual actors can become overweight, or if it is
# only on a "whole party" basis. The entire party will still be afflicted with
# states if the total weight exceeds the party's capacity. In other words,
# define if actor's can equip items that are too heavy for them.
OVERWEIGHT_ACTOR = true
# Determines if items/equipment can still be gained when current weight would
# exceed total carrying capacity after picking it up. The maximum number that
# can be added will still be received if this is false and receiving multiple
# quantities. In other words, can items still be picked up that are too
# heavy for the party.
OVERWEIGHT_PARTY = false
# Set the ID of the variable that will be equal to the party's current weight
CURRENT_VARIABLE = 10
# Set the ID of the variable that will be equal to the party's total capacity
CAPACITY_VARIABLE = 11
# Set to true/false if item weights should automatically be added to the
# description for help menu's, etc.
WEIGHT_DESCRIPTION = true
# Determines the modification of the item's description. Ignore if
# WEIGHT_DESCRIPTION is false.
# EXAMPLE: "[#{weight} lbs] #{text}"
def self.description(text, weight)
return "#{text} (#{weight} kg)"
end
end
#===============================================================================
# * RPG::Item
#===============================================================================
module RPG
class Item
#---------------------------------------------------------------------------
# * weight
# Define the weights of items (when ITEM_ID then WEIGHT)
#---------------------------------------------------------------------------
def weight
return case @id
when 1 then 0.5
when 2 then 0.75
when 3 then 1.0
when 4 then 1.0
when 5 then 1.0
when 6 then 1.0
when 7 then 1.0
when 8 then 1.0
when 9 then 1.0
when 10 then 1.0
else 1.0
end
end
#---------------------------------------------------------------------------
# * description
# Returns the modified description when WEIGHT_DESCRIPTION is true
#---------------------------------------------------------------------------
def description
return !Weight::WEIGHT_DESCRIPTION ? @description :
Weight.description(@description, weight)
end
end
#===============================================================================
# * RPG::Weapon
#===============================================================================
class Weapon
#---------------------------------------------------------------------------
# * weight
# Define the weights of weapons (when WEAPON_ID then WEIGHT)
#---------------------------------------------------------------------------
def weight
return case @id
when 1 then 1.0
when 2 then 1.0
when 3 then 1.0
when 4 then 1.0
when 5 then 1.0
when 6 then 1.0
when 7 then 1.0
when 8 then 1.0
when 9 then 1.0
when 10 then 1.0
else 1.0
end
end
#---------------------------------------------------------------------------
# * description
# Returns the modified description when WEIGHT_DESCRIPTION is true
#---------------------------------------------------------------------------
def description
return !Weight::WEIGHT_DESCRIPTION ? @description :
Weight.description(@description, weight)
end
end
#===============================================================================
# * RPG::Armor
#===============================================================================
class Armor
#---------------------------------------------------------------------------
# * weight
# Define the weights of armors (when ARMOR_ID then WEIGHT)
#---------------------------------------------------------------------------
def weight
return case @id
when 1 then 1.0
when 2 then 1.0
when 3 then 1.0
when 4 then 1.0
when 5 then 1.0
when 6 then 1.0
when 7 then 1.0
when 8 then 1.0
when 9 then 1.0
when 10 then 1.0
when 29 then 2.0
else 1.0
end
end
#---------------------------------------------------------------------------
# * description
# Returns the modified description when WEIGHT_DESCRIPTION is true
#---------------------------------------------------------------------------
def description
return !Weight::WEIGHT_DESCRIPTION ? @description :
Weight.description(@description, weight)
end
end
end
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
# END CONFIGURATION
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
#===============================================================================
# * Game_Actor
#===============================================================================
class Game_Actor
#-----------------------------------------------------------------------------
# * initailize
# Aliased method to add capacity variable to Game_Actor, which is used
# when using STATIC_CAPACITY.
#-----------------------------------------------------------------------------
alias inventory_weight_init initialize
def initialize(actor_id)
inventory_weight_init(actor_id)
@capacity = Weight::STATIC_CAPACITY
end
#-----------------------------------------------------------------------------
# * weight
# Returns the total weight of all equipped items the actor has
#-----------------------------------------------------------------------------
def weight
weight = 0
equipment = [
$data_weapons[@weapon_id],
$data_armors[@armor1_id],
$data_armors[@armor2_id],
$data_armors[@armor3_id],
$data_armors[@armor4_id]
]
equipment.each {|item| weight += (item != nil ? item.weight : 0) }
return weight
end
#-----------------------------------------------------------------------------
# * weight_capacity=
# Sets the carrying capacity of the actor when using STATIC_CAPACITY
#-----------------------------------------------------------------------------
def weight_capacity=(capacity)
@capacity = capacity
end
#-----------------------------------------------------------------------------
# * weight_capacity
# Returns the amount of weight the actor can carry
#-----------------------------------------------------------------------------
def weight_capacity
if Weight::DYNAMIC_CAPACITY
return base_str * Weight::DYNAMIC_MODIFIER
else
return @capacity
end
end
#-----------------------------------------------------------------------------
# * within_capacity?
# Factors in weight when determining if piece of equipment is equippable
# or not.
#-----------------------------------------------------------------------------
def equippable_weight?(item)
return true if item == nil || Weight::OVERWEIGHT_ACTOR
actor_weight = self.weight + item.weight
if item.is_a?(RPG::Weapon)
weapon = $data_weapons[@weapon_id]
actor_weight -= (weapon == nil ? 0 : weapon.weight)
elsif item.is_a?(RPG::Armor)
case item.kind
when 0 # Armor
armor = $data_armors[@armor1_id]
when 1 # Shield
armor = $data_armors[@armor2_id]
when 2 # Helmet
armor = $data_armors[@armor3_id]
when 3 # Accessory
armor = $data_armors[@armor4_id]
end
actor_weight -= (armor == nil ? 0 : armor.weight)
end
return actor_weight <= weight_capacity
end
#-----------------------------------------------------------------------------
# * equip
# Refreshes party weight and states after item change
#-----------------------------------------------------------------------------
alias item_weight_equip equip
def equip(kind, id)
item = kind == 0 ? $data_weapons[id] : $data_armors[id]
if equippable_weight?(item)
item_weight_equip(kind, id)
$game_party.refresh_weight
end
end
end
#===============================================================================
# * Game_Party
#===============================================================================
class Game_Party
#-----------------------------------------------------------------------------
# * weight_capacity
# Returns the cumulative weight capacity of all current party members
#-----------------------------------------------------------------------------
def weight_capacity
weight = 0
@actors.each {|actor| weight += actor.weight_capacity }
return weight
end
#-----------------------------------------------------------------------------
# * actor_weight
# Returns the total weight of all equipment worn by party members
#-----------------------------------------------------------------------------
def actor_weight
weight = 0
@actors.each {|actor| weight += actor.weight }
return weight
end
#-----------------------------------------------------------------------------
# * item_weight
# Returns the total weight of all items in inventory
#-----------------------------------------------------------------------------
def item_weight
weight = 0
@items.each_pair {|id, qty| weight += $data_items[id].weight * qty }
return weight
end
#-----------------------------------------------------------------------------
# * weapon_weight
# Returns the total weight of all weapons in inventory
#-----------------------------------------------------------------------------
def weapon_weight
weight = 0
@weapons.each_pair {|id, qty| weight += $data_weapons[id].weight * qty }
return weight
end
#-----------------------------------------------------------------------------
# * armor_weight
# Returns the total weight of all armors in inventory
#-----------------------------------------------------------------------------
def armor_weight
weight = 0
@armors.each_pair {|id, qty| weight += $data_armors[id].weight * qty }
return weight
end
#-----------------------------------------------------------------------------
# * total_weight
# Returns the total weight of all inventory and equipment that is
# equipped by the party members
#-----------------------------------------------------------------------------
def total_weight
return actor_weight + item_weight + weapon_weight + armor_weight
end
#-----------------------------------------------------------------------------
# * gain_item
# Aliased method to determine if party can add an item to inventory when
# ALLOW_OVERWHEIGHT is set to false. The maximum quantity that can fit
# will be added out of the total quanity if capacity would be exceeded.
#-----------------------------------------------------------------------------
alias item_weight_gain_item gain_item
def gain_item(id, quantity)
if Weight::OVERWEIGHT_PARTY
item_weight_gain_item(id, quantity)
else
item = $data_items[id]
weight = item == nil ? 0 : item.weight
if !enough_capacity?(weight * quantity)
allowed = (weight_capacity - total_weight) / weight
item_weight_gain_item(id, allowed.floor)
else
item_weight_gain_item(id, quantity)
end
end
refresh_weight
end
#-----------------------------------------------------------------------------
# * gain_weapon
# Aliased method to determine if party can add a weapon to inventory when
# ALLOW_OVERWHEIGHT is set to false. The maximum quantity that can fit
# will be added out of the total quanity if capacity would be exceeded.
#-----------------------------------------------------------------------------
alias item_weight_gain_weapon gain_weapon
def gain_weapon(id, quantity)
if Weight::OVERWEIGHT_PARTY
item_weight_gain_weapon(id, quantity)
else
weapon = $data_weapons[id]
weight = weapon == nil ? 0 : weapon.weight
if !enough_capacity?(weight * quantity)
allowed = (weight_capacity - total_weight) / weight
item_weight_gain_weapon(id, allowed.floor)
else
item_weight_gain_weapon(id, quantity)
end
end
refresh_weight
end
#-----------------------------------------------------------------------------
# * gain_armor
# Aliased method to determine if party can add an armor to inventory when
# ALLOW_OVERWHEIGHT is set to false. The maximum quantity that can fit
# will be added out of the total quanity if capacity would be exceeded.
#-----------------------------------------------------------------------------
alias item_weight_gain_armor gain_armor
def gain_armor(id, quantity)
if Weight::OVERWEIGHT_PARTY
item_weight_gain_armor(id, quantity)
else
armor = $data_armors[id]
weight = armor == nil ? 0 : armor.weight
if !enough_capacity?(weight * quantity)
allowed = (weight_capacity - total_weight) / weight
item_weight_gain_armor(id, allowed.floor)
else
item_weight_gain_armor(id, quantity)
end
end
refresh_weight
end
#-----------------------------------------------------------------------------
# * add_actor
# Refreshes party weight and states when actor is added to party
#-----------------------------------------------------------------------------
alias item_weight_add_actor add_actor
def add_actor(actor_id)
item_weight_add_actor(actor_id)
refresh_weight
end
#-----------------------------------------------------------------------------
# * remove_actor
# Refreshes party weight and states when actor is removed from party
#-----------------------------------------------------------------------------
alias item_weight_remove_actor remove_actor
def remove_actor(actor_id)
item_weight_remove_actor(actor_id)
refresh_weight
end
#-----------------------------------------------------------------------------
# * enough_capacity?
# Returns true/false if given weight would not exceed capacity
#-----------------------------------------------------------------------------
def enough_capacity?(weight)
return (total_weight + weight) <= weight_capacity
end
#-----------------------------------------------------------------------------
# * refresh_weight
# Refreshes the weight variables and adds/removes weight states
#-----------------------------------------------------------------------------
def refresh_weight
total, capacity = total_weight, weight_capacity
$game_variables[Weight::CURRENT_VARIABLE] = total
$game_variables[Weight::CAPACITY_VARIABLE] = capacity
# Add/remove states to party as a whole
if Weight::OVERWEIGHT_PARTY && total > capacity
@actors.each {|actor|
Weight::OVERWEIGHT_STATES.each {|state_id| actor.add_state(state_id) }
}
# Add/remove individual states for actors
elsif Weight::OVERWEIGHT_ACTOR
@actors.each {|actor|
if actor.weight > actor.weight_capacity
Weight::OVERWEIGHT_STATES.each {|state_id| actor.add_state(state_id) }
else
Weight::OVERWEIGHT_STATES.each {|state_id| actor.remove_state(state_id) }
end
}
else
@actors.each {|actor|
Weight::OVERWEIGHT_STATES.each {|state_id| actor.remove_state(state_id) }
}
end
end
#-----------------------------------------------------------------------------
# * setup_starting_members
# Alias method to set the game variables at the beginning of the game
#-----------------------------------------------------------------------------
alias item_weight_setup_starting_members setup_starting_members
def setup_starting_members
item_weight_setup_starting_members
refresh_weight
end
end
#===============================================================================
# * Scene_Equip
#-------------------------------------------------------------------------------
# This needs to be here more or less just to what can only be considered either
# bad coding or a bug in RMXP. The "equip" method of Game_Actor is constantly
# called whenever an item is highlighted in Scene_Equip, and this is kind of
# a little bypass for that.
#===============================================================================
class Scene_Equip
#-----------------------------------------------------------------------------
# * update_item
# Cancels equipping item if configured to do so and item would put
# actor overweight
#-----------------------------------------------------------------------------
alias item_weight_update_item update_item
def update_item
if Input.trigger?(Input::C)
item = @item_window.item
unless @actor.equippable_weight?(item)
$game_system.se_play($data_system.buzzer_se)
return
end
end
item_weight_update_item
end
end