Skip to content
Permalink
Browse files

Add a heal rate system

  • Loading branch information...
mcmonkey4eva committed Mar 28, 2016
1 parent 122afd9 commit b2d7734f4e5ae0bc86fd6d85559388e13ac0a33c
@@ -57,7 +57,7 @@ Created by mcmonkey4eva on behalf of the Citizens and Denizen teams.
- Commands:
- `/sentinel stats`
- `/sentinel guard PLAYERNAME`
- `/sentinel healrate RATE`
- `/sentinel forgive PLAYERNAME/all` forgives attackers
- Other:
- old Sentry saves importer?
- Maximum chase range
@@ -363,6 +363,22 @@ else if (arg0.equals("attackrate") && sender.hasPermission("sentinel.attackrate"
}
return true;
}
else if (arg0.equals("healrate") && sender.hasPermission("sentinel.healrate") && args.length > 1) {
try {
int d = Integer.valueOf(args[1]);
if (d >= 0 && d <= 2000) {
sentinel.healRate = d;
sender.sendMessage(prefixGood + "Heal rate set!");
}
else {
throw new NumberFormatException("Number out or range.");
}
}
catch (NumberFormatException ex) {
sender.sendMessage(prefixBad + "Invalid rate number!");
}
return true;
}
else if (arg0.equals("invincible") && sender.hasPermission("sentinel.invincible") && args.length > 1) {
sentinel.setInvincible(!sentinel.invincible);
if (sentinel.invincible) {
@@ -422,7 +438,8 @@ else if (arg0.equals("info") && sender.hasPermission("sentinel.info")) {
if (sender.hasPermission("sentinel.damage")) sender.sendMessage(prefixGood + "/sentinel damage DAMAGE - Sets the NPC's attack damage.");
if (sender.hasPermission("sentinel.armor")) sender.sendMessage(prefixGood + "/sentinel armor ARMOR - Sets the NPC's armor level.");
if (sender.hasPermission("sentinel.health")) sender.sendMessage(prefixGood + "/sentinel health HEALTH - Sets the NPC's health level.");
if (sender.hasPermission("sentinel.attackrate")) sender.sendMessage(prefixGood + "/sentinel attackrate RATE - Toggles the rate at which the NPC attacks, in ticks.");
if (sender.hasPermission("sentinel.attackrate")) sender.sendMessage(prefixGood + "/sentinel attackrate RATE - Changes the rate at which the NPC attacks, in ticks.");
if (sender.hasPermission("sentinel.healrate")) sender.sendMessage(prefixGood + "/sentinel healrate RATE - Changes the rate at which the NPC heals, in ticks.");
if (sender.hasPermission("sentinel.invincible")) sender.sendMessage(prefixGood + "/sentinel invincible - Toggles whether the NPC is invincible.");
if (sender.hasPermission("sentinel.fightback")) sender.sendMessage(prefixGood + "/sentinel fightback - Toggles whether the NPC will fight back.");
if (sender.hasPermission("sentinel.info")) sender.sendMessage(prefixGood + "/sentinel info - Shows info on the current NPC.");
@@ -111,6 +111,9 @@ public SentinelTrait() {
@Persist("attackRate")
public int attackRate = 30;

@Persist("healRate")
public int healRate = 30;

@EventHandler
public void whenWeAreAttacked(EntityDamageByEntityEvent event) {
if (!npc.isSpawned()) {
@@ -146,6 +149,8 @@ public void whenAnEnemyDies(EntityDeathEvent event) {
public void onAttach() {
FileConfiguration config = SentinelPlugin.instance.getConfig();
attackRate = config.getInt("sentinel defaults.attack rate", 30);
healRate
= config.getInt("sentinel defaults.heal rate", 30);
rangedChase = config.getBoolean("sentinel defaults.ranged chase target", false);
closeChase = config.getBoolean("sentinel defaults.close chase target", true);
armor = config.getDouble("sentinel defaults.armor", -1);
@@ -437,7 +442,7 @@ public boolean shouldTarget(LivingEntity entity) {
return isTargeted(entity) && !isIgnored(entity);
}

private HashSet<UUID> currentTargets = new HashSet<UUID>(); // TODO: Apology / cancel attack system! // TODO: stop attack when target dies!
private HashSet<UUID> currentTargets = new HashSet<UUID>(); // TODO: Apology / cancel attack system!

public boolean isRegexTargeted(String name, List<String> regexes) {
for (String str: regexes) {
@@ -556,9 +561,8 @@ private Entity getEntityForID(UUID id) {
public void runUpdate() {
timeSinceAttack += SentinelPlugin.instance.tickRate;
timeSinceHeal += SentinelPlugin.instance.tickRate;
// TODO: HealRate
if (timeSinceHeal > 20 && getLivingEntity().getHealth() < health) {
getLivingEntity().setHealth(getLivingEntity().getHealth() + 1);
if (healRate > 0 && timeSinceHeal > healRate && getLivingEntity().getHealth() < health) {
getLivingEntity().setHealth(Math.min(getLivingEntity().getHealth() + 1.0, health));
timeSinceHeal = 0;
}
for (UUID uuid : new HashSet<UUID>(currentTargets)) {
@@ -16,6 +16,8 @@ sentinel defaults:
invincible: false
# Attack rate, in ticks.
attack rate: 30
# Heal rate, in ticks.
heal rate: 30
# Whether this NPC fights back.
fightback: true

@@ -35,6 +35,8 @@ permissions:
sentinel.armor: true
# /sentinel attackrate RATE
sentinel.attackrate: true
# /sentinel healrate RATE
sentinel.healrate: true
# /sentinel invincible
sentinel.invincible: true
# /sentinel fightback

0 comments on commit b2d7734

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