Esempio n. 1
0
        public override bool Use(IItemOfInterest targetObject, int flavorIndex)
        {
            //first check if we're dealing directly with a barterable object
            IInventory barterInventory = targetObject.gameObject.GetComponent("IInventory") as IInventory;
            Container  container       = null;
            Character  character       = null;

            if (barterInventory == null)
            {
                //if not, check if we're dealing with an owned container
                if (targetObject.IOIType == ItemOfInterestType.WorldItem && targetObject.worlditem.Is <Container> (out container))
                {
                    //get the owner of the container
                    IStackOwner owner = null;
                    if (targetObject.worlditem.Group.HasOwner(out owner) && owner.IsWorldItem)
                    {
                        barterInventory = (IInventory)owner.worlditem.GetComponent(typeof(IInventory));
                    }
                    else                        //if the owner isn't a world item then it hasn't been loaded
                                                //TODO handle unloaded shop owners
                    {
                    }
                    character = owner.worlditem.Get <Character> ();
                }
            }
            else
            {
                character = targetObject.worlditem.Get <Character> ();
            }

            if (character != null)
            {
                ReputationState rep = Profile.Get.CurrentGame.Character.Rep.GetReputation(character.worlditem.FileName);
                if (rep.NormalizedReputationDifference(Profile.Get.CurrentGame.Character.Rep.GlobalReputation) > Extensions.MaxNormaliedReputationDifference)
                {
                    GUIManager.PostWarning(character.worlditem.DisplayName + " is not interested in bartering with you.");
                    return(false);
                }
            }

            if (barterInventory != null)
            {
                if (mCurrentSession == null)
                {
                    mCurrentSession = new BarterSession(this, mCharacterGoods, mPlayerGoods);
                }
                mCurrentSession.Reset(Player.Local.Inventory, barterInventory);
                mCurrentSession.BarteringCharacter = character;
                if (flavorIndex > 0)
                {
                    //flavor 0 is default mode
                    //flavor 1 is zero cost mode (friends, multiplayer, etc)
                    mCurrentSession.ZeroCostMode = true;
                }
                SpawnBarterDialog();
                return(true);
            }
            return(false);
        }
Esempio n. 2
0
 protected float GetCharacterReputation()
 {
     if (!HasFocus)
     {
         return(0f);
     }
     return(ReputationState.NormalizeRep(Profile.Get.CurrentGame.Character.Rep.GetPersonalReputation(Conversation.LastInitiatedConversation.SpeakingCharacter.State.Name.FileName)));
 }
Esempio n. 3
0
        public override void TryToRemoveItem(IStackOwner skillUseTarget, WIStack fromStack, WIStack toStack, WIGroup toGroup, Action callBack, int flavor)
        {
            //instead of attempting to remove it now
            //this skill launched the barter dialog
            //and sets up a session
            WorldItem worldItem = null;

            Stacks.Convert.TopItemToWorldItem(fromStack, out worldItem);
            IWIBase    worldItemToMove = worldItem;
            IInventory barterInventory = null;
            Character  character       = null;

            //this only works with character-owned items
            if (skillUseTarget.IsWorldItem && skillUseTarget.worlditem.Is <Character> (out character))
            {
                barterInventory = character;
                //make sure we can actually barter with the player
                ReputationState rep = Profile.Get.CurrentGame.Character.Rep.GetReputation(character.worlditem.FileName);
                if (rep.NormalizedReputationDifference(Profile.Get.CurrentGame.Character.Rep.GlobalReputation) > Extensions.MaxNormaliedReputationDifference)
                {
                    GUIManager.PostWarning(character.worlditem.DisplayName + " is not interested in bartering with you.");
                    return;
                }

                if (mCurrentSession == null)
                {
                    mCurrentSession = new BarterSession(this, mCharacterGoods, mPlayerGoods);
                }
                mCurrentSession.Reset(Player.Local.Inventory, barterInventory);
                mCurrentSession.BarteringCharacter = character;
                //add the selected goods to the current session immediately
                //so it's there when we start bartering
                mCurrentSession.CharacterStartupItem = worldItemToMove;
                //if the startup item is already in the character's inventory
                //no need to create a startup stack
                //but if it isn't we'll need the startup stack to display it
                WIStack startupStack = null;
                if (!character.HasItem(worldItemToMove, out startupStack))
                {
                    Debug.Log("Item " + worldItemToMove.FileName + " was NOT in character's inventory, creating temporary startup stack");
                    if (fromStack.NumItems == 1)
                    {
                        //just hold the one item
                        mCurrentSession.CharacterStartupStack = character.HoldTemporaryItem(worldItemToMove);
                    }
                    else
                    {
                        mCurrentSession.CharacterStartupStack = character.HoldTemporaryItem(fromStack);
                    }
                }
                else
                {
                    Debug.Log("Item " + worldItemToMove.FileName + " was in character's inventory");
                    mCurrentSession.CharacterStartupStack = startupStack;
                }
                SpawnBarterDialog();
            }
        }
Esempio n. 4
0
 public override void PopulateExamineList(List <WIExamineInfo> examine)
 {
     if (IsDead)
     {
         return;
     }
     examine.Add(Template.ExamineInfo);
     examine.Add(new WIExamineInfo("Their reputation in general is " + ReputationState.ReputationToDescription(State.GlobalReputation)
                                   + "; your reputation with them is " + ReputationState.ReputationToDescription(Profile.Get.CurrentGame.Character.Rep.GetPersonalReputation(worlditem.FileName))));
 }
        private void ChangeReputation(MachineReputation reputation, ReputationState reputationState, string displayLocation, string reason)
        {
            bool reputationChanged = false;
            var  oldReputation     = reputationState.Reputation;

            lock (reputationState)
            {
                reputationChanged = reputationState.Reputation != reputation;

                // Setting a new reputation.
                // NOTE: This means that the transition from 'Bad' to 'Missing' is possible here. We allow this because Missing means
                // we were able to connect to the machine, which means that we restored connectivity and the machine's reputation should no
                // longer be 'Bad'
                reputationState.Reputation = reputation;

                switch (reputation)
                {
                case MachineReputation.Bad:
                case MachineReputation.Timeout:
                    reputationState.ExpireTime = _clock.UtcNow + _configuration.BadReputationTtl;
                    break;

                case MachineReputation.Missing:
                    reputationState.ExpireTime = _clock.UtcNow + _configuration.MissingContentReputationTtl;
                    break;

                case MachineReputation.Good:
                    reputationState.ExpireTime = DateTime.MaxValue;
                    break;
                }
            }

            if (reputationChanged)
            {
                _context.Debug($"Changed reputation{reason} (new: {reputation}, old: {oldReputation}) for machine with location {displayLocation}.");
            }
        }
Esempio n. 6
0
    private void SetReputationForState(ReputationState state, int count,
                                       Dictionary <string, Reputation> groupsOfSameType,
                                       IReadOnlyDictionary <string, Reputation> entityGroupRelationships)
    {
        for (var i = 0; i < count; i++)
        {
            var group = groupsOfSameType.Keys.ElementAt(Random.Range(0, groupsOfSameType.Count));

            if (state == ReputationState.Neutral)
            {
                entityGroupRelationships[group].Relationships.Add(_name, 0);

                Relationships.Add(group, 0);
            }
            else
            {
                entityGroupRelationships[group].Relationships.Add(_name, _reputationStateThresholds[state]);

                Relationships.Add(group, _reputationStateThresholds[state]);
            }

            groupsOfSameType.Remove(group);
        }
    }
Esempio n. 7
0
        protected override void OnUseStart()
        {
            if (LastSkillRoll == SkillRollType.Success)
            {
                Character       character  = LastSkillTarget.worlditem.Get <Character>();
                ReputationState rep        = Profile.Get.CurrentGame.Character.Rep.GetReputation(character.worlditem.FileName);
                int             repChange  = Mathf.FloorToInt(Mathf.Lerp(Extensions.PersonalRepBonusUnskilled, Extensions.PersonalRepBonusSkilled, State.NormalizedMasteryLevel));
                int             repPenalty = Mathf.FloorToInt(Mathf.Lerp(Extensions.PersonalRepPenaltyUnskilled, Extensions.PersonalRepPenaltySkilled, State.NormalizedMasteryLevel));
                if (HasBeenMastered)
                {
                    repPenalty = Mathf.FloorToInt(repPenalty * Extensions.PersonalRepPenaltyMaster);
                }

                ReputationModifier repMod = new ReputationModifier(
                    DisplayName,
                    repChange,
                    1.0f,
                    true,
                    EffectTime,
                    (float)WorldClock.AdjustedRealTime,
                    repPenalty);
                rep.AddModifier(repMod);
            }
        }
Esempio n. 8
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. 9
0
        public override void TryToRemoveItem(IStackOwner skillUseTarget, IWIBase worldItemToMove, IInventory toInventory, Action callBack, int flavor)
        {
            //instead of attempting to remove it now
            //this skill launched the barter dialog
            //and sets up a session
            if (flavor == BuyFlavor)
            {
                int baseCurrencyValue = Mathf.CeilToInt(worldItemToMove.BaseCurrencyValue);
                if (Player.Local.Inventory.InventoryBank.CanAfford(baseCurrencyValue))
                {
                    Player.Local.Inventory.InventoryBank.TryToRemove(baseCurrencyValue);
                    worldItemToMove.Add("OwnedByPlayer");
                    WIStackError error = WIStackError.None;
                    if (!Player.Local.Inventory.AddItems(worldItemToMove, ref error))
                    {
                        Player.Local.ItemPlacement.ItemForceCarry(worldItemToMove.worlditem);
                    }
                    //improve rep with shopkeeper
                    Profile.Get.CurrentGame.Character.Rep.GainPersonalReputation(skillUseTarget.FileName, skillUseTarget.DisplayName, Globals.ReputationChangeTiny);
                    return;
                }
                else
                {
                    GUIManager.PostInfo("You can't afford that.");
                    return;
                }
            }
            else
            {
                IInventory barterInventory = null;
                Character  character       = null;
                //this only works with character-owned items
                if (skillUseTarget.IsWorldItem && skillUseTarget.worlditem.Is <Character> (out character))
                {
                    barterInventory = character;
                    //make sure we can actually barter with the player
                    ReputationState rep = Profile.Get.CurrentGame.Character.Rep.GetReputation(character.worlditem.FileName);
                    if (rep.NormalizedReputationDifference(Profile.Get.CurrentGame.Character.Rep.GlobalReputation) > Extensions.MaxNormaliedReputationDifference)
                    {
                        GUIManager.PostWarning(character.worlditem.DisplayName + " is not interested in bartering with you.");
                        return;
                    }

                    if (mCurrentSession == null)
                    {
                        mCurrentSession = new BarterSession(this, mCharacterGoods, mPlayerGoods);
                    }
                    mCurrentSession.Reset(Player.Local.Inventory, barterInventory);
                    mCurrentSession.BarteringCharacter = character;
                    //add the selected goods to the current session immediately
                    //so it's there when we start bartering
                    mCurrentSession.CharacterStartupItem = worldItemToMove;
                    WIStack startupStack = null;
                    //if the startup item is already in the character's inventory
                    //no need to create a startup stack
                    //but if it isn't we'll need the startup stack to display it
                    if (!character.HasItem(worldItemToMove, out startupStack))
                    {
                        //TODO put entire container in inventory
                        Debug.Log("Item " + worldItemToMove.FileName + " was NOT in character's inventory, creating temporary startup stack");
                        mCurrentSession.CharacterStartupStack = character.HoldTemporaryItem(worldItemToMove);
                    }
                    SpawnBarterDialog();
                }
            }
        }