internal void RemoveAmmo() { MyTuple <Weapon, MyTuple <MyInventory, int>[]> weaponAmmoToPull; while (AmmoToRemoveQueue.TryDequeue(out weaponAmmoToPull)) { var weapon = weaponAmmoToPull.Item1; if (!weapon.Comp.InventoryInited) { continue; } var inventoriesToAddTo = weaponAmmoToPull.Item2; var def = weapon.ActiveAmmoDef.AmmoDefinitionId; var magItem = weapon.ActiveAmmoDef.AmmoDef.Const.AmmoItem; weapon.Comp.IgnoreInvChange = true; weapon.ActiveAmmoDef = weapon.System.WeaponAmmoTypes[weapon.Set.AmmoTypeId]; for (int i = 0; i < inventoriesToAddTo.Length; i++) { var amt = inventoriesToAddTo[i].Item2; weapon.Comp.BlockInventory.RemoveItemsOfType(amt, def); inventoriesToAddTo[i].Item1.Add(magItem, amt); } WepUi.SetDps(weapon.Comp, weapon.Comp.Set.Value.DpsModifier, false, true); weapon.State.Sync.Reloading = false; ComputeStorage(weapon); weapon.Comp.IgnoreInvChange = false; } }
private bool ServerUpdateSetting(PacketObj data) { var packet = data.Packet; var ent = MyEntities.GetEntityByIdOrDefault(packet.EntityId); var comp = ent?.Components.Get <WeaponComponent>(); if (comp?.Ai == null || comp.Platform.State != MyWeaponPlatform.PlatformState.Ready) { return(Error(data, Msg($"CompId: {packet.EntityId}", comp != null), Msg("Ai", comp?.Ai != null), Msg("Ai", comp?.Platform.State == MyWeaponPlatform.PlatformState.Ready))); } uint[] mIds; if (PlayerMIds.TryGetValue(packet.SenderId, out mIds) && mIds[(int)packet.PType] < packet.MId) { mIds[(int)packet.PType] = packet.MId; switch (packet.PType) { case PacketType.RequestSetRof: { WepUi.RequestSetRof(comp.MyCube as IMyTerminalBlock, ((FloatUpdatePacket)packet).Data); break; } case PacketType.RequestSetRange: { WepUi.RequestSetRange(comp.MyCube as IMyTerminalBlock, ((FloatUpdatePacket)packet).Data); break; } case PacketType.RequestSetDps: { WepUi.RequestSetDps(comp.MyCube as IMyTerminalBlock, ((FloatUpdatePacket)packet).Data); break; } case PacketType.RequestSetGuidance: { WepUi.RequestSetGuidance(comp.MyCube as IMyTerminalBlock, ((BoolUpdatePacket)packet).Data); break; } case PacketType.RequestSetOverload: { WepUi.RequestSetOverload(comp.MyCube as IMyTerminalBlock, ((BoolUpdatePacket)packet).Data); break; } } data.Report.PacketValid = true; } else { Log.Line($"ServerUpdateSetting: MidsHasSenderId:{PlayerMIds.ContainsKey(packet.SenderId)} - midsNull:{mIds == null} - senderId:{packet.SenderId}"); } return(true); }
public void Sync(WeaponComponent comp, CompSettingsValues syncFrom) { Guidance = syncFrom.Guidance; Modes = syncFrom.Modes; Range = syncFrom.Range; foreach (var w in comp.Platform.Weapons) { w.UpdateWeaponRange(); } Overrides.Sync(syncFrom.Overrides); if (Overload != syncFrom.Overload || RofModifier != syncFrom.RofModifier || DpsModifier != syncFrom.DpsModifier) { Overload = syncFrom.Overload; RofModifier = syncFrom.RofModifier; WepUi.SetDps(comp, syncFrom.DpsModifier, true); } }