From af9989516814612b925204c333bf24e62c54e963 Mon Sep 17 00:00:00 2001 From: bushtail Date: Sat, 1 Apr 2023 04:57:58 +0000 Subject: [PATCH] Refactored some fishing code Converted some fishing code to kotlin Implemented crayfish fishing --- Server/data/configs/npc_spawns.json | 22 +- .../content/global/skill/fishing/Fish.java | 126 ---------- .../main/content/global/skill/fishing/Fish.kt | 60 +++++ .../global/skill/fishing/FishSpots.java | 56 ----- .../content/global/skill/fishing/FishSpots.kt | 224 ++++++++++++++++++ .../global/skill/fishing/FishingNPC.java | 103 -------- .../global/skill/fishing/FishingNPC.kt | 53 +++++ .../global/skill/fishing/FishingOption.java | 213 ----------------- .../global/skill/fishing/FishingOption.kt | 103 ++++++++ .../global/skill/fishing/FishingSpot.java | 82 ------- .../global/skill/fishing/FishingSpot.kt | 164 +++++++++++++ .../skill/gather/fishing/FishingListener.kt | 50 ++-- .../skill/gather/fishing/FishingPulse.kt | 50 ++-- .../minigame/fishingtrawler/TrawlerLoot.kt | 2 +- Server/src/main/core/api/ContentAPI.kt | 11 + 15 files changed, 672 insertions(+), 647 deletions(-) delete mode 100644 Server/src/main/content/global/skill/fishing/Fish.java create mode 100644 Server/src/main/content/global/skill/fishing/Fish.kt delete mode 100644 Server/src/main/content/global/skill/fishing/FishSpots.java create mode 100644 Server/src/main/content/global/skill/fishing/FishSpots.kt delete mode 100644 Server/src/main/content/global/skill/fishing/FishingNPC.java create mode 100644 Server/src/main/content/global/skill/fishing/FishingNPC.kt delete mode 100644 Server/src/main/content/global/skill/fishing/FishingOption.java create mode 100644 Server/src/main/content/global/skill/fishing/FishingOption.kt delete mode 100644 Server/src/main/content/global/skill/fishing/FishingSpot.java create mode 100644 Server/src/main/content/global/skill/fishing/FishingSpot.kt diff --git a/Server/data/configs/npc_spawns.json b/Server/data/configs/npc_spawns.json index c9715ffae..94107d9b3 100644 --- a/Server/data/configs/npc_spawns.json +++ b/Server/data/configs/npc_spawns.json @@ -869,7 +869,7 @@ }, { "npc_id": "309", - "loc_data": "{2860,2976,0,0,4}-{2856,2977,0,0,4}-{2852,2973,0,0,4}-{2267,3253,0,0,4}-{2266,3253,0,0,4}-{2262,3249,0,0,4}-{2716,3530,0,0,0}-{2561,3374,0,0,4}-{2562,3374,0,0,4}-{2633,3693,0,0,4}-{2633,3694,0,0,4}-{2215,3248,0,0,4}-{2217,3245,0,0,4}-{2213,3241,0,0,4}-{3104,3424,0,0,0}-{3104,3425,0,0,0}-{2566,3370,0,0,0}-{2637,3444,0,0,0}-{2471,3146,0,0,4}-{2465,3156,0,0,4}-{2461,3150,0,0,4}-{2678,3595,0,0,4}-{2689,3598,0,0,4}" + "loc_data": "{2860,2976,0,0,4}-{2856,2977,0,0,4}-{2852,2973,0,0,4}-{2267,3253,0,0,4}-{2266,3253,0,0,4}-{2262,3249,0,0,4}-{2716,3530,0,0,0}-{2561,3374,0,0,4}-{2562,3374,0,0,4}-{2633,3693,0,0,4}-{2633,3694,0,0,4}-{2215,3248,0,0,4}-{2217,3245,0,0,4}-{2213,3241,0,0,4}-{3104,3424,0,0,0}-{3104,3425,0,0,0}-{2566,3370,0,0,0}-{2637,3444,0,0,0}-{2471,3146,0,0,4}-{2465,3156,0,0,4}-{2461,3150,0,0,4}-{2678,3595,0,0,4}" }, { "npc_id": "310", @@ -893,7 +893,7 @@ }, { "npc_id": "323", - "loc_data": "{2926,3177,0,0,6}-{3259,3204,0,0,3}-{3248,3161,0,0,4}-{3259,3206,0,0,3}-{2516,3575,0,0,7}-{2511,3562,0,0,7}-{2498,3547,0,0,7}" + "loc_data": "{2926,3177,0,0,6}-{3248,3161,0,0,4}-{2516,3575,0,0,7}-{2511,3562,0,0,7}-{2498,3547,0,0,7}" }, { "npc_id": "324", @@ -905,7 +905,7 @@ }, { "npc_id": "326", - "loc_data": "{2840,3431,0,0,0}-{3246,3156,0,0,0}-{3245,3152,0,0,0}-{3242,3148,0,0,0}-{2855,3423,0,0,1}-{3267,3148,0,0,6}-{3276,3140,0,0,6}-{3275,3140,0,0,6}-{3169,3266,0,0,3}-{3173,3274,0,0,3}-{2607,3416,0,0,1}-{2604,3417,0,0,1}-{2602,3419,0,0,1}" + "loc_data": "{2840,3431,0,0,0}-{3246,3156,0,0,0}-{3245,3152,0,0,0}-{3242,3148,0,0,0}-{2855,3423,0,0,1}-{3267,3148,0,0,6}-{3276,3140,0,0,6}-{3275,3140,0,0,6}-{2607,3416,0,0,1}-{2604,3417,0,0,1}-{2602,3419,0,0,1}" }, { "npc_id": "333", @@ -9586,7 +9586,11 @@ { "npc_id": "6987", "loc_data": "{2894,3445,0,1,0}" - }, + }, + { + "npc_id": "6996", + "loc_data": "{3259,3206,0,0,3}-{3259,3204,0,0,3}-{3169,3266,0,0,3}-{3173,3274,0,0,3}-{2689,3598,0,0,4}" + }, { "npc_id": "6997", "loc_data": "{3002,3257,0,0,0}-{3058,3429,0,0,0}-{3059,3420,0,0,0}-{3059,3425,0,0,0}-{3049,3429,0,0,0}-{3007,3261,0,0,0}" @@ -10983,17 +10987,13 @@ "npc_id": "5517", "loc_data": "{2403,3853,0,1,0}-{2328,3830,0,1,0}-{2405,3860,0,1,0}-{2335,3894,0,1,0}" }, - { - "npc_id": "3848", - "loc_data": "{2410,3780,0,1,0}-{2414,3780,0,1,0}" - }, { "npc_id": "313", - "loc_data":"{2401,3781,0,1,0}" + "loc_data":"{2401,3781,0,0,0}" }, { "npc_id": "312", - "loc_data": "{2421,3789,0,1,0}" + "loc_data": "{2421,3789,0,0,0}-{2410,3780,0,0,0}-{2414,3780,0,0,0}" }, { "npc_id": "1164", @@ -11041,7 +11041,7 @@ }, { "npc_id": "800", - "loc_data": "{2884,9765,0,1,0}-{2890,9766,0,1,0}-{2894,9764,0,1,0}" + "loc_data": "{2884,9765,0,0,0}-{2890,9766,0,0,0}-{2894,9764,0,0,0}" }, { "npc_id": "3322", diff --git a/Server/src/main/content/global/skill/fishing/Fish.java b/Server/src/main/content/global/skill/fishing/Fish.java deleted file mode 100644 index 06bc90d74..000000000 --- a/Server/src/main/content/global/skill/fishing/Fish.java +++ /dev/null @@ -1,126 +0,0 @@ -package content.global.skill.fishing; - -import core.game.node.item.Item; - -import java.util.HashMap; - -/** - * Represents a type of fish to catch. - * @author ceikry - */ -public enum Fish { - CRAYFISH(new Item(13435),1, 10, 0.15, 0.5), - SHRIMP(new Item(317), 1, 10, 0.191, 0.5), - SARDINE(new Item(327), 5, 20, 0.148, 0.374), - KARAMBWANJI(new Item(3150), 5, 5, 0.4, 0.98), - HERRING(new Item(345), 10, 30, 0.129, 0.504), - ANCHOVIE(new Item(321), 15, 40, 0.098, 0.5), - MACKEREL(new Item(353), 16, 20, 0.055, 0.258), - TROUT(new Item(335), 20, 50, 0.246, 0.468), - COD(new Item(341), 23, 45, 0.063, 0.219), - PIKE(new Item(349), 25, 60, 0.14, 0.379), - SLIMY_EEL(new Item(3379), 28, 65, 0.117, 0.216), - SALMON(new Item(331), 30, 70, 0.156, 0.378), - FROG_SPAWN(new Item(5004), 33, 75, 0.164, 0.379), - TUNA(new Item(359), 35, 80, 0.109, 0.205), - RAINBOW_FISH(new Item(10138), 38, 80, 0.113, 0.254), - CAVE_EEL(new Item(5001), 38, 80, 0.145, 0.316), - LOBSTER(new Item(377), 40, 90, 0.16, 0.375), - BASS(new Item(363), 46, 100, 0.078, 0.16), - SWORDFISH(new Item(371), 50, 100, 0.105, 0.191), - LAVA_EEL(new Item(2148), 53, 30, 0.227, 0.379), - MONKFISH(new Item(7944), 62, 120, 0.293, 0.356), - KARAMBWAN(new Item(3142), 65, 105, 0.414, 0.629), - SHARK(new Item(383), 76, 110, 0.121, 0.16), - SEA_TURTLE(new Item(395), 79, 38, 0.0, 0.0), - MANTA_RAY(new Item(389), 81, 46, 0.0, 0.0), - SEAWEED(new Item(401), 16, 1, 0.63, 0.219), - CASKET(new Item(405), 16, 10, 0.63, 0.219), - OYSTER(new Item(407), 16, 10, 0.63, 0.219); - - /** - * Constructs a new {@code Fish} {@code Object}. - * @param item the Item - * @param level the level. - * @param experience the experience. - */ - Fish(final Item item, final int level, final double experience, final double lowChance, final double highChance, final int... npcs) { - this.item = item; - this.level = level; - this.experience = experience; - this.npcs = npcs; - // The chances are given in the table based on when the fish can first be caught. - // Linearly extrapolate the success chance at level 1. - // y = (x - x0) * ((y1 - y0) / (x1 - x0)) + y0 - this.lowChance = (1 - (double)level)*((highChance - lowChance) / (99.0 - (double)level)) + lowChance; - this.highChance = highChance; - } - - public static HashMap fishMap = new HashMap<>(); - static{ - for(Fish fish : Fish.values()){ - fishMap.putIfAbsent(fish.item.getId(),fish); - } - } - private final Item item; - - /** - * Represents the required level to catch the {@link Fish}. - */ - private final int level; - - /** - * Represents the experience gained from this fish. - */ - private final double experience; - - private final double lowChance; - private final double highChance; - - /** - * The npc ids that give this fish. - */ - private final int[] npcs; - - /** - * Gets the fish. - * @param item the item. - * @return the fash. - */ - public static Fish forItem(Item item) { - return fishMap.get(item.getId()); - } - - /** - * @return the item. - */ - public Item getItem() { - return item; - } - - /** - * @return the level. - */ - public int getLevel() { - return level; - } - - /** - * @return the experience. - */ - public double getExperience() { - return experience; - } - - /** - * Gets the npcs. - * @return the npcs - */ - public int[] getNpcs() { - return npcs; - } - - public double getSuccessChance(int level) { - return ((double)level - 1.0)*((highChance - lowChance) / (99.0 - 1.0)) + lowChance; - } -} diff --git a/Server/src/main/content/global/skill/fishing/Fish.kt b/Server/src/main/content/global/skill/fishing/Fish.kt new file mode 100644 index 000000000..ca1ab4dfe --- /dev/null +++ b/Server/src/main/content/global/skill/fishing/Fish.kt @@ -0,0 +1,60 @@ +package content.global.skill.fishing + +import core.api.asItem +import core.game.node.item.Item +import org.rs09.consts.Items + +enum class Fish(val id: Int, val level: Int, val experience: Double, val lowChance: Double, val highChance: Double) { + CRAYFISH(Items.RAW_CRAYFISH_13435, 1, 10.0, 0.15, 0.5), + SHRIMP(Items.RAW_SHRIMPS_317, 1, 10.0, 0.191, 0.5), + SARDINE(Items.RAW_SARDINE_327, 5, 20.0, 0.148, 0.374), + KARAMBWANJI(Items.RAW_KARAMBWANJI_3150, 5, 5.0, 0.4, 0.98), + HERRING(Items.RAW_HERRING_345, 10, 30.0, 0.129, 0.504), + ANCHOVIE(Items.RAW_ANCHOVIES_321, 15, 40.0, 0.098, 0.5), + MACKEREL(Items.RAW_MACKEREL_353, 16, 20.0, 0.055, 0.258), + TROUT(Items.RAW_TROUT_335, 20, 50.0, 0.246, 0.468), + COD(Items.RAW_COD_341, 23, 45.0, 0.063, 0.219), + PIKE(Items.RAW_PIKE_349, 25, 60.0, 0.14, 0.379), + SLIMY_EEL(Items.SLIMY_EEL_3379, 28, 65.0, 0.117, 0.216), + SALMON(Items.RAW_SALMON_331, 30, 70.0, 0.156, 0.378), + FROG_SPAWN(Items.FROG_SPAWN_5004, 33, 75.0, 0.164, 0.379), + TUNA(Items.RAW_TUNA_359, 35, 80.0, 0.109, 0.205), + RAINBOW_FISH(Items.RAW_RAINBOW_FISH_10138, 38, 80.0, 0.113, 0.254), + CAVE_EEL(Items.RAW_CAVE_EEL_5001, 38, 80.0, 0.145, 0.316), + LOBSTER(Items.RAW_LOBSTER_377, 40, 90.0, 0.16, 0.375), + BASS(Items.RAW_BASS_363, 46, 100.0, 0.078, 0.16), + SWORDFISH(Items.RAW_SWORDFISH_371, 50, 100.0, 0.105, 0.191), + LAVA_EEL(Items.RAW_LAVA_EEL_2148, 53, 30.0, 0.227, 0.379), + MONKFISH(Items.RAW_MONKFISH_7944, 62, 120.0, 0.293, 0.356), + KARAMBWAN(Items.RAW_KARAMBWAN_3142, 65, 105.0, 0.414, 0.629), + SHARK(Items.RAW_SHARK_383, 76, 110.0, 0.121, 0.16), + SEA_TURTLE(Items.RAW_SEA_TURTLE_395, 79, 38.0, 0.0, 0.0), + MANTA_RAY(Items.RAW_MANTA_RAY_389, 81, 46.0, 0.0, 0.0), + SEAWEED(Items.SEAWEED_401, 16, 1.0, 0.63, 0.219), + CASKET(Items.CASKET_405, 16, 10.0, 0.63, 0.219), + OYSTER(Items.OYSTER_407, 16, 10.0, 0.63, 0.219); + + companion object { + val fishMap: HashMap = HashMap() + init { + for(fish in values()) { + fishMap[fish.id] = fish + } + } + + @JvmStatic + fun forItem(item: Item) : Fish? { + return fishMap[item.id] + } + + + } + + fun getSuccessChance(level: Int): Double { + return (level.toDouble() - 1.0) * ((highChance - lowChance) / (99.0 - 1.0)) + lowChance + } + + fun getItem() : Item { + return this.id.asItem() + } +} \ No newline at end of file diff --git a/Server/src/main/content/global/skill/fishing/FishSpots.java b/Server/src/main/content/global/skill/fishing/FishSpots.java deleted file mode 100644 index 65053463a..000000000 --- a/Server/src/main/content/global/skill/fishing/FishSpots.java +++ /dev/null @@ -1,56 +0,0 @@ -package content.global.skill.fishing; - -import core.game.world.map.Location; - -import java.util.HashMap; - -/** - * Fishing spot locations - * @author Ceikry - */ -public enum FishSpots { - CATHERBY(Location.create(2844, 3429, 0), Location.create(2839, 3431, 0), new Location(2836, 3431, 0), new Location(2837, 3431, 0), new Location(2838, 3431, 0), new Location(2839, 3431, 0), new Location(2840, 3431, 0), new Location(2844, 3429, 0), new Location(2845, 3429, 0), new Location(2846, 3429, 0), new Location(2853, 3423, 0), new Location(2854, 3423, 0), new Location(2855, 3423, 0), new Location(2859, 3426, 0), new Location(2860, 3426, 0)), - ENTRANA(new Location(2842, 3359, 0), new Location(2843, 3359, 0), new Location(2844, 3359, 0), new Location(2847, 3361, 0), new Location(2848, 3361, 0), new Location(2849, 3361, 0), new Location(2850, 3361, 0)), - ENTRANA_PLATFORM(new Location(2879, 3334, 0), new Location(2879, 3335, 0), new Location(2879, 3338, 0), new Location(2879, 3339, 0), new Location(2877, 3342, 0), new Location(2876, 3342, 0), new Location(2875, 3342, 0), new Location(2875, 3331, 0), new Location(2876, 3331, 0), new Location(2877, 3331, 0)), - SEERS(new Location(2714, 3533, 0), new Location(2714, 3532, 0), new Location(2726, 3524, 0), new Location(2727, 3524, 0), new Location(2728, 3524, 0)), - DRAYNOR(new Location(3085, 3230, 0), new Location(3086, 3227, 0)), - BARBARIAN(new Location(3110, 3432, 0), new Location(3110, 3433, 0), new Location(3110, 3434, 0), Location.create(3104, 3425, 0), Location.create(3104, 3424, 0)), - LUMBRIDGE(new Location(3239, 3243, 0), new Location(3239, 3241, 0), new Location(3239, 3242, 0), Location.create(3238, 3251, 0), Location.create(3238, 3252, 0), Location.create(3238, 3253, 0)), - LUMBRIDGE_SWAMP(Location.create(3242, 3143, 0), Location.create(3242, 3148, 0), Location.create(3241, 3148, 0), Location.create(3240, 3147, 0), Location.create(3240, 3146, 0), Location.create(3244, 3150, 0), Location.create(3245, 3152, 0), Location.create(3246, 3155, 0), Location.create(3246, 3156, 0), new Location(3239, 3241, 0)), - LUMBRIDGE_MARSH(Location.create(3169, 3266, 0), Location.create(3168, 3266, 0), Location.create(3174, 3274, 0), Location.create(3173, 3274, 0)), - ALKHARID(new Location(3267, 3148, 0), new Location(3268, 3147, 0), new Location(3276, 3140, 0), new Location(3275, 3140, 0)), - FISHING_GUILD(new Location(2612, 3411, 0), new Location(2602, 3423, 0), new Location(2602, 3411, 0), new Location(2602, 3412, 0), new Location(2602, 3414, 0), new Location(2602, 3415, 0), new Location(2603, 3417, 0), new Location(2604, 3417, 0), new Location(2605, 3416, 0), new Location(2606, 3416, 0), new Location(2607, 3416, 0), new Location(2608, 3416, 0), new Location(2609, 3416, 0), new Location(2610, 3416, 0), new Location(2611, 3416, 0), new Location(2612, 3415, 0), new Location(2612, 3414, 0), new Location(2607, 3410, 0), new Location(2606, 3410, 0), new Location(2605, 3410, 0), new Location(2599, 3419, 0), new Location(2600, 3419, 0), new Location(2602, 3419, 0), new Location(2603, 3419, 0), new Location(2604, 3419, 0), new Location(2605, 3420, 0), new Location(2605, 3421, 0), new Location(2604, 3422, 0), new Location(2603, 3422, 0), new Location(2602, 3422, 0), new Location(2601, 3422, 0), new Location(2605, 3424, 0), new Location(2605, 3425, 0), new Location(2602, 3426, 0), new Location(2603, 3426, 0), new Location(2604, 3426, 0)), - GNOME(new Location(2388, 3424, 0), new Location(2390, 3422, 0), new Location(2391, 3421, 0), new Location(2382, 3413, 0), new Location(2382, 3414, 0), new Location(2382, 3415, 0)), CASTLEWAR(new Location(2465, 3156, 0), new Location(2464, 3155, 0), new Location(2468, 3157, 0), new Location(2469, 3157, 0), new Location(2471, 3158, 0), new Location(2472, 3156, 0), new Location(2462, 3145, 0), new Location(2461, 3150, 0), new Location(2461, 3151, 0)), SHILO(new Location(2460, 3144, 0), new Location(2461, 3150, 0), new Location(2461, 3151, 0), new Location(2853, 2977, 0), new Location(2854, 2977, 0), new Location(2855, 2977, 0), new Location(2856, 2977, 0), new Location(2858, 2976, 0), new Location(2859, 2976, 0), new Location(2860, 2976, 0), new Location(2863, 2975, 0), new Location(2863, 2975, 0), new Location(2864, 2975, 0), new Location(2865, 2972, 0), new Location(2860, 2972, 0), new Location(2855, 2974, 0), new Location(2852, 2973, 0)), KARAMJA(new Location(2923, 3178, 0), new Location(2923, 3179, 0), new Location(2923, 3180, 0), new Location(2924, 3181, 0), new Location(2925, 3181, 0), new Location(2926, 3180, 0), new Location(2926, 3179, 0), new Location(2926, 3178, 0), new Location(2926, 3177, 0), new Location(2926, 3176, 0)), DONATOR_ISLAND(Location.create(159, 41, 0), Location.create(160, 41, 0), Location.create(161, 41, 0), Location.create(162, 41, 0), Location.create(162, 30, 0)), - PISCATORIS(Location.create(2341, 3702, 0), Location.create(2342, 3702, 0), Location.create(2343, 3702, 0), Location.create(2344, 3702, 0), Location.create(2345, 3702, 0), Location.create(2346, 3702, 0), Location.create(2347, 3702, 0), Location.create(2349, 3702, 0), Location.create(2352, 3703, 0)), - TUTORIAL_ISLAND(Location.create(3101,3092, 0)), - WILDERNESS_ARENA(Location.create(3187, 3927, 0),Location.create(3185, 3926, 0),Location.create(3183, 3926, 0), Location.create(3181, 3926, 0)); - - FishSpots(final Location... locations) { - this.locations = locations; - } - - private final Location[] locations; - - public Location[] getLocations() { - return locations; - } - - public static HashMap locationMap = new HashMap<>(); - - static{ - FishSpots[] spots = values(); - int spotsLength = spots.length; - for(int x = 0; x < spotsLength; x++){ - Location[] locations = spots[x].locations; - int locationsLength = locations.length; - for(int y = 0; y < locationsLength; y++){ - locationMap.putIfAbsent(locations[y],spots[x]); - } - } - } - - //statically gets the fishing spot (loops suck btw) - public static FishSpots forLocation(Location loc) { - return locationMap.get(loc); - } -} \ No newline at end of file diff --git a/Server/src/main/content/global/skill/fishing/FishSpots.kt b/Server/src/main/content/global/skill/fishing/FishSpots.kt new file mode 100644 index 000000000..937c555c6 --- /dev/null +++ b/Server/src/main/content/global/skill/fishing/FishSpots.kt @@ -0,0 +1,224 @@ +package content.global.skill.fishing + +import core.game.world.map.Location + +enum class FishSpots(vararg val locations: Location) { + CATHERBY( + Location(2844, 3429, 0), + Location(2839, 3431, 0), + Location(2836, 3431, 0), + Location(2837, 3431, 0), + Location(2838, 3431, 0), + Location(2839, 3431, 0), + Location(2840, 3431, 0), + Location(2844, 3429, 0), + Location(2845, 3429, 0), + Location(2846, 3429, 0), + Location(2853, 3423, 0), + Location(2854, 3423, 0), + Location(2855, 3423, 0), + Location(2859, 3426, 0), + Location(2860, 3426, 0) + ), + ENTRANA( + Location(2842, 3359, 0), + Location(2843, 3359, 0), + Location(2844, 3359, 0), + Location(2847, 3361, 0), + Location(2848, 3361, 0), + Location(2849, 3361, 0), + Location(2850, 3361, 0) + ), + ENTRANA_PLATFORM( + Location(2879, 3334, 0), + Location(2879, 3335, 0), + Location(2879, 3338, 0), + Location(2879, 3339, 0), + Location(2877, 3342, 0), + Location(2876, 3342, 0), + Location(2875, 3342, 0), + Location(2875, 3331, 0), + Location(2876, 3331, 0), + Location(2877, 3331, 0) + ), + SEERS( + Location(2714, 3533, 0), + Location(2714, 3532, 0), + Location(2726, 3524, 0), + Location(2727, 3524, 0), + Location(2728, 3524, 0) + ), + DRAYNOR( + Location(3085, 3230, 0), + Location(3086, 3227, 0) + ), + BARBARIAN( + Location(3110, 3432, 0), + Location(3110, 3433, 0), + Location(3110, 3434, 0), + Location(3104, 3425, 0), + Location(3104, 3424, 0) + ), + LUMBRIDGE( + Location(3239, 3243, 0), + Location(3239, 3241, 0), + Location(3239, 3242, 0), + Location(3238, 3251, 0), + Location(3238, 3252, 0), + Location(3238, 3253, 0) + ), + LUMBRIDGE_SWAMP( + Location(3242, 3143, 0), + Location(3242, 3148, 0), + Location(3241, 3148, 0), + Location(3240, 3147, 0), + Location(3240, 3146, 0), + Location(3244, 3150, 0), + Location(3245, 3152, 0), + Location(3246, 3155, 0), + Location(3246, 3156, 0), + Location(3239, 3241, 0) + ), + LUMBRIDGE_MARSH( + Location(3169, 3266, 0), + Location(3168, 3266, 0), + Location(3174, 3274, 0), + Location(3173, 3274, 0) + ), + ALKHARID( + Location(3267, 3148, 0), + Location(3268, 3147, 0), + Location(3276, 3140, 0), + Location(3275, 3140, 0) + ), + FISHING_GUILD( + Location(2612, 3411, 0), + Location(2602, 3423, 0), + Location(2602, 3411, 0), + Location(2602, 3412, 0), + Location(2602, 3414, 0), + Location(2602, 3415, 0), + Location(2603, 3417, 0), + Location(2604, 3417, 0), + Location(2605, 3416, 0), + Location(2606, 3416, 0), + Location(2607, 3416, 0), + Location(2608, 3416, 0), + Location(2609, 3416, 0), + Location(2610, 3416, 0), + Location(2611, 3416, 0), + Location(2612, 3415, 0), + Location(2612, 3414, 0), + Location(2607, 3410, 0), + Location(2606, 3410, 0), + Location(2605, 3410, 0), + Location(2599, 3419, 0), + Location(2600, 3419, 0), + Location(2602, 3419, 0), + Location(2603, 3419, 0), + Location(2604, 3419, 0), + Location(2605, 3420, 0), + Location(2605, 3421, 0), + Location(2604, 3422, 0), + Location(2603, 3422, 0), + Location(2602, 3422, 0), + Location(2601, 3422, 0), + Location(2605, 3424, 0), + Location(2605, 3425, 0), + Location(2602, 3426, 0), + Location(2603, 3426, 0), + Location(2604, 3426, 0) + ), + GNOME( + Location(2388, 3424, 0), + Location(2390, 3422, 0), + Location(2391, 3421, 0), + Location(2382, 3413, 0), + Location(2382, 3414, 0), + Location(2382, 3415, 0) + ), + CASTLEWAR( + Location(2465, 3156, 0), + Location(2464, 3155, 0), + Location(2468, 3157, 0), + Location(2469, 3157, 0), + Location(2471, 3158, 0), + Location(2472, 3156, 0), + Location(2462, 3145, 0), + Location(2461, 3150, 0), + Location(2461, 3151, 0) + ), + SHILO( + Location(2460, 3144, 0), + Location(2461, 3150, 0), + Location(2461, 3151, 0), + Location(2853, 2977, 0), + Location(2854, 2977, 0), + Location(2855, 2977, 0), + Location(2856, 2977, 0), + Location(2858, 2976, 0), + Location(2859, 2976, 0), + Location(2860, 2976, 0), + Location(2863, 2975, 0), + Location(2863, 2975, 0), + Location(2864, 2975, 0), + Location(2865, 2972, 0), + Location(2860, 2972, 0), + Location(2855, 2974, 0), + Location(2852, 2973, 0) + ), + KARAMJA( + Location(2923, 3178, 0), + Location(2923, 3179, 0), + Location(2923, 3180, 0), + Location(2924, 3181, 0), + Location(2925, 3181, 0), + Location(2926, 3180, 0), + Location(2926, 3179, 0), + Location(2926, 3178, 0), + Location(2926, 3177, 0), + Location(2926, 3176, 0) + ), + PISCATORIS( + Location(2341, 3702, 0), + Location(2342, 3702, 0), + Location(2343, 3702, 0), + Location(2344, 3702, 0), + Location(2345, 3702, 0), + Location(2346, 3702, 0), + Location(2347, 3702, 0), + Location(2349, 3702, 0), + Location(2352, 3703, 0) + ), + TUTORIAL_ISLAND( + Location(3101, 3092, 0) + ), + WILDERNESS_AREA( + Location(3187, 3927, 0), + Location(3185, 3926, 0), + Location(3183, 3926, 0), + Location(3181, 3926, 0) + ); + + companion object { + private val locs: ArrayList = ArrayList() + private val locMap: HashMap = HashMap() + init { + for(value in values()) { + for(loc in value.locations) { + locMap[loc] = value + locs.add(loc) + } + } + } + + @JvmStatic + fun forLocation(loc: Location): FishSpots? { + return if (locMap[loc] == null) { + TUTORIAL_ISLAND + } else { + locMap[loc] + } + } + } +} \ No newline at end of file diff --git a/Server/src/main/content/global/skill/fishing/FishingNPC.java b/Server/src/main/content/global/skill/fishing/FishingNPC.java deleted file mode 100644 index e622667d0..000000000 --- a/Server/src/main/content/global/skill/fishing/FishingNPC.java +++ /dev/null @@ -1,103 +0,0 @@ -package content.global.skill.fishing; - -import core.game.node.entity.npc.AbstractNPC; -import core.game.world.GameWorld; -import core.game.world.map.Location; -import core.game.world.map.RegionManager; -import core.plugin.Initializable; -import core.tools.RandomFunction; - -/** - * Represents the fishing npc. - * @author Vexia - * - */ -@Initializable -public final class FishingNPC extends AbstractNPC { - - /** - * Represents the fishing spot. - */ - private FishSpots spot; - - /** - * Represents the delay of switching. - */ - private int switchDelay; - - /** - * Constructs a new {@code FishingNPC} {@code Object}. - */ - public FishingNPC() { - super(0, null); - spot = null; - } - - /** - * Constructs a new {@code FishingNPC} {@code Object}. - * @param id the id. - * @param location the location. - */ - public FishingNPC(int id, Location location) { - super(id, location, false); - switchDelay = getRandomDelay(); - } - - @Override - public AbstractNPC construct(int id, Location location, Object... objects) { - return new FishingNPC(id, location); - } - - @Override - public void handleTickActions() { - if (spot == null) { - return; - } - if (switchDelay < GameWorld.getTicks()) { - moveSpot(); - } - } - - @Override - public void init() { - super.init(); - spot = FishSpots.forLocation(getLocation()); - } - - /** - * Method used to move a spot. - */ - public void moveSpot() { - if (spot == null) { - if (isInvisible()) { - setInvisible(false); - } else { - setInvisible(true); - } - switchDelay = GameWorld.getTicks() + RandomFunction.random(200, 390); - return; - } - if (spot == FishSpots.TUTORIAL_ISLAND) { - return; - } - Location rand = spot.getLocations()[RandomFunction.random(spot.getLocations().length)]; - if (RegionManager.getLocalNpcs(rand, 0).size() == 0) { - getProperties().setTeleportLocation(rand); - } - switchDelay = GameWorld.getTicks() + getRandomDelay(); - } - - /** - * Gets the random delay. - * @return the delay. - */ - private int getRandomDelay() { - return RandomFunction.random(200, 390); - } - - @Override - public int[] getIds() { - return new int[] { 316, 319, 320, 323, 325, 326, 327, 330, 332, 404, 952, 1174, 1175, 1331, 2067, 2068, 2724, 4908, 5748, 5749, 7045, 313, 322, 334, 406, 1191, 1333, 1405, 1406, 3574, 3575, 3848, 3849, 5471, 7044, 233, 234, 235, 236, 309, 310, 311, 314, 315, 317, 318, 328, 329, 331, 403, 800, 927, 1189, 1190, 1236, 1237, 1238, 3019, 7636, 312, 321, 324, 333, 405, 1332, 1399, 3804, 5470, 7046 }; - } - -} diff --git a/Server/src/main/content/global/skill/fishing/FishingNPC.kt b/Server/src/main/content/global/skill/fishing/FishingNPC.kt new file mode 100644 index 000000000..6c7d34629 --- /dev/null +++ b/Server/src/main/content/global/skill/fishing/FishingNPC.kt @@ -0,0 +1,53 @@ +package content.global.skill.fishing + +import core.api.* +import core.game.node.entity.npc.NPC +import core.game.node.entity.npc.NPCBehavior +import core.tools.RandomFunction + +private val fishingSpots = FishingSpot.getAllIds() +class FishingNPC : NPCBehavior(*fishingSpots) { + + override fun onCreation(self: NPC) { + setAttribute(self, "fishing:spot", FishSpots.forLocation(self.location)) + setAttribute(self, "fishing:switchdelay", 0) + } + + override fun tick(self: NPC): Boolean { + if(getSpot(self) == null) { + return false + } + if(getAttribute(self, "fishing:switchdelay", 0) < getWorldTicks()) { + moveSpot(self) + return false + } + return false + } + + private fun moveSpot(self: NPC) { + when (val spot = getSpot(self)) { + null -> { + self.isInvisible = !self.isInvisible + setAttribute(self, "fishing:switchdelay", getWorldTicks() + getRandomDelay()) + return + } + FishSpots.TUTORIAL_ISLAND -> { + return + } + else -> { + val randLoc = spot.locations[RandomFunction.random(spot.locations.size)] + if(findLocalNPCs(randLoc, 0).isEmpty()) self.location = randLoc + setAttribute(self, "fishing:switchdelay", getWorldTicks() + getRandomDelay()) + } + } + } + + private fun getRandomDelay(): Int { + return RandomFunction.random(200, 390) + } + + private fun getSpot(npc: NPC): FishSpots? { + return getAttribute(npc, "fishing:spot", null) + } + +} \ No newline at end of file diff --git a/Server/src/main/content/global/skill/fishing/FishingOption.java b/Server/src/main/content/global/skill/fishing/FishingOption.java deleted file mode 100644 index b1652e64b..000000000 --- a/Server/src/main/content/global/skill/fishing/FishingOption.java +++ /dev/null @@ -1,213 +0,0 @@ -package content.global.skill.fishing; - -import core.game.container.Container; -import core.game.node.entity.skill.Skills; -import core.game.node.entity.player.Player; -import core.game.node.item.Item; -import core.game.world.update.flag.context.Animation; -import core.tools.RandomFunction; -import org.rs09.consts.Items; - -import java.util.Arrays; -import java.util.HashMap; - -/** - * Represents a fishing option. - * @author Emperor - */ -public enum FishingOption { - - CRAYFISH_CAGE(new Item(13431), 1, Animation.create(619), null, "cage", Fish.CRAYFISH), - SMALL_NET(new Item(303), 1, Animation.create(621), null, "net", Fish.SHRIMP, Fish.ANCHOVIE), - BAIT(new Item(307), 5, Animation.create(622), new Item[]{new Item(313)}, "bait", Fish.SARDINE, Fish.HERRING), - LURE(new Item(309), 20, new Animation(622), new Item[]{new Item(Items.FEATHER_314), new Item(Items.STRIPY_FEATHER_10087)}, "lure", Fish.TROUT, Fish.SALMON, Fish.RAINBOW_FISH), - L_BAIT(new Item(307), 25, Animation.create(622), new Item[]{new Item(313)}, "bait", Fish.PIKE), - CAGE(new Item(301), 40, Animation.create(619), null, "cage", Fish.LOBSTER), - HARPOON(new Item(311), 35, Animation.create(618), null, "harpoon", Fish.TUNA, Fish.SWORDFISH), - BARB_HARPOON(new Item(10129), 35, Animation.create(618), null, "harpoon", Fish.TUNA, Fish.SWORDFISH), - BIG_NET(new Item(305), 16, Animation.create(620), null, "net", Fish.MACKEREL, Fish.COD, Fish.BASS, Fish.SEAWEED), - N_HARPOON(new Item(311), 76, Animation.create(618), null, "harpoon", Fish.SHARK), - H_NET(new Item(303), 62, Animation.create(621), null, "net", Fish.MONKFISH), - MORTMYRE_ROD(new Item(307), 5, Animation.create(622), new Item[]{new Item(313)},"bait", Fish.SLIMY_EEL), - LUMBDSWAMP_ROD(new Item(307), 5, Animation.create(622), new Item[]{new Item(313)}, "bait", Fish.SLIMY_EEL, Fish.FROG_SPAWN), - KBWANJI_NET(new Item(Items.SMALL_FISHING_NET_303), 5, Animation.create(621), null, "net", Fish.KARAMBWANJI), - KARAMBWAN_VES(new Item(Items.KARAMBWAN_VESSEL_3157), 65, Animation.create(1193), new Item[]{new Item(Items.RAW_KARAMBWANJI_3150)}, "fish", Fish.KARAMBWAN), - OILY_FISHING_ROD(new Item(Items.OILY_FISHING_ROD_1585), 53, Animation.create(622), new Item[]{new Item(313)}, "bait", Fish.LAVA_EEL); - - public static final HashMap nameMap = new HashMap<>(); - static{ - for(FishingOption option : FishingOption.values()){ - nameMap.putIfAbsent(option.name,option); - } - } - - public static FishingOption forName(String name){ - return nameMap.get(name); - } - /** - * The tool required. - */ - private final Item tool; - - /** - * The fishing level required. - */ - private final int level; - - /** - * The fishing animation. - */ - private final Animation animation; - - /** - * The bait. - */ - private final Item[] bait; - - /** - * The option name. - */ - private final String name; - - /** - * The fish to catch. - */ - private final Fish[] fish; - - /** - * Constructs a new {@code FishingOption} {@code Object}. - * @param tool The tool needed. - * @param level The fishing level required. - * @param animation The animation. - * @param fish The fish to catch. - */ - FishingOption(Item tool, int level, Animation animation, Item[] bait, String name, Fish... fish) { - this.tool = tool; - this.level = level; - this.animation = animation; - this.bait = bait; - this.name = name; - Arrays.sort(fish, (x, y) -> y.getLevel() - x.getLevel()); - this.fish = fish; - } - - /** - * Method used to get a random {@link Fish}. - * @return the {@link Fish}. - */ - public Fish rollFish(final Player player) { - if (this == BIG_NET) { - switch (RandomFunction.randomize(100)) { - case 0: - return Fish.OYSTER; - case 50: - return Fish.CASKET; - case 90: - return Fish.SEAWEED; - } - } - int visibleLevel = player.getSkills().getLevel(Skills.FISHING); - int invisibleLevel = visibleLevel + player.getFamiliarManager().getBoost(Skills.FISHING); - for(Fish f : fish) { - if(f.getLevel() > player.getSkills().getLevel(Skills.FISHING)) { - continue; - } - if(this == LURE && (player.getInventory().contains(Items.STRIPY_FEATHER_10087, 1) != (f == Fish.RAINBOW_FISH))) { - continue; - } - double chance = f.getSuccessChance(invisibleLevel); - //System.out.printf("rollFish: %s %s %s %s %s\n", player.getName(), f.getItem().getName(), f.getLowChance(), f.getHighChance(), chance); - if(RandomFunction.random(0.0, 1.0) < chance) { - return f; - } - } - return null; - } - - /** - * Gets the start message. - * @return The start message. - */ - public String getStartMessage() { - if (name.equals("net")) { - return "You cast out your net..."; - } - return "You attempt to catch a fish."; - } - - /** - * Gets the tool. - * @return The tool. - */ - public Item getTool() { - return tool; - } - - /** - * Gets the level. - * @return The level. - */ - public int getLevel() { - return level; - } - - /** - * Gets the animation. - * @return The animation. - */ - public Animation getAnimation() { - return animation; - } - - public String getBaitName() { - if(bait != null && bait.length > 0) { - return bait[0].getName(); - } else { - return "null"; - } - - } - - public boolean hasBait(Container inventory) { - if(bait == null) { - return true; - } else { - boolean any_bait = false; - for(Item b : bait) { - any_bait = any_bait || inventory.containsItem(b); - } - return any_bait; - } - } - - public boolean removeBait(Container inventory) { - if(bait == null) { - return true; - } else { - // Remove more specific bait (later in the list) first. - for(int i = bait.length; i > 0; i--) { - if(inventory.remove(bait[i-1])) { - return true; - } - } - return false; - } - } - - /** - * Gets the name. - * @return The name. - */ - public String getName() { - return name; - } - - /** - * Gets the fish. - * @return The fish. - */ - public Fish[] getFish() { - return fish; - } - -} diff --git a/Server/src/main/content/global/skill/fishing/FishingOption.kt b/Server/src/main/content/global/skill/fishing/FishingOption.kt new file mode 100644 index 000000000..2cf25e5e9 --- /dev/null +++ b/Server/src/main/content/global/skill/fishing/FishingOption.kt @@ -0,0 +1,103 @@ +package content.global.skill.fishing + +import core.api.* +import core.game.node.entity.player.Player +import core.game.node.entity.skill.Skills +import core.game.world.update.flag.context.Animation +import core.tools.RandomFunction +import org.rs09.consts.Items + +enum class FishingOption(val tool: Int, val level: Int, val animation: Animation, val bait: IntArray?, val option: String, vararg val fish: Fish) { + CRAYFISH_CAGE(Items.CRAYFISH_CAGE_13431, 1, Animation(10009), null, "cage", Fish.CRAYFISH), + SMALL_NET(Items.SMALL_FISHING_NET_303, 1, Animation(621), null, "net", Fish.SHRIMP, Fish.ANCHOVIE), + BAIT(Items.FISHING_ROD_307, 5, Animation(622), intArrayOf(Items.FISHING_BAIT_313), "bait", Fish.SARDINE, Fish.HERRING), + LURE(Items.FLY_FISHING_ROD_309, 20, Animation(622), intArrayOf(Items.FEATHER_314, Items.STRIPY_FEATHER_10087), "lure", Fish.TROUT, Fish.SALMON, Fish.RAINBOW_FISH), + PIKE_BAIT(Items.FISHING_ROD_307, 25, Animation(622), intArrayOf(Items.FISHING_BAIT_313), "bait", Fish.PIKE), + LOBSTER_CAGE(Items.LOBSTER_POT_301, 40, Animation(619), null, "cage", Fish.LOBSTER), + HARPOON(Items.HARPOON_311, 35, Animation(618), null, "harpoon", Fish.TUNA, Fish.SWORDFISH), + BARB_HARPOON(Items.BARB_TAIL_HARPOON_10129, 35, Animation(618), null, "harpoon", Fish.TUNA, Fish.SWORDFISH), + BIG_NET(Items.BIG_FISHING_NET_305, 16, Animation(620), null, "net", Fish.MACKEREL, Fish.COD, Fish.BASS, Fish.SEAWEED), + SHARK_HARPOON(Items.HARPOON_311, 76, Animation(618), null, "harpoon", Fish.SHARK), + MONKFISH_NET(Items.SMALL_FISHING_NET_303, 62, Animation(621), null, "net", Fish.MONKFISH), + MORTMYRE_ROD(Items.FISHING_ROD_307, 5, Animation(622), intArrayOf(Items.FISHING_BAIT_313), "bait", Fish.SLIMY_EEL), + LUMBDSWAMP_ROD(Items.FISHING_ROD_307, 5, Animation(622), intArrayOf(Items.FISHING_BAIT_313), "bait", Fish.SLIMY_EEL, Fish.FROG_SPAWN), + KBWANJI_NET(Items.SMALL_FISHING_NET_303, 5, Animation(621), null, "net", Fish.KARAMBWANJI), + KARAMBWAN_VES(Items.KARAMBWAN_VESSEL_3157, 65, Animation(1193), intArrayOf((Items.RAW_KARAMBWANJI_3150)), "fish", Fish.KARAMBWAN), + OILY_FISHING_ROD(Items.OILY_FISHING_ROD_1585, 53, Animation(622), intArrayOf(Items.FISHING_BAIT_313), "bait", Fish.LAVA_EEL); + + companion object { + private val nameMap: HashMap = HashMap() + + init { + for(value in values()) { + nameMap[value.option] = value + } + } + + fun forName(opName: String): FishingOption? { + return nameMap[opName] + } + } + + fun rollFish(player: Player): Fish? { + if(this == BIG_NET) { + when(RandomFunction.randomize(100)) { + 0 -> return Fish.OYSTER + 50 -> return Fish.CASKET + 90 -> return Fish.SEAWEED + } + } + val vlvl = getDynLevel(player, Skills.FISHING) + val ilvl = vlvl + player.familiarManager.getBoost(Skills.FISHING) + for(f in fish) { + if(f.level > vlvl) { + continue + } + if(this == LURE && inInventory(player, Items.STRIPY_FEATHER_10087) != (f == Fish.RAINBOW_FISH)) { + continue + } + val chance = f.getSuccessChance(ilvl) + if(RandomFunction.random(0.0, 1.0) < chance) { + return f + } + } + return null + } + + fun getBaitName(): String { + if(bait != null && bait.isNotEmpty()) { + return getItemName(bait[0]) + } + return "none" + } + + fun hasBait(player: Player): Boolean { + return if(bait == null) true else { + var anyBait = false + for(b in bait) { + anyBait = anyBait || inInventory(player, b) + } + anyBait + } + } + + fun removeBait(player: Player): Boolean { + return if (bait == null) { + true + } else { + for (i in bait.size downTo 1) { + if (removeItem(player, bait[i - 1], Container.INVENTORY)) { + return true + } + } + false + } + } + + fun getStartMessage(): String { + return if(option == "net") + "You cast out your net..." + else + "You attempt to catch a fish." + } +} \ No newline at end of file diff --git a/Server/src/main/content/global/skill/fishing/FishingSpot.java b/Server/src/main/content/global/skill/fishing/FishingSpot.java deleted file mode 100644 index fcaf85778..000000000 --- a/Server/src/main/content/global/skill/fishing/FishingSpot.java +++ /dev/null @@ -1,82 +0,0 @@ -package content.global.skill.fishing; - -import java.util.HashMap; - -/** - * Represents a fishing spot. - * @author ceikry - */ -public enum FishingSpot { - - NET_BAIT(new int[] { 952, 316, 319, 320, 323, 325, 326, 327, 330, 332, 404, 1331, 2724, 4908, 7045 }, FishingOption.SMALL_NET, FishingOption.BAIT), - LURE_BAIT(new int[] { 309, 310, 311, 314, 315, 317, 318, 328, 329, 331, 403, 927, 1189, 1190, 3019 }, FishingOption.LURE, FishingOption.L_BAIT), - CAGE_HARPOON(new int[] { 312, 321, 324, 333, 405, 1332, 1399, 3804, 5470, 7046}, FishingOption.CAGE, FishingOption.HARPOON), - NET_HARPOON(new int[] { 313, 322, 334, 406, 1191, 1333, 1405, 1406, 3574, 3575, 5471, 7044 }, FishingOption.BIG_NET, FishingOption.N_HARPOON), - HARPOON_NET(new int[] { 3848, 3849 }, FishingOption.HARPOON, FishingOption.H_NET, FishingOption.BARB_HARPOON), - SPOT_MORTMYRE(new int[] {5748, 5749}, FishingOption.MORTMYRE_ROD), - SPOT_LUMDSAWMP(new int[] {2067, 2068}, FishingOption.LUMBDSWAMP_ROD), - SPOT_KBWANJI(new int[] {1174}, FishingOption.KBWANJI_NET), - SPOT_KARAMBWAN(new int[] {1177}, FishingOption.KARAMBWAN_VES), - BAIT_EELS(new int[] {800}, FishingOption.OILY_FISHING_ROD); - - public static HashMap spotMap = new HashMap<>(); - - static{ - FishingSpot[] spots = values(); - for (FishingSpot spot : spots) { - int[] spotIds = spot.ids; - for (int spotId : spotIds) { - spotMap.putIfAbsent(spotId, spot); - } - } - } - - public static FishingSpot forId(int npcId) { - return spotMap.get(npcId); - } - - - /** - * The NPC ids. - */ - private final int[] ids; - - /** - * The fishing options. - */ - private FishingOption options[]; - - /** - * Constructs a new {@code FishingSpot} {@code Object}. - * @param ids The NPC ids. - */ - FishingSpot(int[] ids, FishingOption... options) { - this.ids = ids; - this.options = options; - } - - public FishingOption getOptionByName(String name){ - for(FishingOption o : this.options){ - if(o.getName().equals(name)){return o;} - } - - return FishingOption.SMALL_NET; //safe, default return. - } - - /** - * Gets the ids. - * @return The ids. - */ - public int[] getIds() { - return ids; - } - - /** - * Gets the options. - * @return The options. - */ - public FishingOption[] getOptions() { - return options; - } - -} diff --git a/Server/src/main/content/global/skill/fishing/FishingSpot.kt b/Server/src/main/content/global/skill/fishing/FishingSpot.kt new file mode 100644 index 000000000..cbfda947b --- /dev/null +++ b/Server/src/main/content/global/skill/fishing/FishingSpot.kt @@ -0,0 +1,164 @@ +package content.global.skill.fishing + +import org.rs09.consts.NPCs + +enum class FishingSpot(val ids: IntArray, vararg val options: FishingOption) { + NET_BAIT( + intArrayOf( + NPCs.FISHING_SPOT_952, + NPCs.FISHING_SPOT_316, + NPCs.FISHING_SPOT_319, + NPCs.FISHING_SPOT_320, + NPCs.FISHING_SPOT_323, + NPCs.FISHING_SPOT_325, + NPCs.FISHING_SPOT_326, + NPCs.FISHING_SPOT_327, + NPCs.FISHING_SPOT_330, + NPCs.FISHING_SPOT_332, + NPCs.FISHING_SPOT_404, + NPCs.FISHING_SPOT_1331, + NPCs.FISHING_SPOT_2724, + NPCs.FISHING_SPOT_4908, + NPCs.FISHING_SPOT_7045 + ), + FishingOption.SMALL_NET, + FishingOption.BAIT + ), + CAGE( + intArrayOf( + NPCs.FISHING_SPOT_6267, + NPCs.FISHING_SPOT_6996, + NPCs.FISHING_SPOT_7862, + NPCs.FISHING_SPOT_7863, + NPCs.FISHING_SPOT_7864 + ), + FishingOption.CRAYFISH_CAGE + ), + LURE_BAIT( + intArrayOf( + NPCs.FISHING_SPOT_309, + NPCs.FISHING_SPOT_310, + NPCs.FISHING_SPOT_311, + NPCs.FISHING_SPOT_314, + NPCs.FISHING_SPOT_315, + NPCs.FISHING_SPOT_317, + NPCs.FISHING_SPOT_318, + NPCs.FISHING_SPOT_328, + NPCs.FISHING_SPOT_329, + NPCs.FISHING_SPOT_331, + NPCs.FISHING_SPOT_403, + NPCs.FISHING_SPOT_927, + NPCs.FISHING_SPOT_1189, + NPCs.FISHING_SPOT_1190, + NPCs.FISHING_SPOT_3019 + ), + FishingOption.LURE, + FishingOption.PIKE_BAIT + ), + CAGE_HARPOON( + intArrayOf( + NPCs.FISHING_SPOT_312, + NPCs.FISHING_SPOT_321, + NPCs.FISHING_SPOT_324, + NPCs.FISHING_SPOT_333, + NPCs.FISHING_SPOT_405, + NPCs.FISHING_SPOT_1332, + NPCs.FISHING_SPOT_1399, + NPCs.FISHING_SPOT_3804, + NPCs.FISHING_SPOT_5470, + NPCs.FISHING_SPOT_7046 + ), + FishingOption.LOBSTER_CAGE, + FishingOption.HARPOON + ), + NET_HARPOON( + intArrayOf( + NPCs.FISHING_SPOT_313, + NPCs.FISHING_SPOT_322, + NPCs.FISHING_SPOT_334, + NPCs.FISHING_SPOT_406, + NPCs.FISHING_SPOT_1191, + NPCs.FISHING_SPOT_1333, + NPCs.FISHING_SPOT_1405, + NPCs.FISHING_SPOT_1406, + NPCs.FISHING_SPOT_3574, + NPCs.FISHING_SPOT_3575, + NPCs.FISHING_SPOT_5471, + NPCs.FISHING_SPOT_7044 + ), + FishingOption.BIG_NET, + FishingOption.SHARK_HARPOON + ), + HARPOON_NET( + intArrayOf( + NPCs.FISHING_SPOT_3848, + NPCs.FISHING_SPOT_3849 + ), + FishingOption.HARPOON, + FishingOption.MONKFISH_NET + ), + SPOT_MORTMYRE( + intArrayOf( + NPCs.FISHING_SPOT_5748, + NPCs.FISHING_SPOT_5749 + ), + FishingOption.MORTMYRE_ROD + ), + SPOT_LUMDSWAMP( + intArrayOf( + NPCs.FISHING_SPOT_2067, + NPCs.FISHING_SPOT_2068 + ), + FishingOption.LUMBDSWAMP_ROD + ), + SPOT_KBWANJI( + intArrayOf( + NPCs.FISHING_SPOT_1174 + ), + FishingOption.KBWANJI_NET + ), + SPOT_KARAMBWAN( + intArrayOf( + NPCs.FISHING_SPOT_1177 + ), + FishingOption.KARAMBWAN_VES + ), + BAIT_EELS( + intArrayOf( + NPCs.FISHING_SPOT_800 + ), + FishingOption.OILY_FISHING_ROD + ); + + companion object { + private val spotMap: HashMap = HashMap() + private val array: ArrayList = ArrayList() + + init { + val spots = values() + for(spot in spots) { + for(id in spot.ids) { + spotMap[id] = spot + array.add(id) + } + } + } + + fun forId(npcID: Int) : FishingSpot? { + return spotMap[npcID] + } + + fun getAllIds() : IntArray { + return array.toIntArray() + } + } + + fun getOptionByName(op: String) : FishingOption? { + for(o in options) { + if(o.option == op.lowercase()) { + return o + } + } + return null + } +} \ No newline at end of file diff --git a/Server/src/main/content/global/skill/gather/fishing/FishingListener.kt b/Server/src/main/content/global/skill/gather/fishing/FishingListener.kt index d0b666461..a4e540838 100644 --- a/Server/src/main/content/global/skill/gather/fishing/FishingListener.kt +++ b/Server/src/main/content/global/skill/gather/fishing/FishingListener.kt @@ -15,6 +15,7 @@ import core.game.node.Node import core.game.node.entity.npc.NPC import core.game.node.entity.player.Player import core.game.node.entity.skill.Skills +import core.game.node.item.Item import core.game.system.command.sets.STATS_BASE import core.game.system.command.sets.STATS_FISH import core.game.world.map.path.Pathfinder @@ -37,19 +38,19 @@ class FishingListener : InteractionListener{ private fun handleFishing(player: Player, node: Node, state: Int) : Boolean { val npc = node as? NPC ?: return clearScripts(player) val spot = FishingSpot.forId(npc.id) ?: return clearScripts(player) - val op = spot.getOptionByName(getUsedOption(player)) + val op = spot.getOptionByName(getUsedOption(player)) ?: return clearScripts(player) var forager: Forager? = null if (player.familiarManager.hasFamiliar() && player.familiarManager.familiar is Forager) { forager = player.familiarManager.familiar as Forager } - if (!finishedMoving(player)) + if (!finishedMoving(player)) { return restartScript(player) + } - if (state == 0) { - if (!checkRequirements(player, op, node)) - return clearScripts(player) + if (state == 1) { + if (!checkRequirements(player, op, node)) return clearScripts(player) forager?.let { val dest = player.location.transform(player.direction) Pathfinder.find(it, dest).walk(it) @@ -61,26 +62,21 @@ class FishingListener : InteractionListener{ anim(player, op) forager?.handlePassiveAction() - val fish = op.rollFish(player) ?: return delayClock(player, Clocks.SKILLING, 5) - - if (!hasSpaceFor(player, fish.item) || !op.removeBait(player.inventory)) { - return restartScript(player) - } + val fish = op?.rollFish(player) ?: return delayClock(player, Clocks.SKILLING, 5) + if (!hasSpaceFor(player, Item(fish.id)) || !op.removeBait(player)) return restartScript(player) + player.dispatch(ResourceProducedEvent(fish.id, fish.getItem().amount, node)) + val item = fish.getItem() - player.dispatch(ResourceProducedEvent(fish.item.id, fish.item.amount, node)) - - val item = fish.item if (isActive(SkillcapePerks.GREAT_AIM, player) && RandomFunction.roll(20)) { addItemOrDrop(player, item.id, item.amount) sendMessage(player, colorize("%RYour expert aim catches you a second fish.")) } + addItemOrDrop(player, item.id, item.amount) player.incrementAttribute("$STATS_BASE:$STATS_FISH") rewardXP(player, Skills.FISHING, fish.experience) delayClock(player, Clocks.SKILLING, 5) - - if (!checkRequirements(player, op, node)) - return clearScripts(player) + if (!checkRequirements(player, op, node)) return clearScripts(player) } return keepRunning(player) } @@ -91,17 +87,17 @@ class FishingListener : InteractionListener{ } private fun checkRequirements(player: Player, option: FishingOption, node: Node) : Boolean { - if (!player.inventory.containsItem(option.tool) && !hasBarbTail(player, option)) { - player.dialogueInterpreter.sendDialogue("You need a " + option.tool.name.toLowerCase() + " to catch these fish.") + if (!inInventory(player, option.tool) && !hasBarbTail(player, option)) { + player.dialogueInterpreter.sendDialogue("You need a " + getItemName(option.tool).lowercase() + " to catch these fish.") return false } - if (!option.hasBait(player.inventory)) { - player.dialogueInterpreter.sendDialogue("You don't have any " + option.getBaitName().toLowerCase() + "s left.") + if (!option.hasBait(player)) { + player.dialogueInterpreter.sendDialogue("You don't have any " + option.getBaitName().lowercase() + "s left.") return false } if (player.skills.getLevel(Skills.FISHING) < option!!.level) { val f = option!!.fish[option!!.fish.size - 1] - player.dialogueInterpreter.sendDialogue("You need a fishing level of " + f.level + " to catch " + (if (f == Fish.SHRIMP || f == Fish.ANCHOVIE) "" else "a") + " " + f.item.name.toLowerCase() + ".".trim { it <= ' ' }) + player.dialogueInterpreter.sendDialogue("You need a fishing level of " + f.level + " to catch " + (if (f == Fish.SHRIMP || f == Fish.ANCHOVIE) "" else "a") + " " + getItemName(f.id).lowercase() + ".".trim { it <= ' ' }) return false } if (player.inventory.freeSlots() == 0) { @@ -113,14 +109,10 @@ class FishingListener : InteractionListener{ private fun hasBarbTail(player: Player, option: FishingOption): Boolean { - if (option == FishingOption.HARPOON || option == FishingOption.N_HARPOON) { - if (player.inventory.containsItem(FishingOption.BARB_HARPOON.tool) || player.equipment.containsItem( - FishingOption.BARB_HARPOON.tool - ) - ) { - return true - } + val bh = FishingOption.BARB_HARPOON.tool + if (option == FishingOption.HARPOON || option == FishingOption.SHARK_HARPOON) { + if (inInventory(player, bh) || inEquipment(player, bh)) return true } return false } -} +} \ No newline at end of file diff --git a/Server/src/main/content/global/skill/gather/fishing/FishingPulse.kt b/Server/src/main/content/global/skill/gather/fishing/FishingPulse.kt index 160485157..b779ed9c0 100644 --- a/Server/src/main/content/global/skill/gather/fishing/FishingPulse.kt +++ b/Server/src/main/content/global/skill/gather/fishing/FishingPulse.kt @@ -12,6 +12,10 @@ import content.global.skill.fishing.FishingOption import content.global.skill.skillcapeperks.SkillcapePerks import content.global.skill.skillcapeperks.SkillcapePerks.Companion.isActive import content.global.skill.summoning.familiar.Forager +import core.api.addItem +import core.api.getItemName +import core.api.inEquipment +import core.api.inInventory import core.game.node.item.Item import core.game.system.task.Pulse import core.game.world.map.Location @@ -52,21 +56,21 @@ class FishingPulse(player: Player?, npc: NPC, private val option: FishingOption? if (option == null) { return false } - player.debug(player.inventory.containsItem(option.tool).toString()) - if (!player.inventory.containsItem(option.tool) && !hasBarbTail()) { + player.debug(inInventory(player, option.tool).toString()) + if (!inInventory(player, option.tool) && !hasBarbTail()) { - player.dialogueInterpreter.sendDialogue("You need a " + option.tool.name.toLowerCase() + " to catch these fish.") + player.dialogueInterpreter.sendDialogue("You need a " + getItemName(option.tool).lowercase() + " to catch these fish.") stop() return false } - if (!option.hasBait(player.inventory)) { - player.dialogueInterpreter.sendDialogue("You don't have any " + option.getBaitName().toLowerCase() + "s left.") + if (!option.hasBait(player)) { + player.dialogueInterpreter.sendDialogue("You don't have any " + option.getBaitName().lowercase() + "s left.") stop() return false } if (player.skills.getLevel(Skills.FISHING) < option!!.level) { val f = option!!.fish[option!!.fish.size - 1] - player.dialogueInterpreter.sendDialogue("You need a fishing level of " + f.level + " to catch " + (if (f == Fish.SHRIMP || f == Fish.ANCHOVIE) "" else "a") + " " + f.item.name.toLowerCase() + ".".trim { it <= ' ' }) + player.dialogueInterpreter.sendDialogue("You need a fishing level of " + f.level + " to catch " + (if (f == Fish.SHRIMP || f == Fish.ANCHOVIE) "" else "a") + " " + getItemName(f.id).lowercase() + ".".trim { it <= ' ' }) stop() return false } @@ -109,18 +113,18 @@ class FishingPulse(player: Player?, npc: NPC, private val option: FishingOption? forager.handlePassiveAction() } if (success()) { - if (player.inventory.hasSpaceFor(fish!!.item) && option!!.removeBait(player.inventory)) { + if (player.inventory.hasSpaceFor(Item(fish!!.id)) && option!!.removeBait(player)) { if (player.skillTasks.hasTask()) { updateSkillTask() } - player.dispatch(ResourceProducedEvent(fish!!.item.id, fish!!.item.amount, node!!)) + player.dispatch(ResourceProducedEvent(fish!!.id, 1, node!!)) SkillingPets.checkPetDrop(player, SkillingPets.HERON) - val item = fish!!.item + val item = fish!! if (isActive(SkillcapePerks.GREAT_AIM, player) && RandomFunction.random(100) <= 5) { - player.inventory.add(item) + addItem(player, item.id) player.sendMessage(colorize("%RYour expert aim catches you a second fish.")) } - player.inventory.add(item) + addItem(player, item.id) var fishCaught = player.getAttribute(STATS_BASE + ":" + STATS_FISH, 0) player.setAttribute("/save:$STATS_BASE:$STATS_FISH", ++fishCaught) player.skills.addExperience(Skills.FISHING, fish!!.experience, true) @@ -174,16 +178,12 @@ class FishingPulse(player: Player?, npc: NPC, private val option: FishingOption? } private fun isBareHanded(p: Player): Boolean { - if (option == FishingOption.HARPOON || option == FishingOption.N_HARPOON) { - if (checkFish(p) > 0 && !(player.inventory.containsItem( - option.tool - ) || player.equipment.containsItem(option.tool) || hasBarbTail()) + if (option == FishingOption.HARPOON || option == FishingOption.SHARK_HARPOON) { + if (checkFish(p) > 0 && !(inInventory(player, option.tool) || inEquipment(player, option.tool) || hasBarbTail()) ) { return true } - if (checkFish(p) > 2 && !(player.inventory.containsItem( - option.tool - ) || player.equipment.containsItem(option.tool) || hasBarbTail()) + if (checkFish(p) > 2 && !(inInventory(player, option.tool) || inEquipment(player, option.tool) || hasBarbTail()) ) { return true } @@ -229,11 +229,9 @@ class FishingPulse(player: Player?, npc: NPC, private val option: FishingOption? * @return `True` if so. */ private fun hasBarbTail(): Boolean { - if (option == FishingOption.HARPOON || option == FishingOption.N_HARPOON) { - if (player.inventory.containsItem(FishingOption.BARB_HARPOON.tool) || player.equipment.containsItem( - FishingOption.BARB_HARPOON.tool - ) - ) { + val bh = FishingOption.BARB_HARPOON.tool + if (option == FishingOption.HARPOON || option == FishingOption.SHARK_HARPOON) { + if (inInventory(player, bh) || inEquipment(player, bh)) { return true } } @@ -242,12 +240,12 @@ class FishingPulse(player: Player?, npc: NPC, private val option: FishingOption? override fun message(type: Int) { when (type) { - 0 -> player.packetDispatch.sendMessage(option!!.startMessage) + 0 -> player.packetDispatch.sendMessage(option!!.getStartMessage()) 2 -> { player.packetDispatch.sendMessage( - if (fish == Fish.ANCHOVIE || fish == Fish.SHRIMP) "You catch some " + fish!!.item.name.toLowerCase() + if (fish == Fish.ANCHOVIE || fish == Fish.SHRIMP) "You catch some " + getItemName(fish!!.id).lowercase() .replace("raw", "") - .trim { it <= ' ' } + "." else "You catch a " + fish!!.item.name.toLowerCase() + .trim { it <= ' ' } + "." else "You catch a " + getItemName(fish!!.id).lowercase() .replace("raw", "").trim { it <= ' ' } + ".") if (player.inventory.freeSlots() == 0) { player.dialogueInterpreter.sendDialogue("You don't have enough space in your inventory.") diff --git a/Server/src/main/content/minigame/fishingtrawler/TrawlerLoot.kt b/Server/src/main/content/minigame/fishingtrawler/TrawlerLoot.kt index 48dd0493c..70ff89220 100644 --- a/Server/src/main/content/minigame/fishingtrawler/TrawlerLoot.kt +++ b/Server/src/main/content/minigame/fishingtrawler/TrawlerLoot.kt @@ -31,7 +31,7 @@ object TrawlerLoot { //val chance = RandomFunction.getSkillSuccessChance(lo, hi, fishLevel) val chance = (fishLevel.toDouble() - 15.0)*((hi - lo) / (99.0 - 15.0)) + lo if(RandomFunction.random(0.0, 1.0) < chance) { - return f.item + return Item(f.id) } } } diff --git a/Server/src/main/core/api/ContentAPI.kt b/Server/src/main/core/api/ContentAPI.kt index 16b22952f..0bb6f8f29 100644 --- a/Server/src/main/core/api/ContentAPI.kt +++ b/Server/src/main/core/api/ContentAPI.kt @@ -814,6 +814,17 @@ fun findLocalNPC(entity: Entity, id: Int): NPC? { return RegionManager.getLocalNpcs(entity).firstOrNull { it.id == id } } +/** + * Gets an NPC with the given ID in the same general area as the given Entity + * @param location The location to search around. + * @param distance The maximum distance to the entity. + * @returns an NPC matching the given ID or null if none is found + */ +fun findLocalNPCs(location: Location, distance: Int): MutableList { + return RegionManager.getLocalNpcs(location, distance) +} + + /** * Gets a list of nearby NPCs that match the given IDs. * @param entity the entity to check around