From 14356d31f55bd24d310f78fb01018f71f086e003 Mon Sep 17 00:00:00 2001
From: UnKownOwO <80520429@qq.com>
Date: Wed, 20 Sep 2023 14:53:16 +0800
Subject: [PATCH] =?UTF-8?q?=E8=A7=92=E8=89=B2=E9=80=9A=E8=BF=87=E9=A3=9F?=
=?UTF-8?q?=E7=89=A9=E5=A4=8D=E6=B4=BB=E5=88=9D=E6=AD=A5?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
gs/game/game_command_controller.go | 2 +-
gs/game/game_route_manager.go | 1 +
gs/game/game_tick_manager.go | 13 ++++--
gs/game/player_item.go | 63 ++++++++++++++++++++++++++++++
gs/game/player_stamina.go | 36 +++++++++--------
5 files changed, 93 insertions(+), 22 deletions(-)
diff --git a/gs/game/game_command_controller.go b/gs/game/game_command_controller.go
index 6dc4b72b..700a654f 100644
--- a/gs/game/game_command_controller.go
+++ b/gs/game/game_command_controller.go
@@ -465,7 +465,7 @@ func UnlockCommand(c *CommandContent) {
var GcgCommandController = &CommandController{
Name: "七圣召唤测试",
AliasList: []string{"gcgtest"},
- Description: "unlock 七圣召唤测试命令",
+ Description: "gcgtest 七圣召唤测试命令",
Usage: "命令格式:\n1. {alias} 测试七圣召唤",
Perm: CommandPermNormal,
Func: GcgCommand,
diff --git a/gs/game/game_route_manager.go b/gs/game/game_route_manager.go
index f0fdeb28..f65417dd 100644
--- a/gs/game/game_route_manager.go
+++ b/gs/game/game_route_manager.go
@@ -118,6 +118,7 @@ func (r *RouteManager) initRoute() {
r.registerRouter(cmd.EntityForceSyncReq, GAME.EntityForceSyncReq)
r.registerRouter(cmd.AvatarDieAnimationEndReq, GAME.AvatarDieAnimationEndReq)
r.registerRouter(cmd.WorldPlayerReviveReq, GAME.WorldPlayerReviveReq)
+ r.registerRouter(cmd.UseItemReq, GAME.UseItemReq)
}
type HandlerFunc func(player *model.Player, payloadMsg pb.Message)
diff --git a/gs/game/game_tick_manager.go b/gs/game/game_tick_manager.go
index a8bf4857..abfcde74 100644
--- a/gs/game/game_tick_manager.go
+++ b/gs/game/game_tick_manager.go
@@ -156,6 +156,10 @@ func (t *TickManager) userTimerHandle(userId uint32, action int, data []any) {
return
}
pubg := world.GetPubg()
+ if pubg == nil {
+ logger.Error("pubg is nil, worldId: %v, uid: %v", player.WorldId, userId)
+ return
+ }
pubg.phase++
pubg.RefreshArea()
case UserTimerActionPubgDieExit:
@@ -300,10 +304,11 @@ func (t *TickManager) onTickSecond(now int64) {
GAME.WorldPlayerRTTNotify(world)
}
}
- // // GCG游戏Tick
- // for _, game := range GCG_MANAGER.gameMap {
- // game.onTick()
- // }
+ // GCG游戏Tick
+ for _, game := range GCG_MANAGER.gameMap {
+ game.onTick()
+ }
+ // PUBG游戏
if world := WORLD_MANAGER.GetAiWorld(); WORLD_MANAGER.IsBigWorld(world) {
pubg := world.GetPubg()
if pubg == nil {
diff --git a/gs/game/player_item.go b/gs/game/player_item.go
index 03cee81f..51266e08 100644
--- a/gs/game/player_item.go
+++ b/gs/game/player_item.go
@@ -7,10 +7,68 @@ import (
"hk4e/pkg/logger"
"hk4e/protocol/cmd"
"hk4e/protocol/proto"
+
+ pb "google.golang.org/protobuf/proto"
)
/************************************************** 接口请求 **************************************************/
+// UseItemReq 使用物品请求
+func (g *Game) UseItemReq(player *model.Player, payloadMsg pb.Message) {
+ req := payloadMsg.(*proto.UseItemReq)
+ // 是否拥有物品
+ item, ok := player.GameObjectGuidMap[req.Guid].(*model.Item)
+ if !ok {
+ logger.Error("item not exist, weaponGuid: %v", req.Guid)
+ g.SendError(cmd.UseItemRsp, player, &proto.UseItemRsp{}, proto.Retcode_RET_ITEM_NOT_EXIST)
+ return
+ }
+ // 获取物品配置表
+ itemDataConfig := gdconf.GetItemDataById(int32(item.ItemId))
+ if itemDataConfig == nil {
+ logger.Error("item data config is nil, itemId: %v", item.ItemId)
+ g.SendError(cmd.UseItemRsp, player, &proto.UseItemRsp{})
+ return
+ }
+ // 获取角色
+ avatar, ok := player.GameObjectGuidMap[req.TargetGuid].(*model.Avatar)
+ if !ok {
+ logger.Error("avatar not exist, avatarGuid: %v", req.TargetGuid)
+ g.SendError(cmd.UseItemRsp, player, &proto.UseItemRsp{})
+ return
+ }
+ // 根据物品的材料类型做不同操作
+ switch itemDataConfig.MaterialType {
+ case constant.MATERIAL_TYPE_FOOD:
+ // 复活
+ g.RevivePlayerAvatar(player, avatar.AvatarId)
+ case constant.MATERIAL_TYPE_NOTICE_ADD_HP:
+ // 回血
+ default:
+ g.SendError(cmd.UseItemRsp, player, &proto.UseItemRsp{})
+ return
+ }
+ // 消耗物品
+ changeItemList := []*ChangeItem{
+ {
+ ItemId: item.ItemId,
+ ChangeCount: 1,
+ },
+ }
+ if !g.CostPlayerItem(player.PlayerId, changeItemList) {
+ logger.Error("item count not enough, uid: %v", player.PlayerId)
+ g.SendError(cmd.UseItemRsp, player, &proto.UseItemRsp{}, proto.Retcode_RET_ITEM_COUNT_NOT_ENOUGH)
+ return
+ }
+ useItemRsp := &proto.UseItemRsp{
+ Guid: req.Guid,
+ TargetGuid: req.TargetGuid,
+ ItemId: item.ItemId,
+ OptionIdx: 0,
+ }
+ g.SendMsg(cmd.UseItemRsp, player.PlayerId, player.ClientSeq, useItemRsp)
+}
+
/************************************************** 游戏功能 **************************************************/
type ChangeItem struct {
@@ -18,6 +76,7 @@ type ChangeItem struct {
ChangeCount uint32
}
+// GetAllItemDataConfig 获取所有物品数据配置表
func (g *Game) GetAllItemDataConfig() map[int32]*gdconf.ItemData {
allItemDataConfig := make(map[int32]*gdconf.ItemData)
for itemId, itemData := range gdconf.GetItemDataMap() {
@@ -34,6 +93,7 @@ func (g *Game) GetAllItemDataConfig() map[int32]*gdconf.ItemData {
return allItemDataConfig
}
+// GetPlayerItemCount 获取玩家所持有的某个物品的数量
func (g *Game) GetPlayerItemCount(userId uint32, itemId uint32) uint32 {
player := USER_MANAGER.GetOnlineUser(userId)
if player == nil {
@@ -127,6 +187,7 @@ func (g *Game) AddPlayerItem(userId uint32, itemList []*ChangeItem, isHint bool,
return true
}
+// CostPlayerItem 玩家消耗物品
func (g *Game) CostPlayerItem(userId uint32, itemList []*ChangeItem) bool {
player := USER_MANAGER.GetOnlineUser(userId)
if player == nil {
@@ -204,6 +265,7 @@ func (g *Game) CostPlayerItem(userId uint32, itemList []*ChangeItem) bool {
/************************************************** 打包封装 **************************************************/
+// PacketStoreWeightLimitNotify 背包容量限制通知
func (g *Game) PacketStoreWeightLimitNotify() *proto.StoreWeightLimitNotify {
storeWeightLimitNotify := &proto.StoreWeightLimitNotify{
StoreType: proto.StoreType_STORE_PACK,
@@ -217,6 +279,7 @@ func (g *Game) PacketStoreWeightLimitNotify() *proto.StoreWeightLimitNotify {
return storeWeightLimitNotify
}
+// PacketPlayerStoreNotify 玩家背包内容通知
func (g *Game) PacketPlayerStoreNotify(player *model.Player) *proto.PlayerStoreNotify {
dbItem := player.GetDbItem()
dbWeapon := player.GetDbWeapon()
diff --git a/gs/game/player_stamina.go b/gs/game/player_stamina.go
index 5325d862..bcda89ba 100644
--- a/gs/game/player_stamina.go
+++ b/gs/game/player_stamina.go
@@ -366,25 +366,27 @@ func (g *Game) HandleDrown(player *model.Player, stamina uint32) {
return
}
// 确保玩家正在游泳
- if player.StaminaInfo.State == proto.MotionState_MOTION_SWIM_MOVE || player.StaminaInfo.State == proto.MotionState_MOTION_SWIM_DASH {
- logger.Debug("player drown, curStamina: %v, state: %v", stamina, player.StaminaInfo.State)
- // 设置角色为死亡
- world := WORLD_MANAGER.GetWorldById(player.WorldId)
- if world == nil {
- return
+ if player.StaminaInfo.State != proto.MotionState_MOTION_SWIM_MOVE && player.StaminaInfo.State != proto.MotionState_MOTION_SWIM_DASH {
+ return
+ }
+ logger.Debug("player drown, curStamina: %v, state: %v", stamina, player.StaminaInfo.State)
+ // 设置角色为死亡
+ world := WORLD_MANAGER.GetWorldById(player.WorldId)
+ if world == nil {
+ logger.Error("world is nil, worldId: %v, uid: %v", player.WorldId, player.PlayerId)
+ return
+ }
+ for _, worldAvatar := range world.GetPlayerWorldAvatarList(player) {
+ dbAvatar := player.GetDbAvatar()
+ avatar, exist := dbAvatar.AvatarMap[worldAvatar.GetAvatarId()]
+ if !exist {
+ logger.Error("get db avatar is nil, avatarId: %v", worldAvatar.GetAvatarId())
+ continue
}
- for _, worldAvatar := range world.GetPlayerWorldAvatarList(player) {
- dbAvatar := player.GetDbAvatar()
- avatar, exist := dbAvatar.AvatarMap[worldAvatar.GetAvatarId()]
- if !exist {
- logger.Error("get db avatar is nil, avatarId: %v", worldAvatar.GetAvatarId())
- continue
- }
- if avatar.LifeState != constant.LIFE_STATE_ALIVE {
- continue
- }
- g.KillPlayerAvatar(player, worldAvatar.GetAvatarId(), proto.PlayerDieType_PLAYER_DIE_DRAWN)
+ if avatar.LifeState != constant.LIFE_STATE_ALIVE {
+ continue
}
+ g.KillPlayerAvatar(player, worldAvatar.GetAvatarId(), proto.PlayerDieType_PLAYER_DIE_DRAWN)
}
}