Ignore:
Timestamp:
09/01/13 14:39:13 (8 years ago)
Author:
Jeremy Thurgood <firxen@…>
Branch:
default
Phase:
public
Message:

Arbitrary function condition.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • nagslang/environment.py

    r28 r32  
    1010
    1111class AllConditions(ProtagonistCondition):
     12    """Condition that is met if all provided conditions are met.
     13
     14    Conditions are evaluated lazily, so the first condition to fail stops
     15    processing.
     16    """
    1217    def __init__(self, *conditions):
    1318        self.conditions = conditions
     
    2126
    2227class AnyCondition(ProtagonistCondition):
     28    """Condition that is met if any provided condition is met.
     29
     30    Conditions are evaluated lazily, so the first condition to pass stops
     31    processing.
     32    """
    2333    def __init__(self, *conditions):
    2434        self.conditions = conditions
     
    3242
    3343class WolfFormCondition(ProtagonistCondition):
     44    """Condition that is met if the protagonist is in wolf form.
     45    """
    3446    def check(self, protagonist):
    3547        return protagonist.in_wolf_form()
     
    3749
    3850class HumanFormCondition(ProtagonistCondition):
     51    """Condition that is met if the protagonist is in human form.
     52    """
    3953    def check(self, protagonist):
    4054        return protagonist.in_human_form()
     
    4256
    4357class ItemRequiredCondition(ProtagonistCondition):
     58    """Condition that is met if the protagonist has the required item.
     59    """
    4460    def __init__(self, required_item):
    4561        self.required_item = required_item
     
    4763    def check(self, protagonist):
    4864        return protagonist.has_item(self.required_item)
     65
     66
     67class FunctionCondition(ProtagonistCondition):
     68    """Condition that is met if the provided function returns `True`.
     69    """
     70    def __init__(self, func):
     71        self.func = func
     72
     73    def check(self, protagonist):
     74        return self.func(protagonist)
    4975
    5076
Note: See TracChangeset for help on using the changeset viewer.