From 48b67cb10490eac95d23505b1d5afb320860488c Mon Sep 17 00:00:00 2001 From: Branson778 Date: Sun, 17 Sep 2023 16:32:22 -0700 Subject: [PATCH 01/12] Started LootTableA and menu button functionality. --- build.gradle | 2 +- .../jointheleague/discord_bot/DiscordBot.java | 6 +- .../student/third_feature/FeatureThree.java | 69 +++++++++++++++++++ .../student/third_feature/lootTableA.java | 9 +++ .../first_features/CurrentTimeTest.java | 2 +- .../first_features/RandomNumberTest.java | 2 +- .../second_features/HighLowGameTest.java | 2 +- .../third_features/CatFactsApiTest.java | 2 +- .../examples/third_features/NewsApiTest.java | 2 +- .../templates/FeatureTemplateTest.java | 2 +- 10 files changed, 89 insertions(+), 9 deletions(-) create mode 100644 src/main/java/org/jointheleague/features/student/third_feature/FeatureThree.java create mode 100644 src/main/java/org/jointheleague/features/student/third_feature/lootTableA.java diff --git a/build.gradle b/build.gradle index bee38ebc..bb3a859e 100644 --- a/build.gradle +++ b/build.gradle @@ -11,7 +11,7 @@ repositories { } dependencies { - implementation 'org.javacord:javacord:3.1.1' + implementation 'org.javacord:javacord:3.8.0' implementation 'net.aksingh:owm-japis:2.5.3.0' implementation 'com.googlecode.json-simple:json-simple:1.1.1' implementation 'javax.json:javax.json-api:1.1' diff --git a/src/main/java/org/jointheleague/discord_bot/DiscordBot.java b/src/main/java/org/jointheleague/discord_bot/DiscordBot.java index fa40f61f..5c964504 100644 --- a/src/main/java/org/jointheleague/discord_bot/DiscordBot.java +++ b/src/main/java/org/jointheleague/discord_bot/DiscordBot.java @@ -2,6 +2,7 @@ import org.javacord.api.DiscordApi; import org.javacord.api.DiscordApiBuilder; +import org.javacord.api.entity.intent.Intent; import org.jointheleague.features.abstract_classes.Feature; import org.jointheleague.features.examples.second_features.HighLowGame; import org.jointheleague.features.examples.third_features.CatFactsApi; @@ -9,6 +10,7 @@ import org.jointheleague.features.examples.first_features.CurrentTime; import org.jointheleague.features.examples.first_features.RandomNumber; import org.jointheleague.features.help_embed.HelpListener; +import org.jointheleague.features.student.third_feature.FeatureThree; public class DiscordBot { @@ -28,7 +30,7 @@ public DiscordBot(String token, String channelName) { public void connect(boolean printInvite) { - api = new DiscordApiBuilder().setToken(token).login().join(); + api = new DiscordApiBuilder().setToken(token).addIntents(Intent.MESSAGE_CONTENT).login().join(); //Print the URL to invite the bot if (printInvite) { @@ -46,7 +48,7 @@ public void connect(boolean printInvite) { addFeature(new RandomNumber(channelName)); addFeature(new CurrentTime(channelName)); addFeature(new HighLowGame(channelName)); - addFeature(new NewsApi(channelName)); + addFeature(new FeatureThree(channelName)); addFeature(new CatFactsApi(channelName)); } diff --git a/src/main/java/org/jointheleague/features/student/third_feature/FeatureThree.java b/src/main/java/org/jointheleague/features/student/third_feature/FeatureThree.java new file mode 100644 index 00000000..449d386f --- /dev/null +++ b/src/main/java/org/jointheleague/features/student/third_feature/FeatureThree.java @@ -0,0 +1,69 @@ +package org.jointheleague.features.student.third_feature; + +import org.javacord.api.DiscordApi; +import org.javacord.api.DiscordApiBuilder; +import org.javacord.api.entity.channel.ServerTextChannel; +import org.javacord.api.entity.channel.TextChannel; +import org.javacord.api.entity.message.MessageBuilder; +import org.javacord.api.entity.message.component.ActionRow; +import org.javacord.api.entity.message.component.Button; +import org.javacord.api.event.interaction.MessageComponentCreateEvent; +import org.javacord.api.event.message.MessageCreateEvent; +import org.javacord.api.interaction.MessageComponentInteraction; +import org.javacord.api.listener.interaction.MessageComponentCreateListener; +import org.jointheleague.discord_bot.DiscordBot; +import org.jointheleague.features.abstract_classes.Feature; +import org.jointheleague.features.help_embed.plain_old_java_objects.help_embed.HelpEmbed; +import org.jointheleague.features.templates.FeatureTemplate; + +public class FeatureThree extends FeatureTemplate { + public final String COMMAND = "!fish"; + + TextChannel channel; + public double money = 0; + + + + public FeatureThree(String channelName) { + super(channelName); + + //Create a help embed to describe feature when !help command is sent + helpEmbed = new HelpEmbed( + COMMAND, + "A luck based fishing game with lots of fish, sizes of fish, qualities of fish, upgrades, and more. If new to !\u200Efish, please start with !\u200Efish tutorial. REMEMBER TO ADD A SAVING FEATURE TO ADD A TEXT KEY TO RESTORE PROGRESS" + ); + } + + @Override + public void handle(MessageCreateEvent event) { + channel = event.getChannel(); + String messageContent = event.getMessageContent(); + if (messageContent.equals(COMMAND) || messageContent.equalsIgnoreCase(COMMAND+" tutorial")) { + //respond to message here + event.getChannel().sendMessage("Welcome to !\u200Efish. In this game you will fish, like the name implies. You will continue to fish and gain money. With this money you can upgrade you rod, luck, hook, bait, et cetera. With all of this you should get new better fish. This journey begins the command !\u200Efish menu \nFish Size Value Multiplication Chart: PLACEHOLDER \nRarity Value Multiplication Chart: PLACEHOLDER \n*BETA TUTORIAL*"); + } + else if (messageContent.equalsIgnoreCase(COMMAND + " menu")){ + // event.getChannel().sendMessage("Message to test whether TextChannel broke again."); + new MessageBuilder().setContent("Current Money: " + money+" | Current Location: PLACEHOLDER | Luck Modifier: PLACEHOLDER").addComponents(ActionRow.of(Button.success("fish", "Go Fishing"),Button.secondary("modify", "Modify Set-Up"),Button.secondary("save", "Save Game"))).send(channel); + event.getApi().addMessageComponentCreateListener(event2 -> { + MessageComponentInteraction mci = event2.getMessageComponentInteraction(); + String cID = mci.getCustomId(); + + switch(cID){ + case "fish": + + event.getChannel().sendMessage("FISHING"); + break; + case "modify": + event.getChannel().sendMessage("CHANGING"); + break; + case "save" : + event.getChannel().sendMessage("SAVING"); + break; + } + + + }); + } + } +} diff --git a/src/main/java/org/jointheleague/features/student/third_feature/lootTableA.java b/src/main/java/org/jointheleague/features/student/third_feature/lootTableA.java new file mode 100644 index 00000000..0a5561c0 --- /dev/null +++ b/src/main/java/org/jointheleague/features/student/third_feature/lootTableA.java @@ -0,0 +1,9 @@ +package org.jointheleague.features.student.third_feature; + +public enum lootTableA { + Sardine(10),SeaBass(7.5),Tuna(7),Squid(3.5),Striper(6),Lobster(1.75); + + lootTableA(double weightOrChanceOfGettingFish) { + + } +} diff --git a/src/test/java/org/jointheleague/features/examples/first_features/CurrentTimeTest.java b/src/test/java/org/jointheleague/features/examples/first_features/CurrentTimeTest.java index 7b2cccad..e25f7b25 100644 --- a/src/test/java/org/jointheleague/features/examples/first_features/CurrentTimeTest.java +++ b/src/test/java/org/jointheleague/features/examples/first_features/CurrentTimeTest.java @@ -82,7 +82,7 @@ void itShouldNotHandleMessagesWithoutCommand() { currentTime.handle(messageCreateEvent); //Then - verify(textChannel, never()).sendMessage(); + verify(textChannel, never()).sendMessage(""); } @Test diff --git a/src/test/java/org/jointheleague/features/examples/first_features/RandomNumberTest.java b/src/test/java/org/jointheleague/features/examples/first_features/RandomNumberTest.java index 1b84ccb3..956f2b60 100644 --- a/src/test/java/org/jointheleague/features/examples/first_features/RandomNumberTest.java +++ b/src/test/java/org/jointheleague/features/examples/first_features/RandomNumberTest.java @@ -81,7 +81,7 @@ void itShouldNotHandleMessagesWithoutCommand() { randomNumber.handle(messageCreateEvent); //Then - verify(textChannel, never()).sendMessage(); + verify(textChannel, never()).sendMessage(""); } @Test diff --git a/src/test/java/org/jointheleague/features/examples/second_features/HighLowGameTest.java b/src/test/java/org/jointheleague/features/examples/second_features/HighLowGameTest.java index f67c50f7..3874bcad 100644 --- a/src/test/java/org/jointheleague/features/examples/second_features/HighLowGameTest.java +++ b/src/test/java/org/jointheleague/features/examples/second_features/HighLowGameTest.java @@ -82,7 +82,7 @@ void itShouldNotHandleMessagesWithoutCommand() { highLowGame.handle(messageCreateEvent); //Then - verify(textChannel, never()).sendMessage(); + verify(textChannel, never()).sendMessage(""); } @Test diff --git a/src/test/java/org/jointheleague/features/examples/third_features/CatFactsApiTest.java b/src/test/java/org/jointheleague/features/examples/third_features/CatFactsApiTest.java index 31eec24f..6590d6b8 100644 --- a/src/test/java/org/jointheleague/features/examples/third_features/CatFactsApiTest.java +++ b/src/test/java/org/jointheleague/features/examples/third_features/CatFactsApiTest.java @@ -150,7 +150,7 @@ void givenMessageWithoutCommand_whenHandle_thenDoNothing() { catFactsApi.handle(messageCreateEvent); //Then - verify(textChannel, never()).sendMessage(); + verify(textChannel, never()).sendMessage(""); } } \ No newline at end of file diff --git a/src/test/java/org/jointheleague/features/examples/third_features/NewsApiTest.java b/src/test/java/org/jointheleague/features/examples/third_features/NewsApiTest.java index a8bd08fe..44f9c744 100644 --- a/src/test/java/org/jointheleague/features/examples/third_features/NewsApiTest.java +++ b/src/test/java/org/jointheleague/features/examples/third_features/NewsApiTest.java @@ -178,7 +178,7 @@ void givenMessageWithoutCommand_whenHandle_thenDoNothing() { newsApi.handle(messageCreateEvent); //Then - verify(textChannel, never()).sendMessage(); + verify(textChannel, never()).sendMessage(""); } } \ No newline at end of file diff --git a/src/test/java/org/jointheleague/features/templates/FeatureTemplateTest.java b/src/test/java/org/jointheleague/features/templates/FeatureTemplateTest.java index 8d4ef733..f40ad152 100644 --- a/src/test/java/org/jointheleague/features/templates/FeatureTemplateTest.java +++ b/src/test/java/org/jointheleague/features/templates/FeatureTemplateTest.java @@ -92,7 +92,7 @@ void itShouldNotHandleMessagesWithoutCommand() { featureTemplate.handle(messageCreateEvent); //Then - verify(textChannel, never()).sendMessage(); + verify(textChannel, never()).sendMessage(""); } @Test From 7f6b017df3c2174f719650a48bb7b38cefd1dbc9 Mon Sep 17 00:00:00 2001 From: Branson778 Date: Sun, 24 Sep 2023 16:26:16 -0700 Subject: [PATCH 02/12] Finished basic weighted loot system. --- .../student/third_feature/FeatureThree.java | 51 +++++++++++++++++-- .../student/third_feature/lootTableA.java | 15 +++++- 2 files changed, 61 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/jointheleague/features/student/third_feature/FeatureThree.java b/src/main/java/org/jointheleague/features/student/third_feature/FeatureThree.java index 449d386f..55cc83d2 100644 --- a/src/main/java/org/jointheleague/features/student/third_feature/FeatureThree.java +++ b/src/main/java/org/jointheleague/features/student/third_feature/FeatureThree.java @@ -16,6 +16,8 @@ import org.jointheleague.features.help_embed.plain_old_java_objects.help_embed.HelpEmbed; import org.jointheleague.features.templates.FeatureTemplate; +import java.util.Random; + public class FeatureThree extends FeatureTemplate { public final String COMMAND = "!fish"; @@ -44,15 +46,20 @@ public void handle(MessageCreateEvent event) { } else if (messageContent.equalsIgnoreCase(COMMAND + " menu")){ // event.getChannel().sendMessage("Message to test whether TextChannel broke again."); - new MessageBuilder().setContent("Current Money: " + money+" | Current Location: PLACEHOLDER | Luck Modifier: PLACEHOLDER").addComponents(ActionRow.of(Button.success("fish", "Go Fishing"),Button.secondary("modify", "Modify Set-Up"),Button.secondary("save", "Save Game"))).send(channel); + new MessageBuilder().setContent("Current Money: $" + money+" | Current Location: PLACEHOLDER | Luck Modifier: PLACEHOLDER").addComponents(ActionRow.of(Button.success("fish", "Go Fishing"),Button.secondary("modify", "Modify Set-Up"),Button.secondary("save", "Save Game"))).send(channel); event.getApi().addMessageComponentCreateListener(event2 -> { MessageComponentInteraction mci = event2.getMessageComponentInteraction(); String cID = mci.getCustomId(); switch(cID){ case "fish": - - event.getChannel().sendMessage("FISHING"); + event.getChannel().sendMessage("Going fishing..."); + randomFish("Sea", event); + randomFish("Sea", event); + randomFish("Sea", event); + randomFish("Sea", event); + randomFish("Sea", event); + randomFish("Sea", event); break; case "modify": event.getChannel().sendMessage("CHANGING"); @@ -66,4 +73,42 @@ else if (messageContent.equalsIgnoreCase(COMMAND + " menu")){ }); } } + + public void setMoney(double money) { + this.money = money; + } + + public void addMoney(double money) { + this.money = this.money + money; + } + public void randomFish(String location, MessageCreateEvent event){ + Random random = new Random(); + lootTableA[] list = lootTableA.values(); + double totalWeight = 0.0; + double ran; + lootTableA lt = lootTableA.Sardine; + if(location.equals("Sea")){ + for(int i =0; i < list.length; i++){ + totalWeight = totalWeight + list[i].getChance(); + } + ran = random.nextDouble(totalWeight); + totalWeight =0; + for(int i =0; i < list.length; i++){ + totalWeight = totalWeight + list[i].getChance(); + if(totalWeight>ran){ + lt = list[i]; + break; + } + + } + event.getChannel().sendMessage(" You caught a "+lt.name() + "!"); + addMoney(lt.getValue()); + event.getChannel().sendMessage("You sold this fish for $"+lt.getValue()+" | Your bank account is now at $" + money); + + + + } + } + + } diff --git a/src/main/java/org/jointheleague/features/student/third_feature/lootTableA.java b/src/main/java/org/jointheleague/features/student/third_feature/lootTableA.java index 0a5561c0..87d1152a 100644 --- a/src/main/java/org/jointheleague/features/student/third_feature/lootTableA.java +++ b/src/main/java/org/jointheleague/features/student/third_feature/lootTableA.java @@ -1,9 +1,20 @@ package org.jointheleague.features.student.third_feature; public enum lootTableA { - Sardine(10),SeaBass(7.5),Tuna(7),Squid(3.5),Striper(6),Lobster(1.75); - lootTableA(double weightOrChanceOfGettingFish) { + Sardine(32.5, 3),SeaBass(9, 7),Tuna(15.5, 6.5),Squid(3.5, 30),Striper(6.25, 12.5),Lobster(1.75, 35); + double value; + double weightOrChanceOfGettingFish; + lootTableA(double weightOrChanceOfGettingFish, double value) { + this.weightOrChanceOfGettingFish=weightOrChanceOfGettingFish; + this.value = value; + } + + public double getValue() { + return value; + } + public double getChance() { + return weightOrChanceOfGettingFish; } } From 8b6b04054cd785a0e23023090911f1698578f3de Mon Sep 17 00:00:00 2001 From: Branson778 Date: Mon, 25 Sep 2023 19:51:32 -0700 Subject: [PATCH 03/12] Finished basic upgrade framework --- .../student/third_feature/FeatureThree.java | 95 ++++++++++++++++--- 1 file changed, 83 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/jointheleague/features/student/third_feature/FeatureThree.java b/src/main/java/org/jointheleague/features/student/third_feature/FeatureThree.java index 55cc83d2..66c1fdc6 100644 --- a/src/main/java/org/jointheleague/features/student/third_feature/FeatureThree.java +++ b/src/main/java/org/jointheleague/features/student/third_feature/FeatureThree.java @@ -23,6 +23,8 @@ public class FeatureThree extends FeatureTemplate { TextChannel channel; public double money = 0; + public double luckModifier = 0.00; + String location = "Sea"; @@ -46,7 +48,7 @@ public void handle(MessageCreateEvent event) { } else if (messageContent.equalsIgnoreCase(COMMAND + " menu")){ // event.getChannel().sendMessage("Message to test whether TextChannel broke again."); - new MessageBuilder().setContent("Current Money: $" + money+" | Current Location: PLACEHOLDER | Luck Modifier: PLACEHOLDER").addComponents(ActionRow.of(Button.success("fish", "Go Fishing"),Button.secondary("modify", "Modify Set-Up"),Button.secondary("save", "Save Game"))).send(channel); + new MessageBuilder().setContent("| Current Money: $" + money+" | Current Location: "+location+" | Luck Modifier: +" + luckModifier/5+" points |").addComponents(ActionRow.of(Button.success("fish", "Go Fishing"),Button.secondary("modify", "Modify Set-Up"),Button.secondary("save", "Save Game"))).send(channel); event.getApi().addMessageComponentCreateListener(event2 -> { MessageComponentInteraction mci = event2.getMessageComponentInteraction(); String cID = mci.getCustomId(); @@ -54,15 +56,15 @@ else if (messageContent.equalsIgnoreCase(COMMAND + " menu")){ switch(cID){ case "fish": event.getChannel().sendMessage("Going fishing..."); - randomFish("Sea", event); - randomFish("Sea", event); - randomFish("Sea", event); - randomFish("Sea", event); - randomFish("Sea", event); - randomFish("Sea", event); + randomFish(location, event); + randomFish(location, event); + randomFish(location, event); + randomFish(location, event); + randomFish(location, event); + randomFish(location, event); break; case "modify": - event.getChannel().sendMessage("CHANGING"); + setupModification(event); break; case "save" : event.getChannel().sendMessage("SAVING"); @@ -72,6 +74,10 @@ else if (messageContent.equalsIgnoreCase(COMMAND + " menu")){ }); } + else if(messageContent.equals(COMMAND + " testMoney")){ + money = money + 10000000; + luckModifier = luckModifier + 21354.5; + } } public void setMoney(double money) { @@ -95,20 +101,85 @@ public void randomFish(String location, MessageCreateEvent event){ totalWeight =0; for(int i =0; i < list.length; i++){ totalWeight = totalWeight + list[i].getChance(); - if(totalWeight>ran){ + if(totalWeight>ran){ //test luck addition system lt = list[i]; break; } } - event.getChannel().sendMessage(" You caught a "+lt.name() + "!"); addMoney(lt.getValue()); - event.getChannel().sendMessage("You sold this fish for $"+lt.getValue()+" | Your bank account is now at $" + money); + event.getChannel().sendMessage(" You caught a "+lt.name() + "! "+"| You sold this fish for $"+lt.getValue()+" | Your bank account is now at $" + money); } } + public void setupModification(MessageCreateEvent event){ + new MessageBuilder().setContent("What would you like to modify in your set-up?").addComponents(ActionRow.of(Button.success("upgrade", "Buy Upgrades"),Button.success("location", "Change Location"), Button.danger("leave", "Cancel"))).send(channel); + event.getApi().addMessageComponentCreateListener(event2 -> { + MessageComponentInteraction mci = event2.getMessageComponentInteraction(); + String cID = mci.getCustomId(); + + switch(cID){ + case "upgrade": + upgradeMenu(event); + break; + case "location": + break; + case "leave": + //clear old message here + event.getChannel().sendMessage("Cancelling modification menu. Please go back to !fish menu."); + break; + default: + break; + } + }); + } + public void upgradeMenu(MessageCreateEvent event) { + new MessageBuilder().setContent("What would you like to buy").addComponents(ActionRow.of(Button.success("0", "Carbon Fibre Rod | $125.25"), Button.success("1", "Deep-Dive Lure | $35.50"), Button.danger("2", "Better Boat Service | $1250.75"))).send(channel); + event.getApi().addMessageComponentCreateListener(event2 -> { + MessageComponentInteraction mci = event2.getMessageComponentInteraction(); + String cID = mci.getCustomId(); + //add system to stop purchasing multiple plus a buy message. + switch (cID) { + case "0": + if(money>=125.25) { + money = money - 125.25; + luckModifier = luckModifier + 25; + event.getChannel().sendMessage("Congrats, you now own a carbon fibre fishing rod!"); + } + else{ + event.getChannel().sendMessage("You cannot afford this item."); + } + break; + case "1": + if(money>=35.50) { + money = money - 35.50; + luckModifier = luckModifier + 5.75; + event.getChannel().sendMessage("Congrats, you now own a deep-dive lure!"); + } + else{ + event.getChannel().sendMessage("You cannot afford this item."); + } + break; + case "2": + if(money>=1250.75) { + money = money - 1250.75; + luckModifier = luckModifier + 12.5; + event.getChannel().sendMessage("Congrats, you now have a better boat service!"); + //new location available + } + else{ + event.getChannel().sendMessage("You cannot afford this item."); + } + break; + } + }); + } + } + + + + -} From 37d6adf088c6f59652b4035409eb10bb05069487 Mon Sep 17 00:00:00 2001 From: Branson778 Date: Sun, 1 Oct 2023 16:25:51 -0700 Subject: [PATCH 04/12] Finished basic location swapping and upgrade limits. --- .../student/third_feature/FeatureThree.java | 74 +++++++++++++++---- 1 file changed, 59 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/jointheleague/features/student/third_feature/FeatureThree.java b/src/main/java/org/jointheleague/features/student/third_feature/FeatureThree.java index 66c1fdc6..2aec0a9a 100644 --- a/src/main/java/org/jointheleague/features/student/third_feature/FeatureThree.java +++ b/src/main/java/org/jointheleague/features/student/third_feature/FeatureThree.java @@ -7,6 +7,8 @@ import org.javacord.api.entity.message.MessageBuilder; import org.javacord.api.entity.message.component.ActionRow; import org.javacord.api.entity.message.component.Button; +import org.javacord.api.entity.message.component.SelectMenu; +import org.javacord.api.entity.message.component.SelectMenuOption; import org.javacord.api.event.interaction.MessageComponentCreateEvent; import org.javacord.api.event.message.MessageCreateEvent; import org.javacord.api.interaction.MessageComponentInteraction; @@ -16,6 +18,8 @@ import org.jointheleague.features.help_embed.plain_old_java_objects.help_embed.HelpEmbed; import org.jointheleague.features.templates.FeatureTemplate; +import java.util.ArrayList; +import java.util.List; import java.util.Random; public class FeatureThree extends FeatureTemplate { @@ -24,7 +28,10 @@ public class FeatureThree extends FeatureTemplate { TextChannel channel; public double money = 0; public double luckModifier = 0.00; - String location = "Sea"; + public String location = "Sea"; + public boolean[] bought = new boolean[3]; //Number in boolean is the total number of upgrades at the current moment. + public List locations = new ArrayList(); + @@ -36,6 +43,7 @@ public FeatureThree(String channelName) { COMMAND, "A luck based fishing game with lots of fish, sizes of fish, qualities of fish, upgrades, and more. If new to !\u200Efish, please start with !\u200Efish tutorial. REMEMBER TO ADD A SAVING FEATURE TO ADD A TEXT KEY TO RESTORE PROGRESS" ); + locations.add(location); } @Override @@ -105,13 +113,9 @@ public void randomFish(String location, MessageCreateEvent event){ lt = list[i]; break; } - } addMoney(lt.getValue()); event.getChannel().sendMessage(" You caught a "+lt.name() + "! "+"| You sold this fish for $"+lt.getValue()+" | Your bank account is now at $" + money); - - - } } @@ -126,6 +130,7 @@ public void setupModification(MessageCreateEvent event){ upgradeMenu(event); break; case "location": + changeLocation(event); break; case "leave": //clear old message here @@ -137,45 +142,84 @@ public void setupModification(MessageCreateEvent event){ }); } public void upgradeMenu(MessageCreateEvent event) { - new MessageBuilder().setContent("What would you like to buy").addComponents(ActionRow.of(Button.success("0", "Carbon Fibre Rod | $125.25"), Button.success("1", "Deep-Dive Lure | $35.50"), Button.danger("2", "Better Boat Service | $1250.75"))).send(channel); + new MessageBuilder().setContent("What would you like to buy").addComponents(ActionRow.of(Button.secondary("0", "Carbon Fibre Rod | $125.25"), Button.secondary("1", "Deep-Dive Lure | $35.50"), Button.secondary("2", "Better Boat Service | $1250.75"))).send(channel); event.getApi().addMessageComponentCreateListener(event2 -> { MessageComponentInteraction mci = event2.getMessageComponentInteraction(); String cID = mci.getCustomId(); //add system to stop purchasing multiple plus a buy message. switch (cID) { case "0": - if(money>=125.25) { + if(money>=125.25 && !bought[0]) { money = money - 125.25; luckModifier = luckModifier + 25; - event.getChannel().sendMessage("Congrats, you now own a carbon fibre fishing rod!"); + event.getChannel().sendMessage("Congrats, you now own a carbon fibre fishing rod! This upgrades increases your luck."); + bought[0] = true; } - else{ + else if(money<125.25 && !bought[0]){ event.getChannel().sendMessage("You cannot afford this item."); } + else{ + event.getChannel().sendMessage("You cannot buy an item you already have."); + } break; case "1": - if(money>=35.50) { + if(money>=35.50 && !bought[1]) { money = money - 35.50; luckModifier = luckModifier + 5.75; - event.getChannel().sendMessage("Congrats, you now own a deep-dive lure!"); + event.getChannel().sendMessage("Congrats, you now own a deep-dive lure! This upgrades slightly increases your luck."); + bought[1] = true; } - else{ + else if(money<35.50 && !bought[1]){ event.getChannel().sendMessage("You cannot afford this item."); } + else{ + event.getChannel().sendMessage("You cannot buy an item you already have."); + } break; case "2": - if(money>=1250.75) { + if(money>=1250.75 && !bought[2]) { money = money - 1250.75; luckModifier = luckModifier + 12.5; - event.getChannel().sendMessage("Congrats, you now have a better boat service!"); + event.getChannel().sendMessage("Congrats, you now have a better boat service! This upgrades slightly increases your luck and allows you to travel to a new location, the trench."); + bought[2] = true; + locations.add("Trench"); //new location available } - else{ + else if(money<1250.75 && !bought[2]){ event.getChannel().sendMessage("You cannot afford this item."); } + else{ + event.getChannel().sendMessage("You cannot buy an item you already have."); + } break; } }); + } + public void changeLocation (MessageCreateEvent event){ + List temp = new ArrayList(); + //for(int i=0; i < locations.size(); i++){ + //temp.add(SelectMenuOption.create(locations.get(i), "Click here to travel to " + locations.get(i))); + // } + MessageBuilder mb = new MessageBuilder(); + //SelectMenu menu = SelectMenu.createStringMenu("locationSelect", temp); + mb.setContent("Choose Your New Location"); + for(int i =0; i < locations.size(); i++){ + mb.addComponents(ActionRow.of(Button.secondary(locations.get(i),locations.get(i)))); + } + mb.send(channel); + event.getApi().addMessageComponentCreateListener(event2 -> { + MessageComponentInteraction mci = event2.getMessageComponentInteraction(); + String cID = mci.getCustomId(); + switch(cID){ + case "Sea": + location = "Sea"; + break; + case "Trench": + location = "Trench"; + break; + } + }); + } } From ffd5cd748eedd981b8aed82cf7aba08db9af9e4b Mon Sep 17 00:00:00 2001 From: Branson778 Date: Sun, 8 Oct 2023 16:25:35 -0700 Subject: [PATCH 05/12] Fixed having too many listeners and updated loot tables. --- .../student/third_feature/FeatureThree.java | 34 ++++++++++++------- .../student/third_feature/lootTableA.java | 2 +- .../student/third_feature/lootTableB.java | 19 +++++++++++ 3 files changed, 41 insertions(+), 14 deletions(-) create mode 100644 src/main/java/org/jointheleague/features/student/third_feature/lootTableB.java diff --git a/src/main/java/org/jointheleague/features/student/third_feature/FeatureThree.java b/src/main/java/org/jointheleague/features/student/third_feature/FeatureThree.java index 2aec0a9a..53241161 100644 --- a/src/main/java/org/jointheleague/features/student/third_feature/FeatureThree.java +++ b/src/main/java/org/jointheleague/features/student/third_feature/FeatureThree.java @@ -13,6 +13,7 @@ import org.javacord.api.event.message.MessageCreateEvent; import org.javacord.api.interaction.MessageComponentInteraction; import org.javacord.api.listener.interaction.MessageComponentCreateListener; +import org.javacord.api.util.event.ListenerManager; import org.jointheleague.discord_bot.DiscordBot; import org.jointheleague.features.abstract_classes.Feature; import org.jointheleague.features.help_embed.plain_old_java_objects.help_embed.HelpEmbed; @@ -21,6 +22,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Random; +import java.util.concurrent.TimeUnit; public class FeatureThree extends FeatureTemplate { public final String COMMAND = "!fish"; @@ -32,6 +34,8 @@ public class FeatureThree extends FeatureTemplate { public boolean[] bought = new boolean[3]; //Number in boolean is the total number of upgrades at the current moment. public List locations = new ArrayList(); + ArrayList> lm = new ArrayList>(); + @@ -44,6 +48,7 @@ public FeatureThree(String channelName) { "A luck based fishing game with lots of fish, sizes of fish, qualities of fish, upgrades, and more. If new to !\u200Efish, please start with !\u200Efish tutorial. REMEMBER TO ADD A SAVING FEATURE TO ADD A TEXT KEY TO RESTORE PROGRESS" ); locations.add(location); + } @Override @@ -57,7 +62,10 @@ public void handle(MessageCreateEvent event) { else if (messageContent.equalsIgnoreCase(COMMAND + " menu")){ // event.getChannel().sendMessage("Message to test whether TextChannel broke again."); new MessageBuilder().setContent("| Current Money: $" + money+" | Current Location: "+location+" | Luck Modifier: +" + luckModifier/5+" points |").addComponents(ActionRow.of(Button.success("fish", "Go Fishing"),Button.secondary("modify", "Modify Set-Up"),Button.secondary("save", "Save Game"))).send(channel); - event.getApi().addMessageComponentCreateListener(event2 -> { + for (ListenerManager i: lm){ + i.remove(); + } + lm.add(event.getApi().addMessageComponentCreateListener(event2 -> { MessageComponentInteraction mci = event2.getMessageComponentInteraction(); String cID = mci.getCustomId(); @@ -80,7 +88,7 @@ else if (messageContent.equalsIgnoreCase(COMMAND + " menu")){ } - }); + })); } else if(messageContent.equals(COMMAND + " testMoney")){ money = money + 10000000; @@ -109,10 +117,10 @@ public void randomFish(String location, MessageCreateEvent event){ totalWeight =0; for(int i =0; i < list.length; i++){ totalWeight = totalWeight + list[i].getChance(); - if(totalWeight>ran){ //test luck addition system - lt = list[i]; - break; - } + //if(totalWeight>ran){ //test luck addition system + // lt = list[i]; + // break; + // } } addMoney(lt.getValue()); event.getChannel().sendMessage(" You caught a "+lt.name() + "! "+"| You sold this fish for $"+lt.getValue()+" | Your bank account is now at $" + money); @@ -121,7 +129,7 @@ public void randomFish(String location, MessageCreateEvent event){ public void setupModification(MessageCreateEvent event){ new MessageBuilder().setContent("What would you like to modify in your set-up?").addComponents(ActionRow.of(Button.success("upgrade", "Buy Upgrades"),Button.success("location", "Change Location"), Button.danger("leave", "Cancel"))).send(channel); - event.getApi().addMessageComponentCreateListener(event2 -> { + lm.add(event.getApi().addMessageComponentCreateListener(event2 -> { MessageComponentInteraction mci = event2.getMessageComponentInteraction(); String cID = mci.getCustomId(); @@ -139,11 +147,11 @@ public void setupModification(MessageCreateEvent event){ default: break; } - }); + })); } public void upgradeMenu(MessageCreateEvent event) { new MessageBuilder().setContent("What would you like to buy").addComponents(ActionRow.of(Button.secondary("0", "Carbon Fibre Rod | $125.25"), Button.secondary("1", "Deep-Dive Lure | $35.50"), Button.secondary("2", "Better Boat Service | $1250.75"))).send(channel); - event.getApi().addMessageComponentCreateListener(event2 -> { + lm.add(event.getApi().addMessageComponentCreateListener(event2 -> { MessageComponentInteraction mci = event2.getMessageComponentInteraction(); String cID = mci.getCustomId(); //add system to stop purchasing multiple plus a buy message. @@ -193,7 +201,7 @@ else if(money<1250.75 && !bought[2]){ } break; } - }); + })); } public void changeLocation (MessageCreateEvent event){ List temp = new ArrayList(); @@ -207,7 +215,7 @@ public void changeLocation (MessageCreateEvent event){ mb.addComponents(ActionRow.of(Button.secondary(locations.get(i),locations.get(i)))); } mb.send(channel); - event.getApi().addMessageComponentCreateListener(event2 -> { + lm.add(event.getApi().addMessageComponentCreateListener(event2 -> { MessageComponentInteraction mci = event2.getMessageComponentInteraction(); String cID = mci.getCustomId(); switch(cID){ @@ -218,8 +226,8 @@ public void changeLocation (MessageCreateEvent event){ location = "Trench"; break; } - }); - + })); + event.getApi().removeListener(MessageComponentCreateListener.class, null); } } diff --git a/src/main/java/org/jointheleague/features/student/third_feature/lootTableA.java b/src/main/java/org/jointheleague/features/student/third_feature/lootTableA.java index 87d1152a..0d424f64 100644 --- a/src/main/java/org/jointheleague/features/student/third_feature/lootTableA.java +++ b/src/main/java/org/jointheleague/features/student/third_feature/lootTableA.java @@ -2,7 +2,7 @@ public enum lootTableA { - Sardine(32.5, 3),SeaBass(9, 7),Tuna(15.5, 6.5),Squid(3.5, 30),Striper(6.25, 12.5),Lobster(1.75, 35); + Minnow(35.7525,4),Sardine(32.5, 7),SeaBass(9, 16),Tuna(15.5, 12.5),ReefShark(12.5, 13.5),Squid(3.5, 75),TriggerFish(5,45),ElectricEel(2.25,115),Striper(6.25, 25),Lobster(1.75, 145),Swordfish(0.975,160),Sunfish(0.675,235),GoldMinnowStatue(0.00565,127500); double value; double weightOrChanceOfGettingFish; lootTableA(double weightOrChanceOfGettingFish, double value) { diff --git a/src/main/java/org/jointheleague/features/student/third_feature/lootTableB.java b/src/main/java/org/jointheleague/features/student/third_feature/lootTableB.java new file mode 100644 index 00000000..8a553054 --- /dev/null +++ b/src/main/java/org/jointheleague/features/student/third_feature/lootTableB.java @@ -0,0 +1,19 @@ +package org.jointheleague.features.student.third_feature; + +public enum lootTableB { + Angler(15.125,40),; + double value; + double weightOrChanceOfGettingFish; + lootTableB(double weightOrChanceOfGettingFish, double value) { + this.weightOrChanceOfGettingFish=weightOrChanceOfGettingFish; + this.value = value; + } + + public double getValue() { + return value; + } + + public double getChance() { + return weightOrChanceOfGettingFish; + } +} From 4384f085686e67ec9dbe1fa2d1edd8987af10076 Mon Sep 17 00:00:00 2001 From: Branson778 Date: Sun, 22 Oct 2023 16:29:47 -0700 Subject: [PATCH 06/12] Implemented luck modifier and size system. --- .../student/third_feature/FeatureThree.java | 99 +++++++++++++++---- .../student/third_feature/lootTableA.java | 10 +- .../student/third_feature/lootTableB.java | 38 ++++++- 3 files changed, 124 insertions(+), 23 deletions(-) diff --git a/src/main/java/org/jointheleague/features/student/third_feature/FeatureThree.java b/src/main/java/org/jointheleague/features/student/third_feature/FeatureThree.java index 53241161..8dba3e64 100644 --- a/src/main/java/org/jointheleague/features/student/third_feature/FeatureThree.java +++ b/src/main/java/org/jointheleague/features/student/third_feature/FeatureThree.java @@ -92,7 +92,7 @@ else if (messageContent.equalsIgnoreCase(COMMAND + " menu")){ } else if(messageContent.equals(COMMAND + " testMoney")){ money = money + 10000000; - luckModifier = luckModifier + 21354.5; + luckModifier = luckModifier + 2135450; } } @@ -103,30 +103,93 @@ public void setMoney(double money) { public void addMoney(double money) { this.money = this.money + money; } - public void randomFish(String location, MessageCreateEvent event){ + public void randomFish(String location, MessageCreateEvent event) { Random random = new Random(); - lootTableA[] list = lootTableA.values(); + //lootTableA[] list; + // = new lootTableA[20] double totalWeight = 0.0; double ran; - lootTableA lt = lootTableA.Sardine; - if(location.equals("Sea")){ - for(int i =0; i < list.length; i++){ - totalWeight = totalWeight + list[i].getChance(); - } + lootTableA lt = new lootTableA(0,0,"0"); + if (location.equals("Sea")) { + lootTableA[] list = {new lootTableA(35.7525,4,"Minnow"),new lootTableA(32.5,7,"Sardine"),new lootTableA(9,16,"Sea Bass"),new lootTableA(15.5,12.5,"Tuna"),new lootTableA(12.5,13.5,"Reef Shark"),new lootTableA(3.5,75,"Squid"),new lootTableA(5,45,"Triggerfish"),new lootTableA(2.25,115,"Electric Eel"),new lootTableA(6.25,25,"Striper"),new lootTableA(1.75,145,"Lobster"),new lootTableA(0.975,160,"Swordfish"),new lootTableA(0.675,235,"Sunfish"),new lootTableA(0.0125,126500,"Walking Minnow"),new lootTableA(0.00565,127500,"Gold Minnow Statue")}; + lootAssigning(totalWeight, event, lt, list); + /* for (int i = 0; i < list.length; i++) { + totalWeight = totalWeight + list[i].getChance(); + } + ran = random.nextDouble(totalWeight); + totalWeight = 0; + for (int i = 0; i < list.length; i++) { + totalWeight = totalWeight + list[i].getChance(); + //if(totalWeight>ran){ //test luck addition system + // lt = list[i]; + // break; + // } + } + addMoney(lt.getValue()); + event.getChannel().sendMessage(" You caught a " + lt.name() + "! " + "| You sold this fish for $" + lt.getValue() + " | Your bank account is now at $" + money); */ + } else if (location.equals("Trench")) { + lootTableA[] list = {new lootTableA(25.65,35,"Telescopefish"),new lootTableA(20.2575,40,"Rhinochimaera"),new lootTableA(15.125,55,"Anglerfish"),new lootTableA(12.25751,60,"Barreleye"),new lootTableA(11.524575,70,"Lanternfish"),new lootTableA(10.2575,75,"Glowing Minnow"),new lootTableA(8.7525,90,"Flying Minnow"),new lootTableA(5.245,125,"Abyssal Grenadier"),new lootTableA(5.65,120,"Marine Hatchetfish"),new lootTableA(2.5,165,"Goblin Shark"),new lootTableA(1.15, 225,"Jellyfish"),new lootTableA(0.75, 345, "Six-Gilled Shark"),new lootTableA(0.000125,35000000,"Snailfish")}; + lootAssigning(totalWeight, event, lt, list); + /* lt2 = lootTableB.Telescopefish; + for(int i =0; i < list2.length; i++){ + totalWeight = totalWeight + list2[i].getChance(); + } ran = random.nextDouble(totalWeight); - totalWeight =0; - for(int i =0; i < list.length; i++){ - totalWeight = totalWeight + list[i].getChance(); - //if(totalWeight>ran){ //test luck addition system - // lt = list[i]; - // break; - // } - } - addMoney(lt.getValue()); - event.getChannel().sendMessage(" You caught a "+lt.name() + "! "+"| You sold this fish for $"+lt.getValue()+" | Your bank account is now at $" + money); + totalWeight =0; + for(int i =0; i < list2.length; i++){ + totalWeight = totalWeight + list2[i].getChance(); + //if(totalWeight>ran){ //test luck addition system + // lt = list[i]; + // break; + // } + } + addMoney(lt2.getValue()); + event.getChannel().sendMessage(" You caught a "+lt2.name() + "! "+"| You sold this fish for $"+lt2.getValue()+" | Your bank account is now at $" + money); + }*/ + } + } + +public void lootAssigning(double totalWeight, MessageCreateEvent event,lootTableA lt,lootTableA[] list){ + lootTableB[] list2 = {new lootTableB(0.00125,0.01, "Sub-Atomic", "🥇"),new lootTableB(0.25, 0.1, "Mircoscopic", "🥈"), new lootTableB(1,0.125,"Miniature","🥉"),new lootTableB(10,0.75,"Tiny","🏅"),new lootTableB(25.75,1,"Small","🏅"),new lootTableB(15.6525,1.25,"Medium","🏅"),new lootTableB(6.675,1.65,"Large","🏅"),new lootTableB(2.35,2.35,"Huge","🥉"),new lootTableB(1.25,3.15,"Gigantic","🥉"),new lootTableB(0.75,4,"Titanic","🥉"),new lootTableB(0.25,5.65,"Humongous","🥈"), new lootTableB(0.15,7.5,"Ginormous","🥈"),new lootTableB(0.015,12.75,"Record-Breaking","🥇"),new lootTableB(0.00125,100.75,"Cosmic","🌌"),new lootTableB(0.000165,2575.45,"Special","🎖")}; + double totalWeight2 = 0; + lootTableB size = new lootTableB(0,0,"Error",""); + for(int i =0; i < list.length; i++){ + totalWeight = totalWeight + list[i].getChance(); + } + for(int i =0; i< list2.length; i++){ + totalWeight2 = totalWeight2 + list2[i].getWeight(); + } + //lootTableB[] list2 = {new lootTableB(0.00125,0.01, "Sub-Atomic", "🥇"),new lootTableB(0.25, 0.1, "Mircoscopic", "🥈"), new lootTableB(1,0.125,"Miniature","🥉"),new lootTableB(10,0.75,"Tiny","🏅"),new lootTableB(25.75,1,"Small","🏅"),new lootTableB(15.6525,1.25,"Medium","🏅"),new lootTableB(6.675,1.65,"Large","🏅"),new lootTableB(2.35,2.35,"Huge","🥉"),new lootTableB(1.25,3.15,"Gigantic","🥉"),new lootTableB(0.75,4,"Titanic","🥉"),new lootTableB(0.25,5.65,"Humongous","🥈"), new lootTableB(0.15,7.5,"Ginormous","🥈"),new lootTableB(0.015,12.75,"Record-Breaking","🥇"),new lootTableB(0.00125,100.75,"Cosmic","🌌"),new lootTableB(0.000165,2575.45,"Special","🎖")}; + + Random random = new Random(); + double ran = random.nextDouble(totalWeight)+luckModifier/5; + double ran2 = random.nextDouble(totalWeight2)+luckModifier/12.5; + totalWeight =0; + totalWeight2 =0; + for(int i =0; i < list.length; i++){ + totalWeight = totalWeight + list[i].getChance(); + if(totalWeight>ran){ //test luck addition system + lt = list[i]; + break; + } else if (i == list.length-1 && !(totalWeight>ran)){ + lt = list[i]; + } + } + for(int i =0; i< list2.length; i++){ + totalWeight2 = totalWeight2 + list2[i].getWeight(); + if(totalWeight2>ran2){ + size = list2[i]; + break; + }else if (i == list2.length-1 && !(totalWeight2>ran2)){ + size = list2[i]; } } + addMoney(lt.getValue()*size.getMultiplier()); + money = Math.round(money*100.0)/100.0; + double earned = Math.round(lt.getValue()*size.getMultiplier()*100.0)/100.0; + event.getChannel().sendMessage(" You caught a "+lt.name() +" that was "+ size.name() + "! "+"| You sold this fish for $"+earned+" | Your bank account is now at $" + money + " | The rarity symbols associated with this fish are "+size.getRankingEmoji()+"!"); +} public void setupModification(MessageCreateEvent event){ new MessageBuilder().setContent("What would you like to modify in your set-up?").addComponents(ActionRow.of(Button.success("upgrade", "Buy Upgrades"),Button.success("location", "Change Location"), Button.danger("leave", "Cancel"))).send(channel); lm.add(event.getApi().addMessageComponentCreateListener(event2 -> { diff --git a/src/main/java/org/jointheleague/features/student/third_feature/lootTableA.java b/src/main/java/org/jointheleague/features/student/third_feature/lootTableA.java index 0d424f64..5b56e7c2 100644 --- a/src/main/java/org/jointheleague/features/student/third_feature/lootTableA.java +++ b/src/main/java/org/jointheleague/features/student/third_feature/lootTableA.java @@ -1,13 +1,15 @@ package org.jointheleague.features.student.third_feature; -public enum lootTableA { +public class lootTableA { - Minnow(35.7525,4),Sardine(32.5, 7),SeaBass(9, 16),Tuna(15.5, 12.5),ReefShark(12.5, 13.5),Squid(3.5, 75),TriggerFish(5,45),ElectricEel(2.25,115),Striper(6.25, 25),Lobster(1.75, 145),Swordfish(0.975,160),Sunfish(0.675,235),GoldMinnowStatue(0.00565,127500); + //Minnow(35.7525,4),Sardine(32.5, 7),SeaBass(9, 16),Tuna(15.5, 12.5),ReefShark(12.5, 13.5),Squid(3.5, 75),TriggerFish(5,45),ElectricEel(2.25,115),Striper(6.25, 25),Lobster(1.75, 145),Swordfish(0.975,160),Sunfish(0.675,235),WalkingMinnow(0.0125,126500),GoldMinnowStatue(0.00565,127500); double value; double weightOrChanceOfGettingFish; - lootTableA(double weightOrChanceOfGettingFish, double value) { + String name; + lootTableA(double weightOrChanceOfGettingFish, double value, String name) { this.weightOrChanceOfGettingFish=weightOrChanceOfGettingFish; this.value = value; + this.name = name; } public double getValue() { @@ -17,4 +19,6 @@ public double getValue() { public double getChance() { return weightOrChanceOfGettingFish; } + + public String name(){return name;} } diff --git a/src/main/java/org/jointheleague/features/student/third_feature/lootTableB.java b/src/main/java/org/jointheleague/features/student/third_feature/lootTableB.java index 8a553054..1fe0063a 100644 --- a/src/main/java/org/jointheleague/features/student/third_feature/lootTableB.java +++ b/src/main/java/org/jointheleague/features/student/third_feature/lootTableB.java @@ -1,7 +1,7 @@ -package org.jointheleague.features.student.third_feature; +/*package org.jointheleague.features.student.third_feature; public enum lootTableB { - Angler(15.125,40),; + //Telescopefish(25.65,35),Rhinochimaera(20.2575,40),Angler(15.125,55),Barreleye(12.25751,60),Lanternfish(11.524575,70),GlowingMinnow(10.2575,75),FlyingMinnow(8.7525,90),AbyssalGrenadier(5.245,125),MarineHatchetfish(5.65,120),GoblinShark(2.5,165),Jellyfish(1.15, 225),Snailfish(0.000125,35000000); double value; double weightOrChanceOfGettingFish; lootTableB(double weightOrChanceOfGettingFish, double value) { @@ -17,3 +17,37 @@ public double getChance() { return weightOrChanceOfGettingFish; } } +*/ +package org.jointheleague.features.student.third_feature; + +import org.javacord.api.entity.message.MessageDecoration; + +public class lootTableB { + double weight; + double multiplier; + String name; + String rankingEmoji; + + lootTableB(double weight, double multiplier, String name, String rankingEmoji){ + this.weight = weight; + this.multiplier = multiplier; + this.name = name; + this.rankingEmoji = rankingEmoji; + } + + public double getMultiplier() { + return multiplier; + } + + public double getWeight() { + return weight; + } + + public String name(){ + return name; + } + + public String getRankingEmoji() { + return rankingEmoji; + } +} \ No newline at end of file From 24663a0022934bbb41eecb2f79172e27a0100f6f Mon Sep 17 00:00:00 2001 From: Branson778 Date: Sun, 5 Nov 2023 16:26:49 -0800 Subject: [PATCH 07/12] Implemented lobster pot and fix new upgrade not working --- .../student/third_feature/FeatureThree.java | 187 +++++++++++++++--- 1 file changed, 165 insertions(+), 22 deletions(-) diff --git a/src/main/java/org/jointheleague/features/student/third_feature/FeatureThree.java b/src/main/java/org/jointheleague/features/student/third_feature/FeatureThree.java index 8dba3e64..41367b96 100644 --- a/src/main/java/org/jointheleague/features/student/third_feature/FeatureThree.java +++ b/src/main/java/org/jointheleague/features/student/third_feature/FeatureThree.java @@ -31,8 +31,11 @@ public class FeatureThree extends FeatureTemplate { public double money = 0; public double luckModifier = 0.00; public String location = "Sea"; - public boolean[] bought = new boolean[3]; //Number in boolean is the total number of upgrades at the current moment. + public boolean[] bought = new boolean[9]; //Number in boolean is the total number of upgrades at the current moment. public List locations = new ArrayList(); + public int fishTimes = 1; + boolean lobsterPotOwned = true; + public int lobsters = 0; ArrayList> lm = new ArrayList>(); @@ -61,7 +64,7 @@ public void handle(MessageCreateEvent event) { } else if (messageContent.equalsIgnoreCase(COMMAND + " menu")){ // event.getChannel().sendMessage("Message to test whether TextChannel broke again."); - new MessageBuilder().setContent("| Current Money: $" + money+" | Current Location: "+location+" | Luck Modifier: +" + luckModifier/5+" points |").addComponents(ActionRow.of(Button.success("fish", "Go Fishing"),Button.secondary("modify", "Modify Set-Up"),Button.secondary("save", "Save Game"))).send(channel); + new MessageBuilder().setContent("| Current Money: $" + money+" | Current Location: "+location+" | Luck Modifier: +" + luckModifier/5+" points |").addComponents(ActionRow.of(Button.success("fish", "Go Fishing"),Button.secondary("modify", "Modify Set-Up"),Button.secondary("save", "Save Game"), Button.danger("lobPot", "Lobster Pot"))).send(channel); for (ListenerManager i: lm){ i.remove(); } @@ -72,27 +75,43 @@ else if (messageContent.equalsIgnoreCase(COMMAND + " menu")){ switch(cID){ case "fish": event.getChannel().sendMessage("Going fishing..."); - randomFish(location, event); - randomFish(location, event); - randomFish(location, event); - randomFish(location, event); - randomFish(location, event); - randomFish(location, event); + for(int i=0; i < fishTimes; i++) { + randomFish(location, event); + } + lobsterPotLuck(event); break; case "modify": setupModification(event); + lobsterPotLuck(event); break; case "save" : event.getChannel().sendMessage("SAVING"); break; + case "lobPot" : + if(lobsters>0) { + money = money + 30 * lobsters; + event.getChannel().sendMessage("You are attentive! There were " + lobsters + " lobsters in the pot. You sold these pot lobsters for $" + (30*lobsters) + "!"); + lobsters = 0; + } else{ + event.getChannel().sendMessage("Bummer, no lobsters in the pot. Maybe you should check it more often."); + } + break; } })); } else if(messageContent.equals(COMMAND + " testMoney")){ - money = money + 10000000; - luckModifier = luckModifier + 2135450; + money = money + 10000; + luckModifier = luckModifier + 0; + event.getChannel().sendMessage("We slipped you a bit of cash to get testing started. To warn you, there are "+lobsters+" lobsters in your pot"); + lobsterPotLuck(event); + lobsterPotLuck(event); + lobsterPotLuck(event); + lobsterPotLuck(event); + lobsterPotLuck(event); + + } } @@ -150,7 +169,7 @@ public void randomFish(String location, MessageCreateEvent event) { } public void lootAssigning(double totalWeight, MessageCreateEvent event,lootTableA lt,lootTableA[] list){ - lootTableB[] list2 = {new lootTableB(0.00125,0.01, "Sub-Atomic", "🥇"),new lootTableB(0.25, 0.1, "Mircoscopic", "🥈"), new lootTableB(1,0.125,"Miniature","🥉"),new lootTableB(10,0.75,"Tiny","🏅"),new lootTableB(25.75,1,"Small","🏅"),new lootTableB(15.6525,1.25,"Medium","🏅"),new lootTableB(6.675,1.65,"Large","🏅"),new lootTableB(2.35,2.35,"Huge","🥉"),new lootTableB(1.25,3.15,"Gigantic","🥉"),new lootTableB(0.75,4,"Titanic","🥉"),new lootTableB(0.25,5.65,"Humongous","🥈"), new lootTableB(0.15,7.5,"Ginormous","🥈"),new lootTableB(0.015,12.75,"Record-Breaking","🥇"),new lootTableB(0.00125,100.75,"Cosmic","🌌"),new lootTableB(0.000165,2575.45,"Special","🎖")}; + lootTableB[] list2 = {new lootTableB(0.00125,0.01, "Sub-Atomic", "🥇"),new lootTableB(0.25, 0.1, "Mircoscopic", "🥈"), new lootTableB(1,0.125,"Miniature","🥉"),new lootTableB(1.25,0.5, "Baby", "🥉"),new lootTableB(10,0.75,"Tiny","🏅"),new lootTableB(25.75,1,"Small","🏅"),new lootTableB(15.6525,1.25,"Medium","🏅"),new lootTableB(6.675,1.65,"Large","🏅"),new lootTableB(2.35,2.35,"Huge","🥉"),new lootTableB(1.25,3.15,"Gigantic","🥉"),new lootTableB(0.75,4,"Titanic","🥉"),new lootTableB(0.25,5.65,"Humongous","🥈"), new lootTableB(0.15,7.5,"Ginormous","🥈"),new lootTableB(0.015,12.75,"Record-Breaking","🥇"),new lootTableB(0.00125,100.75,"Cosmic","🌌"),new lootTableB(0.000345, 275.50, "Multi-Dimensional", "🌌"),new lootTableB(0.000215,750.25, "Shiny", "🎖"),new lootTableB(0.000165,2575.45,"Special","🎖")}; double totalWeight2 = 0; lootTableB size = new lootTableB(0,0,"Error",""); for(int i =0; i < list.length; i++){ @@ -213,17 +232,17 @@ public void setupModification(MessageCreateEvent event){ })); } public void upgradeMenu(MessageCreateEvent event) { - new MessageBuilder().setContent("What would you like to buy").addComponents(ActionRow.of(Button.secondary("0", "Carbon Fibre Rod | $125.25"), Button.secondary("1", "Deep-Dive Lure | $35.50"), Button.secondary("2", "Better Boat Service | $1250.75"))).send(channel); + new MessageBuilder().setContent("What would you like to buy").addComponents(ActionRow.of(Button.secondary("3","Rabbit's Foot | $15.00"),Button.secondary("4","Shinier Bait | $30.00"),Button.secondary("1", "Deep-Dive Lure | $35.75")),ActionRow.of(Button.secondary("0", "Carbon Fibre Rod | $125.25"),Button.secondary("5","Durable Fishing Line | $250.25"),Button.secondary("6","Four-Leaf Clover Pot | $300.00")),ActionRow.of(Button.secondary("7","Larger Bait | $350.50"),Button.secondary("8","Multi-Hooked Lure | $650.75"), Button.secondary("2", "Better Boat Service | $1250.75")), ActionRow.of(Button.secondary("9", "Treasure Map | $27500.25"))).send(channel); lm.add(event.getApi().addMessageComponentCreateListener(event2 -> { MessageComponentInteraction mci = event2.getMessageComponentInteraction(); String cID = mci.getCustomId(); - //add system to stop purchasing multiple plus a buy message. + //ask why the upgrades menu is now showing up with all upgrades. switch (cID) { case "0": if(money>=125.25 && !bought[0]) { money = money - 125.25; - luckModifier = luckModifier + 25; - event.getChannel().sendMessage("Congrats, you now own a carbon fibre fishing rod! This upgrades increases your luck."); + luckModifier = luckModifier + 3.75; + event.getChannel().sendMessage("Congrats, you now own a carbon fibre fishing rod! This upgrade increases your luck by allowing you to haul up the better fish easier."); bought[0] = true; } else if(money<125.25 && !bought[0]){ @@ -234,13 +253,13 @@ else if(money<125.25 && !bought[0]){ } break; case "1": - if(money>=35.50 && !bought[1]) { - money = money - 35.50; - luckModifier = luckModifier + 5.75; - event.getChannel().sendMessage("Congrats, you now own a deep-dive lure! This upgrades slightly increases your luck."); + if(money>=35.75 && !bought[1]) { + money = money - 35.75; + luckModifier = luckModifier + 2.5; + event.getChannel().sendMessage("Congrats, you now own a deep-dive lure! This upgrade slightly increases your luck by going deeper into the water where the better fish reside."); bought[1] = true; } - else if(money<35.50 && !bought[1]){ + else if(money<35.75 && !bought[1]){ event.getChannel().sendMessage("You cannot afford this item."); } else{ @@ -250,8 +269,8 @@ else if(money<35.50 && !bought[1]){ case "2": if(money>=1250.75 && !bought[2]) { money = money - 1250.75; - luckModifier = luckModifier + 12.5; - event.getChannel().sendMessage("Congrats, you now have a better boat service! This upgrades slightly increases your luck and allows you to travel to a new location, the trench."); + luckModifier = luckModifier + 3; + event.getChannel().sendMessage("Congrats, you now have a better boat service! This upgrade slightly increases your luck and allows you to travel to a new location, the trench."); bought[2] = true; locations.add("Trench"); //new location available @@ -263,6 +282,109 @@ else if(money<1250.75 && !bought[2]){ event.getChannel().sendMessage("You cannot buy an item you already have."); } break; + case "3": + if(money>=15 && !bought[3]) { + money = money - 15; + luckModifier = luckModifier + 1.25; + event.getChannel().sendMessage("Congrats, you now own a rabbits foot! This might increase your luck if you focus on the results."); + bought[3] = true; + } + else if(money<15 && !bought[3]){ + event.getChannel().sendMessage("You cannot afford this item."); + } + else{ + event.getChannel().sendMessage("You cannot buy an item you already have."); + } + break; + case "4": + if(money>=30 && !bought[4]) { + money = money - 30; + luckModifier = luckModifier + 1.75; + event.getChannel().sendMessage("Congrats, you now own a bunch of shinier bait! This upgrade slightly increases your luck by attracting bigger and better fish."); + bought[4] = true; + } + else if(money<30 && !bought[4]){ + event.getChannel().sendMessage("You cannot afford this item."); + } + else{ + event.getChannel().sendMessage("You cannot buy an item you already have."); + } + break; + case "5": + if(money>=250.25 && !bought[5]) { + money = money - 250.25; + //luckModifier = luckModifier + 5.75; + fishTimes++; + event.getChannel().sendMessage("Congrats, you now own more durable fishing line! This upgrade allows you to catch an extra fish each time you fish."); + bought[5] = true; + } + else if(money<250.25 && !bought[5]){ + event.getChannel().sendMessage("You cannot afford this item."); + } + else{ + event.getChannel().sendMessage("You cannot buy an item you already have."); + } + break; + case "6": + if(money>=300 && !bought[6]) { + money = money - 300; + luckModifier = luckModifier + 5.75; + event.getChannel().sendMessage("Congrats, you now own a four-leaf clover pot! This upgrade increases your luck because common video game tropes make great features."); + bought[6] = true; + } + else if(money<300 && !bought[6]){ + event.getChannel().sendMessage("You cannot afford this item."); + } + else{ + event.getChannel().sendMessage("You cannot buy an item you already have."); + } + break; + case "7": + if(money>=350.5 && !bought[7]) { + money = money - 350.5; + luckModifier = luckModifier + 6.75; + event.getChannel().sendMessage("Congrats, you now own a bunch of larger bait! This upgrade increases your luck by making the bigger fish want to eat the bigger easy food."); + bought[7] = true; + } + else if(money<350.5 && !bought[7]){ + event.getChannel().sendMessage("You cannot afford this item."); + } + else{ + event.getChannel().sendMessage("You cannot buy an item you already have."); + } + break; + case "8": + if(money>=650.75 && !bought[8]) { + money = money - 650.75; + //luckModifier = luckModifier + 5.75; + fishTimes = fishTimes + 2; + event.getChannel().sendMessage("Congrats, you now own a multi-hook lure! This upgrade allows you to catch two more fish in one go."); + bought[9] = true; + } + else if(money<650.75 && !bought[8]){ + event.getChannel().sendMessage("You cannot afford this item."); + } + else{ + event.getChannel().sendMessage("You cannot buy an item you already have."); + } + break; + case "9": + //Fix messages not sending + if(money>=27500.25 && !bought[9]) { + money = money - 27500.25; + //luckModifier = luckModifier + 5.75; + //fishTimes = fishTimes + 2; + locations.add("The Coveted Coves"); + event.getChannel().sendMessage("Congrats, you now own a treasure map! This upgrade allows you to travel to the next location, The Coveted Coves."); + bought[9] = true; + } + else if(money<27500.25 && !bought[8]){ + event.getChannel().sendMessage("You cannot afford this item."); + } + else{ + event.getChannel().sendMessage("You cannot buy an item you already have."); + } + break; } })); } @@ -292,6 +414,27 @@ public void changeLocation (MessageCreateEvent event){ })); event.getApi().removeListener(MessageComponentCreateListener.class, null); } + void lobsterPotLuck(MessageCreateEvent event){ + if(lobsterPotOwned) { + //event.getChannel().sendMessage("TESTPOT"); + int pot = 16; + Random ran = new Random(); + double ranint = ran.nextDouble(pot); + if(ranint>=(pot - 2 - luckModifier/16)){ + lobsters = lobsters + (ran.nextInt(3)+1); + //event.getChannel().sendMessage("Congrats, lobsters added. TESTMESSAGE"); + } + else{ + if(lobsters!=0) { + int removed = ran.nextInt(lobsters); + lobsters = lobsters - removed; + //event.getChannel().sendMessage("Bummer, "+removed+" lobsters were removed from your pot. TESTMESSAGE"); + } else{ + //event.getChannel().sendMessage("Bummer, nothing happened. TESTMESSAGE"); + } + } + } + } } From af3ff7801874428e4af25a27319e8d4bedcf2a87 Mon Sep 17 00:00:00 2001 From: Branson778 Date: Sun, 19 Nov 2023 16:29:28 -0800 Subject: [PATCH 08/12] Implemented The Coveted Coves and fixed rounding. --- .../student/third_feature/FeatureThree.java | 163 ++++++++++++++---- 1 file changed, 132 insertions(+), 31 deletions(-) diff --git a/src/main/java/org/jointheleague/features/student/third_feature/FeatureThree.java b/src/main/java/org/jointheleague/features/student/third_feature/FeatureThree.java index 41367b96..de0bfb37 100644 --- a/src/main/java/org/jointheleague/features/student/third_feature/FeatureThree.java +++ b/src/main/java/org/jointheleague/features/student/third_feature/FeatureThree.java @@ -19,6 +19,8 @@ import org.jointheleague.features.help_embed.plain_old_java_objects.help_embed.HelpEmbed; import org.jointheleague.features.templates.FeatureTemplate; +import java.math.BigDecimal; +import java.math.RoundingMode; import java.util.ArrayList; import java.util.List; import java.util.Random; @@ -31,11 +33,12 @@ public class FeatureThree extends FeatureTemplate { public double money = 0; public double luckModifier = 0.00; public String location = "Sea"; - public boolean[] bought = new boolean[9]; //Number in boolean is the total number of upgrades at the current moment. + public boolean[] bought = new boolean[16]; //Number in boolean is the total number of upgrades at the current moment. public List locations = new ArrayList(); public int fishTimes = 1; - boolean lobsterPotOwned = true; - public int lobsters = 0; + boolean lobsterPotOwned = false; + //public int lobsters = 0; + public ArrayList lobsters = new ArrayList(); ArrayList> lm = new ArrayList>(); @@ -52,6 +55,7 @@ public FeatureThree(String channelName) { ); locations.add(location); + } @Override @@ -88,12 +92,25 @@ else if (messageContent.equalsIgnoreCase(COMMAND + " menu")){ event.getChannel().sendMessage("SAVING"); break; case "lobPot" : - if(lobsters>0) { - money = money + 30 * lobsters; - event.getChannel().sendMessage("You are attentive! There were " + lobsters + " lobsters in the pot. You sold these pot lobsters for $" + (30*lobsters) + "!"); - lobsters = 0; - } else{ - event.getChannel().sendMessage("Bummer, no lobsters in the pot. Maybe you should check it more often."); + for(int i = 0; i< lobsters.size(); i++) { + if (lobsters.get(i) > 0 && lobsterPotOwned == true) { + if (bought[12]) { + money = money + 50 * lobsters.get(i) * locations.size(); + }else{ + money = money + 30 * lobsters.get(i) * locations.size(); + } + if(bought[12]) { + event.getChannel().sendMessage("You are attentive! There were " + lobsters.get(i) + " lobsters in pot " + (i + 1) + ". You sold these pot lobsters for $" + (50 * lobsters.get(i) * locations.size()) + "!"); + lobsters.set(i, 0); + }else{ + event.getChannel().sendMessage("You are attentive! There were " + lobsters.get(i) + " lobsters in pot " + (i + 1) + ". You sold these pot lobsters for $" + (30 * lobsters.get(i) * locations.size()) + "!"); + lobsters.set(i, 0); + } + } else if (lobsterPotOwned = true) { + event.getChannel().sendMessage("Bummer, no lobsters in pot "+(i+1)+". Maybe you should check it more often."); + } else { + event.getChannel().sendMessage("You look for the pot, hoping for lobsters until your realize your search is futile. You don't own a lobster pot yet!"); + } } break; } @@ -102,14 +119,10 @@ else if (messageContent.equalsIgnoreCase(COMMAND + " menu")){ })); } else if(messageContent.equals(COMMAND + " testMoney")){ - money = money + 10000; + money = money + 100000; luckModifier = luckModifier + 0; event.getChannel().sendMessage("We slipped you a bit of cash to get testing started. To warn you, there are "+lobsters+" lobsters in your pot"); - lobsterPotLuck(event); - lobsterPotLuck(event); - lobsterPotLuck(event); - lobsterPotLuck(event); - lobsterPotLuck(event); + } @@ -166,10 +179,14 @@ public void randomFish(String location, MessageCreateEvent event) { event.getChannel().sendMessage(" You caught a "+lt2.name() + "! "+"| You sold this fish for $"+lt2.getValue()+" | Your bank account is now at $" + money); }*/ } + else if (location.equals("The Coveted Coves")){ + lootTableA[] list = {new lootTableA(30,135,"Rockfish"),new lootTableA(22.7525,150,"Golemfish"),new lootTableA(15.752505,245,"Golden Rockfish"),new lootTableA(10.25,275,"Fire-Belly Fish"),new lootTableA(7.5,325,"Lightfish"),new lootTableA(7.5,325,"Darkfish"),new lootTableA(5,300,"Luckfish"),new lootTableA(4.5,400,"Swimming Fossil"),new lootTableA(4.5,425,"Riftfish"),new lootTableA(2.5,535,"Rodfish"),new lootTableA(2,650,"Bronzefish"),new lootTableA(2.5,585,"Moonfish"),new lootTableA(0.5,1475.25,"Boatfish"),new lootTableA(1,875,"Snarefish"),new lootTableA(1.5,750,"Cyclopic Golemfish"),new lootTableA(0.01,12575.25,"Chest of Fish"),new lootTableA(0.0001,1257525.75,"Chest of Precious Fish"),new lootTableA(0.000000001,75254525754525.75,"Bootfish")}; + lootAssigning(totalWeight, event, lt, list); // Fire-Belly Fish could attack the player. Luckfish gives the player a very slight luck increase. Rodfish increases the number of times you can fish by clicking the fish button by one. Boatfish makes the player randomly change to a different location Snarefish trap or delay the player + } } public void lootAssigning(double totalWeight, MessageCreateEvent event,lootTableA lt,lootTableA[] list){ - lootTableB[] list2 = {new lootTableB(0.00125,0.01, "Sub-Atomic", "🥇"),new lootTableB(0.25, 0.1, "Mircoscopic", "🥈"), new lootTableB(1,0.125,"Miniature","🥉"),new lootTableB(1.25,0.5, "Baby", "🥉"),new lootTableB(10,0.75,"Tiny","🏅"),new lootTableB(25.75,1,"Small","🏅"),new lootTableB(15.6525,1.25,"Medium","🏅"),new lootTableB(6.675,1.65,"Large","🏅"),new lootTableB(2.35,2.35,"Huge","🥉"),new lootTableB(1.25,3.15,"Gigantic","🥉"),new lootTableB(0.75,4,"Titanic","🥉"),new lootTableB(0.25,5.65,"Humongous","🥈"), new lootTableB(0.15,7.5,"Ginormous","🥈"),new lootTableB(0.015,12.75,"Record-Breaking","🥇"),new lootTableB(0.00125,100.75,"Cosmic","🌌"),new lootTableB(0.000345, 275.50, "Multi-Dimensional", "🌌"),new lootTableB(0.000215,750.25, "Shiny", "🎖"),new lootTableB(0.000165,2575.45,"Special","🎖")}; + lootTableB[] list2 = {new lootTableB(0.00125,0.01, "Sub-Atomic", "🥇"),new lootTableB(0.25, 0.1, "Microscopic", "🥈"), new lootTableB(1,0.125,"Miniature","🥉"),new lootTableB(1.25,0.5, "a Baby", "🥉"),new lootTableB(10,0.75,"Tiny","🏅"),new lootTableB(25.75,1,"Small","🏅"),new lootTableB(15.6525,1.25,"Medium","🏅"),new lootTableB(6.675,1.65,"Large","🏅"),new lootTableB(2.35,2.35,"Huge","🥉"),new lootTableB(1.25,3.15,"Gigantic","🥉"),new lootTableB(0.75,4,"Titanic","🥉"),new lootTableB(0.25,5.65,"Humongous","🥈"), new lootTableB(0.15,7.5,"Ginormous","🥈"),new lootTableB(0.015,12.75,"Record-Breaking","🥇"),new lootTableB(0.00125,100.75,"Cosmic","🌌"),new lootTableB(0.000345, 275.50, "Multi-Dimensional", "🌌"),new lootTableB(0.000215,750.25, "Shiny", "🎖"),new lootTableB(0.000165,2575.45,"Special","🎖")}; double totalWeight2 = 0; lootTableB size = new lootTableB(0,0,"Error",""); for(int i =0; i < list.length; i++){ @@ -205,12 +222,16 @@ public void lootAssigning(double totalWeight, MessageCreateEvent event,lootTable } addMoney(lt.getValue()*size.getMultiplier()); - money = Math.round(money*100.0)/100.0; - double earned = Math.round(lt.getValue()*size.getMultiplier()*100.0)/100.0; + //money = Math.round(money*100.0)/100.0; + BigDecimal bd = new BigDecimal(money).setScale(2, RoundingMode.HALF_UP); + money = bd.doubleValue(); + BigDecimal bd2 = new BigDecimal(lt.getValue()*size.getMultiplier()).setScale(2, RoundingMode.HALF_UP); + //double earned = Math.round(lt.getValue()*size.getMultiplier()*100.0)/100.0; + double earned = bd2.doubleValue(); event.getChannel().sendMessage(" You caught a "+lt.name() +" that was "+ size.name() + "! "+"| You sold this fish for $"+earned+" | Your bank account is now at $" + money + " | The rarity symbols associated with this fish are "+size.getRankingEmoji()+"!"); } public void setupModification(MessageCreateEvent event){ - new MessageBuilder().setContent("What would you like to modify in your set-up?").addComponents(ActionRow.of(Button.success("upgrade", "Buy Upgrades"),Button.success("location", "Change Location"), Button.danger("leave", "Cancel"))).send(channel); + new MessageBuilder().setContent("What would you like to modify in your set-up?").addComponents(ActionRow.of(Button.success("upgrade", "Buy Upgrades"),Button.success("location", "Change Location"), Button.danger("leave", "Buy Another Lobster Pot | $"+(125*lobsters.size())))).send(channel); lm.add(event.getApi().addMessageComponentCreateListener(event2 -> { MessageComponentInteraction mci = event2.getMessageComponentInteraction(); String cID = mci.getCustomId(); @@ -224,7 +245,17 @@ public void setupModification(MessageCreateEvent event){ break; case "leave": //clear old message here - event.getChannel().sendMessage("Cancelling modification menu. Please go back to !fish menu."); + if(lobsterPotOwned && bought[10]){ + if(money>= (125*lobsters.size())){ + money = money - (125*lobsters.size()); + lobsters.add(0); + event.getChannel().sendMessage("Congratulations, you now have another lobster pot. Your bank account is now at $"+money); + } else{ + event.getChannel().sendMessage("You don't have enough money to buy another lobster pot."); + } + } else{ + event.getChannel().sendMessage("Before trying to buy more lobster pots, consider buying your very first."); + } break; default: break; @@ -232,7 +263,7 @@ public void setupModification(MessageCreateEvent event){ })); } public void upgradeMenu(MessageCreateEvent event) { - new MessageBuilder().setContent("What would you like to buy").addComponents(ActionRow.of(Button.secondary("3","Rabbit's Foot | $15.00"),Button.secondary("4","Shinier Bait | $30.00"),Button.secondary("1", "Deep-Dive Lure | $35.75")),ActionRow.of(Button.secondary("0", "Carbon Fibre Rod | $125.25"),Button.secondary("5","Durable Fishing Line | $250.25"),Button.secondary("6","Four-Leaf Clover Pot | $300.00")),ActionRow.of(Button.secondary("7","Larger Bait | $350.50"),Button.secondary("8","Multi-Hooked Lure | $650.75"), Button.secondary("2", "Better Boat Service | $1250.75")), ActionRow.of(Button.secondary("9", "Treasure Map | $27500.25"))).send(channel); + new MessageBuilder().setContent("What would you like to buy").addComponents(ActionRow.of(Button.secondary("3","Rabbit's Foot | $15.00"),Button.secondary("4","Shinier Bait | $30.00"),Button.secondary("1", "Deep-Dive Lure | $35.75"),Button.secondary("10", "Lobster Pot | $50.00")),ActionRow.of(Button.secondary("0", "Carbon Fibre Rod | $125.25"),Button.secondary("5","Durable Fishing Line | $250.25"),Button.secondary("6","Four-Leaf Clover Pot | $300.00")),ActionRow.of(Button.secondary("7","Larger Bait | $350.50"),Button.secondary("8","Multi-Hooked Lure | $650.75"), Button.secondary("2", "Better Boat Service | $1250.75")),ActionRow.of(Button.secondary("11", "Fish Detector | $1750.00"),Button.secondary("12", "Lobster Pass | 2575.25"),Button.secondary("13", "Second Boat | 12750.25")), ActionRow.of(Button.secondary("9", "Treasure Map | $27500.25"))).send(channel); lm.add(event.getApi().addMessageComponentCreateListener(event2 -> { MessageComponentInteraction mci = event2.getMessageComponentInteraction(); String cID = mci.getCustomId(); @@ -359,7 +390,7 @@ else if(money<350.5 && !bought[7]){ //luckModifier = luckModifier + 5.75; fishTimes = fishTimes + 2; event.getChannel().sendMessage("Congrats, you now own a multi-hook lure! This upgrade allows you to catch two more fish in one go."); - bought[9] = true; + bought[8] = true; } else if(money<650.75 && !bought[8]){ event.getChannel().sendMessage("You cannot afford this item."); @@ -378,13 +409,79 @@ else if(money<650.75 && !bought[8]){ event.getChannel().sendMessage("Congrats, you now own a treasure map! This upgrade allows you to travel to the next location, The Coveted Coves."); bought[9] = true; } - else if(money<27500.25 && !bought[8]){ + else if(money<27500.25 && !bought[9]){ event.getChannel().sendMessage("You cannot afford this item."); } else{ event.getChannel().sendMessage("You cannot buy an item you already have."); } break; + case "10": + if(money>=50 && !bought[10]) { + money = money - 50; + //luckModifier = luckModifier + 5.75; + //fishTimes = fishTimes + 2; + lobsterPotOwned = true; + lobsters.add(0); + event.getChannel().sendMessage("Congrats, you now own a lobster pot! This upgrade allows you to idly catch small lobsters when fishing and shopping for upgrades."); + bought[10] = true; + } + else if(money<50 && !bought[10]){ + event.getChannel().sendMessage("You cannot afford this item."); + } + else{ + event.getChannel().sendMessage("You cannot buy an item you already have."); + } + break; + case"11": + if(money>=1750 && !bought[11]) { + money = money - 1750; + luckModifier = luckModifier + 10.75; + //fishTimes = fishTimes + 2; + event.getChannel().sendMessage("Congrats, you now own a fish detector! This upgrade allows you to detect better fish and increases your luck."); + bought[11] = true; + } + else if(money<1750 && !bought[11]){ + event.getChannel().sendMessage("You cannot afford this item."); + } + else{ + event.getChannel().sendMessage("You cannot buy an item you already have."); + } + break; + case "12": + //2575.25 + if(money>=2575.25 && !bought[12]) { + money = money - 2575.25; + //luckModifier = luckModifier + 5.75; + fishTimes = fishTimes + 2; + event.getChannel().sendMessage("Congrats, you now own a lobster pass! This upgrade allows you to sell all your pot lobsters for a bit more money and to fish two more times in one go."); + bought[12] = true; + } + else if(money<2575.25 && !bought[12]){ + event.getChannel().sendMessage("You cannot afford this item."); + } + else{ + event.getChannel().sendMessage("You cannot buy an item you already have."); + } + break; + case "13": + //12750.25 + if(money>=12750.25 && !bought[13]) { + money = money - 12750.25; + //luckModifier = luckModifier + 5.75; + fishTimes = fishTimes + 6; + event.getChannel().sendMessage("Congrats, you now own a second boat! This upgrade allows you to fish a whopping six more times at the click of one button."); + bought[13] = true; + } + else if(money<12750.25 && !bought[13]){ + event.getChannel().sendMessage("You cannot afford this item."); + } + else{ + event.getChannel().sendMessage("You cannot buy an item you already have."); + } + break; + case "14": + break; } })); } @@ -410,32 +507,36 @@ public void changeLocation (MessageCreateEvent event){ case "Trench": location = "Trench"; break; + case "The Coveted Coves": + location = "The Coveted Coves"; + break; } })); event.getApi().removeListener(MessageComponentCreateListener.class, null); } void lobsterPotLuck(MessageCreateEvent event){ + for(int i =0; i < lobsters.size(); i++){ if(lobsterPotOwned) { //event.getChannel().sendMessage("TESTPOT"); int pot = 16; Random ran = new Random(); double ranint = ran.nextDouble(pot); - if(ranint>=(pot - 2 - luckModifier/16)){ - lobsters = lobsters + (ran.nextInt(3)+1); + if (ranint >= (pot - 2 - luckModifier / 16)) { + lobsters.set(i, lobsters.get(i) + (ran.nextInt(2 + locations.size()) + 1)); //event.getChannel().sendMessage("Congrats, lobsters added. TESTMESSAGE"); - } - else{ - if(lobsters!=0) { - int removed = ran.nextInt(lobsters); - lobsters = lobsters - removed; + } else { + if (lobsters.get(i) != 0) { + int removed = ran.nextInt(lobsters.get(i)); + lobsters.set(i, lobsters.get(i) - removed); //event.getChannel().sendMessage("Bummer, "+removed+" lobsters were removed from your pot. TESTMESSAGE"); - } else{ + } else { //event.getChannel().sendMessage("Bummer, nothing happened. TESTMESSAGE"); } } } } } + } From 78ff422505debd56df290071a45b24794b99e5d1 Mon Sep 17 00:00:00 2001 From: Branson778 Date: Sun, 26 Nov 2023 16:30:11 -0800 Subject: [PATCH 09/12] Finished game and started tests. --- .../student/third_feature/FeatureThree.java | 86 +++++++++++-- .../third_feature/FeatureThreeTest.java | 119 ++++++++++++++++++ 2 files changed, 194 insertions(+), 11 deletions(-) create mode 100644 src/test/java/org/jointheleague/features/student/third_feature/FeatureThreeTest.java diff --git a/src/main/java/org/jointheleague/features/student/third_feature/FeatureThree.java b/src/main/java/org/jointheleague/features/student/third_feature/FeatureThree.java index de0bfb37..e80edab2 100644 --- a/src/main/java/org/jointheleague/features/student/third_feature/FeatureThree.java +++ b/src/main/java/org/jointheleague/features/student/third_feature/FeatureThree.java @@ -39,6 +39,7 @@ public class FeatureThree extends FeatureTemplate { boolean lobsterPotOwned = false; //public int lobsters = 0; public ArrayList lobsters = new ArrayList(); + public String win = ""; ArrayList> lm = new ArrayList>(); @@ -51,9 +52,10 @@ public FeatureThree(String channelName) { //Create a help embed to describe feature when !help command is sent helpEmbed = new HelpEmbed( COMMAND, - "A luck based fishing game with lots of fish, sizes of fish, qualities of fish, upgrades, and more. If new to !\u200Efish, please start with !\u200Efish tutorial. REMEMBER TO ADD A SAVING FEATURE TO ADD A TEXT KEY TO RESTORE PROGRESS" + "A luck based fishing game with lots of fish, sizes of fish, upgrades, and more. If new to !\u200Efish, please start with !\u200Efish tutorial." ); locations.add(location); + //locations.add("Test"); //TODO REMOVE AFTER TESTING } @@ -64,18 +66,18 @@ public void handle(MessageCreateEvent event) { String messageContent = event.getMessageContent(); if (messageContent.equals(COMMAND) || messageContent.equalsIgnoreCase(COMMAND+" tutorial")) { //respond to message here - event.getChannel().sendMessage("Welcome to !\u200Efish. In this game you will fish, like the name implies. You will continue to fish and gain money. With this money you can upgrade you rod, luck, hook, bait, et cetera. With all of this you should get new better fish. This journey begins the command !\u200Efish menu \nFish Size Value Multiplication Chart: PLACEHOLDER \nRarity Value Multiplication Chart: PLACEHOLDER \n*BETA TUTORIAL*"); + event.getChannel().sendMessage("Welcome to !\u200Efish. In this game you will fish, like the name implies. You will continue to fish and gain money. With this money you can upgrade you rod, luck, hook, bait, et cetera. With all of this you should get new better fish. This journey begins the command !\u200Efish menu. Your final goal is to retire, but that will cost you a pretty penny. You must fish up enough many across the different locations to win this game."); } else if (messageContent.equalsIgnoreCase(COMMAND + " menu")){ // event.getChannel().sendMessage("Message to test whether TextChannel broke again."); - new MessageBuilder().setContent("| Current Money: $" + money+" | Current Location: "+location+" | Luck Modifier: +" + luckModifier/5+" points |").addComponents(ActionRow.of(Button.success("fish", "Go Fishing"),Button.secondary("modify", "Modify Set-Up"),Button.secondary("save", "Save Game"), Button.danger("lobPot", "Lobster Pot"))).send(channel); + new MessageBuilder().setContent("| Current Money: $" + money+" | Current Location: "+location+" | Luck Modifier: +" + luckModifier/5+" points | "+win).addComponents(ActionRow.of(Button.success("fish", "Go Fishing"),Button.secondary("modify", "Modify Set-Up"), Button.danger("lobPot", "Lobster Pot"))).send(channel); for (ListenerManager i: lm){ i.remove(); } lm.add(event.getApi().addMessageComponentCreateListener(event2 -> { MessageComponentInteraction mci = event2.getMessageComponentInteraction(); String cID = mci.getCustomId(); - + mci.acknowledge(); switch(cID){ case "fish": event.getChannel().sendMessage("Going fishing..."); @@ -119,7 +121,7 @@ else if (messageContent.equalsIgnoreCase(COMMAND + " menu")){ })); } else if(messageContent.equals(COMMAND + " testMoney")){ - money = money + 100000; + money = money + 10000000; luckModifier = luckModifier + 0; event.getChannel().sendMessage("We slipped you a bit of cash to get testing started. To warn you, there are "+lobsters+" lobsters in your pot"); @@ -183,6 +185,10 @@ else if (location.equals("The Coveted Coves")){ lootTableA[] list = {new lootTableA(30,135,"Rockfish"),new lootTableA(22.7525,150,"Golemfish"),new lootTableA(15.752505,245,"Golden Rockfish"),new lootTableA(10.25,275,"Fire-Belly Fish"),new lootTableA(7.5,325,"Lightfish"),new lootTableA(7.5,325,"Darkfish"),new lootTableA(5,300,"Luckfish"),new lootTableA(4.5,400,"Swimming Fossil"),new lootTableA(4.5,425,"Riftfish"),new lootTableA(2.5,535,"Rodfish"),new lootTableA(2,650,"Bronzefish"),new lootTableA(2.5,585,"Moonfish"),new lootTableA(0.5,1475.25,"Boatfish"),new lootTableA(1,875,"Snarefish"),new lootTableA(1.5,750,"Cyclopic Golemfish"),new lootTableA(0.01,12575.25,"Chest of Fish"),new lootTableA(0.0001,1257525.75,"Chest of Precious Fish"),new lootTableA(0.000000001,75254525754525.75,"Bootfish")}; lootAssigning(totalWeight, event, lt, list); // Fire-Belly Fish could attack the player. Luckfish gives the player a very slight luck increase. Rodfish increases the number of times you can fish by clicking the fish button by one. Boatfish makes the player randomly change to a different location Snarefish trap or delay the player } + else if (location.equals("Test")){ + lootTableA[] list = {new lootTableA(15,10,"Luckfish"),new lootTableA(15,10,"Rodfish"),new lootTableA(15,10,"Boatfish"),new lootTableA(15,10,"Snarefish")}; + lootAssigning(totalWeight, event, lt, list); + } } public void lootAssigning(double totalWeight, MessageCreateEvent event,lootTableA lt,lootTableA[] list){ @@ -198,8 +204,8 @@ public void lootAssigning(double totalWeight, MessageCreateEvent event,lootTable //lootTableB[] list2 = {new lootTableB(0.00125,0.01, "Sub-Atomic", "🥇"),new lootTableB(0.25, 0.1, "Mircoscopic", "🥈"), new lootTableB(1,0.125,"Miniature","🥉"),new lootTableB(10,0.75,"Tiny","🏅"),new lootTableB(25.75,1,"Small","🏅"),new lootTableB(15.6525,1.25,"Medium","🏅"),new lootTableB(6.675,1.65,"Large","🏅"),new lootTableB(2.35,2.35,"Huge","🥉"),new lootTableB(1.25,3.15,"Gigantic","🥉"),new lootTableB(0.75,4,"Titanic","🥉"),new lootTableB(0.25,5.65,"Humongous","🥈"), new lootTableB(0.15,7.5,"Ginormous","🥈"),new lootTableB(0.015,12.75,"Record-Breaking","🥇"),new lootTableB(0.00125,100.75,"Cosmic","🌌"),new lootTableB(0.000165,2575.45,"Special","🎖")}; Random random = new Random(); - double ran = random.nextDouble(totalWeight)+luckModifier/5; - double ran2 = random.nextDouble(totalWeight2)+luckModifier/12.5; + double ran = random.nextDouble(totalWeight)+luckModifier/10.75; + double ran2 = random.nextDouble(totalWeight2)+luckModifier/17.25; totalWeight =0; totalWeight2 =0; for(int i =0; i < list.length; i++){ @@ -229,13 +235,14 @@ public void lootAssigning(double totalWeight, MessageCreateEvent event,lootTable //double earned = Math.round(lt.getValue()*size.getMultiplier()*100.0)/100.0; double earned = bd2.doubleValue(); event.getChannel().sendMessage(" You caught a "+lt.name() +" that was "+ size.name() + "! "+"| You sold this fish for $"+earned+" | Your bank account is now at $" + money + " | The rarity symbols associated with this fish are "+size.getRankingEmoji()+"!"); -} + fishEffect(lt.name(), event); + } public void setupModification(MessageCreateEvent event){ new MessageBuilder().setContent("What would you like to modify in your set-up?").addComponents(ActionRow.of(Button.success("upgrade", "Buy Upgrades"),Button.success("location", "Change Location"), Button.danger("leave", "Buy Another Lobster Pot | $"+(125*lobsters.size())))).send(channel); lm.add(event.getApi().addMessageComponentCreateListener(event2 -> { MessageComponentInteraction mci = event2.getMessageComponentInteraction(); String cID = mci.getCustomId(); - + mci.acknowledge(); switch(cID){ case "upgrade": upgradeMenu(event); @@ -263,11 +270,11 @@ public void setupModification(MessageCreateEvent event){ })); } public void upgradeMenu(MessageCreateEvent event) { - new MessageBuilder().setContent("What would you like to buy").addComponents(ActionRow.of(Button.secondary("3","Rabbit's Foot | $15.00"),Button.secondary("4","Shinier Bait | $30.00"),Button.secondary("1", "Deep-Dive Lure | $35.75"),Button.secondary("10", "Lobster Pot | $50.00")),ActionRow.of(Button.secondary("0", "Carbon Fibre Rod | $125.25"),Button.secondary("5","Durable Fishing Line | $250.25"),Button.secondary("6","Four-Leaf Clover Pot | $300.00")),ActionRow.of(Button.secondary("7","Larger Bait | $350.50"),Button.secondary("8","Multi-Hooked Lure | $650.75"), Button.secondary("2", "Better Boat Service | $1250.75")),ActionRow.of(Button.secondary("11", "Fish Detector | $1750.00"),Button.secondary("12", "Lobster Pass | 2575.25"),Button.secondary("13", "Second Boat | 12750.25")), ActionRow.of(Button.secondary("9", "Treasure Map | $27500.25"))).send(channel); + new MessageBuilder().setContent("What would you like to buy").addComponents(ActionRow.of(Button.secondary("3","Rabbit's Foot | $15.00"),Button.secondary("4","Shinier Bait | $30.00"),Button.secondary("1", "Deep-Dive Lure | $35.75"),Button.secondary("10", "Lobster Pot | $50.00")),ActionRow.of(Button.secondary("0", "Carbon Fibre Rod | $125.25"),Button.secondary("5","Durable Fishing Line | $250.25"),Button.secondary("6","Four-Leaf Clover Pot | $300.00")),ActionRow.of(Button.secondary("7","Larger Bait | $350.50"),Button.secondary("8","Multi-Hooked Lure | $650.75"), Button.secondary("2", "Better Boat Service | $1250.75")),ActionRow.of(Button.secondary("11", "Fish Detector | $1750.00"),Button.secondary("12", "Lobster Pass | $2575.25"),Button.secondary("13", "Second Boat | $12750.25")), ActionRow.of(Button.secondary("9", "Treasure Map | $27500.25"),Button.secondary("14","Retirement | $1500000.00"))).send(channel); lm.add(event.getApi().addMessageComponentCreateListener(event2 -> { MessageComponentInteraction mci = event2.getMessageComponentInteraction(); String cID = mci.getCustomId(); - //ask why the upgrades menu is now showing up with all upgrades. + mci.acknowledge(); switch (cID) { case "0": if(money>=125.25 && !bought[0]) { @@ -481,6 +488,21 @@ else if(money<12750.25 && !bought[13]){ } break; case "14": + //1500000 + if(money>=1500000.00 && !bought[14]) { + money = money - 650.75; + //luckModifier = luckModifier + 5.75; + //fishTimes = fishTimes + 2; + win = "🏆 Winner! 🏆 |"; + event.getChannel().sendMessage("Congrats, you now are retired! You can still fish, but you finally feel accomplished and have won this game."); + bought[14] = true; + } + else if(money<650.75 && !bought[14]){ + event.getChannel().sendMessage("You cannot afford this item."); + } + else{ + event.getChannel().sendMessage("You cannot buy an item you already have."); + } break; } })); @@ -500,6 +522,7 @@ public void changeLocation (MessageCreateEvent event){ lm.add(event.getApi().addMessageComponentCreateListener(event2 -> { MessageComponentInteraction mci = event2.getMessageComponentInteraction(); String cID = mci.getCustomId(); + mci.acknowledge(); switch(cID){ case "Sea": location = "Sea"; @@ -510,6 +533,9 @@ public void changeLocation (MessageCreateEvent event){ case "The Coveted Coves": location = "The Coveted Coves"; break; + case "Test": + location = "Test"; + break; } })); event.getApi().removeListener(MessageComponentCreateListener.class, null); @@ -536,6 +562,44 @@ void lobsterPotLuck(MessageCreateEvent event){ } } } + public void fishEffect(String fishName, MessageCreateEvent event){ + switch(fishName){ + case "Luckfish": + event.getChannel().sendMessage("Congrats, the Luckfish you caught bestowed you with slightly more luck!"); + luckModifier = luckModifier + 1.25; + break; + case "Boatfish": + Random ran = new Random(); + int ranInt = ran.nextInt(locations.size()); + if(ranInt==0){ + location = "Sea"; + } else if(ranInt==1){ + location = "Trench"; + } else{ + location = "Sea"; + event.getChannel().sendMessage("RanInt failed to pick a location this time. "+ranInt); + } + event.getChannel().sendMessage("Bummer, the Boatfish you caught brought you back to one of your other locations."); + break; + case "Rodfish.": + event.getChannel().sendMessage("Congrats, the Rodfish you caught brought you another fishing pole, allowing you to fish another time per button press!"); + fishTimes = fishTimes + 1; + break; + case "Snarefish": + // try { + ran = new Random(); + double random = ran.nextDouble(money-1)+1; + BigDecimal bd = new BigDecimal(random).setScale(2, RoundingMode.HALF_UP); + random = bd.doubleValue(); + money = money-random; + event.getChannel().sendMessage("The Snarefish has snagged your wallet, causing you to lose $"+random+"."); + // event.wait(20000); + // } catch(Exception e){ + // event.getChannel().sendMessage("This game is having trouble processing the effects of the Snarefish. Exception is "+e+ "."); + // } + break; + } + } } diff --git a/src/test/java/org/jointheleague/features/student/third_feature/FeatureThreeTest.java b/src/test/java/org/jointheleague/features/student/third_feature/FeatureThreeTest.java new file mode 100644 index 00000000..8d32df82 --- /dev/null +++ b/src/test/java/org/jointheleague/features/student/third_feature/FeatureThreeTest.java @@ -0,0 +1,119 @@ +package org.jointheleague.features.student.third_feature; + +import org.javacord.api.entity.channel.TextChannel; +import org.javacord.api.event.message.MessageCreateEvent; +import org.jointheleague.features.help_embed.plain_old_java_objects.help_embed.HelpEmbed; +import org.jointheleague.features.templates.FeatureTemplate; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.*; +import static org.mockito.Mockito.never; + +public class FeatureThreeTest { + private final String testChannelName = "test"; + private final FeatureThree featureThree = new FeatureThree(testChannelName); + + private final ByteArrayOutputStream outContent = new ByteArrayOutputStream(); + private final PrintStream originalOut = System.out; + + @Mock + private MessageCreateEvent messageCreateEvent; + + @Mock + private TextChannel textChannel; + + @BeforeEach + void setUp() { + MockitoAnnotations.openMocks(this); + System.setOut(new PrintStream(outContent)); + } + + @AfterEach + public void itShouldNotPrintToSystemOut() { + String expected = ""; + String actual = outContent.toString(); + + assertEquals(expected, actual); + System.setOut(originalOut); + } + + @Test + void itShouldHaveACommand() { + //Given + + //When + String command = featureThree.COMMAND; + + //Then + + if(!(featureThree instanceof FeatureThree)){ + assertNotEquals("!command", command); + } + + assertNotEquals("", command); + assertNotEquals("!", command); + assertEquals('!', command.charAt(0)); + assertNotNull(command); + } + + @Test + void itShouldHandleMessagesWithCommand() { + //Given + HelpEmbed helpEmbed = new HelpEmbed(featureThree.COMMAND, "test"); + when(messageCreateEvent.getMessageContent()).thenReturn(featureThree.COMMAND); + when(messageCreateEvent.getChannel()).thenReturn((textChannel)); + + //When + featureThree.handle(messageCreateEvent); + + //Then + verify(textChannel, times(1)).sendMessage(anyString()); + } + + @Test + void itShouldNotHandleMessagesWithoutCommand() { + //Given + String command = ""; + when(messageCreateEvent.getMessageContent()).thenReturn(command); + + //When + featureThree.handle(messageCreateEvent); + + //Then + verify(textChannel, never()).sendMessage(""); + } + + @Test + void itShouldHaveAHelpEmbed() { + //Given + + //When + HelpEmbed actualHelpEmbed = featureThree.getHelpEmbed(); + + //Then + assertNotNull(actualHelpEmbed); + } + + @Test + void itShouldHaveTheCommandAsTheTitleOfTheHelpEmbed() { + //Given + + //When + String helpEmbedTitle = featureThree.getHelpEmbed().getTitle(); + String command = featureThree.COMMAND; + + //Then + assertEquals(command, helpEmbedTitle); + } +} From 5e85e208a67b2e826fa042e400e7d51be31d8549 Mon Sep 17 00:00:00 2001 From: Branson778 Date: Sun, 10 Dec 2023 16:08:31 -0800 Subject: [PATCH 10/12] Finished tests with minor edits in game for tests. --- build.gradle | 2 + .../student/third_feature/FeatureThree.java | 27 +++++++--- .../third_feature/FeatureThreeTest.java | 53 ++++++++++++++++++- 3 files changed, 72 insertions(+), 10 deletions(-) diff --git a/build.gradle b/build.gradle index bb3a859e..492ddbb5 100644 --- a/build.gradle +++ b/build.gradle @@ -21,6 +21,8 @@ dependencies { testImplementation 'org.junit.jupiter:junit-jupiter:5.7.0' testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.4.2' testImplementation 'org.junit.jupiter:junit-jupiter-api:5.4.2' + testImplementation 'org.junit.jupiter:junit-jupiter:5.8.1' + testImplementation 'org.junit.jupiter:junit-jupiter:5.8.1' } group = 'org.jointheleague' diff --git a/src/main/java/org/jointheleague/features/student/third_feature/FeatureThree.java b/src/main/java/org/jointheleague/features/student/third_feature/FeatureThree.java index e80edab2..4ef63bed 100644 --- a/src/main/java/org/jointheleague/features/student/third_feature/FeatureThree.java +++ b/src/main/java/org/jointheleague/features/student/third_feature/FeatureThree.java @@ -41,6 +41,8 @@ public class FeatureThree extends FeatureTemplate { public ArrayList lobsters = new ArrayList(); public String win = ""; + public lootTableA[] testList = new lootTableA[60]; + ArrayList> lm = new ArrayList>(); @@ -55,7 +57,7 @@ public FeatureThree(String channelName) { "A luck based fishing game with lots of fish, sizes of fish, upgrades, and more. If new to !\u200Efish, please start with !\u200Efish tutorial." ); locations.add(location); - //locations.add("Test"); //TODO REMOVE AFTER TESTING + //locations.add("Test"); } @@ -121,9 +123,9 @@ else if (messageContent.equalsIgnoreCase(COMMAND + " menu")){ })); } else if(messageContent.equals(COMMAND + " testMoney")){ - money = money + 10000000; - luckModifier = luckModifier + 0; - event.getChannel().sendMessage("We slipped you a bit of cash to get testing started. To warn you, there are "+lobsters+" lobsters in your pot"); + //money = money + 10000000; + // luckModifier = luckModifier + 0; + // event.getChannel().sendMessage("We slipped you a bit of cash to get testing started. To warn you, there are "+lobsters+" lobsters in your pot"); @@ -146,7 +148,9 @@ public void randomFish(String location, MessageCreateEvent event) { lootTableA lt = new lootTableA(0,0,"0"); if (location.equals("Sea")) { lootTableA[] list = {new lootTableA(35.7525,4,"Minnow"),new lootTableA(32.5,7,"Sardine"),new lootTableA(9,16,"Sea Bass"),new lootTableA(15.5,12.5,"Tuna"),new lootTableA(12.5,13.5,"Reef Shark"),new lootTableA(3.5,75,"Squid"),new lootTableA(5,45,"Triggerfish"),new lootTableA(2.25,115,"Electric Eel"),new lootTableA(6.25,25,"Striper"),new lootTableA(1.75,145,"Lobster"),new lootTableA(0.975,160,"Swordfish"),new lootTableA(0.675,235,"Sunfish"),new lootTableA(0.0125,126500,"Walking Minnow"),new lootTableA(0.00565,127500,"Gold Minnow Statue")}; - lootAssigning(totalWeight, event, lt, list); + testList = list; + lootAssigning(totalWeight, event, lt, list); + /* for (int i = 0; i < list.length; i++) { totalWeight = totalWeight + list[i].getChance(); } @@ -163,7 +167,9 @@ public void randomFish(String location, MessageCreateEvent event) { event.getChannel().sendMessage(" You caught a " + lt.name() + "! " + "| You sold this fish for $" + lt.getValue() + " | Your bank account is now at $" + money); */ } else if (location.equals("Trench")) { lootTableA[] list = {new lootTableA(25.65,35,"Telescopefish"),new lootTableA(20.2575,40,"Rhinochimaera"),new lootTableA(15.125,55,"Anglerfish"),new lootTableA(12.25751,60,"Barreleye"),new lootTableA(11.524575,70,"Lanternfish"),new lootTableA(10.2575,75,"Glowing Minnow"),new lootTableA(8.7525,90,"Flying Minnow"),new lootTableA(5.245,125,"Abyssal Grenadier"),new lootTableA(5.65,120,"Marine Hatchetfish"),new lootTableA(2.5,165,"Goblin Shark"),new lootTableA(1.15, 225,"Jellyfish"),new lootTableA(0.75, 345, "Six-Gilled Shark"),new lootTableA(0.000125,35000000,"Snailfish")}; - lootAssigning(totalWeight, event, lt, list); + testList = list; + lootAssigning(totalWeight, event, lt, list); + /* lt2 = lootTableB.Telescopefish; for(int i =0; i < list2.length; i++){ totalWeight = totalWeight + list2[i].getChance(); @@ -183,12 +189,17 @@ public void randomFish(String location, MessageCreateEvent event) { } else if (location.equals("The Coveted Coves")){ lootTableA[] list = {new lootTableA(30,135,"Rockfish"),new lootTableA(22.7525,150,"Golemfish"),new lootTableA(15.752505,245,"Golden Rockfish"),new lootTableA(10.25,275,"Fire-Belly Fish"),new lootTableA(7.5,325,"Lightfish"),new lootTableA(7.5,325,"Darkfish"),new lootTableA(5,300,"Luckfish"),new lootTableA(4.5,400,"Swimming Fossil"),new lootTableA(4.5,425,"Riftfish"),new lootTableA(2.5,535,"Rodfish"),new lootTableA(2,650,"Bronzefish"),new lootTableA(2.5,585,"Moonfish"),new lootTableA(0.5,1475.25,"Boatfish"),new lootTableA(1,875,"Snarefish"),new lootTableA(1.5,750,"Cyclopic Golemfish"),new lootTableA(0.01,12575.25,"Chest of Fish"),new lootTableA(0.0001,1257525.75,"Chest of Precious Fish"),new lootTableA(0.000000001,75254525754525.75,"Bootfish")}; - lootAssigning(totalWeight, event, lt, list); // Fire-Belly Fish could attack the player. Luckfish gives the player a very slight luck increase. Rodfish increases the number of times you can fish by clicking the fish button by one. Boatfish makes the player randomly change to a different location Snarefish trap or delay the player + testList = list; + lootAssigning(totalWeight, event, lt, list); // + // Fire-Belly Fish could attack the player. Luckfish gives the player a very slight luck increase. Rodfish increases the number of times you can fish by clicking the fish button by one. Boatfish makes the player randomly change to a different location Snarefish trap or delay the player } else if (location.equals("Test")){ lootTableA[] list = {new lootTableA(15,10,"Luckfish"),new lootTableA(15,10,"Rodfish"),new lootTableA(15,10,"Boatfish"),new lootTableA(15,10,"Snarefish")}; + testList = list; lootAssigning(totalWeight, event, lt, list); + } + } public void lootAssigning(double totalWeight, MessageCreateEvent event,lootTableA lt,lootTableA[] list){ @@ -581,7 +592,7 @@ public void fishEffect(String fishName, MessageCreateEvent event){ } event.getChannel().sendMessage("Bummer, the Boatfish you caught brought you back to one of your other locations."); break; - case "Rodfish.": + case "Rodfish": event.getChannel().sendMessage("Congrats, the Rodfish you caught brought you another fishing pole, allowing you to fish another time per button press!"); fishTimes = fishTimes + 1; break; diff --git a/src/test/java/org/jointheleague/features/student/third_feature/FeatureThreeTest.java b/src/test/java/org/jointheleague/features/student/third_feature/FeatureThreeTest.java index 8d32df82..8e9be256 100644 --- a/src/test/java/org/jointheleague/features/student/third_feature/FeatureThreeTest.java +++ b/src/test/java/org/jointheleague/features/student/third_feature/FeatureThreeTest.java @@ -2,6 +2,9 @@ import org.javacord.api.entity.channel.TextChannel; import org.javacord.api.event.message.MessageCreateEvent; +import org.javacord.api.interaction.MessageComponentInteraction; +import org.javacord.api.listener.interaction.MessageComponentCreateListener; +import org.javacord.api.util.event.ListenerManager; import org.jointheleague.features.help_embed.plain_old_java_objects.help_embed.HelpEmbed; import org.jointheleague.features.templates.FeatureTemplate; import org.junit.jupiter.api.AfterEach; @@ -12,9 +15,10 @@ import java.io.ByteArrayOutputStream; import java.io.PrintStream; +import java.util.ArrayList; +import java.util.Arrays; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.*; @@ -33,6 +37,7 @@ public class FeatureThreeTest { @Mock private TextChannel textChannel; + @BeforeEach void setUp() { MockitoAnnotations.openMocks(this); @@ -116,4 +121,48 @@ void itShouldHaveTheCommandAsTheTitleOfTheHelpEmbed() { //Then assertEquals(command, helpEmbedTitle); } + + @Test + void itShouldApplyFishEffect(){ + featureThree.money = 125.00; + featureThree.location = "The Coveted Coves"; + featureThree.luckModifier = 0.0; + featureThree.fishTimes = 1; + double PreMoney = featureThree.money; + when(messageCreateEvent.getChannel()).thenReturn(textChannel); + featureThree.fishEffect("Luckfish", messageCreateEvent); + featureThree.fishEffect("Boatfish", messageCreateEvent); + featureThree.fishEffect("Rodfish", messageCreateEvent); + featureThree.fishEffect("Snarefish", messageCreateEvent); + assert(PreMoney > featureThree.money); + assertEquals(1.25,featureThree.luckModifier, 0); + assert(!featureThree.location.equals("The Coveted Coves")); + assertEquals(2, featureThree.fishTimes); + } + + @Test + void itShouldFeedLocationalDataWhenUsingRandomFish(){ + //lootTableA[] expected + //System.out.println("TEST"); + //System.out.println("TESTEST"); + featureThree.location = "Trench"; +when(messageCreateEvent.getChannel()).thenReturn(textChannel); +//when(messageCreateEvent.getChannel().sendMessage("")).thenReturn(null); + featureThree.randomFish(featureThree.location, messageCreateEvent); + // lootTableA[] test = {}; +//when(featureThree.lootAssigning()).thenReturn(test); + lootTableA[] expected = {new lootTableA(25.65,35,"Telescopefish"),new lootTableA(20.2575,40,"Rhinochimaera"),new lootTableA(15.125,55,"Anglerfish"),new lootTableA(12.25751,60,"Barreleye"),new lootTableA(11.524575,70,"Lanternfish"),new lootTableA(10.2575,75,"Glowing Minnow"),new lootTableA(8.7525,90,"Flying Minnow"),new lootTableA(5.245,125,"Abyssal Grenadier"),new lootTableA(5.65,120,"Marine Hatchetfish"),new lootTableA(2.5,165,"Goblin Shark"),new lootTableA(1.15, 225,"Jellyfish"),new lootTableA(0.75, 345, "Six-Gilled Shark"),new lootTableA(0.000125,35000000,"Snailfish")}; + //System.out.println(expected); + // System.out.println(featureThree.testList); + assertNotEquals(featureThree.testList, null); + //assertEquals(expected, featureThree.testList); + //System.err.println(featureThree.testList[0]); + //System.err.println(expected[0]); + for(int i =0; i < featureThree.testList.length; i++) { + assertTrue(expected[i].name().equals(featureThree.testList[i].name())); + assertTrue(expected[i].getValue()==featureThree.testList[i].getValue()); + assertTrue(expected[i].getChance()==featureThree.testList[i].getChance()); + } + } + //All other features without a test written in this file have been tested manually and have an issue with the way there are coded that makes them unable to have an accurate test written without major rewrites. } From b11304fa49682149d6938285d9169556b31d6236 Mon Sep 17 00:00:00 2001 From: Branson778 Date: Sun, 17 Dec 2023 15:14:32 -0800 Subject: [PATCH 11/12] Bug Fixing With Gradle Building Test 1 --- .../features/student/third_feature/FeatureThree.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/jointheleague/features/student/third_feature/FeatureThree.java b/src/main/java/org/jointheleague/features/student/third_feature/FeatureThree.java index 4ef63bed..76daa617 100644 --- a/src/main/java/org/jointheleague/features/student/third_feature/FeatureThree.java +++ b/src/main/java/org/jointheleague/features/student/third_feature/FeatureThree.java @@ -557,7 +557,7 @@ void lobsterPotLuck(MessageCreateEvent event){ //event.getChannel().sendMessage("TESTPOT"); int pot = 16; Random ran = new Random(); - double ranint = ran.nextDouble(pot); + double ranint = ran.nextDouble()*pot; if (ranint >= (pot - 2 - luckModifier / 16)) { lobsters.set(i, lobsters.get(i) + (ran.nextInt(2 + locations.size()) + 1)); //event.getChannel().sendMessage("Congrats, lobsters added. TESTMESSAGE"); From ab1f6ff6e3ca35ba7b0e1f8bd4b98b7de5ae51bc Mon Sep 17 00:00:00 2001 From: Branson778 Date: Sun, 17 Dec 2023 15:24:26 -0800 Subject: [PATCH 12/12] Bug Fixing 2 --- .../features/student/third_feature/FeatureThree.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/jointheleague/features/student/third_feature/FeatureThree.java b/src/main/java/org/jointheleague/features/student/third_feature/FeatureThree.java index 76daa617..bf7aa31b 100644 --- a/src/main/java/org/jointheleague/features/student/third_feature/FeatureThree.java +++ b/src/main/java/org/jointheleague/features/student/third_feature/FeatureThree.java @@ -215,8 +215,8 @@ public void lootAssigning(double totalWeight, MessageCreateEvent event,lootTable //lootTableB[] list2 = {new lootTableB(0.00125,0.01, "Sub-Atomic", "🥇"),new lootTableB(0.25, 0.1, "Mircoscopic", "🥈"), new lootTableB(1,0.125,"Miniature","🥉"),new lootTableB(10,0.75,"Tiny","🏅"),new lootTableB(25.75,1,"Small","🏅"),new lootTableB(15.6525,1.25,"Medium","🏅"),new lootTableB(6.675,1.65,"Large","🏅"),new lootTableB(2.35,2.35,"Huge","🥉"),new lootTableB(1.25,3.15,"Gigantic","🥉"),new lootTableB(0.75,4,"Titanic","🥉"),new lootTableB(0.25,5.65,"Humongous","🥈"), new lootTableB(0.15,7.5,"Ginormous","🥈"),new lootTableB(0.015,12.75,"Record-Breaking","🥇"),new lootTableB(0.00125,100.75,"Cosmic","🌌"),new lootTableB(0.000165,2575.45,"Special","🎖")}; Random random = new Random(); - double ran = random.nextDouble(totalWeight)+luckModifier/10.75; - double ran2 = random.nextDouble(totalWeight2)+luckModifier/17.25; + double ran = random.nextDouble()*totalWeight+luckModifier/10.75; + double ran2 = random.nextDouble()*totalWeight2+luckModifier/17.25; totalWeight =0; totalWeight2 =0; for(int i =0; i < list.length; i++){ @@ -501,14 +501,14 @@ else if(money<12750.25 && !bought[13]){ case "14": //1500000 if(money>=1500000.00 && !bought[14]) { - money = money - 650.75; + money = money - 1500000.00; //luckModifier = luckModifier + 5.75; //fishTimes = fishTimes + 2; win = "🏆 Winner! 🏆 |"; event.getChannel().sendMessage("Congrats, you now are retired! You can still fish, but you finally feel accomplished and have won this game."); bought[14] = true; } - else if(money<650.75 && !bought[14]){ + else if(money<1500000.00 && !bought[14]){ event.getChannel().sendMessage("You cannot afford this item."); } else{ @@ -599,7 +599,7 @@ public void fishEffect(String fishName, MessageCreateEvent event){ case "Snarefish": // try { ran = new Random(); - double random = ran.nextDouble(money-1)+1; + double random = ran.nextDouble()*(money-1)+1; BigDecimal bd = new BigDecimal(random).setScale(2, RoundingMode.HALF_UP); random = bd.doubleValue(); money = money-random;