Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Add overflow crop milestones #997

Merged
merged 33 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
afeb540
Add overflow crop milestones
qtlunya Dec 14, 2023
67e28b9
Changes from HiZe
superhize Feb 24, 2024
872c380
Fix
qtlunya Feb 24, 2024
8b83202
Remove test command
qtlunya Feb 24, 2024
ff67996
Address review comments
qtlunya Feb 24, 2024
31e9efc
Cleanup
qtlunya Feb 24, 2024
fe2cb65
Forgot to commit these
qtlunya Feb 24, 2024
41d9810
No more property
qtlunya Feb 25, 2024
8a54410
Fix access
qtlunya Feb 25, 2024
19e9cd9
I don't know what this is doing here
qtlunya Feb 29, 2024
e27db1e
Merge remote-tracking branch 'origin/beta' into overflow-milestones
qtlunya Feb 29, 2024
ffe6e70
Merge branch 'beta' into fork/overflow-milestones
hannibal002 Mar 7, 2024
1466146
Address some review comments
qtlunya Apr 6, 2024
addbf94
Fix build error
qtlunya Apr 6, 2024
a175c66
Address review comments - Part 2
qtlunya Apr 6, 2024
2f79362
Merge remote-tracking branch 'origin/beta' into overflow-milestones
qtlunya Apr 6, 2024
3b1593e
Merge branch 'beta' into fork/overflow-milestones
hannibal002 Apr 24, 2024
ff3809d
fix merge conflicts
hannibal002 Apr 24, 2024
e10ae05
move CropMilestonesOverflowConfig into own class
hannibal002 Apr 24, 2024
a2d265b
code cleanup
hannibal002 Apr 24, 2024
720f289
code cleanup
hannibal002 Apr 24, 2024
9caa101
fix crop milestone display not working when main toggle and display t…
hannibal002 Apr 24, 2024
e9b9caa
make best crop time independent overflow check
hannibal002 Apr 24, 2024
9f88e7d
rename to crop milestone display
hannibal002 Apr 24, 2024
cfcb89b
fewer variable confusion by extracting into more functions
hannibal002 Apr 24, 2024
a7ec34d
add todos
hannibal002 Apr 24, 2024
b32c3c8
code cleanup
hannibal002 Apr 24, 2024
e8cb265
Merge branch 'beta' into fork/overflow-milestones
hannibal002 May 1, 2024
e89ee91
Apply suggestions from code review
qtlunya May 3, 2024
046894a
Improve some config descriptions
qtlunya May 3, 2024
6a38a2a
Use isRoman
qtlunya May 3, 2024
806a339
Add TODO
qtlunya May 3, 2024
52cefb4
Merge branch 'beta' into fork/overflow-milestones
hannibal002 May 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ import at.hannibal2.skyhanni.features.garden.inventory.AnitaExtraFarmingFortune
import at.hannibal2.skyhanni.features.garden.inventory.GardenCropMilestoneInventory
import at.hannibal2.skyhanni.features.garden.inventory.GardenDeskInSBMenu
import at.hannibal2.skyhanni.features.garden.inventory.GardenInventoryNumbers
import at.hannibal2.skyhanni.features.garden.inventory.GardenInventoryTooltipOverflow
import at.hannibal2.skyhanni.features.garden.inventory.GardenNextPlotPrice
import at.hannibal2.skyhanni.features.garden.inventory.GardenPlotIcon
import at.hannibal2.skyhanni.features.garden.inventory.SkyMartCopperPrice
Expand Down Expand Up @@ -753,6 +754,7 @@ class SkyHanniMod {
loadModule(HighlightInquisitors())
loadModule(VerminTracker)
loadModule(SkillProgress)
loadModule(GardenInventoryTooltipOverflow())
loadModule(SkillTooltip())
loadModule(QuiverNotification)
loadModule(MaxPurseItems())
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/at/hannibal2/skyhanni/config/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,9 @@ public static class FarmingWeightConfig {

@Expose
public Map<String, LorenzVec> npcVisitorLocations = new HashMap<>();

@Expose
public Map<CropType, Integer> customGoalMilestone = new HashMap<>();
}

@Expose
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import at.hannibal2.skyhanni.api.SkillAPI
import at.hannibal2.skyhanni.config.ConfigFileType
import at.hannibal2.skyhanni.config.ConfigGuiManager
import at.hannibal2.skyhanni.data.ChatManager
import at.hannibal2.skyhanni.data.GardenCropMilestones
import at.hannibal2.skyhanni.data.GardenCropMilestonesCommunityFix
import at.hannibal2.skyhanni.data.GuiEditManager
import at.hannibal2.skyhanni.data.PartyAPI
Expand Down Expand Up @@ -285,6 +286,14 @@ object Commands {
},
FarmingMilestoneCommand::onComplete
)
registerCommand0(
"shcropgoal",
"Define a custom milestone goal for a crop.",
{
FarmingMilestoneCommand.setGoal(it.getOrNull(0), it.getOrNull(1))
},
FarmingMilestoneCommand::onComplete
)
}

private fun usersBugFix() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,39 @@ public class CropMilestonesConfig {
@FeatureToggle
public boolean progress = true;

@Expose
@ConfigOption(name = "Overflow", desc = "")
@Accordion
public Overflow overflow = new Overflow();

public static class Overflow {

@Expose
@ConfigOption(name = "Display", desc = "Overflow in display.")
@ConfigEditorBoolean
public boolean display = false;

@Expose
@ConfigOption(name = "Inventory", desc = "Overflow as stack size in crop milestones inventory. (will change milestones avg too.")
@ConfigEditorBoolean
public boolean inventoryStackSize = false;

@Expose
@ConfigOption(name = "Tooltip", desc = "Show overflow level progress in the item tooltip on the garden crop milestones inventory.")
@ConfigEditorBoolean
public boolean inventoryTooltip = false;

@Expose
@ConfigOption(name = "Discord RPC", desc = "Overflow in discord RPC milestones display.")
@ConfigEditorBoolean
public boolean discordRPC = false;

@Expose
@ConfigOption(name = "Chat", desc = "Send chat message when gaining overflow level.")
@ConfigEditorBoolean
public boolean chat = false;
}

@Expose
@ConfigOption(
name = "Warn When Close",
Expand Down Expand Up @@ -89,6 +122,13 @@ public String toString() {
@ConfigEditorBoolean
public Property<Boolean> bestShowMaxedNeeded = Property.of(false);

@Expose
@ConfigOption(
name = "Overflow Milestones",
desc = "Show overflow crop milestones beyond 46.")
@ConfigEditorBoolean
public boolean overflowMilestones = false;

@Expose
@ConfigOption(
name = "Milestone Text",
Expand Down
135 changes: 123 additions & 12 deletions src/main/java/at/hannibal2/skyhanni/data/GardenCropMilestones.kt
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
package at.hannibal2.skyhanni.data

import at.hannibal2.skyhanni.data.jsonobjects.repo.GardenJson
import at.hannibal2.skyhanni.events.CropMilestoneOverflowLevelUpEvent
import at.hannibal2.skyhanni.events.CropMilestoneUpdateEvent
import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent
import at.hannibal2.skyhanni.events.LorenzTickEvent
import at.hannibal2.skyhanni.events.RepositoryReloadEvent
import at.hannibal2.skyhanni.features.garden.CropType
import at.hannibal2.skyhanni.features.garden.GardenAPI
import at.hannibal2.skyhanni.features.garden.GardenAPI.getCropType
import at.hannibal2.skyhanni.utils.ChatUtils.chat
import at.hannibal2.skyhanni.utils.InventoryUtils
import at.hannibal2.skyhanni.utils.ItemUtils.getLore
import at.hannibal2.skyhanni.utils.NumberUtil.formatNumber
import at.hannibal2.skyhanni.utils.SoundUtils
import at.hannibal2.skyhanni.utils.SoundUtils.playSound
import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import net.minecraft.item.ItemStack
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent

object GardenCropMilestones {

private val patternGroup = RepoPattern.group("data.garden.milestone")
private val cropPattern by patternGroup.pattern(
"crop",
Expand All @@ -24,6 +32,8 @@ object GardenCropMilestones {
"§7Total: §a(?<name>.*)"
)

private val config get() = GardenAPI.config.cropMilestones

fun getCropTypeByLore(itemStack: ItemStack): CropType? {
for (line in itemStack.getLore()) {
cropPattern.matchMatcher(line) {
Expand Down Expand Up @@ -51,6 +61,73 @@ object GardenCropMilestones {
GardenCropMilestonesCommunityFix.openInventory(event.inventoryItems)
}

/**
* Just for me testing
*/
qtlunya marked this conversation as resolved.
Show resolved Hide resolved
var enabled = false
var menabled = false
var curr = 0L
var mcurr = 0L
var add = 0L
var madd = 0L

@SubscribeEvent
fun onTick(event: LorenzTickEvent) {
if (enabled) {
val stack = InventoryUtils.getItemInHand()
val crop = stack?.getCropType() ?: return
val old = crop.getCounter()
val toAdd = old + add
crop.setCounter(toAdd)
curr = toAdd
} else if (menabled) {
val mush = CropType.MUSHROOM
val mold = mush.getCounter()
val mtoAdd = mold + madd
mush.setCounter(mtoAdd)
mcurr = mtoAdd
}
}

@SubscribeEvent
fun onCropMilestoneOverflowLevelUp(event: CropMilestoneOverflowLevelUpEvent) {
val crop = event.cropType
val oldLevel = event.oldLevel
val newLevel = event.newLevel
val customGoalLevel = ProfileStorageData.profileSpecific?.garden?.customGoalMilestone?.get(crop) ?: 0
val goalReached = newLevel == customGoalLevel

val rewards = buildList {
CalMWolfs marked this conversation as resolved.
Show resolved Hide resolved
qtlunya marked this conversation as resolved.
Show resolved Hide resolved
add(" §r§8+§aRespect from Elite Farmers and SkyHanni members :)")
add(" §r§8+§b1 Flexing Point")
if (newLevel % 5 == 0)
add(" §r§7§8+§d2 SkyHanni User Luck")
}

val messages = listOf(
"§r§3§l▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬§r",
" §r§b§lGARDEN MILESTONE §3${crop.cropName} §8$oldLevel➜§3$newLevel§r",
if (goalReached)
listOf(
"",
" §r§d§lGOAL REACHED!",
"",
).joinToString("\n")
else
"",
" §r§a§lREWARDS§r",
rewards.joinToString("\n"),
"§r§3§l▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬§r"
)

chat(messages.joinToString("\n"), false)

if (goalReached)
chat("§e§lYou have reached your milestone goal of §b§l${customGoalLevel} §e§lin the §b§l${crop.cropName} §e§lcrop!", false)

SoundUtils.createSound("random.levelup", 1f, 1f).playSound()
}

var cropMilestoneData: Map<CropType, List<Int>> = emptyMap()

val cropCounter: MutableMap<CropType, Long>? get() = GardenAPI.storage?.cropCounter
Expand All @@ -63,49 +140,83 @@ object GardenCropMilestones {
}

fun CropType.isMaxed(): Boolean {
if (config.overflowMilestones) return false

// TODO change 1b
val maxValue = cropMilestoneData[this]?.sum() ?: 1_000_000_000 // 1 bil for now
return getCounter() >= maxValue
}

fun getTierForCropCount(count: Long, crop: CropType): Int {
fun getTierForCropCount(count: Long, crop: CropType, allowOverflow: Boolean = false): Int {
var tier = 0
var totalCrops = 0L
val cropMilestone = cropMilestoneData[crop] ?: return 0
val last = cropMilestone.last()

for (tierCrops in cropMilestone) {
totalCrops += tierCrops
if (totalCrops > count) {
if (totalCrops >= count) {
return tier
}
tier++
}

if (allowOverflow) {
while (totalCrops < count) {
totalCrops += last
if (totalCrops >= count) {
return tier
}
tier++
}
}
return tier
}

fun getMaxTier() = cropMilestoneData.values.firstOrNull()?.size ?: 0

fun getCropsForTier(requestedTier: Int, crop: CropType): Long {
fun getCropsForTier(requestedTier: Int, crop: CropType, allowOverflow: Boolean = false): Long {
var totalCrops = 0L
var tier = 0
val cropMilestone = cropMilestoneData[crop] ?: return 0
val definedTiers = cropMilestone.size

if (requestedTier <= definedTiers || !allowOverflow) {
for (tierCrops in cropMilestone) {
totalCrops += tierCrops
tier++
if (tier == requestedTier) {
return totalCrops
}
}

return if (!allowOverflow) 0 else totalCrops
}


for (tierCrops in cropMilestone) {
totalCrops += tierCrops
tier++
if (tier == requestedTier) {
return totalCrops
}
}

return 0
if (requestedTier > definedTiers && allowOverflow) {
qtlunya marked this conversation as resolved.
Show resolved Hide resolved

val additionalTiers = requestedTier - definedTiers

val lastIncrement = cropMilestone.last().toLong()

totalCrops += lastIncrement * additionalTiers
}

return totalCrops
}

fun CropType.progressToNextLevel(): Double {
fun CropType.progressToNextLevel(allowOverflow: Boolean = false): Double {
val progress = getCounter()
val startTier = getTierForCropCount(progress, this)
val startCrops = getCropsForTier(startTier, this)
val end = getCropsForTier(startTier + 1, this).toDouble()
return (progress - startCrops) / (end - startCrops)
val startTier = getTierForCropCount(progress, this, allowOverflow)
val startCrops = getCropsForTier(startTier, this, allowOverflow)
val end = getCropsForTier(startTier + 1, this, allowOverflow)
return (progress - startCrops).toDouble() / (end - startCrops)
}

@SubscribeEvent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,7 @@ object GardenCropMilestonesCommunityFix {
// debug("crop: $crop")
// debug("realTier: $realTier")

val guessNextMax = GardenCropMilestones.getCropsForTier(
realTier + 1,
crop
) - GardenCropMilestones.getCropsForTier(realTier, crop)
val guessNextMax = GardenCropMilestones.getCropsForTier(realTier + 1, crop) - GardenCropMilestones.getCropsForTier(realTier, crop)
// debug("guessNextMax: ${guessNextMax.addSeparators()}")
val nextMax = amountPattern.matchMatcher(next) {
group("max").formatNumber()
Expand All @@ -105,7 +102,7 @@ object GardenCropMilestonesCommunityFix {
wrongData.add("$crop:$realTier:${nextMax.addSeparators()}")
}

val guessTotalMax = GardenCropMilestones.getCropsForTier(46, crop)
val guessTotalMax = GardenCropMilestones.getCropsForTier(46, crop) // no need to overflow here
// println("guessTotalMax: ${guessTotalMax.addSeparators()}")
val totalMax = amountPattern.matchMatcher(total) {
group("max").formatNumber()
Expand Down Expand Up @@ -163,13 +160,8 @@ object GardenCropMilestonesCommunityFix {
}

private fun tryFix(crop: CropType, tier: Int, amount: Int): Boolean {
val guessNextMax = GardenCropMilestones.getCropsForTier(tier + 1, crop) - GardenCropMilestones.getCropsForTier(
tier,
crop
)
if (guessNextMax.toInt() == amount) {
return false
}
val guessNextMax = GardenCropMilestones.getCropsForTier(tier + 1, crop) - GardenCropMilestones.getCropsForTier(tier, crop)
if (guessNextMax.toInt() == amount) return false
GardenCropMilestones.cropMilestoneData = GardenCropMilestones.cropMilestoneData.editCopy {
fix(crop, this, tier, amount)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package at.hannibal2.skyhanni.events

import at.hannibal2.skyhanni.features.garden.CropType

class CropMilestoneOverflowLevelUpEvent(val cropType: CropType, val oldLevel: Int, val newLevel: Int) : LorenzEvent()
qtlunya marked this conversation as resolved.
Show resolved Hide resolved
Loading
Loading