def process_new_weapon_form(char_id): """Add new weapon to database.""" form = AddWeaponForm() if form.validate_on_submit(): new_weapon = Weapon(name=form.name.data, image_url=form.image_url.data, weapon_type=form.weapon_type.data, damage=form.damage.data, damage_type=form.damage_type.data, weapon_range=form.weapon_range.data, description=form.description.data, weight=form.weight.data, condition=form.condition.data, rarity=form.rarity.data, notes=form.notes.data, is_equipped=form.is_equipped.data, character_id=char_id) db.session.add(new_weapon) db.session.commit() serial_weapon = new_weapon.serialize() return (jsonify(serial_weapon), 200) errors = {"errors": form.errors} return jsonify(errors)
def create_weapon(self, weapon_data: dict) -> Weapon: weapon = Weapon( weapon_id = weapon_data['weapon_id'], weapon_name = weapon_data['name'], ops = weapon_data['OPs'] if weapon_data['OPs'] else 0, ammo = weapon_data['ammo'] if weapon_data['ammo'] else 0, ammo_sec = weapon_data['ammo/sec'] if weapon_data['ammo/sec'] else 0, autocharge = weapon_data['autocharge'], burst_size = weapon_data['burst size'] if weapon_data['burst size'] else 0, damage_sec = weapon_data['damage/second'] if weapon_data['damage/second'] else 0, damage_shot = weapon_data['damage/shot'] if weapon_data['damage/shot'] else 0, emp = weapon_data['emp'] if weapon_data['emp'] else 0, energy_second = weapon_data['energy/second'] if weapon_data['energy/second'] else 0, energy_shot = weapon_data['energy/shot'] if weapon_data['energy/shot'] else 0, hardpoint_sprite = weapon_data['hardpoint_sprite'], weapon_range = weapon_data['range'] if weapon_data['range'] else 0, requires_full_charge = weapon_data['requires_full_charge'], size = weapon_data['size'], spec_class = weapon_data['spec_class'], turn_rate = weapon_data['turn rate'] if weapon_data['turn rate'] else 0, turret_sprite = weapon_data['turret_sprite'], proj_speed = weapon_data['proj speed'] if weapon_data['proj speed'] else 0, weapon_type = weapon_data['type'], description = weapon_data['description'], mod_name = self.mode_name ) return weapon
def createItems(weapon, location): w = Weapon.create() w.desc = weapon l = Location.create() l.desc = location w.save() l.save()
def getPlayer(self): name = stringPrompt('What is your name?', 'your Name') player = Player(name, race='Human', charType='Warrior') player.weapon = Weapon() player.player = True self.players.append(player) messageDirect(player)
def take_treasure(self): num = randint(0, len(self.treasures) - 1) if self.treasures[num][0] == "mana": self.hero.take_mana(self.treasures[num][1]) print(f'Found mana potion: {self.treasures[num][1]}') print(f'Hero current mana: {self.hero.curr_mana}') if self.treasures[num][0] == "health": self.hero.take_healing(self.treasures[num][1]) print(f'Found health potion: {self.treasures[num][1]}') print(f'Hero current health: {self.hero.curr_health}') if self.treasures[num][0] == "weapon": w = Weapon(name=self.treasures[num][1], damage=self.treasures[num][2]) if self.hero.equiped_weapon is not None: print(f'Equiped: {str(self.hero.equiped_weapon)}') print(f'Offered: {str(w)}') answer = input('Would you like to change weapon? ') if answer == 'y': self.hero.equip(w) else: self.hero.equip(w) if self.treasures[num][0] == "spell": s = Spell(name=self.treasures[num][1], damage=self.treasures[num][2], mana_cost=self.treasures[num][3], cast_range=self.treasures[num][4]) if self.hero.equiped_spell is not None: print(f'Learned: {str(self.hero.equiped_spell)}') print(f'Offered: {str(s)}') answer = input('Would you like to learn the new spell? ') if answer == 'y': self.hero.learn(s) else: self.hero.learn(s) print(f'Learned new spell: {str(self.hero.equiped_spell)}')
def testGivePlayerEquipment(player_key_string): player = ndb.Key(urlsafe=player_key_string).get() player.equipment.append( Equipment( equipment_type=1, armor_data=Armor(armor_type=0, damage_reduction=0.6, durability=400), ).put()) player.equipment.append( Equipment( equipment_type=0, weapon_data=Weapon(weapon_type=0, power=20, reliability=0.995), ).put()) player.put()
def generate_starter_equipment(character): chest = Armor(name='Cheap Combat Armor',slot='chest',ac=10,value=100) head = Armor(name='Cheap Combat Helmet',slot='head',ac=10,value=100) hands = Armor(name='Cheap Combat Gloves',slot='hands',ac=10,value=100) legs = Armor(name='Cheap Combat Legplates',slot='legs',ac=10,value=100) feet = Armor(name='Cheap Combat Boots',slot='feet',ac=10,value=100) weapon = Weapon(name='Cheap Martian M16 Knockoff',damage_dice='2d4',value=100) db.session.add(chest) db.session.add(head) db.session.add(hands) db.session.add(legs) db.session.add(feet) db.session.add(weapon) db.session.commit() character.inventory.extend([chest,head,legs,feet,weapon,hands]) db.session.add(character) db.session.commit()
def play_game(): print( 'Controls:\n-Move up - w\n-Move down - s\n-Move left - a\n-Move right - d\n-Cast a spell out of fight - j\n' ) hero_name = input('What\'s your name? ') hero = Hero(name=hero_name, title='Vagabond', health=100, mana=100, mana_regeneration_rate=2) weapon = Weapon(name='Wooden sword', damage=10) hero.equip(weapon) quit = False for i in range(1, 4): file_name = f'levels_and_treasures/level{i}.txt' dungeon = Dungeon(file_name) dungeon.create_treasures('levels_and_treasures/treasures.txt') dungeon.spawn(hero) print(f'{hero.known_as()} entered dungeon {i}') dungeon.print_map() while hero.is_alive() and not dungeon.hero_is_at_gateway(): if get_player_move(dungeon): dungeon.print_map() if not hero.is_alive(): print('GAME OVER') quit = True break hero.level_up() if i != 3 and not ask_to_continue(): quit = True break if not quit: print('Congratulations, you won the game! :)')
def getWeaponListingById(self, ids): try: data = [] for i in ids: print("retrieved weapon: ", self.getOneElementById('weapons', i)) data.append(self.getOneElementById('weapons', i)) if data: from models import Weapon weapons = [] for r in data: weapons.append(Weapon(*r)) print("Successfully retrieved weapon") return weapons else: print("Failed to retrieve weapon: no weapon") return None except: print("Failed to retrieve weapon: no connection,", sys.exc_info()[1]) return None
def craftEquipment(inputs): """ @param inputs a json object with inputs.""" # TODO: Break up this code into functional pieces. # TODO: Validate inputs. # TODO: Think hard about redesigning the crafting logic. equipment_template_key = inputs['equipment_template_key'] # Make sure the player has all of the necessary resources. cost_to_craft = EQUIPMENT_TEMPLATE_CRAFT_COSTS[equipment_template_key] player_key = ndb.Key(urlsafe=inputs['player_id']) # TODO: error handle. player = player_key.get() resources_to_put = [] formula_input = {} # TODO: Make this more generic, instead of checking each. DRY this up. if cost_to_craft.metal > 0: # Check for adequate metal resources. if 'metal_resource_key' not in inputs: logging.error('metal_resource_key missing from input!') # TODO: handle failure better than returning none. return None resource_key = ndb.Key(urlsafe=inputs['metal_resource_key']) if resource_key in player.resources: resource = resource_key.get() template = resource.resource_template.get() if (resource.quantity >= cost_to_craft.metal and template.resource_type == RESOURCE_TYPES_INT_MAPPING[METAL_KEY]): resource.quantity -= cost_to_craft.metal resources_to_put.append(resource) formula_input[METAL_KEY] = template # TODO: Add crafting power formulas logic here! else: logging.error( 'Metal Quantity too low, or resource is not metal!') # TODO: handle failure better than returning none. return None else: logging.error('Player does not own metal resource!') # TODO: handle failure better than returning none. return None if cost_to_craft.wood > 0: # Check for adequate wood resources. if 'wood_resource_key' not in inputs: logging.error('wood_resource_key missing from input!') # TODO: handle failure better than returning none. return None resource_key = ndb.Key(urlsafe=inputs['wood_resource_key']) if resource_key in player.resources: resource = resource_key.get() template = resource.resource_template.get() if (resource.quantity >= cost_to_craft.wood and template.resource_type == RESOURCE_TYPES_INT_MAPPING[WOOD_KEY]): resource.quantity -= cost_to_craft.wood resources_to_put.append(resource) formula_input[WOOD_KEY] = template # TODO: Add crafting power formulas logic here! else: logging.error( 'Wood Quantity too low, or resource is not wood!') # TODO: handle failure better than returning none. return None else: logging.error('Player does not own wood resource!') # TODO: handle failure better than returning none. return None if cost_to_craft.leather > 0: # Check for adequate leather resources. if 'leather_resource_key' not in inputs: logging.error('leather_resource_key missing from input!') # TODO: handle failure better than returning none. return None resource_key = ndb.Key(urlsafe=inputs['leather_resource_key']) if resource_key in player.resources: resource = resource_key.get() template = resource.resource_template.get() if (resource.quantity >= cost_to_craft.leather and template.resource_type == RESOURCE_TYPES_INT_MAPPING[LEATHER_KEY]): resource.quantity -= cost_to_craft.leather resources_to_put.append(resource) formula_input[LEATHER_KEY] = template # TODO: Add crafting power formulas logic here! else: logging.error( 'Leather Quantity too low, or resource is not leather!') # TODO: handle failure better than returning none. return None else: logging.error('Player does not own leather resource!') # TODO: handle failure better than returning none. return None # Validation has passed. Create the equipment. equipment_type = EQUIPMENT_TEMPLATE_TO_TYPE_MAPPING[equipment_template_key] crafted_equipment = Equipment(equipment_type=equipment_type, player=player_key) if equipment_type == EQUIPMENT_TYPE_INT_MAPPING[WEAPON_KEY]: crafted_equipment.weapon_data = Weapon( weapon_type=WEAPON_TYPE_INT_MAPPING[equipment_template_key], power=int( getAttributeValue( formula_input, WEAPON_POWER_FORMULA[equipment_template_key])), reliability=getAttributeValue( formula_input, WEAPON_RELIABILITY_FORMULA[equipment_template_key])) player.equipment.append(crafted_equipment.put()) player.put() # TODO: Handle armor crafting. # Crafting complete. Now update the resources. ndb.put_multi(resources_to_put)
def copy_item(): """Copy item to other character.""" if not g.user: return (jsonify("error: login"), 403) args = request.args charid = args["charid"] itemid = args["itemid"] itemtype = args["itemtype"] item = None newitem = None character = Character.query.get(charid) if character.user_id != g.user.id: if not g.user: return (jsonify("error: login"), 403) if itemtype == "ability": item = Ability.query.get(itemid) newitem = Ability(name=item.name, image_url=item.image_url, damage=item.damage, damage_type=item.damage_type, description=item.description, ability_range=item.ability_range, effect_area=item.effect_area, min_level=item.min_level, is_spell=item.is_spell, school=item.school, notes=item.notes, character_id=character.id) elif itemtype == "weapon": item = Weapon.query.get(itemid) newitem = Weapon(name=item.name, image_url=item.image_url, weapon_type=item.weapon_type, damage=item.damage, damage_type=item.damage_type, weapon_range=item.weapon_range, description=item.description, weight=item.weight, condition=item.condition, rarity=item.rarity, notes=item.notes, is_equipped=item.is_equipped, character_id=character.id) else: item = Item.query.get(itemid) newitem = Item(name=item.name, image_url=item.image_url, description=item.description, weight=item.weight, is_wearable=item.is_wearable, armor_class=item.armor_class, condition=item.condition, rarity=item.rarity, quantity=item.quantity, notes=item.notes, is_equipped=item.is_equipped, character_id=character.id) db.session.add(newitem) db.session.commit() return (jsonify(newitem.serialize()), 200)
from models import Character, Weapon, Base, Artifact from sqlalchemy import create_engine from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import sessionmaker, relationship from from_xlsx import character_df, weapon_df, artifact_df character_dict = character_df.transpose().to_dict() weapon_dict = weapon_df.transpose().to_dict() artifact_dict = artifact_df.transpose().to_dict() engine = create_engine("sqlite:///sample.db", echo=True) Base.metadata.create_all(bind=engine) Session = sessionmaker(bind=engine) session = Session() char_objs = [Character(**character_dict.get(key)) for key in character_dict] weapon_objs = [Weapon(**weapon_dict.get(key)) for key in weapon_dict] artifact_objs = [Artifact(**artifact_dict.get(key)) for key in artifact_dict] session.bulk_save_objects(char_objs) session.bulk_save_objects(weapon_objs) session.bulk_save_objects(artifact_objs) session.commit() session.close() con = sqlite3.connect("sample.db") df = pd.read_sql_query("SELECT * from weapon", con)
def test_equip(self): h = Hero(name="Pesho", title="The Great One", health=100, mana=10, mana_regeneration_rate=30) w = Weapon(name="GUN", damage=35) h.equip(w) self.assertEqual(h.equiped_weapon.name, "GUN")
damage_type = "physical", description = "Lorem ipsum dolor sit, amet consectetur adipisicing elit. Est, distinctio! Deleniti delectus harum blanditiis suscipit dolorem quam officiis id odit, qui alias, corrupti esse dolores libero at culpa itaque eveniet.", ability_range = "N/A", effect_area = "self", min_level = "1", is_spell = False, notes = "Lorem ipsum dolor sit, amet consectetur adipisicing elit. Est, distinctio! Deleniti delectus harum blanditiis suscipit dolorem quam officiis id odit, qui alias, corrupti esse dolores libero at culpa itaque eveniet.", character_id = character1.id) weapon1 = Weapon(name = "Orcish Blade", image_url = "static/weapon01.png", weapon_type = "Short Sword", damage = "1D6", damage_type = "Slashing", weapon_range = "4 ft", description = "Lorem ipsum dolor sit, amet consectetur adipisicing elit. Est, distinctio! Deleniti delectus harum blanditiis suscipit dolorem quam officiis id odit, qui alias, corrupti esse dolores libero at culpa itaque eveniet.", weight = 5, condition = "Fair", rarity = "Common", notes = "Lorem ipsum dolor sit, amet consectetur adipisicing elit. Est, distinctio! Deleniti delectus harum blanditiis suscipit dolorem quam officiis id odit, qui alias, corrupti esse dolores libero at culpa itaque eveniet.", is_equipped = True, character_id = character1.id) weapon2 = Weapon(name = "Wooden Bow", image_url = "static/weapon03.png", weapon_type = "Ranged", damage_type = "Piercing", damage = "2D4", weapon_range = "100 ft", description = "Lorem ipsum dolor sit, amet consectetur adipisicing elit. Est, distinctio! Deleniti delectus harum blanditiis suscipit dolorem quam officiis id odit, qui alias, corrupti esse dolores libero at culpa itaque eveniet.", weight = 3,