Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Credits: Rezecib (workshop-343762271)
- local BarbSummoner = Class(function(self, inst)
- self.inst = inst
- -- self.shouldremove = false
- self.barbs = {}
- -- self.save_records = {}
- end)
- function BarbSummoner:Add()
- print("BarbSummoner:Add")
- --self.inst.components.sanity:AddSanityPenalty(barb.GUID, 0.275)
- local theta = math.random() * 2 * PI
- local pt = inst:GetPosition()
- local radius = math.random(3, 6)
- local offset = FindWalkableOffset(pt, theta, radius, 12, true)
- if offset then
- local image = SpawnPrefab("bkbarb")
- if image == nil then return false end
- local pos = pt + offset
- image.Transform:SetPosition(pos:Get())
- image.components.follower:SetLeader(inst)
- image:InheritFromBK(currlevel)
- image:ListenForEvent("death", function(inst) self:Remove(inst) end)
- table.insert(self.barbs, image)
- end
- return true
- end
- function BarbSummoner:Remove(barb)
- print("BarbSummoner:Remove")
- for k,v in pairs(self.barbs) do
- if barb == v then
- --self.inst.components.sanity:RemoveSanityPenalty(barb.GUID, 0.275)
- table.remove(self.barbs, k)
- end
- end
- end
- function BarbSummoner:RemoveAll()
- print("BarbSummoner:RemoveAll")
- for k,v in pairs(self.barbs) do
- -- local save_record = v:GetSaveRecord()
- -- table.insert(self.save_records, save_record)
- --v:Remove()
- table.remove(self.barbs, k)
- end
- end
- function BarbSummoner:DoDespawn()
- print("BarbSummoner:DoDespawn")
- for k,v in pairs(self.barbs) do
- -- local save_record = v:GetSaveRecord()
- -- table.insert(self.save_records, save_record)
- v:Remove()
- end
- end
- function BarbSummoner:OnSave()
- local barbs = {}
- local i = 1
- if #self.barbs > 0 then
- for k,v in pairs(self.barbs) do
- barbs[i] = v:GetSaveRecord()
- i = i + 1
- end
- end
- -- if #self.save_records > 0 then
- -- for k,v in pairs(self.save_records) do
- -- barbs[i] = v:GetSaveRecord()
- -- i = i + 1
- -- end
- -- end
- print("BarbSummoner:OnSave", i-1)
- -- if self.shouldremove then
- -- self:RemoveAll()
- -- end
- return { barbs = barbs}
- end
- function BarbSummoner:OnLoad(data)
- print("BarbSummoner:OnLoad", #data.barbs)
- if data.barbs ~= nil and #data.barbs > 0 then
- for k,v in pairs(data.barbs) do
- local barb = SpawnSaveRecord(v)
- if barb.components.follower.leader ~= self.inst then
- -- self:Add(barb)
- barb.components.follower:SetLeader(self.inst)
- local currlevel = self.inst.components.leveler:GetLevel(BK_LEVEL_SYSTEM) or 1
- barb:InheritFromBK(currlevel)
- print("BarbSummoner:OnLoad:InheritFromBK. currlevel="..currlevel)
- end
- end
- end
- end
- function BarbSummoner:GetBarbCount()
- --return #self.barbs or 0
- local count = 0
- for _ in pairs(self.barbs) do count = count + 1 end
- return count
- end
- return BarbSummoner
Add Comment
Please, Sign In to add comment