CoralMUD-0.15/
CoralMUD-0.15/core/
CoralMUD-0.15/data/
CoralMUD-0.15/data/areas/
CoralMUD-0.15/data/help/
CoralMUD-0.15/data/players/
CoralMUD-0.15/lib/automap/
CoralMUD-0.15/lib/items/
# definitions unique to players for the purpose of scripting.
# It's really just to make it easier on builders.
module PlayerDSL
  include ScriptEnvironment

  def verb cmd, arg=nil
    execute_command(cmd, arg)
  end
end


class Player
  attr_accessor :pathtarget, :clas, :race, :sign, :traits, :socket, :name, :password, :level, :channel_flags, :flags,
                :editing, :security
  include CoralMUD::FileIO ### Players can be saved.  This also implies Readable
  include CoralMUD::HasStuff ### Makes this a generic container for any stuffs.   At the time of adding this it was for objects to be carried.
  include CoralMUD::LivingEntity
  include PlayerDSL

  @@version = 1 # Current version.  This can be increased to make changes to the save structure.
                # This is only required to change if there's a particular change in old variables/structure.

  def initialize
    # use conditional initialization
    initialize_security
    @socket         = nil
    @name           = nil
    @password       = nil
    @level          = 1
    @pathtarget     = nil
    @channel_flags  = {}
    @flags = []
    @editing        = []
    ### Will probably remove these 4.
    @clas         = nil
    @race         = nil
    @sign         = nil
    @traits       = nil
    ### Inventory 
    @inventory    = nil
  end

  # saved instance variables.  Called by writable module.
  def to_configure_properties
    ['@name', '@password', '@level', '@security', '@channel_flags', '@clas', '@race', '@traits', '@sign', '@stuff']
  end

  # hook to configure for versioning.  This method doesn't need to be defined if
  # we aren't going to version manage.  When we change versioning we can edit this.
  def version_config version, data
  end

  def data_transform_on_save map
    # stuff needs to be get_configure
    temp_stuff = []
    each_stuff do |item|
      temp_stuff << item.gen_configure
    end
    map['@stuff'] = temp_stuff
    return map
  end

  def data_transform_on_load v, map
    # transform each item facade.
    arr = map['@stuff']
    arr.each do |i|
      item = ItemFacade.new(nil, false)
      item.configure(i) # loads each room file.
    
      self.accept item
    end
    map.delete '@stuff'

    return map
  end

  #save pfile
  def save_pfile 
    save_to_file ("data/players/%s.yml" % @name.downcase.capitalize)
  end

  #load pfile based on name passed.  return the new ch.
  def self.load_pfile passed_name
    ch = Player.new
    ch.load_from_file("data/players/#{passed_name.downcase.capitalize}.yml")
    return ch
  end

  def free_player
    $dplayer_list.delete self
    from_room if in_room != nil
    @socket.player = nil if @socket
  end
end