mirror of
https://github.com/FlourishingWorld/hk4e.git
synced 2026-02-23 14:32:27 +08:00
优化架构
This commit is contained in:
111
gs/model/Item.go
Normal file
111
gs/model/Item.go
Normal file
@@ -0,0 +1,111 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"hk4e/gs/constant"
|
||||
)
|
||||
|
||||
type Item struct {
|
||||
ItemId uint32 `bson:"itemId"` // 道具id
|
||||
Count uint32 `bson:"count"` // 道具数量
|
||||
Guid uint64 `bson:"-"`
|
||||
}
|
||||
|
||||
func (p *Player) InitAllItem() {
|
||||
for itemId, item := range p.ItemMap {
|
||||
item.Guid = p.GetNextGameObjectGuid()
|
||||
p.ItemMap[itemId] = item
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Player) GetItemGuid(itemId uint32) uint64 {
|
||||
itemInfo := p.ItemMap[itemId]
|
||||
if itemInfo == nil {
|
||||
return 0
|
||||
}
|
||||
return itemInfo.Guid
|
||||
}
|
||||
|
||||
func (p *Player) GetItemCount(itemId uint32) uint32 {
|
||||
isVirtualItem, prop := p.GetVirtualItemProp(itemId)
|
||||
if isVirtualItem {
|
||||
value := p.PropertiesMap[prop]
|
||||
return value
|
||||
} else {
|
||||
itemInfo := p.ItemMap[itemId]
|
||||
if itemInfo == nil {
|
||||
return 0
|
||||
}
|
||||
return itemInfo.Count
|
||||
}
|
||||
}
|
||||
|
||||
// 虚拟道具如下 实际值存在玩家的属性上
|
||||
// 原石 201
|
||||
// 摩拉 202
|
||||
// 创世结晶 203
|
||||
// 树脂 106
|
||||
// 传说任务钥匙 107
|
||||
// 洞天宝钱 204
|
||||
|
||||
func (p *Player) GetVirtualItemProp(itemId uint32) (isVirtualItem bool, prop uint16) {
|
||||
switch itemId {
|
||||
case 106:
|
||||
return true, constant.PlayerPropertyConst.PROP_PLAYER_RESIN
|
||||
case 107:
|
||||
return true, constant.PlayerPropertyConst.PROP_PLAYER_LEGENDARY_KEY
|
||||
case 201:
|
||||
return true, constant.PlayerPropertyConst.PROP_PLAYER_HCOIN
|
||||
case 202:
|
||||
return true, constant.PlayerPropertyConst.PROP_PLAYER_SCOIN
|
||||
case 203:
|
||||
return true, constant.PlayerPropertyConst.PROP_PLAYER_MCOIN
|
||||
case 204:
|
||||
return true, constant.PlayerPropertyConst.PROP_PLAYER_HOME_COIN
|
||||
default:
|
||||
return false, 0
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Player) AddItem(itemId uint32, count uint32) {
|
||||
isVirtualItem, prop := p.GetVirtualItemProp(itemId)
|
||||
if isVirtualItem {
|
||||
value := p.PropertiesMap[prop]
|
||||
value += count
|
||||
p.PropertiesMap[prop] = value
|
||||
} else {
|
||||
itemInfo := p.ItemMap[itemId]
|
||||
if itemInfo == nil {
|
||||
itemInfo = &Item{
|
||||
ItemId: itemId,
|
||||
Count: 0,
|
||||
Guid: p.GetNextGameObjectGuid(),
|
||||
}
|
||||
}
|
||||
itemInfo.Count += count
|
||||
p.ItemMap[itemId] = itemInfo
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Player) CostItem(itemId uint32, count uint32) {
|
||||
isVirtualItem, prop := p.GetVirtualItemProp(itemId)
|
||||
if isVirtualItem {
|
||||
value := p.PropertiesMap[prop]
|
||||
if value < count {
|
||||
value = 0
|
||||
} else {
|
||||
value -= count
|
||||
}
|
||||
p.PropertiesMap[prop] = value
|
||||
} else {
|
||||
itemInfo := p.ItemMap[itemId]
|
||||
if itemInfo == nil {
|
||||
return
|
||||
}
|
||||
if itemInfo.Count < count {
|
||||
itemInfo.Count = 0
|
||||
} else {
|
||||
itemInfo.Count -= count
|
||||
}
|
||||
p.ItemMap[itemId] = itemInfo
|
||||
}
|
||||
}
|
||||
173
gs/model/avatar.go
Normal file
173
gs/model/avatar.go
Normal file
@@ -0,0 +1,173 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
gdc "hk4e/gs/config"
|
||||
"hk4e/gs/constant"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Avatar struct {
|
||||
AvatarId uint32 `bson:"avatarId"` // 角色id
|
||||
Level uint8 `bson:"level"` // 等级
|
||||
Exp uint32 `bson:"exp"` // 经验值
|
||||
Promote uint8 `bson:"promote"` // 突破等阶
|
||||
Satiation uint32 `bson:"satiation"` // 饱食度
|
||||
SatiationPenalty uint32 `bson:"satiationPenalty"` // 饱食度溢出
|
||||
CurrHP float64 `bson:"currHP"` // 当前生命值
|
||||
CurrEnergy float64 `bson:"currEnergy"` // 当前元素能量值
|
||||
FetterList []uint32 `bson:"fetterList"` // 资料解锁条目
|
||||
SkillLevelMap map[uint32]uint32 `bson:"skillLevelMap"` // 技能等级
|
||||
SkillExtraChargeMap map[uint32]uint32 `bson:"skillExtraChargeMap"`
|
||||
ProudSkillBonusMap map[uint32]uint32 `bson:"proudSkillBonusMap"`
|
||||
SkillDepotId uint32 `bson:"skillDepotId"`
|
||||
CoreProudSkillLevel uint8 `bson:"coreProudSkillLevel"` // 已解锁命之座层数
|
||||
TalentIdList []uint32 `bson:"talentIdList"` // 已解锁命之座技能列表
|
||||
ProudSkillList []uint32 `bson:"proudSkillList"` // 被动技能列表
|
||||
FlyCloak uint32 `bson:"flyCloak"` // 当前风之翼
|
||||
Costume uint32 `bson:"costume"` // 当前衣装
|
||||
BornTime int64 `bson:"bornTime"` // 获得时间
|
||||
FetterLevel uint8 `bson:"fetterLevel"` // 好感度等级
|
||||
FetterExp uint32 `bson:"fetterExp"` // 好感度经验
|
||||
NameCardRewardId uint32 `bson:"nameCardRewardId"`
|
||||
NameCardId uint32 `bson:"nameCardId"`
|
||||
Guid uint64 `bson:"-"`
|
||||
EquipGuidList map[uint64]uint64 `bson:"-"`
|
||||
EquipWeapon *Weapon `bson:"-"`
|
||||
EquipReliquaryList []*Reliquary `bson:"-"`
|
||||
FightPropMap map[uint32]float32 `bson:"-"`
|
||||
ExtraAbilityEmbryos map[string]bool `bson:"-"`
|
||||
}
|
||||
|
||||
func (p *Player) InitAllAvatar() {
|
||||
for _, avatar := range p.AvatarMap {
|
||||
p.InitAvatar(avatar)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Player) InitAvatar(avatar *Avatar) {
|
||||
avatarDataConfig := gdc.CONF.AvatarDataMap[int32(avatar.AvatarId)]
|
||||
// 角色战斗属性
|
||||
avatar.FightPropMap = make(map[uint32]float32)
|
||||
avatar.FightPropMap[uint32(constant.FightPropertyConst.FIGHT_PROP_NONE)] = 0.0
|
||||
// 白字攻防血
|
||||
avatar.FightPropMap[uint32(constant.FightPropertyConst.FIGHT_PROP_BASE_ATTACK)] = float32(avatarDataConfig.GetBaseAttackByLevel(avatar.Level))
|
||||
avatar.FightPropMap[uint32(constant.FightPropertyConst.FIGHT_PROP_BASE_DEFENSE)] = float32(avatarDataConfig.GetBaseDefenseByLevel(avatar.Level))
|
||||
avatar.FightPropMap[uint32(constant.FightPropertyConst.FIGHT_PROP_BASE_HP)] = float32(avatarDataConfig.GetBaseHpByLevel(avatar.Level))
|
||||
// 白字+绿字攻防血
|
||||
avatar.FightPropMap[uint32(constant.FightPropertyConst.FIGHT_PROP_CUR_ATTACK)] = float32(avatarDataConfig.GetBaseAttackByLevel(avatar.Level))
|
||||
avatar.FightPropMap[uint32(constant.FightPropertyConst.FIGHT_PROP_CUR_DEFENSE)] = float32(avatarDataConfig.GetBaseDefenseByLevel(avatar.Level))
|
||||
avatar.FightPropMap[uint32(constant.FightPropertyConst.FIGHT_PROP_MAX_HP)] = float32(avatarDataConfig.GetBaseHpByLevel(avatar.Level))
|
||||
// 当前血量
|
||||
avatar.FightPropMap[uint32(constant.FightPropertyConst.FIGHT_PROP_CUR_HP)] = float32(avatar.CurrHP)
|
||||
// 双暴
|
||||
avatar.FightPropMap[uint32(constant.FightPropertyConst.FIGHT_PROP_CRITICAL)] = float32(avatarDataConfig.Critical)
|
||||
avatar.FightPropMap[uint32(constant.FightPropertyConst.FIGHT_PROP_CRITICAL_HURT)] = float32(avatarDataConfig.CriticalHurt)
|
||||
// 元素充能
|
||||
avatar.FightPropMap[uint32(constant.FightPropertyConst.FIGHT_PROP_CHARGE_EFFICIENCY)] = 1.0
|
||||
p.SetCurrEnergy(avatar, avatar.CurrEnergy, true)
|
||||
// guid
|
||||
avatar.Guid = p.GetNextGameObjectGuid()
|
||||
p.GameObjectGuidMap[avatar.Guid] = GameObject(avatar)
|
||||
avatar.EquipGuidList = make(map[uint64]uint64)
|
||||
p.AvatarMap[avatar.AvatarId] = avatar
|
||||
return
|
||||
}
|
||||
|
||||
func (p *Player) AddAvatar(avatarId uint32) {
|
||||
avatarDataConfig := gdc.CONF.AvatarDataMap[int32(avatarId)]
|
||||
skillDepotId := int32(0)
|
||||
// 主角要单独设置
|
||||
if avatarId == 10000005 {
|
||||
skillDepotId = 504
|
||||
} else if avatarId == 10000007 {
|
||||
skillDepotId = 704
|
||||
} else {
|
||||
skillDepotId = avatarDataConfig.SkillDepotId
|
||||
}
|
||||
avatarSkillDepotDataConfig := gdc.CONF.AvatarSkillDepotDataMap[skillDepotId]
|
||||
avatar := &Avatar{
|
||||
AvatarId: avatarId,
|
||||
Level: 1,
|
||||
Exp: 0,
|
||||
Promote: 0,
|
||||
Satiation: 0,
|
||||
SatiationPenalty: 0,
|
||||
CurrHP: 0,
|
||||
CurrEnergy: 0,
|
||||
FetterList: nil,
|
||||
SkillLevelMap: make(map[uint32]uint32),
|
||||
SkillExtraChargeMap: make(map[uint32]uint32),
|
||||
ProudSkillBonusMap: nil,
|
||||
SkillDepotId: uint32(avatarSkillDepotDataConfig.Id),
|
||||
CoreProudSkillLevel: 0,
|
||||
TalentIdList: make([]uint32, 0),
|
||||
ProudSkillList: make([]uint32, 0),
|
||||
FlyCloak: 140001,
|
||||
Costume: 0,
|
||||
BornTime: time.Now().Unix(),
|
||||
FetterLevel: 1,
|
||||
FetterExp: 0,
|
||||
NameCardRewardId: 0,
|
||||
NameCardId: 0,
|
||||
Guid: 0,
|
||||
EquipGuidList: nil,
|
||||
EquipWeapon: nil,
|
||||
EquipReliquaryList: nil,
|
||||
FightPropMap: nil,
|
||||
ExtraAbilityEmbryos: nil,
|
||||
}
|
||||
|
||||
if avatarSkillDepotDataConfig.EnergySkill > 0 {
|
||||
avatar.SkillLevelMap[uint32(avatarSkillDepotDataConfig.EnergySkill)] = 1
|
||||
}
|
||||
for _, skillId := range avatarSkillDepotDataConfig.Skills {
|
||||
if skillId > 0 {
|
||||
avatar.SkillLevelMap[uint32(skillId)] = 1
|
||||
}
|
||||
}
|
||||
for _, openData := range avatarSkillDepotDataConfig.InherentProudSkillOpens {
|
||||
if openData.ProudSkillGroupId == 0 {
|
||||
continue
|
||||
}
|
||||
if openData.NeedAvatarPromoteLevel <= int32(avatar.Promote) {
|
||||
proudSkillId := (openData.ProudSkillGroupId * 100) + 1
|
||||
// TODO if GameData.getProudSkillDataMap().containsKey(proudSkillId) java
|
||||
avatar.ProudSkillList = append(avatar.ProudSkillList, uint32(proudSkillId))
|
||||
}
|
||||
}
|
||||
avatar.CurrHP = avatarDataConfig.GetBaseHpByLevel(avatar.Level)
|
||||
|
||||
p.InitAvatar(avatar)
|
||||
p.AvatarMap[avatarId] = avatar
|
||||
}
|
||||
|
||||
func (p *Player) SetCurrEnergy(avatar *Avatar, value float64, max bool) {
|
||||
avatarDataConfig := gdc.CONF.AvatarDataMap[int32(avatar.AvatarId)]
|
||||
avatarSkillDepotDataConfig := gdc.CONF.AvatarSkillDepotDataMap[avatarDataConfig.SkillDepotId]
|
||||
if avatarSkillDepotDataConfig == nil || avatarSkillDepotDataConfig.EnergySkillData == nil {
|
||||
return
|
||||
}
|
||||
element := avatarSkillDepotDataConfig.ElementType
|
||||
avatar.FightPropMap[uint32(element.MaxEnergyProp)] = float32(avatarSkillDepotDataConfig.EnergySkillData.CostElemVal)
|
||||
if max {
|
||||
avatar.FightPropMap[uint32(element.CurrEnergyProp)] = float32(avatarSkillDepotDataConfig.EnergySkillData.CostElemVal)
|
||||
} else {
|
||||
avatar.FightPropMap[uint32(element.CurrEnergyProp)] = float32(value)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Player) WearWeapon(avatarId uint32, weaponId uint64) {
|
||||
avatar := p.AvatarMap[avatarId]
|
||||
weapon := p.WeaponMap[weaponId]
|
||||
avatar.EquipWeapon = weapon
|
||||
weapon.AvatarId = avatarId
|
||||
avatar.EquipGuidList[weapon.Guid] = weapon.Guid
|
||||
}
|
||||
|
||||
func (p *Player) TakeOffWeapon(avatarId uint32, weaponId uint64) {
|
||||
avatar := p.AvatarMap[avatarId]
|
||||
weapon := p.WeaponMap[weaponId]
|
||||
avatar.EquipWeapon = nil
|
||||
weapon.AvatarId = 0
|
||||
delete(avatar.EquipGuidList, weapon.Guid)
|
||||
}
|
||||
16
gs/model/chat.go
Normal file
16
gs/model/chat.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package model
|
||||
|
||||
const (
|
||||
ChatMsgTypeText = iota
|
||||
ChatMsgTypeIcon
|
||||
)
|
||||
|
||||
type ChatMsg struct {
|
||||
Time uint32 `bson:"time"`
|
||||
ToUid uint32 `bson:"toUid"`
|
||||
Uid uint32 `bson:"uid"`
|
||||
IsRead bool `bson:"isRead"`
|
||||
MsgType uint8 `bson:"msgType"`
|
||||
Text string `bson:"text"`
|
||||
Icon uint32 `bson:"icon"`
|
||||
}
|
||||
51
gs/model/drop.go
Normal file
51
gs/model/drop.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package model
|
||||
|
||||
type GachaPoolInfo struct {
|
||||
GachaType uint32 `bson:"gachaType"` // 卡池类型
|
||||
OrangeTimes uint32 `bson:"orangeTimes"` // 5星保底计数
|
||||
PurpleTimes uint32 `bson:"purpleTimes"` // 4星保底计数
|
||||
MustGetUpOrange bool `bson:"mustGetUpOrange"` // 是否5星大保底
|
||||
MustGetUpPurple bool `bson:"mustGetUpPurple"` // 是否4星大保底
|
||||
}
|
||||
|
||||
type DropInfo struct {
|
||||
GachaPoolInfo map[uint32]*GachaPoolInfo `bson:"gachaPoolInfo"`
|
||||
}
|
||||
|
||||
func NewDropInfo() (r *DropInfo) {
|
||||
r = new(DropInfo)
|
||||
r.GachaPoolInfo = make(map[uint32]*GachaPoolInfo)
|
||||
r.GachaPoolInfo[300] = &GachaPoolInfo{
|
||||
// 温迪
|
||||
GachaType: 300,
|
||||
OrangeTimes: 0,
|
||||
PurpleTimes: 0,
|
||||
MustGetUpOrange: false,
|
||||
MustGetUpPurple: false,
|
||||
}
|
||||
r.GachaPoolInfo[400] = &GachaPoolInfo{
|
||||
// 可莉
|
||||
GachaType: 400,
|
||||
OrangeTimes: 0,
|
||||
PurpleTimes: 0,
|
||||
MustGetUpOrange: false,
|
||||
MustGetUpPurple: false,
|
||||
}
|
||||
r.GachaPoolInfo[431] = &GachaPoolInfo{
|
||||
// 阿莫斯之弓&天空之傲
|
||||
GachaType: 431,
|
||||
OrangeTimes: 0,
|
||||
PurpleTimes: 0,
|
||||
MustGetUpOrange: false,
|
||||
MustGetUpPurple: false,
|
||||
}
|
||||
r.GachaPoolInfo[201] = &GachaPoolInfo{
|
||||
// 常驻
|
||||
GachaType: 201,
|
||||
OrangeTimes: 0,
|
||||
PurpleTimes: 0,
|
||||
MustGetUpOrange: false,
|
||||
MustGetUpPurple: false,
|
||||
}
|
||||
return r
|
||||
}
|
||||
93
gs/model/player.go
Normal file
93
gs/model/player.go
Normal file
@@ -0,0 +1,93 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
const (
|
||||
DbInsert = iota
|
||||
DbDelete
|
||||
DbUpdate
|
||||
DbNormal
|
||||
DbOffline
|
||||
)
|
||||
|
||||
const (
|
||||
SceneNone = iota
|
||||
SceneInitFinish
|
||||
SceneEnterDone
|
||||
)
|
||||
|
||||
type GameObject interface {
|
||||
}
|
||||
|
||||
type Player struct {
|
||||
// 离线数据
|
||||
ID primitive.ObjectID `bson:"_id,omitempty"`
|
||||
PlayerID uint32 `bson:"playerID"` // 玩家uid
|
||||
NickName string `bson:"nickname"` // 玩家昵称
|
||||
Signature string `bson:"signature"` // 玩家签名
|
||||
HeadImage uint32 `bson:"headImage"` // 玩家头像
|
||||
NameCard uint32 `bson:"nameCard"` // 当前名片
|
||||
NameCardList []uint32 `bson:"nameCardList"` // 已解锁名片列表
|
||||
FriendList map[uint32]bool `bson:"friendList"` // 好友uid列表
|
||||
FriendApplyList map[uint32]bool `bson:"friendApplyList"` // 好友申请uid列表
|
||||
OfflineTime uint32 `bson:"offlineTime"` // 离线时间点
|
||||
OnlineTime uint32 `bson:"onlineTime"` // 上线时间点
|
||||
TotalOnlineTime uint32 `bson:"totalOnlineTime"` // 玩家累计在线时长
|
||||
PropertiesMap map[uint16]uint32 `bson:"propertiesMap"` // 玩家自身相关的一些属性
|
||||
RegionId uint32 `bson:"regionId"` // regionId
|
||||
FlyCloakList []uint32 `bson:"flyCloakList"` // 风之翼列表
|
||||
CostumeList []uint32 `bson:"costumeList"` // 角色衣装列表
|
||||
SceneId uint32 `bson:"sceneId"` // 场景
|
||||
Pos *Vector `bson:"pos"` // 玩家坐标
|
||||
Rot *Vector `bson:"rot"` // 玩家朝向
|
||||
ItemMap map[uint32]*Item `bson:"itemMap"` // 玩家统一大背包仓库
|
||||
WeaponMap map[uint64]*Weapon `bson:"weaponMap"` // 玩家武器背包
|
||||
ReliquaryMap map[uint64]*Reliquary `bson:"reliquaryMap"` // 玩家圣遗物背包
|
||||
TeamConfig *TeamInfo `bson:"teamConfig"` // 队伍配置
|
||||
AvatarMap map[uint32]*Avatar `bson:"avatarMap"` // 角色信息
|
||||
DropInfo *DropInfo `bson:"dropInfo"` // 掉落信息
|
||||
MainCharAvatarId uint32 `bson:"mainCharAvatarId"` // 主角id
|
||||
ChatMsgMap map[uint32][]*ChatMsg `bson:"chatMsgMap"` // 聊天信息
|
||||
// 在线数据
|
||||
EnterSceneToken uint32 `bson:"-"` // 玩家的世界进入令牌
|
||||
DbState int `bson:"-"` // 数据库存档状态
|
||||
WorldId uint32 `bson:"-"` // 所在的世界id
|
||||
PeerId uint32 `bson:"-"` // 多人世界的玩家编号
|
||||
GameObjectGuidCounter uint64 `bson:"-"` // 游戏对象guid计数器
|
||||
ClientTime uint32 `bson:"-"` // 玩家客户端的本地时钟
|
||||
ClientRTT uint32 `bson:"-"` // 玩家客户端往返时延
|
||||
GameObjectGuidMap map[uint64]GameObject `bson:"-"` // 游戏对象guid映射表
|
||||
Online bool `bson:"-"` // 在线状态
|
||||
Pause bool `bson:"-"` // 暂停状态
|
||||
SceneLoadState int `bson:"-"` // 场景加载状态
|
||||
CoopApplyMap map[uint32]int64 `bson:"-"` // 敲门申请的玩家uid及时间
|
||||
ClientSeq uint32 `bson:"-"`
|
||||
}
|
||||
|
||||
func (p *Player) GetNextGameObjectGuid() uint64 {
|
||||
p.GameObjectGuidCounter++
|
||||
return uint64(p.PlayerID)<<32 + p.GameObjectGuidCounter
|
||||
}
|
||||
|
||||
func (p *Player) InitAll() {
|
||||
p.GameObjectGuidMap = make(map[uint64]GameObject)
|
||||
p.CoopApplyMap = make(map[uint32]int64)
|
||||
p.InitAllAvatar()
|
||||
p.InitAllWeapon()
|
||||
p.InitAllItem()
|
||||
p.InitAllReliquary()
|
||||
}
|
||||
|
||||
func (p *Player) InitAllReliquary() {
|
||||
for reliquaryId, reliquary := range p.ReliquaryMap {
|
||||
reliquary.Guid = p.GetNextGameObjectGuid()
|
||||
p.ReliquaryMap[reliquaryId] = reliquary
|
||||
if reliquary.AvatarId != 0 {
|
||||
avatar := p.AvatarMap[reliquary.AvatarId]
|
||||
avatar.EquipGuidList[reliquary.Guid] = reliquary.Guid
|
||||
avatar.EquipReliquaryList = append(avatar.EquipReliquaryList, reliquary)
|
||||
}
|
||||
}
|
||||
}
|
||||
16
gs/model/reliquary.go
Normal file
16
gs/model/reliquary.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package model
|
||||
|
||||
type Reliquary struct {
|
||||
ReliquaryId uint64 `bson:"reliquaryId"` // 圣遗物的唯一id
|
||||
ItemId uint32 `bson:"itemId"` // 圣遗物的道具id
|
||||
Level uint8 `bson:"level"` // 等级
|
||||
Exp uint32 `bson:"exp"` // 当前经验值
|
||||
TotalExp uint32 `bson:"totalExp"` // 升级所需总经验值
|
||||
Promote uint8 `bson:"promote"` // 突破等阶
|
||||
Lock bool `bson:"lock"` // 锁定状态
|
||||
AffixIdList []uint32 `bson:"affixIdList"` // 词缀
|
||||
Refinement uint8 `bson:"refinement"` // 精炼等阶
|
||||
MainPropId uint32 `bson:"mainPropId"` // 主词条id
|
||||
AvatarId uint32 `bson:"avatarId"` // 装备角色id
|
||||
Guid uint64 `bson:"-"`
|
||||
}
|
||||
115
gs/model/team.go
Normal file
115
gs/model/team.go
Normal file
@@ -0,0 +1,115 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
gdc "hk4e/gs/config"
|
||||
"hk4e/gs/constant"
|
||||
)
|
||||
|
||||
type Team struct {
|
||||
Name string `bson:"name"`
|
||||
AvatarIdList []uint32 `bson:"avatarIdList"`
|
||||
}
|
||||
|
||||
type TeamInfo struct {
|
||||
TeamList []*Team `bson:"teamList"`
|
||||
CurrTeamIndex uint8 `bson:"currTeamIndex"`
|
||||
CurrAvatarIndex uint8 `bson:"currAvatarIndex"`
|
||||
TeamResonances map[uint16]bool `bson:"-"`
|
||||
TeamResonancesConfig map[int32]bool `bson:"-"`
|
||||
}
|
||||
|
||||
func NewTeamInfo() (r *TeamInfo) {
|
||||
r = &TeamInfo{
|
||||
TeamList: []*Team{
|
||||
{Name: "冒险", AvatarIdList: make([]uint32, 4)},
|
||||
{Name: "委托", AvatarIdList: make([]uint32, 4)},
|
||||
{Name: "秘境", AvatarIdList: make([]uint32, 4)},
|
||||
{Name: "联机", AvatarIdList: make([]uint32, 4)},
|
||||
},
|
||||
CurrTeamIndex: 0,
|
||||
CurrAvatarIndex: 0,
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
func (t *TeamInfo) UpdateTeam() {
|
||||
activeTeam := t.GetActiveTeam()
|
||||
// 队伍元素共鸣
|
||||
t.TeamResonances = make(map[uint16]bool)
|
||||
t.TeamResonancesConfig = make(map[int32]bool)
|
||||
teamElementTypeCountMap := make(map[uint16]uint8)
|
||||
avatarSkillDepotDataMapConfig := gdc.CONF.AvatarSkillDepotDataMap
|
||||
for _, avatarId := range activeTeam.AvatarIdList {
|
||||
if avatarId == 0 {
|
||||
break
|
||||
}
|
||||
skillData := avatarSkillDepotDataMapConfig[int32(avatarId)]
|
||||
if skillData != nil {
|
||||
teamElementTypeCountMap[skillData.ElementType.Value] += 1
|
||||
}
|
||||
}
|
||||
for k, v := range teamElementTypeCountMap {
|
||||
if v >= 2 {
|
||||
element := constant.ElementTypeConst.VALUE_MAP[k]
|
||||
if element.TeamResonanceId != 0 {
|
||||
t.TeamResonances[element.TeamResonanceId] = true
|
||||
t.TeamResonancesConfig[element.ConfigHash] = true
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(t.TeamResonances) == 0 {
|
||||
t.TeamResonances[constant.ElementTypeConst.Default.TeamResonanceId] = true
|
||||
t.TeamResonancesConfig[int32(constant.ElementTypeConst.Default.TeamResonanceId)] = true
|
||||
}
|
||||
}
|
||||
|
||||
func (t *TeamInfo) GetActiveTeamId() uint8 {
|
||||
return t.CurrTeamIndex + 1
|
||||
}
|
||||
|
||||
func (t *TeamInfo) GetTeamByIndex(teamIndex uint8) *Team {
|
||||
if t.TeamList == nil {
|
||||
return nil
|
||||
}
|
||||
if teamIndex >= uint8(len(t.TeamList)) {
|
||||
return nil
|
||||
}
|
||||
activeTeam := t.TeamList[teamIndex]
|
||||
return activeTeam
|
||||
}
|
||||
|
||||
func (t *TeamInfo) GetActiveTeam() *Team {
|
||||
return t.GetTeamByIndex(t.CurrTeamIndex)
|
||||
}
|
||||
|
||||
func (t *TeamInfo) ClearTeamAvatar(teamIndex uint8) {
|
||||
team := t.GetTeamByIndex(teamIndex)
|
||||
if team == nil {
|
||||
return
|
||||
}
|
||||
team.AvatarIdList = make([]uint32, 4)
|
||||
}
|
||||
|
||||
func (t *TeamInfo) AddAvatarToTeam(avatarId uint32, teamIndex uint8) {
|
||||
team := t.GetTeamByIndex(teamIndex)
|
||||
if team == nil {
|
||||
return
|
||||
}
|
||||
for i, v := range team.AvatarIdList {
|
||||
if v == 0 {
|
||||
team.AvatarIdList[i] = avatarId
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (t *TeamInfo) GetActiveAvatarId() uint32 {
|
||||
activeTeam := t.GetActiveTeam()
|
||||
if activeTeam == nil {
|
||||
return 0
|
||||
}
|
||||
if t.CurrAvatarIndex >= uint8(len(activeTeam.AvatarIdList)) {
|
||||
return 0
|
||||
}
|
||||
return activeTeam.AvatarIdList[t.CurrAvatarIndex]
|
||||
}
|
||||
7
gs/model/vector.go
Normal file
7
gs/model/vector.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package model
|
||||
|
||||
type Vector struct {
|
||||
X float64 `bson:"x"`
|
||||
Y float64 `bson:"y"`
|
||||
Z float64 `bson:"z"`
|
||||
}
|
||||
76
gs/model/weapon.go
Normal file
76
gs/model/weapon.go
Normal file
@@ -0,0 +1,76 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
gdc "hk4e/gs/config"
|
||||
)
|
||||
|
||||
type Weapon struct {
|
||||
WeaponId uint64 `bson:"weaponId"` // 武器的唯一id
|
||||
ItemId uint32 `bson:"itemId"` // 武器的道具id
|
||||
Level uint8 `bson:"level"` // 等级
|
||||
Exp uint32 `bson:"exp"` // 当前经验值
|
||||
TotalExp uint32 `bson:"totalExp"` // 升级所需总经验值
|
||||
Promote uint8 `bson:"promote"` // 突破等阶
|
||||
Lock bool `bson:"lock"` // 锁定状态
|
||||
AffixIdList []uint32 `bson:"affixIdList"` // 词缀
|
||||
Refinement uint8 `bson:"refinement"` // 精炼等阶
|
||||
MainPropId uint32 `bson:"mainPropId"` // 主词条id
|
||||
AvatarId uint32 `bson:"avatarId"` // 装备角色id
|
||||
Guid uint64 `bson:"-"`
|
||||
}
|
||||
|
||||
func (p *Player) InitWeapon(weapon *Weapon) {
|
||||
weapon.Guid = p.GetNextGameObjectGuid()
|
||||
p.GameObjectGuidMap[weapon.Guid] = GameObject(weapon)
|
||||
p.WeaponMap[weapon.WeaponId] = weapon
|
||||
if weapon.AvatarId != 0 {
|
||||
avatar := p.AvatarMap[weapon.AvatarId]
|
||||
avatar.EquipGuidList[weapon.Guid] = weapon.Guid
|
||||
avatar.EquipWeapon = weapon
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (p *Player) InitAllWeapon() {
|
||||
for _, weapon := range p.WeaponMap {
|
||||
p.InitWeapon(weapon)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Player) GetWeaponGuid(weaponId uint64) uint64 {
|
||||
weaponInfo := p.WeaponMap[weaponId]
|
||||
if weaponInfo == nil {
|
||||
return 0
|
||||
}
|
||||
return weaponInfo.Guid
|
||||
}
|
||||
|
||||
func (p *Player) GetWeapon(weaponId uint64) *Weapon {
|
||||
return p.WeaponMap[weaponId]
|
||||
}
|
||||
|
||||
func (p *Player) AddWeapon(itemId uint32, weaponId uint64) {
|
||||
weapon := &Weapon{
|
||||
WeaponId: weaponId,
|
||||
ItemId: itemId,
|
||||
Level: 1,
|
||||
Exp: 0,
|
||||
TotalExp: 0,
|
||||
Promote: 0,
|
||||
Lock: false,
|
||||
AffixIdList: make([]uint32, 0),
|
||||
Refinement: 0,
|
||||
MainPropId: 0,
|
||||
Guid: 0,
|
||||
}
|
||||
itemDataConfig := gdc.CONF.ItemDataMap[int32(itemId)]
|
||||
if itemDataConfig.SkillAffix != nil {
|
||||
for _, skillAffix := range itemDataConfig.SkillAffix {
|
||||
if skillAffix > 0 {
|
||||
weapon.AffixIdList = append(weapon.AffixIdList, uint32(skillAffix))
|
||||
}
|
||||
}
|
||||
}
|
||||
p.InitWeapon(weapon)
|
||||
p.WeaponMap[weaponId] = weapon
|
||||
}
|
||||
Reference in New Issue
Block a user