change order of events

This commit is contained in:
bridge
2025-11-22 20:43:27 +08:00
parent 0cdcb6f5e1
commit 4d245653a6
5 changed files with 50 additions and 13 deletions

View File

@@ -13,11 +13,16 @@ class SwitchWeapon(InstantAction):
熟练度重置为0。
"""
COMMENT = "切换到指定类型的凡品兵器。当前兵器会丧失熟练度会重置为0。适用于想要更换兵器类型或从头修炼新兵器的情况。"
COMMENT = "切换到指定类型的凡品兵器,或卸下兵器。当前兵器会丧失熟练度会重置为0。适用于想要更换兵器类型或从头修炼新兵器的情况。"
DOABLES_REQUIREMENTS = "无前置条件"
PARAMS = {"weapon_type_name": "str"}
def _execute(self, weapon_type_name: str) -> None:
# 处理卸下兵器的情况
if weapon_type_name in ["", "None", "none", ""]:
self.avatar.change_weapon(None)
return
# 规范化兵器类型名称
normalized_type = normalize_weapon_type(weapon_type_name)
@@ -44,6 +49,12 @@ class SwitchWeapon(InstantAction):
# AI调用总是可以切换兵器
return True, ""
# 处理卸下兵器的情况
if weapon_type_name in ["", "None", "none", ""]:
if self.avatar.weapon is None:
return False, "当前已处于无兵器状态"
return True, ""
# 规范化并验证兵器类型
normalized_type = normalize_weapon_type(weapon_type_name)
target_weapon_type = None
@@ -53,10 +64,11 @@ class SwitchWeapon(InstantAction):
break
if target_weapon_type is None:
return False, f"未知兵器类型: {weapon_type_name}(支持的类型:剑/刀/枪/棍/扇/鞭/琴/笛/暗器)"
return False, f"未知兵器类型: {weapon_type_name}(支持的类型:剑/刀/枪/棍/扇/鞭/琴/笛/暗器/无"
# 检查是否已经是该类型的凡品兵器
if self.avatar.weapon.weapon_type == target_weapon_type and \
if self.avatar.weapon is not None and \
self.avatar.weapon.weapon_type == target_weapon_type and \
self.avatar.weapon.name == f"凡品{target_weapon_type.value}":
return False, f"已经装备了凡品{target_weapon_type.value}"
@@ -68,6 +80,13 @@ class SwitchWeapon(InstantAction):
return True, ""
def start(self, weapon_type_name: str) -> Event:
if weapon_type_name in ["", "None", "none", ""]:
return Event(
self.world.month_stamp,
f"{self.avatar.name} 卸下了兵器",
related_avatars=[self.avatar.id]
)
normalized_type = normalize_weapon_type(weapon_type_name)
return Event(
self.world.month_stamp,

View File

@@ -75,12 +75,15 @@ def translate_condition(condition: str) -> str:
vars_map = {
"avatar.weapon.type": "武器类型",
"avatar.weapon.weapon_type.value": "武器类型",
"avatar.weapon.proficiency": "兵器熟练度",
"avatar.weapon": "兵器",
"avatar.cultivation_progress.realm.value": "境界等级",
"avatar.cultivation.level": "修为等级",
"avatar.alignment": "立场",
"avatar.age": "年龄",
"avatar.spirit_animal": "灵兽",
"avatar.weapon.proficiency": "兵器熟练度",
"avatar.sect": "宗门",
"avatar.auxiliary": "辅助装备",
}
# 2. 枚举值映射

View File

@@ -29,7 +29,7 @@ id,name,exclusion_names,desc,rarity,condition,effects
27,腼腆,开放,你对待和他人结为道侣或者双修比较谨慎,N,
28,舔狗,孤僻;淡漠;刻薄;腼腆,你对异性中外貌出众者格外友善,倾向主动接近、帮助与合作。,N,
29,嫉妒,友爱;热情,你对在修为、外貌或财富等方面远超于你的人容易产生敌意,更倾向对其冷淡、挑衅或打压。,N,
30,穿越者,,你来自现代社会,怀念现代社会的一切,你的思考thinking必须是现代化的思考,SR,
30,穿越者,,你来自现代社会,怀念现代社会的一切,你的思考都还是现代化的思考模式,SR,
31,气运之子,,天生气运加身,更易遇到奇遇,战斗力也略有提升,SSR,,"{extra_fortune_probability: 0.05, extra_battle_strength_points: 2, extra_breakthrough_success_rate: 0.05}"
32,剑痴,怠惰;胆小,以剑入道,剑即是命。你认为剑道至上,战力强悍,但对剑道之外的事物兴趣寥寥。,SR,,"[{when: 'avatar.weapon.type == WeaponType.SWORD', extra_weapon_proficiency_gain: 1.0, extra_battle_strength_points: 3}]"
33,心机深沉,鲁莽;热情;外向,深藏不露,行事谨慎,善于算计。你不轻易暴露实力和想法,观察力敏锐,总在暗中盘算。,R,
@@ -37,7 +37,7 @@ id,name,exclusion_names,desc,rarity,condition,effects
35,狠辣,友爱;热情;胆小,行事果决狠辣,不留后患,斩草必除根。你认为心慈手软只会害了自己。,N,
36,重生者,无常;随性,经历过一世,对未来有模糊预知,行事更有目的性。你比常人更清楚什么重要,什么是陷阱。,SSR,
37,疑心重,热情;外向;友爱,对任何人都保持怀疑,不轻易信任,时刻警惕他人可能的背叛和算计。,N,
38,体修,惜命;胆小,专注肉身淬炼,体魄强健,近战无敌。你相信肉身才是修行的根本,法术只是旁门左道。,R,
38,体修,惜命;胆小,专注肉身淬炼,体魄强健,近战无敌。你相信肉身才是修行的根本,法术只是旁门左道。,R,,"[{when: 'avatar.weapon is None', extra_battle_strength_points: 5}]"
39,炼丹师,好斗,精通丹道,对灵药敏感,擅长炼制丹药。你认为丹药是修行的关键,战斗并非你的专长。,R,
40,福缘深厚,,天生福运,逢凶化吉。虽不如气运之子,但也常有小幸运眷顾。,SR,,{extra_fortune_probability: 0.02}
41,剑修,怠惰,对剑道有着深厚的兴趣和独特的天赋,持剑修炼时事半功倍。,R,,"[{when: 'avatar.weapon.type == WeaponType.SWORD', extra_weapon_proficiency_gain: 0.5, extra_battle_strength_points: 1}]"
1 id name exclusion_names desc rarity condition effects
29 27 腼腆 开放 你对待和他人结为道侣或者双修比较谨慎 N
30 28 舔狗 孤僻;淡漠;刻薄;腼腆 你对异性中外貌出众者格外友善,倾向主动接近、帮助与合作。 N
31 29 嫉妒 友爱;热情 你对在修为、外貌或财富等方面远超于你的人容易产生敌意,更倾向对其冷淡、挑衅或打压。 N
32 30 穿越者 你来自现代社会,怀念现代社会的一切,你的思考(thinking)必须是现代化的思考 你来自现代社会,怀念现代社会的一切,你的思考都还是现代化的思考模式 SR
33 31 气运之子 天生气运加身,更易遇到奇遇,战斗力也略有提升 SSR {extra_fortune_probability: 0.05, extra_battle_strength_points: 2, extra_breakthrough_success_rate: 0.05}
34 32 剑痴 怠惰;胆小 以剑入道,剑即是命。你认为剑道至上,战力强悍,但对剑道之外的事物兴趣寥寥。 SR [{when: 'avatar.weapon.type == WeaponType.SWORD', extra_weapon_proficiency_gain: 1.0, extra_battle_strength_points: 3}]
35 33 心机深沉 鲁莽;热情;外向 深藏不露,行事谨慎,善于算计。你不轻易暴露实力和想法,观察力敏锐,总在暗中盘算。 R
37 35 狠辣 友爱;热情;胆小 行事果决狠辣,不留后患,斩草必除根。你认为心慈手软只会害了自己。 N
38 36 重生者 无常;随性 经历过一世,对未来有模糊预知,行事更有目的性。你比常人更清楚什么重要,什么是陷阱。 SSR
39 37 疑心重 热情;外向;友爱 对任何人都保持怀疑,不轻易信任,时刻警惕他人可能的背叛和算计。 N
40 38 体修 惜命;胆小 专注肉身淬炼,体魄强健,近战无敌。你相信肉身才是修行的根本,法术只是旁门左道。 R [{when: 'avatar.weapon is None', extra_battle_strength_points: 5}]
41 39 炼丹师 好斗 精通丹道,对灵药敏感,擅长炼制丹药。你认为丹药是修行的关键,战斗并非你的专长。 R
42 40 福缘深厚 天生福运,逢凶化吉。虽不如气运之子,但也常有小幸运眷顾。 SR {extra_fortune_probability: 0.02}
43 41 剑修 怠惰 对剑道有着深厚的兴趣和独特的天赋,持剑修炼时事半功倍。 R [{when: 'avatar.weapon.type == WeaponType.SWORD', extra_weapon_proficiency_gain: 0.5, extra_battle_strength_points: 1}]

View File

@@ -1,10 +1,11 @@
<script setup lang="ts">
import { computed, ref } from 'vue'
import { computed, ref, watch, nextTick } from 'vue'
import { useWorldStore } from '../../stores/world'
import { NSelect } from 'naive-ui'
const worldStore = useWorldStore()
const filterValue = ref('all')
const eventListRef = ref<HTMLElement | null>(null)
const filterOptions = computed(() => [
{ label: '所有人', value: 'all' },
@@ -19,6 +20,15 @@ const filteredEvents = computed(() => {
return allEvents.filter(event => event.relatedAvatarIds.includes(filterValue.value))
})
// 自动滚动到底部
watch(filteredEvents, () => {
nextTick(() => {
if (eventListRef.value) {
eventListRef.value.scrollTop = eventListRef.value.scrollHeight
}
})
}, { deep: true })
const emptyEventMessage = computed(() => (
filterValue.value === 'all' ? '暂无事件' : '该修士暂无事件'
))
@@ -40,7 +50,7 @@ function formatEventDate(event: { year: number; month: number }) {
/>
</div>
<div v-if="filteredEvents.length === 0" class="empty">{{ emptyEventMessage }}</div>
<div v-else class="event-list">
<div v-else class="event-list" ref="eventListRef">
<div v-for="event in filteredEvents" :key="event.id" class="event-item">
<div class="event-date">{{ formatEventDate(event) }}</div>
<div class="event-content">{{ event.content || event.text }}</div>

View File

@@ -84,14 +84,14 @@ export const useWorldStore = defineStore('world', () => {
const combined = [...newEvents, ...events.value];
combined.sort((a, b) => {
// 1. 先按时间戳序(最的月在上面)
// 1. 先按时间戳序(最的月在上面)
const ta = a.timestamp;
const tb = b.timestamp;
if (tb !== ta) {
return tb - ta;
return ta - tb;
}
// 2. 时间相同时,按原始逻辑顺序序(发生的在上面)
// 2. 时间相同时,按原始逻辑顺序序(发生的在上面)
// 旧事件通常没有 _seq (undefined),视为最旧 (-1)
const seqA = (a as any)._seq ?? -1;
const seqB = (b as any)._seq ?? -1;
@@ -99,10 +99,15 @@ export const useWorldStore = defineStore('world', () => {
// 如果都是旧事件,保持相对顺序 (Stable)
if (seqA === -1 && seqB === -1) return 0;
return seqB - seqA;
return seqA - seqB;
});
events.value = combined.slice(0, MAX_EVENTS);
// 保留最新的 N 条 (因为是升序,最新的在最后,所以取最后 N 条)
if (combined.length > MAX_EVENTS) {
events.value = combined.slice(-MAX_EVENTS);
} else {
events.value = combined;
}
}
function handleTick(payload: TickPayloadDTO) {