$include $lib/alynna $include $lib/rp $include #2123 $include $muf/rp/boxutils $include $lib/craft $def rpsys "$rpsystem" match lvar researchers : init { }dict researchers ! 1 dbtop int 1 for var cur dbref cur ! cur @ player? not if continue then ( cur @ "Special/Scientific Method" getstatint not if continue then ) cur @ "approved?" getstatint not if continue then cur @ mlevel 3 > if continue then cur @ "Global Research" getstatstr var topic topic ! researchers @ topic @ array_getitem toint 1 + researchers @ topic @ array_setitem researchers ! repeat ; : known?[ str:topic -- bool:answer ] rpsys str "Global Research/" topic @ "/Finished" cat getpropval if 1 exit then rpsys str "Global Research/" topic @ "/Required Topics" cat getpropstr dup "none" smatch if pop else dup not if pop 0 exit then ":" explode_array foreach var cur cur ! pop rpsys str "Global Research/" cur @ "/Finished" cat getpropval not if 0 exit then repeat then rpsys str "Global Research/" topic @ "/World Stat Requirements" cat getpropstr dup "none" smatch if pop else ":" explode_array foreach var cur var val "/" split toint val ! cur ! pop #0 "Global Stats/" cur @ strcat getstatint val @ < if 0 exit then repeat then 1 ; : supplypercent[ str:topic -- int:result ] var total var actual 0 total ! rpsys str "Global Research/" topic @ "/Materials" cat getpropstr ":" explode_array foreach var cur cur ! pop cur @ "/" rsplit toint total @ + total ! pop repeat rpsys str "Global Research/" topic @ "/MaterialsSpent" cat getpropstr ":" explode_array foreach var cur cur ! pop cur @ "/" rsplit toint actual @ + actual ! pop repeat actual @ 100 * total @ / ; : eligibilitypercent[ str:topic -- int:result ] var total var actual 0 total ! 0 actual ! rpsys str "Global Research/" topic @ "/" researchers @ topic @ array_getitem toint if "Required Skills" else "Leader Skills" then cat getpropstr ":" explode_array foreach var cur swap pop cur ! var val cur @ "/" rsplit toint dup total @ + total ! val ! "/" "\\" subst "Craft/" "`" subst cur ! me @ cur @ getstatint val @ lesser actual @ + actual ! repeat rpsys str "Global Research/" topic @ "/Method" cat getpropstr atoi researchers @ topic @ array_getitem toint if 5 - then 1 greater dup total @ + total ! me @ "Special/Scientific Method" getstatint lesser actual @ + actual ! actual @ 100 * total @ / ; : allpercent[ str:topic -- int:result ] topic @ supplypercent rpsys str "Global Research/" topic @ "/Gilspent" cat getpropstr toint 100 * rpsys str "Global Research/" topic @ "/Gil" cat getpropstr toint / lesser 100 lesser ; PUBLIC allpercent $libdef allpercent : canprogress?[ str:topic -- int:result ] topic @ allpercent rpsys str "Global Research/" topic @ "/Progress" cat getpropstr toint 100 * rpsys str "Global Research/" topic @ "/Level" cat getpropstr toint 1 + 50 * / > rpsys str "Global Research/" topic @ "/Progress" cat getpropstr toint 100 * rpsys str "Global Research/" topic @ "/Level" cat getpropstr toint 1 + 50 * / 100 = or ; PUBLIC canprogress? $libdef canprogress? : dailyjp[ str:topic -- int:result ] rpsys str "Global Research/" topic @ "/JP" cat getpropstr tofloat rpsys str "Global Research/" topic @ "/Level" cat getpropstr tofloat 1 + 50 * / ; PUBLIC dailyjp $libdef dailyjp : researchcontinue[ ref:inventor str:topic -- int:result ] rpsys str "Global Research/" topic @ "/JP" cat getpropstr toint not if rpsys str "Global Research/" topic @ "/Level" cat getpropstr toint 50 * tostr rpsys str "Global Research/" topic @ "/JP" cat rot setprop then rpsys str "Global Research/" topic @ "/Progress" cat getpropstr toint dup var! progress 1 + rpsys str "Global Research/" topic @ "/Progress" cat rot setprop str "The progress of " topic @ " advances from " progress @ " to " progress @ 1 + "." cat .tell rpsys str "Global Research/" topic @ "/Researchers/" me @ name strcat cat getpropstr toint 1 + rpsys str "Global Research/" topic @ "/Researchers/" me @ name strcat cat rot setprop rpsys str "Global Research/" topic @ "/Progress" cat getpropstr toint rpsys str "Global Research/" topic @ "/Level" cat getpropstr toint 1 + 50 * < not if ( COMPLETED ! ) rpsys str "Global Research/" topic @ "/Finished" cat systime setprop 1 dbtop int 1 for var cur dbref cur ! cur @ player? not if continue then cur @ "global research" getstatstr topic @ smatch not if continue then cur @ str "Global Research/" topic @ "/Researched" cat systime setstat repeat 1 exit rpsys str "Global Research/" topic @ "/World Stat Mods" cat getpropstr dup not if pop else "|" explode_array foreach var cur cur ! cur @ case cur @ "+" instring when cur @ "+" split var val val ! cur ! #0 "Global Stats/" cur @ strcat getstatint val @ + #0 "Global Stats/" cur @ strcat rot setstat end cur @ "-" instring when cur @ "-" split var val val ! cur ! #0 "Global Stats/" cur @ strcat getstatint val @ - #0 "Global Stats/" cur @ strcat rot setstat end endcase repeat then else 0 exit then ; PUBLIC researchcontinue $libdef researchcontinue : eligible?[ ref:inventor str:topic -- ] rpsys str "Global Research/" topic @ "/" researchers @ topic @ array_getitem toint if "Required Skills" else "Leader Skills" then cat getpropstr ":" explode_array foreach var val var cur "/" rsplit toint val ! "/" "\\" subst "Craft/" "`" subst cur ! pop inventor @ cur @ getstatint val @ < if 0 exit then repeat rpsys str "Global Research/" topic @ "/Method" cat getpropstr toint researchers @ topic @ array_getitem toint if 5 - then 1 greater inventor @ "Special/Scientific Method" getstatint > if 0 else 1 then ; : list-topics #0 "@rp/Global Stats/" remove_prop rpsys "Global Research/" array_get_propdirs foreach var cur cur ! pop rpsys { "Global research/" cur @ "/Finished" }cat getprop toint not if continue then rpsys { "Global research/" cur @ "/World Stat Mods" }cat getpropstr dup not over "none" smatch or if pop continue then "/" "+" subst dup rpsys { "Global research/" cur @ "/World Stat Mods" }cat rot setprop ":" explode_array foreach "/" rsplit toint var! val var! stat pop ( { cur @ ": " stat @ " " val @ }cat debug ) #0 { "Global Stats/" stat @ }cat getstatint val @ + #0 { "Global Stats/" stat @ }cat rot setstat repeat repeat str "Name" 30 left "|" "LVL" 3 right "|" "Method" 6 right "|" "PRG%" 4 right "|" "WRKRS" 5 right "|" "Item%" 5 right "|" "Gil%" 4 right "|" "Skill%" 6 right "|" "Days Left" cat .tell rpsys "Global Research/" array_get_propdirs foreach cur ! pop cur @ known? not if continue then systime rpsys str "Global Research/" cur @ "/Finished" cat getpropval dup rot swap - 60 60 * 24 * 7 * > and if continue then str me @ "Global Research" getstatstr cur @ smatch if "^yellow^" then cur @ 30 left "|" rpsys str "Global Research/" cur @ "/Finished" cat getpropval if "^yellow^***COMPLETE***^normal^" 40 center cat .tell continue then rpsys str "Global Research/" cur @ "/Level" cat getpropstr 3 right "|" rpsys str "Global Research/" cur @ "/Method" cat getpropstr toint researchers @ cur @ array_getitem toint if 5 - then 1 greater tostr 6 right "|" rpsys str "Global Research/" cur @ "/Progress" cat getpropstr toint 100 * rpsys str "Global Research/" cur @ "/Level" cat getpropstr toint 1 + 50 * / tostr "%" strcat 4 right "|" researchers @ cur @ array_getitem tostr 5 right "|" cur @ supplypercent tostr "%" strcat 5 right "|" rpsys str "Global Research/" cur @ "/Gilspent" cat getpropstr toint 100 * rpsys str "Global Research/" cur @ "/Gil" cat getpropstr toint / tostr "%" strcat 4 right "|" me @ cur @ eligible? if "Yes" else cur @ eligibilitypercent tostr "%" strcat then 6 right "|" rpsys str "Global Research/" cur @ "/Level" cat getpropstr toint 50 * 50 + rpsys str "Global Research/" cur @ "/Progress" cat getpropstr toint - researchers @ cur @ array_getitem toint dup not if pop pop "^gloom^--" else / dup case 10 < when "^green^" end 50 < when "^yellow^" end pop 1 when "^red^" end endcase swap then "^normal^" cat .tell repeat "Global Stats: ^green^" var stats stats ! #0 "@rp/Global Stats/" array_get_propvals foreach tostr "^yellow^ " swap strcat "^green^" strcat strcat ", " strcat stats @ swap strcat stats ! repeat stats @ .tell me @ "Global Research" getstatstr "0" smatch not if "Type +gresearch #focus to spend some JP and do two days work instead of one today." .tell then "See the topics in a much nicer format, with credit given to researchers and financers!" .tell "http://sc.scworlds.net:8765/research" .tell ; $undef maxgil : topiceditor[ str:topic -- ] topic @ capitalize begin "Topic Name: " topic @ strcat .tell "Description: " rpsys str "Global Research/" topic @ "/Desc" cat getpropstr strcat .tell str "Skills and Stats Required: " rpsys str "Global Research/" topic @ "/" researchers @ topic @ array_getitem toint if "Required Skills" else "Leader Skills" then cat getpropstr rpsys str "Global Research/" topic @ "/Finished" cat getprop toint dup not if pop else dup var! tim systime swap - timex "Completed: " swap strcat " ago" strcat .tell #0 "Globaltime" getstatint tim @ swap - 2.5 * int var! diff var second var minute var hour var day var month var year diff @ 60 % second ! diff @ 3600 % 60 / minute ! diff @ 86400 % 3600 / hour ! diff @ 2592000 % 86400 / 1 + day ! diff @ 31104000 % 2592000 / 1 + month ! diff @ 31104000 / year ! month @ 12 > if month @ 12 - month ! then str "IC Time: " hour @ dup 11 > if 12 - 1 var! meridian else 0 meridian ! then dup not if pop 12 then ":" minute @ dup 10 < if intostr "0" swap strcat then " " meridian @ if "PM" else "AM" then ", " #0 "days/" diff @ 604800 % 86400 / 1 + intostr strcat getpropstr ", " day @ english_number " day of the " month @ intostr "{12|1|2}" smatch if "winter" then month @ intostr "{3|4|5}" smatch if "spring" then month @ intostr "{6|7|8}" smatch if "summer" then month @ intostr "{9|10|11}" smatch if "fall" then dup #0 "_msgmacs/season" rot setprop " month " #0 "month/" month @ intostr strcat getpropstr " in the year " year @ 1003 + " AH." cat .tell "^yellow^Result: " rpsys str "Global Research/" topic @ "/Result" cat getpropstr strcat "^normal^" strcat .tell then ", " ":" subst " of " "/" subst "/" "\\" subst ", Scientific Method of " rpsys str "Global Research/" topic @ "/Method" cat getpropstr toint researchers @ topic @ array_getitem toint if 5 - then 1 greater cat .tell "Project Gil remaining: " rpsys str "Global Research/" topic @ "/Gil" cat getpropstr toint rpsys str "Global Research/" topic @ "/Gilspent" cat getpropstr toint - var maxgil dup maxgil ! tostr strcat .tell str "Materials Required: " rpsys str "Global Research/" topic @ "/Materials" cat getpropstr ":" explode_array var needed needed ! rpsys str "Global Research/" topic @ "/MaterialsSpent" cat getpropstr dup not if pop { }dict else ":" explode_array then var spent spent ! var lefto { }dict lefto ! var cur var val spent @ { }dict spent ! foreach swap pop "/" split toint spent @ rot array_setitem spent ! repeat needed @ foreach "/" split toint val ! cur ! pop val @ spent @ cur @ array_getitem - 0 greater lefto @ cur @ array_setitem lefto ! repeat lefto @ foreach tostr " " swap strcat strcat ", " repeat pop cat .tell "Global Stat Requirements: " rpsys str "Global Research/" topic @ "/World Stat Requirements" cat getpropstr " of " "/" subst ", " ":" subst strcat .tell str "Do you want to ^purple^M^normal^) Donate Materials, ^purple^R^normal^) Research, ^purple^G^normal^) Donate Gil" me @ "Group Rank" getstatstr "_" " " subst "{Leader|Quartermaster}" smatch if ", ^purple^D^normal^onate gil from group coffers" then ", or ^purple^Q^normal^) Quit." cat .tell read var choice choice ! choice @ "r" instring if me @ topic @ eligible? not if "You are not eligible to research this topic." .tell continue then "You begin researching." .tell me @ "Global Research" topic @ setstat then choice @ "m" instring if "Ok. First, is the donated item a Weapon, Gear, or Armor?" .tell read dup "{weapon|gear|armor}" smatch not if "Invalid selection" .tell continue then choice ! me @ "+" choice @ strcat choice @ "gear" smatch if "What is the name of the object you want to give?" .tell read " #find " swap strcat strcat then force "Ok, which of these are you wanting to donate?" .tell read var num toint num ! me @ choice @ num @ "name" getboxprop dup not if pop "Invalid selection." .tell continue then var n n ! var quan me @ choice @ num @ "Quantity" getboxprop toint 1 greater quan ! lefto @ n @ array_getitem toint quan @ lesser quan ! quan @ not if "That item is not in demand for this project." .tell exit then spent @ n @ array_getitem toint quan @ + spent @ n @ array_setitem spent ! 1 quan @ 1 for me @ choice @ num @ deleteordecrementboxitem repeat str "You give " quan @ " X ^yellow^[^brown^" n @ "^yellow^]^normal^ to the project." cat .tell "" lefto ! spent @ foreach tostr "/" swap strcat strcat ":" strcat lefto @ swap strcat lefto ! repeat lefto @ ":" rsplit pop lefto ! rpsys str "Global Research/" topic @ "/MaterialsSpent" cat lefto @ setprop rpsys str "Global Research/" topic @ "/Suppliers/" me @ name strcat cat getpropstr toint n @ find_cost #0 "cost" getstatint quan @ * + rpsys str "Global Research/" topic @ "/Suppliers/" me @ name strcat cat rot setprop exit then choice @ "g" instring if "How much gil would you like to contribute?" .tell read toint choice ! rpsys str "Global Research/" topic @ "/Gil" cat getpropstr toint rpsys str "Global Research/" topic @ "/Gilspent" cat getpropstr toint - maxgil ! me @ "gil" getstatint choice @ lesser maxgil @ lesser choice ! str "You contribute " choice @ " gil to the project" cat .tell me @ "gil" getstatfloat choice @ - me @ "Gil" rot setstat rpsys str "Global Research/" topic @ "/Gilspent" cat getpropstr toint choice @ 2 * maxgil @ lesser + rpsys str "Global Research/" topic @ "/Gilspent" cat rot setprop rpsys str "Global Research/" topic @ "/Suppliers/" me @ name strcat cat getpropstr toint choice @ + rpsys str "Global Research/" topic @ "/Suppliers/" me @ name strcat cat rot setprop then choice @ tostr choice ! me @ "Group Rank" getstatstr "_" " " subst "{Leader|Quartermaster}" smatch choice @ "d" instring and if "How much gil would you like to contribute?" .tell read toint choice ! rpsys str "Global Research/" topic @ "/Gil" cat getpropstr toint rpsys str "Global Research/" topic @ "/Gilspent" cat getpropstr toint - maxgil ! me @ "gil" getgroupstat toint choice @ lesser maxgil @ lesser choice ! str "You contribute " choice @ " gil to the project" cat .tell me @ "gil" getgroupstat toint choice @ - me @ "Gil" rot setgroupstat rpsys str "Global Research/" topic @ "/Suppliers/" me @ "Adventuring Group" getstatstr strcat cat getpropstr toint choice @ + rpsys str "Global Research/" topic @ "/Suppliers/" me @ "Adventuring Group" getstatstr strcat cat rot setprop rpsys str "Global Research/" topic @ "/Gilspent" cat getpropstr toint choice @ + rpsys str "Global Research/" topic @ "/Gilspent" cat rot setprop then choice @ tostr choice ! choice @ "q" instring until "Goodbye." .tell ; : focus var topic me @ "Global Research" getstatstr topic ! topic @ "0" smatch if "You must start researching to focus." .tell exit then topic @ canprogress? not if "This topic is lacking in funds and/or supplies. No research can be done." .tell exit then systime me @ "Last Researched" getstatint - 60 60 * 24 * < if str "You must wait " systime me @ "Last Researched" getstatint - 60 60 * 24 * swap - timex " before you can focus again. This is OOC time." cat .tell exit then rpsys str "Global Research/" topic @ "/JP" cat getpropstr toint not if rpsys str "Global Research/" topic @ "/Level" cat getpropstr toint 50 * tostr rpsys str "Global Research/" topic @ "/JP" cat rot setprop then topic @ dailyjp 2 * var cost cost ! str "It will cost " cost @ "JP to contribute another day's worth of research to the topic. Continue?" cat .tell read "y" instring not if "Aborting" .tell exit then me @ jp cost @ < if "Insufficient JP." .tell exit then me @ cost @ jpspend me @ topic @ researchcontinue "You focus on the task at hand and continue the research at the expense of personal time." .tell me @ "last researched" systime setstat ; : main var param strip param ! init param @ not if list-topics exit else param @ "#foc" instring if focus exit then param @ known? not if "Invalid topic. This topic either does not exist, or is not known to the world as a possibility yet." .tell exit then param @ topiceditor exit then ;