Sie sind auf Seite 1von 6

package server.game.content.

lootingbag;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.ArrayList;
import server.game.items.Item;
import server.game.items.ItemAssistant;
import server.game.items.ItemDefinition;
import server.game.items.ground.GroundItem;
import server.game.items.ground.GroundItemHandler;
import server.game.player.Player;
import server.game.player.account_type.Account;
/**
** @author Unknown
** @Heavily Modified by Tyler - Imtyler7 (rune-server)
**/
public class Lootingbag {
public final int LOOTBAG = 11941;
public void clearLootbagInterface(Player c) {
for (int z = 0; z < 28; z++) {
if(c.checkBag) {
c.getPA().sendFrame34a(26706, -1, z, -1);
} else if (c.depositBag) {
c.getPA().sendFrame34a(26716, -1, z, -1);
}
}
}
/*
* Used to update the cost of the loot bag throughout class
*/
public void updateTotalCost(Player c) {
int total = 0;
for (int z = 0; z < c.lootBag.length; z++) {
if (c.lootBag[z] != -1 && c.lootBag[z] != 0)
total += (ItemDefinition.forId(c.lootBag[z]).getShopValu
e() * c.amountLoot[z]);
}
DecimalFormatSymbols separator = new DecimalFormatSymbols();
separator.setGroupingSeparator(',');
DecimalFormat formatter = new DecimalFormat("##,###,###", separa
tor);
c.getPA().sendFrame126("Value: "+formatter.format(total), 26707)
;
}
/*
* Method used for full lootbag updating
*/
public void updateLootbagInterface(Player c) {
if(c.checkBag) {
for (int z = 0; z < c.lootBag.length; z++) {
c.getPA().sendFrame34a(26706, c.lootBag[z], z, c
.amountLoot[z]);
}
updateTotalCost(c);
} else if (c.depositBag) {
for (int z = 0; z < c.playerItems.length; z++) {
c.getPA().sendFrame34a(26716, c.playerItems[z] -
1, z, c.playerItemsN[z]);
}
}
}
/*
* Method used for handling death with loot bag on you
*/
public void handleLootbagDeath(Player c) {
if (c.getItems().playerHasItem(LOOTBAG)) {
for (int i = 0; i < c.lootBag.length; i++) {
if (c.lootBag[i] == -1 || c.lootBag[i] == 0) {
break;
} else
continue;
}
for (int i = 0; i < c.lootBag.length; i++) {
GroundItemHandler.createGroundItem(new GroundIte
m(new Item(c.lootBag[i], c.amountLoot[i]), c.absX, c.absY, c.heightLevel, c));
c.sendGameMessage("You have lost " + c.amountLoo
t[i] + " " + ItemAssistant.getItemName(c.lootBag[i]) + " as you have died.");
c.lootBag[i] = -1;
c.amountLoot[i] = -1;
clearLootbagInterface(c);
updateLootbagInterface(c);
}
c.sendGameMessage("@red@You can teleport back to where y
ou died to collect them!");
}
}
/*
* Check used before allowing taking from lootbag
*/
public boolean takeItemsCheck(Player c, int itemId) {
if (!c.getItems().playerHasItem(LOOTBAG))
return false;
if (!c.inHome()) {
c.sendGameMessage("You must be in the bank at ho
me in order to do this.");
return false;
}
if (c.getItems().freeSlots() == 0) {
c.sendGameMessage("You need at least 1 inventory
slot free to do this!");
return false;
}
return true;
}
/*
* Method used to deposit all of one item into a loot bag
*/
public void depositAllLootbag(Player c) {
if (!c.getItems().playerHasItem(LOOTBAG))
return;
if (!c.inHome()) {
c.sendGameMessage("You must be in the bank at home in or
der to do this.");
return;
}
if (c.getAccount().getType().alias().equals(Account.ULTIMATE_TYP
E.alias())) {
c.sendGameMessage("You cannot deposit items into a non-e
xistant bank.");
return;
}
for (int i = 0; i < c.lootBag.length; i++) {
if (c.lootBag[i] == 0 || c.lootBag[i] == -1)
continue;
c.getItems().addItemToBank(c.lootBag[i], c.amountLoot[i]
);
c.lootBag[i] = -1;
c.amountLoot[i] = -1;
c.getPA().sendFrame34a(26706, -1, c.lootBag[i], -1);
}
updateLootbagInterface(c);
}
/*
* Method used to take a single item from lootBag
*/
public void takeItemLootbag(Player c, int removeId, int removeSlot, int
amount) {
if (!takeItemsCheck(c, amount))
return;
if (c.lootBag[removeSlot] != removeId || !c.getItems().playerHas
Item(LOOTBAG)) {
return;
}
c.getItems().addItem(c.lootBag[removeSlot], (amount != 1) ? c.am
ountLoot[removeSlot] : 1);
if ((c.amountLoot[removeSlot] - amount) == 0) {
c.lootBag[removeSlot] = -1;
c.amountLoot[removeSlot] = -1;
c.getPA().sendFrame34a(26706, -1, removeSlot, -1);
} else {
c.amountLoot[removeSlot] = c.amountLoot[removeSlot] - am
ount;
c.getPA().sendFrame34a(26706, c.lootBag[removeSlot], rem
oveSlot, c.amountLoot[removeSlot]);
}
updateTotalCost(c);
}
/*
* Method used to take all items from lootbag
*/
public void takeAllItemLootbag(Player c, int removeId, int amount) {
int total = 0;
boolean amountLowered = false;
if (!takeItemsCheck(c, removeId))
return;
if (c.getItems().getBagItemAmount(removeId) > c.getItems().freeS
lots()) {
amount = c.getItems().freeSlots();
amountLowered = true;
} else
amount = c.getItems().getBagItemAmount(removeId);
for (int i = 0; i < c.lootBag.length; i++) {
if (total == amount)
break;
if (c.lootBag[i] == removeId) {
c.getItems().addItem(c.lootBag[i], 1);
c.lootBag[i] = -1;
c.amountLoot[i] = -1;
c.getPA().sendFrame34a(26706, -1, i, -1);
total++;
}
}
if (amountLowered)
c.sendGameMessage("You ran out of space in your inventor
y.");
updateTotalCost(c);
}
/*
* Check before allowing items to be added to lootbag
*/
public boolean addItemsCheck(Player c, int itemId, int amount) {
if (itemId == LOOTBAG) {
c.sendGameMessage("You cannot add this into a lo
oting bag.");
return false;
}
if (!c.getItems().playerHasItem(itemId, amount) || !c.ge
tItems().playerHasItem(LOOTBAG)) {
return false;
}
if (!c.inWild()) {
c.sendGameMessage("You need to be in the wildern
ess to do this.");
return false;
}
if (!c.getLastCombatAction().elapsed(600)) {
c.sendGameMessage("You must wait until you're ou
t of combat to do this.");
return false;
}
for (int i = 0; i < c.lootBag.length; i++) {
if (c.lootBag[i] == -1 || c.lootBag[i] == 0) {
break;
} else
continue;
}
return true;
}
/*
* Method used to add all of one item to a lootbag
*/
public void addAllItemToLootbag(Player c, int itemId, int amount) {
boolean hasItem = false;
if (!addItemsCheck(c, itemId, amount))
return;
for (int i = 0; i < c.lootBag.length; i++) {
if (c.lootBag[i] == itemId && (ItemDefinition.forId(item
Id).isStackable() || ItemDefinition.forId(itemId).isNoted())) {
hasItem = true;
break;
}
}
if (hasItem == false) {
for (int i = 0; i < c.lootBag.length; i++) {
if (c.lootBag[i] == -1 || c.lootBag[i] == 0) {
c.getItems().deleteItem(itemId, amount);
c.lootBag[i] = itemId;
c.amountLoot[i] = amount;
break;
}
}
} else {
for (int i = 0; i < c.lootBag.length; i++) {
if (c.lootBag[i] == itemId) {
c.getItems().deleteItem(itemId, amount);
c.amountLoot[i] = c.amountLoot[i] + amou
nt;
break;
}
}
}
updateLootbagInterface(c);
}
/*
* Method used to add a single item to lootbag
*/
public void addItemToLootbag(Player c, int itemId, int amount) {
boolean hasItem = false;
if (!addItemsCheck(c, itemId, amount))
return;
for (int i = 0; i < c.lootBag.length; i++) {
if (c.lootBag[i] == itemId && (ItemDefinition.forId(item
Id).isStackable() || ItemDefinition.forId(itemId).isNoted())) {
hasItem = true;
break;
}
}
if (hasItem == false) {
for (int i = 0; i < c.lootBag.length; i++) {
if (c.lootBag[i] == -1 || c.lootBag[i] == 0) {
c.getItems().deleteItem(itemId, amount);
c.lootBag[i] = itemId;
c.amountLoot[i] = amount;
break;
}
}
} else {
for (int i = 0; i < c.lootBag.length; i++) {
if (c.lootBag[i] == itemId) {
c.getItems().deleteItem(itemId, amount);
c.amountLoot[i] = c.amountLoot[i] + amou
nt;
break;
}
}
}
updateLootbagInterface(c);
}
}

Das könnte Ihnen auch gefallen