Jump to content

Bundler ignores moisture


Tykvesh
  • Pending

Wouldn't it make sense if moisture carried over to resulting items?

58519900_GIF29-Jun-2102-47-29.gif.bd6ece59b8fee498a0be58d27b4352bd.gif

This code below has everything bundled:

Quote

function Bundler:StartBundling(item)
    if item ~= nil and
        item.components.bundlemaker ~= nil and
        item.components.bundlemaker.bundlingprefab ~= nil and
        item.components.bundlemaker.bundledprefab ~= nil then
        self:StopBundling()
        self.bundlinginst = SpawnPrefab(item.components.bundlemaker.bundlingprefab)
        if self.bundlinginst ~= nil then
            if self.bundlinginst.components.container ~= nil then
                self.bundlinginst.components.container:Open(self.inst)
                if self.bundlinginst.components.container:IsOpenedBy(self.inst) then
                    self.bundlinginst.entity:SetParent(self.inst.entity)
                    self.bundlinginst.persists = false
                    self.itemprefab = item.prefab
                    self.itemskinname = item.skinname
                    self.wrappedprefab = item.components.bundlemaker.bundledprefab
                    self.wrappedskinname = item.components.bundlemaker.bundledskinname
                    self.wrappedskin_id = item.components.bundlemaker.bundledskin_id
                    if item.components.inventoryitemmoisture ~= nil then
                        self.itemmoisture = item.components.inventoryitemmoisture.moisture
                        self.itemiswet = item.components.inventoryitemmoisture.iswet
                    end

                    item.components.bundlemaker:OnStartBundling(self.inst)
                    self.inst.sg.statemem.bundling = true
                    self.inst.sg:GoToState("bundling")
                    return true
                end
            end
            self.bundlinginst:Remove()
            self.bundlinginst = nil
        end
    end
end

function Bundler:StopBundling()
    if self.bundlinginst ~= nil then
        if self.bundlinginst.components.container ~= nil then
            if self.inst.components.inventory ~= nil then
                local pos = self.bundlinginst:GetPosition()
                for i = 1, self.bundlinginst.components.container:GetNumSlots() do
                    local item = self.bundlinginst.components.container:RemoveItemBySlot(i)
                    if item ~= nil then
                        item.prevcontainer = nil
                        item.prevslot = nil
                        self.inst.components.inventory:GiveItem(item, nil, pos)
                    end
                end
            else
                self.bundlinginst.components.container:DropEverything()
            end
        end
        self.bundlinginst:Remove()
        self.bundlinginst = nil
    end
    if self.itemprefab ~= nil then
        local item = SpawnPrefab(self.itemprefab, self.itemskinname, self.wrappedskin_id)
        if item ~= nil then
            if item.components.inventoryitem ~= nil and self.itemmoisture ~= nil then
                item.components.inventoryitem:InheritMoisture(self.itemmoisture, self.itemiswet)
            end
   
        
            if self.inst.components.inventory ~= nil then
                self.inst.components.inventory:GiveItem(item, nil, self.inst:GetPosition())
            else
                DropItem(self.inst, item)
            end
        end
        self.itemprefab = nil
        self.wrappedprefab = nil
        self.wrappedskinname = nil
        self.wrappedskin_id = nil
        self.itemmoisture = nil
        self.itemiswet = nil

    end
end

function Bundler:OnFinishBundling()
    if self.bundlinginst ~= nil and
        self.bundlinginst.components.container ~= nil and
        not self.bundlinginst.components.container:IsEmpty() and
        self.wrappedprefab ~= nil then
        local wrapped = SpawnPrefab(self.wrappedprefab, self.wrappedskinname, self.wrappedskin_id)
        if wrapped ~= nil then
            if wrapped.components.unwrappable ~= nil then
                local items = {}
                for i = 1, self.bundlinginst.components.container:GetNumSlots() do
                    local item = self.bundlinginst.components.container:GetItemInSlot(i)
                    if item ~= nil then
                        table.insert(items, item)
                    end
                end
                wrapped.components.unwrappable:WrapItems(items, self.inst)
                self.bundlinginst:Remove()
                self.bundlinginst = nil
                self.itemprefab = nil
                self.wrappedprefab = nil
                self.wrappedskinname = nil
                self.wrappedskin_id = nil
                
                if wrapped.components.inventoryitem ~= nil and self.itemmoisture ~= nil then
                    wrapped.components.inventoryitem:InheritMoisture(self.itemmoisture, self.itemiswet)
                end
                self.itemmoisture = nil
                self.itemiswet = nil

                
                if self.inst.components.inventory ~= nil then
                    self.inst.components.inventory:GiveItem(wrapped, nil, self.inst:GetPosition())
                else
                    DropItem(self.inst, wrapped)
                end
            else
                wrapped:Remove()
            end
        end
    end
end

function Bundler:OnSave()
    local data =
    {
        item = self.itemprefab,
        wrapped = self.wrappedprefab,
        wrappedskinname = self.wrappedskinname,
        wrappedskin_id = self.wrappedskin_id,
        itemmoisture = self.itemmoisture,
        itemiswet = self.itemiswet,

    }
    if self.bundlinginst ~= nil and
        self.bundlinginst.components.container ~= nil and
        not self.bundlinginst.components.container:IsEmpty() then
        data.bundling = self.bundlinginst:GetSaveRecord()
    end
    return next(data) ~= nil and data or nil
end

function Bundler:OnLoad(data)
    if data.item ~= nil or data.bundling ~= nil then
        local currentitem = self.itemprefab
        local currentwrapped = self.wrappedprefab
        local currentskinname = self.wrappedskinname
        local currentskin_id = self.wrappedskin_id
        local currentbundling = self.bundlinginst
        local currentmoisture = self.itemmoisture
        local currentiswet = self.itemiswet

        self.itemprefab = data.item
        self.wrappedprefab = data.wrapped
        self.wrappedskinname = data.wrappedskinname
        self.wrappedskin_id = data.wrappedskin_id
        self.itemmoisture = data.itemmoisture
        self.itemiswet = data.itemiswet

        if data.bundling ~= nil then
            self.bundlinginst = SpawnSaveRecord(data.bundling)
            if self.bundlinginst ~= nil then
                self.bundlinginst.entity:SetParent(self.inst.entity)
                self.bundlinginst.persists = false
            end
        end

        if currentitem ~= nil or currentbundling ~= nil then
            self:StopBundling()
            self.itemprefab = currentitem
            self.wrappedprefab = currentwrapped
            self.wrappedskinname = currentskinname
            self.wrappedskin_id = currentskin_id
            self.bundlinginst = currentbundling
            self.itemmoisture = currentmoisture
            self.itemiswet = currentiswet

        end
    end
end

 


Steps to Reproduce

Cancel of finish bundling with Water-Logged Bundling Wrap

  • Like 1



User Feedback


There are no comments to display.



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
  • Create New...