当前位置: 首页 > news >正文

心情值游戏系统实现

一、心情值结构开放添加

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.Count+count > c.DailyLimit { count = c.DailyLimit - event.Count } } if c.AddCd != 0 { if event.LastTime > 0 && event.LastTime+int64(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, headerLength+2) 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}, }) }

三、功能测试,埋点日志检测

http://www.gsyq.cn/news/1618261.html

相关文章:

  • 【MO三维路径规划】麝牛算法MO多无人机协同集群避障路径规划(目标函数:最低成本:路径、高度、威胁、转角)【含Matlab源码 15684期】
  • [特殊字符] 搬砖的秘密:为什么一次搬 64 块砖最快?
  • 本地化AI漫剧制作:Qwen与ComfyUI实战指南
  • 一个老股民的十年自白十年炒股没亏,但我劝你别学我
  • Rust项目开发完整教程
  • 车间地坪养护秘籍
  • MAX9744与PIC18LF45K50的音频功率放大系统设计
  • 出现“WSL 安装似乎已损坏”的错误通常意味着Windows子系统对于Linux(WSL)的某些组件可能未正确安装或注册。要解决这个问题,你可以尝试以
  • 【新品发布】AI PC快充防护再进阶!艾为电子推出Type‑C OVP系列产品
  • Harness Engineering 实践案例:如何Agent 写一份行为规范
  • Docker网络配置详解
  • Rust模块管理最佳实践
  • 16266350800----wLa6twBAf4yVW4gw----dc_sid=b6eb97905a1c240e1675f230d913b6b5;HMACCOUNT=97C7CB558BC7424
  • 智能体设计范式:Plan-and-Solve
  • C++ 纳秒级交易系统设计
  • 毕业设计项目 基于深度学习的驾驶行为检测(玩手机)
  • 昇腾AI处理器上下文切换优化实践与性能提升
  • 报文发送非网络基本功能
  • 冻库低温环境下的机器人搬运技术测评
  • ASP.NET Core 之 Identity 入门(一)
  • 给阿嬤一封来自云端的信(上)
  • Python装饰器开发实践
  • 终极Win11系统优化指南:免费工具让你的Windows 11运行如飞
  • 游戏编程十年总结(下)
  • 第5章 Function Call 与工具调用框架《AI Agent 开发平台资深技术专家 AI Agent 应用架构师 CTO 面试题库详解》
  • 【安全】Sql注入漏洞的危害和防御
  • GPU监控与进程管理:科研必备的nvidia-smi详解
  • 实测 Claude Sonnet 5 vs Claude Sonnet 4.6:别只看发布公告,API 跑起来才知道差距
  • 打包带在高温环境下会变形吗?
  • Python代码重构最佳实践