胡萝卜牛肉汤ceshi2 位置缓存清空 退游戏保存数据

This commit is contained in:
wenhe committed 2026-07-21 16:42:24 +08:00
1 parent 0c48f7f546
commit 6a35cee4be
2 files changed
+85 -20

No files matched your search

@@ -101,11 +101,23 @@ class CookingService(BlueFoxServerSystem):
if not recipe:
return
# 从内存或方块数据加载翻炒进度
stirInfo = self.stirData.get(key)
if stirInfo is None:
stirInfo = self.loadStirData(playerId, pos, dim, recipe)
if stirInfo:
self.stirData[key] = stirInfo
if recipe.get("needFinished") is True and not stirInfo.get("finished"):
return
if recipe.get("needFinished") is False and stirInfo.get("finished"):
return
if recipe.get("stirCount"):
self.handleStir(key, recipe, playerId, pos, dim, itemDict)
return
self.executeRecipe(recipe, playerId, pos, dim, itemDict)
self.executeRecipe(recipe, playerId, pos, dim, itemDict, key)
# ==================== 配方匹配 ====================
@@ -121,7 +133,7 @@ class CookingService(BlueFoxServerSystem):
# ==================== 配方执行(普通替换) ====================
def executeRecipe(self, recipe, playerId, pos, dim, itemDict):
def executeRecipe(self, recipe, playerId, pos, dim, itemDict, key):
if not self.checkConditions(recipe, playerId, pos, dim, itemDict):
return
@@ -132,6 +144,7 @@ class CookingService(BlueFoxServerSystem):
if recipe.get("target"):
self.replaceBlock(pos, dim, recipe["target"], playerId)
self.clearStirData(key, playerId, pos, dim)
if recipe.get("giveItem"):
self.giveItem(playerId, recipe["giveItem"])
@@ -154,6 +167,7 @@ class CookingService(BlueFoxServerSystem):
data["count"] += 1
data["lastTime"] = now
self.stirData[key] = data
self.saveStirData(playerId, pos, dim, data)
# 提示进度
comp.CreateMsg(playerId).NotifyOneMessage(
@@ -164,11 +178,12 @@ class CookingService(BlueFoxServerSystem):
if recipe.get("onDone") == "finish":
data["finished"] = True
self.stirData[key] = data
self.saveStirData(playerId, pos, dim, data)
if recipe.get("doneMsg"):
comp.CreateMsg(playerId).NotifyOneMessage(playerId, recipe["doneMsg"])
elif recipe.get("target"):
self.replaceBlock(pos, dim, recipe["target"], playerId)
self.stirData.pop(key, None)
self.clearStirData(key, playerId, pos, dim)
# ==================== 条件检查 ====================
@@ -254,6 +269,44 @@ class CookingService(BlueFoxServerSystem):
except:
pass
# ==================== 翻炒数据持久化 ====================
def loadStirData(self, playerId, pos, dim, recipe):
"""从方块上读取之前保存的翻炒进度"""
try:
blockComp = comp.CreateBlockInfo(playerId)
blockData = blockComp.GetBlockEntityData(pos, dim)
if blockData and "rtdd_sc" in blockData:
return {
"count": blockData.get("rtdd_sc", 0),
"lastTime": blockData.get("rtdd_slt", 0.0),
"finished": blockData.get("rtdd_sf", False),
"dropIfDone": recipe.get("dropIfDone", []),
"dropIfNot": recipe.get("dropIfNot", []),
}
except:
pass
return {}
def saveStirData(self, playerId, pos, dim, data):
"""把翻炒进度保存到方块上,退游戏再进也不会丢"""
try:
comp.CreateBlockInfo(playerId).SetBlockEntityData(pos, dim, {
"rtdd_sc": data["count"],
"rtdd_slt": data["lastTime"],
"rtdd_sf": data["finished"],
})
except:
pass
def clearStirData(self, key, playerId, pos, dim):
"""清除内存和方块上的翻炒数据"""
self.stirData.pop(key, None)
try:
comp.CreateBlockInfo(playerId).SetBlockEntityData(pos, dim, {})
except:
pass
# ==================== 拆方块处理 ====================
def OnDestroy(self, args):
@@ -269,7 +322,10 @@ class CookingService(BlueFoxServerSystem):
data = self.stirData.get(key)
if not data:
return
# 尝试从方块数据加载
data = self.loadStirData(playerId, (x, y, z), dim, {})
if not data:
return
if data.get("finished"):
dropItems = data.get("dropIfDone", [])
@@ -279,4 +335,4 @@ class CookingService(BlueFoxServerSystem):
for itemName in dropItems:
self.giveItem(playerId, itemName)
self.stirData.pop(key, None)
self.clearStirData(key, playerId, (x, y, z), dim)