Hello,
Well i forgot to add this to the souce .
This is for basic server v2 go into event/FightEvent and replace the whole code with
Code:
package com.rscd.event;
import com.rscd.DelayedEventHandler;
import com.rscd.model.*;
import com.rscd.util.Formulae;
import com.rscd.entityhandling.defs.extras.ItemDropDef;
import com.rscd.entityhandling.defs.extras.DropDef;
import com.rscd.entityhandling.EntityHandler;
import com.rscd.util.Config;
import java.util.*;
/**
* This class handles combat between
* 2 mobs.
*/
public class FightEvent extends DelayedMobEvent
{
private Mob affectedMob; // The 'defender'
private Random r = new Random();
private int hits;
private int damage = 0;
private final static int FIGHT_DELAY = 1200;
private Mob mobThatWasAttacked = null;
long startTime = 0;
public final int Rand(int low, int high)
{
return low + r.nextInt(high - low);
}
public FightEvent(Mob owner, Mob affectedMob)
{
super(owner, FIGHT_DELAY); // Timer is the delay between hits.
this.affectedMob = affectedMob;
hits = 0;
if(owner instanceof Player)
owner.setFightEvent(this);
if(affectedMob instanceof Player)
affectedMob.setFightEvent(this);
mobThatWasAttacked = affectedMob;
startTime = System.currentTimeMillis();
//owner.incCurrentRound();
}
public void stop()
{
super.running = false;
}
public void run()
{
Mob attacker = null, opponent = null;
Player attackerPlayer = null, opponentPlayer = null;
if(hits++ % 2 == 0)
{
attacker = owner;
opponent = affectedMob;
} else
{
attacker = affectedMob;
opponent = owner;
}
mobThatWasAttacked.setCurrentRound(((int)(System.currentTimeMillis() - attacker.getCombatTimer()) / FIGHT_DELAY));
if(!attacker.equals(mobThatWasAttacked))
attacker.setCurrentRound(((int)(System.currentTimeMillis() - attacker.getCombatTimer()) / FIGHT_DELAY) - 1);
else
if(!opponent.equals(mobThatWasAttacked))
opponent.setCurrentRound(((int)(System.currentTimeMillis() - opponent.getCombatTimer()) / FIGHT_DELAY) - 1);
if(attacker instanceof Player)
attackerPlayer = (Player)attacker;
else
((Npc)attacker).updatePosition();
if(opponent instanceof Player)
opponentPlayer = (Player)opponent;
if(attacker instanceof Npc && opponent instanceof Player)
{
if(opponentPlayer.isPrayerActivated(PARALYZE_MONSTER))
return;
}
damage = Formulae.calcFightHit(attacker, opponent);
opponent.setLastDamage(damage);
int newHp = opponent.getCurStat(3) - damage;
opponent.setCurStat(3, newHp);
ArrayList<Player> playersToInform = new ArrayList<Player>();
playersToInform.addAll(opponent.getViewArea().getPlayersInView());
for(Player p : playersToInform)
{
if(opponentPlayer != null) // Opponent = player
p.informOfModifiedHits(opponentPlayer);
if(opponent instanceof Npc) // Opponent = npc
p.informOfModifiedHits((Npc)opponent);
}
if(opponent instanceof Player) // If the opponent is a player, send their new hits.
opponentPlayer.getActionSender().sendStat(3);
String combatSound = damage > 0 ? "combat1b" : "combat1a";
if(attacker instanceof Player) // If the attacker is a player, send the sound.
attackerPlayer.getActionSender().sendSound(combatSound);
if(opponent instanceof Player) // If the opponent is a player, send the sound.
opponentPlayer.getActionSender().sendSound(combatSound);
if(newHp <= 0) // Defending Mob dead.
{
/** NPCs in combat *
if(attacker instanceof Npc && opponent instanceof Npc)
{
Npc attackerNpc = (Npc)attacker;
Npc opponentNpc = (Npc)opponent;
System.out.println(attackerNpc.getDef().getName() + " killed " + opponentNpc.getDef().getName() + "!");
World.getWorld().unregisterNpc((Npc)opponent);
Collection<Player> allWatched = opponent.getWatchedPlayers().getAllEntities();
System.out.println("Watched: " + allWatched.size());
attacker.removeWatchedNpc((Npc)opponent);
for(Player pl : allWatched)
pl.removeWatchedNpc((Npc)opponent);
World.getWorld().registerItem(new Item(20, opponent.getX(), opponent.getY(), 1, true, null));
}*/
//System.out.println("Attacker killed defender mob in fight event.");
if(attackerPlayer != null && opponentPlayer != null) // Players
{
if(attackerPlayer.isDueling() && opponentPlayer.isDueling()) // If dueling
{
if(attackerPlayer.getWishToDuel().equals(opponentPlayer))
{
//System.out.println(attackerPlayer.getUsername() + " killed " + opponentPlayer.getUsername() + " in DUEL");
opponentPlayer.killedByDuel(attackerPlayer);
attackerPlayer.unsetDuelOptions();
}
} else
opponentPlayer.killedBy(attackerPlayer);
} else
{
if(opponentPlayer != null)
opponentPlayer.killedBy(attacker);
else
{
if(opponent instanceof Npc)
{
((Npc)opponent).die(attacker);
} else
System.out.println("Strange entity killed by FightEvent.");
}
}
if(attacker instanceof Player)
{
int exp = Formulae.roundUp(((opponent.getCombatLevel() * 2) + 10) * 1.5);
switch(attackerPlayer.getCombatStyle())
{
case 0:
for(int x = 0; x < 3; x++)
attackerPlayer.incExp(x, exp / 3);
break;
case 1:
attackerPlayer.incExp(2, exp);
break;
case 2:
attackerPlayer.incExp(0, exp);
break;
case 3:
attackerPlayer.incExp(1, exp);
break;
}
attackerPlayer.incExp(3, exp / 3);
attackerPlayer.getActionSender().sendStats();
}
attacker.setBusy(false);
attacker.setSprite(4);
attacker.setOpponent(null);
attacker.setCombatTimer();
attacker.setState(MobState.IDLE);
attacker.resetCurrentRound();
opponent.resetCurrentRound();
if(attacker instanceof Player)
attackerPlayer.setNeedsUpdate(true);
else
if(opponent instanceof Player)
opponentPlayer.setNeedsUpdate(true);
super.running = false;
}
damage = 0;
}
public void hitNext(int newHit)
{
damage = newHit;
}
public Mob getAffectedMob()
{
return affectedMob;
}
public boolean equals(Object o)
{
if(o instanceof FightEvent)
{
FightEvent e = (FightEvent)o;
return e.belongsTo(owner) && e.getAffectedMob().equals(affectedMob);
}
return false;
}
}
~T X