Restore sword old behaviour for aiming (closes #96)

This commit is contained in:
Zughy 2023-08-13 17:08:59 +02:00
parent 575b0a3b6f
commit 8f74985789
3 changed files with 39 additions and 17 deletions

View File

@ -10,8 +10,8 @@ dofile(modpath .. "/GLOBALS.lua")
arena_lib.register_minigame("block_league", {
name = "Block League",
prefix = "[Block League] ",
name = S("Block League"),
prefix = "[" .. S("Block League") .. "] ",
icon = "bl_pixelgun.png",
teams = { S("orange"), S("blue") },

View File

@ -25,9 +25,11 @@ block_league.register_weapon("block_league:sword", {
sound = "bl_sword_hit",
},]]
-- TODO: questa dovrebbe diventare action1_hold una volta che sarà possibile
-- personalizzare l'animazione dell'oggetto tenuto in mano. Vedasi
-- https://github.com/minetest/minetest/issues/2811
-- TEMP: questa dovrebbe diventare action1_hold una volta che:
-- 1. Sarà possibile personalizzare l'animazione dell'oggetto tenuto in mano.
-- Vedasi https://github.com/minetest/minetest/issues/2811.
-- 2. Sarà possibile ritardare l'azione del clic.
-- Vedasi https://github.com/minetest/minetest/issues/13733
action1 = {
type = "punch",
description = S("push, @1♥", "<style color=#f66c77>" .. dmg1hold),

View File

@ -10,6 +10,7 @@ local function run_action() end
local function attack_loop() end
local function decrease_magazine() end
local function attack_hitscan() end
local function attack_melee() end
local function attack_bullet() end
local function attack_end() end
local function after_damage() end
@ -22,7 +23,7 @@ local function draw_particles() end
-- subito dopo con un'altra (prima dei fatidici 0.5s), quella funzione da 0.5s va
-- annullata. Ne tengo traccia qui
local slow_down_func = {} -- KEY: p_name; VALUE: timer func
local melee_range = block_league.MELEE_RANGE
local MELEE_RANGE = block_league.MELEE_RANGE
@ -77,7 +78,7 @@ function block_league.register_weapon(name, def)
description = def.description,
profile_description = def.profile_description or "",
--TEMP
action1 = def.action1 or "",
action2 = def.action2 or "",
drawtype = def.mesh and "mesh" or "item",
@ -101,21 +102,21 @@ function block_league.register_weapon(name, def)
reload_time = def.reload_time,
sound_reload = def.sound_reload,
range = def.weapon_type == "melee" and melee_range or 0,
range = def.weapon_type == "melee" and MELEE_RANGE or 0,
node_placement_prediction = "", -- disable prediction
-- LMB = first fire
on_use = function(itemstack, user, pointed_thing)
calc_action(def, 1, user)
calc_action(def, 1, user, pointed_thing)
end,
-- RMB = secondary fire
on_secondary_use = function(itemstack, user, pointed_thing)
calc_action(def, 2, user)
calc_action(def, 2, user, pointed_thing)
end,
on_place = function(itemstack, user, pointed_thing)
calc_action(def, 2, user)
calc_action(def, 2, user, pointed_thing)
end,
-- Q = reload
@ -377,7 +378,7 @@ end
function calc_action(weapon, action_id, player)
function calc_action(weapon, action_id, player, pointed_thing)
local is_holdable = ((action_id == 1 and weapon.action1_hold) or (action_id == 2 and weapon.action2_hold)) and true
local in_the_air = weapon.weapon_type == "melee" and block_league.is_in_the_air(player)
local action, held_action
@ -410,7 +411,7 @@ function calc_action(weapon, action_id, player)
player:get_meta():set_int("bl_weapon_state", 2)
wait_for_held_action(weapon, action, held_key, player, 0.3)
else
run_action(weapon, action, player)
run_action(weapon, action, player, pointed_thing)
end
end
@ -523,11 +524,15 @@ end
function run_action(weapon, action, player)
if action.type == "raycast" or action.type == "bullet" or action.type == "punch" or action.type == "custom" then
function run_action(weapon, action, player, pointed_thing)
if action.type == "raycast" or action.type == "bullet" or action.type == "custom" then
player:get_meta():set_int("bl_weapon_state", 2)
attack_loop(weapon, action, player)
elseif action.type == "punch" then
player:get_meta():set_int("bl_weapon_state", 2)
attack_loop(weapon, action, player, pointed_thing)
elseif action.type == "zoom" then
weapon_zoom(action, player)
@ -541,13 +546,13 @@ function run_action(weapon, action, player)
end
function attack_loop(weapon, action, player)
function attack_loop(weapon, action, player, pointed_thing)
local p_name = player:get_player_name()
block_league.sound_play(action.sound, p_name)
if action.type == "punch" then
attack_hitscan(player, weapon, action)
attack_melee(player, weapon, action, pointed_thing)
elseif action.type == "custom" then
action.on_use(player, weapon, action)
else
@ -621,6 +626,21 @@ end
function attack_melee(user, weapon, action, pointed_thing)
if pointed_thing.type ~= "object" then return end
local object = pointed_thing.ref
-- TEMP: non posso calcolare il colpo alla testa perché i `pointed_thing` nativi
-- non ritornano `intersection_point`. Vedasi https://github.com/minetest/minetest/issues/13734
--local headshot = (pointed_thing.intersection_point.y - object:get_pos().y) > 1.275 and true
local headshot = false
local target = {{object = object, headshot = headshot}}
block_league.apply_damage(user, target, weapon, action)
end
function attack_bullet(user, bullet)
local pos = user:get_pos()
local pos_head = {x = pos.x, y = pos.y + user:get_properties().eye_height, z = pos.z}