def createNoteBook(self):
        self.main_notebook = ttk.Notebook(self.master,width=500)
        # make fill y if width of search is not increased
        self.main_notebook.pack(fill="y",expand=1,padx=10)
        self.search_og_frame = ttk.Frame(self.main_notebook)    
        self.owned_og_frame = ttk.Frame(self.main_notebook)    
        self.customer_og_frame = ttk.Frame(self.main_notebook)    
        self.search_og_frame.pack(fill="both", expand=1,pady=10,padx=10)
        self.owned_og_frame.pack(fill="both", expand=1,pady=10,padx=10)
        self.customer_og_frame.pack(fill="both", expand=1,pady=10,padx=10)

        self.main_notebook.add(self.search_og_frame, text="Search Currency")
        self.main_notebook.add(self.owned_og_frame, text="Owned Currency")
        self.main_notebook.add(self.customer_og_frame, text="Customer Details")
        self.user = get_transaction(customer_id=self.userid)

        self.createSearchFrame()
        self.createOwnedFrame()
        self.createCustomerFrame()

        data = getData(limit=10)
        if(type(data)==ConnectionError or type(data)==Timeout or type(data)==TooManyRedirects): 
            ttk.Label(self.search_frame,text="Failed to establish API Connection").grid(row=0,pady=5,padx=10,sticky="news")
            ttk.Button(self.search_frame,text="Refresh",command=self.search_refresh).grid(row=1,pady=5,padx=10,sticky="news")
            ttk.Label(self.owned_frame,text="Failed to establish API Connection").grid(row=0,pady=5,padx=10,sticky="news")
            ttk.Button(self.owned_frame,text="Refresh",command=lambda: self.checkconnect(self.owned_refresh)).grid(row=1,pady=5,padx=10,sticky="news")
        else:
            self.display(data)
            self.checkowned()
 def owned_frame_reset(self):
     self.user = get_transaction(customer_id=self.userid)
     self.owned_init_frame.destroy()
     self.owned_canvas.destroy()
     self.owned_scrollbar.destroy()
     self.owned_frame.destroy()
     self.createOwnedFrame()
Beispiel #3
0
 def create_weapon(self, weapon: Weapons):
     self.db = get_transaction()
     equippable_component = Equippable(EQUIPMENT_SLOTS.WEAPONS)
     weapon_component = Weapon(weapon_type=weapon.weapon_enum,
                               dmg_quantity=weapon.damage_quantity,
                               weapon_dmg=weapon.weapon_damage,
                               dmg_type=weapon.id_weapon_damage_type,
                               light=weapon.light,
                               heavy=weapon.heavy,
                               two_hand=weapon.two_hand,
                               reach=weapon.reach,
                               finesse=weapon.finesse,
                               thrown=weapon.thrown,
                               ammunition=weapon.ammunition,
                               range_from=weapon.range_from,
                               range_to=weapon.range_to,
                               versatile=weapon.versatile,
                               versatile_value=weapon.versatile_value,
                               loading=weapon.loading)
     return Entity(0,
                   0,
                   SKY,
                   weapon.weapon_name,
                   equippable=equippable_component,
                   weapon=weapon_component)
Beispiel #4
0
def get_transaction(tx_hash):
    """
    get transaction from w3, or db
    """
    ret = db.get_transaction(tx_hash)
    if ret is not None:
        return ret
    ret = w3.eth.getTransaction(tx_hash)
    if ret is not None:
        db.insert_transaction(dict(ret))
    if random.randint(1, 20) == 1:
        print(datetime.datetime.today().ctime())

    print('get_transaction:', tx_hash[:10])
    return ret
Beispiel #5
0
    def create_monster(self, monster_name, x, y):
        self.db = get_transaction()
        _monster: Monsters = self.db.query(Monsters).filter(
            Monsters.monster_name == monster_name).one()
        ai_component = BasicMonster()
        ability_component = Ability(strenght=_monster.strenght,
                                    dexterity=_monster.dexterity,
                                    constitution=_monster.constitution,
                                    intelligence=_monster.intelligence,
                                    wisdom=_monster.wisdom,
                                    charisma=_monster.charisma)
        playable_component = Playable(hp=_monster.hit_points,
                                      ac=_monster.armor_class,
                                      xp=_monster.exp)
        inventory_component = Inventory(2)
        equipment_component = Equipment()
        monster = Entity(x,
                         y,
                         DESATURED_GREEN,
                         _monster.monster_name,
                         blocks=True,
                         render_order=RenderOrder.ACTOR,
                         playable=playable_component,
                         ai=ai_component,
                         inventory=inventory_component,
                         equipment=equipment_component,
                         ability=ability_component,
                         image_name="{}_right".format(
                             _monster.monster_name.lower()))
        if len(_monster.monsters_weapons) > 0:
            random = randint(0, 100)
            _weapon = None

            if random > 75:
                _weapon = self.weapon_factory.create_weapon(
                    _monster.monsters_weapons[1])
            else:
                _weapon = self.weapon_factory.create_weapon(
                    _monster.monsters_weapons[0])

            if _weapon != None:
                monster.inventory.add_item(_weapon)
                monster.equipment.toggle_equip_main_hand(_weapon)

        return monster
def process(messaging_event):
    message = messaging_event[
        'message'] if 'message' in messaging_event else {}
    postback = messaging_event[
        'postback'] if 'postback' in messaging_event else None
    sender = messaging_event['sender_data']

    t = texts.get_texts(sender)

    last_action = sender.get('last_action')
    if last_action:
        del sender['last_action']
    message_text = message.get('text')
    intent = get_intent(message, postback)
    cards = get_card_ids(message, postback)

    if intent == 'start' or not sender.get('spoke'):
        return [{
            'text':
            t('welcome'),
            'quick_replies':
            [nlg.pill(t, 'add_sticker'),
             nlg.pill(t, 'add_wishlist')]
        }]

    elif message_text and 'ask_message' in (last_action or ''):
        transaction_id = last_action.split()[1]
        transaction = db.get_transaction(transaction_id)
        users = [
            user for user in transaction['cycle']
            if user != sender['id'] and db.is_user(user)
        ]
        batch_messages = {
            user: [{
                'text':
                get_emoji(sender['id']) + ' ' +
                t('message_received', name=sender['first_name'])
            }, {
                'text':
                message_text,
                'quick_replies':
                [nlg.pill(t, 'reply', {'id': transaction_id})]
            }]
            for user in users
        }
        send_batch_messages(batch_messages)
        # Only for mock users interaction and testing
        replies = get_replies_from_testers(t, users, transaction_id)
        if replies:
            return [{'text': t('message_sent')}] + replies
        #############################################
        return [{'text': t('message_sent')}, nlg.cta(t)]

    elif intent == 'menu':
        return [nlg.menu(t)]

    elif intent == 'trades':
        return nlg.show_trades(t, sender.get('transactions'))

    elif intent == 'stickers':
        return nlg.show_collection(t, sender.get('collection'))

    elif intent == 'wishlist':
        return nlg.show_wanted(t, sender.get('wanted'))

    elif intent == 'add_sticker' or last_action == 'ask_sticker':
        if cards:
            db.add_collection(sender, cards)
            return [{'text': t('collection_changed')}] +\
                    nlg.show_collection(t, sender.get('collection')) +\
                    find_match(t, sender)
        sender['last_action'] = 'ask_sticker'
        return [{'text': t('ask_sticker')}]
    elif intent == 'add_wishlist' or last_action == 'ask_wishlist':
        if cards:
            db.add_wanted(sender, cards)
            return [{'text': t('wanted_changed')}] +\
                    nlg.show_wanted(t, sender.get('wanted')) +\
                    find_match(t, sender)
        sender['last_action'] = 'ask_wishlist'
        return [{'text': t('ask_wishlist')}]

    elif intent == 'talk' or intent == 'reply':
        transaction_id = get_entities(message, postback, 'id')[0]['value']
        sender['last_action'] = 'ask_message ' + transaction_id
        return [{'text': t('ask_message')}]

    elif intent == 'cancel_transaction':
        transaction_id = get_entities(message, postback, 'id')[0]['value']
        transaction = db.get_transaction(transaction_id)
        if 'finished' in transaction:
            # Not cancelable
            return [t('transaction_finished'), nlg.cta(t)]
        transaction['canceled'] = True
        db.set_transaction(transaction_id, transaction)
        db.add_one_wanted(sender,
                          sender['transactions'][transaction_id]['get'])
        db.add_one_collection(sender,
                              sender['transactions'][transaction_id]['put'])
        del sender['transactions'][transaction_id]
        sender['past_transactions'].append(transaction_id)
        return [t('transaction_canceled'), nlg.cta(t)]

    elif intent == 'finish_transaction':
        transaction_id = get_entities(message, postback, 'id')[0]['value']
        transaction = db.get_transaction(transaction_id)
        if 'canceled' in transaction:
            # Not finalizable
            return [t('transaction_canceled'), nlg.cta(t)]
        transaction['finished'] = True
        db.set_transaction(transaction_id, transaction)
        del sender['transactions'][transaction_id]
        sender['past_transactions'].append(transaction_id)
        return [t('transaction_finished'), nlg.cta(t)]

    elif intent == 'remove_sticker' or last_action == 'remove_sticker':
        if cards:
            db.remove_collection(sender, cards)
            return [{'text': t('collection_changed')}] +\
                    nlg.show_collection(t, sender.get('collection'))
        sender['last_action'] = 'remove_sticker'
        return [{'text': t('ask_sticker')}]

    elif intent == 'remove_wishlist' or last_action == 'remove_wishlist':
        if cards:
            db.remove_wanted(sender, cards)
            return [{'text': t('wanted_changed')}] +\
                    nlg.show_wanted(t, sender.get('wanted'))
        sender['last_action'] = 'remove_wishlist'
        return [{'text': t('ask_wishlist')}]

    elif intent == 'hi':
        return [{'text': t('hi')}, nlg.menu(t)]

    elif cards:
        db.add_collection(sender, cards)
        return [{'text': t('collection_changed')}] +\
                nlg.show_collection(t, sender.get('collection')) +\
                find_match(t, sender)

    return [{'text': t('default')}, nlg.menu(t)]
Beispiel #7
0
    def place_entities(self, room, entities):
        db = get_transaction()
        max_monsers_per_room = from_dungeon_level([[2, 1], [3, 4], [5, 6]],
                                                  self.dungeon_level)
        max_items_per_room = from_dungeon_level([[1, 1], [2, 4]],
                                                self.dungeon_level)
        number_of_monsters = randint(0, max_monsers_per_room)
        number_of_items = randint(0, max_items_per_room)
        monster_factory = MonsterFactory()

        monster_chances = {}
        _monsters = db.query(MonstersChances).filter(
            MonstersChances.id_dungeon_level <= self.dungeon_level)
        for _monster in _monsters:
            monster_chances[_monster.monster.monster_name] = _monster.chances
        item_chances = {
            "healing_potion": 70,
            "lightinh_scroll": from_dungeon_level([[25, 4]],
                                                  self.dungeon_level),
            "fireball_scroll": from_dungeon_level([[25, 6]],
                                                  self.dungeon_level),
            "confusion_scroll": from_dungeon_level([[26, 2]],
                                                   self.dungeon_level),
            "sword": from_dungeon_level([[5, 4]], self.dungeon_level),
            "shield": from_dungeon_level([[15, 8]], self.dungeon_level)
        }

        for i in range(number_of_monsters):
            x = randint(room.x1 + 1, room.x2 - 1)
            y = randint(room.y1 + 1, room.y2 - 1)

            if not any([
                    entity
                    for entity in entities if entity.x == x and entity.y == y
            ]):
                monster_choice = random_choice_from_dict(monster_chances)
                entities.append(
                    monster_factory.create_monster(monster_choice, x, y))

        for i in range(number_of_items):
            x = randint(room.x1 + 1, room.x2 - 1)
            y = randint(room.y1 + 1, room.y2 - 1)

            if not any([
                    entity
                    for entity in entities if entity.x == x and entity.y == y
            ]):
                item_choice = random_choice_from_dict(item_chances)
                if item_choice == "healing_potion":
                    item_component = Item(use_funtion=heal, amount=3)
                    item = Entity(x,
                                  y,
                                  VIOLET,
                                  "Healing Potion",
                                  render_order=RenderOrder.ITEM,
                                  item=item_component,
                                  image_name="potion")
                elif item_choice == "fireball_scroll":
                    item_component = Item(
                        use_funtion=cast_fireball,
                        targeting=True,
                        targeting_message=Message(
                            "Left-click a target tile for the fireball, or right-click to cancel",
                            libtcod.light_cyan),
                        damage=25,
                        radius=3)
                    item = Entity(x,
                                  y,
                                  RED,
                                  "Fireball Scroll",
                                  render_order=RenderOrder.ITEM,
                                  item=item_component)
                elif item_choice == "confusion_scroll":
                    item_component = Item(
                        use_funtion=cast_confuse,
                        targeting=True,
                        targeting_message=Message(
                            "Left-click an enemy to confuse it, or right-click to cancel",
                            libtcod.light_cyan),
                        damage=25,
                        radius=3)
                    item = Entity(x,
                                  y,
                                  ORANGE,
                                  "Confuion Scroll",
                                  render_order=RenderOrder.ITEM,
                                  item=item_component)
                elif item_choice == "sword":
                    equippable_component = Equippable(EQUIPMENT_SLOTS.WEAPONS,
                                                      power_bonus=3)
                    weapon_component = Weapon(3, 5, 20, WEAPON_TYPE.SHORTSWORD)
                    item = Entity(x,
                                  y,
                                  SKY,
                                  "Sword",
                                  render_order=RenderOrder.ITEM,
                                  equippable=equippable_component,
                                  weapon=weapon_component)
                elif item_choice == "shield":
                    equippable_component = Equippable(EQUIPMENT_SLOTS.WEAPONS,
                                                      defense_bonus=1)
                    weapon_component = Weapon(0, 1, 50, WEAPON_TYPE.SHIELD)
                    item = Entity(x,
                                  y,
                                  ORANGE,
                                  "Shield",
                                  render_order=RenderOrder.ITEM,
                                  equippable=equippable_component,
                                  weapon=weapon_component)
                else:
                    item_component = Item(use_funtion=cast_lightning,
                                          damage=20,
                                          maximum_range=5)
                    item = Entity(x,
                                  y,
                                  YELLOW,
                                  "Lightning Scroll",
                                  render_order=RenderOrder.ITEM,
                                  item=item_component)

                entities.append(item)