internal void CompChange(bool add, WeaponComponent comp) { if (add) { if (WeaponsIdx.ContainsKey(comp)) { return; } WeaponsIdx.Add(comp, Weapons.Count); Weapons.Add(comp); } else { int idx; if (!WeaponsIdx.TryGetValue(comp, out idx)) { return; } Weapons.RemoveAtFast(idx); if (idx < Weapons.Count) { WeaponsIdx[Weapons[idx]] = idx; } WeaponsIdx.Remove(comp); } }
internal void CompChange(bool add, WeaponComponent comp) { if (add) { if (WeaponsIdx.ContainsKey(comp)) { Log.Line($"CompAddFailed:<{comp.MyCube.EntityId}> - comp({comp.MyCube.DebugName}[{comp.MyCube.BlockDefinition.Id.SubtypeName}]) already existed in {MyGrid.DebugName}"); return; } if (comp.HasArmor) { for (int i = 0; i < comp.Platform.Weapons.Length; i++) { var w = comp.Platform.Weapons[i]; if (w.System.Armor != WeaponDefinition.HardPointDef.HardwareDef.ArmorState.IsWeapon) { Armor.Add(w.Comp.MyCube, w); } } Session.ArmorCubes.Add(comp.MyCube, comp); } WeaponsIdx.Add(comp, Weapons.Count); //Session.IdToCompMap.Add(comp.MyCube.EntityId, comp); Weapons.Add(comp); } else { int idx; if (!WeaponsIdx.TryGetValue(comp, out idx)) { Log.Line($"CompRemoveFailed: <{comp.MyCube.EntityId}> - {Weapons.Count}[{WeaponsIdx.Count}]({WeaponBase.Count}) - {Weapons.Contains(comp)}[{Weapons.Count}] - {Session.GridTargetingAIs[comp.MyCube.CubeGrid].WeaponBase.ContainsKey(comp.MyCube)} - {Session.GridTargetingAIs[comp.MyCube.CubeGrid].WeaponBase.Count} "); return; } if (comp.HasArmor) { for (int i = 0; i < comp.Platform.Weapons.Length; i++) { var w = comp.Platform.Weapons[i]; if (w.System.Armor != WeaponDefinition.HardPointDef.HardwareDef.ArmorState.IsWeapon) { Armor.Remove(w.Comp.MyCube); } } Session.ArmorCubes.Remove(comp.MyCube); } Weapons.RemoveAtFast(idx); if (idx < Weapons.Count) { WeaponsIdx[Weapons[idx]] = idx; } //Session.IdToCompMap.Remove(comp.MyCube.EntityId); WeaponsIdx.Remove(comp); } }