def __init__(self): """ Default constructor """ self.targets = [] self.effects = EffectsCollection() self.spirit = 0
def test_detect_mismatch_in_collection(self): """ Test that matcher can detect a mismatch in collection """ collection = EffectsCollection() handle1 = EffectHandle(trigger='on drink', effect=None, parameters=None, charges=1) handle2 = EffectHandle(trigger='on kick', effect=None, parameters=None, charges=1) handle3 = EffectHandle(trigger='on burn', effect=None, parameters=None, charges=1) collection.add_effect_handle(handle1) collection.add_effect_handle(handle2) matcher = ContainsEffectHandle([handle1, handle2, handle3]) assert_that(matcher._matches(collection), is_(equal_to(False)))
def test_match_single_handle(self): """ Test that single handle can be matched """ collection = EffectsCollection() handle = EffectHandle(trigger="on drink", effect=None, parameters=None, charges=1) collection.add_effect_handle(handle) matcher = ContainsEffectHandle(handle) assert_that(matcher._matches(collection), is_(equal_to(True)))
def test_match_any(self): """ Test that matcher can match to any handle """ collection = EffectsCollection() handle1 = EffectHandle(trigger="on drink", effect=None, parameters=None, charges=1) collection.add_effect_handle(handle1) matcher = ContainsEffectHandle(None) assert_that(matcher._matches(collection), is_(equal_to(True)))
def test_detect_sinle_mismatch(self): """ Test that missing a single handle is detected correctly """ collection = EffectsCollection() handle1 = EffectHandle(trigger="on drink", effect=None, parameters=None, charges=1) collection.add_effect_handle(handle1) handle2 = EffectHandle(trigger="on kick", effect=None, parameters=None, charges=1) matcher = ContainsEffectHandle(handle2) assert_that(matcher._matches(collection), is_(equal_to(False)))
def test_match_any(self): """ Test that matcher can match to any handle """ collection = EffectsCollection() handle1 = EffectHandle(trigger='on drink', effect=None, parameters=None, charges=1) collection.add_effect_handle(handle1) matcher = ContainsEffectHandle(None) assert_that(matcher._matches(collection), is_(equal_to(True)))
def test_match_single_handle(self): """ Test that single handle can be matched """ collection = EffectsCollection() handle = EffectHandle(trigger='on drink', effect=None, parameters=None, charges=1) collection.add_effect_handle(handle) matcher = ContainsEffectHandle(handle) assert_that(matcher._matches(collection), is_(equal_to(True)))
def test_match_multiple_handles(self): """ Test that matcher can match multiple handlers """ collection = EffectsCollection() handle1 = EffectHandle(trigger="on drink", effect=None, parameters=None, charges=1) handle2 = EffectHandle(trigger="on kick", effect=None, parameters=None, charges=1) collection.add_effect_handle(handle1) collection.add_effect_handle(handle2) matcher = ContainsEffectHandle([handle1, handle2]) assert_that(matcher._matches(collection), is_(equal_to(True)))
def test_detect_mismatch_in_collection(self): """ Test that matcher can detect a mismatch in collection """ collection = EffectsCollection() handle1 = EffectHandle(trigger="on drink", effect=None, parameters=None, charges=1) handle2 = EffectHandle(trigger="on kick", effect=None, parameters=None, charges=1) handle3 = EffectHandle(trigger="on burn", effect=None, parameters=None, charges=1) collection.add_effect_handle(handle1) collection.add_effect_handle(handle2) matcher = ContainsEffectHandle([handle1, handle2, handle3]) assert_that(matcher._matches(collection), is_(equal_to(False)))
def test_mismatch_any(self): """ Test that matcher can mismatch to any handle """ collection = EffectsCollection() matcher = ContainsEffectHandle(None) assert_that(matcher._matches(collection), is_(equal_to(False)))
def test_detect_sinle_mismatch(self): """ Test that missing a single handle is detected correctly """ collection = EffectsCollection() handle1 = EffectHandle(trigger='on drink', effect=None, parameters=None, charges=1) collection.add_effect_handle(handle1) handle2 = EffectHandle(trigger='on kick', effect=None, parameters=None, charges=1) matcher = ContainsEffectHandle(handle2) assert_that(matcher._matches(collection), is_(equal_to(False)))
def test_match_multiple_handles(self): """ Test that matcher can match multiple handlers """ collection = EffectsCollection() handle1 = EffectHandle(trigger='on drink', effect=None, parameters=None, charges=1) handle2 = EffectHandle(trigger='on kick', effect=None, parameters=None, charges=1) collection.add_effect_handle(handle1) collection.add_effect_handle(handle2) matcher = ContainsEffectHandle([handle1, handle2]) assert_that(matcher._matches(collection), is_(equal_to(True)))
def build(self): """ Build item Returns: Item """ item = Item(effects_collection=EffectsCollection()) item.name = self.name item.appearance = self.appearance item.location = self.location item.icon = self.icon item.tags = self.tags if self.weapon_data is not None: item.weapon_data = self.weapon_data item.tags.append('weapon') if self.armour_data is not None: item.armour_data = self.armour_data item.tags.append('armour') if self.ammunition_data is not None: item.ammunition_data = self.ammunition_data item.tags.append('ammunition') if self.trap_data is not None: item.trap_data = self.trap_data item.tags.append('trap bag') if self.boots_data is not None: item.boots_data = self.boots_data item.tags.append('boots') for handle in self.effect_handles: item.add_effect_handle(handle) for effect in self.effects: item.add_effect(effect) return item
def __init__(self): """ Default constructor """ super().__init__() self.hit_points = 10 self.max_hp = 10 self.spirit = 5 self.max_spirit = 5 self.model = mock() self.speed = 1 self.tick = 0 self.attack = 1 self.body = 1 self.mind = 1 self.finesse = 1 self.size = 'medium' self.name = 'prototype' self.level = None self.location = () self.items = [] self.weapon = None self.effect_handles = [] self.effects = [] self.effects_collection = EffectsCollection() self.player_character = False self.listeners = [] self.update_listeners = [] self.domains = {} self.spell_entries = [] self.cooldowns = {}
class Spell(): """ Class to represent spells .. versionadded:: 0.9 """ @log_debug def __init__(self): """ Default constructor """ self.targets = [] self.effects = EffectsCollection() self.spirit = 0 @log_debug def add_effect_handle(self, handle): """ Add effect handle :param handle: effect handle to add :type handle: EffectHandle """ self.effects.add_effect_handle(handle) @log_debug def get_effect_handles(self, trigger=None): """ Get effect handles :param trigger: optional trigger type :type trigger: string :returns: effect handles :rtype: [EffectHandle] """ return self.effects.get_effect_handles(trigger) @log_debug def remove_effect_handle(self, handle): """ Remove given handle :param handle: handle to remove :type handle: EffectHandle """ self.effects.remove_effect_handle(handle) @log_info def cast(self, effects_factory): """ Cast the spell :param effects_factory: factory for creating effects :type effects_factory: EffectsFactory """ handles = self.effects.get_effect_handles('on spell hit') effects = [] targets = (x.target for x in self.targets if x.target) for target in targets: for handle in handles: effects.append(effects_factory(key=handle.effect, target=target)) for effect in effects: if not effect.duration or effect.duration <= 0: effect.trigger() else: effect.target.add_effect(effect)
class Spell(): """ Class to represent spells .. versionadded:: 0.9 """ @log_debug def __init__(self): """ Default constructor """ self.targets = [] self.effects = EffectsCollection() self.spirit = 0 @log_debug def add_effect_handle(self, handle): """ Add effect handle :param handle: effect handle to add :type handle: EffectHandle """ self.effects.add_effect_handle(handle) @log_debug def get_effect_handles(self, trigger=None): """ Get effect handles :param trigger: optional trigger type :type trigger: string :returns: effect handles :rtype: [EffectHandle] """ return self.effects.get_effect_handles(trigger) @log_debug def remove_effect_handle(self, handle): """ Remove given handle :param handle: handle to remove :type handle: EffectHandle """ self.effects.remove_effect_handle(handle) @log_info def cast(self, effects_factory): """ Cast the spell :param effects_factory: factory for creating effects :type effects_factory: EffectsFactory """ handles = self.effects.get_effect_handles('on spell hit') effects = [] targets = (x.target for x in self.targets if x.target) for target in targets: for handle in handles: effects.append( effects_factory(key=handle.effect, target=target)) for effect in effects: if not effect.duration or effect.duration <= 0: effect.trigger() else: effect.target.add_effect(effect)