MongooseA living laboratory of myriad worlds.

All help topics · Link to this topic

Showing help on 'effects'

EFFECTS
=======
The effect system applies temporary, time-limited modifiers (buffs and
debuffs) to players: caffeine speed boosts, alcohol impairment, painkillers,
and so on. Effects tick down on a global timer and expire on their own.

SEEING WHICH EFFECTS EXIST


Effects are built from named TEMPLATES on $effect (#9479):
;mapkeys($effect.templates)
=> {"alcohol", "caffeine", "capsaicin", "cocaine", "ibuprofen", "mdma",
"nicotine", "opium", "smoke_inhalation", "theine", "theobromine"}
Inspect one to see what it does:
;$effect.templates["caffeine"]
=> ["apply_msg" -> "You feel a jolt of alertness.",
"expire_msg" -> "The caffeine buzz fades.",
"default_duration" -> 600,
"modifiers" -> {["op"->"multiply", "stat"->"speed", "value"->1.15]}]
A template may define: apply_msg, expire_msg, tick_msg, default_duration
(in seconds), and modifiers -- a list of {op, stat, value} maps where op is
"multiply" or "add".

SEEING A PLAYER'S CURRENT EFFECTS


;player:get_effects() active effect waifs
;player:has_effect("caffeine") true/false
;player:stat_modifier("speed") combined multiplier for a stat (1.0 = none)
ADDING EFFECTS TO YOUR OBJECT
----------------------------
The easy path is the Effectful Mixin ($effectful #9649). $food, $drink, and
$herb already inherit it, so to make a consumable apply effects:
  1. Make sure your object inherits $effectful (#9649).
  2. Set .effects to a map of template-name -> duration-in-seconds:
;your_obj.effects = ["caffeine" -> 600]
  1. Optional knobs: .effect_delay (seconds before onset, 0 = immediate),
.intensity (passed to the effect, default 0.5), .effect_msg (an extra
line shown to the consumer).
  1. At the consumption point call: this:apply_effects(player);
($drink:sip and $food do this for you -- just set .effects.)
Manual path (no mixin):
effect = $effect:new("caffeine", 600); "name, duration, ?intensity, ?source"
player:add_effect(effect);

MAKING A STAT RESPOND TO EFFECTS


An effect does nothing until some verb consults it. The convention is to
multiply your base stat by the player's combined modifier:
;player:walking_speed()
=> return this.walking_speed * this:stat_modifier("speed");
Any "speed" modifier from any active effect then scales the result. Use the
same stat name on the template modifier and on the verb that reads it.
NOTES
-----
Consuming the same effect again refreshes it: durations merge and the
strongest modifier per stat wins.
See also: $effect (#9479), $effectful (#9649), Effect PC (#9478).