Thread: Slash webs issue mage bank

Results 1 to 8 of 8
  1. #1 Slash webs issue mage bank 
    Banned
    Join Date
    Jun 2012
    Posts
    125
    Thanks given
    1
    Thanks received
    2
    Rep Power
    0
    Is there any better way to do this?

    I just quickly came up with this:
    Code:
    public class SlashWeb {
    
    	/**
    	 * The last interaction that player made that is recorded in milliseconds
    	 */
    	public long lastInteraction;
    
    	public Player player;
    	
    	/**
    	 * The constant delay that is required inbetween interactions
    	 */
    	public final long INTERACTION_DELAY = 1_100L;
    	
    	/**
    	 * The slash animation
    	 */
    	public final int ANIMATION = 451;
    	
    	/**
    	 * Constructs a new {@link SlashWeb} object that manages interactions 
    	 * between players and webs.
    	 * 
    	 * @param player	the visible player of this class
    	 */
    	public SlashWeb(final Player player) {
    		this.setPlayer(player);
    	}
    	
    	
    	public void slash(Player player, int objectX, int objectY){
    	if (System.currentTimeMillis() - lastInteraction < INTERACTION_DELAY) {
    		return;
    	}
    	//1st web
    	if(player.objectX == 3095 && player.objectY == 3957 && player.absX == 3094 && player.absY == 3957 || 
    			player.objectX == 3095 && player.objectY == 3957 && player.absX == 3095 && player.absY == 3957){
    		player.turnPlayerTo(objectX, objectY);
    		player.playAnimation(Animation.create(ANIMATION));
    		if (Utils.getRandom(1) == 1) {
    			player.getPA().removeWeb(objectX, objectY);
    			player.write(new SendGameMessage("You slash through the web!"));
    			lastInteraction = System.currentTimeMillis();
    		} else {
    			player.write(new SendGameMessage("You fail to cut through the web."));
    			lastInteraction = System.currentTimeMillis();
    			}
    		}
    	//2nd web
    	if(player.objectX == 3092 && player.objectY == 3957 && player.absX == 3093 && player.absY == 3957 || 
    			player.objectX == 3092 && player.objectY == 3957 && player.absX == 3092 && player.absY == 3957){
    		player.turnPlayerTo(objectX, objectY);
    		player.playAnimation(Animation.create(ANIMATION));
    		if (Utils.getRandom(1) == 1) {
    			player.getPA().removeWeb(objectX, objectY);
    			player.write(new SendGameMessage("You slash through the web!"));
    			lastInteraction = System.currentTimeMillis();
    		} else {
    			player.write(new SendGameMessage("You fail to cut through the web."));
    			lastInteraction = System.currentTimeMillis();
    			}
    		}
    	//3rd web
    	if(player.objectX == 3105 && player.objectY == 3958 && player.absX == 3105 && player.absY == 3959 || 
    			player.objectX == 3105 && player.objectY == 3958 && player.absX == 3105 && player.absY == 3958){
    		player.turnPlayerTo(objectX, objectY);
    		player.playAnimation(Animation.create(ANIMATION));
    		if (Utils.getRandom(1) == 1) {
    			player.getPA().removeWeb(objectX, objectY);
    			player.write(new SendGameMessage("You slash through the web!"));
    			lastInteraction = System.currentTimeMillis();
    		} else {
    			player.write(new SendGameMessage("You fail to cut through the web."));
    			lastInteraction = System.currentTimeMillis();
    			}
    		}
    	//4th web
    		if(player.objectX == 3106 && player.objectY == 3958 && player.absX == 3106 && player.absY == 3959 || 
    				player.objectX == 3106 && player.objectY == 3958 && player.absX == 3105 && player.absY == 3958){
    			player.turnPlayerTo(objectX, objectY);
    			player.playAnimation(Animation.create(ANIMATION));
    			if (Utils.getRandom(1) == 1) {
    				player.getPA().removeWeb(objectX, objectY);
    				player.write(new SendGameMessage("You slash through the web!"));
    				lastInteraction = System.currentTimeMillis();
    			} else {
    				player.write(new SendGameMessage("You fail to cut through the web."));
    				lastInteraction = System.currentTimeMillis();
    				}
    			}
    	else {
    		return;
    	}
    	}
    	
    	public Player getPlayer() {
    		return player;
    	}
    	public void setPlayer(Player player) {
    		this.player = player;
    	}
    	
    }
    Reply With Quote  
     

  2. #2  
    Banned
    Join Date
    Jun 2016
    Posts
    24
    Thanks given
    1
    Thanks received
    2
    Rep Power
    0
    Quote Originally Posted by Owner Jason View Post
    Is there any better way to do this?

    I just quickly came up with this:
    Code:
    public class SlashWeb {
    
    	/**
    	 * The last interaction that player made that is recorded in milliseconds
    	 */
    	public long lastInteraction;
    
    	public Player player;
    	
    	/**
    	 * The constant delay that is required inbetween interactions
    	 */
    	public final long INTERACTION_DELAY = 1_100L;
    	
    	/**
    	 * The slash animation
    	 */
    	public final int ANIMATION = 451;
    	
    	/**
    	 * Constructs a new {@link SlashWeb} object that manages interactions 
    	 * between players and webs.
    	 * 
    	 * @param player	the visible player of this class
    	 */
    	public SlashWeb(final Player player) {
    		this.setPlayer(player);
    	}
    	
    	
    	public void slash(Player player, int objectX, int objectY){
    	if (System.currentTimeMillis() - lastInteraction < INTERACTION_DELAY) {
    		return;
    	}
    	//1st web
    	if(player.objectX == 3095 && player.objectY == 3957 && player.absX == 3094 && player.absY == 3957 || 
    			player.objectX == 3095 && player.objectY == 3957 && player.absX == 3095 && player.absY == 3957){
    		player.turnPlayerTo(objectX, objectY);
    		player.playAnimation(Animation.create(ANIMATION));
    		if (Utils.getRandom(1) == 1) {
    			player.getPA().removeWeb(objectX, objectY);
    			player.write(new SendGameMessage("You slash through the web!"));
    			lastInteraction = System.currentTimeMillis();
    		} else {
    			player.write(new SendGameMessage("You fail to cut through the web."));
    			lastInteraction = System.currentTimeMillis();
    			}
    		}
    	//2nd web
    	if(player.objectX == 3092 && player.objectY == 3957 && player.absX == 3093 && player.absY == 3957 || 
    			player.objectX == 3092 && player.objectY == 3957 && player.absX == 3092 && player.absY == 3957){
    		player.turnPlayerTo(objectX, objectY);
    		player.playAnimation(Animation.create(ANIMATION));
    		if (Utils.getRandom(1) == 1) {
    			player.getPA().removeWeb(objectX, objectY);
    			player.write(new SendGameMessage("You slash through the web!"));
    			lastInteraction = System.currentTimeMillis();
    		} else {
    			player.write(new SendGameMessage("You fail to cut through the web."));
    			lastInteraction = System.currentTimeMillis();
    			}
    		}
    	//3rd web
    	if(player.objectX == 3105 && player.objectY == 3958 && player.absX == 3105 && player.absY == 3959 || 
    			player.objectX == 3105 && player.objectY == 3958 && player.absX == 3105 && player.absY == 3958){
    		player.turnPlayerTo(objectX, objectY);
    		player.playAnimation(Animation.create(ANIMATION));
    		if (Utils.getRandom(1) == 1) {
    			player.getPA().removeWeb(objectX, objectY);
    			player.write(new SendGameMessage("You slash through the web!"));
    			lastInteraction = System.currentTimeMillis();
    		} else {
    			player.write(new SendGameMessage("You fail to cut through the web."));
    			lastInteraction = System.currentTimeMillis();
    			}
    		}
    	//4th web
    		if(player.objectX == 3106 && player.objectY == 3958 && player.absX == 3106 && player.absY == 3959 || 
    				player.objectX == 3106 && player.objectY == 3958 && player.absX == 3105 && player.absY == 3958){
    			player.turnPlayerTo(objectX, objectY);
    			player.playAnimation(Animation.create(ANIMATION));
    			if (Utils.getRandom(1) == 1) {
    				player.getPA().removeWeb(objectX, objectY);
    				player.write(new SendGameMessage("You slash through the web!"));
    				lastInteraction = System.currentTimeMillis();
    			} else {
    				player.write(new SendGameMessage("You fail to cut through the web."));
    				lastInteraction = System.currentTimeMillis();
    				}
    			}
    	else {
    		return;
    	}
    	}
    	
    	public Player getPlayer() {
    		return player;
    	}
    	public void setPlayer(Player player) {
    		this.player = player;
    	}
    	
    }
    This is what I got, all in Objecthandler.java

    Code:
    case "web":
    						if (objectDef.containsOption(0, "Slash")) {
    							player.setNextAnimation(new Animation(PlayerCombat
    									.getWeaponAttackEmote(player.getEquipment()
    											.getWeaponId(), player
    											.getCombatDefinitions()
    											.getAttackStyle())));
    							slashWeb(player, object);
    						}
    Code:
    private static void slashWeb(Player player, WorldObject object) {
    
    		if (Utils.getRandom(1) == 0) {
    			World.spawnTemporaryObject(new WorldObject(object.getId() + 1,
    					object.getType(), object.getRotation(), object.getX(),
    					object.getY(), object.getPlane()), 60000, true);
    			player.getPackets().sendGameMessage("You slash through the web!");
    		} else
    			player.getPackets().sendGameMessage(
    					"You fail to cut through the web.");
    	}
    Code:
    } else if (object.getId() == 733 || object.getId() == 64729) {
    					player.setNextAnimation(new Animation(PlayerCombat
    							.getWeaponAttackEmote(-1, 0)));
    					slashWeb(player, object);
    Reply With Quote  
     

  3. #3  
    Banned
    Join Date
    Jun 2012
    Posts
    125
    Thanks given
    1
    Thanks received
    2
    Rep Power
    0
    Thanks, learned abit from that... I'm a new programmer, so trying to gain as much knowledge as I can

    What about checking if the player is in close to the web? I don't want players being able to hit the web from far
    Reply With Quote  
     

  4. #4  
    Banned

    Join Date
    Oct 2011
    Age
    27
    Posts
    2,566
    Thanks given
    1,027
    Thanks received
    1,168
    Rep Power
    0
    Quote Originally Posted by Owner Jason View Post
    Thanks, learned abit from that... I'm a new programmer, so trying to gain as much knowledge as I can

    What about checking if the player is in close to the web? I don't want players being able to hit the web from far
    Those checks should be pre-processed already (assuming you're using Matrix) along with checks to see if the object actually exists in the region, etc.

    There's a class called RouteEvent which executes an 'event' (java.lang.Runnable- it's actually a parameter of the RouteEvent constructor) once the event is "processed" (processEvent(Player player) in the doc- it's called every game tick to continuously process the event until the conditions are met or the event is terminated (by returning true to say the event is either complete or no longer needed to be ticked)) and it executes the Runnable once the event conditions are met. In ObjectHandler or something you have

    Code:
    player.setRouteEvent(source, runnable);
    The runnable is ran once the route is complete. The source of the event is the node that is being interacted with by the client, a method called generateStrategy or something generates a strategy for the RouteEvent instance to parse. Look for a class called RouteStrategy if you want to see how the algorithms calculate the best path to reach the node. I'm pretty sure there was a parameter which would allow you to add distance with regards to how far away you want the entity to go before the event (the runnable) is executed.
    Reply With Quote  
     

  5. #5  
    Banned

    Join Date
    Oct 2012
    Posts
    4,710
    Thanks given
    1,679
    Thanks received
    1,105
    Rep Power
    0
    Quote Originally Posted by Vip3r View Post
    Those checks should be pre-processed already (assuming you're using Matrix) along with checks to see if the object actually exists in the region, etc.

    There's a class called RouteEvent which executes an 'event' (java.lang.Runnable- it's actually a parameter of the RouteEvent constructor) once the event is "processed" (processEvent(Player player) in the doc- it's called every game tick to continuously process the event until the conditions are met or the event is terminated (by returning true to say the event is either complete or no longer needed to be ticked)) and it executes the Runnable once the event conditions are met. In ObjectHandler or something you have

    Code:
    player.setRouteEvent(source, runnable);
    The runnable is ran once the route is complete. The source of the event is the node that is being interacted with by the client, a method called generateStrategy or something generates a strategy for the RouteEvent instance to parse. Look for a class called RouteStrategy if you want to see how the algorithms calculate the best path to reach the node. I'm pretty sure there was a parameter which would allow you to add distance with regards to how far away you want the entity to go before the event (the runnable) is executed.
    He's not using matrix.

    And stuff like this don't need a whole class.

    You should also make use of the Attributes system provided.
    Reply With Quote  
     

  6. #6  
    Banned
    Join Date
    Jun 2012
    Posts
    125
    Thanks given
    1
    Thanks received
    2
    Rep Power
    0
    This is my removeWebs method
    Don't know if it's done the best way... but it works, but my aim is learning to code better.
    By the way I am using PI
    Code:
        /**
         * Method for removing webs when they are slashed
         * @param x		Object x
         * @param y		Object y
         */
       
     public void removeWeb(int x, int y) {
        	 //1st web
        	if (x == 3092 && y == 3957) {
         		if(Server.getGlobalObjects().exists(733, x, y))
        		Server.getGlobalObjects().add(new GlobalObject(734, x, y, 0, 2, 0,
      				50, 733));
         		else
         		return;
        	 }
        	 //2nd web
        	if (x == 3095 && y == 3957) {
        		if(Server.getGlobalObjects().exists(733, x, y))
        		Server.getGlobalObjects().add(new GlobalObject(734, x, y, 0, 0, 0,
          				50, 733));
        		else
        		return;
             }
        	 //3rd web
        	if (x == 3106 && y == 3958) {
        		if(Server.getGlobalObjects().exists(733, x, y))
        		Server.getGlobalObjects().add(new GlobalObject(734, x, y, 0, 3, 10,
         				50, 733));
        		else
        		return;
            }
            //4th web
        	if (x == 3105 && y == 3958) {
            	if(Server.getGlobalObjects().exists(733, x, y))
        		Server.getGlobalObjects().add(new GlobalObject(734, x, y, 0, 3, 10,
         				50, 733));
            	else
            	return;
            }
             //5th web
        	if (x == 3158 && y == 3951) {
        		if(Server.getGlobalObjects().exists(733, x, y))
        		Server.getGlobalObjects().add(new GlobalObject(734, x, y, 0, 1, 10,
             				50, 733));
        		else
        		return;
            }
        }
    Reply With Quote  
     

  7. #7  
    Banned

    Join Date
    Oct 2011
    Age
    27
    Posts
    2,566
    Thanks given
    1,027
    Thanks received
    1,168
    Rep Power
    0
    Quote Originally Posted by _Patrick_ View Post
    He's not using matrix.

    And stuff like this don't need a whole class.

    You should also make use of the Attributes system provided.
    Stuff like movement processor or a single line check to calculate the distance? :L

    My bad about the matrix thing, someone who was working on a 718 asked me to answer this question, didn't bother checking the secion

    You can calculate the distance between the two entities using:

    Code:
    int distance = (int) (Math.sqrt(Math.pow((Math.abs(y1 - y2)), 2) + Math.pow((Math.abs(x1 - x2)), 2)) + 0.5);
    Reply With Quote  
     

  8. #8  
    Banned
    Join Date
    Jun 2012
    Posts
    125
    Thanks given
    1
    Thanks received
    2
    Rep Power
    0
    Another question, with slashWebs... it makes a new Object... so I was reading a thread about memoryleaks. Could this not cause a memory leak? by it creating a new object each time someone cuts a web? if so how would I dispose of it?
    Reply With Quote  
     


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. Replies: 2
    Last Post: 11-14-2011, 03:22 PM
  2. Replies: 0
    Last Post: 11-14-2011, 06:58 AM
  3. Mage bank webs.
    By Endrosia in forum Help
    Replies: 9
    Last Post: 10-02-2011, 02:44 AM
  4. mage bank webs
    By Boxxy in forum Help
    Replies: 3
    Last Post: 01-11-2011, 04:01 PM
  5. mage bank webs
    By Nathan in forum Snippets
    Replies: 27
    Last Post: 11-27-2010, 01:41 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
  •