예제 #1
0
 def generate_role(self):
     #chance player will queue for each role
     support_chance = 0.25
     tank_chance = 0.15
     dps_chance = 0.9
     if roll(support_chance):
         self.support = True
     if roll(tank_chance):
         self.tank = True
     if roll(dps_chance):
         self.dps = True
     if not self.tank and not self.support and not self.dps:
         Player.generate_role(self)
예제 #2
0
    def open_door(bus, door, entity_that_actioned):
        # By default doors are forced
        roll = ut.roll(20)
        if roll > entity_that_actioned.strength:
            # Failure when opening doors
            bus.publish(door, {
                "object": door,
                "operator": entity_that_actioned,
                "result": c.FAILURE
            },
                        main_category=c.P_CAT_ENV,
                        sub_category=c.AC_ENV_OPEN)
            return False

        # Door is successfully opened
        door.blocks = False
        door.actionable = None
        bus.publish(door, {
            "object": door,
            "operator": entity_that_actioned,
            "result": c.SUCCESS
        },
                    main_category=c.P_CAT_ENV,
                    sub_category=c.AC_ENV_OPEN)
        door.image_ref = door.image_refs[door.index + 1 % 4]
        door.image = door.game.all_images[door.image_ref]
        door.set_in_spritegroup(-1)
        return True
예제 #3
0
    def identify(self, force=False):
        """
        Identify an item. Not that there is a chance that identification results in breaking the item...
        :param force: if set to True then the item will always be identified
        :return: True if the item is identified, False otherwise
        """

        if self.identified:
            return True
        else:

            if not force:
                modifier = 0
                if c.IDENTIFICATION_MODIFIER in self.identification:
                    modifier = self.identification["identification_modifier"]

                # Test: can we identify
                roll = ut.roll(20) + modifier
                if roll > self.owner.game.player.mind:
                    # Failure in identifying the object may result in breaking it...
                    roll = ut.roll(20) + modifier
                    if roll > self.owner.game.player.dexterity:
                        # We broke it...
                        self.owner.game.bus.publish(
                            self.owner, {
                                "item": self.owner,
                                "result": c.FAILURE
                            },
                            main_category=c.P_CAT_ITEM,
                            sub_category=c.AC_ITEM_IDENTIFY)
                        self.owner.game.player.inventory.remove(
                            self.owner)  # destroy it
                    return False

            self.identified = True
            assert self.owner is not None, "Item doesn't seem to have an owner??"
            self.owner.long_desc = self.owner.long_desc_after
            self.owner.name = self.owner.name_after
            self.owner.game.bus.publish(self.owner, {
                "item": self.owner,
                "result": c.SUCCESS
            },
                                        main_category=c.P_CAT_ITEM,
                                        sub_category=c.AC_ITEM_IDENTIFY)
            return True
예제 #4
0
 def attack(self, other_fighter, attack_type="Melee"):
     # attack_rolls = 1D20 + attack bonus
     attack_bonus = self.owner.get_stat_bonus("strength") + self.physical_combat_bonus
     attack_roll = ut.roll(20) + attack_bonus
     if attack_roll > other_fighter.armor_class:
         # Hit: damage weapon (should be from inventory) + srtength bonus + class bonus
         damage = ut.roll(6) + self.owner.get_stat_bonus("strength")
         self.owner.game.bus.publish(self.owner, {"attacker": self.owner,
                                                  "defender": other_fighter.owner,
                                                  "result": c.SUCCESS,
                                                  "attack_type": "weapon",
                                                  "damage": damage},
                                     main_category=c.P_CAT_FIGHT, sub_category=c.AC_FIGHT_HIT)
         other_fighter.take_damage(damage)
     else:
         self.owner.game.bus.publish(self.owner, {"attacker": self.owner,
                                                  "defender": other_fighter.owner,
                                                  "result": c.FAILURE,
                                                  "attack_type": "weapon"},
                                     main_category=c.P_CAT_FIGHT, sub_category=c.AC_FIGHT_HIT)
def statchoice():
    # Using the roll function, we get 6 ability scores, append them to 'stats',
    # and run the choosestat function for each to set stats.
    stats = []
    stats.append(roll(4, 6))
    stats.append(roll(4, 6))
    stats.append(roll(4, 6))
    stats.append(roll(4, 6))
    stats.append(roll(4, 6))
    stats.append(roll(4, 6))
    

    choosestat("strength", 6, 1, stats)
    choosestat("intelligence", 5, 1, stats)
    choosestat("wisdom", 4, 1, stats)
    choosestat("dexterity", 3, 1, stats)
    choosestat("constitution", 2, 1, stats)
    choosestat("charisma", 1, 1, stats)

    displaystats(playerchar)
    reroll = raw_input("Do you wish to re-roll?")
    if reroll == "yes" or reroll == "y":
        statchoice()
    else:
        new_maxhp(playerchar)
        new_maxhp(enemychar)
        new_maxwieght()
        Start_Text()
        profession()
예제 #6
0
 def leave_queue(self):
     chance = 1
     session_time = self.active_session_time
     if session_time < self.min_session_time:
         chance = self.min_stop_chance
     elif session_time < self.max_session_time:
         chance = self.med_stop_chance
     else:
         chance = self.max_stop_chance
     if self.current_wait_time > self.queue_time_limit:
         chance += self.chance_increase
     if roll(chance):
         return True
     return False
예제 #7
0
파일: player.py 프로젝트: staug/LordCrocket
 def gain_experience(self, amount):
     self.experience += amount
     if self.level == 1 and self.experience > 3100:
         self.level = 2
         self.base_hit_points += ut.roll(8)
         self.fighter.physical_combat_bonus = 2
         self.fighter.magical_combat_bonus = 1
         self.saving_throw = 12
         # We fully heal the player
         self.fighter.body_points = self.base_body_points
         self.fighter.hit_points = self.base_hit_points
         print("LEVEL UP")
     elif self.level == 2 and self.experience > 12500:
         self.level = 3
예제 #8
0
 def attack(self, other_fighter):
     # attack_rolls
     for attack in self.attacks:
         attack_roll = ut.roll(20) + self.attack_bonus
         if attack_roll > other_fighter.armor_class:
             # Hit
             damage = ut.roll(attack[1][1], repeat=attack[1][0]) + attack[1][2]
             self.owner.game.bus.publish(self.owner, {"attacker":self.owner,
                                                      "defender":other_fighter.owner,
                                                      "result": c.SUCCESS,
                                                      "attack_type": attack[0], "damage": damage},
                                         main_category=c.P_CAT_FIGHT, sub_category=c.AC_FIGHT_HIT)
             other_fighter.take_damage(damage)
         else:
             self.owner.game.bus.publish(self.owner, {"attacker":self.owner,
                                                      "defender":other_fighter.owner,
                                                      "result": c.FAILURE,
                                                      "attack_type": attack[0]},
                                         main_category=c.P_CAT_FIGHT, sub_category=c.AC_FIGHT_HIT)
     # specials
     if self.specials is not None:
         for special_function in self.specials:
             special_function()
예제 #9
0
    def __init__(self, armor_class=0, hit_dice=(1, 8, 0), attacks=None, morale=0, saving_throw=0,
                 specials=None, death_function=None):

        FighterEntity.__init__(self, hit_points=ut.roll(hit_dice[1], repeat=hit_dice[0]) + hit_dice[2],
                               death_function=death_function)

        if self.death_function is None:
            self.death_function = self.monster_death

        self.attack_bonus = hit_dice[0]
        self.armor_class = armor_class

        self.level = self.attack_bonus = hit_dice[0]
        self.attacks = attacks

        # The following are not used:
        self.morale = morale
        self.saving_throw = saving_throw
        self.specials = specials
예제 #10
0
 def light_damage(target):
     # We test if we have a saving throw from the entity standpoint
     saving = ut.roll(20)
     if saving == 1 or saving <= target.fighter.saving_throw:
         # success
         target.game.bus.publish(target, {
             "defender": target,
             "result": c.SUCCESS,
             "spell_type": "fireball"
         },
                                 main_category=c.P_CAT_FIGHT,
                                 sub_category=c.AC_SPELL)
         target.fighter.take_damage(20)
     else:
         # failure
         target.game.bus.publish(target, {
             "defender": target,
             "result": c.FAILURE,
             "spell_type": "fireball"
         },
                                 main_category=c.P_CAT_FIGHT,
                                 sub_category=c.AC_SPELL)
예제 #11
0
파일: player.py 프로젝트: staug/LordCrocket
    def __init__(self, game, pos):

        self.inventory = []
        self.quest_list = []
        self.registered_actions = []  # use for buf and debuf

        # Rolling base stats
        self.base_strength = ut.roll(6, 3)
        self.base_dexterity = ut.roll(6, 3)
        self.base_mind = ut.roll(6, 3)
        self.base_charisma = ut.roll(6, 3)
        # As a human, adding +1 to 2 random Characteristics
        characteristics = [c.CHAR_NAME, c.STR_NAME, c.DEX_NAME, c.MIND_NAME]
        rd.shuffle(characteristics)
        setattr(self, 'base_' + characteristics[0],
                getattr(self, characteristics[0]) + 1)
        setattr(self, 'base_' + characteristics[1],
                getattr(self, characteristics[1]) + 1)

        # Now starting as an adventurer
        self.base_hit_points = ut.roll(8) + self.strength
        self.base_body_points = 20

        self.saving_throw = 14

        self.experience = 0
        self.level = 1

        Entity.__init__(self,
                        game,
                        MName.name(),
                        pos,
                        "PLAYER",
                        vision=4,
                        fighter=PlayerFighter(
                            hit_points=self.base_hit_points,
                            body_points=self.base_body_points,
                            physical_combat_bonus=1,
                            magical_combat_bonus=0))
        self.inventory_max = 100
        self.base_speed = 10
        self.wealth = 0

        self.invalidate_fog_of_war = True

        # Player needs to heal from exploration
        self.time_before_next_heal = 10  # in 10 turn, recover strength bonus health
        game.bus.register(self,
                          main_category=c.P_CAT_ENV,
                          sub_category=c.AC_ENV_MOVE,
                          function_to_call=self.exploration_heal)

        # TODO Remove the following tests in real life
        self.quest_list.append(
            KillQuest(self,
                      game.bus,
                      "BAT",
                      2,
                      "kill at least 2 bats",
                      rewards={
                          "target": self,
                          "wealth": 20,
                          "xp": 10
                      }))
        self.quest_list.append(
            KillQuest(self,
                      game.bus,
                      "ANY",
                      5,
                      "kill five enemies",
                      rewards={
                          "target": self,
                          "wealth": 15,
                          "xp": 20
                      }))
        self.quest_list.append(
            KillQuest(self,
                      game.bus,
                      "ANY",
                      1,
                      "kill whatever creature",
                      rewards={
                          "target": self,
                          "wealth": 10,
                          "xp": 15
                      }))
        self.quest_list.append(
            KillAllQuest(self,
                         game.bus,
                         game.objects,
                         rewards={
                             "target": self,
                             "wealth": 100,
                             "xp": 150
                         }))
예제 #12
0
    def instantiate_item(game, item, pos):
        if item == "CHEST_GOLD":
            entities.OpenableObjectHelper(
                game,
                pos,
                "CHEST_CLOSED",
                "CHEST_OPEN_GOLD",
                name="Chest",
                use_function=entities.OpenableObjectHelper.manipulate_treasure)
        elif item == "CHEST_TRAP":
            entities.OpenableObjectHelper(
                game,
                pos,
                "CHEST_CLOSED",
                "CHEST_OPEN_TRAP",
                name="Chest",
                use_function=entities.OpenableObjectHelper.manipulate_trap)
        elif item == "CHEST_EMPTY":
            entities.OpenableObjectHelper(
                game,
                pos,
                "CHEST_CLOSED",
                "CHEST_OPEN_EMPTY",
                name="Chest",
                use_function=entities.OpenableObjectHelper.manipulate_empty)
        elif item == "COFFIN":
            entities.OpenableObjectHelper(
                game,
                pos,
                "COFFIN_CLOSED",
                "COFFIN_OPEN",
                name="Chest",
                use_function=entities.OpenableObjectHelper.manipulate_vampire)
        #  ************ POTION ***********
        elif "POTION" in item:
            # Potions: 70% chance 1 dose, otherwise 1d6 dose
            dose = 1
            if ut.roll(100) > st.POTION_MONODOSE_CHANCE:
                dose = ut.roll(6)

            if item == "HEALING_POTION_S":
                long_desc = "a red glow is a promise of a small healing"
                if dose > 1:
                    long_desc += ", enough for {} uses".format(dose)
                if ut.roll(100) < st.POTION_DECAYING_CHANCE:
                    # Potion has decayed
                    if ut.roll(100) < st.POTION_POISON_CHANCE:
                        ItemHelper(game,
                                   "poison",
                                   pos,
                                   "POTION_R_S",
                                   use_function=lambda player=game.player,
                                   value=rd.randint(3, 8): ItemHelper.
                                   cast_heal(player,
                                             heal_amount=-0.25,
                                             expression="PERCENTAGE"),
                                   long_desc="would cost you your life...",
                                   number_use=1,
                                   identification={
                                       c.NOT_IDENTIFIED_NAME: "potion",
                                       c.NOT_IDENTIFIED_DESC: "reddish liquid",
                                       c.IDENTIFICATION_MODIFIER: -2
                                   })
                    else:
                        ItemHelper(game,
                                   "potion of delusion",
                                   pos,
                                   "POTION_R_S",
                                   use_function=lambda player=game.player,
                                   value=rd.randint(3, 8): ItemHelper.
                                   cast_heal(player, heal_amount=0),
                                   long_desc=
                                   "taste like the regular, but does nothing",
                                   number_use=1,
                                   identification={
                                       c.NOT_IDENTIFIED_NAME: "potion",
                                       c.NOT_IDENTIFIED_DESC: "reddish liquid",
                                       c.IDENTIFICATION_MODIFIER: -2
                                   })
                else:
                    ItemHelper(game,
                               "small healing potion",
                               pos,
                               "POTION_R_S",
                               use_function=lambda player=game.player, value=rd
                               .randint(3, 8): ItemHelper.cast_heal(
                                   player, heal_amount=value),
                               long_desc=long_desc,
                               number_use=dose,
                               identification={
                                   c.NOT_IDENTIFIED_NAME: "potion",
                                   c.NOT_IDENTIFIED_DESC: "reddish liquid",
                                   c.IDENTIFICATION_MODIFIER: -2
                               })
            elif item == "HEALING_POTION_N":
                if ut.roll(100) < st.POTION_DECAYING_CHANCE:
                    # Potion has decayed
                    if ut.roll(100) < st.POTION_POISON_CHANCE:
                        ItemHelper(
                            game,
                            "Poison",
                            pos,
                            "POTION_R_S",
                            use_function=lambda player=game.player: ItemHelper.
                            cast_heal(player,
                                      heal_amount=-0.45,
                                      expression="PERCENTAGE"),
                            long_desc="Would cost you your life...",
                            number_use=1,
                            identification={
                                c.NOT_IDENTIFIED_NAME: "potion",
                                c.NOT_IDENTIFIED_DESC:
                                "large quantity of reddish liquid",
                                c.IDENTIFICATION_MODIFIER: 1
                            })
                    else:
                        ItemHelper(game,
                                   "Potion of delusion",
                                   pos,
                                   "POTION_R_S",
                                   use_function=lambda player=game.player:
                                   ItemHelper.cast_heal(player, heal_amount=0),
                                   long_desc=
                                   "Taste like the regular, but does nothing",
                                   number_use=1,
                                   identification={
                                       c.NOT_IDENTIFIED_NAME: "potion",
                                       c.NOT_IDENTIFIED_DESC:
                                       "large quantity of reddish liquid",
                                       c.IDENTIFICATION_MODIFIER: 1
                                   })
                else:
                    ItemHelper(game,
                               "Healing Potion",
                               pos,
                               "POTION_R_N",
                               use_function=lambda player=game.player, value=rd
                               .randint(5, 11): ItemHelper.cast_heal(
                                   player, heal_amount=value),
                               long_desc=
                               "better for your health in large than in small",
                               number_use=dose,
                               identification={
                                   c.NOT_IDENTIFIED_NAME: "potion",
                                   c.NOT_IDENTIFIED_DESC:
                                   "large quantity of reddish liquid",
                                   c.IDENTIFICATION_MODIFIER: 1
                               })
            elif item == "HEALING_POTION_L":
                if ut.roll(100) < st.POTION_DECAYING_CHANCE:
                    # Potion has decayed
                    if ut.roll(100) < st.POTION_POISON_CHANCE:
                        ItemHelper(
                            game,
                            "Poison",
                            pos,
                            "POTION_R_S",
                            use_function=lambda player=game.player: ItemHelper.
                            cast_heal(player,
                                      heal_amount=-0.6,
                                      expression="PERCENTAGE"),
                            long_desc="Would cost you your life...",
                            number_use=1,
                            identification={
                                c.NOT_IDENTIFIED_NAME: "potion",
                                c.NOT_IDENTIFIED_DESC: "slightly red",
                                c.IDENTIFICATION_MODIFIER: 2
                            })
                    else:
                        ItemHelper(game,
                                   "Potion of delusion",
                                   pos,
                                   "POTION_R_S",
                                   use_function=lambda player=game.player:
                                   ItemHelper.cast_heal(player, heal_amount=0),
                                   long_desc=
                                   "Taste like the regular, but does nothing",
                                   number_use=1,
                                   identification={
                                       c.NOT_IDENTIFIED_NAME: "potion",
                                       c.NOT_IDENTIFIED_DESC: "slightly red",
                                       c.IDENTIFICATION_MODIFIER: 2
                                   })
                else:
                    ItemHelper(
                        game,
                        "Large Healing Potion",
                        pos,
                        "POTION_R_L",
                        use_function=lambda player=game.player, value=rd.
                        randint(6, 14): ItemHelper.cast_heal(
                            player, heal_amount=value),
                        long_desc="the best money can buy, don't waste it",
                        number_use=dose,
                        identification={
                            c.NOT_IDENTIFIED_NAME: "potion",
                            c.NOT_IDENTIFIED_DESC: "slightly red",
                            c.IDENTIFICATION_MODIFIER: 3
                        })
        # Equipments
        elif item == "BASIC_SWORD":
            EquipmentHelper(game,
                            "Basic Sword",
                            pos,
                            "SWORD",
                            slot=c.SLOT_HAND_RIGHT,
                            modifiers={c.BONUS_STR: 2})
        elif item == "BASIC_HELMET":
            EquipmentHelper(game,
                            "Basic Helmet",
                            pos,
                            "HELMET",
                            slot=c.SLOT_HEAD,
                            modifiers={c.BONUS_STR: -1})
        elif item == "BASIC_CAPE":
            EquipmentHelper(game,
                            "Cape",
                            pos,
                            "CAPE",
                            slot=c.SLOT_CAPE,
                            modifiers={c.BONUS_STR: 2})
        elif item == "BASIC_RING":
            EquipmentHelper(game,
                            "Ring",
                            pos,
                            "RING",
                            slot=c.SLOT_RING,
                            modifiers={c.BONUS_STR: -1})
예제 #13
0
async def dice(ctx, arg='1d6'):
    await ctx.send(utilities.roll(arg))