胡萝卜牛肉汤ceshi2 位置缓存清空 退游戏保存数据
This commit is contained in:
1 parent
0c48f7f546
commit
6a35cee4be
2 files changed
+85
-20
No files matched your search
@@ -4,18 +4,18 @@
|
||||
每加一道新菜,只需要在这里加一条配方,不用写任何Python代码。
|
||||
|
||||
配方字段说明:
|
||||
source: 被右键的方块ID(必填)
|
||||
item: 玩家手里必须拿的物品,None=空手也行
|
||||
target: 替换成什么方块,None=不替换
|
||||
consume: 消耗物品数量,0=不消耗(默认1)
|
||||
giveItem: 额外给玩家什么物品
|
||||
stirCount: 需要翻炒几次才变身
|
||||
stirCd: 翻炒冷却时间(秒)
|
||||
onDone: "finish"=标记熟了不替换
|
||||
doneMsg: 完成后的提示消息
|
||||
failMsg: 冷却中/失败时的提示
|
||||
dropIfDone: 熟了后拆掉掉落什么
|
||||
dropIfNot: 没熟拆掉掉落什么
|
||||
source: 被右键的方块ID(必填)
|
||||
item: 玩家手里必须拿的物品,None=空手也行
|
||||
target: 替换成什么方块,None=不替换
|
||||
consume: 消耗物品数量,0=不消耗(默认1)
|
||||
giveItem: 额外给玩家什么物品
|
||||
stirCount: 需要翻炒几次才变身
|
||||
stirCd: 翻炒冷却时间(秒)
|
||||
onDone: "finish"=标记熟了不替换
|
||||
needFinished: True=只熟了才触发,False=熟了就不触发
|
||||
doneMsg: 完成后的提示消息
|
||||
dropIfDone: 熟了后拆掉掉落什么
|
||||
dropIfNot: 没熟拆掉掉落什么
|
||||
"""
|
||||
|
||||
RECIPES = [
|
||||
@@ -35,7 +35,6 @@ RECIPES = [
|
||||
"consume": 0,
|
||||
"stirCount": 5,
|
||||
"stirCd": 1.2,
|
||||
"failMsg": "这时候翻动会不好熟的!",
|
||||
},
|
||||
|
||||
# ===== 步骤3:第二阶段 + 木剑翻炒3次 → 标记熟了 =====
|
||||
@@ -47,9 +46,19 @@ RECIPES = [
|
||||
"stirCount": 3,
|
||||
"stirCd": 0.8,
|
||||
"onDone": "finish",
|
||||
"doneMsg": "出锅啦!拿盘子盛出来",
|
||||
"failMsg": "这时候翻动会不好熟的!",
|
||||
"needFinished": False,
|
||||
"doneMsg": "出锅啦!空手右键盛出来",
|
||||
"dropIfDone": ["minecraft:cooked_beef", "rtdd:wok"],
|
||||
"dropIfNot": ["minecraft:beef", "rtdd:wok"],
|
||||
},
|
||||
|
||||
# ===== 步骤4:熟了之后,空手右键 → 拿熟牛肉,锅变回空锅 =====
|
||||
{
|
||||
"source": "rtdd:carrotandbeef_1",
|
||||
"item": None,
|
||||
"needFinished": True,
|
||||
"target": "rtdd:wok",
|
||||
"giveItem": "minecraft:cooked_beef",
|
||||
"consume": 0,
|
||||
},
|
||||
]
|
||||
@@ -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)
|
||||
Reference in new issue
Block a user