1 # This file is part of PlomRogue. PlomRogue is licensed under the GPL version 3
2 # or any later version. For details on its copyright, license, and warranties,
3 # see the file NOTICE in the root directory of the PlomRogue source package.
6 from server.config.world_data import world_db
7 from server.io import log
11 """Make t do nothing (but loudly, if player avatar)."""
12 if t == world_db["Things"][0]:
17 """If passable, move/collide(=attack) thing into T_ARGUMENT's direction."""
18 from server.build_fov_map import build_fov_map
19 from server.config.misc import decrement_lifepoints_func
20 from server.utils import mv_yx_in_dir_legal
21 from server.config.world_data import directions_db, symbols_passable
23 move_result = mv_yx_in_dir_legal(chr(t["T_ARGUMENT"]),
24 t["T_POSY"], t["T_POSX"])
25 if 1 == move_result[0]:
26 pos = (move_result[1] * world_db["MAP_LENGTH"]) + move_result[2]
27 hitted = [id for id in world_db["Things"]
28 if world_db["Things"][id] != t
29 if world_db["Things"][id]["T_LIFEPOINTS"]
30 if world_db["Things"][id]["T_POSY"] == move_result[1]
31 if world_db["Things"][id]["T_POSX"] == move_result[2]]
34 if t == world_db["Things"][0]:
35 hitted_type = world_db["Things"][hit_id]["T_TYPE"]
36 hitted_name = world_db["ThingTypes"][hitted_type]["TT_NAME"]
37 log("You WOUND " + hitted_name + ".")
39 hitter_name = world_db["ThingTypes"][t["T_TYPE"]]["TT_NAME"]
40 log(hitter_name +" WOUNDS you.")
41 decrement_lifepoints_func(world_db["Things"][hit_id])
43 passable = chr(world_db["MAP"][pos]) in symbols_passable
44 dir = [dir for dir in directions_db
45 if directions_db[dir] == chr(t["T_ARGUMENT"])][0]
47 t["T_POSY"] = move_result[1]
48 t["T_POSX"] = move_result[2]
49 for id in t["T_CARRIES"]:
50 world_db["Things"][id]["T_POSY"] = move_result[1]
51 world_db["Things"][id]["T_POSX"] = move_result[2]
53 if t == world_db["Things"][0]:
54 log("You MOVE " + dir + ".")
58 """Make t pick up (topmost?) Thing from ground into inventory. Return it.
60 Define topmostness by how low the thing's type ID is.
62 ids = [id for id in world_db["Things"] if world_db["Things"][id] != t
63 if not world_db["Things"][id]["carried"]
64 if world_db["Things"][id]["T_POSY"] == t["T_POSY"]
65 if world_db["Things"][id]["T_POSX"] == t["T_POSX"]]
69 tid = world_db["Things"][iid]["T_TYPE"]
70 from server.config.actions import actor_pickup_test_hook
71 if (lowest_tid == -1 or tid < lowest_tid) and \
72 actor_pickup_test_hook(t, tid):
75 world_db["Things"][id]["carried"] = True
76 t["T_CARRIES"].append(id)
77 if t == world_db["Things"][0]:
78 log("You PICK UP an object.")
79 return world_db["Things"][id]
82 """Drop to ground from t's inventory, return T_ARGUMENT-indexed Thing."""
83 # TODO: Handle case where T_ARGUMENT matches nothing.
84 if len(t["T_CARRIES"]):
85 id = t["T_CARRIES"][t["T_ARGUMENT"]]
86 t["T_CARRIES"].remove(id)
87 world_db["Things"][id]["carried"] = False
88 if t == world_db["Things"][0]:
89 log("You DROP an object.")
90 return world_db["Things"][id]
93 """Make t use (for now: consume) T_ARGUMENT-indexed Thing in inventory."""
94 # TODO: Handle case where T_ARGUMENT matches nothing.
95 if len(t["T_CARRIES"]):
96 id = t["T_CARRIES"][t["T_ARGUMENT"]]
97 type = world_db["Things"][id]["T_TYPE"]
98 if world_db["ThingTypes"][type]["TT_TOOL"] == "food":
99 t["T_CARRIES"].remove(id)
100 del world_db["Things"][id]
101 t["T_SATIATION"] += world_db["ThingTypes"][type]["TT_TOOLPOWER"]
102 if t == world_db["Things"][0]:
103 log("You CONSUME this thing.")
105 from server.config.actions import actor_use_attempts_hook
106 actor_use_attempts_hook(t, type)