-
Notifications
You must be signed in to change notification settings - Fork 5
Add plugin to track enhancing #146
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
Open
seashairo
wants to merge
7
commits into
Ishadijcks:develop
Choose a base branch
from
seashairo:feature/enhancing-tracker
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8882ccd
Add plugin to track enhancing
seashairo 2d37856
How do I always forget the fucking linter?
seashairo 5c3772d
Untype ActionHrid
seashairo 9e42055
Resolve merge conflicts
seashairo 0a77f83
DRY
seashairo 2b57259
Weird that that didn't error
seashairo 763fa5a
Fix some rendering - numbers didn't look quite right
seashairo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import { ItemHrid } from "../ItemHrid"; | ||
| import { ItemLocationHrid } from "../ItemLocationHrid"; | ||
|
|
||
| export interface ItemHashParts { | ||
| characterId: number; | ||
| itemLocationHrid: ItemLocationHrid; | ||
| itemHrid: ItemHrid; | ||
| enhancementLevel: number; | ||
| } | ||
|
|
||
| /** | ||
| * An item hash looks like | ||
| * `123456::/item_locations/inventory::/items/cheese_enhancer::0` | ||
| * This function will break it down into its component parts so they can be | ||
| * used elsewhere, like when tracking what items are being used for enhancing. | ||
| * | ||
| * @param itemHash - the hash to deconstruct, should be in the above format | ||
| * @returns a deconstructed item hash | ||
| */ | ||
| export function decodeItemHash(itemHash: string): ItemHashParts { | ||
| const parts = itemHash.split("::"); | ||
|
|
||
| return { | ||
| characterId: parseInt(parts[0]), | ||
| itemLocationHrid: parts[1] as any as ItemLocationHrid, | ||
| itemHrid: parts[2] as any as ItemHrid, | ||
| enhancementLevel: parseInt(parts[3]), | ||
| }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| export enum ClientMessageType { | ||
| Ping = "/character_tasks/ping", | ||
| Ping = "ping", | ||
|
seashairo marked this conversation as resolved.
|
||
| } | ||
130 changes: 130 additions & 0 deletions
130
src/MooLite/plugins/EnhancingTracker/EnhancingTrackerPlugin.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| import { MooLitePlugin } from "src/MooLite/core/plugins/MooLitePlugin"; | ||
| import { MooLiteTab } from "src/MooLite/core/plugins/MooLiteTab"; | ||
| import EnhancingTrackerPluginDisplay from "src/MooLite/plugins/EnhancingTracker/EnhancingTrackerPluginDisplay.vue"; | ||
| import { markRaw } from "vue"; | ||
| import { PluginAuthorCredits } from "src/MooLite/core/plugins/PluginAuthorCredits"; | ||
| import { ItemDetail } from "src/MooLite/core/inventory/items/ItemDetail"; | ||
| import { ItemHrid } from "src/MooLite/core/inventory/ItemHrid"; | ||
| import { CharacterAction } from "src/MooLite/core/actions/CharacterAction"; | ||
| import { ItemHashParts, decodeItemHash } from "src/MooLite/core/inventory/items/decodeItemHash"; | ||
| import { ItemAmount } from "src/MooLite/core/inventory/items/ItemAmount"; | ||
| import { ActionHrid } from "src/MooLite/core/actions/ActionHrid"; | ||
|
|
||
| export class EnhancingTrackerPlugin extends MooLitePlugin { | ||
| name: string = "Enhancing Tracker"; | ||
| key = "enhancing-tracker"; | ||
| description: string = "Tracks materials consumed during enhancing."; | ||
|
|
||
| credits: PluginAuthorCredits = { | ||
| author: "seashairo", | ||
| maintainer: "seashairo", | ||
| }; | ||
|
|
||
| tab: MooLiteTab = { | ||
| icon: "⭐", | ||
| pluginName: this.name, | ||
| componentName: "EnhancingTrackerPluginDisplay", | ||
| component: markRaw(EnhancingTrackerPluginDisplay), | ||
| }; | ||
|
|
||
| public get itemDetailMap(): Record<ItemHrid, ItemDetail> { | ||
| return this._game.inventory.itemDetailMap; | ||
| } | ||
|
|
||
| itemBeingEnhancedHrid: ItemHrid | null = null; | ||
| itemsConsumed: Record<ItemHrid, number> = {}; | ||
| bestEnhancementLevel: number = 0; | ||
| successes: number = 0; | ||
| failures: number = 0; | ||
| blessedTeaProcs: number = 0; | ||
| itemState: ItemHashParts | null = null; | ||
| previousAction: CharacterAction | null = null; | ||
|
|
||
| public get successRate(): number { | ||
| const attempts = this.successes + this.failures; | ||
| return attempts === 0 ? 0 : (this.successes / attempts) * 100; | ||
| } | ||
|
|
||
| onActionQueueUpdated(queue: CharacterAction[]): void { | ||
| const currentAction = queue.length ? queue[0] : null; | ||
|
|
||
| const enhancing = "/actions/enhancing/enhance" as unknown as ActionHrid; | ||
| const currentActionIsEnhancing = currentAction?.actionHrid === enhancing; | ||
| const previousActionIsEnhancing = this.previousAction?.actionHrid === enhancing; | ||
|
|
||
| if (currentActionIsEnhancing) { | ||
| previousActionIsEnhancing | ||
| ? this.handleEnhancing(currentAction) | ||
| : this.handleStartedEnhancing(currentAction); | ||
| } | ||
|
|
||
| this.previousAction = currentAction; | ||
| } | ||
|
|
||
| handleStartedEnhancing(currentAction: CharacterAction): void { | ||
| const itemHashParts = decodeItemHash(currentAction.upgradeItemHash); | ||
| this.itemState = itemHashParts; | ||
| this.itemBeingEnhancedHrid = itemHashParts.itemHrid; | ||
| this.bestEnhancementLevel = itemHashParts.enhancementLevel; | ||
| this.itemsConsumed = {}; | ||
| } | ||
|
|
||
| addConsumedItem(itemAmount: ItemAmount): void { | ||
| itemAmount.itemHrid in this.itemsConsumed | ||
| ? (this.itemsConsumed[itemAmount.itemHrid] += itemAmount.count) | ||
| : (this.itemsConsumed[itemAmount.itemHrid] = itemAmount.count); | ||
| } | ||
|
|
||
| handleEnhancing(currentAction: CharacterAction): void { | ||
| const currentItemState = decodeItemHash(currentAction.upgradeItemHash); | ||
| const itemBeingEnhancedHrid = currentItemState.itemHrid; | ||
|
|
||
| // If the item being enhanced has changed hrid, then we're enhancing | ||
| // something new. | ||
| // | ||
| // TODO: Handle this more gracefully. Maybe store a dict of enhancing | ||
| // data against hrid to display a table? | ||
| if (this.itemBeingEnhancedHrid !== itemBeingEnhancedHrid) { | ||
| return this.handleStartedEnhancing(currentAction); | ||
| } | ||
|
|
||
| // Instead of watching the items gained and lost, we want to use the | ||
| // item's enhancement cost. This is because players using the market | ||
| // will hit the onItemGained handler and leave the count inaccurate. | ||
| // | ||
| // TODO: When Blessed Tea procs, do you use 1 or 2 sets of consumables? | ||
| // If it's 1 then this is accurate, but if it's 2 then this logic would | ||
| // need to be part of the level check below | ||
| const enhancingCosts = this._game.inventory.itemDetailMap[itemBeingEnhancedHrid].enhancementCosts; | ||
| enhancingCosts!.forEach((itemAmount) => this.addConsumedItem(itemAmount)); | ||
|
|
||
| const itemState = this.itemState!; | ||
| if (currentItemState.enhancementLevel > itemState.enhancementLevel) { | ||
| const diff = currentItemState.enhancementLevel - itemState.enhancementLevel; | ||
| this.successes += 1; | ||
| // I'm pretty sure the level diff will only ever be 1 or 2, but just | ||
| // in case blessed tea can multi-proc we'll check for anything | ||
| // greater than 1. I'm also assuming (but haven't confirmed) that a | ||
| // blessed tea proc will still be in a single action update and not | ||
| // two separate ones. | ||
| if (diff > 1) { | ||
| this.blessedTeaProcs += 1; | ||
| } | ||
| } else { | ||
| this.failures += 1; | ||
|
|
||
| // Protections don't get counted in the regular consumed items | ||
| // report, so if we drop an enhancement level then we need to | ||
| // manually count a lost protection. | ||
| const protectionHash = currentAction.enhancingProtectionItemHash; | ||
| if (protectionHash !== "" && itemState.enhancementLevel >= currentAction.enhancingProtectionItemMinLevel) { | ||
| const itemHrid = decodeItemHash(protectionHash).itemHrid; | ||
| this.addConsumedItem({ itemHrid, count: 1 }); | ||
| } | ||
| } | ||
|
|
||
| this.bestEnhancementLevel = Math.max(currentItemState.enhancementLevel, this.bestEnhancementLevel); | ||
|
|
||
| this.itemState = currentItemState; | ||
| } | ||
| } |
52 changes: 52 additions & 0 deletions
52
src/MooLite/plugins/EnhancingTracker/EnhancingTrackerPluginDisplay.vue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| <script setup lang="ts"> | ||
| import { Ref, ref } from "vue"; | ||
| import { EnhancingTrackerPlugin } from "src/MooLite/plugins/EnhancingTracker/EnhancingTrackerPlugin"; | ||
| import { ItemAmount } from "src/MooLite/core/inventory/items/ItemAmount"; | ||
| import MooDivider from "src/components/atoms/MooDivider.vue"; | ||
| import ItemIcon from "src/components/atoms/ItemIcon.vue"; | ||
|
|
||
| const props = defineProps<{ | ||
| plugin: EnhancingTrackerPlugin; | ||
| }>(); | ||
|
|
||
| const loot: Ref<ItemAmount[]> = ref([]); | ||
| </script> | ||
|
|
||
| <template> | ||
| <div class="flex flex-col gap-2"> | ||
| <span class="text-center">{{ props.plugin.name }}</span> | ||
|
|
||
| <MooDivider /> | ||
|
|
||
| <div v-if="plugin.itemBeingEnhancedHrid" class="flex flex-col gap-2"> | ||
| <div class="flex items-center justify-between"> | ||
| <p>Enhancing {{ plugin.itemDetailMap[plugin.itemBeingEnhancedHrid].name }}</p> | ||
| <ItemIcon :item="plugin.itemBeingEnhancedHrid" class="inline" /> | ||
| </div> | ||
|
|
||
| <hr /> | ||
|
|
||
| <div> | ||
| <p>Items consumed</p> | ||
| <p v-if="Object.keys(plugin.itemsConsumed).length === 0">None!</p> | ||
| <div v-for="(value, key) in plugin.itemsConsumed" class="flex items-center justify-between"> | ||
| <span> | ||
| <ItemIcon :item="key" class="inline" /> | ||
| {{ plugin.itemDetailMap[key].name }} | ||
| </span> | ||
| <p>{{ value }}</p> | ||
| </div> | ||
| </div> | ||
|
|
||
| <p>Best enhancement level: {{ plugin.bestEnhancementLevel }}</p> | ||
| <p> | ||
| Success rate: {{ plugin.successRate.toFixed(2) }}% ({{ plugin.successes }} / | ||
| {{ plugin.successes + plugin.failures }}) | ||
| </p> | ||
| </div> | ||
|
|
||
| <div v-if="!plugin.itemBeingEnhancedHrid" class="flex flex-col gap-2"> | ||
| <p>It doesn't look like you're enhancing anything at the moment. Try it out!</p> | ||
| </div> | ||
| </div> | ||
| </template> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,7 +15,7 @@ const imgUrl = computed(() => { | |
| const split = (props.item as unknown as string).split("/"); | ||
| const itemPostfix = split[split.length - 1]; | ||
| // TODO(@Isha): Research how these CDN resource urls are generated | ||
| return `/static/media/items_sprite.951ef1ec.svg#${itemPostfix}`; | ||
| return `/static/media/items_sprite.018a3c6e.svg#${itemPostfix}`; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have you figured out how these work? :p
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No idea :D |
||
| }); | ||
| </script> | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.