# Path: elixir_models.py
# class Message(BaseModel):
#     '''A text message from a player, for cross-zone messaging.'''
# 
#     date_sent = DateTimeField(default=datetime.datetime.now)
#     sender = CharField()
#     recipient = CharField(null=True, default=u'')
#     channel = IntegerField(null=True, default=0)
#     body = CharField(null=True, default=u'')
# 
# Path: settings.py
# MAX_DICE_AMOUNT = 100
# 
# Path: elixir_models.py
# class Object(BaseModel):
#     '''In-world objects.'''
# 
#     name = CharField()
#     resource = CharField(default="none")
#     owner = CharField(null=True)
# 
#     loc_x = FloatField(default=0)
#     loc_y = FloatField(default=0)
#     loc_z = FloatField(default=0)
# 
#     rot_x = FloatField(default=0)
#     rot_y = FloatField(default=0)
#     rot_z = FloatField(default=0)
# 
#     scale_x = FloatField(default=1)
#     scale_y = FloatField(default=1)
#     scale_z = FloatField(default=1)
# 
#     speed = FloatField(default=1)
#     vel_x = FloatField(default=0)
#     vel_y = FloatField(default=0)
#     vel_z = FloatField(default=0)
# 
#     states = JSONField(default=[])
#     physical = BooleanField(default=True)
#     last_modified = DateTimeField(default=datetime.datetime.now)
# 
#     scripts = JSONField(default=[])
# 
#     @property
#     def loc(self):
#         return (self.loc_x, self.loc_y, self.loc_z)
# 
#     @loc.setter
#     def loc(self, val):
#         self.loc_x, self.loc_y, self.loc_z = val
# 
#     def set_modified(self, date_time=None):
#         if date_time is None:
#             date_time = datetime.datetime.now()
#         self.last_modified = date_time
#         self.save()
# 
#     @staticmethod
#     def get_objects(since=None, physical=None, limit=None, player=None, scripted=None, name=None):
#         # TODO: Needs integration test.
#         obj = Object.select()
# 
#         if since is not None:
#             obj = obj.where(Object.last_modified>=since)
# 
#         if physical is not None:
#             obj = obj.where(Object.physical==physical)
# 
#         if player is not None:
#             obj = obj.where(Object.states.contains('player')).where(Object.name==player)
# 
#         if scripted is not None:
#             obj = obj.where(Object.scripts!=None) # TODO: Have this only return objects with scripts.
# 
#         if name is not None:
#             obj = obj.where(Object.name==name)
# 
#         obj = obj.order_by(Object.last_modified.desc())
# 
#         if limit is not None:
#             obj = obj.limit(limit)
# 
#         if limit == 1:
#             return obj
# 
#         return [o for o in obj]


import datetime
import re
import random
from elixir_models import Message
from settings import MAX_DICE_AMOUNT
from elixir_models import Object
        from helpers import manhattan
        pass

    def activate(self, *args, **kwargs):
        '''Do something when the scripted object is activated/clicked/etc.
        Script.tick() and Script.activate() are not usually called from
        the same instance.
        Do not rely on saved instance state. Store it in the database.
        '''
        pass

    def roll(self, dicestring):
        '''Roll dice specified by dicestring and return the value.
        Does not allow more dice than the MAX_DICE_AMOUNT setting
        to be rolled at once.'''

        rolls, num, sides, mod = parse(dicestring)
        num = int(num)
        sides = int(sides)
        mod = int(mod)
        if num > MAX_DICE_AMOUNT:
            raise UserWarning("Cannot roll more than %d dice at once." % MAX_DICE_AMOUNT)

        rolls = []
        for i in xrange(num):
            #print "Rolling dice #%d of %d: %f%% done." % (i, num, (float(i)/float(num))*100)
            rolls.append(random.randrange(1, int(sides)+1)+int(mod))
        return sum(rolls)

    def say(self, message):
        '''Write the given text to the zone message database.'''

# Path: elixir_models.py
# class Message(BaseModel):
#     '''A text message from a player, for cross-zone messaging.'''
# 
#     date_sent = DateTimeField(default=datetime.datetime.now)
#     sender = CharField()
#     recipient = CharField(null=True, default=u'')
#     channel = IntegerField(null=True, default=0)
#     body = CharField(null=True, default=u'')
# 
# Path: settings.py
# MAX_DICE_AMOUNT = 100
# 
# Path: elixir_models.py
# class Object(BaseModel):
#     '''In-world objects.'''
# 
#     name = CharField()
#     resource = CharField(default="none")
#     owner = CharField(null=True)
# 
#     loc_x = FloatField(default=0)
#     loc_y = FloatField(default=0)
#     loc_z = FloatField(default=0)
# 
#     rot_x = FloatField(default=0)
#     rot_y = FloatField(default=0)
#     rot_z = FloatField(default=0)
# 
#     scale_x = FloatField(default=1)
#     scale_y = FloatField(default=1)
#     scale_z = FloatField(default=1)
# 
#     speed = FloatField(default=1)
#     vel_x = FloatField(default=0)
#     vel_y = FloatField(default=0)
#     vel_z = FloatField(default=0)
# 
#     states = JSONField(default=[])
#     physical = BooleanField(default=True)
#     last_modified = DateTimeField(default=datetime.datetime.now)
# 
#     scripts = JSONField(default=[])
# 
#     @property
#     def loc(self):
#         return (self.loc_x, self.loc_y, self.loc_z)
# 
#     @loc.setter
#     def loc(self, val):
#         self.loc_x, self.loc_y, self.loc_z = val
# 
#     def set_modified(self, date_time=None):
#         if date_time is None:
#             date_time = datetime.datetime.now()
#         self.last_modified = date_time
#         self.save()
# 
#     @staticmethod
#     def get_objects(since=None, physical=None, limit=None, player=None, scripted=None, name=None):
#         # TODO: Needs integration test.
#         obj = Object.select()
# 
#         if since is not None:
#             obj = obj.where(Object.last_modified>=since)
# 
#         if physical is not None:
#             obj = obj.where(Object.physical==physical)
# 
#         if player is not None:
#             obj = obj.where(Object.states.contains('player')).where(Object.name==player)
# 
#         if scripted is not None:
#             obj = obj.where(Object.scripts!=None) # TODO: Have this only return objects with scripts.
# 
#         if name is not None:
#             obj = obj.where(Object.name==name)
# 
#         obj = obj.order_by(Object.last_modified.desc())
# 
#         if limit is not None:
#             obj = obj.limit(limit)
# 
#         if limit == 1:
#             return obj
# 
#         return [o for o in obj]


# Path: games/objects/basescript.py
import datetime
import re
import random
from elixir_models import Message
from settings import MAX_DICE_AMOUNT
from elixir_models import Object
        from helpers import manhattan

        pass

    def activate(self, *args, **kwargs):
        '''Do something when the scripted object is activated/clicked/etc.
        Script.tick() and Script.activate() are not usually called from
        the same instance.
        Do not rely on saved instance state. Store it in the database.
        '''
        pass

    def roll(self, dicestring):
        '''Roll dice specified by dicestring and return the value.
        Does not allow more dice than the MAX_DICE_AMOUNT setting
        to be rolled at once.'''

        rolls, num, sides, mod = parse(dicestring)
        num = int(num)
        sides = int(sides)
        mod = int(mod)
        if num > MAX_DICE_AMOUNT:
            raise UserWarning("Cannot roll more than %d dice at once." % MAX_DICE_AMOUNT)

        rolls = []
        for i in xrange(num):
            #print "Rolling dice #%d of %d: %f%% done." % (i, num, (float(i)/float(num))*100)
            rolls.append(random.randrange(1, int(sides)+1)+int(mod))
        return sum(rolls)

    def say(self, message):
        '''Write the given text to the zone message database.'''

        Message(sender=self.me_obj.name, message=message, loc_x=self.me_obj.loc_x, loc_y=self.me_obj.loc_y, loc_z=self.me_obj.loc_z, player_generated=False).save()