game/addons/game_ai_npc/models/npc_behavior.py

43 lines
1.9 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# -*- coding: utf-8 -*-
from odoo import api, fields, models
ACTIVITY_LABELS = {
'sleep':'💤 睡眠', 'wake':'☀ 苏醒', 'eat':'🍽 用餐', 'work':'⚒ 劳作',
'rest':'🛋 休息', 'social':'💬 社交', 'wander':'🚶 游荡', 'explore':'🔍 探索',
'study':'📖 研习', 'craft':'🔨 制作', 'trade':'💰 交易', 'train':'⚔ 训练',
}
class GameNpcBehaviorLog(models.Model):
_name = 'game.npc.behavior.log'
_description = 'NPC 行为日志'
_order = 'tick_time desc, id desc'
_rec_name = 'summary'
npc_id = fields.Many2one('game.npc', string='角色', required=True, ondelete='cascade', index=True)
tick_time = fields.Datetime(string='行为时间', default=fields.Datetime.now, index=True)
activity = fields.Selection([
('sleep','睡眠'),('wake','苏醒'),('eat','用餐'),('work','劳作'),
('rest','休息'),('social','社交'),('wander','游荡'),('explore','探索'),
('study','研习'),('craft','制作'),('trade','交易'),('train','训练'),
], string='活动类型', required=True)
location = fields.Char(string='地点')
target_npc_id = fields.Many2one('game.npc', string='互动对象')
summary = fields.Char(string='简述', required=True)
detail = fields.Text(string='详细描述')
world_context = fields.Text(string='世界上下文',
help='Tick 时的世界状态 JSON供后续 LLM 对话使用')
activity_label = fields.Char(string='活动标签', compute='_compute_activity_label')
@api.depends('activity')
def _compute_activity_label(self):
for r in self:
r.activity_label = ACTIVITY_LABELS.get(r.activity, r.activity)
@api.model_create_multi
def create(self, vals_list):
for vals in vals_list:
if not vals.get('tick_time'):
vals['tick_time'] = fields.Datetime.now()
return super().create(vals_list)