use basicio;
use npc;
use math;
use basic;
use os;
use util;
use polsys;
use uo;
use cfgfile;
include "include/damage";
include "class";
include "include/convert";
include "include/skillcheck";
include "include/yesno";
var cfg := readconfigfile("crafting");
var menus := readconfigfile("crafting");
var areatools := readconfigfile("areatools");
var targetted_material;
var materialcfg ;
var qualmod ;
var hpmod ;
var clrmod ;
var diffmod ;
var pointmod ;
var maxgainpoints;
var weightmod ;
var hitscript ;
var makestack ;
var neededamount;
var hecan_make ;
var who2;
var materials := {};
var itemcfg := readconfigfile("::itemdesc");
program use_item(who, item)
//if (getobjproperty(who, "#crafting") > readgameclock())
// SendSysMessage(who, "You must wait to craft again.");
//return;
// endif
// setobjproperty(who, "#crafting", readgameclock()+1);
if (!item)
item := who[2];
who := who[1];
endif
if(getequipmentbylayer(who, 25))
SendSysMessage(who, "You can not craft whilst mounted");
return;
endif
var uses := getobjproperty(item, "uses");
if (!uses)
setobjproperty(item, "uses", randomint(50) + 1);
uses := uses := getobjproperty(item, "uses");
endif
if (!uses)
sendsysmessage(who, "The well-worn tool breaks!");
destroyitem(item);
return;
endif
setobjproperty(item, "uses", uses - 1);
who2 := who;
sendsysmessage(who, "What do you want to use that on?");
var what := target(who, TGTOPT_CHECK_LOS);
if (!what )
sendsysmessage(who, "Targetting Cancelled");
////output(who, "Didn't select anything");
return;
endif
if (!what.movable)
sendsysmessage(who, "You cannot use locked-down items");
return;
endif
reserveitem(what);
targetted_material := what;
////output(who, "Selected " + what.objtype);
materialcfg := readconfigfile("materials");
if (!materialcfg)
sendsysmessage(who, "Crafting error: " + materialcfg.errortext);
syslog("Crafting error: " + materialcfg.errortext);
endif
qualmod := materialcfg[what.objtype].quality;
hpmod := materialcfg[what.objtype].hp;
clrmod := cint(materialcfg[what.objtype].Color);
diffmod := materialcfg[what.objtype].difficulty;
pointmod := materialcfg[what.objtype].points;
maxgainpoints := materialcfg[what.objtype].maxgainpoints;
weightmod := materialcfg[what.objtype].weight;
hitscript := materialcfg[what.objtype].hitscript;
var hisclass := getobjproperty(who, "Class");
var tc := lower(hisclass);
if (tc in getconfigstringarray(materialcfg[what.objtype],"Class") )
else
var e := materialcfg[what.objtype];
sendsysmessage(who, "You do not have the training to work with this material!");
return;
endif
if (!qualmod)
qualmod := 1.0;
endif
if (!hpmod)
hpmod := 1.0;
endif
if (!diffmod)
diffmod := 1.0;
endif
if(!pointmod)
pointmod := 1.0;
endif
if(!weightmod)
weightmod := 1.0;
endif
//if(maxgainpoints >= )
//CheckSkillNoAdvance();
//sendsysmessage(who, "Debug: Too easy for you");
//endif
var menuname := format_hex(item.objtype) + "+" + format_hex(what.graphic);
////output(who, "Menu name is " + menuname);
var tmenu := cfg[menuname];
if (!tmenu)
sendsysmessage(who, "You don't know how to make anything out of this");
return;
endif
var ret;
var exitit := 0;
////output(who,"Showmenu is " + tmenu.showmenu);
var mname := menus[tmenu.showmenu];
while (!exitit)
////output(who, "mname is " + mname);
ret := getsubmenuselection(who, mname, what);
////output(who, "RET == " + ret);
if (!ret)
sendsysmessage(who, "Cancelled");
return;
endif
if (ret.type == 2)
mname := menus[ret.objtype];
else
exitit := 1;
endif
endwhile
var telem:= cfg[hex(ret.objtype)];
//output(who, "Looking for objtype " +hex(ret.objtype));
if (!telem)
//syslog("Unable to find craft.cfg entry for " + ret.objtype);
telem := cfg[format_hex(ret.objtype)];
if (!telem)
//output(who, "Didn't find it");
return;
endif
endif
var makestack := telem.makestack;
if( makestack == error or what.amount == 1)
makestack := 0;
elseif( makestack == 1 )
SendSysmessage(who, "This item will create in a stack using up all the targetted material", 3, 90);
if (YesNo(who, "Are you sure you wish to create a stack?"))
else
SendSysMessage(who, "Cancelled");
return;
endif
endif
var materiallist := {};
var materials := getconfigstringarray(telem, "material");
var temp1 := materials[1];
temp1["/"] := " ";
var temp := splitwords(temp1);
if( targetted_material.amount < cint(temp[2]) ) //hack, i know

SendSysmessage(who, "You don't have enough material!");
return;
endif
materials.erase(1);
foreach material in materials
var d := grabmaterial(who, material, materiallist, makestack);
if (!d )
sendsysmessage(who, "You do not have enough material!");
//material["/"] := " ";
//material:= splitwords(material);
//sendsysmessage(who, "You need " + itemcfg[cint(material[1])].desc);
return;
else
materiallist.append(d[1]);
endif
endforeach
//output(who,"Materiallist == " + materiallist);
var areaitem;
var leaveit;
leaveit := 0;
foreach areaitem in getconfigstringarray(telem, "area")
leaveit := findareaitem(who, areaitem);
if (leaveit)
sendsysmessage(who, "Targetting cancelled");
return;
endif
endforeach
// foreach tool in getconfigstringarray(telem, "tool")
// tool["/"] := " ";
// var stuf := splitwords(tool);
// sendsysmessage(who, getprompt(tool));
// var this := target(who, TGTOPT_CHECK_LOS);
// if (this.objtype <> cint(stuf[1]))
// sendsysmessage(who, "Targetting cancelled");
// return;
// endif
// endforeach
//added by Nick
foreach tool in getconfigstringarray(telem, "tool")
var ok;
while(tool[" "])
tool[" "] := "-";
endwhile
tool["/"] := " ";
var stuf := splitwords(tool);
//sendsysmessage(who, getprompt(tool));
foreach thingie in enumerateitemsInContainer( who.backpack )
if(thingie.objtype == cint(stuf[1]))
ok :=1;
endif
endforeach
if(!ok)
var trash := stuf[2];
while(trash["-"])
trash["-"] := " ";
endwhile
sendsysmessage(who, " " + trash);
var this := target(who, TGTOPT_CHECK_LOS);
if (this.objtype <> cint(stuf[1]))
sendsysmessage(who, "Targetting cancelled");
return;
endif
endif
endforeach
//////////////
var success := 0;
//output(who, "about to check skill");
//sendsysmessage(who, "About to check skill");
foreach skill in getconfigstringarray(telem, "skill")
while (skill["/"])
skill["/"]:= " ";
endwhile
var skillstuff := splitwords(skill);
var tskillid := cint(skillstuff[1]);
//sendsysmessage(who, "Skill is "+tskillid+"");
var tdiff := cint(cint(skillstuff[2]) * diffmod);
//sendsysmessage(who, "Difficulty is "+tdiff+"");
if (tdiff > 100)
tdiff := 100;
endif
var tpoints := modify_points( who, tskillid , cint( cint( skillstuff[3] ) * cdbl( pointmod ) ) );
//Sendsysmessage(who, "Checking skill " + tskillid + " for " + tdiff + " difficulty");
if (newcheckskill(who, tskillid, tdiff, tpoints))
success := 1;
//sendsysmessage(who, "Success");
//output(who, "You made the skillcheck!");
else
success := 0;
//sendsysmessage(who, "Fail");
endif
endforeach
//output(who, "Checked skill");
//ok, if they succeeded in making the item, then the success variable will be 1. Either way, I need to subtract material
getmaterial(who, telem, materiallist, success);
foreach sound in getconfigstringarray(telem, "sound")
sound["/"] := " ";
var st := splitwords(sound);
var cntr;
for (cntr := 1; cntr <= cint(st[2]); cntr := cntr + 1)
playsoundeffect(who, cint(st[1]));
sleep(1);
endfor
endforeach
if (!success)
Sendsysmessage(who, "You fail, and ruin some material");
return;
endif
if (!hecan_make)
hecan_make := 1;
endif
/*if(who.cmdlevel)
sendsysmessage(who, "objtype: "+cint(ret.objtype));
sendsysmessage(who, "hecan_make: "+hecan_make);
endif*/
var it := createiteminbackpack(who, cint(ret.objtype), hecan_make);
var info := struct;
info.+ name;
info.+ acctname;
info.acctname := who.acctname;
info.name := who.name;
setobjproperty(it, "PC-MADE", info);
it.movable := 1; // So nothing gets locked down in a person's pack
if (!it)
return;
endif
var excep := 0;
if (telem.exceptional)
foreach skill in getconfigstringarray(telem, "skill")
while (skill["/"])
skill["/"]:= " ";
endwhile
var skillstuff := splitwords(skill);
if (newgetskill(who, cint(skillstuff[1])) > 90)
if (getobjproperty(who, "debug"))
sendsysmessage(who, "Exceptional item chance...");
endif
var roll := randomint(20);
if (roll == 1)
if (getobjproperty(who, "debug"))
sendsysmessage(who, "Success (rolled a 1)");
endif
excep := 1;
addFame(who);
else
if (getobjproperty(who, "debug"))
sendsysmessage(who, "Failed the roll (rolled a "+roll+")");
endif
excep := 0;
endif
else
excep := 0;
endif
endforeach
endif
it.quality := qualmod;
if(it.objtype == 0xd4e8)
it.color := 1209;
else
it.color := clrmod;
endif
it.weight := it.weight * weightmod;
it.maxhp := cint(it.maxhp * hpmod);
if (hitscript)
var a := {};
a[1] := hitscript;
setobjproperty(it, "OnHit", a);
endif
if (excep || who.cmdlevel && getobjproperty(who, "crafttest"))
setobjproperty(it, "exceptional", 1); // Austin - So spells dont remove would be "magic" from named items
it.quality := 1.25;
var tname := SendTextEntryGump( who,
"You have made an exceptional item!",
TE_CANCEL_ENABLE,
TE_STYLE_NORMAL,
40, // normal: chars, num: value
"What would you like to name this item?" );
if (tname)
it.name := tname;
endif
it.hp := it.maxhp;
else
sendsysmessage(who, "You place the item in your pack");
it.quality := getquality(who, telem);
it.hp := it.maxhp;
endif
endprogram
function getquality(who, elem)
//var skill;
var skillstuff;
var totalskillpoints := 0;
var tcount := 0;
foreach skill in getconfigstringarray(elem, "skill")
while (skill["/"])
skill["/"]:= " ";
endwhile
skillstuff := splitwords(skill);
totalskillpoints := totalskillpoints + newgetskill(who, cint(skillstuff[1]));
tcount := tcount + 1;
endforeach
var avg := cint((totalskillpoints / tcount) * 1.2);
//broadcast("avg: "+avg, 3, 80);
var retval := randomint(avg) + 1;
//broadcast("retval: "+retval, 3, 80);
return retval;
endfunction
function getmaterial(who, telem, materiallist, success )
var ttt := telem.material;
ttt["/"] := " ";
var tt := splitwords(ttt);
neededamount := cint(tt[2]);
//print ("tt is " + tt);
if (!neededamount)
neededamount := 1;
endif
if(!hecan_make)
if( telem.makestack )
hecan_make := targetted_material.amount / neededamount;
else
hecan_make := 1;
endif
endif
//print("Hecan_make: " + hecan_make);
if(success)
subtractamount(targetted_material, neededamount * hecan_make);
else
subtractamount(targetted_material, (neededamount * hecan_make)/3);
endif
foreach elem in getconfigstringarray(telem, "material")
var subamount := 0;
elem["/"] := " ";
var stf := splitwords(elem);
if (!success)
stf[2] := stf[2] / (randomint(3) + 1); //FIXME: this is a little arbitrary, how about a lost amount
// according to the needed material amount and skill?
endif
foreach item in materiallist
if (item.objtype == cint(stf[1]))
output(who, "Found " + item.amount);
if ((item.amount >= (cint(stf[2]) * hecan_make)) and cint(stf[2]) > 0)
subtractamount(item.item, cint(stf[2]) * hecan_make);
stf[2] := 0;
else
stf[2] := cint(stf[2]) - item.amount;
destroyitem(item.item);
endif
endif
endforeach
endforeach
endfunction
/*function getmaterial(who, telem, materiallist, success )
var ttt := telem.material;
ttt["/"] := " ";
var tt := splitwords(ttt);
neededamount := cint(tt[2]);
//////print ("tt is " + tt);
if (!neededamount)
neededamount := 1;
endif
sendsysmessage(who, "Amount Needed: "+neededamount);
if(!hecan_make)
//if( telem.makestack )
hecan_make := targetted_material.amount / neededamount;
//else
//hecan_make := 1;
//endif
endif
//////print("Hecan_make: " + hecan_make);
if(success)
var a := subtractamount(targetted_material, neededamount * hecan_make);
sendsysmessage(who, "a: "+a);
else
var howmuch := cint((neededamount * hecan_make)/ 3);
if (howmuch <= 1)
howmuch := 1;
endif
var b:= subtractamount(targetted_material, howmuch);
sendsysmessage(who, "b: "+b);
endif
foreach elem in getconfigstringarray(telem, "material")
var subamount := 0;
elem["/"] := " ";
var stf := splitwords(elem);
if (!success)
stf[2] := cint(cint(stf[2]) / (randomint(3) + 1)); //FIXME: this is a little arbitrary, how about a lost amount
// according to the needed material amount and skill?
if (stf[2] <= 1)
stf[2] := 1;
endif
endif
foreach item in materiallist
if (item.objtype == cint(stf[1]))
//sendsysmessage(who, "Found " + item.amount);
if ((item.amount >= (cint(stf[2]) * hecan_make)) and cint(stf[2]) > 0)
var c := subtractamount(item.item, cint(stf[2]) * hecan_make);
sendsysmessage(who, "c: "+c);
stf[2] := 0;
else
stf[2] := cint(stf[2]) - item.amount;
var d := subtractamount(item.item, cint(stf[2]) * hecan_make);
sendsysmessage(who, "d: "+d);
endif
endif
endforeach
endforeach
endfunction*/
function getprompt(theprompt)
theprompt[ 1, Find(theprompt, 1," ") ] := "";
return theprompt;
endfunction
function grabmaterial(who, material, materiallist, makestack )
// this function finds the materials they'll need to make an item.
// If it's a regular item (that is, you only make one at a time)
// it looks through their backpack for the necessary materials. If
// they're making a stack, it instead prompts them to target the material
//output (who, who.name + " is trying to get " + material + "for " + materiallist + " makestack == " + makestack);
var materialentry := {};
materialentry.+ objtype;
materialentry.+ amount;
materialentry.+ item;
material["/"] := " ";
//output (who,"material == " + material);
var stuff := splitwords(material);
//////print("makestack: " + makestack);
if (!makestack)
var totalamount := 0;
foreach item in enumerateitemsInContainer( who.backpack )
if (item.objtype == cint(stuff[1]))
//sendsysmessage(who, "Adding " + item.objtype + " to the list");
totalamount := totalamount + item.amount;
materialentry.objtype := item.objtype;
//sendsysmessage(who,"Adding materialentry objtype " + materialentry.objtype);
materialentry.amount := item.amount;
//sendsysmessage(who, "Adding amount " + materialentry.amount);
materialentry.item := item;
//sendsysmessage(who, "Adding item " + item);
//reserveitem(item);
materiallist.append(materialentry);
endif
endforeach
//////print("Materiallist: " + materiallist );
//////print("totalamount: " + totalamount );
if (totalamount >= cint(stuff[2]))
return materiallist;
else
return;
endif
// elseif (cstr(makestack) == "1") //What is this? what's all the code under the "else" for then?
// //materiallist should be empty
// return 1;
else
sendsysmessage(who, "Target the feathers you wish to use");
var whatt := target(who, TGTOPT_CHECK_LOS);
while (whatt.graphic != cint(stuff[1]) && whatt)
sendsysmessage(who, "That's the wrong material!");
//sendsysmessage(who, makestack);
whatt := target(who, TGTOPT_CHECK_LOS);
endwhile
////output(who, " You need " + stuff[2]);
if (!whatt)
sendsysmessage(who, "Targetting cancelled");
return;
endif
reserveitem(whatt);
if (whatt.amount < cint(stuff[2]))
Sendsysmessage(who, "You don't have enough material to make that! " );
return;
endif
materialentry.objtype := whatt.objtype;
materialentry.amount := whatt.amount;
materialentry.item := whatt;
materiallist.append(materialentry);
// //output(who, "Materiallist == " + materiallist);
if( whatt.amount < targetted_material.amount )
hecan_make := cint(whatt.amount / cint(stuff[2]));
else
hecan_make := cint(targetted_material.amount / cint(stuff[2]));
endif
return materiallist;
endif
endfunction
function getsubmenu(thestring)
////output(who2, "I'm in getmenu, damnit!");
//////print ("In getsubmenu, thestring == " + thestring);
var retval := {};
while (thestring[" "])
thestring[" "] := " ";
endwhile
retval := splitwords(thestring);
if (itemcfg[cint(retval[1])].graphic)
retval[1] := itemcfg[cint(retval[1])].graphic;
//////print ("resetting graphic to " + retval[1]);
endif
//////print ("returning " + retval);
return retval;
endfunction
function getgraphic (theval)
var retval;
if (itemcfg[theval].graphic)
retval := itemcfg[theval].graphic;
//////print ("resetting graphic to " + retval[1]);
else
retval := cint(theval);
endif
return retval;
endfunction
function can_make(who, entry, what)
//sendsysmessage(who, "Seeing if you can make " + what + " with entry " + entry);
var dtstuff := splitwords(entry);
var tentry := cfg[dtstuff[1]];
var skill;
foreach skill in getconfigstringarray(cfg[dtstuff[1]], "skill")
//sendsysmessage(who, "Checking for skill " + skill);
while (find(skill, "/", 1))
skill["/"] := " ";
endwhile
var stuff := splitwords(skill);
if (newgetskill(who, cint(stuff[1])) < cint(cint(stuff[2]) * diffmod) )
//output(who, "With skill " + stuff[1] + " You need " + cint(cint(stuff[2]) * diffmod) + " but you have " + newgetskill(who, cint(stuff[1])));
return 0;
endif
return 1;
endforeach
endfunction
function findareaitem(who, areaitem)
//////print ("Lookign for area " + areaitem);
var retval;
var items := getconfigstringarray(areatools[areaitem], "item");
//////print ("item list is " + items);
var i;
foreach item in listitemsnearlocation(who.x, who.y, who.z, 4)
//////print ("there's an " + item.graphic + "nearby");
//////print ("items.length() is " + len(items));
for (i := 1; i <= len(items); i := i + 1)
////////print ("Is " + cint(items
) + " equal to " + cint(item.objtype) + " ?");
if (cint(items) == cint(item.graphic))
//printtextabove(item, "It's me!!");
return 0;
endif
endfor
endforeach
//if it's near them, then return. Otherwise, you have to look for it
sendsysmessage(who, "Select the "+ areaitem+" you want to use this on, or escape to cancel");
var what := targetcoordinates(who);
if (!what.objtype)
return 1;
endif
while (!(what.objtype in items))
sendsysmessage(who, "Select the "+ areaitem+" you want to use this on, or escape to cancel");
what := targetcoordinates(who);
if (!what.objtype)
return 1;
endif
endwhile
return;
endfunction
function getsubmenuselection(who, submenuname, what)
/*
// //output(who2,, "in getsubmenuselection, got " + submenuname);
//
// this function takes the name of a submenu and loads it. It returns an array with
// the objtype of the selection, as well as the submenu name (if any)
*/
var retval := {};
retval.+type;
retval.+objtype;
var entry;
var menuentries2 := {};
var menuentry2 := {};
menuentry2.+objtype;
menuentry2.+type;
menuentry2.+submenu;
var themenu2 := createmenu("What would you like to make?");
////output(who, "About to check for entries ");
foreach entry in getconfigstringarray(submenuname, "Entry")
////output(who, "Got an entry : "+ entry);
var rtvl := can_make(who, entry, what);
if (!rtvl)
////output(who,"can't make " + entry);
endif
if (rtvl)
////output(who, "adding entry" + entry);//
var stuff := splitwords(entry);
////output(who, "Calling AddMenuItem(themenu," + getgraphic(stuff[1]) + "," + stuff[2] + ")");
AddMenuItem(themenu2, getgraphic(cint(stuff[1])), stuff[2]);
menuentry2.objtype := cint(stuff[1]);
menuentry2.submenu := "";
menuentry2.type := 1;
menuentries2.append(menuentry2);
endif
////output(who, menuentries2);
endforeach
//sendsysmessage(who, "Checked!!!!!!!!!!");
foreach entry in getconfigstringarray(submenuname, "submenu")
////////print ("checking submenu " + entry);
var stuff := getsubmenu(entry);
addmenuitem(themenu2, getgraphic(cint(stuff[2])), stuff[3]);
menuentry2.objtype := cint(stuff[2]);
menuentry2.type := 2;
menuentry2.submenu := stuff[1];
menuentries2.append(menuentry2);
endforeach
var retl2 := selectmenuitem2(who, themenu2);
////////print (retl2.errortext);
if (!retl2.index)
////output(who2,, "He didn't select anything!");
return 0;
else
////////print ("Index is " + retl2.index + " objtype == " + retl2.objtype);
if (menuentries2[retl2.index].type == 2)
retval.objtype := menuentries2[retl2.index].submenu;
retval.type := 2;
////output(who2,, "type is 2######################");
else
retval.objtype := menuentries2[retl2.index].objtype;
retval.type := 1;
////////print ("type is 1#$$$$$$$$$$$$$$$$$$$$$$");
endif
endif
//output(who, "returning " + retval);
return retval;
endfunction
function output(who, message)
if (who2.cmdlevel)
sendsysmessage(who, message);
//////print(message);
endif
endfunction
function format_hex(theobjtype)
var thex := hex(theobjtype);
if (len(thex) == 5)
thex["0x"] := "0x0";
elseif (len(thex) == 4)
thex["0x"] := "0x00";
elseif (len(thex) == 3)
thex["0x"] := "0x000";
endif
return thex;
endfunction
function addfame(who)
var hisfame := cint(getobjproperty(who, "Fame"));
if (!hisfame)
hisfame := 1;
endif
hisfame := cint(hisfame * 1.05);
setobjproperty(who, "Fame", hisfame);
sendsysmessage(who, "You have gained fame for crafting this item");
var hisfaith := getobjproperty(who, "Devotion");
if (hisfaith == "Olor")
var hiskarma := getobjproperty(who, "Karma");
if (!hiskarma)
hiskarma := 1;
endif
if (hiskarma < 0)
return;
endif
hiskarma := cint(hiskarma * 1.3);
setobjproperty(who, "Karma", hiskarma);
Sendsysmessage(who, "Olor smiles upon your creation");
endif
endfunction