2018-05-26 15:07:17 +00:00
|
|
|
from sqlalchemy import Column, Integer, String, ForeignKey, Enum
|
|
|
|
import enum
|
|
|
|
from sqlalchemy.ext.declarative import declarative_base
|
2018-06-02 16:11:31 +00:00
|
|
|
from BotErrors import *
|
2018-07-08 19:19:40 +00:00
|
|
|
from sqlalchemy import create_engine, exists, literal
|
2018-06-02 21:41:27 +00:00
|
|
|
from sqlalchemy.orm import sessionmaker, relationship
|
2018-07-15 15:56:56 +00:00
|
|
|
from sqlalchemy.exc import IntegrityError
|
2018-06-02 16:11:31 +00:00
|
|
|
import sqlalchemy
|
2018-06-03 02:42:31 +00:00
|
|
|
from MinecraftAccountInfoGrabber import *
|
2018-07-15 18:27:11 +00:00
|
|
|
from difflib import SequenceMatcher
|
2018-05-26 15:07:17 +00:00
|
|
|
|
|
|
|
SQL_Base = declarative_base()
|
|
|
|
|
2018-07-15 18:27:11 +00:00
|
|
|
def check_similarity(a, b):
|
|
|
|
ratio = SequenceMatcher(None, a, b).ratio()
|
|
|
|
|
|
|
|
if (ratio > 0.6) or (a[0] == b[0]):
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return False
|
2018-05-26 15:07:17 +00:00
|
|
|
|
2018-07-08 19:19:40 +00:00
|
|
|
class DatabaseInterface:
|
2018-06-02 16:11:31 +00:00
|
|
|
|
2018-07-08 19:19:40 +00:00
|
|
|
def __init__(self, db_engine_arg):
|
|
|
|
self.database = GeoffreyDatabase(db_engine_arg)
|
2018-06-02 16:11:31 +00:00
|
|
|
|
2018-07-15 18:27:11 +00:00
|
|
|
def add_location(self, owner, name, x_pos, y_pos, z_pos, tunnel=None, dimension=None):
|
|
|
|
location = Location(name, x_pos, y_pos, z_pos, owner, tunnel, dimension)
|
2018-07-08 19:19:40 +00:00
|
|
|
self.database.add_object(location)
|
2018-06-30 15:07:56 +00:00
|
|
|
return location
|
2018-06-23 16:08:40 +00:00
|
|
|
|
2018-07-15 18:27:11 +00:00
|
|
|
def add_shop(self, owner, name, x_pos, y_pos, z_pos, tunnel=None, dimension=None):
|
|
|
|
shop = Shop(name, x_pos, y_pos, z_pos, owner, tunnel, dimension)
|
2018-07-08 19:19:40 +00:00
|
|
|
self.database.add_object(shop)
|
2018-06-23 17:33:02 +00:00
|
|
|
return shop
|
|
|
|
|
2018-07-08 19:19:40 +00:00
|
|
|
def add_item(self, owner, shop_name, item_name, price, amount):
|
2018-06-30 15:07:56 +00:00
|
|
|
try:
|
2018-07-08 19:19:40 +00:00
|
|
|
shop = self.find_shop_by_name_and_owner(owner, shop_name)
|
2018-06-23 20:27:00 +00:00
|
|
|
|
2018-07-04 00:05:35 +00:00
|
|
|
item = ItemListing(item_name, price, amount, shop[0])
|
2018-07-08 19:19:40 +00:00
|
|
|
self.database.add_object(item)
|
2018-06-30 15:07:56 +00:00
|
|
|
except IndexError:
|
|
|
|
raise LocationLookUpError
|
2018-06-23 20:27:00 +00:00
|
|
|
|
|
|
|
return item
|
|
|
|
|
2018-07-08 19:19:40 +00:00
|
|
|
def add_player(self, player_name, discord_id):
|
2018-06-23 16:08:40 +00:00
|
|
|
|
2018-06-30 15:07:56 +00:00
|
|
|
try:
|
|
|
|
player = self.find_player(player_name)
|
|
|
|
except PlayerNotFound:
|
|
|
|
try:
|
|
|
|
uuid = grab_UUID(player_name)
|
2018-07-08 19:19:40 +00:00
|
|
|
player = self.find_player_by_mc_uuid(uuid)
|
2018-06-30 15:07:56 +00:00
|
|
|
except PlayerNotFound:
|
2018-06-23 16:08:40 +00:00
|
|
|
player = Player(player_name)
|
2018-07-08 19:19:40 +00:00
|
|
|
self.database.add_object(player, discord_id)
|
2018-06-30 15:07:56 +00:00
|
|
|
finally:
|
|
|
|
player.name = player_name
|
2018-06-23 16:08:40 +00:00
|
|
|
|
2018-07-08 19:19:40 +00:00
|
|
|
self.database.session.commit()
|
2018-06-23 16:08:40 +00:00
|
|
|
return player
|
|
|
|
|
2018-07-01 15:10:10 +00:00
|
|
|
def find_location_by_name(self, name):
|
2018-07-04 00:05:35 +00:00
|
|
|
expr = Location.name.ilike('%{}%'.format(name))
|
2018-07-08 19:19:40 +00:00
|
|
|
return self.database.query_by_filter(Location, expr)
|
2018-07-01 15:10:10 +00:00
|
|
|
|
|
|
|
def find_shop_by_name(self, name):
|
2018-07-04 00:05:35 +00:00
|
|
|
expr = Location.name.ilike('%{}%'.format(name))
|
2018-07-08 19:19:40 +00:00
|
|
|
return self.database.query_by_filter(Shop, expr)
|
2018-07-01 15:10:10 +00:00
|
|
|
|
2018-07-08 19:19:40 +00:00
|
|
|
def find_location_by_owner(self, owner):
|
|
|
|
expr = Location.owner == owner
|
|
|
|
return self.database.query_by_filter(Location, expr)
|
2018-06-23 16:08:40 +00:00
|
|
|
|
2018-07-08 19:19:40 +00:00
|
|
|
def find_location_by_owner_name(self, owner_name):
|
|
|
|
owner = self.find_player(owner_name)
|
|
|
|
return self.find_location_by_owner(owner)
|
2018-07-01 15:10:10 +00:00
|
|
|
|
2018-07-08 19:19:40 +00:00
|
|
|
def find_shop_by_name_and_owner(self, owner, name):
|
|
|
|
expr = (Shop.owner == owner) & (Shop.name.ilike(name))
|
|
|
|
return self.database.query_by_filter(Shop, expr)
|
|
|
|
|
|
|
|
def find_location_by_name_and_owner(self, owner, name):
|
|
|
|
expr = (Location.owner == owner) & (Location.name.ilike(name))
|
|
|
|
return self.database.query_by_filter(Location, expr)
|
2018-06-23 20:27:00 +00:00
|
|
|
|
2018-07-15 15:56:56 +00:00
|
|
|
def find_location_around(self, x_pos, z_pos, radius, dimension):
|
2018-07-15 18:27:11 +00:00
|
|
|
dimension_obj = Dimension.str_to_dimension(dimension)
|
2018-07-08 19:19:40 +00:00
|
|
|
expr = (Location.x < x_pos + radius + 1) & (Location.x > x_pos - radius - 1) & (Location.z < z_pos + radius + 1) \
|
2018-07-15 18:27:11 +00:00
|
|
|
& (Location.z > z_pos - radius - 1) & (Location.dimension == dimension_obj)
|
2018-06-23 16:08:40 +00:00
|
|
|
|
2018-07-08 19:19:40 +00:00
|
|
|
return self.database.query_by_filter(Location, expr)
|
2018-06-23 16:08:40 +00:00
|
|
|
|
2018-06-23 20:27:00 +00:00
|
|
|
def find_item(self, item_name):
|
2018-07-08 19:19:40 +00:00
|
|
|
expr = ItemListing.name.ilike('%{}%'.format(item_name))
|
|
|
|
return self.database.query_by_filter(ItemListing, expr)
|
2018-06-23 20:27:00 +00:00
|
|
|
|
|
|
|
def find_shop_selling_item(self, item_name):
|
|
|
|
listings = self.find_item(item_name)
|
|
|
|
|
|
|
|
shops = []
|
|
|
|
for listing in listings:
|
|
|
|
shops.append(listing.shop)
|
2018-07-04 00:05:35 +00:00
|
|
|
shops.append(listing.__str__())
|
2018-06-23 20:27:00 +00:00
|
|
|
|
|
|
|
return shops
|
|
|
|
|
2018-06-30 15:07:56 +00:00
|
|
|
def find_player(self, player_name):
|
2018-07-08 19:19:40 +00:00
|
|
|
expr = Player.name.ilike(player_name)
|
2018-06-30 15:07:56 +00:00
|
|
|
|
|
|
|
try:
|
2018-07-08 19:19:40 +00:00
|
|
|
player = self.database.query_by_filter(Player, expr)[0]
|
2018-06-30 15:07:56 +00:00
|
|
|
except IndexError:
|
|
|
|
raise PlayerNotFound
|
|
|
|
|
|
|
|
return player
|
|
|
|
|
2018-07-08 19:19:40 +00:00
|
|
|
def find_player_by_mc_uuid(self, uuid):
|
2018-06-30 15:07:56 +00:00
|
|
|
expr = Player.id == uuid
|
|
|
|
|
|
|
|
try:
|
2018-07-08 19:19:40 +00:00
|
|
|
player = self.database.query_by_filter(Player, expr)[0]
|
|
|
|
except IndexError:
|
|
|
|
raise PlayerNotFound
|
|
|
|
|
|
|
|
return player
|
|
|
|
|
|
|
|
def find_player_by_discord_uuid(self, uuid):
|
|
|
|
expr = Player.discord_uuid == uuid
|
|
|
|
|
|
|
|
try:
|
|
|
|
player = self.database.query_by_filter(Player, expr)[0]
|
2018-06-30 15:07:56 +00:00
|
|
|
except IndexError:
|
|
|
|
raise PlayerNotFound
|
|
|
|
|
|
|
|
return player
|
|
|
|
|
2018-07-01 15:10:10 +00:00
|
|
|
def get_shop_inventory(self, shop):
|
|
|
|
expr = ItemListing.shop == shop
|
|
|
|
|
2018-07-08 19:19:40 +00:00
|
|
|
return self.database.query_by_filter(ItemListing, expr)
|
|
|
|
|
|
|
|
def delete_location(self, owner, name):
|
|
|
|
expr = (Location.owner == owner) & (Location.name == name)
|
|
|
|
|
|
|
|
self.database.delete_entry(Location, expr)
|
|
|
|
|
|
|
|
|
|
|
|
class DiscordDatabaseInterface(DatabaseInterface):
|
2018-07-15 18:27:11 +00:00
|
|
|
def add_location(self, owner_uuid, name, x_pos, y_pos, z_pos, tunnel=None, dimension=None):
|
2018-07-08 19:19:40 +00:00
|
|
|
owner = DatabaseInterface.find_player_by_discord_uuid(self, owner_uuid)
|
2018-07-15 18:27:11 +00:00
|
|
|
return DatabaseInterface.add_location(self, owner, name, x_pos, y_pos, z_pos, tunnel, dimension)
|
2018-07-08 19:19:40 +00:00
|
|
|
|
2018-07-15 18:27:11 +00:00
|
|
|
def add_shop(self, owner_uuid, name, x_pos, y_pos, z_pos, tunnel=None, dimension=None):
|
2018-07-08 19:19:40 +00:00
|
|
|
owner = DatabaseInterface.find_player_by_discord_uuid(self, owner_uuid)
|
2018-07-15 18:27:11 +00:00
|
|
|
return DatabaseInterface.add_shop(self, owner, name, x_pos, y_pos, z_pos, tunnel, dimension)
|
2018-07-08 19:19:40 +00:00
|
|
|
|
|
|
|
def add_item(self, owner_uuid, shop_name, item_name, price, amount):
|
|
|
|
owner = DatabaseInterface.find_player_by_discord_uuid(self, owner_uuid)
|
|
|
|
return DatabaseInterface.add_item(self, owner, shop_name, item_name, price, amount)
|
|
|
|
|
|
|
|
def add_player(self, player_name, discord_id):
|
|
|
|
try:
|
|
|
|
player = self.find_player(player_name)
|
|
|
|
except PlayerNotFound:
|
|
|
|
try:
|
|
|
|
uuid = grab_UUID(player_name)
|
|
|
|
player = self.find_player_by_mc_uuid(uuid)
|
|
|
|
except PlayerNotFound:
|
|
|
|
player = Player(player_name, discord_id)
|
|
|
|
self.database.add_object(player)
|
|
|
|
finally:
|
|
|
|
player.name = player_name
|
|
|
|
|
|
|
|
self.database.session.commit()
|
|
|
|
return player
|
|
|
|
|
|
|
|
def find_location_by_owner_uuid(self, owner_uuid):
|
|
|
|
owner = DatabaseInterface.find_player_by_discord_uuid(self, owner_uuid)
|
|
|
|
return DatabaseInterface.find_location_by_owner(self, owner)
|
|
|
|
|
|
|
|
def find_shop_by_name_and_owner_uuid(self, owner_uuid, name):
|
|
|
|
owner = DatabaseInterface.find_player_by_discord_uuid(self, owner_uuid)
|
|
|
|
return DatabaseInterface.find_shop_by_name_and_owner(self, owner, name)
|
|
|
|
|
|
|
|
def find_location_by_name_and_owner_uuid(self, owner_uuid, name):
|
|
|
|
owner = DatabaseInterface.find_player_by_discord_uuid(self, owner_uuid)
|
|
|
|
return DatabaseInterface.find_location_by_name_and_owner(self, owner, name)
|
|
|
|
|
|
|
|
def delete_location(self, owner_uuid, name):
|
|
|
|
owner = DatabaseInterface.find_player_by_discord_uuid(self, owner_uuid)
|
|
|
|
return DatabaseInterface.delete_location(self, owner, name)
|
|
|
|
|
|
|
|
|
|
|
|
class GeoffreyDatabase:
|
|
|
|
|
|
|
|
def __init__(self, engine_arg):
|
|
|
|
self.engine = create_engine(engine_arg, echo=True)
|
|
|
|
Session = sessionmaker(bind=self.engine)
|
|
|
|
self.session = Session()
|
|
|
|
SQL_Base.metadata.create_all(self.engine)
|
|
|
|
|
|
|
|
def add_object(self, obj):
|
2018-07-15 15:56:56 +00:00
|
|
|
try:
|
|
|
|
ret = not self.session.query(exists().where(type(obj).id == obj.id))
|
|
|
|
if not ret:
|
|
|
|
self.session.add(obj)
|
|
|
|
self.session.commit()
|
|
|
|
except IntegrityError:
|
|
|
|
raise LocationNameNotUniqueError
|
2018-07-01 15:10:10 +00:00
|
|
|
|
2018-06-02 16:11:31 +00:00
|
|
|
def query_by_filter(self, obj_type, * args):
|
|
|
|
filter_value = self.combine_filter(args)
|
|
|
|
return self.session.query(obj_type).filter(filter_value).all()
|
|
|
|
|
|
|
|
def delete_entry(self, obj_type, * args):
|
|
|
|
filter_value = self.combine_filter(args)
|
|
|
|
entry = self.session.query(obj_type).filter(filter_value)
|
|
|
|
|
|
|
|
if entry.first() is not None:
|
|
|
|
entry.delete()
|
|
|
|
else:
|
|
|
|
raise DeleteEntryError
|
|
|
|
|
2018-06-23 15:17:51 +00:00
|
|
|
def print_database(self, obj_type):
|
|
|
|
obj_list = self.session.query(obj_type).all()
|
|
|
|
|
|
|
|
s = ''
|
|
|
|
|
|
|
|
for obj in obj_list:
|
|
|
|
s = s + '\n' + obj.id
|
|
|
|
return s
|
|
|
|
|
2018-06-02 16:11:31 +00:00
|
|
|
def combine_filter(self, filter_value):
|
|
|
|
return sqlalchemy.sql.expression.and_(filter_value[0])
|
|
|
|
|
2018-06-02 17:40:55 +00:00
|
|
|
|
2018-05-26 15:07:17 +00:00
|
|
|
class TunnelDirection(enum.Enum):
|
|
|
|
North = 'green'
|
|
|
|
East = 'blue'
|
|
|
|
South = 'red'
|
|
|
|
West = 'yellow'
|
|
|
|
|
|
|
|
def str_to_tunnel_dir(arg):
|
|
|
|
arg = arg.lower()
|
2018-07-15 18:27:11 +00:00
|
|
|
|
|
|
|
if check_similarity(TunnelDirection.North.value, arg):
|
2018-05-26 15:07:17 +00:00
|
|
|
return TunnelDirection.North
|
2018-07-15 18:27:11 +00:00
|
|
|
elif check_similarity(TunnelDirection.East.value, arg):
|
2018-05-26 15:07:17 +00:00
|
|
|
return TunnelDirection.East
|
2018-07-15 18:27:11 +00:00
|
|
|
elif check_similarity(TunnelDirection.South.value, arg):
|
2018-05-26 15:07:17 +00:00
|
|
|
return TunnelDirection.South
|
2018-07-15 18:27:11 +00:00
|
|
|
elif check_similarity(TunnelDirection.West.value, arg):
|
2018-05-26 15:07:17 +00:00
|
|
|
return TunnelDirection.West
|
|
|
|
else:
|
|
|
|
raise ValueError
|
|
|
|
|
|
|
|
|
2018-07-04 00:05:35 +00:00
|
|
|
class TunnelSide(enum.Enum):
|
|
|
|
right = 'right'
|
|
|
|
left = 'left'
|
|
|
|
|
|
|
|
def str_to_tunnel_side(arg):
|
|
|
|
arg = arg.lower()
|
2018-07-15 18:27:11 +00:00
|
|
|
if check_similarity(TunnelSide.right.value, arg):
|
2018-07-04 00:05:35 +00:00
|
|
|
return TunnelSide.right
|
2018-07-15 18:27:11 +00:00
|
|
|
elif check_similarity(TunnelSide.left.value, arg):
|
2018-07-04 00:05:35 +00:00
|
|
|
return TunnelSide.left
|
|
|
|
else:
|
|
|
|
raise ValueError
|
|
|
|
|
|
|
|
|
|
|
|
class Dimension(enum.Enum):
|
|
|
|
overworld = 'overworld'
|
|
|
|
nether = 'nether'
|
|
|
|
end = 'end'
|
|
|
|
|
|
|
|
def str_to_dimension(arg):
|
|
|
|
arg = arg.lower()
|
2018-07-15 18:27:11 +00:00
|
|
|
if check_similarity(Dimension.overworld.value, arg):
|
2018-07-04 00:05:35 +00:00
|
|
|
return Dimension.overworld
|
2018-07-15 18:27:11 +00:00
|
|
|
elif check_similarity(Dimension.nether.value, arg):
|
2018-07-04 00:05:35 +00:00
|
|
|
return Dimension.nether
|
2018-07-15 18:27:11 +00:00
|
|
|
elif check_similarity(Dimension.end.value, arg):
|
2018-07-04 00:05:35 +00:00
|
|
|
return Dimension.end
|
|
|
|
else:
|
|
|
|
raise ValueError
|
|
|
|
|
|
|
|
|
2018-05-26 15:07:17 +00:00
|
|
|
class Player(SQL_Base):
|
|
|
|
__tablename__ = 'Players'
|
2018-07-08 19:19:40 +00:00
|
|
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
|
|
|
mc_uuid = Column(String)
|
|
|
|
discord_uuid = Column(String)
|
2018-06-23 15:17:51 +00:00
|
|
|
name = Column(String)
|
|
|
|
locations = relationship("Location", back_populates="owner", lazy='dynamic')
|
2018-05-26 15:07:17 +00:00
|
|
|
|
2018-07-08 19:19:40 +00:00
|
|
|
def __init__(self, name, discord_id=None):
|
|
|
|
self.mc_uuid = grab_UUID(name)
|
|
|
|
self.discord_uuid = discord_id
|
2018-06-23 15:17:51 +00:00
|
|
|
self.name = name
|
2018-05-26 15:07:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Location(SQL_Base):
|
|
|
|
__tablename__ = 'Locations'
|
|
|
|
|
|
|
|
id = Column(Integer, primary_key=True)
|
2018-07-01 15:10:10 +00:00
|
|
|
name = Column(String, unique=True)
|
2018-05-26 15:07:17 +00:00
|
|
|
x = Column(Integer)
|
|
|
|
y = Column(Integer)
|
|
|
|
z = Column(Integer)
|
2018-07-15 18:27:11 +00:00
|
|
|
tunnel_number = Column(Integer)
|
|
|
|
tunnel_direction = Column(Enum(TunnelDirection))
|
2018-07-04 00:05:35 +00:00
|
|
|
tunnel_side = Column(Enum(TunnelSide))
|
|
|
|
dimension = Column(Enum(Dimension))
|
|
|
|
|
2018-06-23 15:17:51 +00:00
|
|
|
owner_id = Column(Integer, ForeignKey('Players.id'))
|
|
|
|
owner = relationship("Player", back_populates="locations")
|
2018-06-23 17:33:02 +00:00
|
|
|
type = Column(String)
|
|
|
|
|
2018-06-02 21:41:27 +00:00
|
|
|
__mapper_args__ = {
|
|
|
|
'polymorphic_on': type,
|
|
|
|
'polymorphic_identity': 'Location'
|
|
|
|
}
|
2018-05-26 15:07:17 +00:00
|
|
|
|
2018-07-15 18:27:11 +00:00
|
|
|
def __init__(self, name, x, y, z, owner, tunnel, dimension):
|
2018-05-26 15:07:17 +00:00
|
|
|
try:
|
|
|
|
self.name = name
|
|
|
|
self.x = x
|
|
|
|
self.y = y
|
|
|
|
self.z = z
|
2018-06-23 15:17:51 +00:00
|
|
|
self.owner = owner
|
2018-05-26 15:07:17 +00:00
|
|
|
|
2018-07-15 18:27:11 +00:00
|
|
|
if tunnel is not None:
|
|
|
|
tunnel_info_list = tunnel.split(',')
|
|
|
|
self.tunnel_direction = TunnelDirection.str_to_tunnel_dir(tunnel_info_list[0])
|
|
|
|
self.tunnel_number = int(tunnel_info_list[1])
|
|
|
|
self.tunnel_side = TunnelSide.str_to_tunnel_side(tunnel_info_list[2])
|
2018-07-08 19:19:40 +00:00
|
|
|
|
2018-07-15 18:27:11 +00:00
|
|
|
if self.dimension is not None:
|
|
|
|
self.dimension = self.dimension = Dimension.str_to_dimension(dimension)
|
|
|
|
else:
|
2018-07-08 19:19:40 +00:00
|
|
|
self.dimension = Dimension.overworld
|
2018-05-26 15:07:17 +00:00
|
|
|
|
|
|
|
except (ValueError, IndexError):
|
|
|
|
raise LocationInitError
|
|
|
|
|
|
|
|
def pos_to_str(self):
|
2018-07-04 00:05:35 +00:00
|
|
|
return '(x= {}, y= {}, z= {}) in the {}'.format(self.x, self.y, self.z, self.dimension.value.title())
|
2018-05-26 15:07:17 +00:00
|
|
|
|
|
|
|
def nether_tunnel_addr_to_str(self):
|
2018-07-15 18:27:11 +00:00
|
|
|
return '{} {} {}'.format(self.tunnel_direction.value.title(), self.tunnel_number, self.tunnel_side.value.title())
|
2018-05-26 15:07:17 +00:00
|
|
|
|
|
|
|
def __str__(self):
|
2018-07-15 18:27:11 +00:00
|
|
|
if self.tunnel_direction is not None:
|
2018-05-26 15:07:17 +00:00
|
|
|
return "Name: {}, Position: {}, Tunnel: {}".format(self.name, self.pos_to_str(),
|
|
|
|
self.nether_tunnel_addr_to_str())
|
|
|
|
else:
|
|
|
|
return "Name: {}, Position: {}".format(self.name, self.pos_to_str())
|
2018-06-23 17:33:02 +00:00
|
|
|
|
2018-06-02 21:41:27 +00:00
|
|
|
|
|
|
|
class Shop(Location):
|
|
|
|
__tablename__ = 'Shops'
|
2018-06-23 17:33:02 +00:00
|
|
|
shop_id = Column(Integer, ForeignKey('Locations.id'), primary_key=True)
|
2018-06-02 21:41:27 +00:00
|
|
|
name = Column(String)
|
2018-06-23 20:27:00 +00:00
|
|
|
inventory = relationship('ItemListing', back_populates='shop', lazy='dynamic')
|
2018-06-02 21:41:27 +00:00
|
|
|
__mapper_args__ = {
|
2018-06-23 17:33:02 +00:00
|
|
|
'polymorphic_identity': 'Shop',
|
2018-06-02 21:41:27 +00:00
|
|
|
}
|
|
|
|
|
2018-07-15 18:27:11 +00:00
|
|
|
def __init__(self, name, x, y, z, owner, tunnel, dimension):
|
|
|
|
Location.__init__(self, name, x, y, z, owner, tunnel, dimension)
|
2018-06-02 21:41:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ItemListing(SQL_Base):
|
|
|
|
__tablename__ = 'Items'
|
|
|
|
|
2018-06-23 20:27:00 +00:00
|
|
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
2018-06-02 21:41:27 +00:00
|
|
|
name = Column(String)
|
|
|
|
price = Column(Integer)
|
2018-07-04 00:05:35 +00:00
|
|
|
amount = Column(Integer)
|
2018-06-02 21:41:27 +00:00
|
|
|
|
2018-06-23 20:27:00 +00:00
|
|
|
shop_id = Column(Integer, ForeignKey('Shops.shop_id'))
|
|
|
|
shop = relationship("Shop", back_populates="inventory")
|
2018-06-02 21:41:27 +00:00
|
|
|
|
2018-07-04 00:05:35 +00:00
|
|
|
def __init__(self, name, price, amount, shop):
|
2018-06-02 21:41:27 +00:00
|
|
|
self.name = name
|
|
|
|
self.price = price
|
2018-07-04 00:05:35 +00:00
|
|
|
self.amount = amount
|
2018-06-23 20:27:00 +00:00
|
|
|
self.shop = shop
|
2018-06-02 21:41:27 +00:00
|
|
|
|
|
|
|
def __str__(self):
|
2018-07-04 00:05:35 +00:00
|
|
|
return "Item: {}, Price: {} for {}D".format(self.name, self.amount, self.price)
|