Release 0.9.0
This commit is contained in:
113
bot/modules/locations/triggers/location_update_on_map.py
Normal file
113
bot/modules/locations/triggers/location_update_on_map.py
Normal file
@@ -0,0 +1,113 @@
|
||||
from bot import loaded_modules_dict
|
||||
from os import path, pardir
|
||||
|
||||
module_name = path.basename(path.normpath(path.join(path.abspath(__file__), pardir, pardir)))
|
||||
trigger_name = path.basename(path.abspath(__file__))[:-3]
|
||||
|
||||
|
||||
def send_location_update_to_map(*args, **kwargs):
|
||||
"""Send location updates to map view via socket.io"""
|
||||
module = args[0]
|
||||
method = kwargs.get("method", None)
|
||||
updated_values_dict = kwargs.get("updated_values_dict", None)
|
||||
|
||||
if updated_values_dict is None:
|
||||
return
|
||||
|
||||
# Check which clients are viewing the map
|
||||
for clientid in module.webserver.connected_clients.keys():
|
||||
current_view = module.get_current_view(clientid)
|
||||
if current_view != "map":
|
||||
continue
|
||||
|
||||
if method in ["upsert", "update", "edit"]:
|
||||
# Send location update for each changed location
|
||||
active_dataset = module.dom.data.get("module_game_environment", {}).get("active_dataset", None)
|
||||
|
||||
# updated_values_dict structure at callback depth 4:
|
||||
# {location_identifier: {location_data}}
|
||||
# location_data includes "owner" field
|
||||
|
||||
for identifier, location_dict in updated_values_dict.items():
|
||||
if not isinstance(location_dict, dict):
|
||||
continue
|
||||
|
||||
# Get owner directly from location_dict
|
||||
owner_steamid = location_dict.get("owner")
|
||||
if owner_steamid is None:
|
||||
continue
|
||||
|
||||
location_id = f"{active_dataset}_{owner_steamid}_{identifier}"
|
||||
|
||||
# Get full location data from DOM if fields are missing in updated_values_dict
|
||||
# (e.g., when only is_enabled is updated)
|
||||
full_location_dict = (
|
||||
module.dom.data
|
||||
.get("module_locations", {})
|
||||
.get("elements", {})
|
||||
.get(active_dataset, {})
|
||||
.get(owner_steamid, {})
|
||||
.get(identifier, {})
|
||||
)
|
||||
|
||||
coordinates = location_dict.get("coordinates")
|
||||
if coordinates is None:
|
||||
coordinates = full_location_dict.get("coordinates", {})
|
||||
|
||||
dimensions = location_dict.get("dimensions")
|
||||
if dimensions is None:
|
||||
dimensions = full_location_dict.get("dimensions", {})
|
||||
|
||||
location_data = {
|
||||
"name": location_dict.get("name", full_location_dict.get("name", "Unknown")),
|
||||
"identifier": identifier,
|
||||
"owner": owner_steamid,
|
||||
"shape": location_dict.get("shape", full_location_dict.get("shape", "circle")),
|
||||
"coordinates": {
|
||||
"x": float(coordinates.get("x", 0)),
|
||||
"y": float(coordinates.get("y", 0)),
|
||||
"z": float(coordinates.get("z", 0))
|
||||
},
|
||||
"dimensions": dimensions,
|
||||
"teleport_entry": location_dict.get("teleport_entry", full_location_dict.get("teleport_entry", {})),
|
||||
"type": location_dict.get("type", full_location_dict.get("type", [])),
|
||||
"is_enabled": location_dict.get("is_enabled", full_location_dict.get("is_enabled", False))
|
||||
}
|
||||
|
||||
module.webserver.send_data_to_client_hook(
|
||||
module,
|
||||
payload={
|
||||
"location_id": location_id,
|
||||
"location": location_data
|
||||
},
|
||||
data_type="location_update",
|
||||
clients=[clientid]
|
||||
)
|
||||
|
||||
elif method in ["remove"]:
|
||||
# Send location removal
|
||||
location_origin = updated_values_dict[2]
|
||||
owner_steamid = updated_values_dict[3]
|
||||
location_identifier = updated_values_dict[-1]
|
||||
location_id = f"{location_origin}_{owner_steamid}_{location_identifier}"
|
||||
|
||||
module.webserver.send_data_to_client_hook(
|
||||
module,
|
||||
payload={
|
||||
"location_id": location_id
|
||||
},
|
||||
data_type="location_remove",
|
||||
clients=[clientid]
|
||||
)
|
||||
|
||||
|
||||
trigger_meta = {
|
||||
"description": "sends location updates to webmap clients",
|
||||
"main_function": send_location_update_to_map,
|
||||
"handlers": {
|
||||
"module_locations/elements/%map_identifier%/%owner_steamid%/%element_identifier%":
|
||||
send_location_update_to_map,
|
||||
}
|
||||
}
|
||||
|
||||
loaded_modules_dict["module_" + module_name].register_trigger(trigger_name, trigger_meta)
|
||||
61
bot/modules/locations/triggers/player_died.py
Normal file
61
bot/modules/locations/triggers/player_died.py
Normal file
@@ -0,0 +1,61 @@
|
||||
from bot import loaded_modules_dict
|
||||
from bot import telnet_prefixes
|
||||
from os import path, pardir
|
||||
|
||||
module_name = path.basename(path.normpath(path.join(path.abspath(__file__), pardir, pardir)))
|
||||
trigger_name = path.basename(path.abspath(__file__))[:-3]
|
||||
|
||||
|
||||
def main_function(origin_module, module, regex_result):
|
||||
player_name = regex_result.group("player_name")
|
||||
command = regex_result.group("command")
|
||||
|
||||
active_dataset = module.dom.data.get("module_game_environment", {}).get("active_dataset", None)
|
||||
all_players_dict = (
|
||||
module.dom.data
|
||||
.get("module_players", {})
|
||||
.get("elements", {})
|
||||
.get(active_dataset)
|
||||
)
|
||||
|
||||
steamid = None
|
||||
servertime_player_died = "n/A"
|
||||
for player_steamid, player_dict in all_players_dict.items():
|
||||
if player_dict["name"] == player_name:
|
||||
steamid = player_steamid
|
||||
servertime_player_died = player_dict.get("last_seen_gametime", servertime_player_died)
|
||||
break
|
||||
|
||||
if steamid is None:
|
||||
return
|
||||
|
||||
if command == 'died':
|
||||
event_data = ['edit_location', {
|
||||
'location_coordinates': {
|
||||
"x": player_dict["pos"]["x"],
|
||||
"y": player_dict["pos"]["y"],
|
||||
"z": player_dict["pos"]["z"]
|
||||
},
|
||||
'location_name': "Place of Death",
|
||||
'action': 'edit',
|
||||
'location_enabled': True,
|
||||
'last_changed': servertime_player_died
|
||||
}]
|
||||
module.trigger_action_hook(origin_module, event_data=event_data, dispatchers_steamid=steamid)
|
||||
|
||||
|
||||
trigger_meta = {
|
||||
"description": "reacts to telnets player dying message",
|
||||
"main_function": main_function,
|
||||
"triggers": [
|
||||
{
|
||||
"regex": (
|
||||
telnet_prefixes["telnet_log"]["timestamp"] +
|
||||
telnet_prefixes["GMSG"]["command"]
|
||||
),
|
||||
"callback": main_function
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
loaded_modules_dict["module_" + module_name].register_trigger(trigger_name, trigger_meta)
|
||||
63
bot/modules/locations/triggers/playerspawn.py
Normal file
63
bot/modules/locations/triggers/playerspawn.py
Normal file
@@ -0,0 +1,63 @@
|
||||
from bot import loaded_modules_dict
|
||||
from bot import telnet_prefixes
|
||||
from os import path, pardir
|
||||
|
||||
module_name = path.basename(path.normpath(path.join(path.abspath(__file__), pardir, pardir)))
|
||||
trigger_name = path.basename(path.abspath(__file__))[:-3]
|
||||
|
||||
|
||||
def main_function(origin_module, module, regex_result):
|
||||
command = regex_result.group("command")
|
||||
if command != "EnterMultiplayer":
|
||||
return
|
||||
|
||||
active_dataset = module.dom.data.get("module_game_environment", {}).get("active_dataset", None)
|
||||
|
||||
player_dict = {
|
||||
"pos": {
|
||||
"x": regex_result.group("pos_x"),
|
||||
"y": regex_result.group("pos_y"),
|
||||
"z": regex_result.group("pos_z")
|
||||
}
|
||||
}
|
||||
player_steamid = regex_result.group("player_steamid")
|
||||
first_seen_gametime_string = module.game_environment.get_last_recorded_gametime_string()
|
||||
|
||||
event_data = ['edit_location', {
|
||||
'location_owner': player_steamid,
|
||||
'location_coordinates': {
|
||||
"x": player_dict["pos"]["x"],
|
||||
"y": player_dict["pos"]["y"],
|
||||
"z": player_dict["pos"]["z"]
|
||||
},
|
||||
'location_name': "Initial Spawn",
|
||||
'action': 'create_new',
|
||||
'location_enabled': True,
|
||||
'last_changed': first_seen_gametime_string
|
||||
}]
|
||||
module.trigger_action_hook(origin_module, event_data=event_data)
|
||||
|
||||
|
||||
trigger_meta = {
|
||||
"description": "reacts to any initial playerspawn",
|
||||
"main_function": main_function,
|
||||
"triggers": [
|
||||
{
|
||||
"regex": (
|
||||
telnet_prefixes["telnet_log"]["timestamp"] +
|
||||
r"PlayerSpawnedInWorld\s"
|
||||
r"\("
|
||||
r"reason: (?P<command>.+?),\s"
|
||||
r"position: (?P<pos_x>.*),\s(?P<pos_y>.*),\s(?P<pos_z>.*)"
|
||||
r"\):\s"
|
||||
r"EntityID=(?P<entity_id>.*),\s"
|
||||
r"PlayerID='(?P<player_steamid>.*)',\s"
|
||||
r"OwnerID='(?P<owner_steamid>.*)',\s"
|
||||
r"PlayerName='(?P<player_name>.*)'"
|
||||
),
|
||||
"callback": main_function
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
loaded_modules_dict["module_" + module_name].register_trigger(trigger_name, trigger_meta)
|
||||
86
bot/modules/locations/triggers/zombiespawn.py
Normal file
86
bot/modules/locations/triggers/zombiespawn.py
Normal file
@@ -0,0 +1,86 @@
|
||||
from bot import loaded_modules_dict
|
||||
from bot import telnet_prefixes
|
||||
from os import path, pardir
|
||||
|
||||
module_name = path.basename(path.normpath(path.join(path.abspath(__file__), pardir, pardir)))
|
||||
trigger_name = path.basename(path.abspath(__file__))[:-3]
|
||||
|
||||
|
||||
def main_function(origin_module, module, regex_result):
|
||||
position_dict = {
|
||||
"pos": {
|
||||
"x": regex_result.group("pos_x"),
|
||||
"y": regex_result.group("pos_y"),
|
||||
"z": regex_result.group("pos_z")
|
||||
}
|
||||
}
|
||||
zombie_id = regex_result.group("entity_id")
|
||||
zombie_name = regex_result.group("zombie_name")
|
||||
|
||||
screamer_safe_locations = []
|
||||
found_screamer_safe_location = False
|
||||
for screamer_safe_location in origin_module.get_elements_by_type("is_screamerfree"):
|
||||
screamer_safe_locations.append(screamer_safe_location)
|
||||
found_screamer_safe_location = True
|
||||
|
||||
active_dataset = module.dom.data.get("module_game_environment", {}).get("active_dataset", None)
|
||||
if zombie_name == "zombieScreamer":
|
||||
for location_dict in screamer_safe_locations:
|
||||
if origin_module.locations.position_is_inside_boundary(position_dict, location_dict):
|
||||
event_data = ['manage_entities', {
|
||||
'dataset': active_dataset,
|
||||
'entity_id': zombie_id,
|
||||
'entity_name': zombie_name,
|
||||
'action': 'kill'
|
||||
}]
|
||||
# no steamid cause it's a system_call
|
||||
module.trigger_action_hook(origin_module.game_environment, event_data=event_data)
|
||||
|
||||
event_data = ['say_to_all', {
|
||||
'message': (
|
||||
'[FF6666]Screamer ([FFFFFF]{entity_id}[FF6666]) spawned[-] '
|
||||
'[FFFFFF]inside [CCCCFF]{location_name}[FFFFFF].[-]'.format(
|
||||
entity_id=zombie_id,
|
||||
location_name=location_dict.get("name")
|
||||
)
|
||||
)
|
||||
}]
|
||||
module.trigger_action_hook(origin_module.game_environment, event_data=event_data)
|
||||
# we only need to match one location. even though a screamer can be in multiple locations at once,
|
||||
# we still only have to kill it once :)
|
||||
break
|
||||
else:
|
||||
if found_screamer_safe_location:
|
||||
event_data = ['say_to_all', {
|
||||
'message': (
|
||||
'[FF6666]Screamer ([FFFFFF]{entity_id}[FF6666]) spawned[-] '
|
||||
'[CCCCFF]somewhere[FFFFFF]...[-]'.format(
|
||||
entity_id=zombie_id
|
||||
)
|
||||
)
|
||||
}]
|
||||
module.trigger_action_hook(origin_module.game_environment, event_data=event_data)
|
||||
|
||||
|
||||
trigger_meta = {
|
||||
"description": "reacts to spawning zombies (screamers, mostly)",
|
||||
"main_function": main_function,
|
||||
"triggers": [
|
||||
{
|
||||
"regex": (
|
||||
telnet_prefixes["telnet_log"]["timestamp"] +
|
||||
r"(?P<command>.+?)\s"
|
||||
r"\["
|
||||
r"type=(.*),\s"
|
||||
r"name=(?P<zombie_name>.+?),\s"
|
||||
r"id=(?P<entity_id>.*)\]\sat\s\((?P<pos_x>.*),\s(?P<pos_y>.*),\s(?P<pos_z>.*)\)\s"
|
||||
r"Day=(\d.*)\s"
|
||||
r"TotalInWave=(\d.*)\s"
|
||||
r"CurrentWave=(\d.*)"
|
||||
),
|
||||
"callback": main_function
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
loaded_modules_dict["module_" + module_name].register_trigger(trigger_name, trigger_meta)
|
||||
Reference in New Issue
Block a user