2018-10-26 23:42:53 +00:00
|
|
|
from django.db import models
|
|
|
|
from django.conf import settings
|
2018-11-22 02:09:30 +00:00
|
|
|
from sys import maxsize
|
2018-10-26 23:42:53 +00:00
|
|
|
|
|
|
|
# Create your models here.
|
|
|
|
|
2018-12-02 00:25:53 +00:00
|
|
|
|
2018-10-26 23:42:53 +00:00
|
|
|
class Player(models.Model):
|
2018-11-22 02:09:30 +00:00
|
|
|
name = models.CharField(max_length=30, unique=True)
|
|
|
|
mc_uuid = models.CharField(max_length=36, unique=True)
|
|
|
|
discord_uuid = models.CharField(max_length=50, unique=True)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def json(self):
|
|
|
|
return {"Name": self.name, "MC UUID": self.mc_uuid, "Discord UUID": self.discord_uuid}
|
2018-10-26 23:42:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Location(models.Model):
|
|
|
|
DIMENSIONS = (
|
|
|
|
('O', 'Overworld'),
|
|
|
|
('N', 'Nether'),
|
|
|
|
('E', 'The End')
|
|
|
|
)
|
|
|
|
|
|
|
|
name = models.CharField(max_length=128, unique=True)
|
|
|
|
|
|
|
|
x_coord = models.IntegerField()
|
|
|
|
z_coord = models.IntegerField()
|
|
|
|
dimension = models.CharField(max_length=1, choices=DIMENSIONS)
|
|
|
|
|
|
|
|
owner = models.ForeignKey(Player, related_name='owner_player', on_delete=models.CASCADE)
|
|
|
|
|
2018-11-22 02:09:30 +00:00
|
|
|
@property
|
|
|
|
def json(self):
|
|
|
|
return {"Type": str(type(self)), "Name": self.name, "x_coord": self.x_coord, "z_coord": self.z_coord,
|
|
|
|
"dimension": self.dimension, "Owner": self.owner.json}
|
|
|
|
|
2018-10-26 23:42:53 +00:00
|
|
|
|
|
|
|
class Shop(Location):
|
|
|
|
def __str__(self):
|
|
|
|
return "Shop: %s" % self.name
|
|
|
|
|
|
|
|
|
|
|
|
class Base(Location):
|
|
|
|
def __str__(self):
|
|
|
|
return "Base: %s" % self.name
|
|
|
|
|
|
|
|
|
|
|
|
class ItemListing(models.Model):
|
|
|
|
item_name = models.CharField(max_length=128)
|
|
|
|
price = models.IntegerField()
|
|
|
|
amount = models.IntegerField()
|
|
|
|
|
|
|
|
shop = models.ForeignKey(Shop, related_name="shop_selling", on_delete=models.CASCADE)
|
|
|
|
|
2018-11-22 02:09:30 +00:00
|
|
|
@property
|
|
|
|
def normalized_price(self):
|
|
|
|
if self.amount == 0:
|
|
|
|
return maxsize
|
|
|
|
else:
|
|
|
|
return self.price/self.amount
|
|
|
|
|
2018-10-26 23:42:53 +00:00
|
|
|
def __str__(self):
|
|
|
|
return "Item: %d %s for %d" % (self.amount, self.item_name, self.amount)
|
|
|
|
|
|
|
|
|
|
|
|
class Tunnel(models.Model):
|
|
|
|
TUNNEL_NAMES = (
|
|
|
|
('N', getattr(settings, 'NORTH', '')),
|
|
|
|
('E', getattr(settings, 'EAST', '')),
|
|
|
|
('S', getattr(settings, 'SOUTH', '')),
|
|
|
|
('W', getattr(settings, 'WEST', ''))
|
|
|
|
)
|
|
|
|
|
|
|
|
tunnel_number = models.IntegerField()
|
|
|
|
tunnel_direction = models.CharField(max_length=1, choices=TUNNEL_NAMES)
|
|
|
|
|
|
|
|
location = models.ForeignKey(Location, related_name="tunnel_location", on_delete=models.CASCADE)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return "Tunnel: %s %d" % (self.tunnel_direction, self.tunnel_number)
|