***
This commit is contained in:
1 parent
0ae134758a
commit
1af5fb128b
37 files changed
+907
-713
No files matched your search
@@ -223,6 +223,7 @@ func (k *KcpConnManager) gameMsgHandle(
|
||||
}
|
||||
if len(session.sendChan) == SessionSendChanLen {
|
||||
logger.Error("session send chan is full, sessionId: %v", protoMsg.SessionId)
|
||||
k.forceCloseKcpConn(sessionId, kcp.EnetWaitSndMax)
|
||||
return
|
||||
}
|
||||
if protoMsg.CmdId == cmd.PlayerLoginRsp {
|
||||
@@ -380,6 +381,7 @@ func (k *KcpConnManager) forwardRobotMsgToClientHandle(session *Session) {
|
||||
case <-ticker.C:
|
||||
if session.connState == ConnClose {
|
||||
logger.Debug("robot msg forward handle stop")
|
||||
ticker.Stop()
|
||||
return
|
||||
}
|
||||
case netMsg := <-k.messageQueue.GetNetMsg():
|
||||
@@ -397,6 +399,7 @@ func (k *KcpConnManager) forwardRobotMsgToClientHandle(session *Session) {
|
||||
ok := k.keyExchange(session, rsp.Uid, rsp)
|
||||
if !ok {
|
||||
logger.Error("key exchange error, uid: %v", rsp.Uid)
|
||||
session.conn.Close()
|
||||
continue
|
||||
}
|
||||
// 关联玩家uid和连接信息
|
||||
@@ -415,6 +418,7 @@ func (k *KcpConnManager) forwardRobotMsgToClientHandle(session *Session) {
|
||||
}
|
||||
if len(session.sendChan) == SessionSendChanLen {
|
||||
logger.Error("session send chan is full, sessionId: %v", protoMsg.SessionId)
|
||||
session.conn.Close()
|
||||
continue
|
||||
}
|
||||
session.sendChan <- protoMsg
|
||||
|
||||
+1
-1
@@ -84,7 +84,7 @@ func Run(ctx context.Context, configFile string) error {
|
||||
messageQueue := mq.NewMessageQueue(api.GS, APPID, discoveryClient)
|
||||
defer messageQueue.Close()
|
||||
|
||||
gameCore := game.NewGameCore(db, messageQueue, GSID, APPID, APPVERSION, discoveryClient)
|
||||
gameCore := game.NewGameCore(discoveryClient, db, messageQueue, GSID, APPID, APPVERSION)
|
||||
defer gameCore.Close()
|
||||
|
||||
// natsrpc server
|
||||
|
||||
+116
-73
@@ -37,33 +37,37 @@ var TICK_MANAGER *TickManager = nil
|
||||
var COMMAND_MANAGER *CommandManager = nil
|
||||
var GCG_MANAGER *GCGManager = nil
|
||||
var PLUGIN_MANAGER *PluginManager = nil
|
||||
var MESSAGE_QUEUE *mq.MessageQueue
|
||||
|
||||
var ONLINE_PLAYER_NUM int32 = 0 // 当前在线玩家数
|
||||
|
||||
var SELF *model.Player
|
||||
|
||||
type Game struct {
|
||||
discovery *rpc.DiscoveryClient // node节点服务器的natsrpc客户端
|
||||
db *dao.Dao
|
||||
snowflake *alg.SnowflakeWorker
|
||||
gsId uint32
|
||||
gsAppid string
|
||||
gsAppVersion string
|
||||
ai *model.Player // 本服的Ai玩家对象
|
||||
isStop bool
|
||||
dispatchCancel bool
|
||||
discoveryClient *rpc.DiscoveryClient // node节点服务器的natsrpc客户端
|
||||
db *dao.Dao // 数据访问对象
|
||||
messageQueue *mq.MessageQueue
|
||||
gsId uint32 // 游戏服务器编号
|
||||
gsAppid string // 游戏服务器appid
|
||||
gsAppVersion string // 游戏服务器版本
|
||||
snowflake *alg.SnowflakeWorker // 雪花唯一id生成器
|
||||
isStop bool // 停服标志
|
||||
dispatchCancel bool // 取消调度标志
|
||||
endlessLoopCounter map[int]uint64 // 死循环保护计数器
|
||||
ai *model.Player // 本服的Ai玩家对象
|
||||
}
|
||||
|
||||
func NewGameCore(db *dao.Dao, messageQueue *mq.MessageQueue, gsId uint32, gsAppid string, gsAppVersion string, discovery *rpc.DiscoveryClient) (r *Game) {
|
||||
func NewGameCore(discoveryClient *rpc.DiscoveryClient, db *dao.Dao, messageQueue *mq.MessageQueue, gsId uint32, gsAppid string, gsAppVersion string) (r *Game) {
|
||||
r = new(Game)
|
||||
r.discovery = discovery
|
||||
r.discoveryClient = discoveryClient
|
||||
r.db = db
|
||||
MESSAGE_QUEUE = messageQueue
|
||||
r.snowflake = alg.NewSnowflakeWorker(int64(gsId))
|
||||
r.messageQueue = messageQueue
|
||||
r.gsId = gsId
|
||||
r.gsAppid = gsAppid
|
||||
r.gsAppVersion = gsAppVersion
|
||||
r.snowflake = alg.NewSnowflakeWorker(int64(gsId))
|
||||
r.isStop = false
|
||||
r.dispatchCancel = false
|
||||
r.endlessLoopCounter = make(map[int]uint64)
|
||||
GAME = r
|
||||
LOCAL_EVENT_MANAGER = NewLocalEventManager()
|
||||
ROUTE_MANAGER = NewRouteManager()
|
||||
@@ -83,60 +87,10 @@ func NewGameCore(db *dao.Dao, messageQueue *mq.MessageQueue, gsId uint32, gsAppi
|
||||
COMMAND_MANAGER.SetSystem(r.ai)
|
||||
// 初始化插件 最后再调用以免插件需要访问其他模块导致出错
|
||||
PLUGIN_MANAGER.InitPlugin()
|
||||
r.run()
|
||||
r.isStop = false
|
||||
r.dispatchCancel = false
|
||||
go r.gameMainLoopD()
|
||||
return r
|
||||
}
|
||||
|
||||
func (g *Game) GetGsId() uint32 {
|
||||
return g.gsId
|
||||
}
|
||||
|
||||
func (g *Game) GetGsAppid() string {
|
||||
return g.gsAppid
|
||||
}
|
||||
|
||||
// GetAi 获取本服的Ai玩家对象
|
||||
func (g *Game) GetAi() *model.Player {
|
||||
return g.ai
|
||||
}
|
||||
|
||||
func (g *Game) CreateRobot(uid uint32, name string, sign string) *model.Player {
|
||||
g.OnLogin(uid, 0, "", nil, new(proto.PlayerLoginReq), true)
|
||||
robot := USER_MANAGER.GetOnlineUser(uid)
|
||||
robot.DbState = model.DbNormal
|
||||
g.SetPlayerBornDataReq(robot, &proto.SetPlayerBornDataReq{AvatarId: 10000007, NickName: name})
|
||||
robot.Signature = sign
|
||||
world := WORLD_MANAGER.GetWorldById(robot.WorldId)
|
||||
g.EnterSceneReadyReq(robot, &proto.EnterSceneReadyReq{
|
||||
EnterSceneToken: world.GetEnterSceneToken(),
|
||||
})
|
||||
g.SceneInitFinishReq(robot, &proto.SceneInitFinishReq{
|
||||
EnterSceneToken: world.GetEnterSceneToken(),
|
||||
})
|
||||
g.EnterSceneDoneReq(robot, &proto.EnterSceneDoneReq{
|
||||
EnterSceneToken: world.GetEnterSceneToken(),
|
||||
})
|
||||
g.PostEnterSceneReq(robot, &proto.PostEnterSceneReq{
|
||||
EnterSceneToken: world.GetEnterSceneToken(),
|
||||
})
|
||||
g.EntityForceSyncReq(robot, &proto.EntityForceSyncReq{
|
||||
MotionInfo: &proto.MotionInfo{
|
||||
Pos: &proto.Vector{X: 500.0, Y: 900.0, Z: -500.0},
|
||||
Rot: new(proto.Vector),
|
||||
},
|
||||
EntityId: world.GetPlayerWorldAvatarEntityId(robot, 10000007),
|
||||
})
|
||||
robot.SetPos(&model.Vector{X: 500.0, Y: 900.0, Z: -500.0})
|
||||
robot.WuDi = true
|
||||
return robot
|
||||
}
|
||||
|
||||
func (g *Game) run() {
|
||||
go g.gameMainLoopD()
|
||||
}
|
||||
|
||||
func (g *Game) gameMainLoopD() {
|
||||
times := 1
|
||||
panicCounter := 0
|
||||
@@ -170,9 +124,8 @@ func (g *Game) gameMainLoop() {
|
||||
logger.Error("stack: %v", logger.Stack())
|
||||
if SELF != nil {
|
||||
logger.Error("the motherfucker player uid: %v", SELF.PlayerId)
|
||||
// info, _ := json.Marshal(SELF)
|
||||
// logger.Error("the motherfucker player info: %v", string(info))
|
||||
GAME.KickPlayer(SELF.PlayerId, kcp.EnetServerKick)
|
||||
g.KickPlayer(SELF.PlayerId, kcp.EnetServerKick)
|
||||
SELF = nil
|
||||
}
|
||||
}
|
||||
}()
|
||||
@@ -222,8 +175,9 @@ func (g *Game) gameMainLoop() {
|
||||
maxRouteCost = 0
|
||||
maxRouteCmdId = 0
|
||||
}
|
||||
g.endlessLoopCounter = make(map[int]uint64)
|
||||
select {
|
||||
case netMsg := <-MESSAGE_QUEUE.GetNetMsg():
|
||||
case netMsg := <-g.messageQueue.GetNetMsg():
|
||||
// 接收客户端消息
|
||||
start := time.Now().UnixNano()
|
||||
ROUTE_MANAGER.RouteHandle(netMsg)
|
||||
@@ -257,6 +211,95 @@ func (g *Game) gameMainLoop() {
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Game) GetGsId() uint32 {
|
||||
return g.gsId
|
||||
}
|
||||
|
||||
func (g *Game) GetGsAppid() string {
|
||||
return g.gsAppid
|
||||
}
|
||||
|
||||
// GetAi 获取本服的Ai玩家对象
|
||||
func (g *Game) GetAi() *model.Player {
|
||||
return g.ai
|
||||
}
|
||||
|
||||
func (g *Game) CreateRobot(uid uint32, name string, sign string) *model.Player {
|
||||
g.OnLogin(uid, 0, "", nil, new(proto.PlayerLoginReq), true)
|
||||
robot := USER_MANAGER.GetOnlineUser(uid)
|
||||
robot.DbState = model.DbNormal
|
||||
g.SetPlayerBornDataReq(robot, &proto.SetPlayerBornDataReq{AvatarId: 10000007, NickName: name})
|
||||
robot.Signature = sign
|
||||
world := WORLD_MANAGER.GetWorldById(robot.WorldId)
|
||||
g.HostEnterMpWorld(robot)
|
||||
g.EnterSceneReadyReq(robot, &proto.EnterSceneReadyReq{
|
||||
EnterSceneToken: world.GetEnterSceneToken(),
|
||||
})
|
||||
g.SceneInitFinishReq(robot, &proto.SceneInitFinishReq{
|
||||
EnterSceneToken: world.GetEnterSceneToken(),
|
||||
})
|
||||
g.EnterSceneDoneReq(robot, &proto.EnterSceneDoneReq{
|
||||
EnterSceneToken: world.GetEnterSceneToken(),
|
||||
})
|
||||
g.PostEnterSceneReq(robot, &proto.PostEnterSceneReq{
|
||||
EnterSceneToken: world.GetEnterSceneToken(),
|
||||
})
|
||||
robot.WuDi = true
|
||||
return robot
|
||||
}
|
||||
|
||||
const (
|
||||
EndlessLoopCheckTypeAcceptQuest = iota
|
||||
EndlessLoopCheckTypeStartQuest
|
||||
EndlessLoopCheckTypeExecQuest
|
||||
EndlessLoopCheckTypeTriggerQuest
|
||||
EndlessLoopCheckTypeUseItem
|
||||
EndlessLoopCheckTypeCallLuaFunc
|
||||
)
|
||||
|
||||
func (g *Game) EndlessLoopCheck(checkType int) {
|
||||
g.endlessLoopCounter[checkType]++
|
||||
checkCount := g.endlessLoopCounter[checkType]
|
||||
EndlessLoopHandleFunc := func() {
|
||||
logger.Error("!!! GAME MAIN LOOP ENDLESS LOOP !!!")
|
||||
logger.Error("checkType: %v, checkCount: %v", checkType, checkCount)
|
||||
logger.Error("stack: %v", logger.Stack())
|
||||
if SELF != nil {
|
||||
logger.Error("the motherfucker player uid: %v", SELF.PlayerId)
|
||||
g.KickPlayer(SELF.PlayerId, kcp.EnetServerKick)
|
||||
SELF = nil
|
||||
}
|
||||
panic("EndlessLoopCheck")
|
||||
}
|
||||
switch checkType {
|
||||
case EndlessLoopCheckTypeAcceptQuest:
|
||||
if checkCount > 100 {
|
||||
EndlessLoopHandleFunc()
|
||||
}
|
||||
case EndlessLoopCheckTypeStartQuest:
|
||||
if checkCount > 1000 {
|
||||
EndlessLoopHandleFunc()
|
||||
}
|
||||
case EndlessLoopCheckTypeExecQuest:
|
||||
if checkCount > 1000 {
|
||||
EndlessLoopHandleFunc()
|
||||
}
|
||||
case EndlessLoopCheckTypeTriggerQuest:
|
||||
if checkCount > 100 {
|
||||
EndlessLoopHandleFunc()
|
||||
}
|
||||
case EndlessLoopCheckTypeUseItem:
|
||||
if checkCount > 100 {
|
||||
EndlessLoopHandleFunc()
|
||||
}
|
||||
case EndlessLoopCheckTypeCallLuaFunc:
|
||||
if checkCount > 100 {
|
||||
EndlessLoopHandleFunc()
|
||||
}
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
var EXIT_SAVE_FIN_CHAN chan bool
|
||||
|
||||
func (g *Game) ServerStopNotify() {
|
||||
@@ -289,7 +332,7 @@ func (g *Game) Close() {
|
||||
userList := USER_MANAGER.GetAllOnlineUserList()
|
||||
for _, player := range userList {
|
||||
g.KickPlayer(player.PlayerId, kcp.EnetServerShutdown)
|
||||
MESSAGE_QUEUE.SendToAll(&mq.NetMsg{
|
||||
g.messageQueue.SendToAll(&mq.NetMsg{
|
||||
MsgType: mq.MsgTypeServer,
|
||||
EventId: mq.ServerUserOnlineStateChangeNotify,
|
||||
ServerMsg: &mq.ServerMsg{
|
||||
@@ -333,7 +376,7 @@ func (g *Game) SendMsgToGate(cmdId uint16, userId uint32, clientSeq uint32, gate
|
||||
ClientSeq: clientSeq,
|
||||
PayloadMessageData: payloadMessageData,
|
||||
}
|
||||
MESSAGE_QUEUE.SendToGate(gateAppId, &mq.NetMsg{
|
||||
g.messageQueue.SendToGate(gateAppId, &mq.NetMsg{
|
||||
MsgType: mq.MsgTypeGame,
|
||||
EventId: mq.NormalMsg,
|
||||
GameMsg: gameMsg,
|
||||
@@ -371,7 +414,7 @@ func (g *Game) SendMsg(cmdId uint16, userId uint32, clientSeq uint32, payloadMsg
|
||||
return
|
||||
}
|
||||
gameMsg.PayloadMessageData = payloadMessageData
|
||||
MESSAGE_QUEUE.SendToGate(player.GateAppId, &mq.NetMsg{
|
||||
g.messageQueue.SendToGate(player.GateAppId, &mq.NetMsg{
|
||||
MsgType: mq.MsgTypeGame,
|
||||
EventId: mq.NormalMsg,
|
||||
GameMsg: gameMsg,
|
||||
@@ -527,7 +570,7 @@ func (g *Game) KickPlayer(userId uint32, reason uint32) {
|
||||
if player == nil {
|
||||
return
|
||||
}
|
||||
MESSAGE_QUEUE.SendToGate(player.GateAppId, &mq.NetMsg{
|
||||
g.messageQueue.SendToGate(player.GateAppId, &mq.NetMsg{
|
||||
MsgType: mq.MsgTypeConnCtrl,
|
||||
EventId: mq.KickPlayerNotify,
|
||||
ConnCtrlMsg: &mq.ConnCtrlMsg{
|
||||
|
||||
@@ -185,7 +185,7 @@ func (c *CommandManager) GotoCommand(content *CommandContent) bool {
|
||||
return pos, true
|
||||
}
|
||||
// 传送玩家到场景以及坐标
|
||||
var sceneId = content.AssignPlayer.SceneId
|
||||
var sceneId = content.AssignPlayer.GetSceneId()
|
||||
var posX, posY, posZ float64
|
||||
|
||||
// 解析命令
|
||||
@@ -212,7 +212,7 @@ func (c *CommandManager) GotoCommand(content *CommandContent) bool {
|
||||
// 传送玩家至指定的位置
|
||||
c.gmCmd.GMTeleportPlayer(content.AssignPlayer.PlayerId, sceneId, posX, posY, posZ)
|
||||
// 发送消息给执行者
|
||||
content.SendSuccMessage(content.Executor, "已传送至指定位置,指定UID:%v,场景ID:%v,X:%.2f,Y:%.2f,Z:%.2f。", content.AssignPlayer.PlayerId, content.AssignPlayer.SceneId, posX, posY, posZ)
|
||||
content.SendSuccMessage(content.Executor, "已传送至指定位置,指定UID:%v,场景ID:%v,X:%.2f,Y:%.2f,Z:%.2f。", content.AssignPlayer.PlayerId, content.AssignPlayer.GetSceneId(), posX, posY, posZ)
|
||||
return true
|
||||
})
|
||||
}
|
||||
@@ -256,7 +256,7 @@ func (c *CommandManager) JumpCommand(content *CommandContent) bool {
|
||||
// 传送玩家至指定的位置
|
||||
c.gmCmd.GMTeleportPlayer(content.AssignPlayer.PlayerId, sceneId, posX, posY, posZ)
|
||||
// 发送消息给执行者
|
||||
content.SendSuccMessage(content.Executor, "已传送至指定场景,指定UID:%v,场景ID:%v,X:%.2f,Y:%.2f,Z:%.2f。", content.AssignPlayer.PlayerId, content.AssignPlayer.SceneId, posX, posY, posZ)
|
||||
content.SendSuccMessage(content.Executor, "已传送至指定场景,指定UID:%v,场景ID:%v,X:%.2f,Y:%.2f,Z:%.2f。", content.AssignPlayer.PlayerId, content.AssignPlayer.GetSceneId(), posX, posY, posZ)
|
||||
return true
|
||||
})
|
||||
}
|
||||
@@ -304,7 +304,7 @@ func (c *CommandManager) EquipCommand(content *CommandContent) bool {
|
||||
// 添加武器
|
||||
// 判断是否要添加全部武器
|
||||
if param1 == "all" {
|
||||
c.gmCmd.GMAddAllWeapon(content.AssignPlayer.PlayerId, 1, level, promote, 1)
|
||||
c.gmCmd.GMAddAllWeapon(content.AssignPlayer.PlayerId, 1, level, promote, 0)
|
||||
content.SendSuccMessage(content.Executor, "已给予所有武器,指定UID:%v,武器等级:%v,突破等级:%v。", content.AssignPlayer.PlayerId, level, promote)
|
||||
return true
|
||||
}
|
||||
@@ -313,7 +313,7 @@ func (c *CommandManager) EquipCommand(content *CommandContent) bool {
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
c.gmCmd.GMAddWeapon(content.AssignPlayer.PlayerId, uint32(itemId), 1, level, promote, 1)
|
||||
c.gmCmd.GMAddWeapon(content.AssignPlayer.PlayerId, uint32(itemId), 1, level, promote, 0)
|
||||
content.SendSuccMessage(content.Executor, "已给予武器,指定UID:%v,武器ID:%v,武器等级:%v,突破等级:%v。", content.AssignPlayer.PlayerId, itemId, level, promote)
|
||||
default:
|
||||
return false
|
||||
@@ -492,7 +492,7 @@ func (c *CommandManager) GiveCommand(content *CommandContent) bool {
|
||||
_, ok = GAME.GetAllWeaponDataConfig()[int32(itemId)]
|
||||
if ok {
|
||||
// 给予玩家武器
|
||||
c.gmCmd.GMAddWeapon(content.AssignPlayer.PlayerId, itemId, count, 1, 0, 1)
|
||||
c.gmCmd.GMAddWeapon(content.AssignPlayer.PlayerId, itemId, count, 1, 0, 0)
|
||||
content.SendSuccMessage(content.Executor, "已给予武器,指定UID:%v,ID:%v,数量:%v。", content.AssignPlayer.PlayerId, itemId, count)
|
||||
return true
|
||||
}
|
||||
@@ -538,7 +538,7 @@ func (c *CommandManager) GiveCommand(content *CommandContent) bool {
|
||||
content.SendSuccMessage(content.Executor, "已给予所有物品,指定UID:%v,数量:%v。", content.AssignPlayer.PlayerId, count)
|
||||
case "weapon":
|
||||
// 给予玩家所有武器
|
||||
c.gmCmd.GMAddAllWeapon(content.AssignPlayer.PlayerId, count, 1, 0, 1)
|
||||
c.gmCmd.GMAddAllWeapon(content.AssignPlayer.PlayerId, count, 1, 0, 0)
|
||||
content.SendSuccMessage(content.Executor, "已给予所有武器,指定UID:%v,数量:%v。", content.AssignPlayer.PlayerId, count)
|
||||
case "reliquary":
|
||||
// 给予玩家所有圣遗物
|
||||
@@ -795,8 +795,8 @@ func (c *CommandManager) NewPointCommandController() *CommandController {
|
||||
}
|
||||
|
||||
func (c *CommandManager) PointCommand(content *CommandContent) bool {
|
||||
var sceneId = content.AssignPlayer.SceneId // 场景id
|
||||
var param1 string // 参数1
|
||||
var sceneId = content.AssignPlayer.GetSceneId() // 场景id
|
||||
var param1 string // 参数1
|
||||
|
||||
return content.Option("uint32", func(param any) bool {
|
||||
// 场景id
|
||||
@@ -810,7 +810,7 @@ func (c *CommandManager) PointCommand(content *CommandContent) bool {
|
||||
if param1 == "all" {
|
||||
// 解锁当前场景所有锚点
|
||||
c.gmCmd.GMUnlockAllPoint(content.AssignPlayer.PlayerId, sceneId)
|
||||
content.SendSuccMessage(content.Executor, "已解锁所有锚点,指定UID:%v,场景ID:%v。", content.AssignPlayer.PlayerId, content.AssignPlayer.SceneId)
|
||||
content.SendSuccMessage(content.Executor, "已解锁所有锚点,指定UID:%v,场景ID:%v。", content.AssignPlayer.PlayerId, content.AssignPlayer.GetSceneId())
|
||||
return true
|
||||
}
|
||||
// 锚点id
|
||||
@@ -819,7 +819,7 @@ func (c *CommandManager) PointCommand(content *CommandContent) bool {
|
||||
return false
|
||||
}
|
||||
c.gmCmd.GMUnlockPoint(content.AssignPlayer.PlayerId, sceneId, uint32(pointId))
|
||||
content.SendSuccMessage(content.Executor, "已解锁锚点,指定UID:%v,场景ID:%v,锚点ID:%v。", content.AssignPlayer.PlayerId, content.AssignPlayer.SceneId, pointId)
|
||||
content.SendSuccMessage(content.Executor, "已解锁锚点,指定UID:%v,场景ID:%v,锚点ID:%v。", content.AssignPlayer.PlayerId, content.AssignPlayer.GetSceneId(), pointId)
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
||||
+21
-37
@@ -12,7 +12,6 @@ import (
|
||||
"hk4e/protocol/proto"
|
||||
|
||||
"google.golang.org/protobuf/encoding/protojson"
|
||||
pb "google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
// GM函数模块
|
||||
@@ -101,16 +100,15 @@ func (g *GMCmd) GMAddAvatar(userId, avatarId uint32, level, promote uint8) {
|
||||
return
|
||||
}
|
||||
// 获取角色
|
||||
avatar, ok := player.GetDbAvatar().AvatarMap[avatarId]
|
||||
if !ok {
|
||||
avatar := player.GetDbAvatar().GetAvatarById(avatarId)
|
||||
if avatar == nil {
|
||||
logger.Error("avatar not exist, avatarId: %v", avatarId)
|
||||
return
|
||||
}
|
||||
// 设置角色的突破等级
|
||||
avatar.Promote = promote
|
||||
// 设置角色的等级
|
||||
// 修正角色属性
|
||||
avatar.Level = level
|
||||
avatar.Exp = 0
|
||||
avatar.Promote = promote
|
||||
GAME.AddPlayerAvatarHp(player.PlayerId, avatarId, 0.0, true, proto.ChangHpReason_CHANGE_HP_ADD_GM)
|
||||
// 角色更新面板
|
||||
GAME.UpdatePlayerAvatarFightProp(player.PlayerId, avatar.AvatarId)
|
||||
// 角色属性表更新通知
|
||||
@@ -184,11 +182,11 @@ func (g *GMCmd) GMAddAll(userId uint32) {
|
||||
// 给予玩家所有物品
|
||||
g.GMAddAllItem(userId, 9999)
|
||||
// 给予玩家所有武器
|
||||
g.GMAddAllWeapon(userId, 1, 90, 5, 5)
|
||||
g.GMAddAllWeapon(userId, 1, 90, 6, 4)
|
||||
// 给予玩家所有圣遗物
|
||||
g.GMAddAllReliquary(userId, 5)
|
||||
// 给予玩家所有角色
|
||||
g.GMAddAllAvatar(userId, 90, 5)
|
||||
g.GMAddAllAvatar(userId, 90, 6)
|
||||
// 给予玩家所有时装
|
||||
g.GMAddAllCostume(userId)
|
||||
// 给予玩家所有风之翼
|
||||
@@ -224,9 +222,9 @@ func (g *GMCmd) GMKillMonster(userId uint32, entityId uint32) {
|
||||
logger.Error("world is nil, worldId: %v, uid: %v", player.WorldId, player.PlayerId)
|
||||
return
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
scene := world.GetSceneById(player.GetSceneId())
|
||||
if scene == nil {
|
||||
logger.Error("scene is nil, sceneId: %v, uid: %v", player.SceneId, player.PlayerId)
|
||||
logger.Error("scene is nil, sceneId: %v, uid: %v", player.GetSceneId(), player.PlayerId)
|
||||
return
|
||||
}
|
||||
// 获取实体
|
||||
@@ -255,9 +253,9 @@ func (g *GMCmd) GMKillAllMonster(userId uint32) {
|
||||
logger.Error("world is nil, worldId: %v, uid: %v", player.WorldId, player.PlayerId)
|
||||
return
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
scene := world.GetSceneById(player.GetSceneId())
|
||||
if scene == nil {
|
||||
logger.Error("scene is nil, sceneId: %v, uid: %v", player.SceneId, player.PlayerId)
|
||||
logger.Error("scene is nil, sceneId: %v, uid: %v", player.GetSceneId(), player.PlayerId)
|
||||
return
|
||||
}
|
||||
// 杀死所有怪物实体
|
||||
@@ -386,9 +384,9 @@ func (g *GMCmd) GMCreateMonster(userId uint32, monsterId uint32, posX, posY, pos
|
||||
logger.Error("world is nil, worldId: %v, uid: %v", player.WorldId, player.PlayerId)
|
||||
return
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
scene := world.GetSceneById(player.GetSceneId())
|
||||
if scene == nil {
|
||||
logger.Error("scene is nil, sceneId: %v, uid: %v", player.SceneId, player.PlayerId)
|
||||
logger.Error("scene is nil, sceneId: %v, uid: %v", player.GetSceneId(), player.PlayerId)
|
||||
return
|
||||
}
|
||||
if count > 100 {
|
||||
@@ -654,8 +652,8 @@ func (g *GMCmd) CreateRobotInAiWorld(uid uint32, name string, avatarId uint32, p
|
||||
dbAvatar := robot.GetDbAvatar()
|
||||
GAME.SetUpAvatarTeamReq(robot, &proto.SetUpAvatarTeamReq{
|
||||
TeamId: 1,
|
||||
AvatarTeamGuidList: []uint64{dbAvatar.AvatarMap[avatarId].Guid},
|
||||
CurAvatarGuid: dbAvatar.AvatarMap[avatarId].Guid,
|
||||
AvatarTeamGuidList: []uint64{dbAvatar.GetAvatarById(avatarId).Guid},
|
||||
CurAvatarGuid: dbAvatar.GetAvatarById(avatarId).Guid,
|
||||
})
|
||||
GAME.SetPlayerHeadImageReq(robot, &proto.SetPlayerHeadImageReq{
|
||||
AvatarId: avatarId,
|
||||
@@ -675,28 +673,14 @@ func (g *GMCmd) CreateRobotInAiWorld(uid uint32, name string, avatarId uint32, p
|
||||
GAME.PostEnterSceneReq(robot, &proto.PostEnterSceneReq{
|
||||
EnterSceneToken: aiWorld.GetEnterSceneToken(),
|
||||
})
|
||||
entityMoveInfo := &proto.EntityMoveInfo{
|
||||
EntityId: aiWorld.GetPlayerActiveAvatarEntity(robot).GetId(),
|
||||
GAME.EntityForceSyncReq(robot, &proto.EntityForceSyncReq{
|
||||
MotionInfo: &proto.MotionInfo{
|
||||
Pos: &proto.Vector{X: float32(posX), Y: float32(posY), Z: float32(posZ)},
|
||||
Rot: &proto.Vector{X: float32(0.0), Y: float32(0.0), Z: float32(0.0)},
|
||||
State: proto.MotionState_MOTION_STANDBY,
|
||||
Pos: &proto.Vector{X: float32(posX), Y: float32(posY), Z: float32(posZ)},
|
||||
Rot: new(proto.Vector),
|
||||
},
|
||||
SceneTime: 0,
|
||||
ReliableSeq: 0,
|
||||
}
|
||||
combatData, err := pb.Marshal(entityMoveInfo)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
GAME.CombatInvocationsNotify(robot, &proto.CombatInvocationsNotify{
|
||||
InvokeList: []*proto.CombatInvokeEntry{{
|
||||
CombatData: combatData,
|
||||
ForwardType: proto.ForwardType_FORWARD_TO_ALL_EXCEPT_CUR,
|
||||
ArgumentType: proto.CombatTypeArgument_ENTITY_MOVE,
|
||||
}},
|
||||
EntityId: aiWorld.GetPlayerActiveAvatarEntity(robot).GetId(),
|
||||
})
|
||||
GAME.UnionCmdNotify(robot, &proto.UnionCmdNotify{})
|
||||
robot.SetPos(&model.Vector{X: posX, Y: posY, Z: posZ})
|
||||
}
|
||||
|
||||
func (g *GMCmd) ServerAnnounce(announceId uint32, announceMsg string, isRevoke bool) {
|
||||
@@ -766,7 +750,7 @@ func (g *GMCmd) AiWorldAoiDebug(v bool) {
|
||||
if aiWorld == nil {
|
||||
return
|
||||
}
|
||||
scene := aiWorld.GetSceneById(aiWorld.GetOwner().SceneId)
|
||||
scene := aiWorld.GetSceneById(aiWorld.GetOwner().GetSceneId())
|
||||
aiWorldAoi := aiWorld.GetAiWorldAoi()
|
||||
gridMap := aiWorldAoi.Debug()
|
||||
logger.Debug("total grid num: %v", len(gridMap))
|
||||
|
||||
@@ -487,10 +487,11 @@ func (c *CommandManager) CallGMCmd(funcName string, paramList []string) (bool, s
|
||||
func (c *CommandManager) HandleCommand(command *CommandMessage) {
|
||||
switch command.GMType {
|
||||
case PlayerChatGM, DevClientGM:
|
||||
logger.Info("run gm cmd, text: %v, uid: %v", command.Text, command.Executor.PlayerId)
|
||||
// 执行命令
|
||||
c.ExecCommand(command)
|
||||
case SystemFuncGM:
|
||||
logger.Info("run gm cmd, FuncName: %v, ParamList: %v", command.FuncName, command.ParamList)
|
||||
logger.Info("run gm func, funcName: %v, paramList: %v", command.FuncName, command.ParamList)
|
||||
// 反射调用game_command_gm.go中的函数并反射解析传入参数类型
|
||||
ok, ret := c.CallGMCmd(command.FuncName, command.ParamList)
|
||||
if command.ResultChan != nil {
|
||||
|
||||
@@ -30,21 +30,16 @@ type PluginEventId uint16
|
||||
|
||||
const (
|
||||
PluginEventIdNone = PluginEventId(iota)
|
||||
PluginEventIdPlayerKillAvatar
|
||||
PluginEventIdMarkMap
|
||||
PluginEventIdAvatarDieAnimationEnd
|
||||
PluginEventIdGadgetInteract
|
||||
PluginEventIdPostEnterScene
|
||||
PluginEventIdEvtDoSkillSucc
|
||||
PluginEventIdEvtBeingHit
|
||||
PluginEventIdEvtCreateGadget
|
||||
PluginEventIdEvtBulletHit
|
||||
)
|
||||
|
||||
// PluginEventKillAvatar 角色被杀死
|
||||
type PluginEventKillAvatar struct {
|
||||
*PluginEvent
|
||||
Player *model.Player // 玩家
|
||||
AvatarId uint32 // 角色id
|
||||
DieType proto.PlayerDieType // 死亡类型
|
||||
}
|
||||
|
||||
// PluginEventMarkMap 地图标点
|
||||
type PluginEventMarkMap struct {
|
||||
*PluginEvent
|
||||
@@ -73,6 +68,34 @@ type PluginEventPostEnterScene struct {
|
||||
Req *proto.PostEnterSceneReq // 请求
|
||||
}
|
||||
|
||||
// PluginEventEvtDoSkillSucc 使用技能
|
||||
type PluginEventEvtDoSkillSucc struct {
|
||||
*PluginEvent
|
||||
Player *model.Player // 玩家
|
||||
Ntf *proto.EvtDoSkillSuccNotify // 请求
|
||||
}
|
||||
|
||||
// PluginEventEvtBeingHit 实体受击
|
||||
type PluginEventEvtBeingHit struct {
|
||||
*PluginEvent
|
||||
Player *model.Player // 玩家
|
||||
HitInfo *proto.EvtBeingHitInfo // 请求
|
||||
}
|
||||
|
||||
// PluginEventEvtCreateGadget 创建物件实体
|
||||
type PluginEventEvtCreateGadget struct {
|
||||
*PluginEvent
|
||||
Player *model.Player // 玩家
|
||||
Ntf *proto.EvtCreateGadgetNotify // 请求
|
||||
}
|
||||
|
||||
// PluginEventEvtBulletHit 子弹命中
|
||||
type PluginEventEvtBulletHit struct {
|
||||
*PluginEvent
|
||||
Player *model.Player // 玩家
|
||||
Ntf *proto.EvtBulletHitNotify // 请求
|
||||
}
|
||||
|
||||
type PluginEventFunc func(event IPluginEvent)
|
||||
|
||||
// IPluginEvent 插件事件接口
|
||||
|
||||
+182
-17
@@ -80,11 +80,14 @@ func NewPluginPubg() *PluginPubg {
|
||||
// OnEnable 插件启用生命周期
|
||||
func (p *PluginPubg) OnEnable() {
|
||||
// 监听事件
|
||||
p.ListenEvent(PluginEventIdPlayerKillAvatar, PluginEventPriorityNormal, p.EventKillAvatar)
|
||||
p.ListenEvent(PluginEventIdMarkMap, PluginEventPriorityNormal, p.EventMarkMap)
|
||||
p.ListenEvent(PluginEventIdAvatarDieAnimationEnd, PluginEventPriorityNormal, p.EventAvatarDieAnimationEnd)
|
||||
p.ListenEvent(PluginEventIdGadgetInteract, PluginEventPriorityNormal, p.EventGadgetInteract)
|
||||
p.ListenEvent(PluginEventIdPostEnterScene, PluginEventPriorityNormal, p.EventPostEnterScene)
|
||||
p.ListenEvent(PluginEventIdEvtDoSkillSucc, PluginEventPriorityNormal, p.EventEvtDoSkillSucc)
|
||||
p.ListenEvent(PluginEventIdEvtBeingHit, PluginEventPriorityNormal, p.EventEvtBeingHit)
|
||||
p.ListenEvent(PluginEventIdEvtCreateGadget, PluginEventPriorityNormal, p.EvtCreateGadget)
|
||||
p.ListenEvent(PluginEventIdEvtBulletHit, PluginEventPriorityNormal, p.EvtBulletHit)
|
||||
// 添加全局定时器
|
||||
p.AddGlobalTick(PluginGlobalTickSecond, p.GlobalTickPubg)
|
||||
p.AddGlobalTick(PluginGlobalTickMinuteChange, p.GlobalTickMinuteChange)
|
||||
@@ -94,17 +97,6 @@ func (p *PluginPubg) OnEnable() {
|
||||
|
||||
/************************************************** 事件监听 **************************************************/
|
||||
|
||||
// EventKillAvatar 角色被杀死事件
|
||||
func (p *PluginPubg) EventKillAvatar(iEvent IPluginEvent) {
|
||||
event := iEvent.(*PluginEventKillAvatar)
|
||||
player := event.Player
|
||||
// 确保游戏开启
|
||||
if !p.IsStartPubg() || p.world.GetId() != player.WorldId {
|
||||
return
|
||||
}
|
||||
p.CreateUserTimer(player.PlayerId, 10, p.UserTimerPubgDieExit, p.world.GetId())
|
||||
}
|
||||
|
||||
// EventMarkMap 地图标点事件
|
||||
func (p *PluginPubg) EventMarkMap(iEvent IPluginEvent) {
|
||||
event := iEvent.(*PluginEventMarkMap)
|
||||
@@ -132,6 +124,7 @@ func (p *PluginPubg) EventAvatarDieAnimationEnd(iEvent IPluginEvent) {
|
||||
event.Cancel()
|
||||
}
|
||||
|
||||
// EventGadgetInteract gadget交互事件
|
||||
func (p *PluginPubg) EventGadgetInteract(iEvent IPluginEvent) {
|
||||
event := iEvent.(*PluginEventGadgetInteract)
|
||||
player := event.Player
|
||||
@@ -144,7 +137,7 @@ func (p *PluginPubg) EventGadgetInteract(iEvent IPluginEvent) {
|
||||
if exist {
|
||||
dbAvatar := player.GetDbAvatar()
|
||||
avatarId := p.world.GetPlayerActiveAvatarId(player)
|
||||
avatar := dbAvatar.AvatarMap[avatarId]
|
||||
avatar := dbAvatar.GetAvatarById(avatarId)
|
||||
pubgWorldGadgetDataConfig := gdconf.GetPubgWorldGadgetDataById(worldGadgetId)
|
||||
switch pubgWorldGadgetDataConfig.Type {
|
||||
case gdconf.PubgWorldGadgetTypeIncAtk:
|
||||
@@ -166,7 +159,7 @@ func (p *PluginPubg) EventGadgetInteract(iEvent IPluginEvent) {
|
||||
logger.Error("get world is nil, worldId: %v, uid: %v", player.WorldId, player.PlayerId)
|
||||
return
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
scene := world.GetSceneById(player.GetSceneId())
|
||||
GAME.KillEntity(player, scene, req.GadgetEntityId, proto.PlayerDieType_PLAYER_DIE_NONE)
|
||||
rsp := &proto.GadgetInteractRsp{
|
||||
GadgetEntityId: req.GadgetEntityId,
|
||||
@@ -178,6 +171,7 @@ func (p *PluginPubg) EventGadgetInteract(iEvent IPluginEvent) {
|
||||
event.Cancel()
|
||||
}
|
||||
|
||||
// EventPostEnterScene 进入场景后事件
|
||||
func (p *PluginPubg) EventPostEnterScene(iEvent IPluginEvent) {
|
||||
event := iEvent.(*PluginEventPostEnterScene)
|
||||
player := event.Player
|
||||
@@ -205,6 +199,164 @@ func (p *PluginPubg) EventPostEnterScene(iEvent IPluginEvent) {
|
||||
})
|
||||
}
|
||||
|
||||
// EventEvtDoSkillSucc 使用技能事件
|
||||
func (p *PluginPubg) EventEvtDoSkillSucc(iEvent IPluginEvent) {
|
||||
event := iEvent.(*PluginEventEvtDoSkillSucc)
|
||||
player := event.Player
|
||||
// 确保游戏开启
|
||||
if !p.IsStartPubg() || p.world.GetId() != player.WorldId {
|
||||
return
|
||||
}
|
||||
world := WORLD_MANAGER.GetWorldById(player.WorldId)
|
||||
if world == nil {
|
||||
logger.Error("get world is nil, worldId: %v, uid: %v", player.WorldId, player.PlayerId)
|
||||
return
|
||||
}
|
||||
ntf := event.Ntf
|
||||
worldAvatar := world.GetWorldAvatarByEntityId(ntf.CasterId)
|
||||
if worldAvatar == nil {
|
||||
return
|
||||
}
|
||||
avatarDataConfig := gdconf.GetAvatarDataById(int32(worldAvatar.GetAvatarId()))
|
||||
if avatarDataConfig == nil {
|
||||
return
|
||||
}
|
||||
logger.Debug("avatar normal attack, avatarId: %v, weaponType: %v, uid: %v", avatarDataConfig.AvatarId, avatarDataConfig.WeaponType, player.PlayerId)
|
||||
switch avatarDataConfig.WeaponType {
|
||||
case constant.WEAPON_TYPE_SWORD_ONE_HAND, constant.WEAPON_TYPE_CLAYMORE, constant.WEAPON_TYPE_POLE, constant.WEAPON_TYPE_CATALYST:
|
||||
scene := world.GetSceneById(player.GetSceneId())
|
||||
avatarEntity := scene.GetEntity(worldAvatar.GetAvatarEntityId())
|
||||
for _, entity := range scene.GetAllEntity() {
|
||||
if entity.GetId() == avatarEntity.GetId() || entity.GetEntityType() != constant.ENTITY_TYPE_AVATAR {
|
||||
continue
|
||||
}
|
||||
distance3D := math.Sqrt(
|
||||
(avatarEntity.GetPos().X-entity.GetPos().X)*(avatarEntity.GetPos().X-entity.GetPos().X) +
|
||||
(avatarEntity.GetPos().Y-entity.GetPos().Y)*(avatarEntity.GetPos().Y-entity.GetPos().Y) +
|
||||
(avatarEntity.GetPos().Z-entity.GetPos().Z)*(avatarEntity.GetPos().Z-entity.GetPos().Z),
|
||||
)
|
||||
if distance3D > PUBG_NORMAL_ATTACK_DISTANCE {
|
||||
continue
|
||||
}
|
||||
p.PubgHit(scene, entity.GetId(), avatarEntity.GetId(), false)
|
||||
}
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
// EventEvtBeingHit 实体受击事件
|
||||
func (p *PluginPubg) EventEvtBeingHit(iEvent IPluginEvent) {
|
||||
event := iEvent.(*PluginEventEvtBeingHit)
|
||||
player := event.Player
|
||||
// 确保游戏开启
|
||||
if !p.IsStartPubg() || p.world.GetId() != player.WorldId {
|
||||
return
|
||||
}
|
||||
world := WORLD_MANAGER.GetWorldById(player.WorldId)
|
||||
if world == nil {
|
||||
logger.Error("get world is nil, worldId: %v, uid: %v", player.WorldId, player.PlayerId)
|
||||
return
|
||||
}
|
||||
scene := world.GetSceneById(player.GetSceneId())
|
||||
hitInfo := event.HitInfo
|
||||
attackResult := hitInfo.AttackResult
|
||||
if attackResult == nil {
|
||||
return
|
||||
}
|
||||
defEntity := scene.GetEntity(attackResult.DefenseId)
|
||||
if defEntity == nil {
|
||||
return
|
||||
}
|
||||
if defEntity.GetEntityType() != constant.ENTITY_TYPE_AVATAR {
|
||||
return
|
||||
}
|
||||
fightProp := defEntity.GetFightProp()
|
||||
currHp := fightProp[constant.FIGHT_PROP_CUR_HP]
|
||||
if currHp-attackResult.Damage > 0.0 {
|
||||
return
|
||||
}
|
||||
defPlayer := USER_MANAGER.GetOnlineUser(defEntity.GetAvatarEntity().GetUid())
|
||||
if defPlayer == nil {
|
||||
return
|
||||
}
|
||||
atkEntity := scene.GetEntity(attackResult.AttackerId)
|
||||
if atkEntity != nil && atkEntity.GetEntityType() == constant.ENTITY_TYPE_AVATAR {
|
||||
atkPlayer := USER_MANAGER.GetOnlineUser(atkEntity.GetAvatarEntity().GetUid())
|
||||
if atkPlayer == nil {
|
||||
return
|
||||
}
|
||||
info := fmt.Sprintf("『%v』击败了『%v』。", atkPlayer.NickName, defPlayer.NickName)
|
||||
GAME.PlayerChatReq(world.GetOwner(), &proto.PlayerChatReq{ChatInfo: &proto.ChatInfo{Content: &proto.ChatInfo_Text{Text: info}}})
|
||||
p.CreateUserTimer(defPlayer.PlayerId, 10, p.UserTimerPubgDieExit, p.world.GetId())
|
||||
}
|
||||
}
|
||||
|
||||
// EvtCreateGadget 创建物件实体事件
|
||||
func (p *PluginPubg) EvtCreateGadget(iEvent IPluginEvent) {
|
||||
event := iEvent.(*PluginEventEvtCreateGadget)
|
||||
player := event.Player
|
||||
// 确保游戏开启
|
||||
if !p.IsStartPubg() || p.world.GetId() != player.WorldId {
|
||||
return
|
||||
}
|
||||
world := WORLD_MANAGER.GetWorldById(player.WorldId)
|
||||
if world == nil {
|
||||
logger.Error("get world is nil, worldId: %v, uid: %v", player.WorldId, player.PlayerId)
|
||||
return
|
||||
}
|
||||
ntf := event.Ntf
|
||||
gadgetDataConfig := gdconf.GetGadgetDataById(int32(ntf.ConfigId))
|
||||
if gadgetDataConfig == nil {
|
||||
logger.Error("gadget data config is nil, gadgetId: %v", ntf.ConfigId)
|
||||
return
|
||||
}
|
||||
// 蓄力箭
|
||||
if gadgetDataConfig.PrefabPath != "ART/Others/Bullet/Bullet_ArrowAiming" &&
|
||||
gadgetDataConfig.PrefabPath != "ART/Others/Bullet/Bullet_Venti_ArrowAiming" {
|
||||
return
|
||||
}
|
||||
pitchAngleRaw := ntf.InitEulerAngles.X
|
||||
pitchAngle := float32(0.0)
|
||||
if pitchAngleRaw < 90.0 {
|
||||
pitchAngle = -pitchAngleRaw
|
||||
} else if pitchAngleRaw > 270.0 {
|
||||
pitchAngle = 360.0 - pitchAngleRaw
|
||||
} else {
|
||||
logger.Error("invalid raw pitch angle: %v, uid: %v", pitchAngleRaw, player.PlayerId)
|
||||
return
|
||||
}
|
||||
yawAngle := ntf.InitEulerAngles.Y
|
||||
bulletPhysicsEngine := world.GetBulletPhysicsEngine()
|
||||
bulletPhysicsEngine.CreateRigidBody(
|
||||
ntf.EntityId,
|
||||
world.GetPlayerActiveAvatarEntity(player).GetId(),
|
||||
player.GetSceneId(),
|
||||
ntf.InitPos.X, ntf.InitPos.Y, ntf.InitPos.Z,
|
||||
pitchAngle, yawAngle,
|
||||
)
|
||||
}
|
||||
|
||||
// EvtBulletHit 子弹命中事件
|
||||
func (p *PluginPubg) EvtBulletHit(iEvent IPluginEvent) {
|
||||
event := iEvent.(*PluginEventEvtBulletHit)
|
||||
player := event.Player
|
||||
// 确保游戏开启
|
||||
if !p.IsStartPubg() || p.world.GetId() != player.WorldId {
|
||||
return
|
||||
}
|
||||
world := WORLD_MANAGER.GetWorldById(player.WorldId)
|
||||
if world == nil {
|
||||
logger.Error("get world is nil, worldId: %v, uid: %v", player.WorldId, player.PlayerId)
|
||||
return
|
||||
}
|
||||
ntf := event.Ntf
|
||||
bulletPhysicsEngine := world.GetBulletPhysicsEngine()
|
||||
if bulletPhysicsEngine.IsRigidBody(ntf.EntityId) {
|
||||
bulletPhysicsEngine.DestroyRigidBody(ntf.EntityId)
|
||||
_ = ntf.HitPoint
|
||||
}
|
||||
}
|
||||
|
||||
/************************************************** 全局定时器 **************************************************/
|
||||
|
||||
// GlobalTickPubg pubg游戏定时器
|
||||
@@ -218,7 +370,7 @@ func (p *PluginPubg) GlobalTickPubg() {
|
||||
return
|
||||
}
|
||||
p.UpdateArea()
|
||||
scene := world.GetSceneById(world.GetOwner().SceneId)
|
||||
scene := world.GetSceneById(world.GetOwner().GetSceneId())
|
||||
for _, scenePlayer := range scene.GetAllPlayer() {
|
||||
pos := GAME.GetPlayerPos(scenePlayer)
|
||||
if !p.IsInBlueArea(pos) {
|
||||
@@ -263,6 +415,19 @@ func (p *PluginPubg) UserTimerPubgEnd(player *model.Player, data []any) {
|
||||
GAME.WorldRemovePlayer(oldWorld, player)
|
||||
newWorld := WORLD_MANAGER.CreateWorld(player)
|
||||
GAME.WorldAddPlayer(newWorld, player)
|
||||
GAME.HostEnterMpWorld(player)
|
||||
GAME.EnterSceneReadyReq(player, &proto.EnterSceneReadyReq{
|
||||
EnterSceneToken: newWorld.GetEnterSceneToken(),
|
||||
})
|
||||
GAME.SceneInitFinishReq(player, &proto.SceneInitFinishReq{
|
||||
EnterSceneToken: newWorld.GetEnterSceneToken(),
|
||||
})
|
||||
GAME.EnterSceneDoneReq(player, &proto.EnterSceneDoneReq{
|
||||
EnterSceneToken: newWorld.GetEnterSceneToken(),
|
||||
})
|
||||
GAME.PostEnterSceneReq(player, &proto.PostEnterSceneReq{
|
||||
EnterSceneToken: newWorld.GetEnterSceneToken(),
|
||||
})
|
||||
WORLD_MANAGER.InitAiWorld(player)
|
||||
roomNumber := GAME.GetGsId() - 1
|
||||
startMinute := roomNumber % 6 * 10
|
||||
@@ -362,7 +527,7 @@ func (p *PluginPubg) StartPubg() {
|
||||
for _, player := range world.GetAllPlayer() {
|
||||
dbAvatar := player.GetDbAvatar()
|
||||
avatarId := p.world.GetPlayerActiveAvatarId(player)
|
||||
avatar := dbAvatar.AvatarMap[avatarId]
|
||||
avatar := dbAvatar.GetAvatarById(avatarId)
|
||||
for k := range avatar.FightPropMap {
|
||||
avatar.FightPropMap[k] = 0.0
|
||||
}
|
||||
@@ -514,7 +679,7 @@ func (p *PluginPubg) SyncMapMarkArea() {
|
||||
|
||||
// GetAlivePlayerList 获取存活玩家列表
|
||||
func (p *PluginPubg) GetAlivePlayerList() []*model.Player {
|
||||
scene := p.world.GetSceneById(p.world.GetOwner().SceneId)
|
||||
scene := p.world.GetSceneById(p.world.GetOwner().GetSceneId())
|
||||
alivePlayerList := make([]*model.Player, 0)
|
||||
for _, scenePlayer := range scene.GetAllPlayer() {
|
||||
if scenePlayer.PlayerId == p.world.GetOwner().PlayerId {
|
||||
|
||||
@@ -138,7 +138,7 @@ func (t *TickManager) userTimerHandle(userId uint32, action int, data []any) {
|
||||
logger.Error("get world is nil, worldId: %v, uid: %v", player.WorldId, userId)
|
||||
return
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
scene := world.GetSceneById(player.GetSceneId())
|
||||
group := scene.GetGroupById(groupId)
|
||||
if group == nil {
|
||||
logger.Error("get group is nil, groupId: %v, uid: %v", groupId, userId)
|
||||
|
||||
@@ -168,7 +168,7 @@ func (u *UserManager) OnlineUser(player *model.Player) {
|
||||
player.Online = true
|
||||
player.OnlineTime = uint32(time.Now().Unix())
|
||||
USER_MANAGER.AddUser(player)
|
||||
MESSAGE_QUEUE.SendToAll(&mq.NetMsg{
|
||||
GAME.messageQueue.SendToAll(&mq.NetMsg{
|
||||
MsgType: mq.MsgTypeServer,
|
||||
EventId: mq.ServerUserOnlineStateChangeNotify,
|
||||
ServerMsg: &mq.ServerMsg{
|
||||
@@ -241,7 +241,7 @@ func (u *UserManager) UserOfflineSave(player *model.Player, changeGsInfo *Change
|
||||
// OfflineUser 玩家离线
|
||||
func (u *UserManager) OfflineUser(player *model.Player, changeGsInfo *ChangeGsInfo) {
|
||||
USER_MANAGER.DeleteUser(player.PlayerId)
|
||||
MESSAGE_QUEUE.SendToAll(&mq.NetMsg{
|
||||
GAME.messageQueue.SendToAll(&mq.NetMsg{
|
||||
MsgType: mq.MsgTypeServer,
|
||||
EventId: mq.ServerUserOnlineStateChangeNotify,
|
||||
ServerMsg: &mq.ServerMsg{
|
||||
@@ -252,7 +252,7 @@ func (u *UserManager) OfflineUser(player *model.Player, changeGsInfo *ChangeGsIn
|
||||
atomic.AddInt32(&ONLINE_PLAYER_NUM, -1)
|
||||
if changeGsInfo.IsChangeGs {
|
||||
gsAppId := USER_MANAGER.GetRemoteUserGsAppId(changeGsInfo.JoinHostUserId)
|
||||
MESSAGE_QUEUE.SendToGate(player.GateAppId, &mq.NetMsg{
|
||||
GAME.messageQueue.SendToGate(player.GateAppId, &mq.NetMsg{
|
||||
MsgType: mq.MsgTypeServer,
|
||||
EventId: mq.ServerUserGsChangeNotify,
|
||||
ServerMsg: &mq.ServerMsg{
|
||||
@@ -311,7 +311,7 @@ func (u *UserManager) autoSyncRemotePlayerMap() {
|
||||
}
|
||||
|
||||
func (u *UserManager) syncRemotePlayerMap() {
|
||||
rsp, err := GAME.discovery.GetGlobalGsOnlineMap(context.TODO(), nil)
|
||||
rsp, err := GAME.discoveryClient.GetGlobalGsOnlineMap(context.TODO(), nil)
|
||||
if err != nil {
|
||||
logger.Error("get global gs online map error: %v", err)
|
||||
return
|
||||
|
||||
@@ -75,6 +75,7 @@ func (w *WorldManager) CreateWorld(owner *model.Player) *World {
|
||||
aoiManager.Init3DRectAoiManager(120, 12, 120, true)
|
||||
world.aiWorldAoi = aoiManager
|
||||
logger.Info("ai world aoi init finish")
|
||||
world.NewPhysicsEngine()
|
||||
}
|
||||
|
||||
return world
|
||||
@@ -100,8 +101,6 @@ func (w *WorldManager) GetAiWorld() *World {
|
||||
// InitAiWorld 初始化Ai世界
|
||||
func (w *WorldManager) InitAiWorld(owner *model.Player) {
|
||||
w.aiWorld = w.GetWorldById(owner.WorldId)
|
||||
w.aiWorld.ChangeToMultiplayer()
|
||||
w.aiWorld.NewPhysicsEngine()
|
||||
}
|
||||
|
||||
func (w *WorldManager) IsAiWorld(world *World) bool {
|
||||
@@ -379,7 +378,7 @@ func (w *World) AddPlayer(player *model.Player) {
|
||||
w.UpdateMultiplayerTeam()
|
||||
}
|
||||
|
||||
scene := w.GetSceneById(player.SceneId)
|
||||
scene := w.GetSceneById(player.GetSceneId())
|
||||
scene.AddPlayer(player)
|
||||
w.InitPlayerTeamEntityId(player)
|
||||
}
|
||||
@@ -387,7 +386,7 @@ func (w *World) AddPlayer(player *model.Player) {
|
||||
func (w *World) RemovePlayer(player *model.Player) {
|
||||
peerId := w.GetPlayerPeerId(player)
|
||||
w.peerList = append(w.peerList[:peerId-1], w.peerList[peerId:]...)
|
||||
scene := w.sceneMap[player.SceneId]
|
||||
scene := w.sceneMap[player.GetSceneId()]
|
||||
scene.RemovePlayer(player)
|
||||
w.RemoveAllEnterSceneContextByUid(player.PlayerId)
|
||||
delete(w.playerMap, player.PlayerId)
|
||||
@@ -507,7 +506,7 @@ func (w *World) GetWorldAvatarByEntityId(avatarEntityId uint32) *WorldAvatar {
|
||||
|
||||
// UpdatePlayerWorldAvatar 更新某玩家在世界队伍中的所有角色
|
||||
func (w *World) UpdatePlayerWorldAvatar(player *model.Player) {
|
||||
scene := w.GetSceneById(player.SceneId)
|
||||
scene := w.GetSceneById(player.GetSceneId())
|
||||
for _, worldAvatar := range w.GetPlayerWorldAvatarList(player) {
|
||||
if worldAvatar.avatarEntityId != 0 {
|
||||
continue
|
||||
@@ -581,7 +580,7 @@ func (w *World) GetPlayerAvatarIndexByAvatarId(player *model.Player, avatarId ui
|
||||
func (w *World) GetPlayerActiveAvatarEntity(player *model.Player) *Entity {
|
||||
activeAvatarId := w.GetPlayerActiveAvatarId(player)
|
||||
avatarEntityId := w.GetPlayerWorldAvatarEntityId(player, activeAvatarId)
|
||||
scene := w.GetSceneById(player.SceneId)
|
||||
scene := w.GetSceneById(player.GetSceneId())
|
||||
entity := scene.GetEntity(avatarEntityId)
|
||||
return entity
|
||||
}
|
||||
@@ -666,7 +665,7 @@ func (w *World) SetPlayerLocalTeam(player *model.Player, avatarIdList []uint32)
|
||||
modifierMap: make(map[uint32]*proto.AbilityAppliedModifier),
|
||||
}
|
||||
}
|
||||
scene := w.GetSceneById(player.SceneId)
|
||||
scene := w.GetSceneById(player.GetSceneId())
|
||||
for _, worldAvatar := range oldLocalTeam {
|
||||
exist := false
|
||||
for _, avatarId := range avatarIdList {
|
||||
@@ -818,6 +817,7 @@ func (w *World) GetChatList() []*proto.ChatInfo {
|
||||
func (w *World) ChangeToMultiplayer() {
|
||||
WORLD_MANAGER.multiplayerWorldNum++
|
||||
w.multiplayer = true
|
||||
w.owner.IsInMp = true
|
||||
}
|
||||
|
||||
// IsPlayerFirstEnter 获取玩家是否首次加入本世界
|
||||
|
||||
@@ -93,9 +93,9 @@ func (s *Scene) RemovePlayer(player *model.Player) {
|
||||
func (s *Scene) CreateEntityAvatar(player *model.Player, avatarId uint32) uint32 {
|
||||
entityId := s.world.GetNextWorldEntityId(constant.ENTITY_TYPE_AVATAR)
|
||||
dbAvatar := player.GetDbAvatar()
|
||||
avatar, ok := dbAvatar.AvatarMap[avatarId]
|
||||
if !ok {
|
||||
logger.Error("avatar error, avatarId: %v", avatar)
|
||||
avatar := dbAvatar.GetAvatarById(avatarId)
|
||||
if avatar == nil {
|
||||
logger.Error("get avatar is nil, avatarId: %v", avatar)
|
||||
return 0
|
||||
}
|
||||
entity := &Entity{
|
||||
|
||||
+7
-20
@@ -13,12 +13,6 @@ import (
|
||||
lua "github.com/yuin/gopher-lua"
|
||||
)
|
||||
|
||||
const (
|
||||
MaxCallLuaFuncLoopCount = 10 // 调用LUA方法递归层数限制
|
||||
)
|
||||
|
||||
var CallLuaFuncLoopCount = 0
|
||||
|
||||
type LuaCtx struct {
|
||||
uid uint32
|
||||
ownerUid uint32
|
||||
@@ -42,14 +36,7 @@ type LuaEvt struct {
|
||||
|
||||
// CallLuaFunc 调用LUA方法
|
||||
func CallLuaFunc(luaState *lua.LState, luaFuncName string, luaCtx *LuaCtx, luaEvt *LuaEvt) bool {
|
||||
if CallLuaFuncLoopCount > MaxCallLuaFuncLoopCount {
|
||||
logger.Error("above max call lua func loop count, stack: %v", logger.Stack())
|
||||
return false
|
||||
}
|
||||
CallLuaFuncLoopCount++
|
||||
defer func() {
|
||||
CallLuaFuncLoopCount--
|
||||
}()
|
||||
GAME.EndlessLoopCheck(EndlessLoopCheckTypeCallLuaFunc)
|
||||
ctx := luaState.NewTable()
|
||||
luaState.SetField(ctx, "uid", lua.LNumber(luaCtx.uid))
|
||||
luaState.SetField(ctx, "owner_uid", lua.LNumber(luaCtx.ownerUid))
|
||||
@@ -108,7 +95,7 @@ func GetContextGroup(player *model.Player, ctx *lua.LTable, luaState *lua.LState
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
scene := world.GetSceneById(player.GetSceneId())
|
||||
group := scene.GetGroupById(uint32(groupId))
|
||||
if group == nil {
|
||||
return nil
|
||||
@@ -124,7 +111,7 @@ func GetContextDbSceneGroup(player *model.Player, groupId uint32) *model.DbScene
|
||||
}
|
||||
owner := world.GetOwner()
|
||||
dbWorld := owner.GetDbWorld()
|
||||
dbScene := dbWorld.GetSceneById(player.SceneId)
|
||||
dbScene := dbWorld.GetSceneById(player.GetSceneId())
|
||||
dbSceneGroup := dbScene.GetSceneGroupById(groupId)
|
||||
return dbSceneGroup
|
||||
}
|
||||
@@ -210,7 +197,7 @@ func PrintContextLog(luaState *lua.LState) int {
|
||||
|
||||
func BeginCameraSceneLook(luaState *lua.LState) int {
|
||||
// TODO 由于解锁风之翼任务相关原因暂时屏蔽
|
||||
luaState.Push(lua.LNumber(-1))
|
||||
luaState.Push(lua.LNumber(0))
|
||||
return 1
|
||||
ctx, ok := luaState.Get(1).(*lua.LTable)
|
||||
if !ok {
|
||||
@@ -312,7 +299,7 @@ func GetGadgetStateByConfigId(luaState *lua.LState) int {
|
||||
luaState.Push(lua.LNumber(-1))
|
||||
return 1
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
scene := world.GetSceneById(player.GetSceneId())
|
||||
group := scene.GetGroupById(uint32(groupId))
|
||||
if group == nil {
|
||||
luaState.Push(lua.LNumber(-1))
|
||||
@@ -484,7 +471,7 @@ func KillEntityByConfigId(luaState *lua.LState) int {
|
||||
luaState.Push(lua.LNumber(-1))
|
||||
return 1
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
scene := world.GetSceneById(player.GetSceneId())
|
||||
group := scene.GetGroupById(uint32(groupId))
|
||||
entity := group.GetEntityByConfigId(uint32(luaTableParam.ConfigId))
|
||||
GAME.KillEntity(player, scene, entity.GetId(), proto.PlayerDieType_PLAYER_DIE_NONE)
|
||||
@@ -723,7 +710,7 @@ func GetRegionEntityCount(luaState *lua.LState) int {
|
||||
luaState.Push(lua.LNumber(-1))
|
||||
return 1
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
scene := world.GetSceneById(player.GetSceneId())
|
||||
count := 0
|
||||
for _, entity := range scene.GetAllEntity() {
|
||||
contain := shape.Contain(&alg.Vector3{X: float32(entity.GetPos().X), Y: float32(entity.GetPos().Y), Z: float32(entity.GetPos().Z)})
|
||||
|
||||
@@ -13,7 +13,7 @@ func forEachPlayerSceneGroup(player *model.Player, handleFunc func(suiteConfig *
|
||||
if world == nil {
|
||||
return
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
scene := world.GetSceneById(player.GetSceneId())
|
||||
for groupId, group := range scene.GetAllGroup() {
|
||||
groupConfig := gdconf.GetSceneGroup(int32(groupId))
|
||||
if groupConfig == nil {
|
||||
@@ -32,7 +32,7 @@ func forEachPlayerSceneGroupTrigger(player *model.Player, handleFunc func(trigge
|
||||
if world == nil {
|
||||
return
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
scene := world.GetSceneById(player.GetSceneId())
|
||||
for groupId, group := range scene.GetAllGroup() {
|
||||
groupConfig := gdconf.GetSceneGroup(int32(groupId))
|
||||
if groupConfig == nil {
|
||||
|
||||
+28
-22
@@ -248,7 +248,7 @@ func (g *Game) AvatarWearFlycloakReq(player *model.Player, payloadMsg pb.Message
|
||||
g.SendError(cmd.AvatarWearFlycloakRsp, player, &proto.AvatarWearFlycloakRsp{})
|
||||
return
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
scene := world.GetSceneById(player.GetSceneId())
|
||||
|
||||
// 确保角色存在
|
||||
avatar, ok := player.GameObjectGuidMap[req.AvatarGuid].(*model.Avatar)
|
||||
@@ -298,7 +298,7 @@ func (g *Game) AvatarChangeCostumeReq(player *model.Player, payloadMsg pb.Messag
|
||||
g.SendError(cmd.AvatarChangeCostumeRsp, player, &proto.AvatarChangeCostumeRsp{})
|
||||
return
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
scene := world.GetSceneById(player.GetSceneId())
|
||||
|
||||
// 确保角色存在
|
||||
avatar, ok := player.GameObjectGuidMap[req.AvatarGuid].(*model.Avatar)
|
||||
@@ -377,8 +377,8 @@ func (g *Game) AddPlayerAvatar(userId uint32, avatarId uint32) {
|
||||
}
|
||||
// 判断玩家是否已有该角色
|
||||
dbAvatar := player.GetDbAvatar()
|
||||
_, exist := dbAvatar.AvatarMap[avatarId]
|
||||
if exist {
|
||||
avatar := dbAvatar.GetAvatarById(avatarId)
|
||||
if avatar != nil {
|
||||
return
|
||||
}
|
||||
dbAvatar.AddAvatar(player, avatarId)
|
||||
@@ -397,7 +397,7 @@ func (g *Game) AddPlayerAvatar(userId uint32, avatarId uint32) {
|
||||
g.UpdatePlayerAvatarFightProp(player.PlayerId, avatarId)
|
||||
|
||||
avatarAddNotify := &proto.AvatarAddNotify{
|
||||
Avatar: g.PacketAvatarInfo(dbAvatar.AvatarMap[avatarId]),
|
||||
Avatar: g.PacketAvatarInfo(dbAvatar.GetAvatarById(avatarId)),
|
||||
IsInTeam: false,
|
||||
}
|
||||
g.SendMsg(cmd.AvatarAddNotify, userId, player.ClientSeq, avatarAddNotify)
|
||||
@@ -514,9 +514,9 @@ func (g *Game) UpdatePlayerAvatarFightProp(userId uint32, avatarId uint32) {
|
||||
return
|
||||
}
|
||||
dbAvatar := player.GetDbAvatar()
|
||||
avatar, exist := dbAvatar.AvatarMap[avatarId]
|
||||
if !exist {
|
||||
logger.Error("avatar not exist, avatarId: %v", avatar.AvatarId)
|
||||
avatar := dbAvatar.GetAvatarById(avatarId)
|
||||
if avatar == nil {
|
||||
logger.Error("get avatar is nil, avatarId: %v", avatarId)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -530,6 +530,7 @@ func (g *Game) UpdatePlayerAvatarFightProp(userId uint32, avatarId uint32) {
|
||||
g.SendMsg(cmd.AvatarFightPropNotify, userId, player.ClientSeq, avatarFightPropNotify)
|
||||
}
|
||||
|
||||
// ChangePlayerAvatarSkillDepot 改变角色技能库
|
||||
func (g *Game) ChangePlayerAvatarSkillDepot(userId uint32, avatarId uint32, changeSkillDepotId uint32, elementType int) {
|
||||
player := USER_MANAGER.GetOnlineUser(userId)
|
||||
if player == nil {
|
||||
@@ -562,8 +563,9 @@ func (g *Game) ChangePlayerAvatarSkillDepot(userId uint32, avatarId uint32, chan
|
||||
}
|
||||
}
|
||||
dbAvatar := player.GetDbAvatar()
|
||||
avatar, exist := dbAvatar.AvatarMap[avatarId]
|
||||
if !exist {
|
||||
avatar := dbAvatar.GetAvatarById(avatarId)
|
||||
if avatar == nil {
|
||||
logger.Error("get avatar is nil, avatarId: %v", avatarId)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -592,6 +594,7 @@ func (g *Game) ChangePlayerAvatarSkillDepot(userId uint32, avatarId uint32, chan
|
||||
g.UpdatePlayerAvatarFightProp(player.PlayerId, avatarId)
|
||||
}
|
||||
|
||||
// AddPlayerAvatarHp 角色加血
|
||||
func (g *Game) AddPlayerAvatarHp(userId uint32, avatarId uint32, value float32, max bool, reason proto.ChangHpReason) {
|
||||
player := USER_MANAGER.GetOnlineUser(userId)
|
||||
if player == nil {
|
||||
@@ -602,7 +605,7 @@ func (g *Game) AddPlayerAvatarHp(userId uint32, avatarId uint32, value float32,
|
||||
if world == nil {
|
||||
return
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
scene := world.GetSceneById(player.GetSceneId())
|
||||
entityId := world.GetPlayerWorldAvatarEntityId(player, avatarId)
|
||||
if entityId == 0 {
|
||||
return
|
||||
@@ -633,6 +636,7 @@ func (g *Game) AddPlayerAvatarHp(userId uint32, avatarId uint32, value float32,
|
||||
})
|
||||
}
|
||||
|
||||
// SubPlayerAvatarHp 角色扣血
|
||||
func (g *Game) SubPlayerAvatarHp(userId uint32, avatarId uint32, value float32, max bool, reason proto.ChangHpReason) {
|
||||
player := USER_MANAGER.GetOnlineUser(userId)
|
||||
if player == nil {
|
||||
@@ -646,7 +650,7 @@ func (g *Game) SubPlayerAvatarHp(userId uint32, avatarId uint32, value float32,
|
||||
if world == nil {
|
||||
return
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
scene := world.GetSceneById(player.GetSceneId())
|
||||
entityId := world.GetPlayerWorldAvatarEntityId(player, avatarId)
|
||||
if entityId == 0 {
|
||||
return
|
||||
@@ -700,6 +704,7 @@ func (g *Game) SubPlayerAvatarHp(userId uint32, avatarId uint32, value float32,
|
||||
}
|
||||
}
|
||||
|
||||
// AddPlayerAvatarEnergy 角色恢复元素能量
|
||||
func (g *Game) AddPlayerAvatarEnergy(userId uint32, avatarId uint32, value float32, max bool) {
|
||||
player := USER_MANAGER.GetOnlineUser(userId)
|
||||
if player == nil {
|
||||
@@ -707,9 +712,9 @@ func (g *Game) AddPlayerAvatarEnergy(userId uint32, avatarId uint32, value float
|
||||
return
|
||||
}
|
||||
dbAvatar := player.GetDbAvatar()
|
||||
avatar, exist := dbAvatar.AvatarMap[avatarId]
|
||||
if !exist {
|
||||
logger.Error("avatar not exist, avatarId: %v", avatarId)
|
||||
avatar := dbAvatar.GetAvatarById(avatarId)
|
||||
if avatar == nil {
|
||||
logger.Error("get avatar is nil, avatarId: %v", avatarId)
|
||||
return
|
||||
}
|
||||
avatarSkillDataConfig := gdconf.GetAvatarEnergySkillConfig(avatar.SkillDepotId)
|
||||
@@ -729,6 +734,7 @@ func (g *Game) AddPlayerAvatarEnergy(userId uint32, avatarId uint32, value float
|
||||
g.UpdatePlayerAvatarFightProp(player.PlayerId, avatarId)
|
||||
}
|
||||
|
||||
// CostPlayerAvatarEnergy 角色消耗元素能量
|
||||
func (g *Game) CostPlayerAvatarEnergy(userId uint32, avatarId uint32, value float32, max bool) {
|
||||
player := USER_MANAGER.GetOnlineUser(userId)
|
||||
if player == nil {
|
||||
@@ -739,9 +745,9 @@ func (g *Game) CostPlayerAvatarEnergy(userId uint32, avatarId uint32, value floa
|
||||
return
|
||||
}
|
||||
dbAvatar := player.GetDbAvatar()
|
||||
avatar, exist := dbAvatar.AvatarMap[avatarId]
|
||||
if !exist {
|
||||
logger.Error("avatar not exist, avatarId: %v", avatarId)
|
||||
avatar := dbAvatar.GetAvatarById(avatarId)
|
||||
if avatar == nil {
|
||||
logger.Error("get avatar is nil, avatarId: %v", avatarId)
|
||||
return
|
||||
}
|
||||
avatarSkillDataConfig := gdconf.GetAvatarEnergySkillConfig(avatar.SkillDepotId)
|
||||
@@ -763,7 +769,7 @@ func (g *Game) CostPlayerAvatarEnergy(userId uint32, avatarId uint32, value floa
|
||||
|
||||
/************************************************** 打包封装 **************************************************/
|
||||
|
||||
// PacketAvatarInfo 转换角色信息
|
||||
// PacketAvatarInfo 打包角色信息
|
||||
func (g *Game) PacketAvatarInfo(avatar *model.Avatar) *proto.AvatarInfo {
|
||||
pbAvatar := &proto.AvatarInfo{
|
||||
IsFocus: false,
|
||||
@@ -861,21 +867,21 @@ func (g *Game) PacketAvatarDataNotify(player *model.Player) *proto.AvatarDataNot
|
||||
dbTeam := player.GetDbTeam()
|
||||
avatarDataNotify := &proto.AvatarDataNotify{
|
||||
CurAvatarTeamId: uint32(dbTeam.GetActiveTeamId()),
|
||||
ChooseAvatarGuid: dbAvatar.AvatarMap[dbAvatar.MainCharAvatarId].Guid,
|
||||
ChooseAvatarGuid: dbAvatar.GetAvatarById(dbAvatar.MainCharAvatarId).Guid,
|
||||
OwnedFlycloakList: dbAvatar.FlyCloakList,
|
||||
// 角色衣装
|
||||
OwnedCostumeList: dbAvatar.CostumeList,
|
||||
AvatarList: make([]*proto.AvatarInfo, 0),
|
||||
AvatarTeamMap: make(map[uint32]*proto.AvatarTeam),
|
||||
}
|
||||
for _, avatar := range dbAvatar.AvatarMap {
|
||||
for _, avatar := range dbAvatar.GetAvatarMap() {
|
||||
pbAvatar := g.PacketAvatarInfo(avatar)
|
||||
avatarDataNotify.AvatarList = append(avatarDataNotify.AvatarList, pbAvatar)
|
||||
}
|
||||
for teamIndex, team := range dbTeam.TeamList {
|
||||
var teamAvatarGuidList []uint64 = nil
|
||||
for _, avatarId := range team.GetAvatarIdList() {
|
||||
teamAvatarGuidList = append(teamAvatarGuidList, dbAvatar.AvatarMap[avatarId].Guid)
|
||||
teamAvatarGuidList = append(teamAvatarGuidList, dbAvatar.GetAvatarById(avatarId).Guid)
|
||||
}
|
||||
avatarDataNotify.AvatarTeamMap[uint32(teamIndex)+1] = &proto.AvatarTeam{
|
||||
AvatarGuidList: teamAvatarGuidList,
|
||||
|
||||
@@ -233,7 +233,7 @@ func (g *Game) SendPrivateChat(player *model.Player, targetUid uint32, content a
|
||||
if USER_MANAGER.GetRemoteUserOnlineState(targetUid) {
|
||||
// 目标玩家在别的服在线
|
||||
gsAppId := USER_MANAGER.GetRemoteUserGsAppId(targetUid)
|
||||
MESSAGE_QUEUE.SendToGs(gsAppId, &mq.NetMsg{
|
||||
g.messageQueue.SendToGs(gsAppId, &mq.NetMsg{
|
||||
MsgType: mq.MsgTypeServer,
|
||||
EventId: mq.ServerChatMsgNotify,
|
||||
ServerMsg: &mq.ServerMsg{
|
||||
|
||||
@@ -135,7 +135,7 @@ func (g *Game) WorldPlayerLocationNotify(world *World) {
|
||||
pos := g.GetPlayerPos(worldPlayer)
|
||||
rot := g.GetPlayerRot(worldPlayer)
|
||||
playerWorldLocationInfo := &proto.PlayerWorldLocationInfo{
|
||||
SceneId: worldPlayer.SceneId,
|
||||
SceneId: worldPlayer.GetSceneId(),
|
||||
PlayerLoc: &proto.PlayerLocationInfo{
|
||||
Uid: worldPlayer.PlayerId,
|
||||
Pos: &proto.Vector{X: float32(pos.X), Y: float32(pos.Y), Z: float32(pos.Z)},
|
||||
@@ -214,7 +214,7 @@ func (g *Game) SceneTimeNotify(world *World) {
|
||||
for _, scene := range world.GetAllScene() {
|
||||
for _, player := range scene.GetAllPlayer() {
|
||||
sceneTimeNotify := &proto.SceneTimeNotify{
|
||||
SceneId: player.SceneId,
|
||||
SceneId: player.GetSceneId(),
|
||||
SceneTime: uint64(scene.GetSceneTime()),
|
||||
}
|
||||
g.SendMsg(cmd.SceneTimeNotify, player.PlayerId, 0, sceneTimeNotify)
|
||||
@@ -235,9 +235,9 @@ func (g *Game) PlayerTimeNotify(world *World) {
|
||||
|
||||
func (g *Game) PlayerGameTimeNotify(world *World) {
|
||||
for _, player := range world.GetAllPlayer() {
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
scene := world.GetSceneById(player.GetSceneId())
|
||||
if scene == nil {
|
||||
logger.Error("scene is nil, sceneId: %v, uid: %v", player.SceneId, player.PlayerId)
|
||||
logger.Error("scene is nil, sceneId: %v, uid: %v", player.GetSceneId(), player.PlayerId)
|
||||
return
|
||||
}
|
||||
for _, scenePlayer := range scene.GetAllPlayer() {
|
||||
|
||||
+18
-18
@@ -150,15 +150,15 @@ func (g *Game) WearPlayerAvatarReliquary(userId uint32, avatarId uint32, reliqua
|
||||
return
|
||||
}
|
||||
dbAvatar := player.GetDbAvatar()
|
||||
avatar, ok := dbAvatar.AvatarMap[avatarId]
|
||||
if !ok {
|
||||
logger.Error("avatar error, avatarId: %v", avatarId)
|
||||
avatar := dbAvatar.GetAvatarById(avatarId)
|
||||
if avatar == nil {
|
||||
logger.Error("get avatar is nil, avatarId: %v", avatarId)
|
||||
return
|
||||
}
|
||||
dbReliquary := player.GetDbReliquary()
|
||||
reliquary, ok := dbReliquary.ReliquaryMap[reliquaryId]
|
||||
if !ok {
|
||||
logger.Error("reliquary error, reliquaryId: %v", reliquaryId)
|
||||
reliquary := dbReliquary.GetReliquaryById(reliquaryId)
|
||||
if reliquary == nil {
|
||||
logger.Error("get reliquary is nil, reliquaryId: %v", reliquaryId)
|
||||
return
|
||||
}
|
||||
// 获取圣遗物配置表
|
||||
@@ -171,9 +171,9 @@ func (g *Game) WearPlayerAvatarReliquary(userId uint32, avatarId uint32, reliqua
|
||||
avatarCurReliquary := avatar.EquipReliquaryMap[uint8(reliquaryConfig.ReliquaryType)]
|
||||
if reliquary.AvatarId != 0 {
|
||||
// 圣遗物在别的角色身上
|
||||
targetReliquaryAvatar, ok := dbAvatar.AvatarMap[reliquary.AvatarId]
|
||||
if !ok {
|
||||
logger.Error("avatar error, avatarId: %v", reliquary.AvatarId)
|
||||
targetReliquaryAvatar := dbAvatar.GetAvatarById(reliquary.AvatarId)
|
||||
if targetReliquaryAvatar == nil {
|
||||
logger.Error("get avatar is nil, avatarId: %v", reliquary.AvatarId)
|
||||
return
|
||||
}
|
||||
// 确保目前角色已装备圣遗物
|
||||
@@ -209,15 +209,15 @@ func (g *Game) WearPlayerAvatarWeapon(userId uint32, avatarId uint32, weaponId u
|
||||
return
|
||||
}
|
||||
dbAvatar := player.GetDbAvatar()
|
||||
avatar, ok := dbAvatar.AvatarMap[avatarId]
|
||||
if !ok {
|
||||
logger.Error("avatar error, avatarId: %v", avatarId)
|
||||
avatar := dbAvatar.GetAvatarById(avatarId)
|
||||
if avatar == nil {
|
||||
logger.Error("get avatar is nil, avatarId: %v", avatarId)
|
||||
return
|
||||
}
|
||||
dbWeapon := player.GetDbWeapon()
|
||||
weapon, ok := dbWeapon.WeaponMap[weaponId]
|
||||
if !ok {
|
||||
logger.Error("weapon error, weaponId: %v", weaponId)
|
||||
weapon := dbWeapon.GetWeaponById(weaponId)
|
||||
if weapon == nil {
|
||||
logger.Error("get weapon is nil, weaponId: %v", weaponId)
|
||||
return
|
||||
}
|
||||
world := WORLD_MANAGER.GetWorldById(player.WorldId)
|
||||
@@ -231,9 +231,9 @@ func (g *Game) WearPlayerAvatarWeapon(userId uint32, avatarId uint32, weaponId u
|
||||
if avatarCurWeapon != nil {
|
||||
if weapon.AvatarId != 0 {
|
||||
// 武器在别的角色身上
|
||||
targetWeaponAvatar, ok := dbAvatar.AvatarMap[weapon.AvatarId]
|
||||
if !ok {
|
||||
logger.Error("avatar error, avatarId: %v", weapon.AvatarId)
|
||||
targetWeaponAvatar := dbAvatar.GetAvatarById(weapon.AvatarId)
|
||||
if targetWeaponAvatar == nil {
|
||||
logger.Error("get avatar is nil, avatarId: %v", weapon.AvatarId)
|
||||
return
|
||||
}
|
||||
// 卸下角色已装备的武器
|
||||
|
||||
+66
-132
@@ -1,7 +1,6 @@
|
||||
package game
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"strings"
|
||||
|
||||
@@ -30,7 +29,7 @@ func DoForward[IET model.InvokeEntryType](player *model.Player, invokeHandler *m
|
||||
if world == nil {
|
||||
return
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
scene := world.GetSceneById(player.GetSceneId())
|
||||
if srcNtf != nil && copyFieldList != nil {
|
||||
for _, fieldName := range copyFieldList {
|
||||
reflection.CopyStructField(newNtf, srcNtf, fieldName)
|
||||
@@ -115,7 +114,7 @@ func (g *Game) CombatInvocationsNotify(player *model.Player, payloadMsg pb.Messa
|
||||
if world == nil {
|
||||
return
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
scene := world.GetSceneById(player.GetSceneId())
|
||||
for _, entry := range ntf.InvokeList {
|
||||
switch entry.ArgumentType {
|
||||
case proto.CombatTypeArgument_COMBAT_EVT_BEING_HIT:
|
||||
@@ -175,7 +174,15 @@ func (g *Game) CombatInvocationsNotify(player *model.Player, payloadMsg pb.Messa
|
||||
}
|
||||
|
||||
func (g *Game) handleEvtBeingHit(player *model.Player, scene *Scene, hitInfo *proto.EvtBeingHitInfo) {
|
||||
world := scene.GetWorld()
|
||||
// 触发事件
|
||||
if PLUGIN_MANAGER.TriggerEvent(PluginEventIdEvtBeingHit, &PluginEventEvtBeingHit{
|
||||
PluginEvent: NewPluginEvent(),
|
||||
Player: player,
|
||||
HitInfo: hitInfo,
|
||||
}) {
|
||||
return
|
||||
}
|
||||
|
||||
attackResult := hitInfo.AttackResult
|
||||
if attackResult == nil {
|
||||
logger.Error("attackResult is nil")
|
||||
@@ -192,26 +199,6 @@ func (g *Game) handleEvtBeingHit(player *model.Player, scene *Scene, hitInfo *pr
|
||||
switch defEntity.GetEntityType() {
|
||||
case constant.ENTITY_TYPE_AVATAR:
|
||||
g.SubPlayerAvatarHp(player.PlayerId, defEntity.GetAvatarEntity().GetAvatarId(), attackResult.Damage, false, proto.ChangHpReason_CHANGE_HP_SUB_MONSTER)
|
||||
if WORLD_MANAGER.IsAiWorld(world) {
|
||||
fightProp := defEntity.GetFightProp()
|
||||
currHp := fightProp[constant.FIGHT_PROP_CUR_HP]
|
||||
if currHp > 0.0 {
|
||||
return
|
||||
}
|
||||
defPlayer := USER_MANAGER.GetOnlineUser(defEntity.GetAvatarEntity().GetUid())
|
||||
if defPlayer == nil {
|
||||
return
|
||||
}
|
||||
atkEntity := scene.GetEntity(attackResult.AttackerId)
|
||||
if atkEntity != nil && atkEntity.GetEntityType() == constant.ENTITY_TYPE_AVATAR {
|
||||
atkPlayer := USER_MANAGER.GetOnlineUser(atkEntity.GetAvatarEntity().GetUid())
|
||||
if atkPlayer == nil {
|
||||
return
|
||||
}
|
||||
info := fmt.Sprintf("『%v』击败了『%v』。", atkPlayer.NickName, defPlayer.NickName)
|
||||
g.PlayerChatReq(world.GetOwner(), &proto.PlayerChatReq{ChatInfo: &proto.ChatInfo{Content: &proto.ChatInfo_Text{Text: info}}})
|
||||
}
|
||||
}
|
||||
case constant.ENTITY_TYPE_MONSTER:
|
||||
fightProp := defEntity.GetFightProp()
|
||||
currHp := fightProp[constant.FIGHT_PROP_CUR_HP]
|
||||
@@ -308,7 +295,7 @@ func (g *Game) handleEntityMove(player *model.Player, world *World, scene *Scene
|
||||
}
|
||||
// 处理耐力消耗
|
||||
g.ImmediateStamina(player, motionInfo.State)
|
||||
// 坠落撞击死亡
|
||||
// 坠落撞击扣血
|
||||
if player.Speed == nil {
|
||||
player.Speed = &model.Vector{X: float64(motionInfo.Speed.X), Y: float64(motionInfo.Speed.Y), Z: float64(motionInfo.Speed.Z)}
|
||||
}
|
||||
@@ -319,21 +306,21 @@ func (g *Game) handleEntityMove(player *model.Player, world *World, scene *Scene
|
||||
deltaSpeedMag := alg.Vector3Magnitude(deltaSpeed)
|
||||
if deltaSpeedMag > 20.0 {
|
||||
logger.Debug("player fall on ground, deltaSpeed: %+v, deltaSpeedMag: %v, uid: %v", deltaSpeed, deltaSpeedMag, player.PlayerId)
|
||||
// 速度矢量20-30部分线性映射到最大生命值百分比扣血
|
||||
rate := deltaSpeedMag - 20.0
|
||||
if rate > 10.0 {
|
||||
rate = 10.0
|
||||
}
|
||||
rate /= 10.0
|
||||
fightProp := entity.GetFightProp()
|
||||
currHp := fightProp[constant.FIGHT_PROP_CUR_HP]
|
||||
maxHp := fightProp[constant.FIGHT_PROP_MAX_HP]
|
||||
damage := float32(0.0)
|
||||
if motionInfo.State == proto.MotionState_MOTION_FALL_ON_GROUND {
|
||||
damage = maxHp * rate
|
||||
} else if motionInfo.State == proto.MotionState_MOTION_FIGHT {
|
||||
damage = currHp * rate
|
||||
// 下落攻击最大生命值百分比扣血上限为40
|
||||
if motionInfo.State == proto.MotionState_MOTION_FIGHT {
|
||||
if rate > 0.4 {
|
||||
rate = 0.4
|
||||
}
|
||||
}
|
||||
g.SubPlayerAvatarHp(player.PlayerId, entity.GetAvatarEntity().GetAvatarId(), damage, false, proto.ChangHpReason_CHANGE_HP_SUB_FALL)
|
||||
fightProp := entity.GetFightProp()
|
||||
maxHp := fightProp[constant.FIGHT_PROP_MAX_HP]
|
||||
g.SubPlayerAvatarHp(player.PlayerId, entity.GetAvatarEntity().GetAvatarId(), maxHp*rate, false, proto.ChangHpReason_CHANGE_HP_SUB_FALL)
|
||||
}
|
||||
}
|
||||
player.Speed = &model.Vector{X: float64(motionInfo.Speed.X), Y: float64(motionInfo.Speed.Y), Z: float64(motionInfo.Speed.Z)}
|
||||
@@ -357,9 +344,9 @@ func (g *Game) SceneBlockAoiPlayerMove(player *model.Player, world *World, scene
|
||||
return
|
||||
}
|
||||
sceneBlockAoiMap := WORLD_MANAGER.GetSceneBlockAoiMap()
|
||||
aoiManager, exist := sceneBlockAoiMap[player.SceneId]
|
||||
aoiManager, exist := sceneBlockAoiMap[player.GetSceneId()]
|
||||
if !exist {
|
||||
logger.Error("get scene block aoi is nil, sceneId: %v, uid: %v", player.SceneId, player.PlayerId)
|
||||
logger.Error("get scene block aoi is nil, sceneId: %v, uid: %v", player.GetSceneId(), player.PlayerId)
|
||||
return
|
||||
}
|
||||
oldGid := aoiManager.GetGidByPos(float32(oldPos.X), 0.0, float32(oldPos.Z))
|
||||
@@ -369,8 +356,8 @@ func (g *Game) SceneBlockAoiPlayerMove(player *model.Player, world *World, scene
|
||||
logger.Debug("player cross scene block grid, oldGid: %v, newGid: %v, uid: %v", oldGid, newGid, player.PlayerId)
|
||||
}
|
||||
// 加载和卸载的group
|
||||
oldNeighborGroupMap := g.GetNeighborGroup(player.SceneId, oldPos)
|
||||
newNeighborGroupMap := g.GetNeighborGroup(player.SceneId, newPos)
|
||||
oldNeighborGroupMap := g.GetNeighborGroup(player.GetSceneId(), oldPos)
|
||||
newNeighborGroupMap := g.GetNeighborGroup(player.GetSceneId(), newPos)
|
||||
for groupId, groupConfig := range oldNeighborGroupMap {
|
||||
_, exist = newNeighborGroupMap[groupId]
|
||||
if exist {
|
||||
@@ -736,7 +723,7 @@ func (g *Game) MassiveEntityElementOpBatchNotify(player *model.Player, payloadMs
|
||||
if world == nil {
|
||||
return
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
scene := world.GetSceneById(player.GetSceneId())
|
||||
ntf.OpIdx = scene.GetMeeoIndex()
|
||||
scene.SetMeeoIndex(scene.GetMeeoIndex() + 1)
|
||||
g.SendToSceneA(scene, cmd.MassiveEntityElementOpBatchNotify, player.ClientSeq, ntf, 0)
|
||||
@@ -747,18 +734,29 @@ func (g *Game) EvtDoSkillSuccNotify(player *model.Player, payloadMsg pb.Message)
|
||||
if player.SceneLoadState != model.SceneEnterDone {
|
||||
return
|
||||
}
|
||||
|
||||
// 触发事件
|
||||
if PLUGIN_MANAGER.TriggerEvent(PluginEventIdEvtDoSkillSucc, &PluginEventEvtDoSkillSucc{
|
||||
PluginEvent: NewPluginEvent(),
|
||||
Player: player,
|
||||
Ntf: ntf,
|
||||
}) {
|
||||
return
|
||||
}
|
||||
|
||||
// logger.Debug("EvtDoSkillSuccNotify: %+v", ntf)
|
||||
// 处理技能开始的耐力消耗
|
||||
g.SkillStartStamina(player, ntf.CasterId, ntf.SkillId)
|
||||
// 触发任务
|
||||
g.TriggerQuest(player, constant.QUEST_FINISH_COND_TYPE_SKILL, "", int32(ntf.SkillId))
|
||||
|
||||
// 消耗元素能量
|
||||
world := WORLD_MANAGER.GetWorldById(player.WorldId)
|
||||
if world == nil {
|
||||
return
|
||||
}
|
||||
activeAvatarId := world.GetPlayerActiveAvatarId(player)
|
||||
dbAvatar := player.GetDbAvatar()
|
||||
avatar := dbAvatar.AvatarMap[activeAvatarId]
|
||||
avatar := dbAvatar.GetAvatarById(activeAvatarId)
|
||||
if avatar == nil {
|
||||
return
|
||||
}
|
||||
@@ -769,48 +767,6 @@ func (g *Game) EvtDoSkillSuccNotify(player *model.Player, payloadMsg pb.Message)
|
||||
if int32(ntf.SkillId) == avatarSkillDataConfig.AvatarSkillId {
|
||||
g.CostPlayerAvatarEnergy(player.PlayerId, activeAvatarId, 0, true)
|
||||
}
|
||||
|
||||
if !WORLD_MANAGER.IsAiWorld(world) {
|
||||
return
|
||||
}
|
||||
iPlugin, err := PLUGIN_MANAGER.GetPlugin(&PluginPubg{})
|
||||
if err != nil {
|
||||
logger.Error("get plugin pubg error: %v", err)
|
||||
return
|
||||
}
|
||||
pluginPubg := iPlugin.(*PluginPubg)
|
||||
if !pluginPubg.IsStartPubg() {
|
||||
return
|
||||
}
|
||||
worldAvatar := world.GetWorldAvatarByEntityId(ntf.CasterId)
|
||||
if worldAvatar == nil {
|
||||
return
|
||||
}
|
||||
avatarDataConfig := gdconf.GetAvatarDataById(int32(worldAvatar.GetAvatarId()))
|
||||
if avatarDataConfig == nil {
|
||||
return
|
||||
}
|
||||
logger.Debug("avatar normal attack, avatarId: %v, weaponType: %v, uid: %v", avatarDataConfig.AvatarId, avatarDataConfig.WeaponType, player.PlayerId)
|
||||
switch avatarDataConfig.WeaponType {
|
||||
case constant.WEAPON_TYPE_SWORD_ONE_HAND, constant.WEAPON_TYPE_CLAYMORE, constant.WEAPON_TYPE_POLE, constant.WEAPON_TYPE_CATALYST:
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
avatarEntity := scene.GetEntity(worldAvatar.GetAvatarEntityId())
|
||||
for _, entity := range scene.GetAllEntity() {
|
||||
if entity.GetId() == avatarEntity.GetId() || entity.GetEntityType() != constant.ENTITY_TYPE_AVATAR {
|
||||
continue
|
||||
}
|
||||
distance3D := math.Sqrt(
|
||||
(avatarEntity.GetPos().X-entity.GetPos().X)*(avatarEntity.GetPos().X-entity.GetPos().X) +
|
||||
(avatarEntity.GetPos().Y-entity.GetPos().Y)*(avatarEntity.GetPos().Y-entity.GetPos().Y) +
|
||||
(avatarEntity.GetPos().Z-entity.GetPos().Z)*(avatarEntity.GetPos().Z-entity.GetPos().Z),
|
||||
)
|
||||
if distance3D > PUBG_NORMAL_ATTACK_DISTANCE {
|
||||
continue
|
||||
}
|
||||
pluginPubg.PubgHit(scene, entity.GetId(), avatarEntity.GetId(), false)
|
||||
}
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Game) EvtAvatarEnterFocusNotify(player *model.Player, payloadMsg pb.Message) {
|
||||
@@ -823,7 +779,7 @@ func (g *Game) EvtAvatarEnterFocusNotify(player *model.Player, payloadMsg pb.Mes
|
||||
if world == nil {
|
||||
return
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
scene := world.GetSceneById(player.GetSceneId())
|
||||
g.SendToSceneA(scene, cmd.EvtAvatarEnterFocusNotify, player.ClientSeq, ntf, 0)
|
||||
}
|
||||
|
||||
@@ -837,7 +793,7 @@ func (g *Game) EvtAvatarUpdateFocusNotify(player *model.Player, payloadMsg pb.Me
|
||||
if world == nil {
|
||||
return
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
scene := world.GetSceneById(player.GetSceneId())
|
||||
g.SendToSceneA(scene, cmd.EvtAvatarUpdateFocusNotify, player.ClientSeq, ntf, 0)
|
||||
}
|
||||
|
||||
@@ -851,7 +807,7 @@ func (g *Game) EvtAvatarExitFocusNotify(player *model.Player, payloadMsg pb.Mess
|
||||
if world == nil {
|
||||
return
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
scene := world.GetSceneById(player.GetSceneId())
|
||||
g.SendToSceneA(scene, cmd.EvtAvatarExitFocusNotify, player.ClientSeq, ntf, 0)
|
||||
}
|
||||
|
||||
@@ -865,7 +821,7 @@ func (g *Game) EvtEntityRenderersChangedNotify(player *model.Player, payloadMsg
|
||||
if world == nil {
|
||||
return
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
scene := world.GetSceneById(player.GetSceneId())
|
||||
g.SendToSceneA(scene, cmd.EvtEntityRenderersChangedNotify, player.ClientSeq, ntf, 0)
|
||||
}
|
||||
|
||||
@@ -879,7 +835,7 @@ func (g *Game) EvtBulletDeactiveNotify(player *model.Player, payloadMsg pb.Messa
|
||||
if world == nil {
|
||||
return
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
scene := world.GetSceneById(player.GetSceneId())
|
||||
g.SendToSceneA(scene, cmd.EvtBulletDeactiveNotify, player.ClientSeq, ntf, 0)
|
||||
}
|
||||
|
||||
@@ -893,15 +849,16 @@ func (g *Game) EvtBulletHitNotify(player *model.Player, payloadMsg pb.Message) {
|
||||
if world == nil {
|
||||
return
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
scene := world.GetSceneById(player.GetSceneId())
|
||||
g.SendToSceneA(scene, cmd.EvtBulletHitNotify, player.ClientSeq, ntf, 0)
|
||||
|
||||
if WORLD_MANAGER.IsAiWorld(world) {
|
||||
bulletPhysicsEngine := world.GetBulletPhysicsEngine()
|
||||
if bulletPhysicsEngine.IsRigidBody(ntf.EntityId) {
|
||||
bulletPhysicsEngine.DestroyRigidBody(ntf.EntityId)
|
||||
_ = ntf.HitPoint
|
||||
}
|
||||
// 触发事件
|
||||
if PLUGIN_MANAGER.TriggerEvent(PluginEventIdEvtBulletHit, &PluginEventEvtBulletHit{
|
||||
PluginEvent: NewPluginEvent(),
|
||||
Player: player,
|
||||
Ntf: ntf,
|
||||
}) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
@@ -915,7 +872,7 @@ func (g *Game) EvtBulletMoveNotify(player *model.Player, payloadMsg pb.Message)
|
||||
if world == nil {
|
||||
return
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
scene := world.GetSceneById(player.GetSceneId())
|
||||
g.SendToSceneA(scene, cmd.EvtBulletMoveNotify, player.ClientSeq, ntf, 0)
|
||||
}
|
||||
|
||||
@@ -929,7 +886,7 @@ func (g *Game) EvtCreateGadgetNotify(player *model.Player, payloadMsg pb.Message
|
||||
if world == nil {
|
||||
return
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
scene := world.GetSceneById(player.GetSceneId())
|
||||
if ntf.InitPos == nil {
|
||||
return
|
||||
}
|
||||
@@ -947,36 +904,13 @@ func (g *Game) EvtCreateGadgetNotify(player *model.Player, payloadMsg pb.Message
|
||||
}
|
||||
g.AddSceneEntityNotify(player, proto.VisionType_VISION_BORN, []uint32{ntf.EntityId}, true, true)
|
||||
|
||||
if WORLD_MANAGER.IsAiWorld(world) {
|
||||
gadgetDataConfig := gdconf.GetGadgetDataById(int32(ntf.ConfigId))
|
||||
if gadgetDataConfig == nil {
|
||||
logger.Error("gadget data config is nil, gadgetId: %v", ntf.ConfigId)
|
||||
return
|
||||
}
|
||||
// 蓄力箭
|
||||
if gadgetDataConfig.PrefabPath != "ART/Others/Bullet/Bullet_ArrowAiming" &&
|
||||
gadgetDataConfig.PrefabPath != "ART/Others/Bullet/Bullet_Venti_ArrowAiming" {
|
||||
return
|
||||
}
|
||||
pitchAngleRaw := ntf.InitEulerAngles.X
|
||||
pitchAngle := float32(0.0)
|
||||
if pitchAngleRaw < 90.0 {
|
||||
pitchAngle = -pitchAngleRaw
|
||||
} else if pitchAngleRaw > 270.0 {
|
||||
pitchAngle = 360.0 - pitchAngleRaw
|
||||
} else {
|
||||
logger.Error("invalid raw pitch angle: %v, uid: %v", pitchAngleRaw, player.PlayerId)
|
||||
return
|
||||
}
|
||||
yawAngle := ntf.InitEulerAngles.Y
|
||||
bulletPhysicsEngine := world.GetBulletPhysicsEngine()
|
||||
bulletPhysicsEngine.CreateRigidBody(
|
||||
ntf.EntityId,
|
||||
world.GetPlayerActiveAvatarEntity(player).GetId(),
|
||||
player.SceneId,
|
||||
ntf.InitPos.X, ntf.InitPos.Y, ntf.InitPos.Z,
|
||||
pitchAngle, yawAngle,
|
||||
)
|
||||
// 触发事件
|
||||
if PLUGIN_MANAGER.TriggerEvent(PluginEventIdEvtCreateGadget, &PluginEventEvtCreateGadget{
|
||||
PluginEvent: NewPluginEvent(),
|
||||
Player: player,
|
||||
Ntf: ntf,
|
||||
}) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
@@ -990,7 +924,7 @@ func (g *Game) EvtDestroyGadgetNotify(player *model.Player, payloadMsg pb.Messag
|
||||
if world == nil {
|
||||
return
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
scene := world.GetSceneById(player.GetSceneId())
|
||||
scene.DestroyEntity(ntf.EntityId)
|
||||
g.RemoveSceneEntityNotifyBroadcast(scene, proto.VisionType_VISION_MISS, []uint32{ntf.EntityId}, 0)
|
||||
}
|
||||
@@ -1005,7 +939,7 @@ func (g *Game) EvtAiSyncSkillCdNotify(player *model.Player, payloadMsg pb.Messag
|
||||
if world == nil {
|
||||
return
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
scene := world.GetSceneById(player.GetSceneId())
|
||||
g.SendToSceneA(scene, cmd.EvtAiSyncSkillCdNotify, player.ClientSeq, ntf, 0)
|
||||
}
|
||||
|
||||
@@ -1019,7 +953,7 @@ func (g *Game) EvtAiSyncCombatThreatInfoNotify(player *model.Player, payloadMsg
|
||||
if world == nil {
|
||||
return
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
scene := world.GetSceneById(player.GetSceneId())
|
||||
g.SendToSceneA(scene, cmd.EvtAiSyncCombatThreatInfoNotify, player.ClientSeq, ntf, 0)
|
||||
}
|
||||
|
||||
@@ -1060,7 +994,7 @@ func (g *Game) handleGadgetEntityBeHitLow(player *model.Player, entity *Entity,
|
||||
if world == nil {
|
||||
return
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
scene := world.GetSceneById(player.GetSceneId())
|
||||
if entity.GetEntityType() != constant.ENTITY_TYPE_GADGET {
|
||||
return
|
||||
}
|
||||
@@ -1115,7 +1049,7 @@ func (g *Game) handleGadgetEntityAbilityLow(player *model.Player, entityId uint3
|
||||
if world == nil {
|
||||
return
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
scene := world.GetSceneById(player.GetSceneId())
|
||||
entity := scene.GetEntity(entityId)
|
||||
if entity == nil {
|
||||
return
|
||||
|
||||
@@ -260,8 +260,8 @@ func (g *Game) DoGachaReq(player *model.Player, payloadMsg pb.Message) {
|
||||
if itemId > 1000 && itemId < 2000 {
|
||||
avatarId := (itemId % 1000) + 10000000
|
||||
dbAvatar := player.GetDbAvatar()
|
||||
_, exist := dbAvatar.AvatarMap[avatarId]
|
||||
if !exist {
|
||||
avatar := dbAvatar.GetAvatarById(avatarId)
|
||||
if avatar == nil {
|
||||
g.AddPlayerAvatar(player.PlayerId, avatarId)
|
||||
} else {
|
||||
constellationItemId := itemId + 100
|
||||
|
||||
@@ -12,11 +12,6 @@ import (
|
||||
)
|
||||
|
||||
func (g *Game) GCGLogin(player *model.Player) {
|
||||
// player.SceneId = 1076
|
||||
// player.Pos.X = 8.974
|
||||
// player.Pos.Y = 0
|
||||
// player.Pos.Z = 9.373
|
||||
|
||||
// GCG目前可能有点问题先不发送
|
||||
// 以后再慢慢搞
|
||||
|
||||
@@ -34,7 +29,7 @@ func (g *Game) GCGLogin(player *model.Player) {
|
||||
|
||||
// GCGTavernInit GCG酒馆初始化
|
||||
func (g *Game) GCGTavernInit(player *model.Player) {
|
||||
if player.SceneId == 1076 {
|
||||
if player.GetSceneId() == 1076 {
|
||||
// GCG酒馆信息通知
|
||||
g.SendMsg(cmd.GCGTCTavernInfoNotify, player.PlayerId, player.ClientSeq, g.PacketGCGTCTavernInfoNotify(player))
|
||||
// GCG酒馆NPC信息通知
|
||||
@@ -186,7 +181,7 @@ func (g *Game) GCGAskDuelReq(player *model.Player, payloadMsg pb.Message) {
|
||||
// 如果为玩家则更改为玩家信息
|
||||
if controller.controllerType == ControllerType_Player {
|
||||
gcgControllerShowInfo.ProfilePicture.AvatarId = player.HeadImage
|
||||
gcgControllerShowInfo.ProfilePicture.AvatarId = dbAvatar.AvatarMap[player.HeadImage].Costume
|
||||
gcgControllerShowInfo.ProfilePicture.AvatarId = dbAvatar.GetAvatarById(player.HeadImage).Costume
|
||||
}
|
||||
gcgAskDuelRsp.Duel.ShowInfoList = append(gcgAskDuelRsp.Duel.ShowInfoList)
|
||||
}
|
||||
@@ -506,7 +501,7 @@ func (g *Game) PacketGCGGameBriefDataNotify(player *model.Player, businessType p
|
||||
if controller.player != nil {
|
||||
gcgPlayerBriefData.Uid = player.PlayerId
|
||||
gcgPlayerBriefData.ProfilePicture.AvatarId = dbTeam.GetActiveAvatarId()
|
||||
gcgPlayerBriefData.ProfilePicture.CostumeId = dbAvatar.AvatarMap[dbTeam.GetActiveAvatarId()].Costume
|
||||
gcgPlayerBriefData.ProfilePicture.CostumeId = dbAvatar.GetAvatarById(dbTeam.GetActiveAvatarId()).Costume
|
||||
gcgPlayerBriefData.NickName = player.NickName
|
||||
}
|
||||
gcgGameBriefDataNotify.GcgBriefData.PlayerBriefList = append(gcgGameBriefDataNotify.GcgBriefData.PlayerBriefList)
|
||||
|
||||
@@ -49,6 +49,7 @@ func (g *Game) UseItemReq(player *model.Player, payloadMsg pb.Message) {
|
||||
/************************************************** 游戏功能 **************************************************/
|
||||
|
||||
func (g *Game) UseItem(userId uint32, itemId uint32, targetParam ...uint64) {
|
||||
g.EndlessLoopCheck(EndlessLoopCheckTypeUseItem)
|
||||
player := USER_MANAGER.GetOnlineUser(userId)
|
||||
if player == nil {
|
||||
logger.Error("player is nil, uid: %v", userId)
|
||||
@@ -70,8 +71,8 @@ func (g *Game) UseItem(userId uint32, itemId uint32, targetParam ...uint64) {
|
||||
continue
|
||||
}
|
||||
dbAvatar := player.GetDbAvatar()
|
||||
_, exist := dbAvatar.AvatarMap[uint32(avatarId)]
|
||||
if !exist {
|
||||
avatar := dbAvatar.GetAvatarById(uint32(avatarId))
|
||||
if avatar == nil {
|
||||
g.AddPlayerAvatar(userId, uint32(avatarId))
|
||||
} else {
|
||||
g.AddPlayerItem(userId, []*ChangeItem{{ItemId: itemId + 100, ChangeCount: 1}}, true, 0)
|
||||
@@ -342,9 +343,9 @@ func (g *Game) PacketPlayerStoreNotify(player *model.Player) *proto.PlayerStoreN
|
||||
playerStoreNotify := &proto.PlayerStoreNotify{
|
||||
StoreType: proto.StoreType_STORE_PACK,
|
||||
WeightLimit: constant.STORE_PACK_LIMIT_WEIGHT,
|
||||
ItemList: make([]*proto.Item, 0, len(dbItem.ItemMap)+len(dbWeapon.WeaponMap)+len(dbReliquary.ReliquaryMap)),
|
||||
ItemList: make([]*proto.Item, 0, dbItem.GetItemMapLen()+dbWeapon.GetWeaponMapLen()+dbReliquary.GetReliquaryMapLen()),
|
||||
}
|
||||
for _, weapon := range dbWeapon.WeaponMap {
|
||||
for _, weapon := range dbWeapon.GetWeaponMap() {
|
||||
itemDataConfig := gdconf.GetItemDataById(int32(weapon.ItemId))
|
||||
if itemDataConfig == nil {
|
||||
logger.Error("get item data config is nil, itemId: %v", weapon.ItemId)
|
||||
@@ -376,7 +377,7 @@ func (g *Game) PacketPlayerStoreNotify(player *model.Player) *proto.PlayerStoreN
|
||||
}
|
||||
playerStoreNotify.ItemList = append(playerStoreNotify.ItemList, pbItem)
|
||||
}
|
||||
for _, reliquary := range dbReliquary.ReliquaryMap {
|
||||
for _, reliquary := range dbReliquary.GetReliquaryMap() {
|
||||
itemDataConfig := gdconf.GetItemDataById(int32(reliquary.ItemId))
|
||||
if itemDataConfig == nil {
|
||||
logger.Error("get item data config is nil, itemId: %v", reliquary.ItemId)
|
||||
@@ -405,7 +406,7 @@ func (g *Game) PacketPlayerStoreNotify(player *model.Player) *proto.PlayerStoreN
|
||||
}
|
||||
playerStoreNotify.ItemList = append(playerStoreNotify.ItemList, pbItem)
|
||||
}
|
||||
for _, item := range dbItem.ItemMap {
|
||||
for _, item := range dbItem.GetItemMap() {
|
||||
itemDataConfig := gdconf.GetItemDataById(int32(item.ItemId))
|
||||
if itemDataConfig == nil {
|
||||
logger.Error("get item data config is nil, itemId: %v", item.ItemId)
|
||||
|
||||
@@ -50,7 +50,7 @@ func (g *Game) SetPlayerBornDataReq(player *model.Player, payloadMsg pb.Message)
|
||||
weaponId := uint64(g.snowflake.GenId())
|
||||
dbWeapon := player.GetDbWeapon()
|
||||
dbWeapon.AddWeapon(player, uint32(avatarDataConfig.InitialWeapon), weaponId)
|
||||
weapon := dbWeapon.WeaponMap[weaponId]
|
||||
weapon := dbWeapon.GetWeaponById(weaponId)
|
||||
dbAvatar.WearWeapon(dbAvatar.MainCharAvatarId, weapon)
|
||||
dbTeam := player.GetDbTeam()
|
||||
dbTeam.GetActiveTeam().SetAvatarIdList([]uint32{dbAvatar.MainCharAvatarId})
|
||||
@@ -94,11 +94,13 @@ func (g *Game) OnLogin(userId uint32, clientSeq uint32, gateAppId string, player
|
||||
// 初始化
|
||||
player.InitOnlineData()
|
||||
|
||||
if player.SceneId > 100 {
|
||||
if player.GetSceneId() > 100 {
|
||||
player.SceneId = 3
|
||||
player.Pos = &model.Vector{X: 2747, Y: 194, Z: -1719}
|
||||
player.Rot = &model.Vector{X: 0, Y: 307, Z: 0}
|
||||
}
|
||||
player.MpPos = new(model.Vector)
|
||||
player.MpRot = new(model.Vector)
|
||||
|
||||
dbQuest := player.GetDbQuest()
|
||||
for _, quest := range dbQuest.GetQuestMap() {
|
||||
@@ -215,14 +217,14 @@ func (g *Game) CreatePlayer(userId uint32) *model.Player {
|
||||
player.OpenStateMap[constant.OPEN_STATE_SHOP_TYPE_PAIMON] = 1
|
||||
player.OpenStateMap[constant.OPEN_STATE_SHOP_TYPE_VIRTUAL_SHOP] = 1
|
||||
|
||||
sceneLuaConfig := gdconf.GetSceneLuaConfigById(int32(player.SceneId))
|
||||
sceneLuaConfig := gdconf.GetSceneLuaConfigById(int32(player.GetSceneId()))
|
||||
if sceneLuaConfig != nil {
|
||||
bornPos := sceneLuaConfig.SceneConfig.BornPos
|
||||
bornRot := sceneLuaConfig.SceneConfig.BornRot
|
||||
player.Pos = &model.Vector{X: float64(bornPos.X), Y: float64(bornPos.Y), Z: float64(bornPos.Z)}
|
||||
player.Rot = &model.Vector{X: float64(bornRot.X), Y: float64(bornRot.Y), Z: float64(bornRot.Z)}
|
||||
} else {
|
||||
logger.Error("get scene lua config is nil, sceneId: %v, uid: %v", player.SceneId, player.PlayerId)
|
||||
logger.Error("get scene lua config is nil, sceneId: %v, uid: %v", player.GetSceneId(), player.PlayerId)
|
||||
player.Pos = &model.Vector{X: 2747, Y: 194, Z: -1719}
|
||||
player.Rot = &model.Vector{X: 0, Y: 307, Z: 0}
|
||||
}
|
||||
@@ -249,7 +251,7 @@ func (g *Game) OnOffline(userId uint32, changeGsInfo *ChangeGsInfo) {
|
||||
|
||||
// 回写当前血量和元素能量属性
|
||||
dbAvatar := player.GetDbAvatar()
|
||||
for _, avatar := range dbAvatar.AvatarMap {
|
||||
for _, avatar := range dbAvatar.GetAvatarMap() {
|
||||
avatar.CurrHP = float64(avatar.FightPropMap[constant.FIGHT_PROP_CUR_HP])
|
||||
avatarSkillDataConfig := gdconf.GetAvatarEnergySkillConfig(avatar.SkillDepotId)
|
||||
if avatarSkillDataConfig != nil {
|
||||
|
||||
@@ -165,40 +165,6 @@ func (g *Game) PlayerConfirmMatchReq(player *model.Player, payloadMsg pb.Message
|
||||
|
||||
/************************************************** 游戏功能 **************************************************/
|
||||
|
||||
func (g *Game) JoinOtherWorld(player *model.Player, hostPlayer *model.Player) {
|
||||
hostWorld := WORLD_MANAGER.GetWorldById(hostPlayer.WorldId)
|
||||
if hostWorld == nil {
|
||||
logger.Error("host world is nil, worldId: %v, uid: %v", hostPlayer.WorldId, player.PlayerId)
|
||||
return
|
||||
}
|
||||
if hostPlayer.SceneLoadState == model.SceneEnterDone {
|
||||
player.SceneJump = true
|
||||
player.SceneId = hostPlayer.SceneId
|
||||
player.SceneLoadState = model.SceneNone
|
||||
player.SceneEnterReason = uint32(proto.EnterReason_ENTER_REASON_TEAM_JOIN)
|
||||
player.SetPos(hostPlayer.GetPos())
|
||||
player.SetRot(hostPlayer.GetRot())
|
||||
g.WorldAddPlayer(hostWorld, player)
|
||||
|
||||
enterSceneToken := hostWorld.AddEnterSceneContext(&EnterSceneContext{
|
||||
OldSceneId: 0,
|
||||
Uid: player.PlayerId,
|
||||
})
|
||||
|
||||
playerEnterSceneNotify := g.PacketPlayerEnterSceneNotifyMp(
|
||||
player,
|
||||
hostPlayer,
|
||||
proto.EnterType_ENTER_OTHER,
|
||||
hostPlayer.SceneId,
|
||||
hostPlayer.GetPos(),
|
||||
enterSceneToken,
|
||||
)
|
||||
g.SendMsg(cmd.PlayerEnterSceneNotify, player.PlayerId, player.ClientSeq, playerEnterSceneNotify)
|
||||
} else {
|
||||
hostWorld.AddWaitPlayer(player.PlayerId)
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Game) PlayerApplyEnterWorld(player *model.Player, targetUid uint32) {
|
||||
applyFailNotify := func(reason proto.PlayerApplyEnterMpResultNotify_Reason) {
|
||||
playerApplyEnterMpResultNotify := &proto.PlayerApplyEnterMpResultNotify{
|
||||
@@ -227,7 +193,7 @@ func (g *Game) PlayerApplyEnterWorld(player *model.Player, targetUid uint32) {
|
||||
return
|
||||
}
|
||||
gsAppId := USER_MANAGER.GetRemoteUserGsAppId(targetUid)
|
||||
MESSAGE_QUEUE.SendToGs(gsAppId, &mq.NetMsg{
|
||||
g.messageQueue.SendToGs(gsAppId, &mq.NetMsg{
|
||||
MsgType: mq.MsgTypeServer,
|
||||
EventId: mq.ServerPlayerMpReq,
|
||||
ServerMsg: &mq.ServerMsg{
|
||||
@@ -311,7 +277,7 @@ func (g *Game) PlayerDealEnterWorld(hostPlayer *model.Player, otherUid uint32, a
|
||||
return
|
||||
}
|
||||
gsAppId := USER_MANAGER.GetRemoteUserGsAppId(otherUid)
|
||||
MESSAGE_QUEUE.SendToGs(gsAppId, &mq.NetMsg{
|
||||
g.messageQueue.SendToGs(gsAppId, &mq.NetMsg{
|
||||
MsgType: mq.MsgTypeServer,
|
||||
EventId: mq.ServerPlayerMpReq,
|
||||
ServerMsg: &mq.ServerMsg{
|
||||
@@ -351,47 +317,6 @@ func (g *Game) PlayerDealEnterWorld(hostPlayer *model.Player, otherUid uint32, a
|
||||
g.SendMsg(cmd.PlayerApplyEnterMpResultNotify, otherPlayer.PlayerId, otherPlayer.ClientSeq, playerApplyEnterMpResultNotify)
|
||||
}
|
||||
|
||||
func (g *Game) HostEnterMpWorld(hostPlayer *model.Player) {
|
||||
world := WORLD_MANAGER.GetWorldById(hostPlayer.WorldId)
|
||||
if world == nil || world.IsMultiplayerWorld() {
|
||||
return
|
||||
}
|
||||
world.ChangeToMultiplayer()
|
||||
|
||||
worldDataNotify := &proto.WorldDataNotify{
|
||||
WorldPropMap: make(map[uint32]*proto.PropValue),
|
||||
}
|
||||
// 是否多人游戏
|
||||
worldDataNotify.WorldPropMap[2] = g.PacketPropValue(2, object.ConvBoolToInt64(world.IsMultiplayerWorld()))
|
||||
g.SendMsg(cmd.WorldDataNotify, hostPlayer.PlayerId, hostPlayer.ClientSeq, worldDataNotify)
|
||||
|
||||
hostPlayer.SceneJump = false
|
||||
hostPlayer.SceneLoadState = model.SceneNone
|
||||
hostPlayer.SceneEnterReason = uint32(proto.EnterReason_ENTER_REASON_HOST_FROM_SINGLE_TO_MP)
|
||||
|
||||
pos := g.GetPlayerPos(hostPlayer)
|
||||
|
||||
enterSceneToken := world.AddEnterSceneContext(&EnterSceneContext{
|
||||
OldSceneId: hostPlayer.SceneId,
|
||||
OldPos: pos,
|
||||
NewSceneId: hostPlayer.SceneId,
|
||||
NewPos: hostPlayer.GetPos(),
|
||||
NewRot: hostPlayer.GetRot(),
|
||||
OldDungeonPointId: 0,
|
||||
Uid: hostPlayer.PlayerId,
|
||||
})
|
||||
|
||||
hostPlayerEnterSceneNotify := g.PacketPlayerEnterSceneNotifyMp(
|
||||
hostPlayer,
|
||||
hostPlayer,
|
||||
proto.EnterType_ENTER_GOTO,
|
||||
hostPlayer.SceneId,
|
||||
hostPlayer.GetPos(),
|
||||
enterSceneToken,
|
||||
)
|
||||
g.SendMsg(cmd.PlayerEnterSceneNotify, hostPlayer.PlayerId, hostPlayer.ClientSeq, hostPlayerEnterSceneNotify)
|
||||
}
|
||||
|
||||
func (g *Game) PlayerLeaveWorld(player *model.Player, force bool, reason proto.PlayerQuitFromMpNotify_QuitReason) bool {
|
||||
if force {
|
||||
g.SendMsg(cmd.PlayerQuitFromMpNotify, player.PlayerId, player.ClientSeq, &proto.PlayerQuitFromMpNotify{Reason: reason})
|
||||
@@ -416,11 +341,100 @@ func (g *Game) PlayerLeaveWorld(player *model.Player, force bool, reason proto.P
|
||||
return true
|
||||
}
|
||||
|
||||
func (g *Game) JoinOtherWorld(player *model.Player, hostPlayer *model.Player) {
|
||||
hostWorld := WORLD_MANAGER.GetWorldById(hostPlayer.WorldId)
|
||||
if hostWorld == nil {
|
||||
logger.Error("host world is nil, worldId: %v, uid: %v", hostPlayer.WorldId, player.PlayerId)
|
||||
return
|
||||
}
|
||||
if hostPlayer.SceneLoadState == model.SceneEnterDone {
|
||||
player.SceneJump = true
|
||||
player.SceneLoadState = model.SceneNone
|
||||
player.SceneEnterReason = uint32(proto.EnterReason_ENTER_REASON_TEAM_JOIN)
|
||||
player.IsInMp = hostWorld.IsMultiplayerWorld()
|
||||
player.SetSceneId(hostPlayer.GetSceneId())
|
||||
if WORLD_MANAGER.IsAiWorld(hostWorld) {
|
||||
player.SetPos(&model.Vector{X: 500.0, Y: 900.0, Z: -500.0})
|
||||
player.SetRot(new(model.Vector))
|
||||
} else {
|
||||
player.SetPos(hostPlayer.GetPos())
|
||||
player.SetRot(hostPlayer.GetRot())
|
||||
}
|
||||
g.WorldAddPlayer(hostWorld, player)
|
||||
|
||||
enterSceneToken := hostWorld.AddEnterSceneContext(&EnterSceneContext{
|
||||
OldSceneId: 0,
|
||||
Uid: player.PlayerId,
|
||||
})
|
||||
|
||||
playerEnterSceneNotify := g.PacketPlayerEnterSceneNotifyMp(
|
||||
player,
|
||||
hostPlayer,
|
||||
proto.EnterType_ENTER_OTHER,
|
||||
hostPlayer.GetSceneId(),
|
||||
hostPlayer.GetPos(),
|
||||
enterSceneToken,
|
||||
)
|
||||
g.SendMsg(cmd.PlayerEnterSceneNotify, player.PlayerId, player.ClientSeq, playerEnterSceneNotify)
|
||||
} else {
|
||||
hostWorld.AddWaitPlayer(player.PlayerId)
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Game) HostEnterMpWorld(hostPlayer *model.Player) {
|
||||
world := WORLD_MANAGER.GetWorldById(hostPlayer.WorldId)
|
||||
if world == nil || world.IsMultiplayerWorld() {
|
||||
return
|
||||
}
|
||||
|
||||
enterSceneId := hostPlayer.GetSceneId()
|
||||
enterPos := hostPlayer.GetPos()
|
||||
enterRot := hostPlayer.GetRot()
|
||||
world.ChangeToMultiplayer()
|
||||
hostPlayer.SetSceneId(enterSceneId)
|
||||
hostPlayer.SetPos(enterPos)
|
||||
hostPlayer.SetRot(enterRot)
|
||||
|
||||
worldDataNotify := &proto.WorldDataNotify{
|
||||
WorldPropMap: make(map[uint32]*proto.PropValue),
|
||||
}
|
||||
// 是否多人游戏
|
||||
worldDataNotify.WorldPropMap[2] = g.PacketPropValue(2, object.ConvBoolToInt64(world.IsMultiplayerWorld()))
|
||||
g.SendMsg(cmd.WorldDataNotify, hostPlayer.PlayerId, hostPlayer.ClientSeq, worldDataNotify)
|
||||
|
||||
hostPlayer.SceneJump = false
|
||||
hostPlayer.SceneLoadState = model.SceneNone
|
||||
hostPlayer.SceneEnterReason = uint32(proto.EnterReason_ENTER_REASON_HOST_FROM_SINGLE_TO_MP)
|
||||
|
||||
currPos := g.GetPlayerPos(hostPlayer)
|
||||
|
||||
enterSceneToken := world.AddEnterSceneContext(&EnterSceneContext{
|
||||
OldSceneId: enterSceneId,
|
||||
OldPos: currPos,
|
||||
NewSceneId: enterSceneId,
|
||||
NewPos: enterPos,
|
||||
NewRot: enterRot,
|
||||
OldDungeonPointId: 0,
|
||||
Uid: hostPlayer.PlayerId,
|
||||
})
|
||||
|
||||
hostPlayerEnterSceneNotify := g.PacketPlayerEnterSceneNotifyMp(
|
||||
hostPlayer,
|
||||
hostPlayer,
|
||||
proto.EnterType_ENTER_GOTO,
|
||||
enterSceneId,
|
||||
enterPos,
|
||||
enterSceneToken,
|
||||
)
|
||||
g.SendMsg(cmd.PlayerEnterSceneNotify, hostPlayer.PlayerId, hostPlayer.ClientSeq, hostPlayerEnterSceneNotify)
|
||||
}
|
||||
|
||||
func (g *Game) WorldAddPlayer(world *World, player *model.Player) {
|
||||
if world.GetWorldPlayerNum() >= 4 && !WORLD_MANAGER.IsAiWorld(world) {
|
||||
return
|
||||
}
|
||||
_, exist := world.GetAllPlayer()[player.PlayerId]
|
||||
playerMap := world.GetAllPlayer()
|
||||
_, exist := playerMap[player.PlayerId]
|
||||
if exist {
|
||||
return
|
||||
}
|
||||
@@ -452,7 +466,7 @@ func (g *Game) WorldRemovePlayer(world *World, player *model.Player) {
|
||||
g.PlayerLeaveWorld(worldPlayer, true, proto.PlayerQuitFromMpNotify_KICK_BY_HOST_LOGOUT)
|
||||
}
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
scene := world.GetSceneById(player.GetSceneId())
|
||||
|
||||
// 清除玩家的载具
|
||||
for vehicleId, entityId := range player.VehicleInfo.CreateEntityIdMap {
|
||||
@@ -544,7 +558,7 @@ func (g *Game) UpdateWorldScenePlayerInfo(player *model.Player, world *World) {
|
||||
Uid: worldPlayer.PlayerId,
|
||||
PeerId: world.GetPlayerPeerId(worldPlayer),
|
||||
Name: worldPlayer.NickName,
|
||||
SceneId: worldPlayer.SceneId,
|
||||
SceneId: worldPlayer.GetSceneId(),
|
||||
OnlinePlayerInfo: onlinePlayerInfo,
|
||||
})
|
||||
}
|
||||
@@ -554,7 +568,7 @@ func (g *Game) UpdateWorldScenePlayerInfo(player *model.Player, world *World) {
|
||||
g.SendMsg(cmd.SceneTeamUpdateNotify, player.PlayerId, player.ClientSeq, sceneTeamUpdateNotify)
|
||||
|
||||
syncTeamEntityNotify := &proto.SyncTeamEntityNotify{
|
||||
SceneId: player.SceneId,
|
||||
SceneId: player.GetSceneId(),
|
||||
TeamEntityInfoList: make([]*proto.TeamEntityInfo, 0),
|
||||
}
|
||||
if world.IsMultiplayerWorld() {
|
||||
@@ -573,7 +587,7 @@ func (g *Game) UpdateWorldScenePlayerInfo(player *model.Player, world *World) {
|
||||
g.SendMsg(cmd.SyncTeamEntityNotify, player.PlayerId, player.ClientSeq, syncTeamEntityNotify)
|
||||
|
||||
syncScenePlayTeamEntityNotify := &proto.SyncScenePlayTeamEntityNotify{
|
||||
SceneId: player.SceneId,
|
||||
SceneId: player.GetSceneId(),
|
||||
}
|
||||
g.SendMsg(cmd.SyncScenePlayTeamEntityNotify, player.PlayerId, player.ClientSeq, syncScenePlayTeamEntityNotify)
|
||||
}
|
||||
@@ -584,7 +598,7 @@ func (g *Game) ServerPlayerMpReq(playerMpInfo *mq.PlayerMpInfo, gsAppId string)
|
||||
switch playerMpInfo.OriginInfo.CmdName {
|
||||
case "PlayerApplyEnterMpReq":
|
||||
applyFailNotify := func(reason proto.PlayerApplyEnterMpResultNotify_Reason) {
|
||||
MESSAGE_QUEUE.SendToGs(gsAppId, &mq.NetMsg{
|
||||
g.messageQueue.SendToGs(gsAppId, &mq.NetMsg{
|
||||
MsgType: mq.MsgTypeServer,
|
||||
EventId: mq.ServerPlayerMpRsp,
|
||||
ServerMsg: &mq.ServerMsg{
|
||||
@@ -652,7 +666,7 @@ func (g *Game) ServerPlayerMpReq(playerMpInfo *mq.PlayerMpInfo, gsAppId string)
|
||||
}
|
||||
g.SendMsg(cmd.PlayerApplyEnterMpNotify, hostPlayer.PlayerId, hostPlayer.ClientSeq, playerApplyEnterMpNotify)
|
||||
|
||||
MESSAGE_QUEUE.SendToGs(gsAppId, &mq.NetMsg{
|
||||
g.messageQueue.SendToGs(gsAppId, &mq.NetMsg{
|
||||
MsgType: mq.MsgTypeServer,
|
||||
EventId: mq.ServerPlayerMpRsp,
|
||||
ServerMsg: &mq.ServerMsg{
|
||||
|
||||
+54
-78
@@ -88,8 +88,28 @@ func (g *Game) QuestDestroyNpcReq(player *model.Player, payloadMsg pb.Message) {
|
||||
|
||||
/************************************************** 游戏功能 **************************************************/
|
||||
|
||||
// AcceptQuest 接取当前条件下能接取到的全部任务
|
||||
const (
|
||||
QuestExecTypeFinish = iota
|
||||
QuestExecTypeFail
|
||||
QuestExecTypeStart
|
||||
)
|
||||
|
||||
// 通用参数匹配
|
||||
func matchParamEqual(param1 []int32, param2 []int32, num int) bool {
|
||||
if len(param1) != num || len(param2) != num {
|
||||
return false
|
||||
}
|
||||
for i := 0; i < num; i++ {
|
||||
if param1[i] != param2[i] {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// AcceptQuest 接取任务
|
||||
func (g *Game) AcceptQuest(player *model.Player, notifyClient bool) {
|
||||
g.EndlessLoopCheck(EndlessLoopCheckTypeAcceptQuest)
|
||||
dbQuest := player.GetDbQuest()
|
||||
addQuestIdList := make([]uint32, 0)
|
||||
for _, questData := range gdconf.GetQuestDataMap() {
|
||||
@@ -186,12 +206,13 @@ func (g *Game) AcceptQuest(player *model.Player, notifyClient bool) {
|
||||
}
|
||||
}
|
||||
|
||||
// StartQuest 开始一个任务
|
||||
// StartQuest 开始任务
|
||||
func (g *Game) StartQuest(player *model.Player, questId uint32, notifyClient bool) {
|
||||
g.EndlessLoopCheck(EndlessLoopCheckTypeStartQuest)
|
||||
dbQuest := player.GetDbQuest()
|
||||
dbQuest.StartQuest(questId)
|
||||
|
||||
g.QuestExec(player, questId, QuestExecTypeStart)
|
||||
g.ExecQuest(player, questId, QuestExecTypeStart)
|
||||
g.QuestStartTriggerCheck(player, questId)
|
||||
|
||||
if notifyClient {
|
||||
@@ -207,14 +228,9 @@ func (g *Game) StartQuest(player *model.Player, questId uint32, notifyClient boo
|
||||
}
|
||||
}
|
||||
|
||||
const (
|
||||
QuestExecTypeFinish = iota
|
||||
QuestExecTypeFail
|
||||
QuestExecTypeStart
|
||||
)
|
||||
|
||||
// QuestExec 任务执行触发操作
|
||||
func (g *Game) QuestExec(player *model.Player, questId uint32, questExecType int) {
|
||||
// ExecQuest 执行任务
|
||||
func (g *Game) ExecQuest(player *model.Player, questId uint32, questExecType int) {
|
||||
g.EndlessLoopCheck(EndlessLoopCheckTypeExecQuest)
|
||||
questDataConfig := gdconf.GetQuestDataById(int32(questId))
|
||||
if questDataConfig == nil {
|
||||
return
|
||||
@@ -340,9 +356,9 @@ func (g *Game) QuestExec(player *model.Player, questId uint32, questExecType int
|
||||
logger.Error("get world is nil, worldId: %v, uid: %v", player.WorldId, player.PlayerId)
|
||||
continue
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
scene := world.GetSceneById(player.GetSceneId())
|
||||
if scene == nil {
|
||||
logger.Error("scene is nil, sceneId: %v, uid: %v", player.SceneId, player.PlayerId)
|
||||
logger.Error("scene is nil, sceneId: %v, uid: %v", player.GetSceneId(), player.PlayerId)
|
||||
continue
|
||||
}
|
||||
g.ChangeGameTime(scene, uint32(hour*60))
|
||||
@@ -362,21 +378,9 @@ func (g *Game) QuestExec(player *model.Player, questId uint32, questExecType int
|
||||
}
|
||||
}
|
||||
|
||||
// 通用参数匹配
|
||||
func matchParamEqual(param1 []int32, param2 []int32, num int) bool {
|
||||
if len(param1) != num || len(param2) != num {
|
||||
return false
|
||||
}
|
||||
for i := 0; i < num; i++ {
|
||||
if param1[i] != param2[i] {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// TriggerQuest 触发任务
|
||||
func (g *Game) TriggerQuest(player *model.Player, cond int32, complexParam string, param ...int32) {
|
||||
g.EndlessLoopCheck(EndlessLoopCheckTypeTriggerQuest)
|
||||
dbQuest := player.GetDbQuest()
|
||||
updateQuestIdList := make([]uint32, 0)
|
||||
for _, quest := range dbQuest.GetQuestMap() {
|
||||
@@ -480,53 +484,14 @@ func (g *Game) TriggerQuest(player *model.Player, cond int32, complexParam strin
|
||||
g.SendMsg(cmd.QuestListUpdateNotify, player.PlayerId, player.ClientSeq, &proto.QuestListUpdateNotify{
|
||||
QuestList: questList,
|
||||
})
|
||||
parentQuestList := make([]*proto.ParentQuest, 0)
|
||||
parentQuestMap := make(map[int32]bool)
|
||||
for _, questId := range updateQuestIdList {
|
||||
questDataConfig := gdconf.GetQuestDataById(int32(questId))
|
||||
if questDataConfig == nil {
|
||||
continue
|
||||
}
|
||||
_, exist := parentQuestMap[questDataConfig.ParentQuestId]
|
||||
if exist {
|
||||
continue
|
||||
}
|
||||
parentQuestMap[questDataConfig.ParentQuestId] = true
|
||||
finishedParentQuest := true
|
||||
subQuestDataMap := gdconf.GetQuestDataMapByParentQuestId(questDataConfig.ParentQuestId)
|
||||
for _, subQuestData := range subQuestDataMap {
|
||||
quest := dbQuest.GetQuestById(uint32(subQuestData.QuestId))
|
||||
if quest == nil {
|
||||
finishedParentQuest = false
|
||||
break
|
||||
}
|
||||
if quest.State != constant.QUEST_STATE_FINISHED {
|
||||
finishedParentQuest = false
|
||||
break
|
||||
}
|
||||
}
|
||||
if finishedParentQuest {
|
||||
childQuestList := make([]*proto.ChildQuest, 0)
|
||||
for _, subQuestData := range subQuestDataMap {
|
||||
childQuestList = append(childQuestList, &proto.ChildQuest{
|
||||
State: constant.QUEST_STATE_FINISHED,
|
||||
QuestId: uint32(subQuestData.QuestId),
|
||||
})
|
||||
}
|
||||
parentQuestList = append(parentQuestList, &proto.ParentQuest{
|
||||
ParentQuestId: uint32(questDataConfig.ParentQuestId),
|
||||
ParentQuestState: 1,
|
||||
IsFinished: true,
|
||||
ChildQuestList: childQuestList,
|
||||
QuestVar: make([]int32, 5),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
parentQuestList := g.PacketParentQuestList(player, updateQuestIdList)
|
||||
if len(parentQuestList) > 0 {
|
||||
g.SendMsg(cmd.FinishedParentQuestUpdateNotify, player.PlayerId, player.ClientSeq, &proto.FinishedParentQuestUpdateNotify{
|
||||
ParentQuestList: parentQuestList,
|
||||
})
|
||||
}
|
||||
|
||||
for _, questId := range updateQuestIdList {
|
||||
quest := dbQuest.GetQuestById(questId)
|
||||
questDataConfig := gdconf.GetQuestDataById(int32(quest.QuestId))
|
||||
@@ -534,7 +499,7 @@ func (g *Game) TriggerQuest(player *model.Player, cond int32, complexParam strin
|
||||
continue
|
||||
}
|
||||
if quest.State == constant.QUEST_STATE_FINISHED {
|
||||
g.QuestExec(player, quest.QuestId, QuestExecTypeFinish)
|
||||
g.ExecQuest(player, quest.QuestId, QuestExecTypeFinish)
|
||||
if len(questDataConfig.ItemIdList) != 0 {
|
||||
for index, itemId := range questDataConfig.ItemIdList {
|
||||
questItem := []*ChangeItem{{ItemId: uint32(itemId), ChangeCount: uint32(questDataConfig.ItemCountList[index])}}
|
||||
@@ -543,7 +508,7 @@ func (g *Game) TriggerQuest(player *model.Player, cond int32, complexParam strin
|
||||
}
|
||||
}
|
||||
if quest.State == constant.QUEST_STATE_FAILED {
|
||||
g.QuestExec(player, quest.QuestId, QuestExecTypeFail)
|
||||
g.ExecQuest(player, quest.QuestId, QuestExecTypeFail)
|
||||
}
|
||||
}
|
||||
g.AcceptQuest(player, true)
|
||||
@@ -595,21 +560,31 @@ func (g *Game) PacketQuestListNotify(player *model.Player) *proto.QuestListNotif
|
||||
|
||||
// PacketFinishedParentQuestNotify 打包已完成父任务列表通知
|
||||
func (g *Game) PacketFinishedParentQuestNotify(player *model.Player) *proto.FinishedParentQuestNotify {
|
||||
ntf := &proto.FinishedParentQuestNotify{
|
||||
ParentQuestList: make([]*proto.ParentQuest, 0),
|
||||
}
|
||||
dbQuest := player.GetDbQuest()
|
||||
parentQuestMap := make(map[int32]bool)
|
||||
questIdList := make([]uint32, len(dbQuest.QuestMap))
|
||||
for questId := range dbQuest.GetQuestMap() {
|
||||
questIdList = append(questIdList, questId)
|
||||
}
|
||||
ntf := &proto.FinishedParentQuestNotify{
|
||||
ParentQuestList: g.PacketParentQuestList(player, questIdList),
|
||||
}
|
||||
return ntf
|
||||
}
|
||||
|
||||
func (g *Game) PacketParentQuestList(player *model.Player, questIdList []uint32) []*proto.ParentQuest {
|
||||
dbQuest := player.GetDbQuest()
|
||||
parentQuestIdMap := make(map[int32]bool)
|
||||
parentQuestList := make([]*proto.ParentQuest, 0)
|
||||
for questId := range questIdList {
|
||||
questDataConfig := gdconf.GetQuestDataById(int32(questId))
|
||||
if questDataConfig == nil {
|
||||
continue
|
||||
}
|
||||
_, exist := parentQuestMap[questDataConfig.ParentQuestId]
|
||||
_, exist := parentQuestIdMap[questDataConfig.ParentQuestId]
|
||||
if exist {
|
||||
continue
|
||||
}
|
||||
parentQuestMap[questDataConfig.ParentQuestId] = true
|
||||
parentQuestIdMap[questDataConfig.ParentQuestId] = true
|
||||
finishedParentQuest := true
|
||||
subQuestDataMap := gdconf.GetQuestDataMapByParentQuestId(questDataConfig.ParentQuestId)
|
||||
for _, subQuestData := range subQuestDataMap {
|
||||
@@ -631,13 +606,14 @@ func (g *Game) PacketFinishedParentQuestNotify(player *model.Player) *proto.Fini
|
||||
QuestId: uint32(subQuestData.QuestId),
|
||||
})
|
||||
}
|
||||
ntf.ParentQuestList = append(ntf.ParentQuestList, &proto.ParentQuest{
|
||||
parentQuestList = append(parentQuestList, &proto.ParentQuest{
|
||||
ParentQuestId: uint32(questDataConfig.ParentQuestId),
|
||||
ParentQuestState: 1,
|
||||
IsFinished: true,
|
||||
ChildQuestList: childQuestList,
|
||||
QuestVar: make([]int32, 5),
|
||||
})
|
||||
}
|
||||
}
|
||||
return ntf
|
||||
return parentQuestList
|
||||
}
|
||||
+45
-58
@@ -106,16 +106,13 @@ func (g *Game) EnterSceneReadyReq(player *model.Player, payloadMsg pb.Message) {
|
||||
|
||||
if player.SceneJump {
|
||||
oldScene.RemovePlayer(player)
|
||||
|
||||
player.SetSceneId(newSceneId)
|
||||
player.SetPos(newPos)
|
||||
player.SetRot(newRot)
|
||||
|
||||
player.SceneId = newSceneId
|
||||
newScene.AddPlayer(player)
|
||||
} else {
|
||||
player.SetPos(newPos)
|
||||
player.SetRot(newRot)
|
||||
|
||||
for _, worldAvatar := range world.GetPlayerWorldAvatarList(player) {
|
||||
entityId := worldAvatar.GetAvatarEntityId()
|
||||
entity := oldScene.GetEntity(entityId)
|
||||
@@ -126,7 +123,7 @@ func (g *Game) EnterSceneReadyReq(player *model.Player, payloadMsg pb.Message) {
|
||||
}
|
||||
|
||||
enterScenePeerNotify := &proto.EnterScenePeerNotify{
|
||||
DestSceneId: player.SceneId,
|
||||
DestSceneId: player.GetSceneId(),
|
||||
PeerId: world.GetPlayerPeerId(player),
|
||||
HostPeerId: world.GetPlayerPeerId(world.GetOwner()),
|
||||
EnterSceneToken: req.EnterSceneToken,
|
||||
@@ -148,11 +145,11 @@ func (g *Game) SceneInitFinishReq(player *model.Player, payloadMsg pb.Message) {
|
||||
logger.Error("get world is nil, worldId: %v, uid: %v", player.WorldId, player.PlayerId)
|
||||
return
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
scene := world.GetSceneById(player.GetSceneId())
|
||||
|
||||
if world.IsMultiplayerWorld() && world.IsPlayerFirstEnter(player) {
|
||||
guestBeginEnterSceneNotify := &proto.GuestBeginEnterSceneNotify{
|
||||
SceneId: player.SceneId,
|
||||
SceneId: player.GetSceneId(),
|
||||
Uid: player.PlayerId,
|
||||
}
|
||||
g.SendToWorldA(world, cmd.GuestBeginEnterSceneNotify, 0, guestBeginEnterSceneNotify, player.PlayerId)
|
||||
@@ -223,7 +220,7 @@ func (g *Game) SceneInitFinishReq(player *model.Player, payloadMsg pb.Message) {
|
||||
g.SendMsg(cmd.HostPlayerNotify, player.PlayerId, player.ClientSeq, hostPlayerNotify)
|
||||
|
||||
sceneTimeNotify := &proto.SceneTimeNotify{
|
||||
SceneId: player.SceneId,
|
||||
SceneId: player.GetSceneId(),
|
||||
SceneTime: uint64(scene.GetSceneTime()),
|
||||
}
|
||||
g.SendMsg(cmd.SceneTimeNotify, player.PlayerId, player.ClientSeq, sceneTimeNotify)
|
||||
@@ -251,7 +248,7 @@ func (g *Game) SceneInitFinishReq(player *model.Player, payloadMsg pb.Message) {
|
||||
}
|
||||
dbAvatar := player.GetDbAvatar()
|
||||
for _, worldAvatar := range world.GetPlayerWorldAvatarList(player) {
|
||||
avatar := dbAvatar.AvatarMap[worldAvatar.GetAvatarId()]
|
||||
avatar := dbAvatar.GetAvatarById(worldAvatar.GetAvatarId())
|
||||
avatarEnterSceneInfo := &proto.AvatarEnterSceneInfo{
|
||||
AvatarGuid: avatar.Guid,
|
||||
AvatarEntityId: world.GetPlayerWorldAvatarEntityId(player, worldAvatar.GetAvatarId()),
|
||||
@@ -296,9 +293,9 @@ func (g *Game) SceneInitFinishReq(player *model.Player, payloadMsg pb.Message) {
|
||||
if player.SceneEnterReason == uint32(proto.EnterReason_ENTER_REASON_REVIVAL) {
|
||||
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())
|
||||
avatar := dbAvatar.GetAvatarById(worldAvatar.GetAvatarId())
|
||||
if avatar == nil {
|
||||
logger.Error("get avatar is nil, avatarId: %v", worldAvatar.GetAvatarId())
|
||||
continue
|
||||
}
|
||||
if avatar.LifeState != constant.LIFE_STATE_DEAD {
|
||||
@@ -325,7 +322,7 @@ func (g *Game) EnterSceneDoneReq(player *model.Player, payloadMsg pb.Message) {
|
||||
logger.Error("get world is nil, worldId: %v, uid: %v", player.WorldId, player.PlayerId)
|
||||
return
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
scene := world.GetSceneById(player.GetSceneId())
|
||||
|
||||
var visionType = proto.VisionType_VISION_NONE
|
||||
if player.SceneJump {
|
||||
@@ -423,7 +420,7 @@ func (g *Game) PostEnterSceneReq(player *model.Player, payloadMsg pb.Message) {
|
||||
|
||||
if world.IsMultiplayerWorld() && world.IsPlayerFirstEnter(player) {
|
||||
guestPostEnterSceneNotify := &proto.GuestPostEnterSceneNotify{
|
||||
SceneId: player.SceneId,
|
||||
SceneId: player.GetSceneId(),
|
||||
Uid: player.PlayerId,
|
||||
}
|
||||
g.SendToWorldA(world, cmd.GuestPostEnterSceneNotify, 0, guestPostEnterSceneNotify, player.PlayerId)
|
||||
@@ -453,7 +450,7 @@ func (g *Game) SceneEntityDrownReq(player *model.Player, payloadMsg pb.Message)
|
||||
if world == nil {
|
||||
return
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
scene := world.GetSceneById(player.GetSceneId())
|
||||
g.KillEntity(player, scene, req.EntityId, proto.PlayerDieType_PLAYER_DIE_DRAWN)
|
||||
|
||||
sceneEntityDrownRsp := &proto.SceneEntityDrownRsp{
|
||||
@@ -469,7 +466,7 @@ func (g *Game) EntityForceSyncReq(player *model.Player, payloadMsg pb.Message) {
|
||||
if world == nil {
|
||||
return
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
scene := world.GetSceneById(player.GetSceneId())
|
||||
|
||||
motionInfo := req.MotionInfo
|
||||
if motionInfo == nil {
|
||||
@@ -545,7 +542,7 @@ func (g *Game) AddSceneEntityNotify(player *model.Player, visionType proto.Visio
|
||||
if world == nil {
|
||||
return
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
scene := world.GetSceneById(player.GetSceneId())
|
||||
// 如果总数量太多则分包发送
|
||||
times := int(math.Ceil(float64(len(entityIdList)) / float64(ENTITY_MAX_BATCH_SEND_NUM)))
|
||||
for i := 0; i < times; i++ {
|
||||
@@ -608,9 +605,9 @@ func (g *Game) EntityFightPropUpdateNotifyBroadcast(scene *Scene, entity *Entity
|
||||
// KillPlayerAvatar 杀死玩家角色实体
|
||||
func (g *Game) KillPlayerAvatar(player *model.Player, avatarId uint32, dieType proto.PlayerDieType) {
|
||||
dbAvatar := player.GetDbAvatar()
|
||||
avatar, exist := dbAvatar.AvatarMap[avatarId]
|
||||
if !exist {
|
||||
logger.Error("get db avatar is nil, avatarId: %v", avatarId)
|
||||
avatar := dbAvatar.GetAvatarById(avatarId)
|
||||
if avatar == nil {
|
||||
logger.Error("get avatar is nil, avatarId: %v", avatarId)
|
||||
return
|
||||
}
|
||||
world := WORLD_MANAGER.GetWorldById(player.WorldId)
|
||||
@@ -621,19 +618,9 @@ func (g *Game) KillPlayerAvatar(player *model.Player, avatarId uint32, dieType p
|
||||
if worldAvatar == nil {
|
||||
return
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
scene := world.GetSceneById(player.GetSceneId())
|
||||
entity := scene.GetEntity(worldAvatar.GetAvatarEntityId())
|
||||
|
||||
// 触发事件
|
||||
if PLUGIN_MANAGER.TriggerEvent(PluginEventIdPlayerKillAvatar, &PluginEventKillAvatar{
|
||||
PluginEvent: NewPluginEvent(),
|
||||
Player: player,
|
||||
AvatarId: avatarId,
|
||||
DieType: dieType,
|
||||
}) {
|
||||
return
|
||||
}
|
||||
|
||||
avatar.LifeState = constant.LIFE_STATE_DEAD
|
||||
avatar.FightPropMap[constant.FIGHT_PROP_CUR_HP] = 0.0
|
||||
|
||||
@@ -659,12 +646,12 @@ func (g *Game) RevivePlayerAvatar(player *model.Player, avatarId uint32) {
|
||||
if world == nil {
|
||||
return
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
scene := world.GetSceneById(player.GetSceneId())
|
||||
|
||||
dbAvatar := player.GetDbAvatar()
|
||||
avatar, exist := dbAvatar.AvatarMap[avatarId]
|
||||
if !exist {
|
||||
logger.Error("get db avatar is nil, avatarId: %v", avatarId)
|
||||
avatar := dbAvatar.GetAvatarById(avatarId)
|
||||
if avatar == nil {
|
||||
logger.Error("get avatar is nil, avatarId: %v", avatarId)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -748,7 +735,7 @@ func (g *Game) ChangeGadgetState(player *model.Player, entityId uint32, state ui
|
||||
if world == nil {
|
||||
return
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
scene := world.GetSceneById(player.GetSceneId())
|
||||
entity := scene.GetEntity(entityId)
|
||||
if entity == nil {
|
||||
logger.Error("get entity is nil, entityId: %v", entityId)
|
||||
@@ -941,7 +928,7 @@ func (g *Game) AddSceneGroupSuite(player *model.Player, groupId uint32, suiteId
|
||||
if world == nil {
|
||||
return
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
scene := world.GetSceneById(player.GetSceneId())
|
||||
g.AddSceneGroupSuiteCore(player, scene, groupId, suiteId)
|
||||
// ntf := &proto.GroupSuiteNotify{
|
||||
// GroupMap: make(map[uint32]uint32),
|
||||
@@ -1025,7 +1012,7 @@ func (g *Game) RefreshSceneGroupSuite(player *model.Player, groupId uint32, suit
|
||||
return
|
||||
}
|
||||
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
scene := world.GetSceneById(player.GetSceneId())
|
||||
group := scene.GetGroupById(groupId)
|
||||
if group != nil {
|
||||
suite := group.GetSuiteById(suiteId)
|
||||
@@ -1038,7 +1025,7 @@ func (g *Game) RefreshSceneGroupSuite(player *model.Player, groupId uint32, suit
|
||||
scene.RemoveGroupSuite(groupId, suiteId)
|
||||
|
||||
dbWorld := player.GetDbWorld()
|
||||
dbScene := dbWorld.GetSceneById(player.SceneId)
|
||||
dbScene := dbWorld.GetSceneById(player.GetSceneId())
|
||||
dbSceneGroup := dbScene.GetSceneGroupById(groupId)
|
||||
dbSceneGroup.RemoveAllKill()
|
||||
}
|
||||
@@ -1129,7 +1116,7 @@ func (g *Game) SceneGroupCreateEntity(player *model.Player, groupId uint32, conf
|
||||
if world == nil {
|
||||
return
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
scene := world.GetSceneById(player.GetSceneId())
|
||||
var entityConfig any = nil
|
||||
switch entityType {
|
||||
case constant.ENTITY_TYPE_MONSTER:
|
||||
@@ -1181,7 +1168,7 @@ func (g *Game) CreateMonster(player *model.Player, pos *model.Vector, monsterId
|
||||
if world == nil {
|
||||
return 0
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
scene := world.GetSceneById(player.GetSceneId())
|
||||
if scene == nil {
|
||||
return 0
|
||||
}
|
||||
@@ -1224,7 +1211,7 @@ func (g *Game) CreateGadget(player *model.Player, pos *model.Vector, gadgetId ui
|
||||
if world == nil {
|
||||
return 0
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
scene := world.GetSceneById(player.GetSceneId())
|
||||
if pos == nil {
|
||||
pos = g.GetPlayerPos(player)
|
||||
pos.X += random.GetRandomFloat64(1.0, 10.0)
|
||||
@@ -1278,7 +1265,7 @@ func (g *Game) GetPosIsInWeatherArea(posX, posZ float64, sceneId, weatherAreaId
|
||||
// GetPlayerInWeatherAreaId 获取玩家所在的天气区域id
|
||||
func (g *Game) GetPlayerInWeatherAreaId(player *model.Player, newPos *model.Vector) uint32 {
|
||||
// 获取场景天气区域配置表
|
||||
sceneWeatherAreaMap := gdconf.GetSceneWeatherAreaMap()[int32(player.SceneId)]
|
||||
sceneWeatherAreaMap := gdconf.GetSceneWeatherAreaMap()[int32(player.GetSceneId())]
|
||||
if sceneWeatherAreaMap == nil {
|
||||
return 0
|
||||
}
|
||||
@@ -1287,7 +1274,7 @@ func (g *Game) GetPlayerInWeatherAreaId(player *model.Player, newPos *model.Vect
|
||||
var priority int32
|
||||
// 玩家所在的天气区域
|
||||
for _, area := range sceneWeatherAreaMap {
|
||||
isInside := g.GetPosIsInWeatherArea(newPos.X, newPos.Z, player.SceneId, uint32(area.AreaId))
|
||||
isInside := g.GetPosIsInWeatherArea(newPos.X, newPos.Z, player.GetSceneId(), uint32(area.AreaId))
|
||||
// 获取天气数据配置表
|
||||
weatherConfig := gdconf.GetWeatherDataById(area.AreaId)
|
||||
if weatherConfig == nil {
|
||||
@@ -1314,7 +1301,7 @@ func (g *Game) SceneWeatherAreaCheck(player *model.Player, oldPos *model.Vector,
|
||||
return
|
||||
}
|
||||
// 如果玩家还在历史区域内就不获取当前所在区域
|
||||
if g.GetPosIsInWeatherArea(newPos.X, newPos.Z, player.SceneId, player.WeatherInfo.WeatherAreaId) {
|
||||
if g.GetPosIsInWeatherArea(newPos.X, newPos.Z, player.GetSceneId(), player.WeatherInfo.WeatherAreaId) {
|
||||
return
|
||||
}
|
||||
// 获取当前所在的天气区域
|
||||
@@ -1417,14 +1404,14 @@ func (g *Game) PacketPlayerEnterSceneNotifyLogin(player *model.Player) *proto.Pl
|
||||
logger.Error("get world is nil, worldId: %v, uid: %v", player.WorldId, player.PlayerId)
|
||||
return new(proto.PlayerEnterSceneNotify)
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
scene := world.GetSceneById(player.GetSceneId())
|
||||
enterSceneToken := world.AddEnterSceneContext(&EnterSceneContext{
|
||||
OldSceneId: 0,
|
||||
Uid: player.PlayerId,
|
||||
})
|
||||
pos := player.GetPos()
|
||||
playerEnterSceneNotify := &proto.PlayerEnterSceneNotify{
|
||||
SceneId: player.SceneId,
|
||||
SceneId: player.GetSceneId(),
|
||||
Pos: &proto.Vector{X: float32(pos.X), Y: float32(pos.Y), Z: float32(pos.Z)},
|
||||
SceneBeginTime: uint64(scene.GetSceneCreateTime()),
|
||||
Type: proto.EnterType_ENTER_SELF,
|
||||
@@ -1437,12 +1424,12 @@ func (g *Game) PacketPlayerEnterSceneNotifyLogin(player *model.Player) *proto.Pl
|
||||
SceneTagIdList: make([]uint32, 0),
|
||||
}
|
||||
SceneTransactionSeq++
|
||||
playerEnterSceneNotify.SceneTransaction = strconv.Itoa(int(player.SceneId)) + "-" +
|
||||
playerEnterSceneNotify.SceneTransaction = strconv.Itoa(int(player.GetSceneId())) + "-" +
|
||||
strconv.Itoa(int(player.PlayerId)) + "-" +
|
||||
strconv.Itoa(int(time.Now().Unix())) + "-" +
|
||||
strconv.Itoa(int(SceneTransactionSeq))
|
||||
for _, sceneTagDataConfig := range gdconf.GetSceneTagDataMap() {
|
||||
if uint32(sceneTagDataConfig.SceneId) == player.SceneId {
|
||||
if uint32(sceneTagDataConfig.SceneId) == player.GetSceneId() {
|
||||
playerEnterSceneNotify.SceneTagIdList = append(playerEnterSceneNotify.SceneTagIdList, uint32(sceneTagDataConfig.SceneTagId))
|
||||
}
|
||||
}
|
||||
@@ -1485,9 +1472,9 @@ func (g *Game) PacketPlayerEnterSceneNotifyCore(
|
||||
logger.Error("get world is nil, worldId: %v, uid: %v", player.WorldId, player.PlayerId)
|
||||
return new(proto.PlayerEnterSceneNotify)
|
||||
}
|
||||
scene := world.GetSceneById(targetPlayer.SceneId)
|
||||
scene := world.GetSceneById(targetPlayer.GetSceneId())
|
||||
playerEnterSceneNotify := &proto.PlayerEnterSceneNotify{
|
||||
PrevSceneId: player.SceneId,
|
||||
PrevSceneId: player.GetSceneId(),
|
||||
PrevPos: &proto.Vector{X: float32(player.GetPos().X), Y: float32(player.GetPos().Y), Z: float32(player.GetPos().Z)},
|
||||
SceneId: sceneId,
|
||||
Pos: &proto.Vector{X: float32(pos.X), Y: float32(pos.Y), Z: float32(pos.Z)},
|
||||
@@ -1542,9 +1529,9 @@ func (g *Game) PacketSceneEntityInfoAvatar(scene *Scene, player *model.Player, a
|
||||
}
|
||||
worldAvatar := scene.GetWorld().GetWorldAvatarByEntityId(entity.GetId())
|
||||
dbAvatar := player.GetDbAvatar()
|
||||
avatar, ok := dbAvatar.AvatarMap[worldAvatar.GetAvatarId()]
|
||||
if !ok {
|
||||
logger.Error("avatar error, avatarId: %v", worldAvatar.GetAvatarId())
|
||||
avatar := dbAvatar.GetAvatarById(worldAvatar.GetAvatarId())
|
||||
if avatar == nil {
|
||||
logger.Error("get avatar is nil, avatarId: %v", worldAvatar.GetAvatarId())
|
||||
return new(proto.SceneEntityInfo)
|
||||
}
|
||||
sceneEntityInfo := &proto.SceneEntityInfo{
|
||||
@@ -1748,9 +1735,9 @@ func (g *Game) PacketSceneEntityInfoGadget(player *model.Player, scene *Scene, e
|
||||
|
||||
func (g *Game) PacketSceneAvatarInfo(scene *Scene, player *model.Player, avatarId uint32) *proto.SceneAvatarInfo {
|
||||
dbAvatar := player.GetDbAvatar()
|
||||
avatar, ok := dbAvatar.AvatarMap[avatarId]
|
||||
if !ok {
|
||||
logger.Error("avatar error, avatarId: %v", avatarId)
|
||||
avatar := dbAvatar.GetAvatarById(avatarId)
|
||||
if avatar == nil {
|
||||
logger.Error("get avatar is nil, avatarId: %v", avatarId)
|
||||
return new(proto.SceneAvatarInfo)
|
||||
}
|
||||
equipIdList := make([]uint32, len(avatar.EquipReliquaryMap)+1)
|
||||
@@ -1900,7 +1887,7 @@ func (g *Game) PacketSceneGadgetInfoVehicle(gadgetVehicleEntity *GadgetVehicleEn
|
||||
|
||||
func (g *Game) PacketDelTeamEntityNotify(world *World, player *model.Player) *proto.DelTeamEntityNotify {
|
||||
delTeamEntityNotify := &proto.DelTeamEntityNotify{
|
||||
SceneId: player.SceneId,
|
||||
SceneId: player.GetSceneId(),
|
||||
DelEntityIdList: []uint32{world.GetPlayerTeamEntityId(player)},
|
||||
}
|
||||
return delTeamEntityNotify
|
||||
|
||||
@@ -112,8 +112,8 @@ func (g *Game) SetPlayerHeadImageReq(player *model.Player, payloadMsg pb.Message
|
||||
req := payloadMsg.(*proto.SetPlayerHeadImageReq)
|
||||
avatarId := req.AvatarId
|
||||
dbAvatar := player.GetDbAvatar()
|
||||
_, exist := dbAvatar.AvatarMap[avatarId]
|
||||
if !exist {
|
||||
avatar := dbAvatar.GetAvatarById(avatarId)
|
||||
if avatar == nil {
|
||||
logger.Error("the head img of the avatar not exist, uid: %v", player.PlayerId)
|
||||
return
|
||||
}
|
||||
@@ -230,7 +230,7 @@ func (g *Game) AskAddFriendReq(player *model.Player, payloadMsg pb.Message) {
|
||||
if USER_MANAGER.GetRemoteUserOnlineState(targetUid) {
|
||||
// 远程在线玩家
|
||||
gsAppId := USER_MANAGER.GetRemoteUserGsAppId(targetUid)
|
||||
MESSAGE_QUEUE.SendToGs(gsAppId, &mq.NetMsg{
|
||||
g.messageQueue.SendToGs(gsAppId, &mq.NetMsg{
|
||||
MsgType: mq.MsgTypeServer,
|
||||
EventId: mq.ServerAddFriendNotify,
|
||||
ServerMsg: &mq.ServerMsg{
|
||||
@@ -327,7 +327,7 @@ func (g *Game) DealAddFriendReq(player *model.Player, payloadMsg pb.Message) {
|
||||
if USER_MANAGER.GetRemoteUserOnlineState(targetUid) {
|
||||
// 远程在线玩家
|
||||
gsAppId := USER_MANAGER.GetRemoteUserGsAppId(targetUid)
|
||||
MESSAGE_QUEUE.SendToGs(gsAppId, &mq.NetMsg{
|
||||
g.messageQueue.SendToGs(gsAppId, &mq.NetMsg{
|
||||
MsgType: mq.MsgTypeServer,
|
||||
EventId: mq.ServerAddFriendNotify,
|
||||
ServerMsg: &mq.ServerMsg{
|
||||
|
||||
@@ -171,7 +171,7 @@ func (g *Game) RestoreCountStaminaHandler(player *model.Player) {
|
||||
if world == nil {
|
||||
return
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
scene := world.GetSceneById(player.GetSceneId())
|
||||
// 处理载具
|
||||
// 遍历玩家创建的载具实体
|
||||
for _, entityId := range player.VehicleInfo.CreateEntityIdMap {
|
||||
@@ -214,7 +214,7 @@ func (g *Game) VehicleRestoreStaminaHandler(player *model.Player) {
|
||||
if world == nil {
|
||||
return
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
scene := world.GetSceneById(player.GetSceneId())
|
||||
// 遍历玩家创建的载具实体
|
||||
for _, entityId := range player.VehicleInfo.CreateEntityIdMap {
|
||||
// 获取载具实体
|
||||
@@ -243,7 +243,7 @@ func (g *Game) SustainStaminaHandler(player *model.Player) {
|
||||
if world == nil {
|
||||
return
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
scene := world.GetSceneById(player.GetSceneId())
|
||||
// 获取玩家处于的载具实体
|
||||
entity := scene.GetEntity(player.VehicleInfo.InVehicleEntityId)
|
||||
if entity == nil {
|
||||
@@ -375,9 +375,9 @@ func (g *Game) HandleDrown(player *model.Player, stamina uint32) {
|
||||
}
|
||||
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())
|
||||
avatar := dbAvatar.GetAvatarById(worldAvatar.GetAvatarId())
|
||||
if avatar == nil {
|
||||
logger.Error("get avatar is nil, avatarId: %v", worldAvatar.GetAvatarId())
|
||||
continue
|
||||
}
|
||||
if avatar.LifeState != constant.LIFE_STATE_ALIVE {
|
||||
|
||||
+14
-14
@@ -66,7 +66,7 @@ func (g *Game) SetUpAvatarTeamReq(player *model.Player, payloadMsg pb.Message) {
|
||||
g.SendError(cmd.SetUpAvatarTeamRsp, player, &proto.SetUpAvatarTeamRsp{})
|
||||
return
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
scene := world.GetSceneById(player.GetSceneId())
|
||||
|
||||
oldAvatarEntity := world.GetPlayerActiveAvatarEntity(player)
|
||||
g.ChangeTeam(player, teamId, avatarIdList, currAvatar.AvatarId)
|
||||
@@ -105,7 +105,7 @@ func (g *Game) ChooseCurAvatarTeamReq(player *model.Player, payloadMsg pb.Messag
|
||||
g.SendError(cmd.ChooseCurAvatarTeamRsp, player, &proto.ChooseCurAvatarTeamRsp{})
|
||||
return
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
scene := world.GetSceneById(player.GetSceneId())
|
||||
if world.IsMultiplayerWorld() {
|
||||
g.SendError(cmd.ChooseCurAvatarTeamRsp, player, &proto.ChooseCurAvatarTeamRsp{})
|
||||
return
|
||||
@@ -178,7 +178,7 @@ func (g *Game) ChangeMpTeamAvatarReq(player *model.Player, payloadMsg pb.Message
|
||||
logger.Error("get world is nil, worldId: %v, uid: %v", player.WorldId, player.PlayerId)
|
||||
return
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
scene := world.GetSceneById(player.GetSceneId())
|
||||
if WORLD_MANAGER.IsAiWorld(world) || !world.IsMultiplayerWorld() || len(avatarIdList) == 0 || len(avatarIdList) > 4 {
|
||||
g.SendError(cmd.ChangeMpTeamAvatarRsp, player, &proto.ChangeMpTeamAvatarRsp{})
|
||||
return
|
||||
@@ -226,7 +226,7 @@ func (g *Game) AvatarDieAnimationEndReq(player *model.Player, payloadMsg pb.Mess
|
||||
if world == nil {
|
||||
return
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
scene := world.GetSceneById(player.GetSceneId())
|
||||
|
||||
// 触发事件
|
||||
if PLUGIN_MANAGER.TriggerEvent(PluginEventIdAvatarDieAnimationEnd, &PluginEventAvatarDieAnimationEnd{
|
||||
@@ -246,7 +246,7 @@ func (g *Game) AvatarDieAnimationEndReq(player *model.Player, payloadMsg pb.Mess
|
||||
g.TeleportPlayer(
|
||||
player,
|
||||
proto.EnterReason_ENTER_REASON_REVIVAL,
|
||||
player.SceneId,
|
||||
player.GetSceneId(),
|
||||
player.GetPos(),
|
||||
player.GetRot(),
|
||||
0,
|
||||
@@ -256,9 +256,9 @@ func (g *Game) AvatarDieAnimationEndReq(player *model.Player, payloadMsg pb.Mess
|
||||
targetAvatarId := uint32(0)
|
||||
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())
|
||||
avatar := dbAvatar.GetAvatarById(worldAvatar.GetAvatarId())
|
||||
if avatar == nil {
|
||||
logger.Error("get avatar is nil, avatarId: %v", worldAvatar.GetAvatarId())
|
||||
continue
|
||||
}
|
||||
if avatar.LifeState != constant.LIFE_STATE_ALIVE {
|
||||
@@ -291,7 +291,7 @@ func (g *Game) WorldPlayerReviveReq(player *model.Player, payloadMsg pb.Message)
|
||||
g.TeleportPlayer(
|
||||
player,
|
||||
proto.EnterReason_ENTER_REASON_REVIVAL,
|
||||
player.SceneId,
|
||||
player.GetSceneId(),
|
||||
player.GetPos(),
|
||||
player.GetRot(),
|
||||
0,
|
||||
@@ -308,7 +308,7 @@ func (g *Game) ChangeAvatar(player *model.Player, targetAvatarId uint32) {
|
||||
logger.Error("get world is nil, worldId: %v, uid: %v", player.WorldId, player.PlayerId)
|
||||
return
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
scene := world.GetSceneById(player.GetSceneId())
|
||||
oldAvatarId := world.GetPlayerActiveAvatarId(player)
|
||||
if targetAvatarId == oldAvatarId {
|
||||
logger.Error("can not change to the same avatar, uid: %v, oldAvatarId: %v, targetAvatarId: %v", player.PlayerId, oldAvatarId, targetAvatarId)
|
||||
@@ -370,7 +370,7 @@ func (g *Game) ChangeTeam(player *model.Player, teamId uint32, avatarIdList []ui
|
||||
AvatarGuidList: make([]uint64, 0),
|
||||
}
|
||||
for _, avatarId := range team.GetAvatarIdList() {
|
||||
avatarTeam.AvatarGuidList = append(avatarTeam.AvatarGuidList, dbAvatar.AvatarMap[avatarId].Guid)
|
||||
avatarTeam.AvatarGuidList = append(avatarTeam.AvatarGuidList, dbAvatar.GetAvatarById(avatarId).Guid)
|
||||
}
|
||||
avatarTeamUpdateNotify.AvatarTeamMap[uint32(teamIndex)+1] = avatarTeam
|
||||
}
|
||||
@@ -407,9 +407,9 @@ func (g *Game) PacketSceneTeamUpdateNotify(world *World, player *model.Player) *
|
||||
logger.Error("player is nil, uid: %v", worldAvatar.GetUid())
|
||||
continue
|
||||
}
|
||||
worldPlayerScene := world.GetSceneById(worldPlayer.SceneId)
|
||||
worldPlayerScene := world.GetSceneById(worldPlayer.GetSceneId())
|
||||
worldPlayerDbAvatar := worldPlayer.GetDbAvatar()
|
||||
worldPlayerAvatar := worldPlayerDbAvatar.AvatarMap[worldAvatar.GetAvatarId()]
|
||||
worldPlayerAvatar := worldPlayerDbAvatar.GetAvatarById(worldAvatar.GetAvatarId())
|
||||
equipIdList := make([]uint32, 0)
|
||||
weapon := worldPlayerAvatar.EquipWeapon
|
||||
equipIdList = append(equipIdList, weapon.ItemId)
|
||||
@@ -419,7 +419,7 @@ func (g *Game) PacketSceneTeamUpdateNotify(world *World, player *model.Player) *
|
||||
sceneTeamAvatar := &proto.SceneTeamAvatar{
|
||||
PlayerUid: worldPlayer.PlayerId,
|
||||
AvatarGuid: worldPlayerAvatar.Guid,
|
||||
SceneId: worldPlayer.SceneId,
|
||||
SceneId: worldPlayer.GetSceneId(),
|
||||
EntityId: world.GetPlayerWorldAvatarEntityId(worldPlayer, worldAvatar.GetAvatarId()),
|
||||
SceneEntityInfo: g.PacketSceneEntityInfoAvatar(worldPlayerScene, worldPlayer, worldAvatar.GetAvatarId()),
|
||||
WeaponGuid: worldPlayerAvatar.EquipWeapon.Guid,
|
||||
|
||||
@@ -25,7 +25,7 @@ func (g *Game) CreateVehicleReq(player *model.Player, payloadMsg pb.Message) {
|
||||
g.SendError(cmd.VehicleInteractRsp, player, &proto.VehicleInteractRsp{})
|
||||
return
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
scene := world.GetSceneById(player.GetSceneId())
|
||||
|
||||
// 创建载具冷却时间
|
||||
createVehicleCd := int64(5000) // TODO 冷却时间读取配置表
|
||||
@@ -76,7 +76,7 @@ func (g *Game) VehicleInteractReq(player *model.Player, payloadMsg pb.Message) {
|
||||
g.SendError(cmd.VehicleInteractRsp, player, &proto.VehicleInteractRsp{})
|
||||
return
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
scene := world.GetSceneById(player.GetSceneId())
|
||||
|
||||
// 获取载具实体
|
||||
entity := scene.GetEntity(req.EntityId)
|
||||
@@ -95,7 +95,7 @@ func (g *Game) VehicleInteractReq(player *model.Player, payloadMsg pb.Message) {
|
||||
|
||||
dbTeam := player.GetDbTeam()
|
||||
dbAvatar := player.GetDbAvatar()
|
||||
avatarGuid := dbAvatar.AvatarMap[dbTeam.GetActiveAvatarId()].Guid
|
||||
avatarGuid := dbAvatar.GetAvatarById(dbTeam.GetActiveAvatarId()).Guid
|
||||
|
||||
switch req.InteractType {
|
||||
case proto.VehicleInteractType_VEHICLE_INTERACT_IN:
|
||||
@@ -116,7 +116,7 @@ func (g *Game) VehicleDestroyMotion(player *model.Player, entity *Entity, state
|
||||
logger.Error("get world is nil, worldId: %v, uid: %v", player.WorldId, player.PlayerId)
|
||||
return
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
scene := world.GetSceneById(player.GetSceneId())
|
||||
|
||||
// 状态等于 MOTION_STATE_DESTROY_VEHICLE 代表请求销毁
|
||||
if state == proto.MotionState_MOTION_DESTROY_VEHICLE {
|
||||
@@ -167,7 +167,7 @@ func (g *Game) DestroyVehicleEntity(player *model.Player, scene *Scene, vehicleI
|
||||
// 离开载具
|
||||
dbTeam := player.GetDbTeam()
|
||||
dbAvatar := player.GetDbAvatar()
|
||||
g.ExitVehicle(player, entity, dbAvatar.AvatarMap[dbTeam.GetActiveAvatarId()].Guid)
|
||||
g.ExitVehicle(player, entity, dbAvatar.GetAvatarById(dbTeam.GetActiveAvatarId()).Guid)
|
||||
}
|
||||
// 删除已创建的载具
|
||||
scene.DestroyEntity(entity.GetId())
|
||||
|
||||
@@ -158,9 +158,9 @@ func (g *Game) WeaponAwakenReq(player *model.Player, payloadMsg pb.Message) {
|
||||
g.SendMsg(cmd.StoreItemChangeNotify, player.PlayerId, player.ClientSeq, g.PacketStoreItemChangeNotifyByWeapon(weapon))
|
||||
// 获取持有该武器的角色
|
||||
dbAvatar := player.GetDbAvatar()
|
||||
avatar, ok := dbAvatar.AvatarMap[weapon.AvatarId]
|
||||
avatar := dbAvatar.GetAvatarById(weapon.AvatarId)
|
||||
// 武器可能没被任何角色装备 仅在被装备时更新面板
|
||||
if ok {
|
||||
if avatar != nil {
|
||||
weaponAwakenRsp.AvatarGuid = avatar.Guid
|
||||
// 角色更新面板
|
||||
g.UpdatePlayerAvatarFightProp(player.PlayerId, avatar.AvatarId)
|
||||
@@ -262,9 +262,9 @@ func (g *Game) WeaponPromoteReq(player *model.Player, payloadMsg pb.Message) {
|
||||
g.SendMsg(cmd.StoreItemChangeNotify, player.PlayerId, player.ClientSeq, g.PacketStoreItemChangeNotifyByWeapon(weapon))
|
||||
// 获取持有该武器的角色
|
||||
dbAvatar := player.GetDbAvatar()
|
||||
avatar, ok := dbAvatar.AvatarMap[weapon.AvatarId]
|
||||
avatar := dbAvatar.GetAvatarById(weapon.AvatarId)
|
||||
// 武器可能没被任何角色装备 仅在被装备时更新面板
|
||||
if ok {
|
||||
if avatar != nil {
|
||||
// 角色更新面板
|
||||
g.UpdatePlayerAvatarFightProp(player.PlayerId, avatar.AvatarId)
|
||||
}
|
||||
@@ -390,9 +390,9 @@ func (g *Game) WeaponUpgradeReq(player *model.Player, payloadMsg pb.Message) {
|
||||
|
||||
// 获取持有该武器的角色
|
||||
dbAvatar := player.GetDbAvatar()
|
||||
avatar, ok := dbAvatar.AvatarMap[weapon.AvatarId]
|
||||
avatar := dbAvatar.GetAvatarById(weapon.AvatarId)
|
||||
// 武器可能没被任何角色装备 仅在被装备时更新面板
|
||||
if ok {
|
||||
if avatar != nil {
|
||||
// 角色更新面板
|
||||
g.UpdatePlayerAvatarFightProp(player.PlayerId, avatar.AvatarId)
|
||||
}
|
||||
|
||||
+62
-58
@@ -273,9 +273,9 @@ func (g *Game) ChangeGameTimeReq(player *model.Player, payloadMsg pb.Message) {
|
||||
logger.Error("get world is nil, worldId: %v, uid: %v", player.WorldId, player.PlayerId)
|
||||
return
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
scene := world.GetSceneById(player.GetSceneId())
|
||||
if scene == nil {
|
||||
logger.Error("scene is nil, sceneId: %v, uid: %v", player.SceneId, player.PlayerId)
|
||||
logger.Error("scene is nil, sceneId: %v, uid: %v", player.GetSceneId(), player.PlayerId)
|
||||
return
|
||||
}
|
||||
logger.Debug("change game time, gameTime: %v, uid: %v", gameTime, player.PlayerId)
|
||||
@@ -411,64 +411,68 @@ func (g *Game) GadgetInteractReq(player *model.Player, payloadMsg pb.Message) {
|
||||
logger.Error("get world is nil, worldId: %v, uid: %v", player.WorldId, player.PlayerId)
|
||||
return
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
scene := world.GetSceneById(player.GetSceneId())
|
||||
entity := scene.GetEntity(req.GadgetEntityId)
|
||||
if entity == nil {
|
||||
logger.Error("get entity is nil, entityId: %v, uid: %v", req.GadgetEntityId, player.PlayerId)
|
||||
return
|
||||
}
|
||||
if entity.GetEntityType() != constant.ENTITY_TYPE_GADGET {
|
||||
logger.Error("entity type is not gadget, entityType: %v, uid: %v", entity.GetEntityType(), player.PlayerId)
|
||||
return
|
||||
}
|
||||
gadgetEntity := entity.GetGadgetEntity()
|
||||
gadgetDataConfig := gdconf.GetGadgetDataById(int32(gadgetEntity.GetGadgetId()))
|
||||
if gadgetDataConfig == nil {
|
||||
logger.Error("get gadget data config is nil, gadgetId: %v, uid: %v", gadgetEntity.GetGadgetId(), player.PlayerId)
|
||||
return
|
||||
}
|
||||
logger.Debug("[GadgetInteractReq] GadgetData: %+v, EntityId: %v, uid: %v", gadgetDataConfig, entity.GetId(), player.PlayerId)
|
||||
|
||||
interactType := proto.InteractType_INTERACT_NONE
|
||||
switch gadgetDataConfig.Type {
|
||||
case constant.GADGET_TYPE_GADGET:
|
||||
// 掉落物捡起
|
||||
interactType = proto.InteractType_INTERACT_PICK_ITEM
|
||||
gadgetNormalEntity := gadgetEntity.GetGadgetNormalEntity()
|
||||
g.AddPlayerItem(player.PlayerId, []*ChangeItem{{
|
||||
ItemId: gadgetNormalEntity.GetItemId(),
|
||||
ChangeCount: 1,
|
||||
}}, true, 0)
|
||||
g.KillEntity(player, scene, entity.GetId(), proto.PlayerDieType_PLAYER_DIE_NONE)
|
||||
case constant.GADGET_TYPE_ENERGY_BALL:
|
||||
// TODO 元素能量球吸收
|
||||
interactType = proto.InteractType_INTERACT_PICK_ITEM
|
||||
activeAvatarId := world.GetPlayerActiveAvatarId(player)
|
||||
g.AddPlayerAvatarEnergy(player.PlayerId, activeAvatarId, 10.0, false)
|
||||
case constant.GADGET_TYPE_GATHER_OBJECT:
|
||||
// 采集物摘取
|
||||
interactType = proto.InteractType_INTERACT_GATHER
|
||||
gadgetNormalEntity := gadgetEntity.GetGadgetNormalEntity()
|
||||
g.AddPlayerItem(player.PlayerId, []*ChangeItem{{
|
||||
ItemId: gadgetNormalEntity.GetItemId(),
|
||||
ChangeCount: 1,
|
||||
}}, true, 0)
|
||||
g.KillEntity(player, scene, entity.GetId(), proto.PlayerDieType_PLAYER_DIE_NONE)
|
||||
case constant.GADGET_TYPE_CHEST:
|
||||
// 宝箱开启
|
||||
interactType = proto.InteractType_INTERACT_OPEN_CHEST
|
||||
// 宝箱交互结束 开启宝箱
|
||||
if req.OpType == proto.InterOpType_INTER_OP_FINISH {
|
||||
// 随机掉落
|
||||
g.chestDrop(player, entity)
|
||||
// 更新宝箱状态
|
||||
g.SendMsg(cmd.WorldChestOpenNotify, player.PlayerId, player.ClientSeq, &proto.WorldChestOpenNotify{
|
||||
GroupId: entity.GetGroupId(),
|
||||
SceneId: scene.GetId(),
|
||||
ConfigId: entity.GetConfigId(),
|
||||
})
|
||||
g.ChangeGadgetState(player, entity.GetId(), constant.GADGET_STATE_CHEST_OPENED)
|
||||
g.KillEntity(player, scene, entity.GetId(), proto.PlayerDieType_PLAYER_DIE_NONE)
|
||||
switch entity.GetEntityType() {
|
||||
case constant.ENTITY_TYPE_GADGET:
|
||||
gadgetEntity := entity.GetGadgetEntity()
|
||||
gadgetDataConfig := gdconf.GetGadgetDataById(int32(gadgetEntity.GetGadgetId()))
|
||||
if gadgetDataConfig == nil {
|
||||
logger.Error("get gadget data config is nil, gadgetId: %v, uid: %v", gadgetEntity.GetGadgetId(), player.PlayerId)
|
||||
return
|
||||
}
|
||||
logger.Debug("[GadgetInteractReq] GadgetData: %+v, EntityId: %v, uid: %v", gadgetDataConfig, entity.GetId(), player.PlayerId)
|
||||
switch gadgetDataConfig.Type {
|
||||
case constant.GADGET_TYPE_GADGET:
|
||||
// 掉落物捡起
|
||||
interactType = proto.InteractType_INTERACT_PICK_ITEM
|
||||
gadgetNormalEntity := gadgetEntity.GetGadgetNormalEntity()
|
||||
g.AddPlayerItem(player.PlayerId, []*ChangeItem{{
|
||||
ItemId: gadgetNormalEntity.GetItemId(),
|
||||
ChangeCount: 1,
|
||||
}}, true, 0)
|
||||
g.KillEntity(player, scene, entity.GetId(), proto.PlayerDieType_PLAYER_DIE_NONE)
|
||||
case constant.GADGET_TYPE_ENERGY_BALL:
|
||||
// TODO 元素能量球吸收
|
||||
interactType = proto.InteractType_INTERACT_PICK_ITEM
|
||||
activeAvatarId := world.GetPlayerActiveAvatarId(player)
|
||||
g.AddPlayerAvatarEnergy(player.PlayerId, activeAvatarId, 10.0, false)
|
||||
case constant.GADGET_TYPE_GATHER_OBJECT:
|
||||
// 采集物摘取
|
||||
interactType = proto.InteractType_INTERACT_GATHER
|
||||
gadgetNormalEntity := gadgetEntity.GetGadgetNormalEntity()
|
||||
g.AddPlayerItem(player.PlayerId, []*ChangeItem{{
|
||||
ItemId: gadgetNormalEntity.GetItemId(),
|
||||
ChangeCount: 1,
|
||||
}}, true, 0)
|
||||
g.KillEntity(player, scene, entity.GetId(), proto.PlayerDieType_PLAYER_DIE_NONE)
|
||||
case constant.GADGET_TYPE_CHEST:
|
||||
// 宝箱开启
|
||||
interactType = proto.InteractType_INTERACT_OPEN_CHEST
|
||||
// 宝箱交互结束 开启宝箱
|
||||
if req.OpType == proto.InterOpType_INTER_OP_FINISH {
|
||||
// 随机掉落
|
||||
g.chestDrop(player, entity)
|
||||
// 更新宝箱状态
|
||||
g.SendMsg(cmd.WorldChestOpenNotify, player.PlayerId, player.ClientSeq, &proto.WorldChestOpenNotify{
|
||||
GroupId: entity.GetGroupId(),
|
||||
SceneId: scene.GetId(),
|
||||
ConfigId: entity.GetConfigId(),
|
||||
})
|
||||
g.ChangeGadgetState(player, entity.GetId(), constant.GADGET_STATE_CHEST_OPENED)
|
||||
g.KillEntity(player, scene, entity.GetId(), proto.PlayerDieType_PLAYER_DIE_NONE)
|
||||
}
|
||||
default:
|
||||
logger.Error("not support gadget type: %v, uid: %v", gadgetDataConfig.Type, player.PlayerId)
|
||||
}
|
||||
default:
|
||||
logger.Error("not support entity type: %v, uid: %v", entity.GetEntityType(), player.PlayerId)
|
||||
}
|
||||
|
||||
rsp := &proto.GadgetInteractRsp{
|
||||
@@ -489,7 +493,7 @@ func (g *Game) EnterTransPointRegionNotify(player *model.Player, payloadMsg pb.M
|
||||
}
|
||||
dbAvatar := player.GetDbAvatar()
|
||||
for _, worldAvatar := range world.GetPlayerWorldAvatarList(player) {
|
||||
avatar := dbAvatar.AvatarMap[worldAvatar.GetAvatarId()]
|
||||
avatar := dbAvatar.GetAvatarById(worldAvatar.GetAvatarId())
|
||||
if avatar.LifeState == constant.LIFE_STATE_DEAD {
|
||||
g.RevivePlayerAvatar(player, worldAvatar.GetAvatarId())
|
||||
}
|
||||
@@ -724,7 +728,7 @@ func (g *Game) TeleportPlayer(
|
||||
return
|
||||
}
|
||||
|
||||
oldSceneId := player.SceneId
|
||||
oldSceneId := player.GetSceneId()
|
||||
oldPos := g.GetPlayerPos(player)
|
||||
newSceneId := sceneId
|
||||
newPos := pos
|
||||
@@ -733,17 +737,17 @@ func (g *Game) TeleportPlayer(
|
||||
var enterType proto.EnterType
|
||||
if newSceneId != oldSceneId {
|
||||
player.SceneJump = true
|
||||
logger.Debug("player jump scene, scene: %v, pos: %v", player.SceneId, newPos)
|
||||
logger.Debug("player jump scene, scene: %v, pos: %v", player.GetSceneId(), newPos)
|
||||
enterType = proto.EnterType_ENTER_JUMP
|
||||
if enterReason == proto.EnterReason_ENTER_REASON_DUNGEON_ENTER {
|
||||
logger.Debug("player tp to dungeon scene, sceneId: %v, pos: %v", player.SceneId, newPos)
|
||||
logger.Debug("player tp to dungeon scene, sceneId: %v, pos: %v", player.GetSceneId(), newPos)
|
||||
enterType = proto.EnterType_ENTER_DUNGEON
|
||||
}
|
||||
delTeamEntityNotify := g.PacketDelTeamEntityNotify(world, player)
|
||||
g.SendMsg(cmd.DelTeamEntityNotify, player.PlayerId, player.ClientSeq, delTeamEntityNotify)
|
||||
} else {
|
||||
player.SceneJump = false
|
||||
logger.Debug("player goto scene, scene: %v, pos: %v", player.SceneId, newPos)
|
||||
logger.Debug("player goto scene, scene: %v, pos: %v", player.GetSceneId(), newPos)
|
||||
enterType = proto.EnterType_ENTER_GOTO
|
||||
}
|
||||
|
||||
|
||||
@@ -60,6 +60,14 @@ type Avatar struct {
|
||||
FightPropMap map[uint32]float32 `bson:"-" msgpack:"-"`
|
||||
}
|
||||
|
||||
func (a *DbAvatar) GetAvatarById(avatarId uint32) *Avatar {
|
||||
return a.AvatarMap[avatarId]
|
||||
}
|
||||
|
||||
func (a *DbAvatar) GetAvatarMap() map[uint32]*Avatar {
|
||||
return a.AvatarMap
|
||||
}
|
||||
|
||||
func (a *DbAvatar) InitDbAvatar(player *Player) {
|
||||
for _, avatar := range a.AvatarMap {
|
||||
a.InitAvatar(player, avatar)
|
||||
|
||||
+8
-4
@@ -20,6 +20,14 @@ type Item struct {
|
||||
Guid uint64 `bson:"-" msgpack:"-"`
|
||||
}
|
||||
|
||||
func (i *DbItem) GetItemMap() map[uint32]*Item {
|
||||
return i.ItemMap
|
||||
}
|
||||
|
||||
func (i *DbItem) GetItemMapLen() int {
|
||||
return len(i.ItemMap)
|
||||
}
|
||||
|
||||
func (i *DbItem) InitDbItem(player *Player) {
|
||||
for itemId, item := range i.ItemMap {
|
||||
item.Guid = player.GetNextGameObjectGuid()
|
||||
@@ -44,10 +52,6 @@ func (i *DbItem) GetItemCount(itemId uint32) uint32 {
|
||||
return itemInfo.Count
|
||||
}
|
||||
|
||||
func (i *DbItem) GetItemMapLen() int {
|
||||
return len(i.ItemMap)
|
||||
}
|
||||
|
||||
func (i *DbItem) AddItem(player *Player, itemId uint32, count uint32) {
|
||||
itemInfo := i.ItemMap[itemId]
|
||||
if itemInfo == nil {
|
||||
|
||||
@@ -32,6 +32,14 @@ type Reliquary struct {
|
||||
Guid uint64 `bson:"-" msgpack:"-"`
|
||||
}
|
||||
|
||||
func (r *DbReliquary) GetReliquaryById(reliquaryId uint64) *Reliquary {
|
||||
return r.ReliquaryMap[reliquaryId]
|
||||
}
|
||||
|
||||
func (r *DbReliquary) GetReliquaryMap() map[uint64]*Reliquary {
|
||||
return r.ReliquaryMap
|
||||
}
|
||||
|
||||
func (r *DbReliquary) GetReliquaryMapLen() int {
|
||||
return len(r.ReliquaryMap)
|
||||
}
|
||||
@@ -54,7 +62,7 @@ func (r *DbReliquary) InitReliquary(player *Player, reliquary *Reliquary) {
|
||||
r.ReliquaryMap[reliquary.ReliquaryId] = reliquary
|
||||
if reliquary.AvatarId != 0 {
|
||||
dbAvatar := player.GetDbAvatar()
|
||||
avatar := dbAvatar.AvatarMap[reliquary.AvatarId]
|
||||
avatar := dbAvatar.GetAvatarById(reliquary.AvatarId)
|
||||
avatar.EquipGuidMap[reliquary.Guid] = reliquary.Guid
|
||||
avatar.EquipReliquaryMap[uint8(reliquaryConfig.ReliquaryType)] = reliquary
|
||||
}
|
||||
|
||||
@@ -32,6 +32,14 @@ type Weapon struct {
|
||||
Guid uint64 `bson:"-" msgpack:"-"`
|
||||
}
|
||||
|
||||
func (w *DbWeapon) GetWeaponById(weaponId uint64) *Weapon {
|
||||
return w.WeaponMap[weaponId]
|
||||
}
|
||||
|
||||
func (w *DbWeapon) GetWeaponMap() map[uint64]*Weapon {
|
||||
return w.WeaponMap
|
||||
}
|
||||
|
||||
func (w *DbWeapon) GetWeaponMapLen() int {
|
||||
return len(w.WeaponMap)
|
||||
}
|
||||
@@ -48,7 +56,7 @@ func (w *DbWeapon) InitWeapon(player *Player, weapon *Weapon) {
|
||||
w.WeaponMap[weapon.WeaponId] = weapon
|
||||
if weapon.AvatarId != 0 {
|
||||
dbAvatar := player.GetDbAvatar()
|
||||
avatar := dbAvatar.AvatarMap[weapon.AvatarId]
|
||||
avatar := dbAvatar.GetAvatarById(weapon.AvatarId)
|
||||
avatar.EquipGuidMap[weapon.Guid] = weapon.Guid
|
||||
avatar.EquipWeapon = weapon
|
||||
}
|
||||
|
||||
+50
-10
@@ -84,29 +84,69 @@ type Player struct {
|
||||
WuDi bool `bson:"-" msgpack:"-"` // 是否开启玩家角色无敌
|
||||
EnergyInf bool `bson:"-" msgpack:"-"` // 是否开启玩家角色无限能量
|
||||
StaminaInf bool `bson:"-" msgpack:"-"` // 是否开启玩家无限耐力
|
||||
IsInMp bool `bson:"-" msgpack:"-"` // 是否位于多人世界
|
||||
MpSceneId uint32 `bson:"-" msgpack:"-"` // 多人世界场景
|
||||
MpPos *Vector `bson:"-" msgpack:"-"` // 多人世界坐标
|
||||
MpRot *Vector `bson:"-" msgpack:"-"` // 多人世界朝向
|
||||
// 特殊数据
|
||||
ChatMsgMap map[uint32][]*ChatMsg `bson:"-" msgpack:"-"` // 聊天信息 数据量偏大 只从db读写 不保存到redis
|
||||
RemoteWorldPlayerNum uint32 `bson:"-"` // 远程展示世界内人数 在线同步到redis 不保存到db
|
||||
}
|
||||
|
||||
func (p *Player) GetPos() *Vector {
|
||||
return &Vector{X: p.Pos.X, Y: p.Pos.Y, Z: p.Pos.Z}
|
||||
func (p *Player) GetSceneId() uint32 {
|
||||
if p.IsInMp {
|
||||
return p.MpSceneId
|
||||
} else {
|
||||
return p.SceneId
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Player) GetRot() *Vector {
|
||||
return &Vector{X: p.Rot.X, Y: p.Rot.Y, Z: p.Rot.Z}
|
||||
func (p *Player) SetSceneId(sceneId uint32) {
|
||||
if p.IsInMp {
|
||||
p.MpSceneId = sceneId
|
||||
} else {
|
||||
p.SceneId = sceneId
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Player) GetPos() *Vector {
|
||||
if p.IsInMp {
|
||||
return &Vector{X: p.MpPos.X, Y: p.MpPos.Y, Z: p.MpPos.Z}
|
||||
} else {
|
||||
return &Vector{X: p.Pos.X, Y: p.Pos.Y, Z: p.Pos.Z}
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Player) SetPos(pos *Vector) {
|
||||
p.Pos.X = pos.X
|
||||
p.Pos.Y = pos.Y
|
||||
p.Pos.Z = pos.Z
|
||||
if p.IsInMp {
|
||||
p.MpPos.X = pos.X
|
||||
p.MpPos.Y = pos.Y
|
||||
p.MpPos.Z = pos.Z
|
||||
} else {
|
||||
p.Pos.X = pos.X
|
||||
p.Pos.Y = pos.Y
|
||||
p.Pos.Z = pos.Z
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Player) GetRot() *Vector {
|
||||
if p.IsInMp {
|
||||
return &Vector{X: p.MpRot.X, Y: p.MpRot.Y, Z: p.MpRot.Z}
|
||||
} else {
|
||||
return &Vector{X: p.Rot.X, Y: p.Rot.Y, Z: p.Rot.Z}
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Player) SetRot(rot *Vector) {
|
||||
p.Rot.X = rot.X
|
||||
p.Rot.Y = rot.Y
|
||||
p.Rot.Z = rot.Z
|
||||
if p.IsInMp {
|
||||
p.MpRot.X = rot.X
|
||||
p.MpRot.Y = rot.Y
|
||||
p.MpRot.Z = rot.Z
|
||||
} else {
|
||||
p.Rot.X = rot.X
|
||||
p.Rot.Y = rot.Y
|
||||
p.Rot.Z = rot.Z
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Player) GetNextGameObjectGuid() uint64 {
|
||||
|
||||
Reference in new issue
Block a user