Get fighter abilities saved into database
This commit is contained in:
@@ -21,6 +21,11 @@ from sqlalchemy import Table, Column, Integer, ForeignKey, Boolean
|
||||
from sqlalchemy.orm import mapper
|
||||
from eos.db import saveddata_meta
|
||||
from eos.types import Fighter
|
||||
from sqlalchemy.orm import *
|
||||
from sqlalchemy.sql import and_
|
||||
from eos.effectHandlerHelpers import *
|
||||
from eos.types import FighterAbility
|
||||
|
||||
|
||||
fighters_table = Table("fighters", saveddata_meta,
|
||||
Column("groupID", Integer, primary_key=True),
|
||||
@@ -30,4 +35,17 @@ fighters_table = Table("fighters", saveddata_meta,
|
||||
Column("amountActive", Integer, nullable = False),
|
||||
Column("projected", Boolean, default = False))
|
||||
|
||||
mapper(Fighter, fighters_table)
|
||||
fighter_abilities_table = Table("fightersAbilities", saveddata_meta,
|
||||
Column("groupID", Integer, ForeignKey("fighters.groupID"), primary_key=True, index = True),
|
||||
Column("effectID", Integer, nullable = False, primary_key=True),
|
||||
Column("active", Boolean, default = False))
|
||||
|
||||
mapper(Fighter, fighters_table,
|
||||
properties = {
|
||||
"_Fighter__abilities": relation(
|
||||
FighterAbility,
|
||||
backref="fighter",
|
||||
cascade='all, delete, delete-orphan'),
|
||||
})
|
||||
|
||||
mapper(FighterAbility, fighter_abilities_table)
|
||||
|
||||
@@ -18,10 +18,11 @@
|
||||
#===============================================================================
|
||||
|
||||
from eos.modifiedAttributeDict import ModifiedAttributeDict, ItemAttrShortcut, ChargeAttrShortcut
|
||||
from eos.effectHandlerHelpers import HandledItem, HandledCharge
|
||||
from eos.effectHandlerHelpers import HandledItem, HandledCharge, HandledDroneCargoList
|
||||
from sqlalchemy.orm import validates, reconstructor
|
||||
import eos.db
|
||||
import logging
|
||||
from eos.types import FighterAbility
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -40,6 +41,9 @@ class Fighter(HandledItem, HandledCharge, ItemAttrShortcut, ChargeAttrShortcut):
|
||||
self.amount = 0
|
||||
self.amountActive = 0
|
||||
self.projected = False
|
||||
|
||||
self.__abilities = self.__getAbilities()
|
||||
|
||||
self.build()
|
||||
|
||||
@reconstructor
|
||||
@@ -65,6 +69,12 @@ class Fighter(HandledItem, HandledCharge, ItemAttrShortcut, ChargeAttrShortcut):
|
||||
self.__dps = None
|
||||
self.__volley = None
|
||||
self.__miningyield = None
|
||||
|
||||
if len(self.abilities) != len(self.item.effects):
|
||||
self.__abilities = []
|
||||
for ability in self.__getAbilities():
|
||||
self.__abilities.append(ability)
|
||||
|
||||
self.__itemModifiedAttributes = ModifiedAttributeDict()
|
||||
self.__itemModifiedAttributes.original = self.__item.attributes
|
||||
self.__itemModifiedAttributes.overrides = self.__item.overrides
|
||||
@@ -77,6 +87,16 @@ class Fighter(HandledItem, HandledCharge, ItemAttrShortcut, ChargeAttrShortcut):
|
||||
self.__chargeModifiedAttributes.original = charge.attributes
|
||||
self.__chargeModifiedAttributes.overrides = charge.overrides
|
||||
|
||||
def __getAbilities(self):
|
||||
"""Returns list of FighterAbilities that are loaded with data"""
|
||||
print "getting list of abilities"
|
||||
return [FighterAbility(effect) for effect in self.item.effects.values()]
|
||||
|
||||
@property
|
||||
def abilities(self):
|
||||
return self.__abilities or []
|
||||
|
||||
|
||||
@property
|
||||
def itemModifiedAttributes(self):
|
||||
return self.__itemModifiedAttributes
|
||||
|
||||
61
eos/saveddata/fighterAbility.py
Normal file
61
eos/saveddata/fighterAbility.py
Normal file
@@ -0,0 +1,61 @@
|
||||
#===============================================================================
|
||||
# Copyright (C) 2010 Diego Duclos
|
||||
#
|
||||
# This file is part of eos.
|
||||
#
|
||||
# eos is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published by
|
||||
# the Free Software Foundation, either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# eos is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with eos. If not, see <http://www.gnu.org/licenses/>.
|
||||
#===============================================================================
|
||||
|
||||
from eos.modifiedAttributeDict import ModifiedAttributeDict, ItemAttrShortcut, ChargeAttrShortcut
|
||||
from eos.effectHandlerHelpers import HandledItem, HandledCharge
|
||||
from sqlalchemy.orm import validates, reconstructor
|
||||
import eos.db
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
class FighterAbility(object):
|
||||
|
||||
def __init__(self, effect):
|
||||
print "creating fighter ability"
|
||||
"""Initialize from the program"""
|
||||
self.__effect = effect
|
||||
self.effectID = effect.ID if effect is not None else None
|
||||
self.active = False
|
||||
#self.build()
|
||||
|
||||
@reconstructor
|
||||
def init(self):
|
||||
'''Initialize from the database'''
|
||||
print "Initialize fighter ability from the database, effectID:"
|
||||
self.__effect = None
|
||||
print self.effectID
|
||||
|
||||
'''
|
||||
if self.effectID:
|
||||
self.__item = eos.db.getItem(self.itemID)
|
||||
if self.__item is None:
|
||||
logger.error("Item (id: %d) does not exist", self.itemID)
|
||||
return
|
||||
'''
|
||||
|
||||
self.build()
|
||||
|
||||
def build(self):
|
||||
# pull needed values from effect to here
|
||||
pass
|
||||
|
||||
@property
|
||||
def effect(self):
|
||||
return self.__effect
|
||||
@@ -27,7 +27,9 @@ from eos.saveddata.targetResists import TargetResists
|
||||
from eos.saveddata.character import Character, Skill
|
||||
from eos.saveddata.module import Module, State, Slot, Hardpoint, Rack
|
||||
from eos.saveddata.drone import Drone
|
||||
from eos.saveddata.fighterAbility import FighterAbility
|
||||
from eos.saveddata.fighter import Fighter
|
||||
|
||||
from eos.saveddata.cargo import Cargo
|
||||
from eos.saveddata.implant import Implant
|
||||
from eos.saveddata.implantSet import ImplantSet
|
||||
|
||||
Reference in New Issue
Block a user