物件交互bug修复
This commit is contained in:
1 parent
9a78027a83
commit
258695308e
4 files changed
+56
-21
No files matched your search
@@ -1,6 +1,8 @@
|
||||
package net
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
@@ -11,6 +13,7 @@ import (
|
||||
"hk4e/protocol/cmd"
|
||||
"hk4e/protocol/proto"
|
||||
|
||||
"google.golang.org/protobuf/encoding/protojson"
|
||||
pb "google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
@@ -104,14 +107,18 @@ func ProtoDecode(kcpMsg *KcpMsg,
|
||||
msg.PayloadMessage = protoMessage.message
|
||||
protoMsgList = append(protoMsgList, msg)
|
||||
}
|
||||
// for _, msg := range protoMsgList {
|
||||
// cmdName := "???"
|
||||
// if msg.PayloadMessage != nil {
|
||||
// cmdName = string(msg.PayloadMessage.ProtoReflect().Descriptor().FullName())
|
||||
// }
|
||||
// logger.Debug("[RECV UNION CMD] cmdId: %v, cmdName: %v, sessionId: %v, headMsg: %v",
|
||||
// msg.CmdId, cmdName, msg.SessionId, msg.HeadMessage)
|
||||
// }
|
||||
for _, msg := range protoMsgList {
|
||||
cmdName := "???"
|
||||
if msg.PayloadMessage != nil {
|
||||
cmdName = string(msg.PayloadMessage.ProtoReflect().Descriptor().FullName())
|
||||
}
|
||||
logger.Debug("[RECV UNION CMD] cmdId: %v, cmdName: %v, sessionId: %v, headMsg: %v",
|
||||
msg.CmdId, cmdName, msg.SessionId, msg.HeadMessage)
|
||||
data, _ := protojson.Marshal(msg.PayloadMessage)
|
||||
var buf bytes.Buffer
|
||||
_ = json.Indent(&buf, data, "", "\t")
|
||||
logger.Debug("%v", buf.String())
|
||||
}
|
||||
} else {
|
||||
protoMsg.PayloadMessage = protoMessageList[0].message
|
||||
protoMsgList = append(protoMsgList, protoMsg)
|
||||
@@ -121,6 +128,10 @@ func ProtoDecode(kcpMsg *KcpMsg,
|
||||
}
|
||||
logger.Debug("[RECV] cmdId: %v, cmdName: %v, sessionId: %v, headMsg: %v",
|
||||
protoMsg.CmdId, cmdName, protoMsg.SessionId, protoMsg.HeadMessage)
|
||||
data, _ := protojson.Marshal(protoMsg.PayloadMessage)
|
||||
var buf bytes.Buffer
|
||||
_ = json.Indent(&buf, data, "", "\t")
|
||||
logger.Debug("%v", buf.String())
|
||||
}
|
||||
return protoMsgList
|
||||
}
|
||||
@@ -200,6 +211,10 @@ func ProtoEncode(protoMsg *ProtoMsg,
|
||||
}
|
||||
logger.Debug("[SEND] cmdId: %v, cmdName: %v, sessionId: %v, headMsg: %v",
|
||||
protoMsg.CmdId, cmdName, protoMsg.SessionId, protoMsg.HeadMessage)
|
||||
data, _ := protojson.Marshal(protoMsg.PayloadMessage)
|
||||
var buf bytes.Buffer
|
||||
_ = json.Indent(&buf, data, "", "\t")
|
||||
logger.Debug("%v", buf.String())
|
||||
kcpMsg = new(KcpMsg)
|
||||
kcpMsg.SessionId = protoMsg.SessionId
|
||||
kcpMsg.CmdId = protoMsg.CmdId
|
||||
|
||||
@@ -831,7 +831,9 @@ func (e *Entity) AbilityAction(ability *Ability, action *gdconf.ActionData, enti
|
||||
continue
|
||||
}
|
||||
count := math.Ceil(float64(totalEnergy) / float64(sameEnergy))
|
||||
GAME.CreateDropGadget(owner, entity.GetPos(), uint32(itemDataConfig.GadgetId), uint32(action.ConfigID), uint32(count))
|
||||
for i := 0; i < int(count); i++ {
|
||||
GAME.CreateDropGadget(owner, entity.GetPos(), uint32(itemDataConfig.GadgetId), uint32(action.ConfigID), 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1034,14 +1036,20 @@ func (g *GadgetTrifleItemEntity) CreateGadgetTrifleItemEntity(itemId, count uint
|
||||
type GadgetGatherEntity struct {
|
||||
*GadgetEntity
|
||||
itemId uint32
|
||||
count uint32
|
||||
}
|
||||
|
||||
func (g *GadgetGatherEntity) GetItemId() uint32 {
|
||||
return g.itemId
|
||||
}
|
||||
|
||||
func (g *GadgetGatherEntity) CreateGadgetGatherEntity(itemId uint32) {
|
||||
func (g *GadgetGatherEntity) GetCount() uint32 {
|
||||
return g.count
|
||||
}
|
||||
|
||||
func (g *GadgetGatherEntity) CreateGadgetGatherEntity(itemId, count uint32) {
|
||||
g.itemId = itemId
|
||||
g.count = count
|
||||
}
|
||||
|
||||
type GadgetWorktopEntity struct {
|
||||
|
||||
+19
-9
@@ -1333,9 +1333,9 @@ func (g *Game) CreateConfigEntity(scene *Scene, groupId uint32, entityConfig any
|
||||
gadgetGatherEntity := scene.CreateEntityGadgetGather(
|
||||
&model.Vector{X: float64(gadget.Pos.X), Y: float64(gadget.Pos.Y), Z: float64(gadget.Pos.Z)},
|
||||
&model.Vector{X: float64(gadget.Rot.X), Y: float64(gadget.Rot.Y), Z: float64(gadget.Rot.Z)},
|
||||
uint32(gadget.ConfigId), groupId, int(gadget.VisionLevel), uint32(gatherDataConfig.GadgetId), uint32(constant.GADGET_STATE_DEFAULT),
|
||||
uint32(gadget.ConfigId), groupId, int(gadget.VisionLevel), uint32(gatherDataConfig.GadgetId), constant.GADGET_STATE_DEFAULT,
|
||||
)
|
||||
gadgetGatherEntity.CreateGadgetGatherEntity(uint32(gatherDataConfig.ItemId))
|
||||
gadgetGatherEntity.CreateGadgetGatherEntity(uint32(gatherDataConfig.ItemId), 1)
|
||||
scene.CreateEntity(gadgetGatherEntity)
|
||||
return gadgetGatherEntity.GetId()
|
||||
case constant.GADGET_TYPE_WORKTOP:
|
||||
@@ -1484,8 +1484,9 @@ func (g *Game) CreateGadget(player *model.Player, pos *model.Vector, gadgetId ui
|
||||
|
||||
// CreateDropGadget 创建掉落物的物件实体
|
||||
func (g *Game) CreateDropGadget(player *model.Player, pos *model.Vector, gadgetId, itemId, count uint32) uint32 {
|
||||
if gadgetId == 0 {
|
||||
logger.Error("create gadget id is zero, pos: %+v, itemId: %v, count: %v, uid: %v", pos, itemId, count, player.PlayerId)
|
||||
gadgetDataConfig := gdconf.GetGadgetDataById(int32(gadgetId))
|
||||
if gadgetDataConfig == nil {
|
||||
logger.Error("get gadget data config is nil, gadgetId: %v", gadgetId)
|
||||
return 0
|
||||
}
|
||||
world := WORLD_MANAGER.GetWorldById(player.WorldId)
|
||||
@@ -1500,11 +1501,20 @@ func (g *Game) CreateDropGadget(player *model.Player, pos *model.Vector, gadgetI
|
||||
}
|
||||
rot := new(model.Vector)
|
||||
rot.Y = random.GetRandomFloat64(0.0, 360.0)
|
||||
gadgetTrifleItemEntity := scene.CreateEntityGadgetTrifleItem(pos, rot, constant.VISION_LEVEL_NORMAL, gadgetId, constant.GADGET_STATE_DEFAULT)
|
||||
gadgetTrifleItemEntity.CreateGadgetTrifleItemEntity(itemId, count)
|
||||
scene.CreateEntity(gadgetTrifleItemEntity)
|
||||
g.AddSceneEntityNotify(player, proto.VisionType_VISION_BORN, []uint32{gadgetTrifleItemEntity.GetId()}, true, false)
|
||||
return gadgetTrifleItemEntity.GetId()
|
||||
entityId := uint32(0)
|
||||
if gadgetDataConfig.Type == constant.GADGET_TYPE_GATHER_OBJECT {
|
||||
gadgetGatherEntity := scene.CreateEntityGadgetGather(pos, rot, 0, 0, constant.VISION_LEVEL_NORMAL, gadgetId, constant.GADGET_STATE_DEFAULT)
|
||||
gadgetGatherEntity.CreateGadgetGatherEntity(itemId, count)
|
||||
scene.CreateEntity(gadgetGatherEntity)
|
||||
entityId = gadgetGatherEntity.GetId()
|
||||
} else {
|
||||
gadgetTrifleItemEntity := scene.CreateEntityGadgetTrifleItem(pos, rot, constant.VISION_LEVEL_NORMAL, gadgetId, constant.GADGET_STATE_DEFAULT)
|
||||
gadgetTrifleItemEntity.CreateGadgetTrifleItemEntity(itemId, count)
|
||||
scene.CreateEntity(gadgetTrifleItemEntity)
|
||||
entityId = gadgetTrifleItemEntity.GetId()
|
||||
}
|
||||
g.AddSceneEntityNotify(player, proto.VisionType_VISION_BORN, []uint32{entityId}, true, false)
|
||||
return entityId
|
||||
}
|
||||
|
||||
// GetPosIsInWeatherArea 获取坐标是否在指定的天气区域
|
||||
|
||||
@@ -426,13 +426,15 @@ func (g *Game) GadgetInteractReq(player *model.Player, payloadMsg pb.Message) {
|
||||
// 掉落物捡起
|
||||
interactType = proto.InteractType_INTERACT_PICK_ITEM
|
||||
gadgetTrifleItemEntity := entity.(*GadgetTrifleItemEntity)
|
||||
g.AddPlayerItem(player.PlayerId, []*ChangeItem{{ItemId: gadgetTrifleItemEntity.GetItemId(), ChangeCount: 1}}, proto.ActionReasonType_ACTION_REASON_SUBFIELD_DROP)
|
||||
itemList := []*ChangeItem{{ItemId: gadgetTrifleItemEntity.GetItemId(), ChangeCount: gadgetTrifleItemEntity.GetCount()}}
|
||||
g.AddPlayerItem(player.PlayerId, itemList, proto.ActionReasonType_ACTION_REASON_SUBFIELD_DROP)
|
||||
g.KillEntity(player, scene, entity.GetId(), proto.PlayerDieType_PLAYER_DIE_NONE)
|
||||
case constant.GADGET_TYPE_GATHER_OBJECT:
|
||||
// 采集物摘取
|
||||
interactType = proto.InteractType_INTERACT_GATHER
|
||||
gadgetGatherEntity := entity.(*GadgetGatherEntity)
|
||||
g.AddPlayerItem(player.PlayerId, []*ChangeItem{{ItemId: gadgetGatherEntity.GetItemId(), ChangeCount: 1}}, proto.ActionReasonType_ACTION_REASON_GATHER)
|
||||
itemList := []*ChangeItem{{ItemId: gadgetGatherEntity.GetItemId(), ChangeCount: gadgetGatherEntity.GetCount()}}
|
||||
g.AddPlayerItem(player.PlayerId, itemList, proto.ActionReasonType_ACTION_REASON_GATHER)
|
||||
g.KillEntity(player, scene, entity.GetId(), proto.PlayerDieType_PLAYER_DIE_NONE)
|
||||
case constant.GADGET_TYPE_CHEST:
|
||||
// 宝箱开启
|
||||
|
||||
Reference in new issue
Block a user