Пример #1
0
    def create(self,
               map: Map,
               nodeParentId: int = None,
               contextType: ObjectType = None) -> int:
        """
        Create new map and create empty map image, because of exporting        
        :param map: Map object
        :param nodeParentId: id of parent node in tree
        :param contextType: Object type of tree, where item is located
        :return: id of created map
        """
        if contextType is None:
            contextType = self.TYPE

        values = {
            'name': map.name if map.name else '',
            'description': map.description if map.description else '',
            'map_file': map.mapFile,
        }

        id = self.database.insert(self.DATABASE_TABLE, values)
        map.id = id

        node = NodeObject(None, map.name, nodeParentId, map)
        nodeId = self.treeDAO.insert_node(node, contextType)

        for mapItem in map.mapItems:
            mapItem.mapId = id
            MapItemDAO().create(mapItem)

        self.create_map_image(map)
        return id
Пример #2
0
    def create(self,
               modifier: Modifier,
               nodeParentId: int = None,
               contextType: ObjectType = None) -> int:
        """
        Create new Modifier
        :param modifier: Modifier object
        :param nodeParentId: id of parent node in tree
        :param contextType: Object type of tree, where item is located
        :return: id of created Modifier
        """
        if not contextType:
            contextType = self.TYPE

        if modifier.valueType is ModifierValueTypes.TYPE_ARMOR_SIZE:
            value = ArmorSize.by_name(ArmorSize, modifier.value).value
        elif modifier.valueType is ModifierValueTypes.TYPE_WEAPON_HANDLING:
            value = Handling.by_name(Handling, modifier.value).value
        elif modifier.valueType is ModifierValueTypes.TYPE_WEAPON_WEIGHT:
            value = WeaponWeight.by_name(WeaponWeight, modifier.value).value
        else:
            value = modifier.value

        intValues = {
            'value':
            value,
            'valueType':
            modifier.valueType.value if modifier.valueType else None,
            'targetType':
            modifier.targetType.value if modifier.targetType else None,
            'characterTargetAttribute':
            modifier.characterTargetAttribute.value
            if modifier.characterTargetAttribute else None,
            'itemTargetAttribute':
            modifier.itemTargetAttribute.value
            if modifier.itemTargetAttribute else None
        }

        strValues = {
            'name': modifier.name,
            'desccription': modifier.description
        }

        id = self.database.insert(self.DATABASE_TABLE, intValues)
        modifier.id = id

        self.obj_database.insert_translate(strValues, modifier.lang, id,
                                           self.TYPE)

        # Create node for tree structure
        node = NodeObject(None, modifier.name, nodeParentId, modifier)
        self.treeDAO.insert_node(node, contextType)

        return id
Пример #3
0
    def create(self, monster: Monster, nodeParentId: int = None, contextType: ObjectType = None) -> int:
        """
        Create new Monster
        :param monster: Modifier object
        :param nodeParentId: id of parent node in tree
        :param contextType: Object type of tree, where item is located
        :return: id of created monster
        """

        if not contextType:
            contextType = self.TYPE

        intValues = {
            'defense'     : monster.defense,
            'endurance'   : monster.endurance,
            'rampancy'    : monster.rampancy,
            'mobility'    : monster.mobility,
            'perseverance': monster.perseverance,
            'intelligence': monster.intelligence,
            'charisma'    : monster.charisma,
            'experience'  : monster.experience,
            'hp'          : monster.hp,
            'alignment'   : monster.alignment.value if monster.alignment else None,
            'monsterRace' : monster.monsterRace.value if monster.monsterRace else None,
            'size'        : monster.size.value if monster.size else None,
        }

        strValues = {
            'name'       : monster.name,
            'description': monster.description,
            'offense'    : monster.offense,
            'viability'  : monster.viability,
        }

        id = self.database.insert(self.DATABASE_TABLE, intValues)
        monster.id = id

        self.database.insert_translate(strValues, monster.lang, id, self.TYPE)

        # Create node for tree structure
        node = NodeObject(None, monster.name, nodeParentId, monster)
        nodeId = self.treeDAO.insert_node(node, contextType)

        for one in monster.containers + monster.armors + monster.moneyList + monster.meleeWeapons + monster.rangedWeapons + monster.throwableWeapons + monster.items:
            ItemDAO().create(one, nodeId, contextType)

        for spell in monster.spells:
            SpellDAO().create(spell, nodeId, contextType)

        for ability in monster.abilities:
            AbilityDAO().create(ability, nodeId, contextType)

        return id
Пример #4
0
    def create(self,
               scenario: Scenario,
               nodeParentId: int = None,
               contextType: ObjectType = None) -> int:
        """
        Create new scenario
        :param scenario: Scenario object
        :param nodeParentId: id of parent node in tree
        :param contextType: Object type of tree, where item is located
        :return: id of created Scenario
        """
        if not contextType:
            contextType = self.TYPE

        if isinstance(scenario.date, dd.date):
            curDate = scenario.date
        else:
            curDate = datetime.strptime(scenario.date,
                                        '%d/%m/%Y') if scenario.date else None
        intValues = {'date': curDate.toordinal() if curDate else None}

        strValues = {
            'name': scenario.name,
            'description': scenario.description
        }

        id = self.database.insert(self.DATABASE_TABLE, intValues)
        scenario.id = id

        self.database.insert_translate(strValues, scenario.lang, id, self.TYPE)

        # Create node for tree structure
        node = NodeObject(None, scenario.name, nodeParentId, scenario)
        nodeId = self.treeDAO.insert_node(node, contextType)

        for location in scenario.locations:
            LocationDAO().create(location, nodeId, contextType)

        for spell in scenario.spells:
            SpellDAO().create(spell, nodeId, contextType)

        for ability in scenario.abilities:
            AbilityDAO().create(ability, nodeId, contextType)

        for effect in scenario.effects:
            EffectDAO().create(effect, nodeId, contextType)

        for character in scenario.party:
            PartyCharacterDAO().create(character, nodeId, contextType)

        return id
Пример #5
0
    def create(self,
               spell: Spell,
               nodeParentId: int = None,
               contextType: ObjectType = None) -> int:
        """
        Create new Spell
        :param spell: Spell object
        :param nodeParentId: id of parent node in tree
        :param contextType: Object type of tree, where item is located
        :return: id of created Spell
        """

        if not contextType:
            contextType = self.TYPE

        intValues = {
            'cast_time': spell.cast_time if spell.cast_time else 0,
            'drd_class': spell.drd_class.value if spell.drd_class else None
        }

        strValues = {
            'name': spell.name,
            'description': spell.description,
            'mana_cost_initial': spell.mana_cost_initial,
            'mana_cost_continual': spell.mana_cost_continual,
            'range': spell.range,
            'scope': spell.scope,
            'duration': spell.duration
        }

        # Insert NON transable values
        id = self.database.insert(self.DATABASE_TABLE, intValues)

        # Insert transable values
        self.database.insert_translate(strValues, spell.lang, id, self.TYPE)

        spell.id = id

        # Create node for tree structure
        node = NodeObject(None, spell.name, nodeParentId, spell)
        self.treeDAO.insert_node(node, contextType)

        return id
Пример #6
0
    def create_node_link(self,
                         nodeType: NodeType,
                         name: str,
                         parentId: int,
                         parentType: ObjectType = None,
                         targetObject: object = None):
        """
        Create node in tree, that link to some object, that already exist        
        :param nodeType: Type of node (Folder, NodeObject)
        :param name: name of node
        :param parentId: id of parent object
        :param parentType: 
        :param targetObject: target object
        :return: node
        """
        if nodeType is NodeType.FOLDER:
            node = Folder(None, name, parentId)
            self.treeDAO.insert_node(node, parentType)
        else:
            if targetObject.object_type is ObjectType.MODIFIER:

                parentObjectId = self.treeDAO.get_node(parentId).object.id
                parentObject = parentType.instance().DAO()().get(
                    parentObjectId)

                EffectDAO().create_link(parentObject, targetObject)

            elif targetObject.object_type is ObjectType.EFFECT and parentType is ObjectType.ITEM:
                parentObjectId = self.treeDAO.get_node(parentId).object.id
                parentObject = parentType.instance().DAO()().get(
                    parentObjectId)

                ItemDAO().create_effect_link(parentObject, targetObject)
            elif targetObject.object_type is ObjectType.ABILITY_CONTEXT:
                parentObjectId = self.treeDAO.get_node(parentId).object.id
                parentObject = parentType.instance().DAO()().get(
                    parentObjectId)

                AbilityDAO().create_context_link(parentObject, targetObject)
            else:
                node = NodeObject(None, name, parentId, targetObject)
                self.treeDAO.insert_node(node, parentType)
Пример #7
0
    def create(self,
               location: Location,
               nodeParentId: int = None,
               contextType: ObjectType = None) -> int:
        """
        Create new location        
        :param location: Location object
        :param nodeParentId: id of parent node in tree
        :param contextType: Object type of tree, where item is located
        :return: id of created location
        """

        if not contextType:
            contextType = self.TYPE

        strValues = {
            'name': location.name,
            'description': location.description
        }

        id = self.database.insert_null(self.DATABASE_TABLE)
        location.id = id

        self.database.insert_translate(strValues, location.lang, id, self.TYPE)

        # Create node for tree structure
        node = NodeObject(None, location.name, nodeParentId, location)
        nodeId = self.treeDAO.insert_node(node, contextType)

        for one in location.containers + location.armors + location.moneyList + location.meleeWeapons + location.rangedWeapons + location.throwableWeapons + location.items:
            ItemDAO().create(one, nodeId, contextType)

        for monster in location.monsters:
            MonsterDAO().create(monster, nodeId, contextType)

        for one in location.locations:
            self.create(one, nodeId, contextType)

        for character in location.characters:
            CharacterDAO().create(character, nodeId, contextType)

        return id
Пример #8
0
def map_objects(data: dict) -> list:
    """
    Map data from database to Node object
    :param data: data from database
    :return: list of Node objects
    """
    nodes = []
    for row in data:
        if row['type'] is NodeType.FOLDER.value:
            obj = Folder(row['ID'], row['name'], row['parent_id'])
        elif row['type'] is NodeType.OBJECT.value:
            target_object = ObjectType(
                row['target_type']).instance().DAO()().get(row['target_id'])
            obj = NodeObject(row['ID'], row['name'], row['parent_id'],
                             target_object, ObjectType(row['parent_type']))
        else:
            obj = None
        nodes.append(obj)

    return nodes
Пример #9
0
    def create(self,
               ability: Ability,
               nodeParentId: int = None,
               contextType: ObjectType = None) -> int:
        """
        Create new ability
        :param ability: Ability object
        :param nodeParentId: id of parent node in tree
        :param contextType: Object type of tree, where item is located
        :return: id of created ability
        """

        if not contextType:
            contextType = self.TYPE

        intValues = {
            'drd_race': ability.drd_race.value if ability.drd_race else None,
            'drd_class':
            ability.drd_class.value if ability.drd_class else None,
            'level': ability.level
        }

        strValues = {
            'name': ability.name,
            'description': ability.description,
            'chance': ability.chance
        }

        id = self.database.insert(self.DATABASE_TABLE, intValues)
        ability.id = id

        self.database.insert_translate(strValues, ability.lang, id, self.TYPE)

        # Create node for tree structure
        node = NodeObject(None, ability.name, nodeParentId, ability)
        nodeId = self.treeDAO.insert_node(node, contextType)

        for context in ability.contexts:
            AbilityContextDAO().create(context, nodeId, contextType)

        return id
Пример #10
0
    def create(self,
               effect: Effect,
               nodeParentId: int = None,
               contextType: ObjectType = None) -> int:
        """
        Create new effect
        :param effect: Effect object
        :param nodeParentId: id of parent node in tree
        :param contextType: Object type of tree, where item is located
        :return: id of created effect
        """
        if not contextType:
            contextType = self.TYPE

        if type(effect.active) is str:
            active = True if effect.active == 'true' else False
        else:
            active = effect.active

        intValues = {
            'targetType':
            effect.targetType.value if effect.targetType else None,
            'active': int(active) if active else 0
        }

        strValues = {'name': effect.name, 'description': effect.description}

        id = self.database.insert(self.DATABASE_TABLE, intValues)
        effect.id = id

        self.database.insert_translate(strValues, effect.lang, id, self.TYPE)

        # Create node for tree structure
        node = NodeObject(None, effect.name, nodeParentId, effect)
        nodeId = self.treeDAO.insert_node(node, contextType)

        for modifier in effect.modifiers:
            ModifierDAO().create(modifier, nodeId, contextType)
        return id
Пример #11
0
    def create(self,
               context: AbilityContext,
               nodeParentId: int = None,
               contextType: ObjectType = None) -> int:
        """
        Create new ability context
        :param context: Ability context object
        :param nodeParentId: id of parent node in tree
        :param contextType: Object type of tree, where item is located
        :return: id of created ability context
        """
        if contextType is None:
            contextType = self.TYPE

        intValues = {
            'value':
            context.value,
            'valueType':
            context.valueType.value if context.valueType else None,
            'targetAttribute':
            context.targetAttribute.value if context.targetAttribute else None
        }

        strValues = {'name': context.name, 'description': context.description}

        id = self.database.insert(self.DATABASE_TABLE, intValues)
        context.id = id

        self.obj_database.insert_translate(strValues, context.lang, id,
                                           self.TYPE)

        # Create node for tree structure
        node = NodeObject(None, context.name, nodeParentId, context)
        self.treeDAO.insert_node(node, contextType)

        return id
Пример #12
0
    def create(self, item: Item, nodeParentId: int = None, contextType: ObjectType = None) -> int:
        """
        Create new Item, depend on item type, insert correct data
        Items types:
            Item, Armor, Container, MeleeWeapon, ThrowableWeapon, RangedWeapon, Money
        :param item: Item object
        :param nodeParentId: id of parent node in tree
        :param contextType: Object type of tree, where item is located
        :return: id of created item
        """
        if not contextType:
            contextType = self.TYPE

        strValues = {
            'name'       : item.name,
            'description': item.description
        }
        intValues = {
            'amount': item.amount,
            'price' : item.price,
            'type'  : item.type.value if item.type else None,
            'weight': item.weight
        }
        if isinstance(item, Armor):
            intValues.update({
                'quality': item.quality,
                'weightA': item.weightA,
                'weightB': item.weightB,
                'weightC': item.weightC,
                'size'   : item.size.value if item.size else None,
            })

        elif isinstance(item, Container):
            intValues.update({
                'capacity' : item.capacity,
                'parent_id': item.parent_id
            })

        elif isinstance(item, MeleeWeapon):
            intValues.update({
                'strength'    : item.strength,
                'rampancy'    : item.rampancy,
                'defence'     : item.defence,
                'length'      : item.length,
                'initiative'  : item.initiative,
                'handling'    : item.handling.value if item.handling else None,
                'weaponWeight': item.weaponWeight.value if item.weaponWeight else None,
                'racial'      : item.racial.value if item.racial else None

            })
        elif isinstance(item, Money):
            intValues.update({
                'copper': item.copper,
                'silver': item.silver,
                'gold'  : item.gold
            })

        elif isinstance(item, RangeWeapon):
            intValues.update({
                'initiative'  : item.initiative,
                'strength'    : item.strength,
                'rampancy'    : item.rampancy,
                'rangeLow'    : item.rangeLow,
                'rangeMedium' : item.rangeMedium,
                'rangeHigh'   : item.rangeHigh,
                'weaponWeight': item.weaponWeight.value if item.weaponWeight else None,
                'racial'      : item.racial.value if item.racial else None
            })
        elif isinstance(item, ThrowableWeapon):
            intValues.update({
                'initiative'  : item.initiative,
                'strength'    : item.strength,
                'rampancy'    : item.rampancy,
                'rangeLow'    : item.rangeLow,
                'rangeMedium' : item.rangeMedium,
                'rangeHigh'   : item.rangeHigh,
                'defence'     : item.defence,
                'weaponWeight': item.weaponWeight.value if item.weaponWeight else None,
                'racial'      : item.racial.value if item.racial else None
            })

        id = self.database.insert(self.DATABASE_TABLE, intValues)
        item.id = id

        self.database.insert_translate(strValues, item.lang, id, self.TYPE)

        # Create node for tree structure
        node = NodeObject(None, item.name, nodeParentId, item)
        nodeId = self.treeDAO.insert_node(node, contextType)

        for effect in item.effects:
            EffectDAO().create(effect, nodeId, contextType)

        if isinstance(item, Container):
            for one in item.containers + item.armors + item.moneyList + item.meleeWeapons + item.rangedWeapons + item.throwableWeapons + item.items:
                self.create(one, nodeId, contextType)

        return id
Пример #13
0
    def create(self, character: Character, nodeParentId: int = None, contextType: ObjectType = None) -> int:
        """
        Create new character
        :param character: Character object
        :param nodeParentId: id of parent node in tree
        :param contextType: Object type of tree, where item is located
        :return: id of created character
        """
        if contextType is None:
            contextType = self.TYPE

        intValues = {
            'agility'      : character.agility,
            'charisma'     : character.charisma,
            'intelligence' : character.intelligence,
            'mobility'     : character.mobility,
            'strength'     : character.strength,
            'toughness'    : character.toughness,
            'age'          : character.age,
            'height'       : character.height,
            'weight'       : character.weight,
            'level'        : character.level,
            'xp'           : character.xp,
            'maxHealth'    : character.maxHealth,
            'maxMana'      : character.maxMana,
            'currentHealth': character.currentHealth,
            'currentMana'  : character.currentMana,
            'drdClass'     : character.drdClass.value if character.drdClass else None,
            'drdRace'      : character.drdRace.value if character.drdRace else None,
            'alignment'    : character.alignment.value if character.alignment else None,
        }

        strValues = {
            'name'       : character.name,
            'description': character.description
        }

        id = self.database.insert(self.DATABASE_TABLE, intValues)
        character.id = id

        self.database.insert_translate(strValues, character.lang, id, self.TYPE)

        # Create node for tree structure
        node = NodeObject(None, character.name, nodeParentId, character)
        nodeId = self.treeDAO.insert_node(node, contextType)

        for spell in character.spells:
            SpellDAO().create(spell, nodeId, contextType)

        for ability in character.abilities:
            AbilityDAO().create(ability, nodeId, contextType)

        for effect in character.effects:
            EffectDAO().create(effect, nodeId, contextType)

        if character.inventory is None:
            c = Container(None, None, TR().tr('Inventory'), None, -1)
            inventoryId = ItemDAO().create(c, nodeId, contextType)
        else:
            character.inventory.parent_id = -1
            inventoryId = ItemDAO().create(character.inventory, nodeId, contextType)

        if character.ground is None:
            c = Container(None, None, TR().tr('Ground'), None, -2)
            groundId = ItemDAO().create(c, nodeId, contextType)
        else:
            character.ground.parent_id = -2
            groundId = ItemDAO().create(character.ground, nodeId, contextType)

        self.database.update(self.DATABASE_TABLE, id, {'inventoryId': inventoryId, 'groundId': groundId})

        return id