Myriad Lite Creator Random
Myriad_Lite_Creator_Random-v0.0.1-20120203.lsl
// Myriad_Lite_Character_Creator-v0.0.1-20120203.lsl
// Copyright (c) 2012 By Allen Kerensky (OSG/SL)
// The Myriad RPG System was designed, written, and illustrated by Ashok Desai
// Myriad RPG licensed under the Creative Commons Attribution 2.0 UK: England and Wales
// http://creativecommons.org/licenses/by/2.0/uk/
// Myriad Lite software Copyright (c) 2011-2012 by Allen Kerensky (OSG/SL)
// Baroun's Adventure Machine Copyright (c) 2008-2011 by Baroun Tardis (SL)
// Myriad Lite and Baroun's Adventure Machine licensed under the
// Creative Commons Attribution-Share Alike-Non-Commercial 3.0 Unported
// http://creativecommons.org/licenses/by-nc-sa/3.0/
// You must agree to the terms of this license before making any use of this software.
// If you do not agree to this license, simply delete these materials.
// There is no warranty, express or implied, for your use of these materials.
integer CHANOBJECT;
integer HANDOBJECT;
integer CHANMYRIAD = -999;
integer HANDMYRIAD;
integer CHANCOMMAND = 5;
integer HANDCOMMAND;
list REGION_GENERATORS;
list REGION_POINT_POOLS;
list REGION_GENRES;
list REGION_SPECIES;
list REGION_BACKGROUNDS;
list REGION_CAREERS;
list REGION_EQUIPMENT;
list AV_STATISTICS;
list AV_RESILIENCES;
list AV_SKILLS;
list AV_BOONS;
list AV_FLAWS;
list AV_MORTAL_EFFECTS;
list AV_SOCIAL_EFFECTS;
list AV_MAGIC_EFFECTS;
list AV_VEHICLE_EFFECTS;
list AV_SPECIES;
list AV_BACKGROUNDS;
list AV_CAREERS;
list AV_EQUIPMENT;
key POSER; // who is sitting here
integer PN_SHOWCAT = 0;
integer PN_SHOWITEM = 0;
integer PN_SHOWPOOL = 0;
list RES_STATS = [];
list RES_TYPES = [];
SETUP() {
// calculate listener channel
CHANOBJECT = (integer)("0x"+llGetSubString((string)llGetKey(),0,6));
// release previous object channel
if ( HANDOBJECT != 0 ) llListenRemove(HANDOBJECT);
// start object-specific listener
HANDOBJECT = llListen(CHANOBJECT,"",NULL_KEY,"");
// release previous Myriad channel
if ( HANDMYRIAD != 0 ) llListenRemove(HANDMYRIAD);
// listen on Myriad region event channel
HANDMYRIAD = llListen(CHANMYRIAD,"",NULL_KEY,"");
// release previous command channel
if ( HANDCOMMAND != 0 ) llListenRemove(CHANCOMMAND);
// listen on command channel
HANDCOMMAND = llListen(CHANCOMMAND,"",llGetOwner(),"");
// search all prims for prims to show output on, by name
integer numprims = llGetNumberOfPrims();
integer i;
for ( i=2; i <= numprims; i++) {
llSetLinkPrimitiveParamsFast(i,[PRIM_TEXT,"",<0,0,0>,0]);
string primname = llGetLinkName(i);
if ( primname == "SHOW ITEM" ) { PN_SHOWITEM = i; }
if ( primname == "SHOW CATEGORY" ) { PN_SHOWCAT = i; }
if ( primname == "SHOW POINTPOOL" ) { PN_SHOWPOOL = i; }
}
}
SAVE() {
string tempname = llGetObjectName();
llSetObjectName("");
llSay(PUBLIC_CHANNEL,"VERSION=0.0.3");
llSay(PUBLIC_CHANNEL,"NAME="+llKey2Name(POSER));
// Species
llSay(PUBLIC_CHANNEL,"SPECIES=Unknown");
// Backgrounds
llSay(PUBLIC_CHANNEL,"BACKGROUNDS=Unknown");
// Careers
llSay(PUBLIC_CHANNEL,"CAREERS=Unknown");
llSay(PUBLIC_CHANNEL,"XP=0");
llSay(PUBLIC_CHANNEL,"XPLEVEL=1");
// Statistics
integer numstats = llGetListLength(AV_STATISTICS);
integer count;
for ( count = 0; count < numstats; count++) {
string name = llList2String(AV_STATISTICS,count++);
integer amount = llList2Integer(AV_STATISTICS,count);
if ( amount > 0 ) llSay(PUBLIC_CHANNEL,"STATISTIC="+name+","+(string)amount);
}
// Resiliences
numstats = llGetListLength(AV_RESILIENCES);
for ( count = 0; count < numstats; count++) {
string name = llList2String(AV_RESILIENCES,count++);
integer amount = llList2Integer(AV_RESILIENCES,count);
string base = llList2String(RES_STATS,llListFindList(RES_STATS,[name]) + 1);
integer baseamt;
if ( llList2String(RES_TYPES,llListFindList(RES_TYPES,[name]) + 1 ) == "Critical" ) {
baseamt = llCeil( llList2Float(AV_STATISTICS,llListFindList(AV_STATISTICS,[base]) + 1) / 2 );
} else {
baseamt = llList2Integer(AV_STATISTICS,llListFindList(AV_STATISTICS,[base]) + 1);
}
if ( (baseamt + amount ) > 0 ) llSay(PUBLIC_CHANNEL,"RESILIENCE="+name+","+(string)(baseamt+amount));
}
// Boons
numstats = llGetListLength(AV_BOONS);
for ( count = 0; count < numstats; count++) {
string name = llList2String(AV_BOONS,count++);
integer amount = llList2Integer(AV_BOONS,count);
if ( amount > 0 ) llSay(PUBLIC_CHANNEL,"BOON="+name+","+(string)amount);
}
// Flaws
numstats = llGetListLength(AV_FLAWS);
for ( count = 0; count < numstats; count++) {
string name = llList2String(AV_FLAWS,count++);
integer amount = llList2Integer(AV_FLAWS,count);
if ( amount > 0 ) llSay(PUBLIC_CHANNEL,"FLAW="+name+","+(string)amount);
}
// Skills
numstats = llGetListLength(AV_SKILLS);
for ( count = 0; count < numstats; count++) {
string name = llList2String(AV_SKILLS,count++);
integer amount = llList2Integer(AV_SKILLS,count);
if ( amount > 0 ) llSay(PUBLIC_CHANNEL,"SKILL="+name+","+(string)amount);
}
// Mortal Combat SFX
numstats = llGetListLength(AV_MORTAL_EFFECTS);
for ( count = 0; count < numstats; count++) {
string name = llList2String(AV_MORTAL_EFFECTS,count++);
integer amount = llList2Integer(AV_MORTAL_EFFECTS,count);
if ( amount > 0 ) llSay(PUBLIC_CHANNEL,"EFFECT="+name+","+(string)amount);
}
// Social Combat SFX
numstats = llGetListLength(AV_SOCIAL_EFFECTS);
for ( count = 0; count < numstats; count++) {
string name = llList2String(AV_SOCIAL_EFFECTS,count++);
integer amount = llList2Integer(AV_SOCIAL_EFFECTS,count);
if ( amount > 0 ) llSay(PUBLIC_CHANNEL,"EFFECT="+name+","+(string)amount);
}
// Magic SFX
numstats = llGetListLength(AV_MAGIC_EFFECTS);
for ( count = 0; count < numstats; count++) {
string name = llList2String(AV_MAGIC_EFFECTS,count++);
integer amount = llList2Integer(AV_MAGIC_EFFECTS,count);
if ( amount > 0 ) llSay(PUBLIC_CHANNEL,"EFFECT="+name+","+(string)amount);
}
// Vehicle SFX
numstats = llGetListLength(AV_VEHICLE_EFFECTS);
for ( count = 0; count < numstats; count++) {
string name = llList2String(AV_VEHICLE_EFFECTS,count++);
integer amount = llList2Integer(AV_VEHICLE_EFFECTS,count);
if ( amount > 0 ) llSay(PUBLIC_CHANNEL,"EFFECT="+name+","+(string)amount);
}
// Stunts
llSay(PUBLIC_CHANNEL,"STUNTS=");
// Quotes
llSay(PUBLIC_CHANNEL,"QUOTE=");
// Equipment
numstats = llGetListLength(AV_EQUIPMENT);
for ( count = 0; count < numstats; count++) {
string name = llList2String(AV_EQUIPMENT,count++);
integer amount = llList2Integer(AV_EQUIPMENT,count);
if ( amount > 0 ) llSay(PUBLIC_CHANNEL,"EQUIPMENT="+name+","+(string)amount);
}
llSetObjectName(tempname);
}
RESET() {
key who = llAvatarOnSitTarget();
if ( who != NULL_KEY ) { llUnSit(who); }
llResetScript();
}
ROLLUP() {
// Stats: Mundane: d3, Heroic: d5, Godlike: d7
integer numstats = llGetListLength(AV_STATISTICS);
integer count;
for ( count = 0; count < numstats; count++) {
integer amount;
if ( llList2String(REGION_GENERATORS,0) == "Mundane" ) {
amount = ((integer)llFrand(3.0)) + 1;
} else if ( llList2String(REGION_GENERATORS,0) == "Heroic" ) {
amount = ((integer)llFrand(5.0)) + 1;
} else if ( llList2String(REGION_GENERATORS,0) == "Godlike" ) {
amount = ((integer)llFrand(7.0)) + 1;
}
AV_STATISTICS = llListReplaceList(AV_STATISTICS,[amount],count,count);
}
// Skills: 7 skills and levels: Mundane=1d4-1, Heroic=1d4, Godlike=1d4+1
numstats = llGetListLength(AV_SKILLS) / 2;
for ( count = 0; count < 7; count++) {
integer skillnum = ((integer)llFrand(numstats) * 2 );
integer amount;
if ( llList2String(REGION_GENERATORS,0) == "Mundane" ) {
amount = (integer)llFrand(4.0);
} else if ( llList2String(REGION_GENERATORS,0) == "Heroic" ) {
amount = ((integer)llFrand(4.0)) + 1;
} else if ( llList2String(REGION_GENERATORS,0) == "Godlike" ) {
amount = ((integer)llFrand(4.0)) + 2;
}
AV_SKILLS = llListReplaceList(AV_SKILLS,[amount],skillnum + 1, skillnum + 1);
}
// SFX: Mundane = 3 SFX, Heroic = 5 SFX, Godlike = 7 SFX
// Roll once for each Resilience: Mundane: d4, Heroic: d6, Godlike: d8
numstats = llGetListLength(AV_RESILIENCES);
for ( count = 0; count < numstats; count++) {
string name = llList2String(AV_RESILIENCES,count++);
string base = llList2String(RES_STATS,llListFindList(RES_STATS,[name]) + 1);
integer baseamt;
if ( llList2String(RES_TYPES,llListFindList(RES_TYPES,[name]) + 1 ) == "Critical" ) {
baseamt = llCeil( llList2Float(AV_STATISTICS,llListFindList(AV_STATISTICS,[base]) + 1) / 2 );
} else {
baseamt = llList2Integer(AV_STATISTICS,llListFindList(AV_STATISTICS,[base]) + 1);
}
integer amount;
if ( llList2String(REGION_GENERATORS,0) == "Mundane" ) {
amount = ((integer)llFrand(4.0)) + 1;
} else if ( llList2String(REGION_GENERATORS,0) == "Heroic" ) {
amount = ((integer)llFrand(6.0)) + 1;
} else if ( llList2String(REGION_GENERATORS,0) == "Godlike" ) {
amount = ((integer)llFrand(8.0)) + 1;
}
AV_RESILIENCES = llListReplaceList(AV_RESILIENCES,[baseamt + amount],count,count);
}
// Boons: d4-2 boons
// Flaws: d4-2 flaws
}
default {
state_entry() {
SETUP();
llRegionSay(CHANMYRIAD,"LIST_REGION_SETTINGS");
}
listen(integer channel,string name,key id,string message) {
name = ""; // LSLINT
id = NULL_KEY; // LSLINT
if ( channel == CHANOBJECT ) {
if ( llSubStringIndex(message,"REGION_SETTING") == 0 ) {
// Parse non-comment lines in keyword = value[,value,...] format
list FIELDS = llParseString2List(message,["|"],[]); // break line of text into = delimited fields
string SUBFIELD = llStringTrim(llList2String(FIELDS,1),STRING_TRIM); // field one is the data
list SUBFIELDS = llParseString2List(SUBFIELD,["="],[]);
string CMD = llList2String(SUBFIELDS,0);
string DATA = llList2String(SUBFIELDS,1); // break data field into comma-delimited subfields if needed
if ( CMD == "GENERATORS" ) {
REGION_GENERATORS = llCSV2List(DATA);
llOwnerSay("REGION_GENERATORS = "+(string)REGION_GENERATORS);
return;
}
if ( CMD == "POINT_POOLS") {
REGION_POINT_POOLS = llCSV2List(DATA);
return;
}
if ( CMD == "STATISTICS") {
list stats = llCSV2List(DATA);
integer num_stats = llGetListLength(stats);
integer count;
AV_STATISTICS = [];
for ( count = 0; count < num_stats; count++) {
AV_STATISTICS = AV_STATISTICS + [llList2String(stats,count),0];
}
return;
}
if ( CMD == "RESILIENCES" ) {
list res = llCSV2List(DATA);
integer num_res = llGetListLength(res);
integer count;
AV_RESILIENCES = [];
for ( count = 0; count < num_res; count++) {
AV_RESILIENCES = AV_RESILIENCES + [llList2String(res,count),0];
}
return;
}
if ( CMD == "SKILLS" ) {
list skills = llCSV2List(DATA);
integer num_skills = llGetListLength(skills);
integer count;
AV_SKILLS = [];
for ( count = 0; count < num_skills; count++) {
AV_SKILLS = AV_SKILLS + [llList2String(skills,count),0];
}
return;
}
if ( CMD == "GENRES" ) {
REGION_GENRES = llCSV2List(DATA);
return;
}
if ( CMD == "BOONS" ) {
list boons = llCSV2List(DATA);
integer num_boons = llGetListLength(boons);
integer count;
AV_BOONS = [];
for ( count = 0; count < num_boons; count++) {
AV_BOONS = AV_BOONS + [llList2String(boons,count),0];
}
return;
}
if ( CMD == "FLAWS" ) {
list flaws = llCSV2List(DATA);
integer num_flaws = llGetListLength(flaws);
integer count;
AV_FLAWS = [];
for ( count = 0; count < num_flaws; count++) {
AV_FLAWS = AV_FLAWS + [llList2String(flaws,count),0];
}
return;
}
if ( CMD == "MORTAL_EFFECTS" ) {
list meffects = llCSV2List(DATA);
integer num_meffects = llGetListLength(meffects);
integer count;
AV_MORTAL_EFFECTS = [];
for ( count = 0; count < num_meffects; count++) {
AV_MORTAL_EFFECTS = AV_MORTAL_EFFECTS + [llList2String(meffects,count),0];
}
return;
}
if ( CMD == "SOCIAL_EFFECTS" ) {
list seffects = llCSV2List(DATA);
integer num_seffects = llGetListLength(seffects);
integer count;
AV_SOCIAL_EFFECTS = [];
for ( count = 0; count < num_seffects; count++) {
AV_SOCIAL_EFFECTS = AV_SOCIAL_EFFECTS + [llList2String(seffects,count),0];
}
return;
}
if ( CMD == "MAGIC_EFFECTS" ) {
list mageffects = llCSV2List(DATA);
integer num_mageffects = llGetListLength(mageffects);
integer count;
AV_MAGIC_EFFECTS = [];
for ( count = 0; count < num_mageffects; count++) {
AV_MAGIC_EFFECTS = AV_MAGIC_EFFECTS + [llList2String(mageffects,count),0];
}
return;
}
if ( CMD == "VEHICLE_EFFECTS" ) {
list veffects = llCSV2List(DATA);
integer num_veffects = llGetListLength(veffects);
integer count;
AV_VEHICLE_EFFECTS = [];
for ( count = 0; count < num_veffects; count++) {
AV_VEHICLE_EFFECTS = AV_VEHICLE_EFFECTS + [llList2String(veffects,count),0];
}
return;
}
if ( CMD == "SPECIES" ) {
REGION_SPECIES = llCSV2List(DATA);
integer num_ts = llGetListLength(REGION_SPECIES);
integer count;
AV_SPECIES = [];
for ( count = 0; count < num_ts; count++) {
AV_SPECIES = AV_SPECIES + [llList2String(REGION_SPECIES,count),0];
}
return;
}
if ( CMD == "BACKGROUNDS" ) {
REGION_BACKGROUNDS = llCSV2List(DATA);
integer num_tb = llGetListLength(REGION_BACKGROUNDS);
integer count;
AV_BACKGROUNDS = [];
for ( count = 0; count < num_tb; count++) {
AV_BACKGROUNDS = AV_BACKGROUNDS + [llList2String(REGION_BACKGROUNDS,count),0];
}
return;
}
if ( CMD == "CAREERS" ) {
REGION_CAREERS = llCSV2List(DATA);
integer num_tc = llGetListLength(REGION_CAREERS);
integer count;
AV_CAREERS = [];
for ( count = 0; count < num_tc; count++) {
AV_CAREERS = AV_CAREERS + [llList2String(REGION_CAREERS,count),0];
}
return;
}
if ( CMD == "EQUIPMENT" ) {
REGION_EQUIPMENT = llCSV2List(DATA);
integer numeq = llGetListLength(REGION_EQUIPMENT);
integer count;
AV_EQUIPMENT = [];
for ( count = 0; count < numeq; count++) {
AV_EQUIPMENT = AV_EQUIPMENT + [llList2String(REGION_EQUIPMENT,count),0];
}
return;
}
if ( CMD == "LIST_COMPLETE" ) {
state GetRes;
}
return;
}
return;
}
}
touch_start(integer touches) {
touches = 0; // LSLINT
llResetScript();
}
}
state GetRes { // get resilience base stats
state_entry() {
SETUP();
integer reslen = llGetListLength(AV_RESILIENCES);
integer count;
for ( count = 0; count < reslen; count += 2) {
string resname = llList2String(AV_RESILIENCES,count);
llRegionSay(CHANMYRIAD,"GET_RESILIENCE|"+resname);
}
llSleep(1.0); // this delay is weak coding - need more reliable fix
state Random;
}
listen(integer channel,string name,key id,string message) {
channel = 0; // LSLINT
name = ""; // LSLINT
id = NULL_KEY; // LSLINT
if ( llGetSubString(message,0,10) == "RESILIENCE|" ) {
// RESILIENCE|RESILIENCE=Wounds|BASE_STAT=Power|TYPE=Critical|ACTION=Death|DESCRIPTION=how damaged the players body is
list tokens = llParseString2List(message,["|"],[]);
integer tokencount = llGetListLength(tokens);
integer i;
string resname = "";
string resstat = "";
string restype = "";
for ( i = 1; i < tokencount; i++) {
string attrib = llList2String(llParseString2List(llList2String(tokens,i),["="],[]),0);
string value = llList2String(llParseString2List(llList2String(tokens,i),["="],[]),1);
if ( attrib == "RESILIENCE" ) resname = value;
if ( attrib == "BASE_STAT" ) resstat = value;
if ( attrib == "TYPE" ) restype = value;
}
RES_STATS += [resname,resstat];
RES_TYPES += [resname,restype];
}
}
}
state Random {
state_entry() {
llOwnerSay("State: Random");
SETUP();
}
changed(integer change) {
if ( change & CHANGED_LINK ) {
POSER = llAvatarOnSitTarget();
ROLLUP();
SAVE();
RESET();
}
}
}