Implemented functionality where user can search for traps in some chests (#534)

* Initial commit

* Implemented cooldown timer and added ardougne castle chest

* Refactoring

* Removing unused variable
This commit is contained in:
AugustasK
2023-01-20 18:48:45 +02:00
committed by GitHub
parent 9fd4b470c8
commit f56402845b
7 changed files with 229 additions and 96 deletions
@@ -0,0 +1,143 @@
package com.rs2.game.content.skills.thieving;
import com.rs2.GameConstants;
import com.rs2.event.CycleEvent;
import com.rs2.event.CycleEventContainer;
import com.rs2.event.CycleEventHandler;
import com.rs2.game.content.randomevents.RandomEventHandler;
import com.rs2.game.players.Player;
import com.rs2.util.Misc;
import java.util.Arrays;
public class SearchForTraps {
public enum chestsWithTraps {
ARDOUGNE_NATURE_RUNE_CHEST(2568, 28, 25, new int[][]{
{561, 1},
{995, 3},
}, false),
ARDOUGNE_10_COIN_CHEST(2566, 13, 25, new int[][]{
{995, 10}
}, false),
ARDOUGNE_50_COIN_CHEST(2567, 43, 125, new int[][]{
{995, 50}
}, false),
ARDOUGNE_CASTLE_CHEST(2570, 72, 500, new int[][]{
{995, 1000},
{383, 1},
{1623, 1},
{449, 1}
}, true);
private final int chestId;
private final int levelReq;
private final double xp;
private final int[][] reward;
private final boolean randomizeRewards;
private long resetTime;
private chestsWithTraps(final int chestId, final int levelReq, final double xp, int[][] reward, boolean randomizeRewards) {
this.chestId = chestId;
this.levelReq = levelReq;
this.xp = xp;
this.reward = reward;
this.randomizeRewards = randomizeRewards;
this.resetTime = System.currentTimeMillis();
}
public int getChestId() {
return chestId;
}
public int getLevelReq() {
return levelReq;
}
public double getXp() {
return xp;
}
public int[][] getReward() {
return reward;
}
}
public static void searchForTraps(final Player client, final int chestId) {
if (ThieveOther.thievingEnabled(client)) {
for (final chestsWithTraps chest : chestsWithTraps.values()) {
if (chest.getChestId() == chestId) {
if (client.playerLevel[GameConstants.THIEVING] < chest.getLevelReq()) {
client.getDialogueHandler().sendStatement("You must have a thieving level of " + chest.getLevelReq() + " to steal from this chest.");
return;
}
if (System.currentTimeMillis() < chest.resetTime) {
long timeFirstSearchForTraps = chest.resetTime - (GameConstants.CYCLE_TIME * getChestResetTime(chest.getChestId()));
if (client.hasSearchedForTraps() || System.currentTimeMillis() - timeFirstSearchForTraps >= GameConstants.CYCLE_TIME) {
client.getPacketSender().sendMessage("This chest has already been looted");
return;
}
}
client.getPacketSender().sendMessage("You search the chest for traps");
client.startAnimation(536);
RandomEventHandler.addRandom(client);
int resetTime = getChestResetTime(chest.getChestId());
client.getPacketSender().sendMessage("You find a trap on the chest...");
client.getPacketSender().sendMessage("You disable the trap");
client.getPlayerAssistant().addSkillXP((int) chest.getXp(), GameConstants.THIEVING);
chest.resetTime = System.currentTimeMillis() + (resetTime * GameConstants.CYCLE_TIME);
client.getPacketSender().sendMessage("You open the chest");
client.startAnimation(536);
if (chest.getReward() != null && !chest.randomizeRewards) {
Arrays.stream(chest.reward).forEach(reward -> {
client.getItemAssistant().addOrDropItem(reward[0], reward[1]);
});
client.getPacketSender().sendMessage("You find treasure inside!");
} else if (chest.getReward() != null && chest.randomizeRewards) {
int randomizedReward = randomizeReward(chest.reward);
int[] reward = chest.reward[randomizedReward];
client.getItemAssistant().addOrDropItem(reward[0], reward[1]);
} else {
client.getPacketSender().sendMessage("The chest is empty");
}
client.setHasSearchedForTraps(true);
CycleEventHandler.getSingleton().addEvent(client, new CycleEvent() {
@Override
public void execute(CycleEventContainer container) {
client.setHasSearchedForTraps(false);
container.stop();
}
@Override
public void stop() {
}
}, resetTime);
}
}
}
}
private static int getChestResetTime(int i) {
int resetTime = 0;
switch (i) {
case 2566:
resetTime = 7;
break;
case 2567:
resetTime = 70;
break;
case 2568:
resetTime = 10;
break;
case 2570:
resetTime = 240;
break;
}
return resetTime;
}
private static int randomizeReward(int[][] items) {
return Misc.random(items.length);
}
}
@@ -17,9 +17,7 @@ import com.rs2.util.Misc;
public class ThieveOther {
private static boolean isPicking = false;
private static final int[][] LOCKED_DOORS = {{2550, 2674, 3305}, {2551, 2674, 3304}};
public static boolean lockedDoor(Player player, int objectType) {
for (int[] element : LOCKED_DOORS) {
int objectId = element[0];
@@ -32,57 +30,58 @@ public class ThieveOther {
}
return true;
}
public static void stealFromChest(Player client, int level, int exp, int reward, int amount) {
if (client.playerLevel[GameConstants.THIEVING] < level) {
client.getPacketSender().sendMessage("You need " + level + " thieving to thieve this chest.");
return;
}
if (!SkillHandler.THIEVING) {
client.getPacketSender().sendMessage("Thieving is currently disabled.");
return;
}
client.getItemAssistant().addItem(reward, amount);
client.getPlayerAssistant().addSkillXP(exp, GameConstants.THIEVING);
client.getPacketSender().sendMessage("You steal " + ItemAssistant.getItemName(reward) + " from the chest.");
}
public static void pickLock(final Player client, int level, final double exp, final int x, final int y, final int hardness, boolean lock) {
if (!client.getItemAssistant().playerHasItem(1523, 1) && lock) {
client.getPacketSender().sendMessage("You need a lock pick to do that.");
return;
}
if (playerHasRequiredThievingLevel(client, level) && thievingEnabled(client)) {
if (isPicking) {
client.getPacketSender().sendMessage("You are already picking a lock.");
return;
}
isPicking = true;
client.getPacketSender().sendMessage("You attempt to pick the lock.");
CycleEventHandler.getSingleton().addEvent(client, new CycleEvent() {
@Override
public void execute(CycleEventContainer container) {
if (Misc.random(10) < hardness) {
client.getPacketSender().sendMessage("You fail to pick the lock.");
container.stop();
return;
}
client.getPlayerAssistant().movePlayer(x, y, client.heightLevel);
client.getPacketSender().sendMessage("You manage to pick the lock.");
client.getPlayerAssistant().addSkillXP(exp, GameConstants.THIEVING);
container.stop();
}
@Override
public void stop() {
isPicking = false;
}
}, 3);
}
}
public static boolean playerHasRequiredThievingLevel(final Player client, int level) {
if (client.playerLevel[GameConstants.THIEVING] < level) {
client.getPacketSender().sendMessage("You need " + level + " thieving to thieve this chest.");
return;
return false;
}
return true;
}
public static boolean thievingEnabled(final Player client) {
if (!SkillHandler.THIEVING) {
client.getPacketSender().sendMessage("Thieving is currently disabled.");
return;
return false;
}
if (isPicking) {
client.getPacketSender().sendMessage("You are already picking a lock.");
return;
}
isPicking = true;
client.getPacketSender().sendMessage("You attempt to pick the lock.");
CycleEventHandler.getSingleton().addEvent(client, new CycleEvent() {
@Override
public void execute(CycleEventContainer container) {
if (Misc.random(10) < hardness) {
client.getPacketSender().sendMessage("You fail to pick the lock.");
container.stop();
return;
}
client.getPlayerAssistant().movePlayer(x, y, client.heightLevel);
client.getPacketSender().sendMessage("You manage to pick the lock.");
client.getPlayerAssistant().addSkillXP(exp, GameConstants.THIEVING);
container.stop();
}
@Override
public void stop() {
isPicking = false;
}
}, 3);
return true;
}
}
}
@@ -93,6 +93,9 @@ public class ItemAssistant {
} else if (!hasFreeSlots(amount) && !isStackable(item)) {
GameEngine.itemHandler.createGroundItem(player, item, player.getX(), player.getY(), amount, player.playerId);
player.getPacketSender().sendMessage("You have no inventory space, so the item(s) appear beneath you.");
} else if (isStackable(item) && !hasFreeSlots(1) && !playerHasItem(item)) {
GameEngine.itemHandler.createGroundItem(player, item, player.getX(), player.getY(), amount, player.playerId);
player.getPacketSender().sendMessage("You have no inventory space, so the item(s) appear beneath you.");
} else {
addItem(item, amount);
}
@@ -1,13 +1,13 @@
package com.rs2.game.npcs;
import java.util.ArrayList;
import com.rs2.game.content.minigames.FightCaves;
import com.rs2.game.players.PlayerHandler;
import com.rs2.util.Misc;
import com.rs2.world.Boundary;
import com.rs2.world.clip.Region;
import java.util.ArrayList;
public class NpcData {
public static final int[] npcsOnlyMage = { 907, 908, 909, 910, 911, 912,
@@ -22,28 +22,19 @@ import com.rs2.game.content.skills.prayer.Ectofuntus;
import com.rs2.game.content.skills.runecrafting.AbyssalHandler;
import com.rs2.game.content.skills.runecrafting.RuneCraftingActions;
import com.rs2.game.content.skills.smithing.Smelting;
import com.rs2.game.content.skills.thieving.SearchForTraps;
import com.rs2.game.content.skills.thieving.Stalls;
import com.rs2.game.content.skills.thieving.ThieveOther;
import com.rs2.game.content.skills.woodcutting.Woodcutting;
import com.rs2.game.content.traveling.DesertCactus;
import com.rs2.game.globalworldobjects.ClimbOther;
import com.rs2.game.globalworldobjects.PassDoor;
import com.rs2.game.globalworldobjects.ClimbOther.ClimbData;
import com.rs2.game.globalworldobjects.PassDoor;
import com.rs2.game.items.ItemAssistant;
import com.rs2.game.items.impl.LightSources;
import com.rs2.game.npcs.NpcHandler;
import com.rs2.game.npcs.impl.MilkCow;
import com.rs2.game.objects.impl.AxeInLog;
import com.rs2.game.objects.impl.BrimhavenVines;
import com.rs2.game.objects.impl.Climbing;
import com.rs2.game.objects.impl.FlourMill;
import com.rs2.game.objects.impl.Levers;
import com.rs2.game.objects.impl.OpenObject;
import com.rs2.game.objects.impl.OtherObjects;
import com.rs2.game.objects.impl.Pickable;
import com.rs2.game.objects.impl.Searching;
import com.rs2.game.objects.impl.UseOther;
import com.rs2.game.objects.impl.Webs;
import com.rs2.game.objects.impl.*;
import com.rs2.game.players.Player;
import com.rs2.game.players.Position;
import com.rs2.util.Misc;
@@ -2817,10 +2808,21 @@ public class ObjectsActions {
case 2550:
ThieveOther.pickLock(player, 1, 3.5, 2674, 3306, 1, false);
break;
case 2551:
ThieveOther.pickLock(player, 14, 15, 2674, 3303, 2, false);
break;
case 2566:
SearchForTraps.searchForTraps(player, 2566); // uzdeti 28 thv
break;
case 2568:
SearchForTraps.searchForTraps(player, 2568);
break;
case 2567:
SearchForTraps.searchForTraps(player, 2567);
break;
case 2570:
SearchForTraps.searchForTraps(player, 2570);
break;
case 2272:
player.getPacketSender().object(2271, 2984, 3336, 1, 10);
player.getPacketSender().sendMessage("You close the cupboard.");
@@ -11,7 +11,8 @@ public class Searching {
BOOKCASE(new int[] {380, 381, 4617, 4671, 9611}, "The bookcase is empty."),
WARDROBE(new int[] {389}, "The wardrobe is empty."),
DRAWER(new int[] {348, 350, 5618}, "The drawer is empty."),
CHEST(new int[] {378}, "The chest is empty.");
CHEST(new int[] {378}, "The chest is empty."),
CHEST_WITH_TRAP(new int[] {2566, 2567, 2568, 2570}, "You have activated a trap on the chest.");
private final int[] objectId;
private final String searchText;
@@ -33,6 +34,9 @@ public class Searching {
for (SearchData s: SearchData.values()) {
for (int i = 0; i < s.getObjectId().length; i++) {
if (objectType == s.getObjectId()[i]) {
if (s == SearchData.CHEST_WITH_TRAP) {
player.dealDamage(2);
}
player.searchObjectDelay = System.currentTimeMillis();
player.getPacketSender().sendMessage(s.getObjectText());
}
@@ -1,19 +1,9 @@
package com.rs2.game.players;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.Queue;
import com.everythingrs.hiscores.Hiscores;
import com.rs2.event.*;
import com.rs2.plugin.PluginService;
import org.apache.mina.common.IoSession;
import com.rs2.GameConstants;
import com.rs2.GameEngine;
import com.rs2.event.*;
import com.rs2.game.content.BankPin;
import com.rs2.game.content.EmoteHandler;
import com.rs2.game.content.combat.CombatAssistant;
@@ -35,28 +25,11 @@ import com.rs2.game.content.minigames.magetrainingarena.MageTrainingArena;
import com.rs2.game.content.music.PlayList;
import com.rs2.game.content.music.sound.SoundList;
import com.rs2.game.content.skills.SkillInterfaces;
import com.rs2.game.content.skills.agility.Agility;
import com.rs2.game.content.skills.agility.ApeAtollAgility;
import com.rs2.game.content.skills.agility.BarbarianAgility;
import com.rs2.game.content.skills.agility.GnomeAgility;
import com.rs2.game.content.skills.agility.PyramidAgility;
import com.rs2.game.content.skills.agility.WerewolfAgility;
import com.rs2.game.content.skills.agility.WildernessAgility;
import com.rs2.game.content.skills.agility.*;
import com.rs2.game.content.skills.cooking.Potatoes;
import com.rs2.game.content.skills.core.Mining;
import com.rs2.game.content.skills.crafting.GlassBlowing;
import com.rs2.game.content.skills.farming.Allotments;
import com.rs2.game.content.skills.farming.Bushes;
import com.rs2.game.content.skills.farming.Compost;
import com.rs2.game.content.skills.farming.Flowers;
import com.rs2.game.content.skills.farming.FruitTree;
import com.rs2.game.content.skills.farming.Herbs;
import com.rs2.game.content.skills.farming.Hops;
import com.rs2.game.content.skills.farming.Seedling;
import com.rs2.game.content.skills.farming.SpecialPlantOne;
import com.rs2.game.content.skills.farming.SpecialPlantTwo;
import com.rs2.game.content.skills.farming.ToolLeprechaun;
import com.rs2.game.content.skills.farming.WoodTrees;
import com.rs2.game.content.skills.farming.*;
import com.rs2.game.content.skills.fletching.LogCuttingInterface;
import com.rs2.game.content.skills.runecrafting.Runecrafting;
import com.rs2.game.content.skills.slayer.Slayer;
@@ -68,14 +41,10 @@ import com.rs2.game.dialogues.DialogueHandler;
import com.rs2.game.globalworldobjects.DoubleGates;
import com.rs2.game.globalworldobjects.GateHandler;
import com.rs2.game.globalworldobjects.SingleGates;
import com.rs2.game.items.GameItem;
import com.rs2.game.items.Inventory;
import com.rs2.game.items.ItemData;
import com.rs2.game.items.ItemAssistant;
import com.rs2.game.items.ItemConstants;
import com.rs2.game.items.*;
import com.rs2.game.items.impl.Greegree.MonkeyData;
import com.rs2.game.items.impl.PotionMixing;
import com.rs2.game.items.impl.Teles;
import com.rs2.game.items.impl.Greegree.MonkeyData;
import com.rs2.game.npcs.Npc;
import com.rs2.game.npcs.NpcActions;
import com.rs2.game.npcs.NpcHandler;
@@ -88,11 +57,15 @@ import com.rs2.net.PacketSender;
import com.rs2.net.StaticPacketBuilder;
import com.rs2.net.packets.PacketHandler;
import com.rs2.net.packets.impl.ChallengePlayer;
import com.rs2.plugin.PluginService;
import com.rs2.util.ISAACRandomGen;
import com.rs2.util.Misc;
import com.rs2.util.Stream;
import com.rs2.world.Boundary;
import com.rs2.world.ObjectManager;
import org.apache.mina.common.IoSession;
import java.util.*;
public abstract class Player {
@@ -1747,6 +1720,7 @@ public abstract class Player {
public boolean isMining;
public boolean hasThievedStall;
public boolean hasSearchedForTraps;
public boolean stopFiremaking, pickedUpFiremakingLog, logLit;
public boolean hasThievedStall() {
@@ -1757,6 +1731,14 @@ public abstract class Player {
this.hasThievedStall = hasThievedStall;
}
public boolean hasSearchedForTraps() {
return hasSearchedForTraps;
}
public void setHasSearchedForTraps(boolean hasSearchedForTraps) {
this.hasSearchedForTraps = hasSearchedForTraps;
}
public boolean antiFirePot;
public boolean underWater;