Jump to content
Sign in to follow this  
Sakon

Complete mining

Recommended Posts

[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]

Share this post


Link to post
Share on other sites
[quote name='verinia']Looks good :)[/QUOTE]

Thanks.

Share this post


Link to post
Share on other sites
Tried adding this into my Mining.java, compiled but threw out errors on server start. Using PI

Share this post


Link to post
Share on other sites
Okay so

Why you do
[CODE]private int[][] objectId;[/CODE]

instead of..

when you can just do

[code] private final List<Integer> objectIds = new ArrayList<>();[/code]

and

[code]private int getPickAnimation(Client player) {[/code]

This just doesn't make any sense you could store it to the enum,

same goes with
[code]private boolean getPickRequirements(Client player) {[/code]


There's lots of stuff that could be done better. Just giving some constructive critism. Edited by FUZENSETH

Share this post


Link to post
Share on other sites
[quote name='Fuzen Seth']Okay so

Why you do
[CODE]private int[][] objectId;[/CODE]

instead of..

when you can just do

[code] private final List<Integer> objectIds = new ArrayList<>();[/code]

and

[code]private int getPickAnimation(Client player) {[/code]

This just doesn't make any sense you could store it to the enum,

same goes with
[code]private boolean getPickRequirements(Client player) {[/code]


There's lots of stuff that could be done better. Just giving some constructive critism.[/QUOTE]

It's time for Fuzen to release a better version me thinks ;)

OT: Could be better, but thanks for sharing.

Share this post


Link to post
Share on other sites
Sign in to follow this  

×