Commits

Anonymous committed 959446c

Now the experience can also be increased by simply saying char.exp = new_value. If the new value is lower than the current value, nothing happens, but it gives the return value False.

Comments (0)

Files changed (1)

             return self.calculate_might(second_run=True)
         else: 
             return might
+    
+    def set_experience(exp): 
+        """Set the experience of the char. Exp can't be decreased this way. 
         
+        This is a thin wrapper around upgrade()
+        
+        It is used to be able to handle exp as property, so people can just say: 
+        char.exp = 10
+        
+        instead of 
+        
+        char.upgrade(10-char.exp)
+        
+        @param exp: The new experience value.
+        @type exp: float or int."""
+        if exp > self.exp: 
+            self.upgrade(exp - self.exp)
+            return self.exp
+        else: 
+            return False
     
-    # Experience as property. 
-    exp = property(fget=calculate_might)
+    # The experience of the char as property, so it is always up to date. 
+    exp = property(fget=calculate_might, fset=set_experience)
     
     
     def upgrade(self,expadd,object=('weighted',[])):