Redid the 'damage pooling' system (removed memory leak).

Found bugs in XP distribution--
When the last hit was from magic players gained only 3/4ths of the ranged xp they should have - fixed
Players get no XP from killing other players with range
This commit is contained in:
CodeForFame 2011-05-14 07:34:42 -05:00
parent acf0ad8e80
commit ea0509b8f8
7 changed files with 1739 additions and 1573 deletions

View File

@ -10,11 +10,10 @@ import org.moparscape.msc.gs.model.Npc;
import org.moparscape.msc.gs.model.Path;
import org.moparscape.msc.gs.model.Player;
import org.moparscape.msc.gs.model.World;
import org.moparscape.msc.gs.model.mini.Damager;
import org.moparscape.msc.gs.model.mini.Damage;
import org.moparscape.msc.gs.states.CombatState;
import org.moparscape.msc.gs.tools.DataConversions;
public class FightEvent extends DelayedEvent {
private Mob affectedMob;
@ -61,7 +60,9 @@ public class FightEvent extends DelayedEvent {
}
public void run() {
if (!owner.loggedIn() || (affectedMob instanceof Player && !((Player) affectedMob).loggedIn())) {
if (!owner.loggedIn()
|| (affectedMob instanceof Player && !((Player) affectedMob)
.loggedIn())) {
owner.resetCombat(CombatState.ERROR);
affectedMob.resetCombat(CombatState.ERROR);
return;
@ -98,8 +99,8 @@ public class FightEvent extends DelayedEvent {
}
}
if (opponent instanceof Player && attacker instanceof Player) {
if(((Player)opponent).isSleeping()) {
((Player)opponent).getActionSender().sendWakeUp(false);
if (((Player) opponent).isSleeping()) {
((Player) opponent).getActionSender().sendWakeUp(false);
}
}
@ -108,26 +109,32 @@ public class FightEvent extends DelayedEvent {
* opponent.resetCombat(CombatState.LOST); return; }
*/
attacker.incHitsMade();
if (attacker instanceof Npc && opponent.isPrayerActivated(12) && ((Npc)attacker).getTeam() == 2) {
if (attacker instanceof Npc && opponent.isPrayerActivated(12)
&& ((Npc) attacker).getTeam() == 2) {
return;
}
int damage = (attacker instanceof Player && opponent instanceof Player ? Formulae.calcFightHit(attacker, opponent) : Formulae.calcFightHitWithNPC(attacker, opponent));
int damage = (attacker instanceof Player && opponent instanceof Player ? Formulae
.calcFightHit(attacker, opponent) : Formulae
.calcFightHitWithNPC(attacker, opponent));
if (attacker instanceof Player && opponent instanceof Npc) {
Npc npc = (Npc) opponent;
int newDmg = damage;
if (npc.getCurHits() - damage <= 0 && npc.getCurHits() > 0) {
newDmg = npc.getCurHits();
}
npc.getSyndicate().addDamage(owner, newDmg, false, true, false);
npc.getSyndicate().addDamage(owner, newDmg, Damage.COMBAT_DAMAGE);
}
if (attacker instanceof Npc && opponent instanceof Player && attacker.getHitsMade() >= (attacked ? 4 : 3)) {
if (attacker instanceof Npc && opponent instanceof Player
&& attacker.getHitsMade() >= (attacked ? 4 : 3)) {
Npc npc = (Npc) attacker;
Player player = (Player) opponent;
if (npc.getCurHits() <= npc.getDef().hits * 0.10 && npc.getCurHits() > 0) {
if (!npc.getLocation().inWilderness() && npc.getDef().attackable && !npc.getDef().aggressive) {
if (npc.getCurHits() <= npc.getDef().hits * 0.10
&& npc.getCurHits() > 0) {
if (!npc.getLocation().inWilderness()
&& npc.getDef().attackable && !npc.getDef().aggressive) {
boolean go = true;
for (int i : Constants.GameServer.NPCS_THAT_DONT_RETREAT) {
if (i == npc.getID()) {
@ -142,9 +149,14 @@ public class FightEvent extends DelayedEvent {
npc.resetCombat(CombatState.RUNNING);
player.resetCombat(CombatState.WAITING);
npc.setRan(true);
npc.setPath(new Path(attacker.getX(), attacker.getY(), DataConversions.random(npc.getLoc().minX(), npc.getLoc().maxX()), DataConversions.random(npc.getLoc().minY(), npc.getLoc().maxY())));
npc.setPath(new Path(attacker.getX(), attacker.getY(),
DataConversions.random(npc.getLoc().minX(), npc
.getLoc().maxX()), DataConversions
.random(npc.getLoc().minY(), npc
.getLoc().maxY())));
player.resetAll();
player.getActionSender().sendMessage("Your opponent is retreating");
player.getActionSender().sendMessage(
"Your opponent is retreating");
return;
}
}
@ -161,7 +173,8 @@ public class FightEvent extends DelayedEvent {
double cur = n.getHits();
int percent = (int) ((cur / max) * 100);
if (n.isScripted()) {
Instance.getPluginHandler().getNpcAIHandler(opponent.getID()).onHealthPercentage(n, percent);
Instance.getPluginHandler().getNpcAIHandler(opponent.getID())
.onHealthPercentage(n, percent);
}
}
@ -199,97 +212,32 @@ public class FightEvent extends DelayedEvent {
if (newHp <= 0) {
int tempDmg = 0;
Player toLoot = null;
//Logging.debug(opponent+" killed by "+attacker);
// Logging.debug(opponent+" killed by "+attacker);
if (attacker instanceof Player) {
Player attackerPlayer = (Player) attacker;
toLoot = attackerPlayer;
int exp = DataConversions.roundUp(Formulae.combatExperience(opponent) / 4D);
int newXP = 0;
if (opponent instanceof Player) {
//Logging.debug(opponent+" killed by "+attacker);
// Logging.debug(opponent+" killed by "+attacker);
opponent.killedBy(attackerPlayer, false);
}
if (attacker instanceof Player && opponent instanceof Npc) {
Npc npc = (Npc) opponent;
for (Damager fig : ((Npc) opponent).getSyndicate().getDamagers()) {
// boolean found = false;
if (fig.getPlayer().isDueling()) {
continue;
}
if (fig.getDamage() > tempDmg) {
toLoot = fig.getPlayer();
tempDmg = fig.getDamage();
}
if (fig.isUseMagic() && !fig.isUseCombat()) { // if they
// shot
// magic, and didn't
// kill the npc with
// melee
continue;
}
/*
* for(Player p :
* attackerPlayer.getViewArea().getPlayersInView()) if(p
* == fig.player) found = true; if(!found) // skip a
* person who is not in the area. continue;
*/// meh, no big deal, less cpu without it.
if (fig.getDamage() > npc.getDef().hits) {
fig.setDamage(npc.getDef().hits);
}
if (fig.getPlayer() != null) {
newXP = (exp * fig.getDamage()) / npc.getDef().hits;
if (fig.getPlayer() != attackerPlayer && fig.isUseRanged()) {
fig.getPlayer().incExp(4, newXP * 4, true, true);
fig.getPlayer().getActionSender().sendStat(4);
attacker.resetCombat(CombatState.WON);
opponent.resetCombat(CombatState.LOST);
continue;
}
switch (fig.getPlayer().getCombatStyle()) {
case 0:
for (int x = 0; x < 2; x++) {
fig.getPlayer().incExp(x, newXP, true, true);
fig.getPlayer().getActionSender().sendStat(x);
}
fig.getPlayer().incExp(2, newXP, true, true);
fig.getPlayer().getActionSender().sendStat(2);
break;
case 1:
fig.getPlayer().incExp(2, newXP * 3, true, true);
fig.getPlayer().getActionSender().sendStat(2);
break;
case 2:
fig.getPlayer().incExp(0, newXP * 3, true, true);
fig.getPlayer().getActionSender().sendStat(0);
break;
case 3:
fig.getPlayer().incExp(1, newXP * 3, true, true);
fig.getPlayer().getActionSender().sendStat(1);
break;
}
fig.getPlayer().incExp(3, newXP, true, true);
fig.getPlayer().getActionSender().sendStat(3);
}
}
npc.getSyndicate().distributeExp(npc);
} else {
int exp = DataConversions.roundUp(Formulae
.combatExperience(opponent) / 4D);
switch (attackerPlayer.getCombatStyle()) {
case 0:
for (int x = 0; x < 2; x++) {
attackerPlayer.incExp(x, newXP, true, true);
attackerPlayer.incExp(x, exp, true, true);
attackerPlayer.getActionSender().sendStat(x);
}
attackerPlayer.incExp(2, newXP, true, true);
attackerPlayer.incExp(2, exp, true, true);
attackerPlayer.getActionSender().sendStat(2);
break;
case 1:
@ -309,7 +257,7 @@ public class FightEvent extends DelayedEvent {
attackerPlayer.getActionSender().sendStat(3);
}
}
//if the dead mob isn't a player...
// if the dead mob isn't a player...
if (!(affectedMob instanceof Player)) {
opponent.killedBy(toLoot, false);
}

View File

@ -13,7 +13,7 @@ import org.moparscape.msc.gs.model.Npc;
import org.moparscape.msc.gs.model.PathGenerator;
import org.moparscape.msc.gs.model.Player;
import org.moparscape.msc.gs.model.Projectile;
import org.moparscape.msc.gs.model.mini.Damager;
import org.moparscape.msc.gs.model.mini.Damage;
import org.moparscape.msc.gs.states.Action;
import org.moparscape.msc.gs.tools.DataConversions;
@ -174,7 +174,7 @@ public class RangeEvent extends DelayedEvent {
}
if (affectedMob instanceof Npc) {
Npc npc = (Npc) affectedMob;
npc.getSyndicate().addDamage(owner, damage, false, false, true);
npc.getSyndicate().addDamage(owner, damage, Damage.RANGE_DAMAGE);
}
Projectile projectile = new Projectile(owner, affectedMob, 2);
@ -212,49 +212,10 @@ public class RangeEvent extends DelayedEvent {
owner.resetRange();
if (owner instanceof Player) {
Player attackerPlayer = (Player) owner;
int exp = DataConversions.roundUp(Formulae.combatExperience(affectedMob) / 4D);
int newXP = 0;
if (owner instanceof Player && affectedMob instanceof Npc) {
if (affectedMob instanceof Npc) {
Npc npc = (Npc) affectedMob;
for (Damager fig : ((Npc) affectedMob).getSyndicate().getDamagers()) {
if (fig.isUseMagic() && attackerPlayer != fig.getPlayer())
continue;
if (fig.getDamage() > npc.getDef().hits)
fig.setDamage(npc.getDef().hits);
if (fig.getPlayer() != null) {
newXP = (exp * fig.getDamage()) / npc.getDef().hits;
if (fig.isUseRanged()) {
fig.getPlayer().incExp(4, newXP * 4, true, true);
fig.getPlayer().getActionSender().sendStat(4);
continue;
}
switch (fig.getPlayer().getCombatStyle()) {
case 0:
for (int x = 0; x < 3; x++) {
fig.getPlayer().incExp(x, newXP, true, true);
fig.getPlayer().getActionSender().sendStat(x);
}
break;
case 1:
fig.getPlayer().incExp(2, newXP * 3, true, true);
fig.getPlayer().getActionSender().sendStat(2);
break;
case 2:
fig.getPlayer().incExp(0, newXP * 3, true, true);
fig.getPlayer().getActionSender().sendStat(0);
break;
case 3:
fig.getPlayer().incExp(1, newXP * 3, true, true);
fig.getPlayer().getActionSender().sendStat(1);
break;
}
fig.getPlayer().incExp(3, newXP, true, true);
fig.getPlayer().getActionSender().sendStat(3);
}
}
npc.getSyndicate().distributeExp(npc);
}
}
} else {

View File

@ -1,9 +1,12 @@
package org.moparscape.msc.gs.model;
import java.util.ArrayList;
import org.moparscape.msc.gs.model.mini.Damager;
import java.util.Collection;
import java.util.Map;
import java.util.WeakHashMap;
import org.moparscape.msc.config.Formulae;
import org.moparscape.msc.gs.model.mini.Damage;
import org.moparscape.msc.gs.tools.DataConversions;
/**
* Each NPC has a Damage Syndicate (pool of damage) binded to them.
@ -12,36 +15,76 @@ import org.moparscape.msc.gs.model.mini.Damager;
*
*/
public class Syndicate {
/**
* All the damagers of this NPC Syndicate
*/
private ArrayList<Damager> damagers = new ArrayList<Damager>();
public void addDamage(Player p, int damage, boolean magic, boolean combat, boolean ranged) {
boolean exist = false;
Damager other = null;
for (Damager damager : getDamagers()) {
if (damager.getPlayer().getUsername().equals(p.getUsername())) {
exist = true;
other = damager;
break;
}
}
if (!exist) {
other = new Damager(p);
getDamagers().add(other);
}
other.setDamage(other.getDamage() + damage);
if (magic)
other.setUseMagic(true);
if (combat)
other.setUseCombat(true);
if (ranged)
other.setUseRanged(true);
}
private Map<Player, Damage> damage = new WeakHashMap<Player, Damage>();
public ArrayList<Damager> getDamagers() {
return damagers;
}
public void addDamage(final Player player, final int damage,
final int damageType) {
final Damage prev = this.damage.get(player);
if (prev != null) {
prev.addDamage(damage, damageType);
} else {
this.damage.put(player, new Damage(damage, damageType));
}
}
public Map<Player, Damage> getDamages() {
return damage;
}
public void distributeExp(final Npc npc) {
final Map<Player, Damage> dmgs = getDamages();
final int exp = DataConversions.roundUp(Formulae
.combatExperience(npc) / 4D);
int newXP = 0;
for (final Player p : dmgs.keySet()) {
Damage dmg = dmgs.get(p);
int total = dmg.getTotalDamage();
if (total > npc.getDef().hits) {
total = npc.getDef().hits;
}
if (p != null) {
newXP = (exp * total) / npc.getDef().hits;
p.incExp(4, roundAndCast(newXP * 4 * dmg.getRangePortion()),
true);
p.getActionSender().sendStat(4);
switch (p.getCombatStyle()) {
case 0:
for (int x = 0; x < 3; x++) {
p.incExp(x,
roundAndCast(newXP * dmg.getCombatPortion()),
true);
p.getActionSender().sendStat(x);
}
break;
case 1:
p.incExp(2,
roundAndCast(newXP * 3 * dmg.getCombatPortion()),
true);
p.getActionSender().sendStat(2);
break;
case 2:
p.incExp(0,
roundAndCast(newXP * 3 * dmg.getCombatPortion()),
true);
p.getActionSender().sendStat(0);
break;
case 3:
p.incExp(1,
roundAndCast(newXP * 3 * dmg.getCombatPortion()),
true);
p.getActionSender().sendStat(1);
break;
}
p.incExp(3, roundAndCast(newXP * dmg.getCombatPortion()), true);
p.getActionSender().sendStat(3);
}
}
}
public int roundAndCast(double d) {
return (int) Math.round(d);
}
}

View File

@ -0,0 +1,77 @@
package org.moparscape.msc.gs.model.mini;
/**
* Damage values
*
* @author CodeForFame
*
*/
public class Damage {
public static final int COMBAT_DAMAGE = 0;
public static final int MAGIC_DAMAGE = 1;
public static final int RANGE_DAMAGE = 2;
private final int[] damage = new int[3];
public Damage(final int damage, final int type) {
this.addDamage(damage, type);
}
public int getMagicDamage() {
return damage[MAGIC_DAMAGE];
}
public void setMagicDamage(final int damage) {
this.damage[MAGIC_DAMAGE] = damage;
}
public void addMagicDamage(final int damage) {
this.damage[MAGIC_DAMAGE] += damage;
}
public int getRangeDamage() {
return this.damage[RANGE_DAMAGE];
}
public void setRangeDamage(final int damage) {
this.damage[RANGE_DAMAGE] = damage;
}
public void addRangeDamage(final int damage) {
this.damage[RANGE_DAMAGE] += damage;
}
public int getCombatDamage() {
return damage[COMBAT_DAMAGE];
}
public void setCombatDamage(final int damage) {
this.damage[COMBAT_DAMAGE] = damage;
}
public void addCombatDamage(final int damage) {
this.damage[COMBAT_DAMAGE] += damage;
}
public void addDamage(final int damage, final int damageType) {
// CBF typing out legit bounds checking...
this.damage[damageType % 3] += damage;
}
public int getTotalDamage() {
return getCombatDamage() + getRangeDamage() + getMagicDamage();
}
public double getRangePortion() {
return getRangeDamage() / getTotalDamage();
}
public double getMagicPortion() {
return getMagicDamage() / getTotalDamage();
}
public double getCombatPortion() {
return getCombatDamage() / getTotalDamage();
}
}

View File

@ -1,78 +0,0 @@
package org.moparscape.msc.gs.model.mini;
import org.moparscape.msc.gs.model.Player;
/**
* a Damager (Player) that adds to a pool (Syndicate) of an NPC
*
* @author xEnt
*
*/
public class Damager {
/**
* Damage this player has dealt
*/
private int damage = 0;
/**
* the Player/Damager
*/
private Player player;
/**
* Have they used melee on this NPC?
*/
private boolean useCombat = false;
/**
* Have they used magic on this NPC?
*/
private boolean useMagic = false;
/**
* Have they used ranged on this NPC?
*/
private boolean useRanged = false;
public int getDamage() {
return damage;
}
public void setDamage(int damage) {
this.damage = damage;
}
public Player getPlayer() {
return player;
}
public void setPlayer(Player player) {
this.player = player;
}
public boolean isUseCombat() {
return useCombat;
}
public void setUseCombat(boolean useCombat) {
this.useCombat = useCombat;
}
public boolean isUseMagic() {
return useMagic;
}
public void setUseMagic(boolean useMagic) {
this.useMagic = useMagic;
}
public boolean isUseRanged() {
return useRanged;
}
public void setUseRanged(boolean useRanged) {
this.useRanged = useRanged;
}
public Damager(Player p) {
this.player = p;
}
}

View File

@ -1,6 +1,7 @@
package org.moparscape.msc.gs.plugins.ai;
import java.util.ArrayList;
import java.util.Map;
import org.moparscape.msc.config.Formulae;
import org.moparscape.msc.gs.Instance;
@ -9,11 +10,10 @@ import org.moparscape.msc.gs.model.GameObject;
import org.moparscape.msc.gs.model.Npc;
import org.moparscape.msc.gs.model.Player;
import org.moparscape.msc.gs.model.Projectile;
import org.moparscape.msc.gs.model.mini.Damager;
import org.moparscape.msc.gs.model.mini.Damage;
import org.moparscape.msc.gs.plugins.dependencies.NpcAI;
import org.moparscape.msc.gs.plugins.dependencies.NpcScript;
/**
* KingBlackDragon intelligence class.
*
@ -22,156 +22,187 @@ import org.moparscape.msc.gs.plugins.dependencies.NpcScript;
*/
public class KingBlackDragon extends NpcScript implements NpcAI {
@Override
public int getID() {
return 477;
}
@Override
public void onHealthPercentage(Npc npc, int percent) {
/*
* if(percent > 60 && percent <= 80 && npc.getStage() == 1) {
* npc.setStage(2); shootFire(npc); } if(percent > 45 && percent <= 60
* && npc.getStage() == 2) { npc.setStage(3); if(npc.getOpponent() !=
* null || npc.getOpponent() instanceof Player) { sendNpcChat(npc,
* (Player)npc.getOpponent(), "You can't kill me damn humans", true); }
* } if(percent > 35 && percent < 50 && npc.getStage() == 3) {
* npc.setStage(4); shootFire(npc); } if(percent > 5 && percent < 25 &&
* npc.getStage() == 4) { npc.setStage(5); absorbHealth(npc); }
* if(percent > 50 && percent < 65 && npc.getStage() == 5) {
* npc.setStage(6); shootFire(npc); } if(percent > 42 && percent < 49 &&
* npc.getStage() == 5) { npc.setStage(7); for(Player p :
* npc.getViewArea().getPlayersInView()) { if(p != null) {
* p.getActionSender().sendMessage("The " + npc.getDef().name +
* " gets stronger!"); npc.getDef().strength+=npc.getDef().strength *
* 0.30; } } } if(percent > 25 && percent < 40 && npc.getStage() == 7) {
* npc.setStage(8); shootFire(npc); }
*/
}
public void absorbHealth(Npc npc) {
for (Damager dam : npc.getSyndicate().getDamagers()) {
if (dam == null || dam.getPlayer() == null)
continue;
int drain = Formulae.Rand((int) (dam.getPlayer().getMaxStat(3) * 0.25) / 2, (int) (dam.getPlayer().getMaxStat(3) * 0.25));
Projectile projectile = new Projectile(dam.getPlayer(), npc, 4);
int newhp = npc.getCurHits() + drain;
if (newhp > npc.getDef().hits)
newhp = npc.getDef().hits;
npc.setHits(newhp);
ArrayList<Player> playersToInform = new ArrayList<Player>();
playersToInform.addAll(npc.getViewArea().getPlayersInView());
playersToInform.addAll(dam.getPlayer().getViewArea().getPlayersInView());
for (Player p : playersToInform) {
p.informOfModifiedHits(npc);
p.informOfProjectile(projectile);
}
shootPlayer(npc, dam.getPlayer(), drain, 1);
dam.getPlayer().getActionSender().sendMessage("The " + npc.getDef().name + " absorbs health from you");
@Override
public int getID() {
return 477;
}
}
@Override
public void onMageAttack(Player attacker, Npc npc) {
/*
* if(npc.getStage() == 0) { npc.setStage(1); sendNpcChat(npc, attacker,
* "Feel my Wrath Humans!", true); shootFire(npc); }
*/
}
@Override
public void onMeleeAttack(Player attacker, final Npc npc) {
/*if (attacker.getCurStat(5) > (int) (attacker.getMaxStat(5) * 0.01)) {
attacker.setCurStat(5, (int) (attacker.getMaxStat(5) * 0.01));
attacker.getActionSender().sendStat(5);
attacker.getActionSender().sendMessage("The dragon lowers your Prayer");
}*/
if (attacker.getCurStat(5) > 0) {
//attacker.setCurStat(5, (int)(attacker.getCurStat(5) * 0.10));
// for (int prayerID = 0; prayerID < 14; prayerID++) {
// attacker.setPrayer(prayerID, false);
// }
// attacker.setDrainRate(0);
// attacker.getActionSender().sendMessage("You have run out of prayer points. Return to a church to recharge");
// attacker.getActionSender().sendPrayers();
@Override
public void onHealthPercentage(Npc npc, int percent) {
/*
* if(percent > 60 && percent <= 80 && npc.getStage() == 1) {
* npc.setStage(2); shootFire(npc); } if(percent > 45 && percent <= 60
* && npc.getStage() == 2) { npc.setStage(3); if(npc.getOpponent() !=
* null || npc.getOpponent() instanceof Player) { sendNpcChat(npc,
* (Player)npc.getOpponent(), "You can't kill me damn humans", true); }
* } if(percent > 35 && percent < 50 && npc.getStage() == 3) {
* npc.setStage(4); shootFire(npc); } if(percent > 5 && percent < 25 &&
* npc.getStage() == 4) { npc.setStage(5); absorbHealth(npc); }
* if(percent > 50 && percent < 65 && npc.getStage() == 5) {
* npc.setStage(6); shootFire(npc); } if(percent > 42 && percent < 49 &&
* npc.getStage() == 5) { npc.setStage(7); for(Player p :
* npc.getViewArea().getPlayersInView()) { if(p != null) {
* p.getActionSender().sendMessage("The " + npc.getDef().name +
* " gets stronger!"); npc.getDef().strength+=npc.getDef().strength *
* 0.30; } } } if(percent > 25 && percent < 40 && npc.getStage() == 7) {
* npc.setStage(8); shootFire(npc); }
*/
}
/*
* if(npc.getStage() == 0) { npc.setStage(1); sendNpcChat(npc, attacker,
* "Feel my Wrath Humans!", true); }
*/
}
public void shootFire(Npc npc) {
try {
if (npc != null) {
if (npc.getOpponent() != null && npc.getOpponent() instanceof Player) {
Instance.getDelayedEventHandler().add(new org.moparscape.msc.gs.event.MiniEvent((Player) npc.getOpponent(), 2500, new Object[] { npc }) {
public void action() {
Npc n = (Npc) super.args[0];
if (n != null || n.getHits() > 0) {
NpcScript script = new NpcScript();
for (Damager dam : n.getSyndicate().getDamagers()) {
if (dam == null || dam.getPlayer() == null)
continue;
if (dam.getPlayer().equals(owner))
continue;
script.shootPlayer(n, dam.getPlayer(), Formulae.Rand((int) (dam.getPlayer().getMaxStat(3) * 0.25) / 2, (int) (dam.getPlayer().getMaxStat(3) * 0.25)), 1);
dam.getPlayer().getActionSender().sendMessage("The " + n.getDef().name + " spits fire at you");
GameObject obj = new GameObject(dam.getPlayer().getLocation(), 1036, 0, 0);
world.registerGameObject(obj);
Instance.getDelayedEventHandler().add(new ObjectRemover(obj, 500));
Instance.getDelayedEventHandler().add(new org.moparscape.msc.gs.event.MiniEvent((Player) n.getOpponent(), 2500, new Object[] { n }) {
public void action() {
shootFire((Npc) super.args[0]);
}
public void absorbHealth(Npc npc) {
final Map<Player, Damage> dmgs = npc.getSyndicate().getDamages();
for (final Player p : dmgs.keySet()) {
if (p == null)
continue;
});
}
}
int drain = Formulae.Rand((int) (p.getMaxStat(3) * 0.25) / 2,
(int) (p.getMaxStat(3) * 0.25));
Projectile projectile = new Projectile(p, npc, 4);
int newhp = npc.getCurHits() + drain;
if (newhp > npc.getDef().hits)
newhp = npc.getDef().hits;
npc.setHits(newhp);
ArrayList<Player> playersToInform = new ArrayList<Player>();
playersToInform.addAll(npc.getViewArea().getPlayersInView());
playersToInform.addAll(p.getViewArea().getPlayersInView());
for (Player p1 : playersToInform) {
p1.informOfModifiedHits(npc);
p1.informOfProjectile(projectile);
}
});
shootPlayer(npc, p, drain, 1);
p.getActionSender().sendMessage(
"The " + npc.getDef().name + " absorbs health from you");
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void onNpcAttack(Npc npc, Player player) {
/*if (player.getCurStat(5) > (int) (player.getMaxStat(5) * 0.01)) {
player.setCurStat(5, (int) (player.getMaxStat(5) * 0.01));
player.getActionSender().sendStat(5);
player.getActionSender().sendMessage("The dragon lowers your Prayer");
}*/
if (player.getCurStat(5) > 0) {
//player.setCurStat(5, (int)(player.getCurStat(5) * 0.10));
// for (int prayerID = 0; prayerID < 14; prayerID++) {
// player.setPrayer(prayerID, false);
// }
// player.setDrainRate(0);
//player.getActionSender().sendMessage("You have run out of prayer points. Return to a church to recharge");
//player.getActionSender().sendPrayers();
@Override
public void onMageAttack(Player attacker, Npc npc) {
/*
* if(npc.getStage() == 0) { npc.setStage(1); sendNpcChat(npc, attacker,
* "Feel my Wrath Humans!", true); shootFire(npc); }
*/
}
}
@Override
public void onNpcDeath(Npc npc, Player player) {
/*
* if(npc.getOpponent() != null || npc.getOpponent() instanceof Player)
* { sendNpcChat(npc, (Player)npc.getOpponent(),
* "I'll be back muhahahaa", true); }
*/
}
@Override
public void onMeleeAttack(Player attacker, final Npc npc) {
/*
* if (attacker.getCurStat(5) > (int) (attacker.getMaxStat(5) * 0.01)) {
* attacker.setCurStat(5, (int) (attacker.getMaxStat(5) * 0.01));
* attacker.getActionSender().sendStat(5);
* attacker.getActionSender().sendMessage
* ("The dragon lowers your Prayer"); }
*/
if (attacker.getCurStat(5) > 0) {
// attacker.setCurStat(5, (int)(attacker.getCurStat(5) * 0.10));
// for (int prayerID = 0; prayerID < 14; prayerID++) {
// attacker.setPrayer(prayerID, false);
// }
// attacker.setDrainRate(0);
// attacker.getActionSender().sendMessage("You have run out of prayer points. Return to a church to recharge");
// attacker.getActionSender().sendPrayers();
}
/*
* if(npc.getStage() == 0) { npc.setStage(1); sendNpcChat(npc, attacker,
* "Feel my Wrath Humans!", true); }
*/
}
@Override
public void onRangedAttack(Player p, Npc npc) {
/*
* if(npc.getStage() == 0) { npc.setStage(1); sendNpcChat(npc, p,
* "Feel my Wrath Humans!", true); shootFire(npc); }
*/
}
public void shootFire(Npc npc) {
try {
if (npc != null) {
if (npc.getOpponent() != null
&& npc.getOpponent() instanceof Player) {
Instance.getDelayedEventHandler().add(
new org.moparscape.msc.gs.event.MiniEvent(
(Player) npc.getOpponent(), 2500,
new Object[] { npc }) {
public void action() {
Npc n = (Npc) super.args[0];
if (n != null || n.getHits() > 0) {
NpcScript script = new NpcScript();
final Map<Player, Damage> dmgs = n
.getSyndicate().getDamages();
for (final Player p : dmgs.keySet()) {
if (p == null)
continue;
if (p.equals(owner))
continue;
script.shootPlayer(
n,
p,
Formulae.Rand(
(int) (p.getMaxStat(3) * 0.25) / 2,
(int) (p.getMaxStat(3) * 0.25)),
1);
p.getActionSender()
.sendMessage(
"The "
+ n.getDef().name
+ " spits fire at you");
GameObject obj = new GameObject(p
.getLocation(), 1036, 0, 0);
world.registerGameObject(obj);
Instance.getDelayedEventHandler()
.add(new ObjectRemover(obj,
500));
Instance.getDelayedEventHandler()
.add(new org.moparscape.msc.gs.event.MiniEvent(
(Player) n
.getOpponent(),
2500,
new Object[] { n }) {
public void action() {
shootFire((Npc) super.args[0]);
}
});
}
}
}
});
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void onNpcAttack(Npc npc, Player player) {
/*
* if (player.getCurStat(5) > (int) (player.getMaxStat(5) * 0.01)) {
* player.setCurStat(5, (int) (player.getMaxStat(5) * 0.01));
* player.getActionSender().sendStat(5);
* player.getActionSender().sendMessage
* ("The dragon lowers your Prayer"); }
*/
if (player.getCurStat(5) > 0) {
// player.setCurStat(5, (int)(player.getCurStat(5) * 0.10));
// for (int prayerID = 0; prayerID < 14; prayerID++) {
// player.setPrayer(prayerID, false);
// }
// player.setDrainRate(0);
// player.getActionSender().sendMessage("You have run out of prayer points. Return to a church to recharge");
// player.getActionSender().sendPrayers();
}
}
@Override
public void onNpcDeath(Npc npc, Player player) {
/*
* if(npc.getOpponent() != null || npc.getOpponent() instanceof Player)
* { sendNpcChat(npc, (Player)npc.getOpponent(),
* "I'll be back muhahahaa", true); }
*/
}
@Override
public void onRangedAttack(Player p, Npc npc) {
/*
* if(npc.getStage() == 0) { npc.setStage(1); sendNpcChat(npc, p,
* "Feel my Wrath Humans!", true); shootFire(npc); }
*/
}
}