示例#1
0
 def testBadTargets(self):
     spells = ["passdoor", "enchant"]
     badTargets = [self.targetCharObj, self.targetCreaObj]
     charObj = self.charDict.get("mage")
     charObj.setLevel(10)
     for spellName in spells:
         chant = magic.getSpellChant(spellName)
         for target in badTargets:
             spellObj = magic.Spell(charObj, target, spellName, chant)
             assert not spellObj.cast(charObj)
     spells = [
         "vigor",
         "heal",
         "fireball",
         "lightning",
         "hurt",
         "disintegrate",
         "turn",
         "curepoison",
         "befuddle",
         "teleport",
         "enchant",
         "bless",
         "protect",
         "curse",
         "poison",
         "intoxicate",
         "vuln",
     ]
     badTargets = [self.targetDoorObj]
     for spellName in spells:
         chant = magic.getSpellChant(spellName)
         for target in badTargets:
             spellObj = magic.Spell(charObj, target, spellName, chant)
             assert not spellObj.cast(charObj)
示例#2
0
 def testHealthSpells(self):
     spells = ["vigor", "heal"]
     target = self.targetCharObj
     for charClass in self.charDict.keys():
         charObj = self.charDict[charClass]
         for level in [1, 3, 7, 10]:
             charObj.setLevel(level)
             for spellName in spells:
                 chant = magic.getSpellChant(spellName)
                 spellObj = magic.Spell(charObj, target, spellName, chant)
                 msg = ("testHealthSpells - class=" + charClass +
                        " - level=" + str(level) + " - spell=" + spellName +
                        " - damage=" + str(spellObj.health))
                 assert spellObj.health != 0, msg
示例#3
0
 def testDamageSpells(self):
     spells = ["fireball", "lightning", "hurt", "disintegrate"]
     target = self.targetCharObj
     for charClass in self.charDict.keys():
         charObj = self.charDict[charClass]
         for level in [1, 3, 7, 10]:
             charObj.setLevel(level)
             for spellName in spells:
                 chant = magic.getSpellChant(spellName)
                 spellObj = magic.Spell(charObj, target, spellName, chant)
                 msg = ("testDamageSpells - class=" + charClass +
                        " - level=" + str(level) + " - spell=" + spellName +
                        " - damage=" + str(spellObj.damage))
                 assert spellObj.damage != 0, msg
示例#4
0
 def testBadLevels(self):
     spells = ["lightning", "identify", "disintegrate"]
     goodLvls = {
         "mage": {
             "lightning": [4, 7, 10],
             "identify": [5, 7, 10],
             "disintegrate": [7, 10],
         },
         "fighter": {
             "lightning": [8, 10],
             "identify": [10],
             "disintegrate": []
         }
     }
     badLvls = {
         "mage": {
             "lightning": [1, 3],
             "identify": [1, 4],
             "disintegrate": [1, 3, 6],
         },
         "fighter": {
             "lightning": [1, 3, 7],
             "identify": [1, 4, 9],
             "disintegrate": [1, 100],
         },
     }
     target = self.targetCharObj
     for className in goodLvls.keys():
         charObj = self.charDict.get(className)
         for spellName in spells:
             chant = magic.getSpellChant(spellName)
             for level in goodLvls[className][spellName]:
                 charObj.setLevel(level)
                 spellObj = magic.Spell(charObj, target, spellName, chant)
                 lvlReq = str(spellObj.levelRequired)
                 assert spellObj.cast(charObj), (
                     "level " + str(charObj.getLevel()) + " " +
                     charObj.getClassName() + " should be able to cast " +
                     spellObj.spellName + " which requires level " +
                     str(lvlReq) + "\n" + spellObj.debug())
             for level in badLvls[className][spellName]:
                 charObj.setLevel(level)
                 spellObj = magic.Spell(charObj, target, spellName, chant)
                 lvlReq = str(spellObj.levelRequired)
                 assert not spellObj.cast(charObj), (
                     "level " + str(charObj.getLevel()) + " " +
                     charObj.getClassName() + " should not be able to " +
                     "cast " + spellObj.spellName +
                     " which requires level " + str(lvlReq))
示例#5
0
 def testDoorSpells(self):
     spells = ["passdoor"]
     target = self.targetCharObj
     for charClass in self.charDict.keys():
         charObj = self.charDict[charClass]
         for level in [1, 3, 7, 10]:
             charObj.setLevel(level)
             for spellName in spells:
                 chant = magic.getSpellChant(spellName)
                 spellObj = magic.Spell(charObj, target, spellName, chant)
                 msg = ("testDoorSpells - class=" + charClass +
                        " - level=" + str(level) + " - spell=" + spellName +
                        " - succeeded=" + str(spellObj.succeeded))
                 # assert spellObj.succeeded != 0, msg
                 msg = msg  # remove when we complete the assert
示例#6
0
文件: object.py 项目: jnewblanc/sog
    def study(self, charObj):
        """ Display the spell chant and add spell to Char's known spells
            * scroll disintegrates in calling function """

        msg = ""
        spellName = self.getSpellName()

        # Get the chant
        spellChant = getSpellChant(spellName)
        msg += self.describe(article="The") + ' reads, "' + spellChant + '"\n'

        # Learn the spell
        if charObj.learnSpell(spellName):
            msg += 'You learn the "' + spellName + '" spell\n'

        return msg
示例#7
0
    def testMana(self):
        spells = [
            "vigor",
            "heal",
            "fireball",
            "lightning",
            "hurt",
            "disintegrate",
            "curepoison",
            "befuddle",
            "teleport",
            "protect",
            "poison",
            "intoxicate",
            "vuln",
        ]
        badMana = 1
        goodMana = 99
        charObj = self.charDict.get("mage")
        target = self.targetCharObj
        for spellName in spells:
            if spellName == "":
                continue
            charObj.setMana(goodMana)
            chant = magic.getSpellChant(spellName)
            # cast with plenty of mana - should pass
            spellObj = magic.Spell(charObj, target, spellName, chant)
            msg = ("ManaPass: spell=" + spellName + " - charHas=" +
                   str(charObj.getMana()) + " - spellReq: " +
                   str(spellObj.getMana()))
            assert spellObj.succeeded, msg

            # cast with insufficient mana - should fail
            charObj.setMana(badMana)
            spellObj = magic.Spell(charObj, target, spellName, chant)
            msg = ("ManaFail: spell=" + spellName + " - charHas=" +
                   str(charObj.getMana()) + " - spellReq: " +
                   str(spellObj.getMana()))
            assert not spellObj.succeeded, msg
示例#8
0
文件: object.py 项目: jnewblanc/sog
    def cast(self, charObj, targetObj):
        """ cast a spell using a device """
        if self.getCharges() <= 0:
            charObj.client.spoolOut("This item has no charges left\n")
            return False
        if self.getCharges() == 1:
            if self.getType() == "Scroll":
                charObj.client.spoolOut(
                    self.describe(article="The") + " disintegrates\n"
                )
            else:
                charObj.client.spoolOut(self.describe(article="The") + " fizzles\n")

        spellName = self.getSpellName()
        # With devices, spellChant is not required, so we get it and pass it in
        spellChant = getSpellChant(spellName)

        # create the spell object, which determines if it succeeds
        spellObj = Spell(
            charObj,
            targetObj,
            spellName,
            chant=spellChant,
            requiresmana=False,
            useSelfCriteria=False,
        )

        # Apply effects of spell
        if spellObj.cast(charObj.getRoom()):
            pass
        else:
            charObj.client.spoolOut(spellObj.getFailedReason() + "\n")

        self.decrementChargeCounter()

        return None