/*************************************************************************** * w$ = (Base$ * (Base$ * (% Demand/100))) * $PI = ((w$ * (Qty - (Tx Qty/Qty))) + w$) **************************************************************************/ public int CurrentPrice(int SectorID, int StationID, int CommodityID) { int ppi = 0; //Provides class modifiers SectorDataObject sdo = (from sl in DataController.DataAccess.SectorList where sl.sectorID.Equals(SectorID) select sl).FirstOrDefault(); //Provides qty and price property CommodityShopInventoryDataObject csi = (from cs in DataController.DataAccess.CommodityShopInventoryList where cs.stationID.Equals(StationID) && cs.commodityID.Equals(CommodityID) select cs).FirstOrDefault(); //Provides class of item CommodityDataObject cdo = (from c in DataController.DataAccess.commodityMasterList where c.commodityID.Equals(CommodityID) select c).FirstOrDefault(); int demandPercent = 0; switch (cdo.commodityClass) { case CommodityDataObject.COMMODITYCLASS.Common: demandPercent = sdo.common; break; case CommodityDataObject.COMMODITYCLASS.Luxury: demandPercent = sdo.luxury; break; case CommodityDataObject.COMMODITYCLASS.Food: demandPercent = sdo.food; break; case CommodityDataObject.COMMODITYCLASS.Minerals: demandPercent = sdo.minerals; break; case CommodityDataObject.COMMODITYCLASS.Medical: demandPercent = sdo.medical; break; case CommodityDataObject.COMMODITYCLASS.Military: demandPercent = sdo.military; break; case CommodityDataObject.COMMODITYCLASS.Industrial: demandPercent = sdo.industrial; break; default: break; } int workingPrice = (cdo.commodityBasePrice * (cdo.commodityBasePrice * (demandPercent / 100))); ppi = ((workingPrice * (csi.commodityQuantity - (csi.commodityLastQuantity / csi.commodityQuantity))) + workingPrice); return(ppi); }
/// <summary> /// Will be loaded during initial game setup; Here only for testing purposes /// </summary> internal void LoadCommodityShopInventories() { //Only happens on a NEW GAME //loop through all stores foreach (CommodityShopDataObject csd in DataController.DataAccess.commodityShopMasterList) { List<CommodityShopInventoryDataObject> tempShopInventory = new List<CommodityShopInventoryDataObject>(); //create an inventory item for each master item record we have // and assign it a quantity foreach (CommodityDataObject cd in DataController.DataAccess.commodityMasterList) { int even = (int)perItemMax / DataController.DataAccess.commodityMasterList.Count; int share = even - (DataController.DataAccess.GetRandomInt(0, 100) / 10); string shopBuysOrSells = DataController.DataAccess.GetRandomInt(0, 50) > 25 ? "B" : "S"; CommodityShopInventoryDataObject cid = new CommodityShopInventoryDataObject(csd.stationID, cd.commodityID, share, 0, shopBuysOrSells); tempShopInventory.Add(cid); } //move some of the inventory quantity around so it's not so uniform. //TODO: Check perItemMin and keep it under perItemMax foreach (CommodityShopInventoryDataObject cid in tempShopInventory) { int rndAmt = DataController.DataAccess.GetRandomInt(1, cid.commodityQuantity); int rndItem = DataController.DataAccess.GetRandomInt(0, tempShopInventory.Count - 1); tempShopInventory.ElementAt(rndItem).commodityQuantity += rndAmt; cid.commodityQuantity -= rndAmt; } //The DataController property is a pass-through to the SaveGame object DataController.DataAccess.CommodityShopInventoryList.AddRange(tempShopInventory); } }
/// <summary> /// Will be loaded during initial game setup; Here only for testing purposes /// </summary> internal void LoadCommodityShopInventories() { //Only happens on a NEW GAME //loop through all stores foreach (CommodityShopDataObject csd in DataController.DataAccess.commodityShopMasterList) { List <CommodityShopInventoryDataObject> tempShopInventory = new List <CommodityShopInventoryDataObject>(); //create an inventory item for each master item record we have // and assign it a quantity foreach (CommodityDataObject cd in DataController.DataAccess.commodityMasterList) { int even = (int)perItemMax / DataController.DataAccess.commodityMasterList.Count; int share = even - (DataController.DataAccess.GetRandomInt(0, 100) / 10); string shopBuysOrSells = DataController.DataAccess.GetRandomInt(0, 50) > 25 ? "B" : "S"; CommodityShopInventoryDataObject cid = new CommodityShopInventoryDataObject(csd.stationID, cd.commodityID, share, 0, shopBuysOrSells); tempShopInventory.Add(cid); } //move some of the inventory quantity around so it's not so uniform. //TODO: Check perItemMin and keep it under perItemMax foreach (CommodityShopInventoryDataObject cid in tempShopInventory) { int rndAmt = DataController.DataAccess.GetRandomInt(1, cid.commodityQuantity); int rndItem = DataController.DataAccess.GetRandomInt(0, tempShopInventory.Count - 1); tempShopInventory.ElementAt(rndItem).commodityQuantity += rndAmt; cid.commodityQuantity -= rndAmt; } //The DataController property is a pass-through to the SaveGame object DataController.DataAccess.CommodityShopInventoryList.AddRange(tempShopInventory); } }
/*############################################################################################# * Merchant NPCs should be loaded into GDC from MDS and augmented from the state file if a * save game has been loaded. * --- * The simulation runs on a timer, and that timer actually acts based on an interval value * that has a base setting defined above, and a random value for each NPC that is assigned * when the NPC is added to the data pool. This allows us to stagger the activity of NPCs so * they don't all act at the exact same time. * * When a tick happens, NPCs will: * * Check to see if the next action will take place in the player's current sector or not. * This will determine if we only simulate or have to instantiate * * Simulation: * If at a station, they will find a station that buys their goods for less than they * paid for them, calc the route, and jump to the first sector. * If in a sector on their route, they'll jump to the next sector in the route * If the next sector in the route is the destination sector, they'll dock immediately * at the station, sell their goods, and buy the lowest cost good that they can * afford/fit into their cargo hold * * Instantiation * If at any time any of the sim steps coincide with the player's current sector * If at a station, we instantiate the prefab at the spawn point outside of that station * and assign any data we need from the data object to the component (at least the * ID of the data object and the name of the pilot). We also generate the route as * per the sim verion and the NPC will start their trip to the necessary gate. * If in a sector, we instantiate the prefab at the gate that leads to the previous * sector. The NPC will move to the gate that leads to the next sector, and the * gate mechanics will take over at that point. * If in the destination sector, the NPC will spawn at the inbound gate and will move * to the destination station where the docking process will take over. * --- * The tick might happen before or after the player arrives in the system. In this case, the tick * will be SIMULATED and will not invoke the instantiation, so the NPC will "ghost in" while * the player isn't looking. * Certain instantiated activities will force a tick and reset the tick timer for that NPC: * * Jumping out of a system - gate mechanics transfer the NPC and resets the timer * * Docking at a station - triggers the buying and selling, and resets the timer #############################################################################################*/ /* * */ public void LoadNewMerchants() { //Takes the records from the DataController and puts them into the // working collection for use in the game. List <MerchantNPCDataObject> Merchs = DataController.DataAccess.merchantMasterList; //But we need to set them up with initial locations and purposes. foreach (MerchantNPCDataObject merch in Merchs) { //Each merchant will start at a station (currently 37) StationDataObject sdo = (from s in DataController.DataAccess.stationMasterList orderby System.Guid.NewGuid() select s).First(); merch.CurrentSectorID = sdo.sectorID; merch.CurrentStationID = sdo.stationID; //Now it needs to BUY stuff from that station // Go for the LOWEST PRICED ITEM List <CommodityShopInventoryDataObject> shopInv = DataController.DataAccess.GetShopInventory(sdo.stationID); CommodityShopInventoryDataObject csidoBuy = (from si in shopInv where si.currentPrice.Equals(shopInv.Min(s => s.currentPrice)) && si.shopBuysOrSells.Equals("S") select si).First(); int shopQty = csidoBuy.commodityQuantity; //How much can we hold? int cargoCap = (from cgo in DataController.DataAccess.cargoHoldMasterList where cgo.iD.Equals(merch.CargoID) select cgo).FirstOrDefault().capacity; //Do we have anything in there already? int cargoNow = merch.Inventory.inventoryQuantity; if (cargoNow == 0) { //They can only carry one item, and since this is the only way for them to get // items into their cargo hold, we assume they have something or they don't if (cargoNow < cargoCap) { int canBuy = cargoCap - cargoNow; if (shopQty > canBuy && (csidoBuy.currentPrice * canBuy) < merch.Wallet) { //Buy the canBuy amount. merch.Inventory.inventoryQuantity = canBuy; merch.Inventory.inventoryObjectType = PlayerInventoryDataObject.INVENTORY_TYPE.Commodity; merch.Inventory.inventoryObjectID = csidoBuy.commodityID; merch.Inventory.inventoryObjectClass = PlayerInventoryDataObject.INVENTORY_CLASS.Commodity; merch.InventoryPurchaseTotal = (canBuy * csidoBuy.currentPrice); merch.Wallet -= merch.InventoryPurchaseTotal; } else { //Need to find another low price item to buy. //Need to excise the item finding part into it's own method. //Also need to track the ID's of the items we've already tried. } } } //So we have cargo (theoretically). Figure out where in the universe we can sell this crap CommodityShopInventoryDataObject csidoSell = (from si in DataController.DataAccess.CommodityShopInventoryList where si.commodityID.Equals(csidoBuy.commodityID) && si.stationID != sdo.stationID && si.currentPrice > csidoBuy.currentPrice select si).FirstOrDefault(); //Ideally we have values. Set them merch.DestinationSectorID = 0; //Crap. Need to get this from the record we have in csidoSell :( } }