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.