refactor llm

This commit is contained in:
bridge
2025-11-19 01:23:55 +08:00
parent c4bc8daddc
commit e7d6ce7879
37 changed files with 499 additions and 315 deletions

View File

@@ -168,7 +168,7 @@ class ActualActionMixin():
...
@abstractmethod
def finish(self, **params) -> list[Event]:
async def finish(self, **params) -> list[Event]:
return []

View File

@@ -71,7 +71,7 @@ class Battle(InstantAction):
# InstantAction 已实现 step 完成
def finish(self, avatar_name: str) -> list[Event]:
async def finish(self, avatar_name: str) -> list[Event]:
res = self._last_result
if not (isinstance(res, tuple) and len(res) == 4):
return []
@@ -87,10 +87,10 @@ class Battle(InstantAction):
pass
result_event = Event(self.world.month_stamp, result_text, related_avatars=rel_ids, is_major=True)
# 生成战斗小故事(同步调用,与其他动作保持一致)
# 生成战斗小故事
target = self._get_target(avatar_name)
start_text = self._start_event_content if hasattr(self, '_start_event_content') else result_event.content
story = StoryTeller.tell_story(start_text, result_event.content, self.avatar, target, prompt=self.STORY_PROMPT)
story = await StoryTeller.tell_story(start_text, result_event.content, self.avatar, target, prompt=self.STORY_PROMPT)
story_event = Event(self.world.month_stamp, story, related_avatars=rel_ids, is_story=True)
return [result_event, story_event]

View File

@@ -118,7 +118,7 @@ class Breakthrough(TimedAction):
# TimedAction 已统一 step 逻辑
def finish(self) -> list[Event]:
async def finish(self) -> list[Event]:
if not self._last_result:
return []
result_ok = self._last_result[0] == "success"
@@ -139,7 +139,7 @@ class Breakthrough(TimedAction):
# 故事参与者:本体 +(可选)相关角色
prompt = TribulationSelector.get_story_prompt(str(calamity))
story = StoryTeller.tell_story(core_text, ("突破成功" if result_ok else "突破失败"), self.avatar, self._calamity_other, prompt=prompt)
story = await StoryTeller.tell_story(core_text, ("突破成功" if result_ok else "突破失败"), self.avatar, self._calamity_other, prompt=prompt)
events.append(Event(self.world.month_stamp, story, related_avatars=rel_ids, is_story=True))
return events

View File

@@ -85,7 +85,7 @@ class Catch(TimedAction):
region = self.avatar.tile.region
return Event(self.world.month_stamp, f"{self.avatar.name}{region.name} 尝试御兽", related_avatars=[self.avatar.id])
def finish(self) -> list[Event]:
async def finish(self) -> list[Event]:
res = self._caught_result
if not (isinstance(res, tuple) and len(res) == 3):
return []

View File

@@ -71,7 +71,7 @@ class Cultivate(TimedAction):
# TimedAction 已统一 step 逻辑
def finish(self) -> list[Event]:
async def finish(self) -> list[Event]:
return []

View File

@@ -32,7 +32,7 @@ class DevourMortals(TimedAction):
def start(self) -> Event:
return Event(self.world.month_stamp, f"{self.avatar.name} 在城镇开始吞噬凡人", related_avatars=[self.avatar.id])
def finish(self) -> list[Event]:
async def finish(self) -> list[Event]:
return []

View File

@@ -75,7 +75,7 @@ class Escape(InstantAction):
# InstantAction 已实现 step 完成
def finish(self, avatar_name: str) -> list[Event]:
async def finish(self, avatar_name: str) -> list[Event]:
return []

View File

@@ -65,7 +65,7 @@ class Harvest(TimedAction):
# TimedAction 已统一 step 逻辑
def finish(self) -> list[Event]:
async def finish(self) -> list[Event]:
return []

View File

@@ -43,7 +43,7 @@ class HelpMortals(TimedAction):
# TimedAction 已统一 step 逻辑
def finish(self) -> list[Event]:
async def finish(self) -> list[Event]:
return []

View File

@@ -65,7 +65,7 @@ class Hunt(TimedAction):
# TimedAction 已统一 step 逻辑
def finish(self) -> list[Event]:
async def finish(self) -> list[Event]:
return []

View File

@@ -67,7 +67,7 @@ class MoveAwayFromAvatar(TimedAction):
# TimedAction 已统一 step 逻辑
def finish(self, avatar_name: str) -> list[Event]:
async def finish(self, avatar_name: str) -> list[Event]:
return []

View File

@@ -47,7 +47,7 @@ class MoveAwayFromRegion(InstantAction):
# InstantAction 已实现 step 完成
def finish(self, region: str) -> list[Event]:
async def finish(self, region: str) -> list[Event]:
return []

View File

@@ -59,7 +59,7 @@ class MoveToAvatar(DefineAction, ActualActionMixin):
done = self.avatar.tile == target.tile
return ActionResult(status=(ActionStatus.COMPLETED if done else ActionStatus.RUNNING), events=[])
def finish(self, avatar_name: str) -> list[Event]:
async def finish(self, avatar_name: str) -> list[Event]:
return []

View File

@@ -52,7 +52,7 @@ class MoveToRegion(DefineAction, ActualActionMixin):
done = self.avatar.is_in_region(r) or ((self.avatar.pos_x, self.avatar.pos_y) in getattr(r, "cors", ()))
return ActionResult(status=(ActionStatus.COMPLETED if done else ActionStatus.RUNNING), events=[])
def finish(self, region: Region | str) -> list[Event]:
async def finish(self, region: Region | str) -> list[Event]:
return []

View File

@@ -63,7 +63,7 @@ class NurtureWeapon(TimedAction):
related_avatars=[self.avatar.id]
)
def finish(self) -> list[Event]:
async def finish(self) -> list[Event]:
weapon_name = self.avatar.weapon.name if self.avatar.weapon else "兵器"
proficiency = self.avatar.weapon_proficiency
# 注意升华事件已经在_execute中添加这里只添加完成事件

View File

@@ -31,7 +31,7 @@ class Play(TimedAction):
# TimedAction 已统一 step 逻辑
def finish(self) -> list[Event]:
async def finish(self) -> list[Event]:
return []

View File

@@ -48,7 +48,7 @@ class PlunderMortals(TimedAction):
# TimedAction 已统一 step 逻辑
def finish(self) -> list[Event]:
async def finish(self) -> list[Event]:
return []

View File

@@ -59,7 +59,7 @@ class SelfHeal(TimedAction):
# TimedAction 已统一 step 逻辑
def finish(self) -> list[Event]:
async def finish(self) -> list[Event]:
healed_total = int(getattr(self, "_healed_total", 0))
# 统一用一次事件简要反馈
return [Event(self.world.month_stamp, f"{self.avatar.name} 疗伤完成HP已回满本次恢复{healed_total}当前HP {self.avatar.hp}", related_avatars=[self.avatar.id])]

View File

@@ -79,7 +79,7 @@ class SellItems(InstantAction):
# InstantAction 已实现 step 完成
def finish(self, item_name: str) -> list[Event]:
async def finish(self, item_name: str) -> list[Event]:
return []

View File

@@ -75,6 +75,6 @@ class SwitchWeapon(InstantAction):
related_avatars=[self.avatar.id]
)
def finish(self, weapon_type_name: str) -> list[Event]:
async def finish(self, weapon_type_name: str) -> list[Event]:
return []