From 09dad913fec3abdc473972e2b4352fa865f05b90 Mon Sep 17 00:00:00 2001 From: 1 <1@72wo.cn> Date: Wed, 17 Dec 2025 06:56:55 +0000 Subject: [PATCH] =?UTF-8?q?refactor(player):=20=E8=B0=83=E6=95=B4=E9=A2=9C?= =?UTF-8?q?=E8=89=B2=E7=9F=A9=E9=98=B5=E6=95=B0=E6=8D=AE=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E4=B8=BAfloat32=E5=B9=B6=E4=BC=98=E5=8C=96NPC=E5=AE=9A?= =?UTF-8?q?=E6=97=B6=E4=BB=BB=E5=8A=A1=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- logic/controller/map.go | 3 +-- logic/service/player/color.go | 14 +++++++------- logic/service/player/new.go | 3 +-- logic/service/player/player.go | 2 +- modules/blazing/model/pet.go | 4 ++-- 5 files changed, 12 insertions(+), 14 deletions(-) diff --git a/logic/controller/map.go b/logic/controller/map.go index bc304d4e..bef36b23 100644 --- a/logic/controller/map.go +++ b/logic/controller/map.go @@ -3,7 +3,6 @@ package controller import ( "blazing/common/socket/errorcode" "sync/atomic" - "time" "blazing/logic/service/fight" "blazing/logic/service/maphot" @@ -39,7 +38,7 @@ func (h Controller) MapHot(data *maphot.InInfo, c *player.Player) (result *mapho } func (h *Controller) MapLeave(data *space.LeaveMapInboundInfo, c *player.Player) (result *info.LeaveMapOutboundInfo, err errorcode.ErrorCode) { //这个时候player应该是空的 atomic.StoreUint32(&c.Canmon, 0) - c.MapNPC.Reset(5 * time.Second) + //data.Broadcast(c.Info.MapID, info.LeaveMapOutboundInfo{UserID: c.Info.UserID}) //同步广播 result = &info.LeaveMapOutboundInfo{ UserID: c.Info.UserID, diff --git a/logic/service/player/color.go b/logic/service/player/color.go index 91347a73..283b20d5 100644 --- a/logic/service/player/color.go +++ b/logic/service/player/color.go @@ -14,8 +14,8 @@ import ( // - redBias: 保持原有 R 偏好(0..1) // - brightnessScale: 0..1,0 表示不额外提升亮度(行为近似原函数),1 表示允许最大可用 offset(受每行 sum 限制) // 返回:20 字节矩阵(直接 uint8 原样使用) -func RandomMatrixNoSingleColorBright(seed int64, alphaRow [5]uint8, brightChance, redBias, brightnessScale float64) [20]uint8 { - var out [20]uint8 +func RandomMatrixNoSingleColorBright(seed int64, alphaRow [5]float32, brightChance, redBias, brightnessScale float64) [20]float32 { + var out [20]float32 // clamp params if brightChance < 0 { @@ -162,7 +162,7 @@ func RandomMatrixNoSingleColorBright(seed int64, alphaRow [5]uint8, brightChance } else { // 在 [minOffsetBase, allowedMax] 随机取一个 offset off := minOffsetBase + int(grand.Intn(allowedMax-minOffsetBase+1)) - out[base+4] = uint8(off) + out[base+4] = float32(off) hadOffsetRow = true } } @@ -200,9 +200,9 @@ func RandomMatrixNoSingleColorBright(seed int64, alphaRow [5]uint8, brightChance if allowedBySum < minOffsetBase { // 若仍不足则设为 min(minOffsetBase, allowedBySum) 或强制给一个较小的值 if allowedBySum > 0 { - out[base+4] = uint8(allowedBySum) + out[base+4] = float32(allowedBySum) } else { - out[base+4] = uint8(minOffsetBase) // 最后手段(风险低,因为我们可能已把 sum=0) + out[base+4] = float32(minOffsetBase) // 最后手段(风险低,因为我们可能已把 sum=0) } } else { desiredMax := int(float64(maxOffsetBase) * brightnessScale) @@ -213,7 +213,7 @@ func RandomMatrixNoSingleColorBright(seed int64, alphaRow [5]uint8, brightChance desiredMax = minOffsetBase } off := minOffsetBase + int(grand.Intn(desiredMax-minOffsetBase+1)) - out[base+4] = uint8(off) + out[base+4] = float32(off) } } @@ -226,6 +226,6 @@ func RandomMatrixNoSingleColorBright(seed int64, alphaRow [5]uint8, brightChance } // 便利 wrapper:默认 redBias=0.6,brightnessScale=0.5 -func RandomMatrixNoSingleColorBrightDefault(seed int64, alphaRow [5]uint8, brightChance float64) [20]uint8 { +func RandomMatrixNoSingleColorBrightDefault(seed int64, alphaRow [5]float32, brightChance float64) [20]float32 { return RandomMatrixNoSingleColorBright(seed, alphaRow, brightChance, 0.6, 0.5) } diff --git a/logic/service/player/new.go b/logic/service/player/new.go index 1258888c..4d8f9b8a 100644 --- a/logic/service/player/new.go +++ b/logic/service/player/new.go @@ -5,7 +5,6 @@ import ( "blazing/logic/service/common" "blazing/modules/base/service" "blazing/modules/blazing/model" - "time" ) // NewPlayer 使用 Options 模式创建 Player 实例 @@ -19,7 +18,7 @@ func NewPlayer(opts ...PlayerOption) *Player { p.User = service.NewBaseSysUserService() p.monsters = generateThreeUniqueNumbers() p.Done = NewDone(p) //发布订阅事件 - p.MapNPC = cool.Cron.ScheduleFunc(10*time.Second, func() { + p.MapNPC = cool.Cron.CustomFunc(p, func() { // 获取当前地图的怪物配置 diff --git a/logic/service/player/player.go b/logic/service/player/player.go index 40c1ac25..f7137df2 100644 --- a/logic/service/player/player.go +++ b/logic/service/player/player.go @@ -73,7 +73,7 @@ func (o *OgrePetInfo) RandSHiny(t int64) { } - o.ShinyInfo[0].ColorMatrixFilter = RandomMatrixNoSingleColorBrightDefault(time.Now().Unix()+t, [5]uint8{0, 0, 0, 1, 0}, 0.6) + o.ShinyInfo[0].ColorMatrixFilter = RandomMatrixNoSingleColorBrightDefault(time.Now().Unix()+t, [5]float32{0, 0, 0, 1, 0}, 0.6) //g.Dump(ttt.ShinyInfo) // ttt.Shiny = 0 //待确认是否刷新异色 } diff --git a/modules/blazing/model/pet.go b/modules/blazing/model/pet.go index 775620ce..4153c602 100644 --- a/modules/blazing/model/pet.go +++ b/modules/blazing/model/pet.go @@ -540,7 +540,7 @@ type GlowFilter struct { Color uint32 `json:"color,omitempty"` // Alpha 透明度,0.0~1.0(浮点型,无法用uint8,保留float64) - Alpha float64 `json:"alpha,omitempty"` + Alpha float32 `json:"alpha,omitempty"` // BlurX 水平模糊量,0~255(uint8),默认值 6 BlurX uint8 `json:"blurX,omitempty"` @@ -559,5 +559,5 @@ type GlowFilter struct { // Knockout 是否挖空,默认 false Knockout bool `json:"knockout,omitempty"` - ColorMatrixFilter [20]uint8 `json:"matrix,omitempty"` + ColorMatrixFilter [20]float32 `json:"matrix,omitempty"` }