diff options
author | Aaron Marks <nymacro@gmail.com> | 2005-11-15 11:41:17 +0000 |
---|---|---|
committer | Aaron Marks <nymacro@gmail.com> | 2005-11-15 11:41:17 +0000 |
commit | 3d5bcc32ea4ac19e8da7bcf4a59443f3a013ba6d (patch) | |
tree | ff833024b07a36587d02cc8c10b59cda50229bab /scripts | |
parent | 9c4f838ef2e9b801a08c3550647aff4efcbb1ebd (diff) | |
download | manaserv-3d5bcc32ea4ac19e8da7bcf4a59443f3a013ba6d.tar.gz manaserv-3d5bcc32ea4ac19e8da7bcf4a59443f3a013ba6d.tar.bz2 manaserv-3d5bcc32ea4ac19e8da7bcf4a59443f3a013ba6d.tar.xz manaserv-3d5bcc32ea4ac19e8da7bcf4a59443f3a013ba6d.zip |
Updated bindings, game state class and more (see ChangeLog).
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/init.rb | 59 |
1 files changed, 53 insertions, 6 deletions
diff --git a/scripts/init.rb b/scripts/init.rb index 25e8dbc9..290598fe 100644 --- a/scripts/init.rb +++ b/scripts/init.rb @@ -1,19 +1,66 @@ -print "Hello there, this is embedded into TMW!\n" +print "enter init.rb\n" class EquipHandler < Tmw::MessageHandler def initialize() super end - # this isn't possible -- does not override parent receiveMessage def receiveMessage(computer, message) + print "Message ID: ", message.getId(), "\n" item = message.readLong() slot = message.readByte() - print "Trying to equip ", item, " at ", slot, "\n" + print "Trying to equip ", item, " at ", slot.to_i(), "\n" + + result = Tmw::MessageOut.new() + result.writeShort(Tmw::SMSG_EQUIP_RESPONSE) + result.writeByte(Tmw::EQUIP_OK) + computer.send(result.getPacket()) + end +end + +# Override default equip message handler +Tmw::connectionHandler.registerHandler(Tmw::CMSG_EQUIP, EquipHandler.new()) + + +# Remote Ruby expression execution +class RubyHandler < Tmw::MessageHandler + def initialize() + super + print "Ruby message handler activated\n" + end + + def receiveMessage(computer, message) + src = message.readString() + print src, "\n"; + # doesn't work properly yet (need to have SWIG use std::string nicely) + #eval(src, TOPLEVEL_BINDING) + end +end + +Tmw::connectionHandler.registerHandler(0x800, RubyHandler.new()) + + +# simple enemy +class SimpleEnemy < Tmw::Being + def initialize() + super + end + + def update() + print "Updating!\n" end end -a = EquipHandler.new() -Tmw::connectionHandler.registerHandler(Tmw::CMSG_EQUIP, a) +# simple item +class SimpleItem < Tmw::Item + def initialize() + super + type = 100 + end + + def use() + print "USE THIS THING!!" + end +end -print "Done init.rb\n" +print "exit init.rb\n" |