public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
// Get objects
Action action = (Action) scriptEntry.getObject("action");
dLocation location = (dLocation) scriptEntry.getObject("location");
Element range = (Element) scriptEntry.getObject("range");
Element id = (Element) scriptEntry.getObject("id");
// Report to dB
dB.report(scriptEntry, getName(),
aH.debugObj("NPC", ((BukkitScriptEntryData)scriptEntry.entryData).getNPC().toString())
+ action.name() + id.debug()
+ (location != null ? location.debug() : "")
+ (range != null ? range.debug() : "" ));
dNPC npc = ((BukkitScriptEntryData)scriptEntry.entryData).getNPC();
if (!npc.getCitizen().hasTrait(Anchors.class))
npc.getCitizen().addTrait(Anchors.class);
switch (action) {
case ADD:
npc.getCitizen().getTrait(Anchors.class).addAnchor(id.asString(), location);
return;
case ASSUME:
{
Anchor n = npc.getCitizen().getTrait(Anchors.class)
.getAnchor(id.asString());
if (n == null)
dB.echoError(scriptEntry.getResidingQueue(), "Invalid anchor name '" + id.asString() + "'");
else
npc.getEntity().teleport(n.getLocation());
}
return;
case WALKNEAR:
{
Anchor n = npc.getCitizen().getTrait(Anchors.class)
.getAnchor(id.asString());
if (n == null)
dB.echoError(scriptEntry.getResidingQueue(), "Invalid anchor name '" + id.asString() + "'");
else if (range == null)
dB.echoError(scriptEntry.getResidingQueue(), "Must specify a range!");
else
npc.getNavigator().setTarget(
Utilities.getWalkableLocationNear(n.getLocation(), range.asInt()));
}
return;
case WALKTO:
{
Anchor n = npc.getCitizen().getTrait(Anchors.class)
.getAnchor(id.asString());
if (n == null)
dB.echoError(scriptEntry.getResidingQueue(), "Invalid anchor name '" + id.asString() + "'");
else
npc.getNavigator().setTarget(n.getLocation());
}
return;
case REMOVE:
{
Anchor n = npc.getCitizen().getTrait(Anchors.class)
.getAnchor(id.asString());
if (n == null)
dB.echoError(scriptEntry.getResidingQueue(), "Invalid anchor name '" + id.asString() + "'");
else
npc.getCitizen().getTrait(Anchors.class).removeAnchor(n);
}
}