diff --git a/resources/tips.yml b/resources/tips.yml index 986887b..2006020 100644 --- a/resources/tips.yml +++ b/resources/tips.yml @@ -1,4 +1,23 @@ tips: - - 不要挖直上或直下! - - 使用!!etp back death返回死亡点 - - 新人在晚上建议挖三填一 \ No newline at end of file + - text: "不要挖直上或直下!/n小心掉进岩浆!" + weight: 20 + - text: "使用!!etp back death返回死亡点" + weight: 20 + - text: "新人在晚上建议挖三填一" + weight: 50 + - text: "Star Platinum!The World!" + weight: 10 + command: + - "tick freeze" + - 'execute as @a unless entity @s[nbt={active_effects:[{id:"minecraft:jump_boost"}]}] run effect give @s minecraft:jump_boost 1000000 255 true' + - 'execute as @a unless entity @s[nbt={active_effects:[{id:"minecraft:slowness"}]}] run effect give @s minecraft:slowness 1000000 255 true' + - 'execute as @a unless entity @s[nbt={active_effects:[{id:"minecraft:mining_fatigue"}]}] run effect give @s minecraft:mining_fatigue 1000000 255 true' + - 'execute as @a unless entity @s[nbt={active_effects:[{id:"minecraft:weakness"}]}] run effect give @s minecraft:weakness 1000000 255 true' + - "delay 5" + - 'execute as @a[nbt={active_effects:[{id:"minecraft:jump_boost",amplifier:-1b}]}] run effect clear @s minecraft:jump_boost' + - 'execute as @a[nbt={active_effects:[{id:"minecraft:slowness",amplifier:-1b}]}] run effect clear @s minecraft:slowness' + - 'execute as @a[nbt={active_effects:[{id:"minecraft:mining_fatigue",amplifier:-1b}]}] run effect clear @s minecraft:mining_fatigue' + - 'execute as @a[nbt={active_effects:[{id:"minecraft:weakness",amplifier:-1b}]}] run effect clear @s minecraft:weakness' + - "tick unfreeze" + - 'tellraw @a {"text":"[事件] §5时间开始流动!"}' + prefix: "[事件]" diff --git a/tips/__init__.py b/tips/__init__.py index deda5b9..60f2330 100644 --- a/tips/__init__.py +++ b/tips/__init__.py @@ -95,12 +95,48 @@ def send_tips(): if tips is not None: with tLock: while Task: - tip = random.choice(tips) - try: - tip = RText.from_json_object(tip) - except ValueError: - tip = str(tip) - psi.broadcast(RText.join(" ", [prefixRText, tip])) + + # 计算权重 + total_weight = sum(tip.get('weight', 0) for tip in tips) + + if total_weight != 0: + + # 权重分配 + rand = random.randint(1, total_weight) + current = 0 + selected_tip = None + commands = {} + + # 抽取tip + for one_tip in tips: + current += one_tip.get('weight', 0) + if rand <= current: + selected_tip = one_tip.get('text', None) + commands = one_tip.get('command', {}) + prefixRText = one_tip.get('prefix', prefixRText) + break + + if selected_tip is not None: + + # 执行tip附带的命令 + def execute_command(): + for command in commands: + # 添加命令delay的延时执行功能 + if command.startswith("delay"): + delay_time = float(command.split()[1]) + time.sleep(delay_time) + else: + psi.execute(command) + + # 用/n分行 + lines = selected_tip.split('/n') + for tip in lines: + try: + tip = RText.from_json_object(tip) + except ValueError: + tip = str(tip) + psi.broadcast(RText.join(" " if prefixRText is not "" and prefixRText is not None else "", [prefixRText if prefixRText is not None else "", tip])) + execute_command() time.sleep(interval)