Added run path action & wired up test button

This commit is contained in:
Malcolm Roberts 2024-01-15 20:59:26 -06:00
parent e065094616
commit fde5095f11
5 changed files with 61 additions and 9 deletions

View File

@ -2,6 +2,7 @@
#define _mr_auto_quest_actions_ #define _mr_auto_quest_actions_
#include "${LavishScript.HomeDirectory}/Scripts/mr/auto_quest/actions/npc_dialog_action.iss" #include "${LavishScript.HomeDirectory}/Scripts/mr/auto_quest/actions/npc_dialog_action.iss"
#include "${LavishScript.HomeDirectory}/Scripts/mr/auto_quest/actions/run_path_action.iss"
function RunAction(string actionType, jsonvalue params) function RunAction(string actionType, jsonvalue params)
{ {
@ -9,6 +10,10 @@ function RunAction(string actionType, jsonvalue params)
{ {
call npc_dialog_action params call npc_dialog_action params
} }
if ${actionType.Equal["run_path"]}
{
call run_path_action params
}
} }
#endif #endif

View File

@ -0,0 +1,33 @@
#includeoptional "${LavishScript.HomeDirectory}/Scripts/mr/common/api.iss"
variable(global) MRBotApi MRApi
function run_path_action(jsonvalueref params)
{
variable jsoniterator pathIterator
params.Get["path"]:GetIterator[pathIterator]
if !${MRApi(exists)}
{
echo "MRApi not available"
}
if !${MRNav(exists)}
{
echo "MRNav not available"
}
if ${pathIterator:First(exists)}
{
variable point3f nextLocation
do
{
nextLocation:Set[${pathIterator.Value.Get[x]},${pathIterator.Value.Get[y]},${pathIterator.Value.Get[z]}]
call MRApi.MoveTo "${Me.Name}" "${nextLocation}" 1
call MRApi.WaitForMoveTo "${Me.Name}" "${nextLocation}" 1
}
while ${pathIterator:Next(exists)}
}
}

View File

@ -100,6 +100,8 @@ objectdef QuestWriterController
{ {
variable jsonvalue step variable jsonvalue step
step:SetValue["${Context.Source.Metadata.Get["step"].AsJSON~}"] step:SetValue["${Context.Source.Metadata.Get["step"].AsJSON~}"]
echo "Testing step ${step.Get["params"].AsJSON~}"
QueueCommand call RunAction ${step.Get["type"]} "${step.Get["params"].AsJSON~}" QueueCommand call RunAction ${step.Get["type"]} "${step.Get["params"].AsJSON~}"
} }

View File

@ -6,7 +6,7 @@ objectdef RelayApi
variable point3f location variable point3f location
location:Set[${Context.Get["parameters", "location", "X"]}, ${Context.Get["parameters", "location", "Y"]}, ${Context.Get["parameters", "location", "Z"]}] location:Set[${Context.Get["parameters", "location", "X"]}, ${Context.Get["parameters", "location", "Y"]}, ${Context.Get["parameters", "location", "Z"]}]
MRApi:MoveTo["${Context.Get["parameters","ForWho"]}", "${location}", ${Context.Get["parameters", "minDistance"]}] ;MRApi:MoveTo["${Context.Get["parameters","ForWho"]}", "${location}", ${Context.Get["parameters", "minDistance"]}]
} }
} }

View File

@ -1,12 +1,15 @@
#ifndef _mr_api_ #ifndef _mr_api_
#define _mr_api_ #define _mr_api_
objectdef MRApi objectdef MRBotApi
{ {
static member:bool IsForMe(string forWhoTarget) variable string test = "test MRAPI";
member:bool IsForMe(string forWhoTarget)
{ {
variable string target = ${forWhoTarget}; variable string target = ${forWhoTarget}
variable string prefix = ${forWhoTarget.Token[1, ":"]}; variable string prefix = ${forWhoTarget.Token[1, ":"]}
variable bool negate = FALSE; variable bool negate = FALSE
echo "IsForMe ${forWhoTarget} ${prefix} ${target}"
if ${target.Count[":"]} > 0 if ${target.Count[":"]} > 0
@ -62,19 +65,28 @@ objectdef MRApi
return ${negate} return ${negate}
} }
static method MoveTo(string forWho, point3f location, float minDistance = 0) function MoveTo(string forWho, point3f location, float minDistance = 0)
{ {
echo "Moving to ${location}" echo "Moving to ${location}"
if ${MRApi.IsForMe[${forWho}]} if ${This.IsForMe["${forWho}"]}
{ {
MRNav:MoveTo["${location}"] MRNav:MoveTo["${location}"]
} }
else else
{ {
echo "NotForMe" echo "${forWho} NotForMe"
} }
} }
function WaitForMoveTo(string forWho, point3f location, float minDistance = 0)
{
echo "Waiting for move to ${location}"
while ${Math.Distance[${Me.X},${Me.Y},${Me.Z},${location.X},${location.Y},${location.Z}]} > ${minDistance}
{
echo "waiting for path to complete ${Math.Distance[${Me.X},${Me.Y},${Me.Z},${location.X},${location.Y},${location.Z}]}"
wait 5
}
}
} }