def handle_player_received_memory(entity, memory, message, member_id): _member = entities.get_entity(member_id) ui_dialog.create(5, 5, message, title='Dialog with %s' % _member['stats']['name']) _m = ui_menu.create(5, 15, title='Respond') for life_id in memory: if not life_id in entity['ai']['life_memory']: life.create_life_memory(entity, life_id) entity['ai']['life_memory'][life_id].update(memory[life_id]) ui_menu.add_selectable(_m, 'Bribe', lambda: 1==1 and ui_dialog.delete(ui_dialog.ACTIVE_DIALOG)) ui_menu.add_selectable(_m, 'Leave', lambda: 1==1 and ui_dialog.delete(ui_dialog.ACTIVE_DIALOG))
def focus_on_entity(entity, target_id, show_line=False, pause=False): global HAS_FOCUS, PAUSE if HAS_FOCUS or '--no-fx' in sys.argv: return HAS_FOCUS = target_id PAUSE = pause _entity = ui_dialog.create(18, 7, 'Enemy spotted!') entities.register_event(_entity, 'delete', lambda e: lose_focus()) entities.trigger_event(DIRECTOR, 'create_timer', time=120, exit_callback=lambda e: ui_dialog.delete(_entity)) if show_line: for x, y in shapes.line(movement.get_position(entity), movement.get_position_via_id(target_id)): effects.vapor(x, y, group='effects_freetick', start_alpha=1.0, fade_rate=.01)
def corpse(x, y, char, owner_id): _entity = _create(x, y, '', char, 4, 'corpse', fore_color=(130, 110, 110)) _entity['owner_id'] = owner_id entities.register_event(_entity, 'seen', _corpse_seen) entities.register_event( _entity, 'get_interactions', lambda e, menu, target_id: ui_menu.add_selectable( menu, 'Examine', lambda: ui_dialog.create(x - camera.X, y - camera. Y, 'Dead?'))) return _entity
def handle_player_received_memory(entity, memory, message, member_id): _member = entities.get_entity(member_id) ui_dialog.create(5, 5, message, title='Dialog with %s' % _member['stats']['name']) _m = ui_menu.create(5, 15, title='Respond') for life_id in memory: if not life_id in entity['ai']['life_memory']: life.create_life_memory(entity, life_id) entity['ai']['life_memory'][life_id].update(memory[life_id]) ui_menu.add_selectable( _m, 'Bribe', lambda: 1 == 1 and ui_dialog.delete(ui_dialog.ACTIVE_DIALOG)) ui_menu.add_selectable( _m, 'Leave', lambda: 1 == 1 and ui_dialog.delete(ui_dialog.ACTIVE_DIALOG))
def _shoot_weapon(entity, weapon_id, target_id): _weapon = entities.get_entity(weapon_id) _x, _y = movement.get_position( entities.get_entity(_weapon['stats']['owner'])) if not target_id in entities.ENTITIES: logging.warning('Target deleted during shooting.') return _tx, _ty = movement.get_position(entities.get_entity(target_id)) _direction = numbers.direction_to((_x, _y), (_tx, _ty)) effects.muzzle_flash(_x, _y, _direction) entities.trigger_event(_weapon, 'flag_sub', flag='ammo', value=1) entities.trigger_event(entity, 'create_noise', volume=80, direction=numbers.direction_to((_x, _y), (_tx, _ty)), text='BAM', callback=lambda t, x, y: entities.trigger_event( t, 'update_target_memory', target_id=entity['_id'], key='last_seen_at', value=[x, y]), context_callback=lambda x, y: ui_dialog.create( x, y, 'Gunshot (Unknown)', title='Noise')) entity['stats']['action_points'] -= stats.get_shoot_cost(entity, weapon_id) entities.trigger_event(entity, 'get_accuracy') _accuracy = stats.get_accuracy(entity, weapon_id) _damage = flags.get_flag(_weapon, 'damage') effects.light(_x, _y, random.randint(3, 5), r=1.5, g=1.5, b=0) if _weapon['stats']['kind'] == 'explosive': items.explosive(entity, _x, _y, _tx, _ty, 4, _accuracy, _damage) else: items.bullet(entity, _x, _y, _tx, _ty, 1, _accuracy, _damage)
def _shoot_weapon(entity, weapon_id, target_id): _weapon = entities.get_entity(weapon_id) _x, _y = movement.get_position(entities.get_entity(_weapon['stats']['owner'])) if not target_id in entities.ENTITIES: logging.warning('Target deleted during shooting.') return _tx, _ty = movement.get_position(entities.get_entity(target_id)) _direction = numbers.direction_to((_x, _y), (_tx, _ty)) effects.muzzle_flash(_x, _y, _direction) entities.trigger_event(_weapon, 'flag_sub', flag='ammo', value=1) entities.trigger_event(entity, 'create_noise', volume=80, direction=numbers.direction_to((_x, _y), (_tx, _ty)), text='BAM', callback=lambda t, x, y: entities.trigger_event(t, 'update_target_memory', target_id=entity['_id'], key='last_seen_at', value=[x, y]), context_callback=lambda x, y: ui_dialog.create(x, y, 'Gunshot (Unknown)', title='Noise')) entity['stats']['action_points'] -= stats.get_shoot_cost(entity, weapon_id) entities.trigger_event(entity, 'get_accuracy') _accuracy = stats.get_accuracy(entity, weapon_id) _damage = flags.get_flag(_weapon, 'damage') effects.light(_x, _y, random.randint(3, 5), r=1.5, g=1.5, b=0) if _weapon['stats']['kind'] == 'explosive': items.explosive(entity, _x, _y, _tx, _ty, 4, _accuracy, _damage) else: items.bullet(entity, _x, _y, _tx, _ty, 1, _accuracy, _damage)
def corpse(x, y, char, owner_id): _entity = _create(x, y, '', char, 4, 'corpse', fore_color=(130, 110, 110)) _entity['owner_id'] = owner_id entities.register_event(_entity, 'seen', _corpse_seen) entities.register_event(_entity, 'get_interactions', lambda e, menu, target_id: ui_menu.add_selectable(menu, 'Examine', lambda: ui_dialog.create(x-camera.X, y-camera.Y, 'Dead?'))) return _entity
def get_mission_briefing(mission): ui_dialog.create(5, 5, mission['briefing'], title='Mission: %s' % mission['title'])
def handle_mouse_pressed(entity, x, y, button): global DRAGGING_NODE, LAST_CLICKED_POS, SELECTING_TARGET_CALLBACK if ui_menu.get_active_menu() or ui_menu.DELAY: return if timers.has_timer_with_name(entity, 'passout'): return _x = x+camera.X _y = y+camera.Y if button == 1: if DRAGGING_NODE: DRAGGING_NODE = None elif not (_x, _y) in zones.get_active_solids(entity): if not DRAGGING_NODE: for entity_id in [t for t in entity['ai']['visible_life'] if entity['ai']['life_memory'][t]['can_see']]: if entity['_id'] == entity_id: continue _entity = entities.get_entity(entity_id) _tx, _ty = movement.get_position(_entity) if (_x, _y) == (_tx, _ty): if SELECTING_TARGET_CALLBACK: SELECTING_TARGET_CALLBACK(entity, entity_id) SELECTING_TARGET_CALLBACK = None else: LAST_CLICKED_POS = (_x, _y) create_life_interact_menu(entity, entity_id) return else: for entity_id in entities.get_entity_group('contexts'): _entity = entities.get_entity(entity_id) if not _entity['callback']: continue if (_entity['tile']['x'], _entity['tile']['y']) == (_x, _y): _entity['callback'](x+2, y-3) return else: for entity_id in list(entity['ai']['targets'] - entity['ai']['visible_life']): _tx, _ty = entity['ai']['life_memory'][entity_id]['last_seen_at'] if (_tx, _ty-2) == (_x, _y): ui_dialog.create(x + 2, y - 3, '%s - Last seen <time>' % entities.get_entity(entity_id)['stats']['name']) return else: for entity_id in entities.get_entity_group('items'): _item = entities.get_entity(entity_id) if _item['stats']['owner']: continue if (_x, _y) == movement.get_position(_item): create_item_menu(entity, _item, _x, _y) return create_walk_node(entity, _x, _y, clear=True) return for node in entity['node_grid']['nodes'].values(): if (_x, _y) == (node['node']['x'], node['node']['y']): DRAGGING_NODE = node entities.trigger_event(DRAGGING_NODE['node'], 'set_fore_color', color=(255, 255, 0)) break if (_x, _y) in node['node']['path']: if not (_x, _y) in node['node']['busy_pos']: LAST_CLICKED_POS = (_x, _y) create_action_menu(entity, LAST_CLICKED_POS[0], LAST_CLICKED_POS[1], on_path=True) else: LAST_CLICKED_POS = None return elif button == 2: if DRAGGING_NODE: entities.trigger_event(DRAGGING_NODE['node'], 'set_fore_color', color=(255, 255, 255)) DRAGGING_NODE = None else: for node in entity['node_grid']['nodes'].values(): if (_x, _y) == (node['node']['x'], node['node']['y']): entity['node_grid']['path'].remove(node['node']['_id']) entities.delete_entity(node['node']) redraw_path(entity) del entity['node_grid']['nodes'][node['node']['_id']] if not entity['node_grid']['nodes']: clear_path(entity) break else: create_walk_node(entity, _x, _y)
def handle_mouse_pressed(entity, x, y, button): global DRAGGING_NODE, LAST_CLICKED_POS, SELECTING_TARGET_CALLBACK if ui_menu.get_active_menu() or ui_menu.DELAY: return if timers.has_timer_with_name(entity, 'passout'): return _x = x + camera.X _y = y + camera.Y if button == 1: if DRAGGING_NODE: DRAGGING_NODE = None elif not (_x, _y) in zones.get_active_solids(entity): if not DRAGGING_NODE: for entity_id in [ t for t in entity['ai']['visible_life'] if entity['ai']['life_memory'][t]['can_see'] ]: if entity['_id'] == entity_id: continue _entity = entities.get_entity(entity_id) _tx, _ty = movement.get_position(_entity) if (_x, _y) == (_tx, _ty): if SELECTING_TARGET_CALLBACK: SELECTING_TARGET_CALLBACK(entity, entity_id) SELECTING_TARGET_CALLBACK = None else: LAST_CLICKED_POS = (_x, _y) create_life_interact_menu(entity, entity_id) return else: for entity_id in entities.get_entity_group('contexts'): _entity = entities.get_entity(entity_id) if not _entity['callback']: continue if (_entity['tile']['x'], _entity['tile']['y']) == (_x, _y): _entity['callback'](x + 2, y - 3) return else: for entity_id in list(entity['ai']['targets'] - entity['ai']['visible_life']): _tx, _ty = entity['ai']['life_memory'][entity_id][ 'last_seen_at'] if (_tx, _ty - 2) == (_x, _y): ui_dialog.create( x + 2, y - 3, '%s - Last seen <time>' % entities.get_entity( entity_id)['stats']['name']) return else: for entity_id in entities.get_entity_group( 'items'): _item = entities.get_entity(entity_id) if _item['stats']['owner']: continue if (_x, _y) == movement.get_position(_item): create_item_menu(entity, _item, _x, _y) return create_walk_node(entity, _x, _y, clear=True) return for node in entity['node_grid']['nodes'].values(): if (_x, _y) == (node['node']['x'], node['node']['y']): DRAGGING_NODE = node entities.trigger_event(DRAGGING_NODE['node'], 'set_fore_color', color=(255, 255, 0)) break if (_x, _y) in node['node']['path']: if not (_x, _y) in node['node']['busy_pos']: LAST_CLICKED_POS = (_x, _y) create_action_menu(entity, LAST_CLICKED_POS[0], LAST_CLICKED_POS[1], on_path=True) else: LAST_CLICKED_POS = None return elif button == 2: if DRAGGING_NODE: entities.trigger_event(DRAGGING_NODE['node'], 'set_fore_color', color=(255, 255, 255)) DRAGGING_NODE = None else: for node in entity['node_grid']['nodes'].values(): if (_x, _y) == (node['node']['x'], node['node']['y']): entity['node_grid']['path'].remove(node['node']['_id']) entities.delete_entity(node['node']) redraw_path(entity) del entity['node_grid']['nodes'][node['node']['_id']] if not entity['node_grid']['nodes']: clear_path(entity) break else: create_walk_node(entity, _x, _y)