use of org.spongepowered.api.item.inventory.ItemStack in project Skree by Skelril.
the class JungleRaidEffectProcessor method titanMode.
private static void titanMode(JungleRaidInstance inst) {
FlagEffectData data = inst.getFlagData();
Collection<Player> players = inst.getPlayers(PlayerClassifier.PARTICIPANT);
if (inst.isFlagEnabled(JungleRaidFlag.TITAN_MODE) && data.titan == null) {
Player player = Probability.pickOneOf(players);
data.titan = player.getUniqueId();
ItemStack teamHood = newItemStack(ItemTypes.LEATHER_HELMET);
teamHood.offer(Keys.DISPLAY_NAME, Text.of(TextColors.WHITE, "Titan Hood"));
teamHood.offer(Keys.COLOR, Color.BLACK);
// playerEquipment.set(EquipmentTypes.HEADWEAR, teamHood);
tf(player).inventory.armorInventory[3] = tf(teamHood);
}
for (Player player : players) {
if (inst.isFlagEnabled(JungleRaidFlag.TITAN_MODE) && player.getUniqueId().equals(data.titan)) {
List<PotionEffect> potionEffects = player.getOrElse(Keys.POTION_EFFECTS, new ArrayList<>());
potionEffects.add(PotionEffect.of(PotionEffectTypes.NIGHT_VISION, 1, 20 * 20));
player.offer(Keys.POTION_EFFECTS, potionEffects);
}
}
}
use of org.spongepowered.api.item.inventory.ItemStack in project Skree by Skelril.
the class GoldRushInstance method payPlayer.
public boolean payPlayer(Player player) {
BigDecimal fee = cofferRisk.get(player.getUniqueId());
// They didn't pay, CHEATER!!!
if (fee == null)
return false;
net.minecraft.item.ItemStack[] itemStacks = tf(player).inventory.mainInventory;
BigDecimal goldValue = BigDecimal.ZERO;
BigDecimal itemValue = BigDecimal.ZERO;
Optional<MarketService> optService = Sponge.getServiceManager().provide(MarketService.class);
List<ItemStack> returned = new ArrayList<>();
for (int i = 0; i < itemStacks.length; ++i) {
net.minecraft.item.ItemStack is = itemStacks[i];
if (is == null || is.getItem() != CustomItemTypes.PRIZE_BOX)
continue;
Optional<ItemStack> optOpened = PrizeBox.getPrizeStack(is);
if (optService.isPresent() && optOpened.isPresent()) {
MarketService service = optService.get();
ItemStack opened = optOpened.get();
Optional<BigDecimal> value = service.getPrice(opened);
if (value.isPresent()) {
BigDecimal quantity = new BigDecimal(opened.getQuantity());
if (opened.getItem() == ItemTypes.GOLD_NUGGET || opened.getItem() == ItemTypes.GOLD_INGOT || opened.getItem() == BlockTypes.GOLD_BLOCK.getItem().get()) {
goldValue = goldValue.add(value.get().multiply(quantity));
} else {
itemValue = itemValue.add(value.get().multiply(quantity));
returned.add(opened);
}
}
}
itemStacks[i] = null;
}
// Get the original grab amount (The Sum of Gold & Items)
BigDecimal originalGrabbed = goldValue.add(itemValue);
// Create a penalty value if the player was in a flood (Time Taken / Time Per Penalty) * Penalty Increment Value
// for instance (6000 milliseconds after / 3000 millisecond penality increment) * 9 coffer increment value
// would result in 18 coffers being the penalty value
BigDecimal penaltyValue = new BigDecimal(getTimeTakenAfterFlood()).divide(PENALTY_INCREMENT, 2, RoundingMode.UP).multiply(PENALTY_INCREMENT_VALUE);
// Total grabbed is the original grab amount - the penalty value
BigDecimal totalGrabbed = originalGrabbed.subtract(penaltyValue);
// The ratio they would have recieved with no time penalty
// Calculated as the multiplier * (Grab Ratio * (Value of stuff (grab amount) / Pivotal value (target amount)))
BigDecimal originalGrabRatio = multiplier.multiply(GRAB_RATIO.multiply(originalGrabbed.divide(PIVOTAL_VALUE, 2, RoundingMode.DOWN)));
// The same calculation as the original grab ratio, just using the time penalty modified grab amount
BigDecimal grabRatio = multiplier.multiply(GRAB_RATIO.multiply(totalGrabbed.divide(PIVOTAL_VALUE, 2, RoundingMode.DOWN)));
// The penalty ratio is the percentage value loss from the original grab ratio
BigDecimal penaltyRatio = originalGrabRatio.subtract(grabRatio);
// The loot split times the group modifier
BigDecimal multipliedLootSplit = multiplier.multiply(lootSplit);
// The amount of money they gain from the their boosted risk
BigDecimal splitBoost = multipliedLootSplit.multiply(grabRatio);
// The total amount of money they get, being the loot split + their boosted risk value
// minus item value
BigDecimal personalLootSplit = multipliedLootSplit.add(splitBoost);
player.sendMessage(Text.of(TextColors.YELLOW, "You obtain: "));
player.sendMessage(Text.of(TextColors.YELLOW, " - Bail: ", format(fee)));
player.sendMessage(Text.of(TextColors.YELLOW, " - Split: ", format(multipliedLootSplit), ", Multiplied by: ", format(multiplier), "x, Boosted by: ", format(grabRatio.multiply(new BigDecimal(100))), "%"));
if (penaltyRatio.compareTo(BigDecimal.ZERO) != 0) {
player.sendMessage(Text.of(TextColors.YELLOW, " - Boost time penalty: ", format(penaltyRatio.multiply(new BigDecimal(100))), "%"));
}
if (grabRatio.compareTo(BigDecimal.ZERO) != 0) {
player.sendMessage(Text.of(TextColors.YELLOW, " - Boost value: ", format(splitBoost)));
}
BigDecimal total = fee.add(personalLootSplit);
player.sendMessage(Text.of(TextColors.YELLOW, "Total: ", format(total)));
// Give the player their items
Optional<PlayerStateService> optInvService = Sponge.getServiceManager().provide(PlayerStateService.class);
if (optInvService.isPresent()) {
PlayerStateService invService = optInvService.get();
invService.loadInventoryIfStored(player);
}
returned.forEach(i -> player.getInventory().offer(i));
MarketImplUtil.setBalanceTo(player, total.add(MarketImplUtil.getMoney(player)), Cause.source(this).build());
remove(player);
return true;
}
use of org.spongepowered.api.item.inventory.ItemStack in project Skree by Skelril.
the class ScrollOfSummation method onRightClick.
@Listener
public void onRightClick(InteractBlockEvent.Secondary.MainHand event, @First Player player) {
Optional<ItemStack> optHeldItem = player.getItemInHand(HandTypes.MAIN_HAND);
if (!optHeldItem.isPresent()) {
return;
}
ItemStack held = optHeldItem.get();
if (held.getItem() != this) {
return;
}
net.minecraft.item.ItemStack[] pInv = tf(player).inventory.mainInventory;
Optional<ItemStack[]> optCompacted = new ItemCompactor(ImmutableList.of(CoalValueMap.inst(), IronValueMap.inst(), GoldValueMap.inst(), RedstoneValueMap.inst(), LapisValueMap.inst(), DiamondValueMap.inst(), EmeraldValueMap.inst(), CofferValueMap.inst())).execute((ItemStack[]) (Object[]) pInv);
if (optCompacted.isPresent()) {
Task.builder().execute(() -> {
ItemStack[] nInv = optCompacted.get();
for (int i = 0; i < pInv.length; ++i) {
pInv[i] = tf(nInv[i]);
}
tf(player).inventoryContainer.detectAndSendChanges();
tf(player).inventory.decrStackSize(tf(player).inventory.currentItem, 1);
player.sendMessage(Text.of(TextColors.GOLD, "The scroll glows brightly before turning to dust..."));
}).delayTicks(1).submit(SkreePlugin.inst());
event.setUseBlockResult(Tristate.FALSE);
}
}
use of org.spongepowered.api.item.inventory.ItemStack in project Skree by Skelril.
the class SkullOfTheFallen method onRightClick.
@Listener
public void onRightClick(InteractBlockEvent.Secondary.MainHand event, @First Player player) {
Optional<ItemStack> optHeldItem = player.getItemInHand(HandTypes.MAIN_HAND);
if (!optHeldItem.isPresent()) {
return;
}
if (this != optHeldItem.get().getItem()) {
return;
}
Location<World> pLoc = player.getLocation();
Optional<WorldService> optWorldService = Sponge.getServiceManager().provide(WorldService.class);
if (optWorldService.isPresent()) {
WorldService worldService = optWorldService.get();
WildernessWorldWrapper wrapper = worldService.getEffectWrapper(WildernessWorldWrapper.class).get();
Optional<Integer> optLevel = wrapper.getLevel(pLoc);
if (optLevel.isPresent()) {
int level = optLevel.get();
DecimalFormat df = new DecimalFormat("#,###.##");
player.sendMessages(Text.of(TextColors.YELLOW, "Wilderness level: " + level), Text.of(TextColors.YELLOW, "PvP Enabled: " + (wrapper.allowsPvP(level) ? "Yes" : "No")), Text.of(TextColors.YELLOW, "Mob damage: +" + df.format(wrapper.getDamageMod(level))), Text.of(TextColors.YELLOW, "Mob health: x" + df.format(wrapper.getHealthMod(level))), Text.of(TextColors.YELLOW, "Ore modifier: x" + df.format(wrapper.getOreMod(wrapper.getDropTier(level)))), Text.of(TextColors.YELLOW, "Drop modifier: x" + df.format(level * wrapper.getDropMod(wrapper.getDropTier(level)))));
} else {
player.sendMessage(Text.of(TextColors.RED, "You're not in a Wilderness world!"));
}
event.setUseBlockResult(Tristate.FALSE);
}
}
use of org.spongepowered.api.item.inventory.ItemStack in project Skree by Skelril.
the class MagicBlockStateHelper method dropItems.
protected static void dropItems(Location<World> loc, Cause cause) {
ItemStack ladder = ItemStackFactory.newItemStack((BlockType) CustomBlockTypes.MAGIC_LADDER);
ItemStack platform = ItemStackFactory.newItemStack((BlockType) CustomBlockTypes.MAGIC_PLATFORM);
Collection<ItemStack> drops = new ArrayList<>();
drops.addAll(newItemStackCollection(ladder, foundLadder));
drops.addAll(newItemStackCollection(platform, foundPlatform));
new ItemDropper(loc).dropStacks(drops, SpawnTypes.DROPPED_ITEM);
resetCounts();
}
Aggregations