Exemple #1
0
def _get_roll_from_form_and_system(form, system_field):
    attr = form.cleaned_data["attribute_roll"]
    difficulty = 6
    if system_field.difficulty:
        difficulty = system_field.difficulty
    if attr == BODY_[0] or attr == MIND_[0] or attr == PARRY_[0]:
        if attr == BODY_[0]:
            return Roll.get_body_roll(difficulty=difficulty)
        elif attr == MIND_[0]:
            return Roll.get_mind_roll(difficulty=difficulty)
        elif attr == PARRY_[0]:
            return Roll.get_roll(difficulty=difficulty, parry_type=system_field.parry_type, speed=REACTION)
        else:
            raise ValueError("Unexpected attr")
    else:
        attribute = get_object_or_404(Attribute, id=attr)
        ability = get_object_or_404(Ability, id=form.cleaned_data["ability_roll"])
        return Roll.get_roll(attribute = attribute,
                             ability = ability,
                             difficulty = difficulty,
                             speed=system_field.speed)
    def test_get_body_roll(self):
        roll = Roll.get_body_roll()
        roll2 = Roll.get_body_roll(7)
        self.assertEquals(roll.is_body, True)
        self.assertEquals(roll2.is_body, True)
        roll3 = Roll.get_body_roll()
        self.assertEquals(roll3, roll)
        roll4 = Roll.get_body_roll(7)
        self.assertEquals(roll2, roll4)
        self.assertEquals(Roll.objects.count(), 2)

        roll5 = Roll.get_body_roll(
            difficulty=7, speed=NO_SPEED_INFO)  # Default is free action
        self.assertEquals(Roll.objects.count(), 3)
        roll6 = Roll.get_body_roll(difficulty=7, speed=NO_SPEED_INFO)
        self.assertEquals(roll5, roll6)
        self.assertEquals(Roll.objects.count(), 3)