Mar 212009
Achaea MUD ZMUD script for management of vials
#CLASS {Aliases|VialManagement} #ALIAS _SetupVial { silenceon _SendCommandOnPrompt ii #WAIT 2000 #FORALL @VialList {#UNVAR %1} #VAR VialList "" _nodef VialManagement #VAR VialStats "" _nodef VialManagement #ADDKEY VialStats TotalHealth 0 #ADDKEY VialStats TotalMana 0 #ADDKEY VialStats TotalEpidermal 0 #ADDKEY VialStats TotalMending 0 #LOOPDB @InvHolding { #IF (%match( %key, "vial%d")) { #VAR %key "" _nodef VialManagement #ADDKEY %key Contents Empty #ADDKEY %key UsesLeft 0 #ADDKEY %key Life 0 #ADDKEY %key Location Hand VialList = %push( %key, @VialList) } } #FORALL @VialList { #TRIGGER TrigVialSetup {^It has (%d) months of usefulness left.$} {#ADDKEY %i Life %%1} #COND {^A*({mending|epidermal|mana|health})*sloshes about in it.$} { #ADDKEY %i Contents %proper( %%1) #ADDKEY %i UsesLeft 200 } {within|param=3} p %i #WAIT 2000 } #UNTRIGGER TrigVialSetup silenceoff } #ALIAS _UseVial { ;UseVial Health/Mana/Epidermal/Mending #ADDKEY VialStats VialToUse "" #ADDKEY VialStats TotalHealth 0 #ADDKEY VialStats TotalMana 0 #ADDKEY VialStats TotalEpidermal 0 #ADDKEY VialStats TotalMending 0 #IF (%numparam > 0 and not %null( @VialList)) { #FORALL @VialList { #IF (%db( @{%i}, Contents)=%1 and (%db( @{%i}, UsesLeft) > 0) and %null( @VialStats.VialToUse)) {#ADDKEY VialStats VialToUse %i} #ADDKEY VialStats Total%db( @{%i}, Contents) %eval( %db( @{%i}, UsesLeft) + %db( @VialStats, Total%db( @{%i}, Contents))) } #IF (not %null( @VialStats.VialToUse)) { #IF ((%1="Health") or (%1 = "Mana")) { #ADDKEY Personal Elixir 0 #EXEC _SendCommandOnPrompt "sip @VialStats.VialToUse" } #IF ((%1="Mending") or (%1 = "Epidermal")) { #ADDKEY Personal Salve 0 #EXEC _SendCommandOnPrompt "apply @VialStats.VialToUse to %2" } } { #IF ((%1="Health") or (%1 = "Mana")) {#IF (%db( @Personal, Sip%1)) {#BUTTON bSip%1}} #IF ((%1="Mending") or (%1 = "Epidermal")) {#IF (%db( @Personal, Apply%1)) {#BUTTON bApply%1}} #EXEC _Debug "_UseVial Failed to Find Vial with %1" } } } #ALIAS _VialsStat { #EXEC _WaitForEQBal #FORALL @VialList { #IF (%db( @{%i}, Location)=Hand) { put %i in pack #ADDKEY %i Location Pack } #NOOP } } #ALIAS _HoldVials { #EXEC _WaitForEQBal #FORALL @VialList { #IF (%db( @{%i}, Location)=Pack) { take %i from pack #ADDKEY %i Location Hand } #NOOP } } #ALIAS _GiveVilas {#IF (%numparam = 2) { #VAR VialsToGive "" _nodef VialManagement #FORALL @VialList {#IF (%eval( %eval( %db( @{%i}, Contents)=%1) and %eval( %db( @{%i}, UsesLeft)=0))) {#ADDITEM VialsToGive %i}} #IF (not %null( @VialsToGive)) {#EXEC _ActionAdd Give %2|@VialsToGive "" "RepeatSuccess" "" "" "" "~#EXEC _ActionAdd Selfishness 0"} } {#ECHO _GiveVilas WHAT(Health/Mana/Epidermal/Mending) WHO}} #ALIAS _CheckVials { VialList = %sort( @VialList) #IF (%numparam = 1) { " " #VAR VialsToGive "" _nodef VialManagement #FORALL @VialList {#IF (%eval( %eval( %db( @{%i}, Contents)=%1) and %eval( %db( @{%i}, UsesLeft)=0))) {#ADDITEM VialsToGive %i}} #IF (not %null( @VialsToGive)) {#ECHO %numitems( @VialsToGive) Empty of %1} } { " " #VAR VialsToGive "" _nodef VialManagement #FORALL @VialList {#IF (%eval( %eval( %db( @{%i}, Contents)=Mana) and %eval( %db( @{%i}, UsesLeft)=0))) {#ADDITEM VialsToGive %i}} #IF (not %null( @VialsToGive)) {#ECHO %numitems( @VialsToGive) Empty of Mana} #VAR VialsToGive "" _nodef VialManagement #FORALL @VialList {#IF (%eval( %eval( %db( @{%i}, Contents)=Health) and %eval( %db( @{%i}, UsesLeft)=0))) {#ADDITEM VialsToGive %i}} #IF (not %null( @VialsToGive)) {#ECHO %numitems( @VialsToGive) Empty of Health} #VAR VialsToGive "" _nodef VialManagement #FORALL @VialList {#IF (%eval( %eval( %db( @{%i}, Contents)=Mending) and %eval( %db( @{%i}, UsesLeft)=0))) {#ADDITEM VialsToGive %i}} #IF (not %null( @VialsToGive)) {#ECHO %numitems( @VialsToGive) Empty of Mending} #VAR VialsToGive "" _nodef VialManagement #FORALL @VialList {#IF (%eval( %eval( %db( @{%i}, Contents)=Epidermal) and %eval( %db( @{%i}, UsesLeft)=0))) {#ADDITEM VialsToGive %i}} #IF (not %null( @VialsToGive)) {#ECHO %numitems( @VialsToGive) Empty of Epidermal} } } #ALIAS _FillVials {#IF (%numparam = 1) { #VAR VialsToGive "" _nodef VialManagement #FORALL @VialList {#IF (%eval( %eval( %db( @{%i}, Contents)=%1) and %eval( %db( @{%i}, UsesLeft)=0))) {#ADDKEY %i UsesLeft 200}} } {#ECHO FillVials WHAT(Health/Mana/Epidermal/Mending)}} #ALIAS _Mending {_UseVial Mending %1} #ALIAS _Epidermal {_UseVial Epidermal %1} #ALIAS _FixVialList { _SendCommandOnPrompt ii #WAIT 5000 #VAR VialList "" _nodef VialManagement #LOOPDB @InvHolding {#IF (%match( %key, "vial%d")) {VialList = %push( %key, @VialList)}} #VAR VialList %sort( @VialList) _nodef VialManagement " " #ECHO Done } #VAR vial274891 {ContentsHealthUsesLeft200Life111LocationHand} #VAR VialList {vial283992|vial349381|vial315579|vial314681|vial147565|vial347699|vial277059|vial274891|vial317372|vial284599|vial111485} #VAR vial277059 {ContentsHealthUsesLeft200Life111LocationHand} #VAR vial284599 {ContentsMendingUsesLeft200Life111LocationHand} #VAR vial314681 {ContentsManaUsesLeft184Life111LocationHand} #VAR vial315579 {ContentsHealthUsesLeft200Life111LocationHand} #VAR vial317372 {ContentsEpidermalUsesLeft200Life111LocationHand} #VAR vial147565 {ContentsManaUsesLeft200Life111LocationHand} #VAR VialStats {TotalHealth650TotalMana584TotalEpidermal200TotalMending400VialToUsevial349381} #VAR VialsToGive {vial147565|vial314681|vial315579|vial349381} #VAR vial111485 {ContentsMendingUsesLeft200Life136LocationHand} #VAR vial283992 {ContentsManaUsesLeft0Life111LocationHand} #VAR vial349381 {ContentsHealthUsesLeft49Life136LocationHand} #VAR vial347699 {ContentsManaUsesLeft200Life139LocationHand} #TRIGGER {^A (*) vial contains nothing that is drinkable.$} { #ADDKEY @VialStats.VialToUse UsesLeft 0 #ADDKEY Personal Elixir 1 } #TRIGGER {^You may drink another health or mana elixir.$} {#ADDKEY @VialStats.VialToUse UsesLeft %eval( %db( @{%db( @VialStats , VialToUse)}, UsesLeft)-1)} #TRIGGER {^A (*) vial contains nothing that is spreadable.$} { #ADDKEY @VialStats.VialToUse UsesLeft 0 #ADDKEY Personal Salve 1 } #TRIGGER {^What is it that you wish to drink?$} {_Debug "You don't have that vial"} #CLASS 0