mirror of
https://github.com/solero/houdini.git
synced 2024-11-22 05:27:23 +00:00
Use vanilla_inventory
and legacy_inventory
columns to determine default inventories
This commit is contained in:
parent
874c4d6a68
commit
2d9b73e54b
@ -1,6 +1,7 @@
|
||||
from houdini.data import AbstractDataCollection, db
|
||||
from functools import cached_property
|
||||
|
||||
|
||||
class Flooring(db.Model):
|
||||
__tablename__ = 'flooring'
|
||||
|
||||
@ -29,7 +30,6 @@ class Furniture(db.Model):
|
||||
innocent = db.Column(db.Boolean, nullable=False, server_default=db.text("false"))
|
||||
|
||||
|
||||
|
||||
class Igloo(db.Model):
|
||||
__tablename__ = 'igloo'
|
||||
|
||||
@ -118,6 +118,14 @@ class IglooCollection(AbstractDataCollection):
|
||||
__indexby__ = 'id'
|
||||
__filterby__ = 'id'
|
||||
|
||||
@cached_property
|
||||
def legacy_inventory(self):
|
||||
return [item for item in self.values() if item.legacy_inventory]
|
||||
|
||||
@cached_property
|
||||
def vanilla_inventory(self):
|
||||
return [item for item in self.values() if item.vanilla_inventory]
|
||||
|
||||
|
||||
class PenguinIglooCollection(AbstractDataCollection):
|
||||
__model__ = PenguinIgloo
|
||||
@ -130,6 +138,14 @@ class LocationCollection(AbstractDataCollection):
|
||||
__indexby__ = 'id'
|
||||
__filterby__ = 'id'
|
||||
|
||||
@cached_property
|
||||
def legacy_inventory(self):
|
||||
return [item for item in self.values() if item.legacy_inventory]
|
||||
|
||||
@cached_property
|
||||
def vanilla_inventory(self):
|
||||
return [item for item in self.values() if item.vanilla_inventory]
|
||||
|
||||
|
||||
class PenguinLocationCollection(AbstractDataCollection):
|
||||
__model__ = PenguinLocation
|
||||
@ -146,6 +162,14 @@ class FurnitureCollection(AbstractDataCollection):
|
||||
def innocent(self):
|
||||
return [item for item in self.values() if item.innocent]
|
||||
|
||||
@cached_property
|
||||
def legacy_inventory(self):
|
||||
return [item for item in self.values() if item.legacy_inventory]
|
||||
|
||||
@cached_property
|
||||
def vanilla_inventory(self):
|
||||
return [item for item in self.values() if item.vanilla_inventory]
|
||||
|
||||
|
||||
class PenguinFurnitureCollection(AbstractDataCollection):
|
||||
__model__ = PenguinFurniture
|
||||
@ -158,6 +182,14 @@ class FlooringCollection(AbstractDataCollection):
|
||||
__indexby__ = 'id'
|
||||
__filterby__ = 'id'
|
||||
|
||||
@cached_property
|
||||
def legacy_inventory(self):
|
||||
return [item for item in self.values() if item.legacy_inventory]
|
||||
|
||||
@cached_property
|
||||
def vanilla_inventory(self):
|
||||
return [item for item in self.values() if item.vanilla_inventory]
|
||||
|
||||
|
||||
class PenguinFlooringCollection(AbstractDataCollection):
|
||||
__model__ = PenguinFlooring
|
||||
|
@ -73,6 +73,14 @@ class ItemCollection(AbstractDataCollection):
|
||||
def innocent(self):
|
||||
return [item for item in self.values() if item.innocent]
|
||||
|
||||
@cached_property
|
||||
def legacy_inventory(self):
|
||||
return [item for item in self.values() if item.legacy_inventory]
|
||||
|
||||
@cached_property
|
||||
def vanilla_inventory(self):
|
||||
return [item for item in self.values() if item.vanilla_inventory]
|
||||
|
||||
|
||||
class PenguinItemCollection(AbstractDataCollection):
|
||||
__model__ = PenguinItem
|
||||
|
@ -136,11 +136,6 @@ async def igloos_load(server):
|
||||
server.logger.info(f'Loaded {len(server.flooring)} igloo flooring')
|
||||
|
||||
|
||||
DefaultFurnitureItems = [787, 788, 790, 792, 793]
|
||||
DefaultIglooId = 1
|
||||
DefaultLocationId = 1
|
||||
|
||||
|
||||
@handlers.handler(XMLPacket('login'), priority=Priority.Low)
|
||||
@handlers.allow_once
|
||||
async def load_igloo_inventory(p):
|
||||
@ -150,15 +145,29 @@ async def load_igloo_inventory(p):
|
||||
p.flooring = await PenguinFlooringCollection.get_collection(p.id)
|
||||
p.locations = await PenguinLocationCollection.get_collection(p.id)
|
||||
|
||||
if DefaultIglooId not in p.igloos:
|
||||
await p.igloos.insert(igloo_id=DefaultIglooId)
|
||||
default_igloos = p.server.igloos.legacy_inventory if p.is_legacy_client else \
|
||||
p.server.igloos.vanilla_inventory
|
||||
for default_item in default_igloos:
|
||||
if default_item.id not in p.igloos:
|
||||
await p.igloos.insert(igloo_id=default_item.id)
|
||||
|
||||
if DefaultLocationId not in p.locations:
|
||||
await p.locations.insert(location_id=DefaultLocationId)
|
||||
default_locations = p.server.locations.legacy_inventory if p.is_legacy_client else \
|
||||
p.server.locations.vanilla_inventory
|
||||
for default_item in default_locations:
|
||||
if default_item.id not in p.locations:
|
||||
await p.locations.insert(location_id=default_item.id)
|
||||
|
||||
for default_item_id in DefaultFurnitureItems:
|
||||
if default_item_id not in p.furniture:
|
||||
await p.furniture.insert(furniture_id=default_item_id)
|
||||
default_flooring = p.server.flooring.legacy_inventory if p.is_legacy_client else \
|
||||
p.server.flooring.vanilla_inventory
|
||||
for default_item in default_flooring:
|
||||
if default_item.id not in p.flooring:
|
||||
await p.flooring.insert(flooring_id=default_item.id)
|
||||
|
||||
default_furniture = p.server.furniture.legacy_inventory if p.is_legacy_client else \
|
||||
p.server.furniture.vanilla_inventory
|
||||
for default_item in default_furniture:
|
||||
if default_item.id not in p.furniture:
|
||||
await p.furniture.insert(furniture_id=default_item.id)
|
||||
|
||||
|
||||
@handlers.handler(XTPacket('g', 'gm'))
|
||||
@ -254,9 +263,6 @@ async def handle_buy_furniture(p, furniture: Furniture):
|
||||
if furniture is None:
|
||||
return await p.send_error(402)
|
||||
|
||||
if furniture.id in p.furniture:
|
||||
return await p.send_error(400)
|
||||
|
||||
if p.coins < furniture.cost:
|
||||
return await p.send_error(401)
|
||||
|
||||
|
@ -40,21 +40,20 @@ async def items_load(server):
|
||||
server.logger.info(f'Loaded {len(server.items)} clothing items')
|
||||
|
||||
|
||||
DefaultInventory = [1285, 9106]
|
||||
|
||||
|
||||
@handlers.handler(XMLPacket('login'), priority=Priority.Low)
|
||||
@handlers.allow_once
|
||||
async def load_inventory(p):
|
||||
p.inventory = await PenguinItemCollection.get_collection(p.id)
|
||||
p.permissions = await PenguinPermissionCollection.get_collection(p.id)
|
||||
|
||||
if p.color not in p.inventory:
|
||||
if p.color is not None and p.color not in p.inventory:
|
||||
await p.inventory.insert(item_id=p.color)
|
||||
|
||||
for default_item_id in DefaultInventory:
|
||||
if default_item_id not in p.inventory:
|
||||
await p.inventory.insert(item_id=default_item_id)
|
||||
default_items = p.server.items.legacy_inventory if p.is_legacy_client else \
|
||||
p.server.items.vanilla_inventory
|
||||
for default_item in default_items:
|
||||
if default_item.id not in p.inventory:
|
||||
await p.inventory.insert(item_id=default_item.id)
|
||||
|
||||
|
||||
@handlers.handler(XTPacket('i', 'gi'))
|
||||
|
Loading…
Reference in New Issue
Block a user