Ruby programmer?

Content and general development discussion, including maps, quests, and server code from the development team.
Post Reply
Metalcore
Peon
Peon
Posts: 16
Joined: 06 Nov 2005, 20:32
Location: Georgia
Contact:

Ruby programmer?

Post by Metalcore » 07 Nov 2005, 23:09

I posted in the job postings forums and said I have ruby experience (which I do) and criptos directed me here.

I've written the majority of an IRC bot in Ruby, pretty much everying except the part that actually connects to IRC >_>
If you want look at the code (it's poorly commented, i warn you), tell me here, or PM/e-mail me.

I read on the wiki that there were plans to write a Quest script in Ruby, so I fooled around a bit, which probably won't be much help, since I have no idea what the input will be, but you can always start somewhere.

The Quest class:

Code: Select all

class Quest
	attr_accessor :gold, :invent, :exp
	def initialize(name, gold=150, exp=150, reward=[])
		#name of the quest
		@name = name
		#reward of gold
		#default 150
		@gold = gold
		#reward of item, should be array, even with one item, assumed to be an ID number
		#default nothing, empty array
		@reward = reward
		#reward of experience
		#default 150
		@exp = exp
	end
	def complete()
		#what happens after the quest is completed
		#user gets rewards of gold and experience
		$user.gold += @gold
		$user.exp += @exp
		#adds each item in the reward to the users inventory
		i = $user.invent.size
		@reward.each { |r|
			$user.invent[i] = r
			i += 1
		}
	end
end
I also had to make a dummy User class, which was simple

Code: Select all

class User
	attr_accessor :gold, :invent, :exp
	def initialize(name, gold=0, exp=0, invent=[])
		#set gold, inventory, and experience to nothing, unless given otherwise
		@name = name
		@gold = gold
		@invent = invent
		@exp = exp
	end
	def to_s
		s = ""
		@invent.each { |i| 
			s << i.to_s + " "
		}
		return "#{@name} has #{@gold} gold, #{exp} experience, and items with IDs "  + s + "."
	end
end
I then just ran some simple testing, and it all worked, for the record.

Code: Select all

$user = User.new("Evan", 50,100,[45,63])
testQ = Quest.new("Free the chicken", 40, 90, [49])
puts $user
testQ.complete()
puts $user
$user = User.new("Evan",50,100,[45,63])
testQ = Quest.new("Survive")
puts $user
testQ.complete()
puts $user
which returned

Code: Select all

Evan has 50 gold, 100 experience, and items with IDs 45 63 .
Evan has 90 gold, 190 experience, and items with IDs 45 63 49 .
Evan has 50 gold, 100 experience, and items with IDs 45 63 .
Evan has 200 gold, 250 experience, and items with IDs 45 63 .
Evan
User avatar
nym
Novice
Novice
Posts: 116
Joined: 18 Aug 2004, 11:01
Contact:

Post by nym » 08 Nov 2005, 01:34

Interesting, if you wouldn't mind it could be helpful if you started researching more into the matter of how you want to be able to do things in Ruby for TMW (Ruby class structure etc.). I am no Ruby master (i know basics, but never bothered to really learn much), so that would be helpful for when the scripting bindings are implemented.
YOU ARE READING THIS!
User avatar
criptos
Peon
Peon
Posts: 75
Joined: 20 Sep 2005, 17:00
Contact:

Post by criptos » 08 Nov 2005, 05:19

Coding at Ruby, isn´t the issue Now..

The issue now, is how to create a binding beween manaworld and ruby, so using ruby we can manage and code NPC...

:)
May the Source be With You
User avatar
criptos
Peon
Peon
Posts: 75
Joined: 20 Sep 2005, 17:00
Contact:

Post by criptos » 08 Nov 2005, 06:05

Take a loot at SWIG.

SWIGs a software development tool that connects programs written in C and C++ with a variety of high-level programming languages. SWIG is used with different types of languages including common scripting languages such as Perl, PHP, Python, Tcl, Ruby and PHP

Also, take a loot here:
The Ruby binding for KDE TMW needs this... to be able to create a NPC which can execute a Ruby script for their AI, or for something....

A Howto of embedding ruby at c++

What seems a c++ class for embedding ruby

This is all I have found so far about Ruby, Embeeding and C++
May the Source be With You
User avatar
Bjørn
TMW Adviser
TMW Adviser
Posts: 1430
Joined: 09 Dec 2004, 19:50
Location: North Rhine-Westphalia, Germany
Contact:

Post by Bjørn » 08 Nov 2005, 13:37

Ok that did it, I've removed the CSS markup for "postlink" so now default link colors apply to links in posts as well, making them visible as red.

About embedding Ruby, you're free to try it nymacro but I tried following that howto about embedding Ruby into C++ and found it too complex when compared to using a scripting language like Lua for example. I guess it depends on what we want to do with it exactly.
User avatar
criptos
Peon
Peon
Posts: 75
Joined: 20 Sep 2005, 17:00
Contact:

Post by criptos » 08 Nov 2005, 16:48

So, what we want to do exactly...

We better define that now? so no over work is done?

I think that rigth now, what we need to do, is a easy way to bind certain parts of the tmw to the ruby, so you can script with ruby...

What certain parts, mostly the control of beings....
May the Source be With You
User avatar
Crush
TMW Adviser
TMW Adviser
Posts: 8046
Joined: 25 Aug 2005, 17:08
Location: Germany

Post by Crush » 08 Nov 2005, 20:04

so what funktions do we need? scripts should be able to do the following things:

-send players through multiple choice dialogs
-artificial intelligence of the npcs (and maybe monsters, too?)
-ambient effects (animated fireplaces, birds flying around...)
-trigger events on the map when specific events happen
-we could also use the scripting language for combat skills. that would make the skill engine much more flexible than a hard coded system and would allow server admins to rebalance the existing skills or implement customized skills on their servers without having to learn c++ (ok, they have to learn ruby instead), dig through the whole server sourcecode and recompile it.


to accomplish these tasks scripts have to be capable of:

-display text windows and selection windows
-spawn and remove beings
-move beings manually
-move beings with automatic pathfinding. react when the target position has been reached or is unreachable
-read the positions and propertys of beings
-change the apperance of beings
-make map tiles walkable or blocked (open/closed door for example)
-spawn, move and remove special effects (single sprites, sprite animations or particle emitters)
-give and take items, money and skills to and from players
-temporary alter the stats of players (allows the implementation of custom buffs and status alligments)
-hurt beings and/or players with an attack that is processed by the normal damage rules (for example give players who step into lava pit 100 fire property damage)


scripts should be bound either to the whole world (cronjobs or global events), the current map (triggers for example) or to a specific object (ai scripts, status alligments).
User avatar
nym
Novice
Novice
Posts: 116
Joined: 18 Aug 2004, 11:01
Contact:

Post by nym » 09 Nov 2005, 13:48

Currently the plans are to make the scripts able to control most aspects of the server, allowing a large amount of control (only having the server core implemented in C++).

As for SWIG, i didn't look at it for the support for multiple languages, but for the ease of creating the actual language bindings. Having bindings generated for us makes maintaining scripting bindings much easier, and will also make the initial creation of them much easier.

Although i have no problems with creating the bindings by hand (it will allow more control over what is accessible, and how it is accessed). If we want to do this it would be nice to have a pure-virtual class which defines what/how the scripting bindings must operate, as this will allow further language support in the future if we require (it is also probably better from the design perspective also. And I like Lisp and Tcl...).

I would like to get feedback as soon as possible in this matter, as i plan on starting to design & code tomorrow.

Thanks :P
YOU ARE READING THIS!
User avatar
ElvenProgrammer
TMW Adviser
TMW Adviser
Posts: 2526
Joined: 13 Apr 2004, 20:11
Location: Italy
Contact:

Post by ElvenProgrammer » 09 Nov 2005, 17:58

Nothing to add, go for me! :arrow:
Metalcore
Peon
Peon
Posts: 16
Joined: 06 Nov 2005, 20:32
Location: Georgia
Contact:

Post by Metalcore » 09 Nov 2005, 22:49

sounds good to me.

another good thing about Ruby is that if we have some sort of client-side scripting, you can write simple settings file in Ruby that looks and feels like a normal text file with a few anomalies, so a player will not be required to learn Ruby to simply download and use prefab scripts.
Evan
Post Reply