public float GetPrice(PortWareIdentifier identifier, float quantity, PortTradeDirection direction) { switch (direction) { case PortTradeDirection.ShipPurchaseFromPort: { if (_model.Prices_ShipPurchaseFromPort.ContainsKey(identifier)) { return(_model.Prices_ShipPurchaseFromPort[identifier] * quantity); } else { return(float.MaxValue); } } case PortTradeDirection.ShipSaleToPort: { if (_model.Prices_ShipSaleToPort.ContainsKey(identifier)) { return(_model.Prices_ShipSaleToPort[identifier] * quantity); } else { return(float.MaxValue); } } default: { throw new NotImplementedException("Sale direction " + direction.ToString() + " not implemented."); } } }
public PortGood(PortWareIdentifier goodId, UIDisplayData uiDisplayData, string assetUrl, float purchasePrice, float quantity) { GoodId = goodId; AssetUrl = assetUrl; PurchasePrice = purchasePrice; UIDisplayData = uiDisplayData; Quantity = quantity; }
public static bool GetServiceType(PortWareIdentifier wareType, out PortServiceTypes serviceType) { bool success = Enum.TryParse(wareType.ToString(), out serviceType); if (!success) { serviceType = PortServiceTypes.Null; } return(success); }
public static bool GetCargoType(PortWareIdentifier wareType, out StatelessCargoTypes cargoType) { bool success = Enum.TryParse(wareType.ToString(), out cargoType); if (!success) { cargoType = StatelessCargoTypes.Null; } return(success); }
/// <summary> /// If numChange is negative, quantity will be removed. /// </summary> /// <param name="portGoodIdentifier"></param> /// <param name="numChange"></param> void UpdateGoodCounts(PortWareIdentifier portGoodIdentifier, float numChange) { if (!_model.PortGoodCounts.ContainsKey(portGoodIdentifier) && numChange >= 0) { _model.PortGoodCounts.Add(portGoodIdentifier, (int)numChange); return; } _model.PortGoodCounts[portGoodIdentifier] += (int)numChange; if (_model.PortGoodCounts[portGoodIdentifier] <= 0) { _model.PortGoodCounts.Remove(portGoodIdentifier); } }
protected virtual void SetCargoPurchasePrice(PortWareIdentifier i, float price) { if (i == PortWareIdentifier.Null) { return; } if (_model.Prices_ShipPurchaseFromPort.ContainsKey(i)) { _model.Prices_ShipPurchaseFromPort[i] = price; } else { _model.Prices_ShipPurchaseFromPort.Add(i, price); } }
/// <summary> /// Adds if addOrRemove is true, removes otherwise /// </summary> /// <param name="statefulCargo"></param> /// <param name="addOrRemove"></param> void UpdateUIStatLists(PortWareIdentifier portGoodIdentifier, StatefulCargo statefulCargo, bool addOrRemove) { if (addOrRemove) { if (!_model.UIComponent.Goods.ContainsKey(portGoodIdentifier)) { _model.UIComponent.Goods.Add(portGoodIdentifier, UIHelper.GetUIData(statefulCargo)); } } else { if (_model.UIComponent.Goods.ContainsKey(portGoodIdentifier)) { _model.UIComponent.Goods.Remove(portGoodIdentifier); } } }
/// <summary> /// If quantity <0, set statelessCargo to null to have it removed from the UIComponent /// </summary> /// <param name="portWareIdentifier"></param> /// <param name="statelessCargo"></param> void UpdateUIStatLists(PortWareIdentifier portWareIdentifier, StatelessCargo statelessCargo) { if (statelessCargo == null) { _model.UIComponent.Goods.Remove(portWareIdentifier); } else { var uiData = UIHelper.GetUIData(statelessCargo); if (!_model.UIComponent.Goods.ContainsKey(portWareIdentifier)) { _model.UIComponent.Goods.Add(portWareIdentifier, uiData); } else { _model.UIComponent.Goods[portWareIdentifier] = uiData; } } }
/// <summary> /// Removes the stateful cargo with the given ID if it exists /// </summary> /// <param name="id"></param> /// <returns></returns> public override StatefulCargo RemoveStatefulCargo(int id) { if (_model.StatefulCargo.ContainsKey(id)) { StatefulCargo s = _model.StatefulCargo[id]; _model.FilledHolds -= Core.Models.StatefulCargo.SpacePerObject(s.CargoType); _decrementStatefulCargoCount(s.CargoType); if (StatefulCargoPriceGetter != null) { SetCargoPurchasePrice(PortHelper.GetPortWareIdentifier(s.CargoType), StatefulCargoPriceGetter(new StatefulCargo_RO(s), GetCargoAmount(s.CargoType), PriceType.PortPurchasing)); SetCargoSalePrice(PortHelper.GetPortWareIdentifier(s.CargoType), StatefulCargoPriceGetter(new StatefulCargo_RO(s), GetCargoAmount(s.CargoType), PriceType.PortSelling)); } PortWareIdentifier identifier = PortHelper.GetPortWareIdentifier(s.CargoType); if (s.CargoType == StatefulCargoTypes.Module) { _model.UIComponent.Modules.Remove(id); } else if (identifier != PortWareIdentifier.Null) { UpdateGoodCounts(identifier, -1); UpdateUIStatLists(identifier, s, false); if (!_model.PortGoodCounts.ContainsKey(identifier))//UpdateGoodCounts will have removed the key if no more goods of this type are in the inventory { _model.Prices_ShipSaleToPort.Remove(identifier); } } return(s); } else { return(null); } }
public static PortGoodCategory GetPortGoodCategory(PortWareIdentifier cargoType) { switch (cargoType) { case PortWareIdentifier.LaserTurret: case PortWareIdentifier.DefensiveMine: return(PortGoodCategory.Defenses); case PortWareIdentifier.Module: return(PortGoodCategory.Module); case PortWareIdentifier.PlasmaCannon: case PortWareIdentifier.Laser: case PortWareIdentifier.EnergyDisruptor: return(PortGoodCategory.Weapon); case PortWareIdentifier.Hull1: case PortWareIdentifier.Hull2: case PortWareIdentifier.Hull3: case PortWareIdentifier.Engine1: case PortWareIdentifier.Engine2: case PortWareIdentifier.Engine3: return(PortGoodCategory.Components); //Ships //Not sure if we'll actually allow ships to carry other ships: but this simplifies port buying/selling of ships case PortWareIdentifier.Penguin: case PortWareIdentifier.Reaper: case PortWareIdentifier.Battlecruiser: case PortWareIdentifier.Barge: return(PortGoodCategory.Ship); case PortWareIdentifier.Cash: case PortWareIdentifier.Hydrogen: case PortWareIdentifier.Iron: case PortWareIdentifier.Neutronium: case PortWareIdentifier.Hydrocarbons: case PortWareIdentifier.Woman: case PortWareIdentifier.ThoriumOre: case PortWareIdentifier.Thorium: case PortWareIdentifier.IronOre: case PortWareIdentifier.Organics: case PortWareIdentifier.Bauxite: case PortWareIdentifier.Silica: case PortWareIdentifier.Water: case PortWareIdentifier.Oxygen: case PortWareIdentifier.Opium: return(PortGoodCategory.Resource); case PortWareIdentifier.AmbassadorMissile: case PortWareIdentifier.HellHoundMissile: return(PortGoodCategory.Consumables); case PortWareIdentifier.Biodome: case PortWareIdentifier.CargoHold: return(PortGoodCategory.Components); default: return(PortGoodCategory.NotForSale); } }
/// <summary> /// Checks if this port is buying the specified type /// </summary> /// <param name="portWareIdentifier"></param> /// <returns></returns> public bool IsCargoForPurchase(PortWareIdentifier portWareIdentifier) { return(true); }
/// <summary> /// Note that the galaxyID will be sent to the client for purchase requests /// </summary> /// <param name="galaxyID"></param> /// <param name="goodId"></param> /// <param name="assetUrl"></param> /// <param name="description"></param> /// <param name="name"></param> /// <param name="purchasePrice"></param> /// <param name="sellPrice"></param> /// <param name="weaponStats"></param> public ModulePortGood(int galaxyID, PortWareIdentifier goodId, UIDisplayData uidata, string assetUrl, float purchasePrice, float quantity) : base(goodId, uidata, assetUrl, purchasePrice, quantity) { GalaxyID = galaxyID; }