Beispiel #1
0
def explosive(entity, x, y, tx, ty, speed, accuracy, damage):
	_entity = _create(x, y, 'Explosive', '.', 0, 'bullet')
	_entity['owner'] = entity['_id']
	_entity['start_position'] = (x, y)
	_entity['end_position'] = (tx, ty)
	_entity['speed'] = speed
	_entity['damage'] = damage
	_toss_distance = numbers.distance(_entity['start_position'], _entity['end_position'])
	_entity['accuracy'] = numbers.clip(random.randint(int(round(accuracy * .25)), accuracy), 0, 100) - (accuracy * (1 - (_toss_distance / 20.0)))
	_entity['slow_down'] = False
	_direction_mod = random.uniform(-accuracy, accuracy) * 2
	
	entities.create_event(_entity, 'explode')
	entities.create_event(_entity, 'activate_explosive')
	entities.register_event(_entity, 'explode', frag_grenade_explode)
	entities.register_event(_entity, 'explode', entities.delete_entity)
	entities.register_event(_entity, 'activate_explosive', lambda e: entities.trigger_event(e, 'create_timer', time=90, exit_callback=lambda ee: entities.trigger_event(ee, 'explode')))
	entities.register_event(_entity, 'check_next_position', check_next_position)
	
	entities.add_entity_to_group(_entity, 'bullets')
	timers.register(_entity)
	
	entities.trigger_event(_entity, 'set_direction', direction=numbers.direction_to((x, y), (tx, ty)) + _direction_mod)
	entities.trigger_event(_entity, 'create_timer', time=speed, enter_callback=_explosive_tick, name='movement')
	entities.register_event(_entity, 'position_changed', lambda e, **kwargs: check_for_collisions(e))
	
	if not '--no-fx' in sys.argv:
		entities.register_event(_entity, 'position_changed', lambda e, x, y, **kwargs: _bullet_effects(e, x, y))
	
	entities.register_event(_entity, 'collision_with_entity', lambda e, **kwargs: entities.trigger_event(e, 'activate_explosive'))
	entities.register_event(_entity, 'collision_with_entity', lambda e, **kwargs: _explosive_stop_dumb_hack(e))
	entities.register_event(_entity, 'collision_with_solid', lambda e: timers.stop_timer(e, 'movement'))
	entities.register_event(_entity, 'collision_with_solid', _explosive_stop_dumb_hack)
	entities.register_event(_entity, 'collision_with_solid', lambda e: entities.trigger_event(e, 'activate_explosive'))
Beispiel #2
0
def explosive(entity, x, y, tx, ty, speed, accuracy, damage):
    _entity = _create(x, y, 'Explosive', '.', 0, 'bullet')
    _entity['owner'] = entity['_id']
    _entity['start_position'] = (x, y)
    _entity['end_position'] = (tx, ty)
    _entity['speed'] = speed
    _entity['damage'] = damage
    _toss_distance = numbers.distance(_entity['start_position'],
                                      _entity['end_position'])
    _entity['accuracy'] = numbers.clip(
        random.randint(int(round(accuracy * .25)), accuracy), 0,
        100) - (accuracy * (1 - (_toss_distance / 20.0)))
    _entity['slow_down'] = False
    _direction_mod = random.uniform(-accuracy, accuracy) * 2

    entities.create_event(_entity, 'explode')
    entities.create_event(_entity, 'activate_explosive')
    entities.register_event(_entity, 'explode', frag_grenade_explode)
    entities.register_event(_entity, 'explode', entities.delete_entity)
    entities.register_event(
        _entity, 'activate_explosive', lambda e: entities.trigger_event(
            e,
            'create_timer',
            time=90,
            exit_callback=lambda ee: entities.trigger_event(ee, 'explode')))
    entities.register_event(_entity, 'check_next_position',
                            check_next_position)

    entities.add_entity_to_group(_entity, 'bullets')
    timers.register(_entity)

    entities.trigger_event(_entity,
                           'set_direction',
                           direction=numbers.direction_to(
                               (x, y), (tx, ty)) + _direction_mod)
    entities.trigger_event(_entity,
                           'create_timer',
                           time=speed,
                           enter_callback=_explosive_tick,
                           name='movement')
    entities.register_event(_entity, 'position_changed',
                            lambda e, **kwargs: check_for_collisions(e))

    if not '--no-fx' in sys.argv:
        entities.register_event(
            _entity, 'position_changed',
            lambda e, x, y, **kwargs: _bullet_effects(e, x, y))

    entities.register_event(
        _entity, 'collision_with_entity',
        lambda e, **kwargs: entities.trigger_event(e, 'activate_explosive'))
    entities.register_event(_entity, 'collision_with_entity',
                            lambda e, **kwargs: _explosive_stop_dumb_hack(e))
    entities.register_event(_entity, 'collision_with_solid',
                            lambda e: timers.stop_timer(e, 'movement'))
    entities.register_event(_entity, 'collision_with_solid',
                            _explosive_stop_dumb_hack)
    entities.register_event(
        _entity, 'collision_with_solid',
        lambda e: entities.trigger_event(e, 'activate_explosive'))
Beispiel #3
0
def _locate_npc_message(goal, member_id):
	_target_id = goal['target_id']
	_member = entities.get_entity(member_id)
	_mission = entities.get_entity(goal['mission_id'])
		
	if not _target_id in _member['ai']['life_memory'] or not _member['ai']['life_memory'][_target_id]['last_seen_at']:
		goal['message'] = 'Gather location info on target.'
		
		return
	
	if _member['ai']['life_memory'][_target_id]['is_dead']:
		goal['message'] = 'Confirmed: Target is dead.'
		
		entities.trigger_event(_member, 'complete_goal', mission_id=goal['mission_id'], goal_id=goal['_id'])
	
	elif _member['ai']['life_memory'][_target_id]['can_see']:
		goal['message'] = 'Target in line of sight.'
		
		entities.trigger_event(_member, 'complete_goal', mission_id=goal['mission_id'], goal_id=goal['_id'])
	
	elif _member['ai']['life_memory'][_target_id]['last_seen_at']:
		_direction = numbers.direction_to(movement.get_position(_member), _member['ai']['life_memory'][_target_id]['last_seen_at'])
		_distance = numbers.distance(movement.get_position(_member), _member['ai']['life_memory'][_target_id]['last_seen_at'])
		_real_direction = conversions.get_real_direction(_direction)
		_real_distance = conversions.get_real_distance(_distance)
		
		goal['message'] = 'Target last seen %s meters to the %s' % (_real_distance, _real_direction)
	
	_member['ai']['life_memory'][_target_id]['mission_related'] = True
Beispiel #4
0
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)
Beispiel #5
0
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)
Beispiel #6
0
def create_shoot_menu(entity, target_id):
	_tx, _ty = movement.get_position_via_id(target_id)
	_weapon = entities.get_entity(items.get_items_in_holder(entity, 'weapon')[0])
	_menu = ui_menu.create(_tx-camera.X+2, _ty-camera.Y-4, title='Shoot')
	_accuracy = stats.get_accuracy(entity, _weapon['_id'])
	_x, _y = movement.get_position(entity)
	_direction = numbers.direction_to((_x, _y), (_tx, _ty))
	_final_direction = _direction + (_accuracy * numbers.distance((_x, _y), (_tx, _ty)))
	_spray_accuracy = (100 * (_direction / float(_final_direction)))
	
	entities.trigger_event(_weapon, 'get_actions', menu=_menu)
	ui_menu.add_selectable(_menu, 'Spray (Acc: %.2d)' % _spray_accuracy, lambda: entities.trigger_event(entity, 'shoot', target_id=target_id) and settings.set_tick_mode('normal'))
	ui_menu.add_selectable(_menu, 'Snipe (Acc: %s)' % _accuracy, lambda: _)
Beispiel #7
0
def bullet(entity, x, y, tx, ty, speed, accuracy, damage):
    _entity = _create(x, y, 'Bullet', '.', 0, 'bullet')
    _entity['owner'] = entity['_id']
    _entity['start_position'] = (x, y)
    _entity['end_position'] = (tx, ty)
    _entity['speed'] = speed
    _entity['damage'] = damage

    entities.add_entity_to_group(_entity, 'bullets')
    timers.register(_entity)

    entities.trigger_event(_entity,
                           'set_direction',
                           direction=numbers.direction_to(
                               (x, y),
                               (tx, ty)) + random.uniform(-accuracy, accuracy))
    entities.trigger_event(_entity,
                           'create_timer',
                           time=speed,
                           repeat=-1,
                           enter_callback=_bullet_tick,
                           repeat_callback=_bullet_tick)
    entities.register_event(_entity, 'position_changed',
                            lambda e, **kwargs: check_for_collisions(e))
    entities.register_event(
        _entity, 'collision_with_entity', lambda e, target_id: entities.
        trigger_event(entities.get_entity(target_id), 'hit', projectile=e))
    entities.register_event(_entity, 'collision_with_entity',
                            lambda e, target_id: entities.delete_entity(e))
    entities.register_event(
        _entity, 'collision_with_solid', lambda e: effects.light(
            movement.get_position(e)[0],
            movement.get_position(e)[1], random.randint(3, 4)))
    entities.register_event(_entity, 'collision_with_solid',
                            lambda e: entities.delete_entity(e))
    entities.register_event(
        _entity, 'collision_with_solid',
        lambda e: effects.smoke_cloud(movement.get_position(e)[0],
                                      movement.get_position(e)[1],
                                      random.uniform(2, 2.75),
                                      start_alpha=random.uniform(0.45, .65),
                                      decay_amount=1.5))
    entities.register_event(_entity, 'check_next_position',
                            check_next_position)

    if not '--no-fx' in sys.argv:
        entities.register_event(
            _entity, 'position_changed',
            lambda e, x, y, **kwargs: _bullet_effects(e, x, y))
Beispiel #8
0
def create_shoot_menu(entity, target_id):
    _tx, _ty = movement.get_position_via_id(target_id)
    _weapon = entities.get_entity(
        items.get_items_in_holder(entity, 'weapon')[0])
    _menu = ui_menu.create(_tx - camera.X + 2,
                           _ty - camera.Y - 4,
                           title='Shoot')
    _accuracy = stats.get_accuracy(entity, _weapon['_id'])
    _x, _y = movement.get_position(entity)
    _direction = numbers.direction_to((_x, _y), (_tx, _ty))
    _final_direction = _direction + (_accuracy * numbers.distance((_x, _y),
                                                                  (_tx, _ty)))
    _spray_accuracy = (100 * (_direction / float(_final_direction)))

    entities.trigger_event(_weapon, 'get_actions', menu=_menu)
    ui_menu.add_selectable(
        _menu, 'Spray (Acc: %.2d)' % _spray_accuracy,
        lambda: entities.trigger_event(entity, 'shoot', target_id=target_id
                                       ) and settings.set_tick_mode('normal'))
    ui_menu.add_selectable(_menu, 'Snipe (Acc: %s)' % _accuracy, lambda: _)
Beispiel #9
0
def _locate_npc_message(goal, member_id):
    _target_id = goal['target_id']
    _member = entities.get_entity(member_id)
    _mission = entities.get_entity(goal['mission_id'])

    if not _target_id in _member['ai']['life_memory'] or not _member['ai'][
            'life_memory'][_target_id]['last_seen_at']:
        goal['message'] = 'Gather location info on target.'

        return

    if _member['ai']['life_memory'][_target_id]['is_dead']:
        goal['message'] = 'Confirmed: Target is dead.'

        entities.trigger_event(_member,
                               'complete_goal',
                               mission_id=goal['mission_id'],
                               goal_id=goal['_id'])

    elif _member['ai']['life_memory'][_target_id]['can_see']:
        goal['message'] = 'Target in line of sight.'

        entities.trigger_event(_member,
                               'complete_goal',
                               mission_id=goal['mission_id'],
                               goal_id=goal['_id'])

    elif _member['ai']['life_memory'][_target_id]['last_seen_at']:
        _direction = numbers.direction_to(
            movement.get_position(_member),
            _member['ai']['life_memory'][_target_id]['last_seen_at'])
        _distance = numbers.distance(
            movement.get_position(_member),
            _member['ai']['life_memory'][_target_id]['last_seen_at'])
        _real_direction = conversions.get_real_direction(_direction)
        _real_distance = conversions.get_real_distance(_distance)

        goal['message'] = 'Target last seen %s meters to the %s' % (
            _real_distance, _real_direction)

    _member['ai']['life_memory'][_target_id]['mission_related'] = True
Beispiel #10
0
def bullet(entity, x, y, tx, ty, speed, accuracy, damage):
	_entity = _create(x, y, 'Bullet', '.', 0, 'bullet')
	_entity['owner'] = entity['_id']
	_entity['start_position'] = (x, y)
	_entity['end_position'] = (tx, ty)
	_entity['speed'] = speed
	_entity['damage'] = damage
	
	entities.add_entity_to_group(_entity, 'bullets')
	timers.register(_entity)
	
	entities.trigger_event(_entity, 'set_direction', direction=numbers.direction_to((x, y), (tx, ty))+random.uniform(-accuracy, accuracy))
	entities.trigger_event(_entity, 'create_timer', time=speed, repeat=-1, enter_callback=_bullet_tick, repeat_callback=_bullet_tick)
	entities.register_event(_entity, 'position_changed', lambda e, **kwargs: check_for_collisions(e))
	entities.register_event(_entity, 'collision_with_entity', lambda e, target_id: entities.trigger_event(entities.get_entity(target_id), 'hit', projectile=e))
	entities.register_event(_entity, 'collision_with_entity', lambda e, target_id: entities.delete_entity(e))
	entities.register_event(_entity, 'collision_with_solid', lambda e: effects.light(movement.get_position(e)[0], movement.get_position(e)[1], random.randint(3, 4)))
	entities.register_event(_entity, 'collision_with_solid', lambda e: entities.delete_entity(e))
	entities.register_event(_entity, 'collision_with_solid', lambda e: effects.smoke_cloud(movement.get_position(e)[0], movement.get_position(e)[1], random.uniform(2, 2.75), start_alpha=random.uniform(0.45, .65), decay_amount=1.5))
	entities.register_event(_entity, 'check_next_position', check_next_position)
	
	if not '--no-fx' in sys.argv:
		entities.register_event(_entity, 'position_changed', lambda e, x, y, **kwargs: _bullet_effects(e, x, y))