"drop_thing": "u",
"teleport": "p",
"door": "D",
+ "consume": "C",
"help": "h",
"toggle_map_mode": "L",
"toggle_tile_draw": "m",
class Task:
argtypes = ''
- todo = 3
+ todo = 1
def __init__(self, thing, args=()):
self.thing = thing
class Task_WAIT(Task):
- todo = 1
def do(self):
pass
class Task_MOVE(Task):
- todo = 1
argtypes = 'string:direction'
def get_move_target(self):
class Task_WRITE(Task):
- todo = 1
argtypes = 'string:char string'
def check(self):
class Task_FLATTEN_SURROUNDINGS(Task):
- todo = 10
argtypes = 'string'
def check(self):
class Task_PICK_UP(Task):
- todo = 1
def check(self):
if self.thing.carrying:
class Task_DROP(Task):
- todo = 1
def check(self):
if not self.thing.carrying:
class Task_DOOR(Task):
- todo = 1
def do(self):
self.thing.carrying = None
t.open()
else:
t.close()
+
+
+
+class Task_INTOXICATE(Task):
+
+ def check(self):
+ if self.thing.carrying is None:
+ raise PlayError('nothing to consume')
+ if self.thing.carrying.type_ != 'Consumable':
+ raise PlayError('cannot consume non-consumable')
+
+ def do(self):
+ self.thing.game.things.remove(self.thing.carrying)
+ self.thing.carrying = None
+ for c_id in self.thing.game.sessions:
+ if self.thing.game.sessions[c_id]['thing_id'] == self.thing.id_:
+ self.thing.game.io.send('RANDOM_COLORS', c_id)
+ self.thing.game.io.send('CHAT "You are drunk now."', c_id)
+ self.thing.drunk = 10000
+class Thing_Consumable(Thing):
+ symbol_hint = 'B'
+ portable = True
+
+
+
+class Thing_ConsumableSpawner(ThingSpawner):
+ child_type = 'Consumable'
+
+
+
class ThingAnimate(Thing):
blocking = True
+ drunk = 0
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
return None
def proceed(self):
+ self.drunk -= 1
+ if self.drunk == 0:
+ for c_id in self.game.sessions:
+ if self.game.sessions[c_id]['thing_id'] == self.id_:
+ self.game.io.send('DEFAULT_COLORS', c_id)
+ self.game.io.send('CHAT "You sober up."', c_id)
+ self.game.changed = True
self._fov = None
if self.task is None:
self.task = self.get_next_task()
return
-
try:
self.task.check()
except GameError as e:
<button id="take_thing"></button>
<button id="drop_thing"></button>
<button id="door"></button>
+ <button id="consume"></button>
<button id="teleport"></button>
</td>
</tr>
<li>pick up thing: <input id="key_take_thing" type="text" value="z" />
<li>drop thing: <input id="key_drop_thing" type="text" value="u" />
<li>open/close: <input id="key_door" type="text" value="D" />
+<li>consume: <input id="key_consume" type="text" value="C" />
<li><input id="key_switch_to_chat" type="text" value="t" />
<li><input id="key_switch_to_play" type="text" value="p" />
<li><input id="key_switch_to_study" type="text" value="?" />
'take_thing': 'pick up thing',
'drop_thing': 'drop thing',
'door': 'open/close',
+ 'consume': 'consume',
'toggle_map_mode': 'toggle map view',
'toggle_tile_draw': 'toggle protection character drawing',
'hex_move_upleft': 'up-left',
};
let terminal = {
- foreground: 'white',
- background: 'black',
initialize: function() {
this.rows = rows_selector.value;
this.cols = cols_selector.value;
this.pre_el = document.getElementById("terminal");
- this.pre_el.style.color = this.foreground;
- this.pre_el.style.backgroundColor = this.background;
+ this.set_default_colors();
+ this.apply_colors();
this.content = [];
let line = []
for (let y = 0, x = 0; y <= this.rows; x++) {
line.push(' ');
}
},
+ apply_colors: function() {
+ this.pre_el.style.color = this.foreground;
+ this.pre_el.style.backgroundColor = this.background;
+ },
+ set_default_colors: function() {
+ this.foreground = 'white';
+ this.background = 'black';
+ this.apply_colors();
+ },
+ set_random_colors: function() {
+ function rand(offset) {
+ return Math.floor(offset + Math.random() * 96).toString(16);
+ }
+ this.foreground = '#' + rand(159) + rand(159) + rand(159);
+ this.background = '#' + rand(0) + rand(0) + rand(0);
+ this.apply_colors();
+ },
blink_screen: function() {
this.pre_el.style.color = this.background;
this.pre_el.style.backgroundColor = this.foreground;
};
} else if (tokens[0] === 'TASKS') {
game.tasks = tokens[1].split(',');
- console.log(game.tasks);
tui.mode_write.legal = game.tasks.includes('WRITE');
} else if (tokens[0] === 'THING_TYPE') {
game.thing_types[tokens[1]] = tokens[2]
} else if (tokens[0] === 'LOGIN_OK') {
this.send(['GET_GAMESTATE']);
tui.switch_mode('post_login_wait');
+ } else if (tokens[0] === 'DEFAULT_COLORS') {
+ terminal.set_default_colors();
+ } else if (tokens[0] === 'RANDOM_COLORS') {
+ terminal.set_random_colors();
} else if (tokens[0] === 'ADMIN_OK') {
tui.is_admin = true;
tui.log_msg('@ you now have admin rights');
'drop_thing': 'DROP',
'move': 'MOVE',
'door': 'DOOR',
+ 'consume': 'INTOXICATE',
},
init: function() {
this.mode_chat.available_modes = ["play", "study", "edit", "admin_enter"]
this.mode_play.available_modes = ["chat", "study", "edit", "admin_enter"]
this.mode_play.available_actions = ["move", "take_thing", "drop_thing",
- "teleport", "door"];
+ "teleport", "door", "consume"];
this.mode_study.available_modes = ["chat", "play", "admin_enter", "edit"]
this.mode_study.available_actions = ["toggle_map_mode", "move_explorer"];
this.mode_admin.available_modes = ["admin_thing_protect", "control_pw_type",
server.send(["TASK:PICK_UP"]);
} else if (event.key === tui.keys.drop_thing && tui.task_action_on('drop_thing')) {
server.send(["TASK:DROP"]);
+ } else if (event.key === tui.keys.consume && tui.task_action_on('consume')) {
+ server.send(["TASK:INTOXICATE"]);
} else if (event.key === tui.keys.door && tui.task_action_on('door')) {
server.send(["TASK:DOOR"]);
} else if (event.key in tui.movement_keys && tui.task_action_on('move')) {
document.getElementById("door").onclick = function() {
server.send(['TASK:DOOR']);
};
+document.getElementById("consume").onclick = function() {
+ server.send(['TASK:INTOXICATE']);
+};
document.getElementById("teleport").onclick = function() {
game.teleport();
};
cmd_GOD_THING_PROTECTION, cmd_THING_PROTECTION,
cmd_SET_MAP_CONTROL_PASSWORD, cmd_SPAWN_POINT)
from plomrogue.tasks import (Task_WAIT, Task_MOVE, Task_WRITE, Task_PICK_UP,
- Task_DROP, Task_FLATTEN_SURROUNDINGS, Task_DOOR)
+ Task_DROP, Task_FLATTEN_SURROUNDINGS, Task_DOOR,
+ Task_INTOXICATE)
from plomrogue.things import (Thing_Player, Thing_Item, Thing_ItemSpawner,
Thing_SpawnPoint, Thing_SpawnPointSpawner,
- Thing_Door, Thing_DoorSpawner)
+ Thing_Door, Thing_DoorSpawner, Thing_Consumable,
+ Thing_ConsumableSpawner)
from plomrogue.config import config
game = Game(config['savefile'])
game.register_task(Task_PICK_UP)
game.register_task(Task_DROP)
game.register_task(Task_DOOR)
+game.register_task(Task_INTOXICATE)
game.register_thing_type(Thing_Player)
game.register_thing_type(Thing_Item)
game.register_thing_type(Thing_ItemSpawner)
game.register_thing_type(Thing_SpawnPointSpawner)
game.register_thing_type(Thing_Door)
game.register_thing_type(Thing_DoorSpawner)
+game.register_thing_type(Thing_Consumable)
+game.register_thing_type(Thing_ConsumableSpawner)
game.read_savefile()
game.io.start_loop()
for port in config['servers']:
pass
cmd_PONG.argtypes = ''
+def cmd_DEFAULT_COLORS(game):
+ game.tui.set_default_colors()
+cmd_DEFAULT_COLORS.argtypes = ''
+
+def cmd_RANDOM_COLORS(game):
+ game.tui.set_random_colors()
+cmd_RANDOM_COLORS.argtypes = ''
+
class Game(GameBase):
turn_complete = False
tasks = {}
self.register_command(cmd_PLAY_ERROR)
self.register_command(cmd_TASKS)
self.register_command(cmd_FOV)
+ self.register_command(cmd_DEFAULT_COLORS)
+ self.register_command(cmd_RANDOM_COLORS)
self.map_content = ''
self.player_id = -1
self.info_db = {}
import json
self.mode_play.available_modes = ["chat", "study", "edit", "admin_enter"]
self.mode_play.available_actions = ["move", "take_thing", "drop_thing",
- "teleport", "door"]
+ "teleport", "door", "consume"]
self.mode_study.available_modes = ["chat", "play", "admin_enter", "edit"]
self.mode_study.available_actions = ["toggle_map_mode", "move_explorer"]
self.mode_admin.available_modes = ["admin_thing_protect", "control_pw_type",
'take_thing': 'z',
'drop_thing': 'u',
'teleport': 'p',
+ 'consume': 'C',
'door': 'D',
'help': 'h',
'toggle_map_mode': 'L',
self.input_ = ""
self.restore_input_values()
+ def set_default_colors(self):
+ curses.init_color(1, 1000, 1000, 1000)
+ curses.init_color(2, 0, 0, 0)
+ self.do_refresh = True
+
+ def set_random_colors(self):
+
+ def rand(offset):
+ import random
+ return int(offset + random.random()*375)
+
+ curses.init_color(1, rand(625), rand(625), rand(625))
+ curses.init_color(2, rand(0), rand(0), rand(0))
+ self.do_refresh = True
+
def loop(self, stdscr):
import datetime
def safe_addstr(y, x, line):
if y < self.size.y - 1 or x + len(line) < self.size.x:
- stdscr.addstr(y, x, line)
+ stdscr.addstr(y, x, line, curses.color_pair(1))
else: # workaround to <https://stackoverflow.com/q/7063128>
cut_i = self.size.x - x - 1
cut = line[:cut_i]
last_char = line[cut_i]
- stdscr.addstr(y, self.size.x - 2, last_char)
+ stdscr.addstr(y, self.size.x - 2, last_char, curses.color_pair(1))
stdscr.insstr(y, self.size.x - 2, ' ')
- stdscr.addstr(y, x, cut)
+ stdscr.addstr(y, x, cut, curses.color_pair(1))
def handle_input(msg):
command, args = self.parser.parse(msg)
def draw_screen():
stdscr.clear()
+ stdscr.bkgd(' ', curses.color_pair(1))
recalc_input_lines()
if self.mode.has_input_prompt:
draw_input()
'toggle_map_mode': 'toggle map view',
'toggle_tile_draw': 'toggle protection character drawing',
'door': 'open/close',
+ 'consume': 'consume',
}
action_tasks = {
'drop_thing': 'DROP',
'door': 'DOOR',
'move': 'MOVE',
+ 'consume': 'INTOXICATE',
}
curses.curs_set(False) # hide cursor
- curses.use_default_colors()
+ curses.start_color()
+ self.set_default_colors()
+ curses.init_pair(1, 1, 2)
stdscr.timeout(10)
reset_screen_size()
self.explorer = YX(0, 0)
self.send('TASK:DROP')
elif key == self.keys['door'] and task_action_on('door'):
self.send('TASK:DOOR')
+ elif key == self.keys['consume'] and task_action_on('consume'):
+ self.send('TASK:INTOXICATE')
elif key == self.keys['teleport']:
player = self.game.get_thing(self.game.player_id)
if player.position in self.game.portals: