summaryrefslogtreecommitdiff
path: root/main.py
blob: 53993f11d59b9587cbbc9d07424d4e1ff35e7ac2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import math
from character import CharacterPlan
from game import Difficulty, Roll, d
from creature import CreaturePlan
from actions import Attack
from items import Weapon

import pb2e

def treat_wounds(check_res, heal_bonus=0):
    if check_res <= Roll.Fumble:
        return -d(8)
    if check_res == Roll.Fail:
        return 0
    if check_res == Roll.Success:
        return 2*d(8) + heal_bonus
    if check_res == Roll.Crit:
        return 4*d(8) + heal_bonus

def strike(check_res, dmg, crit_dmg=0):
    if check_res == Roll.Success:
        return dmg
    if check_res == Roll.Crit:
        return 2*dmg + crit_dmg
    return 0


def show_stat(name, dist):
    print(name)
    values = list(dist.probabilities.keys())
    mn = min(values)
    mx = max(values)
    print("min", mn, dist.probabilities[mn])
    print("max", mx, dist.probabilities[mx])
    print("Exp", dist.expected())
    print("Std", dist.standard_deviation())
    print("<0", dist.accumulate_prob(lambda x: x < 0))
    print(">0", dist.accumulate_prob(lambda x: x > 0))
    print("")
    assert abs(dist.accumulate_prob(lambda x: True) - 1) < math.pow(10, -10)



def main():
    treat_options = [
        {"dc": 15, "heal_bonus": 0},
        {"dc": 20, "heal_bonus": 15}
    ]
    bonus = 10
    show_stat("Assurance 15", 2*d(8))
    for opt in treat_options:
        dc = opt["dc"]
        treat = d(20).apply(Roll.check, dc, bonus).apply(treat_wounds, opt["heal_bonus"])
        risky = d(20).apply(Roll.check, dc, bonus+2).apply(lambda x: Roll.Crit if x == Roll.Success else x)
        risky = risky.apply(treat_wounds, opt["heal_bonus"]) + (-d(8))

        show_stat("Treat Wounds " + str(dc), treat)
        show_stat("Risky Surgery " + str(dc), risky)

    treat = d(20).apply(Roll.check, 20, bonus+1).apply(treat_wounds, 15)
    show_stat("Treat Wounds 20 +1", treat)

def main2():
    ac = 18
    bonus = +8
    dmg = d(6)+4
    attack = d(20).apply(Roll.check, ac, bonus)
    show_stat("attack", attack)
    total_dmg = attack.apply(strike, dmg+1)
    show_stat("dogslicer", total_dmg)
    total_dmg = attack.apply(strike, dmg, d(8))
    show_stat("rapier", total_dmg)

def test3():
    level = 2
    #char_js = pb2e.download_character(pfb_id=160180)
    char_js = pb2e.open_character("quizrel2")
    char_plan = CharacterPlan(char_js)
    char = char_plan.build(level)
    falcata = Weapon("falcata", "martial", "sword", 8, fatal=12)
    char.weapons.append(falcata)
    char.update_fundamental_runes()

    creature_plan = CreaturePlan(default_difficulty=Difficulty.Moderate)
    # creature_plan["reflex"] = Difficulty.High
    # creature_plan["ac"] = Difficulty.High
    creature = creature_plan.build(level)
    attack = Attack(char, creature, falcata)
    print(char.toJSON())
    print(f"Attack +{attack.bonus()} vs AC {attack.target.ac()}")
    show_stat("roll", attack.roll())
    show_stat("falcata", attack.strike())


if __name__ == '__main__':
    test3()