自动化烹饪流程
This commit is contained in:
@ -1,11 +1,31 @@
|
||||
local CookingBench = {}
|
||||
local Utils = require("GamePlay.Utils")
|
||||
local Emitter = require("Utils.Emitter")
|
||||
local CookManager = require("GamePlay.CookSystem.CookManager")
|
||||
local KismetSystemLibrary = import("KismetSystemLibrary")
|
||||
local ESlateVisibility = import("ESlateVisibility")
|
||||
|
||||
|
||||
--- 获取每次tick温度下降速度
|
||||
local function GetCoolingRate(wco)
|
||||
return 0.5
|
||||
end
|
||||
|
||||
--- 获取每次点火的效率
|
||||
local function GetHeatingEfficiency(wco)
|
||||
return 8
|
||||
end
|
||||
|
||||
local function GetMaxTemperature(wco)
|
||||
return 210
|
||||
end
|
||||
|
||||
function CookingBench:ctor()
|
||||
self.is_cooking = false
|
||||
self.temperature = 0
|
||||
self.max_temperature = 200
|
||||
|
||||
|
||||
self.burn_timer = nil
|
||||
end
|
||||
|
||||
@ -14,6 +34,7 @@ function CookingBench:OnInitialized()
|
||||
end
|
||||
|
||||
function CookingBench:Construct()
|
||||
CookManager:Reset()
|
||||
self:UpdateCookState()
|
||||
self:UpdateFireState()
|
||||
end
|
||||
@ -27,36 +48,44 @@ end
|
||||
|
||||
function CookingBench:OnRabbitClicked()
|
||||
if self.is_cooking then
|
||||
local new_value = self.temperature + 8
|
||||
if new_value > self.max_temperature then
|
||||
self.temperature = self.max_temperature
|
||||
local max = GetMaxTemperature(self)
|
||||
local once = GetHeatingEfficiency(self)
|
||||
local new_value = self.temperature + once
|
||||
if new_value > max then
|
||||
self.temperature = max
|
||||
else
|
||||
self.temperature = new_value
|
||||
end
|
||||
else
|
||||
self.is_cooking = true
|
||||
self.temperature = 100
|
||||
self.temperature = 50
|
||||
|
||||
self.burn_timer = KismetSystemLibrary.K2_SetTimerDelegate(
|
||||
slua.createDelegate(function()
|
||||
local new_value = self.temperature - 1
|
||||
if new_value > 0 then
|
||||
self.temperature = new_value
|
||||
else
|
||||
self.temperature = 0
|
||||
self.is_cooking = false
|
||||
KismetSystemLibrary.K2_ClearTimerHandle(self, self.burn_timer)
|
||||
self.burn_timer = nil
|
||||
end
|
||||
self:UpdateCookState()
|
||||
self:UpdateFireState()
|
||||
end),
|
||||
0.1, true, true, 0, 0
|
||||
slua.createDelegate(function() self:CookTick() end),
|
||||
1 / 30, true, true, 0, 0
|
||||
)
|
||||
end
|
||||
self:UpdateCookState()
|
||||
self:UpdateFireState()
|
||||
end
|
||||
|
||||
--- 每秒30次tick
|
||||
function CookingBench:CookTick()
|
||||
local drop_value = GetCoolingRate(self)
|
||||
local new_value = self.temperature - drop_value
|
||||
if new_value > 0 then
|
||||
self.temperature = new_value
|
||||
CookManager:Tick(self.temperature, 1 / 30)
|
||||
else
|
||||
self.temperature = 0
|
||||
self.is_cooking = false
|
||||
KismetSystemLibrary.K2_ClearTimerHandle(self, self.burn_timer)
|
||||
self.burn_timer = nil
|
||||
end
|
||||
self:UpdateCookState()
|
||||
self:UpdateFireState()
|
||||
end
|
||||
|
||||
function CookingBench:UpdateCookState()
|
||||
if self.temperature > 0 then
|
||||
self.WBP_CookingProcess:SetVisible(true)
|
||||
|
||||
@ -1,26 +1,43 @@
|
||||
-- 锅的控件
|
||||
local CookingPot = {}
|
||||
local Utils = require("GamePlay.Utils")
|
||||
local Emitter = require("Utils.Emitter")
|
||||
local ESlateVisibility = import("ESlateVisibility")
|
||||
|
||||
function CookingPot:ctor()
|
||||
self.cook_slot_clicked_handle = nil
|
||||
self.cook_material_change_handle = nil
|
||||
end
|
||||
|
||||
|
||||
function CookingPot:Construct()
|
||||
self.cook_slot_clicked_handle = Emitter.OnEvent(
|
||||
"cook_slot_clicked",
|
||||
function(slot) self:OnCookSlotClicked(slot) end
|
||||
self.MaterialImg:SetVisibility(ESlateVisibility.Collapsed)
|
||||
self.cook_material_change_handle = Emitter.OnEvent(
|
||||
"cook_material_change",
|
||||
function(cook_material_id, is_auto_push) self:OnCookMaterialChange(cook_material_id, is_auto_push) end
|
||||
)
|
||||
|
||||
end
|
||||
|
||||
function CookingPot:Destruct()
|
||||
Emitter.OffEvent("cook_slot_clicked", self.cook_slot_clicked_handle)
|
||||
Emitter.OffEvent("cook_material_change", self.cook_material_change_handle)
|
||||
end
|
||||
|
||||
function CookingPot:OnCookSlotClicked(slot)
|
||||
local item = slot:ConsumeMaterial()
|
||||
if item == nil then end
|
||||
|
||||
function CookingPot:OnCookMaterialChange(cook_material_id, is_auto_push)
|
||||
print(cook_material_id, is_auto_push)
|
||||
local config = Utils.GetHomelandItemDesc(cook_material_id)
|
||||
if config == nil then return end
|
||||
self.MaterialImg:SetVisibility(ESlateVisibility.SelfHitTestInvisible)
|
||||
self.MaterialImg:SetBrushFromSoftTexture(config.DisplayResource, true)
|
||||
if not is_auto_push then
|
||||
self:PlayAnimation(self.Anim_Cook, 0, 1, 0, 1, false)
|
||||
end
|
||||
end
|
||||
|
||||
function CookingPot:OnCookSlotClicked(config)
|
||||
if config == nil then return end
|
||||
self.MaterialImg:SetVisibility(ESlateVisibility.SelfHitTestInvisible)
|
||||
self.MaterialImg:SetBrushFromSoftTexture(config.DisplayResource, true)
|
||||
self:PlayAnimation(self.Anim_Cook, 0, 1, 0, 1, false)
|
||||
end
|
||||
|
||||
|
||||
@ -1,22 +1,21 @@
|
||||
local CookingSlot = {}
|
||||
local Emitter = require("Utils.Emitter")
|
||||
local CookManager = require("GamePlay.CookSystem.CookManager")
|
||||
local Utils = require("GamePlay.Utils")
|
||||
local ESlateVisibility = import("ESlateVisibility")
|
||||
|
||||
|
||||
|
||||
|
||||
function CookingSlot:ctor()
|
||||
self.cook_item = nil
|
||||
self.material = "500001"
|
||||
end
|
||||
|
||||
function CookingSlot:OnInitialized()
|
||||
self.MainBtn.OnClicked:Add(function()
|
||||
Emitter.EmitEvent("cook_slot_clicked", self)
|
||||
CookManager:AddCookMaterial(self.material)
|
||||
self:ConsumeMaterial()
|
||||
end)
|
||||
self:SetCookMaterial("400009")
|
||||
end
|
||||
|
||||
function CookingSlot:SetCookMaterial(cook_item)
|
||||
self.cook_item = cook_item
|
||||
function CookingSlot:SetCookMaterial(material)
|
||||
self.material = material
|
||||
self:RefreshDisplay()
|
||||
end
|
||||
|
||||
@ -26,14 +25,16 @@ end
|
||||
|
||||
function CookingSlot:RefreshDisplay()
|
||||
self:SetEmpty()
|
||||
if self.cook_item then
|
||||
self.CookingMaterialImg:SetVisibility(ESlateVisibility.SelfHitTestInvisible)
|
||||
end
|
||||
if not self.material then return end
|
||||
local config = Utils.GetHomelandItemDesc(self.material)
|
||||
if config == nil then return end
|
||||
self.CookingMaterialImg:SetBrushFromSoftTexture(config.DisplayResource, true)
|
||||
self.CookingMaterialImg:SetVisibility(ESlateVisibility.SelfHitTestInvisible)
|
||||
end
|
||||
|
||||
function CookingSlot:ConsumeMaterial()
|
||||
-- if self.cook_item == nil then return end
|
||||
local item = self.cook_item
|
||||
if self.material == nil then return end
|
||||
local item = self.material
|
||||
self:SetCookMaterial(nil)
|
||||
return item
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user