Jump to content

Sakon

Member
  • Content count

    8
  • Joined

  • Last visited

  1. Sakon

    Complete mining

    [quote name='verinia']Looks good :)[/QUOTE] Thanks.
  2. [code] package armadyl.model.content.skills.mining; import armadyl.Config; public class MiningConfig { public enum Ores { Copper( new int[][] { { 31080, 31081 }, { 31082, 2090 }, { 2091, 9708 } }, 1, 436, 25 * Config.MINING_EXPERIENCE, "copper ore", 25, 29000), Tin( new int[][] { { 9714, 31078 }, { 2094, 2095 } }, 1, 438, 40 * Config.MINING_EXPERIENCE, "tin ore", 35, 29000), Iron( new int[][] { { 31071, 31072 }, { 31073, 2093 }, { 2092, 9717 } }, 10, 440, 55 * Config.MINING_EXPERIENCE, "iron ore", 45, 31000), Coal( new int[][] { { 31068, 31069 }, { 31070, 2096 }, { 2097, 14850 } }, 25, 453, 70 * Config.MINING_EXPERIENCE, "coal", 55, 33000), Gold( new int[][] { { 2099, 31066 }, { 9720, 2098 } }, 45, 444, 85 * Config.MINING_EXPERIENCE, "gold ore", 65, 35000), Mithril( new int[][] { { 31086, 31088 }, { 2103, 2102 } }, 35, 447, 40 * Config.MINING_EXPERIENCE, "mithril ore", 75, 37000), Adamantite( new int[][] { { 31083, 31085 }, { 2105, 2104 } }, 40, 449, 50 * Config.MINING_EXPERIENCE, "adamantite ore", 85, 39000), Runite( new int[][] { { 14859, 4860 }, { 2106, 2107 } }, 70, 451, 100 * Config.MINING_EXPERIENCE, "runite ore", 95, 41000); private int[][] objectId; private int requiredLevel, oreId, expGained, respawnTime, survivingChance; String oreName; Ores(int[][] objectId, int requiredLevel, int oreId, int expGained, String oreName, int respawnTime, int survivingChance) { this.objectId = objectId; this.requiredLevel = requiredLevel; this.oreId = oreId; this.expGained = expGained; this.oreName = oreName; this.respawnTime = respawnTime; this.survivingChance = survivingChance; } public int[][] getObjectId() { return objectId; } public int getRequiredLevel() { return requiredLevel; } public int getOreId() { return oreId; } public int getExpGained() { return expGained; } public String getOreName() { return oreName; } public int getRespawnTime() { return respawnTime; } public int getSurvivingChance() { return survivingChance; } public static Ores getOreConfig(int id) { for (Ores oreConfig : values()) { for (int[] oreId : oreConfig.getObjectId()) { if (oreId[0] == id) return oreConfig; } } return null; } } } [/code] [code] package armadyl.model.content.skills.mining; import armadyl.Server; import armadyl.event.Event; import armadyl.event.EventContainer; import armadyl.model.objects.ObjectList; import armadyl.world.Location; /** * The respawning time for the ores. * * @author Sakon */ public class OreRespawn implements Event { private Location location; private int oreId; private MiningConfig.Ores ores; public OreRespawn(MiningConfig.Ores ores, Location location, int oreId) { this.setOres(ores); this.location = location; this.oreId = oreId; } public void setOres(MiningConfig.Ores ores) { this.ores = ores; } [MENTION=15855]Over[/MENTION]ride public void execute(EventContainer container) { Server.objectHandler.createAnObject(oreId, location.getX(), location.getY(), location.getPlane()); ObjectList.remFromList(location); container.stop(); } public MiningConfig.Ores getOres() { return ores; } } [/code] [code] package armadyl.model.content.skills.mining; import java.util.Random; import armadyl.Server; import armadyl.event.EventManager; import armadyl.model.content.skills.Action; import armadyl.model.content.skills.Skills; import armadyl.model.objects.ObjectList; import armadyl.model.players.Client; import armadyl.util.Misc; import armadyl.world.Location; public class Mining extends Action { private Location location; private int oreId; private MiningConfig.Ores ores; private final int[] RANDOM_GEMS = { 1623, 1621, 1619, 1617, 1631 }; public Mining(MiningConfig.Ores ores, Location location, int oreId) { this.setOres(ores); this.location = location; this.setOreId(oreId); } public void setOres(MiningConfig.Ores ores) { this.ores = ores; } [MENTION=15855]Over[/MENTION]ride public boolean commence(Client player) { if (ObjectList.containsObject(location)) { return false; } if (player.isBusy()) return false; if (player.playerLevel[Skills.MINING] < ores.getRequiredLevel()) { player.sendMessage("You need a Mining Level of " + ores.getRequiredLevel() + " to mine this ore."); return false; } if (player.getItems().freeSlots() < 1) { player.sendMessage("Not enough space in your inventory."); return false; } if (!getPickRequirements(player)) { player.sendMessage("You need a Pickaxe to mine this ore."); player.sendMessage("You do not have a Pickaxe which you have the Mining level to use."); return false; } player.clearPlayersInterface(); player.setBusy(true); player.setSkilling(true); player.turnPlayerTo(location.getX(), location.getY()); player.startAnimation(getPickAnimation(player), 1); player.sendMessage("You swing your pick at the rock..."); player.startAnimation(getPickAnimation(player), 1); setActionDelay(player, 1); return true; } public int getPickBoost(Client player) { if (player.getItems().playerHasItem(1265) || player.playerEquipment[player.playerWeapon] == 1265) { return 1; } if (player.getItems().playerHasItem(1267) || player.playerEquipment[player.playerWeapon] == 1267) { return 2; } if (player.getItems().playerHasItem(1269) || player.playerEquipment[player.playerWeapon] == 1269) { return 3; } if (player.getItems().playerHasItem(1273) || player.playerEquipment[player.playerWeapon] == 1273) { return 4; } if (player.getItems().playerHasItem(1271) || player.playerEquipment[player.playerWeapon] == 1271) { return 5; } if (player.getItems().playerHasItem(1275) || player.playerEquipment[player.playerWeapon] == 1275) { return 6; } if (player.getItems().playerHasItem(15259) || player.playerEquipment[player.playerWeapon] == 15259) { return 10; } return 1; } private int getPickAnimation(Client player) { int[][] animation = { { 1265, 1, 625 }, { 1267, 1, 626 }, { 1269, 6, 627 }, { 1273, 21, 628 }, { 1271, 31, 629 }, { 1275, 41, 624 }, { 15259, 61, 12188 } }; for (int[] animIndex : animation) { if (player.playerLevel[Skills.MINING] >= animIndex[1]) { if (player.getItems().playerHasItem(animIndex[0]) || player.playerEquipment[player.playerWeapon] == animIndex[0]) { return animIndex[2]; } } } return -1; } private boolean getPickRequirements(Client player) { int[][] miningIndex = { { 1265, 1 }, { 1267, 1 }, { 1269, 6 }, { 1273, 21 }, { 1271, 31 }, { 1275, 41 }, { 15259, 61 } }; for (int[] mining : miningIndex) { if (player.getItems().playerHasItem(mining[0]) || player.playerEquipment[player.playerWeapon] == mining[0]) { if (player.playerLevel[Skills.MINING] >= mining[1]) { return true; } else { return false; } } } return false; } public boolean removeOre(int survivingChance) { int random = Misc.random(100); if (survivingChance >= random) { return true; } else { return false; } } [MENTION=15855]Over[/MENTION]ride public boolean process(Client player) { if (!player.isSkilling()) player.getActionManager().stopEarly(); if (player.getItems().freeSlots() < 1) { player.sendMessage("Not enough space in your inventory."); player.getActionManager().stopEarly(); } if (ObjectList.containsObject(location)) { player.getActionManager().stopEarly(); } player.startAnimation(getPickAnimation(player), 1); return true; } [MENTION=15855]Over[/MENTION]ride public int processWithDelay(Client player) { Random random = new Random(); double odds = random.nextDouble() * 100; double baseChance = Math.pow(10d - ores.getRequiredLevel() / 10d, 2d) / 2d; double chance = (baseChance + ((player.playerLevel[Skills.MINING] - ores.getRequiredLevel()) / 2d) + (getPickBoost(player) / 10d)) + random.nextInt((int) baseChance / 3); if (chance < odds) return 3; double totalXp = ores.getExpGained(); player.getItems().addItem(ores.getOreId(), 1); player.sendMessage("You get some " + ores.getOreName() + "."); if (Misc.random(25) == 10) { player.getItems().addItem( RANDOM_GEMS[(int) (RANDOM_GEMS.length * Math.random())], 1); } player.getPA().addSkillXP((int) totalXp, Skills.MINING); if (removeOre(ores.getSurvivingChance())) { return -1; } else { return 1; } } [MENTION=15855]Over[/MENTION]ride public void finish(Client player) { for (int q = 0; q < ores.getObjectId().length; q++) { if (ores.getObjectId()[q][0] == oreId) { Server.objectHandler.createAnObject(ores.getObjectId()[q][1], location.getX(), location.getY(), location.getPlane()); } } ObjectList.addToList(location, oreId); EventManager.getSingleton().addEvent( new OreRespawn(ores, location, oreId), ores.getRespawnTime()); player.setBusy(false); player.startAnimation(-1); } public int getOreId() { return oreId; } public void setOreId(int oreId) { this.oreId = oreId; } } [/code] to set the action; [code] if (MiningConfig.Ores.getOreConfig(id) != null) { player.getActionManager() .setAction( new Mining(MiningConfig.Ores.getOreConfig(id), location, id)); return; } [/code]
  3. [code] package armadyl.model.content; import java.util.HashMap; /** * Enumeration containing the experience rates for each mode which the player * will choose from. * * @author Sakon */ public enum Rates { ROOKIE(500, 9178), MEDIUM(200, 9179), HARD(50, 9180), EXTREME(10, 9181); /** * Experience rate the player will be choosing. */ private int rate; /** * The buttons in the dialogue. */ private int button; /** * Constructs the enumeration. * * [MENTION=75098]Para[/MENTION]m xp * the experience rates the player can choose from. */ private Rates(int rate, int button) { this.rate = rate; this.button = button; } /** * Gets the experience rates the players can choose from. * * [MENTION=184045]return[/MENTION] the experience. */ public int getRate() { return rate; } /** * Gets the button on the initialization dialogue * * [MENTION=184045]return[/MENTION] The button id */ public int getButton() { return button; } /** * Sets the experience rate. * * [MENTION=75098]Para[/MENTION]m xp * the experience. * [MENTION=184045]return[/MENTION] */ public int setRate(int rate) { return this.rate = rate; } /** * Constructs the hashmap. */ public static HashMap<Integer, Rates> type = new HashMap<Integer, Rates>(); /** * Populates the hashmap. */ static { for (final Rates b : values()) { Rates.type.put(b.getButton(), b); } } /** * Gets the rates value for the button pressed * * [MENTION=75098]Para[/MENTION]m button * The button id */ public static Rates forId(int button) { return type.get(button); } } [/code] Add the getter and the setter in the player/client class. [code] /** * Gets the experience rate. * * [MENTION=184045]return[/MENTION] the rate. */ public Rates getRates() { return rate; } [/code] [code] /** * Sets the experience rate for the player * * [MENTION=75098]Para[/MENTION]m rate * The experience rate */ public void setRate(Rates rate) { this.rate = rate; } [/code] Also add these in that class. [code] /** * Toggles the player's state of rate configuration */ public void toggleRateConfig() { this.configuringRates = !configuringRates; } /** * Checks if the player is configuring their exp rates * * [MENTION=184045]return[/MENTION] * True if so, else false */ public boolean isConfiguringRates() { return configuringRates; } [/code] Playersave class [code] } else if (token.equals("exp-rate")) { p.setRate(Rates.valueOf(token2)); [/code] [code] characterfile.write("exp-rate = ", 0, 11); characterfile.write(p.getRates().toString(), 0, p .getRates().toString().length()); characterfile.newLine(); [/code] addSkillXp method [code] amount = (int) ((double) amount * 1.0D) * c.getRates().getRate(); [/code] In your client class, wherever it calls out the addStarter method, put your dialogue there and call out the toggleRateConfig() method. Dialogue, though you'll have to convert it to the way you handle it. [code] package armadyl.model.content.dialogue.impl; import armadyl.model.content.dialogue.Dialogue; import armadyl.model.npcs.NPC; import armadyl.model.players.Client; /** * The experience dialogue. * * @author Sakon * */ public class RateDialogue extends Dialogue { /** * Handles the dialogue for choosing the experience rates. */ [MENTION=15855]Over[/MENTION]ride public void handleDialogue(Client player, NPC npc) throws Exception { player.setDialogueHook(this); player.setDialogueNpc(npc); switch (getCurrentStage()) { case 0: sendOption4(player, "Rookie", "Medium", "Hard", "Extreme"); setOptionSets(2, 3, 4, 5); setOptionDialogue(true); break; } } } [/code] Clicking buttons; [code] /* Check if the player is configuring their exp rates */ if (c.isConfiguringRates()) { Rates rates = Rates.forId(actionButtonId); if (rates != null) { c.setRate(rates); c.getPA().closeAllWindows(); c.toggleRateConfig(); c.sendMessage("You set your experience rate to: " + Misc.formatPlayerName(rates.toString() .toLowerCase())); } } [/code]
  4. Nice updates mate.
×