2024-06-24 09:03:13 +00:00
|
|
|
package object7
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
|
|
|
|
"github.com/teeworlds-go/go-teeworlds-protocol/network7"
|
|
|
|
"github.com/teeworlds-go/go-teeworlds-protocol/packer"
|
|
|
|
)
|
|
|
|
|
|
|
|
type SnapObject interface {
|
2024-06-24 14:50:15 +00:00
|
|
|
// id separating this snap item from other items with same type
|
|
|
|
// the ids are unique per type
|
|
|
|
// for players it matches their ClientId
|
2024-06-24 09:03:13 +00:00
|
|
|
Id() int
|
2024-06-24 14:50:15 +00:00
|
|
|
|
|
|
|
// type of the snap item
|
|
|
|
TypeId() int
|
2024-06-24 09:03:13 +00:00
|
|
|
|
|
|
|
// number of packed integers
|
|
|
|
// not the number of bytes
|
|
|
|
Size() int
|
|
|
|
|
|
|
|
Pack() []byte
|
|
|
|
Unpack(u *packer.Unpacker) error
|
|
|
|
}
|
|
|
|
|
|
|
|
// Comes without payload
|
|
|
|
// you have to call item.Unpack(u) manually after getting it
|
2024-06-24 14:50:15 +00:00
|
|
|
func NewObject(typeId int, itemId int) SnapObject {
|
|
|
|
if typeId == network7.ObjProjectile {
|
|
|
|
return &Projectile{ItemId: itemId}
|
|
|
|
} else if typeId == network7.ObjLaser {
|
|
|
|
return &Laser{ItemId: itemId}
|
|
|
|
} else if typeId == network7.ObjFlag {
|
2024-06-24 09:03:13 +00:00
|
|
|
return &Flag{ItemId: itemId}
|
2024-06-24 14:50:15 +00:00
|
|
|
} else if typeId == network7.ObjPickup {
|
2024-06-24 09:03:13 +00:00
|
|
|
return &Pickup{ItemId: itemId}
|
2024-06-24 14:50:15 +00:00
|
|
|
} else if typeId == network7.ObjGameData {
|
2024-06-24 09:03:13 +00:00
|
|
|
return &GameData{ItemId: itemId}
|
2024-06-24 14:50:15 +00:00
|
|
|
} else if typeId == network7.ObjGameDataTeam {
|
2024-06-24 09:03:13 +00:00
|
|
|
return &GameDataTeam{ItemId: itemId}
|
2024-06-24 14:50:15 +00:00
|
|
|
} else if typeId == network7.ObjGameDataFlag {
|
2024-06-24 09:03:13 +00:00
|
|
|
return &GameDataFlag{ItemId: itemId}
|
2024-06-24 14:50:15 +00:00
|
|
|
} else if typeId == network7.ObjCharacter {
|
2024-06-24 09:03:13 +00:00
|
|
|
return &Character{ItemId: itemId}
|
2024-06-24 14:50:15 +00:00
|
|
|
} else if typeId == network7.ObjPlayerInfo {
|
2024-06-24 09:03:13 +00:00
|
|
|
return &PlayerInfo{ItemId: itemId}
|
2024-06-24 14:50:15 +00:00
|
|
|
} else if typeId == network7.ObjSpectatorInfo {
|
|
|
|
return &SpectatorInfo{ItemId: itemId}
|
|
|
|
} else if typeId == network7.ObjExplosion {
|
|
|
|
return &Explosion{ItemId: itemId}
|
|
|
|
} else if typeId == network7.ObjSpawn {
|
|
|
|
return &Spawn{ItemId: itemId}
|
|
|
|
} else if typeId == network7.ObjHammerHit {
|
|
|
|
return &HammerHit{ItemId: itemId}
|
|
|
|
} else if typeId == network7.ObjDeath {
|
|
|
|
return &Death{ItemId: itemId}
|
|
|
|
} else if typeId == network7.ObjSoundWorld {
|
|
|
|
return &SoundWorld{ItemId: itemId}
|
|
|
|
} else if typeId == network7.ObjDamage {
|
|
|
|
return &Damage{ItemId: itemId}
|
2024-06-24 09:03:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: remove this is just for debugging
|
2024-06-24 14:50:15 +00:00
|
|
|
log.Fatalf("unknown item type %d\n", typeId)
|
2024-06-24 09:03:13 +00:00
|
|
|
|
|
|
|
unknown := &Unknown{
|
|
|
|
ItemId: itemId,
|
2024-06-24 14:50:15 +00:00
|
|
|
ItemType: typeId,
|
2024-06-24 09:03:13 +00:00
|
|
|
}
|
|
|
|
return unknown
|
|
|
|
}
|