-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Max Health and Mana Manipulation API #2909
Merged
Chicken-Bones
merged 63 commits into
tModLoader:1.4
from
absoluteAquarian:1.4-health-mana-api
Sep 23, 2022
Merged
Max Health and Mana Manipulation API #2909
Chicken-Bones
merged 63 commits into
tModLoader:1.4
from
absoluteAquarian:1.4-health-mana-api
Sep 23, 2022
Conversation
This file contains 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
- initial changes to the health/mana API * added a helper function in Player for using maximum health- and mana-increasing items * modified the AchivementHelper code in the event that achievements are enabled in the future * added fields in Player indicating how many Life Crystals, Life Fruit and Mana Crystals they have consumed * updated ExampleMod to account for the new API ! This PR is not complete. UI still needs to be addressed as well as some other things. - modified ExampleLifeFruit to better mimic how Life Fruits work - better comment in ExampleLifeFruit - better comment 2
- also modified all vanilla uses of checking if statLifeMax or statManaMax were above/below a certain number with checks for consumed item counts in order to properly account for the new API - updated ExampleLifeFruitPlayer to account for the new API
- removed ModifyBaseMaxStats, PreModifyMaxStats and PostModifyMaxStats in favor of a StatModifier hook - made the setters for ConsumedLifeCrystals, ConsumedLifeFruit and ConsumedManaCrystals public for better API accessibility (a mod may want to just set these directly) - added code to save/load ConsumedLifeCrystals, ConsumedLifeFruit and ConsumedManaCrystals
- changed ExampleLifeFruit's usage of ModifyMaxStats to be less confusing - moved duplicated code to a PlayerLoader helper method, ResetMaxStatsToVanilla - added Utils.Clamp usage - clamped the values for the ConsumedLifeCrystals, ConsumeLifeFruit and ConsumedManaCrystals properties - added/updated XML summaries
… still TODO) - also removed the sets added to ItemID due to them not having a use - updated ExampleMod with examples of drawing with an overlay for the Classic display set - fixed a copy/paste typo
…operties in PlayerStatsSnapshot work
- all existing `ModResourceOverlay` hooks were converted into more "general" Resource hooks - added `IResourceDrawSource` to `ResourceOverlayDrawContext` - updated ExampleMod - updated XML summaries
- added missing `IResourceDrawSource` classes for the panel drawing - fixed a bug in `PlayerIO` which prevented the ConsumedX properties in Player to save properly - deserializing `null` as a `TagCompound` actually results in an empty tag, so i added a proper check in `PlayerIO` for when the fallback system to load the ConsumedX properties should be used - `ModResourceOverlay` and `ResourceOverlayLoader` API changes
…ter the max amount of fruits are used
- the `AmountOfHearts` property in `PlayerStatsSnapshot` was renamed to `AmountOfLifeHearts` - added helper methods to `ResourceOverlayLoader` for drawing resources for modder convenience
… ExampleLifeFruit + added the sprite for ExampleManaCrystal
…mation and sound"
…d.HandlePacket to be more friendly to additional cases in the future
- made ExampleLifeFruit actually use its texture - renamed VanillaHealthOverlay to VanillaLifeOverlay - renamed the "ClassicHealthOverlay" image to "ClassicLifeOverlay" - renamed the "FancyHealthOverlay_X" images to "FancyLifeOverlay_X" - added ExampleManaCrystal - added VanillaManaOverlay - renamed ExampleLifeFruitPlayer to ExampleStatIncreasePlayer and moved it to `Common/Players` - renamed ExampleLifeFruitSystem to ExampleStatIncreaseSystem and moved it to `Common/Systems` - made VanillaLifeOverlay "replace" the bars from right to left - fixed some bugs caused by `float` precision limits
- properly implemented PreDrawResourceDisplay and PostDrawResourceDisplay in the Fancy and Bars display sets - expanded PlayerResourceSetsManager to include modded display sets - updated XML summaries
…le for ModResourceDisplaySet
- moved the code reponsible for adding the modded display sets to `Main.ResourceSetsManager` to before `Mod.SetupContent()` is called so that they're available for use in `Mod.PostSetupContent()` and onwards - made the Classic display set be "registered" after the Bars display set - changed the logic of `PlayerResourceSetsManager.CycleResourceSet()` to go from first to last instead of last to first
- removed compound saving in PlayerIO in favor of a better alternative - added code to save/load the ConsumedX properties directly
…since they're the vanilla values anyway
- removed `ResourceSlotId` in favor of just checking asset instances - added a new `ResourceStat` property to `ResourceOverlayDrawContext` - fixed a bug that caused the display cycling to get stuck between Classic and Swapped Bars - modified ExampleMod to account for the new changes - updated XML comments
Chicken-Bones
requested changes
Sep 22, 2022
ExampleMod/Common/UI/ExampleDisplaySets/ExampleReversedBarsDisplay.cs
Outdated
Show resolved
Hide resolved
patches/tModLoader/Terraria/GameContent/UI/ResourceSets/PlayerResourceSetsManager.cs.patch
Outdated
Show resolved
Hide resolved
patches/tModLoader/Terraria/GameContent/UI/ResourceSets/PlayerResourceSetsManager.cs.patch
Outdated
Show resolved
Hide resolved
patches/tModLoader/Terraria/GameContent/UI/ResourceSets/PlayerStatsSnapshot.cs.patch
Outdated
Show resolved
Hide resolved
...Loader/Terraria/GameContent/UI/ResourceSets/HorizontalBarsPlayerReosurcesDisplaySet.cs.patch
Outdated
Show resolved
Hide resolved
...es/tModLoader/Terraria/GameContent/UI/ResourceSets/ClassicPlayerResourcesDisplaySet.cs.patch
Show resolved
Hide resolved
…ted fields in `ResourceDrawSettings`
Chicken-Bones
requested changes
Sep 23, 2022
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Incredibly, I think this is the only change still required
- made `ResourceOverlayDrawContext.resourceNumber` start at 0 by default - made the Bars panel drawing have `resourceNumber` start at -1 - added `ResourceIndexOffset` to `ResourceDrawSettings` - actually tested the changed display set cycling code - various bug fixes
Chicken-Bones
changed the title
[1.4] Max Health and Mana Manipulation API
Max Health and Mana Manipulation API
Sep 23, 2022
This was referenced Sep 23, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Benefit - Medium
Complexity - High
Feature - Hook
Request for new modding functionality
Requestor-Modders
Issues or PRs adding or fixing TML modder API
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.
What is the new feature?
This PR aims to make modifying the player's maximum health and mana, as well as their displays, more friendly to mod developers.
Features include:
Player.statLifeMax
andPlayer.statManaMax
ModResourceOverlay
ModResourceDisplaySet
ModResourceDisplaySet
displays is handled via the pre-existing option in the ingame Settings>Video menuconfig.json
Player.statLifeMax
andPlayer.statManaMax
Player
for tracking how many Life Crystals, Life Fruit and Mana Crystals have been consumedPlayer.ConsumedLifeCrystals
Player.ConsumedLifeFruit
Player.ConsumedManaCrystals
Player.UseHealthMaxIncreasingItem()
andPlayer.UseManaMaxIncreasingItem()
Why should this be part of tModLoader?
Modifying the player's maximum health and mana currently requires using
Player.statLifeMax2
andPlayer.statManaMax2
, which -- even though it works -- is clunky and goes against the purpose of those fields: "temporary" increases/decreases.Furthermore, modifying how vanilla's hearts/stars/bars for health and mana are drawn is cumbersome, requiring a method detour or IL edit to be used, which can cause conflicts when multiple mods try to do so at once.
As a side note, any legacy usage of modifying
Player.statLifeMax2
andPlayer.statManaMax2
will still be supported, but mod developers should be encouraged to move to the new API.Are there alternative designs?
n/a
Sample usage for the new feature
Modifying the player's maximum health:
Drawing custom hearts over the hearts in the Classic resource display set:
ExampleMod updates
Content/Items/Consumables/ExampleLifeFruit.cs
was updated to use the new APIContent/Items/Consumables/ExampleManaCrystal.cs
, which serves as an example mana increasing itemCommon/UI/ResourceOverlay
folder, which contains examples of modifying vanilla's resource display setsCommon/UI/ExampleDisplaySets
folder, which contains an example of usingModResourceDisplaySet
ExampleLifeFruitPlayer
was renamed toExampleStatIncreasePlayer
and was moved toCommon/Players
ExampleMod.Networking.cs
to account for the newExampleManaCrystal
statsen-US.hjson
localization file to add an entry forExampleReversedBarsDisplay
(theModResourceDisplaySet
example)Additional Information
ModLoader/Default/ModLoaderMod.cs
was modified to be more friendly to future additionsModAccessorySlotPlayer
was also modifiedPlayer.statLifeMax
and/orPlayer.statManaMax
were changed to check thePlayer.ConsumedLifeCrystals
,Player.ConsumedLifeFruit
andPlayer.ConsumedManaCrystals
properties instead, since that's what was really happening in the first placeAmountOfLifeHearts
andAmountOfManaStars
properties toPlayerStatsSnapshot
and changed theLifePerSegment
andManaPerSegment
fields to be getter properties dependent on these new propertiesPlayerResourceSetsManager
(akaMain.ResourceSetsManager
) was expanded to includeModResourceDisplaySet
instancesModResourceDisplaySet
was loaded, you can get the instance viaMain.ResourceSetsManager.GetDisplaySet<T>()
Main.ResourceSetsManager.GetDisplaySet("ModName/Name")
IPlayerResourceDisplaySet.NameKey
was removed in favor of aDisplayedName
getter property, though the property still exists for whoever might want to use it