Skip to content

Commit

Permalink
Progress toward #10, much more accurate DV calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
syntaxaire committed Aug 18, 2019
1 parent 23769e2 commit b0da01e
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 26 deletions.
1 change: 1 addition & 0 deletions analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,4 @@ def print_value_weight_ratio():
# get_bugged_eat_messages()
# print_wiki_nonwiki()
# get_wikified_nonwiki()
breakpoint()
9 changes: 9 additions & 0 deletions helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,12 @@ def cp437_to_unicode(val: int):
# control character - must be loaded from table
glyph = cp437_conv[val]
return glyph


def roll_average(val: str):
"""Return the average of a 'xdy' format dice roll, as a floored integer."""
if 'd' not in val:
raise ValueError("roll_average called with non-xdy format")
num, sides = val.split('d')
one_die_avg = (int(sides) + 1) / 2
return int(one_die_avg * int(num))
65 changes: 41 additions & 24 deletions qudobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from anytree import NodeMixin

from config import config
from helpers import cp437_to_unicode
from helpers import cp437_to_unicode, roll_average
from qudtile import QudTile
from svalue import sValue

Expand Down Expand Up @@ -574,33 +574,50 @@ def dv(self):
# same here
dv = self.part_Shield_DV
elif self.inherits_from('Creature'):
dv = 6 + int(self.stat_DV_Value) #AG modifier logic is broken for the time being
# the 'DV' here is the actual DV of the creature or NPC, after:
# base of 6 plus any explicit DV bonus,
# skills, agility modifier (which may be a range determined by
# dice rolls, and which changes DV by 1 for every 2 points of agility
# over/under 16), and any equipment that is guaranteed to be worn
#dv = 6 + int(self.stat_DV_Value) # base DV of all Creatures
#if self.skill_Acrobatics_Dodge:
# the 'Spry' skill
# dv += 2
#if self.skill_Acrobatics_Tumble:
# the 'Tumble' skill
# dv += 1
#ag = self.agility
#if ag:
# if '-' in ag:
# a range, e.g. '18 - 20'
# lower, upper = ag.split('-')
# dvlower = dv + (int(lower) - 16) // 2
# dvupper = dv + (int(upper) - 16) // 2
# if dvlower == dvupper:
# dv = dvlower
# else:
# agility was a range so DV may be a range as well
# dv = str(dvlower) + ' - ' + str(dvupper)
# else:
# an integer, not a range
# dv += (int(ag) - 16) // 2
dv = 6
if self.stat_DV_Value:
dv += int(self.stat_DV_Value)
if self.skill_Acrobatics_Dodge: # the 'Spry' skill
dv += 2
if self.skill_Acrobatics_Tumble: # the 'Tumble' skill
dv += 1
ag_str = self.agility
if '+' in ag_str:
# agility was an sValue-format specifier, e.g. '18+1d4+1d3' (after light processing)
ag = 0
for part in ag_str.split('+'):
if 'd' not in part:
ag += int(part)
else:
ag += roll_average(part)
else:
ag = int(ag_str) # agility was given as an integer
if self.role == 'Minion': # lose 20% to all stats
ag = int(ag * 0.8)
# 1 point bonus to DV for every 2 points of agility over 16
dv += ((int(ag) - 16) // 2)
# does this creature have armor with DV modifiers?
if self.inventoryobject:
for name in list(self.inventoryobject.keys()):
if name[0] in '*#@':
# special values like '*Junk 1'
continue
item = qindex[name]
if item.dv:
print(dv)
dv += int(item.dv)
print(dv, item.name, item.dv)
# does this creature have mutations that affect DV?
if self.mutation:
for mutation, info in self.mutation.items():
if mutation == 'Carapace':
lvl = int(info['Level']) + 1
dv -= (7 - (lvl // 2))
return str(dv) if dv else None

@property
Expand Down
5 changes: 3 additions & 2 deletions svalue.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ def __str__(self):
if len(self) == 1:
return str(self.low)
else:
#return str(self.low) + " - " + str(self.high)
# return str(self.low) + " - " + str(self.high)
return str(self.svalstring)

def __repr__(self):
return "sValue " + self.svalue
return "sValue " + self.svalue

0 comments on commit b0da01e

Please sign in to comment.