$include $lib/alynna $include $lib/rp $include $muf/rp/boxutils $include $lib/jobs : gdiscounter[ f:input d:tgt s:type s:spec -- f:output ] input @ { type @ spec @ "gresearch" }rps dup not if pop exit else var! research { "Global Research" research @ "Researchers" tgt @ name }rps tofloat 2.0 / { "Global Research" research @ "Level" }rps tofloat 50 * 50 + / dup 100.0 * var! x 1 swap - * x @ if { "Your purchase of " spec @ " will be discounted by " x @ 2 round "% due to your research into the subject." }cat tgt @ swap ansi_notify then then ; MAGECALL gdiscounter $libdef gdiscounter : badgeCheck me @ "Total Refunded" getaccountstat toint var! total total @ 1 > if me @ "Indecisive" "You have refunded an ability, proving you are not entirely certain of your actions." addbadge then total @ 10 > if me @ "Undecided" "You have refunded 10 JP worth of abilities, showing you undecided in your direction." addbadge then total @ 100 > if me @ "Mid Life Crisis" "You have refunded 100 JP worth of abilities. Perhaps you're looking for a new direction in life." addbadge then total @ 1000 > if me @ "Reborn" "You have refunded 1000 JP worth of abilities, making you effectively born again." addbadge then total @ 10000 > if me @ "Retconned" "You have refunded 10000 JP worth of abilities, proving your past self was simply retconned out of existence." addbadge then ; : jprefund[ s:target i:amount ] me @ "Job" getstatstr var! job amount @ me @ "Refund Points" getstatint > if { "Insufficient refund points to complete request. You have " me @ "Refund Points" getstatint ", you need " amount @ "." }tell exit then amount @ me @ { "Jobs/" job @ }cat getstatfloat me @ { "Jobs/" job @ "spent" }cat getstatfloat - > if { "Insufficient free JP in your current job to complete the request. You have " me @ { "Jobs/" job @ }cat getstatfloat me @ { "Jobs/" job @ "spent" }cat getstatfloat - 2 fchop ", you need " amount @ "." }tell exit then { "You're about to refund ^GREEN^" amount @ "JP^ ^ in " job @ " at a cost of ^RED^" amount @ "^ ^ refund points. Do you wish to continue? (y/N)" }tell read "y*" smatch not if { "Aborted." }tell exit then { "Checking to see if you can retrain " amount @ "JP in " job @ " without affecting any other jobs you have spent JP in ..." }tell me @ job @ amount @ safeToRefund? dup var! conflicts if { "Unable to proceed, because the amount of JP from this job would disqualify you from the following jobs you have already spent JP in: ^RED^" conflicts @ array_commas "^ ^\rEither you can refund less points, or you can remove the points from these other jobs first." }tell else { "Yes we can! Converting JP to uJP and deducting the Refund Points." }tell me @ "jobs/" job @ strcat over over getstat amount @ - setstat me @ "Universal JP" over over getstat amount @ + setstat me @ "Refund Points" over over getstat toint amount @ - setstat me @ "Total Refunded" over over getaccountstat toint amount @ + setaccountstat me @ "Refunded/JP" systime setstat { "Stimulus package applied." }tell then ; : specialrefund[ str:target int:amount -- ] "Special/" target @ strcat var! spec me @ spec @ getstatint 1 < if "You do not have that to refund." .tell exit then me @ spec @ getstatint amount @ lesser amount ! me @ spec @ getstatint 1 - me @ spec @ rot setstat me @ me @ "Job" getstatstr dup var! job target @ talentcost var! cost cost @ me @ "special" spec @ gdiscounter cost ! me @ spec @ getstatint 1 + me @ spec @ rot setstat cost @ 0 > not target @ "Craft Skill" smatch not and if "This job does not support that special skill at that rating, or you have it over a rating of 25." .tell exit then rpsys "Talents/" array_get_propdirs foreach var! cur pop rpsys { "Talents/" cur @ "/Requirement" }cat getpropstr dup not if pop continue then target @ smatch not if continue then me @ "Special/" cur @ strcat getstatint me @ spec @ getstatint < not if "You have another special skill that relies on this special skill. You must refund it first." .tell exit then repeat target @ "Craft Skill" smatch if 6 cost ! rpsys { "Jobs/" job @ "/Special" }cat getpropstr "Craft Skill" instring not if "You can return Craft Skill to any job that has Craft Skill in it." .tell exit then then { "Are you sure you want to refund " amount @ " point" amount @ 1 > if "s" then " of the special skill [" target @ "] to your job of " job @ " for " amount @ cost @ * " JP? The job will lose the JP as if it was never earned, and the JP will be converted to uJP to be spent as you please." }cat .tell read tolower "{y|yes}" smatch not if "Aborting." .tell exit then me @ "Refund Points" getstatint amount @ cost @ * < me @ "Universal JP" getstatint 0 < not and if { "You do not have the refund points required. You have " me @ "Refund Points" getstatint ". It takes 1 point per JP to refund." }cat .tell exit then me @ { "Jobs/" job @ }cat getstatfloat amount @ cost @ * < me @ { "Jobs/" job @ "spent" }cat getstatfloat amount @ cost @ * < or if "Your current job does not have enough JP to support the refund." .tell exit then amount @ cost @ * cost ! me @ job @ cost @ safeToRefund? dup var! conflicts if { "Refund failed because removing the amount of points requested, would make the following jobs unavailable, which you have already spent JP in: ^RED^" conflicts @ array_commas "^ ^\rEither try to refund less points or refund spent JP from these jobs first." }tell exit then me @ "Universal JP" getstatint 0 < not if me @ "Refund Points" getstatint cost @ - me @ "Refund Points" rot setstat me @ "Total Refunded" getaccountstat toint cost @ + me @ "Total Refunded" rot setaccountstat me @ { "Jobs/" job @ }cat getstatfloat cost @ - me @ { "Jobs/" job @ }cat rot setstat me @ { "Jobs/" job @ "spent" }cat getstatfloat cost @ - me @ { "Jobs/" job @ "spent" }cat rot setstat me @ "Refunded/" target @ strcat systime setstat then me @ spec @ getstatint amount @ - me @ spec @ rot setstat me @ "Universal JP" getstatfloat cost @ + me @ "Universal JP" rot setstat me @ { "Lock up Specials/" target @ }cat 0 setstat "Refunded." .tell ; : subskillrefund[ str:target int:amount -- ] amount @ 1 greater amount ! target @ var! spec me @ "Job" getstatstr var! job me @ spec @ getstatint 1 < if "You do not have that to refund." .tell exit then me @ spec @ getstatint amount @ lesser amount ! me @ spec @ getstatint 1 - me @ spec @ rot setstat me @ target @ subskillcost var! cost me @ spec @ getstatint 1 + me @ spec @ rot setstat cost @ 0 > not if "This job does not support that skill at that rating, or you have it over a rating of 25." .tell exit then { "Are you sure you want to refund " amount @ " point" amount @ 1 > if "s" then " of the sub skill [" target @ "] to your job of " job @ " for " amount @ cost @ * " JP? The job will lose the JP as if it was never earned, and the JP will be converted to uJP to be spent as you please." }cat .tell read tolower "{y|yes}" smatch not if "Aborting." .tell exit then me @ "Refund Points" getstatint amount @ cost @ * < me @ "Universal JP" getstatint 0 < not and if { "You do not have the refund points required. You have " me @ "Refund Points" getstatint ". It takes 1 point per JP to refund." }cat .tell exit then me @ { "Jobs/" job @ }cat getstatfloat amount @ cost @ * < me @ { "Jobs/" job @ "spent" }cat getstatfloat amount @ cost @ * < or if "Your current job does not have enough JP to support the refund." .tell exit then amount @ cost @ * cost ! me @ job @ cost @ safeToRefund? dup var! conflicts if { "Refund failed because removing the amount of points requested, would make the following jobs unavailable, which you have already spent JP in: ^RED^" conflicts @ array_commas "^ ^\r Either try to refund less points or refund spent JP from these jobs first." }tell exit then me @ "Universal JP" getstatint 0 < not if me @ "Refund Points" getstatint cost @ - me @ "Refund Points" rot setstat me @ "Total Refunded" getaccountstat toint cost @ + me @ "Total Refunded" rot setaccountstat me @ { "Jobs/" job @ }cat getstatfloat cost @ - me @ { "Jobs/" job @ }cat rot setstat me @ { "Jobs/" job @ "spent" }cat getstatfloat cost @ - me @ { "Jobs/" job @ "spent" }cat rot setstat then me @ spec @ getstatint amount @ - me @ spec @ rot setstat me @ "Total Refunded" getaccountstat toint cost @ + me @ "Total Refunded" rot setaccountstat me @ "Universal JP" getstatfloat cost @ + me @ "Universal JP" rot setstat "Refunded." .tell ; : craftskillrefund[ str:target int:amount -- ] { "Craft/" target @ }cat var! spec me @ "Job" getstatstr var! job me @ spec @ getstatint 1 < if "You do not have that to refund." .tell exit then target @ tolower "{mhunting|hunting|stalking|apothecary|harvesting|fishing|butchering}" smatch if "That skill can be gained without JP, and thus cannot be refunded." .tell exit then 6 var! cost me @ spec @ getstatint amount @ lesser amount ! { "Are you sure you want to refund " amount @ " point" amount @ 1 > if "s" then " of the synthesis skill [" target @ "] for " cost @ amount @ * " refund points. These points will become Craft Skill, which can themselves be refunded, or used to #practice another synth skill." }cat .tell read tolower "{y|yes}" smatch not if "Aborting." .tell exit then me @ "Refund Points" getstatint amount @ cost @ * < me @ "Universal JP" getstatint 0 < not and if { "You do not have the refund points required. You have " me @ "Refund Points" getstatint ". It takes 1 point per JP to refund." }cat .tell exit then amount @ cost @ * cost ! me @ "Refund Points" getstatint cost @ - me @ "Refund Points" rot setstat me @ "Total Refunded" getaccountstat toint cost @ + me @ "Total Refunded" rot setaccountstat me @ spec @ getstatint amount @ - me @ spec @ rot setstat me @ "Special/Craft Skill" getstatint amount @ + me @ "Special/Craft Skill" rot setstat "Refunded." .tell ; : resourcerefund[ str:target int:amount -- ] target @ tolower "*s" smatch target @ "stables" smatch not and if target @ tolower dup "s" rsplit pop target ! then target @ not if "Invalid target. +refund resource (resource)" .tell exit then { "Resources/" target @ }cat var! spec me @ "Job" getstatstr var! job me @ spec @ getstatint 1 < if "You do not have that to refund." .tell "Resources found: " me @ "@rp/resources/" array_get_propvals { swap foreach pop repeat }list array_commas strcat .tell exit then .debug-off 1 var! cost me @ spec @ getstatint amount @ lesser amount ! me @ "Resourcesspent" getstatint dup not if pop "You haven't spent any resources." .tell exit then amount @ lesser amount ! { "Are you sure you want to refund " amount @ " point" amount @ 1 > if "s" then " of the Resource [" target @ "] for " cost @ amount @ * " refund points. These points will become unallocated and can be reinvested as you please." }cat .tell read tolower "{y|yes}" smatch not if "Aborting." .tell exit then me @ "Refund Points" getstatint amount @ cost @ * < me @ "Universal JP" getstatint 0 < not and if { "You do not have the refund points required. You have " me @ "Refund Points" getstatint ". It takes 1 point per JP to refund." }cat .tell exit then amount @ cost @ * cost ! me @ "Refund Points" getstatint cost @ - me @ "Refund Points" rot setstat me @ "Total Refunded" getaccountstat toint cost @ + me @ "Total Refunded" rot setaccountstat me @ spec @ getstatint amount @ - me @ spec @ rot setstat target @ "gem" instring if amount @ 2 * amount ! then target @ "refinery" instring if amount @ 2 * amount ! then me @ "ResourcesSpent" 0 amount @ - adjstat "Refunded." .tell ; : main[ str:target -- ] me @ "Refund Start" getstatint not if me @ "Refund Start" 1 setstat me @ "Refund Points" 50 setstat then target @ "=" instring not if 1 var! amount else target @ "=" split toint 1 greater amount ! target ! then rpsys { "Talents/" target @ "/desc" }cat getpropstr if target @ amount @ specialrefund badgecheck exit then target @ "resource*" smatch if target @ tolower "" "resource" subst strip amount @ resourcerefund badgecheck exit then target @ "/" instring if target @ amount @ subskillrefund badgecheck exit then target @ "`" instring if target @ "" "`" subst amount @ craftskillrefund badgecheck exit then target @ "JP" smatch if target @ amount @ jprefund badgecheck exit then badgecheck target @ not target @ "help" instring or if { "Type +refund (something)=(amount) to refund things. You must be in a job that supports the refunded item at the level you have it." }cat .tell "You can refund synth skills[Type +synth #skills] by typing +refund `skill, like +refund `Blades" .tell "You can refund resources with +refund resource (resource)" .tell "You can refund unspent JP in your current job with +refund JP=" .tell exit then { "I do not understand what you want to refund. I do not know what [" target @ "] is." }cat .tell ;