Esempio n. 1
0
        private VisDesire[] GetVisDesires()
        {
            // start by making all of the character's vis stockpiles available
            VisDesire[] desires = new VisDesire[MagicArts.Count];
            desires[0]  = new VisDesire(MagicArts.Creo, -this.GetVisCount(MagicArts.Creo));
            desires[1]  = new VisDesire(MagicArts.Intellego, -this.GetVisCount(MagicArts.Intellego));
            desires[2]  = new VisDesire(MagicArts.Muto, -this.GetVisCount(MagicArts.Muto));
            desires[3]  = new VisDesire(MagicArts.Perdo, -this.GetVisCount(MagicArts.Perdo));
            desires[4]  = new VisDesire(MagicArts.Rego, -this.GetVisCount(MagicArts.Rego));
            desires[5]  = new VisDesire(MagicArts.Animal, -this.GetVisCount(MagicArts.Animal));
            desires[6]  = new VisDesire(MagicArts.Aquam, -this.GetVisCount(MagicArts.Aquam));
            desires[7]  = new VisDesire(MagicArts.Auram, -this.GetVisCount(MagicArts.Auram));
            desires[8]  = new VisDesire(MagicArts.Corpus, -this.GetVisCount(MagicArts.Corpus));
            desires[9]  = new VisDesire(MagicArts.Herbam, -this.GetVisCount(MagicArts.Herbam));
            desires[10] = new VisDesire(MagicArts.Ignem, -this.GetVisCount(MagicArts.Ignem));
            desires[11] = new VisDesire(MagicArts.Imaginem, -this.GetVisCount(MagicArts.Imaginem));
            desires[12] = new VisDesire(MagicArts.Mentem, -this.GetVisCount(MagicArts.Mentem));
            desires[13] = new VisDesire(MagicArts.Terram, -this.GetVisCount(MagicArts.Terram));
            desires[14] = new VisDesire(MagicArts.Vim, -this.GetVisCount(MagicArts.Vim));
            foreach (IGoal goal in _goals)
            {
                goal.ModifyVisDesires(this, desires);
            }
            foreach (VisDesire desire in desires)
            {
                desire.Quantity = Math.Truncate(desire.Quantity * 2.0) / 2.0;
            }

            return(desires);
        }
Esempio n. 2
0
        private void ProcessVisOffers(List <VisTradeOffer> offers)
        {
            IEnumerable <VisTradeOffer> internalOffers = offers;

            // now we have to determine which offers to accept
            // as a first pass at an algorithm,
            // we'll sort according to amount of vis needed,
            // and attempt to fulfill trades on the vis type we need the most of

            // the front of the desires list should be the type we most want
            // the front of the stocks list should be what we most want to give up in trade
            do
            {
                var prioritizedVisDesires = _tradeDesires.VisDesires.Where(v => v.Quantity > 0).OrderByDescending(v => v.Quantity);
                var prioritizedVisStocks  = _tradeDesires.VisDesires.Where(v => v.Quantity < 0).OrderBy(v => v.Quantity);
                var bestOffers            = from offer in internalOffers
                                            join visDesire in _tradeDesires.VisDesires on offer.Ask.Art equals visDesire.Art
                                            join visStock in _tradeDesires.VisDesires on offer.Bid.Art equals visStock.Art
                                            orderby visDesire.Quantity descending, visStock.Quantity, offer.Ask.Quantity
                select offer;
                if (bestOffers.Any())
                {
                    var       offer           = bestOffers.First();
                    VisDesire mostDesired     = _tradeDesires.VisDesires[offer.Ask.Art.AbilityId % 300];
                    VisDesire mostOverstocked = _tradeDesires.VisDesires[offer.Bid.Art.AbilityId % 300];
                    if (GetVisCount(offer.Bid.Art) >= offer.Bid.Quantity && offer.Mage.GetVisCount(offer.Ask.Art) >= offer.Ask.Quantity)
                    {
                        Log.Add("Executing vis trade with " + offer.Mage.Name);
                        Log.Add("Trading " + offer.Bid.Quantity.ToString("0.000") + " pawns of " + offer.Bid.Art.AbilityName + " vis");
                        Log.Add("for " + offer.Ask.Quantity.ToString("0.000") + " pawns of " + offer.Ask.Art.AbilityName + " vis");
                        offer.Mage.Log.Add("Executing vis trade with " + Name);
                        offer.Mage.Log.Add("Trading " + offer.Ask.Quantity.ToString("0.000") + " pawns of " + offer.Ask.Art.AbilityName + " vis");
                        offer.Mage.Log.Add("for " + offer.Bid.Quantity.ToString("0.000") + " pawns of " + offer.Bid.Art.AbilityName + " vis");

                        offer.Execute();
                        internalOffers = internalOffers.Where(o => o != offer);
                        GainVis(offer.Ask.Art, offer.Ask.Quantity);
                        mostDesired.Quantity -= offer.Ask.Quantity;
                        internalOffers        = internalOffers.Where(o => o.Ask.Art != mostDesired.Art || o.Ask.Quantity <= mostDesired.Quantity);
                        UseVis(offer.Bid.Art, offer.Bid.Quantity);
                        mostOverstocked.Quantity += offer.Bid.Quantity;
                        internalOffers            = internalOffers.Where(o => o.Bid.Art != mostOverstocked.Art || o.Bid.Quantity <= Math.Abs(mostOverstocked.Quantity));
                    }
                    else
                    {
                        internalOffers = internalOffers.Where(o => o != offer);
                    }
                }
            } while (internalOffers.Any());
        }
Esempio n. 3
0
 public abstract void ModifyVisNeeds(Character character, VisDesire[] desires);
Esempio n. 4
0
 public void ModifyVisNeeds(Character character, VisDesire[] desires)
 {
     if (!_hasCovenant.IsComplete(character))
     {
         _hasCovenant.ModifyVisNeeds(character, desires);
     }
     if (!_mtCondition.IsComplete(character))
     {
         _mtCondition.ModifyVisNeeds(character, desires);
     }
 }
Esempio n. 5
0
 public void ModifyVisNeeds(Character character, VisDesire[] desires)
 {
     if (!_minScore.IsComplete(character))
     {
         _minScore.ModifyVisNeeds(character, desires);
     }
 }
Esempio n. 6
0
 public void ModifyVisNeeds(Character character, VisDesire[] desires)
 {
     if (!IsComplete(character))
     {
         foreach (AbilityScoreCondition artCondition in _artRequirements)
         {
             artCondition.ModifyVisNeeds(character, desires);
         }
     }
 }
Esempio n. 7
0
 public override void ModifyVisNeeds(Character character, VisDesire[] desires)
 {
 }
Esempio n. 8
0
 public override void ModifyVisNeeds(Character character, VisDesire[] desires)
 {
     if (!IsComplete(character))
     {
         foreach (Ability ability in _abilities)
         {
             if (MagicArts.IsArt(ability)  && character.GetType() == typeof(Magus))
             {
                 CharacterAbilityBase charAbility = character.GetAbility(ability);
                 double experienceNeeded = charAbility.GetExperienceUntilLevel(_total);
                 double visPer = 0.5 + (charAbility.Value + _total) / 20.0;
                 double visNeeded = experienceNeeded * visPer / ((Magus)(character)).VisStudyRate;
                 desires[charAbility.Ability.AbilityId % 300].Quantity += visNeeded;
             }
         }
     }
 }
Esempio n. 9
0
 public void ModifyVisNeeds(Character character, VisDesire[] desires)
 {
     if (!_hasLab.IsComplete(character))
     {
         _hasLab.ModifyVisNeeds(character, desires);
     }
     foreach (Ability ability in _visTypes)
     {
         desires[ability.AbilityId % 300].Quantity += _total;
     }
 }
Esempio n. 10
0
 public void ModifyVisNeeds(Character character, VisDesire[] desires)
 {
     _abilityScoreCondition.ModifyVisNeeds(character, desires);
 }
Esempio n. 11
0
 public void ModifyVisNeeds(Character character, VisDesire[] desires)
 {
     double visNeed = character.SeasonalAge / 20.0;
     VisCondition visCondition = new VisCondition(_artsRequired, visNeed, Desire, Tier, DueDate == null ? null : DueDate - 1);
     visCondition.ModifyVisNeeds(character, desires);
 }
Esempio n. 12
0
 public void ModifyVisNeeds(Character character, VisDesire[] desires)
 {
     _hasLabCondition.ModifyVisNeeds(character, desires);
     _attributeAbilityScore.ModifyVisNeeds(character, desires);
 }
Esempio n. 13
0
 public void ModifyVisNeeds(Character character, VisDesire[] desires)
 {
     _labScoreGoal.ModifyVisNeeds(character, desires);
 }
Esempio n. 14
0
        private VisDesire[] GetVisDesires()
        {
            // start by making all of the character's vis stockpiles available
            VisDesire[] desires = new VisDesire[15];
            desires[0] = new VisDesire(MagicArts.Creo, -this.GetVisCount(MagicArts.Creo));
            desires[1] = new VisDesire(MagicArts.Intellego, -this.GetVisCount(MagicArts.Intellego));
            desires[2] = new VisDesire(MagicArts.Muto, -this.GetVisCount(MagicArts.Muto));
            desires[3] = new VisDesire(MagicArts.Perdo, -this.GetVisCount(MagicArts.Perdo));
            desires[4] = new VisDesire(MagicArts.Rego, -this.GetVisCount(MagicArts.Rego));
            desires[5] = new VisDesire(MagicArts.Animal, -this.GetVisCount(MagicArts.Animal));
            desires[6] = new VisDesire(MagicArts.Aquam, -this.GetVisCount(MagicArts.Aquam));
            desires[7] = new VisDesire(MagicArts.Auram, -this.GetVisCount(MagicArts.Auram));
            desires[8] = new VisDesire(MagicArts.Corpus, -this.GetVisCount(MagicArts.Corpus));
            desires[9] = new VisDesire(MagicArts.Herbam, -this.GetVisCount(MagicArts.Herbam));
            desires[10] = new VisDesire(MagicArts.Ignem, -this.GetVisCount(MagicArts.Ignem));
            desires[11] = new VisDesire(MagicArts.Imaginem, -this.GetVisCount(MagicArts.Imaginem));
            desires[12] = new VisDesire(MagicArts.Mentem, -this.GetVisCount(MagicArts.Mentem));
            desires[13] = new VisDesire(MagicArts.Terram, -this.GetVisCount(MagicArts.Terram));
            desires[14] = new VisDesire(MagicArts.Vim, -this.GetVisCount(MagicArts.Vim));
            foreach (IGoal goal in _goals)
            {
                goal.ModifyVisNeeds(this, desires);
            }
            foreach (VisDesire desire in desires)
            {
                desire.Quantity = Math.Truncate(desire.Quantity * 2.0) / 2.0;
            }

            return desires;
        }
Esempio n. 15
0
        private IList<VisTradeOffer> VisForVis(Magus mage, VisDesire[] otherVisDesires)
        {
            List<VisOffer> bids = new List<VisOffer>();
            List<VisOffer> asks = new List<VisOffer>();
            for(byte i = 0; i < 15; i++)
            {
                if(VisDesires[i].Quantity < 0 && otherVisDesires[i].Quantity > 0)
                {
                    // we have a surplus, they want it
                    if(Math.Abs(VisDesires[i].Quantity) > otherVisDesires[i].Quantity)
                    {
                        // our surplus is larger than their need; fulfill the need
                        bids.Add(new VisOffer(otherVisDesires[i].Art, otherVisDesires[i].Quantity));
                    }
                    else
                    {
                        // our surplus is smaller than their need; empty our stocks
                        bids.Add(new VisOffer(otherVisDesires[i].Art, Math.Abs(VisDesires[i].Quantity)));
                    }

                }
                if(VisDesires[i].Quantity > 0 && otherVisDesires[i].Quantity < 0)
                {
                    // they have a surplus, we want it
                    if (Math.Abs(otherVisDesires[i].Quantity) > VisDesires[i].Quantity)
                    {
                        // their surplus is larger than our need; fulfill the need
                        asks.Add(new VisOffer(otherVisDesires[i].Art, VisDesires[i].Quantity));
                    }
                    else
                    {
                        // our surplus is smaller than their need; empty our stocks
                        asks.Add(new VisOffer(otherVisDesires[i].Art, Math.Abs(otherVisDesires[i].Quantity)));
                    }
                }
            }
            // we should now have a list of bids and asks
            // we need at least one bid and one ask to make a deal
            if (bids.Count() > 0 && asks.Count() > 0)
            {
                List<VisTradeOffer> visTradeOffer = new List<VisTradeOffer>();
                foreach (VisOffer bid in bids)
                {
                    foreach (VisOffer ask in asks)
                    {
                        // figure out which quantity is smaller, and make the larger one equal to that
                        if (bid.Quantity > ask.Quantity)
                        {
                           visTradeOffer.Add(new VisTradeOffer(mage, new VisOffer(bid.Art, ask.Quantity), ask));
                        }
                        else
                        {
                            visTradeOffer.Add(new VisTradeOffer(mage, bid, new VisOffer(ask.Art, bid.Quantity)));
                        }
                    }
                }
                return visTradeOffer;
            }
            return null;
        }
Esempio n. 16
0
 public MagusTradingDesires(Magus magus, VisDesire[] visDesires, IEnumerable<BookDesire> booksDesired, IEnumerable<BookForTrade> booksForTrade)
 {
     Mage = magus;
     VisDesires = visDesires;
     BookDesires = booksDesired.ToDictionary(l => l.Ability);
     BooksForTrade = booksForTrade;
 }