public bool HasEquipment(Equipment item) { bool found = false; switch (item.EquipmentType) { case EquipmentType.Weapon: found = HasWeapon(((Weapon)item).Type, true); break; case EquipmentType.Shield: found = HasShield(((Shield)item).Type); break; case EquipmentType.Gadget: found = HasGadget(((Gadget)item).Type); break; } return found; }
public void AddEquipment(Equipment item) { Equipment[] equip = EquipmentByType(item.EquipmentType); int slot = -1; for (int i = 0; i < equip.Length && slot == -1; i++) if (equip[i] == null) slot = i; if (slot >= 0) equip[slot] = item.Clone(); }
private void UpdateSell() { sellSideSelected = false; selectedEquipment = null; UpdateInfo(); lstSellWeapon.Items.Clear(); lstSellShield.Items.Clear(); lstSellGadget.Items.Clear(); Ship ship = Game.CurrentGame.Commander.Ship; Equipment[] equipSell; int index; equipSell = ship.EquipmentByType(EquipmentType.Weapon); for (index = 0; index < equipSell.Length; index++) lstSellWeapon.Items.Add(equipSell[index] == null ? (object)Strings.EquipmentFreeSlot : equipSell[index]); equipSell = ship.EquipmentByType(EquipmentType.Shield); for (index = 0; index < equipSell.Length; index++) lstSellShield.Items.Add(equipSell[index] == null ? (object)Strings.EquipmentFreeSlot : equipSell[index]); equipSell = ship.EquipmentByType(EquipmentType.Gadget); for (index = 0; index < equipSell.Length; index++) lstSellGadget.Items.Add(equipSell[index] == null ? (object)Strings.EquipmentFreeSlot : equipSell[index]); ListBox[] sellBoxes = new ListBox[] { lstSellWeapon, lstSellShield, lstSellGadget }; Label[] sellLabels = new Label[] { lblSellWeaponNoSlots, lblSellShieldNoSlots, lblSellGadgetNoSlots }; for (int i = 0; i < sellBoxes.Length; i++) { bool entries = (sellBoxes[i].Items.Count > 0); sellBoxes[i].Visible = entries; sellLabels[i].Visible = !entries; if (entries) sellBoxes[i].Height = sellBoxes[i].ItemHeight * Math.Min(sellBoxes[i].Items.Count, 5) + 2; } }
private void SelectedIndexChanged(object sender, System.EventArgs e) { if (!handlingSelect) { handlingSelect = true; object obj = ((ListBox)sender).SelectedItem; DeselectAll(); ((ListBox)sender).SelectedItem = obj; sellSideSelected = (((ListBox)sender).Name.IndexOf("Sell") >= 0); if (typeof(Equipment).IsInstanceOfType(obj)) selectedEquipment = (Equipment)obj; else selectedEquipment = null; handlingSelect = false; UpdateInfo(); } }
public bool TradeShip(ShipSpec specToBuy, int netPrice, string newShipName, IWin32Window owner) { bool traded = false; if (netPrice > 0 && Debt > 0) FormAlert.Alert(AlertType.DebtNoBuy, owner); else if (netPrice > CashToSpend) FormAlert.Alert(AlertType.ShipBuyIf, owner); else if (specToBuy.CrewQuarters < Ship.SpecialCrew.Length) { string passengers = Ship.SpecialCrew[1].Name; if (Ship.SpecialCrew.Length > 2) passengers += " and " + Ship.SpecialCrew[2].Name; FormAlert.Alert(AlertType.ShipBuyPassengerQuarters, owner, passengers); } else if (specToBuy.CrewQuarters < Ship.CrewCount) FormAlert.Alert(AlertType.ShipBuyCrewQuarters, owner); else if (Ship.ReactorOnBoard) FormAlert.Alert(AlertType.ShipBuyReactor, owner); else { Equipment[] special = new Equipment[] { Consts.Weapons[(int)WeaponType.MorgansLaser], Consts.Weapons[(int)WeaponType.QuantumDistruptor], Consts.Shields[(int)ShieldType.Lightning], Consts.Gadgets[(int)GadgetType.FuelCompactor], Consts.Gadgets[(int)GadgetType.HiddenCargoBays] }; bool[] add = new bool[special.Length]; bool addPod = false; int extraCost = 0; for (int i = 0; i < special.Length; i++) { if (!Ship.HasEquipment(special[i])) continue; if (specToBuy.Slots(special[i].EquipmentType) == 0) FormAlert.Alert(AlertType.ShipBuyNoSlots, owner, newShipName, special[i].Name, Strings.EquipmentTypes[(int)special[i].EquipmentType]); else { extraCost += special[i].TransferPrice; add[i] = true; } } if (Ship.EscapePod) { addPod = true; extraCost += Consts.PodTransferCost; } if (netPrice + extraCost > CashToSpend) FormAlert.Alert(AlertType.ShipBuyIfTransfer, owner); extraCost = 0; for (int i = 0; i < special.Length; i++) { if (!add[i]) continue; if (netPrice + extraCost + special[i].TransferPrice > CashToSpend) FormAlert.Alert(AlertType.ShipBuyNoTransfer, owner, special[i].Name); else if (FormAlert.Alert(AlertType.ShipBuyTransfer, owner, special[i].Name, special[i].Name.ToLower(), Functions.FormatNumber(special[i].TransferPrice)) == DialogResult.Yes) extraCost += special[i].TransferPrice; else add[i] = false; } if (addPod) { if (netPrice + extraCost + Consts.PodTransferCost > CashToSpend) FormAlert.Alert(AlertType.ShipBuyNoTransfer, owner, Strings.ShipInfoEscapePod); else if (FormAlert.Alert(AlertType.ShipBuyTransfer, owner, Strings.ShipInfoEscapePod, Strings.ShipInfoEscapePod.ToLower(), Functions.FormatNumber(Consts.PodTransferCost)) == DialogResult.Yes) extraCost += Consts.PodTransferCost; else addPod = false; } if (FormAlert.Alert(AlertType.ShipBuyConfirm, owner, Ship.Name, newShipName, (add[0] || add[1] || add[2] || addPod ? Strings.ShipBuyTransfer : "")) == DialogResult.Yes) { CrewMember[] oldCrew = Ship.Crew; Ship = new Ship(specToBuy.Type); Cash -= (netPrice + extraCost); for (int i = 0; i < Math.Min(oldCrew.Length, Ship.Crew.Length); i++) Ship.Crew[i] = oldCrew[i]; for (int i = 0; i < special.Length; i++) { if (add[i]) Ship.AddEquipment(special[i]); } if (addPod) Ship.EscapePod = true; else if (Insurance) { Insurance = false; NoClaim = 0; } traded = true; } } return traded; }