void Update() { if (!GetComponent <CharacterMovement>().isInTransit()) { currentCity = destinationCity; SellGoods(this.oracle); BuyGoodsAndSetDestination(this.oracle); } }
public void BuyGoodsAndSetDestination(TradeOracle oracle) { Log("Start BuyGoodsAndSetDestination"); TradeOrders orders = oracle.WhatShouldIBuy(sheet.inventory, currentCity, currentCity.MarketPlace.TradeRoutes); Log("Current city:" + currentCity); destinationCity = orders.Destination.CityOne; if (currentCity == orders.Destination.CityOne) { destinationCity = orders.Destination.CityToo; } Log("Destination city:" + destinationCity); Log("Starting currency:" + sheet.inventory.currency); sheet.inventory.currency -= currentCity.MarketPlace.BuyThese(orders.Manifests); Log("After trade currency:" + sheet.inventory.currency); Log("Items before purchase:" + Item.ListToString(sheet.inventory.items)); sheet.inventory.AddCollection(orders.Manifests); Log("Items after purchase:" + Item.ListToString(sheet.inventory.items)); GetComponent <CharacterMovement>().destination = destinationCity.gameObject.GetComponent <NavigationWaypoint>(); Log("End BuyGoodsAndSetDestination"); }
public void WhatShouldISell(TradeCity currentCity, List <Item> manifest) { List <Item> toSell = new List <Item>(); //foreach (TradeData data in currentCity.MarketPlace.TradeDataManifest) //{ // if (manifest != null) // { // foreach (Item item in manifest) // { // if (item.Type == data.Item) // { // if (data.CurrentCost() > item.PurchasedPrice) // { // if (toSell.Contains(item)) // { // toSell.Add(manifest[item]); // } // else // { // toSell.Add(item, manifest[item]); // } // Log("Decided to sell:" + item.Type + " at " + data.CurrentCost() + " bought it at " + item.PurchasedPrice + " for a profit of " + (item.PurchasedPrice - data.CurrentCost())); // } // else // { // Log("Decided not to sell:" + item.Type + " at " + data.CurrentCost() + " bought it at " + item.PurchasedPrice + " for a loss of " + (data.CurrentCost() - item.PurchasedPrice)); // } // } // } // } //} //TradeOrders tradeOrder = GameObject.FindGameObjectWithTag("GameManager").AddComponent<TradeOrders>(); //tradeOrder.Manifests = toSell; }
public List <Instruction> GetInstructions(CharacterSheet sheet) { this.logger = GameObject.FindGameObjectWithTag("GameManager").GetComponent <GameManager>().GetLogger(); //First Go to Local Trade House //Find out what all it has //Look at list of other trade houses //See who needs what this house has //Take an item there //set sheet base city as the destination city //if no matches and other cities travel to them List <Instruction> instructions = new List <Instruction>(); Instruction goToTradeHouse = new Instruction(); goToTradeHouse.destination = sheet.baseCity.TradeHouses[0].gameObject.GetComponent <NavigationWaypoint>(); goToTradeHouse.building = sheet.baseCity.TradeHouses[0]; goToTradeHouse.gather = new ItemType[] { }; goToTradeHouse.give = new ItemType[] { }; instructions.Add(goToTradeHouse); Dictionary <ItemType, int> currentCityHas = sheet.baseCity.TradeHouses[0].inventory.GetCountOfItems(); Dictionary <TradeCity, Dictionary <ItemType, int> > otherCitiesHave = new Dictionary <TradeCity, Dictionary <ItemType, int> >(); RegionOracle regionOracle = GameObject.FindGameObjectWithTag("GameManager").GetComponent <GameManager>().GetRegionOracle(); foreach (TownOracle townOracle in regionOracle.townOracles) { otherCitiesHave.Add(townOracle.town.GetComponent <TradeCity>(), townOracle.town.GetComponent <TradeCity>().TradeHouses[0].inventory.GetCountOfItems()); } TradeCity newBaseCity = sheet.baseCity; logger.Log(debug, "Starting multicitytrader foreach loop"); foreach (ItemType item in currentCityHas.Keys) { logger.Log(debug, "Searing for item:(" + item + ") which has amount:(" + currentCityHas[item] + ")"); if (currentCityHas[item] > allItemsAtLeast) { logger.Log(debug, "Item:(" + item + ") can be traded"); foreach (TradeCity town in otherCitiesHave.Keys) { logger.Log(debug, "Searing for item:(" + item + ") in town (" + town.name + ")"); if (!otherCitiesHave[town].ContainsKey(item) || otherCitiesHave[town][item] <= allItemsAtLeast) { logger.Log(debug, "Item:(" + item + ") can be traded to town (" + town.name + ")"); Instruction getTradeItem = new Instruction(); goToTradeHouse.destination = sheet.baseCity.TradeHouses[0].gameObject.GetComponent <NavigationWaypoint>(); goToTradeHouse.building = sheet.baseCity.TradeHouses[0]; goToTradeHouse.gather = new ItemType[] { item }; goToTradeHouse.give = new ItemType[] { }; instructions.Add(goToTradeHouse); Instruction depositTradeItem = new Instruction(); depositTradeItem.destination = town.TradeHouses[0].gameObject.GetComponent <NavigationWaypoint>(); depositTradeItem.building = town.TradeHouses[0]; depositTradeItem.gather = new ItemType[] { }; depositTradeItem.give = new ItemType[] { item }; instructions.Add(depositTradeItem); newBaseCity = town; } } } } if (newBaseCity == sheet.baseCity) { foreach (TownOracle townOracle in regionOracle.townOracles) { if (townOracle.town.GetComponent <TradeCity>() != sheet.baseCity) { sheet.baseCity = townOracle.town.GetComponent <TradeCity>(); break; } } } else { sheet.baseCity = newBaseCity; } return(instructions); }
public void Register() { TradeCity city = GetClosestCity(); if (!city) { logger.Log(debug, "Everything is aweeful"); return; } logger.Log(debug, "Everything is awesome"); JobOracle oracle = GameObject.FindGameObjectWithTag("GameManager").GetComponent <GameManager>().GetJobOracle(); System.Type buildingType = this.GetType(); if (buildingType == typeof(Bakery)) { city.Bakeries.Add((Bakery)this); } else if (buildingType == typeof(Barn)) { city.Barns.Add((Barn)this); } else if (buildingType == typeof(BowShop)) { city.BowShops.Add((BowShop)this); } else if (buildingType == typeof(Brewhouse)) { city.Brewhouses.Add((Brewhouse)this); } else if (buildingType == typeof(CharcoalPit)) { city.CharcoalPits.Add((CharcoalPit)this); } else if (buildingType == typeof(Farm)) { city.Farms.Add((Farm)this); } else if (buildingType == typeof(Forest)) { city.Forests.Add((Forest)this); } else if (buildingType == typeof(Foundry)) { city.Foundries.Add((Foundry)this); } else if (buildingType == typeof(GuildHall)) { city.GuildHalls.Add((GuildHall)this); } else if (buildingType == typeof(HuntingLodge)) { city.HuntingLodges.Add((HuntingLodge)this); } else if (buildingType == typeof(LogStore)) { city.LogStores.Add((LogStore)this); } else if (buildingType == typeof(Masonry)) { city.Masonries.Add((Masonry)this); } else if (buildingType == typeof(Mill)) { city.Mills.Add((Mill)this); } else if (buildingType == typeof(Mine)) { city.Mines.Add((Mine)this); } else if (buildingType == typeof(OreShop)) { city.OreShops.Add((OreShop)this); } else if (buildingType == typeof(Pond)) { city.Ponds.Add((Pond)this); } else if (buildingType == typeof(SawHouse)) { city.SawHouses.Add((SawHouse)this); } else if (buildingType == typeof(Smithy)) { city.Smithies.Add((Smithy)this); } else if (buildingType == typeof(Tavern)) { city.Taverns.Add((Tavern)this); } else if (buildingType == typeof(WoodCut)) { city.WoodCuts.Add((WoodCut)this); } else if (buildingType == typeof(TradeHouse)) { city.TradeHouses.Add((TradeHouse)this); } oracle.AddJobs(CurrentPositions, TotalPositions); }
public TradeOrders WhatShouldIBuy(Inventory traderInventory, TradeCity currentCity, List <TradeRoute> avaliableTradeRoutes) { int bestProfit = 0; Item bestItem = new Item(); int canAffordOfBestItem = 0; TradeRoute bestRoute = avaliableTradeRoutes[0]; int purchasedPrice = 0; foreach (TradeRoute route in avaliableTradeRoutes) { TradeCity destination = route.CityOne; if (route.CityOne == currentCity) { destination = route.CityToo; } Log("Assesing city:" + destination); foreach (TradeData currentTradeData in currentCity.MarketPlace.TradeDataManifest) { if (currentTradeData.CurrentCost() < traderInventory.currency) { Log("Can Afford " + currentTradeData.ToString()); foreach (TradeData destinationTradeData in destination.MarketPlace.TradeDataManifest) { if (currentTradeData.Item == destinationTradeData.Item) { if (destinationTradeData.CurrentCost() - currentTradeData.CurrentCost() > bestProfit) { Log("Can make a new best profit at :" + (destinationTradeData.CurrentCost() - currentTradeData.CurrentCost()) + " better then :" + bestProfit); bestProfit = destinationTradeData.CurrentCost() - currentTradeData.CurrentCost(); bestItem.Type = currentTradeData.Item; canAffordOfBestItem = traderInventory.currency / currentTradeData.CurrentCost(); bestRoute = route; purchasedPrice = currentTradeData.CurrentCost(); } else { Log("Can not make a new best profit at :" + (destinationTradeData.CurrentCost() - currentTradeData.CurrentCost()) + " worse then :" + bestProfit); } } } } else { Log("Can Not Afford " + currentTradeData.ToString()); } } } List <Item> manifest = new List <Item>(); bestItem.PurchasedPrice = purchasedPrice; manifest.Add(bestItem); TradeOrders tradeOrder = GameObject.FindGameObjectWithTag("GameManager").AddComponent <TradeOrders>(); tradeOrder.Manifests = manifest; tradeOrder.Destination = bestRoute; Log("Decided on " + canAffordOfBestItem + " of " + bestItem.Type + " at " + bestItem.PurchasedPrice + " for a gain of " + bestProfit); return(tradeOrder); }