i was working on combat and noticed u had to make everything double
or 3 times for npc v npc, pvp, pvnpc, i got tired of copy pasting everything
and editing it a little bit, so i decided to make an entity system so if u
update something in the combat code, it updates on all combat systems
this is a huge release, i'll get this removed if people flame me or say
it's coded bad or w/e because i don't give a fuck, it works for me
NOTE: not all of the methods, ints and booleans used will be called
exactly the same as yours, and some stuff is "leeched" as i'm using the
base of my dopscape v1 from back when cleaned v3 was the source
used most
add a new java interface called Entity and paste this in it
Code:
/**
* File: melee.java
* Methods which will help with melee combat
*
* @version 1.00 BETA
* @author dophert
*/
public interface Entity
{
/**
* This will apply damage to the chosen entity
* @param damage : the amount of damage caused.
* @param type : poison or regular
*/
public abstract void appendHit(int damage, int type);
/**
* This will send a graphics update request to the chosen entity
* @param gfx : the graphics id
* @param height : height above surface
*/
public abstract void appendGfx(int gfx, int height);
/**
* Request an anim from the chosen entity
* @param anim : the animation ID
*/
public abstract void requestAnim(int anim);
/**
* Get the absolute X coord
*/
public abstract int getXCoord();
/**
* Get the absolute y coord
*/
public abstract int getYCoord();
/**
* Get's the entity's defence bonus
*/
public abstract int getDef(int wat);
/**
* Get's the entity's attack bonus
*/
public abstract int getAtk();
/**
* Get's the entity's best attack bonus
*/
public abstract int checkBestBonus();
/**
* Get's the entity's type.
*/
public abstract int getType();
/**
* @return lastHit.
*/
public abstract long getLastHit();
/**
* @param value : sets lastHit to this value.
*/
public abstract void setLastHit(long value);
/**
* @return attack animation id.
*/
public abstract int getAttackAnim();
/**
* @return defence animation id.
*/
public abstract int defenceAnim();
/**
* @param the entity you wish to face.
*/
public abstract void face(int i);
/**
* @return defence animation id.
*/
public abstract int getId();
/**
* @return attackType.
*/
public abstract int getAttackType();
/**
* @param x X coord to walk to
* @param y Y coord to walk to
*/
public abstract void walkTo(int x, int y);
/**
* @return drawback graphics id.
*/
public abstract int getDrawback();
/**
* @return projectile graphics id.
*/
public abstract int projectileGfx();
/**
* @return id of entity attacking on.
*/
public abstract int attackOn();
/**
* @return hit graphics id.
*/
public abstract int hitGfx();
/**
* @return max hit.
*/
public abstract int maxHit();
/**
* @return fighting type (crush, etc).
*/
public abstract int fightType();
/**
* @param X coordinate to face to
* @param Y coordinate to face to
*/
public abstract void turnTo(int pointX, int pointY);
/**
* @return protection prayer.
*/
public abstract int protect();
/**
* @return magic defence.
*/
public abstract int mageDef();
/**
* Add any effects in this void, such as Exp, drains, boosts, ...
* @param i The amount of damage dealt on the opponent
*/
public abstract void combatEffects(int i, Entity n);
/**
* ID of person attacking u
*/
public abstract int attackingOn();
/**
* static final variables.
*/
public int HUMAN = 1;
public int NPC = 2;
}
then a new class called Melee and paste this in it
Code:
/**
* File: melee.java
* Methods which will help with melee combat
*
* @version 1.00 BETA
* @author dophert
*/
public class Melee {
public void attack(final Entity e, final Entity n){
final int l = (e.getXCoord() - n.getXCoord()) * -1;
final int i1 = (e.getYCoord() - n.getYCoord()) * -1;
if(e.getAttackType() == MELEE && System.currentTimeMillis() - e.getLastHit() > 2500){
if(ObjectHandler.GoodDistance(e.getXCoord(), e.getYCoord(), n.getXCoord(), n.getYCoord(), 1)){
e.requestAnim(e.getAttackAnim());
e.setLastHit(System.currentTimeMillis());
e.turnTo(n.getXCoord(), n.getYCoord());
if(n.getType() == 2) n.turnTo(e.getXCoord(), e.getYCoord());
int attack = misc.random(e.getAtk());
int defence = misc.random(n.getDef(e.fightType())) + misc.random(n.getDef(e.fightType()) / 2);
int dmg = misc.random(e.maxHit() - 1);
if(attack > defence && n.protect() != 1 && n.protect() != 4){
e.combatEffects(dmg + 1, n);
n.appendHit(dmg + 1, 0);
} else if(n.getType() == n.HUMAN && e.getType() == e.HUMAN && n.protect() == 1){
e.combatEffects(dmg + 1 / 2, n);
n.appendHit(dmg + 1 / 2, 0);
} else {
e.combatEffects(0, n);
n.appendHit(0, 0);
}
n.face(e.getId());
n.requestAnim(n.defenceAnim());
}
} else if(e.getAttackType() == RANGE && System.currentTimeMillis() - e.getLastHit() > 2000){
e.setLastHit(System.currentTimeMillis());
e.turnTo(n.getXCoord(), n.getYCoord());
if(n.getType() == 2) n.turnTo(e.getXCoord(), e.getYCoord());
e.requestAnim(e.getAttackAnim());
e.walkTo(e.getXCoord(), e.getYCoord());
if(e.getDrawback() > 0) e.appendGfx(e.getDrawback(), 100);
if(e.projectileGfx() > 0)
if(n.getType() == e.HUMAN)
GraphicsHandler.createProjectilec(e.getYCoord(), e.getXCoord(), l, i1, 50, 80, e.projectileGfx(), 43, 34, -e.attackOn() - 1);
else if(n.getType() == e.NPC)
GraphicsHandler.createProjectilec(e.getYCoord(), e.getXCoord(), l, i1, 50, 80, e.projectileGfx(), 43, 34, e.attackOn() + 1);
final int attack = misc.random(e.getAtk());
final int defence = misc.random(n.getDef(e.fightType())) + misc.random(n.getDef(e.fightType()) / 2);
EventManager.getSingleton().addEvent(
new Event() {
public void execute(EventContainer c) {
if(n.protect() != 4 && n.protect() != 2 && attack > defence){
int dmg = misc.random(e.maxHit() + 1);
e.combatEffects(dmg + 1, n);
n.appendHit(dmg + 1, 0);
} else {
n.appendHit(0, 0);
}
n.requestAnim(n.defenceAnim());
c.stop(); // stops the event from running
}
}, 1750); // executes after 1,500 ms = 1,5 seconds
} else if(e.getAttackType() == MAGIC && System.currentTimeMillis() - e.getLastHit() > 2000){
e.setLastHit(System.currentTimeMillis());
e.requestAnim(e.getAttackAnim());
e.walkTo(e.getXCoord(), e.getYCoord());
e.turnTo(n.getXCoord(), n.getYCoord());
if(n.getType() == 2) n.turnTo(e.getXCoord(), e.getYCoord());
if(e.getDrawback() > 1) e.appendGfx(e.getDrawback(), 100);
if(e.projectileGfx() > 0)
if(n.getType() == e.HUMAN)
GraphicsHandler.createProjectilec(e.getYCoord(), e.getXCoord(), l, i1, 50, 80, e.projectileGfx(), 43, 34, -e.attackOn() - 1);
else if(n.getType() == e.NPC)
GraphicsHandler.createProjectilec(e.getYCoord(), e.getXCoord(), l, i1, 50, 80, e.projectileGfx(), 43, 34, e.attackOn() + 1);
final int attack = misc.random(e.getAtk());
final int defence = misc.random(n.mageDef()) + misc.random(n.mageDef() / 2);
EventManager.getSingleton().addEvent(
new Event() {
public void execute(EventContainer c) {
if(n.protect() != 4 && n.protect() != 3 && attack > defence){
int dmg = misc.random(e.maxHit() - 1);
e.combatEffects(dmg + 1, n);
n.appendHit(dmg + 1, 0);
GraphicsHandler.stillgfx(e.hitGfx(), n.getYCoord(), n.getXCoord(), 100);
} else {
n.appendHit(0, 0);
GraphicsHandler.stillgfx(85, n.getYCoord(), n.getXCoord(), 100);
}
n.requestAnim(n.defenceAnim());
c.stop(); // stops the event from running
}
}, 1750); // executes after 1,500 ms = 1,5 seconds
}
}
public static final int MELEE = 1;
public static final int RANGE = 2;
public static final int MAGIC = 3;
}
in the Player class add these methods
Code:
public long lastHit = 0;
public void turnTo(int pointX, int pointY) {
FocusPointX = 2*pointX+1;
FocusPointY = 2*pointY+1;
}
public long getLastHit(){
return lastHit;
}
public int fightType(){
return checkBestBonus();
}
public void setLastHit(long value){
lastHit = value;
}
public void requestAnim(int anim) {
startAnimation(anim);
}
public int getXCoord() {
return absX;
}
public int getYCoord() {
return absY;
}
public int getType(){
return 1;
}
public int getId(){
return playerId;
}
public int maxHit(){
client c = (client)this;
switch(getAttackType()){
case Melee.MELEE:
return Strength.getMaxHit(c);
case Melee.RANGE:
return Range.getRange(c);
case Melee.MAGIC:
return Autocast.MageHit[c.Autocast_SpellIndex];
}
return 0;
}
public int hitGfx(){
client c = (client)this;
if(c.isAutocast) return Autocast.MageEndingGFX[c.Autocast_SpellIndex];
return 0;
}
public int defenceAnim(){
return WeaponEmotes.GetBlockAnim((playerEquipment[playerWeapon]));
}
public int getAttackType(){
client c = (client)this;
if(c.getItemName(playerEquipment[playerWeapon]).toLowerCase().contains("bow"))
return 2;
if(c.isAutocast)
return 3;
return 1;
}
public int checkBestBonus() {
if(playerBonus[1] > playerBonus[2] && playerBonus[1] > playerBonus[3])
return 1;
if(playerBonus[2] > playerBonus[1] && playerBonus[2] > playerBonus[3])
return 2;
if(playerBonus[3] > playerBonus[2] && playerBonus[3] > playerBonus[1])
return 3;
return 1;
}
public int getAttackAnim(){
client c = (client)this;
if(c.isAutocast){
return Autocast.animG[Autocast.animationGroup[c.Autocast_SpellIndex]];
} else if(usingSpecial && specBar >= s.SpecDrainAmount(playerEquipment[playerWeapon])){
return s.StartSpecEmote(playerEquipment[playerWeapon]);
} else {
return WeaponEmotes.GetWepAnim(playerEquipment[playerWeapon]);
}
}
public void add2ndHit(Entity n){
int attack = misc.random(getAtk());
int defence = misc.random(n.getDef(fightType()));
int dmg = misc.random(maxHit() - 1) + 1;
exp(dmg);
if(attack > defence && n.protect() != 1){
n.appendHit(dmg, 0);
} else if(n.getType() == n.HUMAN && n.protect() == 1){
n.appendHit(dmg / 2, 0);
} else {
n.appendHit(0, 0);
}
}
public void combatEffects(int i, Entity n){
client p = (client)this;
int wep = playerEquipment[playerWeapon];
exp(i);
if(usingSpecial){
if(specBar >= s.SpecDrainAmount(wep)){
if(s.ReturnPlayerSpecGfx(wep) > 0) appendGfx(s.ReturnPlayerSpecGfx(wep), 100);
if(s.ReturnOtherGfx(wep) > 0) GraphicsHandler.stillgfx(s.ReturnOtherGfx(wep), n.getYCoord(), n.getXCoord(), 100);
switch(wep){
case 5698:
boostStr(25);
break;
case 4151:
boostAtk(25);
break;
case 1434:
boostStr(10);
boostAtk(15);
break;
case 1305:
boostStr(30);
break;
case 4587:
boostAtk(25);
break;
}
specBar -= s.SpecDrainAmount(wep);
p.resetBar();
}
}
}
public boolean boostStr, boostAtk;
public int strBoost, atkBoost;
public void boostStr(int amt){
boostStr = true;
strBoost = amt;
}
public void boostAtk(int amt){
boostAtk = true;
atkBoost = amt;
}
public int getDef(int wat) {
switch(getAttackType()){
case Melee.MELEE:
if(playerBonus[wat + 5] > 0) return ((playerBonus[wat + 5] / 2) + (playerLevel[1] / 4));
if(playerBonus[wat + 5] < 1) return ((playerBonus[wat + 5]) + (playerLevel[1] / 4));
case Melee.RANGE:
if(playerBonus[9] > 0) return ((playerBonus[9] / 2) + (playerLevel[4] / 4));
if(playerBonus[9] < 1) return ((playerBonus[9]) + (playerLevel[4] / 4));
case Melee.MAGIC:
if(playerBonus[8] > 0) return (playerBonus[8] + (playerLevel[0]/2));
if(playerBonus[8] < 1) return (playerBonus[8]) + (5);
default:
return 0;
}
}
public void exp(int i){
int xpRate = 100;
client p = (client)this;
if(getAttackType() == Melee.MELEE){
switch(FightType){
case 1: // Accurate
p.addSkillXP(i * xpRate, playerAttack);
break;
case 2: // Agressive
p.addSkillXP(i * xpRate, playerStrength);
break;
case 4: // Defensive
p.addSkillXP(i * xpRate, playerDefence);
break;
case 3: // Controlled
p.addSkillXP(i * xpRate, playerStrength);
break;
}
} else if(getAttackType() == Melee.RANGE){
p.addSkillXP(i * xpRate, playerRanged);
} else if(getAttackType() == Melee.MAGIC){
p.addSkillXP(i * xpRate, playerMagic);
}
}
public int getAtk(){
switch(getAttackType()){
case Melee.MELEE:
int myBonus = 0;
int atkB = playerBonus[checkBestBonus()];
if(atkB > 0) {
myBonus = playerBonus[checkBestBonus()] + playerLevel[0];
}
if(atkB < 1) {
myBonus = (playerBonus[checkBestBonus()] * 2) + playerLevel[0];
}
if(atkLow)
myBonus += (int)(myBonus * 5) / 100;
if(atkMid)
myBonus += (int)(myBonus * 10) / 100;
if(atkHigh)
myBonus += (int)(myBonus * 15) / 100;
if(boostAtk){
myBonus += (int)(myBonus * atkBoost) / 100;
boostAtk = false;
}
return myBonus;
case Melee.RANGE:
if(playerBonus[5] > 0) return playerBonus[5] + playerLevel[4];
if(playerBonus[5] < 1) return (playerBonus[5]*2)+playerLevel[4];
case Melee.MAGIC:
if(playerBonus[3] > 0) return playerBonus[3] + playerLevel[6];
if(playerBonus[3] < 1) return (playerBonus[3] * 2) + playerLevel[6];
default:
return 0;
}
}
public int mageDef(){
if(playerBonus[8] > 0) return (playerBonus[8] + (playerLevel[0]/2));
if(playerBonus[8] < 1) return (playerBonus[8]) + (5);
return 0;
}
public void appendHit(int damage, int type){
if ((playerLevel[3] - damage) < 0)
damage = playerLevel[3];
NewHP = (playerLevel[playerHitpoints] - damage);
playerLevel[playerHitpoints] = NewHP;
if (NewHP <= 0) {
NewHP = 0;
IsDead = true;
}
if(type == 1) poisondmg = true;
if(hitUpdateRequired == false){
hitDiff = damage;
hitUpdateRequired = true;
updateRequired = true;
} else {
hitDiff2 = damage;
hitUpdate2Required = true;
updateRequired = true;
}
}
public void appendGfx(int gfx, int height) {
mask100var1 = gfx;
mask100var2 = 65536 * height;
mask100update = true;
updateRequired = true;
}
public int attackOn(){
return AttackingOn;
}
public void walkTo(int x, int y) {
client client = (client)this;
newWalkCmdSteps = (Math.abs((x+y)));
if(newWalkCmdSteps % 2 != 0)
newWalkCmdSteps /= 2;
if(++newWalkCmdSteps > walkingQueueSize) {
// println("Warning: WalkTo("+packetType+") command contains too many steps ("+newWalkCmdSteps+").");
newWalkCmdSteps = 0;
}
int firstStepX = absX;
int tmpFSX = firstStepX;
firstStepX -= mapRegionX*8;
for(i = 1; i < newWalkCmdSteps; i++) {
newWalkCmdX[i] = x;
newWalkCmdY[i] = y;
tmpNWCX[i] = newWalkCmdX[i];
tmpNWCY[i] = newWalkCmdY[i];
}
newWalkCmdX[0] = newWalkCmdY[0] = tmpNWCX[0] = tmpNWCY[0] = 0;
int firstStepY = absY;
int tmpFSY = firstStepY;
firstStepY -= mapRegionY*8;
newWalkCmdIsRunning = ((client.inStream.readSignedByteC() == 1));
for(i = 0; i < newWalkCmdSteps; i++) {
newWalkCmdX[i] += firstStepX;
newWalkCmdY[i] += firstStepY;
}
}
public void tele(int x, int y)
{
teleportToX = x;
teleportToY = y;
}
public int getDrawback(){
client p = (client)this;
switch(getAttackType()){
case 2:
switch(playerEquipment[playerArrows]){
case 882:
return 19;
case 884:
return 18;
case 886:
return 20;
case 888:
return 21;
case 890:
return 22;
case 892:
return 24;
}
break;
case 3:
if(Autocast.MagicType[p.Autocast_SpellIndex] != 2){
return Autocast.MageStartingGFX[p.Autocast_SpellIndex];
}
break;
}
return 0;
}
public int protect(){
if(protMelee == true) return 1;
else if(protRange == true) return 2;
else if(protMage == true) return 3;
else return 0;
}
public int projectileGfx(){
client p = (client)this;
switch(getAttackType()){
case 2:
switch(playerEquipment[playerArrows]){
case 882:
return 10;
case 884:
return 9;
case 886:
return 11;
case 888:
return 12;
case 890:
return 13;
case 892:
return 15;
case 4740:
return 28;
}
break;
case 3:
if(Autocast.MagicType[p.Autocast_SpellIndex] == 0){
return Autocast.MageMovingGFX[p.Autocast_SpellIndex];
}
break;
}
return 0;
}
then the same for NPC class
Code:
public void combatEffects(int i, Entity n){
switch(npcType){
case 2027:
if(misc.random(2) == 1){
if(HP + i > MaxHP) i = HP - MaxHP;
HP += i;
n.appendGfx(398, 100);
}
break;
default:
break;
}
}
public int getId(){
return npcId;
}
public int getFightType(){
return 1;
}
public long getLastHit(){
return lastHit;
}
public void setLastHit(long value){
lastHit = value;
}
public int protect(){
if(npcType == 1160) return 1;
else if(npcType == 1158) return 4;
else return 0;
}
public int attackingOn(){
return StartKilling;
}
public int getAttackType(){
switch(npcType){
case 2455:
case 2456:
case 2881:
case 2892:
return 2;
case 2457:
case 2882:
case 13:
return 3;
case 2440:
case 2443:
case 2446:
return 0;
default:
return 1;
}
}
public int getType(){
return 2;
}
public int getAttackAnim(){
return server.npcEmote.list.elementAt(npcType).attack();
}
public int defenceAnim(){
return WeaponEmotes.npcBlockanim(npcType);
}
public void requestAnim(int anim){
if(npcType >= 2440 && npcType <= 2448)
return;
animNumber = anim;
animUpdateRequired = true;
updateRequired = true;
}
public int getXCoord(){
return absX;
}
public int getYCoord(){
return absY;
}
public int checkBestBonus(){
return 1;
}
public int getDrawback(){
switch(npcType){
default:
return 0;
}
}
public int projectileGfx(){
return server.npcCombat.list.elementAt(npcType).projectile();
}
public int attackOn(){
return StartKilling;
}
public int hitGfx(){
return server.npcCombat.list.elementAt(npcType).endGfx();
}
public int maxHit(){
switch(npcType){
case 2025:
case 2027:
case 2028:
case 2029:
case 2030:
return 30;
case 2026:
return 30 + (MaxHP - HP) / 3;
default:
return Strength.getMaxHitNpc(this);
}
}
public void walkTo(int x, int y){
}
public int getAtk(){
for(int i = 0; i < 3000; i++){
if(server.npcHandler.NpcList[i] != null){
if(server.npcHandler.NpcList[i].npcId == npcType){
return server.npcHandler.NpcList[i].npcCombat;
}
}
}
return 0;
}
public int getDef(int wat){
for(int i = 0; i < 3000; i++){
if(server.npcHandler.NpcList[i] != null){
if(server.npcHandler.NpcList[i].npcId == npcType){
return server.npcHandler.NpcList[i].npcCombat + 1;
}
}
}
return 0;
}
public int mageDef(){
if(getAttackType() != Melee.MAGIC){
for(int i = 0; i < 3000; i++){
if(server.npcHandler.NpcList[i] != null){
if(server.npcHandler.NpcList[i].npcId == npcType){
return server.npcHandler.NpcList[i].npcCombat + 1;
}
}
}
} else {
for(int i = 0; i < 3000; i++){
if(server.npcHandler.NpcList[i] != null){
if(server.npcHandler.NpcList[i].npcId == npcType){
return server.npcHandler.NpcList[i].npcCombat / 100 - server.npcHandler.NpcList[i].npcCombat / 10;
}
}
}
}
return 0;
}
public void appendHit(int damage, int type){
if ((HP - damage) < 0) {
damage = HP;
}
if(type == 1) poisondmg = true;
if(!hitUpdateRequired){
hitDiff = damage;
updateRequired = true;
hitUpdateRequired = true;
} else {
hitDiff2 = damage;
updateRequired = true;
hitUpdateRequired2 = true;
}
}
public int fightType(){
return 0;
}
public void appendGfx(int gfx, int height){
GfxId = gfx;
GfxDelay = 0;
GfxHeight = 65536 * height;
GraphicsUpdateRequired = true;
}
then implement the Entity interface in both of those classes by adding
in the class' declaration(i think that's what it is, correct me if wrong)
so it ends up to be something like
Code:
public class Player implements Entity
{
and
Code:
public class NPC implements Entity
{
in NPCHandler, delete all of your attack methods
- AttackPlayer
- AttackPlayerMage
- AttackNpc
- AttackNpcMage
those should normally be there, maybe on another name, as i said names can vary
and in process search for
Code:
} else if (npcs[i].RandomWalk == false && npcs[i].IsUnderAttack == true) {
if(npcs[i].npcType == 2745 || npcs[i].npcType == 1645 || npcs[i].npcType == 509 || npcs[i].npcType == 1241 || npcs[i].npcType == 1246 || npcs[i].npcType == 1159 || npcs[i].npcType == 54 || npcs[i].npcType == 2025 || npcs[i].npcType == 2026 || npcs[i].npcType == 2027 || npcs[i].npcType == 2028 || npcs[i].npcType == 2029 || npcs[i].npcType == 2030){
NpcCombat.AttackPlayerMage(i);
} else {
NpcCombat.AttackPlayer(i);
FollowPlayerCB(i, npcs[i].StartKilling);
}
change that to
Code:
} else if (npcs[i].RandomWalk == false && npcs[i].IsUnderAttack == true) {
server.melee.attack(npcs[i], server.playerHandler.players.elementAt(npcs[i].StartKilling));
I'm using a vector for storing the players, so yours might be something like
Code:
server.playerHandler.players[npcs[i].StartKilling]
then search for
Code:
} else if (npcs[i].followingPlayer && npcs[i].followPlayer > 0 && server.playerHandler.players[npcs[i].followPlayer] != null) {
if(server.playerHandler.players[npcs[i].followPlayer].AttackingOn > 0) {
int follow = npcs[i].followPlayer;
npcs[i].StartKilling = server.playerHandler.players[follow].AttackingOn;
npcs[i].RandomWalk = true;
npcs[i].IsUnderAttack = true;
if(npcs[i].StartKilling > 0) {
if(npcs[i].npcType == 2745 || npcs[i].npcType == 1645 || npcs[i].npcType == 509 || npcs[i].npcType == 1241 || npcs[i].npcType == 1246 || npcs[i].npcType == 54 || npcs[i].npcType == 2025 || npcs[i].npcType == 2026 || npcs[i].npcType == 2027 || npcs[i].npcType == 2028 || npcs[i].npcType == 2029 || npcs[i].npcType == 2030){
NpcCombat.AttackPlayerMage(i);
} else {
NpcCombat.AttackPlayer(i);
FollowPlayerCB(i, npcs[i].StartKilling);
}
}
} else {
}
} else if (npcs[i].IsUnderAttackNpc == true) {
AttackNPC(i);
}
change it to
Code:
} else if (npcs[i].followingPlayer && npcs[i].followPlayer > 0 && server.playerHandler.players.elementAt(npcs[i].followPlayer) != null) {
if(server.playerHandler.players.elementAt(npcs[i].followPlayer).AttackingOn > 0) {
int follow = npcs[i].followPlayer;
npcs[i].StartKilling = server.playerHandler.players.elementAt(follow).AttackingOn;
npcs[i].RandomWalk = true;
npcs[i].IsUnderAttack = true;
if(npcs[i].StartKilling > 0) {
server.melee.attack(npcs[i], server.playerHandler.players.elementAt(npcs[i].StartKilling));
}
} else {
}
} else if (npcs[i].IsUnderAttackNpc == true) {
AttackNPC(i);
}
that should be all in npchandler, if not, please pm or post in this thread
but don't spam this thread
in client.java change your attack boolean to this
Code:
public void Attack() {
server.melee.attack(PlayerHandler.players.elementAt(playerId), server.playerHandler.players.elementAt(AttackingOn));
}
again, i used a vector here, yours will (propably) be
Code:
PlayerHandler.players[playerId], server.playerHandler.players[AttackingOn]
and your attacknpc boolean to this
Code:
public void AttackNPC() {
server.melee.attack(this, server.npcHandler.npcs[AttackingOn]);
}
now, i have made some easy CFG files to use in your server for adding npcs
very easily, so u can edit how they attack u, such as portals don't attack
back, wizards using magic, archers using range and warriors using range,
the only flaw here is that u can only have 1 attack per npc instead of
for example jad who uses all 3, but u can code that with a simple switch
add these classes:
NpcEmoteList:
Code:
public class NpcEmoteList
{
public NpcEmoteList(int attack, int defence, int death){
this.attack = attack;
this.defence = defence;
this.death = death;
}
public int attack;
public int defence;
public int death;
public int attack(){
return attack;
}
public int defence(){
return defence;
}
public int death(){
return death;
}
}
NpcEmote:
Code:
import java.io.File;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.Vector;
public class NpcEmote
{
public NpcEmote(String folder) throws IOException {
BufferedReader br;
File f = new File(folder);
if(f.exists()){
String s;
br = new BufferedReader(new FileReader(f));
while((s = br.readLine()) != null){
if(!s.startsWith("//")){
String[] numbers = s.split("\t");
NpcEmoteList npc = new NpcEmoteList(
Integer.parseInt(numbers[3]),
Integer.parseInt(numbers[4]),
Integer.parseInt(numbers[5]));
list.add(npc);
}
}
} else {
System.out.println("[NpcEmote] Can't find the combat.cfg !");
}
br = null;
}
public Vector<NpcEmoteList> list = new Vector<NpcEmoteList>();
}
NpcCombatlist:
Code:
public class NpcCombatList
{
public NpcCombatList(int npcId, int emt, int dmg, int sGfx, int proj, int eGfx){
newNPCL(npcId, emt, dmg, sGfx, proj, eGfx);
}
public void newNPCL(int npcId, int emt, int dmg, int sGfx, int proj, int eGfx){
this.npcId = npcId;
if(emt > 0)
emotes = emt;
else emotes = -1;
if(dmg > 0)
damage = dmg;
else damage = -1;
if(sGfx > 0)
startGfx = sGfx;
else startGfx = -1;
if(proj > 0)
projectile = proj;
else proj = -1;
if(eGfx > 0)
endGfx = eGfx;
else endGfx = -1;
}
public int npcId;
public int emotes;
public int damage;
public int startGfx;
public int projectile;
public int endGfx;
public int npcId(){
return npcId;
}
public int emotes(){
return emotes;
}
public int damage(){
return damage;
}
public int startGfx(){
return startGfx;
}
public int projectile(){
return projectile;
}
public int endGfx(){
return endGfx;
}
}
NpcCombat:
Code:
import java.io.File;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.Vector;
public class NpcCombat
{
public NpcCombat(String folder) throws IOException {
BufferedReader br;
File f = new File(folder);
if(f.exists()){
String s;
br = new BufferedReader(new FileReader(f));
while((s = br.readLine()) != null){
if(!s.startsWith("//")){
if(s.equals("[END]")) break;
String[] numbers = s.split("\t");
NpcCombatList npc = new NpcCombatList(
Integer.parseInt(numbers[2]),
Integer.parseInt(numbers[3]),
Integer.parseInt(numbers[4]),
Integer.parseInt(numbers[4]),
Integer.parseInt(numbers[6]),
Integer.parseInt(numbers[7]));
list.add(npc);
}
}
} else {
System.out.println("[NpcCombat] Can't find the combat.cfg !");
}
br = null;
}
public Vector<NpcCombatList> list = new Vector<NpcCombatList>();
}
then in server add these:
Code:
public static NpcCombat npcCombat;
public static NpcEmote npcEmote;
public static Melee melee;
and this where all classes are loaded (well, most of them)
Code:
melee = new Melee();
npcCombat = new NpcCombat("npc/combat.cfg");
npcEmote = new NpcEmote("npc/emote.cfg");
also, add the SpecialAttacks class, which i nearly forgot
Code:
public class SpecialAttacks
{
public int ReturnPlayerSpecGfx(int i) {
switch(i){
case 5698:
return 252;
case 1305:
return 248;
case 7158:
return 559;
case 1434:
return 251;
case 4587:
return 347;
case 861:
return 256;
case 859:
return 250;
case 6724:
return 472;
case 3204:
return 285;
case 4153:
return 340;
case 1249:
return 253;
default:
return 0;
}
}
public int ReturnOtherGfx(int i) {
switch(i){
case 4151:
return 341;
case 1249:
return 254;
case 8039:
return 631;
default:
return 0;
}
}
public int SpecDrainAmount(int i) {
switch(i){
case 5698:
case 1434:
case 3204:
case 1305:
case 1249:
case 859:
return 25;
case 4151:
case 4153:
case 7158:
case 861:
return 50;
case 4587:
return 75;
case 6724:
case 6739:
return 100;
default:
return 0;
}
}
public int StartSpecEmote(int i) {
switch(i){
case 5698:
return 1062;
case 4151:
return 1658;
case 7158:
return 3157;
case 1305:
return 1058;
case 1434:
return 1060;
case 4587:
return 1872;
case 861:
return 1074;
case 859:
case 6724:
return 426;
case 4153:
return 1667;
case 3204:
return 1203;
case 1249:
return 405;
case 6739:
return 2876;
case 805:
return 806;
default:
return 0;
}
}
public boolean need2ndHit(int i){
if(i == 5698 || i == 1231 || i == 1215 || i == 5680) return true;
else return false;
}
}
that's everything i hope, now add this folder to your server
http://files.filefront.com/npcrar/;1.../fileinfo.html
NOTE: if u have ANY error, please contact me or someone else if the error
is not clear this took me quite the while to make, so please don't
leech this, i don't give a shit if u do, but i would really appreciate
some credits or comments on this because it's the only attempt on
a good combat system that's not half assed(well, this is half assed,
but it's much better than that deltascape shit or the richscape
crap u see these days)
NOTE 2: BACKUP YOUR FUCKING FILES BEFORE U ATTEMPT THIS, I PUT THIS AT THE
BOTTOM OF THE PAGE SO U PROPABLY DIDNT LOL
credits (these are not only credits for this):
- GRAHAMS EVENT MANAGER ALL THE WAY, deserves capitals for its awesomeness
- Dophert, because he (I) made this
- Hayzie, for trying to help me fix some T2 errors this causes
- Josh, he owns
- Rhys, for being offline every fucking time i try to ask something
- Lee, for being a fag
- Sub, first guy ever from rune-server to go in my msn
- G (gnarly), for being polite enough to help me with something with CFG loading
- my parents, for having sex with me as result
- my parents, yet again, for having more sex resulting in 2 brothers and 1 sister
- you for reading
- much much more ;D
PS: if u don't get how to add new npcs into the combat system, just pm me, or ask here
if i add to much more, my mozilla will just crash, so tyvm for reading i hope u enjoy
I RELEASED THIS BECAUSE I THINK MORE PEOPLE SHOULD RELEASE THINGS THEY
MAKE, I DONT GIVE A SHITTING FUCK ABOUT LEECHERS AND NEITHER SHOULD U