Project Zomboid

Project Zomboid

Stop, Drop 'n Roll (the "Fire Self-Extinguish" Mod)!
阿珍 11 Mar, 2023 @ 3:53pm
Chinese translation
DropRollAction = ISBaseTimedAction:derive("翻滚动作");

DropRollAction.CLOTHING_LAYER_ORDERING = {
"西装",
"全套西装头",
"尾巴",
"夹克",
"浴袍",
"衣服",
"毛衣",
"毛衣的帽子",
"裙子",
"裤子",
"头盔",
"帽子",
"帽子",
"面具",
"面具的眼睛",
"面具",
"身体额外的",
"短袖衬衫",
"衬衫",
"shirt",
"内衣",
"腿1",
"背心",
"袜子",
"内衣内衣裤",
"鞋",
"躯干腿",
"内衣",
"内衣底",
"内衣1",
"内衣2",
}

function DropRollAction.isValidForPlayer(player)
if player:getVehicle() then
print("在车里,滚动无效");
return false;
end;

if not player:isOnFire() then
print("滚动无效:身上没着火");
return false;
end

return true;
end

function DropRollAction:isValid()
-- We only check when populating.
return true;
end

function DropRollAction:determineNumItemsToDestroy()
local lucky = self.character:getTraits():contains("幸运");
local unlucky = self.character:getTraits():contains("不幸");
local numItemsToDestroy = Math.ceil(ZombRand(2));
if lucky then
numItemsToDestroy = numItemsToDestroy - Math.ceil(ZombRand(2));
elseif unlucky then
numItemsToDestroy = numItemsToDestroy + Math.ceil(ZombRand(2));
end
if unlucky or not lucky then
numItemsToDestroy = Math.min(numItemsToDestroy, 1);
end
if numItemsToDestroy < 0 then return 0 end;
return numItemsToDestroy;
end

function DropRollAction.addClothingHole(clothing)
local coveredParts = BloodClothingType.getCoveredParts(clothing:getBloodClothingType());
local coveredPartsLength = coveredParts:size();
for i=0,coveredPartsLength do
local coveredPart = coveredParts:get(i);
if clothing:getVisual():getHole(coveredPart) == 0.0 then
print("在 ", clothing, " 加了洞 ", coveredPart);
clothing:getVisual():setHole(coveredPart);
clothing:removePatch(coveredPart);
clothing:setCondition(clothing:getCondition() - clothing:getCondLossPerHole());
return;
end
end
end

function DropRollAction.burnClothing(clothing)
if not clothing:getCanHaveHoles() then
print("衣服不能有洞,所以设置条件为零");
clothing:setCondition(clothing:getCondition() / 2);
return;
end

DropRollAction.addClothingHole(clothing);
end

function DropRollAction:destroyRandomClothing()
local numItemsToDestroy = self:determineNumItemsToDestroy();
print("需要销毁的物品: ", numItemsToDestroy);
if numItemsToDestroy == 0 then
return
end

local numDestroyed = 0;
for _, bodyLocation in ipairs(DropRollAction.CLOTHING_LAYER_ORDERING) do
local foundClothing = nil;
for i=0, self.character:getWornItems():size()-1 do
local clothing = self.character:getWornItems():getItemByIndex(i);
if clothing:getBodyLocation() == bodyLocation then
foundClothing = clothing;
break;
end;
end
if foundClothing then
print("着火 ", foundClothing);
DropRollAction.burnClothing(foundClothing);
numDestroyed = numDestroyed + 1;
end
if numDestroyed == numItemsToDestroy then
print("毁了足够多的衣服.");
break;
end
end

print("发送服装更新...");
self.character:resetModel();
sendClothing(self.character);
end

function DropRollAction:extinguishFlames()
if isClient() then
self.character:sendStopBurning();
else
self.character:StopBurning()
end

self.character:getSquare():transmitStopFire();
self.character:getSquare():stopFire();
end

function DropRollAction:update()
self.tick = self.tick + 1;
if (self.tick == self.quashTime) then
print("灭火!");
self:destroyRandomClothing();
self:extinguishFlames();
end
self.character:setMetabolicTarget(Metabolics.FitnessHeavy);
end

function DropRollAction:start()
print("下落或翻滚!");
self:setActionAnim("DropRoll");
end

function DropRollAction:stop()
print("不再掉落和翻动!");
ISBaseTimedAction.stop(self);
end

function DropRollAction:perform()
ISBaseTimedAction.perform(self);
end

function DropRollAction:new(character, time, quashTime)
local o = ISBaseTimedAction.new(self, character);
o.stopOnAim = true;
o.stopOnWalk = true;
o.stopOnRun = true;
o.tick = 0;
o.quashTime = quashTime;
o.maxTime = time;
o.ignoreHandsWounds = true;
o.animSpeed = 1.0;
if o.character:isTimedActionInstant() then o.maxTime = 1; end
o.caloriesModifier = 16;
return o;
end

function DropRollAction.doDropRollAction(player)
local lucky = player:getTraits():contains("幸运");
local unlucky = player:getTraits():contains("不幸");
local reducedTime = 0;
if lucky then
reducedTime = 15 + Math.ceil(ZombRand(30));
elseif not unlucky then
reducedTime = Math.ceil(ZombRand(15));
end
print("基于运气的撤销时间减少: ", reducedTime);
local dropRollAction = DropRollAction:new(player, 300, 180 - reducedTime);
ISTimedActionQueue.add(dropRollAction);
end

function DropRollAction.onFillWorldObjectContextMenu(playerNum, context, worldObjects, test)
if test then return end;

local player = getSpecificPlayer(playerNum);

if DropRollAction.isValidForPlayer(player) then
context:addOption("停下,翻滚!", player, DropRollAction.doDropRollAction, player:getSquare());
end
end

Events.OnFillWorldObjectContextMenu.Add(DropRollAction.onFillWorldObjectContextMenu);