Thread: [ANY][GENERIC] Ranged/Poison/Venom item checking

Page 1 of 2 12 LastLast
Results 1 to 10 of 14
  1. #1 [ANY][GENERIC] Ranged/Poison/Venom item checking 
    Extreme Donator

    nbness2's Avatar
    Join Date
    Aug 2011
    Posts
    692
    Thanks given
    274
    Thanks received
    139
    Rep Power
    430
    Currently developing for a server and a lot of the ranged data and poisonous weapon data was in the player class ( and really didn't contain much such as only dds for poisonous weapons ), decided this was a much more readable and non-hardcoded alternative.
    You can add/remove as you please, but I feel like this covers a lot of bases and enables whoever uses this to clean up their code a ton (if they need or want to).
    Hopefully this is easy to grasp for beginners and experts alike, I named and annotated stuff so that it is (hopefully) easy to understand.
    Only thing I think I'm missing content-wise is dungeoneering arrows and bows, which I made super simple to add so if you want it you can do it.
    If you wanted proper dungeoneering bows and arrows, I'd recommend copying ARROWS/BOWS enum and renaming it DUNG_(ARROWS/BOWS), rename all the enum items (BRONZE_ARROWS, IRON_ARROWS, ..., etc) to (NOVITE_X, BATHUS_X, ..., etc), and adding in the correct ids for the bows/arrows.

    Credits would be cool

    Gist for WeaponConstants and Misc.arrayContains: Github

    I named it WeaponConstants because I cba to think of a better name when it's just generic and you can always rename it.
    Spoiler for WeaponConstants.java:

    Code:
    package com....combat;
    
    import com....Misc;
    
    /**
     * Nbness, 4/2017
     */
    public class WeaponConstants {
    
    
    
        public enum ARROWS{
            BRONZE_ARROWS(0, new int[] {882, 883, 5616, 5622, 598, 942}),
            IRON_ARROWS(0, new int[] {884, 885, 5617, 5623, 2532, 2533}),
            STEEL_ARROWS(1, new int[] {886, 886, 5618, 5624, 2534, 2535}),
            MITHRIL_ARROWS(2, new int[] {888, 889, 5619, 5625, 2536, 2537}),
            ADAMANT_ARROWS(3, new int[] {890, 891, 5620, 5626, 2538, 2539}),
            RUNE_ARROWS(4, new int[] {892, 893, 5621, 5627, 2540, 2541}),
            DRAGON_ARROWS(5, new int[] {11212, 11227, 11228, 11229, 11217, 11222});
    
    
            private final int arrowTier;
            private final int[] arrowIds;
    
            /**
             * ARROWS is an arrow type for a specific tier of arrows.
             *
             * @param arrowTier
             *          The arrows within tier X can only be used with a bow with tier X or higher.
             *
             * @param arrowIds
             *          The array containing the item ids of arrows in that tier
             */
            ARROWS(int arrowTier, int[] arrowIds){
                this.arrowTier = arrowTier;
                this.arrowIds = arrowIds;
            }
    
        }
    
        private final static ARROWS[] ARROW_TYPES = {
                ARROWS.BRONZE_ARROWS, ARROWS.IRON_ARROWS, ARROWS.STEEL_ARROWS, ARROWS.MITHRIL_ARROWS, ARROWS.ADAMANT_ARROWS,
                ARROWS.RUNE_ARROWS, ARROWS.DRAGON_ARROWS
        };
    
        /**
         * isItemArrow checks to see if the item corresponding to the item id given is an arrow.
         *
         * @param itemId
         *          The id of the item being tested to see if it is an arrow.
         *
         * @return boolean
         */
        public static boolean isItemArrow(int itemId){
            for (ARROWS arrowType: ARROW_TYPES){
                if (Misc.arrayContains(arrowType.arrowIds, itemId)) return true;
            }
            return false;
        }
    
        /**
         * getArrowTier accesses the arrow types and if the item corresponding to the item id given is classified as an arrow
         *      by isItemArrow, it will return the tier of the arrow.
         *
         * @param itemId
         *          The id of the item that you are trying to get the arrow tier of.
         *
         * @return int
         */
        public static int getArrowTier(int itemId){
            for (ARROWS arrowType: ARROW_TYPES){
                if (Misc.arrayContains(arrowType.arrowIds, itemId)) return arrowType.arrowTier;
            }
            return -1;
        }
    
    
    
        public enum BOLTS{
            BRONZE_BOLTS(0, new int[] {877, 878, 6061, 6062, 879, 9236}),
            BLURITE_BOLTS(1, new int[] {9139, 9286, 9293, 9300, 9237, 9335}),
            SILVER_BOLTS(1, new int[] {9145, 9292, 9299, 9306}),
            IRON_BOLTS(2, new int[] {9140, 9287, 9294, 9301, 880, 9238}),
            STEEL_BOLTS(3, new int[] {9141, 9288, 9295, 9302, 9239, 9336}),
            BLACK_BOLTS(4, new int[] {13083, 13084, 13085, 13086}),
            MITHRIL_BOLTS(5, new int[] {9142, 9289, 9296, 9303, 9240, 9337, 9241, 9338}),
            ADAMANT_BOLTS(6, new int[] {9143, 9290, 9297, 9304, 9339, 9242, 9243, 9340}),
            RUNE_BOLTS(7, new int[] {9144, 9291, 9298, 9305, 9244, 9341, 9245, 9342});
    
    
            private final int boltTier;
            private final int[] boltIds;
    
            /**
             * BOLTS is an bolt type for a specific tier of bolts.
             *
             * @param boltTier
             *          The bolts within tier X can only be used with a crossbow with tier X or higher.
             *
             * @param boltIds
             *          The array containing the item ids of bolts in that tier
             */
            BOLTS(int boltTier, int[] boltIds){
                this.boltTier = boltTier;
                this.boltIds = boltIds;
            }
        }
    
        private final static BOLTS[] BOLT_TYPES = {
                BOLTS.BRONZE_BOLTS, BOLTS.BLURITE_BOLTS, BOLTS.SILVER_BOLTS, BOLTS.IRON_BOLTS, BOLTS.STEEL_BOLTS,
                BOLTS.BLACK_BOLTS, BOLTS.MITHRIL_BOLTS, BOLTS.ADAMANT_BOLTS, BOLTS.RUNE_BOLTS
        };
    
        /**
         * isItemBolt checks to see if the item corresponding to the item id given is a bolt.
         *
         * @param itemId
         *          The id of the item being tested to see if it is a bolt.
         *
         * @return boolean
         */
        public static boolean isItemBolt(int itemId){
            for (BOLTS boltType: BOLT_TYPES){
                if (Misc.arrayContains(boltType.boltIds, itemId)) return true;
            }
            return false;
        }
    
        /**
         * getArrowTier accesses the bolt types and if the item corresponding to the item id given is classified as a bolt
         *      by isItemBolt, it will return the tier of the bolt.
         *
         * @param itemId
         *          The id of the item that you are trying to get the bolt tier of.
         *
         * @return int
         */
        public static int getBoltTier(int itemId){
            for (BOLTS boltType: BOLT_TYPES){
                if (Misc.arrayContains(boltType.boltIds, itemId)) return boltType.boltTier;
            }
            return -1;
        }
    
    
        public enum BOWS{
            REGULAR_BOWS(0, new int[] {839, 841}),
            OAK_BOWS(1, new int[] {843, 845}),
            WILLOW_BOWS(2, new int[] {847, 849, 10280, 13541}),
            MAPLE_BOWS(3, new int[] {851, 853, 18331}),
            YEW_BOWS(4, new int[] {855, 857, 10282, 13542}),
            MAGIC_BOWS(4, new int[] {859, 861, 10284, 13543, 18332}),
            DARK_BOWS(5, new int[] {11235, 13405, 15701, 15702, 15703, 15704}),
            NO_AMMO_BOWS(6, new int[] {4212, 4214, 4215, 4216, 4217, 4218, 4219, 4220, 4221, 4222, 4223, 20171, 20172});
    
    
            private final int bowTier;
            private final int[] bowIds;
    
            /**
             * BOWS is a bow type for a specific wood type of bows.
             *
             * @param bowTier
             *          The tier of the bows contained in BOWS.X_BOWS.bowIds
             *          Bows with tier X can only be used with arrows of tier X or lower.
             *
             * @param bowIds
             *          The array containing the item ids of bows in X_BOWS
             */
            BOWS(int bowTier, int[] bowIds){
                this.bowTier = bowTier;
                this.bowIds = bowIds;
            }
        }
    
        private static BOWS[] BOW_TYPES = {
                BOWS.REGULAR_BOWS, BOWS.OAK_BOWS, BOWS.WILLOW_BOWS, BOWS.MAPLE_BOWS, BOWS.YEW_BOWS, BOWS.MAGIC_BOWS,
                BOWS.DARK_BOWS, BOWS.NO_AMMO_BOWS
        };
    
        /**
         * isItemBow checks if the item corresponding to the given itemId is a bow.
         *
         * @param itemId
         *          Item ID of the item being tested to check if it is a bow.
         *
         * @return boolean
         */
        public static boolean isItemBow(int itemId){
            for (BOWS bowType: BOW_TYPES){
                if (Misc.arrayContains(bowType.bowIds, itemId)) return true;
            }
            return false;
        }
    
        /**
         * getBowTier accesses the bow types and if the item corresponding to the item id given is classified as a bow
         *      by isItemBow, it will return the tier of the bow.
         * @param itemId
         *          Item ID of the item that you are trying to get the bow tier of.
         *
         * @return int
         */
        public static int getBowTier(int itemId){
            for (BOWS bowType: BOW_TYPES){
                if (Misc.arrayContains(bowType.bowIds, itemId)) return bowType.bowTier;
            }
            return -1;
        }
    
    
    
        public enum CROSSBOWS{
            TIER_0_CBOWS(0, new int[] {767, 837, 9174, 11165, 11167}),
            TIER_1_CBOWS(1, new int[] {9176}),
            TIER_2_CBOWS(2, new int[] {9177, 8880}),
            TIER_3_CBOWS(3, new int[] {9179, 10156}),
            TIER_4_CBOWS(4, new int[] {13081}),
            TIER_5_CBOWS(5, new int[] {9181}),
            TIER_6_CBOWS(6, new int[] {9183, 14684}),
            TIER_7_CBOWS(7, new int[] {9185, 18357});
    
    
            private int cbowTier;
            private int[] cbowIds;
    
            /**
             * CROSSBOWS is a crossbow type for a specific tier of crossbows.
             *
             * @param cbowTier
             *          The tier of the crossbows contained in TIER_X_CBOWS.cbowIds
             *          Crossbows with tier X can only be used with bolts of tier X or lower.
             *
             * @param cbowIds
             *          The array containing the item ids of crossbows in TIER_X_CBOWS
             */
            CROSSBOWS(int cbowTier, int[] cbowIds){
                this.cbowTier = cbowTier;
                this.cbowIds = cbowIds;
            }
        }
    
        private static CROSSBOWS[] CROSSBOW_TYPES =  {
                CROSSBOWS.TIER_0_CBOWS, CROSSBOWS.TIER_1_CBOWS, CROSSBOWS.TIER_2_CBOWS, CROSSBOWS.TIER_3_CBOWS,
                CROSSBOWS.TIER_4_CBOWS, CROSSBOWS.TIER_5_CBOWS, CROSSBOWS.TIER_6_CBOWS, CROSSBOWS.TIER_7_CBOWS
        };
    
        /**
         * isItemCBow checks if the item corresponding to the given itemId is a crossbow.
         *
         * @param itemId
         *          Item ID of the item being tested to check if it is a crossbow.
         *
         * @return boolean
         */
        public static boolean isItemCbow(int itemId){
            for (CROSSBOWS cbowType: CROSSBOW_TYPES){
                if (Misc.arrayContains(cbowType.cbowIds, itemId)) return true;
            }
            return false;
        }
    
        /**
         * getCbowTier accesses the bow types and if the item corresponding to the item id given is classified as a crossbow
         *      by isItemCbow, it will return the tier of the crossbow.
         * @param itemId
         *          Item ID of the item that you are trying to get the crossbow tier of.
         *
         * @return int
         */
        public static int getCbowTier(int itemId){
            for (CROSSBOWS cbowType: CROSSBOW_TYPES){
                if (Misc.arrayContains(cbowType.cbowIds, itemId)) return cbowType.cbowTier;
            }
            return -1;
        }
    
    
    
        public enum OTHER_RANGED{
            DARTS(0, new int[] {806, 807, 808, 809, 810, 811, 812, 813, 814, 815, 816, 817, 818, 3093, 3094, 5628, 5629, 5630,
                    5631, 5632, 5633, 5634, 5635, 5636, 5637, 5638, 5639, 5640, 5641, 11230, 11231, 11232, 11233, 11234}),
    
            THROWING_KNIVES(1, new int[] {863, 864, 856, 866, 867, 868, 869, 870, 871, 862, 863, 864, 865, 866, 5654, 5655,
                    5656, 5657, 5658, 5659, 5660, 5661, 5662, 5663, 5664, 5665, 5666, 5667}),
    
            JAVELINS(2, new int[] {825, 826, 827, 828, 829, 830, 831, 832, 833, 834, 835, 836, 5642, 5643, 5644, 5645, 5646,
                    5647, 5648, 5649, 5650, 5651, 5652, 5653, 13879, 13880, 13881, 13882, 13953, 13954, 13955, 13956}),
    
            THROWNAXES(3, new int[] {800, 801, 802, 803, 804, 805, 13883, 13957}),
    
            TOKTZ(4, new int[] {6522});
    
    
            private int otherRangedWeaponType;
            private int[] itemIds;
    
            /**
             * OTHER_RANGED is a ranged weapon type for a specific type of "other" ranged weapons such as Darts, knives, etc.
             *
             * @param otherType
             *          Type of the "other" ranged weapon.
             *          Mainly an easy way to differentiate for the purposes of attack delays, animations, etc.
             *
             * @param itemIds
             *          The array containing the item ids of other ranged weapon types in OTHER_RANGED.X
             */
            OTHER_RANGED(int otherType, int[] itemIds){
                this.otherRangedWeaponType = otherType;
                this.itemIds = itemIds;
            }
        }
    
        private static OTHER_RANGED[] OTHER_TYPES = {
                OTHER_RANGED.DARTS, OTHER_RANGED.THROWING_KNIVES, OTHER_RANGED.JAVELINS, OTHER_RANGED.THROWNAXES
        };
    
        /**
         * isItemOtherRanged checks if the item corresponding to the given itemId is an "other" ranged weapon.
         *
         * @param itemId
         *          Item ID of the item being tested to check if it is an "other" ranged weapon.
         *
         * @return boolean
         */
        public static boolean isItemOtherRanged(int itemId){
            for (OTHER_RANGED otherType: OTHER_TYPES){
                if (Misc.arrayContains(otherType.itemIds, itemId)) return true;
            }
            return false;
        }
    
        /**
         * getOtherType accesses the bow types and if the item corresponding to the item id given is classified as an
         * "other" ranged weapon by isItemOtherRanged, it will return the tier of the "other" ranged weapon.
         *
         * @param itemId
         *          Item ID of the item that you are trying to get the "other" ranged weapon type of.
         *
         * @return int
         */
        public static int getOtherType(int itemId){
            for (OTHER_RANGED otherType: OTHER_TYPES){
                if (Misc.arrayContains(otherType.itemIds, itemId)) return otherType.otherRangedWeaponType;
            }
            return -1;
        }
    
        private static int[] NO_AMMO = {4212, 4214, 4215, 4216, 4217, 4218, 4219, 4220, 4221, 4222, 4223, 20171, 20172};
    
        /**
         * weaponUsesAmmo checks if the weapon corresponding to the id given uses ammo.
         * OTHER_TYPES weapons use ammo, just not bolts/arrows. They use themselves!
         *
         * @param itemId
         *          Item ID of the item that you are checking if it uses ammo or not.
         *
         * @return boolean
         */
        public static boolean weaponUsesAmmo(int itemId){
            if (Misc.arrayContains(NO_AMMO, itemId)){
                return false;
            }
            return true;
        }
    
        /**
         * isItemRanged checks if the item corresponding to the id given is classified as a ranged weapon.
         *
         * @param itemId
         *          Item ID of the item that you are checking if it is ranged or not.
         *
         * @return boolean
         */
        public static boolean isItemRanged(int itemId){
            if (isItemBow(itemId) || isItemCbow(itemId) || isItemOtherRanged(itemId)){
                return true;
            }
            return false;
        }
    
        /**
         * canUseWeaponWithAmmo checks to see if the weapon corresponding to the id weaponId can be used with the ammo
         *      corresponding to the id ammoId
         *
         * @param weaponId
         *          Item ID of the weapon that you are checking the type of and checking if you can use it with the ammo
         *              corresponding to the id ammoId
         *
         * @param ammoId
         *          Item ID of the ammo that you are checking the type of and checking if you can use it with the weapon
         *              corresponding to the id weaponId
         *
         * @return boolean
         */
        public static boolean canUseWeaponWithAmmo(int weaponId, int ammoId){
            if (isItemRanged(weaponId)){
                if (!weaponUsesAmmo(weaponId)){
                    return true;
                }
                if (isItemBow(weaponId) && isItemArrow(ammoId)){
                    return (getBowTier(weaponId) >= getArrowTier(ammoId));
                }
                if (isItemCbow(weaponId) && isItemBolt(ammoId)){
                    return (getCbowTier(weaponId) >= getBoltTier(ammoId));
                }
            }
            return false;
        }
    
    
        /*Example ids, not real venemous item ids*/
        private static int VENOMOUS_WEP_1 = 1;
        private static int VENOMOUS_WEP_2 = 2;
        private static int VENOMOUS_WEP_3 = 3;
        private static int ETC = 4;
        private static int[] VENOMOUS_IDS = {
                VENOMOUS_WEP_1, VENOMOUS_WEP_2, VENOMOUS_WEP_3, ETC
    
        };
    
        /**
         * isItemVenomous checks if the item has venomous properties.
         *
         * @param itemId
         * Item ID of the item that you are checking if it is venomous.
         *
         * @return boolean
         */
        public static boolean isItemVenomous(int itemId){
            if (Misc.arrayContains(VENOMOUS_IDS, itemId)){
                return true;
            }
            return false;
        }
    
    
    
        private static int[] KP_POISON = {
                // Weapons with (kp), cant be cured by antipoison
                3170, 3171, 3172, 3173, 3174, 3175, 1376, 4584, 11381, 11388, 11395, 11402, 11409, 11416
        };
    
        private static int[] LEVEL_0_POISON = {
                // Add custom stuff here
        };
    
        private static int[] LEVEL_1_POISON = {
                // Add custom stuff here
        };
    
        private static int[] LEVEL_2_POISON = {
                // Ranged (p) ammo
                812, 813, 814, 815, 816, 817, 818, 831, 832, 833, 834, 835, 836, 870, 871, 872, 873, 874, 875, 876, 878, 883,
                885, 887, 889, 891, 893, 9287, 9288, 9289, 9290, 9291, 9292, 11227, 11231, 13880, 15958, 15959, 15960, 15961,
                15962, 15963, 15964, 15965, 15966, 15967, 15968, 16482, 16487, 16492, 16497, 16502, 16507, 16512, 16517, 16522,
                16527, 16532, 21680, 21687, 21694, 21701, 21712, 21719, 21726, 21733
        };
    
        private static int[] LEVEL_3_POISON = {
                // Ranged (p+) ammo
                5616, 5617, 5618, 5619, 5620, 5621, 5628, 5629, 5630, 5631, 5632, 5633, 5634, 5642, 5643, 5644, 5645, 5646,
                5647, 5654, 5655, 5656, 5657, 5658, 5660, 5668, 6061, 9293, 9294, 9295, 9296, 9297, 9298, 9299, 11228, 11233,
                13881, 13955, 15970, 15971, 15972, 15973, 15974, 15975, 15976, 15977, 15978, 15979, 16537, 16542, 16547, 16552,
                16557, 16562, 16567, 16572, 16577, 16582, 16587, 21681, 21688, 21695, 21702, 21713, 21720, 21727, 21734
        };
    
        private static int[] LEVEL_4_POISON = {
                // Ranged (p++)/(s) ammo
                5622, 5623, 5624, 5625, 5626, 5627, 5635, 5636, 5637, 5638, 5639, 5640, 5641, 5648, 5649, 5650, 5651, 5652,
                5653, 5661, 5662, 5663, 5664, 5665, 5666, 5667, 6062, 9300, 9301, 9302, 9393, 9304, 9305, 9306, 11229, 11234, 13882,
                13956, 15980, 15981, 15982, 15983, 15984, 15985, 15986, 15988, 15988, 15989, 15990, 16592, 16597, 16602, 16607,
                16612, 16617, 16622, 16627, 16632, 16637, 16642, 21682, 21689, 21696, 21703, 21714, 21721, 21728, 21735,
    
                // Melee (p) weapons
                1219, 1221, 1223, 1225, 1227, 1229, 1231, 1233, 1235, 1251, 1253, 1255, 1257, 1259, 1261, 1263, 4582, 6593, 8874,
                11379, 11386, 11393, 11400, 11407, 11414, 13466, 13766, 13771, 13772, 15849, 15853, 15857, 15861, 15865, 15869,
                15873, 15877, 15881, 15885, 15889, 16219, 16223, 16227, 16231, 16235, 16239, 16243, 16247, 16251, 16255, 16259,
                16759, 16767, 1676775, 16783, 16791, 16799, 16807, 16815, 16816, 16823, 16831, 16839, 17065, 17073, 17081, 17089,
                17097, 17105, 17113, 17121, 17129, 17137, 17145
    
    
        };
    
        private static int[] LEVEL_5_POISON = {
                // Melee (p+) weapons
                5668, 5670, 5672, 5674, 5676, 5678, 5680, 5682, 5684, 5704, 5706, 5708, 5710, 5712, 5714, 5716, 5734, 6061,
                6595, 8876, 11228, 11233, 11382, 11382, 11387, 11392, 11397, 11402, 11407, 11412, 11417, 13467, 13767, 13773,
                13774, 15850, 15854, 15858, 15862, 15866, 15870, 15874, 15878, 15882, 15886, 15890, 16220, 16224, 16228, 16232,
                16236, 16240, 16244, 16248, 16252, 16256, 16260, 16761, 16769, 16777, 16785, 16793, 16801, 16809, 16817, 16825,
                16833, 16841, 17067, 17075, 17083, 17091, 17099, 17107, 17115, 17123, 17131, 17139, 17147
        };
    
        private static int[] LEVEL_6_POISON = {
                // Melee (p++)/(s) weapons
                5686, 5688, 5690, 5692, 5694, 5696, 5698, 5700, 5718, 5720, 5722, 5724, 5726, 5728, 5730, 5732, 5734, 5736,
                8878, 10584, 11384, 11391, 11398, 11405, 11412, 11419, 13468, 13768, 13775, 13776, 15851, 15855, 15859, 15863,
                15867, 15871, 15875, 15879, 15883, 15887, 15891, 16221, 16225, 16229, 16233, 16237, 16241, 16245, 16249, 16253,
                16257, 16261, 16763, 16771, 16779, 16787, 16795, 16803, 16811, 16819, 16827, 16835, 16843, 17069, 17076, 17083,
                17090, 17097, 17104, 17111, 17118, 17125, 17132, 17139, 17146,
    
                // (kp) weapons
                3170, 3171, 3172, 3173, 3174, 1376, 4584, 11381, 11388, 11395, 11402, 11409, 11416
        };
    
        /**
         * getItemPoisonLevel gets the item corresponding to itemId's poison level.
         * Poison damage applied is equal to the item's poison level.
         *
         * @param itemId
         *          Item ID of the item that you are getting the poison level for.
         *
         * @return int
         */
        public static int getItemPoisonLevel(int itemId){
            int poisonLevel = 0;
            for (int[] poisonArray: new int[][] {LEVEL_0_POISON, LEVEL_1_POISON, LEVEL_2_POISON, LEVEL_3_POISON, LEVEL_4_POISON, LEVEL_5_POISON, LEVEL_6_POISON}){
                if (Misc.arrayContains(poisonArray, itemId)){
                    return poisonLevel;
                }
                poisonLevel++;
            }
            return 0;
        }
    
        /**
         * isItemPoisonous checks if the item has poisonous properties.
         *
         * @param itemId
         * Item ID of the item that you are checking if it is poisonous.
         *
         * @return boolean
         */
        public static boolean isItemPoisonous(int itemId){
            for (int[] poisonArray: new int[][] {LEVEL_0_POISON, LEVEL_1_POISON, LEVEL_2_POISON, LEVEL_3_POISON, LEVEL_4_POISON, LEVEL_5_POISON, LEVEL_6_POISON}){
                if (Misc.arrayContains(poisonArray, itemId)){
                    return true;
                }
            }
            return false;
        }
    
        /**
         * isItemPoisonous checks if the item has karambwan poison applied to it.
         *
         * @param itemId
         * Item ID of the item that you are checking if it has karambwan poison applied to it.
         *
         * @return boolean
         */
        public static boolean isItemKp(int itemId){
          return Misc.arrayContains(KP_POISON, itemId);
        }
    
    }



    I recommend this one to go in util.Misc ( generally where misc stuff is ). Just a simple check if an item is in there, can be changed to string or whatever you want very easily by changing "int[]" and "int" to "<dataTypeHere>[]" and "<dataTypeHere>".
    Spoiler for Misc.arrayContains():

    Code:
    /**
     * arrayContains checks if the int[] array contains the item.
     *
     * @param array
     * 			The int[] array you are checking if it contains the item.
     *
     * @param item
     * 			The item you are checking if it is contained in the int[] array.
     *
     * @return boolean
     */
    
    public static boolean arrayContains(int[] array, int item){
    	for (int i: array){
    		if (item == i){
    			return true;
    		}
    	}
    	return false;
    }



    Generic Examples

    Spoiler for Examples:

    Example 1, Attack.java: Using arrows with crossbow, vice versa
    Code:
    import com....Player;
    import com....WeaponConsatnts;
    
    int weaponId = player.getEquipmentSlot(WEAPON_SLOT);
    int ammoId = player.getEquipmentSlot(AMMO_SLOT);
    boolean usingOtherRangeWeapon = WeaponConstants.isItemOtherRanged(weaponId);
    if (player.getUsingRange() && !WeaponConstants.canUseWeaponWithAmmo(weaponId, ammoId) && !usingOtherRangeWeapon) {
    	player.sendMessage("You can't use " + ItemDef.itemName(ammoId) + "s with " + ItemDef.itemName(weaponId) + ".");
    	return;
    }
    Example 2, Attack.java: Attacking entity
    Code:
    import com....World;
    import com....Player;
    import com....Npc;
    import com....WeaponConstants;
    
    int ammoId = player.getEquipmentSlot(AMMO_SLOT);
    Entity target = (Npc) or (Player)
    if (WeaponConstants.weaponUsesAmmo(player.lastWeaponUsed)) {
    	World.dropItem(target, ammoId);
    }
    Example 3, ApplyDamage.java: Attacking with a poisonous weapon
    Code:
    import com....Combat;
    import com....Npc;
    import com....Player;
    import com....Poison;
    import com....WeaponConstants;
    
    Entity attacker; // Npc or Player
    Entity victim; // Npc or Player
    int poisonLevel;
    boolean isKaramPoison = false;
    int weaponId = attacker.getEquipmentSlot(WEAPON_SLOT);
    int ammoId = attacker.getEquipmentSlot(AMMO_SLOT);
    int damage = Combat.calculateDamage(attacker, victim);
    
    
    if (damage > 0 && !victim.getPoisonedStatus(weaponId)){
         if (WeaponConstants.isItemRanged(weaponId) && !WeaponConstants.isItemOtherRanged(weaponId)){
              poisonLevel = WeaponConstants.getItemPoisonLevel(ammoId);
         } else {
              poisonLevel = WeaponConstants.getItemPoisonLevel(weaponId);
              isKaramPoison = WeaponConsatnts.isItemKp(weaponId);
         }
         Poison.appendPoison(victim, poisonLevel, isKaramPoison);
    }
    Reply With Quote  
     

  2. #2  
    What's a sundial in the shade?

    Lumiere's Avatar
    Join Date
    May 2013
    Age
    27
    Posts
    543
    Thanks given
    224
    Thanks received
    100
    Rep Power
    113
    All those arrays, and some of the naming
    LEVEL_6_POISON - LEVEL_1_POISON, might as-well start a new class for Poison types.

    Also; Enums shouldn't be named like constants. EX: "public enum CROSSBOWS {"
    Should just be "public enum Crossbows {"

    Could have easily consolidated a lot of this, you could have had "Crossbows" & "Bows" in the same Enum, rather than separately.
    Could have made for example; "RangedWeapons" or something as the enum, and from there specified types, such as "Crossbow" "Shortbow" "Longbow" etc.

    Arrows and Bolts also could be consolidated into a single enum such as "Ammo" or "Consumables" which could also incorporate magic runes, etc. Dunno.
    I'm sure someone else will have better/more detailed notes than I

    Good job on the effort though, and thanks for the contribution.

    Spoiler for Revy is perfect:
    Reply With Quote  
     

  3. #3  
    Extreme Donator

    nbness2's Avatar
    Join Date
    Aug 2011
    Posts
    692
    Thanks given
    274
    Thanks received
    139
    Rep Power
    430
    Quote Originally Posted by Lumiere View Post
    All those arrays, and some of the naming
    LEVEL_6_POISON - LEVEL_1_POISON, might as-well start a new class for Poison types.

    Also; Enums shouldn't be named like constants. EX: "public enum CROSSBOWS {"
    Should just be "public enum Crossbows {"

    Could have easily consolidated a lot of this, you could have had "Crossbows" & "Bows" in the same Enum, rather than separately.
    Could have made for example; "RangedWeapons" or something as the enum, and from there specified types, such as "Crossbow" "Shortbow" "Longbow" etc.

    Arrows and Bolts also could be consolidated into a single enum such as "Ammo" or "Consumables" which could also incorporate magic runes, etc. Dunno.
    I'm sure someone else will have better/more detailed notes than I

    Good job on the effort though, and thanks for the contribution.
    I'm not too well versed in java. No courses or anything, I've practically learned everything I know by rsps, so I don't know too well the "ethical" stuff like too many arrays.
    Good point on the enum names, just a personal preference. You never really need to directly access them outside of getters however, so it shouldn't be a burden on anyone planning to use as-is. If it is, they can just use an ide and refactor all of them in about 3 seconds each.
    I originally was going to do poisons in the Poison class, probably going to do it eventually but that's what I have right now
    I could have consolidated them in to 1 enum at the cost of being more complex, adding subclasses or extra constructor parameters. However I'd rather not sacrifice readability at this point unless I really must. I could do something like this
    Spoiler for dis:

    Code:
    public enum Ammo{
         ARROWS(new int[][] {
                             { 882, 883, 5616, 5622, 598, 942 },
                             { 884, 885, 5617, 5623, 2532, 2533}, ...});
         BOLTS(new int[][] {...}),
         ...;
         Ammo(int[][] ammoIds){
              this.ammoIds = ammoIds;
         }
    }

    where the ammo tier is the index of the id list, but I decided against that. I like stuff to be easily understood by others
    I might update it later, but I like how it is now and how well it is currently working with my code.
    Reply With Quote  
     

  4. #4  
    Super Donator


    Join Date
    Feb 2011
    Age
    27
    Posts
    1,126
    Thanks given
    180
    Thanks received
    178
    Rep Power
    243
    Good contribution overall thoe.. But why not do like this instead of having a nesting array contains

    Code:
    public boolean arrayContains(int[] array, int key) {
         return ArrayUtils.contains(array, key);
    }
    Reply With Quote  
     

  5. #5  
    Extreme Donator

    nbness2's Avatar
    Join Date
    Aug 2011
    Posts
    692
    Thanks given
    274
    Thanks received
    139
    Rep Power
    430
    Quote Originally Posted by Gnakos View Post
    Good contribution overall thoe.. But why not do like this instead of having a nesting array contains

    Code:
    public boolean arrayContains(int[] array, int key) {
         return ArrayUtils.contains(array, key);
    }
    In the end it works all the same. May do this later, but for now it works.
    Reply With Quote  
     

  6. #6  
    Super Donator


    Join Date
    Feb 2011
    Age
    27
    Posts
    1,126
    Thanks given
    180
    Thanks received
    178
    Rep Power
    243
    Quote Originally Posted by nbness View Post
    In the end it works all the same. May do this later, but for now it works.
    Yepp Just showing an example of using exisiting functions to simplify and making it more clean

    BTW: You double posted this thread.
    Reply With Quote  
     

  7. #7  
    Banned

    Join Date
    Mar 2011
    Posts
    657
    Thanks given
    105
    Thanks received
    75
    Rep Power
    0
    Is there any reason why you have to have a Bolts and Arrows? Rather than something like.. Projectile which contains both?
    Reply With Quote  
     

  8. Thankful user:


  9. #8  
    Extreme Donator

    nbness2's Avatar
    Join Date
    Aug 2011
    Posts
    692
    Thanks given
    274
    Thanks received
    139
    Rep Power
    430
    Quote Originally Posted by Eggspurt View Post
    Is there any reason why you have to have a Bolts and Arrows? Rather than something like.. Projectile which contains both?
    I could do that, but I don't see a need to because of my extra functions that makes that sort of trivial. I guess it would just be for personal preference, but I personally like them separate. I also think the projectile descriptor applies to more than arrows and bolts, like magic spells that travel and such. I guess if you wanted to use and change it to be that way, that's your choice but 99.9% of cases you only care if you can use the bow/cbow with a certain ammo and the functionality doesnt really change wether you clump the 2 together or not.
    Reply With Quote  
     

  10. #9  
    What's a sundial in the shade?

    Lumiere's Avatar
    Join Date
    May 2013
    Age
    27
    Posts
    543
    Thanks given
    224
    Thanks received
    100
    Rep Power
    113
    Quote Originally Posted by nbness View Post
    I could do that, but I don't see a need to because of my extra functions that makes that sort of trivial. I guess it would just be for personal preference, but I personally like them separate. I also think the projectile descriptor applies to more than arrows and bolts, like magic spells that travel and such. I guess if you wanted to use and change it to be that way, that's your choice but 99.9% of cases you only care if you can use the bow/cbow with a certain ammo and the functionality doesnt really change wether you clump the 2 together or not.
    Not sure if this will work, as I just wrote it up real quick and didn't test or anything.
    Anyways, you insist on claiming this is preference, but it is not.
    Not only does the way you have it make it an atrocity to read, but it's just redundant.
    As for the naming of the Enums, that's not preference either, it's all conventions, and that's something any programmer should follow.

    Took me 5 - 10 minutes to re-write this simple little part, don't be lazy, 'preference' is not the issue here.
    Code:
    	public enum Ammunition {
    		BRONZE_ARROWS(0, new int [] {882, 883, 5616, 5622, 598, 942}),
    		IRON_ARROWS(0, new int [] {884, 885, 5617, 5623, 2532, 2533}),
    		STEEL_ARROWS(1, new int [] {886, 886, 5618, 5624, 2534, 2535}),
    		MITHRIL_ARROWS(2, new int [] {888, 889, 5619, 5625, 2536, 2537}),
    		ADAMANT_ARROWS(3, new int [] {890, 891, 5620, 5626, 2538, 2539}),
    		RUNE_ARROWS(4, new int [] {892, 893, 5621, 5627, 2540, 2541}),
    		DRAGON_ARROWS(5, new int [] {11212, 11227, 11228, 11229, 11217, 11222}),
    		BRONZE_BOLTS(0, new int [] {877, 878, 6061, 6062, 879, 9236}),
    		BLURITE_BOLTS(1, new int [] {9139, 9286, 9293, 9300, 9237, 9335}),
    		SILVER_BOLTS(1, new int [] {9145, 9292, 9299, 9306}),
    		IRON_BOLTS(2, new int [] {9140, 9287, 9294, 9301, 880, 9238}),
    		STEEL_BOLTS(3, new int [] {9141, 9288, 9295, 9302, 9239, 9336}),
    		BLACK_BOLTS(4, new int [] {13083, 13084, 13085, 13086}),
    		MITHRIL_BOLTS(5, new int [] {9142, 9289, 9296, 9303, 9240, 9337, 9241, 9338}),
    		ADAMANT_BOLTS(6, new int [] {9143, 9290, 9297, 9304, 9339, 9242, 9243, 9340}),
    		RUNE_BOLTS(7, new int [] {9144, 9291, 9298, 9305, 9244, 9341, 9245, 9342});
    
    		private final int tier;
    		private final int [] id;
    
    		private Ammunition(final int tier, final int [] id){
    			this.tier = tier;
    			this.id = id;
    		}
    		public int getTier() {
    			return tier;
    		}
    		public int [] getId() {
    			return id;
    		}
    		public static Optional<Ammunition> getBolts() {
    			return Arrays.stream(values()).filter(s -> s.name().contains("BOLTS")).findFirst();
    		}
    		public static Optional<Ammunition> getArrows() {
    			return Arrays.stream(values()).filter(s -> s.name().contains("ARROWS")).findFirst();
    		}
        }
    The optionals probably aren't correct either, not sure.
    Cba to do more though lol

    EDIT: This is going to be the same concept for Bows, Crossbows, and Throwables.
    As for bows that don't take ammunition, just make a boolean or something, all in one Enum.

    Spoiler for Revy is perfect:
    Reply With Quote  
     

  11. #10  
    Extreme Donator

    nbness2's Avatar
    Join Date
    Aug 2011
    Posts
    692
    Thanks given
    274
    Thanks received
    139
    Rep Power
    430
    Quote Originally Posted by Lumiere View Post
    Not sure if this will work, as I just wrote it up real quick and didn't test or anything.
    Anyways, you insist on claiming this is preference, but it is not.
    Not only does the way you have it make it an atrocity to read, but it's just redundant.
    As for the naming of the Enums, that's not preference either, it's all conventions, and that's something any programmer should follow.

    The optionals probably aren't correct either, not sure.
    Cba to do more though lol

    EDIT: This is going to be the same concept for Bows, Crossbows, and Throwables.
    As for bows that don't take ammunition, just make a boolean or something, all in one Enum.
    90% of the sources I see don't follow "conventions", and I haven't taken any java classes so I never formally learned all of this "convention" stuff. If it works it works.
    Reply With Quote  
     

Page 1 of 2 12 LastLast

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. Item check
    By Metorrite in forum Help
    Replies: 4
    Last Post: 05-27-2013, 07:59 AM
  2. Replies: 16
    Last Post: 02-18-2013, 10:33 AM
  3. Replies: 16
    Last Post: 12-27-2012, 09:18 PM
  4. [PI] inventory item check function
    By evilguyme in forum Help
    Replies: 4
    Last Post: 06-03-2012, 01:40 AM
  5. Item check
    By Sillhouette in forum Help
    Replies: 0
    Last Post: 10-15-2011, 10:29 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
  •