Skip to content
This repository was archived by the owner on Feb 10, 2024. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
189 changes: 55 additions & 134 deletions src/main/java/net/kodehawa/mantarobot/commands/CurrencyActionCmds.java

Large diffs are not rendered by default.

51 changes: 35 additions & 16 deletions src/main/java/net/kodehawa/mantarobot/commands/CurrencyCmds.java
Original file line number Diff line number Diff line change
Expand Up @@ -616,13 +616,12 @@ private static void useItem(IContext ctx, MongoUser dbUser, Player player, Strin
return;
}

if (item.getItemType() != ItemType.INTERACTIVE && item.getItemType() != ItemType.CRATE &&
item.getItemType() != ItemType.POTION && item.getItemType() != ItemType.BUFF) {
if (!item.getItemType().isUsable()) {
ctx.sendLocalized("commands.useitem.not_interactive", EmoteReference.ERROR);
return;
}

if (item.getAction() == null && (item.getItemType() != ItemType.POTION && item.getItemType() != ItemType.BUFF)) {
if (item.getAction() == null && !item.getItemType().isPotion()) {
ctx.sendLocalized("commands.useitem.interactive_no_action", EmoteReference.ERROR);
return;
}
Expand All @@ -632,7 +631,7 @@ private static void useItem(IContext ctx, MongoUser dbUser, Player player, Strin
return;
}

applyPotionEffect(ctx, dbUser, item, player, amount, isMax);
handleItemAction(ctx, dbUser, item, player, amount, isMax);
}

private static void tools(IContext ctx, MongoUser dbUser) {
Expand Down Expand Up @@ -781,12 +780,11 @@ private static void showInventory(IContext ctx, User user, Player player, MongoU
DiscordUtils.sendPaginatedEmbed(ctx.getUtilsContext(), builder, DiscordUtils.divideFields(7, fields), toShow);
}

public static void applyPotionEffect(IContext ctx, MongoUser dbUser, Item item, Player player, int amount, boolean isMax) {
if ((item.getItemType() == ItemType.POTION || item.getItemType() == ItemType.BUFF) && item instanceof Potion potion) {
public static void handleItemAction(IContext ctx, MongoUser dbUser, Item item, Player player, int amount, boolean isMax) {
if (item.getItemType().isPotion() && item instanceof Potion potion) {
final var equippedItems = dbUser.getEquippedItems();
var type = equippedItems.getTypeFor(item);
var currentPotion = equippedItems.getCurrentEffect(type);
var activePotion = equippedItems.isEffectActive(type, potion.getMaxUses());
var currentPotion = equippedItems.getCurrentEffect(potion.getEffectType());
var activePotion = equippedItems.isEffectActive(potion.getEffectType(), potion.getMaxUses());
var isActive = currentPotion != null && currentPotion.getAmountEquipped() > 1;
var amountEquipped = 0L;
if (activePotion || isActive) { // currentPotion is NOT null here (both activePotion and isActive would mean a potion exists)
Expand Down Expand Up @@ -814,11 +812,15 @@ public static void applyPotionEffect(IContext ctx, MongoUser dbUser, Item item,
// In case you have more than a potion equipped, we'll just stack the rest as necessary.
if (activePotion || isActive) { // currentPotion is NOT null here (both activePotion and isActive would mean a potion exists)
//Currently has a potion equipped, but wants to stack a potion of other type.
var equippedItem = ItemHelper.fromId(currentPotion.getPotion());
if (currentPotion.getPotion() != ItemHelper.idOf(item)) {
ctx.sendLocalized("general.misc_item_usage.not_same_potion",
EmoteReference.ERROR,
ItemHelper.fromId(currentPotion.getPotion()).getName(),
item.getName()
equippedItem.getEmojiDisplay(),
equippedItem.getName(),
item.getEmojiDisplay(),
item.getName(),
ctx.getLanguageContext().get("items.effect_types." + potion.getEffectType().name().toLowerCase())
);

return;
Expand All @@ -829,15 +831,24 @@ public static void applyPotionEffect(IContext ctx, MongoUser dbUser, Item item,

// Currently has a potion equipped, and is of the same type.
if (attempted < 16) {
equippedItems.equipEffect(type, activePotion ? amount : Math.max(1, amount - 1));
equippedItems.equipEffect(potion.getEffectType(), activePotion ? amount : Math.max(1, amount - 1));
var equipped = currentPotion.getAmountEquipped();

ctx.sendLocalized("general.misc_item_usage.potion_applied_multiple",
EmoteReference.CORRECT, item.getName(), Utils.capitalize(type.toString()), equipped
EmoteReference.CORRECT,
item.getEmojiDisplay(),
item.getName(),
ctx.getLanguageContext().get("items.effect_types." + potion.getEffectType().name().toLowerCase()),
equipped
);
} else {
// Too many stacked (max: 15).
ctx.sendLocalized("general.misc_item_usage.max_stack_size", EmoteReference.ERROR, item.getName(), attempted);
ctx.sendLocalized("general.misc_item_usage.max_stack_size",
EmoteReference.ERROR,
item.getEmojiDisplay(),
item.getName(),
attempted
);
return;
}
} else {
Expand All @@ -847,7 +858,11 @@ public static void applyPotionEffect(IContext ctx, MongoUser dbUser, Item item,
// If there's more than 1, proceed to equip the stacks.
if (amount > 15) {
//Too many stacked (max: 15).
ctx.sendLocalized("general.misc_item_usage.max_stack_size_2", EmoteReference.ERROR, item.getName(), amount);
ctx.sendLocalized("general.misc_item_usage.max_stack_size_2",
EmoteReference.ERROR,
item.getEmojiDisplay(),
item.getName(),
amount);
return;
}

Expand All @@ -858,7 +873,11 @@ public static void applyPotionEffect(IContext ctx, MongoUser dbUser, Item item,
// Apply the effect.
equippedItems.applyEffect(effect);
ctx.sendLocalized("general.misc_item_usage.potion_applied",
EmoteReference.CORRECT, item.getName(), Utils.capitalize(type.toString()), amount
EmoteReference.CORRECT,
item.getEmojiDisplay(),
item.getName(),
ctx.getLanguageContext().get("items.effect_types." + potion.getEffectType().name().toLowerCase()),
amount
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
import net.kodehawa.mantarobot.core.command.slash.IContext;
import net.kodehawa.mantarobot.core.command.slash.SlashCommand;
import net.kodehawa.mantarobot.core.command.slash.SlashContext;
import net.kodehawa.mantarobot.core.listeners.operations.ButtonOperations;
import net.kodehawa.mantarobot.core.listeners.operations.ComponentOperations;
import net.kodehawa.mantarobot.core.listeners.operations.ModalOperations;
import net.kodehawa.mantarobot.core.listeners.operations.core.ModalOperation;
import net.kodehawa.mantarobot.core.listeners.operations.core.Operation;
Expand Down Expand Up @@ -1129,7 +1129,7 @@ private static void clearCommand(IContext ctx) {

var languageContext = ctx.getLanguageContext();
var message = ctx.sendResult(languageContext.get("commands.custom.clear.confirmation").formatted(EmoteReference.WARNING));
ButtonOperations.create(message, 60, e -> {
ComponentOperations.createButton(message, 60, e -> {
if (e.getUser().getIdLong() != ctx.getAuthor().getIdLong()) {
return Operation.IGNORED;
}
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/net/kodehawa/mantarobot/commands/MarryCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import net.kodehawa.mantarobot.core.command.meta.Options;
import net.kodehawa.mantarobot.core.command.slash.SlashCommand;
import net.kodehawa.mantarobot.core.command.slash.SlashContext;
import net.kodehawa.mantarobot.core.listeners.operations.ButtonOperations;
import net.kodehawa.mantarobot.core.listeners.operations.ComponentOperations;
import net.kodehawa.mantarobot.core.listeners.operations.core.Operation;
import net.kodehawa.mantarobot.core.modules.Module;
import net.kodehawa.mantarobot.core.modules.commands.base.CommandCategory;
Expand Down Expand Up @@ -158,7 +158,7 @@ protected void process(SlashContext ctx) {
.formatted(EmoteReference.MEGA, proposedToUser.getName(), ctx.getAuthor().getName(), EmoteReference.STOPWATCH)
);

ButtonOperations.create(message, 120, e -> {
ComponentOperations.createButton(message, 120, e -> {
// Ignore all messages from anyone that isn't the user we already proposed to. Waiting for confirmation...
if (!e.getUser().getId().equals(proposedToUser.getId())) {
return Operation.IGNORED;
Expand Down Expand Up @@ -426,7 +426,7 @@ protected void process(SlashContext ctx) {
);

//Start the operation.
ButtonOperations.create(message, 60, e -> {
ComponentOperations.createButton(message, 60, e -> {
if (e.getUser().getIdLong() != author.getIdLong()) {
return Operation.IGNORED;
}
Expand Down Expand Up @@ -519,7 +519,7 @@ protected void process(SlashContext ctx) {

var finalContent = Utils.HTTP_URL.matcher(name).replaceAll("-url-");
var message = ctx.sendResult(String.format(languageContext.get("commands.marry.buyhouse.confirm"), EmoteReference.WARNING, housePrice, finalContent));
ButtonOperations.create(message, 30, e -> {
ComponentOperations.createButton(message, 30, e -> {
if (e.getUser().getIdLong() != ctx.getAuthor().getIdLong()) {
return Operation.IGNORED;
}
Expand Down Expand Up @@ -611,7 +611,7 @@ protected void process(SlashContext ctx) {

var finalContent = Utils.HTTP_URL.matcher(name).replaceAll("-url-");
var message = ctx.sendResult(String.format(languageContext.get("commands.marry.buycar.confirm"), EmoteReference.WARNING, carPrice, finalContent));
ButtonOperations.create(message, 30, e -> {
ComponentOperations.createButton(message, 30, e -> {
if (e.getUser().getIdLong() != ctx.getAuthor().getIdLong()) {
return Operation.IGNORED;
}
Expand Down Expand Up @@ -678,7 +678,7 @@ protected void process(SlashContext ctx) {

final var languageContext = ctx.getLanguageContext();
final var message = ctx.sendResult(String.format(languageContext.get("commands.divorce.confirm"), EmoteReference.WARNING));
ButtonOperations.create(message, 45, e -> {
ComponentOperations.createButton(message, 45, e -> {
if (e.getUser().getIdLong() != ctx.getAuthor().getIdLong()) {
return Operation.IGNORED;
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/net/kodehawa/mantarobot/commands/PetCmds.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import net.kodehawa.mantarobot.core.command.slash.AutocompleteContext;
import net.kodehawa.mantarobot.core.command.slash.SlashCommand;
import net.kodehawa.mantarobot.core.command.slash.SlashContext;
import net.kodehawa.mantarobot.core.listeners.operations.ButtonOperations;
import net.kodehawa.mantarobot.core.listeners.operations.ComponentOperations;
import net.kodehawa.mantarobot.core.listeners.operations.core.Operation;
import net.kodehawa.mantarobot.core.modules.Module;
import net.kodehawa.mantarobot.core.modules.commands.base.CommandCategory;
Expand Down Expand Up @@ -514,7 +514,7 @@ protected void process(SlashContext ctx) {
player.locked(true);
player.updateAllChanged();

ButtonOperations.create(message, 60, event -> {
ComponentOperations.createButton(message, 60, event -> {
if (event.getUser().getIdLong() != ctx.getAuthor().getIdLong()) {
return Operation.IGNORED;
}
Expand Down Expand Up @@ -703,7 +703,7 @@ protected void process(SlashContext ctx) {
var message = ctx.sendResult(
String.format(ctx.getLanguageContext().get("commands.pet.buy.confirm"), EmoteReference.WARNING, name, type, toBuy.getCost(), petChoice.getReadableName())
);
ButtonOperations.create(message, 60, event -> {
ComponentOperations.createButton(message, 60, event -> {
if (event.getUser().getIdLong() != ctx.getAuthor().getIdLong()) {
return Operation.IGNORED;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import net.kodehawa.mantarobot.core.command.slash.AutocompleteContext;
import net.kodehawa.mantarobot.core.command.slash.SlashCommand;
import net.kodehawa.mantarobot.core.command.slash.SlashContext;
import net.kodehawa.mantarobot.core.listeners.operations.ButtonOperations;
import net.kodehawa.mantarobot.core.listeners.operations.ComponentOperations;
import net.kodehawa.mantarobot.core.listeners.operations.core.InteractiveOperation;
import net.kodehawa.mantarobot.core.listeners.operations.core.Operation;
import net.kodehawa.mantarobot.core.modules.Module;
Expand Down Expand Up @@ -283,7 +283,7 @@ protected void process(SlashContext ctx) {
var lang = ctx.getLanguageContext();

var message = ctx.sendResult(lang.get("commands.profile.unequip.confirm").formatted(EmoteReference.WARNING, equippedItem.getEmoji(), equippedItem.getName()));
ButtonOperations.create(message, ctx.getAuthor().getIdLong(), event -> {
ComponentOperations.createButton(message, ctx.getAuthor().getIdLong(), event -> {
var author = event.getUser();
if (author.getIdLong() != ctx.getAuthor().getIdLong()) {
return InteractiveOperation.IGNORED;
Expand Down
58 changes: 57 additions & 1 deletion src/main/java/net/kodehawa/mantarobot/commands/ProfileCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import net.kodehawa.mantarobot.commands.currency.item.ItemHelper;
import net.kodehawa.mantarobot.commands.currency.item.ItemReference;
import net.kodehawa.mantarobot.commands.currency.item.PlayerEquipment;
import net.kodehawa.mantarobot.commands.currency.item.PotionEffect;
import net.kodehawa.mantarobot.commands.currency.item.special.helpers.Breakable;
import net.kodehawa.mantarobot.commands.currency.profile.Badge;
import net.kodehawa.mantarobot.commands.currency.profile.ProfileComponent;
Expand Down Expand Up @@ -427,6 +428,60 @@ public void onExpire() {
}
}

@Description("See buffs applied to someone's profile.")
@Options({@Options.Option(type = OptionType.USER, name = "user", description = "The user to see buffs of.")})
@Help(
description = "See buffs applied to your own or someone's profile.",
usage = "`/profile buffs user:[user]`",
parameters = {@Help.Parameter(name = "user", description = "The user to see buffs of.", optional = true)}
)
public static class Buffs extends SlashCommand {
@Override
protected void process(SlashContext ctx) {
var toLookup = ctx.getOptionAsUser("user", ctx.getAuthor());
var lang = ctx.getLanguageContext();
if (toLookup.isBot()) {
ctx.replyEphemeral("commands.profile.bot_notice", EmoteReference.ERROR);
return;
}

var dbUser = ctx.getDBUser(toLookup);

var equippedItems = dbUser.getEquippedItems();
var sorted = equippedItems.getEffectListSorted();
if (sorted.isEmpty()) {
ctx.sendLocalized("commands.profile.buffs.no_buffs", EmoteReference.ERROR, toLookup.getName());
return;
}
List<MessageEmbed.Field> fields = new LinkedList<>();
for (PotionEffect effect : sorted) {
// this adds a blank field between each entry
if (!fields.isEmpty() && (fields.size() == 1 || fields.size() % 2 == 0)) {
fields.add(new MessageEmbed.Field(
EmbedBuilder.ZERO_WIDTH_SPACE,
EmbedBuilder.ZERO_WIDTH_SPACE,
true)
);
}
var field = PotionEffect.toDisplayField(ctx, effect, equippedItems);
if (field == null) continue;
fields.add(field);
}

var splitFields = DiscordUtils.divideFields(9, fields);
var embed = new EmbedBuilder()
.setThumbnail(toLookup.getEffectiveAvatarUrl())
.setAuthor(lang.get("commands.profile.buffs.header").formatted(toLookup.getName()),
null, toLookup.getEffectiveAvatarUrl()
)
.setDescription(String.format(lang.get("general.buy_sell_paged_react"), String.format(lang.get("general.reaction_timeout"), 200)))
.setColor(ctx.getMemberColor())
.setFooter("Thanks for using Mantaro! %s".formatted(EmoteReference.HEART), ctx.getGuild().getIconUrl());

DiscordUtils.listButtons(ctx.getUtilsContext(), 200, embed, splitFields);
}
}

@Description("See profile statistics.")
@Options({@Options.Option(type = OptionType.USER, name = "user", description = "The user to see stats for.")})
@Help(
Expand Down Expand Up @@ -573,7 +628,8 @@ private static MessageEmbed buildProfile(IContext ctx, User userLooked) {
if (mh != null) {
try {
mhMember = mh.retrieveMemberById(userLooked.getId()).useCache(true).complete();
} catch (ErrorResponseException ignored) { } // Expected UNKNOWN_MEMBER
} catch (ErrorResponseException ignored) {
} // Expected UNKNOWN_MEMBER
}

Badge.assignBadges(player, player.getStats(), dbUser);
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/net/kodehawa/mantarobot/commands/WaifuCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import net.kodehawa.mantarobot.core.command.meta.Options;
import net.kodehawa.mantarobot.core.command.slash.SlashCommand;
import net.kodehawa.mantarobot.core.command.slash.SlashContext;
import net.kodehawa.mantarobot.core.listeners.operations.ButtonOperations;
import net.kodehawa.mantarobot.core.listeners.operations.ComponentOperations;
import net.kodehawa.mantarobot.core.listeners.operations.core.Operation;
import net.kodehawa.mantarobot.core.modules.Module;
import net.kodehawa.mantarobot.core.modules.commands.base.CommandCategory;
Expand Down Expand Up @@ -248,7 +248,7 @@ protected void process(SlashContext ctx) {
}

var message = ctx.sendResult(ctx.getLanguageContext().get("commands.waifu.optout.warning").formatted(EmoteReference.WARNING));
ButtonOperations.create(message, 60, e -> {
ComponentOperations.createButton(message, 60, e -> {
if (e.getUser().getIdLong() != ctx.getAuthor().getIdLong()) {
return Operation.IGNORED;
}
Expand Down Expand Up @@ -429,7 +429,7 @@ protected void process(SlashContext ctx) {
final var valuePayment = (long) (currentValue * 0.15);
//Send confirmation message.
var message = ctx.sendResult(ctx.getLanguageContext().get("commands.waifu.unclaim.confirmation").formatted(EmoteReference.MEGA, name, valuePayment, EmoteReference.STOPWATCH));
ButtonOperations.create(message, 60, ie -> {
ComponentOperations.createButton(message, 60, ie -> {
if (ie.getUser().getIdLong() != ctx.getAuthor().getIdLong()) {
return Operation.IGNORED;
}
Expand Down
Loading