Skip to content
This repository has been archived by the owner on Feb 10, 2024. It is now read-only.

Commit

Permalink
add(effects): make milky potion able to select specific type & remove…
Browse files Browse the repository at this point in the history
… distinction between potion/buff

add(effects): rename waifu pill -> tea and make it conditionless (this is not a final decision)
add(operations): add select menu ops
fix(equipment): potions/buffs could be equipped lol
fix(profile): buffs cmd failed if no buffs
  • Loading branch information
MrLar authored and Kodehawa committed Oct 14, 2023
1 parent f6e5418 commit 7ec9460
Show file tree
Hide file tree
Showing 20 changed files with 259 additions and 118 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,6 @@ private static void mine(IContext ctx, Player player, MongoUser dbUser, Marriage
}

var message = "";
var waifuHelp = false;
var petHelp = false;

var item = (Pickaxe) ItemHelper.fromId(equipped);
Expand All @@ -272,21 +271,16 @@ private static void mine(IContext ctx, Player player, MongoUser dbUser, Marriage
var moneyIncrease = item.getMoneyIncrease() <= 0 ? 1 : item.getMoneyIncrease();
money += Math.max(moneyIncrease / 2, random.nextInt(moneyIncrease));

if (ItemHelper.handleEffect(dbUser.getEquippedItems(), ItemReference.WAIFU_PILL, dbUser)) {
final var waifus = dbUser.waifuEntrySet();
if (waifus.stream().anyMatch((w) -> w.getValue() > 20_000L)) {
money += Math.max(20, random.nextInt(100));
waifuHelp = true;
}

var hasTea = ItemHelper.handleEffect(ItemReference.TEA, dbUser);
if (hasTea) {
money += Math.max(20, random.nextInt(100));
}

var reminder = random.nextInt(6) == 0 && item == ItemReference.BROM_PICKAXE ?
languageContext.get("commands.mine.reminder") : "";

var hasPotion = ItemHelper.handleEffect(
dbUser.getEquippedItems(),
ItemReference.POTION_HASTE, dbUser
);
var hasPotion = ItemHelper.handleEffect(ItemReference.POTION_HASTE, dbUser);

HousePet pet = null;
var activePetChoice = player.getActivePetChoice(marriage);
Expand Down Expand Up @@ -408,8 +402,8 @@ private static void mine(IContext ctx, Player player, MongoUser dbUser, Marriage
}
}

if (waifuHelp) {
message += "\n" + languageContext.get("commands.mine.waifu_help");
if (hasTea) {
message += "\n" + languageContext.get("commands.mine.tea_help");
}

player.addBadgeIfAbsent(Badge.GEM_FINDER);
Expand Down Expand Up @@ -499,7 +493,7 @@ private static void fish(IContext ctx, Player player, MongoUser dbUser, Marriage
var nominalLevel = item.getLevel() - 3;
var extraMessage = "";
var chance = random.nextInt(100);
var buff = ItemHelper.handleEffect(dbUser.getEquippedItems(), ItemReference.FISHING_BAIT, dbUser);
var buff = ItemHelper.handleEffect(ItemReference.FISHING_BAIT, dbUser);

if (buff) {
chance += 6;
Expand Down Expand Up @@ -576,15 +570,12 @@ private static void fish(IContext ctx, Player player, MongoUser dbUser, Marriage
}
}

// START OF WAIFU HELP IMPLEMENTATION
boolean waifuHelp = false;
if (ItemHelper.handleEffect(dbUser.getEquippedItems(), ItemReference.WAIFU_PILL, dbUser)) {
if (dbUser.waifuEntrySet().stream().anyMatch((w) -> w.getValue() > 20_000L)) {
money += Math.max(10, random.nextInt(150));
waifuHelp = true;
}
// START OF TEA HELP IMPLEMENTATION
var hasTea = ItemHelper.handleEffect(ItemReference.TEA, dbUser);
if (hasTea) {
money += Math.max(10, random.nextInt(150));
}
// END OF WAIFU HELP IMPLEMENTATION
// END OF TEA HELP IMPLEMENTATION

// START OF FISH LOOT CRATE HANDLING
if (random.nextInt(400) > 380) {
Expand Down Expand Up @@ -689,7 +680,7 @@ private static void fish(IContext ctx, Player player, MongoUser dbUser, Marriage
ctx.sendFormatStripped(extraMessage + "\n\n" + languageContext.get("commands.fish.success"), item.getEmojiDisplay(), itemDisplay, item.getName());
} else if (money > 0) { //there's money and fish
ctx.sendFormatStripped(extraMessage + "\n\n" + languageContext.get("commands.fish.success_money"),
item.getEmojiDisplay(), itemDisplay, money, item.getName(), (waifuHelp ? "\n" + languageContext.get("commands.fish.waifu_help") : "")
item.getEmojiDisplay(), itemDisplay, money, item.getName(), (hasTea ? "\n" + languageContext.get("commands.fish.tea_help") : "")
);
}

Expand Down Expand Up @@ -725,7 +716,7 @@ private static void chop(IContext ctx, Player player, MongoUser dbUser, Marriage
}

var chance = random.nextInt(100);
var hasPotion = ItemHelper.handleEffect(dbUser.getEquippedItems(), ItemReference.POTION_HASTE, dbUser);
var hasPotion = ItemHelper.handleEffect(ItemReference.POTION_HASTE, dbUser);

if (hasPotion) {
chance += 9;
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
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,13 @@ protected void process(SlashContext ctx) {
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 : equippedItems.getEffectListSorted()) {
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(
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@

package net.kodehawa.mantarobot.commands.currency.item;

import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.interactions.commands.Command;
import net.dv8tion.jda.api.interactions.commands.build.OptionData;
import net.dv8tion.jda.api.interactions.components.selections.StringSelectMenu;
import net.kodehawa.mantarobot.commands.currency.item.special.Broken;
import net.kodehawa.mantarobot.commands.currency.item.special.Food;
import net.kodehawa.mantarobot.commands.currency.item.special.Potion;
Expand All @@ -33,7 +35,10 @@
import net.kodehawa.mantarobot.core.command.slash.AutocompleteContext;
import net.kodehawa.mantarobot.core.command.slash.IContext;
import net.kodehawa.mantarobot.core.command.slash.SlashContext;
import net.kodehawa.mantarobot.core.listeners.operations.ComponentOperations;
import net.kodehawa.mantarobot.core.listeners.operations.core.Operation;
import net.kodehawa.mantarobot.core.modules.commands.i18n.I18nContext;
import net.kodehawa.mantarobot.data.I18n;
import net.kodehawa.mantarobot.data.MantaroData;
import net.kodehawa.mantarobot.db.entities.MongoUser;
import net.kodehawa.mantarobot.db.entities.Player;
Expand All @@ -48,6 +53,7 @@
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
Expand Down Expand Up @@ -107,16 +113,54 @@ public static void setItemActions() {
}));

ItemReference.POTION_CLEAN.setAction((ctx, season) -> {
Player player = ctx.getPlayer();
MongoUser dbUser = ctx.getDBUser();
var equipped = dbUser.getEquippedItems();
equipped.resetEffect(null);
player.processItem(ItemReference.POTION_CLEAN, -1);

player.updateAllChanged();
equipped.updateAllChanged(dbUser);
var menu = StringSelectMenu.create("milky_select")
.setRequiredRange(1, 1)
.setPlaceholder(ctx.getLanguageContext().get("general.misc_item_usage.milk.placeholder"));
var types = ctx.getDBUser().getEquippedItems().getEffectTypes();
if (types.isEmpty()) {
ctx.sendLocalized("general.misc_item_usage.milk.none_active", EmoteReference.ERROR);
return true;
}
for (var effectType : types) {
menu.addOption(
ctx.getLanguageContext().get("items.effect_types." + effectType.name().toLowerCase()),
effectType.name()
);
}
var message = ctx.sendResult(ctx.getLanguageContext().get("general.misc_item_usage.milk.header"));
ComponentOperations.createSelect(message, 60, event -> {
var selected = event.getSelectedOptions();
User user = event.getUser();
MongoUser dbUser = MantaroData.db().getUser(user);
var langContext = new I18nContext(I18n.getForLanguage(dbUser.getLang()));
if (!selected.isEmpty()) {
try {
var effectType = PotionEffectType.valueOf(selected.get(0).getValue());
Player player = MantaroData.db().getPlayer(user);
var equipped = dbUser.getEquippedItems();
equipped.resetEffect(effectType);
player.processItem(ItemReference.POTION_CLEAN, -1);

player.updateAllChanged();
equipped.updateAllChanged(dbUser);

event.getHook().editOriginal(
langContext.get("general.misc_item_usage.milk.success")
.formatted(
EmoteReference.CORRECT,
langContext.get("items.effect_types." + effectType.name().toLowerCase())
)
).setComponents().queue();
return Operation.COMPLETED;
} catch (IllegalArgumentException ignored) {}
}
event.getHook().editOriginal(
langContext.get("general.misc_item_usage.milk.invalid")
.formatted(EmoteReference.ERROR)
).setComponents().queue();
return Operation.COMPLETED;
}, Collections.singletonList(menu.build()));

ctx.sendLocalized("general.misc_item_usage.milk", EmoteReference.CORRECT);
return true;
});

Expand Down Expand Up @@ -422,8 +466,9 @@ private static List<Item> handleItemDrop(Predicate<Item> predicate, boolean norm
.collect(Collectors.toList());
}

public static boolean handleEffect(PlayerEquipment equipment, Item item, MongoUser user) {
public static boolean handleEffect(Item item, MongoUser user) {
if (!(item instanceof Potion potion)) return false;
var equipment = user.getEquippedItems();
var type = potion.getEffectType();
boolean isEffectPresent = equipment.getCurrentEffect(type) != null;

Expand Down Expand Up @@ -485,7 +530,7 @@ public static Tuple<Boolean, Player, MongoUser> handleDurability(IContext ctx, I
var equippedItems = user.getEquippedItems();
var subtractFrom = 0;

if (handleEffect(equippedItems, ItemReference.POTION_STAMINA, user)) {
if (handleEffect(ItemReference.POTION_STAMINA, user)) {
subtractFrom = random.nextInt(7);
} else {
subtractFrom = random.nextInt(10);
Expand Down
Loading

0 comments on commit 7ec9460

Please sign in to comment.