package aoi import ( "f1-game/internal/enum" "fmt" ) type ( Point struct { X int32 Y int32 } Object struct { ObjectID int64 // 对象唯一id ObjectType enum.ObjectType // 对象类型 PrevPoint Point // 上一个坐标点 Point Point // 当前坐标点 isWatcher bool // 是否为观察者,当前对象可以观察到哪些人 (tower有变化会收到消息) isMarker bool // 是否为被观察者 ownerID int64 // 拥有者ID } ) func NewWatcher(id int64, _type enum.ObjectType, x, y int32, ownerID int64) *Object { return NewObject(id, _type, x, y, true, false, ownerID) } func NewMarker(id int64, _type enum.ObjectType, x, y int32) *Object { return NewObject(id, _type, x, y, false, true, 0) } func NewObject(id int64, _type enum.ObjectType, x, y int32, isWatcher, isMarker bool, ownerID int64) *Object { object := &Object{ ObjectID: id, ObjectType: _type, isWatcher: isWatcher, isMarker: isMarker, ownerID: ownerID, } object.PrevPoint.X = x object.PrevPoint.Y = y object.Point.X = x object.Point.Y = y return object } func (p *Object) SetPoint(x, y int32) { p.PrevPoint.X = p.Point.X p.PrevPoint.Y = p.Point.Y p.Point.X = x p.Point.Y = y } func (p *Point) Equal(p2 *Point) bool { return p.X == p2.X && p.Y == p2.Y } func (p *Object) String() string { if p.isMarker { return fmt.Sprintf("marker objectID = %d, point(%d,%d -> %d,%d)", p.ObjectID, p.PrevPoint.X, p.PrevPoint.Y, p.Point.X, p.Point.Y) } if p.isWatcher { return fmt.Sprintf("watcher objectID = %d, point(%d,%d -> %d,%d)", p.ObjectID, p.PrevPoint.X, p.PrevPoint.Y, p.Point.X, p.Point.Y) } return fmt.Sprintf("objectID = %d, point(%d,%d -> %d,%d)", p.ObjectID, p.PrevPoint.X, p.PrevPoint.Y, p.Point.X, p.Point.Y) } func (p *Object) Info() string { return fmt.Sprintf("id = %d, type = %v, point(%d,%d), isMarker = %v, isWatcher = %v, ownerID = %d", p.ObjectID, enum.GetObjectTypeName(p.ObjectType), p.Point.X, p.Point.Y, p.isMarker, p.isWatcher, p.ownerID, ) } func (p *Object) IsWatcher() bool { return p.isWatcher } func (p *Object) IsMarker() bool { return p.isMarker } func (p *Object) OwnerID() int64 { return p.ownerID } func (p *Object) Clean() { p.ObjectID = 0 p.PrevPoint.X = 0 p.PrevPoint.Y = 0 p.Point.X = 0 p.Point.Y = 0 p.isWatcher = false p.isMarker = false p.ownerID = 0 }