Commits

Anonymous committed 72eb0da

Added competition in skills.

  • Participants
  • Parent commits bd8814a

Comments (0)

Files changed (3)

File ministory.py

 char2 = Char(source="tag:1w6.org,2008:Nasfar")
 char1 = Char(source="tag:1w6.org,2008:" + name)
 
+# story(char1.compete_skill(char2, "cooking"))
+
 story("...Press enter to read on...")
 
 story('''
 I don't know about heroes, they come and go, but I persist, and I follow them when they move across the lands. 
 
 Don't hope for the heroes. They will desert you when you need them most, because heroes live to die. 
-
 But I live to live, so don't hope for my help, either. 
 
 Please don't hope for my help.
 Ideas: 
     - Lazy loading modules, to be able to print stuff at once without having to print before the imports.
 
+The code for the TextRPG can be found at U{http://dreehg.org/ArneBab/textrpg}
+
 """
 
 # Structure for the metadata inspired by Fufezan: 
                 diag(self.name + ': ' + i, localize=False)
             # If the string is empty, just add a blank line without the characters name. 
             else: diag("...", localize=False)
-            
-    def check_skill(self, skill_name, mods=[], MW=9): 
-        """Test the skill of the char against a target number.
         
-        Wounds are taken into account as modifiers automatically. """
-        if skill_name in self.skills: 
-            value = self.skills[skill_name][_("Zahlenwert")]
-        else: 
-            # If the char doesn't have the skill, we use the default. ouch! 
-            # TODO: Query a list of related skills (can be used with a mod of -3). 
-            value = 3
-        return super(Char, self).check(value, mods=mods, MW=MW)
+    def compete_skill(self, other, skill_name, self_mods=[], other_mods=[]): 
+        """Compete with the other char in the specified skill. 
+        
+        @return If we won and by how much: (won, diff). Diff is always >=0. 
+        """
+        my_result = self.roll(self.get_effective_skill_value(skill_name, related_skills=[], related_attributes=[]), mods=self_mods)
+        other_result = other.roll(other.get_effective_skill_value(skill_name, related_skills=[], related_attributes=[]), mods=other_mods)
+        return my_result > other_result, abs(my_result - other_result)
     
     def fight_round(self, other, *args, **kwds): 
         """Fight for one round."""

File textrpg_1d6/char.py

 
     
     def check_skill(self, skill_name, MW=9, related_skills=[], related_attributes=[], mods=[]):
-        """Do a skill check against a target number."""
+        """Do a skill check against a target number.
+        
+        Wounds are taken into account as modifiers automatically. 
+        """
         # If the char has skills and the skill exists, do a check on it. 
-        if self.amov.fertigkeiten != " " and skill_name in self.amov.fertigkeiten.keys(): 
-            return self.check(self.amov.fertigkeiten[skill_name][_("Zahlenwert")], mods=mods, MW=MW)
+        return self.check(self.get_effective_skill_value(skill_name, related_skills=[], related_attributes=[]), mods=mods, MW=MW)
+
+
+    def get_effective_skill_value(self, skill_name, related_skills=[], related_attributes=[]): 
+        """Get the effective value for tests. 
+        
+        This doesn't take wounds into account, as they are already taken account in the method self.check()."""
+        if skill_name in self.skills.keys(): 
+            return self.skills[skill_name][_("Zahlenwert")]
         # If the skill doesn't exist in Fertigkeiten, see if we can do the check on some related skill, but with a malus of 3. 
         # TODO: Implement Jobs and background. 
-        elif self.amov.fertigkeiten != " ": 
+        else: 
             for i in related_skills: 
-                if i in self.amov.fertigkeiten.keys(): 
-                    return self.check(self.amov.fertigkeiten[i][_("Zahlenwert")] - 3, mods=mods, MW=MW)
+                if i in self.skills.keys(): 
+                    return self.skills[i][_("Zahlenwert")] - 3
         # If the char has no skills, see if we can check against a related attribute, but with a malus of 9. 
-        if self.amov.eigenschaften != " ": 
-            for i in related_attributes: 
-                if i in self.amov.eigenschaften.keys() and self.amov.eigenschaften[i][_("Zahlenwert")] >= 12: 
-                    return self.check(self.amov.eigenschaften[i][_("Zahlenwert")] - 9, mods=mods, MW=MW)
-            # If none of the related Attributes fits, just use the default of 12. 
-            return self.check(12 - 9, mods=mods, MW=MW)
-        # If the char has no attributes or skills, just use the default attribute of 12. 
-        else: 
-            return self.check(12 - 9, mods=mods, MW=MW)
-        # TODO: Move the code for finding the right value into another function like get_effective_skill_value() or so. 
+        for i in related_attributes: 
+            if i in self.attributes.keys() and self.attributes[i][_("Zahlenwert")] >= 12: 
+                return self.attributes[i][_("Zahlenwert")] - 9
+        # If the char has no fitting attributes or skills, just use the default attribute of 12. 
+        return 12 - 9
+        
     
     
     def do_attack(self,  mods=[]):