-- 在创建“ShellInsert”配方时调用的函数,用于将电池插入到MJOLNIR装甲上 function Recipe.OnCreate.ShellInsert(items, result, player) local ShellNow = nil -- MJOLNIR装甲当前状态 local Battery = nil -- 电池当前状态 -- 遍历配方材料 for i = 0, items:size() - 1 do -- 如果当前材料是电池,则将其赋值给Battery if items:get(i):getType() == "Battery" then Battery = items:get(i) end -- 如果当前材料是MJOLNIR装甲,则将其赋值给ShellNow if items:get(i):getType() == "MJOLNIRArmorMkVI" then ShellNow = items:get(i); end end -- 如果MJOLNIR装甲的Shellbattery值为空,则将其设置为0 if ShellNow:getModData().Shellbattery == nil then ShellNow:getModData().Shellbattery = 0 end -- 如果MJOLNIR装甲的Shellbattery加上电池的使用时间不超过3600秒,则可以将电池插入到装甲上 if ShellNow:getModData().Shellbattery + math.floor(Battery:getUsedDelta() * 12 * 60) <= 3600 then result:getModData().Shellbattery = ShellNow:getModData().Shellbattery + math.floor(Battery:getUsedDelta() * 12 * 60) getPlayer():Say(getText("UI_ContextMenu_BatteryIn") .. tostring(math.floor(result:getModData().Shellbattery / 6) / 10) .. getText("UI_ContextMenu_HourUnit")) else -- 否则,将电池还给玩家背包,并提示电池已经充满 result:getModData().Shellbattery = ShellNow:getModData().Shellbattery player:getInventory():AddItem(Battery) player:Say(getText("UI_ContextMenu_BatteryFull")) end -- 将结果物品放回玩家身上 player:setWornItem(result:getBodyLocation(), result) end

-- 在创建“ShellBatteryRemain”配方时调用的函数,用于显示MJOLNIR装甲的电池剩余时间 function Recipe.OnCreate.ShellBatteryRemain(items, result, player) -- 如果MJOLNIR装甲的Shellbattery值为空,则将其设置为0 if items:get(0):getModData().Shellbattery == nil then items:get(0):getModData().Shellbattery = 0 end -- 将MJOLNIR装甲的Shellbattery值赋值给结果物品 result:getModData().Shellbattery = items:get(0):getModData().Shellbattery -- 将结果物品放回玩家身上 player:setWornItem(result:getBodyLocation(), result) -- 显示电池剩余时间 getPlayer():Say(getText("UI_ContextMenu_BatteryRemain") .. tostring(math.floor(result:getModData().Shellbattery / 6) / 10) .. getText("UI_ContextMenu_HourUnit")) end


原文地址: https://www.cveoy.top/t/topic/bZO8 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录