예제 #1
0
        public static int CalculateLocalPrice(int basePrice, IWIBase item)
        {
            if (item == null)
            {
                Debug.Log("Local price in container null, returning");
                return(basePrice);
            }

            if (item.IsWorldItem)
            {
                basePrice *= Mats.MatTypeToInt(item.worlditem.Props.Global.MaterialType);
            }
            else
            {
                basePrice *= Mats.MatTypeToInt(item.GetStackItem(WIMode.None).GlobalProps.MaterialType);
            }

            if (item.IsStackContainer)
            {
                for (int i = 0; i < item.StackContainer.StackList.Count; i++)
                {
                    for (int j = 0; j < item.StackContainer.StackList[i].Items.Count; j++)
                    {
                        basePrice += Mathf.CeilToInt(item.StackContainer.StackList[i].Items[j].BaseCurrencyValue);
                    }
                }
            }

            return(basePrice);
        }
예제 #2
0
        protected IEnumerator LaunchProjectile(Equippable equippable, Weapon weapon)
        {
            if (!HasProjectile)
            {
                //if we don't have a projectile it doesn't matter
                //MasterAudio.PlaySound (mEquippable.Sounds.SoundType, ToolDoppleganger.transform, mEquippable.Sounds.SoundUseUnuccessfully);
                mEquippable.UseUnsuccessfully();
                ToolState = PlayerToolState.Equipped;
                yield break;
            }
            //convert the projectile object to a world item if it isn't already
            Projectile projectile = null;

            if (ProjectileObject.IsWorldItem)
            {
                //get the projectile from the existing worlditem
                projectile = ProjectileObject.worlditem.Get <Projectile>();
            }
            else
            {
                WorldItem worlditemProjectile = null;
                //clone the projectile from the stack item
                WorldItems.CloneFromStackItem(ProjectileObject.GetStackItem(WIMode.Stacked), WIGroups.Get.Player, out worlditemProjectile);
                //initialize immediately
                worlditemProjectile.Initialize();
                worlditemProjectile.transform.position = ToolActionPointObject.position;
                worlditemProjectile.transform.rotation = ToolActionPointObject.rotation;
                //set the projectile object to null
                ProjectileObject = null;
                //give it a second to initialze
                projectile = worlditemProjectile.Get <Projectile>();
            }

            if (projectile != null)
            {
                projectile.Launch(ToolActionPointObject, weapon, LaunchForce);
                //play the launching sound
                mEquippable.UseSuccessfully();
                //MasterAudio.PlaySound (mEquippable.Sounds.SoundType, ToolDoppleganger.transform, mEquippable.Sounds.SoundUseSuccessfully);
                yield return(null);
            }
            else
            {
                Debug.Log("Projectile was null");
            }
            RefreshToolDoppleganger(false);
            yield return(null);

            if (UsesTensionMorph)
            {
                TensionChannel.Percent = 0f;
            }
            yield break;
        }
예제 #3
0
        public void CopyFrom(IWIBase iwiBase)
        {
            if (iwiBase == null)
            {
                Clear();
            }

            if (iwiBase.IsWorldItem)
            {
                CopyFrom(iwiBase.worlditem);
            }
            else
            {
                CopyFrom(iwiBase.GetStackItem(WIMode.Stacked));
            }
        }
예제 #4
0
        public static int CalculateLocalPrice(int basePrice, IWIBase item)
        {
            if (item == null)
            {
                Debug.Log("Local price in recepticle null, returning");
                return(basePrice);
            }

            int            sizeMult = (int)item.Size;
            int            matMult  = 1;
            WIMaterialType mat      = WIMaterialType.Dirt;

            if (item.IsWorldItem)
            {
                mat = item.worlditem.Props.Global.MaterialType;
            }
            else
            {
                mat = item.GetStackItem(WIMode.None).GlobalProps.MaterialType;
            }
            switch (mat)
            {
            case WIMaterialType.Stone:
                matMult = 10;
                break;

            case WIMaterialType.Bone:
                matMult = 15;
                break;

            case WIMaterialType.Crystal:
                matMult = 20;
                break;

            case WIMaterialType.Fabric:
                matMult = 3;
                break;

            case WIMaterialType.Glass:
                matMult = 8;
                break;

            case WIMaterialType.Wood:
                matMult = 7;
                break;

            case WIMaterialType.Plant:
                matMult = 11;
                break;

            case WIMaterialType.Metal:
                matMult = 13;
                break;

            default:
                break;
            }

            basePrice *= sizeMult;
            basePrice *= matMult;

            if (item.IsStackContainer)
            {
                for (int i = 0; i < item.StackContainer.StackList.Count; i++)
                {
                    for (int j = 0; j < item.StackContainer.StackList [i].Items.Count; j++)
                    {
                        basePrice += Mathf.CeilToInt(item.StackContainer.StackList [i].Items [j].BaseCurrencyValue);
                    }
                }
            }

            return(basePrice);
        }
예제 #5
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();
        }
예제 #6
0
        //this is used in a lot of places
        //eg in player inventory squares for crafting to check if the thing you've put in the square meets requirements
        public static bool AreRequirementsMet(IWIBase item, GenericWorldItem template, BlueprintStrictness strictness, int numItemsInStack, out int maxItemsToCraft)
        {
            maxItemsToCraft = 1;

            if (item != null && item.IsQuestItem)
            {
                return(false);
            }

            bool prefabReqsMet = true;
            bool stackReqsMet  = true;
            bool stateReqsMet  = true;
            bool subCatReqsMet = true;

            //first we need to get the thing we're crafting from
            //if it's a liquid container we need to get the state data
            if (item.Is <LiquidContainer> ())
            {
                LiquidContainerState stateData = null;
                bool foundState = false;
                if (item.IsWorldItem)
                {
                    stateData  = item.worlditem.Get <LiquidContainer> ().State;
                    foundState = true;
                }
                else
                {
                    if (item.GetStackItem(WIMode.None).GetStateData <LiquidContainerState> (out stateData))
                    {
                        foundState = true;
                    }
                }

                if (foundState)
                {
                    //see if the liquid container contains what's needed
                    mCheckRequirements.CopyFrom(stateData.Contents);
                    mCheckRequirements.InstanceWeight = stateData.Contents.InstanceWeight;
                }
            }
            else
            {
                //if it's not a liquid container just get it from the item
                mCheckRequirements.CopyFrom(item);
                mCheckRequirements.InstanceWeight = numItemsInStack;
            }

            if (Flags.Check((uint)strictness, (uint)BlueprintStrictness.PrefabName, Flags.CheckType.MatchAny))
            {
                prefabReqsMet = string.Equals(mCheckRequirements.PrefabName, template.PrefabName, StringComparison.InvariantCultureIgnoreCase);
            }
            if (Flags.Check((uint)strictness, (uint)BlueprintStrictness.StackName, Flags.CheckType.MatchAny))
            {
                stackReqsMet = string.Equals(mCheckRequirements.StackName, template.StackName, StringComparison.InvariantCultureIgnoreCase);
                if (!stackReqsMet)
                {
                    try {
                        //check for the rare case where a non-numbered item is compared against a numbered item
                        //'x #' vs 'x'
                        //'x' vs 'x #'
                        bool isReqDigit  = char.IsDigit(mCheckRequirements.StackName, mCheckRequirements.StackName.Length - 1);
                        bool isItemDigit = char.IsDigit(template.StackName, template.StackName.Length - 1);
                        if (isReqDigit != isItemDigit)
                        {
                            string nonNumbered = isItemDigit ? mCheckRequirements.StackName : template.StackName;
                            string numbered    = isReqDigit ? mCheckRequirements.StackName.Substring(0, mCheckRequirements.StackName.Length - 2) : template.StackName.Substring(0, template.StackName.Length - 2);
                            stackReqsMet = nonNumbered.Equals(numbered);
                                                        #if UNITY_EDITOR
                            Debug.Log("Checking numbered against non-numbered in crafting: " + mCheckRequirements.StackName + " vs " + template.StackName + " - check " + nonNumbered + ", " + numbered + " - " + stackReqsMet.ToString());
                                                        #endif
                        }
                    } catch (Exception e) {
                        Debug.LogError("Error when checking for item digits in crafting skill: " + e.ToString());
                    }
                }
            }
            if (Flags.Check((uint)strictness, (uint)BlueprintStrictness.StateName, Flags.CheckType.MatchAny))
            {
                if ((string.IsNullOrEmpty(mCheckRequirements.State) || string.IsNullOrEmpty(template.State)) || (mCheckRequirements.State.Equals("Default") || template.State.Equals("Default")))
                {
                    stateReqsMet = true;
                }
                else
                {
                    stateReqsMet = string.Equals(mCheckRequirements.State, template.State, StringComparison.InvariantCultureIgnoreCase);
                }
            }
            if (Flags.Check((uint)strictness, (uint)BlueprintStrictness.Subcategory, Flags.CheckType.MatchAny))
            {
                if (string.IsNullOrEmpty(mCheckRequirements.Subcategory) || string.IsNullOrEmpty(template.Subcategory))
                {
                    subCatReqsMet = true;
                }
                else
                {
                    subCatReqsMet = string.Equals(mCheckRequirements.Subcategory, template.Subcategory, StringComparison.InvariantCultureIgnoreCase);
                }
            }
                        #if UNITY_EDITOR
            Debug.Log(template.PrefabName + " prefab reqs met: " + prefabReqsMet.ToString() + "\nstackReqsMet: " + stackReqsMet.ToString() + "\nstateReqsMet: " + stateReqsMet.ToString() + "\nsubCatReqsMet: " + subCatReqsMet.ToString());
                        #endif
            //max items to craft is the instance weight divided by instance weight of the template
            //instance weight of template tells us how many we need in that stack to craft
            maxItemsToCraft = mCheckRequirements.InstanceWeight / template.InstanceWeight;
            //if we have enough items to craft, we can proceed
            return(prefabReqsMet && stackReqsMet && stateReqsMet && subCatReqsMet && maxItemsToCraft >= template.InstanceWeight);
        }