@@ -305,10 +305,8 @@ func (p *Parser) bindNewPlayer(playerEntity st.IEntity) {
305
305
wep := p .gameState .weapons [entityID ]
306
306
307
307
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 )
312
310
p .gameState .weapons [entityID ] = wep
313
311
}
314
312
@@ -479,14 +477,18 @@ func (p *Parser) nadeProjectileDestroyed(proj *common.GrenadeProjectile) {
479
477
func (p * Parser ) bindWeapon (entity * st.Entity , wepType common.EquipmentElement ) {
480
478
entityID := entity .ID ()
481
479
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
485
490
}
486
491
487
- p .gameState .weapons [entityID ] = common .NewEquipment (wepType )
488
- eq := p .gameState .weapons [entityID ]
489
- eq .Owner = currentOwner
490
492
eq .EntityID = entityID
491
493
eq .AmmoInMagazine = - 1
492
494
0 commit comments