Anonymous avatar Anonymous committed 1276edd

Now experience is spent incrementally.

Comments (0)

Files changed (2)

 char2 = Char(source="tag:1w6.org,2008:Nasfar")
 char1 = Char(source="tag:1w6.org,2008:" + name)
 
-# story(char1.compete_skill(char2, "cooking"))
+# won, diff = char1.compete_skill(char2, "cooking")
+# won: If we won
+# Diff: By how much we won or lost (always positive). 
 
 story("...Press enter to read on...")
 
     else: 
         return False # We lost
 
-def give_exp(char, amount=9): 
-    """Wrapper for scripts."""
-    return get_experience(char, amount=amount)
+def give_exp(char, amount=0): 
+    """Give experience to only one char."""
+    return get_experience([char], amount=amount)
 
-def get_experience(char, amount=0):
-    """Show the experience the char gets and what the char does with it."""
-    diag("\n***experience of " + char.name + "***")
-    diag(char.name + " got " + str(amount) + " experience.")
+def get_experience(chars, amount=0):
+    """Show the experience the chars get and what they do with it."""
+    # Dialog header
+    if len(chars) == 1: 
+        diag("\n***experience of " + chars[0].name + "***")
+        diag(chars[0].name + " got " + str(amount) + " experience.")
+    else: 
+        diag("\n***experience***")
+        diag("The characters got " + str(amount) + " experience.")
+    
+    # Info text for each char. 
+    for i in chars: 
+        # Upgrade in single point steps, so the experience gets spread a bit. 
+        # if it's less than two points, use it completely. 
+        if amount <= 2: 
+            text = upgrade_info(i, amount)
+            if text: 
+                diag(text)
+        # If it's more than one point, spread all but one in single points 
+        # and at last improve by 1 plus the remaining fraction. 
+        # With this, no value gets less than one point/Strich 
+        # (no use in spreading points which can only give an increase by pure chance). 
+        else: 
+            for j in range(int(amount) -1): 
+                text = upgrade_info(i, 1)
+                if text: 
+                    diag(text)
+            text = upgrade_info(i, amount - int(amount) + 1)
+            if text: 
+                diag(text)
+        
+    # Dialog footer. 
+    diag("***/experience***\n")
+
+def upgrade_info(char, amount): 
+    """Return the effects of improving teh char by the given amount of points/Strichen."""
     upgrade = char.upgrade(amount)
     item_name = " ".join(upgrade[0].items()[0][0])
     old_value = upgrade[0].items()[0][1]["Zahlenwert"] 
     new_value = upgrade[1].items()[0][1]["Zahlenwert"]
     if old_value < new_value:
-        diag(char.name + " raised " + item_name + " from " + str(old_value) + " to " + str(new_value))
-    diag("***/experience***\n")
-
+        return char.name + " raised " + item_name + " from " + str(old_value) + " to " + str(new_value)
+    else: 
+        return False
 
 if __name__ == "__main__": 
     print "...Creating main character..."
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.