Skip to content

Commit

Permalink
add a per-weapon-damage command, fixes #125
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Oct 3, 2019
1 parent cd64082 commit 4bd5f42
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 10 deletions.
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -114,14 +114,15 @@ Sentinel is integrated into by external plugins as well, including:
- /sentinel avoidrange RANGE - Sets the distance to try to keep from threats.
- /sentinel range RANGE - Sets the NPC's maximum attack range.
- /sentinel damage DAMAGE - Sets the NPC's attack damage.
- /sentinel weapondamage MATERIAL DAMAGE - Sets the NPC's attack damage for a specific weapon material.
- /sentinel armor ARMOR - Sets the NPC's armor level.
- /sentinel health HEALTH - Sets the NPC's health level.
- /sentinel attackrate RATE ['ranged'] - Changes the rate at which the NPC attacks, in seconds. Either ranged or close modes.
- /sentinel healrate RATE - Changes the rate at which the NPC heals, in seconds.
- /sentinel respawntime TIME - Changes the time it takes for the NPC to respawn, in seconds.
- /sentinel chaserange RANGE - Changes the maximum distance an NPC will run before returning to base.
- /sentinel drops - Changes the drops of the current NPC.
- /sentinel dropchance [ID] [CHANCE] - Changes the chance of a drop. Use "/sentinel dropchance" to see the drops list with IDs, then do like "/sentinel dropchance 3 50" (that puts a 50% chance on item with ID 3).
- /sentinel dropchance ID CHANCE - Changes the chance of a drop. Use "/sentinel dropchance" to see the drops list with IDs, then do like "/sentinel dropchance 3 50" (that puts a 50% chance on item with ID 3).
- /sentinel targettime TIME - Sets the NPC's enemy target time limit in seconds.
- /sentinel speed SPEED - Sets the NPC's movement speed modifier.
- /sentinel guarddistance MINIMUM_DISTANCE [SELECTION_RANGE] - Sets the NPC's minimum guard distance (how far you must go before the NPC moves to keep up) and selection range (how close it will try to get to you).
Expand Down
19 changes: 16 additions & 3 deletions src/main/java/org/mcmonkey/sentinel/SentinelTrait.java
Expand Up @@ -478,6 +478,12 @@ public void save(SentinelTargetList o, DataKey dataKey) {
@Persist("guard_selection_range")
public double guardSelectionRange = 4;

/**
* Map of weapon material names to custom damage amount.
*/
@Persist("weapon_damage_map")
public HashMap<String, Double> weaponDamage = new HashMap<>();

/**
* The target entity this NPC is chasing (if any).
*/
Expand Down Expand Up @@ -909,13 +915,20 @@ public void faceLocation(Location l) {
* Gets the NPC's current damage value (based on held weapon if calculation is required).
*/
public double getDamage() {
if (damage >= 0) {
return damage;
}
ItemStack weapon = itemHelper.getHeldItem();
if (weapon == null) {
if (damage >= 0) {
return damage;
}
return 1;
}
Double customDamage = weaponDamage.get(weapon.getType().name().toLowerCase());
if (customDamage != null) {
return customDamage;
}
if (damage >= 0) {
return damage;
}
// TODO: Less randomness, more game-like calculations.
double multiplier = 1;
multiplier += weapon.getItemMeta() == null || !weapon.getItemMeta().hasEnchant(Enchantment.DAMAGE_ALL)
Expand Down
Expand Up @@ -4,6 +4,7 @@
import net.citizensnpcs.api.command.CommandContext;
import net.citizensnpcs.api.command.Requirements;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.CommandSender;
import org.mcmonkey.sentinel.SentinelPlugin;
import org.mcmonkey.sentinel.SentinelTrait;
Expand Down Expand Up @@ -41,7 +42,7 @@ public void accuracy(CommandContext args, CommandSender sender, SentinelTrait se
return;
}
try {
double d = Double.parseDouble(args.getString(1));
double d = args.getDouble(1);
if (d >= 0 && d <= 10) {
sentinel.accuracy = d;
sender.sendMessage(SentinelCommand.prefixGood + "Accuracy offset set!");
Expand All @@ -65,7 +66,7 @@ public void reach(CommandContext args, CommandSender sender, SentinelTrait senti
return;
}
try {
double d = Double.parseDouble(args.getString(1));
double d = args.getDouble(1);
if (d >= 0) {
sentinel.reach = d;
sender.sendMessage(SentinelCommand.prefixGood + "Reach set!");
Expand All @@ -90,7 +91,7 @@ public void attackRate(CommandContext args, CommandSender sender, SentinelTrait
return;
}
try {
double da = Double.parseDouble(args.getString(1));
double da = args.getDouble(1);
int d = (int) (da * 20);
if (d >= SentinelPlugin.instance.tickRate && d <= SentinelTrait.attackRateMax) {
if (args.argsLength() > 2 && args.getString(2).toLowerCase().contains("ranged")) {
Expand Down Expand Up @@ -121,7 +122,7 @@ public void range(CommandContext args, CommandSender sender, SentinelTrait senti
return;
}
try {
double d = Double.parseDouble(args.getString(1));
double d = args.getDouble(1);
if (d > 0 && d < 200) {
sentinel.range = d;
sender.sendMessage(SentinelCommand.prefixGood + "Range set!");
Expand All @@ -146,7 +147,7 @@ public void damage(CommandContext args, CommandSender sender, SentinelTrait sent
return;
}
try {
Double d = Double.parseDouble(args.getString(1));
double d = args.getDouble(1);
if (d < SentinelPlugin.instance.maxHealth) {
sentinel.damage = d;
sender.sendMessage(SentinelCommand.prefixGood + "Damage set!");
Expand All @@ -160,6 +161,45 @@ public void damage(CommandContext args, CommandSender sender, SentinelTrait sent
}
}

@Command(aliases = {"sentinel"}, usage = "weapondamage MATERIAL DAMAGE",
desc = "Sets the NPC's attack damage for a specific weapon material.",
modifiers = {"weapondamage"}, permission = "sentinel.weapondamage", min = 2, max = 3)
@Requirements(livingEntity = true, ownership = true, traits = {SentinelTrait.class})
public void weaponDamage(CommandContext args, CommandSender sender, SentinelTrait sentinel) {
String weapon = args.getString(1).toLowerCase();
try {
Material.valueOf(weapon.toUpperCase());
}
catch (IllegalArgumentException ex) {
sender.sendMessage(SentinelCommand.prefixBad + "Invalid weapon material (name misspelled?)");
return;
}
if (args.argsLength() <= 2) {
Double damage = sentinel.weaponDamage.get(weapon);
sender.sendMessage(SentinelCommand.prefixGood + "Current weapon damage for '" + weapon + "': " + ChatColor.AQUA + (damage == null ? "Unset" : damage));
return;
}
try {
double d = args.getDouble(2);
if (d < SentinelPlugin.instance.maxHealth) {
if (d < 0) {
sentinel.weaponDamage.remove(weapon);
sender.sendMessage(SentinelCommand.prefixGood + "Weapon damage removed!");
}
else {
sentinel.weaponDamage.put(weapon, d);
sender.sendMessage(SentinelCommand.prefixGood + "Weapon damage set!");
}
}
else {
throw new NumberFormatException("Number out of range (must be < " + SentinelPlugin.instance.maxHealth + ").");
}
}
catch (NumberFormatException ex) {
sender.sendMessage(SentinelCommand.prefixBad + "Invalid weapon damage number: " + ex.getMessage());
}
}

@Command(aliases = {"sentinel"}, usage = "safeshot ['true'/'false']",
desc = "Toggles whether the NPC will avoid damaging non-targets.",
modifiers = {"safeshot"}, permission = "sentinel.safeshot", min = 1, max = 2)
Expand Down
Expand Up @@ -188,7 +188,7 @@ public void drops(CommandContext args, CommandSender sender, SentinelTrait senti
((Player) sender).openInventory(inv);
}

@Command(aliases = {"sentinel"}, usage = "dropchance [ID] [CHANCE]",
@Command(aliases = {"sentinel"}, usage = "dropchance ID CHANCE",
desc = "Changes the chance of a drop.",
modifiers = {"dropchance"}, permission = "sentinel.drops", min = 1, max = 3)
@Requirements(livingEntity = true, ownership = true, traits = {SentinelTrait.class})
Expand Down
Expand Up @@ -69,6 +69,7 @@ else if (sentinel.getGuarding() != null) {
paginator.addLine(SentinelCommand.prefixGood + "Realistic Targeting Enabled: " + ChatColor.AQUA + sentinel.realistic);
paginator.addLine(SentinelCommand.prefixGood + "Run-Away Enabled: " + ChatColor.AQUA + sentinel.runaway);
paginator.addLine(SentinelCommand.prefixGood + "Squad: " + ChatColor.AQUA + (sentinel.squad == null ? "None" : sentinel.squad));
paginator.addLine(SentinelCommand.prefixGood + "Per-weapon damage values: " + ChatColor.AQUA + sentinel.weaponDamage.toString());
int page = 1;
if (args.argsLength() == 2) {
try {
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/plugin.yml
Expand Up @@ -36,6 +36,8 @@ permissions:
sentinel.range: true
# /sentinel damage DAMAGE
sentinel.damage: true
# /sentinel weapondamage MATERIAL DAMAGE
sentinel.weapondamage: true
# /sentinel health HEALTH
sentinel.health: true
# /sentinel armor ARMOR
Expand Down

0 comments on commit 4bd5f42

Please sign in to comment.