fixed object package

This commit is contained in:
Sky Johnson 2025-08-05 19:57:01 -05:00
parent d38847344c
commit 5ed7c44270
3 changed files with 1383 additions and 46 deletions

View File

@ -14,6 +14,16 @@ type ObjectSpawn struct {
// Object-specific properties // Object-specific properties
clickable bool // Whether the object can be clicked/interacted with clickable bool // Whether the object can be clicked/interacted with
deviceID int8 // Device ID for interactive objects deviceID int8 // Device ID for interactive objects
// Merchant properties (duplicated from spawn since fields are unexported)
merchantID int32
merchantType int8
merchantMinLevel int32
merchantMaxLevel int32
isCollector bool
// Transport properties (duplicated from spawn since fields are unexported)
transporterID int32
} }
// NewObjectSpawn creates a new object spawn with default values // NewObjectSpawn creates a new object spawn with default values
@ -25,11 +35,11 @@ func NewObjectSpawn() *ObjectSpawn {
baseSpawn.SetSpawnType(ObjectSpawnType) baseSpawn.SetSpawnType(ObjectSpawnType)
// Set object appearance defaults // Set object appearance defaults
appearance := baseSpawn.GetAppearance() appearance := baseSpawn.GetAppearanceData()
appearance.ActivityStatus = ObjectActivityStatus appearance.ActivityStatus = ObjectActivityStatus
appearance.Pos.State = ObjectPosState appearance.Pos.State = ObjectPosState
appearance.Difficulty = ObjectDifficulty appearance.Difficulty = ObjectDifficulty
baseSpawn.SetAppearance(appearance) // Note: No SetAppearance method, but appearance is modified by reference
return &ObjectSpawn{ return &ObjectSpawn{
Spawn: baseSpawn, Spawn: baseSpawn,
@ -65,15 +75,42 @@ func (os *ObjectSpawn) IsObject() bool {
// Copy creates a deep copy of the object spawn // Copy creates a deep copy of the object spawn
func (os *ObjectSpawn) Copy() *ObjectSpawn { func (os *ObjectSpawn) Copy() *ObjectSpawn {
// Copy base spawn // Create new object spawn with new spawn
newSpawn := os.Spawn.Copy() newObjectSpawn := NewObjectSpawn()
// Create new object spawn // Copy properties from original
newObjectSpawn := &ObjectSpawn{ newObjectSpawn.clickable = os.clickable
Spawn: newSpawn, newObjectSpawn.deviceID = os.deviceID
clickable: os.clickable,
deviceID: os.deviceID, // Copy spawn properties
newObjectSpawn.SetDatabaseID(os.GetDatabaseID())
newObjectSpawn.SetID(os.GetID())
newObjectSpawn.SetName(os.GetName())
newObjectSpawn.SetLevel(os.GetLevel())
newObjectSpawn.SetSize(os.GetSize())
newObjectSpawn.SetSpawnType(os.GetSpawnType())
newObjectSpawn.SetX(os.GetX())
newObjectSpawn.SetY(os.GetY(), false)
newObjectSpawn.SetZ(os.GetZ())
newObjectSpawn.SetHeading(int16(os.GetHeading()), int16(os.GetHeading()))
newObjectSpawn.SetFactionID(os.GetFactionID())
newObjectSpawn.SetTarget(os.GetTarget())
newObjectSpawn.SetAlive(os.IsAlive())
// Copy merchant properties if they exist
if os.merchantID > 0 {
newObjectSpawn.merchantID = os.merchantID
newObjectSpawn.merchantType = os.merchantType
newObjectSpawn.merchantMinLevel = os.merchantMinLevel
newObjectSpawn.merchantMaxLevel = os.merchantMaxLevel
} }
// Copy transport properties if they exist
if os.transporterID > 0 {
newObjectSpawn.transporterID = os.transporterID
}
newObjectSpawn.isCollector = os.isCollector
return newObjectSpawn return newObjectSpawn
} }
@ -86,9 +123,9 @@ func (os *ObjectSpawn) HandleUse(clientID int32, command string) error {
// Copy relevant properties for handling // Copy relevant properties for handling
object.clickable = os.clickable object.clickable = os.clickable
object.deviceID = os.deviceID object.deviceID = os.deviceID
object.transporterID = os.GetTransporterID() object.transporterID = os.transporterID
object.appearanceShowCommandIcon = int8(0) object.appearanceShowCommandIcon = int8(0)
if os.GetAppearance().ShowCommandIcon == 1 { if os.GetAppearanceData().ShowCommandIcon == 1 {
object.appearanceShowCommandIcon = ObjectShowCommandIcon object.appearanceShowCommandIcon = ObjectShowCommandIcon
} }
@ -99,18 +136,18 @@ func (os *ObjectSpawn) HandleUse(clientID int32, command string) error {
// SetShowCommandIcon sets whether to show the command icon // SetShowCommandIcon sets whether to show the command icon
func (os *ObjectSpawn) SetShowCommandIcon(show bool) { func (os *ObjectSpawn) SetShowCommandIcon(show bool) {
appearance := os.GetAppearance() appearance := os.GetAppearanceData()
if show { if show {
appearance.ShowCommandIcon = ObjectShowCommandIcon appearance.ShowCommandIcon = ObjectShowCommandIcon
} else { } else {
appearance.ShowCommandIcon = 0 appearance.ShowCommandIcon = 0
} }
os.SetAppearance(appearance) // Appearance is modified by reference, no need to set it back
} }
// ShowsCommandIcon returns whether the command icon is shown // ShowsCommandIcon returns whether the command icon is shown
func (os *ObjectSpawn) ShowsCommandIcon() bool { func (os *ObjectSpawn) ShowsCommandIcon() bool {
return os.GetAppearance().ShowCommandIcon == ObjectShowCommandIcon return os.GetAppearanceData().ShowCommandIcon == ObjectShowCommandIcon
} }
// GetObjectInfo returns comprehensive information about the object spawn // GetObjectInfo returns comprehensive information about the object spawn
@ -128,12 +165,12 @@ func (os *ObjectSpawn) GetObjectInfo() map[string]any {
info["clickable"] = os.clickable info["clickable"] = os.clickable
info["device_id"] = os.deviceID info["device_id"] = os.deviceID
info["shows_command_icon"] = os.ShowsCommandIcon() info["shows_command_icon"] = os.ShowsCommandIcon()
info["transporter_id"] = os.GetTransporterID() info["transporter_id"] = os.transporterID
info["merchant_id"] = os.GetMerchantID() info["merchant_id"] = os.merchantID
info["is_collector"] = os.IsCollector() info["is_collector"] = os.isCollector
// Add position info // Add position info
appearance := os.GetAppearance() appearance := os.GetAppearanceData()
info["x"] = appearance.Pos.X info["x"] = appearance.Pos.X
info["y"] = appearance.Pos.Y info["y"] = appearance.Pos.Y
info["z"] = appearance.Pos.Z info["z"] = appearance.Pos.Z
@ -142,40 +179,114 @@ func (os *ObjectSpawn) GetObjectInfo() map[string]any {
return info return info
} }
// Getter and setter methods for object-specific properties
// GetMerchantID returns the merchant ID
func (os *ObjectSpawn) GetMerchantID() int32 {
return os.merchantID
}
// SetMerchantID sets the merchant ID
func (os *ObjectSpawn) SetMerchantID(merchantID int32) {
os.merchantID = merchantID
}
// GetMerchantType returns the merchant type
func (os *ObjectSpawn) GetMerchantType() int8 {
return os.merchantType
}
// SetMerchantType sets the merchant type
func (os *ObjectSpawn) SetMerchantType(merchantType int8) {
os.merchantType = merchantType
}
// GetMerchantMinLevel returns the minimum merchant level
func (os *ObjectSpawn) GetMerchantMinLevel() int8 {
return int8(os.merchantMinLevel)
}
// GetMerchantMaxLevel returns the maximum merchant level
func (os *ObjectSpawn) GetMerchantMaxLevel() int8 {
return int8(os.merchantMaxLevel)
}
// SetMerchantLevelRange sets the merchant level range
func (os *ObjectSpawn) SetMerchantLevelRange(minLevel, maxLevel int8) {
os.merchantMinLevel = int32(minLevel)
os.merchantMaxLevel = int32(maxLevel)
}
// GetTransporterID returns the transporter ID
func (os *ObjectSpawn) GetTransporterID() int32 {
return os.transporterID
}
// SetTransporterID sets the transporter ID
func (os *ObjectSpawn) SetTransporterID(transporterID int32) {
os.transporterID = transporterID
}
// IsCollector returns whether this object is a collector
func (os *ObjectSpawn) IsCollector() bool {
return os.isCollector
}
// SetCollector sets whether this object is a collector
func (os *ObjectSpawn) SetCollector(isCollector bool) {
os.isCollector = isCollector
}
// GetZoneName returns the zone name (from spawn system)
func (os *ObjectSpawn) GetZoneName() string {
// TODO: Implement when zone system is integrated
// For now return empty string
return ""
}
// SetZoneName sets the zone name (placeholder for spawn system)
func (os *ObjectSpawn) SetZoneName(zoneName string) {
// TODO: Implement when zone system is integrated
// This would be handled by the spawn system
}
// ObjectSpawnManager manages object spawns specifically // ObjectSpawnManager manages object spawns specifically
type ObjectSpawnManager struct { type ObjectSpawnManager struct {
spawnManager *spawn.SpawnManager // Reference to global spawn manager objects map[int32]*ObjectSpawn // Object spawns by spawn ID
objects map[int32]*ObjectSpawn // Object spawns by spawn ID // TODO: Add reference to spawn manager when it exists
} }
// NewObjectSpawnManager creates a new object spawn manager // NewObjectSpawnManager creates a new object spawn manager
func NewObjectSpawnManager(spawnManager *spawn.SpawnManager) *ObjectSpawnManager { func NewObjectSpawnManager() *ObjectSpawnManager {
return &ObjectSpawnManager{ return &ObjectSpawnManager{
spawnManager: spawnManager, objects: make(map[int32]*ObjectSpawn),
objects: make(map[int32]*ObjectSpawn),
} }
} }
// AddObjectSpawn adds an object spawn to both the object and spawn managers // AddObjectSpawn adds an object spawn to the manager
func (osm *ObjectSpawnManager) AddObjectSpawn(objectSpawn *ObjectSpawn) error { func (osm *ObjectSpawnManager) AddObjectSpawn(objectSpawn *ObjectSpawn) error {
// Add to spawn manager first if objectSpawn == nil {
if err := osm.spawnManager.AddSpawn(objectSpawn.Spawn); err != nil { return fmt.Errorf("cannot add nil object spawn")
return err
} }
// Add to object tracking // Add to object tracking
osm.objects[objectSpawn.GetID()] = objectSpawn osm.objects[objectSpawn.GetID()] = objectSpawn
// TODO: Add to global spawn manager when it exists
return nil return nil
} }
// RemoveObjectSpawn removes an object spawn from both managers // RemoveObjectSpawn removes an object spawn from the manager
func (osm *ObjectSpawnManager) RemoveObjectSpawn(spawnID int32) error { func (osm *ObjectSpawnManager) RemoveObjectSpawn(spawnID int32) error {
// Remove from object tracking // Remove from object tracking
if _, exists := osm.objects[spawnID]; !exists {
return fmt.Errorf("object spawn %d not found", spawnID)
}
delete(osm.objects, spawnID) delete(osm.objects, spawnID)
// Remove from spawn manager // TODO: Remove from global spawn manager when it exists
return osm.spawnManager.RemoveSpawn(spawnID) return nil
} }
// GetObjectSpawn retrieves an object spawn by ID // GetObjectSpawn retrieves an object spawn by ID
@ -187,16 +298,8 @@ func (osm *ObjectSpawnManager) GetObjectSpawn(spawnID int32) *ObjectSpawn {
func (osm *ObjectSpawnManager) GetObjectSpawnsByZone(zoneName string) []*ObjectSpawn { func (osm *ObjectSpawnManager) GetObjectSpawnsByZone(zoneName string) []*ObjectSpawn {
result := make([]*ObjectSpawn, 0) result := make([]*ObjectSpawn, 0)
// Get all spawns in zone and filter for objects // TODO: Filter by zone when zone system is implemented
spawns := osm.spawnManager.GetSpawnsByZone(zoneName) // For now, return empty slice
for _, spawn := range spawns {
if spawn.GetSpawnType() == ObjectSpawnType {
if objectSpawn, exists := osm.objects[spawn.GetID()]; exists {
result = append(result, objectSpawn)
}
}
}
return result return result
} }
@ -236,7 +339,7 @@ func ConvertSpawnToObject(spawn *spawn.Spawn) *ObjectSpawn {
} }
// Set clickable based on appearance flags or other indicators // Set clickable based on appearance flags or other indicators
appearance := spawn.GetAppearance() appearance := spawn.GetAppearanceData()
if appearance.ShowCommandIcon == ObjectShowCommandIcon { if appearance.ShowCommandIcon == ObjectShowCommandIcon {
objectSpawn.clickable = true objectSpawn.clickable = true
} }
@ -269,9 +372,13 @@ func LoadObjectSpawnFromData(spawnData map[string]any) *ObjectSpawn {
// Load position data // Load position data
if x, ok := spawnData["x"].(float32); ok { if x, ok := spawnData["x"].(float32); ok {
appearance := objectSpawn.GetAppearance() objectSpawn.SetX(x)
appearance.Pos.X = x }
objectSpawn.SetAppearance(appearance) if y, ok := spawnData["y"].(float32); ok {
objectSpawn.SetY(y, false)
}
if z, ok := spawnData["z"].(float32); ok {
objectSpawn.SetZ(z)
} }
// TODO: Load other properties as needed // TODO: Load other properties as needed

View File

@ -67,7 +67,7 @@ type ObjectInterface interface {
SetTransporterID(int32) SetTransporterID(int32)
// Copying // Copying
Copy() ObjectInterface Copy() *ObjectSpawn
} }
// EntityInterface defines the interface for entities in trade/spell systems // EntityInterface defines the interface for entities in trade/spell systems

File diff suppressed because it is too large Load Diff