tcWander(MOBWander) // ordinary wander behaviour
tcChanceToWander(ChanceBehaviour){ // make it random
numDice = 1
sides = 1000
chance = (0..5)
behaviour = ref('tcWander')
}
//declare a goblin prototype
"goblin"(MOBImpl, name:"hob-goblin", shortNames:["goblin"]){bean->
bean.parent = ref("baseMob", true)
bean.lazyInit = true
articleRequired = true
description = "This is a $name."
heartbeatBehaviours = [ref("tcChanceToWander")]
}
def $area = "my/area/name"
…
"$area:goblin"(MOBImpl){bean->
bean.parent = ref("baseMob", true)
bean.lazyInit = true
articleRequired = true
description = "This is a $name."
heartbeatBehaviours = [ref("tcChanceToWander")]
}
class Mobile implements Component {
private Set<Wearable> equipment;
// …
public void wearItem(Wearable w) {
// …
equipment.add(w);
// …
}
}
class Mobile implements Component {
private Set<Entity> equipment;
// …
public void wearItem(Wearable w) {
// …
equipment.add(w.entity());
// …
}
}
public void setEquippedItems(Set<Wearable> equipment) {
this.equipment = equipment;
}
MudObjectImpl redPill = context.getBean("blankMudObject") // get a new object from the spring context -
// or you could use a map "[:] as MudObjectImpl"
//if you wanted (would need to run "initialise" after creation tho)
redPill.setName("red pill")
redPill.setShortNames(["pill", "red pill"])
redPill.setDescription("A small, red pill. Are you ready to find out the truth? Then eat it…")
redPill.metaClass.eat = { Alive player, String str ->
if(str == "red pill" && delegate.currentContainer == player){
Thread.start(){
sendMessageToRoom(player, "You almost choke as you swallow the little red pill…",
"${player.name} looks a bit sick as he eats a red pill.")
Thread.sleep(2000)
sendMessageToRoom(player, "Wow, that feels MUCH better.", "A flash of light bursts forth from
${player.name}'s mouth as the power of a God issues forth. ")
player.subject.principals.add(new MudPrincipal("god"))
delegate.dest(true)
}
return true
}
return false
}
For anyone not familiar with the term, a component system differs from a typical class hierarchy system in that each potential "class" of object is a separate, stand-alone class definition. At runtime, the items and mobs within the mud are nothing more than a reference number or string that is associated with one or more instances of those component classes. So, a knife might be Entity #15 and have the components "MudObject" and "Weapon", rather than being a class "Knife" that extends "Weapon" which extends "MudObject".
If anyone has used or worked on such a system, I'm curious to know what you think its greatest strength and greatest weakness is/was.