Thread: Ring of Suffering

Results 1 to 5 of 5
  1. #1 Ring of Suffering 
    Extreme Donator

    Join Date
    Apr 2015
    Posts
    369
    Thanks given
    215
    Thanks received
    79
    Rep Power
    74
    Ring of Suffering snippet

    Going to keep releasing Basic features I develop. As I plan on releasing my source in the future once we are done with it.

    Main Package
    Code:
    package com.osrsunity.game.items.effects;
    
    import com.osrsunity.game.character.Hit;
    import com.osrsunity.game.character.npc.NPC;
    import com.osrsunity.game.character.player.Player;
    
    /**
     * 
     * Handles everything to do with ring of suffering and its upgrading, except uncharging, as their is no point to uncharge.
     * 
     * @author Durky
     *
     */
    public class RingOfSuffering {
    
    	public static final int RING_OF_SUFFERING = 19550;
    	public static final int RING_OF_SUFFERING_I = 19710; // 750k nightmare points. Double stats
    	public static final int RING_OF_SUFFERING_R = 20655; // 2500 ring of duels,granting up to 100k points so 40 per ring.
    	public static final int RING_OF_SUFFERING_RI = 20657; // both combined.
    
    	private static final int RING_OF_RECOIL = 2550;
    	private static final int RING_OF_RECOIL_NOTED = 2551;
    	private static final int MAX_CHARGES = 100_000;
    
    	/**
    	 * Charge ring with recoils.
    	 */
    	public static boolean chargeRingWithRecoils(Player player, int useId, int useWith) {
    		if (useId == RING_OF_RECOIL || useId == RING_OF_RECOIL_NOTED || useWith == RING_OF_RECOIL
    				|| useWith == RING_OF_RECOIL_NOTED) {
    			int otherInt = 0;
    			int itemToDelete = 2550;
    			if (useId == RING_OF_RECOIL || useId == RING_OF_RECOIL_NOTED) {
    				otherInt = useWith;
    				itemToDelete = useId == RING_OF_RECOIL ? RING_OF_RECOIL : RING_OF_RECOIL_NOTED;
    			}
    			if (useWith == RING_OF_RECOIL || useWith == RING_OF_RECOIL_NOTED) {
    				otherInt = useWith;
    				itemToDelete = useWith == RING_OF_RECOIL ? RING_OF_RECOIL : RING_OF_RECOIL_NOTED;
    			}
    			int playerCharges = player.sufferingCharges;
    			int amountToDelete = player.getItems().getItemAmount(itemToDelete);
    			int chargesToAdd = (amountToDelete * 40);
    			String message = "";
    			if (player.getItems().playerHasItem(itemToDelete, amountToDelete)) {
    				if ((playerCharges + (amountToDelete * 40)) > MAX_CHARGES) {
    					player.sendMessage("You only require " + (MAX_CHARGES - playerCharges) / 40
    							+ " rings of recoil to fully charge this item.");
    					return false;
    				} else {
    					player.getItems().deleteItem(itemToDelete, amountToDelete);
    					player.sufferingCharges += chargesToAdd;
    				}
    			}
    			switch (otherInt) {
    			case RING_OF_SUFFERING:
    				player.getItems().deleteItem(RING_OF_SUFFERING, 1);
    				player.getItems().addItem(RING_OF_SUFFERING_R, 1);
    				message = "You Upgrade your Ring to a Ring of Suffering(r) and add " + chargesToAdd + " charges!";
    				break;
    			case RING_OF_SUFFERING_I:
    				player.getItems().deleteItem(RING_OF_SUFFERING_I, 1);
    				player.getItems().addItem(RING_OF_SUFFERING_RI, 1);
    				message = "You Upgrade your Ring to a Ring of Suffering(ri) and add " + chargesToAdd + " charges!";
    				break;
    			case RING_OF_SUFFERING_R:
    				message = "You add " + chargesToAdd + " charges to your ring of suffering (r) !";
    				break;
    			case RING_OF_SUFFERING_RI:
    				message = "You add " + chargesToAdd + " charges to your ring of suffering (ri) !";
    				break;
    			}
    			player.sufferingRecoil = true;
    			player.sendMessage(
    					"Your Ring has been turned on and will now use charges, Right click it to disable this.");
    			player.sendMessage(message);
    			return true;
    		}
    		return false;
    	}
    
    	/**
    	 * right click toggle effect.
    	 */
    	public static void toggle(Player player) {
    		boolean toggle = player.sufferingRecoil;
    		String message = (toggle ? "off" : "on");
    		player.sufferingRecoil = player.sufferingRecoil ? false : true;
    		player.sendMessage("You toggle your ring of suffering recoil effect " + message + "");
    	}
    
    	/**
    	 * recoil on NPC
    	 */
    	public static void handleUseNPC(Player player, int damage, NPC i) {
    		if (player.playerEquipment[Player.playerRing] == RING_OF_SUFFERING_R
    				|| player.playerEquipment[Player.playerRing] == RING_OF_SUFFERING_RI) {
    			if (player.sufferingRecoil) {
    				if (player.sufferingCharges > 0) {
    					int recDamage = damage / 10 + 1;
    					i.damage(new Hit(recDamage));
    					player.sufferingCharges--;
    				}
    			}
    		}
    	}
    
    	/**
    	 * Recoil on player
    	 */
    	public static void handleUsePlayer(Player player, int damage, Player other) {
    		if (player.playerEquipment[Player.playerRing] == RING_OF_SUFFERING_R
    				|| player.playerEquipment[Player.playerRing] == RING_OF_SUFFERING_RI) {
    			if (player.sufferingRecoil) {
    				if (player.sufferingCharges > 0) {
    					int recDamage = damage / 10 + 1;
    					player.damage(new Hit(recDamage));
    					player.sufferingCharges--;
    				}
    			}
    		}
    	}
    }
    Use item on item - On my server we don't allow downgrading, As there is no point(imo), so we make people do a quick " ROS terms of service when doing the initial upgrade"
    Code:
     if(itemUsed == RingOfSuffering.RING_OF_SUFFERING || useWith == RingOfSuffering.RING_OF_SUFFERING && !player.hasAcceptedROSTerms){
    			player.dialogue().start(new Dialogue() {
    				@Override
    				protected void start(Object... parameters) {
    					send(Type.CHOICE,null, "Yes, Charge this item. I understand it will not be able to be uncharged.",
    							"Do nothing.");
    				}
    				@Override
    				protected void select(int index) {
    					if(index == 1){
    						player.hasAcceptedROSTerms = true;
    						RingOfSuffering.chargeRingWithRecoils(player, itemUsed, useWith);
    						stop();
    						return;
    					}
    					else{
    						stop();
    						return;
    					}
    				}
    			});
    			return;
    		}
    		if(RingOfSuffering.chargeRingWithRecoils(player, itemUsed, useWith)){
    			return;
    		}
    Applying the recoil, if you have a ring of recoil already coded in, toss this in its main method. My server has a specific check for players and for NPCs apply the right one in the correct place.
    Code:
     //toggled on, If not toggled don't bother checking.
    if(c.sufferingRecoil){
    	RingOfSuffering.handleUsePlayer(c,damage,o);
    			}
    i'm not a professional developer, I'm a self taught programmer and if you have suggestions to any code i've written please post below.
    Reply With Quote  
     

  2. #2  
    Respected Member


    Kris's Avatar
    Join Date
    Jun 2016
    Age
    26
    Posts
    3,638
    Thanks given
    820
    Thanks received
    2,642
    Rep Power
    5000
    The code looks fine I believe. I do have a problem with the item on item interaction though, however this isn't an attack at your code as it's fairly irrelevant to the thread itself. Don't really see why these servers nowadays don't write an abstract system to handle item on item interactions more elegantly, in an abstract and neat fashion. Wouldn't have to do shit like constantly check if (first.getId() == x && second.getId() == y || first.getId() == y && second.getId() == x)..
    Which apparently, as I look back on your code, you do not even have used. Have you tested what happens if someone uses the items vice versa? If someone uses a ring of recoil on say.. an armadyl godsword?
    I can't see any code restricting that whatsoever.
    Attached image
    Reply With Quote  
     

  3. Thankful user:


  4. #3  
    Extreme Donator

    Join Date
    Apr 2015
    Posts
    369
    Thanks given
    215
    Thanks received
    79
    Rep Power
    74
    Quote Originally Posted by Kris View Post
    The code looks fine I believe. I do have a problem with the item on item interaction though, however this isn't an attack at your code as it's fairly irrelevant to the thread itself. Don't really see why these servers nowadays don't write an abstract system to handle item on item interactions more elegantly, in an abstract and neat fashion. Wouldn't have to do shit like constantly check if (first.getId() == x && second.getId() == y || first.getId() == y && second.getId() == x)..
    Which apparently, as I look back on your code, you do not even have used. Have you tested what happens if someone uses the items vice versa? If someone uses a ring of recoil on say.. an armadyl godsword?
    I can't see any code restricting that whatsoever.
    yeah so, I check if you're using the an item on the a ring of suffering or its offsprings
    Then i confirm that a recoil is also used.

    But i agree, the massive switch statments, and Massive if and else's need recoded.
    an abstract system would clean it up a lot, althought I don't personally see this as a massive improvement to the servers performance so its more or less a developer QOL (Quality of life ) So its a low priority.
    Reply With Quote  
     

  5. #4  
    Respected Member


    Kris's Avatar
    Join Date
    Jun 2016
    Age
    26
    Posts
    3,638
    Thanks given
    820
    Thanks received
    2,642
    Rep Power
    5000
    Quote Originally Posted by durky View Post
    yeah so, I check if you're using the an item on the a ring of suffering or its offsprings
    Then i confirm that a recoil is also used.

    But i agree, the massive switch statments, and Massive if and else's need recoded.
    an abstract system would clean it up a lot, althought I don't personally see this as a massive improvement to the servers performance so its more or less a developer QOL (Quality of life ) So its a low priority.
    There's a massive improvement to that actually.
    As of right now, every time you use an item on another item in the game, you force the server to go through all those if-statements until it either finds a match or reaches the end of the method. An abstract method, something like mine uses a simple map. It combines the hash of both objects together and gets the result from the map - an action or a null, depending on whether there's an action associated to the item pair or not.

    The improvement is quite big actually as you might be able to tell, although truthfully, with nowadays computers it doesn't matter that much. You'd need massive amounts of statements there for it to actually affect the performance.
    Attached image
    Reply With Quote  
     

  6. Thankful user:


  7. #5  
    Banned

    Join Date
    Mar 2011
    Posts
    657
    Thanks given
    105
    Thanks received
    75
    Rep Power
    0
    Quote Originally Posted by Kris View Post
    There's a massive improvement to that actually.
    As of right now, every time you use an item on another item in the game, you force the server to go through all those if-statements until it either finds a match or reaches the end of the method. An abstract method, something like mine uses a simple map. It combines the hash of both objects together and gets the result from the map - an action or a null, depending on whether there's an action associated to the item pair or not.

    The improvement is quite big actually as you might be able to tell, although truthfully, with nowadays computers it doesn't matter that much. You'd need massive amounts of statements there for it to actually affect the performance.
    It combines the hash of both objects together and gets the result from the map - an action or a null, depending on whether there's an action associated to the item pair or not.

    Thats a great idea .
    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. making ring of stone turning u into a stone
    By i cliff i in forum Tutorials
    Replies: 12
    Last Post: 07-24-2008, 06:21 AM
  2. real working ring of reciol (not the crap 1)
    By natsu in forum Tutorials
    Replies: 14
    Last Post: 03-10-2008, 10:37 PM
  3. Working Ring Of Life That Works
    By Sean in forum Tutorials
    Replies: 18
    Last Post: 03-09-2008, 08:39 PM
  4. Fix For Ring of Stone
    By Ferret in forum Tutorials
    Replies: 1
    Last Post: 08-22-2007, 07:21 PM
  5. Working Ring Of Recoil
    By Carney in forum Tutorials
    Replies: 27
    Last Post: 07-25-2007, 02:38 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •