class Item(Structure):
def __init__(self,item_id, quality_index = None, size_index = None, cut_index = None):
data = None
self.group = 'other'
for key in item_prototypes:
if item_prototypes[key].has_key(item_id):
data = copy(item_prototypes[key][item_id])
if not data:
debug(['Item not found',item_id])
if isinstance(data,Structure):
for key in data.namespace():
self.set(key,data[key])
else:
for key in data:
self.set(key,data[key])
# else:
# debug(['wrong item data',type(data)])
self.price = self.base_cost
if self.has('quality_mod'):
self.quality_mod = self.quality_mod.split()
if quality_index is not None and len(self.quality_mod) > 0:
self.quality_index = max(0,min(quality_index, len(self.quality_mod)-1))
else:
self.quality_index = random.randrange(0, len(self.quality_mod))
quality,mod = self.quality_mod[self.quality_index].split('/')
self.quality_index += 1
self.price *= float(mod)
else:
self.quality = 'normal'
self.quality_index = 2
if self.has('size_mod'):
self.size_mod = self.size_mod.split()
if size_index is not None and len(self.size_mod) > 0:
size_index = max(0,min(size_index, len(self.size_mod)-1))
else:
size_index = random.randrange(0, len(self.size_mod))
size,mod = self.size_mod[size_index].split('/')
self.price *= float(mod)
self.size = size
self.size_index = size_index + 1
if self.has('cut_mod'):
cut_list = self.cut_mod.split()
if cut_index is not None and len(cut_list) > 0:
cut_index = max(0,min(cut_index, len(cut_list)-1))
else:
cut_index = random.randrange(0, len(cut_list))
cut,mod = cut_list[cut_index].split('/')
self.price *= float(mod)
self.cut = cut
if self.has('can_be_made_from'):
material_group = select(self.can_be_made_from)
self.material = select(item_prototypes['weighted_random'][material_group])
if self.has('has_picture') and self.has_picture:
entry = select(item_prototypes['treasures_images'].keys())
self.rus_desc = item_prototypes['treasures_images'][entry].rus_desc
self.eng_desc = item_prototypes['treasures_images'][entry].eng_desc
self.count = 1
self.order = 1
self.item_id = item_id
# self.id = self.item_id + str(self.cost) + self.quality
self.id = item_id + self.get_property('size') + self.get_property('cut')
self.id += self.get_property('quality') + self.get_property('has_picture')
self.id += self.get_property('base_cost') + self.get_property('cost')