def attack(self, enemy): attack_value = self.base_attack # for item in self.equipped_items: # if hasattr(item, 'attack_value'): # attack_value += item.attack_value attack = dice.roll(attack_value, 6) damage = attack - enemy.defense_value if damage <= 0: return if damage > 0: enemy.current_hp -= damage enemy.save() return
def generate_enemy(strength): hpmax = dice.roll(enemy_strength_dict[strength]['hpmax'][0],enemy_strength_dict[strength]['hpmax'][1]) #c enemy = Enemy([x for x in enemy_strength_dict[strength]]) enemy = Enemy(name=enemy_strength_dict[strength]['name'], xp_value=enemy_strength_dict[strength]['xp_value'], renown_value=enemy_strength_dict[strength]['renown_value'], hpmax=hpmax, current_hp=hpmax, base_attack=enemy_strength_dict[strength]['base_attack'], base_defense=enemy_strength_dict[strength]['base_defense'], gold=enemy_strength_dict[strength]['gold'] ) enemy.save() # print 'name', enemy.name # print 'xp', enemy.xp_value # print 'renown', enemy.renown_value # print 'hpmax', enemy.hpmax # print 'current hp', enemy.current_hp # print 'base attack', enemy.base_attack # print 'base defense', enemy.base_defense # print 'gold', enemy.gold # enemy.delete() return enemy
def home(request): characters = [] if request.user.is_authenticated(): characters = Character.objects.filter(created_by=request.user.profile.id) if request.POST: form = CreateCharacterForm(request.POST) if form.is_valid(): hp = dice.roll(18, 5) character = Character(name=request.POST['name'], hpmax=hp, current_hp=hp) request.user.profile.created_characters.add(character) character.save() inventory = Inventory(character=character) inventory.save() return redirect('home') else: form = CreateCharacterForm() context = { 'form': form, 'characters': characters, } return render(request, 'home.html', context)
def initiative_roll(self): roll = dice.roll(1, 21) return roll
def create(cls): hpmax = dice.roll(15,6) gold = dice.roll(5,6) enemy = cls(hpmax=hpmax, gold=gold) return enemy
# print "\t", item # return def initiative_roll(self): roll = dice.roll(1, 21) return roll enemy_strength_dict = { 'weak': {'name': 'An Enemy!', 'xp_value': 5, 'renown_value': 7, 'hpmax': [13, 5], 'current_hp': 0, 'base_attack': 4, 'base_defense': 5, 'gold': dice.roll(5, 7) }, 'medium': {'name': 'A Medium Strength Enemy!', 'xp_value': 15, 'renown_value': 14, 'hpmax': [17, 5], 'current_hp': 0, 'base_attack': 8, 'base_defense': 8, 'gold': dice.roll(9, 7) }, 'strong': {'name': 'A Strong Enemy!', 'xp_value': 45, 'renown_value': 21, 'hpmax': [25, 5], 'current_hp': 0,
def create(cls): hpmax = dice.roll(15,7) character = cls(hpmax=hpmax) return character
def display_equipped(self): pass # print "These are your equipped items" # for item in self.equipped_items: # print "\t", item # return def initiative_roll(self): roll = dice.roll(1, 21) return roll enemy_strength_dict = { 'weak': {'name': 'An Enemy!', 'xp_value': 5, 'renown_value': 7, 'hpmax': dice.roll(13, 5), 'current_hp': 0, 'base_attack': 4, 'base_defense': 5, 'gold': dice.roll(5, 7) }, 'medium': {'name': 'An Enemy!', 'xp_value': 15, 'renown_value': 14, 'hpmax': dice.roll(17, 5), 'current_hp': 0, 'base_attack': 8, 'base_defense': 8, 'gold': dice.roll(9, 7) }, 'strong': {'name': 'An Enemy!',