#=====================================================
# Multi-slot equipment script
#------------------------------------------------------------------------------
# Guillaume777
# 6.2.1
# 2006/02/14
#=========================================================
#To change slots of character
#     $game_actors[1].weapon_slots = [0,0]
#     $game_actors[1].armor_slots = [2,3,4,5,6,7]
#
#To make armor equipable in new slot :
#     Add (5) in its name, where 5 is its slot number
#To make 2handed weapons :
#     Add an element called 2handed to a weapon
#     or, adds its id in TWO_HANDED_WEAPONS = []
#     or, adds (2handed) in its name
#To make a weapon double attack
#     Add an element called 2attacks to a weapon
#     or, adds its id in DOUBLE_ATTACK_WEAPONS = []
#     or, adds (2atks) in its name
#To make a weapon/armor cursed
#     Adds its id in CURSED_WEAPONS or CURSED_ARMORS, or
#     put (cursed) in its name
#To make a weapon require an offhand instead of any weapon
#     Adds its id in NEEDS_OFFHAND or
#     Adds (needs_offhand) in its name
module G7_MS_MOD #you set the default names,slots, etc here

#========Set weapon/armor properties ===================
CURSED_WEAPONS = [36,37]                          #ids of weapons to be cursed
CURSED_ARMORS = [39,40]                           #ids of armors to be cursed

TWO_HANDED_WEAPONS = [17]                         #ids of 2handed weapons
DOUBLE_ATTACK_WEAPONS = [4]                       #ids of double attack weapons
 NEEDS_OFFHAND = [3,4,5,6,7,8,9,10,11,12,25,
        26,27,28,29,30,31,32,33,34,35,36,37,38]

 SWITCH_EQUIP_WEAPONS = [[38,36], [43,42]]
 SWITCH_EQUIP_ARMORS = [[41,40], [42,39]]
 # use 1 array, first value of array = false item, second value = true item

 #=========Set weapon/armor properties with element tagging and name edit=======
 CURSED_STRING = 'cursed' # put (cursed) in item name for it to be cursed
 HANDS_ELEMENT = 'handed' #nb of hands in front of HANDS_ELEMENT in the database
 HANDS_STRING = 'handed' # name of string in item name like (2handed)

 MULTI_ATTACK_ELEMENT = 'attacks' #name of element to tag to multi attacks like
                                  # (2attacks)
 MULTI_ATTACK_STRING = 'atks' #string in item name, like (3atks)

 NEEDS_OFFHAND_STRING = 'needs_offhand' #string in item name if the weapon
                                        #needs an offhand like (needs_offhand)
 #=====Set character slots properties ===================
 WEAPON_KINDS = [0,0] #number of weapons,  0 = weapon
 WEAPON_KIND_NAMES = ['Prawa ręka', 'Lewa ręka'] #custom name of extra weapon slots,
 WEAPON_KIND_POWERS = [100, 100] # 100 = normal power, 90 = 90% power, etc
 #leave empty or put nil inside if you want default name
 ARMOR_KINDS = [1,2,3,4,5,6,7]
# 1 = shield
# 2 = helmet
# 3 = armor
# 4 = acc
# 5 = and more : extra slot
 EXTRA_SLOT_NAMES = ['Rękawice','Buty','Amulet']
#Name of the extra slots in equip window
#You need as many words as there are '5' or more in armor_kinds
#The first order of the slots names reflect the order of the 5 in armor_kinds
#Put (5) or more to in the armor name to have it assigned to the extra slot

 #=============Set multi-weapon behavior================
 IGNORE_OFFHAND = false #ignore off_hand support
 TWOHANDED_IN_OFFHAND = true #if false don't show two handed weapon in offhand
                                 #window
 ALL_WEAPONS_FOR_SKILLS = true #true = combined power of all weapons for skills
                               #false = only power of first weapon
 SHIELD_HAND_SLOT = 1 #slot number to be used for shield hand
 WEAPON_SHIELD_SHARE = true #if true, dont use shield and second weap at same time
 SHIELD_HAND_WIELD = true#true = allow to use shield hand for two handed weapon
 WEAPON_HAND_WIELD = true #true = allow to use weapon hand for two handed weapon
 MULTI_WEAPONS_PENALITY = 0 #percent of atk
                            #that will be substracted if you use two weap
 #============Set appearance properties ===============
 FONT_NAME = 'Arial' #font to use
 CURSED_COLOR = Color.new(255, 50, 50) #color of cursed equiped items
 SHOW_REMOVE = false #show empty in offhand window
 
 WINDOWS_STRETCH = true #true : equip_right stretch to adjust to nb of slots
 MAX_SHOW_SLOTS = 6 #maximum number of slots in 1 screen in equip right window
 #Useless if windows_stretch = false
 HELP_AT_BOTTOM = false #if true : will leave place for help window at bottom
                       #useless if you didn't mofidy the help window y coordinate

 STATUS_WINDOW_ARRANGE = true #if true : you get a new status window.
 EVADE = false # if draw_actor_parameter is configured to receive parameter 7
 #( evade ), then it will show in new status window
 # EVADE = true has no effect if STATUS_WINDOW_ARRANGE is false
#================ end of settings =================
 def initialize
   super
   RPG.set_new_item_types #fix armor and weapon properties at start of game
 end
end #end module

module RPG
  def RPG.set_new_item_types
    if @initialized_item_types then return end
    for armor in $data_armors #for each armor
       unless armor == nil #if armor
          armor.set_adv_type #set new type
          armor.set_cursed #set if item is cursed or not
       end
    end
    for weapon in $data_weapons #for each armor
      unless weapon == nil #if armor
         weapon.set_needs_offhand #set if it needs an offhand or not
         weapon.set_nb_hands #set the number of hands to wield it
         weapon.set_nb_attacks #set the number of attacks it can do
         weapon.set_cursed #set if item is cursed or not
      end
    end
    @initialized_item_types = true
  end
  def RPG.initialized_item_types=(bool)
    @initialized_item_types = bool
  end
#--------------------------------------------------------------------------
# New armor type = number in name of armor
#--------------------------------------------------------------------------
 class Armor
  attr_accessor :cursed
  def set_adv_type
    pattern =  /\((\d+)\)/
    if @name.sub!(pattern, '') != nil
      @kind = $1.to_i - 1 #set kind to number in name of armor
    end
  end
  def set_cursed
    pattern = '('+G7_MS_MOD::CURSED_STRING+')'     
    if @name.sub!(pattern, '') != nil then cursed = true end
    if G7_MS_MOD::CURSED_ARMORS.include?(@id) then cursed = true end
    @cursed = cursed
  end
 end #end armor

 class Weapon
  attr_accessor :needs_offhand #does it need an offhand weapon
  attr_accessor :nb_hands #numbers of hands it requires
  attr_accessor :nb_attacks #number of attacks it can do
  attr_accessor :cursed #true if item is cursed
  def set_cursed
    pattern = '('+G7_MS_MOD::CURSED_STRING+')'
    if @name.sub!(pattern, '') != nil then cursed = true end
    if G7_MS_MOD::CURSED_WEAPONS.include?(@id) then cursed = true end
    @cursed = cursed
  end
  def set_needs_offhand
    pattern = '('+G7_MS_MOD::NEEDS_OFFHAND_STRING+')'
   if @name.sub!(pattern, '') != nil then
    @needs_offhand = true
   elsif G7_MS_MOD::NEEDS_OFFHAND.include?(self.id) then
    @needs_offhand = true
   elsif @needs_offhand== nil then
    @needs_offhand = false
   end
  end
#--------------------------------------------------------------------------
# Returns number of hands needed for weapons
#--------------------------------------------------------------------------
 def set_nb_hands
   if G7_MS_MOD::TWO_HANDED_WEAPONS.include?(self.id) then
    nb_hands = 2
   end
   pattern = /\((\d+)#{G7_MS_MOD::HANDS_STRING}\)/
   if @name.sub!(pattern, '') != nil
     nb_hands = $1.downcase.delete('a-z')
     nb_hands = $1.to_i
   end
   for elementnb in self.element_set #search element
    elementname = $data_system.elements[elementnb].downcase
    if elementname.delete('0-9') == G7_MS_MOD::HANDS_ELEMENT.downcase #if weapons has element for another attack
     elementname = elementname.delete('a-z') #get the nb of attacks
     if elementname != '' then
      nb_hands = elementname.to_i
     end
    end
   end
   if nb_hands.is_a?(Integer) == false or nb_hands <= 0 then nb_hands = 1 end
   @nb_hands = nb_hands
  end #end nb_hands

#--------------------------------------------------------------------------
# Returns the number of attack the weapon can do
#--------------------------------------------------------------------------
  def set_nb_attacks
   if G7_MS_MOD::DOUBLE_ATTACK_WEAPONS.include?(self.id) then
    nb_attacks = 2
   else
    nb_attacks = 1
   end

   pattern = /\((\d+)#{G7_MS_MOD::MULTI_ATTACK_STRING}\)/
   if @name.sub!(pattern, '') != nil
     nb_attacks = $1.downcase.delete('a-z')
     nb_attacks = $1.to_i
   end

   for elementnb in self.element_set #search element that could
    #add more attacks
    elementname = $data_system.elements[elementnb].downcase
    if elementname.delete('0-9') == G7_MS_MOD::MULTI_ATTACK_ELEMENT.downcase #if weapons has element for another attack
     elementname = elementname.delete('a-z') #get the nb of attacks
     if elementname != '' then
      nb_attacks = elementname.to_i
      self.element_set.delete(elementnb) #delete the element
     end
    end
   end
   if nb_attacks.is_a?(Integer) == false or nb_attacks <= 0 then nb_attacks = 1 end
   @nb_attacks = nb_attacks
  end #end nb_attack
 end #end weapon
end #end module