Content Patcher

Content Patcher

378k Downloads

[Content Patcher] add daily luck token

Thom1729 opened this issue ยท 4 comments

commented

In my Crystal Ball mod, I define a new token whose value is best, good, neutral, bad or worst depending on daily luck. I have since learned about dynamic tokens and query expressions. If Content Patcher offered a token for daily luck (as a number), then the Crystal Ball mod could be implemented entirely via data packs.

Adding a luck token to Content Patcher sounds like a good first issue I might tackle. Does this sound reasonable to add? If so, does AverageDailyLuck sound sensible?

commented

I see how to implement player-specific daily luck using LocalOrHostPlayerValueProvider. However, it looks like if the player is not specified in the token, then LocalOrHostPlayerValueProvider will default to the current player. In order to default to average luck, should I need to extend LocalOrHostPlayerValueProvider? (I don't mind doing so if this is the right answer; I just don't want to add unnecessary complexity.)

commented

Hi! Sure, I think that'd make sense as a core token. We should make it accept an optional PlayerType argument like a few other tokens already do, so content packs can choose which daily luck they want (e.g. {{DailyLuck}} = average, {{DailyLuck: currentPlayer}}, etc).

commented

Subclassing it could work, though ideally we should support an optional input argument like {{DailyLuck: average}} for consistency. That would mean repeating a lot of the logic anyway, so it might make sense to just implement a new value provider with its own enum like this:

/// <summary>A source for the daily luck token.</summary>
public enum DailyLuckSource
{
    /// <summary>Get daily luck for the player hosting the world in multiplayer.</summary>
    HostPlayer,

    /// <summary>Get daily luck for the current player, regardless of whether they're the main or secondary player.</summary>
    CurrentPlayer,
    
    /// <summary>Get the average daily luck across all players.</summary>
    Average
}
commented

Added in Content Patcher 1.21 via #617. Thanks!