コード例 #1
0
ファイル: spell.py プロジェクト: novasdream/PyOT
        def runeCallback(thing, creature, position, onPosition, onThing, strength=None, **k):
            print "runeCallback"
            target = creature
            if self.targetType == TARGET_TARGET:
                target = onThing
                if not isinstance(target, Creature):
                    if not isinstance(target, Creature):
                        print onThing, onThing.position, onThing.position.getTile().getCreatureCount()
                        try:
                            target = onThing.position.getTile().topCreature()
                            print target
                        except:
                            raise                    
                    if not target:
                        creature.onlyOnCreatures()
                        return False

            creature.spellTargets = [target]
                    
            if creature.isPlayer():
                if not target.inRange(creature.position, self.targetRange, self.targetRange):
                    creature.cancelMessage(_l(creature, "Target is too far away"))
                    return False
                    
                if not creature.canDoSpell(self.icon, self.group):
                    creature.exhausted()
                    return False

                if creature.getSkull() == SKULL_BLACK and config.blackSkullDisableAreaRunes and self.targetType == TARGET_AREA:
                    return creature.cancelMessage(_l(creature, "You have a black skull and can't cast area spells."))
                
                if self.learned and not creature.canUseSpell(self.name):
                    return creature.cancelMessage(_l(creature, "You need to learn this spell first."))
                    
                if self.vocations and creature.getVocationId() not in self.vocations:
                    return creature.cancelMessage(_l(creature, "Your vocation cannot use this spell."))
                    
                if self._requireGreater:
                    for var in self._requireGreater:
                        if creature.data[var] < self._requireGreater[var]:
                            creature.notEnough(var)
                            return False
                            
                if self._requireLess:
                    for var in self._requireLess:
                        if creature.data[var] > self._requireLess[var]:
                            creature.message(_l(creature, "Your %s is too high!") % var)
                            return False
                
                if self._requireCallback:
                    for call in self._requireCallback:
                        if not call(caster=creature): return

                if not thing.count:
                    creature.needMagicItem()
                    creature.magicEffect(EFFECT_POFF)
                        
                else:
                    thing.modify(-1)  
                    
                    # Integrate mana seeker
                    try:
                        creature.modifyMana(-self._requireGreater["mana"])
                        creature.modifySpentMana(self._requireGreater["mana"])
                    except:
                        pass

                    # Integrate soul seeker
                    try:
                        creature.modifySoul(-self._requireGreater["soul"])
                    except:
                        pass
                    
                    creature.cooldownSpell(self.icon, self.group, self.cooldown, self.groupCooldown)
                    
            if self.castEffect:
                creature.magicEffect(self.castEffect)
            
            for call in self.effectOnCaster:
                call(caster=creature, target=creature, strength=strength)
            
            for array in self.conditionOnCaster:
                creature.condition(array[0].copy(), array[1])
                
            if self.targetType == TARGET_TARGET and self.shootEffect:
                creature.shoot(creature.position, target.position, self.shootEffect)
                
            if not self.targetType == TARGET_AREA:
                for call in self.effectOnTarget:
                    call(target=target, caster=creature, strength=strength)
                
                if self._targetEffect:
                    target.magicEffect(self._targetEffect)
                    
                for array in self.conditionOnTarget:
                    target.condition(array[0].copy(), array[1])
        
            else:
                area = self.targetArea(caster=creature) if callable(self.targetArea) else self.targetArea
                positions = calculateAreaDirection(creature.position, creature.direction, area)
                targetGenerators = []
                for pos in positions:
                    if self.areaEffect:
                        creature.magicEffect(self.areaEffect, pos)
                        
                    creatures = game.map.getTile(pos).creatures()
                    if creatures:
                        targetGenerators.append(creatures)
                        
                for generator in targetGenerators:
                    for targ in generator:
                        if creature.isMonster() and not config.monsterAoEAffectMonsters and targ.isMonster():
                            continue

                        creature.spellTargets.append(targ)

                        if self._targetEffect:
                            targ.magicEffect(self._targetEffect)
                        
                        for call in self.effectOnTarget:
                            call(target=targ, caster=creature, strength=strength)
コード例 #2
0
ファイル: spell.py プロジェクト: novasdream/PyOT
        def spellCallback(creature, strength=None, **k):
            target = creature
            if self.targetType == TARGET_TARGET or self.targetType == TARGET_TARGETSELF or self.targetType == TARGET_TARGETONLY:
                if creature.target:
                    target = creature.target
                    if self.targetType == TARGET_TARGETONLY:
                        self.targetType = TARGET_TARGET
                elif self.targetType == TARGET_TARGET and self.targetArea: #if no target but area still cast the spell (dont need not creature.target)
                    self.targetType = TARGET_AREA #if not and the spell is cast as an area spell do the area being defined.
                elif self.targetType == TARGET_TARGET and not self.targetArea:
                    return False
                elif self.targetType == TARGET_TARGETONLY:
                    return creature.cancelMessage(_l(creature, "You need a target to cast this spell."))
 
            if creature.isPlayer():
                if not target.inRange(creature.position, self.targetRange, self.targetRange):
                    creature.cancelMessage(_l(creature, "Target is too far away"))

                    return False
                    
                if not creature.canDoSpell(self.icon, self.group):
                    creature.exhausted()

                    return False
                    
                if creature.getSkull() == SKULL_BLACK and config.blackSkullDisableAreaSpells and self.targetType == TARGET_AREA:
                    return creature.cancelMessage(_l(creature, "You have a black skull and can't cast area spells."))
                
                if self.learned and not creature.canUseSpell(self.name):
                    return creature.cancelMessage(_l(creature, "You need to learn this spell first."))
                    
                if self.vocations and creature.getVocationId() not in self.vocations:
                    return creature.cancelMessage(_l(creature, "Your vocation cannot use this spell."))
                    
                if self._requireGreater:
                    for var in self._requireGreater:
                        if creature.data[var] < self._requireGreater[var]:
                            creature.notEnough(var)

                            return False
                            
                if self._requireLess:
                    for var in self._requireLess:
                        if creature.data[var] > self._requireLess[var]:
                            creature.message(_l(creature, "Your %s is too high!") % var)

                            return False
                
                if self._requireCallback:
                    for call in self._requireCallback:
                        if not call(caster=creature):

                            return
                        
                # Integrate mana seeker
                try:
                    creature.modifyMana(-self._requireGreater["mana"])
                    creature.modifySpentMana(self._requireGreater["mana"])
                except:
                    pass

                # Integrate soul seeker
                try:
                    creature.modifySoul(-self._requireGreater["soul"])
                except:
                    pass
                
                creature.cooldownSpell(self.icon, self.group, self.cooldown, self.groupCooldown)
            creature.spellTargets = []
                    
            if self.castEffect:
                creature.magicEffect(self.castEffect)

            for call in self.effectOnCaster:
                call(caster=creature, target=creature, strength=strength)
            
            for array in self.conditionOnCaster:
                creature.condition(array[0].copy(), array[1])
                
            if self.targetType in (TARGET_TARGET, TARGET_TARGETSELF) and target and target != creature and self.shootEffect:
                creature.shoot(creature.position, target.position, self.shootEffect)
                
            if not self.targetType == TARGET_AREA:
                creature.spellTargets.append(target)
                for call in self.effectOnTarget:
                    call(target=target, caster=creature, strength=strength)
                
                if self._targetEffect:
                    target.magicEffect(self._targetEffect)
                    
                for array in self.conditionOnTarget:
                    target.condition(array[0].copy(), array[1])

            if self.targetType == TARGET_AREA:
                area = self.targetArea(caster=creature) if callable(self.targetArea) else self.targetArea
                positions = calculateAreaDirection(creature.position, creature.direction, area)
                targetGenerators = []
                for pos in positions:
                    if self.areaEffect:
                        creature.magicEffect(self.areaEffect, pos)
                        
                    creatures = game.map.getTile(pos).creatures()
                    if creatures:
                        targetGenerators.append(creatures)
                        
                for generator in targetGenerators:
                    for targ in generator:
                        if creature.isMonster() and not config.monsterAoEAffectMonsters and targ.isMonster():
                            continue

                        creature.spellTargets.append(targ)

                        if self._targetEffect:
                            targ.magicEffect(self._targetEffect)
                        
                        for call in self.effectOnTarget:
                            call(target=targ, caster=creature, strength=strength)