Esempio n. 1
0
        public int NumGoodsSent(BarterParty party, WIStack stack)
        {
            List <BarterGoods> goods = null;

            if (party == BarterParty.Player)
            {
                goods = PlayerGoods;
            }
            else
            {
                goods = CharacterGoods;
            }
            int numItems = 0;

            foreach (BarterGoods good in goods)
            {
                if (good.TryGetValue(stack, out numItems))
                {
                    break;
                }
            }
            return(numItems);
        }
Esempio n. 2
0
        public void RecalculateValueOfGoods(BarterParty party, bool recalculateItems)
        {
            if (!IsActive)
            {
                TotalValueCharacterGoods = 0;
                TotalValuePlayerGoods    = 0;
                BaseValueCharacterGoods  = 0;
                BaseValuePlayerGoods     = 0;
                return;
            }

            List <BarterGoods> goods = CharacterGoods;

            if (party == BarterParty.Player)
            {
                goods = PlayerGoods;
            }

            if (goods.Count == 0)
            {
                BaseValueCharacterGoods = 0;
                BaseValuePlayerGoods    = 0;
            }
            else if (recalculateItems)
            {
                float baseValueOfGoods = 0;
                foreach (BarterGoods good in goods)
                {
                    int numItems = good.NumItems;
                    if (numItems > 0)
                    {
                        IWIBase topItem       = good.TopItem;
                        float   goodBaseValue = topItem.BaseCurrencyValue;
                        if (topItem.Is <Stolen> ())
                        {
                            goodBaseValue *= Globals.StolenGoodsValueMultiplier;
                        }
                        baseValueOfGoods += goodBaseValue * numItems;
                    }
                }
                if (party == BarterParty.Player)
                {
                    BaseValuePlayerGoods = baseValueOfGoods;
                }
                else
                {
                    BaseValueCharacterGoods = baseValueOfGoods;
                }
            }

            float           repPriceModifier = 0f;
            ReputationState rep = null;

            if (IsBarteringWithCharacter)
            {
                rep = Profile.Get.CurrentGame.Character.Rep.GetReputation(BarteringCharacter.worlditem.FileName);
                repPriceModifier = rep.NormalizedOffsetReputation;                //this will be a value from -1 to 1
            }
            else
            {
                repPriceModifier = Profile.Get.CurrentGame.Character.Rep.NormalizedOffsetGlobalReputation;
            }
            float skillPriceModifier  = BarterManager.State.NormalizedOffsetUsageLevel;           //this will be a value from -1 to 1
            float regionPriceModifier = 0f;
            float goodsPriceModifier  = (repPriceModifier + skillPriceModifier + regionPriceModifier) / 2f;

            if (BarterManager.HasBeenMastered)
            {
                //mastering the barter skill reduces all penalties to zero
                goodsPriceModifier = Mathf.Max(0, goodsPriceModifier);
            }
            goodsPriceModifier *= Globals.BarterMaximumPriceModifier;

            //divide the final modifier by 2 to get its effects on both sets of goods
            TotalValuePlayerGoods    = Mathf.FloorToInt(BaseValuePlayerGoods + (BaseValuePlayerGoods * (goodsPriceModifier / 2f)));
            TotalValueCharacterGoods = Mathf.FloorToInt(BaseValueCharacterGoods - (BaseValueCharacterGoods * (goodsPriceModifier / 2f)));
            //the value of currency is not affected by reputation or skill
            TotalValuePlayerGoods    += PlayerGoodsBank.BaseCurrencyValue;
            TotalValueCharacterGoods += CharacterGoodsBank.BaseCurrencyValue;
            ReputationPriceModifier   = repPriceModifier;
            SkillPriceModifier        = skillPriceModifier;
            FinalPriceModifier        = goodsPriceModifier;

            RefreshAction.SafeInvoke();
        }
Esempio n. 3
0
        public bool AddGoods(WIStack newGoodsStack, int numGoodsToAdd, BarterParty party)
        {
            bool result = false;
            List <BarterGoods> goods = CharacterGoods;

            if (party == BarterParty.Player)
            {
                goods = PlayerGoods;
            }

            int         goodIndex        = 0;
            int         numExistingGoods = 0;
            BarterGoods existingGood     = null;
            BarterGoods emptyGood        = null;
            BarterGoods compatibleGood   = null;

            foreach (BarterGoods good in goods)
            {
                if (good.Count == 0)
                {
                    if (emptyGood == null)
                    {
                        //save our first empty record for later
                        emptyGood = good;
                    }
                }
                else
                {
                    //there's a chance this good already has a record for this stack
                    //if that's the case we can drop it here and end our search
                    if (good.TryGetValue(newGoodsStack, out numExistingGoods))
                    {
                        //hooray, success
                        existingGood = good;
                    }
                    else if (compatibleGood == null)
                    {
                        //okay, it wasn't in the records, but it may still stack
                        //get the top item in this good and see if it stacks with the new item
                        WIStack topRecord = good.Keys.First();
                        if (Stacks.Can.Stack(topRecord, newGoodsStack))
                        {
                            //save our first compatible record for later
                            compatibleGood = good;
                        }
                    }
                }
                goodIndex++;
                //don't break the look if we've found a compatible good
                //because we don't want to lose the chance that we
                //find the existing record entry
            }
            //the only way we've left by now is if we found an exact mach
            //so settle for second and third best here
            if (existingGood != null)
            {
                //we set numExistingGoods when we found the existing good
                //so just add the goods to add and we're set
                existingGood [newGoodsStack] = (numExistingGoods + numGoodsToAdd);
                result = true;
            }
            else if (compatibleGood != null)
            {
                compatibleGood.Add(newGoodsStack, numGoodsToAdd);
                result = true;
            }
            else if (emptyGood != null)
            {
                emptyGood.Add(newGoodsStack, numGoodsToAdd);
                result = true;
            }
            if (result)
            {
                //recaluclate our total values
                RecalculateValueOfGoods(party, true);
                //refresh our squares and interface
                RefreshAction.SafeInvoke();
            }
            return(result);
        }
Esempio n. 4
0
        public bool RemoveGoods(BarterParty party, IWIBase goodToRemove, int numToRemove)
        {
            if (goodToRemove == null || numToRemove == 0)
            {
                return(false);
            }

            List <BarterGoods> goods = null;

            if (party == BarterParty.Player)
            {
                goods = PlayerGoods;
            }
            else
            {
                goods = CharacterGoods;
            }
            List <KeyValuePair <BarterGoods, WIStack> > goodStacksToRemove = new List <KeyValuePair <BarterGoods, WIStack> > ();
            List <KeyValuePair <KeyValuePair <BarterGoods, WIStack>, int> > goodStacksToUpdate = new List <KeyValuePair <KeyValuePair <BarterGoods, WIStack>, int> > ();

            foreach (BarterGoods good in goods)
            {
                foreach (KeyValuePair <WIStack, int> goodPair in good)
                {
                    if (Stacks.Can.Stack(goodPair.Key, goodToRemove))
                    {
                        if (numToRemove <= 1)
                        {
                            //simple removal
                            int numItems = goodPair.Value;
                            numItems--;
                            if (numItems <= 0)
                            {
                                goodStacksToRemove.Add(new KeyValuePair <BarterGoods, WIStack> (good, goodPair.Key));
                            }
                            else
                            {
                                goodStacksToUpdate.Add(new KeyValuePair <KeyValuePair <BarterGoods, WIStack>, int> (new KeyValuePair <BarterGoods, WIStack> (good, goodPair.Key), numItems));
                            }
                            break;
                        }
                        else
                        {
                            //TODO removal of multiple items across multiple stacks
                        }
                    }
                }
            }
            foreach (KeyValuePair <BarterGoods, WIStack> goodStackToRemove in goodStacksToRemove)
            {
                goodStackToRemove.Key.Remove(goodStackToRemove.Value);
            }
            foreach (KeyValuePair <KeyValuePair <BarterGoods, WIStack>, int> goodToUpdate in goodStacksToUpdate)
            {
                goodToUpdate.Key.Key [goodToUpdate.Key.Value] = goodToUpdate.Value;
            }
            //recaluclate our total values
            RecalculateValueOfGoods(party, true);
            //update squares and interface
            RefreshAction.SafeInvoke();
            return(true);
        }