1.MongoDB、Redis兼容集群模式

2.离线数据接口化访问
This commit is contained in:
flswld
2023-02-26 23:03:13 +08:00
parent 01cb17d4a9
commit 0395dc0bc2
60 changed files with 1298 additions and 464 deletions

View File

@@ -23,7 +23,7 @@ func (c *CommandManager) GMTeleportPlayer(userId, sceneId uint32, posX, posY, po
// GMAddUserItem 给予玩家物品
func (c *CommandManager) GMAddUserItem(userId, itemId, itemCount uint32) {
GAME_MANAGER.AddUserItem(userId, []*UserItem{
GAME_MANAGER.AddUserItem(userId, []*ChangeItem{
{
ItemId: itemId,
ChangeCount: itemCount,
@@ -75,9 +75,9 @@ func (c *CommandManager) GMAddUserAllItem(userId, itemCount uint32) {
// for itemId := range GAME_MANAGER.GetAllItemDataConfig() {
// c.GMAddUserItem(userId, uint32(itemId), itemCount)
// }
itemList := make([]*UserItem, 0)
itemList := make([]*ChangeItem, 0)
for itemId := range GAME_MANAGER.GetAllItemDataConfig() {
itemList = append(itemList, &UserItem{
itemList = append(itemList, &ChangeItem{
ItemId: uint32(itemId),
ChangeCount: itemCount,
})

View File

@@ -108,10 +108,11 @@ func NewGameManager(dao *dao.Dao, messageQueue *mq.MessageQueue, gsId uint32, gs
}
robot := r.CreateRobot(uid, random.GetRandomStr(8), random.GetRandomStr(10))
r.AddUserAvatar(uid, avatarId)
dbAvatar := robot.GetDbAvatar()
r.SetUpAvatarTeamReq(robot, &proto.SetUpAvatarTeamReq{
TeamId: 1,
AvatarTeamGuidList: []uint64{robot.AvatarMap[avatarId].Guid},
CurAvatarGuid: robot.AvatarMap[avatarId].Guid,
AvatarTeamGuidList: []uint64{dbAvatar.AvatarMap[avatarId].Guid},
CurAvatarGuid: dbAvatar.AvatarMap[avatarId].Guid,
})
robot.Pos.X -= random.GetRandomFloat64(25.0, 35.0)
robot.Pos.Y += 1.0
@@ -160,7 +161,7 @@ func (g *GameManager) run() {
}
func (g *GameManager) gameMainLoopD() {
for times := 1; times <= 100000; times++ {
for times := 1; times <= 10000; times++ {
logger.Warn("start game main loop, times: %v", times)
g.gameMainLoop()
logger.Warn("game main loop stop")

View File

@@ -41,12 +41,13 @@ func (g *GameManager) AddUserAvatar(userId uint32, avatarId uint32) {
return
}
// 判断玩家是否已有该角色
_, ok := player.AvatarMap[avatarId]
dbAvatar := player.GetDbAvatar()
_, ok := dbAvatar.AvatarMap[avatarId]
if ok {
// TODO 如果已有转换命座材料
return
}
player.AddAvatar(avatarId)
dbAvatar.AddAvatar(player, avatarId)
// 添加初始武器
avatarDataConfig := gdconf.GetAvatarDataById(int32(avatarId))
@@ -62,7 +63,7 @@ func (g *GameManager) AddUserAvatar(userId uint32, avatarId uint32) {
g.UpdateUserAvatarFightProp(player.PlayerID, avatarId)
avatarAddNotify := &proto.AvatarAddNotify{
Avatar: g.PacketAvatarInfo(player.AvatarMap[avatarId]),
Avatar: g.PacketAvatarInfo(dbAvatar.AvatarMap[avatarId]),
IsInTeam: false,
}
g.SendMsg(cmd.AvatarAddNotify, userId, player.ClientSeq, avatarAddNotify)
@@ -102,9 +103,9 @@ func (g *GameManager) AvatarPromoteGetRewardReq(player *model.Player, payloadMsg
// 设置该奖励为已被获取状态
avatar.PromoteRewardMap[req.PromoteLevel] = true
// 给予突破奖励
rewardItemList := make([]*UserItem, 0, len(rewardConfig.RewardItemMap))
rewardItemList := make([]*ChangeItem, 0, len(rewardConfig.RewardItemMap))
for itemId, count := range rewardConfig.RewardItemMap {
rewardItemList = append(rewardItemList, &UserItem{
rewardItemList = append(rewardItemList, &ChangeItem{
ItemId: itemId,
ChangeCount: count,
})
@@ -158,22 +159,23 @@ func (g *GameManager) AvatarPromoteReq(player *model.Player, payloadMsg pb.Messa
return
}
// 将被消耗的物品列表
costItemList := make([]*UserItem, 0, len(avatarPromoteConfig.CostItemMap)+1)
costItemList := make([]*ChangeItem, 0, len(avatarPromoteConfig.CostItemMap)+1)
// 突破材料是否足够并添加到消耗物品列表
for itemId, count := range avatarPromoteConfig.CostItemMap {
costItemList = append(costItemList, &UserItem{
costItemList = append(costItemList, &ChangeItem{
ItemId: itemId,
ChangeCount: count,
})
}
// 消耗列表添加摩拉的消耗
costItemList = append(costItemList, &UserItem{
costItemList = append(costItemList, &ChangeItem{
ItemId: constant.ITEM_ID_SCOIN,
ChangeCount: uint32(avatarPromoteConfig.CostCoin),
})
// 突破材料以及摩拉是否足够
dbItem := player.GetDbItem()
for _, item := range costItemList {
if player.GetItemCount(item.ItemId) < item.ChangeCount {
if dbItem.GetItemCount(player, item.ItemId) < item.ChangeCount {
logger.Error("item count not enough, itemId: %v", item.ItemId)
// 摩拉的错误提示与材料不同
if item.ItemId == constant.ITEM_ID_SCOIN {
@@ -217,7 +219,8 @@ func (g *GameManager) AvatarUpgradeReq(player *model.Player, payloadMsg pb.Messa
return
}
// 经验书数量是否足够
if player.GetItemCount(req.ItemId) < req.Count {
dbItem := player.GetDbItem()
if dbItem.GetItemCount(player, req.ItemId) < req.Count {
logger.Error("item count not enough, itemId: %v", req.ItemId)
g.SendError(cmd.AvatarUpgradeRsp, player, &proto.AvatarUpgradeRsp{}, proto.Retcode_RET_ITEM_COUNT_NOT_ENOUGH)
return
@@ -239,7 +242,7 @@ func (g *GameManager) AvatarUpgradeReq(player *model.Player, payloadMsg pb.Messa
// 角色获得的经验
expCount := uint32(itemParam) * req.Count
// 摩拉数量是否足够
if player.GetItemCount(constant.ITEM_ID_SCOIN) < expCount/5 {
if dbItem.GetItemCount(player, constant.ITEM_ID_SCOIN) < expCount/5 {
logger.Error("item count not enough, itemId: %v", constant.ITEM_ID_SCOIN)
g.SendError(cmd.AvatarUpgradeRsp, player, &proto.AvatarUpgradeRsp{}, proto.Retcode_RET_SCOIN_NOT_ENOUGH)
return
@@ -265,7 +268,7 @@ func (g *GameManager) AvatarUpgradeReq(player *model.Player, payloadMsg pb.Messa
return
}
// 消耗升级材料以及摩拉
g.CostUserItem(player.PlayerID, []*UserItem{
g.CostUserItem(player.PlayerID, []*ChangeItem{
{
ItemId: req.ItemId,
ChangeCount: req.Count,
@@ -365,13 +368,14 @@ func (g *GameManager) UpdateUserAvatarFightProp(userId uint32, avatarId uint32)
logger.Error("player is nil, uid: %v", userId)
return
}
avatar, ok := player.AvatarMap[avatarId]
dbAvatar := player.GetDbAvatar()
avatar, ok := dbAvatar.AvatarMap[avatarId]
if !ok {
logger.Error("avatar is nil, avatarId: %v", avatar)
return
}
// 角色初始化面板
player.InitAvatarFightProp(avatar)
dbAvatar.InitAvatarFightProp(avatar)
avatarFightPropNotify := &proto.AvatarFightPropNotify{
AvatarGuid: avatar.Guid,

View File

@@ -67,7 +67,8 @@ func (g *GameManager) TakeoffEquipReq(player *model.Player, payloadMsg pb.Messag
return
}
// 卸下圣遗物
player.TakeOffReliquary(avatar.AvatarId, reliquary.ReliquaryId)
dbAvatar := player.GetDbAvatar()
dbAvatar.TakeOffReliquary(avatar.AvatarId, reliquary)
// 角色更新面板
g.UpdateUserAvatarFightProp(player.PlayerID, avatar.AvatarId)
// 更新玩家装备
@@ -147,12 +148,14 @@ func (g *GameManager) WearUserAvatarReliquary(userId uint32, avatarId uint32, re
logger.Error("player is nil, uid: %v", userId)
return
}
avatar, ok := player.AvatarMap[avatarId]
dbAvatar := player.GetDbAvatar()
avatar, ok := dbAvatar.AvatarMap[avatarId]
if !ok {
logger.Error("avatar error, avatarId: %v", avatarId)
return
}
reliquary, ok := player.ReliquaryMap[reliquaryId]
dbReliquary := player.GetDbReliquary()
reliquary, ok := dbReliquary.ReliquaryMap[reliquaryId]
if !ok {
logger.Error("reliquary error, reliquaryId: %v", reliquaryId)
return
@@ -167,7 +170,7 @@ func (g *GameManager) WearUserAvatarReliquary(userId uint32, avatarId uint32, re
avatarCurReliquary := avatar.EquipReliquaryMap[uint8(reliquaryConfig.ReliquaryType)]
if reliquary.AvatarId != 0 {
// 圣遗物在别的角色身上
targetReliquaryAvatar, ok := player.AvatarMap[reliquary.AvatarId]
targetReliquaryAvatar, ok := dbAvatar.AvatarMap[reliquary.AvatarId]
if !ok {
logger.Error("avatar error, avatarId: %v", reliquary.AvatarId)
return
@@ -175,22 +178,22 @@ func (g *GameManager) WearUserAvatarReliquary(userId uint32, avatarId uint32, re
// 确保目前角色已装备圣遗物
if avatarCurReliquary != nil {
// 卸下角色已装备的圣遗物
player.TakeOffReliquary(avatarId, avatarCurReliquary.ReliquaryId)
dbAvatar.TakeOffReliquary(avatarId, avatarCurReliquary)
// 将目标圣遗物的角色装备当前角色曾装备的圣遗物
player.WearReliquary(targetReliquaryAvatar.AvatarId, avatarCurReliquary.ReliquaryId)
dbAvatar.WearReliquary(targetReliquaryAvatar.AvatarId, avatarCurReliquary)
}
// 将目标圣遗物的角色卸下圣遗物
player.TakeOffReliquary(targetReliquaryAvatar.AvatarId, reliquary.ReliquaryId)
dbAvatar.TakeOffReliquary(targetReliquaryAvatar.AvatarId, reliquary)
// 更新目标圣遗物角色的装备
avatarEquipChangeNotify := g.PacketAvatarEquipChangeNotifyByReliquary(targetReliquaryAvatar, uint8(reliquaryConfig.ReliquaryType))
g.SendMsg(cmd.AvatarEquipChangeNotify, userId, player.ClientSeq, avatarEquipChangeNotify)
} else if avatarCurReliquary != nil {
// 角色当前有圣遗物则卸下
player.TakeOffReliquary(avatarId, avatarCurReliquary.ReliquaryId)
dbAvatar.TakeOffReliquary(avatarId, avatarCurReliquary)
}
// 角色装备圣遗物
player.WearReliquary(avatarId, reliquaryId)
dbAvatar.WearReliquary(avatarId, reliquary)
// 更新角色装备
avatarEquipChangeNotify := g.PacketAvatarEquipChangeNotifyByReliquary(avatar, uint8(reliquaryConfig.ReliquaryType))
@@ -204,12 +207,14 @@ func (g *GameManager) WearUserAvatarWeapon(userId uint32, avatarId uint32, weapo
logger.Error("player is nil, uid: %v", userId)
return
}
avatar, ok := player.AvatarMap[avatarId]
dbAvatar := player.GetDbAvatar()
avatar, ok := dbAvatar.AvatarMap[avatarId]
if !ok {
logger.Error("avatar error, avatarId: %v", avatarId)
return
}
weapon, ok := player.WeaponMap[weaponId]
dbWeapon := player.GetDbWeapon()
weapon, ok := dbWeapon.WeaponMap[weaponId]
if !ok {
logger.Error("weapon error, weaponId: %v", weaponId)
return
@@ -225,18 +230,18 @@ func (g *GameManager) WearUserAvatarWeapon(userId uint32, avatarId uint32, weapo
if avatarCurWeapon != nil {
if weapon.AvatarId != 0 {
// 武器在别的角色身上
targetWeaponAvatar, ok := player.AvatarMap[weapon.AvatarId]
targetWeaponAvatar, ok := dbAvatar.AvatarMap[weapon.AvatarId]
if !ok {
logger.Error("avatar error, avatarId: %v", weapon.AvatarId)
return
}
// 卸下角色已装备的武器
player.TakeOffWeapon(avatarId, avatarCurWeapon.WeaponId)
dbAvatar.TakeOffWeapon(avatarId, avatarCurWeapon)
// 将目标武器的角色卸下武器
player.TakeOffWeapon(targetWeaponAvatar.AvatarId, weapon.WeaponId)
dbAvatar.TakeOffWeapon(targetWeaponAvatar.AvatarId, weapon)
// 将目标武器的角色装备当前角色曾装备的武器
player.WearWeapon(targetWeaponAvatar.AvatarId, avatarCurWeapon.WeaponId)
dbAvatar.WearWeapon(targetWeaponAvatar.AvatarId, avatarCurWeapon)
// 更新目标武器角色的装备
weaponEntityId := uint32(0)
@@ -248,11 +253,11 @@ func (g *GameManager) WearUserAvatarWeapon(userId uint32, avatarId uint32, weapo
g.SendMsg(cmd.AvatarEquipChangeNotify, userId, player.ClientSeq, avatarEquipChangeNotify)
} else {
// 角色当前有武器则卸下
player.TakeOffWeapon(avatarId, avatarCurWeapon.WeaponId)
dbAvatar.TakeOffWeapon(avatarId, avatarCurWeapon)
}
}
// 角色装备武器
player.WearWeapon(avatarId, weaponId)
dbAvatar.WearWeapon(avatarId, weapon)
// 更新角色装备
weaponEntityId := uint32(0)

View File

@@ -222,7 +222,7 @@ func (g *GameManager) DoGachaReq(player *model.Player, payloadMsg pb.Message) {
}
// 先扣掉粉球或蓝球再进行抽卡
g.CostUserItem(player.PlayerID, []*UserItem{
g.CostUserItem(player.PlayerID, []*ChangeItem{
{
ItemId: costItemId,
ChangeCount: gachaTimes,
@@ -268,19 +268,21 @@ func (g *GameManager) DoGachaReq(player *model.Player, payloadMsg pb.Message) {
// 添加抽卡获得的道具
if itemId > 1000 && itemId < 2000 {
avatarId := (itemId % 1000) + 10000000
_, exist := player.AvatarMap[avatarId]
dbAvatar := player.GetDbAvatar()
_, exist := dbAvatar.AvatarMap[avatarId]
if !exist {
g.AddUserAvatar(player.PlayerID, avatarId)
} else {
constellationItemId := itemId + 100
if player.GetItemCount(constellationItemId) < 6 {
g.AddUserItem(player.PlayerID, []*UserItem{{ItemId: constellationItemId, ChangeCount: 1}}, false, 0)
dbItem := player.GetDbItem()
if dbItem.GetItemCount(player, constellationItemId) < 6 {
g.AddUserItem(player.PlayerID, []*ChangeItem{{ItemId: constellationItemId, ChangeCount: 1}}, false, 0)
}
}
} else if itemId > 10000 && itemId < 20000 {
g.AddUserWeapon(player.PlayerID, itemId)
} else {
g.AddUserItem(player.PlayerID, []*UserItem{{ItemId: itemId, ChangeCount: 1}}, false, 0)
g.AddUserItem(player.PlayerID, []*ChangeItem{{ItemId: itemId, ChangeCount: 1}}, false, 0)
}
// 计算星尘星辉
@@ -294,7 +296,7 @@ func (g *GameManager) DoGachaReq(player *model.Player, payloadMsg pb.Message) {
}
// 星尘
if xc != 0 {
g.AddUserItem(player.PlayerID, []*UserItem{{
g.AddUserItem(player.PlayerID, []*ChangeItem{{
ItemId: 222,
ChangeCount: xc,
}}, false, 0)
@@ -305,7 +307,7 @@ func (g *GameManager) DoGachaReq(player *model.Player, payloadMsg pb.Message) {
}
// 星辉
if xh != 0 {
g.AddUserItem(player.PlayerID, []*UserItem{{
g.AddUserItem(player.PlayerID, []*ChangeItem{{
ItemId: 221,
ChangeCount: xh,
}}, false, 0)
@@ -392,7 +394,8 @@ func (g *GameManager) doGachaOnce(userId uint32, gachaType uint32, mustGetUpEnab
}
// 获取用户的卡池保底信息
gachaPoolInfo := player.DropInfo.GachaPoolInfo[gachaType]
dbGacha := player.GetDbGacha()
gachaPoolInfo := dbGacha.GachaPoolInfo[gachaType]
if gachaPoolInfo == nil {
logger.Error("user gacha pool info not found, gacha type: %v", gachaType)
return false, 0

View File

@@ -169,6 +169,7 @@ func (g *GameManager) GCGAskDuelReq(player *model.Player, payloadMsg pb.Message)
},
}
// 玩家信息列表
dbAvatar := player.GetDbAvatar()
for _, controller := range game.controllerMap {
gcgControllerShowInfo := &proto.GCGControllerShowInfo{
ControllerId: controller.controllerId,
@@ -177,7 +178,7 @@ func (g *GameManager) GCGAskDuelReq(player *model.Player, payloadMsg pb.Message)
// 如果为玩家则更改为玩家信息
if controller.controllerType == ControllerType_Player {
gcgControllerShowInfo.ProfilePicture.AvatarId = player.HeadImage
gcgControllerShowInfo.ProfilePicture.AvatarId = player.AvatarMap[player.HeadImage].Costume
gcgControllerShowInfo.ProfilePicture.AvatarId = dbAvatar.AvatarMap[player.HeadImage].Costume
}
gcgAskDuelRsp.Duel.ShowInfoList = append(gcgAskDuelRsp.Duel.ShowInfoList)
}
@@ -481,6 +482,8 @@ func (g *GameManager) PacketGCGGameBriefDataNotify(player *model.Player, busines
},
IsNewGame: true, // TODO 根据游戏修改
}
dbTeam := player.GetDbTeam()
dbAvatar := player.GetDbAvatar()
for _, controller := range game.controllerMap {
gcgPlayerBriefData := &proto.GCGPlayerBriefData{
ControllerId: controller.controllerId,
@@ -494,8 +497,8 @@ func (g *GameManager) PacketGCGGameBriefDataNotify(player *model.Player, busines
// 玩家信息
if controller.player != nil {
gcgPlayerBriefData.Uid = player.PlayerID
gcgPlayerBriefData.ProfilePicture.AvatarId = player.TeamConfig.GetActiveAvatarId()
gcgPlayerBriefData.ProfilePicture.CostumeId = player.AvatarMap[player.TeamConfig.GetActiveAvatarId()].Costume
gcgPlayerBriefData.ProfilePicture.AvatarId = dbTeam.GetActiveAvatarId()
gcgPlayerBriefData.ProfilePicture.CostumeId = dbAvatar.AvatarMap[dbTeam.GetActiveAvatarId()].Costume
gcgPlayerBriefData.NickName = player.NickName
}
gcgGameBriefDataNotify.GcgBriefData.PlayerBriefList = append(gcgGameBriefDataNotify.GcgBriefData.PlayerBriefList)

View File

@@ -8,7 +8,7 @@ import (
"hk4e/protocol/proto"
)
type UserItem struct {
type ChangeItem struct {
ItemId uint32
ChangeCount uint32
}
@@ -49,7 +49,7 @@ func (g *GameManager) GetAllItemDataConfig() map[int32]*gdconf.ItemData {
}
// AddUserItem 玩家添加物品
func (g *GameManager) AddUserItem(userId uint32, itemList []*UserItem, isHint bool, hintReason uint16) {
func (g *GameManager) AddUserItem(userId uint32, itemList []*ChangeItem, isHint bool, hintReason uint16) {
player := USER_MANAGER.GetOnlineUser(userId)
if player == nil {
logger.Error("player is nil, uid: %v", userId)
@@ -58,6 +58,7 @@ func (g *GameManager) AddUserItem(userId uint32, itemList []*UserItem, isHint bo
playerPropNotify := &proto.PlayerPropNotify{
PropMap: make(map[uint32]*proto.PropValue),
}
dbItem := player.GetDbItem()
for _, userItem := range itemList {
// 物品为虚拟物品则另外处理
switch userItem.ItemId {
@@ -83,7 +84,7 @@ func (g *GameManager) AddUserItem(userId uint32, itemList []*UserItem, isHint bo
g.AddUserPlayerExp(userId, userItem.ChangeCount)
default:
// 普通物品直接进背包
player.AddItem(userItem.ItemId, userItem.ChangeCount)
dbItem.AddItem(player, userItem.ItemId, userItem.ChangeCount)
}
}
if len(playerPropNotify.PropMap) > 0 {
@@ -97,10 +98,10 @@ func (g *GameManager) AddUserItem(userId uint32, itemList []*UserItem, isHint bo
for _, userItem := range itemList {
pbItem := &proto.Item{
ItemId: userItem.ItemId,
Guid: player.GetItemGuid(userItem.ItemId),
Guid: dbItem.GetItemGuid(userItem.ItemId),
Detail: &proto.Item_Material{
Material: &proto.Material{
Count: player.GetItemCount(userItem.ItemId),
Count: dbItem.GetItemCount(player, userItem.ItemId),
},
},
}
@@ -127,7 +128,7 @@ func (g *GameManager) AddUserItem(userId uint32, itemList []*UserItem, isHint bo
}
}
func (g *GameManager) CostUserItem(userId uint32, itemList []*UserItem) {
func (g *GameManager) CostUserItem(userId uint32, itemList []*ChangeItem) {
player := USER_MANAGER.GetOnlineUser(userId)
if player == nil {
logger.Error("player is nil, uid: %v", userId)
@@ -136,6 +137,7 @@ func (g *GameManager) CostUserItem(userId uint32, itemList []*UserItem) {
playerPropNotify := &proto.PlayerPropNotify{
PropMap: make(map[uint32]*proto.PropValue),
}
dbItem := player.GetDbItem()
for _, userItem := range itemList {
// 物品为虚拟物品则另外处理
switch userItem.ItemId {
@@ -164,7 +166,7 @@ func (g *GameManager) CostUserItem(userId uint32, itemList []*UserItem) {
// 冒险阅历应该也没人会去扣吧?
default:
// 普通物品直接扣除
player.CostItem(userItem.ItemId, userItem.ChangeCount)
dbItem.CostItem(player, userItem.ItemId, userItem.ChangeCount)
}
}
if len(playerPropNotify.PropMap) > 0 {
@@ -176,13 +178,13 @@ func (g *GameManager) CostUserItem(userId uint32, itemList []*UserItem) {
ItemList: make([]*proto.Item, 0),
}
for _, userItem := range itemList {
count := player.GetItemCount(userItem.ItemId)
count := dbItem.GetItemCount(player, userItem.ItemId)
if count == 0 {
continue
}
pbItem := &proto.Item{
ItemId: userItem.ItemId,
Guid: player.GetItemGuid(userItem.ItemId),
Guid: dbItem.GetItemGuid(userItem.ItemId),
Detail: &proto.Item_Material{
Material: &proto.Material{
Count: count,
@@ -200,11 +202,11 @@ func (g *GameManager) CostUserItem(userId uint32, itemList []*UserItem) {
GuidList: make([]uint64, 0),
}
for _, userItem := range itemList {
count := player.GetItemCount(userItem.ItemId)
count := dbItem.GetItemCount(player, userItem.ItemId)
if count > 0 {
continue
}
storeItemDelNotify.GuidList = append(storeItemDelNotify.GuidList, player.GetItemGuid(userItem.ItemId))
storeItemDelNotify.GuidList = append(storeItemDelNotify.GuidList, dbItem.GetItemGuid(userItem.ItemId))
}
if len(storeItemDelNotify.GuidList) > 0 {
g.SendMsg(cmd.StoreItemDelNotify, userId, player.ClientSeq, storeItemDelNotify)

View File

@@ -56,7 +56,15 @@ func (g *GameManager) OnLoginOk(userId uint32, player *model.Player, clientSeq u
player.GateAppId = gateAppId
// 初始化
player.InitAll()
player.InitOnlineData()
dbAvatar := player.GetDbAvatar()
dbAvatar.InitAllAvatar(player)
dbReliquary := player.GetDbReliquary()
dbReliquary.InitAllReliquary(player)
dbWeapon := player.GetDbWeapon()
dbWeapon.InitAllWeapon(player)
dbItem := player.GetDbItem()
dbItem.InitAllItem(player)
// 确保玩家位置安全
player.Pos.X = player.SafePos.X
@@ -68,9 +76,6 @@ func (g *GameManager) OnLoginOk(userId uint32, player *model.Player, clientSeq u
player.Rot = &model.Vector{X: 0, Y: 307, Z: 0}
}
player.CombatInvokeHandler = model.NewInvokeHandler[proto.CombatInvokeEntry]()
player.AbilityInvokeHandler = model.NewInvokeHandler[proto.AbilityInvokeEntry]()
if userId < PlayerBaseUid {
return
}
@@ -196,12 +201,15 @@ func (g *GameManager) PacketStoreWeightLimitNotify() *proto.StoreWeightLimitNoti
}
func (g *GameManager) PacketPlayerStoreNotify(player *model.Player) *proto.PlayerStoreNotify {
dbItem := player.GetDbItem()
dbWeapon := player.GetDbWeapon()
dbReliquary := player.GetDbReliquary()
playerStoreNotify := &proto.PlayerStoreNotify{
StoreType: proto.StoreType_STORE_PACK,
WeightLimit: constant.STORE_PACK_LIMIT_WEIGHT,
ItemList: make([]*proto.Item, 0, len(player.WeaponMap)+len(player.ReliquaryMap)+len(player.ItemMap)),
ItemList: make([]*proto.Item, 0, len(dbItem.ItemMap)+len(dbWeapon.WeaponMap)+len(dbReliquary.ReliquaryMap)),
}
for _, weapon := range player.WeaponMap {
for _, weapon := range dbWeapon.WeaponMap {
itemDataConfig := gdconf.GetItemDataById(int32(weapon.ItemId))
if itemDataConfig == nil {
logger.Error("get item data config is nil, itemId: %v", weapon.ItemId)
@@ -233,7 +241,7 @@ func (g *GameManager) PacketPlayerStoreNotify(player *model.Player) *proto.Playe
}
playerStoreNotify.ItemList = append(playerStoreNotify.ItemList, pbItem)
}
for _, reliquary := range player.ReliquaryMap {
for _, reliquary := range dbReliquary.ReliquaryMap {
itemDataConfig := gdconf.GetItemDataById(int32(reliquary.ItemId))
if itemDataConfig == nil {
logger.Error("get item data config is nil, itemId: %v", reliquary.ItemId)
@@ -262,7 +270,7 @@ func (g *GameManager) PacketPlayerStoreNotify(player *model.Player) *proto.Playe
}
playerStoreNotify.ItemList = append(playerStoreNotify.ItemList, pbItem)
}
for _, item := range player.ItemMap {
for _, item := range dbItem.ItemMap {
itemDataConfig := gdconf.GetItemDataById(int32(item.ItemId))
if itemDataConfig == nil {
logger.Error("get item data config is nil, itemId: %v", item.ItemId)
@@ -293,24 +301,25 @@ func (g *GameManager) PacketPlayerStoreNotify(player *model.Player) *proto.Playe
}
func (g *GameManager) PacketAvatarDataNotify(player *model.Player) *proto.AvatarDataNotify {
chooseAvatarId := player.MainCharAvatarId
dbAvatar := player.GetDbAvatar()
dbTeam := player.GetDbTeam()
avatarDataNotify := &proto.AvatarDataNotify{
CurAvatarTeamId: uint32(player.TeamConfig.GetActiveTeamId()),
ChooseAvatarGuid: player.AvatarMap[chooseAvatarId].Guid,
CurAvatarTeamId: uint32(dbTeam.GetActiveTeamId()),
ChooseAvatarGuid: dbAvatar.AvatarMap[dbAvatar.MainCharAvatarId].Guid,
OwnedFlycloakList: player.FlyCloakList,
// 角色衣装
OwnedCostumeList: player.CostumeList,
AvatarList: make([]*proto.AvatarInfo, 0),
AvatarTeamMap: make(map[uint32]*proto.AvatarTeam),
}
for _, avatar := range player.AvatarMap {
for _, avatar := range dbAvatar.AvatarMap {
pbAvatar := g.PacketAvatarInfo(avatar)
avatarDataNotify.AvatarList = append(avatarDataNotify.AvatarList, pbAvatar)
}
for teamIndex, team := range player.TeamConfig.TeamList {
for teamIndex, team := range dbTeam.TeamList {
var teamAvatarGuidList []uint64 = nil
for _, avatarId := range team.GetAvatarIdList() {
teamAvatarGuidList = append(teamAvatarGuidList, player.AvatarMap[avatarId].Guid)
teamAvatarGuidList = append(teamAvatarGuidList, dbAvatar.AvatarMap[avatarId].Guid)
}
avatarDataNotify.AvatarTeamMap[uint32(teamIndex)+1] = &proto.AvatarTeam{
AvatarGuidList: teamAvatarGuidList,
@@ -336,7 +345,6 @@ func (g *GameManager) CreatePlayer(userId uint32, nickName string, mainCharAvata
player.PlayerID = userId
player.NickName = nickName
player.Signature = ""
player.MainCharAvatarId = mainCharAvatarId
player.HeadImage = mainCharAvatarId
player.Birthday = []uint8{0, 0}
player.NameCard = 210001
@@ -368,29 +376,28 @@ func (g *GameManager) CreatePlayer(userId uint32, nickName string, mainCharAvata
player.Pos = &model.Vector{X: 2747, Y: 194, Z: -1719}
player.Rot = &model.Vector{X: 0, Y: 307, Z: 0}
player.ItemMap = make(map[uint32]*model.Item)
player.WeaponMap = make(map[uint64]*model.Weapon)
player.ReliquaryMap = make(map[uint64]*model.Reliquary)
player.AvatarMap = make(map[uint32]*model.Avatar)
dbAvatar := player.GetDbAvatar()
dbAvatar.MainCharAvatarId = mainCharAvatarId
player.GameObjectGuidMap = make(map[uint64]model.GameObject)
player.DropInfo = model.NewDropInfo()
player.GCGInfo = model.NewGCGInfo()
// 添加选定的主角
player.AddAvatar(mainCharAvatarId)
// 添加初始武器
dbAvatar.AddAvatar(player, mainCharAvatarId)
// 添加主角初始武器
avatarDataConfig := gdconf.GetAvatarDataById(int32(mainCharAvatarId))
if avatarDataConfig == nil {
logger.Error("config is nil, mainCharAvatarId: %v", mainCharAvatarId)
return nil
}
weaponId := uint64(g.snowflake.GenId())
player.AddWeapon(uint32(avatarDataConfig.InitialWeapon), weaponId)
// 角色装上初始武器
player.WearWeapon(mainCharAvatarId, weaponId)
dbWeapon := player.GetDbWeapon()
dbWeapon.AddWeapon(player, uint32(avatarDataConfig.InitialWeapon), weaponId)
weapon := dbWeapon.WeaponMap[weaponId]
dbAvatar.WearWeapon(mainCharAvatarId, weapon)
player.TeamConfig = model.NewTeamInfo()
player.TeamConfig.GetActiveTeam().SetAvatarIdList([]uint32{mainCharAvatarId})
dbTeam := player.GetDbTeam()
dbTeam.GetActiveTeam().SetAvatarIdList([]uint32{mainCharAvatarId})
player.ChatMsgMap = make(map[uint32][]*model.ChatMsg)

View File

@@ -46,8 +46,9 @@ func (g *GameManager) AddUserReliquary(userId uint32, itemId uint32) uint64 {
// 圣遗物主属性
mainPropId := uint32(reliquaryMainConfig.MainPropId)
// 玩家添加圣遗物
player.AddReliquary(itemId, reliquaryId, mainPropId)
reliquary := player.GetReliquary(reliquaryId)
dbReliquary := player.GetDbReliquary()
dbReliquary.AddReliquary(player, itemId, reliquaryId, mainPropId)
reliquary := dbReliquary.GetReliquary(reliquaryId)
if reliquary == nil {
logger.Error("reliquary is nil, itemId: %v, reliquaryId: %v", itemId, reliquaryId)
return 0
@@ -108,8 +109,9 @@ func (g *GameManager) CostUserReliquary(userId uint32, reliquaryIdList []uint64)
GuidList: make([]uint64, 0, len(reliquaryIdList)),
StoreType: proto.StoreType_STORE_PACK,
}
dbReliquary := player.GetDbReliquary()
for _, reliquaryId := range reliquaryIdList {
reliquaryGuid := player.CostReliquary(reliquaryId)
reliquaryGuid := dbReliquary.CostReliquary(player, reliquaryId)
if reliquaryGuid == 0 {
logger.Error("reliquary cost error, reliquaryId: %v", reliquaryId)
return

View File

@@ -148,8 +148,9 @@ func (g *GameManager) SceneInitFinishReq(player *model.Player, payloadMsg pb.Mes
},
AvatarEnterInfo: make([]*proto.AvatarEnterSceneInfo, 0),
}
dbAvatar := player.GetDbAvatar()
for _, worldAvatar := range world.GetPlayerWorldAvatarList(player) {
avatar := player.AvatarMap[worldAvatar.GetAvatarId()]
avatar := dbAvatar.AvatarMap[worldAvatar.GetAvatarId()]
avatarEnterSceneInfo := &proto.AvatarEnterSceneInfo{
AvatarGuid: avatar.Guid,
AvatarEntityId: world.GetPlayerWorldAvatarEntityId(player, worldAvatar.GetAvatarId()),
@@ -652,7 +653,8 @@ func (g *GameManager) PacketSceneEntityInfoAvatar(scene *Scene, player *model.Pl
Z: float32(entity.GetPos().Z),
}
worldAvatar := scene.GetWorld().GetWorldAvatarByEntityId(entity.GetId())
avatar, ok := player.AvatarMap[worldAvatar.GetAvatarId()]
dbAvatar := player.GetDbAvatar()
avatar, ok := dbAvatar.AvatarMap[worldAvatar.GetAvatarId()]
if !ok {
logger.Error("avatar error, avatarId: %v", worldAvatar.GetAvatarId())
return new(proto.SceneEntityInfo)
@@ -897,7 +899,8 @@ func (g *GameManager) PacketSceneEntityInfoGadget(scene *Scene, entityId uint32)
}
func (g *GameManager) PacketSceneAvatarInfo(scene *Scene, player *model.Player, avatarId uint32) *proto.SceneAvatarInfo {
avatar, ok := player.AvatarMap[avatarId]
dbAvatar := player.GetDbAvatar()
avatar, ok := dbAvatar.AvatarMap[avatarId]
if !ok {
logger.Error("avatar error, avatarId: %v", avatarId)
return new(proto.SceneAvatarInfo)

View File

@@ -80,19 +80,20 @@ func (g *GameManager) BuyGoodsReq(player *model.Player, payloadMsg pb.Message) {
return
}
if player.GetItemCount(201) < costHcoinCount {
dbItem := player.GetDbItem()
if dbItem.GetItemCount(player, 201) < costHcoinCount {
return
}
g.CostUserItem(player.PlayerID, []*UserItem{{
g.CostUserItem(player.PlayerID, []*ChangeItem{{
ItemId: 201,
ChangeCount: costHcoinCount,
}})
g.AddUserItem(player.PlayerID, []*UserItem{{
g.AddUserItem(player.PlayerID, []*ChangeItem{{
ItemId: buyItemId,
ChangeCount: buyItemCount,
}}, true, constant.ActionReasonShop)
req.Goods.BoughtNum = player.GetItemCount(buyItemId)
req.Goods.BoughtNum = dbItem.GetItemCount(player, buyItemId)
buyGoodsRsp := &proto.BuyGoodsRsp{
ShopType: req.ShopType,
@@ -110,15 +111,16 @@ func (g *GameManager) McoinExchangeHcoinReq(player *model.Player, payloadMsg pb.
}
count := req.Hcoin
if player.GetItemCount(203) < count {
dbItem := player.GetDbItem()
if dbItem.GetItemCount(player, 203) < count {
return
}
g.CostUserItem(player.PlayerID, []*UserItem{{
g.CostUserItem(player.PlayerID, []*ChangeItem{{
ItemId: 203,
ChangeCount: count,
}})
g.AddUserItem(player.PlayerID, []*UserItem{{
g.AddUserItem(player.PlayerID, []*ChangeItem{{
ItemId: 201,
ChangeCount: count,
}}, false, 0)

View File

@@ -127,7 +127,8 @@ func (g *GameManager) SetPlayerHeadImageReq(player *model.Player, payloadMsg pb.
logger.Debug("user change head image, uid: %v", player.PlayerID)
req := payloadMsg.(*proto.SetPlayerHeadImageReq)
avatarId := req.AvatarId
_, exist := player.AvatarMap[avatarId]
dbAvatar := player.GetDbAvatar()
_, exist := dbAvatar.AvatarMap[avatarId]
if !exist {
logger.Error("the head img of the avatar not exist, uid: %v", player.PlayerID)
return

View File

@@ -39,7 +39,8 @@ func (g *GameManager) ChangeAvatarReq(player *model.Player, payloadMsg pb.Messag
return
}
if !world.GetMultiplayer() {
player.TeamConfig.CurrAvatarIndex = uint8(newAvatarIndex)
dbTeam := player.GetDbTeam()
dbTeam.CurrAvatarIndex = uint8(newAvatarIndex)
}
world.SetPlayerAvatarIndex(player, newAvatarIndex)
oldAvatarEntityId := world.GetPlayerWorldAvatarEntityId(player, oldAvatarId)
@@ -89,31 +90,33 @@ func (g *GameManager) SetUpAvatarTeamReq(player *model.Player, payloadMsg pb.Mes
return
}
avatarGuidList := req.AvatarTeamGuidList
selfTeam := teamId == uint32(player.TeamConfig.GetActiveTeamId())
dbTeam := player.GetDbTeam()
selfTeam := teamId == uint32(dbTeam.GetActiveTeamId())
if (selfTeam && len(avatarGuidList) == 0) || len(avatarGuidList) > 4 {
g.SendError(cmd.SetUpAvatarTeamRsp, player, &proto.SetUpAvatarTeamRsp{})
return
}
avatarIdList := make([]uint32, 0)
dbAvatar := player.GetDbAvatar()
for _, avatarGuid := range avatarGuidList {
for avatarId, avatar := range player.AvatarMap {
for avatarId, avatar := range dbAvatar.AvatarMap {
if avatarGuid == avatar.Guid {
avatarIdList = append(avatarIdList, avatarId)
}
}
}
player.TeamConfig.GetTeamByIndex(uint8(teamId - 1)).SetAvatarIdList(avatarIdList)
dbTeam.GetTeamByIndex(uint8(teamId - 1)).SetAvatarIdList(avatarIdList)
avatarTeamUpdateNotify := &proto.AvatarTeamUpdateNotify{
AvatarTeamMap: make(map[uint32]*proto.AvatarTeam),
}
for teamIndex, team := range player.TeamConfig.TeamList {
for teamIndex, team := range dbTeam.TeamList {
avatarTeam := &proto.AvatarTeam{
TeamName: team.Name,
AvatarGuidList: make([]uint64, 0),
}
for _, avatarId := range team.GetAvatarIdList() {
avatarTeam.AvatarGuidList = append(avatarTeam.AvatarGuidList, player.AvatarMap[avatarId].Guid)
avatarTeam.AvatarGuidList = append(avatarTeam.AvatarGuidList, dbAvatar.AvatarMap[avatarId].Guid)
}
avatarTeamUpdateNotify.AvatarTeamMap[uint32(teamIndex)+1] = avatarTeam
}
@@ -133,7 +136,7 @@ func (g *GameManager) SetUpAvatarTeamReq(player *model.Player, payloadMsg pb.Mes
}
currAvatarId := currAvatar.AvatarId
currAvatarIndex := world.GetPlayerAvatarIndexByAvatarId(player, currAvatarId)
player.TeamConfig.CurrAvatarIndex = uint8(currAvatarIndex)
dbTeam.CurrAvatarIndex = uint8(currAvatarIndex)
world.SetPlayerAvatarIndex(player, currAvatarIndex)
sceneTeamUpdateNotify := g.PacketSceneTeamUpdateNotify(world)
@@ -157,12 +160,13 @@ func (g *GameManager) ChooseCurAvatarTeamReq(player *model.Player, payloadMsg pb
g.SendError(cmd.ChooseCurAvatarTeamRsp, player, &proto.ChooseCurAvatarTeamRsp{})
return
}
team := player.TeamConfig.GetTeamByIndex(uint8(teamId) - 1)
dbTeam := player.GetDbTeam()
team := dbTeam.GetTeamByIndex(uint8(teamId) - 1)
if team == nil || len(team.GetAvatarIdList()) == 0 {
return
}
player.TeamConfig.CurrTeamIndex = uint8(teamId) - 1
player.TeamConfig.CurrAvatarIndex = 0
dbTeam.CurrTeamIndex = uint8(teamId) - 1
dbTeam.CurrAvatarIndex = 0
// player.TeamConfig.UpdateTeam()
world.SetPlayerAvatarIndex(player, 0)
world.SetPlayerLocalTeam(player, team.GetAvatarIdList())
@@ -239,7 +243,8 @@ func (g *GameManager) PacketSceneTeamUpdateNotify(world *World) *proto.SceneTeam
logger.Error("scene is nil, sceneId: %v", worldPlayer.SceneId)
return new(proto.SceneTeamUpdateNotify)
}
worldPlayerAvatar := worldPlayer.AvatarMap[worldAvatar.GetAvatarId()]
worldPlayerDbAvatar := worldPlayer.GetDbAvatar()
worldPlayerAvatar := worldPlayerDbAvatar.AvatarMap[worldAvatar.GetAvatarId()]
equipIdList := make([]uint32, 0)
weapon := worldPlayerAvatar.EquipWeapon
equipIdList = append(equipIdList, weapon.ItemId)

View File

@@ -114,7 +114,9 @@ func (g *GameManager) DestroyVehicleEntity(player *model.Player, scene *Scene, v
// 如果玩家正在载具中
if g.IsPlayerInVehicle(player, gadgetEntity.GetGadgetVehicleEntity()) {
// 离开载具
g.ExitVehicle(player, entity, player.AvatarMap[player.TeamConfig.GetActiveAvatarId()].Guid)
dbTeam := player.GetDbTeam()
dbAvatar := player.GetDbAvatar()
g.ExitVehicle(player, entity, dbAvatar.AvatarMap[dbTeam.GetActiveAvatarId()].Guid)
}
// 删除已创建的载具
scene.DestroyEntity(entity.GetId())
@@ -220,7 +222,9 @@ func (g *GameManager) VehicleInteractReq(player *model.Player, payloadMsg pb.Mes
return
}
avatarGuid := player.AvatarMap[player.TeamConfig.GetActiveAvatarId()].Guid
dbTeam := player.GetDbTeam()
dbAvatar := player.GetDbAvatar()
avatarGuid := dbAvatar.AvatarMap[dbTeam.GetActiveAvatarId()].Guid
switch req.InteractType {
case proto.VehicleInteractType_VEHICLE_INTERACT_IN:

View File

@@ -50,8 +50,9 @@ func (g *GameManager) AddUserWeapon(userId uint32, itemId uint32) uint64 {
return 0
}
weaponId := uint64(g.snowflake.GenId())
player.AddWeapon(itemId, weaponId)
weapon := player.GetWeapon(weaponId)
dbWeapon := player.GetDbWeapon()
dbWeapon.AddWeapon(player, itemId, weaponId)
weapon := dbWeapon.GetWeapon(weaponId)
if weapon == nil {
logger.Error("weapon is nil, itemId: %v, weaponId: %v", itemId, weaponId)
return 0
@@ -70,8 +71,9 @@ func (g *GameManager) CostUserWeapon(userId uint32, weaponIdList []uint64) {
GuidList: make([]uint64, 0, len(weaponIdList)),
StoreType: proto.StoreType_STORE_PACK,
}
dbWeapon := player.GetDbWeapon()
for _, weaponId := range weaponIdList {
weaponGuid := player.CostWeapon(weaponId)
weaponGuid := dbWeapon.CostWeapon(player, weaponId)
if weaponGuid == 0 {
logger.Error("weapon cost error, weaponId: %v", weaponId)
return
@@ -142,7 +144,8 @@ func (g *GameManager) WeaponAwakenReq(player *model.Player, payloadMsg pb.Messag
return
}
// 摩拉数量是否足够
if player.GetItemCount(constant.ITEM_ID_SCOIN) < weaponConfig.AwakenCoinCostList[weapon.Refinement] {
dbItem := player.GetDbItem()
if dbItem.GetItemCount(player, constant.ITEM_ID_SCOIN) < weaponConfig.AwakenCoinCostList[weapon.Refinement] {
logger.Error("item count not enough, itemId: %v", constant.ITEM_ID_SCOIN)
g.SendError(cmd.WeaponAwakenRsp, player, &proto.WeaponAwakenRsp{}, proto.Retcode_RET_SCOIN_NOT_ENOUGH)
return
@@ -224,7 +227,7 @@ func (g *GameManager) WeaponAwakenReq(player *model.Player, payloadMsg pb.Messag
return
}
// 消耗作为精炼材料的道具
g.CostUserItem(player.PlayerID, []*UserItem{
g.CostUserItem(player.PlayerID, []*ChangeItem{
{
ItemId: item.ItemId,
ChangeCount: 1,
@@ -236,7 +239,7 @@ func (g *GameManager) WeaponAwakenReq(player *model.Player, payloadMsg pb.Messag
return
}
// 消耗摩拉
g.CostUserItem(player.PlayerID, []*UserItem{
g.CostUserItem(player.PlayerID, []*ChangeItem{
{
ItemId: constant.ITEM_ID_SCOIN,
ChangeCount: weaponConfig.AwakenCoinCostList[weapon.Refinement],
@@ -260,7 +263,8 @@ func (g *GameManager) WeaponAwakenReq(player *model.Player, payloadMsg pb.Messag
// 更新武器的物品数据
g.SendMsg(cmd.StoreItemChangeNotify, player.PlayerID, player.ClientSeq, g.PacketStoreItemChangeNotifyByWeapon(weapon))
// 获取持有该武器的角色
avatar, ok := player.AvatarMap[weapon.AvatarId]
dbAvatar := player.GetDbAvatar()
avatar, ok := dbAvatar.AvatarMap[weapon.AvatarId]
// 武器可能没被任何角色装备 仅在被装备时更新面板
if ok {
weaponAwakenRsp.AvatarGuid = avatar.Guid
@@ -315,22 +319,23 @@ func (g *GameManager) WeaponPromoteReq(player *model.Player, payloadMsg pb.Messa
return
}
// 将被消耗的物品列表
costItemList := make([]*UserItem, 0, len(weaponPromoteConfig.CostItemMap)+1)
costItemList := make([]*ChangeItem, 0, len(weaponPromoteConfig.CostItemMap)+1)
// 突破材料是否足够并添加到消耗物品列表
for itemId, count := range weaponPromoteConfig.CostItemMap {
costItemList = append(costItemList, &UserItem{
costItemList = append(costItemList, &ChangeItem{
ItemId: itemId,
ChangeCount: count,
})
}
// 消耗列表添加摩拉的消耗
costItemList = append(costItemList, &UserItem{
costItemList = append(costItemList, &ChangeItem{
ItemId: constant.ITEM_ID_SCOIN,
ChangeCount: uint32(weaponPromoteConfig.CostCoin),
})
// 突破材料以及摩拉是否足够
dbItem := player.GetDbItem()
for _, item := range costItemList {
if player.GetItemCount(item.ItemId) < item.ChangeCount {
if dbItem.GetItemCount(player, item.ItemId) < item.ChangeCount {
logger.Error("item count not enough, itemId: %v", item.ItemId)
// 摩拉的错误提示与材料不同
if item.ItemId == constant.ITEM_ID_SCOIN {
@@ -357,7 +362,8 @@ func (g *GameManager) WeaponPromoteReq(player *model.Player, payloadMsg pb.Messa
// 更新武器的物品数据
g.SendMsg(cmd.StoreItemChangeNotify, player.PlayerID, player.ClientSeq, g.PacketStoreItemChangeNotifyByWeapon(weapon))
// 获取持有该武器的角色
avatar, ok := player.AvatarMap[weapon.AvatarId]
dbAvatar := player.GetDbAvatar()
avatar, ok := dbAvatar.AvatarMap[weapon.AvatarId]
// 武器可能没被任何角色装备 仅在被装备时更新面板
if ok {
// 角色更新面板
@@ -576,10 +582,10 @@ func (g *GameManager) WeaponUpgradeReq(player *model.Player, payloadMsg pb.Messa
return
}
// 将被消耗的物品列表
costItemList := make([]*UserItem, 0, len(req.ItemParamList)+1)
costItemList := make([]*ChangeItem, 0, len(req.ItemParamList)+1)
// 突破材料是否足够并添加到消耗物品列表
for _, itemParam := range req.ItemParamList {
costItemList = append(costItemList, &UserItem{
costItemList = append(costItemList, &ChangeItem{
ItemId: itemParam.ItemId,
ChangeCount: itemParam.Count,
})
@@ -592,13 +598,14 @@ func (g *GameManager) WeaponUpgradeReq(player *model.Player, payloadMsg pb.Messa
return
}
// 消耗列表添加摩拉的消耗
costItemList = append(costItemList, &UserItem{
costItemList = append(costItemList, &ChangeItem{
ItemId: constant.ITEM_ID_SCOIN,
ChangeCount: coinCost,
})
// 校验物品是否足够
dbItem := player.GetDbItem()
for _, item := range costItemList {
if player.GetItemCount(item.ItemId) < item.ChangeCount {
if dbItem.GetItemCount(player, item.ItemId) < item.ChangeCount {
logger.Error("item count not enough, itemId: %v", item.ItemId)
// 摩拉的错误提示与材料不同
if item.ItemId == constant.ITEM_ID_SCOIN {
@@ -652,7 +659,8 @@ func (g *GameManager) WeaponUpgradeReq(player *model.Player, payloadMsg pb.Messa
g.SendMsg(cmd.StoreItemChangeNotify, player.PlayerID, player.ClientSeq, g.PacketStoreItemChangeNotifyByWeapon(weapon))
// 获取持有该武器的角色
avatar, ok := player.AvatarMap[weapon.AvatarId]
dbAvatar := player.GetDbAvatar()
avatar, ok := dbAvatar.AvatarMap[weapon.AvatarId]
// 武器可能没被任何角色装备 仅在被装备时更新面板
if ok {
// 角色更新面板
@@ -660,9 +668,9 @@ func (g *GameManager) WeaponUpgradeReq(player *model.Player, payloadMsg pb.Messa
}
// 将给予的材料列表
addItemList := make([]*UserItem, 0, len(returnItemList))
addItemList := make([]*ChangeItem, 0, len(returnItemList))
for _, param := range returnItemList {
addItemList = append(addItemList, &UserItem{
addItemList = append(addItemList, &ChangeItem{
ItemId: param.ItemId,
ChangeCount: param.Count,
})

View File

@@ -194,19 +194,19 @@ func (t *TickManager) onTickMinute(now int64) {
i := int32(0)
for itemId := range allItemDataConfig {
num := random.GetRandomInt32(1, 9)
GAME_MANAGER.AddUserItem(player.PlayerID, []*UserItem{{ItemId: uint32(itemId), ChangeCount: uint32(num)}}, true, 0)
GAME_MANAGER.AddUserItem(player.PlayerID, []*ChangeItem{{ItemId: uint32(itemId), ChangeCount: uint32(num)}}, true, 0)
i++
if i > count {
break
}
}
GAME_MANAGER.AddUserItem(player.PlayerID, []*UserItem{{ItemId: 102, ChangeCount: 30}}, true, 0)
GAME_MANAGER.AddUserItem(player.PlayerID, []*UserItem{{ItemId: 201, ChangeCount: 10}}, true, 0)
GAME_MANAGER.AddUserItem(player.PlayerID, []*UserItem{{ItemId: 202, ChangeCount: 100}}, true, 0)
GAME_MANAGER.AddUserItem(player.PlayerID, []*UserItem{{ItemId: 203, ChangeCount: 10}}, true, 0)
GAME_MANAGER.AddUserItem(player.PlayerID, []*ChangeItem{{ItemId: 102, ChangeCount: 30}}, true, 0)
GAME_MANAGER.AddUserItem(player.PlayerID, []*ChangeItem{{ItemId: 201, ChangeCount: 10}}, true, 0)
GAME_MANAGER.AddUserItem(player.PlayerID, []*ChangeItem{{ItemId: 202, ChangeCount: 100}}, true, 0)
GAME_MANAGER.AddUserItem(player.PlayerID, []*ChangeItem{{ItemId: 203, ChangeCount: 10}}, true, 0)
// 蓝球粉球
GAME_MANAGER.AddUserItem(player.PlayerID, []*UserItem{{ItemId: 223, ChangeCount: 1}}, true, 0)
GAME_MANAGER.AddUserItem(player.PlayerID, []*UserItem{{ItemId: 224, ChangeCount: 1}}, true, 0)
GAME_MANAGER.AddUserItem(player.PlayerID, []*ChangeItem{{ItemId: 223, ChangeCount: 1}}, true, 0)
GAME_MANAGER.AddUserItem(player.PlayerID, []*ChangeItem{{ItemId: 224, ChangeCount: 1}}, true, 0)
}
}
}

View File

@@ -309,11 +309,12 @@ func (w *World) AddPlayer(player *model.Player, sceneId uint32) {
w.peerList = append(w.peerList, player)
w.playerMap[player.PlayerID] = player
// 将玩家自身当前的队伍角色信息复制到世界的玩家本地队伍
team := player.TeamConfig.GetActiveTeam()
dbTeam := player.GetDbTeam()
team := dbTeam.GetActiveTeam()
if player.PlayerID == w.owner.PlayerID {
w.SetPlayerLocalTeam(player, team.GetAvatarIdList())
} else {
activeAvatarId := player.TeamConfig.GetActiveAvatarId()
activeAvatarId := dbTeam.GetActiveAvatarId()
w.SetPlayerLocalTeam(player, []uint32{activeAvatarId})
}
playerNum := w.GetWorldPlayerNum()
@@ -328,7 +329,8 @@ func (w *World) AddPlayer(player *model.Player, sceneId uint32) {
for _, worldPlayer := range w.playerMap {
list := w.GetPlayerWorldAvatarList(worldPlayer)
maxIndex := len(list) - 1
index := int(worldPlayer.TeamConfig.CurrAvatarIndex)
worldPlayerDbTeam := worldPlayer.GetDbTeam()
index := int(worldPlayerDbTeam.CurrAvatarIndex)
if index > maxIndex {
w.SetPlayerAvatarIndex(worldPlayer, 0)
} else {

View File

@@ -88,7 +88,8 @@ func (s *Scene) SetEntityLifeState(entity *Entity, lifeState uint16, dieType pro
return
}
// 获取角色
avatar, ok := player.AvatarMap[entity.avatarEntity.avatarId]
dbAvatar := player.GetDbAvatar()
avatar, ok := dbAvatar.AvatarMap[entity.avatarEntity.avatarId]
if !ok {
logger.Error("avatar is nil, avatarId: %v", avatar)
return
@@ -139,7 +140,8 @@ func (s *Scene) SetEntityLifeState(entity *Entity, lifeState uint16, dieType pro
func (s *Scene) CreateEntityAvatar(player *model.Player, avatarId uint32) uint32 {
entityId := s.world.GetNextWorldEntityId(constant.ENTITY_ID_TYPE_AVATAR)
avatar, ok := player.AvatarMap[avatarId]
dbAvatar := player.GetDbAvatar()
avatar, ok := dbAvatar.AvatarMap[avatarId]
if !ok {
logger.Error("avatar error, avatarId: %v", avatar)
return 0
@@ -153,7 +155,7 @@ func (s *Scene) CreateEntityAvatar(player *model.Player, avatarId uint32) uint32
moveState: uint16(proto.MotionState_MOTION_NONE),
lastMoveSceneTimeMs: 0,
lastMoveReliableSeq: 0,
fightProp: player.AvatarMap[avatarId].FightPropMap, // 使用角色结构的数据
fightProp: dbAvatar.AvatarMap[avatarId].FightPropMap, // 使用角色结构的数据
entityType: uint32(proto.ProtEntityType_PROT_ENTITY_AVATAR),
avatarEntity: &AvatarEntity{
uid: player.PlayerID,
@@ -169,7 +171,7 @@ func (s *Scene) CreateEntityAvatar(player *model.Player, avatarId uint32) uint32
EntityId: entity.id,
FightPropMap: entity.fightProp,
Uid: entity.avatarEntity.uid,
AvatarGuid: player.AvatarMap[avatarId].Guid,
AvatarGuid: dbAvatar.AvatarMap[avatarId].Guid,
},
})
return entity.id