Last active
June 1, 2016 15:11
-
-
Save GedMullen/dcb99c146cb1eabfb0e00f9214fa2c83 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Room | |
Rooms are simple containers that has no location of their own. | |
""" | |
import random | |
from evennia import DefaultRoom, TICKER_HANDLER | |
from evennia import utils | |
from characters import Character | |
from npc import Npc | |
ECHOES = ["{wScotty says: 'I cannae do it Captain'", | |
"{wSpok says: 'Live long and prosper'", | |
"{wMcCoy says: 'He's not going to make it Jim'"] # etc | |
class WeatherRoom(DefaultRoom): | |
"This room is ticked at regular intervals" | |
def at_object_creation(self): | |
"called only when the object is first created" | |
TICKER_HANDLER.add(self, 10, hook_key="at_weather_update") | |
def at_weather_update(self, *args, **kwargs): | |
"ticked at regular intervals" | |
echo = random.choice(ECHOES) | |
self.msg_contents(echo) | |
def at_object_receive(self, obj, source_location): | |
if utils.inherits_from(obj, Npc): # An NPC has entered | |
pass | |
else: | |
if utils.inherits_from(obj, Character): | |
# A PC has entered, NPC is caught above. | |
# Cause the character to look around | |
obj.execute_cmd('look') | |
for item in self.contents: | |
if utils.inherits_from(item, Npc): | |
# An NPC is in the room | |
item.at_char_entered(obj) | |
class Room(DefaultRoom): | |
""" | |
Rooms are like any Object, except their location is None | |
(which is default). They also use basetype_setup() to | |
add locks so they cannot be puppeted or picked up. | |
(to change that, use at_object_creation instead) | |
See examples/object.py for a list of | |
properties and methods available on all Objects. | |
""" | |
def at_object_receive(self, obj, source_location): | |
if utils.inherits_from(obj, Npc): # An NPC has entered | |
pass | |
else: | |
if utils.inherits_from(obj, Character): | |
# A PC has entered, NPC is caught above. | |
# Cause the character to look around | |
obj.execute_cmd('look') | |
for item in self.contents: | |
if utils.inherits_from(item, Npc): | |
# An NPC is in the room | |
item.at_char_entered(obj) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment