烹饪基本流程完成
This commit is contained in:
		
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							| @ -1,14 +1,14 @@ | |||||||
| local CookManager = {} | local CookManager = {} | ||||||
| local Utils = require("GamePlay.Utils") | local Utils = require("GamePlay.Utils") | ||||||
| local Emitter = require("Utils.Emitter") | local Emitter = require("Utils.Emitter") | ||||||
|  | local CookMaterialUtils = require("Utils.Cook.CookMaterial") | ||||||
| local ECookingHeat = import("ECookingHeat") | local ECookingHeat = import("ECookingHeat") | ||||||
|  |  | ||||||
| --- @enum ECookCheckStatus | --- @enum ECookCheckStatus | ||||||
| local ECookCheckStatus = { | local ECookCheckStatus = { | ||||||
|     Normal = 0,     -- 不用做任何操作 |     Normal = 0,     -- 不用做任何操作 | ||||||
|     NextState = 1,  -- 可以进入下一个阶段 |     NextState = 1,  -- 可以进入下一个阶段 | ||||||
|     OverCook = 2,   -- 炸锅了,结束游戏 |     Error = 2,      -- 出现了错误 | ||||||
|     Error = 3,      -- 出现了错误 |  | ||||||
| } | } | ||||||
|  |  | ||||||
| local function TemperatureToDoneness(temperature) | local function TemperatureToDoneness(temperature) | ||||||
| @ -16,6 +16,7 @@ local function TemperatureToDoneness(temperature) | |||||||
| end | end | ||||||
|  |  | ||||||
| function CookManager:Reset() | function CookManager:Reset() | ||||||
|  |     self.current_temperature = 0       -- 当前的温度 | ||||||
|     self.temperature_thresholds = {}   -- 温度临界值,缓存表格内容 |     self.temperature_thresholds = {}   -- 温度临界值,缓存表格内容 | ||||||
|     self.heating_record_table = {}     -- 食材受热记录表 |     self.heating_record_table = {}     -- 食材受热记录表 | ||||||
|  |  | ||||||
| @ -23,10 +24,11 @@ end | |||||||
|  |  | ||||||
| function CookManager:Tick(temperature, delta_time) | function CookManager:Tick(temperature, delta_time) | ||||||
|     local need_remove_record = {}   -- 记录已经到火候,或其他原因,需要移除的食材 |     local need_remove_record = {}   -- 记录已经到火候,或其他原因,需要移除的食材 | ||||||
|  |     self.current_temperature = temperature | ||||||
|  |  | ||||||
|     -- 遍历,为所有的食材加热 |     -- 遍历,为所有的食材加热 | ||||||
|     for cook_material_id, record_table in pairs(self.heating_record_table) do |     for cook_material_id, record_table in pairs(self.heating_record_table) do | ||||||
|         local doneness = TemperatureToDoneness(temperature) -- 获取此时的火候 |         local doneness = CookMaterialUtils.TemperatureToDoneness(temperature) -- 获取此时的火候 | ||||||
|         local record_value = record_table[doneness] or 0 |         local record_value = record_table[doneness] or 0 | ||||||
|         record_table[doneness] = record_value + (delta_time * 1000) |         record_table[doneness] = record_value + (delta_time * 1000) | ||||||
|  |  | ||||||
| @ -54,9 +56,6 @@ end | |||||||
|  |  | ||||||
| function CookManager:GetCookMaterialNextState(cook_material_id, doneness) | function CookManager:GetCookMaterialNextState(cook_material_id, doneness) | ||||||
|     local threshold = self.temperature_thresholds[cook_material_id] |     local threshold = self.temperature_thresholds[cook_material_id] | ||||||
|  |  | ||||||
|     print(threshold, "here ---------------") |  | ||||||
|  |  | ||||||
|     if not threshold then return "None" end |     if not threshold then return "None" end | ||||||
|     local state_config = threshold.CookConfig:Get(doneness) |     local state_config = threshold.CookConfig:Get(doneness) | ||||||
|     if not state_config then return "None" end |     if not state_config then return "None" end | ||||||
| @ -95,5 +94,18 @@ function CookManager:AddCookMaterial(cook_material_id, is_auto_push) | |||||||
|     Emitter.EmitEvent("cook_material_change", cook_material_id, is_auto_push) |     Emitter.EmitEvent("cook_material_change", cook_material_id, is_auto_push) | ||||||
| end | end | ||||||
|  |  | ||||||
|  | function CookManager:UseCookware(cookward_id) | ||||||
|  |     for cook_materiad_id, _ in pairs(self.heating_record_table) do | ||||||
|  |         local next_state = CookMaterialUtils.GetCookwareOpNextState( | ||||||
|  |             cookward_id, cook_materiad_id, self.current_temperature | ||||||
|  |         ) | ||||||
|  |         if next_state ~= "None" then | ||||||
|  |             self:AddCookMaterial(next_state, true) | ||||||
|  |         end | ||||||
|  |     end | ||||||
|  |  | ||||||
|  |     Emitter.EmitEvent("use_cookward", self.cookware_id) | ||||||
|  | end | ||||||
|  |  | ||||||
|  |  | ||||||
| return CookManager | return CookManager | ||||||
| @ -5,6 +5,7 @@ local Emitter = require("Utils.Emitter") | |||||||
| local ESlateVisibility = import("ESlateVisibility") | local ESlateVisibility = import("ESlateVisibility") | ||||||
|  |  | ||||||
| function CookingPot:ctor() | function CookingPot:ctor() | ||||||
|  |     self.cookware_click_handle = nil | ||||||
|     self.cook_material_change_handle = nil |     self.cook_material_change_handle = nil | ||||||
| end | end | ||||||
|  |  | ||||||
| @ -16,10 +17,16 @@ function CookingPot:Construct() | |||||||
|         function(cook_material_id, is_auto_push) self:OnCookMaterialChange(cook_material_id, is_auto_push) end |         function(cook_material_id, is_auto_push) self:OnCookMaterialChange(cook_material_id, is_auto_push) end | ||||||
|     ) |     ) | ||||||
|  |  | ||||||
|  |     self.cookware_click_handle = Emitter.OnEvent( | ||||||
|  |         "use_cookward", | ||||||
|  |         function(cookware_id) self:OnUseCookware(cookware_id) end | ||||||
|  |     ) | ||||||
|  |  | ||||||
| end | end | ||||||
|  |  | ||||||
| function CookingPot:Destruct() | function CookingPot:Destruct() | ||||||
|     Emitter.OffEvent("cook_material_change", self.cook_material_change_handle) |     Emitter.OffEvent("cook_material_change", self.cook_material_change_handle) | ||||||
|  |     Emitter.OffEvent("use_cookward", self.cookware_click_handle) | ||||||
| end | end | ||||||
|  |  | ||||||
|  |  | ||||||
| @ -34,6 +41,11 @@ function CookingPot:OnCookMaterialChange(cook_material_id, is_auto_push) | |||||||
|     end |     end | ||||||
| end | end | ||||||
|  |  | ||||||
|  | function CookingPot:OnUseCookware(cookware_id) | ||||||
|  |     self:PlayAnimation(self.Anim_StirFry, 0, 1, 0, 1, false) | ||||||
|  | end | ||||||
|  |  | ||||||
|  |  | ||||||
| function CookingPot:OnCookSlotClicked(config) | function CookingPot:OnCookSlotClicked(config) | ||||||
|     if config == nil then return end |     if config == nil then return end | ||||||
|     self.MaterialImg:SetVisibility(ESlateVisibility.SelfHitTestInvisible) |     self.MaterialImg:SetVisibility(ESlateVisibility.SelfHitTestInvisible) | ||||||
|  | |||||||
							
								
								
									
										22
									
								
								Content/Lua/HomeLand/UI/Hearth/Widgets/Cookware.lua
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								Content/Lua/HomeLand/UI/Hearth/Widgets/Cookware.lua
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,22 @@ | |||||||
|  | ---@class Cookware | ||||||
|  | local Cookware = {} | ||||||
|  | local Emitter = require("Utils.Emitter") | ||||||
|  | local CookManager = require("GamePlay.CookSystem.CookManager") | ||||||
|  |  | ||||||
|  |  | ||||||
|  | function Cookware:OnInitialized() | ||||||
|  |     self.cookware_id = 0 | ||||||
|  |     self.MainBtn.OnClicked:Add(function() | ||||||
|  |         CookManager:UseCookware(self.cookware_id) | ||||||
|  |     end) | ||||||
|  | end | ||||||
|  | function Cookware:Construct() | ||||||
|  |  | ||||||
|  | end | ||||||
|  |  | ||||||
|  | function Cookware:Destruct() | ||||||
|  |  | ||||||
|  | end | ||||||
|  |  | ||||||
|  |  | ||||||
|  | return Class(nil, nil, Cookware) | ||||||
							
								
								
									
										20
									
								
								Content/Lua/Utils/Cook/CookMaterial.lua
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								Content/Lua/Utils/Cook/CookMaterial.lua
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,20 @@ | |||||||
|  | local CookMaterialUtils = {} | ||||||
|  | local Utils = require("GamePlay.Utils") | ||||||
|  |  | ||||||
|  | function CookMaterialUtils.TemperatureToDoneness(temperature) | ||||||
|  |     return math.floor(temperature / 70) | ||||||
|  | end | ||||||
|  |  | ||||||
|  | function CookMaterialUtils.GetCookwareOpNextState(cookward_id, cook_material_id, temperature) | ||||||
|  |     local config = Utils.GetDataTableConfig( | ||||||
|  |         "CookMaterialStateConfig", cook_material_id | ||||||
|  |     ) | ||||||
|  |     if not config then return nil end | ||||||
|  |     local doneness = CookMaterialUtils.TemperatureToDoneness(temperature) | ||||||
|  |     local doneness_config = config.CookConfig:Get(doneness) | ||||||
|  |     if not doneness_config then return nil end | ||||||
|  |     return doneness_config.CookwareNextStateID | ||||||
|  | end | ||||||
|  |  | ||||||
|  |  | ||||||
|  | return CookMaterialUtils | ||||||
							
								
								
									
										
											BIN
										
									
								
								Content/Resource/Texture/UI/Homeland/Hearth/wokSpatula.uasset
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Content/Resource/Texture/UI/Homeland/Hearth/wokSpatula.uasset
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								Content/UI/HomeLand/Hearth/Widgets/WBP_Cookware.uasset
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Content/UI/HomeLand/Hearth/Widgets/WBP_Cookware.uasset
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							| @ -98,6 +98,9 @@ struct FBusyCookMaterialStateChangeConfig : public FTableRowBase { | |||||||
| 	UPROPERTY(EditAnywhere, BlueprintReadOnly, DisplayName = "用于渐变的资源") | 	UPROPERTY(EditAnywhere, BlueprintReadOnly, DisplayName = "用于渐变的资源") | ||||||
| 	TSoftObjectPtr<UObject> TransformMask; | 	TSoftObjectPtr<UObject> TransformMask; | ||||||
|  |  | ||||||
|  | 	UPROPERTY(EditAnywhere, BlueprintReadOnly, DisplayName = "使用厨具后,下一个状态ID") | ||||||
|  | 	FName CookwareNextStateID; | ||||||
|  |  | ||||||
| 	UPROPERTY(EditAnywhere, BlueprintReadOnly, DisplayName = "烹饪时长: Ms") | 	UPROPERTY(EditAnywhere, BlueprintReadOnly, DisplayName = "烹饪时长: Ms") | ||||||
| 	float CookingDuration; | 	float CookingDuration; | ||||||
| }; | }; | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user