Intial Commit
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
require "QMIA_State"
|
||||
require "IAArrange"
|
||||
require "TimedActions/IAArrangeAction"
|
||||
|
||||
-- Use Item Arrange's actual drop/arrange implementation and duration. Keeping this
|
||||
-- class in shared makes its complete() available to Build 42 multiplayer servers.
|
||||
QMIArrangeAction = IAArrangeAction:derive("QMIArrangeAction")
|
||||
|
||||
function QMIArrangeAction:new(character, item, srcContainer, destContainer)
|
||||
local obj = QMIA.containerTarget(destContainer)
|
||||
local o = IAArrangeAction.new(self, character, item, srcContainer, obj and obj:getSquare())
|
||||
o.destContainer = destContainer
|
||||
o.stopOnWalk = true
|
||||
o.stopOnRun = true
|
||||
o.stopOnAim = true
|
||||
return o
|
||||
end
|
||||
|
||||
-- A full surface / missing load must not cancel the remaining Quartermaster haul.
|
||||
-- Revalidate at start and complete instead; skipped items stay in their carrier.
|
||||
function QMIArrangeAction:isValid() return true end
|
||||
|
||||
function QMIArrangeAction:canArrange()
|
||||
local item, src, square, player = self.item, self.srcContainer, self.dropSquare, self.character
|
||||
if not item or not src or not square or not player then return false end
|
||||
local obj, ci = QMIA.containerTarget(self.destContainer)
|
||||
if not obj or obj:getObjectIndex() < 0 or obj:getSquare() ~= square
|
||||
or not QMIA.isMarked(obj, ci) then return false end
|
||||
-- Only unload carried items. A skipped Quartermaster load is never teleported.
|
||||
if not src:isInCharacterInventory(player) or not src:contains(item)
|
||||
or item:getContainer() ~= src or not src:isRemoveItemAllowed(item) then return false end
|
||||
if item:isEquipped() or item:isFavorite() or item:getIsCraftingConsumed() then return false end
|
||||
if not QMIA.canAccess(square, player) then return false end
|
||||
local here = player:getSquare()
|
||||
if not here or here:getZ() ~= square:getZ()
|
||||
or math.abs(here:getX() - square:getX()) > 1
|
||||
or math.abs(here:getY() - square:getY()) > 1
|
||||
or here:isSomethingTo(square) then return false end
|
||||
return IA.CheckSpace(square, item) == true
|
||||
end
|
||||
|
||||
function QMIArrangeAction:waitToStart()
|
||||
if not self:canArrange() then return false end
|
||||
self.character:faceLocation(self.dropSquare:getX(), self.dropSquare:getY())
|
||||
local waitingForTransaction = IAArrangeAction.waitToStart(self)
|
||||
return self.character:shouldBeTurning() or waitingForTransaction
|
||||
end
|
||||
|
||||
function QMIArrangeAction:start()
|
||||
self.qmiaSkip = not self:canArrange()
|
||||
if self.qmiaSkip then
|
||||
self.action:setTime(0)
|
||||
return
|
||||
end
|
||||
self.character:faceLocation(self.dropSquare:getX(), self.dropSquare:getY())
|
||||
IAArrangeAction.start(self)
|
||||
end
|
||||
|
||||
function QMIArrangeAction:update()
|
||||
if self.qmiaSkip then return end
|
||||
self.character:faceLocation(self.dropSquare:getX(), self.dropSquare:getY())
|
||||
IAArrangeAction.update(self)
|
||||
end
|
||||
|
||||
function QMIArrangeAction:complete()
|
||||
-- The server rechecks ownership, distance and available space immediately
|
||||
-- before using Item Arrange's own removal/drop/arrange implementation.
|
||||
if self.qmiaSkip or not self:canArrange() then return true end
|
||||
return IAArrangeAction.complete(self)
|
||||
end
|
||||
Reference in New Issue
Block a user