1 Attachment(s)
[Huge-Tut]MagicHandler.java [Basically full magic]..
Todays date: [4/27/07] Time: [8:54 PM - Eastern]
Spells this includes;
- All modern battle spells
- All God spells + Charge spell
- Confuse, Weaken & Curse spells
- All Ancient projectile spells
- All Ancient multi-target spells
Spell features;
Quote:
~~~~~~~~
Confuse :: Reduces the NPC's maximum hit power for 2 minutes
--------------
Smoke spells :: Poison NPC's for 2 minutes
Blood spells :: Heal you for what damage you hit
Shadow spells :: Reduce the NPC's maximum hit power for 2 minutes
Ice spells :: Prevents the NPC from walking
~~~~~~~~
This is only for player on npc. If you want it to work for players too, you will have to edit the code yourself. Mainly because I'm using winterloves and I can't be bothered to add Player on player.
[PLEASE NOTE]
Quote:
This is my own personal code. I didn't leech it from anywhere and it took me 2 days to code it. If you see it posted anywhere else then that person ripped it from here.
Also; This does not include the 'Vulnerability', 'Enfeeble' & 'Stun' spell because I do not know the projectile ids for them. If you wish to have them you can add them to the cfg file.
~~~~~~~~~~~~~~~~~~~~~~~~~~
Step 1:
Replace your magic packet with this:
Code:
case 131: //Magic on NPCS
int npcIndex = inStream.readSignedWordBigEndianA();
int spell = inStream.readSignedWordA();
System.out.println("SpellID - "+spell);
int EnemyX2 = server.npcHandler.npcs[npcIndex].absX;
int EnemyY2 = server.npcHandler.npcs[npcIndex].absY;
int EnemyHP2 = server.npcHandler.npcs[npcIndex].HP;
int casterX = absX;
int casterY = absY;
int offsetY = (casterX - EnemyX2) * -1;
int offsetX = (casterY - EnemyY2) * -1;
int X = absX;
int Y = absY;
if (EnemyHP2 == 0 || server.npcHandler.npcs[npcIndex].IsDead)
{
TurnPlayerTo(EnemyX2, EnemyY2);
updateRequired = true;
appearanceUpdateRequired = true;
teleportToX = absX;
teleportToY = absY;
sendMessage("This npc is already dead.");
return;
}
TurnPlayerTo(EnemyX2, EnemyY2);
updateRequired = true;
appearanceUpdateRequired = true;
teleportToX = absX;
teleportToY = absY;
MagicHandler.npcX = EnemyX2;
MagicHandler.npcY = EnemyY2;
MagicHandler.npcHP = EnemyHP2;
MagicHandler.npcIndex = npcIndex;
MagicHandler.MagicSpell(spell, playerId, MultiTargetSpell(spell), StillSpell(spell), playerLevel[6]);
break;
Step 2:
Add these:
Code:
/*
* These are all the ancient spells that are multi-target ;)
*/
public boolean MultiTargetSpell(int i)
{
if (i == 12963 || i == 13011 || i == 12919 || i == 12881 || i == 12975 || i == 13023 || i == 12929 || i == 12891)
{
return true;
}
return false;
}
/*
* These are mainly god spells since they aren't multi-target
*/
public boolean StillSpell(int i)
{
if (i == 1190 || i == 1191 || i == 1192)
{
return true;
}
return false;
}
/*
* ==========================================
* Damage npc and delete runes when the last
* GFX has hit the npc, if the hit is
* succesful.
* ==========================================
* Copyright© Mr. Brightsite 2007
*/
public void appendHitToNpc(int index, int hitDiff, boolean stillSpell) //Used for MagicHandler
{
if (hitDiff != 0)
{
if (stillSpell)
{
isStillSpell = false;
stillgfx2(stillSpellGFX, MagicHandler.graphicHeight, MagicHandler.npcY, MagicHandler.npcX, 2);
stillSpellGFX = -1;
}
if ((MagicHandler.npcHP - hitDiff < 0)) {
hitDiff = MagicHandler.npcHP;
}
if (MagicHandler.itHeals)
{
if (misc.random(2) == 1)
{
NewHP = (playerLevel[playerHitpoints] + (hitDiff / 4));
if(NewHP >= getLevelForXP(playerXP[playerHitpoints])){
NewHP = getLevelForXP(playerXP[playerHitpoints]);
}
sendMessage("You drain the enemies health.");
refreshSkills();
}
}
if (MagicHandler.itFreezes)
{
sendMessage(""+getFrozenMessage(MagicHandler.spellID)+"");
if (server.npcHandler.npcs[index].freezeTimer <= 0)
{
server.npcHandler.npcs[index].freezeTimer = getFreezeTimer(MagicHandler.spellID);
}
}
if (MagicHandler.itReducesAttack)
{
if (misc.random(2) == 1)
{
if (server.npcHandler.npcs[index].reducedAttack <= 0)
{
sendMessage("You reduce the enemies attack power.");
server.npcHandler.npcs[index].MaxHit -= (hitDiff / 2);
if ((server.npcHandler.npcs[index].MaxHit - (hitDiff / 2)) < server.npcHandler.npcs[index].MaxHit)
{
server.npcHandler.npcs[index].MaxHit = 0;
}
server.npcHandler.npcs[index].reducedAttack = getAttackTimer(MagicHandler.spellID);
}
}
}
if (MagicHandler.itPoisons)
{
if (misc.random(2) == 1)
{
if (server.npcHandler.npcs[index].poisonTimer <= 0)
{
sendMessage("You poison the enemy.");
server.npcHandler.npcs[index].poisonTimer = 120;
server.npcHandler.npcs[index].poisonDmg = true;
server.npcHandler.poisonNpc(index);
}
}
}
deleteItem(rune1, getItemSlot(rune1), rune1Am);
deleteItem(rune2, getItemSlot(rune2), rune2Am);
deleteItem(rune3, getItemSlot(rune3), rune3Am);
deleteItem(rune4, getItemSlot(rune4), rune4Am);
addSkillXP((spellXP), 6);
addSkillXP((spellXP / 2), 3);
server.npcHandler.npcs[index].hitDiff = hitDiff;
server.npcHandler.npcs[index].Killing[playerId] += hitDiff;
server.npcHandler.npcs[index].updateRequired = true;
server.npcHandler.npcs[index].hitUpdateRequired = true;
}
}
public String getFrozenMessage(int spell)
{
if (spell == 12861 || spell == 12881 || spell == 12871 || spell == 12891)
{
return "You freeze the enemy.";
}
if (spell == 1572)
{
return "You bind the enemy.";
}
if (spell == 1582)
{
return "You snare the enemy.";
}
if (spell == 1592)
{
return "You entangle the enemy.";
}
return "You freeze the enemy.";
}
public int getFreezeTimer(int spell)
{
if (spell == 12861)
{
return 10;
}
if (spell == 12881)
{
return 20;
}
if (spell == 12871)
{
return 30;
}
if (spell == 12891)
{
return 40;
}
if (spell == 1572)
{
return 10;
}
if (spell == 1582)
{
return 20;
}
if (spell == 1592)
{
return 30;
}
return 10;
}
public int getAttackTimer(int spell)
{
if (spell == 12987)
{
return 10;
}
if (spell == 13011)
{
return 20;
}
if (spell == 12999)
{
return 30;
}
if (spell == 13023)
{
return 40;
}
if (spell == 1153)
{
return 10;
}
return 10;
}
Step 3:
Add this under process:
Code:
if (arenaSpellTimer > 0)
{
arenaSpellTimer--;
}
if (arenaSpellTimer == 0)
{
if (SaradominStrike)
{
SaradominStrike = false;
sendMessage("Your Saradomin Strike's power has returned to normal.");
}
if (GuthixClaws)
{
GuthixClaws = false;
sendMessage("Your Claws of Guthix's power has returned to normal.");
}
if (ZamorakFlames)
{
ZamorakFlames = false;
sendMessage("Your Flames of Zamorak's power has returned to normal.");
}
}
if (spellHitTimer > 0)
{
spellHitTimer--;
}
if (spellHitTimer == 0)
{
if (castSpell)
{
castSpell = false;
appendHitToNpc(MagicHandler.npcIndex, MagicHandler.hitDiff2, isStillSpell);
}
}
Step 4:
Find case 185 and add this:
Code:
case 4169: //Charge arena spells
if (arenaSpellTimer <= 0)
{
if (!playerHasItemAmount(554, 3) || !playerHasItemAmount(565, 3) || !playerHasItemAmount(556, 3))
{
sendMessage("You don't have enough runes to cast this spell.");
}
else
{
if (playerHasItemAmount(554, 3) && playerHasItemAmount(565, 3) && playerHasItemAmount(556, 3))
{
if (playerEquipment[playerCape] == 2412 || playerEquipment[playerCape] == 2413 || playerEquipment[playerCape] == 2414)
{
deleteItem(554, getItemSlot(554), 3);
deleteItem(565, getItemSlot(565), 3);
deleteItem(556, getItemSlot(556), 3);
startAnimation(1820);
stillgfx(441, absY, absX);
arenaSpellTimer = 120; //2 Minutes
if (playerEquipment[playerCape] == 2412)
{
SaradominStrike = true;
sendMessage("You summon the power of the gods and increase your Saradomin Strike's power.");
}
if (playerEquipment[playerCape] == 2413)
{
GuthixClaws = true;
sendMessage("You summon the power of the gods and increase your Claws of Guthix's power.");
}
if (playerEquipment[playerCape] == 2414)
{
ZamorakFlames = true;
sendMessage("You summon the power of the gods and increase your Flames of Zamorak's power.");
}
}
else
{
sendMessage("You need to be wearing a god cape to cast this spell.");
}
}
}
}
else
{
sendMessage("Your god spell is at it's full power.");
}
break;
Step 5:
Add this void:
Code:
public void multiTargetNPC(int spellId, int maxDamage, int range)
{
for(int i = 0; i < server.npcHandler.maxNPCs; i++)
{
if (server.npcHandler.npcs[i] != null)
{
if (distanceToPoint(server.npcHandler.npcs[i].absX, server.npcHandler.npcs[i].absY) <= range && !server.npcHandler.npcs[i].IsDead)
{
if (server.npcHandler.npcs[i].heightLevel == heightLevel)
{
int damage = misc.random(maxDamage);
if (damage == 0)
{
stillgfx2(85, MagicHandler.graphicHeight, server.npcHandler.npcs[i].absY, server.npcHandler.npcs[i].absX, 2);
}
else
{
if (server.npcHandler.npcs[i].HP >= 0)
{
if (server.npcHandler.npcs[i].HP - damage < 0)
{
damage = server.npcHandler.npcs[i].HP;
}
int myHP = playerLevel[playerHitpoints];
if (MagicHandler.itHeals)
{
if (misc.random(2) == 1)
{
NewHP = (playerLevel[playerHitpoints] + (hitDiff / 4));
if(NewHP >= getLevelForXP(playerXP[playerHitpoints])){
NewHP = getLevelForXP(playerXP[playerHitpoints]);
}
sendMessage("You drain the enemies health.");
refreshSkills();
}
}
if (MagicHandler.itFreezes)
{
sendMessage(""+getFrozenMessage(MagicHandler.spellID)+"");
if (server.npcHandler.npcs[i].freezeTimer <= 0)
{
server.npcHandler.npcs[i].freezeTimer = getFreezeTimer(MagicHandler.spellID);
}
}
if (MagicHandler.itReducesAttack)
{
if (misc.random(2) == 1)
{
if (server.npcHandler.npcs[i].reducedAttack <= 0)
{
sendMessage("You reduce the enemies attack power.");
server.npcHandler.npcs[i].MaxHit -= (hitDiff / 2);
if ((server.npcHandler.npcs[i].MaxHit - (hitDiff / 2)) < server.npcHandler.npcs[i].MaxHit)
{
server.npcHandler.npcs[i].MaxHit = 0;
}
server.npcHandler.npcs[i].reducedAttack = getAttackTimer(MagicHandler.spellID);
}
}
}
if (MagicHandler.itPoisons)
{
if (misc.random(2) == 1)
{
if (server.npcHandler.npcs[i].poisonTimer <= 0)
{
sendMessage("You poison the enemy.");
server.npcHandler.npcs[i].poisonTimer = 120;
server.npcHandler.npcs[i].poisonDmg = true;
server.npcHandler.poisonNpc(i);
}
}
}
stillgfx2(spellId, MagicHandler.graphicHeight, server.npcHandler.npcs[i].absY, server.npcHandler.npcs[i].absX, 2);
server.npcHandler.npcs[i].hitDiff = damage;
server.npcHandler.npcs[i].Killing[playerId] += damage;
server.npcHandler.npcs[i].updateRequired = true;
server.npcHandler.npcs[i].hitUpdateRequired = true;
}
}
}
}
}
}
}
Step 6:
Find this line under your firespell boolean:
Code:
stillgfx2(finishID, 100, enemyY, enemyX, 95);
Replace that line with this:
Code:
stillgfx2(finishID, MagicHandler.graphicHeight, enemyY, enemyX, 95);
Step 7:
Save and close your client.java then open up player.java and add these:
Code:
public int spellHitTimer;
public boolean castSpell, isStillSpell;
public int stillSpellGFX;
public int rune1, rune1Am, rune2, rune2Am, rune3, rune3Am, rune4, rune4Am, spellXP;
public int arenaSpellTimer;
public boolean SaradominStrike, GuthixClaws, ZamorakFlames;
Step 8:
Save and close your player.java and open up your NPC.java. Add these:
Code:
public int freezeTimer, poisonTimer, poisonDelay, reducedAttack;
public boolean poisonDmg;
Step 9:
Find this void:
Code:
public void getNextNPCMovement()
Replace that whole void with this:
Code:
public void getNextNPCMovement() {
if (freezeTimer <= 0){
direction = -1;
direction = getNextWalkingDirection();
}
}
Step 10:
Find this void:
Code:
protected void appendHitUpdate(stream str)
Replace that whole void with this:
Code:
protected void appendHitUpdate(stream str) {
try {
HP -= hitDiff;
if (HP <= 0) {
IsDead = true;
}
str.writeByteC(hitDiff); // What the npc got 'hit' for
if (hitDiff > 0 && !poisonDmg) {
str.writeByteS(1); // 0: red hitting - 1: blue hitting
} else if (hitDiff > 0 && poisonDmg) {
str.writeByteS(2); // 0: red hitting - 1: blue hitting
} else {
str.writeByteS(0); // 0: red hitting - 1: blue hitting
}
str.writeByteS(HP); // Their current hp, for HP bar
str.writeByteC(MaxHP); // Their max hp, for HP bar
poisonDmg = false;
} catch(Exception e) {
e.printStackTrace();
}
}
Step 11:
Save and close NPC.java and open your NpcHandler.java. Add this void:
Code:
public void poisonNpc(int index)
{
npcs[index].poisonDmg = true;
npcs[index].poisonDelay = misc.random(60);
npcs[index].hitDiff = misc.random(5);
npcs[index].hitDiff = npcs[index].hitDiff;
npcs[index].updateRequired = true;
npcs[index].hitUpdateRequired = true;
}
Step 12:
Add this under process:
Code:
if (npcs[i].freezeTimer > 0) {
npcs[i].freezeTimer--;
}
if (npcs[i].reducedAttack > 0) {
npcs[i].reducedAttack--;
}
if (npcs[i].reducedAttack == 0) {
npcs[i].MaxHit = (int)Math.floor((npcs[i].MaxHP / 10));
}
if (npcs[i].poisonTimer > 0) {
npcs[i].poisonTimer--;
}
if (npcs[i].poisonTimer == 0) {
npcs[i].poisonDmg = false;
npcs[i].poisonDelay = -1;
}
if (npcs[i].poisonDelay > 0) {
npcs[i].poisonDelay--;
}
if (npcs[i].poisonTimer > 0 && npcs[i].poisonDelay == 0){
poisonNpc(i);
}
Step 13:
Make a new file named "magicSpells.cfg" and put this inside it:
Code:
//
// magicSpells.cfg
//
// ===================================
// Copyright© Mr. Brightsite 2007
// ===================================
//
// ===================================
// NOTE:
// You may edit these numbers
// if you wish.
//
// ===================================
//
// =========================================
// Uses First:
// This defines wether the spell
// uses a launch gfx, like modern.
// Need to use this because ancient
// spells don't use a launch graphic.
// ----
// 1 = Yes
// 0 = No
// ----
//
// ========
// MODERN
// ========
//------ID------emote--gfx----usesFirst-lvl----rune1--rune1am--rune2---rune2am--rune3--rune3am--rune4--rune4am-item---hitdiff--XP-----projH.--EndH.----SpellName
spell = 1152 711 90 1 1 558 1 556 1 -1 0 -1 0 -1 2 6 43 100 Wind_Strike
spell = 1153 1165 108 1 3 555 3 557 2 559 1 -1 0 -1 0 13 43 100 Confuse
spell = 1154 711 93 1 5 555 1 556 1 558 1 -1 0 -1 4 8 43 100 Water_Strike
spell = 1156 711 96 1 9 557 2 556 1 558 1 -1 0 -1 6 10 43 100 Earth_Strike
spell = 1157 1164 105 1 11 555 3 557 2 559 1 -1 0 -1 0 21 43 100 Weaken
spell = 1158 711 99 1 13 554 3 556 2 558 1 -1 0 -1 8 12 43 100 Fire_Strike
spell = 1160 711 117 1 17 556 2 562 1 -1 0 -1 0 -1 9 14 43 100 Air_Bolt
spell = 1161 1163 102 1 19 555 2 557 3 559 1 -1 0 -1 0 29 43 100 Curse
spell = 1163 711 120 1 23 555 2 556 2 562 1 -1 0 -1 11 17 43 100 Water_Bolt
spell = 1572 1164 177 1 20 557 3 555 3 561 2 -1 0 -1 0 30 43 100 Bind
spell = 1166 711 123 1 29 557 3 556 2 562 1 -1 0 -1 12 20 43 100 Eath_Bolt
spell = 1169 711 126 1 35 554 4 556 3 562 1 -1 0 -1 13 22 43 100 Fire_Bolt
spell = 1171 1165 145 1 39 557 2 556 2 562 1 -1 0 -1 15 25 43 100 Crumble_Undead
spell = 1172 711 132 1 41 556 3 560 1 -1 0 -1 0 -1 13 26 43 100 Air_Blast
spell = 1175 711 135 1 47 555 3 556 3 560 1 -1 0 -1 14 29 43 100 Water_Blast
spell = 1539 708 87 1 50 554 5 560 1 -1 0 -1 0 1409 25 30 43 100 Iban_Blast
spell = 1582 1164 177 1 50 557 4 555 4 561 2 -1 0 -1 0 60 43 100 Snare
spell = 12037 1978 327 1 50 560 1 558 4 -1 0 -1 0 4170 19 30 43 100 Magic_Dart
spell = 1177 711 138 1 53 555 3 557 4 560 1 -1 0 -1 15 32 43 100 Earth_Blast
spell = 1181 711 129 1 59 556 4 554 5 560 1 -1 0 -1 16 35 43 100 Fire_Blast
spell = 1183 1167 158 1 62 556 5 565 1 -1 0 -1 0 -1 17 36 43 100 Air_Wave
spell = 1185 1167 161 1 65 556 5 565 1 555 7 -1 0 -1 18 38 43 100 Water_Wave
spell = 1188 1167 164 1 70 556 5 565 1 557 7 -1 0 -1 19 40 43 100 Earth_Wave
spell = 1189 1167 155 1 75 556 5 565 1 554 7 -1 0 -1 20 43 43 100 Fire_Wave
spell = 1592 1164 177 1 79 557 5 555 5 561 4 -1 0 -1 0 89 43 100 Entangle
// =========
// ANCIENT
// =========
spell = 12939 1978 383 0 50 562 2 560 2 554 1 556 1 4675 13 30 43 50 Smoke_Rush
spell = 12987 1978 377 0 52 562 2 560 2 556 1 566 1 4675 14 31 43 0 Shadow_Rush
spell = 12901 1978 371 0 56 562 2 560 2 565 1 -1 0 4675 15 33 0 0 Blood_Rush
spell = 12861 1978 359 0 58 562 2 560 2 555 2 -1 0 4675 16 34 0 0 Ice_Rush
spell = 12951 1978 385 0 74 560 2 565 2 554 2 556 2 4675 26 42 43 50 Smoke_Blitz
spell = 12999 1978 379 0 76 560 2 565 2 556 2 566 2 4675 24 43 43 0 Shadow_Blitz
spell = 12911 1978 373 0 80 560 2 565 4 -1 0 -1 0 4675 25 45 0 0 Blood_Blitz
spell = 12871 1978 365 0 82 560 2 565 2 555 3 -1 0 4675 26 46 0 0 Ice_Blitz
// =========================
// MODERN - NON PROJECTILE
// =========================
spell = 1190 811 76 0 60 554 2 565 2 556 4 -1 0 2415 20 61 100 100 Saradomin_Strike
spell = 1191 811 77 0 60 554 1 565 2 556 4 -1 0 2416 20 61 100 100 Claws_Of_Guthix
spell = 1192 811 78 0 60 554 4 565 2 556 1 -1 0 2417 20 61 0 0 Flames_Of_Zamorak
// ==========================
// ANCIENT - NON PROJECTILE
// ==========================
spell = 12963 1979 387 0 62 562 4 560 2 554 2 556 2 4675 17 36 0 0 Smoke_Burst
spell = 13011 1979 382 0 64 562 4 560 2 556 2 566 2 4675 17 34 0 0 Shadow_Burst
spell = 12919 1979 373 0 68 562 4 560 2 565 2 -1 0 4675 21 39 0 0 Blood_Burst
spell = 12881 1979 363 0 70 560 2 562 4 555 4 -1 0 4675 22 40 0 0 Ice_Burst
spell = 12975 1979 390 0 86 560 4 565 2 554 4 557 4 4675 27 48 0 0 Smoke_Barrage
spell = 13023 1979 383 0 88 560 4 565 2 556 4 566 3 4675 28 48 0 0 Shadow_Barrage
spell = 12929 1979 377 0 92 560 4 565 4 566 1 -1 0 4675 29 51 0 0 Blood_Barrage
spell = 12891 1979 369 0 94 560 4 565 2 555 6 -1 0 4675 30 52 0 0 Ice_Barrage
[EOF]
Step 14:
Download my MagicHandler in the attachment below and rename it to "MagicHandler.java"
Step 15:
Run your server and enjoy :d
EDIT: Almost forgot;
Add this in GraphicsHandler.java:
Code:
public static void createNormalSpell(int castId, int casterY, int casterX, int offsetY, int offsetX, int angle, int speed, int movegfxID ,int startHeight, int endHeight, int MageAttackIndex, int finishID, int enemyY, int enemyX) {
for (Player p : server.playerHandler.players) {
if(p != null) {
client person = (client)p;
if((person.playerName != null || person.playerName != "null"))
person.firespell(castId, casterY, casterX, offsetY, offsetX, angle, speed, movegfxID, startHeight, endHeight, MageAttackIndex, finishID, enemyY, enemyX);}
}
}
Quote:
Credits go to - Me (Mr. Brightside) 95%, Xerozcheez 5% (For decoding magic)
Rep would be appreciated since you guys don't really deserve full magic from a 2 day job