Skip to content

Commit 819b3d5

Browse files
committed
fix: clone static actor map-bucket lookup rewards
1 parent b3c88aa commit 819b3d5

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

internal/worldruntime/map_index.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,8 @@ func (m *MapIndex) StaticActor(entityID uint64) (StaticEntity, bool) {
290290
if ok {
291291
return cloneStaticEntity(actor), true
292292
}
293-
return m.staticActorMapPresenceLocked(entityID)
293+
actor, ok = m.staticActorMapPresenceLocked(entityID)
294+
return cloneStaticEntity(actor), ok
294295
}
295296

296297
func (m *MapIndex) RemoveStatic(entityID uint64) (StaticEntity, bool) {

internal/worldruntime/map_index_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,3 +475,33 @@ func TestMapIndexStaticActorSnapshotsCloneDeathRewardDropVnums(t *testing.T) {
475475
t.Fatalf("expected static actor reward snapshots to be isolated from callers, got %+v", actors[0].DeathReward.DropVnums)
476476
}
477477
}
478+
479+
func TestMapIndexStaticActorLookupClonesDeathRewardDropVnumsWhenEntityIndexIsMissing(t *testing.T) {
480+
index := NewMapIndex(NewBootstrapTopology(0))
481+
guard := StaticEntity{
482+
Entity: Entity{ID: 12, Kind: EntityKindStaticActor, Name: "PracticeMob"},
483+
Position: NewPosition(42, 1700, 2800),
484+
RaceNum: 20300,
485+
CombatProfile: StaticActorCombatProfilePracticeMob,
486+
SpawnGroupRef: "practice.mob_delta",
487+
DeathReward: StaticActorDeathReward{Experience: 75, Gold: 60, DropVnums: []uint32{27001, 27002}},
488+
}
489+
if !index.RegisterStatic(guard) {
490+
t.Fatal("expected static actor registration to succeed")
491+
}
492+
delete(index.staticByEntityID, guard.Entity.ID)
493+
494+
lookup, ok := index.StaticActor(guard.Entity.ID)
495+
if !ok {
496+
t.Fatal("expected static actor lookup through surviving map bucket to succeed")
497+
}
498+
lookup.DeathReward.DropVnums[0] = 99999
499+
500+
lookup, ok = index.StaticActor(guard.Entity.ID)
501+
if !ok {
502+
t.Fatal("expected second static actor lookup through surviving map bucket to succeed")
503+
}
504+
if len(lookup.DeathReward.DropVnums) != 2 || lookup.DeathReward.DropVnums[0] != 27001 || lookup.DeathReward.DropVnums[1] != 27002 {
505+
t.Fatalf("expected static actor lookup to clone reward drops from surviving map bucket, got %+v", lookup.DeathReward.DropVnums)
506+
}
507+
}

0 commit comments

Comments
 (0)