87 lines
2.4 KiB
Python
87 lines
2.4 KiB
Python
from mesa import Agent
|
|
import random
|
|
|
|
|
|
def dice(number):
|
|
return random.randint(1, number)
|
|
|
|
|
|
|
|
class Wall(Agent):
|
|
def __init__(self, unique_id, model):
|
|
super().__init__(unique_id, model)
|
|
|
|
def step(self):
|
|
pass
|
|
|
|
|
|
class Box(Agent):
|
|
def __init__(self, unique_id, model):
|
|
super().__init__(unique_id, model)
|
|
self.gold = 3 * dice(6)
|
|
self.isBox = True
|
|
self.isCreature = False
|
|
|
|
def step(self):
|
|
pass
|
|
|
|
|
|
class Weapon():
|
|
def __init__(self, name, type, damage):
|
|
self.name = name
|
|
self.type = type
|
|
self.damage = damage
|
|
|
|
|
|
class Armor():
|
|
def __init__(self, name, defence, mp):
|
|
self.name = name
|
|
self.defence = defence
|
|
self.mag_protection = mp
|
|
|
|
|
|
class Creature(Agent):
|
|
def __init__(self, unique_id, model, n, s, a, w, maxhp, hp, weap, arm, g):
|
|
super().__init__(unique_id, model)
|
|
self.name = n
|
|
self.strength = s
|
|
self.agility = a
|
|
self.wisdom = w
|
|
self.maxHealth = maxhp
|
|
self.health = hp
|
|
self.gold = g
|
|
self.weapon1 = weap
|
|
self.armor = arm
|
|
self.isBox = False
|
|
self.isCreature = True
|
|
|
|
def meleeAttack(self, opponent):
|
|
attackValue = self.strength + dice(6)
|
|
defenseValue = opponent.strength + opponent.armor.defence
|
|
damage = attackValue - defenseValue
|
|
if damage > 0:
|
|
opponent.health = opponent.health - (damage + self.weapon1.damage)
|
|
|
|
def rangeAttack(self, opponent):
|
|
attackValue = self.agility + dice(6)
|
|
defenseValue = opponent.agility
|
|
damage = attackValue - defenseValue
|
|
if (damage > 0) and (damage + self.weapon1.damage - opponent.armor.defence > 0):
|
|
opponent.health = opponent.health - (damage + self.weapon1.damage - opponent.armor.defence)
|
|
|
|
def magicAttack(self, opponent):
|
|
attackValue = self.wisdom + dice(6)
|
|
defenseValue = opponent.wisdom
|
|
damage = attackValue - defenseValue
|
|
if (damage > 0) and (damage + self.weapon1.damage - opponent.armor.mag_protection > 0):
|
|
opponent.health = opponent.health - (damage + self.weapon1.damage - opponent.armor.mag_protection)
|
|
|
|
def defaultAttack(self, opponent):
|
|
if self.weapon1.type == "Meele":
|
|
self.meleeAttack(opponent)
|
|
elif self.weapon1.type == "Range":
|
|
self.rangeAttack(opponent)
|
|
else:
|
|
self.magicAttack(opponent)
|
|
|