public async Task NegotiatePrice(Equipment item) { int charm = Player.Attribute[Attributes.charm]; charm = Math.Min(charm, 80); int maxAccept = (int)(item.Price(Data) * Math.Pow(charm, .7) / 11); int offer = (int)((6 + Random.NextDouble()) * maxAccept / 14.0); int choice = await MakeOffer(item, offer, false); if (choice == 0) { await CompleteSale(item, offer); return; } int ask = 0; OfferWindow.SetOffer(offer, ask); ask = await GetAskingPrice(); if (ask == 0) { await BuybackFormatter.SeeYouLater(); return; } if (ask < 1.5 * offer) { await CompleteSale(item, ask); return; } int spread = maxAccept - offer; if (ask > spread + maxAccept) { await ComeBackWhenSerious(); return; } spread = ask - offer; double scale = maxAccept / (double)spread; offer = (int)(offer + (1 + Random.NextDouble() * 5) * scale); maxAccept = spread; if (offer >= ask) { offer = ask - 1; } int lastAsk = ask; do { bool finalOffer = false; OfferWindow.RejectAskingPrice(ask, IsAskWayTooHigh(ask, offer, maxAccept)); choice = await MakeOffer(item, offer, finalOffer); if (choice == 0) { await CompleteSale(item, offer); return; } else if (finalOffer) { await MaybeDealLater(); return; } OfferWindow.SetOffer(offer, lastAsk); ask = await GetAskingPrice(); if (ask == 0) { await MaybeDealLater(); return; } if (ask == lastAsk || (ask > lastAsk && Random.NextDouble() < 0.5)) { await ComeBackWhenSerious(); return; } double diff = lastAsk - ask; if (diff == 0) { diff = Random.NextDouble() * 3; } if (diff / maxAccept < 0.03) { diff /= 1.3; } lastAsk = ask; spread = (int)(offer + diff / 1.2 + Random.NextDouble() * diff / 1.6); if (spread > ask - 2 && Random.NextDouble() < .5) { await CompleteSale(item, ask); return; } if (spread >= ask) { finalOffer = true; } else { offer = spread; if (ask - offer < 3) { finalOffer = true; } if (offer <= 0) { await ComeBackWhenSerious(); return; } } } while (true); }
private void SetOfferText(TextWindow offerWind, int offer, int ask) { OfferWindow.SetOffer(offer, ask); }