예제 #1
0
 def update(self):
     self.has_run = False
     self.attributes = {}
     self.effects = {}
     self.restricted = set()
     attrs = Attribute.all().ancestor(self.player).fetch(1000)
     for attr in attrs:
         self.attributes[attr.name] = attr
         if attr not in self.attribute_types:
             self.attribute_types[attr.name] = cached_get_by_key_name(AttributeType, attr.name)
     # if you're missing default attributes, create them
     for name in ["health", "energy"]:
         if name not in self.attributes:
             self.attributes[name] = Attribute.get_or_prepare(self.player, name)
             if name not in self.attribute_types:
                 self.attribute_types[name] = cached_get_by_key_name(AttributeType, name)
예제 #2
0
 def run_effects_at(self, ref_time):
     if self.has_run:
         raise Alert("This Thespian has already completed running")
     for name, delta in self.effects.items():
         attr_type = self.attribute_types[name]
         # create new attributes if you are acted upon by them
         attr = Attribute.get_or_prepare(self.player, name, attr_type)
         if not attr.is_saved():
             attr.latest_date = ref_time
         current_value = self.fast_forward(attr, ref_time)["value"]
         new_value = current_value + delta
         if attr_type in self.restricted and (new_value < attr_type.min_value or new_value > attr_type.max_value):
             raise Alert("%s has insufficient %s" % (self.player.nickname, name))
         new_value = min(max(new_value, attr_type.min_value), attr_type.max_value)
         attr.latest_value = new_value
         attr.latest_date = ref_time
         attr.put()
     self.has_run = True