Example #1
0
    def test_Weapon(self):
        player = Thief()
        player.strength_base = 17
        player.equip_weapon(weapons.Dagger())

        player.add_experience(14000)
        self.assertEqual(player.level, 5)
        player.equip_weapon(weapons.Dagger())
        self.assertEqual(3, player.determine_ability_modifier())
        player.equip_weapon(weapons.LongBow())
        self.assertEqual(0, player.determine_ability_modifier())

        #Test damage
        player.strength_base = 17  #+3 modifier
        player.equip_weapon(weapons.Dagger())  #1D6

        self.assertTrue(player.get_equipped_weapon().is_critical_strike(20))
        self.assertFalse(player.get_equipped_weapon().is_critical_strike(21))
        self.assertFalse(player.get_equipped_weapon().is_critical_strike(19))

        for _i in range(100):
            dmg = player.get_equipped_weapon()._normal_strike(player)  #1D6
            print("Player Weapon Damage: {}".format(dmg))
            self.assertGreaterEqual(dmg, 4)
            self.assertLessEqual(dmg, 9)
        #Critical strike
        for _i in range(100):
            dmg = player.get_equipped_weapon()._critical_strike(
                player)  #1D6 + 1D6 + 3*2
            print("Player Weapon Damage: {}".format(dmg))
            self.assertGreaterEqual(dmg, 8)
            self.assertLessEqual(dmg, 18)
Example #2
0
 def test_item_state(self):
     dagger = weapons.Dagger(3)
     state = dagger.get_state()
     dagger2 = items.Item.create_from_state(state)
     self.assertEqual(dagger.__class__, dagger2.__class__)
     self.assertEqual(dagger.count, 3)
     self.assertEqual(dagger.count, dagger2.count)
Example #3
0
    def test_throw_actions(self):
        gm = game_manager
        player = gm.create_player('thief')
        gm.start_new_game('fred', player)
        user = gm.get_user('fred', 'test')
        user.set_room(rooms.CellRoom(player))
        room = user.room

        dagger = weapons.Dagger()
        #Throw item you don't have
        reply = room.throw(dagger, None)
        self.assertTrue('not carrying' in reply)
        print(reply)

        #Throw at non-existent item
        player.pickup(dagger)
        reply = room.throw(dagger, 'chest')
        self.assertTrue(
            ReplyHelpers.render_action_template(
                'no_such_target', item_text=dagger.description) in reply)
        print(reply)

        #Throw item at door
        reply = room.throw(dagger, 'door')
        self.assertTrue('door' in reply)
        print(reply)
        self.assertTrue('you throw' in reply.lower())
Example #4
0
    def test_cast_drink(self):
        gm = game_manager
        player = gm.create_player('mage')
        gm.start_new_game('fred', player)
        user = gm.get_user('fred', 'test')
        user.set_room(rooms.CellRoom(player))
        room = user.room

        #Can't drink that
        reply = room.drink(weapons.Dagger())
        print(reply)
        self.assertTrue("you can't" in reply.lower())

        #Not carrying that
        reply = room.drink(items.Beer())
        print(reply)
        self.assertTrue("you're not carrying" in reply.lower())

        player.pickup(items.Beer())
        reply = room.drink(items.Beer())
        self.assertTrue("you drink the beer" in reply.lower())
        print(reply)

        player.pickup(potions.HealingPotion())
        reply = room.drink(potions.HealingPotion())
        self.assertTrue("you drink the healing potion" in reply.lower())
        print(reply)
Example #5
0
 def test_get_attack_type(self):
     self.assertEqual(weapons.Spear().get_attack_type(), 'spear')
     self.assertEqual(weapons.Dagger().get_attack_type(), 'dagger')
     self.assertEqual(weapons.LongSword().get_attack_type(), 'sword')
     self.assertEqual(weapons.ShortSword().get_attack_type(), 'sword')
     self.assertEqual(weapons.LongBow().get_attack_type(), 'arrow')
     self.assertEqual(weapons.ShortBow().get_attack_type(), 'arrow')
     self.assertEqual(weapons.Spear().get_attack_type(), 'spear')
Example #6
0
    def test_describe(self):
        gm = game_manager
        player = gm.create_player('mage')
        gm.start_new_game('fred', player)
        user = gm.get_user('fred', 'test')
        user.set_room(rooms.CellRoom(player))
        room = user.room

        reply = room.describe(weapons.Dagger())
        print(reply)
Example #7
0
    def test_Attack(self):
        player = Thief()  #+2 attack bonus at level 1
        player.strength_base = 17  #+3 strength modifier
        player.equip_weapon(weapons.Dagger())  #+2 proficiency
        for _i in range(100):
            dice_roll = GameRules.roll_weapon_attack_score(player)
            #critical_strike = player.get_equipped_weapon().is_critical_strike(dice_roll.roll)
            print("Player Attack score: {}".format(dice_roll.total))
            if not player.get_equipped_weapon().is_critical_miss(
                    dice_roll.roll):
                self.assertGreaterEqual(dice_roll.total, 7)
            self.assertLessEqual(dice_roll.total, 27)

        player.add_bonus('POTION', PlayerAttributes.STRENGTH,
                         4)  #21 strength, +5 strength modifer
        for _i in range(100):
            dice_roll = GameRules.roll_weapon_attack_score(player)
            #critical_strike = player.get_equipped_weapon().is_critical_strike(dice_roll.roll)
            print("Player Attack score: {}".format(dice_roll.total))
            if not player.get_equipped_weapon().is_critical_miss(
                    dice_roll.roll):
                self.assertGreaterEqual(dice_roll.total, 9)
            self.assertLessEqual(dice_roll.total, 29)

        player.remove_bonus('POTION')
        player.equip_weapon(weapons.LongBow())  #0 proficiency
        player.dexterity_base = 0  #-5 dexterity modifier, +2 attack bonus
        for _i in range(100):
            dice_roll = GameRules.roll_weapon_attack_score(player)
            #critical_strike = player.get_equipped_weapon().is_critical_strike(dice_roll.roll)
            print("Player Attack score: {}".format(dice_roll.total))
            if not player.get_equipped_weapon().is_critical_miss(
                    dice_roll.roll):
                self.assertGreaterEqual(dice_roll.total, -2)
            self.assertLessEqual(dice_roll.total, 17)

        player.dexterity_base = 12  #+1 dexterity modifier
        for _i in range(100):
            dice_roll = GameRules.roll_weapon_attack_score(player)
            #critical_strike = player.get_equipped_weapon().is_critical_strike(dice_roll.total)
            print("Player Attack score: {}".format(dice_roll.total))
            if not player.get_equipped_weapon().is_critical_miss(
                    dice_roll.roll):
                self.assertGreaterEqual(dice_roll.total, 4)
            self.assertLessEqual(dice_roll.total, 23)
Example #8
0
    def __init__(self, player, load_from_state=False):
        super(CellRoom, self).__init__(player)

        self._add_action_override(Actions.OPEN,'loose_stone',new_action=Actions.PULL)
        self._add_action_override(Actions.PICKUP,'loose_stone',new_action=Actions.PULL)
        self._add_action_override(Actions.PULL,'door',new_action=Actions.OPEN)

        if not load_from_state:
            RoomOpenableItem(self, 'loose_stone', is_hidden=True)
            if player.is_mage: itms = [weapons.Staff(), armor.Robe()]
            elif player.is_thief: itms = [weapons.Dagger(), armor.LightArmor()]
            elif player.is_fighter: itms = [weapons.LongSword(), armor.HeavyArmor()]
            elif player.is_ranger: itms = [weapons.LongBow(), armor.LightArmor(), weapons.WoodArrow(10)]
            SearchableItem(self, 'straw', itms)
            Door(self, 'door', is_open=False, key_id=Keys.CELLROOM_DOOR_KEY, spell_resistance=5, lock_resistance=5)
            RoomItem(self, 'barred_window')
            self.add_floor_item(items.StaleBread())
            self._set_state('hidden_item_taken', False)
Example #9
0
    def test_Skills(self):
        player = Thief()
        player.strength_base = 17
        player.equip_weapon(weapons.Dagger())
        player.add_experience(14000)
        self.assertEqual(player.level, 5)  #3d6 damage
        for _i in range(100):
            dmg = skills.SneakAttack().damage(player)
            print("Player Sneak Attack score: {}".format(dmg))
            self.assertGreaterEqual(dmg, 3)
            self.assertLessEqual(dmg, 18)

        #Add ThiefsDagger (+1 SneakAttack bonus)
        player.equip_weapon(weapons.ThiefsDagger())
        for _i in range(100):
            dmg = skills.SneakAttack().damage(player)
            print("Player Sneak Attack score: {}".format(dmg))
            self.assertGreaterEqual(dmg, 4)
            self.assertLessEqual(dmg, 19)
Example #10
0
    def test_goblin(self):
        player = players.Thief()
        player.equip_weapon(weapons.Dagger())
        player.equip_armor(armor.LightArmor())
        player.strength_base = 15
        player.dexterity_base = 10

        player.max_hit_points = 100

        goblin = players.Goblin()
        goblin.affect(player, players.Effects.Heal, 0)
        self.assertGreaterEqual(goblin.hit_points, 2, "Hit points set")

        goblin.max_hit_points = 100

        player_def = player.get_defense()
        goblin_def = goblin.get_defense()
        print("Player Hit Points: {}".format(player.hit_points))
        print("Player def: {}".format(player_def))
        print("Player ability modifier: {}".format(
            player.determine_ability_modifier()))
        print("Player proficiency modifier: {}".format(
            player.determine_proficiency_bonus()))
        print("---")
        print("Goblin Hit Points: {}".format(goblin.hit_points))
        print("Goblin def: {}".format(goblin_def))
        print("Goblin ability modifier: {}".format(
            goblin.determine_ability_modifier()))
        print("Goblin proficiency modifier: {}".format(
            goblin.determine_proficiency_bonus()))
        print("---")
        dice_roll = GameRules.roll_initiative_check(goblin)
        gob_init_check = dice_roll.total
        dice_roll = GameRules.roll_initiative_check(player)
        player_init_check = dice_roll.total
        print("Goblin Initiative: {} ({})".format(gob_init_check,
                                                  goblin.initiative_bonus))
        print("Player Initiative: {} ({})".format(player_init_check,
                                                  player.initiative_bonus))
        if gob_init_check > player_init_check:
            print("Goblin was quicker to react, and starts first")
        else:
            print("Player was quicker to react, and starts first")
        print("---")

        #Attacks
        a = base_classes.Observer(goblin)
        b = base_classes.Observer(player)

        done_sneak_attack = False

        while not goblin.is_dead and not player.is_dead:
            if gob_init_check < player_init_check:
                player.strike(goblin)
                if not done_sneak_attack:
                    player.skill_attack(skills.SneakAttack(), goblin)
                    done_sneak_attack = True
                goblin.strike(player)
            else:
                goblin.strike(player)
                player.strike(goblin)
                if not done_sneak_attack:
                    player.skill_attack(skills.SneakAttack(), goblin)
                    done_sneak_attack = True
Example #11
0
class PlayerStats(BaseStats):
    __PlayerAttributes = 1
    __WEAPON = 2
    __ARMOR = 3
    __HIT_POINTS = 4
    __ATTR_MODIFIERS = BaseStats._ATTR_MODIFIERS
    __SKILL_MODIFIERS = BaseStats._SKILL_MODIFIERS
    _STATS = {
        Thief: {
            __HIT_POINTS: [1, 8, 8],  #1d8+8
            __PlayerAttributes: {
                PlayerAttributes.INTELLIGENCE: 8,
                PlayerAttributes.STRENGTH: 10,
                PlayerAttributes.DEXTERITY: 11,
                PlayerAttributes.CONSITUTION: 12,
                PlayerAttributes.WISDOM: 2,
                PlayerAttributes.CHARISMA: 2,
            },
            __ATTR_MODIFIERS: {
                'Faster Reaction': [PlayerAttributes.INITIATIVE, 2],
                'Throw bonus': [PlayerAttributes.THROW, 2]
            },
            __WEAPON: weapons.Fists(),
            __ARMOR: armor.BodyArmor()
        },
        Fighter: {
            __HIT_POINTS: [1, 8, 8],  #1d8+8
            __PlayerAttributes: {
                PlayerAttributes.INTELLIGENCE: 8,
                PlayerAttributes.STRENGTH: 10,
                PlayerAttributes.DEXTERITY: 11,
                PlayerAttributes.CONSITUTION: 12,
                PlayerAttributes.WISDOM: 2,
                PlayerAttributes.CHARISMA: 2,
            },
            __ATTR_MODIFIERS: {
                'Faster Reaction': [PlayerAttributes.INITIATIVE, 2],
                'Throw bonus': [PlayerAttributes.THROW, 2]
            },
            __WEAPON: weapons.Fists(),
            __ARMOR: armor.BodyArmor()
        },
        Ranger: {
            __HIT_POINTS: [1, 8, 8],  #1d8+8
            __PlayerAttributes: {
                PlayerAttributes.INTELLIGENCE: 8,
                PlayerAttributes.STRENGTH: 10,
                PlayerAttributes.DEXTERITY: 11,
                PlayerAttributes.CONSITUTION: 12,
                PlayerAttributes.WISDOM: 2,
                PlayerAttributes.CHARISMA: 2,
            },
            __ATTR_MODIFIERS: {
                'Faster Reaction': [PlayerAttributes.INITIATIVE, 2],
                'Throw bonus': [PlayerAttributes.THROW, 2]
            },
            __WEAPON: weapons.Fists(),
            __ARMOR: armor.BodyArmor()
        },
        Mage: {
            __HIT_POINTS: [1, 6, 6],  #1d6+6
            __PlayerAttributes: {
                PlayerAttributes.INTELLIGENCE: 12,
                PlayerAttributes.STRENGTH: 8,
                PlayerAttributes.DEXTERITY: 11,
                PlayerAttributes.CONSITUTION: 10,
                PlayerAttributes.WISDOM: 8,
                PlayerAttributes.CHARISMA: 4,
            },
            __ATTR_MODIFIERS: {
                'Faster Reaction': [PlayerAttributes.INITIATIVE, 2]
            },
            __WEAPON: weapons.Fists(),
            __ARMOR: armor.BodyArmor()
        },
        Goblin: {
            __HIT_POINTS: [1, 8, 1],  #1d8+1
            __PlayerAttributes: {
                PlayerAttributes.INTELLIGENCE: 5,
                PlayerAttributes.STRENGTH: 10,
                PlayerAttributes.DEXTERITY: 11,
                PlayerAttributes.CONSITUTION: 12,
                PlayerAttributes.WISDOM: 2,
                PlayerAttributes.CHARISMA: 2,
            },
            __ATTR_MODIFIERS: {
                'Faster Reaction': [PlayerAttributes.INITIATIVE, 2]
            },
            __WEAPON: weapons.Dagger(),
            __ARMOR: armor.LightArmor()
        },
        Rat: {
            __HIT_POINTS: [1, 6, 1],  #1d6+1
            __PlayerAttributes: {
                PlayerAttributes.INTELLIGENCE: 2,
                PlayerAttributes.STRENGTH: 8,
                PlayerAttributes.DEXTERITY: 8,
                PlayerAttributes.CONSITUTION: 4,
                PlayerAttributes.WISDOM: 1,
                PlayerAttributes.CHARISMA: 1,
            },
            __ATTR_MODIFIERS: {
                'Faster Reaction': [PlayerAttributes.INITIATIVE, 2]
            },
            __WEAPON: weapons.Claws(),
            __ARMOR: armor.FurArmor()
        },
        ZombieRat: {
            __HIT_POINTS: [1, 6, 1],  #1d6+1
            __PlayerAttributes: {
                PlayerAttributes.INTELLIGENCE: 2,
                PlayerAttributes.STRENGTH: 8,
                PlayerAttributes.DEXTERITY: 8,
                PlayerAttributes.CONSITUTION: 4,
                PlayerAttributes.WISDOM: 1,
                PlayerAttributes.CHARISMA: 1,
            },
            __ATTR_MODIFIERS: {
                'Faster Reaction': [PlayerAttributes.INITIATIVE, 2]
            },
            __WEAPON: weapons.Claws(),
            __ARMOR: armor.FurArmor()
        },
    }

    @staticmethod
    def get_attributes(monster):
        return PlayerStats._STATS[monster.__class__][
            PlayerStats.__PlayerAttributes]

    @staticmethod
    def get_weapon(monster):
        return PlayerStats._STATS[monster.__class__][PlayerStats.__WEAPON]

    @staticmethod
    def get_armor(monster):
        return PlayerStats._STATS[monster.__class__][PlayerStats.__ARMOR]

    @staticmethod
    def get_hp_dice(monster):
        return PlayerStats._STATS[monster.__class__][
            PlayerStats.__HIT_POINTS][0]

    @staticmethod
    def get_hp_sides(monster):
        return PlayerStats._STATS[monster.__class__][
            PlayerStats.__HIT_POINTS][1]

    @staticmethod
    def get_hp_bonus(monster):
        return PlayerStats._STATS[monster.__class__][
            PlayerStats.__HIT_POINTS][2]
Example #12
0
    def test_CellRoom_Thief(self):
        gm = game_manager
        player = gm.create_player('thief')
        gm.start_new_game('fred', player)
        user = gm.get_user('fred', 'test')
        user.set_room(rooms.CellRoom(player))

        #What can I do
        request = AlexaRequest(self.app,
                               user_id='fred',
                               application_id='quest_game')
        request.set_intent('WhatCanIDoIntent')
        response = request.post()
        print(response.get_output_text())
        self.assertTrue(
            'you could search the room' in response.get_output_text().lower())
        player = user.room.player

        #Search room
        request = AlexaRequest(self.app,
                               user_id='fred',
                               application_id='quest_game')
        request.set_intent('SearchIntent')
        request.set_slots([request.create_slot('sitem', 'room')])
        response = request.post()
        print(response.get_output_text())
        self.assertTrue(
            ReplyHelpers.render_room_template('cellroom_search') in
            response.get_output_text())
        player = user.room.player

        #What can I do
        request = AlexaRequest(self.app,
                               user_id='fred',
                               application_id='quest_game')
        request.set_intent('WhatCanIDoIntent')
        response = request.post()
        print(response.get_output_text())
        self.assertTrue('you could open the loose stone' in
                        response.get_output_text().lower())

        #Search room
        request.set_intent('SearchIntent')
        response = request.post()
        print(response.get_output_text())
        self.assertTrue(
            ReplyHelpers.render_room_template('cellroom_search') in
            response.get_output_text())

        #What can I do
        request.set_intent('WhatCanIDoIntent')
        response = request.post()
        print(response.get_output_text())

        #Pull loose stone
        request.set_intent('PullIntent')
        request.set_slots([request.create_slot('item', 'loose stone')])
        response = request.post()
        print(response.get_output_text())
        lockpick = items.LockPick()
        self.assertTrue(
            ReplyHelpers.render_room_template('cellroom_pull_stone') in
            response.get_output_text())
        self.assertTrue(
            ReplyHelpers.render_room_template('cellroom_pull_stone_full',
                                              item_text=lockpick.description)
            in response.get_output_text())
        self.assertTrue(player.is_carrying(lockpick))

        #What can I do
        request = AlexaRequest(self.app,
                               user_id='fred',
                               application_id='quest_game')
        request.set_intent('WhatCanIDoIntent')
        response = request.post()
        print(response.get_output_text())
        self.assertTrue(
            'you could search the straw' in response.get_output_text().lower())

        #Pull loose stone again
        request.set_intent('OpenIntent')
        request.set_slots([request.create_slot('oitem', 'loose stone')])
        response = request.post()
        print(response.get_output_text())
        self.assertTrue(
            ReplyHelpers.render_room_template('cellroom_pull_stone') in
            response.get_output_text())
        self.assertTrue(
            ReplyHelpers.render_room_template('cellroom_pull_stone_empty') in
            response.get_output_text())

        #Pull door
        request.set_intent('PullIntent')
        request.set_slots([request.create_slot('item', 'door')])
        response = request.post()
        print(response.get_output_text())
        self.assertTrue(
            ReplyHelpers.render_room_template('locked', item='door') in
            response.get_output_text())

        #Open something
        request.set_intent('OpenIntent')
        request.set_slots([])
        response = request.post()
        print(response.get_output_text())

        request.set_intent('SelectItemIntent')
        request.set_slots([request.create_slot('ditem', 'door')])
        response = request.post(request.session_id)
        print(response.get_output_text())
        self.assertTrue(
            ReplyHelpers.render_room_template('locked', item='door') in
            response.get_output_text())

        #Pull chest
        request.set_intent('PullIntent')
        request.set_slots([request.create_slot('item', 'chest')])
        response = request.post()
        print(response.get_output_text())
        self.assertTrue(
            ReplyHelpers.render_room_template(
                'no_such_room_item', room='room', action='pull') in
            response.get_output_text())

        #Describe dagger
        request.set_intent('DescribeItemIntent')
        request.set_slots([request.create_slot('ditem', 'dagger')])
        response = request.post()
        print(response.get_output_text())
        self.assertTrue(
            ReplyHelpers.render_room_template(
                'no_such_room_item', room='room', action='describe') in
            response.get_output_text())

        #Open door
        request.set_intent('OpenIntent')
        request.set_slots([request.create_slot('oitem', 'door')])
        response = request.post()
        print(response.get_output_text())
        self.assertTrue(
            ReplyHelpers.render_room_template('locked', item='door') in
            response.get_output_text())

        #Open window
        request.set_intent('OpenIntent')
        request.set_slots([request.create_slot('oitem', 'window')])
        response = request.post()
        print(response.get_output_text())
        self.assertTrue(
            ReplyHelpers.render_room_template(
                'cellroom_barred_window_open_cannot') in
            response.get_output_text())

        #Pickup bread
        request.set_intent('PickupIntent')
        request.set_slots([request.create_slot('ditem', 'bread')])
        response = request.post()
        print(response.get_output_text())
        self.assertTrue(
            ReplyHelpers.render_room_template(
                'pickup_item', item=items.StaleBread().description) in
            response.get_output_text())

        #Pickup bread
        request.set_intent('PickupIntent')
        request.set_slots([request.create_slot('ditem', 'bread')])
        response = request.post()
        print(response.get_output_text())
        self.assertTrue(
            ReplyHelpers.render_room_template(
                'no_such_room_item', action='pickup', room='room') in
            response.get_output_text())

        #Drop bread
        request.set_intent('DropIntent')
        request.set_slots([request.create_slot('ditem', 'bread')])
        response = request.post()
        print(response.get_output_text())
        self.assertTrue(
            ReplyHelpers.render_room_template(
                'drop_item', item=items.StaleBread().description) in
            response.get_output_text())

        #Pickup bread
        request.set_intent('PickupIntent')
        request.set_slots([request.create_slot('ditem', 'bread')])
        response = request.post()
        print(response.get_output_text())
        self.assertTrue(
            ReplyHelpers.render_room_template(
                'pickup_item', item=items.StaleBread().description) in
            response.get_output_text())

        #Search floor
        request.set_intent('SearchIntent')
        request.set_slots([request.create_slot('sitem', 'floor')])
        response = request.post()
        print(response.get_output_text())
        self.assertTrue(
            ReplyHelpers.render_room_template('search_item', item='floor') in
            response.get_output_text())

        picked = False
        while not picked:
            #Picklock door
            request.set_intent('PickLockIntent')
            request.set_slots([request.create_slot('oitem', 'door')])
            response = request.post()
            picked = ReplyHelpers.render_room_template(
                'picklock_success', item='door') in response.get_output_text()
            self.assertTrue(
                ReplyHelpers.render_room_template('picklock_success',
                                                  item='door')
                in response.get_output_text()
                or ReplyHelpers.render_room_template('picklock_fail',
                                                     item='door')
                in response.get_output_text())

        player = user.player
        player.max_hit_points = 100
        player.strength_base = 15
        player.dexterity_base = 10

        #Search straw
        request.set_intent('SearchIntent')
        request.set_slots([request.create_slot('sitem', 'straw')])
        response = request.post()
        print(response.get_output_text())
        self.assertTrue(
            ReplyHelpers.render_room_template('search_item', item='straw') in
            response.get_output_text())

        #Rat has attacked
        #Describe rat
        monster = user.room.get_monsters()[0]
        monster.max_hit_points = 20
        request.set_intent('DescribeItemIntent')
        request.set_slots([request.create_slot('ditem', 'rat')])
        response = request.post()
        print(response.get_output_text())
        self.assertTrue(
            ReplyHelpers.render_descr_template('descr_rat',
                                               hit_points=monster.hit_points)
            in response.get_output_text())

        while len(user.room.get_alive_monsters()) > 0:
            if player.get_item(weapons.Dagger()).count == 4:
                request.set_intent('ThrowTargetIntent')
                request.set_slots([
                    request.create_slot('target', 'rat'),
                    request.create_slot('titem', 'dagger')
                ])
            elif player.get_item(weapons.Dagger()).count == 3:
                request.set_intent('ThrowIntent')
                request.set_slots([request.create_slot('titem', 'dagger')])
            else:
                request.set_intent('StrikeIntent')
                request.set_slots([request.create_slot('target', 'rat')])
                if player.get_item(weapons.Dagger()).count == 1:
                    player.pickup(weapons.Dagger(3))

            response = request.post()
            print(response.get_output_text())

        #search rat
        request.set_intent('SearchIntent')
        request.set_slots([request.create_slot('sitem', 'rat')])
        response = request.post()
        print(response.get_output_text())
        #self.assertTrue(ReplyHelpers.render_room_template('search_item',item='rat') in response.get_output_text())

        request.set_intent('DescribeItemIntent')
        request.set_slots([request.create_slot('ditem', 'rat')])
        response = request.post()
        print(response.get_output_text())
        self.assertTrue(
            ReplyHelpers.render_descr_template('descr_rat',
                                               hit_points=monster.hit_points)
            in response.get_output_text())

        #Describe dagger
        request.set_intent('DescribeItemIntent')
        request.set_slots([request.create_slot('ditem', 'dagger')])
        response = request.post()
        print(response.get_output_text())
        self.assertTrue(
            ReplyHelpers.render_descr_template('descr_dagger') in
            response.get_output_text())

        #Open door
        request.set_intent('OpenIntent')
        request.set_slots([request.create_slot('oitem', 'door')])
        response = request.post()
        print(response.get_output_text())
        self.assertTrue(
            ReplyHelpers.render_room_template('door_open') in
            response.get_output_text())

        #Go back to cell
        request.set_intent('OpenIntent')
        request.set_slots([request.create_slot('oitem', 'door')])
        response = request.post()
        print(response.get_output_text())

        #Open door again
        request.set_intent('OpenIntent')
        request.set_slots([request.create_slot('oitem', 'door')])
        response = request.post()
        print(response.get_output_text())
        self.assertTrue(
            ReplyHelpers.render_room_template('door_already_open') in
            response.get_output_text())

        #Unlock open door
        request.set_intent('UnlockIntent')
        request.set_slots([request.create_slot('oitem', 'door')])
        response = request.post()
        print(response.get_output_text())
        self.assertTrue(
            ReplyHelpers.render_room_template('not_locked', item='door') in
            response.get_output_text())

        #Close an open door
        request.set_intent('CloseIntent')
        request.set_slots([request.create_slot('oitem', 'door')])
        response = request.post()
        print(response.get_output_text())
        self.assertTrue(
            ReplyHelpers.render_room_template('close', item='door') in
            response.get_output_text())

        #Describe dagger
        request.set_intent('DescribeItemIntent')
        request.set_slots([request.create_slot('ditem', 'dagger')])
        response = request.post()
        print(response.get_output_text())
        self.assertTrue(
            ReplyHelpers.render_descr_template('descr_dagger') in
            response.get_output_text())
Example #13
0
    def test_store(self):
        gm = game_manager
        player = gm.create_player('mage')
        gm.start_new_game('fred', player)
        user = gm.get_user('fred', 'test')

        room = rooms.room.StoreRoom(player, [weapons.Weapon, armor.Armor])
        room.store_item(weapons.Dagger(), is_unlimited=True)
        room.store_item(weapons.WoodArrow(10))

        player.pickup(items.Gold())
        self.assertFalse(player.is_carrying(weapons.Dagger()))
        result = room.buy('dagger')
        self.assertTrue("you buy the dagger" in result.lower())
        print(result)
        self.assertTrue(player.is_carrying(weapons.Dagger()))
        self.assertTrue(player.money == 0.8)
        result = room.buy('dagger', 2)
        self.assertTrue("you buy the daggers" in result.lower())
        print(result)
        self.assertTrue(player.inventory.count_items(weapons.Dagger()) == 3)
        self.assertTrue(player.money == 0.4)

        result = room.buy('healing potion')
        self.assertTrue("you can't buy" in result.lower())
        print(result)

        result = room.buy('light armor')
        self.assertTrue("you can't buy" in result.lower())
        print(result)

        #Not enough money
        result = room.buy('daggers', 3)
        self.assertTrue("you don't have enough" in result.lower())
        print(result)
        self.assertTrue(player.inventory.count_items(weapons.Dagger()) == 3)
        self.assertTrue(player.money == 0.4)

        result = room.sell('healing potion')
        self.assertTrue("you couldn't sell" in result.lower())
        print(result)

        player.pickup(armor.LightArmor())
        result = room.sell('light armor')
        self.assertTrue("you sell the light armor" in result.lower())
        print(result)

        result = room.sell('dagger')
        self.assertTrue("you sell the dagger" in result.lower())
        print(result)
        self.assertTrue(player.inventory.count_items(weapons.Dagger()) == 2)
        self.assertTrue(player.money == 5.6)
        result = room.buy('light armor')
        self.assertTrue(player.money == 0.6)

        result = room.whats_for_sale()
        self.assertTrue("10 wood arrows" in result.lower())
        print(result)

        #Sell too many
        result = room.sell('daggers', 3)
        self.assertTrue("you're not carrying enough" in result.lower())
        print(result)
        self.assertTrue(player.inventory.count_items(weapons.Dagger()) == 2)
        self.assertTrue(player.money == 0.6)

        #Buy all the arrows
        player.pickup(items.Gold(3))
        result = room.buy('wood arrows', 10)
        self.assertTrue("you buy the wood arrows" in result.lower())
        print(result)

        result = room.whats_for_sale()
        self.assertTrue("wood arrows" not in result.lower())
        print(result)

        result = room.buy('wood arrow')
        self.assertTrue("you can't buy" in result.lower())
        print(result)
Example #14
0
 def test_is_throwable(self):
     self.assertTrue(weapons.Spear().is_throwable)
     self.assertFalse(weapons.ShortSword().is_throwable)
     self.assertTrue(weapons.Dagger().is_throwable)
     self.assertFalse(weapons.LongBow().is_throwable)
     self.assertFalse(weapons.IronArrow().is_throwable)