I am working on creating "Soulbound" items to the mud. The builder would inherit LIB_SOULBOUND and add the functions to Set, Get, and Run soulbound items. I have designed SetSoulBound() to accept hard integers 0 and 1 which work great when defined in the create() of the object. But when I try to pass a function through SetSoulBound() nothing happens. So I tried to add a init() function to the inherited soulbound file to be called at the same time as the object's init() file is called at the end of eventMove() but nothing happens.
I'm trying find a way for the function passed in SetSoulBound() to be called after the object is cloned.
Files attached. Please be gentle when criticizing my coding skills or lack thereof!
The files are available for fair use with respective rights intact of contributed works.
soulbound.c (inherited file)
/* /lib/props/soulbound.c
*
* Libray object to create objects
* players cannot drop, give away,
* put in other objects (item
* smuggling) or sell
*
* created on: 20110729
* created by: Elo'him@ForgottenGods
*/
// Last Modified: 20110731 by Elo
//GetLastEnvironment()
#include <lib.h>
#include <function.h>
inherit LIB_PERSIST;
inherit LIB_OBJECT;
private mixed bound = 0;
// begin abstract methods
varargs SetRetainOnDeath();
varargs SetPreventDrop();
varargs SetPreventGet();
varargs SetPreventPut();
string GetName();
string GetCoreDesc();
string GetExternalDesc();
string GetDefiniteShort();
// end abstract methods
int GetSoulBound(){
if( intp(bound) ) return bound;
if( functionp(bound) ) return evaluate(bound, this_object());
// it's not a func or a int so its no good to us
return 0;
}
void RunSoulBound(){
// This can be called directly
//although I couldn't guess as to why
mixed responsePrevent;
responsePrevent = bound?"You cannot do that with the "+
remove_article((string)GetShort())+"; it is soul bound.":0 ;
SetPreventDrop(responsePrevent);
SetPreventGet(responsePrevent);
SetPreventPut(responsePrevent);
SetRetainOnDeath(bound);
return;
}
int SetSoulBound(mixed val){
if(intp(val)){
bound = val;
RunSoulBound();
return bound;
}
else if( !(functionp(val) & FP_OWNER_DESTED) ) {
bound = evaluate(val, this_object());
RunSoulBound();
return 1;
}
// it's not a func or a int so its no good to us
return 0;
}
mixed CanSell(){
if (!GetSoulBound()) return 1;
return "You cannot do that with the "
+(string)GetShort()+" because it is a soulbound item.";
return !GetSoulBound();
}
string GetExternalDesc(){
if( GetSoulBound() )
return GetCoreDesc()+"\n%^BOLD%^The "+
GetDefiniteShort()+" is soulbound.%^RESET%^";
else return GetCoreDesc();
}
string array GetSave(){
return ({ "bound" });
}
static mixed array AddSave(){
return persist::AddSave( ({"bound"}) );
}
void init(){
// no need to make the master soulbound!
write("\n[debug]: "+file_name()+" all clear.");
if(clonep() & functionp(bound)){
bound;
}
}
SimpleShirt.c (file inheriting soulbound.c)
/*
gamboised
Body Jerkin
Hands Gloves
Legs Chausses
Feet Ledelsens
Body Tunic
Hands Gloves
Legs Slacks
Feet Boots
Body Separates
Hands Gauntlets
Legs Loincloth
Feet Gaiters
*/
// override eventDestruct()?
#include <lib.h>
#include <armor_types.h>
#include <damage_types.h>
inherit LIB_ARMOR;
inherit LIB_SOULBOUND;
int sbItem();
void prsItem();
static void create(){
armor::create();
SetKeyName("shirt");
SetAdjectives( ({"simple"}) );
SetId( ({ "shirt" }) );
SetShort( "simple shirt" );
SetLong(
"gamboised simple shirt"
);
SetProtection( PHYS_DAMAGE, 1 );
SetSoulBound( sbItem() );
SetArmorType( A_SHIRT );
SetMaterials( ([ "textile" : 100 ]) );
SetValue( 0 );
SetMass( 1 );
}
void init(){
::init();
RunSoulBound();
if( clonep() ){ prsItem(); }
}
int sbItem(){
return creatorp(environment());
}
void prsItem(){
mapping imapp = ([]);
if(!environment() || !living(environment())) return;
switch ( environment()->GetRace() ) {
case "noor":
imapp = ([
"name" : "tunic",
"adj" : ({"simple"}),
"id" : ({ "tunic","shirt" }),
"short" : "simple tunic",
"long" : "A simple tunic",
]);
break;
case "nuar":
imapp = ([
"name" : "body wraps",
"adj" : ({"simple"}),
"id" : ({ "body wraps","hosen" }),
"short" : "simple body wraps",
"long" : "A simple body wraps",
]);
break;
case "vorskh":
imapp = ([
"name" : "jerkin",
"adj" : ({"simple"}),
"id" : ({ "jerkin","shirt" }),
"short" : "simple jerkin",
"long" : "A simple jerkin",
]);
break;
default:
imapp = ([
"name" : "shirt",
"adj" : ({"simple"}),
"id" : ({ "shirt" }),
"short" : "simple shirt",
"long" : "A simple shirt",
]);
}
SetKeyName(imapp["name"]);
SetAdjectives( imapp["adj"] );
SetId( imapp["id"] );
SetShort( imapp["short"] );
SetLong( imapp["long"] );
return;
}