Ejemplo n.º 1
0
from lampost.datastore.classes import get_dbo_class
from lampost.context.resource import m_requires
from lampost.datastore.exceptions import DataError
from lampost.editor.editor import Editor, ChildrenEditor
from lampost.env.movement import Direction
from lampost.env.room import Room
from lampost.context.config import m_configured
from lampost.model.area import Area

m_requires(__name__, 'datastore', 'log', 'perm', 'dispatcher', 'edit_notify_service')

m_configured(__name__, 'root_area_id', 'default_start_room')


class AreaEditor(Editor):
    def initialize(self):
        super().initialize(Area)

    def _pre_create(self):
        if object_exists('player', self.raw['dbo_id']):
            raise DataError("Area name should not match any player name.")

    def _pre_delete(self, del_obj):
        if del_obj.dbo_id == root_area_id:
            raise DataError("Cannot delete root area.")
        for room in load_object_set(Room, 'area_rooms:{}'.format(del_obj.dbo_id)):
            room_clean_up(room, self.session, del_obj.dbo_id)


class RoomEditor(ChildrenEditor):
    def initialize(self):
Ejemplo n.º 2
0
from lampost.context.resource import m_requires
from lampost.gameops.action import action_handler, ActionError
from lampost.context.config import m_configured
from lampost.lpmud.fight import Fight
from lampost.lpmud import attributes
from lampost.lpmud.combat import calc_consider
from lampost.model.entity import Entity

m_requires(__name__, 'log', 'tools', 'dispatcher')

m_configured(__name__, 'refresh_interval', 'refresh_rates')


class EntityLP(Entity):
    health = 0
    stamina = 0
    mental = 0
    action = 0
    auto_fight = True

    weapon = None
    last_opponent = None

    _refresh_pulse = None
    _current_action = None
    _action_target = None
    _next_command = None
    _action_pulse = None

    def __init__(self):
        super().__init__()
Ejemplo n.º 3
0
from lampost.context.config import m_configured
from lampost.context.resource import m_requires
from lampost.datastore.dbofield import DBOField, DBOTField
from lampost.datastore.auto import TemplateField
from lampost.lpmud.archetype import Archetype
from lampost.lpmud.attributes import fill_pools
from lampost.lpmud.entity import EntityLP
from lampost.lpmud.skill import add_skill
from lampost.model.mobile import MobileTemplate, Mobile

m_requires(__name__, 'log', 'datastore', 'dispatcher')

m_configured(__name__, 'affinities', 'attributes', 'base_attr_value')


class MobileTemplateLP(MobileTemplate):
    class_id = 'mobile'
    default_skills = DBOField([], 'default_skill')

    def on_loaded(self):
        if self.archetype:
            arch = load_object(self.archetype, Archetype)
            for attr_name, start_value in arch.base_attrs.items():
                setattr(self.instance_cls, attr_name, start_value)
            self.desc = arch.desc
        else:
            for attr in attributes:
                setattr(self.instance_cls, attr['dbo_id'], base_attr_value * self.level)
        self.enemies = affinities[self.affinity]['enemies']

    def config_instance(self, mobile, owner):
Ejemplo n.º 4
0
    if maintenance_lc:
        maintenance_lc.stop()
    maintenance_lc = PeriodicCallback(lambda: dispatch('maintenance'), 60 * maintenance_interval * 1000)
    maintenance_lc.start()
    info("Maintenance Event heartbeat started at {} minutes", maintenance_interval)


class Registration():
    def __init__(self, event_type, callback, owner=None, priority=0):
        self.event_type = event_type
        self.callback = callback
        self.owner = owner if owner else getattr(callback, '__self__', self)
        self.priority = priority

    def cancel(self):
        pass


class PulseRegistration(Registration):
    def __init__(self, freq, callback, owner=None, priority=0, repeat=True):
        super().__init__('pulse_i', callback, owner, priority)
        self.freq = freq
        self.repeat = repeat

    def cancel(self):
        self.freq = 0


m_configured(__name__, 'pulse_interval', 'maintenance_interval')
Ejemplo n.º 5
0
from lampost.context.config import m_configured

pool_keys = []
attr_list = []


def _on_configured():
    global attr_list, pool_keys
    pool_keys = [(pool['dbo_id'], "base_{}".format(pool['dbo_id'])) for pool in resource_pools]
    attr_list = [attr['dbo_id'] for attr in attributes]

m_configured(__name__, 'attributes', 'resource_pools')


def base_pools(entity):
    for pool in resource_pools:
        total = sum(getattr(entity, key) * value for key, value in pool['calc'].items())
        setattr(entity, 'base_{}'.format(pool['dbo_id']), total)


def fill_pools(entity):
    base_pools(entity)
    for pool_id, base_pool_id in pool_keys:
        setattr(entity, pool_id, getattr(entity, base_pool_id))


def restore_attrs(entity):
    for attr in attr_list:
        setattr(entity, attr, getattr(entity, "perm_{}".format(attr)))

Ejemplo n.º 6
0
import time
from datetime import datetime, timedelta
from os import urandom
from base64 import b64encode

from lampost.context.resource import m_requires, requires
from lampost.context.config import m_configured
from lampost.util.lputil import ClientError

m_requires(__name__, 'log', 'dispatcher', 'user_manager')

m_configured(__name__, 'refresh_link_interval', 'broadcast_interval', 'link_dead_prune', 'link_dead_interval',
             'link_idle_refresh')


class SessionManager():
    def __init__(self):
        self.session_map = {}
        self.player_info_map = {}
        self.player_session_map = {}

    def _post_init(self):
        register_p(self._refresh_link_status, seconds=refresh_link_interval)
        register_p(self._broadcast_status, seconds=broadcast_interval)
        self.link_dead_prune = timedelta(seconds=link_dead_prune)
        self.link_dead_interval = timedelta(seconds=link_dead_interval)
        self.link_idle_refresh = timedelta(seconds=link_idle_refresh)
        register('player_logout', self._player_logout)

    def get_session(self, session_id):
        return self.session_map.get(session_id)
Ejemplo n.º 7
0

def _on_configured():
    if _web_server:
        _web_server.lsp_js('config.js', "var lampost_config = {{title:'{0}', description:'{1}'}};".format(lampost_title, lampost_description))


def init(web_server):

    global _web_server
    _web_server = web_server

    web_server.add(r'/game_connect', GameConnect)
    web_server.add(r'/link', Link)
    web_server.add(r'/login', Login)
    web_server.add(r'/action', Action)
    web_server.add(r'/register', Register)
    web_server.add(r'/unregister', Unregister)
    web_server.add(r'/remote_log', RemoteLog)

    web_server.add(r'/messages/friend_response', FriendResponse)
    web_server.add(r'/messages/delete', MessageDelete)

    web_server.add(r'/settings/(.*)', Settings)

    _on_configured()


m_configured(__name__, 'lampost_title', 'lampost_description')

Ejemplo n.º 8
0
from lampost.context.resource import m_requires
from lampost.context.config import m_configured

m_requires(__name__, 'dispatcher')

client_displays = {}

def _on_configured():
    client_displays.clear()
    for display in default_displays:
        client_displays[display['name']] = display['value']

m_configured(__name__, 'default_displays')


def _post_init():
    register('session_connect', set_displays)


def set_displays(session):
    session.append({'client_config': {'default_displays': client_displays}})

Ejemplo n.º 9
0
m_requires(__name__, 'log', 'tools', 'dispatcher')

damage_categories = {}


def _on_configured():
    global damage_categories
    damage_categories = {group['dbo_id']: set() for group in damage_groups}
    for damage_type in damage_types:
        dbo_id, damage_group = damage_type['dbo_id'], damage_type['group']
        if damage_group:
            damage_categories['any'].add(dbo_id)
            damage_categories[damage_group].add(dbo_id)

m_configured(__name__, 'damage_types', 'damage_groups')


CON_LEVELS = ['Insignificant', 'Trivial', 'Pesky', 'Annoying', 'Irritating', 'Bothersome', 'Troublesome',
              'Evenly Matched',
              'Threatening', 'Difficult', 'Intimidating', 'Imposing', 'Frightening', 'Terrifying', 'Unassailable']
CON_RANGE = int((len(CON_LEVELS) - 1) / 2)


def validate_weapon(ability, weapon_type):
    if not ability.weapon_type or ability.weapon_type == 'unused':
        return
    if ability.weapon_type == 'unarmed':
        if weapon_type:
            raise ActionError("You can't do that with a weapon.")
        return
Ejemplo n.º 10
0
from lampost.comm.broadcast import BroadcastMap
from lampost.context.config import m_configured
from lampost.context.resource import m_requires, requires
from lampost.datastore.dbofield import DBOField
from lampost.env.movement import Direction
from lampost.env.room import Room
from lampost.gameops import target_gen
from lampost.gameops.action import convert_verbs, ActionError
from lampost.model.item import BaseItem

m_requires(__name__, 'datastore', 'dispatcher')

m_configured(__name__, 'instance_preserve_hours')

instance_map = {}


class InstanceManager():
    def _post_init(self):
        register('maintenance', self.remove_old)

    def next_instance(self):
        instance_id = db_counter('instance_id')
        area_instance = AreaInstance(instance_id)
        instance_map[instance_id] = area_instance
        return area_instance

    def remove_old(self):
        stale_pulse = future_pulse(instance_preserve_hours * 60 * 60)
        for instance_id, instance in instance_map.copy().items():
            if instance.pulse_stamp < stale_pulse and not [entity for entity in instance.entities
Ejemplo n.º 11
0
from lampost.comm.broadcast import Broadcast

from lampost.context.resource import m_requires
from lampost.datastore.auto import AutoField
from lampost.datastore.dbo import CoreDBO, ChildDBO
from lampost.datastore.dbofield import DBOField, DBOCField
from lampost.env.movement import Direction
from lampost.context.config import m_configured
from lampost.gameops.script import Scriptable, Shadow
from lampost.model.item import Connected


m_requires(__name__, 'log', 'dispatcher', 'datastore')

m_configured(__name__, 'room_reset_time')


def tell(listeners, msg_type, *args):
    for listener in listeners:
        try:
            receiver = getattr(listener, msg_type)
        except AttributeError:
            continue
        receiver(*args)


class Exit(CoreDBO):
    class_id = 'exit'

    target_class = None
Ejemplo n.º 12
0
from lampost.context.config import m_configured
from lampost.context.resource import m_requires
from lampost.util.lputil import PermError

m_requires(__name__, 'datastore')


def _on_configured():
    global _rev_levels
    _rev_levels = {level: name for name, level in imm_levels.items()}

m_configured(__name__, 'imm_levels', 'system_accounts', 'system_level')


def _post_init():
    global immortals
    immortals = get_all_hash('immortals')
    immortals.update({account: system_level for account in system_accounts})


def perm_name(num_level):
    return _rev_levels.get(num_level, 'player')


def update_immortal_list(player):
    if player.imm_level:
        set_db_hash('immortals', player.dbo_id, player.imm_level)
        immortals[player.dbo_id] = player.imm_level
    else:
        delete_index('immortals', player.dbo_id)
        try:
Ejemplo n.º 13
0
from lampost.server.services import ClientService
from lampost.gameops.action import make_action
from lampost.context.resource import m_requires
from lampost.context.config import m_configured
from lampost.util.lputil import timestamp

m_requires(__name__, 'dispatcher', 'datastore', 'channel_service')

m_configured(__name__, 'max_channel_history')


class Channel():
    def __init__(self, channel_type, instance_id=None, general=False, aliases=()):
        if instance_id == 'next':
            instance_id = db_counter('channel')
        make_action(self, (channel_type,) + aliases)
        self.id = "{}_{}".format(channel_type, instance_id) if instance_id else channel_type
        channel_service.register_channel(self.id, general)

    def __call__(self, source, command, **_):
        space_ix = command.find(" ")
        if space_ix == -1:
            return source.display_line("Say what?")
        self.send_msg(source.name + ":" + command[space_ix:])

    def send_msg(self, msg):
        channel_service.dispatch_message(self.id, msg)

    def disband(self):
        channel_service.unregister_channel(self.id)
Ejemplo n.º 14
0
from lampost.context.config import m_configured
from lampost.datastore.dbo import KeyDBO, DBOAccess
from lampost.datastore.dbofield import DBOField, DBOLField

m_configured(__name__, 'base_attr_value', 'attributes', 'default_start_room')


class Archetype(DBOAccess, KeyDBO):
    dbo_key_type = 'archetype'
    dbo_set_key = 'archetypes'

    name = DBOField("Unnamed")
    desc = DBOField('')
    base_attrs = DBOField({})


class PlayerRace(Archetype):
    dbo_key_type = "race"
    dbo_set_key = "races"

    default_skills = DBOField([], 'default_skill')
    start_room = DBOLField(dbo_class_id='room')
    start_instanced = DBOField(False)

    @classmethod
    def new_dto(cls):
        dto = super().new_dto()
        dto['start_room'] = default_start_room
        dto['base_attrs'] = {attr['dbo_id']: base_attr_value for attr in attributes}
        return dto
Ejemplo n.º 15
0
import random
import string

from lampost.server.handlers import MethodHandler
from lampost.server.user import User
from lampost.context.resource import m_requires, requires
from lampost.datastore.exceptions import DataError
from lampost.context.config import m_configured
from lampost.model.player import Player
from lampost.util.encrypt import make_hash
from lampost.util.lputil import ClientError


m_requires(__name__, 'datastore', 'dispatcher', 'user_manager', 'perm', 'email_sender', 'friend_service')

m_configured(__name__, 'lampost_title')

@requires('session_manager')
class Settings(MethodHandler):

    def get_account(self):
        user_id = self.raw['user_id']
        if self.session.user.dbo_id != user_id:
            check_perm(self.player, 'admin')
        return load_object(user_id, User).edit_dto

    def create_account(self):
        account_name = self.raw['account_name'].lower()
        if get_index("ix:user:name", account_name) or object_exists('player', account_name) or\
                account_name in perm.system_accounts or object_exists('area', account_name):
            raise DataError("InUse: {}".format(account_name))
Ejemplo n.º 16
0
from lampost.comm.channel import Channel
from lampost.context.config import m_configured
from lampost.context.resource import m_requires
from lampost.env.room import Room, safe_room
from lampost.gameops.action import ActionError
from lampost.mud.action import mud_action, imm_actions

m_requires(__name__, 'log', 'datastore', 'dispatcher', 'perm', 'user_manager', 'instance_manager',
           'message_service', 'friend_service')

m_configured(__name__, 'default_start_room')

_init_priority = 5000


def _post_init():
    global shout_channel, imm_channel
    shout_channel = Channel('shout', general=True)
    imm_channel = Channel('imm')
    register('player_create', _player_create)
    register('player_baptise', _baptise, priority=-100)
    register('imm_baptise', _imm_baptise, priority=-100)
    register('missing_env', _start_env)


def _player_create(player, user):
    if len(user.player_ids) == 1 and not player.imm_level:
        player.imm_level = perm_level('builder')
        update_immortal_list(player)
        dispatch('imm_level_change', player, 0)
        message_service.add_message('system', "Welcome!  Your first player has been given immortal powers.  Check out the 'Editor' window on the top menu.", player.dbo_id)
Ejemplo n.º 17
0
from lampost.datastore.dbofield import DBOField
import lampost.env.room
from lampost.gameops.action import ActionError
from lampost.context.config import m_configured

m_configured(__name__, "room_stamina", "room_action", "default_room_size")

exit_cost_map = {}
prep_multiplier = 1


def find_cost(room):
    if room and room.size:
        try:
            return exit_cost_map[room.size]
        except KeyError:
            exit_cost_map[room.size] = {
                "action": int(room_stamina * room.size / default_room_size),
                "stamina": int(room_action * room.size / default_room_size),
            }
            return exit_cost_map[room.size]


class ExitLP(lampost.env.room.Exit):
    class_id = "exit"

    guarded = DBOField(False)
    door_key = DBOField()

    @property
    def prep_time(self):