Skip to content

Commit e0887e1

Browse files
datatables: fix EqUnknown issues
Co-authored-by: Markus <[email protected]>
1 parent 3634f34 commit e0887e1

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

datatables.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -305,10 +305,8 @@ func (p *Parser) bindNewPlayer(playerEntity st.IEntity) {
305305
wep := p.gameState.weapons[entityID]
306306

307307
if wep == nil {
308-
// Something is clearly wrong here
309-
// But since we had an empty Equipment instance here before the change
310-
// from array with default elements to map, let's create a new instance.
311-
wep = new(common.Equipment)
308+
// sometimes a weapon is assigned to a player before the weapon entity is created
309+
wep = common.NewEquipment(common.EqUnknown)
312310
p.gameState.weapons[entityID] = wep
313311
}
314312

@@ -479,14 +477,18 @@ func (p *Parser) nadeProjectileDestroyed(proj *common.GrenadeProjectile) {
479477
func (p *Parser) bindWeapon(entity *st.Entity, wepType common.EquipmentElement) {
480478
entityID := entity.ID()
481479

482-
var currentOwner *common.Player
483-
if wep, ok := p.gameState.weapons[entityID]; ok {
484-
currentOwner = wep.Owner
480+
eq, eqExists := p.gameState.weapons[entityID]
481+
if !eqExists {
482+
eq = common.NewEquipment(wepType)
483+
p.gameState.weapons[entityID] = eq
484+
} else {
485+
// If we are here, we already have a player that holds this weapon
486+
// so the zero-valued Equipment instance was already created in bindPlayer().
487+
// In this case we should create update the weapon type
488+
// but keep the same memory address so player's rawWeapons would still have a pointer to it
489+
eq.Weapon = wepType
485490
}
486491

487-
p.gameState.weapons[entityID] = common.NewEquipment(wepType)
488-
eq := p.gameState.weapons[entityID]
489-
eq.Owner = currentOwner
490492
eq.EntityID = entityID
491493
eq.AmmoInMagazine = -1
492494

0 commit comments

Comments
 (0)