use of com.sx4.bot.entities.economy.item.Rod in project Sx4 by sx4-discord-bot.
the class FishCommand method onCommand.
public void onCommand(Sx4CommandEvent event) {
EmbedBuilder embed = new EmbedBuilder();
event.getMongo().withTransaction(session -> {
Bson filter = Filters.and(Filters.eq("userId", event.getAuthor().getIdLong()), Filters.eq("item.type", ItemType.ROD.getId()));
Document data = event.getMongo().getItems().find(session, filter).first();
if (data == null) {
event.replyFailure("You do not have a fishing rod").queue();
session.abortTransaction();
return;
}
CooldownItemStack<Rod> rodStack = new CooldownItemStack<>(event.getBot().getEconomyManager(), data);
long usableAmount = rodStack.getUsableAmount();
if (usableAmount == 0) {
event.reply("Slow down! You can go fishing again in " + TimeUtility.LONG_TIME_FORMATTER.parse(rodStack.getTimeRemaining()) + " :stopwatch:").queue();
session.abortTransaction();
return;
}
Rod rod = rodStack.getItem();
long yield = rod.getYield(event.getBot().getEconomyManager());
embed.setAuthor(event.getAuthor().getName(), null, event.getAuthor().getEffectiveAvatarUrl()).setColor(event.getMember().getColorRaw()).setDescription(String.format("You fish for 5 minutes and sell your fish! (**$%,d**) :fish:", yield));
if (rod.getDurability() == 2) {
embed.appendDescription("\n\nYour fishing rod will break the next time you use it :warning:");
} else if (rod.getDurability() == 1) {
embed.appendDescription("\n\nYour fishing rod broke in the process");
}
Bson itemFilter = Filters.and(Filters.eq("userId", event.getAuthor().getIdLong()), Filters.eq("item.id", rod.getId()));
if (rod.getDurability() == 1) {
event.getMongo().getItems().deleteOne(session, itemFilter);
} else {
List<Bson> update = List.of(EconomyUtility.getResetsUpdate(usableAmount, FishCommand.COOLDOWN), Operators.set("item.durability", Operators.subtract("$item.durability", 1)));
event.getMongo().getItems().updateOne(session, itemFilter, update);
}
event.getMongo().getUsers().updateOne(session, Filters.eq("_id", event.getAuthor().getIdLong()), Updates.inc("economy.balance", yield), new UpdateOptions().upsert(true));
}).whenComplete((updated, exception) -> {
if (ExceptionUtility.sendExceptionally(event, exception)) {
return;
}
if (updated) {
event.reply(embed.build()).queue();
}
});
}
use of com.sx4.bot.entities.economy.item.Rod in project Sx4 by sx4-discord-bot.
the class FishingRodCommand method info.
@Command(value = "info", aliases = { "information" }, description = "View information on a users fishing rod")
@CommandId(382)
@Examples({ "fishing rod info", "fishing rod info @Shea#6653", "fishing rod info Shea" })
@BotPermissions(permissions = { Permission.MESSAGE_EMBED_LINKS })
public void info(Sx4CommandEvent event, @Argument(value = "user", endless = true, nullDefault = true) Member member) {
Member effectiveMember = member == null ? event.getMember() : member;
User user = member == null ? event.getAuthor() : effectiveMember.getUser();
Bson filter = Filters.and(Filters.eq("userId", effectiveMember.getIdLong()), Filters.eq("item.type", ItemType.ROD.getId()));
Document data = event.getMongo().getItem(filter, Projections.include("item"));
if (data == null) {
event.replyFailure("That user does not have a fishing rod").queue();
return;
}
Rod rod = Rod.fromData(event.getBot().getEconomyManager(), data.get("item", Document.class));
EmbedBuilder embed = new EmbedBuilder().setAuthor(user.getName() + "'s " + rod.getName(), null, user.getEffectiveAvatarUrl()).setColor(effectiveMember.getColorRaw()).setThumbnail("https://emojipedia-us.s3.amazonaws.com/thumbs/120/twitter/147/fishing-pole-and-fish_1f3a3.png").addField("Durability", rod.getDurability() + "/" + rod.getMaxDurability(), false).addField("Current Price", String.format("$%,d", rod.getCurrentPrice()), false).addField("Price", String.format("$%,d", rod.getPrice()), false).addField("Yield", String.format("$%,d to $%,d", rod.getMinYield(), rod.getMaxYield()), false);
event.reply(embed.build()).queue();
}
use of com.sx4.bot.entities.economy.item.Rod in project Sx4 by sx4-discord-bot.
the class FishingRodCommand method shop.
@Command(value = "shop", description = "View all the fishing rods you are able to buy or craft")
@CommandId(379)
@Examples({ "fishing rod shop" })
@BotPermissions(permissions = { Permission.MESSAGE_EMBED_LINKS })
public void shop(Sx4CommandEvent event) {
List<Rod> rods = event.getBot().getEconomyManager().getItems(Rod.class);
PagedResult<Rod> paged = new PagedResult<>(event.getBot(), rods).setPerPage(12).setCustomFunction(page -> {
EmbedBuilder embed = new EmbedBuilder().setAuthor("Fishing Rod Shop", null, event.getSelfUser().getEffectiveAvatarUrl()).setTitle("Page " + page.getPage() + "/" + page.getMaxPage()).setDescription("Fishing rods are a good way to gain some money").setFooter(PagedResult.DEFAULT_FOOTER_TEXT);
page.forEach((rod, index) -> {
List<ItemStack<CraftItem>> items = rod.getCraft();
String craft = items.isEmpty() ? "None" : items.stream().map(ItemStack::toString).collect(Collectors.joining("\n"));
embed.addField(rod.getName(), String.format("Price: $%,d\nCraft: %s\nDurability: %,d", rod.getPrice(), craft, rod.getMaxDurability()), true);
});
return new MessageBuilder().setEmbeds(embed.build());
});
paged.execute(event);
}
use of com.sx4.bot.entities.economy.item.Rod in project Sx4 by sx4-discord-bot.
the class FishingRodCommand method upgrade.
@Command(value = "upgrade", description = "Upgrade your fishing rod by a certain attribute")
@CommandId(431)
@Examples({ "fishing rod upgrade money", "fishing rod upgrade durability 5" })
public void upgrade(Sx4CommandEvent event, @Argument(value = "upgrade") Upgrade upgrade, @Argument(value = "upgrades") @DefaultNumber(1) @Limit(min = 1, max = 100) int upgrades) {
if (!upgrade.containsType(ItemType.ROD)) {
event.replyFailure("You can not use that upgrade on a fishing rod").queue();
return;
}
event.getMongo().withTransaction(session -> {
Document data = event.getMongo().getItems().find(session, Filters.and(Filters.eq("userId", event.getAuthor().getIdLong()), Filters.eq("item.type", ItemType.ROD.getId()))).first();
if (data == null) {
event.replyFailure("You do not have a fishing rod").queue();
session.abortTransaction();
return null;
}
Document item = data.get("item", Document.class);
Rod defaultRod = event.getBot().getEconomyManager().getItemById(item.getInteger("id"), Rod.class);
Rod rod = new Rod(item, defaultRod);
int currentUpgrades = rod.getUpgrades();
long price = 0;
for (int i = 0; i < upgrades; i++) {
price += Math.round(0.015D * defaultRod.getPrice() * currentUpgrades++ + 0.025D * defaultRod.getPrice());
}
UpdateResult result = event.getMongo().getUsers().updateOne(session, Filters.eq("_id", event.getAuthor().getIdLong()), List.of(EconomyUtility.decreaseBalanceUpdate(price)));
if (result.getModifiedCount() == 0) {
event.replyFormat("You do not have **$%,d** %s", price, event.getConfig().getFailureEmote()).queue();
session.abortTransaction();
return null;
}
List<Bson> update = new ArrayList<>();
update.add(Operators.set("item.upgrades", Operators.add(Operators.ifNull("$item.upgrades", 0), upgrades)));
update.add(Operators.set("item.price", Operators.add("$item.price", Math.round(defaultRod.getPrice() * 0.015D) * upgrades)));
if (upgrade == Upgrade.MONEY) {
int increase = (int) Math.round(defaultRod.getMinYield() * upgrade.getValue()) * upgrades;
update.add(Operators.set("item.minYield", Operators.add("$item.minYield", increase)));
update.add(Operators.set("item.maxYield", Operators.add("$item.maxYield", increase)));
} else if (upgrade == Upgrade.DURABILITY) {
int increase = (int) upgrade.getValue() * upgrades;
update.add(Operators.set("item.durability", Operators.add("$item.durability", increase)));
update.add(Operators.set("item.maxDurability", Operators.add("$item.maxDurability", increase)));
}
event.getMongo().getItems().updateOne(session, Filters.and(Filters.eq("userId", event.getAuthor().getIdLong()), Filters.eq("item.id", rod.getId())), update);
return String.format("You just upgraded %s %d time%s for your `%s` for **$%,d**", upgrade.getName().toLowerCase(), upgrades, (upgrades == 1 ? "" : "s"), rod.getName(), price);
}).whenComplete((message, exception) -> {
if (ExceptionUtility.sendExceptionally(event, exception) || message == null) {
return;
}
event.replySuccess(message).queue();
});
}
use of com.sx4.bot.entities.economy.item.Rod in project Sx4 by sx4-discord-bot.
the class FishingRodCommand method upgrades.
@Command(value = "upgrades", description = "View all the upgrades you can use on a fishing rod")
@CommandId(432)
@Examples({ "pickaxe upgrades" })
public void upgrades(Sx4CommandEvent event) {
EnumSet<Upgrade> upgrades = Upgrade.getUpgrades(ItemType.ROD);
PagedResult<Upgrade> paged = new PagedResult<>(event.getBot(), Arrays.asList(upgrades.toArray(Upgrade[]::new))).setPerPage(3).setCustomFunction(page -> {
EmbedBuilder embed = new EmbedBuilder().setTitle("Fishing Rod Upgrades");
page.forEach((upgrade, index) -> embed.addField(upgrade.getName(), upgrade.getDescription(), false));
return new MessageBuilder().setEmbeds(embed.build());
});
paged.execute(event);
}
Aggregations