diff --git a/objects/minibiome/elder/elderaltar/elderaltar.lua b/objects/minibiome/elder/elderaltar/elderaltar.lua index 2ac67205ec..5cc21b177a 100644 --- a/objects/minibiome/elder/elderaltar/elderaltar.lua +++ b/objects/minibiome/elder/elderaltar/elderaltar.lua @@ -1,162 +1,170 @@ -local recipes = -{ -{inputs = { wrappedbody=1 }, outputs = { brain=1,fuscienceresource=120,bone=8,leather=1,alienmeat=4,faceskin=1,rawribmeat=2,liquidblood=40 }, time = 5.0}, -{inputs = { wrappedbodyputrid=1 }, outputs = { brain=1,fumadnessresource=5,bone=8,leather=1,rottingfleshmaterial=4,slew2=12,biospore=2,liquidbioooze=40 }, time = 5.0}, -{inputs = { wrappedbodyalien=1 }, outputs = { brain=1,fuprecursorresource=5,bone=8,leather=1,slew4=12,rawribmeat=2,cellmateria=4,liquidalienjuice=40 }, time = 5.0}, -{inputs = { cthulureward=1,elderrelic7=1,elderrelic11=1 }, outputs = { elderripper=1 }, time = 15.0}, -{inputs = { cthulureward=1, elderrelic5=1, elderrelic11=1 }, outputs = { eldercarbine=1 }, time = 15.0}, -{inputs = { cthulureward=1, elderrelic12=1, elderrelic11=1 }, outputs = { elderpistol=1 }, time = 15.0 }, -{inputs = { cthulureward=1, elderrelic6=1, elderrelic8=1 }, outputs = { elderrepeater=1 }, time = 15.0 }, -{inputs = { eldertome=1,elderrelic7=1,elderrelic3=3 }, outputs = { elderspear=1 }, time = 15.0}, -{inputs = { eldertome=1, elderrelic2=1, elderrelic3=5 }, outputs = { elderblade=1 }, time = 15.0}, -{inputs = { elderrelic3=6, elderrelic5=2, elderrelic7=1 }, outputs = { elderbroadsword=1 }, time = 15.0 }, -{inputs = { cthulureward=1, eldertome=1, elderrelic3=5 }, outputs = { elderbow=1 }, time = 15.0}, -{inputs = { nocxiumbar=5, elderrelic2=1, elderrelic7=1 }, outputs = { elderwhip=1 }, time = 15.0 }, -{inputs = { eldertome=1, elderrelic7=2, cthulureward=1 }, outputs = { cultiststaff1=1 }, time = 15.0 }, -{inputs = { eldertome=1, elderrelic6=2, elderrelic9=1 }, outputs = { cultiststaff2=1 }, time = 15.0 }, -{inputs = { eldertome=1, elderrelic12=2, elderrelic14=1 }, outputs = { cultiststaff3=1 }, time = 15.0 }, -{inputs = { nocxiumbar=5, elderrelic6=1, elderrelic3=4 }, outputs = { elderaxe=1 }, time = 15.0 }, -{inputs = { cthulureward=1, elderrelic8=1, elderrelic12=1 }, outputs = { eldergrappler=1 }, time = 15.0}, -{inputs = { nocxiumbar=5, eldertome=1, elderrelic12=5 }, outputs = { eldershield=1 }, time = 15.0 }, -{inputs = { nocxiumbar=6, elderrelic12=1, elderrelic6=1 }, outputs = { elderarmorhead=1 }, time = 15.0 }, -{inputs = { nocxiumbar=7, elderrelic2=1, elderrelic14=1 }, outputs = { elderarmorchest=1 }, time = 15.0}, -{inputs = { nocxiumbar=5, elderrelic1=1, elderrelic5=1 }, outputs = { elderarmorpants=1 }, time = 15.0 }, -{inputs = { nocxiumbar=6, elderrelic6=1, elderrelic11=1 }, outputs = { cultarmorhead=1 }, time = 15.0 }, -{inputs = { nocxiumbar=7, elderrelic7=1, elderrelic12=1 }, outputs = { cultarmorchest=1 }, time = 15.0 }, -{inputs = { nocxiumbar=5, elderrelic8=1, elderrelic14=1 }, outputs = { cultarmorpants=1 }, time = 15.0 }, -{inputs = { cthulureward=1, elderrelic3=2, elderrelic14=1 }, outputs = { eldermace=1 }, time = 15.0 }, -{inputs = { elderrelic12=5, elderrelic4=1, elderrelic8=1 }, outputs = { eldershotgun=1 }, time = 15.0 }, -{inputs = { cthulureward=1, elderrelic1=3, elderrelic11=2 }, outputs = { eldergrenadelauncher=1 }, time = 15.0 }, -{inputs = { shoggothessence=5}, outputs = { shoggothflesh=1 }, time = 1.0 }, -{inputs = { shoggothflesh=1}, outputs = { essence=1000,fuscienceresource=1000 }, time = 1.0 } -} +local recipes = {} function init() - self.timer = 1 - self.mintick = 1 - self.crafting = false - self.output = {} + storage.timer = storage.timer or 1 + self.mintick = 1 + self.inputStart=config.getParameter("inputSlotsStart") or 0 + self.inputEnd=math.max(self.inputStart,config.getParameter("inputSlotsEnd") or 2) + self.outputStart=config.getParameter("outputSlotsStart") or 3 + self.outputEnd=config.getParameter("outputSlotsEnd") or -1 + if (self.outputEnd t2[k] then - return false - end - end - return true - end - -return filter(recipes, function(l) return subset(l.inputs, query) end) + local function subset(t1,t2) + if next(t2) == nil then + return false + end + if t1 == t2 then + return true + end + for k,_ in pairs(t1) do + if not t2[k] or t1[k] > t2[k] then + return false + end + end + return true + end + + return filter(recipes, function(l) return subset(l.inputs, query) end) end - function getOutSlotsFor(something) - local empty = {} -- empty slots in the outputs - local slots = {} -- slots with a stack of "something" - - for i = 3, 11 do -- iterate all output slots - local stack = world.containerItemAt(entity.id(), i) -- get the stack on i - if stack ~= nil then -- not empty - if stack.name == something then -- its "something" - table.insert(slots,i) -- possible drop slot - end - else -- empty - table.insert(empty, i) - end - end - - for _,e in pairs(empty) do -- add empty slots to the end - table.insert(slots,e) - end - return slots + local empty = {} -- empty slots in the outputs + local slots = {} -- slots with a stack of "something" + if self.outputEnd == nil then + self.outputEnd = world.containerSize(entity.id()) + end + for i = self.outputStart,self.outputEnd do -- iterate all output slots + local stack = world.containerItemAt(entity.id(), i) -- get the stack on i + if stack ~= nil then -- not empty + if stack.name == something then -- its "something" + -- possible drop slot + slots[#slots+1]=i + end + else -- empty + empty[#empty+1]=i + end + end + + for _,e in pairs(empty) do -- add empty slots to the end + slots[#slots+1]=e + end + return slots end +function throwItemIn(item,isOutput) + if isOutput then + local possibleSlots=getOutSlotsFor(item.name) + for _,slot in pairs(possibleSlots) do + if item then + item=world.containerPutItemsAt(entity.id(), item, slot) + else + break + end + end + else + item=world.containerStackItems(entity.id(), item) + end + if item ~= nil then + world.spawnItem(item.name, entity.position(), item.count) + end +end -function update(dt) - self.timer = self.timer - dt - if self.timer <= 0 then - if self.crafting then - for k,v in pairs(self.output) do - local leftover = {name = k, count = v} - local slots = getOutSlotsFor(k) - for _,i in pairs(slots) do - leftover = world.containerPutItemsAt(entity.id(), leftover, i) - if leftover == nil then - break - end - end - - if leftover ~= nil then - world.spawnItem(leftover.name, entity.position(), leftover.count) - end - end - self.crafting = false - self.output = {} - self.timer = self.mintick --reset timer to a safe minimum - animator.setAnimationState("samplingarrayanim", "idle") - animator.playSound("active") - end - - if not self.crafting and self.timer <= 0 then --make sure we didn't just finish crafting - if not startCrafting(getValidRecipes(getInputContents())) then self.timer = self.mintick end --set timeout if there were no recipes - end - end +function giveItems(items,isOutput) + if #items>0 then + for _,item in pairs(items) do + throwItemIn(item,isOutput) + end + end +end + +function refund() + giveItems(storage.inputs) + storage.inputs={} end +function die(smash) + refund() +end +function update(dt) + storage.timer = storage.timer - dt + if storage.timer <= 0 then + if storage.crafting then + giveItems(storage.output,true) + storage.crafting = false + storage.output = {} + storage.inputs = {} + storage.timer = self.mintick --reset timer to a safe minimum + animator.setAnimationState("samplingarrayanim", storage.crafting and "working" or "idle") + animator.playSound("active") + end + + if not storage.crafting and storage.timer <= 0 then --make sure we didn't just finish crafting + if not startCrafting(getValidRecipes(getInputContents())) then storage.timer = self.mintick end --set timeout if there were no recipes + end + end +end function startCrafting(result) - - if next(result) == nil then return false - else _,result = next(result) - for k,v in pairs(result.inputs) do - if not world.containerConsume(entity.id(), {item = k , count = v}) then return false end - end - - self.crafting = true - self.timer = result.time - self.output = result.outputs - animator.setAnimationState("samplingarrayanim", "working") - return true - end + if next(result) == nil then return false + else _,result = next(result) + for k,v in pairs(result.inputs) do + if not world.containerConsume(entity.id(), {item = k , count = v}) then + --honestly this should never fire, but...just in case. + refund() + return false + else + storage.inputs[#storage.inputs+1]={item = k , count = v} + end + end + + storage.crafting = true + storage.timer = result.time + for name,quantity in pairs(result.outputs) do + storage.output[#storage.output+1]={name=name,count=quantity} + end + animator.setAnimationState("samplingarrayanim", storage.crafting and "working" or "idle") + return true + end end diff --git a/objects/minibiome/elder/elderaltar/elderaltar.object b/objects/minibiome/elder/elderaltar/elderaltar.object index 3f906ab369..68d69fa59a 100644 --- a/objects/minibiome/elder/elderaltar/elderaltar.object +++ b/objects/minibiome/elder/elderaltar/elderaltar.object @@ -1,62 +1,93 @@ { - "objectName" : "elderaltar", - "colonyTags" : [ "elder", "hideous", "statue" ], - "printable" : false, - "rarity" : "legendary", - "description" : "An altar dedicated to some unspeakable horror. I wonder what function it serves?", - "shortdescription" : "^#86a84a;Elder Altar^reset;", - "subtitle" : "a dark, terrible relic.", - "race" : "generic", - "category" : "Ancient Artifact", - "price" : 14000, - "objectType" : "container", - "hydrophobic" : false, - "rooting" : true, - "inventoryIcon" : "elderaltaricon.png", - "orientations" : [ - { - "dualImage" : "elderaltar.png:.", + "objectName" : "elderaltar", + "colonyTags" : [ "elder", "hideous", "statue" ], + "printable" : false, + "rarity" : "legendary", + "description" : "An altar dedicated to some unspeakable horror. I wonder what function it serves?", + "shortdescription" : "^#86a84a;Elder Altar^reset;", + "subtitle" : "a dark, terrible relic.", + "race" : "generic", + "category" : "Ancient Artifact", + "price" : 14000, + "objectType" : "container", + "hydrophobic" : false, + "rooting" : true, + "inventoryIcon" : "elderaltaricon.png", + "orientations" : [ + { + "dualImage" : "elderaltar.png:.", - "imagePosition" : [0, 0], - "frames" : 5, - "animationCycle" : 1.0, + "imagePosition" : [0, 0], + "frames" : 5, + "animationCycle" : 1.0, - "spaceScan" : 0.1, - "anchors" : [ "bottom" ] - } - ], + "spaceScan" : 0.1, + "anchors" : [ "bottom" ] + } + ], - "animation" : "/objects/minibiome/elder/elderaltar/elderaltar.animation", - "animationParts" : { - "samplingarrayanim" : "elderaltar.png" - }, - "scripts" : [ "/objects/minibiome/elder/elderaltar/elderaltar.lua", - "/scripts/npcToyObject.lua" ], - "scriptDelta" : 30, - "recipeGroup" : "elderaltar", - "openSounds" : [ "/sfx/objects/locker_open.ogg" ], - "slotCount" : 12, - "uiConfig" : "/interface/extractor/elderaltar.config", - "frameCooldown" : 67, - "autoCloseCooldown" : 3600, + "animation" : "/objects/minibiome/elder/elderaltar/elderaltar.animation", + "animationParts" : { + "samplingarrayanim" : "elderaltar.png" + }, + "scripts" : [ "/objects/minibiome/elder/elderaltar/elderaltar.lua", + "/scripts/npcToyObject.lua" ], + "scriptDelta" : 30, + "recipeGroup" : "elderaltar", + "openSounds" : [ "/sfx/objects/locker_open.ogg" ], + "slotCount" : 12, + "uiConfig" : "/interface/extractor/elderaltar.config", + "frameCooldown" : 67, + "autoCloseCooldown" : 3600, - "npcToy" : { - "influence" : [ - "sink", - "sinkComplete" - ], - "defaultReactions" : { - "sink" : [ - [1.0, "crouchcollect"] - ], - "sinkComplete" : [ - [1.0, "smile"] - ] - }, - "preciseStandPositionLeft" : [-1.0, 0.0], - "preciseStandPositionRight" : [1.0, 0.0], - "maxNpcs" : 2 - } + "npcToy" : { + "influence" : [ + "sink", + "sinkComplete" + ], + "defaultReactions" : { + "sink" : [ + [1.0, "crouchcollect"] + ], + "sinkComplete" : [ + [1.0, "smile"] + ] + }, + "preciseStandPositionLeft" : [-1.0, 0.0], + "preciseStandPositionRight" : [1.0, 0.0], + "maxNpcs" : 2 + }, + "recipes":[ + {"outputs":{"brain":1,"faceskin":1,"alienmeat":4,"liquidblood":40,"rawribmeat":2,"fuscienceresource":120,"bone":8,"leather":1},"time":5,"inputs":{"wrappedbody":1}}, + {"outputs":{"liquidbioooze":40,"brain":1,"slew2":12,"fumadnessresource":5,"bone":8,"rottingfleshmaterial":4,"leather":1,"biospore":2},"time":5,"inputs":{"wrappedbodyputrid":1}}, + {"outputs":{"brain":1,"slew4":12,"rawribmeat":2,"fuprecursorresource":5,"liquidalienjuice":40,"cellmateria":4,"bone":8,"leather":1},"time":5,"inputs":{"wrappedbodyalien":1}}, + {"outputs":{"elderripper":1},"time":15,"inputs":{"cthulureward":1,"elderrelic7":1,"elderrelic11":1}}, + {"outputs":{"eldercarbine":1},"time":15,"inputs":{"elderrelic5":1,"cthulureward":1,"elderrelic11":1}}, + {"outputs":{"elderpistol":1},"time":15,"inputs":{"cthulureward":1,"elderrelic11":1,"elderrelic12":1}}, + {"outputs":{"elderrepeater":1},"time":15,"inputs":{"elderrelic6":1,"cthulureward":1,"elderrelic8":1}}, + {"outputs":{"elderspear":1},"time":15,"inputs":{"eldertome":1,"elderrelic7":1,"elderrelic3":3}}, + {"outputs":{"elderblade":1},"time":15,"inputs":{"eldertome":1,"elderrelic2":1,"elderrelic3":5}}, + {"outputs":{"elderbroadsword":1},"time":15,"inputs":{"elderrelic5":2,"elderrelic7":1,"elderrelic3":6}}, + {"outputs":{"elderbow":1},"time":15,"inputs":{"eldertome":1,"cthulureward":1,"elderrelic3":5}}, + {"outputs":{"elderwhip":1},"time":15,"inputs":{"nocxiumbar":5,"elderrelic7":1,"elderrelic2":1}}, + {"outputs":{"cultiststaff1":1},"time":15,"inputs":{"eldertome":1,"elderrelic7":2,"cthulureward":1}}, + {"outputs":{"cultiststaff2":1},"time":15,"inputs":{"elderrelic6":2,"eldertome":1,"elderrelic9":1}}, + {"outputs":{"cultiststaff3":1},"time":15,"inputs":{"elderrelic14":1,"eldertome":1,"elderrelic12":2}}, + {"outputs":{"elderaxe":1},"time":15,"inputs":{"nocxiumbar":5,"elderrelic6":1,"elderrelic3":4}}, + {"outputs":{"eldergrappler":1},"time":15,"inputs":{"cthulureward":1,"elderrelic8":1,"elderrelic12":1}}, + {"outputs":{"eldershield":1},"time":15,"inputs":{"nocxiumbar":5,"eldertome":1,"elderrelic12":5}}, + {"outputs":{"elderarmorhead":1},"time":15,"inputs":{"nocxiumbar":6,"elderrelic6":1,"elderrelic12":1}}, + {"outputs":{"elderarmorchest":1},"time":15,"inputs":{"nocxiumbar":7,"elderrelic14":1,"elderrelic2":1}}, + {"outputs":{"elderarmorpants":1},"time":15,"inputs":{"nocxiumbar":5,"elderrelic5":1,"elderrelic1":1}}, + {"outputs":{"cultarmorhead":1},"time":15,"inputs":{"nocxiumbar":6,"elderrelic6":1,"elderrelic11":1}}, + {"outputs":{"cultarmorchest":1},"time":15,"inputs":{"nocxiumbar":7,"elderrelic7":1,"elderrelic12":1}}, + {"outputs":{"cultarmorpants":1},"time":15,"inputs":{"nocxiumbar":5,"elderrelic14":1,"elderrelic8":1}}, + {"outputs":{"eldermace":1},"time":15,"inputs":{"elderrelic14":1,"cthulureward":1,"elderrelic3":2}}, + {"outputs":{"eldershotgun":1},"time":15,"inputs":{"elderrelic8":1,"elderrelic12":5,"elderrelic4":1}}, + {"outputs":{"eldergrenadelauncher":1},"time":15,"inputs":{"cthulureward":1,"elderrelic1":3,"elderrelic11":2}}, + {"outputs":{"shoggothflesh":1},"time":1,"inputs":{"shoggothessence":5}}, + {"outputs":{"fuscienceresource":1000,"essence":1000},"time":1,"inputs":{"shoggothflesh":1}} + ] }