Commits

Anonymous committed 58c8487

Added fighting styles: defensive and attack head.

Comments (0)

Files changed (1)

     def battle(self, other): 
         """Fight a dadly battle."""
         return battle(self, other)
+        
+        
+    def fight_round(self,  other, styles_self=[], styles_other=[]):
+        """One battle action against another char.
+        
+    @param styles_self: The different styles the char should use (defense, pull back, escape, target: area). 
+    @type styles_self: A list of Strings. 
+    
+    @param styles_other: The different styles the enemy uses. 
+    @type styles_other: A list of Strings. 
+    
+    @return: [ If the char won (bool), [your new wounds, critical, taken tp damage], [the 
+enemies new wounds, critical, taken tp damage] ]
+
+    Plans: 
+        - TODO: Add options for own fight style. 
+        - TODO: Add options for other fight style. 
+        
+    Planned options for own fight style: 
+        - defense (+6, no damage enemy)
+        - pull back (+9, no damage enemy)
+        - try to escape. 
+        - target specific body area for additional damage. 
+        - Shield/evasion (treshold for the enemies diff, below which no hit was archieved).
+    
+    Ideas: 
+        - Define a damage multiplier, which shows how effective the damage type is against the specific enemy -> do that in the char itself. 
+        - Define the effectivity of the armor against the weapon. 
+        - Get the treshold directly from the char. 
+."""
+       # Initialize all variables empty
+        won = None #: Did we win this round?
+        mods_self = [] #: The modifiers for the protagonists attack roll. 
+        mods_other = [] #: The modifiers for the enemies attack roll. 
+        deep_wounds_self, deep_wounds_other, critical_wounds_self, critical_wounds_other = 0, 0, 0, 0
+        
+        
+        # Apply the effects of the fighting styles. 
+            # For the attacker
+        # The defensive style gives 6 points bonus, but the other char won't take any damage. 
+        if "defensive" in styles_self: 
+            mods_self.append(+6)
+        # Targetting the head gives 6 points malus, but increases the damage by 18 points. 
+        if "target head" in styles_self: 
+            mods_self.append(-6)
+            
+            # For the defender
+        # The defensive style gives 6 points bonus, but the other char won't take any damage. 
+        if "defensive" in styles_other: 
+            mods_other.append(+6)
+        # Targetting the head gives 6 points malus, but increases the damage by 18 points. 
+        if "target head" in styles_other: 
+            mods_other.append(-6)
+        
+        
+        #: The damage we get
+        self.damage_self = 0
+        #: The damage the other gets
+        self.damage_other = 0
+        
+        # Do the rolls for both fighters. 
+        attack_self = self.attack_roll(mods=mods_self)
+        attack_other = other.attack_roll(mods=mods_other)
+        
+        # If I throw higher
+        if attack_self > attack_other: 
+            won = True
+            if not "defensive" in styles_self: 
+                # Now check for damage (we hit)
+                # The damage consists of several factors. 
+                # First the difference between the attack rolls. 
+                self.damage_other += attack_self - attack_other
+                # Then the damage of our weapon. 
+                self.damage_other += self.dam
+                # And substracted the armor of the other. 
+                self.damage_other -= other.arm
+                
+                # For specific body ares, the damage increases. 
+                if "target head" in styles_self: 
+                    self.damage_other += 18
+        
+                # Clean out negative damage. If the damage is below zero, the armor caught all damage. 
+                if self.damage_other < 0: 
+                    self.damage_other = 0
+                
+                # Now actually do the damage. This returns a tuple: (new deep wounds, new critical wounds)
+                deep_wounds_other, critical_wounds_other = other.damage(tp=self.damage_other)
+        
+        # If the other rolls better
+        elif attack_self < attack_other: 
+            won = False
+            # Check for our damage (the other hit)
+            if not "defensive" in styles_other: 
+                # The damage consists of several factors. 
+                # First the difference between the attack rolls. 
+                self.damage_self += attack_other - attack_self
+                # Then the damage of our weapon. 
+                self.damage_self += other.dam
+                # And substracted the armor of the other. 
+                self.damage_self -= self.arm
+                
+                # For specific body ares, the damage increases. 
+                if "target head" in styles_other: 
+                    self.damage_self += 18
+    
+                # Clean out negative damage. If the damage is below zero, the armor caught all damage. 
+                if self.damage_self < 0: 
+                    self.damage_self = 0
+                
+                # Now actually take the damage. This returns a tuple: (new deep wounds, new critical wounds)
+                deep_wounds_self, critical_wounds_self = self.damage(tp=self.damage_self)
+
+        # If we get the same result, the attacker wins, us. 
+        else:   
+            won = True
+            if not "defensive" in styles_self: 
+                # Now check for damage (we hit)
+                # The damage consists of several factors. 
+                # First the difference between the attack rolls. 
+                self.damage_other += attack_self - attack_other
+                # Then the damage of our weapon. 
+                self.damage_other += self.dam
+                # And substracted the armor of the other. 
+                self.damage_other -= other.arm
+                
+                # For specific body ares, the damage increases. 
+                if "target head" in styles_self: 
+                    self.damage_other += 18
+            
+                # Clean out negative damage. If the damage is below zero, the armor caught all damage. 
+                if self.damage_other < 0: 
+                    self.damage_other = 0
+                
+                # Now actually do the damage. This returns a tuple: (new deep wounds, new critical wounds)
+                deep_wounds_other, critical_wounds_other = other.damage(tp=self.damage_other)
+            
+        return won, [deep_wounds_self, critical_wounds_self, self.damage_self], [deep_wounds_other, critical_wounds_other, self.damage_other]
     
 
 def ask(question): 
     @param attacker: Is me the attacker? 
     @type: Bool
     """
-    style = ask("How do you want to fight? (Usual, defensive, pull back, target a body area)")
+    styles_self = []
+    style = ask("How do you want to fight? (Usual, defensive, target head)")
+    if style.lower() in ["target head", "head", "h"]: 
+        styles_self.append("target head")
+    elif style.lower() in ["defensive", "d"]: 
+        styles_self.append("defensive")
     # TODO: Use the style. 
     if attacker: 
-        won, injuries_self, injuries_other = me.fight_round(other)
+        won, injuries_self, injuries_other = me.fight_round(other, styles_self=styles_self)
     else: 
-        won, injuries_other, injuries_self = other.fight_round(me)
+        won, injuries_other, injuries_self = other.fight_round(me, styles_other=styles_self)
         won = not won
     return won, injuries_self, injuries_other
 
             diag(other.name + " attacks you.")
             won, injuries_self, injuries_other = select_battle_style(me, other, attacker=False)
         if won:
-            diag("You hit")
-        else: diag("You got hit")
+            diag("You won.")
+        else: diag("You lost.")
         diag(battle_info(me, other))
     if me.active: 
         return True # We won