汤锅功能实现 6

This commit is contained in:
wenhe committed 2026-09-16 14:08:24 +08:00
1 parent c342dcc93d
commit 72172ba09c
8 files changed
+679 -568

No files matched your search

@@ -36,7 +36,7 @@ from ....BlueFoxTools.ToolsConfig import LevelId
blockEntityDataComp = comp.CreateBlockEntityData(LevelId)
# ---- 只导入汤锅自己的数据库 ----
from ..TangguoData import SWITCH_RULES, ITEM_USE_ON_RULES, TIMER_RULES
from ..TangguoData import SWITCH_RULES, ITEM_USE_ON_RULES, TIMER_RULES, BOWL, PLATE
# ---- 统一分发器 ----
from ...service.FeatureDispatcher import FeatureDispatcher
@@ -83,6 +83,32 @@ class TangguoService(BlueFoxServerSystem):
cur = nxt
self._timerTotal[src] = (total, stages)
# 级数信息: source -> (当前第几级, 总级数) 用于提示"第X级/共Y级"
self._timerStages = {}
nextMap, prevMap = {}, {}
for r in TIMER_RULES:
if r.get("target"):
nextMap[r["source"]] = r["target"]
prevMap.setdefault(r["target"], r["source"])
for src in self._timerBySrc:
if src not in nextMap:
self._timerStages[src] = (1, 1)
continue
head = src
while head in prevMap and prevMap[head] in self._timerBySrc:
head = prevMap[head]
totalLevel, cur, seen = 0, head, set()
while cur in self._timerBySrc and cur not in seen:
seen.add(cur)
totalLevel += 1
cur = nextMap[cur]
cur, level, seen2 = head, 1, set()
while cur != src and cur in nextMap and cur not in seen2:
seen2.add(cur)
level += 1
cur = nextMap[cur]
self._timerStages[src] = (level, totalLevel)
# 终点方块 -> 成品名(从 take_out 规则 tip 的"盛出 XX"提取, 用于计时提示)
self._finalNames = {}
for r in SWITCH_RULES:
@@ -93,29 +119,47 @@ class TangguoService(BlueFoxServerSystem):
if nm:
self._finalNames[r["block"]] = nm
# 终点方块 -> 出锅动作(从 take_out 规则的 item 推断: 木碗/盘子/空手)
self._finalInfo = {}
for r in SWITCH_RULES:
if r.get("action") == "take_out":
it = r.get("item")
if it == BOWL:
self._finalInfo[r["block"]] = "手持木碗出锅"
elif it == PLATE:
self._finalInfo[r["block"]] = "手持盘子出锅"
elif it is None:
self._finalInfo[r["block"]] = "空手取出"
self.timerSources = set()
self.startTimerTips = {} # 空手右键启动计时 -> 提示(含总共多少秒)
self.timingTips = {} # 空手右键"已在计时中" -> 提示(同样含总共多少秒)
for src, r in self._timerBySrc.items():
self.timerSources.add(src)
self.featureBlocks.add(src) # 登记右键路由, 空手右键才分发到这里
total, stages = self._timerTotal[src]
total, stages = self._timerTotal[src] # total = 从当前级到终点剩余秒数
curLv, totLv = self._timerStages.get(src, (1, 1))
lvTip = "(第%d级/共%d级)" % (curLv, totLv) if totLv > 1 else ""
if len(stages) == 1:
stage = ""
perTip = ""
elif len(set(stages)) == 1:
stage = "(%d级×%d秒)" % (len(stages), stages[0])
perTip = "每级%d秒" % stages[0]
else:
stage = "(%d级: %s)" % (len(stages), "→".join("%d秒" % s for s in stages))
perTip = "先%d秒,再%s" % (stages[0], ",".join("%d秒" % s for s in stages[1:]))
perStr = (", " + perTip) if perTip else ""
if r.get("randomTargets"):
tip = "§a开始煮饭…共需计时%d秒%s; 计时结束变成 熟米饭(形态随机)" % (total, stage)
t2 = "§e正在煮饭中…共需计时%d秒%s, 计时结束变成 熟米饭(形态随机)" % (total, stage)
tip = "§a开始煮饭%s: 还需%d秒%s, 计时结束变成 熟米饭(形态随机)" % (lvTip, total, perStr)
t2 = "§e正在煮饭中%s: 还需%d秒%s, 计时结束变成 熟米饭(形态随机)" % (lvTip, total, perStr)
else:
tip = "§a开始熬制…共需计时%d秒%s" % (total, stage)
t2 = "§e正在熬制中…共需计时%d秒%s" % (total, stage)
end = self._timerTerminalName(src)
if end:
tip += "; 计时结束变成 %s" % end
t2 += ", 计时结束变成 %s" % end
endBlock = self._timerTerminal(src)
endName = self._finalNames.get(endBlock, "") if endBlock else ""
act = self._finalInfo.get(endBlock) if endBlock else None
actStr = (", " + act) if act else ""
base = "还需%d秒%s" % (total, perStr)
if endName:
base += ", 计时结束变成 %s%s" % (endName, actStr)
tip = "§a开始熬制%s: %s" % (lvTip, base)
t2 = "§e正在熬制中%s: %s" % (lvTip, base)
self.startTimerTips[src] = tip
self.timingTips[src] = t2
@@ -170,29 +214,29 @@ class TangguoService(BlueFoxServerSystem):
try:
data = blockEntityDataComp.GetBlockEntityData(dim, pos)
if data and data["rtdd_tid"] == blockName:
comp.CreateMsg(playerId).NotifyOneMessage(
playerId, self.timingTips.get(blockName, "§e已经在计时中"))
msg = self.timingTips.get(blockName) or "§e正在熬制中"
comp.CreateMsg(playerId).NotifyOneMessage(playerId, msg)
return
except Exception:
pass
started = FeatureDispatcher.startTimerFor(blockName, dim, pos, playerId)
if started:
comp.CreateMsg(playerId).NotifyOneMessage(
playerId, self.startTimerTips.get(blockName, "§a开始计时…"))
msg = self.startTimerTips.get(blockName) or "§a已启动计时"
comp.CreateMsg(playerId).NotifyOneMessage(playerId, msg)
else:
comp.CreateMsg(playerId).NotifyOneMessage(
playerId, "§c汤锅需要放在点燃的炉灶上才能开始计时")
playerId, "§c需要放在点燃的炉灶上")
def _timerTerminalName(self, src):
"""沿计时链走到终点方块, 返回成品名(未取到则返回空串)"""
def _timerTerminal(self, src):
"""沿计时链走到终点方块(返回方块id); randomTargets 返回 None"""
cur, seen = src, set()
while cur in self._timerBySrc and cur not in seen:
seen.add(cur)
r = self._timerBySrc[cur]
if r.get("randomTargets"):
return ""
return None
cur = r["target"]
return self._finalNames.get(cur, "")
return cur
def handleItemUseOn(self, args):
"""由 FeatureDispatcher 转发的"手持物品右键方块表面"入口(锅态汤面)。
@@ -266,7 +310,7 @@ class TangguoService(BlueFoxServerSystem):
return "rtdd:stewedsoup"
# ============================================================================
# 三、工具方法:获取玩家主手物品
# 三、工具方法,获取玩家主手物品
# ============================================================================
def getCarriedItem(self, playerId):
@@ -275,7 +319,7 @@ class TangguoService(BlueFoxServerSystem):
serverApi.GetMinecraftEnum().ItemPosType.CARRIED, 0, True)
# ============================================================================
# 四、工具方法:给玩家物品
# 四、工具方法,给玩家物品
# ============================================================================
def giveItem(self, playerId, itemName, count=1, aux=0):
@@ -286,7 +330,7 @@ class TangguoService(BlueFoxServerSystem):
pass
# ============================================================================
# 五、工具方法:消耗物品
# 五、工具方法,消耗物品
# ============================================================================
def consumeItem(self, playerId, itemDict, amount=1):
@@ -307,7 +351,7 @@ class TangguoService(BlueFoxServerSystem):
"userData": itemDict.get("userData", {})})
# ============================================================================
# 六、工具方法:以掉落物形式生成物品
# 六、工具方法,以掉落物形式生成物品
# ============================================================================
def dropItem(self, dim, pos, itemName, count=1, aux=0):
@@ -318,7 +362,7 @@ class TangguoService(BlueFoxServerSystem):
pass
# ============================================================================
# 七、工具方法:替换方块 / 清空方块(清空时 aux 强制 0, 兼容定向变体)
# 七、工具方法,替换方块 / 清空方块(清空时 aux 强制 0, 兼容定向变体)
# ============================================================================
def replaceBlock(self, pos, dim, newBlockName, playerId=None):
@@ -339,7 +383,7 @@ class TangguoService(BlueFoxServerSystem):
oldBlockHandling=0, dimensionId=dim)
# ============================================================================
# 八、工具方法:冷却检查
# 八、工具方法,冷却检查
# ============================================================================
def checkCooldown(self, key, cd=0.4):