Intial Commit

This commit is contained in:
2026-10-27 17:27:44 -04:00
parent 1fa6e14bde
commit 5743c34a21
49 changed files with 1454 additions and 0 deletions
@@ -0,0 +1,85 @@
require "TimedActions/ISBaseTimedAction"
require "KLT_LAV"
KLT_ReloadLAV = ISBaseTimedAction:derive("KLT_ReloadLAV")
local L = KLTLAV
function KLT_ReloadLAV:isValid()
if isClient() or not L.isGunner(self.vehicle, self.character) or not L.weaponReady(self.vehicle) then return false end
local gun = self.vehicle:getPartById(L.weaponPart)
local storage = self.vehicle:getPartById(L.storagePart)
return gun == self.gun and storage == self.storage and storage:getInventoryItem() ~= nil
and storage:getCondition() > 0 and gun:getItemContainer() == self.breech
and storage:getItemContainer() == self.source and self.breech:isEmpty()
and self.source:contains(self.round) and L.isAmmoType(self.round:getFullType())
end
function KLT_ReloadLAV:start()
self.character:getEmitter():playSound("Turret_Reload_Open")
end
function KLT_ReloadLAV:clearPending()
if L.pendingReload[self.character] == self then L.pendingReload[self.character] = nil end
end
function KLT_ReloadLAV:stop()
self:clearPending()
ISBaseTimedAction.stop(self)
end
function KLT_ReloadLAV:forceCancel()
self:clearPending()
end
function KLT_ReloadLAV:perform()
-- Validate again: leaving the seat, losing the round or loading another
-- shell during the action must never create or move ammunition.
if self:isValid() then
self.source:Remove(self.round)
self.breech:AddItem(self.round)
self.character:getEmitter():playSound("Turret_Reload_Close")
end
self:clearPending()
ISBaseTimedAction.perform(self)
end
function KLT_ReloadLAV:new(character, vehicle, gun, storage, round)
local o = ISBaseTimedAction.new(self, character)
o.vehicle = vehicle
o.gun = gun
o.storage = storage
o.source = storage:getItemContainer()
o.breech = gun:getItemContainer()
o.round = round
o.maxTime = 300 -- about five seconds before character modifiers
o.stopOnWalk = true
o.stopOnRun = true
o.stopOnAim = false -- pendingReload blocks firing while the player holds aim
return o
end
function L.queueReload(character)
local vehicle = character and character:getVehicle()
if not L.isGunner(vehicle, character) or not L.weaponReady(vehicle) or L.pendingReload[character] then return false end
if isClient() then character:Say("LAV reload prototype currently supports single-player."); return false end
local gun = vehicle:getPartById(L.weaponPart)
local storage = vehicle:getPartById(L.storagePart)
local source = storage and storage:getItemContainer()
local breech = gun and gun:getItemContainer()
if not source or not breech or not breech:isEmpty() then return false end
-- Match MTK tank reload priority: HE first when both types are stored.
local round = source:FindAndReturn(L.heAmmoType) or source:FindAndReturn(L.ammoType)
if not round then character:Say("No 90 mm AP or HE shells in LAV ammunition storage."); return false end
local action = KLT_ReloadLAV:new(character, vehicle, gun, storage, round)
if not action:isValid() then return false end
L.pendingReload[character] = action
ISTimedActionQueue.add(action)
return true
end
Events.OnKeyPressed.Add(function(key)
if key == Keyboard.KEY_R and getGameSpeed() > 0
and not (UIManager and UIManager.isMouseOverInventory and UIManager.isMouseOverInventory()) then
L.queueReload(getSpecificPlayer(0))
end
end)