matteoferla/DnD-battler

TypeError: 'AttackRoll' object is not subscriptable

Closed this issue · 4 comments

image

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_36960/1179340639.py in <module>
----> 1 print(arena.battle())

j:\clone\dnd-battler\DnD_battler\encounter\_action.py in battle(self, reset, verbose)
    128             character.tally['hp'] += character.hp
    129             character.tally['healing_spells'] += character.healing_spells
--> 130         if verbose: self.masterlog.append(str(self))
    131         # return self or side?
    132         return self

j:\clone\dnd-battler\DnD_battler\encounter\_base.py in __str__(self)
     55     def __str__(self):
     56         string = "=" * 50 + ' ' + self.name + " " + "=" * 50 + ";\n"
---> 57         string += self.predict()
     58         string += "-" * 110 + '\n'
     59         string += "Battles: " + str(self.tally['battles']) + "; Sum of rounds: " + str(

j:\clone\dnd-battler\DnD_battler\encounter\_action.py in predict(self)
     76         for character in self:
     77             for move in character.attacks:
---> 78                 move['damage'].avg = True
     79                 damage[character.alignment] += safediv((20 + move['attack'].bonus - ac[not_us(character.alignment)]),
     80                                                        20 * move['damage'].roll())

TypeError: 'AttackRoll' object is not subscriptable

This one I would certainly have to dig in to more to hazard a guess.

Looks like the same code as in the master though at first glance.

image

from DnD_battler import Creature, Encounter
level1 = Creature(name="buff peasant1", abilities = {'str': 15,'dex': 14,'con':13,'int':12,'wis':10,'cha': 8}, alignment ="good", attack_parameters=[['longsword', 4, 2, 8]])
billbybob2 = Creature.load('basilisk')
arena2 = Encounter(level1, billbybob2)
print(arena2.battle())
            for move1 in character.attacks:
                move = move1.ability_die
                print("MOVE")		
                print(move)
                print(move. __dict__) 
                #print(character.attacks)
                move.avg = True
                damage[character.alignment] += safediv((20 + move.bonus - ac[not_us(character.alignment)]), 20 * move.roll())
				#damage[character.alignment] += safediv((20 + move['attack'].bonus - ac[not_us(character.alignment)]), 20 * move['damage'])
                move.avg = False
                hp[character.alignment] += character.starting_hp

So something like that?
10 length war

Rough a priori predictions:
> unaligned = expected rounds to survive: 769.87; crudely normalised: 0%
> good= expected rounds to survive: 47.97; crudely normalised: 0%
--------------------------------------------------------------------------------------------------------------
Battles: 10; Sum of rounds: 10; unaligned : 1.0 ± 0.0; good: 0.0 ± 0.0; ;
> Team unaligned  = winning battles: 10; perfect battles: 0; close-call battles: 0;
> Team good = winning battles: 0; perfect battles: 0; close-call battles: 0;
------------------------------------------------- Combattants  ------------------------------------------------;
buff peasant1: {team=good; avg hp=-10.2 (from 4); avg healing spells left=0.0 (from 0); damage done (per battle average)= 2.85; hits/misses (PBA)= 0.25/0.1; rounds (PBA)=0.35;};
buff peasant1: {team=good; avg hp=-10.2 (from 4); avg healing spells left=0.0 (from 0); damage done (per battle average)= 2.85; hits/misses (PBA)= 0.25/0.1; rounds (PBA)=0.35;};
basilisk: {team=unaligned ; avg hp=46.3 (from 52); avg healing spells left=0.0 (from 0); damage done (per battle average)= 7.1; hits/misses (PBA)= 0.5/0.0; rounds (PBA)=1.0;};
basilisk: {team=unaligned ; avg hp=46.3 (from 52); avg healing spells left=0.0 (from 0); damage done (per battle average)= 7.1; hits/misses (PBA)= 0.5/0.0; rounds (PBA)=1.0;};