/* * Written by: Xeon * * Crafting Assist Script * * Version 0.2 -- Feb 5th, 2007 * */ ; Global Variable Declarations variable collection:int CountUsed variable bool doCraft variable int currStep /* * Possible Values of cState: */ variable int cState #define CS_STATION 10 /* Using Crafting Station */ #define CS_STATION_RECIPE 11 /* Waiting for Recipe selection */ #define CS_STATION_INGRED 12 /* Selecting Ingredients/Materials needed */ #define CS_STATION_SETUP 13 /* Setup the workbench with Ingredients */ #define CS_STATION_BEGIN 14 /* Waiting to begin recipe */ #define CS_ACTION 20 /* Using Recipe actions */ #define CS_ACTION_FIND 21 /* Select Available Action */ #define CS_ACTION_WAIT 22 /* Waiting for Action to finish */ #define CS_ACTION_MANUAL 23 /* Requires User Input (manual typing) */ #define CS_ACTION_OOAP 24 /* Out Of Action Points */ #define CS_ACTION_OOM 25 /* Out Of Material (ingredients) */ #define CS_COMPLICATE 30 /* Checking Complication */ #define CS_COMPLICATE_FIND 31 /* Selecting Complication Action */ #define CS_COMPLICATE_WAIT 32 /* Waiting for Complication Action to finish */ #define CS_LOOT 40 /* Looting */ #define CS_MOVE 50 /* Moving to Target */ #define CS_MOVE_TARGET 51 /* Selecting Correct Target */ #define CS_MOVE_WAIT 52 /* Waiting for movement to finish */ #define CS_ORDER 60 /* Talking to Order Giver/Taker */ #define CS_ORDER_NEW 61 /* Getting new Orders */ #define CS_ORDER_DONE 62 /* Completing Finished Orders */ #define CS_SUPPLY 70 /* Talking to Item/Resupply Vendor */ #define CS_SUPPLY_BUY 71 /* Buying supplies */ #define CS_SUPPLY_SORT 72 /* Moving supplies around inventory */ #define CS_SUPPLY_SELL 73 /* Sell any loot */ atom(script) VG_OnIncomingText(string Text, string ChannelNumber, string ChannelName) { ; This event is fired every time that text get's sent to the client ;echo "IncomingText ${ChannelNumber} : ${ChannelName} :Text: ${Text}" ;call MyOutput "${ChannelNumber} : ${ChannelName} :Text: ${Text}" if ( ${Text.Find[Select the recipe you wish to use]} ) { ;VGEcho "State: ${Refining.State}" > screen call MyOutput "Select the recipe you wish to use" cState:Set[CS_STATION] } elseif ( ${Text.Find[Crafting recipe selected]} ) { ;VGEcho "Refining:DoSetup" > screen call MyOutput "${Text}" ;Refining:Begin ;Refining:DoSetup ;call DumpRefining cState:Set[CS_STATION_RECIPE] } elseif ( ${Text.Find[You may now set up your workbench]} ) { ;VGEcho "Refining:Start" > screen ;call MyOutput " === Refining:Start ===" ;Refining:Start cState:Set[CS_STATION_SETUP] } elseif ( ${Text.Find[has been completed]} ) { ; We finished the last Action ; make sure to set the state so we can find another action to do cState:Set[CS_ACTION] } elseif ( ${Text.Find[Recipe section 1 complete]} ) { ;Stage 1 done } elseif ( ${Text.Find[Recipe section 2 complete]} ) { ;Stage 2 done } elseif ( ${Text.Find[Recipe section 3 complete]} ) { ;Stage 3 done } elseif ( ${Text.Find[You do not have enough action points]} ) { if ( ${Refining.Stage.Index} < 4 ) { VGEcho "Arg! Ran out of Action Points" > screen Refining:Cancel cState:Set[CS_ACTION_OOAP] } else { VGEcho "Arg! You do it manualy!" > screen cState:Set[CS_ACTION_MANUAL] } doCraft:Set[FALSE] } elseif ( ${Text.Find[Missing item of type:]} ) { VGEcho "Ran out of materials, exiting!" > screen cState:Set[CS_ACTION_OOM] ;Refining:Cancel } elseif ( ${Text.Find[Your crafting session ends]} ) { ; All Done! ; Set the next action to Loot! cState:Set[CS_LOOT] ; Clear out the variables for the next run through CountUsed:Set[""] if ${CountUsed.FirstKey(exists)} { do { call MyOutput "Clearing: ${CountUsed.CurrentKey}" CountUsed:Set[${CountUsed.CurrentKey}, 0] } while ${CountUsed.NextKey(exists)} } } } atom(script) VG_OnCraftingAlert(string Text, string AlertID) { ;This event is fired upon every instance that the ; Vanguard client sends a 'crafting alert' call MyOutput "${AlertID}:: ${Text}" call MyOutput "State: ${Refining.State}" call MyOutput "Progress: ${Refining.CurrentRecipe.ProgressBarPct}" call MyOutput "Quality: ${Refining.Quality}" } function CheckState() { wait 10 ;VGEcho "CheckState called == ${cState}" > screen Switch ${cState} { case CS_STATION /* Using Crafting Station */ break case CS_STATION_RECIPE /* Waiting for Recipe selection */ if ( ${Refining.CurrentRecipe}(exists) ) { cState:Set[CS_STATION_INGRED] } else { ; Still waiting for them to select a recipe cState:Set[CS_STATION] } break case CS_STATION_INGRED /* Selecting Ingredients/Materials needed */ ; Check to see if we have all the required Ingredients call CheckIngredients if ( ${Return} ) { VGEcho "You have all the required Ingredients" > screen cState:Set[CS_STATION_SETUP] } else { VGEcho "You don't have required Ingredients for that Recipe" > screen VGEcho "Try a different one" > screen cState:Set[CS_STATION] } break case CS_STATION_SETUP /* Setup workbench with Ingredients */ Refining:DoSetup call DumpRefining cState:Set[CS_STATION_BEGIN] break case CS_STATION_BEGIN /* Waiting to begin recipe */ VGEcho "Refining:Start" > screen call MyOutput " === Refining:Start ===" Refining:Start cState:Set[CS_ACTION] break case CS_ACTION /* Using Recipe actions */ cState:Set[CS_ACTION_FIND] break case CS_ACTION_FIND /* Select Available Action */ call FindAction cState:Set[CS_ACTION_WAIT] break case CS_ACTION_WAIT /* Waiting for Action to finish */ ; Don't do anything here as this state will be changed ; by an Event from VG_OnIncomingText() break case CS_ACTION_MANUAL /* Requires User Input (manual typing) */ break case CS_ACTION_OOAP /* Out Of Action Points */ break case CS_ACTION_OOM /* Out Of Material (ingredients) */ break case CS_COMPLICATE /* Checking Complication */ break case CS_COMPLICATE_FIND /* Selecting Complication Action */ break case CS_COMPLICATE_WAIT /* Waiting for Complication Action to finish */ break case CS_LOOT /* Looting */ call DoLoot break case CS_MOVE /* Moving to Target */ break case CS_MOVE_TARGET /* Selecting Correct Target */ break case CS_MOVE_WAIT /* Waiting for movement to finish */ break case CS_ORDER /* Talking to Order Giver/Taker */ break case CS_ORDER_NEW /* Getting new Orders */ break case CS_ORDER_DONE /* Completing Finished Orders */ break case CS_SUPPLY /* Talking to Item/Resupply Vendor */ break case CS_SUPPLY_BUY /* Buying supplies */ break case CS_SUPPLY_SORT /* Moving supplies around inventory */ break case CS_SUPPLY_SELL /* Sell any loot */ break default /* Hmm, how did we get here? */ } } function DoLoot() { ; Should probably check to see if we have a Loot window open Loot:LootAll } function:bool CheckIngredients() { ;Check our UsableItemCount to see if we have enough if ( ${Refining.UsableItemCount} > 15 ) { VGEcho "Igredients Found: ${Refining.UsableItemCount}" > screen return TRUE } else { VGEcho "You do not have enough Ingredients (${Refining.UsableItemCount})" > screen return FALSE } } function FindAction() { variable int tstep variable int substep variable int count ;VGEcho "State: ${Refining.State}" > screen ;VGEcho "StepCount: ${Refining.CurrentRecipe.StepCount}" > screen if ( ${Refining.Stage.Index} == 1 ) { VGEcho "Stage: (${Refining.Stage.Name}:${Refining.Stage.Index}) StepCount: ${Refining.Stage.StepCount} " > screen call MyOutput "Stage: (${Refining.Stage.Name}:${Refining.Stage.Index}) StepCount: ${Refining.Stage.StepCount}" ; if ( ${Refining.CurrentRecipe.IsWorkOrder} ) ; If this is stage 1 of a WorkOrder then just always select the first AvailAction Refining.Stage.Step[1].AvailAction[1]:Use } elseif ( ${Refining.Stage.Index} > 1 ) { VGEcho "Stage: (${Refining.Stage.Name}:${Refining.Stage.Index}) StepCount: ${Refining.Stage.StepCount} " > screen call MyOutput "Stage: (${Refining.Stage.Name}:${Refining.Stage.Index}) StepCount: ${Refining.Stage.StepCount}" ; ; As long as Quality is low, try to find and use a Quality increasing action ; if ( ${Refining.Quality} < 350 ) { call TryQualityAction if ( ${Return} ) return } ; ; Sometimes ${Refining.Stage.StepCount} = 0, but we still have two AvailActions ; if ( ${Refining.Stage.StepCount} == 0 ) { VGEcho "Bah! StepCount == 0" > screen VGEcho "You will have to do this Stage manualy" > screen return } ; Don't have to worry about Quality now ; Just use the first AvailAction we can ; However, if the ${Refining.CurrentRecipe.ProgressBarPct} is > 50% ; and there are 2 StepCount's then don't use 1 anymore if (( ${Refining.CurrentRecipe.ProgressBarPct} >= 50 ) && ( ${Refining.Stage.StepCount} > 1 )) { tstep:Set[2] } else { tstep:Set[1] } ; Cycle through all the possible AvailActions and find one to use do { substep:Set[1] call MyOutput "AvailActionsCount: ${Refining.Stage.Step[${tstep}].AvailActionsCount}" do { call MyOutput "Avail Name: (${tstep})(${substep}) :Name: ${Refining.Stage.Step[${tstep}].AvailAction[${substep}].Name}" VGEcho "Using Avail Name: ${Refining.Stage.Step[${tstep}].AvailAction[${substep}].Name}" > screen Refining.Stage.Step[${tstep}].AvailAction[${substep}]:Use return } while ( ${substep:Inc} <= ${Refining.Stage.Step[${tstep}].AvailActionsCount} ) } while ( ${tstep:Inc} <= ${Refining.Stage.StepCount} ) } } /* Try to find an Action in the current Stage that will increase quality */ function:bool TryQualityAction() { variable int tstep variable int substep variable int count ; Find any Quality enhancing steps and use them! VGEcho "Trying to improve Quality!" > screen tstep:Set[1] do { ;VGEcho "CountUsed: ${Refining.Stage.Index}:${tstep} ::: ${CountUsed.Element["${Refining.Stage.Index}:${tstep}"]}" > screen if ( ${CountUsed["${Refining.Stage.Index}:${tempvar}"](exists)} ) { if ( ${CountUsed.Element["${Refining.Stage.Index}:${tstep}"]} >= 50 ) { ; Skip to the next Step, as this one is all used up continue } } ;call MyOutput "Step ${tstep}:Name: ${Refining.Stage.Step[${tstep}].Name}" ;call MyOutput "Step ${tstep}:Description: ${Refining.Stage.Step[${tstep}].Description}" ;call MyOutput "Step ${tstep}:AvailActionsCount: ${Refining.Stage.Step[${tstep}].AvailActionsCount}" substep:Set[1] do { ;call MyOutput "Step ${tstep}:AvailAction ${substep}:Name: ${Refining.Stage.Step[${tstep}].AvailAction[${substep}].Name}" ;call MyOutput "Step ${tstep}:AvailAction ${substep}:ActionPointCost: ${Refining.Stage.Step[${tstep}].AvailAction[${substep}].ActionPointCost}" ;call MyOutput "Step ${tstep}:AvailAction ${substep}:Description: ${Refining.Stage.Step[${tstep}].AvailAction[${substep}].Description}" if ( ${Refining.Stage.Step[${tstep}].AvailAction[${substep}].Description.Find[Quality: High]} ) { ; Yeah, use this to increase Quality call MyOutput "Avail Name: (${tstep})(${substep}) :Name: ${Refining.Stage.Step[${tstep}].AvailAction[${substep}].Name}" VGEcho "Using: ${Refining.Stage.Step[${tstep}].AvailAction[${substep}].Name}" > screen Refining.Stage.Step[${tstep}].AvailAction[${substep}]:Use ;count:Set[${CountUsed.Element["${Refining.Stage.Index}:${tstep}"]} + 1] ;CountUsed:Set["${Refining.Stage.Index}:${tstep}",${count}] return TRUE } } while ( ${substep:Inc} <= ${Refining.Stage.Step[${tstep}].AvailActionsCount} ) } while ( ${tstep:Inc} <= ${Refining.Stage.StepCount} ) return FALSE } function DumpRefining() { if ( ${Refining.CurrentRecipe.StepCount} > 0 ) { ;VGEcho "State: ${Refining.State}" > screen call MyOutput "Refining.State: ${Refining.State}" ;UsableItemCount call MyOutput "UsableItemCount: ${Refining.UsableItemCount}" ;OrigActionPointsAvail call MyOutput "OrigActionPointsAvail: ${Refining.OrigActionPointsAvail}" ;ActionPointsUsed call MyOutput "ActionPointsUsed: ${Refining.ActionPointsUsed}" call MyOutput "Quality: ${Refining.Quality}" call MyOutput " ==== CurrentRecipe Data ==== " call MyOutput "ID: ${Refining.CurrentRecipe.ID}" call MyOutput "Name: ${Refining.CurrentRecipe.Name}" call MyOutput "Description: ${Refining.CurrentRecipe.Description}" call MyOutput "Stage1Name: ${Refining.CurrentRecipe.Stage1Name}" call MyOutput "Stage2Name: ${Refining.CurrentRecipe.Stage2Name}" call MyOutput "Stage3Name: ${Refining.CurrentRecipe.Stage3Name}" call MyOutput "Stage4Name: ${Refining.CurrentRecipe.Stage4Name}" call MyOutput "ActionPointsTotal: ${Refining.CurrentRecipe.ActionPointsTotal}" call MyOutput "ProgressBarPct: ${Refining.CurrentRecipe.ProgressBarPct}" call MyOutput "NumUses: ${Refining.CurrentRecipe.NumUses}" call MyOutput "IsWorkOrder: ${Refining.CurrentRecipe.IsWorkOrder}" call MyOutput "IsRefining: ${Refining.CurrentRecipe.IsRefining}" call MyOutput "IsFinishing: ${Refining.CurrentRecipe.IsFinishing}" call MyOutput "StepCount: ${Refining.CurrentRecipe.StepCount}" call MyOutput " ============================================================= " call MyOutput "Stage: ${Refining.Stage.Name}" call MyOutput "Stage: ${Refining.Stage.Index}" call MyOutput "Stage: ${Refining.Stage.StepCount}" call MyOutput " ============================================================= " variable int tstep = 1 tstep:Set[1] do { ;call MyOutput " ============================================================= " ;call MyOutput "Step ${tstep}:InStage.Name: ${Refining.CurrentRecipe.Step[${tstep}].InStage.Name}" ;call MyOutput "Step ${tstep}:InStage.Index: ${Refining.CurrentRecipe.Step[${tstep}].InStage.Index}" ;call MyOutput "Step ${tstep}:InStage.StepCount: ${Refining.CurrentRecipe.Step[${tstep}].InStage.StepCount}" call MyOutput "Step ${tstep}:Name: ${Refining.CurrentRecipe.Step[${tstep}].Name}" call MyOutput "Step ${tstep}:Description: ${Refining.CurrentRecipe.Step[${tstep}].Description}" call MyOutput "Step ${tstep}:AvailActionsCount: ${Refining.CurrentRecipe.Step[${tstep}].AvailActionsCount}" variable int substep = 1 substep:Set[1] do { call MyOutput "Step ${tstep}:AvailAction ${substep}:Name: ${Refining.CurrentRecipe.Step[${tstep}].AvailAction[${substep}].Name}" call MyOutput "Step ${tstep}:AvailAction ${substep}:ActionPointCost: ${Refining.CurrentRecipe.Step[${tstep}].AvailAction[${substep}].ActionPointCost}" call MyOutput "Step ${tstep}:AvailAction ${substep}:Description: ${Refining.CurrentRecipe.Step[${tstep}].AvailAction[${substep}].Description}" } while ( ${substep:Inc} <= ${Refining.CurrentRecipe.Step[${tstep}].AvailActionsCount} ) } while ( ${tstep:Inc} <= ${Refining.CurrentRecipe.StepCount} ) call MyOutput " ============================================================= " call MyOutput " ============= Dump Done ===================== " call MyOutput " ============================================================= " } } function SetOutputFile(string Filename) { ;OutputFile:Set[${Filename}] redirect "${OutputFile}" echo "============ ${Time} craft.iss Output started ==================" redirect -append "${OutputFile}" echo "=============================================" } function MyOutput(string Message) { ;echo "${Time}::${Message}" redirect -append "${OutputFile}" echo "${Time}::${Message}" } ;/* ;addtrigger damage "Your @Spell@ hits @Mob@ for @Damage@ damage" ;atom damage(string Line, string Spell, string Mob, int Damage) ;*/ function main() { declare OutputFile string script "${Script.CurrentDirectory}/craft-output.log" declare lasttarget string script "None" declare startXP int script startXP = 0 declare lastXP int script lastXP = 0 variable int tempXP = 0 declare startCraftXP int script startCraftXP = 0 variable int lastCraftXP = 0 ; If ISXEVG isn't loaded, then no reason to run this script. if (!${ISXVG(exists)}) { return } call SetOutputFile "${OutputFile}" ;Tell the user that the script has initialized and is running! VGEcho "Crafting Assistant started" > screen ; Get player data and log to output file: call MyOutput "=================================================" call MyOutput "Name: ${Me.FName}" call MyOutput "Class: ${Me.Class}" call MyOutput "Level: ${Me.Level}" call MyOutput "XP: ${Me.XP} XP%: ${Me.XPPct}" call MyOutput "=================================================" startXP:Set[${Me.CraftXP}] startCraftXP:Set[${Me.CraftXP}] lastCraftXP:Set[${Me.CraftXP}] ;Initialize/Attach the event Atoms that we defined previously Event[VG_OnIncomingText]:AttachAtom[VG_OnIncomingText] Event[VG_OnCraftingAlert]:AttachAtom[VG_OnCraftingAlert] ; This bit of scripting tells the script to "waitframe" over and ; over while ${ISXVG(exists)}. In other words, as long as the ; extension is loaded. do { ; Check what state of crafting we are in call CheckState if ${QueuedCommands} ProcessQueued else WaitFrame if (${lastCraftXP} < ${Me.CraftXP}) { tempXP:Set[${Me.CraftXP} - ${lastCraftXP}] lastCraftXP:Set[${Me.CraftXP}] VGEcho "You gained ${tempXP} Crafting XP" > screen } } while ${ISXVG(exists)} } function atexit() { ; If ISXEVG isn't loaded, then no reason to run this script. if (!${ISXVG(exists)}) { return } variable int totalXP=0 totalXP:Set[${Me.CraftXP} - ${startXP}] VGEcho "Total Crafting XP gained: ${totalXP}" > screen call MyOutput "=================================================" call MyOutput "CraftingLevel : ${Me.CraftingLevel}" call MyOutput "XP: ${Me.CraftXP} XP%: ${Me.CraftXPPct}" call MyOutput "Crafting XP gained: ${totalXP}" call MyOutput "=================================================" ;Remove the event listeners Event[VG_OnIncomingText]:DetachAtom[VG_OnIncomingText] Event[VG_OnCraftingAlert]:DetachAtom[VG_OnCraftingAlert] ;Send a final message telling the user that the script has ended VGEcho "Craft Assist has stopped" > screen }