mirror of
https://github.com/FlourishingWorld/hk4e.git
synced 2026-03-01 00:35:36 +08:00
1.MongoDB、Redis兼容集群模式
2.离线数据接口化访问
This commit is contained in:
@@ -13,8 +13,8 @@ type ChatMsg struct {
|
||||
ID primitive.ObjectID `bson:"_id,omitempty"`
|
||||
Sequence uint32 `bson:"-"`
|
||||
Time uint32 `bson:"Time"`
|
||||
ToUid uint32 `bson:"ToUid"`
|
||||
Uid uint32 `bson:"Uid"`
|
||||
ToUid uint32 `bson:"ToUid"`
|
||||
IsRead bool `bson:"IsRead"`
|
||||
MsgType uint8 `bson:"MsgType"`
|
||||
Text string `bson:"Text"`
|
||||
@@ -8,6 +8,20 @@ import (
|
||||
"hk4e/pkg/logger"
|
||||
)
|
||||
|
||||
type DbAvatar struct {
|
||||
AvatarMap map[uint32]*Avatar // 角色列表
|
||||
MainCharAvatarId uint32 // 主角id
|
||||
}
|
||||
|
||||
func (p *Player) GetDbAvatar() *DbAvatar {
|
||||
if p.DbAvatar == nil {
|
||||
p.DbAvatar = &DbAvatar{
|
||||
AvatarMap: make(map[uint32]*Avatar),
|
||||
}
|
||||
}
|
||||
return p.DbAvatar
|
||||
}
|
||||
|
||||
type Avatar struct {
|
||||
AvatarId uint32 // 角色id
|
||||
LifeState uint16 // 存活状态
|
||||
@@ -35,26 +49,26 @@ type Avatar struct {
|
||||
ExtraAbilityEmbryos map[string]bool `bson:"-" msgpack:"-"`
|
||||
}
|
||||
|
||||
func (p *Player) InitAllAvatar() {
|
||||
for _, avatar := range p.AvatarMap {
|
||||
p.InitAvatar(avatar)
|
||||
func (a *DbAvatar) InitAllAvatar(player *Player) {
|
||||
for _, avatar := range a.AvatarMap {
|
||||
a.InitAvatar(player, avatar)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Player) InitAvatar(avatar *Avatar) {
|
||||
func (a *DbAvatar) InitAvatar(player *Player, avatar *Avatar) {
|
||||
// 角色战斗属性
|
||||
p.InitAvatarFightProp(avatar)
|
||||
a.InitAvatarFightProp(avatar)
|
||||
// guid
|
||||
avatar.Guid = p.GetNextGameObjectGuid()
|
||||
p.GameObjectGuidMap[avatar.Guid] = GameObject(avatar)
|
||||
avatar.Guid = player.GetNextGameObjectGuid()
|
||||
player.GameObjectGuidMap[avatar.Guid] = GameObject(avatar)
|
||||
avatar.EquipGuidMap = make(map[uint64]uint64)
|
||||
avatar.EquipReliquaryMap = make(map[uint8]*Reliquary)
|
||||
p.AvatarMap[avatar.AvatarId] = avatar
|
||||
a.AvatarMap[avatar.AvatarId] = avatar
|
||||
return
|
||||
}
|
||||
|
||||
// InitAvatarFightProp 初始化角色面板
|
||||
func (p *Player) InitAvatarFightProp(avatar *Avatar) {
|
||||
func (a *DbAvatar) InitAvatarFightProp(avatar *Avatar) {
|
||||
avatarDataConfig := gdconf.GetAvatarDataById(int32(avatar.AvatarId))
|
||||
if avatarDataConfig == nil {
|
||||
logger.Error("avatarDataConfig error, avatarId: %v", avatar.AvatarId)
|
||||
@@ -77,10 +91,10 @@ func (p *Player) InitAvatarFightProp(avatar *Avatar) {
|
||||
avatar.FightPropMap[uint32(constant.FIGHT_PROP_CRITICAL_HURT)] = float32(avatarDataConfig.CriticalHurt)
|
||||
// 元素充能
|
||||
avatar.FightPropMap[uint32(constant.FIGHT_PROP_CHARGE_EFFICIENCY)] = 1.0
|
||||
p.SetCurrEnergy(avatar, avatar.CurrEnergy, true)
|
||||
a.SetCurrEnergy(avatar, avatar.CurrEnergy, true)
|
||||
}
|
||||
|
||||
func (p *Player) AddAvatar(avatarId uint32) {
|
||||
func (a *DbAvatar) AddAvatar(player *Player, avatarId uint32) {
|
||||
avatarDataConfig := gdconf.GetAvatarDataById(int32(avatarId))
|
||||
if avatarDataConfig == nil {
|
||||
logger.Error("avatar data config is nil, avatarId: %v", avatarId)
|
||||
@@ -140,11 +154,11 @@ func (p *Player) AddAvatar(avatarId uint32) {
|
||||
avatar.PromoteRewardMap[promoteLevel] = false
|
||||
}
|
||||
|
||||
p.InitAvatar(avatar)
|
||||
p.AvatarMap[avatarId] = avatar
|
||||
a.InitAvatar(player, avatar)
|
||||
a.AvatarMap[avatarId] = avatar
|
||||
}
|
||||
|
||||
func (p *Player) SetCurrEnergy(avatar *Avatar, value float64, max bool) {
|
||||
func (a *DbAvatar) SetCurrEnergy(avatar *Avatar, value float64, max bool) {
|
||||
var avatarSkillDataConfig *gdconf.AvatarSkillData = nil
|
||||
if avatar.AvatarId == 10000005 || avatar.AvatarId == 10000007 {
|
||||
avatarSkillDepotDataConfig := gdconf.GetAvatarSkillDepotDataById(int32(avatar.SkillDepotId))
|
||||
@@ -175,9 +189,8 @@ func (p *Player) SetCurrEnergy(avatar *Avatar, value float64, max bool) {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Player) WearReliquary(avatarId uint32, reliquaryId uint64) {
|
||||
avatar := p.AvatarMap[avatarId]
|
||||
reliquary := p.ReliquaryMap[reliquaryId]
|
||||
func (a *DbAvatar) WearReliquary(avatarId uint32, reliquary *Reliquary) {
|
||||
avatar := a.AvatarMap[avatarId]
|
||||
reliquaryConfig := gdconf.GetItemDataById(int32(reliquary.ItemId))
|
||||
if reliquaryConfig == nil {
|
||||
logger.Error("reliquary config error, itemId: %v", reliquary.ItemId)
|
||||
@@ -188,9 +201,8 @@ func (p *Player) WearReliquary(avatarId uint32, reliquaryId uint64) {
|
||||
avatar.EquipGuidMap[reliquary.Guid] = reliquary.Guid
|
||||
}
|
||||
|
||||
func (p *Player) TakeOffReliquary(avatarId uint32, reliquaryId uint64) {
|
||||
avatar := p.AvatarMap[avatarId]
|
||||
reliquary := p.ReliquaryMap[reliquaryId]
|
||||
func (a *DbAvatar) TakeOffReliquary(avatarId uint32, reliquary *Reliquary) {
|
||||
avatar := a.AvatarMap[avatarId]
|
||||
reliquaryConfig := gdconf.GetItemDataById(int32(reliquary.ItemId))
|
||||
if reliquaryConfig == nil {
|
||||
logger.Error("reliquary config error, itemId: %v", reliquary.ItemId)
|
||||
@@ -201,17 +213,15 @@ func (p *Player) TakeOffReliquary(avatarId uint32, reliquaryId uint64) {
|
||||
delete(avatar.EquipGuidMap, reliquary.Guid)
|
||||
}
|
||||
|
||||
func (p *Player) WearWeapon(avatarId uint32, weaponId uint64) {
|
||||
avatar := p.AvatarMap[avatarId]
|
||||
weapon := p.WeaponMap[weaponId]
|
||||
func (a *DbAvatar) WearWeapon(avatarId uint32, weapon *Weapon) {
|
||||
avatar := a.AvatarMap[avatarId]
|
||||
avatar.EquipWeapon = weapon
|
||||
weapon.AvatarId = avatarId
|
||||
avatar.EquipGuidMap[weapon.Guid] = weapon.Guid
|
||||
}
|
||||
|
||||
func (p *Player) TakeOffWeapon(avatarId uint32, weaponId uint64) {
|
||||
avatar := p.AvatarMap[avatarId]
|
||||
weapon := p.WeaponMap[weaponId]
|
||||
func (a *DbAvatar) TakeOffWeapon(avatarId uint32, weapon *Weapon) {
|
||||
avatar := a.AvatarMap[avatarId]
|
||||
avatar.EquipWeapon = nil
|
||||
weapon.AvatarId = 0
|
||||
delete(avatar.EquipGuidMap, weapon.Guid)
|
||||
@@ -8,12 +8,19 @@ type GachaPoolInfo struct {
|
||||
MustGetUpPurple bool // 是否4星大保底
|
||||
}
|
||||
|
||||
type DropInfo struct {
|
||||
type DbGacha struct {
|
||||
GachaPoolInfo map[uint32]*GachaPoolInfo
|
||||
}
|
||||
|
||||
func NewDropInfo() (r *DropInfo) {
|
||||
r = new(DropInfo)
|
||||
func (p *Player) GetDbGacha() *DbGacha {
|
||||
if p.DbGacha == nil {
|
||||
p.DbGacha = NewDbGacha()
|
||||
}
|
||||
return p.DbGacha
|
||||
}
|
||||
|
||||
func NewDbGacha() (r *DbGacha) {
|
||||
r = new(DbGacha)
|
||||
r.GachaPoolInfo = make(map[uint32]*GachaPoolInfo)
|
||||
r.GachaPoolInfo[300] = &GachaPoolInfo{
|
||||
// 温迪
|
||||
@@ -0,0 +1,89 @@
|
||||
package model
|
||||
|
||||
import "hk4e/common/constant"
|
||||
|
||||
type DbItem struct {
|
||||
ItemMap map[uint32]*Item // 道具仓库
|
||||
}
|
||||
|
||||
func (p *Player) GetDbItem() *DbItem {
|
||||
if p.DbItem == nil {
|
||||
p.DbItem = &DbItem{
|
||||
ItemMap: make(map[uint32]*Item),
|
||||
}
|
||||
}
|
||||
return p.DbItem
|
||||
}
|
||||
|
||||
type Item struct {
|
||||
ItemId uint32 // 道具id
|
||||
Count uint32 // 道具数量
|
||||
Guid uint64 `bson:"-" msgpack:"-"`
|
||||
}
|
||||
|
||||
func (i *DbItem) InitAllItem(player *Player) {
|
||||
for itemId, item := range i.ItemMap {
|
||||
item.Guid = player.GetNextGameObjectGuid()
|
||||
player.GameObjectGuidMap[item.Guid] = GameObject(item)
|
||||
i.ItemMap[itemId] = item
|
||||
}
|
||||
}
|
||||
|
||||
func (i *DbItem) GetItemGuid(itemId uint32) uint64 {
|
||||
itemInfo := i.ItemMap[itemId]
|
||||
if itemInfo == nil {
|
||||
return 0
|
||||
}
|
||||
return itemInfo.Guid
|
||||
}
|
||||
|
||||
func (i *DbItem) GetItemCount(player *Player, itemId uint32) uint32 {
|
||||
prop, ok := constant.VIRTUAL_ITEM_PROP[itemId]
|
||||
if ok {
|
||||
value := player.PropertiesMap[prop]
|
||||
return value
|
||||
} else {
|
||||
itemInfo := i.ItemMap[itemId]
|
||||
if itemInfo == nil {
|
||||
return 0
|
||||
}
|
||||
return itemInfo.Count
|
||||
}
|
||||
}
|
||||
|
||||
func (i *DbItem) AddItem(player *Player, itemId uint32, count uint32) {
|
||||
itemInfo := i.ItemMap[itemId]
|
||||
if itemInfo == nil {
|
||||
// 该物品为新物品时校验背包物品容量
|
||||
// 目前物品包括材料和家具
|
||||
if len(i.ItemMap) > constant.STORE_PACK_LIMIT_MATERIAL+constant.STORE_PACK_LIMIT_FURNITURE {
|
||||
return
|
||||
}
|
||||
itemInfo = &Item{
|
||||
ItemId: itemId,
|
||||
Count: 0,
|
||||
Guid: player.GetNextGameObjectGuid(),
|
||||
}
|
||||
player.GameObjectGuidMap[itemInfo.Guid] = GameObject(itemInfo)
|
||||
}
|
||||
itemInfo.Count += count
|
||||
i.ItemMap[itemId] = itemInfo
|
||||
}
|
||||
|
||||
func (i *DbItem) CostItem(player *Player, itemId uint32, count uint32) {
|
||||
itemInfo := i.ItemMap[itemId]
|
||||
if itemInfo == nil {
|
||||
return
|
||||
}
|
||||
if itemInfo.Count < count {
|
||||
itemInfo.Count = 0
|
||||
} else {
|
||||
itemInfo.Count -= count
|
||||
}
|
||||
if itemInfo.Count == 0 {
|
||||
delete(i.ItemMap, itemId)
|
||||
delete(player.GameObjectGuidMap, itemInfo.Guid)
|
||||
} else {
|
||||
i.ItemMap[itemId] = itemInfo
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,19 @@ import (
|
||||
"hk4e/pkg/logger"
|
||||
)
|
||||
|
||||
type DbReliquary struct {
|
||||
ReliquaryMap map[uint64]*Reliquary // 圣遗物背包
|
||||
}
|
||||
|
||||
func (p *Player) GetDbReliquary() *DbReliquary {
|
||||
if p.DbReliquary == nil {
|
||||
p.DbReliquary = &DbReliquary{
|
||||
ReliquaryMap: make(map[uint64]*Reliquary),
|
||||
}
|
||||
}
|
||||
return p.DbReliquary
|
||||
}
|
||||
|
||||
type Reliquary struct {
|
||||
ReliquaryId uint64 // 圣遗物的唯一id
|
||||
ItemId uint32 // 圣遗物的道具id
|
||||
@@ -19,44 +32,45 @@ type Reliquary struct {
|
||||
Guid uint64 `bson:"-" msgpack:"-"`
|
||||
}
|
||||
|
||||
func (p *Player) InitReliquary(reliquary *Reliquary) {
|
||||
func (r *DbReliquary) InitAllReliquary(player *Player) {
|
||||
for _, reliquary := range r.ReliquaryMap {
|
||||
r.InitReliquary(player, reliquary)
|
||||
}
|
||||
}
|
||||
|
||||
func (r *DbReliquary) InitReliquary(player *Player, reliquary *Reliquary) {
|
||||
// 获取圣遗物配置表
|
||||
reliquaryConfig := gdconf.GetItemDataById(int32(reliquary.ItemId))
|
||||
if reliquaryConfig == nil {
|
||||
logger.Error("reliquary config error, itemId: %v", reliquary.ItemId)
|
||||
return
|
||||
}
|
||||
reliquary.Guid = p.GetNextGameObjectGuid()
|
||||
p.GameObjectGuidMap[reliquary.Guid] = GameObject(reliquary)
|
||||
p.ReliquaryMap[reliquary.ReliquaryId] = reliquary
|
||||
reliquary.Guid = player.GetNextGameObjectGuid()
|
||||
player.GameObjectGuidMap[reliquary.Guid] = GameObject(reliquary)
|
||||
r.ReliquaryMap[reliquary.ReliquaryId] = reliquary
|
||||
if reliquary.AvatarId != 0 {
|
||||
avatar := p.AvatarMap[reliquary.AvatarId]
|
||||
dbAvatar := player.GetDbAvatar()
|
||||
avatar := dbAvatar.AvatarMap[reliquary.AvatarId]
|
||||
avatar.EquipGuidMap[reliquary.Guid] = reliquary.Guid
|
||||
avatar.EquipReliquaryMap[uint8(reliquaryConfig.ReliquaryType)] = reliquary
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Player) InitAllReliquary() {
|
||||
for _, reliquary := range p.ReliquaryMap {
|
||||
p.InitReliquary(reliquary)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Player) GetReliquaryGuid(reliquaryId uint64) uint64 {
|
||||
reliquaryInfo := p.ReliquaryMap[reliquaryId]
|
||||
func (r *DbReliquary) GetReliquaryGuid(reliquaryId uint64) uint64 {
|
||||
reliquaryInfo := r.ReliquaryMap[reliquaryId]
|
||||
if reliquaryInfo == nil {
|
||||
return 0
|
||||
}
|
||||
return reliquaryInfo.Guid
|
||||
}
|
||||
|
||||
func (p *Player) GetReliquary(reliquaryId uint64) *Reliquary {
|
||||
return p.ReliquaryMap[reliquaryId]
|
||||
func (r *DbReliquary) GetReliquary(reliquaryId uint64) *Reliquary {
|
||||
return r.ReliquaryMap[reliquaryId]
|
||||
}
|
||||
|
||||
func (p *Player) AddReliquary(itemId uint32, reliquaryId uint64, mainPropId uint32) {
|
||||
func (r *DbReliquary) AddReliquary(player *Player, itemId uint32, reliquaryId uint64, mainPropId uint32) {
|
||||
// 校验背包圣遗物容量
|
||||
if len(p.ReliquaryMap) > constant.STORE_PACK_LIMIT_RELIQUARY {
|
||||
if len(r.ReliquaryMap) > constant.STORE_PACK_LIMIT_RELIQUARY {
|
||||
return
|
||||
}
|
||||
itemDataConfig := gdconf.GetItemDataById(int32(itemId))
|
||||
@@ -76,16 +90,16 @@ func (p *Player) AddReliquary(itemId uint32, reliquaryId uint64, mainPropId uint
|
||||
AvatarId: 0,
|
||||
Guid: 0,
|
||||
}
|
||||
p.InitReliquary(reliquary)
|
||||
p.ReliquaryMap[reliquaryId] = reliquary
|
||||
r.InitReliquary(player, reliquary)
|
||||
r.ReliquaryMap[reliquaryId] = reliquary
|
||||
}
|
||||
|
||||
func (p *Player) CostReliquary(reliquaryId uint64) uint64 {
|
||||
reliquary := p.ReliquaryMap[reliquaryId]
|
||||
func (r *DbReliquary) CostReliquary(player *Player, reliquaryId uint64) uint64 {
|
||||
reliquary := r.ReliquaryMap[reliquaryId]
|
||||
if reliquary == nil {
|
||||
return 0
|
||||
}
|
||||
delete(p.ReliquaryMap, reliquaryId)
|
||||
delete(p.GameObjectGuidMap, reliquary.Guid)
|
||||
delete(r.ReliquaryMap, reliquaryId)
|
||||
delete(player.GameObjectGuidMap, reliquary.Guid)
|
||||
return reliquary.Guid
|
||||
}
|
||||
@@ -32,7 +32,7 @@ func (t *Team) SetAvatarIdList(avatarIdList []uint32) {
|
||||
}
|
||||
}
|
||||
|
||||
type TeamInfo struct {
|
||||
type DbTeam struct {
|
||||
TeamList []*Team
|
||||
CurrTeamIndex uint8
|
||||
CurrAvatarIndex uint8
|
||||
@@ -40,8 +40,15 @@ type TeamInfo struct {
|
||||
TeamResonancesConfig map[int32]bool `bson:"-" msgpack:"-"`
|
||||
}
|
||||
|
||||
func NewTeamInfo() (r *TeamInfo) {
|
||||
r = &TeamInfo{
|
||||
func (p *Player) GetDbTeam() *DbTeam {
|
||||
if p.DbTeam == nil {
|
||||
p.DbTeam = NewDbTeam()
|
||||
}
|
||||
return p.DbTeam
|
||||
}
|
||||
|
||||
func NewDbTeam() (r *DbTeam) {
|
||||
r = &DbTeam{
|
||||
TeamList: []*Team{
|
||||
{Name: "冒险", AvatarIdList: make([]uint32, 4)},
|
||||
{Name: "委托", AvatarIdList: make([]uint32, 4)},
|
||||
@@ -54,7 +61,7 @@ func NewTeamInfo() (r *TeamInfo) {
|
||||
return r
|
||||
}
|
||||
|
||||
func (t *TeamInfo) UpdateTeam() {
|
||||
func (t *DbTeam) UpdateTeam() {
|
||||
activeTeam := t.GetActiveTeam()
|
||||
// TODO 队伍元素共鸣
|
||||
t.TeamResonances = make(map[uint16]bool)
|
||||
@@ -88,11 +95,11 @@ func (t *TeamInfo) UpdateTeam() {
|
||||
}
|
||||
}
|
||||
|
||||
func (t *TeamInfo) GetActiveTeamId() uint8 {
|
||||
func (t *DbTeam) GetActiveTeamId() uint8 {
|
||||
return t.CurrTeamIndex + 1
|
||||
}
|
||||
|
||||
func (t *TeamInfo) GetTeamByIndex(teamIndex uint8) *Team {
|
||||
func (t *DbTeam) GetTeamByIndex(teamIndex uint8) *Team {
|
||||
if t.TeamList == nil {
|
||||
return nil
|
||||
}
|
||||
@@ -103,11 +110,11 @@ func (t *TeamInfo) GetTeamByIndex(teamIndex uint8) *Team {
|
||||
return activeTeam
|
||||
}
|
||||
|
||||
func (t *TeamInfo) GetActiveTeam() *Team {
|
||||
func (t *DbTeam) GetActiveTeam() *Team {
|
||||
return t.GetTeamByIndex(t.CurrTeamIndex)
|
||||
}
|
||||
|
||||
func (t *TeamInfo) GetActiveAvatarId() uint32 {
|
||||
func (t *DbTeam) GetActiveAvatarId() uint32 {
|
||||
team := t.GetActiveTeam()
|
||||
if team == nil {
|
||||
return 0
|
||||
@@ -6,6 +6,19 @@ import (
|
||||
"hk4e/pkg/logger"
|
||||
)
|
||||
|
||||
type DbWeapon struct {
|
||||
WeaponMap map[uint64]*Weapon // 武器背包
|
||||
}
|
||||
|
||||
func (p *Player) GetDbWeapon() *DbWeapon {
|
||||
if p.DbWeapon == nil {
|
||||
p.DbWeapon = &DbWeapon{
|
||||
WeaponMap: make(map[uint64]*Weapon),
|
||||
}
|
||||
}
|
||||
return p.DbWeapon
|
||||
}
|
||||
|
||||
type Weapon struct {
|
||||
WeaponId uint64 // 武器的唯一id
|
||||
ItemId uint32 // 武器的道具id
|
||||
@@ -19,38 +32,39 @@ type Weapon struct {
|
||||
Guid uint64 `bson:"-" msgpack:"-"`
|
||||
}
|
||||
|
||||
func (p *Player) InitWeapon(weapon *Weapon) {
|
||||
weapon.Guid = p.GetNextGameObjectGuid()
|
||||
p.GameObjectGuidMap[weapon.Guid] = GameObject(weapon)
|
||||
p.WeaponMap[weapon.WeaponId] = weapon
|
||||
func (w *DbWeapon) InitAllWeapon(player *Player) {
|
||||
for _, weapon := range w.WeaponMap {
|
||||
w.InitWeapon(player, weapon)
|
||||
}
|
||||
}
|
||||
|
||||
func (w *DbWeapon) InitWeapon(player *Player, weapon *Weapon) {
|
||||
weapon.Guid = player.GetNextGameObjectGuid()
|
||||
player.GameObjectGuidMap[weapon.Guid] = GameObject(weapon)
|
||||
w.WeaponMap[weapon.WeaponId] = weapon
|
||||
if weapon.AvatarId != 0 {
|
||||
avatar := p.AvatarMap[weapon.AvatarId]
|
||||
dbAvatar := player.GetDbAvatar()
|
||||
avatar := dbAvatar.AvatarMap[weapon.AvatarId]
|
||||
avatar.EquipGuidMap[weapon.Guid] = weapon.Guid
|
||||
avatar.EquipWeapon = weapon
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Player) InitAllWeapon() {
|
||||
for _, weapon := range p.WeaponMap {
|
||||
p.InitWeapon(weapon)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Player) GetWeaponGuid(weaponId uint64) uint64 {
|
||||
weaponInfo := p.WeaponMap[weaponId]
|
||||
func (w *DbWeapon) GetWeaponGuid(weaponId uint64) uint64 {
|
||||
weaponInfo := w.WeaponMap[weaponId]
|
||||
if weaponInfo == nil {
|
||||
return 0
|
||||
}
|
||||
return weaponInfo.Guid
|
||||
}
|
||||
|
||||
func (p *Player) GetWeapon(weaponId uint64) *Weapon {
|
||||
return p.WeaponMap[weaponId]
|
||||
func (w *DbWeapon) GetWeapon(weaponId uint64) *Weapon {
|
||||
return w.WeaponMap[weaponId]
|
||||
}
|
||||
|
||||
func (p *Player) AddWeapon(itemId uint32, weaponId uint64) {
|
||||
func (w *DbWeapon) AddWeapon(player *Player, itemId uint32, weaponId uint64) {
|
||||
// 校验背包武器容量
|
||||
if len(p.WeaponMap) > constant.STORE_PACK_LIMIT_WEAPON {
|
||||
if len(w.WeaponMap) > constant.STORE_PACK_LIMIT_WEAPON {
|
||||
return
|
||||
}
|
||||
itemDataConfig := gdconf.GetItemDataById(int32(itemId))
|
||||
@@ -72,16 +86,16 @@ func (p *Player) AddWeapon(itemId uint32, weaponId uint64) {
|
||||
for _, skillAffix := range itemDataConfig.SkillAffix {
|
||||
weapon.AffixIdList = append(weapon.AffixIdList, uint32(skillAffix))
|
||||
}
|
||||
p.InitWeapon(weapon)
|
||||
p.WeaponMap[weaponId] = weapon
|
||||
w.InitWeapon(player, weapon)
|
||||
w.WeaponMap[weaponId] = weapon
|
||||
}
|
||||
|
||||
func (p *Player) CostWeapon(weaponId uint64) uint64 {
|
||||
weapon := p.WeaponMap[weaponId]
|
||||
func (w *DbWeapon) CostWeapon(player *Player, weaponId uint64) uint64 {
|
||||
weapon := w.WeaponMap[weaponId]
|
||||
if weapon == nil {
|
||||
return 0
|
||||
}
|
||||
delete(p.WeaponMap, weaponId)
|
||||
delete(p.GameObjectGuidMap, weapon.Guid)
|
||||
delete(w.WeaponMap, weaponId)
|
||||
delete(player.GameObjectGuidMap, weapon.Guid)
|
||||
return weapon.Guid
|
||||
}
|
||||
@@ -1,76 +0,0 @@
|
||||
package model
|
||||
|
||||
import "hk4e/common/constant"
|
||||
|
||||
type Item struct {
|
||||
ItemId uint32 // 道具id
|
||||
Count uint32 // 道具数量
|
||||
Guid uint64 `bson:"-" msgpack:"-"`
|
||||
}
|
||||
|
||||
func (p *Player) InitAllItem() {
|
||||
for itemId, item := range p.ItemMap {
|
||||
item.Guid = p.GetNextGameObjectGuid()
|
||||
p.GameObjectGuidMap[item.Guid] = GameObject(item)
|
||||
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 {
|
||||
prop, ok := constant.VIRTUAL_ITEM_PROP[itemId]
|
||||
if ok {
|
||||
value := p.PropertiesMap[prop]
|
||||
return value
|
||||
} else {
|
||||
itemInfo := p.ItemMap[itemId]
|
||||
if itemInfo == nil {
|
||||
return 0
|
||||
}
|
||||
return itemInfo.Count
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Player) AddItem(itemId uint32, count uint32) {
|
||||
itemInfo := p.ItemMap[itemId]
|
||||
if itemInfo == nil {
|
||||
// 该物品为新物品时校验背包物品容量
|
||||
// 目前物品包括材料和家具
|
||||
if len(p.ItemMap) > constant.STORE_PACK_LIMIT_MATERIAL+constant.STORE_PACK_LIMIT_FURNITURE {
|
||||
return
|
||||
}
|
||||
itemInfo = &Item{
|
||||
ItemId: itemId,
|
||||
Count: 0,
|
||||
Guid: p.GetNextGameObjectGuid(),
|
||||
}
|
||||
p.GameObjectGuidMap[itemInfo.Guid] = GameObject(itemInfo)
|
||||
}
|
||||
itemInfo.Count += count
|
||||
p.ItemMap[itemId] = itemInfo
|
||||
}
|
||||
|
||||
func (p *Player) CostItem(itemId uint32, count uint32) {
|
||||
itemInfo := p.ItemMap[itemId]
|
||||
if itemInfo == nil {
|
||||
return
|
||||
}
|
||||
if itemInfo.Count < count {
|
||||
itemInfo.Count = 0
|
||||
} else {
|
||||
itemInfo.Count -= count
|
||||
}
|
||||
if itemInfo.Count == 0 {
|
||||
delete(p.ItemMap, itemId)
|
||||
delete(p.GameObjectGuidMap, itemInfo.Guid)
|
||||
} else {
|
||||
p.ItemMap[itemId] = itemInfo
|
||||
}
|
||||
}
|
||||
+38
-41
@@ -25,45 +25,43 @@ type GameObject interface {
|
||||
|
||||
type Player struct {
|
||||
// 离线数据 请尽量不要定义接口等复杂数据结构
|
||||
ID primitive.ObjectID `bson:"_id,omitempty"`
|
||||
PlayerID uint32 `bson:"PlayerID"` // 玩家uid
|
||||
NickName string // 玩家昵称
|
||||
Signature string // 玩家签名
|
||||
HeadImage uint32 // 玩家头像
|
||||
Birthday []uint8 // 生日
|
||||
NameCard uint32 // 当前名片
|
||||
NameCardList []uint32 // 已解锁名片列表
|
||||
FriendList map[uint32]bool // 好友uid列表
|
||||
FriendApplyList map[uint32]bool // 好友申请uid列表
|
||||
OfflineTime uint32 // 离线时间点
|
||||
OnlineTime uint32 // 上线时间点
|
||||
TotalOnlineTime uint32 // 玩家累计在线时长
|
||||
PropertiesMap map[uint16]uint32 // 玩家自身相关的一些属性
|
||||
FlyCloakList []uint32 // 风之翼列表
|
||||
CostumeList []uint32 // 角色衣装列表
|
||||
SceneId uint32 // 场景
|
||||
SafePos *Vector // 玩家在陆地时的坐标
|
||||
Pos *Vector // 玩家坐标
|
||||
Rot *Vector // 玩家朝向
|
||||
ItemMap map[uint32]*Item // 玩家统一大背包仓库
|
||||
WeaponMap map[uint64]*Weapon // 玩家武器背包
|
||||
ReliquaryMap map[uint64]*Reliquary // 玩家圣遗物背包
|
||||
TeamConfig *TeamInfo // 队伍配置
|
||||
AvatarMap map[uint32]*Avatar // 角色信息
|
||||
DropInfo *DropInfo // 掉落信息
|
||||
MainCharAvatarId uint32 // 主角id
|
||||
GCGInfo *GCGInfo // 七圣召唤信息
|
||||
IsGM uint8 // 管理员权限等级
|
||||
DbQuest *DbQuest // 任务
|
||||
ID primitive.ObjectID `bson:"_id,omitempty"`
|
||||
PlayerID uint32 `bson:"PlayerID"` // 玩家uid
|
||||
NickName string // 昵称
|
||||
Signature string // 签名
|
||||
HeadImage uint32 // 头像
|
||||
Birthday []uint8 // 生日
|
||||
NameCard uint32 // 当前名片
|
||||
NameCardList []uint32 // 已解锁名片列表
|
||||
FriendList map[uint32]bool // 好友uid列表
|
||||
FriendApplyList map[uint32]bool // 好友申请uid列表
|
||||
OfflineTime uint32 // 离线时间点
|
||||
OnlineTime uint32 // 上线时间点
|
||||
TotalOnlineTime uint32 // 累计在线时长
|
||||
PropertiesMap map[uint16]uint32 // 玩家自身相关的一些属性
|
||||
FlyCloakList []uint32 // 风之翼列表
|
||||
CostumeList []uint32 // 角色衣装列表
|
||||
SceneId uint32 // 场景
|
||||
IsGM uint8 // 管理员权限等级
|
||||
SafePos *Vector // 在陆地时的坐标
|
||||
Pos *Vector // 坐标
|
||||
Rot *Vector // 朝向
|
||||
DbItem *DbItem // 道具
|
||||
DbWeapon *DbWeapon // 武器
|
||||
DbReliquary *DbReliquary // 圣遗物
|
||||
DbTeam *DbTeam // 队伍
|
||||
DbAvatar *DbAvatar // 角色
|
||||
DbGacha *DbGacha // 卡池
|
||||
DbQuest *DbQuest // 任务
|
||||
// 在线数据 请随意 记得加忽略字段的tag
|
||||
LastSaveTime uint32 `bson:"-" msgpack:"-"` // 上一次保存时间
|
||||
EnterSceneToken uint32 `bson:"-" msgpack:"-"` // 玩家的世界进入令牌
|
||||
EnterSceneToken uint32 `bson:"-" msgpack:"-"` // 世界进入令牌
|
||||
DbState int `bson:"-" msgpack:"-"` // 数据库存档状态
|
||||
WorldId uint32 `bson:"-" msgpack:"-"` // 所在的世界id
|
||||
GameObjectGuidCounter uint64 `bson:"-" msgpack:"-"` // 游戏对象guid计数器
|
||||
LastKeepaliveTime uint32 `bson:"-" msgpack:"-"` // 上一次保持活跃时间
|
||||
ClientTime uint32 `bson:"-" msgpack:"-"` // 玩家客户端的本地时钟
|
||||
ClientRTT uint32 `bson:"-" msgpack:"-"` // 玩家客户端往返时延
|
||||
ClientTime uint32 `bson:"-" msgpack:"-"` // 客户端的本地时钟
|
||||
ClientRTT uint32 `bson:"-" msgpack:"-"` // 客户端往返时延
|
||||
GameObjectGuidMap map[uint64]GameObject `bson:"-" msgpack:"-"` // 游戏对象guid映射表
|
||||
Online bool `bson:"-" msgpack:"-"` // 在线状态
|
||||
Pause bool `bson:"-" msgpack:"-"` // 暂停状态
|
||||
@@ -78,6 +76,7 @@ type Player struct {
|
||||
GateAppId string `bson:"-" msgpack:"-"` // 网关服务器的appid
|
||||
FightAppId string `bson:"-" msgpack:"-"` // 战斗服务器的appid
|
||||
GCGCurGameGuid uint32 `bson:"-" msgpack:"-"` // GCG玩家所在的游戏guid
|
||||
GCGInfo *GCGInfo `bson:"-" msgpack:"-"` // 七圣召唤信息
|
||||
// 特殊数据
|
||||
ChatMsgMap map[uint32][]*ChatMsg `bson:"-" msgpack:"-"` // 聊天信息 数据量偏大 只从db读写 不保存到redis
|
||||
}
|
||||
@@ -87,17 +86,15 @@ func (p *Player) GetNextGameObjectGuid() uint64 {
|
||||
return uint64(p.PlayerID)<<32 + p.GameObjectGuidCounter
|
||||
}
|
||||
|
||||
func (p *Player) InitAll() {
|
||||
func (p *Player) InitOnlineData() {
|
||||
// 在线数据初始化
|
||||
p.GameObjectGuidMap = make(map[uint64]GameObject)
|
||||
p.CoopApplyMap = make(map[uint32]int64)
|
||||
p.StaminaInfo = new(StaminaInfo)
|
||||
p.VehicleInfo = new(VehicleInfo)
|
||||
p.VehicleInfo.LastCreateEntityIdMap = make(map[uint32]uint32)
|
||||
p.StaminaInfo = NewStaminaInfo()
|
||||
p.VehicleInfo = NewVehicleInfo()
|
||||
p.CombatInvokeHandler = NewInvokeHandler[proto.CombatInvokeEntry]()
|
||||
p.AbilityInvokeHandler = NewInvokeHandler[proto.AbilityInvokeEntry]()
|
||||
p.GCGInfo = NewGCGInfo() // 临时测试用数据
|
||||
p.InitAllAvatar()
|
||||
p.InitAllWeapon()
|
||||
p.InitAllItem()
|
||||
p.InitAllReliquary()
|
||||
}
|
||||
|
||||
// 多人世界网络同步包转发器
|
||||
|
||||
@@ -18,6 +18,10 @@ type StaminaInfo struct {
|
||||
DrownBackDelay uint8 // 溺水返回安全点延时
|
||||
}
|
||||
|
||||
func NewStaminaInfo() *StaminaInfo {
|
||||
return new(StaminaInfo)
|
||||
}
|
||||
|
||||
// SetStaminaCost 设置动作需要消耗的耐力
|
||||
func (s *StaminaInfo) SetStaminaCost(state proto.MotionState) {
|
||||
// 根据状态决定要修改的耐力
|
||||
|
||||
@@ -6,3 +6,11 @@ type VehicleInfo struct {
|
||||
// TODO 玩家可以在其他世界创建载具 需要额外处理
|
||||
LastCreateEntityIdMap map[uint32]uint32 // 最后一次创建载具的实体Id map[vehicleId]EntityId
|
||||
}
|
||||
|
||||
func NewVehicleInfo() *VehicleInfo {
|
||||
return &VehicleInfo{
|
||||
InVehicleEntityId: 0,
|
||||
LastCreateTime: 0,
|
||||
LastCreateEntityIdMap: make(map[uint32]uint32),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user