forked from wowsims/cata
-
Notifications
You must be signed in to change notification settings - Fork 38
[Feature] Generic secondary resources #54
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
bbf50c3
[Feature] Generic secondary resouces
2e79f66
Merge branch 'master' into feature/generic-resources
1337LutZ 837193f
Remove unintended file
eda54c5
[Feature]Generic Resoruces: Update implementation and replace Holy P…
5d1fe07
[Feature] Generic Resources: Remove line comments from test
98dd829
[Feature] Generic Resource: Remove old proto mappings
ddea63f
[Feature] Generic resources - Part 1 APL implementation
758fb68
[Feature] Generic Resource: Add support for callbacks
c49ff3c
[Feature] Generic Resource: Add missing callback invoke
5d8d680
Add SecondaryResource class & extend APL dynamic string
1337LutZ 1bd49b8
Merge branch 'feature/generic-resources' of https://github.com/wowsim…
1337LutZ d53ff8a
[Feature] Generic Resource: Fix APL
b1592a1
[Feature] Generic Resources: Make bar track Int32
0022a93
[Feature] Generic Resource: Update resource implementation
c4c9ecf
[Feature] Generic Resources: Make resource bar private to core
014be3c
[Feature] Generic Resource: Map secondary resource names correctly in…
e1ed415
Merge remote-tracking branch 'origin/master' into feature/generic-res…
5ac1cb8
[Feature] Generic resource: Remove chi from secondary resources
44bce62
Merge branch 'master' into feature/generic-resources
54c93d8
[Feature] Generic Resouce: Fixup unintended removed code
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
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,143 @@ | ||
| // Implements a generic resource bar that can be used to implement secondary resources | ||
| // TODO: Check whether pre-pull OOC resource loss needs to be supported for DemonicFury | ||
| package core | ||
|
|
||
| import "math" | ||
|
|
||
| type SecondaryResourceType int32 | ||
|
|
||
| const ( | ||
| SoulShards SecondaryResourceType = 117198 | ||
| HolyPower SecondaryResourceType = 138248 | ||
| Maelstrom SecondaryResourceType = 53817 | ||
| Chi SecondaryResourceType = 97272 | ||
| ArcaneCharges SecondaryResourceType = 36032 | ||
| ShadowOrbs SecondaryResourceType = 95740 | ||
| BurningEmbers SecondaryResourceType = 108647 | ||
| DemonicFury SecondaryResourceType = 104315 | ||
| ) | ||
|
|
||
| type SecondaryResourceBar interface { | ||
| CanSpend(limit float64) bool // Check whether the current resource is available or not | ||
| Spend(amount float64, action ActionID, sim *Simulation) // Spend the specified amount of resource | ||
| SpendUpTo(limit float64, action ActionID, sim *Simulation) float64 // Spends as much resource as possible up to the speciefied limit; Returns the amount of resource spent | ||
| Gain(amount float64, action ActionID, sim *Simulation) // Gain the amount specified from the action | ||
| Reset(sim *Simulation) // Resets the current resource bar | ||
| Value() float64 // Returns the current amount of resource | ||
| } | ||
|
|
||
| type SecondaryResourceConfig struct { | ||
| Type SecondaryResourceType // The type of resource the bar tracks | ||
| Max float64 // The maximum amount the bar tracks | ||
| Default float64 // The default value this bar should be initialized with | ||
| } | ||
InDebt marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| type _SecondaryResourceBar struct { | ||
InDebt marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| config SecondaryResourceConfig | ||
| value float64 | ||
| unit *Unit | ||
| metrics map[ActionID]*ResourceMetrics | ||
| } | ||
|
|
||
| // CanSpend implements SecondaryResourceBar. | ||
| func (bar *_SecondaryResourceBar) CanSpend(limit float64) bool { | ||
| return bar.value >= limit | ||
| } | ||
|
|
||
| // Gain implements SecondaryResourceBar. | ||
| func (bar *_SecondaryResourceBar) Gain(amount float64, action ActionID, sim *Simulation) { | ||
| bar.value += amount | ||
| baseAmount := amount | ||
| if bar.value > bar.config.Max { | ||
| amount -= bar.value - bar.config.Max | ||
| bar.value = bar.config.Max | ||
| } | ||
InDebt marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| metrics := bar.GetMetric(action) | ||
| metrics.AddEvent(baseAmount, amount) | ||
| if sim.Log != nil { | ||
| bar.unit.Log( | ||
| sim, | ||
| "Gained %0.0f generic resource from %s (%0.0f --> %0.0f) of %0.0f total.", | ||
InDebt marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| amount, | ||
| action, | ||
| bar.value-amount, | ||
| bar.value, | ||
| bar.config.Max, | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| // Reset implements SecondaryResourceBar. | ||
| func (bar *_SecondaryResourceBar) Reset(sim *Simulation) { | ||
| bar.value = 0 | ||
| if bar.config.Default > 0 { | ||
| bar.Gain(bar.config.Default, ActionID{SpellID: int32(bar.config.Type)}, sim) | ||
| } | ||
| } | ||
|
|
||
| // Spend implements SecondaryResourceBar. | ||
| func (bar *_SecondaryResourceBar) Spend(amount float64, action ActionID, sim *Simulation) { | ||
| if amount > bar.value { | ||
| panic("Trying to spend more resource than is available.") | ||
| } | ||
InDebt marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| metrics := bar.GetMetric(action) | ||
| if sim.Log != nil { | ||
| bar.unit.Log( | ||
| sim, | ||
| "Spent %0.0f generic resource from %s (%0.0f --> %0.0f) of %0.0f total.", | ||
| amount, | ||
| metrics.ActionID, | ||
| bar.value, | ||
| bar.value-amount, | ||
| bar.config.Max, | ||
| ) | ||
| } | ||
|
|
||
| metrics.AddEvent(-amount, -amount) | ||
| bar.value -= amount | ||
| } | ||
|
|
||
| // SpendUpTo implements SecondaryResourceBar. | ||
| func (bar *_SecondaryResourceBar) SpendUpTo(limit float64, action ActionID, sim *Simulation) float64 { | ||
| if bar.value > limit { | ||
| bar.Spend(limit, action, sim) | ||
| return limit | ||
| } | ||
|
|
||
| max := math.Floor(bar.value) | ||
| bar.Spend(max, action, sim) | ||
| return max | ||
| } | ||
|
|
||
| // Value implements SecondaryResourceBar. | ||
| func (bar *_SecondaryResourceBar) Value() float64 { | ||
| return bar.value | ||
| } | ||
|
|
||
| func (bar *_SecondaryResourceBar) GetMetric(action ActionID) *ResourceMetrics { | ||
| metric, ok := bar.metrics[action] | ||
| if !ok { | ||
| metric = bar.unit.NewGenericMetric(action) | ||
| bar.metrics[action] = metric | ||
| } | ||
|
|
||
| return metric | ||
| } | ||
|
|
||
| func (unit *Unit) NewSecondaryResourceBar(config SecondaryResourceConfig) SecondaryResourceBar { | ||
InDebt marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if config.Type <= 0 { | ||
| panic("Invalid SecondaryResourceType given.") | ||
| } | ||
|
|
||
| if config.Max <= 0 { | ||
| panic("Invalid maximum resource value given.") | ||
| } | ||
|
|
||
| if config.Default < 0 || config.Default > config.Max { | ||
| panic("Invalid default value given for resource bar") | ||
| } | ||
|
|
||
| return &_SecondaryResourceBar{config: config, unit: unit, metrics: make(map[ActionID]*ResourceMetrics)} | ||
| } | ||
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
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
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
InDebt marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
Binary file not shown.
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
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
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
Oops, something went wrong.
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.