def test_init_weapon(self): name = 'short_sword' sprite = 'imgs/dungeon_crawl/item/weapon/short_sword_2_old.png' description = 'A basic little sword, but one that can already prove very useful' price = 500 equipped_sprite = [ 'imgs/dungeon_crawl/player/hand_right/short_sword.png' ] durability = 40 reach = [1] power = 4 kind = 'PHYSICAL' weight = 2 restrictions = [] possible_effects = [] sword = Weapon(name, sprite, description, price, equipped_sprite, power, kind, weight, durability, reach, restrictions, possible_effects) self.assertEqual(name, sword.name) self.assertEqual(description, sword.desc) self.assertEqual('Short Sword', str(sword)) self.assertEqual(price, sword.price) self.assertEqual(price // 2, sword.resell_price) self.assertEqual(durability, sword.durability_max) self.assertEqual(durability, sword.durability) self.assertEqual(reach, sword.reach) self.assertEqual(power, sword.atk) self.assertEqual(DamageKind[kind], sword.attack_kind) self.assertEqual(weight, sword.weight) self.assertEqual(restrictions, sword.restrictions) self.assertEqual(possible_effects, sword.effects)
def __init__(self, stringFileLocation = ""): with open(stringFileLocation, 'r') as file: print(file.readline()) rows = file.read().splitlines() for row in rows: #print(row) weapon = Weapon(row) self[weapon.name] = weapon print("wapen regels gelezen: ",len(rows)) print("wapens in dict: ",len(self))
def test___init1__(self): w = Weapon('1;Tau;A;Melee;Melee ;User ;2;1;') self.assertIsInstance(w, Weapon) self.assertEqual(w.type, "melee") self.assertEqual(w.shots, [0]) self.assertEqual(w.shots.AttacksUser, True) self.assertEqual(w.range, (0, 0)) self.assertEqual(w.S, [0]) self.assertEqual(w.S.efectModelStrengt, "+") self.assertEqual(w.AP, [2]) self.assertEqual(w.D, [1]) self.assertEqual(w.cost, 1)
def test___init3__(self): w = Weapon('3;Tau;Improvised weapon;Melee;Melee;User;0;1;-') self.assertIsInstance(w, Weapon) self.assertEqual(w.type, "melee") self.assertEqual(w.shots, [0]) self.assertEqual(w.shots.AttacksUser, True) self.assertEqual(w.range, (0, 0)) self.assertEqual(w.S, [0]) self.assertEqual(w.S.efectModelStrengt, "+") self.assertEqual(w.AP, [0]) self.assertEqual(w.D, [1]) self.assertEqual(w.cost, 3)
def test___init7__(self): w = Weapon( '7;Tau;Bubotic Axe;Melee;Melee;+1;-2;1;You can re-roll wound rolls of 1 for this weapon.' ) self.assertIsInstance(w, Weapon) self.assertEqual(w.type, "melee") self.assertEqual(w.shots, [0]) self.assertEqual(w.shots.AttacksUser, True) self.assertEqual(w.range, (0, 0)) self.assertEqual(w.S, [1]) self.assertEqual(w.S.efectModelStrengt, "+") self.assertEqual(w.AP, [2]) self.assertEqual(w.D, [1]) self.assertEqual(w.cost, 7)
def test___init6__(self): w = Weapon( '6;Tau;Hyper Blight Grenades;6";Grenade D6;4;0;2;Plague Weapon. Each wound roll of 6+ made for this weapon inflicts a mortal wound in addition to any other damage.' ) self.assertIsInstance(w, Weapon) self.assertEqual(w.type, "grenade") self.assertEqual(w.shots, [1, 2, 3, 4, 5, 6]) self.assertEqual(w.shots.AttacksUser, False) self.assertEqual(w.range, (1, 6)) self.assertEqual(w.S, [4]) self.assertEqual(w.S.efectModelStrengt, "") self.assertEqual(w.AP, [0]) self.assertEqual(w.D, [2]) self.assertEqual(w.cost, 6)
def test___init5__(self): w = Weapon( '5;Tau;Injector pistol;3";Pistol 1;4;-1;D6;Plague Weapon. This weapon\'s damage changes to 1 when attacking VEHICLES.' ) self.assertIsInstance(w, Weapon) self.assertEqual(w.type, "pistol") self.assertEqual(w.shots, [1]) self.assertEqual(w.shots.AttacksUser, False) self.assertEqual(w.range, (0, 3)) self.assertEqual(w.S, [4]) self.assertEqual(w.S.efectModelStrengt, "") self.assertEqual(w.AP, [1]) self.assertEqual(w.D, [1, 2, 3, 4, 5, 6]) self.assertEqual(w.cost, 5)
def test___init4__(self): w = Weapon( '4;Tau;Plaguespitter;9";Assault D6;User;-1;1;Plague Weapon.This weapon automatically hits its target.' ) self.assertIsInstance(w, Weapon) self.assertEqual(w.type, "assault") self.assertEqual(w.shots, [1, 2, 3, 4, 5, 6]) self.assertEqual(w.shots.AttacksUser, False) self.assertEqual(w.range, (1, 9)) self.assertEqual(w.S, [0]) self.assertEqual(w.S.efectModelStrengt, "+") self.assertEqual(w.AP, [1]) self.assertEqual(w.D, [1]) self.assertEqual(w.cost, 4)
def test___init2__(self): w = Weapon( '2;Tau;Plagueburst Mortar;12"-48";Heavy D6;8;-2;D3;Plague Weapon. This weapon can target units that are not visible to the bearer.' ) self.assertIsInstance(w, Weapon) self.assertEqual(w.type, "heavy") self.assertEqual(w.shots, [1, 2, 3, 4, 5, 6]) self.assertEqual(w.shots.AttacksUser, False) self.assertEqual(w.range, (12, 48)) self.assertEqual(w.S, [8]) self.assertEqual(w.S.efectModelStrengt, "") self.assertEqual(w.AP, [2]) self.assertEqual(w.D, [1, 2, 3]) self.assertEqual(w.cost, 2)
def test___init9__(self): w = Weapon( '9;Tau;Contagion spray;9";Pistol 2D3;*;-2;1;Attacks made with this weapon automatically hit the selected target. This weapon always wounds on a result of a 2+ unless the target unit has the VEHICLE keyword, in which case a result of 6+ is required.' ) self.assertIsInstance(w, Weapon) self.assertEqual(w.type, "pistol") self.assertEqual(w.shots, [2, 3, 4, 3, 4, 5, 4, 5, 6]) self.assertEqual(w.shots.AttacksUser, False) self.assertEqual(w.range, (0, 9)) self.assertEqual(w.S, [0]) self.assertEqual(w.S.efectModelStrengt, "*") self.assertEqual(w.AP, [2]) self.assertEqual(w.D, [1]) self.assertEqual(w.cost, 9)
def test___init8__(self): w = Weapon( '8;Tau;Great plague cleaver;Melee;Melee;x2;-3;D6;When attacking with this weapon, you must subtract 1 from the hit roll. You can re-roll wound rolls of 1 for this weapon.' ) self.assertIsInstance(w, Weapon) self.assertEqual(w.type, "melee") self.assertEqual(w.shots, [0]) self.assertEqual(w.shots.AttacksUser, True) self.assertEqual(w.range, (0, 0)) self.assertEqual(w.S, [2]) self.assertEqual(w.S.efectModelStrengt, "x") self.assertEqual(w.AP, [3]) self.assertEqual(w.D, [1, 2, 3, 4, 5, 6]) self.assertEqual(w.cost, 8)
def parse_item_file(name): # Retrieve data root for item it_tree_root = etree.parse('data/items.xml').getroot().find('.//' + name) sprite = 'imgs/dungeon_crawl/item/' + it_tree_root.find( 'sprite').text.strip() info = it_tree_root.find('info').text.strip() price = it_tree_root.find('price') if price is not None: price = int(price.text.strip()) else: price = 0 category = it_tree_root.find('category').text.strip() if category == 'potion': effect_name = it_tree_root.find('effect').text.strip() power = int(it_tree_root.find('power').text.strip()) duration = int(it_tree_root.find('duration').text.strip()) effect = Effect(effect_name, power, duration) item = Potion(name, sprite, info, price, effect) elif category == 'consumable': effect_name = it_tree_root.find('effect').text.strip() power = int(it_tree_root.find('power').text.strip()) duration = int(it_tree_root.find('duration').text.strip()) effect = Effect(effect_name, power, duration) item = Consumable(name, sprite, info, price, effect) elif category == 'armor': body_part = it_tree_root.find('bodypart').text.strip() defense_el = it_tree_root.find('def') defense = int(defense_el.text.strip()) if defense_el is not None else 0 weight = int(it_tree_root.find('weight').text.strip()) eq_sprites = it_tree_root.find('equipped_sprites') if eq_sprites is not None: equipped_sprites = [] for eq_sprite in eq_sprites.findall('sprite'): equipped_sprites.append('imgs/dungeon_crawl/player/' + eq_sprite.text.strip()) else: equipped_sprites = [ 'imgs/dungeon_crawl/player/' + it_tree_root.find('equipped_sprite').text.strip() ] restrictions = load_restrictions(it_tree_root.find('restrictions')) item = Equipment(name, sprite, info, price, equipped_sprites, body_part, defense, 0, 0, weight, restrictions) elif category == 'shield': parry = int(float(it_tree_root.find('parry_rate').text.strip()) * 100) defense_el = it_tree_root.find('def') defense = int(defense_el.text.strip()) if defense_el is not None else 0 fragility = int(it_tree_root.find('fragility').text.strip()) weight = int(it_tree_root.find('weight').text.strip()) equipped_sprite = [ 'imgs/dungeon_crawl/player/hand_left/' + it_tree_root.find('equipped_sprite').text.strip() ] restrictions = load_restrictions(it_tree_root.find('restrictions')) item = Shield(name, sprite, info, price, equipped_sprite, defense, weight, parry, fragility, restrictions) elif category == 'weapon': power = int(it_tree_root.find('power').text.strip()) attack_kind = it_tree_root.find('kind').text.strip() weight = int(it_tree_root.find('weight').text.strip()) fragility = int(it_tree_root.find('fragility').text.strip()) w_range = [ int(reach) for reach in it_tree_root.find('range').text.strip().split(',') ] equipped_sprite = [ 'imgs/dungeon_crawl/player/hand_right/' + it_tree_root.find('equipped_sprite').text.strip() ] restrictions = load_restrictions(it_tree_root.find('restrictions')) item = Weapon(name, sprite, info, price, equipped_sprite, power, attack_kind, weight, fragility, w_range, restrictions) elif category == 'key': item = Key(name, sprite, info, price) elif category == 'spellbook': spell = it_tree_root.find('effect').text.strip() item = Spellbook(name, sprite, info, price, spell) else: # No special category item = Item(name, sprite, info, price) return item
def random_weapon(price=None, durability=None): attrs = random_weapon_attributes(price, durability) return Weapon(attrs['name'], attrs['sample_img'], attrs['desc'], attrs['cost'], [attrs['sample_img']], attrs['power'], attrs['attack_kind'], attrs['weight'], attrs['durability'], attrs['reach'], attrs['restrictions'], attrs['effects'])