Merge pull request #146 from acstache/bleeding

Implement boss health using the Bukkit Max Health API, and remove health-multiplier limitation of "0 < limit <= 1".
This commit is contained in:
garbagemule
2013-01-05 05:51:04 -08:00
4 changed files with 14 additions and 72 deletions
+1 -1
View File
@@ -1,7 +1,7 @@
name: MobArena name: MobArena
author: garbagemule author: garbagemule
main: com.garbagemule.MobArena.MobArena main: com.garbagemule.MobArena.MobArena
version: 0.94.4.91 version: 0.94.4.93
softdepend: [Spout,MultiVerse,MultiWorld,XcraftGate,Towny,Heroes,MagicSpells,Vault] softdepend: [Spout,MultiVerse,MultiWorld,XcraftGate,Towny,Heroes,MagicSpells,Vault]
commands: commands:
ma: ma:
@@ -480,9 +480,6 @@ public class ArenaListener
if (damager instanceof Projectile) { if (damager instanceof Projectile) {
damager = ((Projectile) damager).getShooter(); damager = ((Projectile) damager).getShooter();
} }
else if (damager instanceof Wolf && arena.hasPet(damager)) {
damager = (Player) ((Wolf) damager).getOwner();
}
} }
// Pet wolf // Pet wolf
@@ -499,7 +496,7 @@ public class ArenaListener
} }
// Boss // Boss
else if (monsters.getBossMonsters().contains(damagee)) { else if (monsters.getBossMonsters().contains(damagee)) {
onBossDamage(event, (LivingEntity) damagee, damager); onBossDamage(event, (LivingEntity) damagee, damager); // Now an emtpy method
} }
// Regular monster // Regular monster
else if (monsters.getMonsters().contains(damagee)) { else if (monsters.getMonsters().contains(damagee)) {
@@ -519,7 +516,7 @@ public class ArenaListener
} }
// If PvP is disabled and damager is a player, cancel damage // If PvP is disabled and damager is a player, cancel damage
else if (arena.inArena(player)) { else if (arena.inArena(player)) {
if (!pvpEnabled && damager instanceof Player) { if (!pvpEnabled && (damager instanceof Player || damager instanceof Wolf)) {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
@@ -545,12 +542,12 @@ public class ArenaListener
aps.inc("hits"); aps.inc("hits");
} }
else if (damager instanceof Wolf && arena.hasPet(damager)) { else if (damager instanceof Wolf && arena.hasPet(damager)) {
event.setDamage(1); //event.setDamage(1);
Player p = (Player) ((Wolf) damager).getOwner(); Player p = (Player) ((Wolf) damager).getOwner();
ArenaPlayerStatistics aps = arena.getArenaPlayer(p).getStats(); ArenaPlayerStatistics aps = arena.getArenaPlayer(p).getStats();
aps.add("dmgDone", event.getDamage()); aps.add("dmgDone", event.getDamage());
// arena.getArenaPlayer(p).getStats().dmgDone += event.getDamage();
} }
//TODO add in check for player made golems doing damage
else if (damager instanceof LivingEntity) { else if (damager instanceof LivingEntity) {
if (!monsterInfight) if (!monsterInfight)
event.setCancelled(true); event.setCancelled(true);
@@ -573,21 +570,7 @@ public class ArenaListener
} }
private void onBossDamage(EntityDamageEvent event, LivingEntity monster, Entity damager) { private void onBossDamage(EntityDamageEvent event, LivingEntity monster, Entity damager) {
// Health the boss back up. //TODO useless method as of Entity Max Health API, maybe add in some stat tracking for leaderboards instead?
monster.setHealth(monster.getMaxHealth());
// Damage the underlying MABoss.
MABoss boss = monsters.getBoss(monster);
boss.damage(event.getDamage());
// If it died, remove it from the arena.
if (boss.isDead()) {
monsters.removeBoss(monster);
monster.damage(10000);
}
// And "cancel out" the damage.
event.setDamage(1);
} }
public void onEntityCombust(EntityCombustEvent event) { public void onEntityCombust(EntityCombustEvent event) {
@@ -156,8 +156,10 @@ public class MASpawnThread implements Runnable
monsterManager.addMonster(e); monsterManager.addMonster(e);
// Set the health. // Set the health.
e.resetMaxHealth(); // Avoid conflicts/enormous multiplications from other plugins handling Mob health
int health = (int) Math.max(1D, e.getMaxHealth() * mul); int health = (int) Math.max(1D, e.getMaxHealth() * mul);
e.setHealth(Math.min(health, e.getMaxHealth())); e.setMaxHealth(health);
e.setHealth(health);
// Switch on the type. // Switch on the type.
switch (w.getType()){ switch (w.getType()){
+5 -48
View File
@@ -5,8 +5,7 @@ import org.bukkit.entity.LivingEntity;
public class MABoss public class MABoss
{ {
private LivingEntity entity; private LivingEntity entity;
private int health, health25, maxHealth; private boolean dead;
private boolean dead, lowHealth;
/** /**
* Create an MABoss from the given entity with the given max health. * Create an MABoss from the given entity with the given max health.
@@ -14,12 +13,10 @@ public class MABoss
* @param maxHealth a max health value * @param maxHealth a max health value
*/ */
public MABoss(LivingEntity entity, int maxHealth) { public MABoss(LivingEntity entity, int maxHealth) {
entity.setMaxHealth(maxHealth);
entity.setHealth(maxHealth);
this.entity = entity; this.entity = entity;
this.dead = false; this.dead = false;
this.lowHealth = false;
this.health = this.maxHealth = maxHealth;
this.health25 = maxHealth / 4;
} }
/** /**
@@ -35,7 +32,7 @@ public class MABoss
* @return the current health of the boss * @return the current health of the boss
*/ */
public int getHealth() { public int getHealth() {
return health; return entity.getHealth();
} }
/** /**
@@ -43,47 +40,7 @@ public class MABoss
* @return the maximum health of the boss * @return the maximum health of the boss
*/ */
public int getMaxHealth() { public int getMaxHealth() {
return maxHealth; return entity.getMaxHealth();
}
/**
* Set the health of this boss as a percentage between 1 and 100.
* @param percentage an integer percentage
*/
public void setHealth(int percentage) {
if (percentage < 1) {
percentage = 1;
}
else if (percentage > 100) {
percentage = 100;
}
health = maxHealth * percentage / 100;
}
/**
* Heal the boss for the given amount. Useful for "siphon life"-like abilities.
* @param amount the health amount
*/
public void heal(int amount) {
health = Math.min(maxHealth, health + amount);
}
/**
* Damage the boss for the given amount. Used internally by MobArena.
* @param amount the amount.
*/
public void damage(int amount) {
health -= amount;
if (health <= health25 && !lowHealth) {
lowHealth = true;
//System.out.println("Boss is at 25%!");
}
if (health <= 0) {
dead = true;
}
} }
/** /**