simplify and expand Stage Object indexer

This commit is contained in:
wish
2023-07-23 13:27:10 +10:00
parent 769f989c91
commit 19e1eae5e2

View File

@@ -30,7 +30,7 @@ type Stage struct {
// Objects // Objects
objects map[uint32]*Object objects map[uint32]*Object
objectIndex uint8 objectIndex uint16
// Map of session -> charID. // Map of session -> charID.
// These are clients that are CURRENTLY in the stage // These are clients that are CURRENTLY in the stage
@@ -56,7 +56,6 @@ func NewStage(ID string) *Stage {
clients: make(map[*Session]uint32), clients: make(map[*Session]uint32),
reservedClientSlots: make(map[uint32]bool), reservedClientSlots: make(map[uint32]bool),
objects: make(map[uint32]*Object), objects: make(map[uint32]*Object),
objectIndex: 0,
rawBinaryData: make(map[stageBinaryKey][]byte), rawBinaryData: make(map[stageBinaryKey][]byte),
maxPlayers: 4, maxPlayers: 4,
} }
@@ -97,16 +96,10 @@ func (s *Stage) isQuest() bool {
} }
func (s *Stage) NextObjectID() uint32 { func (s *Stage) NextObjectID() uint32 {
s.objectIndex = s.objectIndex + 1 s.objectIndex++
// Objects beyond 127 do not duplicate correctly
// Indexes 0 and 127 does not update position correctly
if s.objectIndex == 127 {
s.objectIndex = 1
}
bf := byteframe.NewByteFrame() bf := byteframe.NewByteFrame()
bf.WriteUint8(0) bf.WriteUint16(127)
bf.WriteUint8(s.objectIndex) bf.WriteUint16(s.objectIndex)
bf.WriteUint16(0) bf.Seek(0, 0)
obj := uint32(bf.Data()[3]) | uint32(bf.Data()[2])<<8 | uint32(bf.Data()[1])<<16 | uint32(bf.Data()[0])<<24 return bf.ReadUint32()
return obj
} }