-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathitem.py
110 lines (97 loc) · 5.75 KB
/
item.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import xml.etree.ElementTree as ET
import spritesheet
import dataTypes
#SlotTypes
# 1-warrior 2 special 3 heavy armour
# 4-mage 5 special 6 robes
# 7-ranger 8 special 9 hides
# 10 - rings
#11 - usbale by all
class spriteRef:#sprite ref object
def __init__(self, spriteFile, index, foldername):
#store data
self.fileLocation = "resources/Sprites/" + foldername + "/" + spriteFile.lower() + ".png"
self.index = index.split("x")
for x in range(2):#get location of sprite in terms of size
#print(x)
self.index[x] = int(self.index[x])*8
if len(self.index) == 3:#multiply size if larger
self.size = 8*int(self.index[2])
else:
self.size = 8
def __str__(self):
return "[%s, %s]" % (self.index, self.fileLocation)
class Material:#material object
def __init__(self, name, type, itemClass, slotType, desc, tier=None, texture=None, rateOfFire = None, damage = None, range=None, projectile=None, use=[], group=None):
#store all variables for easy use
self.name = name
self.type = type
self.itemClass = itemClass
if texture:
self.Texture = texture
ss = spritesheet.spritesheet(self.Texture.fileLocation)
self.image = ss.image_at((self.Texture.index[0], self.Texture.index[1], self.Texture.size, self.Texture.size), colorkey=dataTypes.WHITE)
else:
self.Texture = None
self.image = None
if projectile:
self.projectile = projectile
ss = spritesheet.spritesheet(self.projectile.fileLocation)
self.projectileImage = ss.image_at((self.projectile.index[0], self.projectile.index[1], self.Texture.size, self.Texture.size), colorkey=dataTypes.WHITE)
self.SlotType = slotType
self.description = desc
self.tier = tier
self.rateOfFire = rateOfFire
self.damage = damage
self.range = range
self.useMeta = use
self.group = group
self.__repr__ = self.__str__
def __str__(self):
return "<%s type=%s id=%s {SlotType=%s, description=%s, Texture=%s}>" % (self.itemClass, self.type, self.name, self.SlotType, self.description, self.Texture)
class ItemStack:#itemstack object
def __init__(self, amount, material):
#store the amount of objects and the material
self.amount = amount
self.material = material
def return_Itemstack(self):#return an array which has the item stack data
return [self.amount, self.material]
Nothing = Material("None", "0xfff", "None", 11, None, None)#blank item
allItems = {"0xfff":Nothing}#all items
#https://docs.python.org/3/library/xml.etree.elementtree.html
def init():
tree = ET.parse("resources/xml/items.xml")#get ref to items xml file
root = tree.getroot()#get root
for child in root:#for obeject
#print(child.tag, child.attrib)
itemClass = child.find('Class').text#get itemcallss
if itemClass == "Equipment" and child.find("Weapon")!= None:#create material object for weapon type
allItems[child.get('type')] = Material(child.get('id'),
child.get('type'),
itemClass,
child.find("SlotType").text,
child.find("Description").text,
tier=child.find("Tier"),
texture=spriteRef(child.find("Texture").find("File").text, child.find("Texture").find("Index").text, "items"),
rateOfFire=int(child.find("RateOfFire").text),
damage=[int(_) for _ in child.find("Damage").text.split("-")],
range=int(child.find("Range").text),
projectile=spriteRef(child.find("ProjectileTexture").find("File").text, child.find("ProjectileTexture").find("Index").text, "items"))
elif itemClass == "Equipment" and child.find("Special")!= None:#create material for special type
allItems[child.get('type')] = Material(child.get('id'),
child.get('type'),
itemClass,
child.find("SlotType").text,
child.find("Description").text,
tier="UT",
texture=spriteRef(child.find("Texture").find("File").text, child.find("Texture").find("Index").text, "items"),
use=[child.find("Use").find("Action").text, child.find("Use").find("Amount").text])
elif itemClass == "Consumable" and child.find("Item") != None:#create material for consumable type
allItems[child.get('type')] = Material(child.get('id'),
child.get('type'),
itemClass,
child.find("SlotType").text,
child.find("Description").text,
group=child.find("Group").text,
texture=spriteRef(child.find("Texture").find("File").text, child.find("Texture").find("Index").text, "items"),
use=[child.find("Use").find("Action").text, child.find("Use").find("Amount").text])