Skip to content
Permalink
Browse files

[Incomplete] speed modifier for #36

  • Loading branch information...
mcmonkey4eva committed Jun 27, 2016
1 parent b0b3a7b commit 05fe5f51f16131d2e769e3d12ee8016ac82309f8
@@ -63,6 +63,8 @@ Created by mcmonkey4eva on behalf of the Citizens and Denizen teams.
- /sentinel targets - Shows the targets of the current NPC.
- /sentinel kill - Kills the NPC.
- /sentinel respawn - Respawns the NPC.
- /sentinel targettime TIME - Sets the NPC's enemy target time limit.
- /sentinel speed - Sets the NPC's speed modifier.
- /sentinel targettime TIME - Sets the NPCs enemy target time limit.

### Sentry user?
@@ -453,6 +453,22 @@ else if (arg0.equals("damage") && sender.hasPermission("sentinel.damage") && arg
}
return true;
}
else if (arg0.equals("speed") && sender.hasPermission("sentinel.speed") && args.length > 1) {
try {
Double d = Double.valueOf(args[1]);
if (d < 1000 && d >= 0) {
sentinel.speed = d;
sender.sendMessage(prefixGood + "Speed set!");
}
else {
throw new NumberFormatException("Number out or range.");
}
}
catch (NumberFormatException ex) {
sender.sendMessage(prefixBad + "Invalid speed number!");
}
return true;
}
else if (arg0.equals("armor") && sender.hasPermission("sentinel.armor") && args.length > 1) {
try {
Double d = Double.valueOf(args[1]);
@@ -775,7 +791,8 @@ else if (arg0.equals("stats") && sender.hasPermission("sentinel.info")) {
if (sender.hasPermission("sentinel.enemydrops")) sender.sendMessage(prefixGood + "/sentinel enemydrops - Toggles whether enemy mobs of this NPC drop items.");
if (sender.hasPermission("sentinel.kill")) sender.sendMessage(prefixGood + "/sentinel kill - Kills the NPC.");
if (sender.hasPermission("sentinel.respawn")) sender.sendMessage(prefixGood + "/sentinel respawn - Respawns the NPC.");
if (sender.hasPermission("sentinel.targettime")) sender.sendMessage(prefixGood + "/sentinel targettime TIME - Sets the NPCs enemy target time limit.");
if (sender.hasPermission("sentinel.targettime")) sender.sendMessage(prefixGood + "/sentinel targettime TIME - Sets the NPC's enemy target time limit.");
if (sender.hasPermission("sentinel.speed")) sender.sendMessage(prefixGood + "/sentinel speed SPEED - Sets the NPC's speed modifier.");
if (sender.hasPermission("sentinel.info")) sender.sendMessage(prefixGood + "/sentinel info - Shows info on the current NPC.");
if (sender.hasPermission("sentinel.info")) sender.sendMessage(prefixGood + "/sentinel targets - Shows the targets of the current NPC.");
if (sender.hasPermission("sentinel.info")) sender.sendMessage(prefixGood + "/sentinel stats - Shows statistics about the current NPC.");
@@ -177,6 +177,9 @@ public SentinelTrait() {
@Persist("enemyTargetTime")
public long enemyTargetTime = 0;

@Persist("speed")
public double speed = 1;

public LivingEntity chasing = null;

public UUID getGuarding() {
@@ -344,28 +347,28 @@ public void swingWeapon() {
}

public HashMap.SimpleEntry<Location, Vector> getLaunchDetail(Location target, Vector lead) {
double speed;
double speeda;
npc.faceLocation(target);
double angt = -1;
Location start = getLivingEntity().getEyeLocation().clone().add(getLivingEntity().getEyeLocation().getDirection());
for (speed = 20; speed <= 45; speed += 5) {
angt = SentinelUtilities.getArrowAngle(start, target, speed, 20);
for (speeda = 20; speeda <= 45; speeda += 5) {
angt = SentinelUtilities.getArrowAngle(start, target, speeda, 20);
if (!Double.isInfinite(angt)) {
break;
}
}
if (Double.isInfinite(angt)) {
return null;
}
double hangT = SentinelUtilities.hangtime(angt, speed, target.getY() - start.getY(), 20);
double hangT = SentinelUtilities.hangtime(angt, speeda, target.getY() - start.getY(), 20);
Location to = target.clone().add(lead.clone().multiply(hangT));
Vector relative = to.clone().subtract(start.toVector()).toVector();
double deltaXZ = Math.sqrt(relative.getX() * relative.getX() + relative.getZ() * relative.getZ());
if (deltaXZ == 0) {
deltaXZ = 0.1;
}
for (speed = 20; speed < 45; speed += 5) {
angt = SentinelUtilities.getArrowAngle(start, to, speed, 20);
for (speeda = 20; speeda < 45; speeda += 5) {
angt = SentinelUtilities.getArrowAngle(start, to, speeda, 20);
if (!Double.isInfinite(angt)) {
break;
}
@@ -376,8 +379,8 @@ public void swingWeapon() {
relative.setY(Math.tan(angt) * deltaXZ);
relative = relative.normalize();
Vector normrel = relative.clone();
speed = speed + (1.188 * hangT * hangT);
relative = relative.multiply(speed / 20.0);
speeda = speeda + (1.188 * hangT * hangT);
relative = relative.multiply(speeda / 20.0);
start.setDirection(normrel);
return new HashMap.SimpleEntry<Location, Vector>(start, relative);
}
@@ -565,6 +568,7 @@ public void chase(LivingEntity entity) {
}
chasing = entity;
npc.getNavigator().getDefaultParameters().stuckAction(null);
npc.getNavigator().getLocalParameters().speedModifier((float)speed);
npc.getNavigator().setTarget(entity.getLocation());
}

@@ -1054,13 +1058,16 @@ public void runUpdate() {
if (dist > 7 * 7) {
npc.getNavigator().getDefaultParameters().range(100);
npc.getNavigator().getDefaultParameters().stuckAction(TeleportStuckAction.INSTANCE);
npc.getNavigator().getLocalParameters().speedModifier((float)speed);
npc.getNavigator().setTarget(player.getLocation());
}
}
}
else if (chaseRange > 0) {
Location near = nearestPathPoint();
if (near != null && near.distanceSquared(getLivingEntity().getLocation()) > chaseRange * chaseRange) {
npc.getNavigator().getDefaultParameters().stuckAction(TeleportStuckAction.INSTANCE);
npc.getNavigator().getLocalParameters().speedModifier((float)speed);
npc.getNavigator().setTarget(near);
}
}
@@ -30,6 +30,8 @@ sentinel defaults:
enemy drops: false
# How long to target temporary enemies for, in ticks. 0 means never-forget.
enemy target time: 0
# What speed should be used, as a multiple of the default speed.
speed: 0

random:
# What sound to play when the "spectral" attack is used.
@@ -70,6 +70,8 @@ permissions:
sentinel.sentryimport: true
# /sentinel targettime TIME
sentinel.targettime: true
# /sentinel speed SPEED
sentinel.speed: true
# /sentinel info, /sentinel targets, /sentinel stats
sentinel.info: true
# Edit other people's NPCs

0 comments on commit 05fe5f5

Please sign in to comment.
You can’t perform that action at this time.