daily pastebin goal
11%
SHARE
TWEET

Untitled

a guest Jul 12th, 2018 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Room Class
  2. class Room
  3.   include DataMapper::Resource
  4.   property :oid, Integer, :key => true
  5.   property :name, String, :default => 'Unnamed'
  6.   property :display_name, String, :default => 'Unnamed'
  7.   property :desc, Text, :default => 'A nondescript room.'
  8.   property :exits, Object # Hash of exit.name => exit.oid
  9.   property :commands, Object # Hash of cmd.name => cmd.obj
  10.   property :occupants, Object # Array of player oid
  11.   property :contents, Object # Array of item oid
  12.   property :owner, Integer # oid of owner
  13.   property :created_at, DateTime
  14.   property :updated_at, DateTime
  15.  
  16.   def enter(player)
  17.     room = self
  18.     player.parent_obj = room.oid
  19.     room.occupants << player.oid
  20.     player.save
  21.     room.save
  22.     player.io.puts("You have entered #{room.name}.")
  23.   end
  24.  
  25.   def leave(player)
  26.     room = self
  27.     room.occupants.delete(player.oid)
  28.     player.parent_obj = nil
  29.     player.io.puts("You have left #{room.name}.")
  30.   end
  31. end
  32.  
  33. # Player Class
  34. class Player
  35.   include DataMapper::Resource
  36.   property :oid, Integer, :key => true
  37.   property :name, String, :default => "Unnamed"
  38.   property :display_name, String, :default => "Unnamed"
  39.   property :desc, Text, :default => "A nondescript person."
  40.   property :type, String, :default => 'player'
  41.   property :owner, Integer
  42.   property :pwhash, String, :length => 32
  43.   property :access, String
  44.   property :ip, String
  45.   property :connected, Boolean
  46.   property :last_connect, DateTime
  47.   property :ship, Integer
  48.   property :credits, Integer
  49.   property :race, String, :default => "human"
  50.   property :class, String
  51.   property :sex, String
  52.   property :health, Integer
  53.   property :str, Integer, :default => 10
  54.   property :dex, Integer, :default => 10
  55.   property :int, Integer, :default => 10
  56.   property :wis, Integer, :default => 10
  57.   property :con, Integer, :default => 10
  58.   property :cha, Integer, :default => 10
  59.   property :created_at, DateTime
  60.   property :updated_at, DateTime
  61.   property :in_combat_with, Object # Array of enemy.oid
  62.   property :parent_obj, Integer # typically the room.oid the player is in
  63.   property :inventory, Object # Array of item.oid
  64.   property :prefs, Object # Hash of pref_key => pref_value
  65. end
  66.  
  67. # create first room in the database
  68. room = Room.new(:oid => 0,
  69.   :name => "Room Zero",
  70.   :display_name => "Room Zero",
  71.   :desc => "The initial room object",
  72.   :owner => 1)
  73. room.save
  74.  
  75. # create the first player in the database
  76. player = Player.new(:oid => 1,
  77.   :name => "NewPlayerTest",
  78.   :pwhash => "acbd18db4cc2f85cedef654fccc4a4d8",
  79.   :access => 'admin')
  80. player.save
  81.  
  82.  
  83. steve@dungeon:~/MyRubyMud$ ruby mud.rb
  84. /usr/lib/ruby/gems/1.8/gems/extlib-0.9.13/lib/extlib/hook.rb:248:in `execute_before_create_hook_nan_hook_stack': undefined method `<=' for nil:NilClass (NoMethodError)
  85.         from /usr/lib/ruby/gems/1.8/gems/extlib-0.9.13/lib/extlib/hook.rb:298:in `create_hook'
  86.         from /usr/lib/ruby/gems/1.8/gems/extlib-0.9.13/lib/extlib/hook.rb:297:in `catch'
  87.         from /usr/lib/ruby/gems/1.8/gems/extlib-0.9.13/lib/extlib/hook.rb:297:in `create_hook'
  88.         from /usr/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/resource.rb:567:in `save_self'
  89.         from /usr/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/resource.rb:333:in `save'
  90.         from mud.rb:46
  91. steve@dungeon:~/MyRubyMud$ rm world.db db.log
  92. steve@dungeon:~/MyRubyMud$ ruby1.9.1 mud.rb
  93. /opt/ruby1.9.1/lib/ruby1.9.1/gems/1.9.1/gems/extlib-0.9.13/lib/extlib/hook.rb:248:in `execute_before_create_hook_nan_hook_stack': undefined method `<=' for nil:NilClass (NoMethodError)
  94.         from /opt/ruby1.9.1/lib/ruby1.9.1/gems/1.9.1/gems/extlib-0.9.13/lib/extlib/hook.rb:298:in `block in create_hook'
  95.         from /opt/ruby1.9.1/lib/ruby1.9.1/gems/1.9.1/gems/extlib-0.9.13/lib/extlib/hook.rb:297:in `catch'
  96.         from /opt/ruby1.9.1/lib/ruby1.9.1/gems/1.9.1/gems/extlib-0.9.13/lib/extlib/hook.rb:297:in `create_hook'
  97.         from /opt/ruby1.9.1/lib/ruby1.9.1/gems/1.9.1/gems/dm-core-0.10.0/lib/dm-core/resource.rb:567:in `save_self'
  98.         from /opt/ruby1.9.1/lib/ruby1.9.1/gems/1.9.1/gems/dm-core-0.10.0/lib/dm-core/resource.rb:333:in `save'
  99.         from mud.rb:46:in `<main>'
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top