/* * (non-Javadoc) * * @see org.saga.buildings.signs.BuildingSign#onRightClick(org.saga.player.SagaPlayer) */ @Override protected void onRightClick(SagaPlayer sagaPlayer) { // Create item: ItemStack item = this.item.createItem(); // Available goods: if (stored < 1.0) { sagaPlayer.message(EconomyMessages.insufItems(item.getType())); return; } // Trim amount based on goods: if (item.getAmount() > stored) item.setAmount(stored.intValue()); // Trim amount based on coins: double coins = EconomyDependency.getCoins(sagaPlayer); if (item.getAmount() * price > coins) item.setAmount((int) (coins / price)); // Available coins: if (item.getAmount() < 1) { sagaPlayer.message(EconomyMessages.insufCoins()); return; } // Take item: if (item.getAmount() < 1) { sagaPlayer.message(EconomyMessages.insufItems(item.getType())); return; } stored -= item.getAmount(); // Finish transaction: Double cost = price * item.getAmount(); EconomyDependency.removeCoins(sagaPlayer, cost); getBuilding().getSettlement().payCoins(cost); sagaPlayer.addItem(item); // Inform: sagaPlayer.message(EconomyMessages.bought(item.getType(), item.getAmount(), price)); // Statistics: StatisticsManager.manager() .addBuy(sagaPlayer, item.getType(), item.getAmount(), price * item.getAmount()); // Update sign: refresh(); }
/* * (non-Javadoc) * * @see org.saga.buildings.signs.BuildingSign#getLine(int, org.saga.buildings.signs.BuildingSign.SignStatus) */ @Override public String getLine(int index, SignStatus status) { switch (status) { case ENABLED: if (index == 1) return item.getAmount().intValue() + AMOUNT_DIV_DISPLAY + GeneralMessages.materialAbrev(item.getType()); if (index == 2) return "price: " + EconomyMessages.coins(price); if (index == 3) return stored.intValue() + "/" + maxStored.intValue(); break; case DISABLED: if (index == 1) return item.getAmount().intValue() + AMOUNT_DIV_DISPLAY + GeneralMessages.materialAbrev(item.getType()); if (index == 2) return "price: " + EconomyMessages.coins(price); if (index == 3) return "come back later"; break; case INVALIDATED: if (index == 1) return SettlementConfiguration.config().invalidSignColor + "amt" + AMOUNT_DIV_DISPLAY + "item/ID"; if (index == 2) return SettlementConfiguration.config().invalidSignColor + "price"; if (index == 3) return SettlementConfiguration.config().invalidSignColor + "max amount"; break; default: return "-"; } return ""; }