diff gamelib/missions.py @ 41:e285b1e31a08

Add can_attempt method for future flexibility
author Neil Muller <drnlmuller@gmail.com>
date Mon, 07 May 2012 13:59:50 +0200
parents efc4f90cfd63
children 373c57ab4140
line wrap: on
line diff
--- a/gamelib/missions.py	Mon May 07 00:27:59 2012 +0200
+++ b/gamelib/missions.py	Mon May 07 13:59:50 2012 +0200
@@ -38,7 +38,8 @@
     SHORT_DESCRIPTION = None
     LONG_DESCRIPTION = None
     MINIMUM_REPUTATION = None
-    available = True
+    # Flag for missions that can only be attempted once
+    completed = False
 
     def __init__(self, init_data=None):
         pass
@@ -47,10 +48,24 @@
         """Serialize the mission state for saving, etc."""
         return []
 
+    def can_attempt(self, state):
+        """Can we currently attempt the mission"""
+        if self.completed:
+            return False
+        if (self.MINIMUM_REPUTATION is not None and
+                self.MINIMUM_REPUTATION > state.reputation):
+            # Don't have the reputation completed
+            return False
+        return True
+
     def attempt(self, equipment, state):
         """Attempt the mission with the given equipment list.
         Returns a result object with the results of the mission."""
 
+        # Handle error case
+        if self.completed:
+            raise RuntimeError('Cannot attempt a completed mission')
+
         # No equipment is usually a special case.
         if not equipment:
             return self.attempt_no_equipment(state)
@@ -236,8 +251,6 @@
     MINIMUM_REPUTATION = 20
 
     def attempt(self, equipment, state):
-        if not self.available:
-            raise RuntimeError('Cannot attempt an unavailable mission')
-        self.available = False
+        self.completed = True
         return Result(SUCCESS, 0, 50, (
                 "Mount Rushmore is remarkably easy to destroy."))