Add use_item / can_use_item; item effects system#13
Merged
Conversation
Items can now define an effects dict in items.json:
{ "id": "groceries", "type": "food", "effects": { "hunger": 35, "mood": 3 } }
New script functions (snake_case via Scriban auto-rename):
{{ use_item "groceries" }}
Consumes 1 unit, applies all effects to mc, returns HTML stat summary.
Returns an error string if not owned or no effects defined.
{{ if can_use_item "groceries" }}
Guard: true only when player owns >=1 and effects are defined.
Implementation:
- ItemDefinition.Effects: Dictionary<string,int> parsed from JSON
- MergeItemsFromJson: parses effects field via dynamic JObject iteration
- UseItem: delegates attr changes to existing AttrChange() for consistency;
builds a coloured HTML summary of applied changes
- CanUseItem: lightweight ownership + effects-defined check
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Consumable items (food, drinks) previously had no actual mechanic — they sat in inventory with a description saying "eat to restore hunger" but nothing happened. This PR makes them real.
items.json additions (story-side)
{ "id": "groceries", "type": "food", "effects": { "hunger": 35, "mood": 3 } } { "id": "energy_drink", "type": "food", "effects": { "energy": 25, "mood": -3 } }New script functions
Consumes 1 unit, applies all effects to mc via the existing
AttrChangepipeline, returns an HTML stat summary (e.g.+35 Hunger | +3 Mood). Returns a red error string if not owned or no effects defined.Guard: true only when player owns ≥1 of the item and effects are defined. Use to show/hide the "use" link.
Implementation details
ItemDefinition.Effects: Dictionary<string,int>— parsed from JSONeffectsfieldMergeItemsFromJson: iteratesitem.effectsJObject propertiesUseItem: delegates toAttrChange("mc", ...)for consistency with the existing attr pipeline; builds coloured HTML summaryCanUseItem: lightweight check, no side effectsTest plan
groceriesitem to inventory{{ if can_use_item "groceries" }}shows link only when owned{{ use_item "groceries" }}reduces count by 1, raises Hunger by 35, shows summary{{ use_item "groceries" }}when not owned returns error string (no crash)🤖 Generated with Claude Code