Create a new class and call it CombatFormulas.java, add this in it:
NOTE: It's not compulsory to create a new class, it's just that I'm organised and like to keep things clean.
Code:
package server.model.combat;
import server.model.players.Client;
/**
*
*
* @author Rhubarb
*
*/
public class CombatFormulas {
/**
* Is the player in the diagonal block: formula.
* @param attacked
* @param attacker
* @return
*/
public final static boolean isInDiagonalBlock(Client attacked, Client attacker) {
return attacked.absX - 1 == attacker.absX
&& attacked.absY + 1 == attacker.absY
|| attacker.absX - 1 == attacked.absX
&& attacker.absY + 1 == attacked.absY
|| attacked.absX + 1 == attacker.absX
&& attacked.absY - 1 == attacker.absY
|| attacker.absX + 1 == attacked.absX
&& attacker.absY - 1 == attacked.absY
|| attacked.absX + 1 == attacker.absX
&& attacked.absY + 1 == attacker.absY
|| attacker.absX + 1 == attacked.absX
&& attacker.absY + 1 == attacked.absY;
}
/**
* Stops the diagonal attack, if they're in that region.
* @param attacked
* @param attacker
*/
public static void stopDiagonalAttack(Client attacked, Client attacker) {
if (attacker.freezeTimer > 0) {
attacker.sendMessage("A magical force stops you from moving.");
attacker.getCombat().resetPlayerAttack();
} else {
int xMove = attacked.getX() - attacker.getX();
int yMove = 0;
if (xMove == 0)
yMove = attacked.getY() - attacker.getY();
int k = attacker.getX() + xMove;
k -= attacker.mapRegionX * 8;
attacker.getNewWalkCmdX()[0] = attacker.getNewWalkCmdY()[0] = 0;
int l = attacker.getY() + yMove;
l -= attacker.mapRegionY * 8;
for (int n = 0; n < attacker.newWalkCmdSteps; n++) {
attacker.getNewWalkCmdX()[n] += k;
attacker.getNewWalkCmdY()[n] += l;
}
}
}
}
You can also re-use this for other combat formulas, so don't just use it for the diagonal fix - thank you.
Now go into CombatAssistant.java:
Add this method underneath public void playerDelayedHit:
Code:
/**
* Diagonal fix, not using magic.
*/
if (CombatFormulas.isInDiagonalBlock(c, o) && c.projectileStage == 0
&& !c.usingMagic) {
CombatFormulas.stopDiagonalAttack(c, o);
return;
}
o.playerIndex = c.playerId;
}
Underneath public boolean checkReqs:
Code:
Client opponent = (Client) PlayerHandler.players[c.playerIndex];
if (!c.getCombat().usingHally() && !c.usingBow && !c.usingMagic
&& !c.autocasting && c.spellId <= 0
&& CombatFormulas.isInDiagonalBlock(opponent, c))
CombatFormulas.stopDiagonalAttack(opponent, c);
if (!opponent.getCombat().usingHally() && !opponent.usingBow
&& !opponent.usingMagic && !opponent.autocasting
&& opponent.spellId <= 0 && CombatFormulas.isInDiagonalBlock(c, opponent))
CombatFormulas.stopDiagonalAttack(c, opponent);
You may have to modify some methods to make it fit with your PI, if not .
Credits: whoever made the diagonal code.