Skip to content
Permalink
Browse files

Bugs, updates, readme patch, snowball item, fixes #47

  • Loading branch information...
mcmonkey4eva committed Jul 15, 2016
1 parent dc13dd3 commit d525e1b907ca067bfaeb98ec4a31d9362c7a401c
@@ -101,6 +101,7 @@ These are all valid targets and ignores:
- Spectral arrow (makes the target glow, without damaging it.)
- (To make a target glow ++ damage it, equip a bow + arm it with spectral arrows!)
- Respawning can be set to "-1" to cause the NPC to delete itself on death, or "0" to prevent respawn.
- Sentinels will guard a point or path if either is set using the command "`/npc path`"

### Need help using Sentinel? Try one of these places:

@@ -14,7 +14,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<craftbukkit.version>1.10-R0.1-SNAPSHOT</craftbukkit.version>
<citizens.version>2.0.19-SNAPSHOT</citizens.version>
<citizens.version>2.0.20-SNAPSHOT</citizens.version>
<sentry.version>1.9.0</sentry.version>
<BUILD_NUMBER>Unknown</BUILD_NUMBER>
</properties>
@@ -783,6 +783,7 @@ else if (arg0.equals("stats") && sender.hasPermission("sentinel.info")) {
sender.sendMessage(prefixGood + "Arrows fired: " + ChatColor.AQUA + sentinel.stats_arrowsFired);
sender.sendMessage(prefixGood + "Potions thrown: " + ChatColor.AQUA + sentinel.stats_potionsThrown);
sender.sendMessage(prefixGood + "Fireballs launched: " + ChatColor.AQUA + sentinel.stats_fireballsFired);
sender.sendMessage(prefixGood + "Snowballs thrown: " + ChatColor.AQUA + sentinel.stats_snowballsThrown);
sender.sendMessage(prefixGood + "Punches: " + ChatColor.AQUA + sentinel.stats_punches);
sender.sendMessage(prefixGood + "Times spawned: " + ChatColor.AQUA + sentinel.stats_timesSpawned);
sender.sendMessage(prefixGood + "Damage Given: " + ChatColor.AQUA + sentinel.stats_damageGiven);
@@ -4,12 +4,10 @@
import net.citizensnpcs.api.ai.TargetType;
import net.citizensnpcs.api.ai.TeleportStuckAction;
import net.citizensnpcs.api.ai.speech.SpeechContext;
import net.citizensnpcs.api.ai.speech.VocalChord;
import net.citizensnpcs.api.persistence.Persist;
import net.citizensnpcs.api.trait.Trait;
import net.citizensnpcs.api.trait.trait.Inventory;
import net.citizensnpcs.api.trait.trait.Owner;
import net.citizensnpcs.npc.ai.speech.CitizensSpeechFactory;
import net.citizensnpcs.trait.waypoint.Waypoint;
import net.citizensnpcs.trait.waypoint.WaypointProvider;
import net.citizensnpcs.trait.waypoint.Waypoints;
@@ -70,6 +68,9 @@ public SentinelTrait() {
@Persist("stats_fireballsFired")
public long stats_fireballsFired = 0;

@Persist("stats_snowballsThrown")
public long stats_snowballsThrown = 0;

@Persist("stats_punches")
public long stats_punches = 0;

@@ -424,11 +425,20 @@ public void fireArrow(ItemStack type, Location target, Vector lead) {
}
}
arrow.setVelocity(start.getValue());
// TODO: Apply damage amount!
// TODO: Prevent pick up if needed!
useItem();
}

public void fireSnowball(Location target) {
swingWeapon();
stats_snowballsThrown++;
npc.faceLocation(target);
Vector forward = getLivingEntity().getEyeLocation().getDirection();
Location spawnAt = getLivingEntity().getEyeLocation().clone().add(forward.clone().multiply(2));
Entity ent = spawnAt.getWorld().spawnEntity(spawnAt, EntityType.SNOWBALL);
ent.setVelocity(target.clone().subtract(spawnAt).toVector().normalize().multiply(2.5)); // TODO: Fiddle with '2.5'.
}

public void fireFireball(Location target) {
swingWeapon();
stats_fireballsFired++;
@@ -437,7 +447,6 @@ public void fireFireball(Location target) {
Location spawnAt = getLivingEntity().getEyeLocation().clone().add(forward.clone().multiply(2));
Entity ent = spawnAt.getWorld().spawnEntity(spawnAt, EntityType.SMALL_FIREBALL);
ent.setVelocity(target.clone().subtract(spawnAt).toVector().normalize().multiply(4)); // TODO: Fiddle with '4'.
// TODO: Apply damage amount!
}

public double getDamage() {
@@ -623,24 +632,51 @@ public void takeArrow() {
}
Inventory inv = npc.getTrait(Inventory.class);
ItemStack[] items = inv.getContents();
for (int i = 0; i < items.length; i++) {
ItemStack item = items[i];
if (item != null) {
Material mat = item.getType();
if (mat == Material.ARROW || mat == Material.TIPPED_ARROW || mat == Material.SPECTRAL_ARROW) {
if (item.getAmount() > 1) {
item.setAmount(item.getAmount() - 1);
items[i] = item;
inv.setContents(items);
return;
}
else {
items[i] = null;
inv.setContents(items);
return;
}
for (int i = 0; i < items.length; i++) {
ItemStack item = items[i];
if (item != null) {
Material mat = item.getType();
if (mat == Material.ARROW || mat == Material.TIPPED_ARROW || mat == Material.SPECTRAL_ARROW) {
if (item.getAmount() > 1) {
item.setAmount(item.getAmount() - 1);
items[i] = item;
inv.setContents(items);
return;
}
else {
items[i] = null;
inv.setContents(items);
return;
}
}
}
}
}

public void takeSnowball() {
if (!npc.hasTrait(Inventory.class)) {
return;
}
Inventory inv = npc.getTrait(Inventory.class);
ItemStack[] items = inv.getContents();
for (int i = 0; i < items.length; i++) {
ItemStack item = items[i];
if (item != null) {
Material mat = item.getType();
if (mat == Material.SNOW_BALL) {
if (item.getAmount() > 1) {
item.setAmount(item.getAmount() - 1);
items[i] = item;
inv.setContents(items);
return;
}
else {
items[i] = null;
inv.setContents(items);
return;
}
}
}
}
}

@@ -671,7 +707,7 @@ public void grabNextItem() {
ItemStack item = items[i];
if (item != null) {
Material mat = item.getType();
if (mat == Material.SPLASH_POTION || mat == Material.LINGERING_POTION
if (mat == Material.SPLASH_POTION || mat == Material.LINGERING_POTION || mat == Material.SNOW_BALL
|| mat == Material.BOW || mat == Material.NETHER_STAR || mat == Material.BLAZE_ROD) {
if (item.getAmount() > 1) {
item.setAmount(item.getAmount() - 1);
@@ -700,6 +736,7 @@ public void rechase() {
}

public void tryAttack(LivingEntity entity) {
// TODO: Simplify this code!
stats_attackAttempts++;
if (usesBow()) {
if (canSee(entity)) {
@@ -724,6 +761,28 @@ else if (rangedChase) {
chase(entity);
}
}
else if (usesSnowball()) {
if (canSee(entity)) {
if (timeSinceAttack < attackRate) {
if (rangedChase) {
rechase();
}
return;
}
timeSinceAttack = 0;
ItemStack item = getArrow();
if (item != null) {
fireSnowball(entity.getEyeLocation());
if (needsAmmo) {
takeSnowball();
grabNextItem();
}
}
}
else if (rangedChase) {
chase(entity);
}
}
else if (usesPotion()) {
if (canSee(entity)) {
if (timeSinceAttack < attackRate) {
@@ -847,7 +906,12 @@ public LivingEntity getLivingEntity() {
}

public boolean isRanged() {
return usesBow() || usesFireball();
return usesBow()
|| usesFireball()
|| usesSnowball()
|| usesLightning()
|| usesSpectral()
|| usesPotion();
}

public boolean usesBow() {
@@ -858,6 +922,10 @@ public boolean usesFireball() {
return getLivingEntity().getEquipment().getItemInMainHand().getType() == Material.BLAZE_ROD;
}

public boolean usesSnowball() {
return getLivingEntity().getEquipment().getItemInMainHand().getType() == Material.SNOW_BALL;
}

public boolean usesLightning() {
return getLivingEntity().getEquipment().getItemInMainHand().getType() == Material.NETHER_STAR;
}
@@ -1033,8 +1101,10 @@ private void updateTargets() {
Entity e = getEntityForID(uuid.targetID);
if (e == null) {
currentTargets.remove(uuid);
continue;
}
else if (e.getLocation().distanceSquared(getLivingEntity().getLocation()) > range * range * 4) {
double d = e.getLocation().distanceSquared(getLivingEntity().getLocation());
if (d > range * range * 4 && d > chaseRange * chaseRange * 4) {
currentTargets.remove(uuid);
}
else if (uuid.ticksLeft > 0) {

0 comments on commit d525e1b

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