Implement unique key generation for weapon grants to prevent overwrites

This commit is contained in:
Ilya Groshev
2026-04-16 16:07:56 +03:00
parent cbc052c3ed
commit ef8a241a0a
5 changed files with 27 additions and 13 deletions
+9
View File
@@ -156,6 +156,15 @@ func (g *PossessionGranter) GrantCostume(user *UserState, costumeId int32, nowMi
func (g *PossessionGranter) GrantWeapon(user *UserState, weaponId int32, nowMillis int64) {
key := fmt.Sprintf("reward-weapon-%d-%d", weaponId, nowMillis)
if _, exists := user.Weapons[key]; exists {
for i := 2; ; i++ {
candidate := fmt.Sprintf("%s-%d", key, i)
if _, exists := user.Weapons[candidate]; !exists {
key = candidate
break
}
}
}
user.Weapons[key] = WeaponState{
UserWeaponUuid: key,
WeaponId: weaponId,