dice_roller.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import numpy as np
  2. import math
  3. class Weapon:
  4. def __init__(self, name, gpe, dammage, type, pene, range, mode, at, rch, attribute):
  5. self.name = name
  6. self.gpe = gpe
  7. self.dammage = dammage
  8. self.type = type
  9. self.pene = pene
  10. self.range = range
  11. self.mode = mode
  12. self.at = at
  13. self.rch = rch
  14. self.attribute = attribute
  15. class MyPerso:
  16. def __init__(self):
  17. self.experience = 17400
  18. self.CC = 52
  19. self.CT = 40
  20. self.F = 46
  21. self.E = 45
  22. self.AG = 50
  23. self.INT = 34
  24. self.PER = 43
  25. self.FM = 43
  26. self.SOC = 40
  27. self.MF = 2 * math.floor((self.F + 2 * 5) / 10) + 30 / 10
  28. self.weapons = [
  29. Weapon("Flamethrower", "Base", "2d10+5", "", 3, 20, None, None, None, None)
  30. ]
  31. def bonus(self, int):
  32. return np.round(int / 10)
  33. def dices(self, number_of_dice, int):
  34. dice = np.random.random_integers(1, int, number_of_dice)
  35. print("rolled %s dice of %s and got %s" % (number_of_dice, int, dice))
  36. return dice
  37. def initiative(self):
  38. return self.dices(1, 10) + self.bonus(self.AG)
  39. def perception(self, bonus=0):
  40. return (self.dices(1, 100) - self.PER - bonus - 20) < 0
  41. def flamethrower(self, hord=True):
  42. if hord:
  43. return np.ceil(self.weapons[0].range / 4) + self.dices(1, 5)
  44. def bolter_damage(self, success_degree):
  45. throw = []
  46. for degree in range(success_degree):
  47. current_throw = self.dices(3, 10)
  48. throw.append(current_throw[np.argsort(current_throw)[-2:]])
  49. print(throw)
  50. return np.sum(throw) + 5 * success_degree
  51. def bolter(self, bonus_ct=0):
  52. ct_dice = self.CT - self.dices(1, 100) + bonus_ct
  53. print("ct_dice_roll %i" % ct_dice)
  54. if ct_dice > 0:
  55. success_degree = 1 + int(math.floor(ct_dice / 10))
  56. print(success_degree)
  57. else:
  58. success_degree = 0
  59. return self.bolter_damage(success_degree)
  60. def sword_damage(self):
  61. return self.dices(1, 10) + 3 + self.MF
  62. def test_cc(self, bonus=0):
  63. return self.CC + bonus - self.dices(1, 100) > 0
  64. def fast_attack(self):
  65. damage = 0
  66. for i in range(2):
  67. if self.test_cc():
  68. damage += self.sword_damage()
  69. print("Sword damage % i penetration 4" % damage)
  70. return damage