Also decided to have two separate functions that return the mode items as Items or Modes. Returning them as Items makes it easier to check if provided modeID from user database is valid (since we cannot easily map the modeID to create a Mode), returning as Modes allows us to easily use them for setters. There's probably a better way to do this, but w/e
118 lines
3.8 KiB
Python
118 lines
3.8 KiB
Python
#===============================================================================
|
|
# 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
|
|
from eos.effectHandlerHelpers import HandledItem
|
|
from eos.saveddata.mode import Mode
|
|
|
|
class Ship(ItemAttrShortcut, HandledItem):
|
|
def __init__(self, item):
|
|
|
|
if item.category.name != "Ship":
|
|
raise ValueError('Passed item "%s" (category: (%s)) is not under Ship category'%(item.name, item.category.name))
|
|
|
|
self.__item = item
|
|
self.__itemModifiedAttributes = ModifiedAttributeDict()
|
|
if not isinstance(item, int):
|
|
self.__buildOriginal()
|
|
|
|
self.commandBonus = 0
|
|
|
|
def __fetchItemInfo(self):
|
|
import eos.db
|
|
self.__item = eos.db.getItem(self.__item)
|
|
self.__buildOriginal()
|
|
|
|
def __buildOriginal(self):
|
|
self.__itemModifiedAttributes.original = self.item.attributes
|
|
|
|
@property
|
|
def item(self):
|
|
if isinstance(self.__item, int):
|
|
self.__fetchItemInfo()
|
|
|
|
return self.__item
|
|
|
|
@property
|
|
def itemModifiedAttributes(self):
|
|
if isinstance(self.__item, int):
|
|
self.__fetchItemInfo()
|
|
|
|
return self.__itemModifiedAttributes
|
|
|
|
def clear(self):
|
|
self.itemModifiedAttributes.clear()
|
|
self.commandBonus = 0
|
|
|
|
def calculateModifiedAttributes(self, fit, runTime, forceProjected = False):
|
|
if forceProjected: return
|
|
for effect in self.item.effects.itervalues():
|
|
if effect.runTime == runTime and effect.isType("passive"):
|
|
effect.handler(fit, self, ("ship",))
|
|
|
|
def checkModeItem(self, item):
|
|
"""
|
|
Checks if provided item is a valid mode.
|
|
|
|
If ship has modes, and current item is not valid, return forced mode
|
|
else if mode is valid, return Mode
|
|
else if ship does not have modes, return None
|
|
|
|
@todo: rename this
|
|
"""
|
|
items = self.getModeItems()
|
|
|
|
if items != None:
|
|
if item == None or item not in items:
|
|
# We have a tact dessy, but mode is None or not valid. Force new mode
|
|
return Mode(items[0])
|
|
elif item in items:
|
|
# We have a valid mode
|
|
return Mode(item)
|
|
return None
|
|
|
|
def getModes(self):
|
|
items = self.getModeItems()
|
|
return [Mode(item) for item in items]
|
|
|
|
def getModeItems(self):
|
|
"""
|
|
Returns a list of valid mode items for ship. Note that this returns the
|
|
valid Item objects, not the Mode objects. Returns None if not a
|
|
t3 dessy
|
|
"""
|
|
# @todo: is there a better way to determine this that isn't hardcoded groupIDs?
|
|
if self.item.groupID != 1305:
|
|
return None
|
|
|
|
modeGroupID = 1306
|
|
import eos.db
|
|
|
|
items = []
|
|
g = eos.db.getGroup(modeGroupID, eager=("items.icon", "items.attributes"))
|
|
for item in g.items:
|
|
if item.raceID == self.item.raceID:
|
|
items.append(item)
|
|
|
|
return items
|
|
|
|
def __deepcopy__(self, memo):
|
|
copy = Ship(self.item)
|
|
return copy
|