Go to the documentation of this file.00001
00002 '''
00003 Resources.py
00004 global resource manager for client and server
00005 . loads various the .xml data files that define basically all static data in the system
00006 . some files are available (and required) on client and servers but not all
00007
00008 16/08/2010 gsk
00009 '''
00010
00011 import ResMgr
00012
00013 from config import consts
00014
00015
00016 class StatsEffect():
00017 def __init__(self):
00018 self.stat = None
00019 self.value = None
00020 self.slot = None
00021
00022 class ProficiencyDef():
00023 def __init__(self):
00024 self.id = None
00025 self.nRanks = None
00026 self.effects = {}
00027
00028 class MobDef():
00029 def __init__(self):
00030 self.id = None
00031 self.name = None
00032 self.type = None
00033 self.model = None
00034
00035 class ItemDef():
00036 def __init__(self):
00037 self.id = None
00038 self.itemClass = None
00039 self.name = None
00040 self.handling = None
00041 self.dmgType = None
00042 self.dmg = None
00043 self.dly = None
00044
00045 class SpawnDef():
00046 def __init__(self):
00047 self.id = None
00048 self.entityType = None
00049 self.mobDefId = None
00050 self.mobName = None
00051 self.Xp = 0
00052 self.weaponId = None
00053
00054 class ResourceDB():
00055 __instance = None
00056
00057 def __init__(self):
00058 if ResourceDB.__instance: return
00059 ResourceDB.__instance=self;
00060 self.strings = {}
00061 self.mobs = {}
00062 self.spawns = {}
00063 self.effects = {}
00064 self.proficiencies = {}
00065 self.items = {}
00066
00067 def load(self, languageCode='en', isServer=False):
00068 self.loadStrings(languageCode)
00069 self.loadMobDefs()
00070
00071 if isServer:
00072 self.loadItems()
00073 self.loadSpawns()
00074 self.loadStatsEffects()
00075 self.loadProficiencies()
00076
00077
00078 def loadItems(self):
00079 print "loading items.xml ..."
00080 sectionName = "scripts/common/data/items.xml"
00081 section = ResMgr.openSection(sectionName)
00082 for entry in section.values():
00083 idef = ItemDef()
00084 idef.id = entry['id'].asString
00085 idef.itemClass = entry['class'].asString
00086 if idef.itemClass == 'weapon':
00087 idef.dmgType = entry['damageType'].asString
00088 idef.handling = entry['handling'].asString
00089 idef.dmg = entry['damage'].asInt
00090 idef.dly = entry['delay'].asInt
00091 self.items[idef.id] = idef
00092
00093 def loadProficiencies(self):
00094 print "loading proficiencies.xml ..."
00095 sectionName = "scripts/common/data/proficiencies.xml"
00096 section = ResMgr.openSection(sectionName)
00097 for entry in section.values():
00098 pdef = ProficiencyDef()
00099 pdef.id = entry['id'].asString
00100 pdef.nRanks = entry['ranks'].asInt
00101 effects = entry['effects']
00102 for effect in effects.values():
00103 rank = effect['rank'].asInt
00104 effectId = effect['id'].asString
00105 pdef.effects[rank] = effectId
00106
00107
00108 self.proficiencies[pdef.id] = pdef
00109
00110 def loadStatsEffects(self):
00111 print "loading statseffects.xml ..."
00112 sectionName = "scripts/common/data/statseffects.xml"
00113 section = ResMgr.openSection(sectionName)
00114 for entry in section.values():
00115 effect = StatsEffect()
00116 effect.id = entry['id'].asString
00117 effect.stat = entry['stat'].asString
00118 effect.slot = consts.STATSEFFECTS_SLOTS.index(entry['slot'].asString)
00119 effect.value = entry['value'].asInt
00120 self.effects[effect.id] = effect
00121
00122 def loadMobDefs(self):
00123 print "loading mobs.xml ..."
00124 sectionName = "scripts/common/data/mobs.xml"
00125 section = ResMgr.openSection(sectionName)
00126 for entry in section.values():
00127 mob = MobDef()
00128 mob.id = entry['id'].asString
00129 mob.name = entry['name'].asString
00130 mob.type = entry['type'].asString
00131 mob.model = entry['model'].asString
00132 self.mobs[mob.id] = mob
00133
00134 def loadSpawns(self):
00135 print "loading spawns.xml ..."
00136 sectionName = "scripts/common/data/spawns.xml"
00137 section = ResMgr.openSection(sectionName)
00138 for entry in section.values():
00139 spawn = SpawnDef()
00140 spawn.id = entry['id'].asString
00141 spawn.entityType = entry['type'].asString
00142 spawn.mobDefId = entry['mobId'].asString
00143 spawn.mobName = entry['mobName'].asString
00144 spawn.respawnDelay = entry['respawnDelay'].asInt
00145 spawn.Xp = entry['Xp'].asInt
00146 if entry.has_key('weapon'):
00147 spawn.weaponId = entry['weapon'].asString
00148
00149 self.spawns[spawn.id] = spawn
00150
00151 def loadStrings(self, languageCode):
00152 print "loading internationalization [%s] ..." % (languageCode)
00153 sectionName = "scripts/common/data/strings.%s.xml" % (languageCode)
00154 section = ResMgr.openSection(sectionName)
00155 for entry in section.values():
00156 id = entry['id'].asInt
00157 text = entry['text'].asString
00158 self.strings[id]=text
00159
00160
00161
00162 ResourceDB = ResourceDB()