一、心情值结构开放添加1、添加附加在Role上Mood心情值系统2、增加配置中所有有关mood心情值的登陆Mood结构初始化buff校验心情值门槛判定心情值结构返回以及通过配置的心情值变化事件等供服务调用的标准方法// 供心情值变化事件调用 func (mgr *RoleMgr) addMoodByEvent(ctx *GameContext, triggerType pb.MoodTriggerType, value int32) (*pb.MoodEvent, MoodValueChange, int32) { eventId : int32(triggerType) c : ctx.config.TbMood.Get(eventId) if c nil || value 0 { log.Warn(event not exist or value zero, log.Int32(eventId, eventId), log.Int32(value, value)) return nil, MoodValueChange{}, 0 } if c.Value 0 mgr.mood.Value ctx.config.TbGlobalConfig.Get().MaxMoodValue { return nil, MoodValueChange{}, 0 } if c.Value 0 mgr.mood.Value 0 { return nil, MoodValueChange{}, 0 } player : mgr.player now : player.NowUnix() event, exist : mgr.mood.Events[eventId] if !exist { event pb.MoodEvent{ Id: eventId, } } count : value if c.PerTimes 0 { total : event.RestValue value count total / c.PerTimes if c.StoreRest { event.RestValue total % c.PerTimes } } if count 0 { if c.StoreRest { mgr.setMoodEvent(event) } return nil, MoodValueChange{}, 0 } if c.DailyLimit ! 0 { if event.Count c.DailyLimit { ctx.Debug(mood daily limit, log.Int32(eventId, eventId)) return nil, MoodValueChange{}, 0 } if event.Countcount c.DailyLimit { count c.DailyLimit - event.Count } } if c.AddCd ! 0 { if event.LastTime 0 event.LastTimeint64(c.AddCd) now { ctx.Debug(mood event in cd , log.Int32(eventId, eventId)) return nil, MoodValueChange{}, 0 } } event.Count count event.LastTime now if c.AddCd ! 0 { event.NextAddTime now int64(c.AddCd) } else { event.NextAddTime 0 } changeValue : c.Value * count change : mgr.changeMoodValue(ctx, changeValue) mgr.player.TdaLogMoodChange(ctx, eventId, change.ChangeValue) mgr.setMoodEvent(event) ctx.Debug(mood event happened, log.Any(event, event), log.Int32(current mood value, mgr.mood.Value), log.Int32(change value, changeValue)) return event, change, c.Priority }// CheckMoodGateForBuff 校验指定心情值是否能使用对应的 buffEffect。 func (mgr *RoleMgr) CheckMoodGateForBuff(ctx *GameContext, mood int32, buffEffect pb.MoodBuffEffectType) MoodGateCheckResult { requiredMoodL, requiredMoodR : mgr.getRangeMoodValueWithoutBuffEffect(ctx, buffEffect) var result MoodGateCheckResult if !mgr.IsMoodSystemOpen(ctx) { result.Status pb.StatusCode_StatusCode_MOOD_SYSTEM_NOT_OPEN return result } if requiredMoodR 0 { // 配置表中没有定义不含该 buffEffect 的有效心情区间配置缺失或该 buff 覆盖所有阶段 result MoodGateCheckResult{ RequiredMood: -2, Shortfall: 0, } } else if mood requiredMoodL mood requiredMoodR { result MoodGateCheckResult{ RequiredMood: -1, Shortfall: 0, } } else if mood requiredMoodL { result MoodGateCheckResult{ RequiredMood: requiredMoodL, Shortfall: requiredMoodL - mood, } } else { result MoodGateCheckResult{ RequiredMood: requiredMoodR, Shortfall: requiredMoodR - mood, } } if result.RequiredMood -1 { result.Status pb.StatusCode_StatusCode_OK } else if result.RequiredMood -2 { result.Status pb.StatusCode_StatusCode_CFG_NOT_FOUND } else { result.Status pb.StatusCode_StatusCode_MOOD_NOT_ENOUGH } return result }3、Mood心情值系统开启定时器校验Mood系统的开启的Condition是否满足后判断是否开启// IsMoodSystemOpen 检测是否开启心情系统,当条件满足时进行初始化并标记 func (mgr *RoleMgr) IsMoodSystemOpen(ctx *GameContext) bool { if mgr.moodOpenNoticeSent { return true } mgr.CheckIsInit(ctx) return mgr.moodOpenNoticeSent }func (mgr *RoleMgr) SlowTick(ctx *GameContext, playerNowUnixMilli int64) bool { execute : false nowUnix : playerNowUnixMilli / 1000 mgr.checkMoodData(ctx, nowUnix, false) if mgr.AddMoodByEvent(ctx, pb.MoodTriggerType_MoodTriggerType_Offline_Deacy, 1) { execute true } if mgr.checkPawnData(ctx) { execute true } if mgr.checkPawnRoleInfoDirty(ctx) { execute true } return execute }定时器做mgr.AddMoodByEvent(ctx, pb.MoodTriggerType_MoodTriggerType_Offline_Deacy, 1)心情值时间衰减的任务任务中调用IsMoodSystemOpen判断并初始化。二、统一接口调用、埋点、信息推送1、接口调用直接调2、moodbuff影响点埋点埋点接口//供调用 func (mgr *RoleMgr) MoodBuffEffect(ctx *GameContext, buffId int32) { if buffId 0 { mgr.player.TdaLogMoodBuffEffect(ctx, buffId) } } //写入日志 func (player *Player) TdaLogMoodBuffEffect(ctx *GameContext, buffId int32) { distinctId : player.getTdaDistinctId() if distinctId { ctx.Debug(distinctId nil) return } headerLength : player.fillTdaEventCommLogHeader(ctx) eventProperties : make(map[string]any, headerLength2) eventProperties[td.TlpBuffId] buffId player.server.tdaLogRecorder.Track(td.TdaLogMoodBuffEffect, player.analysisAccountId, distinctId, util.MergeMap(eventProperties, player.getTdaEventCommLogHeader())) }Mood影响蓝图奖励埋点3、Mood系统开启信息推送// NotifyMoodOpenIfNeeded 通知玩家心情系统已开启。 func (mgr *RoleMgr) NotifyMoodOpenIfNeeded(ctx *GameContext) { mgr.player.Send(pb.OpenFunctionNotice{ Status: pb.StatusCode_StatusCode_OK, OpenFunctions: []pb.FunctionType{pb.FunctionType_FunctionType_MOOD}, }) }三、功能测试埋点日志检测