Dateien nach "/" hochladen
This commit is contained in:
8
ai.lua
8
ai.lua
@@ -113,6 +113,14 @@ local function try_fire(self_ent, target_pos)
|
||||
local cd = weapon == "plasma" and SHOOT_COOLDOWN_PLASMA or SHOOT_COOLDOWN_BULLET
|
||||
if (now - (self_ent._ai_last_shot or 0)) < cd then return false end
|
||||
|
||||
-- Spider-Ammo pruefen
|
||||
if weapon == "plasma" then
|
||||
local ammo = self_ent._spider_ammo or SPIDER_AMMO_MAX
|
||||
if ammo < SPIDER_AMMO_MIN_TO_FIRE then return false end
|
||||
-- Ammo verbrauchen
|
||||
self_ent._spider_ammo = math.max(0, ammo - SPIDER_AMMO_COST)
|
||||
end
|
||||
|
||||
local my_pos = self_ent.object:get_pos()
|
||||
local aim = {x=target_pos.x, y=target_pos.y+1.2, z=target_pos.z}
|
||||
local origin = {x=my_pos.x, y=my_pos.y+4.0, z=my_pos.z}
|
||||
|
||||
140
init.lua
140
init.lua
@@ -12,8 +12,13 @@ dofile(modpath .. "/mecha_control_panel.lua")
|
||||
dofile(modpath .. "/mecha_controller.lua")
|
||||
|
||||
|
||||
local MECH_EXPLOSION_DAMAGE = tonumber(minetest.settings:get("assorted_mecha_explosion_damage")) or 100
|
||||
local MECH_BULLET_DAMAGE = tonumber(minetest.settings:get("assorted_mecha_bullet_damage")) or 10
|
||||
local MECH_EXPLOSION_DAMAGE = tonumber(minetest.settings:get("assorted_mecha_explosion_damage")) or 100
|
||||
local MECH_BULLET_DAMAGE = tonumber(minetest.settings:get("assorted_mecha_bullet_damage")) or 10
|
||||
SPIDER_PLASMA_DAMAGE = tonumber(minetest.settings:get("assorted_mecha_spider_plasma_damage")) or 1000
|
||||
SPIDER_AMMO_MAX = tonumber(minetest.settings:get("assorted_mecha_spider_ammo_max")) or 100
|
||||
SPIDER_AMMO_REGEN = tonumber(minetest.settings:get("assorted_mecha_spider_ammo_regen")) or 2.0
|
||||
SPIDER_AMMO_COST = tonumber(minetest.settings:get("assorted_mecha_spider_ammo_cost")) or 50
|
||||
SPIDER_AMMO_MIN_TO_FIRE = SPIDER_AMMO_COST
|
||||
|
||||
local function apply_mech_scope(player, mech)
|
||||
if not player or not mech then return end
|
||||
@@ -40,6 +45,79 @@ local function remove_mech_scope(player)
|
||||
end
|
||||
end
|
||||
|
||||
-- ── Spider Ammo HUD ───────────────────────────────────────────────────────────
|
||||
|
||||
local function add_ammo_hud(player)
|
||||
if not player then return end
|
||||
local meta = player:get_meta()
|
||||
|
||||
-- Label
|
||||
local label_id = player:hud_add({
|
||||
type = "text",
|
||||
position = {x = 0.5, y = 0.88},
|
||||
offset = {x = 0, y = -28},
|
||||
text = "PLASMA AMMO",
|
||||
alignment = {x = 0, y = 0},
|
||||
scale = {x = 100, y = 30},
|
||||
number = 0x00FF99,
|
||||
})
|
||||
meta:set_int("ammo_hud_label", label_id)
|
||||
|
||||
-- Statbar (0-20 Halbsymbole = 10 volle Symbole)
|
||||
local bar_id = player:hud_add({
|
||||
type = "statbar",
|
||||
position = {x = 0.5, y = 0.88},
|
||||
offset = {x = -95, y = 0},
|
||||
text = "ammo_charge.png",
|
||||
text2 = "ammo_charge_empty.png",
|
||||
number = 20,
|
||||
item = 20,
|
||||
direction = 0,
|
||||
size = {x = 24, y = 24},
|
||||
})
|
||||
meta:set_int("ammo_hud_bar", bar_id)
|
||||
|
||||
-- Prozentanzeige
|
||||
local pct_id = player:hud_add({
|
||||
type = "text",
|
||||
position = {x = 0.5, y = 0.88},
|
||||
offset = {x = 112, y = 0},
|
||||
text = "100%",
|
||||
alignment = {x = -1, y = 0},
|
||||
scale = {x = 80, y = 20},
|
||||
number = 0xFFFFFF,
|
||||
})
|
||||
meta:set_int("ammo_hud_pct", pct_id)
|
||||
end
|
||||
|
||||
local function remove_ammo_hud(player)
|
||||
if not player then return end
|
||||
local meta = player:get_meta()
|
||||
for _, key in ipairs({"ammo_hud_label", "ammo_hud_bar", "ammo_hud_pct"}) do
|
||||
local id = meta:get_int(key)
|
||||
if id and id > 0 then
|
||||
player:hud_remove(id)
|
||||
meta:set_int(key, 0)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function update_ammo_hud(player, ammo_pct)
|
||||
if not player then return end
|
||||
local meta = player:get_meta()
|
||||
local bar_id = meta:get_int("ammo_hud_bar")
|
||||
local pct_id = meta:get_int("ammo_hud_pct")
|
||||
if bar_id and bar_id > 0 then
|
||||
local bar_val = math.floor((ammo_pct / 100) * 20 + 0.5)
|
||||
player:hud_change(bar_id, "number", bar_val)
|
||||
end
|
||||
if pct_id and pct_id > 0 then
|
||||
local color = ammo_pct >= SPIDER_AMMO_MIN_TO_FIRE and 0x00FF99 or 0xFF4444
|
||||
player:hud_change(pct_id, "text", math.floor(ammo_pct) .. "%")
|
||||
player:hud_change(pct_id, "number", color)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -218,6 +296,10 @@ local function register_mech(mech)
|
||||
self._mech_stand_anim = mech.stand_animation
|
||||
self._mech_head_name = mech.head_name
|
||||
self._mech_name = mech.name
|
||||
-- Spider-Ammo initialisieren (gilt fuer alle Mechs mit head_spider)
|
||||
if mech.head_name == "assorted_mecha:head_spider" then
|
||||
self._spider_ammo = self._spider_ammo or SPIDER_AMMO_MAX
|
||||
end
|
||||
-- Initialize AI state (restore from staticdata if available)
|
||||
assorted_mecha_ai_init(self)
|
||||
if staticdata and staticdata ~= "" then
|
||||
@@ -270,6 +352,20 @@ local vel = self.object:get_velocity() or {x=0, y=0, z=0}
|
||||
vel.y = vel.y - (dtime * 9.8)
|
||||
self.object:set_velocity(vel)
|
||||
|
||||
-- Spider-Ammo: passiver Regen (alle Mechs mit head_spider)
|
||||
if mech.head_name == "assorted_mecha:head_spider" then
|
||||
if (self._spider_ammo or SPIDER_AMMO_MAX) < SPIDER_AMMO_MAX then
|
||||
self._spider_ammo = math.min(
|
||||
SPIDER_AMMO_MAX,
|
||||
(self._spider_ammo or 0) + SPIDER_AMMO_REGEN * dtime
|
||||
)
|
||||
end
|
||||
-- HUD beim Fahrer aktualisieren
|
||||
if self.driver then
|
||||
update_ammo_hud(self.driver, self._spider_ammo or SPIDER_AMMO_MAX)
|
||||
end
|
||||
end
|
||||
|
||||
if self.driver then
|
||||
local control = self.driver:get_player_control()
|
||||
local yaw = self.object:get_yaw()
|
||||
@@ -417,6 +513,10 @@ clicker:set_properties({visual_size = {x=1, y=1, z=1}})
|
||||
clicker:hud_set_flags({crosshair = true, wielditem = true})
|
||||
clicker:set_eye_offset({x=0, y=0, z=0}, {x=0, y=0, z=0})
|
||||
clicker:get_meta():set_int("mech_third_person", 0)
|
||||
-- Ammo-HUD entfernen (nur Spider)
|
||||
if mech.head_name == "assorted_mecha:head_spider" then
|
||||
remove_ammo_hud(clicker)
|
||||
end
|
||||
else
|
||||
clicker:set_attach(self.object, "", mech.player_attach_offset, {x=0, y=0, z=0})
|
||||
clicker:set_eye_offset(mech.player_eye_offset)
|
||||
@@ -448,6 +548,11 @@ clicker:set_properties({visual_size = {x=1, y=1, z=1}})
|
||||
-- Scope overlay replaces crosshair; hide ingame crosshair & wielditem
|
||||
clicker:hud_set_flags({crosshair = false, wielditem = false})
|
||||
clicker:get_meta():set_int("mech_third_person", 0)
|
||||
-- Ammo-HUD anzeigen (nur Spider)
|
||||
if mech.head_name == "assorted_mecha:head_spider" then
|
||||
add_ammo_hud(clicker)
|
||||
update_ammo_hud(clicker, self._spider_ammo or SPIDER_AMMO_MAX)
|
||||
end
|
||||
end
|
||||
end,
|
||||
|
||||
@@ -754,8 +859,33 @@ on_step = function(self, dtime)
|
||||
|
||||
local control = target_player:get_player_control()
|
||||
if control.aux1 and not self.is_firing then
|
||||
self.is_firing = true
|
||||
|
||||
-- Ammo-Check: zugehoerigen mech1-Body in der Naehe suchen
|
||||
local mech_ent = nil
|
||||
local hp = self.object:get_pos()
|
||||
for _, obj in ipairs(minetest.get_objects_inside_radius(hp, 2)) do
|
||||
if not obj:is_player() then
|
||||
local e = obj:get_luaentity()
|
||||
if e and e.name == "assorted_mecha:mech1" then
|
||||
mech_ent = e
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local ammo = mech_ent and (mech_ent._spider_ammo or SPIDER_AMMO_MAX) or SPIDER_AMMO_MAX
|
||||
if ammo < SPIDER_AMMO_MIN_TO_FIRE then
|
||||
-- Leer: kein Schuss, kurzer Click-Sound als Feedback
|
||||
minetest.sound_play("bullet", {pos = self.object:get_pos(), gain = 0.3, max_hear_distance = 8})
|
||||
return
|
||||
end
|
||||
|
||||
self.is_firing = true
|
||||
-- Ammo verbrauchen und HUD aktualisieren
|
||||
if mech_ent then
|
||||
mech_ent._spider_ammo = math.max(0, ammo - SPIDER_AMMO_COST)
|
||||
update_ammo_hud(target_player, mech_ent._spider_ammo)
|
||||
end
|
||||
|
||||
local shoot_speed = 15
|
||||
self.object:set_animation({x=24, y=38}, shoot_speed, 0)
|
||||
@@ -1122,7 +1252,7 @@ minetest.register_entity("assorted_mecha:plasma_bolt", {
|
||||
for _, obj in ipairs(minetest.get_objects_inside_radius(epos, radius)) do
|
||||
if obj:is_player() then
|
||||
if obj:get_player_name() ~= self.shooter_name then
|
||||
obj:set_hp(math.max(0, obj:get_hp() - MECH_EXPLOSION_DAMAGE))
|
||||
obj:set_hp(math.max(0, obj:get_hp() - SPIDER_PLASMA_DAMAGE))
|
||||
end
|
||||
else
|
||||
local ent = obj:get_luaentity()
|
||||
@@ -1131,7 +1261,7 @@ minetest.register_entity("assorted_mecha:plasma_bolt", {
|
||||
local own = self.shooter_name and ent._driver_name == self.shooter_name
|
||||
local proj = string.find(n,"plasma_bolt") or string.find(n,"mecha_bullet") or string.find(n,"node_shard")
|
||||
if not own and not proj then
|
||||
obj:punch(obj, 1.0, {full_punch_interval=1.0, damage_groups={fleshy=MECH_EXPLOSION_DAMAGE}})
|
||||
obj:punch(obj, 1.0, {full_punch_interval=1.0, damage_groups={fleshy=SPIDER_PLASMA_DAMAGE}})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -9,3 +9,19 @@ assorted_mecha_explosion_damage (Plasma Bolt Explosion Damage) int 100 1 1000
|
||||
# Damage dealt by a single mecha bullet to players and entities on direct hit.
|
||||
# Default: 100 HP per hit
|
||||
assorted_mecha_bullet_damage (Mecha Bullet Direct Hit Damage) int 100 1 1000
|
||||
|
||||
# Damage dealt by a spider plasma bolt (10x base explosion damage).
|
||||
# Default: 1000 HP per hit
|
||||
assorted_mecha_spider_plasma_damage (Spider Plasma Bolt Damage) int 1000 1 10000
|
||||
|
||||
# Spider plasma cannon max ammo capacity (= number of shots * 50).
|
||||
# Each shot costs 50 ammo. Default: 100 (= 2 shots max)
|
||||
assorted_mecha_spider_ammo_max (Spider Plasma Max Ammo) int 100 50 200
|
||||
|
||||
# Spider plasma ammo regen rate in percent per second.
|
||||
# Default: 2.0 (= full reload in ~50 seconds)
|
||||
assorted_mecha_spider_ammo_regen (Spider Plasma Ammo Regen %/s) float 2.0 0.1 10.0
|
||||
|
||||
# Spider plasma ammo cost per shot (in percent of max ammo).
|
||||
# Default: 50 (= 2 shots when full)
|
||||
assorted_mecha_spider_ammo_cost (Spider Plasma Ammo Cost per Shot %) int 50 10 100
|
||||
|
||||
Reference in New Issue
Block a user