def _trap_activation_describe(mud, id, players, room_id, rooms, penalty_value, trap_tag): trap_type = rooms[room_id]['trap']['trapType'] if trap_type in ('net', 'chain net'): if rooms[room_id]['trap']['trap_activation'].startswith('pressure'): desc = (trap_tag + "You hear a click as you step onto a pressure plate. A " + trap_type + " falls from above and pins you down") mud.send_message(id, random_desc(desc) + '.<r>\n\n') else: desc = (trap_tag + "A " + trap_type + " falls from above and pins you down") mud.send_message(id, random_desc(desc) + '.<r>\n\n') elif trap_type in ('pit', 'tar pit'): desc = (trap_tag + "You fall into a " + trap_type) mud.send_message(id, random_desc(desc) + '.<r>\n\n') elif trap_type in ('ditch', 'marsh', 'bog'): desc = (trap_tag + "You fall into a muddy " + trap_type, trap_tag + "You slip and fall into a muddy " + trap_type) mud.send_message(id, random_desc(desc) + '.<r>\n\n') elif trap_type.startswith('dart'): desc = (trap_tag + "Poisoned darts emerge from holes in the wall and " + "sting you for <r><f15><b88>* " + str(penalty_value) + " *<r>" + trap_tag + " hit points") mud.send_message(id, random_desc(desc) + '.<r>\n\n')
def escape_from_trap(mud, id, players: {}, rooms: {}, items_db: {}): """Attempt to escape from a trap """ room_id = players[id]['room'] if not rooms[room_id]['trap'].get('trapEscapeMethod'): mud.send_message(id, random_desc("Nothing happens") + '.\n\n') return escape_method = rooms[room_id]['trap']['trapEscapeMethod'] if 'slash' in escape_method: _escape_with_cutting_tool(mud, id, players, rooms, items_db) else: mud.send_message(id, random_desc("Nothing happens") + '.\n\n')
def trap_activation(mud, id, players: {}, rooms: {}, exit_direction): """Activates a trap """ room_id = players[id]['room'] if not rooms[room_id]['trap'].get('trap_activation'): return False # Is the trap already activated? if rooms[room_id]['trap']['trap_activationTime'] != 0: return False trap_tag = '<f202>' # recognised activation type activation_type = rooms[room_id]['trap']['trap_activation'] if not (activation_type == 'tripwire' or activation_type.startswith('move') or activation_type.startswith('pressure')): return False # probability of the trap being activated prob = 100 if rooms[room_id]['trap'].get('trap_activationProbability'): prob = rooms[room_id]['trap']['trap_activationProbability'] rand_percent = randint(1, 100) if rand_percent > prob: return False # which exit activates the trap? if not rooms[room_id]['trap'].get('trapExit'): return False # are we going in that direction? if rooms[room_id]['trap']['trapExit'] != exit_direction: return False # add player to the list of trapped ones rooms[room_id]['trap']['trappedPlayers'] = [players[id]['name']] # record the time when the trap was activated if time_string_to_sec(rooms[room_id]['trap']['trapDuration']) > 0: rooms[room_id]['trap']['trap_activationTime'] = \ int(time.time()) # reset the amount of damage to the trap rooms[room_id]['trap']['trapDamaged'] = 0 # subtract a trap penalty from the player penalty_type = rooms[room_id]['trap']['trapPenaltyType'] penalty_value = randint(1, rooms[room_id]['trap']['trapPenalty']) players[id][penalty_type] -= penalty_value # describe the trapped player if len(rooms[room_id]['trap']['trap_activationDescription']) > 0: desc = rooms[room_id]['trap']['trap_activationDescription'] mud.send_message(id, trap_tag + random_desc(desc) + '.<r>\n\n') else: _trap_activation_describe(mud, id, players, room_id, rooms, penalty_value, trap_tag) return True
def _describe_trap_deactivation(mud, room_id, trap, players: {}): """Describes when a trap gets reset """ for pid in players: if players[pid]['name'] is None: continue if players[pid]['room'] != room_id: continue if players[pid]['name'] not in trap['trappedPlayers']: continue if trap['trapType'] == 'net' or \ trap['trapType'] == 'chain net': desc = 'The ' + trap['trapType'] + ' lifts and you escape' mud.send_message(pid, random_desc(desc) + '.\n\n') elif trap['trapType'] == 'pit' or trap['trapType'] == 'tar pit': desc = 'You clamber out from the ' + \ trap['trapType'] mud.send_message(pid, random_desc(desc) + '.\n\n') elif (trap['trapType'] == 'ditch' or trap['trapType'] == 'marsh' or trap['trapType'] == 'bog'): desc = 'With squelching noises, you climb out of the muddy ' + \ trap['trapType'] mud.send_message(pid, random_desc(desc) + '.\n\n')
def describe_trapped_player(mud, id, players: {}, rooms: {}): """Describes being in a trap """ room_id = players[id]['room'] if not rooms[room_id]['trap'].get('trapType'): return trap_type = rooms[room_id]['trap']['trapType'] if trap_type == 'net': desc = ("You struggle with the net but it's pinning you down", "You seem to be trapped in a net", "Being covered by a net makes it difficult to move") mud.send_message(id, random_desc(desc) + '.\n\n') elif trap_type == 'chain net': desc = ("You struggle with the net but its chain webbing is " + "pinning you down", "You seem to be trapped in a net made from linked chains", "Being covered by a chain net makes it difficult to move") mud.send_message(id, random_desc(desc) + '.\n\n') elif trap_type == 'tar pit': desc = ("You have sunk into a pit of sticky tar, " + "which prevents you from moving", "Sticky tar surrounds you, preventing you from moving") mud.send_message(id, random_desc(desc) + '.\n\n') elif trap_type == 'pit': desc = ("You have fallen into a pit in the ground, which you " + "don't seem to be able to get out from", "You appear to be in a hole in the ground") mud.send_message(id, random_desc(desc) + '.\n\n') elif trap_type in ('ditch', 'marsh', 'bog'): desc = ("You have fallen into a " + trap_type + " full of thick mud, " + "which is too slippery to get out from", "You appear to be swimming very slowly in a " + trap_type + " full of thick mud") mud.send_message(id, random_desc(desc) + '.\n\n')
def _escape_with_cutting_tool(mud, id, players: {}, rooms: {}, items_db: {}): """Escape from a trap using a cutting tool """ item_id = _holding_cutting_weapon(id, players, items_db) if item_id == -1: desc = ("You attempt to escape with your bare hands, " + "but remain trapped|You tug and wrestle but can't escape", "Looks like you need to use a cutting tool, otherwise " + "you'll be here for a while", "Looks like you need something to cut with") mud.send_message(id, random_desc(desc) + '.\n\n') return room_id = players[id]['room'] max_trap_damage = rooms[room_id]['trap']['trapDamagedMax'] tool_damage_max = items_db[item_id]['mod_str'] slashing_damage = randint(1, tool_damage_max) trap_damage = \ rooms[room_id]['trap']['trapDamaged'] + slashing_damage if trap_damage < max_trap_damage: rooms[room_id]['trap']['trapDamaged'] = trap_damage damage_str = ', causing <f15><b2>* ' + str(slashing_damage) + \ ' *<r> points of damage to it' desc = 'You slash at the ' + rooms[room_id]['trap']['trapType'] + \ damage_str + '|You cut the ' + \ rooms[room_id]['trap']['trapType'] + damage_str mud.send_message(id, random_desc(desc) + '.\n\n') else: rooms[room_id]['trap']['trapDamaged'] = 0 rooms[room_id]['trap']['trappedPlayers'].clear() if len(rooms[room_id]['trap']['trapEscapeDescription']) > 0: desc = rooms[room_id]['trap']['trapEscapeDescription'] mud.send_message(id, random_desc(desc) + '.\n\n') else: desc = 'You cut a large hole in the ' + \ rooms[room_id]['trap']['trapType'] + ' and escape' mud.send_message(id, random_desc(desc) + '.\n\n')
def familiar_sight(mud, nid, npcs, npcs_db, rooms, players, id, items, items_db): """familiar reports what it sees """ start_room_id = npcs[nid]['room'] room_exits = rooms[start_room_id]['exits'] mud.send_message(id, "Your familiar says:\n") if len(room_exits) == 0: mud.send_message(id, "There are no exits.") else: if len(room_exits) > 1: mud.send_message(id, "There are " + str(len(room_exits)) + " exits.") else: exit_description = random_desc("a single|one") mud.send_message(id, "There is " + exit_description + " exit.") creatures_count = 0 creatures_friendly = 0 creatures_races = [] for plyr in players: if players[plyr]['name'] is None: continue if players[plyr]['room'] == npcs[nid]['room']: creatures_count = creatures_count + 1 if players[plyr]['race'] not in creatures_races: creatures_races.append(players[plyr]['race']) for name, value in players[plyr]['affinity'].items(): if npcs[nid]['familiarOf'] == name: if value >= 0: creatures_friendly = creatures_friendly + 1 for n_co in npcs: if n_co != nid: if npcs[n_co]['room'] == npcs[nid]['room']: creatures_count = creatures_count + 1 if npcs[n_co].get('race'): if npcs[n_co]['race'] not in creatures_races: creatures_races.append(npcs[n_co]['race']) if npcs[n_co].get('affinity'): for name, value in npcs[n_co]['affinity'].items(): if npcs[nid]['familiarOf'] == name: if value >= 0: creatures_friendly = creatures_friendly + 1 if creatures_count > 0: creature_str = random_desc("creature|being|entity") creatures_msg = 'I see ' if creatures_count > 1: creatures_msg = creatures_msg + str(creatures_count) + ' ' + \ creature_str + 's' else: creatures_msg = creatures_msg + 'one ' + creature_str creatures_msg = creatures_msg + ' here.' friendly_word = \ random_desc("friendly|nice|pleasing|not threatening") if creatures_friendly > 0: if creatures_friendly > 1: creatures_msg = creatures_msg + ' ' + \ str(creatures_friendly) + ' are ' + friendly_word + '.' else: if creatures_friendly == creatures_count: creatures_msg = \ creatures_msg + ' They are ' + friendly_word + '.' else: creatures_msg = \ creatures_msg + ' One is ' + friendly_word + '.' creatures_msg = creatures_msg + '\n' if len(creatures_races) > 0: creatures_msg = creatures_msg + 'They are ' if len(creatures_races) == 1: creatures_msg = \ creatures_msg + '<f220>' + creatures_races[0] + 's<r>.' else: if len(creatures_races) == 2: creatures_msg = \ creatures_msg + '<f220>' + creatures_races[0] + \ 's<r> and <f220>' + creatures_races[1] + 's<r>.' else: ctr = 0 for rac in creatures_races: if ctr == 0: creatures_msg = \ creatures_msg + '<f220>' + rac + 's<r>' if ctr > 0: if ctr < len(creatures_races) - 1: creatures_msg = \ creatures_msg + ', <f220>' + rac + 's<r>' else: creatures_msg = \ creatures_msg + ' and <f220>' + \ rac + 's<r>.' ctr = ctr + 1 mud.send_message(id, creatures_msg) items_in_room = 0 weapons_in_room = 0 armor_in_room = 0 edible_in_room = 0 for iid, _ in list(items.items()): if items[iid]['room'] == npcs[nid]['room']: if items[iid].get('weight'): if items[iid]['weight'] > 0: items_in_room += 1 if (items[iid]['mod_str'] > 0 and (items[iid]['clo_lhand'] > 0 or items[iid]['clo_rhand'] > 0)): weapons_in_room += 1 if items[iid]['mod_endu'] > 0 and \ items[iid]['clo_chest'] > 0: armor_in_room += 1 if items[iid]['edible'] != 0: edible_in_room += 1 if armor_in_room > 0 and weapons_in_room > 0: mud.send_message(id, 'There are some weapons and armor here.') else: if armor_in_room > 0: mud.send_message(id, 'There is some armor here.') else: if weapons_in_room > 0: mud.send_message(id, 'There are some weapons here.') else: mud.send_message(id, 'There are some items here.') if edible_in_room: mud.send_message(id, 'There are some edibles here.') mud.send_message(id, '\n\n')
def _catch_fish(players: {}, id, rooms: {}, items_db: {}, mud) -> None: """The player catches a fish """ if randint(1, 100) < 80: return rid = players[id]['room'] if not holding_fishing_rod(players, id, items_db): return if not is_fishing_site(rooms, rid): return room_name_lower = rooms[rid]['name'].lower() fish_names = [] fishing_season = { "carp": [4, 5, 6, 7, 8, 9, 10, 11, 12], "pike fish": [1, 2, 3, 9, 10, 11, 12], "minnow": [], "tench": [], "chub": [1, 2, 3, 6, 7, 8, 9, 10, 11, 12], "trout": [1, 2, 3, 4, 5, 6, 9, 10, 11, 12], "cod fish": [1, 2, 10, 11, 12], "haddock": [1, 9, 10, 11, 12], "turbot": [1, 9, 10, 11, 12], "sturgeon": [], "dogfish": [4, 5, 6, 7, 8, 9, 10], "pollack": [4, 5, 6, 7, 8, 9, 10], "sea bass": [5, 6, 7, 8, 9, 10, 11, 12], "mullet": [5, 6, 7, 8, 9, 10, 11, 12] } if 'lake' in room_name_lower: fish_names = ('carp', 'pike fish', 'minnow', 'tench') elif 'river' in room_name_lower: fish_names = ('trout', 'chub') elif 'sea' in room_name_lower or 'ocean' in room_name_lower: if not holding_fly_fishing_rod(players, id, items_db): fish_names = ('cod fish', 'haddock', 'turbot', 'sturgeon', 'dogfish', 'pollack', 'sea bass', 'mullet') else: fish_names = ('sea bass', 'mullet') elif 'pond' in room_name_lower: if not holding_fly_fishing_rod(players, id, items_db): fish_names = ('pond weed') if not fish_names: return fish_ids = [] curr_month_number = int(datetime.datetime.today().strftime("%m")) no_of_fish = 0 for iid, item in items_db.items(): if item['edible'] <= 0: continue if item['weight'] <= 0: continue item_name_lower = item['name'].lower() for fish in fish_names: if fish in item_name_lower: if iid in players[id]['inv']: no_of_fish += 1 # is this fishable at this time of year? if fishing_season.get(fish): if curr_month_number in fishing_season[fish]: fish_ids.append(iid) else: fish_ids.append(iid) if no_of_fish > 1: return if not fish_ids: return caught_id = random.choice(fish_ids) if caught_id in players[id]['inv']: return caught_str = \ items_db[caught_id]['article'] + ' ' + items_db[caught_id]['name'] msg_str = random_desc('You catch ' + caught_str) players[id]['inv'].append(caught_id) del players[id]['isFishing'] mud.send_message(id, msg_str + '\n\n')