refactor(player): 调整颜色矩阵数据类型为float32并优化NPC定时任务逻辑
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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() {
|
||||
|
||||
// 获取当前地图的怪物配置
|
||||
|
||||
|
||||
@@ -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 //待确认是否刷新异色
|
||||
}
|
||||
|
||||
@@ -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"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user