X-Git-Url: https://plomlompom.com/repos/?a=blobdiff_plain;f=server%2Fcommands.py;h=b8216a0fec6433699401b6eefc9cfa4bf41a7080;hb=HEAD;hp=7ad36d00eedbf87419cef00c1927ee446869273f;hpb=428f55c523a2995e6c4e80d4b4f7c8726202a5b4;p=plomrogue diff --git a/server/commands.py b/server/commands.py index 7ad36d0..b8216a0 100644 --- a/server/commands.py +++ b/server/commands.py @@ -7,7 +7,7 @@ from server.config.world_data import world_db from server.config.io import io_db from server.io import log, strong_write from server.utils import integer_test, id_setter -from server.world import set_world_inactive, turn_over +from server.world import set_world_inactive, turn_over, eat_vs_hunger_threshold from server.update_map_memory import update_map_memory from server.build_fov_map import build_fov_map @@ -57,8 +57,7 @@ def command_thingshere(str_y, str_x): for id in world_db["Things"] if not world_db["Things"][id]["carried"] if world_db["Things"][id]["T_TYPE"] == tid - if y == world_db["Things"][id]["T_POSY"] - if x == world_db["Things"][id]["T_POSX"]]: + if pos == world_db["Things"][id]["pos"]]: type = world_db["Things"][id]["T_TYPE"] name = world_db["ThingTypes"][type]["TT_NAME"] strong_write(io_db["file_out"], name + "\n") @@ -301,6 +300,13 @@ def command_ttcorpseid(str_int): print("Ignoring: Corpse ID belongs to no known ThignType.") +@test_ThingType_id +def command_ttlifepoints(val_string): + setter("ThingType", "TT_LIFEPOINTS", 0, 255)(val_string) + tt = world_db["ThingTypes"][command_ttid.id] + tt["eat_vs_hunger_threshold"] = eat_vs_hunger_threshold(command_ttid.id) + + @test_ThingAction_id def command_taname(name): """Set TA_NAME of selected ThingAction. @@ -321,6 +327,15 @@ def command_taname(name): print("Ignoring: Invalid action name.") +@test_ThingAction_id +def command_taeffort(val_string): + setter("ThingAction", "TA_EFFORT", 0, 255)(val_string) + if world_db["ThingActions"][command_taid.id]["TA_NAME"] == "use": + for ttid in world_db["ThingTypes"]: + tt = world_db["ThingTypes"][ttid] + tt["eat_vs_hunger_threshold"] = eat_vs_hunger_threshold(ttid) + + def setter(category, key, min, max=None): """Build setter for world_db([category + "s"][id])[key] to >=min/<=max.""" if category is None: @@ -403,7 +418,9 @@ def setter_tpos(axis): val = integer_test(str_int, 0, 255) if None != val: if val < world_db["MAP_LENGTH"]: - world_db["Things"][command_tid.id]["T_POS" + axis] = val + t = world_db["Things"][command_tid.id] + t["T_POS" + axis] = val + t["pos"] = t["T_POSY"] * world_db["MAP_LENGTH"] + t["T_POSX"] if world_db["WORLD_ACTIVE"] \ and world_db["Things"][command_tid.id]["T_LIFEPOINTS"]: build_fov_map(world_db["Things"][command_tid.id]) @@ -424,7 +441,8 @@ def set_command(action): def play_wait(): """Try "wait" as player's T_COMMAND.""" - set_command("wait") + if world_db["WORLD_ACTIVE"]: + set_command("wait") def action_exists(action): @@ -438,21 +456,21 @@ def action_exists(action): def play_pickup(): """Try "pickup" as player's T_COMMAND".""" - if action_exists("pickup"): + if action_exists("pickup") and world_db["WORLD_ACTIVE"]: t = world_db["Things"][0] - ids = [id for id in world_db["Things"] if id - if not world_db["Things"][id]["carried"] - if world_db["Things"][id]["T_POSY"] == t["T_POSY"] - if world_db["Things"][id]["T_POSX"] == t["T_POSX"]] + ids = [tid for tid in world_db["Things"] if tid + if not world_db["Things"][tid]["carried"] + if world_db["Things"][tid]["pos"] == t["pos"]] + from server.config.commands import play_pickup_attempt_hook if not len(ids): log("NOTHING to pick up.") - else: + elif play_pickup_attempt_hook(t): set_command("pickup") def play_drop(str_arg): """Try "drop" as player's T_COMMAND, int(str_arg) as T_ARGUMENT / slot.""" - if action_exists("drop"): + if action_exists("drop") and world_db["WORLD_ACTIVE"]: t = world_db["Things"][0] if 0 == len(t["T_CARRIES"]): log("You have NOTHING to drop in your inventory.") @@ -467,17 +485,20 @@ def play_drop(str_arg): def play_use(str_arg): """Try "use" as player's T_COMMAND, int(str_arg) as T_ARGUMENT / slot.""" - if action_exists("use"): + if action_exists("use") and world_db["WORLD_ACTIVE"]: t = world_db["Things"][0] if 0 == len(t["T_CARRIES"]): log("You have NOTHING to use in your inventory.") else: val = integer_test(str_arg, 0, 255) if None != val and val < len(t["T_CARRIES"]): - id = t["T_CARRIES"][val] - type = world_db["Things"][id]["T_TYPE"] - if not world_db["ThingTypes"][type]["TT_TOOL"] == "food": - log("You CAN'T consume this thing.") + tid = t["T_CARRIES"][val] + tt = world_db["ThingTypes"][world_db["Things"][tid]["T_TYPE"]] + from server.config.commands import play_use_attempt_hook + hook_test = play_use_attempt_hook(t, tt) + if not (tt["TT_TOOL"] == "food" or hook_test): + if hook_test != False: + log("You CAN'T use this thing.") return world_db["Things"][0]["T_ARGUMENT"] = val set_command("use") @@ -487,7 +508,7 @@ def play_use(str_arg): def play_move(str_arg): """Try "move" as player's T_COMMAND, str_arg as T_ARGUMENT / direction.""" - if action_exists("move"): + if action_exists("move") and world_db["WORLD_ACTIVE"]: from server.config.world_data import directions_db, symbols_passable t = world_db["Things"][0] if not str_arg in directions_db: @@ -514,5 +535,6 @@ def play_move(str_arg): def command_ai(): """Call ai() on player Thing, then turn_over().""" from server.ai import ai - ai(world_db["Things"][0]) - turn_over() + if world_db["WORLD_ACTIVE"]: + ai(world_db["Things"][0]) + turn_over()