示例#1
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: _)
示例#2
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)
示例#3
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: _)
示例#4
0
文件: life.py 项目: witheld9/r3-tdw
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)