public IList <BookTradeOffer> GenerateBookTradeOffers(MagusTradingDesires tradeDesires) { List <BookTradeOffer> tradeList = new List <BookTradeOffer>(); foreach (BookForTrade book in BooksForTrade) { if (tradeDesires.BookDesires.ContainsKey(book.Book.Topic) && tradeDesires.Mage.ValidToRead(book.Book)) { // we have a book they want, see if they have a book we want foreach (BookForTrade theirBook in tradeDesires.BooksForTrade) { if (BookDesires.ContainsKey(theirBook.Book.Topic) && Mage.ValidToRead(theirBook.Book) && theirBook.Book.Quality == book.Book.Quality && theirBook.Book.Level <= book.Book.Level + 1.0 && theirBook.Book.Level >= book.Book.Level - 1.0) { tradeList.Add(new BookTradeOffer(tradeDesires.Mage, book.Book, theirBook.Book)); } } } } return(tradeList); }
public IList <VisForBookOffer> GenerateSellBookOffers(MagusTradingDesires otherDesires) { List <VisForBookOffer> bookTradeOffers = new List <VisForBookOffer>(); if (BooksForTrade.Any() && otherDesires.BookDesires.Any()) { // we have books, they want books foreach (BookForTrade bookForTrade in BooksForTrade) { // if we're interested in the topic of this book and it's of sufficient level if (otherDesires.BookDesires.ContainsKey(bookForTrade.Book.Topic) && otherDesires.BookDesires[bookForTrade.Book.Topic].CurrentLevel < bookForTrade.Book.Level && otherDesires.Mage.ValidToRead(bookForTrade.Book)) { // evaluate the value of the book to them double bookVisValue = otherDesires.Mage.RateLifetimeBookValue(bookForTrade.Book); // TODO: improve pricing mechanics double price = bookVisValue + bookForTrade.MinimumPrice / 2; var offer = GenerateVisOffer(price, otherDesires.VisDesires, VisDesires); if (offer != null) { bookTradeOffers.Add(new VisForBookOffer(otherDesires.Mage, offer, price, bookForTrade.Book)); } } } } return(bookTradeOffers); }
public MagusTradingDesires GenerateTradingDesires() { _tradeDesires = new MagusTradingDesires( this, GetVisDesires(), GetBookDesires().Distinct(), EvaluateBookValuesAsSeller(GetUnneededBooksFromCollection()) ); if (_tradeDesires == null) { throw new NullReferenceException(); } return(_tradeDesires); }
private void AddWritingGoals(MagusTradingDesires tradingDesires) { // TODO: right now, this logic is causing characters to start trying to learn skills // they have no interest in so that they can write a book to sell off // this may not be inherently wrong, but it should certainly be the case that more attractive choices always exist double comm = GetAttributeValue(AttributeType.Communication); foreach (BookDesire bookDesire in tradingDesires.BookDesires.Values) { CharacterAbilityBase charAbility = GetAbility(bookDesire.Ability); bool isArt = MagicArts.IsArt(bookDesire.Ability); if (!_tractatusGoals.Where(t => !t.IsComplete(this) && t.Topic == bookDesire.Ability).Any() && (isArt || comm > -2)) { // add tractatus goal to both goal list and writing goal list ushort previouslyWrittenCount = GetTractatiiWrittenOnTopic(bookDesire.Ability); string name = Name + " " + bookDesire.Ability.AbilityName + " T" + previouslyWrittenCount.ToString(); TractatusGoal tractGoal = new TractatusGoal(bookDesire.Ability, name, previouslyWrittenCount); _tractatusGoals.Add(tractGoal); _goals.Add(tractGoal); } double baseLevel = charAbility.Value / 2.0; // don't add a summa goal if we already have one for this topic in progress if (baseLevel - 1 > bookDesire.CurrentLevel && !_summaGoals.Where(s => !s.IsComplete(this) && s.Topic == charAbility.Ability).Any()) { // try to constrain the level of the summa to be something doable in an efficient period of time double rate = comm + GetAbility(_writingLanguage).Value; double writingPointsNeeded = isArt ? bookDesire.CurrentLevel + 1 : bookDesire.CurrentLevel * 5 + 5; double efficientLevel = Math.Ceiling(writingPointsNeeded / rate) * rate; if (efficientLevel < baseLevel) { // add summa goal to both goal list and writing goal list string name = Name + " " + bookDesire.Ability.AbilityName + " Summa L" + efficientLevel.ToString("0.00"); SummaGoal summaGoal = new SummaGoal(bookDesire.Ability, efficientLevel, name); _goals.Add(summaGoal); _summaGoals.Add(summaGoal); } else if (writingPointsNeeded < rate) { // it's a one-season summa, may as well do it if it's better than practice // but we should make sure that it's worth at least two seasons of study double quality = comm + 6; double xpToLevel = baseLevel * (baseLevel + 1) / 2.0; if(!isArt) { xpToLevel *= 5; } if (xpToLevel >= 2 * quality && (isArt || quality > 4)) { string name = Name + " " + bookDesire.Ability.AbilityName + " Summa L" + (charAbility.Value / 2.0).ToString("0.00"); SummaGoal summaGoal = new SummaGoal(bookDesire.Ability, baseLevel, name); _goals.Add(summaGoal); _summaGoals.Add(summaGoal); } } } } }
public MagusTradingDesires GenerateTradingDesires() { _tradeDesires = new MagusTradingDesires( this, GetVisDesires(), GetBookDesires().Distinct(), EvaluateBookValuesAsSeller(GetUnneededBooksFromCollection()) ); if (_tradeDesires == null) { throw new NullReferenceException(); } return _tradeDesires; }
public IList <VisTradeOffer> GenerateVisOffers(MagusTradingDesires otherDesires) { // handle vis trades return(VisForVis(otherDesires.Mage, otherDesires.VisDesires)); }
public IList<VisTradeOffer> GenerateVisOffers(MagusTradingDesires otherDesires) { // handle vis trades return VisForVis(otherDesires.Mage, otherDesires.VisDesires); }
public IList<BookVisOffer> GenerateSellBookOffers(MagusTradingDesires otherDesires) { List<BookVisOffer> bookTradeOffers = new List<BookVisOffer>(); if (BooksForTrade.Any() && otherDesires.BookDesires.Any()) { // we have books, they want books foreach (BookForTrade bookForTrade in BooksForTrade) { // if we're interested in the topic of this book and it's of sufficient level if (otherDesires.BookDesires.ContainsKey(bookForTrade.Book.Topic) && otherDesires.BookDesires[bookForTrade.Book.Topic].CurrentLevel < bookForTrade.Book.Level && otherDesires.Mage.ValidToRead(bookForTrade.Book)) { // evaluate the value of the book to them double bookVisValue = otherDesires.Mage.RateLifetimeBookValue(bookForTrade.Book); // TODO: improve pricing mechanics double price = bookVisValue + bookForTrade.MinimumPrice / 2; for (int i = 0; i < 15; i++) { if (-(otherDesires.VisDesires[i].Quantity) >= price && VisDesires[i].Quantity >= price) { // we can offer this sort of vis for the book bookTradeOffers.Add(new BookVisOffer(otherDesires.Mage, VisDesires[i].Art, price, bookForTrade.Book)); } } } } } return bookTradeOffers; }
public IList<BookTradeOffer> GenerateBookTradeOffers(MagusTradingDesires tradeDesires) { List<BookTradeOffer> tradeList = new List<BookTradeOffer>(); foreach(BookForTrade book in BooksForTrade) { if (tradeDesires.BookDesires.ContainsKey(book.Book.Topic) && tradeDesires.Mage.ValidToRead(book.Book)) { // we have a book they want, see if they have a book we want foreach (BookForTrade theirBook in tradeDesires.BooksForTrade) { if (BookDesires.ContainsKey(theirBook.Book.Topic) && Mage.ValidToRead(theirBook.Book) && theirBook.Book.Quality == book.Book.Quality && theirBook.Book.Level <= book.Book.Level + 1.0 && theirBook.Book.Level >= book.Book.Level - 1.0) { tradeList.Add(new BookTradeOffer(tradeDesires.Mage, book.Book, theirBook.Book)); } } } } return tradeList; }