예제 #1
0
        public bool FillLiquidContainer(IWIBase liquidContainer, IWIBase foodStuff, WIStack foodStuffStack)
        {
            if (!foodStuff.Is <FoodStuff>())
            {
                //nope! can't do it
                return(false);
            }

            System.Object fssObject = null;
            //check the foodstuff first since it has to be liquid
            if (foodStuff.GetStateOf <FoodStuff>(out fssObject))
            {
                FoodStuffState fss = (FoodStuffState)fssObject;
                if (fss.IsLiquid(foodStuff.State))
                {
                    //okay we've confirmed it's a liquid
                    //now see if the liquid container can hold it
                    if (!liquidContainer.Is <LiquidContainer>())
                    {
                        //we're returning true because it'll make the correct noise and the item will disappear
                        GUIManager.PostWarning("The liquid cannot be held by this container. It seeps away.");
                        foodStuff.RemoveFromGame();
                        return(true);
                    }

                    System.Object lcObject = null;
                    if (liquidContainer.GetStateOf <LiquidContainer>(out lcObject))
                    {
                        LiquidContainerState lcs         = (LiquidContainerState)lcObject;
                        string           liquidFillError = string.Empty;
                        int              numFilled       = 0;
                        GenericWorldItem genericLiquid   = new GenericWorldItem(foodStuff);
                        if (lcs.TryToFillWith(genericLiquid, foodStuffStack.NumItems, out numFilled, out liquidFillError))
                        {
                            //hooray, it worked
                            //how we have to pop items off the top of the food stuff stack
                            for (int i = 0; i < numFilled; i++)
                            {
                                Stacks.Pop.AndToss(foodStuffStack);
                            }
                            GUIManager.PostInfo("Filled " + numFilled.ToString());
                            return(true);
                        }
                        else
                        {
                            GUIManager.PostWarning(liquidFillError);
                        }
                    }
                }
            }
            return(false);
        }
예제 #2
0
        protected override void OnUseFinish()
        {
            if (ProgressCanceled)
            {
                LastCallback.SafeInvoke();
                return;
            }

            if (LastUseImmune)
            {
                //don't do anything if skill immunity was used
                return;
            }

            bool    removedItem    = false;
            bool    attachScript   = false;
            IWIBase finalItem      = null;
            string  scriptToAttach = string.Empty;

            if (State.HasBeenMastered && !string.IsNullOrEmpty(Extensions.AttachScriptOnUseUnmastered))
            {
                scriptToAttach = Extensions.AttachScriptOnUseMastered;
            }
            else if (!string.IsNullOrEmpty(Extensions.AttachScriptOnUseUnmastered))
            {
                scriptToAttach = Extensions.AttachScriptOnUseUnmastered;
            }

            //if we only target certain scripts for failure and this one doesn't have at least one of those scripts, treat it as a win
            if (Extensions.FailureTargetScripts.Count > 0)
            {
                if (MoveItemToInventory)
                {
                    if (!LastItemToMove.HasAtLeastOne(Extensions.FailureTargetScripts))
                    {
                        LastSkillResult = true;
                    }
                }
                else
                {
                    if (!LastFromStack.TopItem.HasAtLeastOne(Extensions.FailureTargetScripts))
                    {
                        LastSkillResult = true;
                    }
                }
            }

            try {
                WIStackError error = WIStackError.None;
                if (LastSkillResult)
                {
                    attachScript = Extensions.AttachScriptOnSuccess;
                    //we either add it based on inventory or else stacks
                    if (MoveItemToInventory)
                    {
                        Debug.Log("Adding to inventory, we were successful");
                        //convert it to a stack item BEFORE pushing it so we know we'll have the actual copy
                        finalItem = LastItemToMove.GetStackItem(WIMode.Unloaded);
                        StartCoroutine(LastInventory.AddItem(finalItem));
                        removedItem = true;
                    }
                    else
                    {
                        finalItem   = LastFromStack.TopItem;
                        removedItem = (Stacks.Pop.AndPush(LastFromStack, LastToStack, ref error));
                    }

                    if (State.HasBeenMastered)
                    {
                        GUIManager.PostSuccess(Extensions.GUIMessageOnSuccessMastered);
                    }
                    else
                    {
                        GUIManager.PostSuccess(Extensions.GUIMessageOnSuccessUnmastered);
                    }
                }
                else
                {
                    attachScript = Extensions.AttachScriptOnFail;
                    if (MoveItemToInventory)
                    {
                        //we're moving things into our inventory
                        if (Extensions.DestroyItemOnFail)
                        {
                            //Debug.Log("Destroying item on failure");
                            LastItemToMove.RemoveFromGame();
                            removedItem = true;
                            //don't attach a script because there's nothing to attach it to
                        }
                        else if (Extensions.SubstituteItemOnFail)
                        {
                            //Debug.Log("Adding substitution instead");
                            LastItemToMove.RemoveFromGame();
                            finalItem = Extensions.Substitution.ToStackItem();
                            StartCoroutine(LastInventory.AddItem(finalItem));
                            removedItem = true;
                        }
                        else if (Extensions.MoveItemOnFail)
                        {
                            Debug.Log("Failed, but still moving item - item null? " + (LastItemToMove == null).ToString());
                            finalItem = LastItemToMove.GetStackItem(WIMode.Unloaded);
                            StartCoroutine(LastInventory.AddItem(finalItem));
                            removedItem = true;
                        }
                    }
                    else
                    {
                        //we're moving things from stack to stack
                        if (Extensions.DestroyItemOnFail)
                        {
                            //just get rid of it
                            Stacks.Pop.AndToss(LastFromStack);
                            removedItem = true;
                        }
                        else if (Extensions.SubstituteItemOnFail)
                        {
                            //just get rid of it
                            Stacks.Pop.AndToss(LastFromStack);
                            removedItem = true;
                            //then put substitute item in other stack
                            //only attach a script if we actually push the item
                            finalItem   = Extensions.Substitution.ToStackItem();
                            removedItem = Stacks.Push.Item(LastToStack, finalItem, ref error);
                        }
                        else if (Extensions.MoveItemOnFail)
                        {
                            finalItem   = LastFromStack.TopItem;
                            removedItem = Stacks.Pop.AndPush(LastFromStack, LastToStack, ref error);
                        }
                    }

                    if (finalItem == null)
                    {
                        Debug.Log("Final item was null in remove item skill, not applying extensions");
                    }
                    else
                    {
                        if (Extensions.UnskilledRepPenaltyOnFail > 0 || Extensions.SkilledRepPenaltyOnFail > 0)
                        {
                            //only do this if we CAN suffer a rep loss
                            int globalRepLoss = 0;
                            int ownerRepLoss  = 0;
                            if (State.HasBeenMastered)
                            {
                                globalRepLoss = Mathf.Max(1, Mathf.FloorToInt(
                                                              (finalItem.BaseCurrencyValue * Globals.BaseCurrencyToReputationMultiplier) *
                                                              Mathf.Lerp(Extensions.UnskilledRepPenaltyOnFail, Extensions.SkilledRepPenaltyOnFail, State.NormalizedMasteryLevel) *
                                                              Extensions.MasterRepPenaltyOnFail));
                                ownerRepLoss = Mathf.Max(1, Mathf.FloorToInt(
                                                             (finalItem.BaseCurrencyValue * Globals.BaseCurrencyToReputationMultiplier) *
                                                             Mathf.Lerp(Extensions.UnskilledOwnerRepPenaltyOnFail, Extensions.SkilledOwnerRepPenaltyOnFail, State.NormalizedMasteryLevel) *
                                                             Extensions.MasterOwnerRepPenaltyOnFail));
                                GUIManager.PostDanger(Extensions.GUIMessageOnFailureMastered);
                            }
                            else
                            {
                                globalRepLoss = Mathf.Max(1, Mathf.FloorToInt(
                                                              (finalItem.BaseCurrencyValue * Globals.BaseCurrencyToReputationMultiplier) *
                                                              Mathf.Lerp(Extensions.UnskilledRepPenaltyOnFail, Extensions.SkilledRepPenaltyOnFail, State.NormalizedMasteryLevel)));
                                ownerRepLoss = Mathf.Max(1, Mathf.FloorToInt(
                                                             (finalItem.BaseCurrencyValue * Globals.BaseCurrencyToReputationMultiplier) *
                                                             Mathf.Lerp(Extensions.UnskilledOwnerRepPenaltyOnFail, Extensions.SkilledOwnerRepPenaltyOnFail, State.NormalizedMasteryLevel)));
                                GUIManager.PostDanger(Extensions.GUIMessageOnFailureUnmastered);
                            }
                            Profile.Get.CurrentGame.Character.Rep.LoseGlobalReputation(globalRepLoss);
                            //see if we've just stolen from a character
                            Character character = null;
                            if (LastSkillTarget != null && LastSkillTarget.IOIType == ItemOfInterestType.WorldItem && LastSkillTarget.worlditem.Is <Character>(out character))
                            {
                                Profile.Get.CurrentGame.Character.Rep.LosePersonalReputation(character.worlditem.FileName, character.worlditem.DisplayName, ownerRepLoss);
                            }
                        }
                    }
                }
            } catch (Exception e) {
                Debug.LogWarning("Couldn't move item because: " + e.ToString());
            }

            if (attachScript && finalItem != null && !string.IsNullOrEmpty(scriptToAttach))
            {
                //Debug.Log("Attaching script " + scriptToAttach + " to final item");
                finalItem.Add(scriptToAttach);
            }

            if (removedItem)
            {
                if (LastSkillResult)
                {
                    MasterAudio.PlaySound(Extensions.SoundTypeOnSuccess, Extensions.SoundOnSuccess);
                }
                else
                {
                    MasterAudio.PlaySound(Extensions.SoundTypeOnFailure, Extensions.SoundOnFailure);
                }
            }

            LastCallback.SafeInvoke();
        }
예제 #3
0
        public void AquireLastOffer()
        {
            if (LastOfferItems == null || string.IsNullOrEmpty(LastOfferType))
            {
                return;
            }

            Player.Local.Inventory.InventoryBank.AddBaseCurrencyOfType(LastOfferMade, WICurrencyType.A_Bronze);

            for (int i = 0; i < LastOfferItems.Count; i++)
            {
                mLastOfferItem = LastOfferItems[i];
                //update which items we've aquired
                switch (LastOfferType)
                {
                case "UndatedShard":
                    ActiveMuseum.UndatedShardAquired++;
                    break;

                case "UndatedSmall":
                    ActiveMuseum.UndatedSmallAquired++;
                    break;

                case "DatedShard":
                    if (mLastOfferItem.GetStateOf <ArtifactShard>(out mArtifactStateObject))
                    {
                        mArtifactShardState = (ArtifactShardState)mArtifactStateObject;
                        ActiveMuseum.DatedShardsAquired.Add(mArtifactShardState.Age);
                    }
                    break;

                case "DatedSmall":
                    if (mLastOfferItem.GetStateOf <Artifact>(out mArtifactStateObject))
                    {
                        mArtifactState = (ArtifactState)mArtifactStateObject;
                        ArtifactQuality currentQuality;
                        if (!ActiveMuseum.SmallArtifactsAquired.TryGetValue(mArtifactState.Age, out currentQuality))
                        {
                            //if we haven't alread aquired this age add it now
                            ActiveMuseum.SmallArtifactsAquired.Add(mArtifactState.Age, mArtifactState.Quality);
                        }
                        else if (IsOfHigherQuality(mArtifactState.Quality, currentQuality))
                        {
                            //set the existing entry to the newer level of quality
                            ActiveMuseum.SmallArtifactsAquired[mArtifactState.Age] = mArtifactState.Quality;
                        }
                    }
                    break;

                case "DatedLarge":
                    if (mLastOfferItem.GetStateOf <Artifact>(out mArtifactStateObject))
                    {
                        mArtifactState = (ArtifactState)mArtifactStateObject;
                        ArtifactQuality currentQuality;
                        if (!ActiveMuseum.LargeArtifactsAquired.TryGetValue(mArtifactState.Age, out currentQuality))
                        {
                            //if we haven't alread aquired this age add it now
                            ActiveMuseum.LargeArtifactsAquired.Add(mArtifactState.Age, mArtifactState.Quality);
                        }
                        else if (IsOfHigherQuality(mArtifactState.Quality, currentQuality))
                        {
                            //set the existing entry to the newer level of quality
                            ActiveMuseum.LargeArtifactsAquired[mArtifactState.Age] = mArtifactState.Quality;
                        }
                    }
                    break;

                default:
                    Debug.Log("Couldn't find artifact type " + LastOfferType);
                    break;
                }
                //destroy it - the curator will disply a doppleganger
                mLastOfferItem.RemoveFromGame();
            }

            Mods.Get.Runtime.SaveMod(ActiveMuseum, "Museum", ActiveMuseum.Name);


            LastOfferItems.Clear();
            UndatedShard.Clear();
            UndatedSmall.Clear();
            DatedShard.Clear();
            DatedSmall.Clear();
            DatedLarge.Clear();
            //this will force the containers to update their newly missing items
            GUI.GUIInventoryInterface.Get.RefreshContainers();

            RefreshCuratedItems();
        }