def create(self, name, class_uid, race_uid, stats, body_uid):
        """
        Creates a new character based on arguments
        :return:
        """
        uid = "player"
        new_instance = Character(
            uid=uid,
            name=name,
            character_class=self.get_class_template_by_uid(class_uid).copy(),
            character_race=self.get_race_template_by_uid(race_uid).copy(),
            stats=stats,
            display=Display((255, 255, 255), (0, 0, 0), "@"),
            body=self.factory_service.build_body_instance_by_uid(body_uid),
            inventory=Inventory())
        health_base = new_instance.character_class.hit_die
        constitution_bonus = new_instance.get_stat_modifier(
            StatsEnum.Constitution)
        total_health = health_base + constitution_bonus
        new_instance.stats.set_core_current_value(StatsEnum.Health,
                                                  total_health)
        new_instance.stats.set_core_maximum_value(StatsEnum.Health,
                                                  total_health)

        return new_instance
Esempio n. 2
0
def mimic(point=None, dungeon_level=1):
    npc = Character(point,
                    'C',
                    'Chest',
                    COLORS.get('mimic'),
                    species=Species.CREATURE)

    npc.add_component(Health(30), 'health')
    npc.add_component(Offence(base_power=3), 'offence')
    npc.add_component(Defence(defence=3), 'defence')
    npc.add_component(Level(xp_value=50), 'level')
    display_char = ['C'] * 10
    display_char.append('M')
    display_char.append('M')
    display_char.append('M')
    display_char.append('M')
    display_char.append('M')
    npc.add_component(Display(display_char), 'display')

    teeth = equipment.teeth()
    teeth.lootable = False

    npc.inventory.add_item(teeth)
    npc.equipment.toggle_equip(teeth)

    pubsub.pubsub.subscribe(
        pubsub.Subscription(npc, pubsub.PubSubTypes.ATTACKED, mimic_activate))

    return npc
Esempio n. 3
0
 def initialize(self):
     self.screen = Display.get_instance().display
     self.screen.fill((0, 0, 0))
     if self.instant:
         if randint(0, 1) == 0:
             self.attacker_wins()
         else:
             self.defender_wins()
def build_leather_hood():
    _item = Item(
        uid="hood",
        name="hood",
        description="A leather hood.",
        display=Display(Colors.DARK_GRAY, Colors.BLACK_COLOR, "!"),
    )
    _item.register_component(data.python_templates.material.Leather.copy())
    _item.register_component(Stats(health=10, size=Size.Medium, weight=2))
    _item.register_component(
        Armor(base_armor_class=2,
              armor_category=item_enums.ArmorCategory.Medium,
              wearable_body_parts_uid=["humanoid_head"],
              worn_layer=item_enums.WornLayer.Outer))

    return _item
def build_long_sword():
    _long_sword = Item(
        uid="long_sword",
        name="Longsword",
        description="A longsword.",
        display=Display(Colors.DARK_GRAY, Colors.BLACK_COLOR, "!"),
    )
    _long_sword.register_component(data.python_templates.material.Iron.copy())
    _long_sword.register_component(Stats(health=1, size=Size.Medium))
    _long_sword.register_component(
        Weapon(weapon_category=item_enums.WeaponCategory.Martial,
               weapon_type=item_enums.WeaponType.Melee,
               size=Size.Medium,
               melee_damage_type=DamageType.Slash,
               damage_dice=DiceStack(1, Dice(8))))

    return _long_sword
def build_boot():
    _boot = Item(
        uid="boot",
        name="Boot",
        description="An iron boot",
        display=Display(Colors.DARK_GRAY, Colors.BLACK_COLOR, "!"),
    )
    _boot.register_component(data.python_templates.material.Iron.copy())
    _boot.register_component(Stats(health=10, size=Size.Medium, weight=0.5))
    _boot.register_component(
        Armor(base_armor_class=0.5,
              armor_category=item_enums.ArmorCategory.Medium,
              wearable_body_parts_uid=["humanoid_foot"],
              worn_layer=item_enums.WornLayer.Outer,
              maximum_dexterity_bonus=2))

    return _boot
def build_leather_pants():
    # TODO Some items need to take two slots rather than one.
    item = Item(
        uid="pants",
        name="pants",
        description="Leather pants",
        display=Display(Colors.DARK_GRAY, Colors.BLACK_COLOR, "!"),
    )
    item.register_component(data.python_templates.material.Leather.copy())
    item.register_component(Stats(health=10, size=Size.Medium, weight=0.5))
    item.register_component(
        Armor(base_armor_class=1,
              armor_category=item_enums.ArmorCategory.Medium,
              wearable_body_parts_uid=["humanoid_leg"],
              worn_layer=item_enums.WornLayer.Outer,
              maximum_dexterity_bonus=2))

    return item
Esempio n. 8
0
def hornets(point=None, dungeon_level=1):
    health_component = Health(2)

    creature = Character(point,
                         chr(178),
                         'hornet',
                         COLORS.get('hornet'),
                         ai=BasicNPC(),
                         species=Species.INSECT,
                         health=health_component,
                         act_energy=3)

    creature.add_component(Offence(base_power=1), 'offence')
    creature.add_component(Defence(defence=1), 'defence')
    creature.add_component(Level(xp_value=10), 'level')
    creature.add_component(
        Display([
            chr(176),
            chr(176),
            chr(176),
            chr(177),
            chr(177),
            chr(177),
            chr(178),
            chr(178),
            chr(178)
        ]), 'display')
    creature.add_component(
        DamageModifier(blunt=0.8,
                       slashing=0.8,
                       fire=1.2,
                       ice=1.2,
                       electric=1.2), 'damagemodifier')

    teeth = equipment.teeth()
    teeth.lootable = False

    creature.inventory.add_item(teeth)
    creature.equipment.toggle_equip(teeth)

    return creature
 def initialize(self):
     if not self.initialized:
         self.map.initialize()
         self.screen = Display.get_instance().display
         self.initialized = True
    def __init__(self, initial):

        Display.get_instance()
        self.current_state = initial(self)
        self.next_state = None
Esempio n. 11
0
from components.display import Display
from components.stats import make_character_stats
from components.outfitter import Outfitter
from data.python_templates.classes import thief_class, warrior_class
from data.python_templates.races import human_race, orc_race, troll_race
from data.python_templates.body import humanoid_body
from util.colors import Colors


weak_orc = Character(
    uid="weak_orc",
    name="Weak Orc",
    character_class=warrior_class,
    character_race=orc_race,
    stats=make_character_stats(health=10),
    display=Display(Colors.ORC_GREEN, Colors.BLACK_COLOR, "O"),
    body=humanoid_body.copy(),
)
strong_orc = Character(
    uid="strong_orc",
    name="Strong Orc",
    character_class=warrior_class,
    character_race=orc_race,
    stats=make_character_stats(health=16, strength=12, constitution=12),
    display=Display(Colors.ORC_GREEN, Colors.BLACK_COLOR, "O"),
    body=humanoid_body.copy(),
)
weak_troll = Character(
    uid="weak_troll",
    name="Weak Troll",
    character_class=warrior_class,
Esempio n. 12
0
    def __init__(self, parent, c):
        tk.Frame.__init__(self, parent, bg="white")
        self.code = ""
        self.buttons = screen.BUTTONS
        self.products = c.products

        # Messages and user inputs are printed on this screen.
        Display(self, c).pack(fill="x")

        # Calculator grid
        self.calculatorView = tk.Frame(self)
        self.calculatorGrid = tk.Frame(self.calculatorView)
        self.calculatorView.pack()
        self.calculatorGrid.grid()

        config = {
            "parent": parent,
            "controller": c,
            "continueIcon": tk.PhotoImage(file="assets/icons/continue.png"),
            "checkImage": tk.PhotoImage(file="assets/icons/tick.png"),
            "payIcon": tk.PhotoImage(file="assets/icons/payIcon.png"),
            "payCashIcon": tk.PhotoImage(file="assets/icons/payCash.png"),
            "payCardIcon": tk.PhotoImage(file="assets/icons/payCard.png"),
            "cancelIcon": tk.PhotoImage(file="assets/icons/cancel.png"),
            "couponIcon": tk.PhotoImage(file="assets/icons/coupon.png")
        }

        @lockerWrapper
        def onSubmit(c):
            playSoundEffect(3)

            # When no code is entered, return to cart window
            if c.screenMessage.get(
            ) == "Enter Code" and c.stage == screen.CODE:
                cartWindow(config)
                return

            # Validate code entered by user for the 3 stages

            # ***** STAGE 1: CODE *****
            if c.stage == screen.CODE:
                code = c.screenMessage.get()
                try:
                    screen.BUTTON_CODES[code]
                    self.code = code
                    c.screenMessage.set("Enter Amount")
                    c.stage = screen.AMOUNT
                    c.toggleLock(False)
                except KeyError:
                    threading.Thread(target=errorMessageResolver,
                                     args=(
                                         c,
                                         "Invalid Code",
                                     )).start()
                    playSoundEffect(4)

            # ***** STAGE 2: CODE *****
            elif c.stage == screen.AMOUNT:
                amount = c.screenMessage.get()
                if amount.isdigit():
                    c.setAmount(int(amount))
                    threading.Thread(target=processCode, args=(
                        c,
                        self.code,
                    )).start()
                else:
                    threading.Thread(target=errorMessageResolver,
                                     args=(
                                         c,
                                         "Invalid Amount",
                                     )).start()
                    playSoundEffect(4)

            # ***** STAGE 3: CONFIRM *****
            elif c.stage == screen.CONFIRM:
                # Check if there are enough products to match the client's needs
                if c.selected.quantity.get() - c.amount >= 0:
                    # If the product is already in the basket/cart, it should be modified. Otherwise, place the object in your basket.
                    try:
                        if c.basket[c.selected.id]:
                            previous = c.basket[c.selected.id][
                                "price"] * c.basket[c.selected.id]["amount"]
                            c.updateSubtotal(previous * -1)
                            c.updateSubtotal(c.selected.price.get() * c.amount)

                            previousCart = c.basket[c.selected.id]["amount"]
                            c.cart.set((c.cart.get() - previousCart) +
                                       c.amount)
                    except KeyError:
                        c.updateSubtotal(c.selected.price.get() * c.amount)
                        c.cart.set(c.cart.get() + c.amount)

                    # Add product to basket
                    c.basket[c.selected.id] = {
                        "id": c.selected.id,
                        "name": c.selected.name.get(),
                        "price": c.selected.price.get(),
                        "quantity": c.selected.quantity.get(),
                        "amount": c.amount
                    }

                    # Reset amount for next purchase
                    c.setAmount(0)
                    cartWindow(config)
                    c.screenMessage.set("Enter Code")

                    c.toggleLock(False)
                else:
                    # When there is insufficient inventory, display an out of stock message
                    threading.Thread(target=errorMessageResolver,
                                     args=(
                                         c,
                                         "Out of Stock",
                                     )).start()
                    playSoundEffect(4)
                    c.toggleLock(False)
                c.stage = screen.CODE

            # ***** STAGE 4: PAY (Cash transaction only) *****
            # Note: Card payments are made directly via the receipt window. Users are not required to enter payment details.
            elif c.stage == screen.PAY_CASH:
                # The server handles all transaction procedures. This involves things like dealing
                # with changes and updating the balance.
                c.toggleLock(True)
                cash = c.screenMessage.get()
                try:
                    success = finishAndPay(c, float(cash), "cash")
                    if success:
                        # The server returns results, which are then edited on the client side.
                        response = updateTicketBalance()
                        if response["success"]:
                            c.ticketBalance.set(c.ticketBalance.get() + 1)
                except ValueError:
                    threading.Thread(target=errorMessageResolver,
                                     args=(
                                         c,
                                         "Invalid Cash",
                                     )).start()
                    playSoundEffect(4)

        # Generate the buttons on the screen
        for row in range(len(self.buttons)):
            for col in range(4):
                button = self.buttons[row][col]
                tk.Button(self.calculatorGrid,
                          command=partial(pressKey, c, parent, button),
                          bg=getButtonColor(button),
                          fg=constants.BUTTON_TEXT_COLOR,
                          font=constants.BUTTON_FONT,
                          activebackground=getButtonHover(button),
                          activeforeground=constants.BUTTON_TEXT_COLOR,
                          state="disabled" if button == "" else "normal",
                          width=3,
                          height=2,
                          text=button,
                          cursor="arrow" if button == "" else "hand1",
                          padx=10,
                          pady=4).grid(row=row, column=col, sticky="news")

        # Continue button
        self.calculator_button = tk.Button(
            self,
            cursor="hand1",
            command=partial(onSubmit, c),
            bg=constants.CALCULATOR_CONFIRM_BUTTON,
            font=constants.CALCULATOR_FONT,
            activebackground=constants.CALCULATOR_HOVER_COLOR,
            activeforeground="white",
            text="Continue",
            height=2,
            fg="white")
        self.calculator_button.pack(fill="x")