Today on the internet…

Today while sitting in the bbg IRC (freenode.net / #bbg) , an epic(!) battle occurred!

lmaopirate has joined
[11:56]    lmaopirate: ARRR ME HEARTIES
[11:56]    lmaopirate fires a cannon at lolninja.
[11:56]    roflsamurai: ahhhhh!
[11:56]    lmaopirate has disconnected: Client Quit
[11:57]    lolninja: lol wtf

Zork/MUD-like basic item structure

So at work the other day I was explaining Lantern to a buddy (@shamuspeveril) and we somehow got onto the topic of how well nodejs would work for a zork like game or a mud. Well, sure enough, with the idea stuck in my head I sat down today and tried to think through. Luckily I think this concept will apply well to what I hope to do with the Lantern server, so I don’t feel like I deviated too much from my path.

In case you are not sure what a MUD is, this is a brief description grabbed from wiki :

MUDs combine elements of role-playing games, hack and slash, interactive fiction, and online chat. Players can read or view depictions of rooms, objects, other players, non-player characters, and actions performed in the virtual world. Players typically interact with each other and the world by typing commands that resemble a natural language.

And if you don’t know what Zork is… Leave. Just go.

Anyways, making the basic nodejs server to handle limited verbs was pretty simple. Ex:
Server:

[code]
var http = require("http");
var url = require("url");
var fs = require("fs");
var sys = require("sys");
var qs = require("querystring");
var send404 = function(res){
res.writeHead(404);
res.write(‘404’);
res.end();
}

var server = http.createServer(function(req,res)
{
var path = url.parse(req.url).pathname;
sys.puts(path);
switch (path)
{
case "/":
fs.readFile(‘mud/index.html’, ‘utf8’, function(err, data)
{
if(err) {
res.writeHead(500, {});
res.end();
throw err;
}

res.writeHead(200, {
‘Content-Length’: data.length
, ‘Content-Type’: ‘text/html’
});
res.write(data);
res.end();
});
break;

case "/command":
var commands = qs.parse(url.parse(req.url).query).commands;
handleCommands(commands);
break;
default:
if (/\.(js|html|swf)$/.test(path)){
try {
var swf = path.substr(-4) == ‘.swf’;
res.writeHead(200, {‘Content-Type’: swf ? ‘application/x-shockwave-flash’ : (‘text/’ + (path.substr(-3) == ‘.js’ ? ‘javascript’ : ‘html’))});
res.write(fs.readFileSync(__dirname + path, swf ? ‘binary’ : ‘utf8’), swf ? ‘binary’ : ‘utf8’);
res.end();
} catch(e){
send404(res);
}
break;
}

send404(res);
break;
}
});

server.listen(8000);

function handleCommands(commands)
{
var commandArr = commands.split(" ");
verbs(commandArr[0]);
}

function verbs(v)
{
switch(v)
{
case "n":
case "north":
sys.puts("Moving north");
break;
case "s":
case "south":
sys.puts("Moving south");
break;
}
}
[/code]

Client :

[code]
$(function(){
var commandObj = {
commands: document.getElementById(‘commands’).value
}

$.get("http://localhost:8000/command", commandObj,
function(data)
{

}
, "json");
});
[/code]

So that just handles north/n and south/s but you can see how it would progress. Which should lead you to the problem I hit when I added the “south” command block – That is going to be one massive switch statement. So instead of continuing forward with my massive switch I decided to think about it yesterday and I think I came up with a solution that I will use also in Lantern for my crafting system.

The system relies on the item know what is can do and containing all the information that would make it able to control itself instead of a large switch/case on my part. And this whole set up is made 100 times easier because I’m going to be using mongodb.  Here’s some pseudo code to give you an idea of what I’m talking about:

[code]

{
type:"Room",
exits:
{
north:{desc:"You see an exit to the north",room:3242},
south:{desc:"There’s a small door that seems to be locked",room:123}
},
description: "You’re in a big room with two doors.",
items:"123,63,7456,34,99,4563,215789,45"

commands:
{
look:{desc:"The room you are in is stupidly large with only two tiny doors, one to the north and a seemingly locked one to the south."};
yell:{desc:"You shout at the top of your lungs and you just hear your voice echoing mockingly off the walls."}
}
}

{
type:"Item",
id:123,
description: "The rock is small and perfectly circular.",
commands:
{
take:{desc:"You take the rock and put it in your backpack.",callback:"addToInventory"};
}
}

{
type:"Item",
id:99,
description: "A small glass bottle filled with an unknown liquid."
commands:
{
combine:{desc:"Blah blah", callback:combineWith, ingredients:4345, creates:8456}
}
}

[/code]

As you can see with a system like this, each item is responsible for knowing everything about it and the other items it interacts with. While this make be more difficult to create up front, I feel that once the system is in place I could easily use this in Lantern, a MUD or really any game going forward.

Or maybe I’m brutally over thinking the problem. Is there a better way to handle item relations and verbs?  Would a massive switch/case with all the different verbs I want be the way to go?  Even if I got that path, I need a similar structure to above just for the content. And then added a simple onetime use command like “lick” or something would require new code instead of just text.

Let me know what you think. I will be starting on code like this soonish for Lantern and would like to have a method pinned out. Right after I figure out the mapping issues I’m having ^^

Updates to Openbracket

There have been a few changes here and a few more are on the way.  Most notably is that here forward I will attempt to use excerpts to reduce the ‘wall of text’ that my blog was/is. Please let me know in the comments what you think of this change. If people like it I’ll keep it, otherwise I’ll revert. Another change that will be coming soon is a Lantern page where I will keep an updated overview of the game and it’s features.
Hope everyone likes these changes ^^

Lantern's Market

I would like to explore and get some thoughts out of my head on this topic.  But before I get too far into this, I should first explain a little about Lantern’s item system, crafting, questing, rare items and in general how they are collected.

A feature that hasn’t been fully scoped out yet, but roughly exists in my head is the crafting system for lantern (another post later) which will rely heavily on a rather different stat system, but that’s another post as well. The crafting system will be similar to that you find in many other games when it comes to the end result. Players will be able to create items from raw materials to sell. The big difference is if I make a sword and you make a sword, these swords could end up being very different.  The quality of the sword, it’s bonuses and other attributes will depend on the maker. For the market this means that items won’t all be priced the same and players will need to figure out what is attributes are  valued when making and buying certain items.

The next interesting note is there will only be a handful of NPC’s that sell items. Most of the items in the game will end up being player made.

A third factor is that this game will maintain a living universe. This means that rare drops from a certain boss/challenge will likely only happen the once. This means there will actually be items in the game that only one person will ever have.

Fourthly with monsters having limited to no drops a player will almost be forced to play the market to make money. That’s right. No grinding for loot. You can grind for everything else but that 😛

And finally, markets will be localized. What I mean by this is that if you put an item for sale in a town ‘a’, those in town ‘b’ can’t see it. The issue with this, if I want the system to remain logical, is how the player can have an item on sale in town if they aren’t there? A few story idea’s have crossed my mind, but the one I think I’m going to go with is a group who offers you handle sales of items for a small percentage.

With all these different factors, my intention to allow the market to have the freedom to grow as it will (no imits on prices),  all players being able to craft to some extent and the ability to have players run a monopoly, I believe this could be a very interesting system.

Lantern's server to date

For Lantern I am going out of my comfort zone. Way out of my comfort zone and all of this is new to me, so this post is going to double as a way for me to remember what I’m doing and as a way to ask about improvements/suggestions for my set up.

Firstly, I am using JS on the front end for my map. I’ve decided to go with jQuery as my library since  I find it makes things similar to AS3 which is where I’m most comfortable.

Next, I’m using nodeJS for the server. I’ve never before used anything but apache and it’s really different for me to handle the way it serves pages.

Since I’m using nodeJS and I’m trying new things, I decided to use mongoDB for the database. This is the first time I’ve used something other than MySQL so you can image the shock for me when I first started storing objects or when I had to set up a driver. The one that looked most promising to me and the one I went with in the end is Christv’s node native mongodb driver.

Finally, since my map system for Lantern will have real time updates I decided to lean on socket.io to handle my clients/communicate. This sits nicely on top of nodeJS but was the one that gave me the most trouble. First with it’s repo and the zip’s not having all the necessary files and then trying to figure out where the hell all the files belong. The client folder belongs in the root of the file you are running in node just in case anyone is wondering.

And as it turns out, today I was finally able to get all these different components running through nodeJS on my Ubuntu VM. Over the next few days I hope to be able to merge all these different tests into a single working example that I can hand to a few friends maybe that will be interested in helping.

But anyways, this setup is coming along nicely and it pleasant to see all the pieces fall in line. Hopefully the login;register will be rewritten soon to use with new system without too much trouble.

Lantern version goals

Here’s my plan:

v0.1

  • Player creatation/login
  • Some sort of design – rough
  • A working home page – This break down into:
    • Inventory
    • Player stats
    • Equipable items
  • A working map page
    • Players can see other players on the map and move around
    • Can engage in combat
    • Map will update as players move
    • Actual art and proper layout
  • Admin tools for:
    • Item/NPC/Creature/Quest creatation
    • Map editting tool – Torn on how to make this tool. If I use AIR it would be much faster for me to make and would, I think, run faster with all the elements beinging on the local machine.  Web based has the bonus of access from anywhere. I’m leadning towards AIR but I’ll put more thought into this after I get the map mostly working with nodejs

v0.2 – Private alpha

  • Forum
  • Parties
  • A 30% (at least) complete map with art
  • NPC with basic quest

v0.3

  • player levels/skills/stats/crafting options complete

v0.4

  • Complete implementation of the living universe quest system
  • Game libraries – Records of the games history

v0.5

  • First major story arch added.
  • Creature AI
  • Creature population

v0.6

  • Map art 75% complete
  • Market

v0.7

  • Populate world with towns/npcs

v0.8- Beta

  • Site’s final art/layout
  • Minor quests and major arch 2

v0.9

  • Balancing
  • Load testing / optimizations
  • Bug fixing

v 1.0 – Launch

  • Donatation page
  • Site Ads
  • Ad campagain
  • Dance party
MarketMarket

Lantern Map

Look at this awesome map! Look at it!

This is a rough map I made in a few minutes for my friend William aka jetfx (http://jetfx.livejournal.com/). William is a cartographer, a world builder freak and an aspiring author. He will hopefully be helping me with my maps and story for Lantern as we move forward. Whenever he has a better map that the pretty epic one I drew, I’ll post it for you all to see.

*UPDATE*

William, being pretty damn quick, thought my map looked too crappy to share so he cleaned it up for me as you can see. I decided to leave mine so you can see how much better he is and why I’m pretty stoked he’s agreed to help.

Random Encounters

Progress on Random Encounters, a mini-game of sorts that I am using as a test bed for some of my Lantern concepts, is slowly trucking along.  The game engine along with it’s content creation tools are almost complete. Skinning hasn’t been thought about yet, but the game itself is close.  Something that I need to do and haven’t yet is find a *cheap* host that will allow me to install mongo and nodejs.  Emphasis on cheap as I am broke.

Random Encounters for me is a test for mongo, some simple js. though the initial build won’t have it and some gameplay concepts that aren’t nessicairly related to lantern but ones I am playing with.

The game will constantly be in beta and will be my playground for new idea’s and tests.  After the current road map I have in mind is complete, which I will write down and post later, I will likely publish all the code for people to use if they have the urge to host a crappy game.

Anyways, here’s a little snippet of code for mongo to get a random record that took me a while to get working.

[code]

$numOfCreatures = $collection->count();
$ranCreatureId = floor(rand(0,$numOfCreatures-1));
$ranCreateObj = $collection->find()->limit(-1)->skip($ranCreatureId)->getNext();

[/code]

Windows + VirtualBox + Ubuntu + nodejs = hooray!

As I’m sure some of my readers (all four of you) may know because of the IRC room, I’ve lately been trying to get nodejs running on a virtual machine (ubuntu since nodejs doesn’t like windows and I don’t want to virtualize osx) that is accessible from my host (windows) so I can use it for Lantern. Well I had a few minutes tonight to sit down and do some reading and I figured it out, hence the post so I don’t forget.

I’ll go right from step one in case anyone else is trying to do this with no prior knowledge 😉 I should also mention if you’re on *nix you don’t need to do this.

  • Get virtualbox
  • Get Ubuntu (or whatever distro tickles your fancy)
  • Install a vm of ubuntu
  • Download nodejs on vm
  • Config/Make/Install – I had to install g++ and cmake to get it to build properly
  • (The tricky part) On your host (windows) navigate to your virtualbox installation via command – something like this : C:\Program Files\Sun\VirtualBox\
  • Run these commands :

VBoxManage.exe setextradata “ubuntu2” “VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestssh/Protocol” TCP
VBoxManage.exe setextradata “ubuntu2” “VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestssh/GuestPort” 8000
VBoxManage.exe setextradata “ubuntu2” “VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestssh/HostPort” 8000

  • Launch your vm, start node js and on your host in a browser go to localhost:8000- HOORAY!

So here’s what I know about the commands what you need to edit to make it work

  • Instead of “ubuntu2” use the name of your vm.
  • the guestssh isn’t important. Just a name use to group the settings. Call it whatever you want.
  • Guest and Host ports are the port you want to access on your vm.
  • If you change you’re installation at all from the default you’ll have to figure out the other changers yourself here : http://www.virtualbox.org/manual/ch06.html#natforward

Good luck ^^

Lantern Update

In my last post I was discussing Lantern’s combat and party system. These two features are very closely related to the map, which is going to be the main area of action in Lantern, so I have been thinking a lot about how to approach this map. I think from some discussions I have had with people in the #bbg irc room and with a few coworkers, I’m going to try to use nodejs for handling the communication and npc logic. From my understanding of nodejs (which is very limited so please correct me if I’m wrong) I can use it to push data to players that need it and create objects at run time on the server and run based on a timer. What I’m looking to do with this functionality is to run the npc’s logic independant of players input.  I’m pretty sure nodejs will allow me to do this. All I need to do is set up linux on a virtual machine and get everything all playing nicely together so I can continue to develop on my local machine.

But as I work on Lantern and think about, the need to a test bed is becoming more apparent to me. So to fix this need I’m going to take a quick break from Lantern to make myself a small game that I can use to test different parts of Lantern. This will range from Mongo scripts to game tools (for creating quests/items/etc). The scope of the test bed currently is very limited to the mongo scripts and the game tools. If I can think of a way to test nodejs in this that would be great, but for now, just testing some idea’s around those other elements would be enough. This small game test bed will be call Random Encounters. The game is exactly what it sounds like. You click a button and you encounter things. The game will suck, but it’s purpose is testing.  This small game will hopefully be online in the next few weeks. Work has be pretty busy of late, so I haven’t been able to look at anything lately.

So that’s where I am. If anyone can confirm or deny my thoughts on nodejs that would be great.