Thread: Diagonal combat fix - Project Insanity

Page 1 of 3 123 LastLast
Results 1 to 10 of 23
  1. #1 Diagonal combat fix - Project Insanity 
    Registered Member

    Join Date
    May 2012
    Posts
    253
    Thanks given
    5
    Thanks received
    146
    Rep Power
    122
    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.
    Reply With Quote  
     

  2. Thankful user:


  3. #2  
    Banned

    Join Date
    Apr 2012
    Age
    27
    Posts
    2,936
    Thanks given
    1,126
    Thanks received
    1,081
    Rep Power
    0
    looks cool, will try.
    Reply With Quote  
     

  4. #3  
    強い者は生き残る
    Ashpire's Avatar
    Join Date
    Mar 2012
    Age
    27
    Posts
    2,721
    Thanks given
    914
    Thanks received
    1,897
    Rep Power
    2231
    looks good
    Attached image
    Reply With Quote  
     

  5. #4  
    Registered Member I'mAGeek's Avatar
    Join Date
    Jan 2012
    Age
    28
    Posts
    504
    Thanks given
    146
    Thanks received
    44
    Rep Power
    16
    Well done
    Reply With Quote  
     

  6. #5  
    Super Donator


    Join Date
    Jun 2007
    Age
    31
    Posts
    2,157
    Thanks given
    316
    Thanks received
    282
    Rep Power
    779
    If they're not in a straight line, they must be diagonal so

    Code:
    return !((attacker.absX == attacked.absX) || (attacker.absY == attacked.absY));
    Reply With Quote  
     

  7. #6  
    Registered Member

    Join Date
    Dec 2008
    Posts
    1,010
    Thanks given
    0
    Thanks received
    1
    Rep Power
    271
    All you really need is something like this
    Code:
    	private static void ensureParallelity(Entity follower, Entity following) {
    		if (follower.getLocation().getDistanceTo(following.getLocation()) == 1) {
    			if (follower.getLocation().getX() - following.getLocation().getX() > 0) {
    				follower.getWalkingQueue().addDisciminentStep(follower.getLocation().getX() - 1, follower.getLocation().getY());
    			} else if (follower.getLocation().getX() - following.getLocation().getX() < 0) {
    				follower.getWalkingQueue().addDisciminentStep(follower.getLocation().getX() + 1, follower.getLocation().getY());
    			} else if (follower.getLocation().getY() - following.getLocation().getY() > 0) {
    				follower.getWalkingQueue().addDisciminentStep(follower.getLocation().getX(), follower.getLocation().getY() - 1);
    			} else {
    				follower.getWalkingQueue().addDisciminentStep(follower.getLocation().getX(), follower.getLocation().getY() + 1);
    			}
    			follower.getWalkingQueue().processNextMovement();
    		}
    	}
    	
    	private static boolean checkParallelity(Entity follower, Entity following) {
    		return follower.getLocation().getX() != following.getLocation().getX() && follower.getLocation().getY() != following.getLocation().getY();
    	}
    Have the parallelity of the fighting NPC/player's be checked when their distance from each other is 1 tile. On most servers this would normally be where the following is exited due to satisfactory distance.
    In absence of a real father figure I looked to Dr House for guidance through my turbulent teenaged years.
    Reply With Quote  
     

  8. Thankful users:


  9. #7  
    Super Donator


    Join Date
    Jun 2007
    Age
    31
    Posts
    2,157
    Thanks given
    316
    Thanks received
    282
    Rep Power
    779
    Code:
    return follower.getLocation().getX() != following.getLocation().getX() && follower.getLocation().getY() != following.getLocation().getY();
    Will do nothing if standing directly on top of each other, and ensureParallelity doesn't check of the distance is equal to 0, so nothing happens in this case
    Reply With Quote  
     

  10. Thankful user:


  11. #8  
    Registered Member

    Join Date
    Dec 2008
    Posts
    1,010
    Thanks given
    0
    Thanks received
    1
    Rep Power
    271
    Quote Originally Posted by HcoJustin View Post
    Code:
    return follower.getLocation().getX() != following.getLocation().getX() && follower.getLocation().getY() != following.getLocation().getY();
    Will do nothing if standing directly on top of each other, and ensureParallelity doesn't check of the distance is equal to 0, so nothing happens in this case
    Oh shit what the hell I didn't even notice that lol thanks. Either way you can ensure parallelity by using the first function, just make sure they're one tile away first. I did mine like this:
    Code:
    		if (npc.getLocation().getDistanceTo(following.getLocation()) == 1) {
    			if (checkParallelity(npc, following)) {
    				ensureParallelity(npc, following);
    			}
    			return;
    		} else if (npc.getLocation().getDistanceTo(following.getLocation()) == 0) {
    			Location location = Location.getClosestWalkableLocation(npc.getLocation());
    			npc.getWalkingQueue().addStep(location.getX(), location.getY());
    			npc.getWalkingQueue().processNextMovement();
    			return;
    		}
    In absence of a real father figure I looked to Dr House for guidance through my turbulent teenaged years.
    Reply With Quote  
     

  12. Thankful user:


  13. #9  
    Super Donator


    Join Date
    Jun 2007
    Age
    31
    Posts
    2,157
    Thanks given
    316
    Thanks received
    282
    Rep Power
    779
    ^ That's the piece of code missing to make it all work l0l
    Reply With Quote  
     

  14. Thankful user:


  15. #10  
    Registered Member
    Join Date
    Aug 2009
    Posts
    630
    Thanks given
    79
    Thanks received
    24
    Rep Power
    52
    Quote Originally Posted by Derivezor View Post
    Oh shit what the hell I didn't even notice that lol thanks. Either way you can ensure parallelity (which isn't even a real word by the way) by using the first function, just make sure they're one tile away first. I did mine like this:
    Code:
    		if (npc.getLocation().getDistanceTo(following.getLocation()) == 1) {
    			if (checkParallelity(npc, following)) {
    				ensureParallelity(npc, following);
    			}
    			return;
    		} else if (npc.getLocation().getDistanceTo(following.getLocation()) == 0) {
    			Location location = Location.getClosestWalkableLocation(npc.getLocation());
    			npc.getWalkingQueue().addStep(location.getX(), location.getY());
    			npc.getWalkingQueue().processNextMovement();
    			return;
    		}
    where i need to put this
    Reply With Quote  
     

Page 1 of 3 123 LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Sell 614 Diagonal Combat Fix
    By bracket in forum Selling
    Replies: 1
    Last Post: 05-22-2012, 03:44 PM
  2. [Dementhium] Diagonal Combat Fix (Working)
    By EvanFaise in forum Help
    Replies: 10
    Last Post: 01-25-2012, 06:29 AM
  3. Replies: 15
    Last Post: 07-05-2011, 05:55 AM
  4. Project insanity Combat
    By Mickt3 in forum Help
    Replies: 7
    Last Post: 05-06-2011, 12:24 PM
  5. Replies: 0
    Last Post: 07-19-2010, 11:28 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •