package model import ( "roserver/baseserver/aoi" "roserver/serverproto" ) type Entity struct { uid uint64 //uid ownerUid uint64 //拥有该实体的玩家ID realZone int32 //实际所在的服务器(发送协议使用) logicZone int32 //选择登录的区服(显示所在区服使用) position serverproto.Vector3 //实际位置 lastPos serverproto.Vector3 //上次的实际位置 direction *Direction3D isOnGround bool //是否在地面上 topSpeed float32 //x,z轴最高移动速度 topSpeedY float32 //y轴最高移动速度 dirChangeTime uint64 posChangeTime uint64 //// selfObj *aoi.AoiObject //AOI坐标系统中的位置 IsMaster bool unitType int32 isHide bool showInfo *serverproto.PlayerShowInfo selfMapParam *serverproto.SelfCrossMapParam selfWitness *Witness UpdateCycle uint64 } func NewEntity(uid uint64) *Entity { retEntity := &Entity{ uid: uid, direction: &Direction3D{}, selfMapParam: &serverproto.SelfCrossMapParam{}, } return retEntity } func (this *Entity) isSummon() bool { return this.ownerUid > 0 } func (this *Entity) setWitness(spaceMemory *SpaceMemory) { witness := &Witness{ spaceMemory: spaceMemory, } this.selfWitness = witness witness.attach(this) } func (this *Entity) addPositionAndDirectionStream(msg *serverproto.UnitPosAndDir) { msg.Uid = this.uid msg.UType = this.unitType msg.Pos = &serverproto.Vector3{} *msg.Pos = this.position msg.Dir = &serverproto.Vector3{} *msg.Dir = this.direction.dir //msg.IsOnGround = this.isOnGround } func (this *Entity) onEnterSpace() { ssAckMsg := &serverproto.SSGCrossMapEnterAck{ LineNum: this.selfWitness.spaceMemory.lineNum, MapType: this.selfWitness.spaceMemory.mapType, UnitInfo: &serverproto.UnitPosAndDir{}, } this.addPositionAndDirectionStream(ssAckMsg.UnitInfo) this.selfWitness.sendToClient(ssAckMsg) this.selfWitness.syncEnterNtf() } func (this *Entity) onLeaveSpace(uidList []interface{}) { ssLeaveNtfMsg := &serverproto.SSGCrossMapLeaveNtf{} ssLeaveNtfMsg.UnitInfoList = append(ssLeaveNtfMsg.UnitInfoList, &serverproto.UnitPosAndDir{ Uid: this.uid, Pos: &this.position, UType: this.unitType, }) this.selfWitness.sendToClient(ssLeaveNtfMsg) this.selfWitness.leaveSpace(ssLeaveNtfMsg, uidList) } func (this *Entity) FillShowInfo(info *serverproto.PlayerShowInfo) { if this.showInfo != nil { *info = *this.showInfo } info = this.showInfo } //位置同步更新 func (this *Entity) OnUpdateDataFromClient(msg *serverproto.SSGCrossMapSyncPosReq) { if msg.Pos == nil { msg.Pos = &zeroPosition } if msg.Dir == nil { msg.Dir = &serverproto.Vector3{} } this.selfWitness.OnUpdateDataFromClient(msg.Pos, msg.Dir) this.position = *msg.Pos this.direction.dir = *msg.Dir } func (this *Entity) UpdateEntityParamFromClient(msg *serverproto.SSGCrossMapSyncParamReq) { if this.selfWitness != nil { ssNtfMsg := &serverproto.SSGCrossMapSyncParamNtf{} ssNtfMsg.SyncUnitList = append(ssNtfMsg.SyncUnitList, &serverproto.UnitPosAndDir{ Uid: this.selfWitness.selfEntity.uid, Pos: msg.Pos, Dir: msg.Dir, ParamId: msg.ParamId, }) this.selfWitness.playerViewNtf(ssNtfMsg) //set direction if msg.Dir != nil { this.selfWitness.selfEntity.direction.dir = *msg.Dir } } } func (this *Entity) ShowChange(info *serverproto.PlayerShowInfo) bool { if info == nil { return false } if info.NickName != "" { this.showInfo.NickName = info.NickName } if info.FashionData != nil { this.showInfo.FashionData = info.FashionData } //MoveSet处理 //地图形象显示变更通知 changeNtfMsg := &serverproto.SSGCrossMapOtherUnitShowInfoNtf{} changeNtfMsg.ShowInfoList = append(changeNtfMsg.ShowInfoList, info) this.selfWitness.playerViewNtf(changeNtfMsg) return true } func (this *Entity) update(updateCycle uint64) { this.UpdateCycle = updateCycle this.selfWitness.OnUpdatePos(&this.position, &this.direction.dir) }