package model import ( "roserver/baseserver/aoi" "roserver/baseserver/model" "roserver/serverproto" ) type MapUnitType int32 const ( MAX_SEND_NUM = 20 * 2 UnityType_Player MapUnitType = 1 UnityType_Boss MapUnitType = 2 UnityType_Other MapUnitType = 3 ) type AoiMap struct { aoi *aoi.Aoi mapType int32 mapDynamicId uint64 //公会AOI Id playerMap map[uint64]*MapRole //[uuid,MapRole] playerCliMap map[uint64]*MapRole //[cliSessionID,MapRole] not uuid } func NewAoiMap(id uint64) *AoiMap { aoiMap := &AoiMap{ mapDynamicId: id, } aoiMap.aoi = aoi.NewAoi() aoiMap.playerMap = make(map[uint64]*MapRole, 2000) aoiMap.playerCliMap = make(map[uint64]*MapRole, 2000) return aoiMap } var zeroPosition = serverproto.Position{} //todo // 暂时没有处理发送策略,先实现测试效率,后续再根据策略调整,发送哪些玩家的数据 func (this *AoiMap) PlayerEnterMap(pos *serverproto.Position, uid uint64, cli *model.ClientID, unitType int32, showInfo *serverproto.PlayerShowInfo, isMaster bool) *MapRole { if pos == nil { pos = &serverproto.Position{} } player, ok := this.playerMap[uid] if !ok { player = newMapRole(uid, pos, this, 0) player.bTestSend = true player.unitType = unitType this.playerMap[uid] = player this.playerCliMap[cli.SessID] = player } else { player.pos = *pos } player.showInfo = showInfo player.IsMaster = isMaster //移除之前的cliId对应数据 if player.cliID.SessID != 0 && player.cliID.SessID != cli.SessID { delete(RoleMapMag.playerMapList, player.cliID.SessID) } player.cliID = *cli player.selfObj = this.aoi.Enter(uid, player.pos.X, player.pos.Y, player.pos.Z, true, player.IsMaster) player.syncSurrounding() //用户快速查找 RoleMapMag.playerMapList[player.cliID.SessID] = this RoleMapMag.playerUidList[player.uid] = player return player } func (this *AoiMap) NpcEnterMap(pos *serverproto.Position, uid, ownerPlayerUid uint64, isHide bool, unitType int32) bool { //if pos == nil { // pos = &serverproto.Position{} //} //player, ok := this.playerMap[ownerPlayerUid] //if !ok { // util.DebugF("[NpcEnterMap] ownerPlayer not find", ownerPlayerUid) // return false //} // //npc := newMapRole(uid, pos, this, ownerPlayerUid) //npc.unitType = unitType //npc.isHide = isHide //npc.IsMaster = false //this.playerMap[uid] = npc //npc.selfObj = this.aoi.Enter(uid, npc.pos.X, npc.pos.Y, npc.pos.Z, true, npc.IsMaster) // ////对其他人隐藏,通知自己 //if isHide { // enterSelfNtfMsg := &serverproto.SCPlayerEnterNtf{} // enterSelfNtfMsg.Players = append(enterSelfNtfMsg.Players, &serverproto.Player{ // Uid: uid, // Pos: pos, // UType: npc.unitType, // }) // player.SendGate(enterSelfNtfMsg, nil, true) //} else { // npc.summonSyncSurrounding() //} // //util.DebugF("[NpcEnterMap] enter success owner:%v uid:%v", ownerPlayerUid, uid) return true } func (this *AoiMap) PlayerMove(pos *serverproto.Position, cliId uint64) { if pos == nil { pos = &zeroPosition } player, ok := this.playerCliMap[cliId] if !ok { return } player.playerMove(pos) } func (this *AoiMap) PlayerMoveTo(pos *serverproto.Position, uid uint64) { if pos == nil { pos = &zeroPosition } player, ok := this.playerMap[uid] if !ok { return } player.targetPos = *pos //todo... } func (this *AoiMap) PlayerLeave(cliId uint64) (uint64, bool) { player, ok := this.playerCliMap[cliId] if !ok { return 0, false } delete(this.playerMap, player.uid) delete(this.playerCliMap, player.cliID.SessID) delete(RoleMapMag.playerUidList, player.uid) delete(RoleMapMag.playerMapList, player.cliID.SessID) return player.uid, player.playerLeave() } func (this *AoiMap) NpcLeave(uid uint64) bool { player, ok := this.playerMap[uid] if !ok { return false } delete(this.playerMap, player.uid) delete(RoleMapMag.playerUidList, player.uid) return player.playerLeave() } func (this *AoiMap) PlayerShowChange(cliId uint64, info *serverproto.PlayerShowInfo) bool { player, ok := this.playerCliMap[cliId] if !ok { return false } return player.showChange(info) } func (this *AoiMap) MapRoleDoAction(cliId, uid uint64, actionId int32, pos *serverproto.Position) bool { player, ok := this.playerCliMap[cliId] if !ok { return false } return player.mapDoDoAction(actionId, pos) } func (this *AoiMap) SummonSetVisible(summonId uint64, visible bool) { player := this.getPlayer(summonId) if player != nil && player.isHide != !visible { player.isHide = !visible player.summonVisibleSyncSurrounding() } } func (this *AoiMap) getPlayer(uid uint64) *MapRole { if player, ok := this.playerMap[uid]; ok { return player } return nil } func (this *AoiMap) getPlayerByCliId(cliId uint64) *MapRole { if player, ok := this.playerCliMap[cliId]; ok { return player } return nil } func (this *AoiMap) Update(ms uint64) { for id, _ := range this.playerMap { if this.playerMap[id] == nil { continue } //this.playerMap[id].TestUpdate() } }