feat(cache): 添加复合键缓存操作支持 添加了基于 uint32+string 组合键的缓存操作方法,包括 GetByCompoundKey、SetByCompoundKey、DelByCompoundKey 和 ContainsByCompoundKey 方法,用于处理用户ID和会话ID的组合缓存场景 fix(vscode): 添加 cSpell 配置支持 struc 词汇 refactor(session): 移除过时的会话管理方法 移除了基于单一字符串键的会话管理方法,因为已迁移到使用 复合键的缓存操作方式 ```
337 lines
12 KiB
Go
337 lines
12 KiB
Go
package info
|
||
|
||
import (
|
||
"blazing/common/data"
|
||
"blazing/modules/player/model"
|
||
"fmt"
|
||
|
||
"github.com/tnnmigga/enum"
|
||
)
|
||
|
||
type ChangePetInfo struct {
|
||
// UserId 米米号,野怪为0
|
||
UserId uint32 `json:"userId"`
|
||
// PetId 切换上场的精灵编号
|
||
ID uint32 `fieldDesc:"当前对战精灵ID" `
|
||
// PetName 精灵名字,固定16字节长度
|
||
Name string `struc:"[16]byte"`
|
||
// Level 切换上场的精灵等级
|
||
Level uint32 `json:"level"`
|
||
// Hp 切换上场的精灵当前生命值
|
||
Hp uint32 `json:"hp"`
|
||
// MaxHp 切换上场的精灵最大生命值
|
||
MaxHp uint32 `json:"maxHp"`
|
||
CatchTime uint32 `fieldDesc:"捕捉时间" `
|
||
}
|
||
type NoteInviteToFightOutboundInfo struct {
|
||
UserID uint32 `codec:"true"`
|
||
Nick string `struc:"[16]byte" default:"seer" json:"nick"` // 16字节昵称
|
||
// Mode 战斗模式 1 = 1v1 2 = 6v6
|
||
|
||
Mode uint32 `codec:"true"`
|
||
}
|
||
|
||
type S2C_NOTE_HANDLE_FIGHT_INVITE struct {
|
||
// UserID 对方的userid
|
||
UserID uint32
|
||
|
||
Nick string `struc:"[16]byte" default:"seer" json:"nick"` // 16字节昵称
|
||
// Result 处理结果
|
||
// 0=对方拒绝了对战
|
||
// 1=对方同意了对战
|
||
// 2=对方在线时长超过6小时
|
||
// 3=对方没有可出战的精灵
|
||
// 4=对方不在线
|
||
Result uint32
|
||
}
|
||
type Fightinfo struct {
|
||
///PlayerID uint32
|
||
// 战斗模式 1 = 1v1 2 = 6v6 3大乱斗 0 什么都不做
|
||
Mode uint32
|
||
//Type uint32 //战斗类型
|
||
|
||
Status uint32
|
||
}
|
||
|
||
// FightPetInfo 战斗精灵信息结构体,FightPetInfo类
|
||
type FightPetInfo struct {
|
||
// 用户ID(野怪为0),@UInt long
|
||
UserID uint32 `fieldDesc:"用户ID 野怪为0" `
|
||
|
||
// 当前对战精灵ID,@UInt long
|
||
ID uint32 `fieldDesc:"当前对战精灵ID" `
|
||
|
||
Name string `struc:"[16]byte"`
|
||
// 精灵的捕获时间,@UInt long
|
||
CatchTime uint32 `fieldDesc:"精灵的捕获时间" `
|
||
|
||
// 当前HP,@UInt long
|
||
Hp uint32 `fieldDesc:"当前HP" `
|
||
|
||
// 最大HP,@UInt long
|
||
MaxHp uint32 `fieldDesc:"最大HP" `
|
||
|
||
// 当前等级,@UInt long
|
||
Level uint32 `fieldDesc:"当前等级" `
|
||
|
||
// 精灵是否能捕捉(1为能捕捉,0为不能捕捉),
|
||
Catchable uint32 `fieldDesc:"精灵是否能捕捉. 1为能捕捉 0为不能捕捉" `
|
||
//能力提升属性
|
||
Prop [6]int8
|
||
}
|
||
type AttackValueS struct {
|
||
FAttack AttackValue
|
||
SAttack AttackValue
|
||
}
|
||
|
||
func NewAttackValue(userid uint32) *AttackValue {
|
||
return &AttackValue{
|
||
userid,
|
||
0,
|
||
0,
|
||
0,
|
||
0,
|
||
0,
|
||
0,
|
||
0,
|
||
0,
|
||
[]model.SkillInfo{},
|
||
0,
|
||
[20]int8{},
|
||
[6]int8{},
|
||
0,
|
||
}
|
||
}
|
||
|
||
// AttackValue 战斗中的攻击数值信息
|
||
type AttackValue struct {
|
||
UserID uint32 `json:"userId" fieldDescription:"玩家的米米号 与野怪对战userid = 0"`
|
||
SkillID uint32 `json:"skillId" fieldDescription:"使用技能的id"`
|
||
AttackTime uint32 `json:"attackTime" fieldDescription:"是否击中 如果为0 则miss 如果为1 则击中,2为必中"`
|
||
LostHp uint32 `json:"lostHp" fieldDescription:"我方造成的伤害"`
|
||
GainHp int32 `json:"gainHp" fieldDescription:"我方获得血量"`
|
||
RemainHp int32 `json:"remainHp" fieldDescription:"我方剩余血量"`
|
||
MaxHp uint32 `json:"maxHp" fieldDescription:"我方最大血量"`
|
||
//颜色
|
||
State uint32 `json:"state" `
|
||
SkillListLen uint32 `struc:"sizeof=SkillList"`
|
||
SkillList []model.SkillInfo `json:"skillList" fieldDescription:"根据精灵的数据插入技能 最多4条 不定长"`
|
||
IsCritical uint32 `json:"isCritical" fieldDescription:"是否暴击"`
|
||
Status [20]int8 //精灵的状态
|
||
// 攻击,防御,特供,特防,速度,命中
|
||
Prop [6]int8
|
||
Offensive float32
|
||
// OwnerMaxShield uint32 `json:"ownerMaxShield" fieldDescription:"我方最大护盾"`
|
||
// OwnerCurrentShield uint32 `json:"ownerCurrentShield" fieldDescription:"我方当前护盾"`
|
||
}
|
||
|
||
type WeakenedS struct {
|
||
Stack int8 `struc:"skip"`
|
||
Round int8
|
||
}
|
||
|
||
// 定义战斗状态枚举
|
||
// EnumPetStatus:宠物战斗异常/增益状态枚举,值范围 0-255
|
||
var PetStatus = enum.New[struct {
|
||
// 无状态(默认值)
|
||
NULL EnumPetStatus `enum:"255"`
|
||
// 麻痹:行动概率降低,有概率无法出手
|
||
Paralysis EnumPetStatus `enum:"0"`
|
||
// 中毒:每回合损失一定比例体力,持续至解除
|
||
Poisoned EnumPetStatus `enum:"1"`
|
||
// 烧伤:每回合损失体力,物理攻击威力降低50%
|
||
Burned EnumPetStatus `enum:"2"`
|
||
// 吸血:攻击时吸取对方体力回复自身(比例生效)
|
||
DrainHP EnumPetStatus `enum:"3"`
|
||
// 被吸血:自身体力被对方攻击时按比例被吸取
|
||
DrainedHP EnumPetStatus `enum:"4"`
|
||
// 冻伤:每回合损失体力,有概率无法行动,火系攻击可解除
|
||
Frozen EnumPetStatus `enum:"5"`
|
||
// 害怕:本回合完全无法进行攻击类操作
|
||
Fear EnumPetStatus `enum:"6"`
|
||
// 疲惫:连续使用同一技能后触发,暂时无法使用该技能
|
||
Tired EnumPetStatus `enum:"7"`
|
||
// 睡眠:无法行动,持续1-3回合后苏醒,受攻击可提前解除
|
||
Sleep EnumPetStatus `enum:"8"`
|
||
// 石化:无法行动,受到攻击时有概率解除,否则持续至回合结束
|
||
Petrified EnumPetStatus `enum:"9"`
|
||
// 混乱:行动时有概率攻击自身,持续若干回合后解除
|
||
Confused EnumPetStatus `enum:"10"`
|
||
// 衰弱:全属性降低,伤害输出减少,受治疗效果降低
|
||
Weakened EnumPetStatus `enum:"11"`
|
||
// 山神守护:免疫大部分异常状态,受到的所有伤害降低
|
||
MountainGodGuard EnumPetStatus `enum:"12"`
|
||
// 易燃:受到火系伤害翻倍,持续3回合或被火系攻击命中后解除
|
||
Flammable EnumPetStatus `enum:"13"`
|
||
// 狂暴:攻击属性提升,防御属性降低,无法自主选择攻击目标
|
||
Berserk EnumPetStatus `enum:"14"`
|
||
// 冰封:完全无法行动,持续固定回合数,仅特定技能可解除
|
||
IceBound EnumPetStatus `enum:"15"`
|
||
// 流血:每回合损失固定比例体力,无视部分防御效果
|
||
Bleeding EnumPetStatus `enum:"16"`
|
||
// 免疫能力下降:不会被敌方技能降低攻击/防御/速度等属性
|
||
ImmuneToStatDrop EnumPetStatus `enum:"17"`
|
||
// 免疫异常状态:不会被附加麻痹/中毒/烧伤等所有异常状态
|
||
ImmuneToAbnormal EnumPetStatus `enum:"18"`
|
||
// 瘫痪:完全无法行动,比麻痹效果更强,无概率解除
|
||
Paralyzed EnumPetStatus `enum:"19"`
|
||
// 失明(预留):命中概率大幅降低,技能命中率下降
|
||
// Blind EnumBattleStatus `enum:"20"`
|
||
}]()
|
||
|
||
// 枚举类型别名(根据实际枚举库要求定义)
|
||
type EnumPetStatus = byte
|
||
|
||
// 精灵的能力提升
|
||
type PropDict struct {
|
||
// 攻击(@UInt long → uint32)
|
||
Attack int8
|
||
// 防御(@UInt long → uint32)
|
||
Defence int8
|
||
// 特攻(@UInt long → uint32)
|
||
SpecialAttack int8
|
||
// 特防(@UInt long → uint32)
|
||
SpecialDefence int8
|
||
|
||
// 速度(@UInt long → uint32)
|
||
Speed int8
|
||
// 命中(@UInt long → uint32)
|
||
Accuracy int8
|
||
}
|
||
|
||
// BattleLevels 战斗属性等级结构体,对应原6字节数组
|
||
|
||
// NoteUseSkillOutboundInfo 战斗技能使用通知的出站信息结构体
|
||
type NoteUseSkillOutboundInfo struct {
|
||
FirstAttackInfo AttackValue // 本轮先手的精灵在释放技能结束后的状态
|
||
SecondAttackInfo AttackValue // 本轮后手的精灵在释放技能结束后的状态
|
||
}
|
||
|
||
type FightStartOutboundInfo struct {
|
||
// @UInt long类型
|
||
IsCanAuto uint32 `fieldDesc:"是否自动 默认给0 怀疑是自动战斗器使用的" `
|
||
|
||
// 当前战斗精灵信息1(前端通过userid判断是否为我方)
|
||
Info1 FightPetInfo `fieldDesc:"当前战斗精灵的信息 可能不准.看前端代码是以userid来判断哪个结构体是我方的" serialize:"struct"`
|
||
|
||
// 当前战斗精灵信息2(前端通过userid判断是否为我方)
|
||
Info2 FightPetInfo `fieldDesc:"当前战斗精灵的信息 可能不准.看前端代码是以userid来判断哪个结构体是我方的" serialize:"struct"`
|
||
}
|
||
|
||
type FightUserInfo struct {
|
||
// 用户ID(野怪为0),@UInt long
|
||
UserID uint32 `fieldDesc:"userID 如果为野怪则为0" `
|
||
|
||
// 玩家名称(野怪为UTF-8的'-',固定16字节)
|
||
// 使用[16]byte存储固定长度的字节数组
|
||
Nick string `struc:"[16]byte"`
|
||
}
|
||
type S2C_2404 struct {
|
||
// 用户ID(野怪为0),@UInt long
|
||
UserID uint32 `fieldDesc:"userID 如果为野怪则为0" `
|
||
}
|
||
type S2C_50005 struct {
|
||
//奖励称号
|
||
Title uint32
|
||
}
|
||
|
||
// NoteReadyToFightInfo 战斗准备就绪消息结构体,NoteReadyToFightInfo
|
||
type NoteReadyToFightInfo struct {
|
||
//MAXPET uint32 `struc:"skip"` // 最大精灵数 struc:"skip"`
|
||
// 战斗类型ID(与野怪战斗为3,与人战斗为1,前端似乎未使用)
|
||
// @UInt long
|
||
Status uint32 `fieldDesc:"战斗类型ID 但前端好像没有用到 与野怪战斗为3,与人战斗似乎是1" `
|
||
//Mode uint32 `struc:"skip"`
|
||
// 我方信息
|
||
OurInfo FightUserInfo `fieldDesc:"我方信息" serialize:"struct"`
|
||
// Our *socket.Player `struc:"skip"`
|
||
OurPetListLen uint32 `struc:"sizeof=OurPetList"`
|
||
// 我方携带精灵的信息
|
||
// ArrayList<ReadyFightPetInfo>,使用切片模拟动态列表
|
||
OurPetList []ReadyFightPetInfo `fieldDesc:"我方携带精灵的信息" serialize:"lengthFirst,lengthType=uint16,type=structArray"`
|
||
|
||
// 对方信息
|
||
OpponentInfo FightUserInfo `fieldDesc:"对方信息" serialize:"struct"`
|
||
//Opp *socket.Player `struc:"skip"`
|
||
OpponentPetListLen uint32 `struc:"sizeof=OpponentPetList"`
|
||
// 敌方的精灵信息
|
||
// 野怪战斗时:客户端接收此包前已生成精灵PetInfo,将部分信息写入该列表
|
||
OpponentPetList []ReadyFightPetInfo `fieldDesc:"敌方的精灵信息 如果是野怪 那么再给客户端发送这个包体时就提前生成好了这只精灵的PetInfo,然后把从PetInfo中把部分信息写入到这个敌方的精灵信息中再发送这个包结构体" serialize:"lengthFirst,lengthType=uint16,type=structArray"`
|
||
}
|
||
|
||
// 当A和B都 这时候给双方回复开始战斗包
|
||
func (t *NoteReadyToFightInfo) onBothFinished() {
|
||
fmt.Println("A和B都已完成,触发onBothFinished")
|
||
}
|
||
|
||
// ReadyFightPetInfo 准备战斗的精灵信息结构体,ReadyFightPetInfo类
|
||
type ReadyFightPetInfo struct {
|
||
// 精灵ID,@UInt long
|
||
ID uint32 `fieldDesc:"精灵ID" `
|
||
|
||
// 精灵等级,@UInt long
|
||
Level uint32 `fieldDesc:"精灵等级" `
|
||
|
||
// 精灵当前HP,@UInt long
|
||
Hp uint32 `fieldDesc:"精灵HP" `
|
||
|
||
// 精灵最大HP,@UInt long
|
||
MaxHp uint32 `fieldDesc:"最大HP" `
|
||
SkillListLen uint32 `struc:"sizeof=SkillList"`
|
||
// 技能信息列表(固定4个元素,技能ID和剩余PP,无技能则为0)
|
||
// List<SkillInfo>,初始化容量为4
|
||
SkillList []model.SkillInfo `fieldDesc:"技能信息 技能ID跟剩余PP 固定32字节 没有给0" serialize:"fixedLength=4,type=structArray"`
|
||
|
||
// 精灵捕获时间,@UInt long
|
||
CatchTime uint32 `fieldDesc:"精灵捕获时间" `
|
||
|
||
// 捕捉地图(固定给0),@UInt long
|
||
CatchMap uint32 `fieldDesc:"捕捉地图 给0" `
|
||
|
||
// 固定给0,@UInt long
|
||
CatchRect uint32 `fieldDesc:"给0" `
|
||
|
||
// 固定给0,@UInt long
|
||
CatchLevel uint32 `fieldDesc:"给0" `
|
||
SkinID uint32 `fieldDesc:"精灵皮肤ID" `
|
||
// 是否闪光(@UInt long → uint32,0=否,1=是)
|
||
ShinyLen uint32 `json:"-" struc:"sizeof=ShinyInfo"`
|
||
ShinyInfo []data.GlowFilter `json:"ShinyInfo,omitempty"`
|
||
}
|
||
|
||
// FightOverInfo 战斗结束信息结构体 2506
|
||
type FightOverInfo struct {
|
||
//0 正常结束
|
||
//1=isPlayerLost 对方玩家退出
|
||
// 2=isOvertime 超时
|
||
// 3=isDraw 双方平手
|
||
// 4=isSysError 系统错误
|
||
// 5=isNpcEscape 精灵主动逃跑
|
||
Winpet *model.PetInfo `struc:"skip"`
|
||
Round uint32 `struc:"skip"`
|
||
LastAttavue AttackValue `struc:"skip"`
|
||
//7 切磋结束
|
||
Reason EnumBattleOverReason // 固定值0
|
||
WinnerId uint32 // 胜者的米米号 野怪为0
|
||
TwoTimes uint32 // 双倍经验剩余次数
|
||
ThreeTimes uint32 // 三倍经验剩余次数
|
||
AutoFightTimes uint32 // 自动战斗剩余次数
|
||
EnergyTimes uint32 // 能量吸收器剩余次数
|
||
LearnTimes uint32 // 双倍学习器剩余次数
|
||
}
|
||
|
||
type CatchMonsterOutboundInfo struct {
|
||
// CatchTime 捕捉时间
|
||
|
||
CatchTime uint32 `json:"catchTime" `
|
||
// PetId 宠物编号
|
||
|
||
PetId uint32 `json:"petId" `
|
||
}
|
||
type LoadPercentOutboundInfo struct {
|
||
// 玩家userId,使用结构体标签模拟注解
|
||
Id uint32 `fieldDescription:"玩家userId" autoCodec:"true"`
|
||
// 加载百分比,使用结构体标签模拟注解
|
||
Percent uint32 `fieldDescription:"加载百分比" autoCodec:"true"`
|
||
}
|