Commit 5e741751 authored by Andy Castille's avatar Andy Castille
Browse files


parent d9504c97
......@@ -11,16 +11,18 @@ from cou_server.entities.requirements import (
class Action:
def __init__(self, action=None):
def __init__(self, action=None, action_word=None):
if isinstance(action, str) or not action:
if action:
self.action_name = action
self.custom_action_word = action_word
self.enabled = True
self.multi_enabled = False
self.ground_action = False
self.description = str()
self.time_required = 0
self.associated_skill = str()
self.item_requirements = ItemRequirements()
self.skill_requirements = SkillRequirements()
self.energy_requirements = EnergyRequirements()
from datetime import datetime, timedelta
import time
from typing import Union
import gevent
......@@ -58,10 +59,11 @@ class Entity(IPersistable, IActionable, MetabolicsChange):
responses: dict
states: dict
current_state: SpriteSheet
respawn: datetime
respawn: Union[datetime, None]
gains: dict = {"energy": 0, "mood": 0, "img": 0, "currants": 0}
def __init__(self):
raise NotImplementedError()
from copy import deepcopy
from random import randint
from cou_server.entities.entity import create_id
from cou_server.entities.action import Action
# All items known to the server
ITEMS = dict()
# Discounts, stored as itemType: part paid out of 1 (eg. 0.8 for 20% off)
DROP = Action("drop")
DROP.description = "Drop this item on the ground."
DROP.multi_enabled = True
PICK_UP = Action("pickup")
PICK_UP.description = "Put this item in your inventory."
PICK_UP.multi_enabled = True
class Item:
category: str
icon_url: str
sprite_url: str
broken_url: str
tool_animation: str
name: str
recipe_name: str
description: str
item_type: str
item_id: str
price: int
stacks_to: int
icon_num: int = 4
durability: int
sub_slots: int = 0
x: float
y: float
on_ground: bool = False
is_container: bool = False
sub_slot_filter: list
actions: list
consume_values: dict
metadata: dict
drop: Action(DROP)
pick_up: Action(PICK_UP)
def __init__(self, **kwargs):
for key, value in kwargs.items():
setattr(self, key, value)
def put_item_on_ground(self, x, y, label, id=None):
def discount(self) -> float:
if self.item_type in DISCOUNTS:
return DISCOUNTS[self.item_type]
return 1.0
def clone(item_type: str):
return deepcopy(ITEMS[item_type])
def action_list(self) -> list:
result = list()
if self.on_ground:
for action in self.actions:
if action.ground_action:
result += action.__dict__
result += PICK_UP.__dict__
# Make sure the drop action is last
drop_instance = None
for action in self.actions:
if action.action_name == DROP.action_name:
drop_instance = action
if drop_instance:
result = [action.__dict__ for action in self.actions]
result += DROP.__dict__
return result
def filter_allows(self, test_item, item_type):
# Allow an empty slot
if not test_item and not item_type:
return True
# Bags except empty item types (this is an empty slot)
if item_type is not None and len(item_type) == 0:
return True
if not test_item:
test_item = ITEMS[item_type]
if len(self.sub_slot_filter) == 0:
return not test_item.is_container
return test_item.item_type in self.sub_slot_filter
def __repr__(self):
return f"An item of type {self.item_type} with metadata {self.metadata}"
def put_on_ground(self, x, y, street_name: str, item_id: str = None, count: int = 1):
street = None # TODO: StreetUpdateHandler.streets[streetName]
if not street:
for i in range(0, count):
temp_id = item_id
if not temp_id:
rand_str = str(randint(0, 9999))
temp_id = "i" + create_id(x, y, self.item_type, street_name + rand_str)
item = Item.clone(self.item_type)
item.x = x
item.y = y # TODO: street.getYFromGround(item.x, item.y, 1, 1)
item.item_id = temp_id
item.on_ground = True
item.metadata = self.metadata
# TODO: street.groundItems[tempId] = item;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment