| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- 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)
- }
|