protected IEnumerator AddToReceptaclePivotOverTime(WorldItem potentialOccupant, ReceptaclePivot pivotInFocus) { //remove it from any situation that could cause a c**k-up worlditem.Group.AddChildItem(potentialOccupant); potentialOccupant.SetMode(WIMode.World); //this will put it into the world and un-equip it etc //wait for that to happen yield return(null); WIStack pivotStack = worlditem.StackContainer.StackList [pivotInFocus.State.Index]; WIStackError error = WIStackError.None; //do not auto convert to stack item if (!Stacks.Push.Item(pivotStack, potentialOccupant, StackPushMode.Manual, ref error)) { Debug.Log("Couldn't push item into group because " + error.ToString()); yield break; } //wait again for the worlditem to get situated yield return(null); potentialOccupant.OnRemoveFromStack += Refresh; potentialOccupant.OnModeChange += Refresh; potentialOccupant.tr.parent = pivotInFocus.tr; //this will move it into the recepticle position pivotInFocus.Refresh(); yield return(null); OnItemPlacedInReceptacle.SafeInvoke(); mAddingToReceptaclePivot = false; }
protected void FillTrapWithGoodies(float skillRoll) { int numGoodies = Mathf.Max(1, Mathf.FloorToInt(skillRoll * Globals.TrappingNumWaterGoodiesPerSkillRoll)); StackItem goodie = null; WICategory category = null; WIStackError error = WIStackError.None; if (WorldItems.Get.Category(FillCategoryName, out category)) { for (int i = 0; i < numGoodies; i++) { if (WorldItems.RandomStackItemFromCategory(category, out goodie)) { Stacks.Push.Item(worlditem.StackContainer, goodie, ref error); } } } if (worlditem.StackContainer.IsFull) { Trigger(null); } else { PlayAnimation(AnimationTriggerClipName); } }
public virtual bool AddToReceptacle(WorldItem potentialOccupant) { if (State.Locked) { return(false); } if (mCooldownStartTime + mCooldownInterval > WorldClock.RealTime) { return(false); } bool result = false; ReceptaclePivot emptyPivot = null; if (HasRoom(potentialOccupant, out emptyPivot) && IsObjectPermitted(potentialOccupant, emptyPivot.Settings)) { //first we have to move the potential occupant into our group WIStack pivotStack = worlditem.StackContainer.StackList [emptyPivot.State.Index]; WIStackError error = WIStackError.None; result = Stacks.Push.Item(pivotStack, potentialOccupant, ref error); } if (result) { potentialOccupant.OnRemoveFromStack += Refresh; potentialOccupant.OnUnloaded += Refresh; potentialOccupant.OnAddedToPlayerInventory += Refresh; OnItemPlacedInReceptacle.SafeInvoke(); emptyPivot.Refresh(); } return(result); }
public void AquirePotion(string potionName, int numItems) { Potion potion = null; if (mPotionLookup.TryGetValue(potionName, out potion)) { //create a potion stack item from the generic world item gPotionGenericWorldItem.Subcategory = potionName; gPotionGenericWorldItem.DisplayName = potion.CommonName; Debug.Log("Got potion " + potionName + " now adding to inventory"); for (int i = 0; i < numItems; i++) { StackItem potionStackItem = gPotionGenericWorldItem.ToStackItem(); WIStackError error = WIStackError.None; if (!Player.Local.Inventory.AddItems(potionStackItem, ref error)) { Debug.Log("Couldn't add potion " + potionName + " to inventory for some reason"); } } } else { Debug.Log("Couldn't find potion name " + potionName + " in lookup"); } }
public void OnPlayerUseWorldItemSecondary(object secondaryResult) { WIListResult dialogResult = secondaryResult as WIListResult; switch (dialogResult.SecondaryResult) { case "RemovePowerSource": WIStackError error = WIStackError.None; if (Player.Local.Inventory.AddItems(PowerSourceDopplegangerProps.ToStackItem(), ref error)) { HasPowerSource = false; OnPowerSourceRemoved.SafeInvoke(); FXManager.Get.SpawnFX(worlditem.tr.position, FXOnPowerSourceRemoved); } break; case "AddPowerSource": if (Player.Local.Tool.IsEquipped && Stacks.Can.Stack(Player.Local.Tool.worlditem, PowerSourceDopplegangerProps)) { //PowerSourceDopplegangerProps.CopyFrom (Player.Local.Tool.worlditem); Player.Local.Tool.worlditem.RemoveFromGame(); HasPowerSource = true; Refresh(); } break; default: break; } }
protected void FillCraftingSquares() { foreach (InventorySquareCrafting square in CraftingSquaresRow0) { if (square.EnabledForBlueprint) { StackItem stackItem = square.RequiredItemTemplate.ToStackItem(); WIStackError error = WIStackError.None; Stacks.Push.Item(square.Stack, stackItem, ref error); } } foreach (InventorySquareCrafting square in CraftingSquaresRow1) { if (square.EnabledForBlueprint) { StackItem stackItem = square.RequiredItemTemplate.ToStackItem(); WIStackError error = WIStackError.None; Stacks.Push.Item(square.Stack, stackItem, ref error); } } foreach (InventorySquareCrafting square in CraftingSquaresRow2) { if (square.EnabledForBlueprint) { StackItem stackItem = square.RequiredItemTemplate.ToStackItem(); WIStackError error = WIStackError.None; Stacks.Push.Item(square.Stack, stackItem, ref error); } } }
public void SwapStackWithSelectedStack(WIStack selectedStack) { WIStackError error = WIStackError.None; if (Stacks.Add.Items(selectedStack, mStack, ref error)) { UpdateDisplay(); } }
public bool PushWearable(Wearable wearable) { if (!mStack.HasTopItem && Wearable.CanWear(Type, BodyPart, Orientation, wearable.worlditem)) { WIStackError error = WIStackError.None; return(Stacks.Push.Item(mStack, wearable.worlditem, ref error)); } return(false); }
protected void SendItemsBackToInventory() { if (GameManager.Is(FGameState.InGame)) { SendRequirementsRowBackToInventory(CraftingSquaresRow0); SendRequirementsRowBackToInventory(CraftingSquaresRow1); SendRequirementsRowBackToInventory(CraftingSquaresRow2); WIStackError error = WIStackError.None; } }
protected void TryToFillBookStand() { if (worlditem.StackContainer.IsEmpty) { StackItem item = Books.Get.RandomBookAvatarStackItem(); WIStackError error = WIStackError.None; Stacks.Push.Item(worlditem.StackContainer, item, ref error); State.LastTimeFilled = WorldClock.AdjustedRealTime; } }
protected IEnumerator Unequip() { //turn off the player projection (even if it's not already on) player.Projections.WeaponTrajectory.Hide(); ToolState = PlayerToolState.Unequipping; //clear all actions mActions.Clear(); LaunchForce = 0f; yield return(StartCoroutine(PlayAnimation("ToolGenericUnequip"))); //clear dopplegangers, projectiles, etc if (HasProjectile) { WIStackError stackError = WIStackError.None; if (ProjectileStack != null) { //push the projectile onto the bottom of its stack //this will prevent rampant AQI switching Stacks.Push.Item(ProjectileStack, ProjectileObject, false, StackPushMode.Auto, ref stackError); } else { //if we don't have the stack any more just add it to the player inventory player.Inventory.AddItems(ProjectileObject, ref stackError); } ProjectileObject = null; ProjectileStack = null; } ToolState = PlayerToolState.Unequipped; RefreshToolDoppleganger(false); if (HasWorldItem) { //parent the worlditem back under its group just in case //this will become unnecessary eventually //worlditem.UnlockTransform (tr); UnlockWorldItem(); if (worlditem.Is(WIMode.Equipped)) { worlditem.SetMode(WIMode.Stacked); } worlditem = null; } //if we're unequipping because the AQI is changing //then wait here until it's finished while (player.Inventory.LockQuickslots) { yield return(null); } yield break; }
protected void SendRequirementsRowBackToInventory(List <InventorySquareCrafting> row) { for (int i = 0; i < row.Count; i++) { InventorySquareCrafting square = row[i]; if (square.HasStack && square.Stack.NumItems > 0) { WIStackError error = WIStackError.None; Player.Local.Inventory.AddItems(square.Stack, ref error); } } }
protected IEnumerator TryToFillBookcase() { if (State.HasBeenFilled) { yield break; } State.HasBeenFilled = true; while (worlditem.Group == null) { //wait for on initialized to finish working yield return(null); } WIStackContainer stackContainer = worlditem.StackContainer; List <StackItem> avatarStackItems = new List <StackItem>(); switch (State.FillMethod) { case ContainerFillMethod.AllRandomItemsFromCategory: default: var getStackItemsByBookAndOwner = Books.Get.BookStackItemsByFlagsAndOwner(stackContainer.NumStacks, State.Flags, State.ManualSkillLevel, worlditem, true, avatarStackItems); while (getStackItemsByBookAndOwner.MoveNext()) { yield return(getStackItemsByBookAndOwner.Current); } break; case ContainerFillMethod.SpecificItems: Books.Get.BookStackItemsByName(State.SpecificBooks, avatarStackItems); break; } WIStackError error = WIStackError.None; for (int i = 0; i < avatarStackItems.Count; i++) { if (!Stacks.Push.Item(stackContainer, avatarStackItems[i], ref error)) { break; } yield return(null); } yield return(null); //wait for one last bit, then refresh our recepticle worlditem.Get <Receptacle>().Refresh(); yield break; }
public bool AddItems(IWIBase inventoryItem) { bool result = false; WIStackError error = WIStackError.None; foreach (WIStackContainer container in ActiveStackContainers) { if (Stacks.Add.Items(inventoryItem, container, ref error)) { // //Debug.Log ("Added " + inventoryItem.name + " to stack container in world item inventory"); result = true; break; } } return(result); }
public void OnClickTakeAllButton() { WIStackError error = WIStackError.None; bool allItemsGone = true; foreach (WIStack stack in ContainerDisplay.Enabler.EnablerContainer.StackList) { if (stack.NumItems > 0 && !Player.Local.Inventory.AddItems(stack, ref error)) { allItemsGone = false; } } Refresh(); /* * if (allItemsGone) { * TakeAllButton.SendMessage ("SetDisabled", SendMessageOptions.DontRequireReceiver); * } */ }
public void OnPlayerUseWorldItemSecondary(object secondaryResult) { WIListResult dialogResult = secondaryResult as WIListResult; switch (dialogResult.SecondaryResult) { case "Pluck": WIStackError error = WIStackError.None; WorldItem pluckedWorldItem = null; if (WorldItems.CloneWorldItem(PluckedItem, STransform.zero, false, WIGroups.GetCurrent(), out pluckedWorldItem)) { pluckedWorldItem.Initialize(); } Player.Local.Inventory.AddItems(pluckedWorldItem, ref error); creature.OnTakeDamage(); creature.FleeFromThing(Player.Local); break; default: break; } }
public void OnPlayerUseWorldItemSecondary(object secondaryResult) { WIListResult dialogResult = secondaryResult as WIListResult; switch (dialogResult.SecondaryResult) { case "PourOnSelf": MasterAudio.PlaySound(MasterAudio.SoundType.PlayerInterface, "FillLiquidContainer"); Player.Local.Status.RemoveCondition("BurnedByFire"); Player.Local.Status.AddCondition("Wet"); State.Contents.Clear(); break; case "Drink": WorldItem liquid = null; if (WorldItems.Get.PackPrefab(State.Contents.PackName, State.Contents.PrefabName, out liquid)) //this is tricky - we want to drink it without destroying the prefab { FoodStuff foodstuff = null; if (liquid.Is <FoodStuff>(out foodstuff)) //DON'T consume the foodstuff! { FoodStuff.Drink(foodstuff); State.Contents.InstanceWeight--; GUIManager.PostInfo("Drank 1 " + State.Contents.DisplayName + ", " + State.Contents.InstanceWeight.ToString() + "/" + State.Capacity.ToString() + " left."); } } break; case "Pour Out": //two options here //if we're in the inventory then we want to add our contents to the selected stack //if we're in the world we want to dump it into the world bool playSound = false; if (PrimaryInterface.IsMaximized("Inventory")) { WIStack selectedStack = Player.Local.Inventory.SelectedStack; if (Stacks.Can.Stack(selectedStack, State.Contents)) { WIStackError error = WIStackError.None; for (int i = 0; i < State.Contents.InstanceWeight; i++) { StackItem contents = State.Contents.ToStackItem(); if (!Stacks.Push.Item(selectedStack, contents, ref error)) { break; } else { playSound = true; } } } } else { State.Contents.Clear(); GUIManager.PostInfo("Discarded contents"); if (Player.Local.Surroundings.IsWorldItemInRange) { Flammable flammable = null; if (Player.Local.Surroundings.WorldItemFocus.worlditem.Is <Flammable>(out flammable) && flammable.IsOnFire) { flammable.Extinguish(); } } playSound = true; } if (playSound) { MasterAudio.PlaySound(MasterAudio.SoundType.PlayerInterface, "FillLiquidContainer"); } break; default: break; } }
public virtual void OnClickSquare() { if (!IsEnabled || !HasStack) { return; } if (InterfaceActionManager.LastMouseClick == 1) { OnRightClickSquare(); return; } WIStackError error = WIStackError.None; bool playSound = false; bool splitStack = false; bool quickAdd = false; string soundName = "InventoryPlaceStack"; //skill usage bool useSkillToRemove = false; //left clicking can pick up, split, or quick-add if (InterfaceActionManager.Get.IsKeyDown(InterfaceActionType.StackSplit)) { splitStack = true; } /* else if (AllowShiftClick && InterfaceActionManager.Get.IsKeyDown (InterfaceActionType.StackQuickAdd)) { * quickAdd = true; * }*/ mRemoveItemSkillNames.Clear(); if (mStack.HasOwner(out mSkillUseTarget)) { //SKILL USE if (mSkillUseTarget.UseRemoveItemSkill(mRemoveItemSkillNames, ref mSkillUseTarget)) { useSkillToRemove = true; quickAdd = false; } } WIStack selectedStack = Player.Local.Inventory.SelectedStack; if (mStack.HasTopItem) { //if our stack has items if (selectedStack.HasTopItem) { //and the selected stack ALSO has items //------Special cases------// //LIQUID CONTAINER CHECK - can we put the thing we're holding into the thing we've clicked? if (FillLiquidContainer(mStack.TopItem, selectedStack.TopItem, selectedStack)) { playSound = true; soundName = "FillLiquidContainer"; } else if (Stacks.Can.Stack(mStack.TopItem, selectedStack.TopItem)) { //if the selected stack's items can stack with our stack's items, //then we're putting items IN the stack //this is only allowed if the stack isn't owned if (useSkillToRemove) { //play an error and get out MasterAudio.PlaySound(MasterAudio.SoundType.PlayerInterface, SoundNameFailure); return; } else { //otherwise try to add the items normally playSound = Stacks.Add.Items(selectedStack, mStack, ref error); } } else { //if the selected stack's items can't be stacked //then we're swapping the stack //ie, we're removing items FROM the stack //this is only allowed if the stack isn't owned if (useSkillToRemove) { //so play an error and get out MasterAudio.PlaySound(MasterAudio.SoundType.PlayerInterface, SoundNameFailure); return; } else { //otherwise try to swap stacks normally playSound = Stacks.Swap.Stacks(mStack, selectedStack, ref error); } } } else { //----SHIFT CLICK CHECK----// //check for shift click - this bypasses everything and adds the item to the player's inventory //this only works if the stack does not already belong to the player's group if (quickAdd) { //Debug.Log ("Starting quick add.."); if (Player.Local.Inventory.CanItemFit(mStack.TopItem)) { if (Player.Local.Inventory.QuickAddItems(mStack, ref error)) { soundName = "InventoryPickUpStack"; playSound = true; } } else { GUIManager.PostWarning(mStack.TopItem.DisplayName + " won't fit in your inventory"); } } else { //if the selected stack does NOT have any items //we're putting items IN the stack if (splitStack && mStack.NumItems > 1) { //we're splitting the stack and adding the contents to the selected stack //this is only allowed if the stack isn't owned if (useSkillToRemove) { //play an error and get out MasterAudio.PlaySound(MasterAudio.SoundType.PlayerInterface, SoundNameFailure); return; } int numToAdd = mStack.NumItems / 2; bool addResult = true; //IWIBase topItem = null; for (int i = 0; i < numToAdd; i++) { if (!Stacks.Pop.AndPush(mStack, selectedStack, ref error)) { addResult = false; break; } } playSound = addResult; } else { //if we're not splitting stacks //THIS is where we finally REMOVE items from this stack using a skill if (useSkillToRemove) { UseSkillsToRemoveStack(); return; } else if (Stacks.Add.Items(mStack, selectedStack, ref error)) { playSound = true; soundName = "InventoryPickUpStack"; } } } } } else if (selectedStack.HasTopItem) { //if our stack does NOT have items //we're adding items TO our stack //this is only allowed if the stack isn't owned if (useSkillToRemove) { //so play an error and get out MasterAudio.PlaySound(MasterAudio.SoundType.PlayerInterface, SoundNameFailure); return; } else if (Stacks.Add.Items(selectedStack, mStack, ref error)) { //otherwise try to add the items and get out playSound = true; } } if (error != WIStackError.None) { GUIManager.PostStackError(error); } if (playSound) { MasterAudio.PlaySound(MasterAudio.SoundType.PlayerInterface, soundName); } UpdateDisplay(); }
IEnumerator FillContainerOverTime(bool immediately) { if (!immediately) { yield return(null); //wait for a tick to let recepticles etc. update properties } State.LastFillTime = WorldClock.AdjustedRealTime; //fill container WIStackError error = WIStackError.None; WIStackContainer container = worlditem.StackContainer; int numDesired = State.NumberOfItems; int numAdded = 0; int lastItemIndex = 0; int maxDuplicates = 3; bool continueFilling = true; int hashCode = Mathf.Abs((worlditem.Group.Props.UniqueID + worlditem.FileName).GetHashCode()); int numDuplicates = 0; bool belowDuplicateThreshold = true; GenericWorldItem genericItem = null; WICategory category = null; IBank bank = null; if (State.FillBank) { Character character = null; if (worlditem.Is <Character> (out character) && character.HasBank) { bank = character.InventoryBank; Bank.FillWithRandomCurrency(bank, character.State.Flags.Wealth); } } switch (State.NumberOfItemsRandomness) { case ContainerFillRandomness.Slight: default: numDesired = Mathf.Max(1, numDesired + UnityEngine.Random.Range(-1, 1)); break; case ContainerFillRandomness.Moderate: numDesired = Mathf.Max(1, numDesired + UnityEngine.Random.Range(-5, 5)); break; case ContainerFillRandomness.Extreme: numDesired = Mathf.Max(1, numDesired + UnityEngine.Random.Range(-10, 10)); break; } yield return(null); switch (State.FillMethod) { case ContainerFillMethod.AllRandomItemsFromCategory: default: if (WorldItems.Get.Category(State.WICategoryName, out category)) { Dictionary <string, int> itemsSoFar = new Dictionary <string, int> (); if (category.HasMinInstanceItems) { gMinInstanceItems.Clear(); category.GetMinInstanceItems(gMinInstanceItems); for (int i = 0; i < gMinInstanceItems.Count; i++) { if (itemsSoFar.TryGetValue(gMinInstanceItems [i].PrefabName, out numDuplicates)) { numDuplicates++; itemsSoFar [gMinInstanceItems [i].PrefabName] = numDuplicates; } else { itemsSoFar.Add(gMinInstanceItems [i].PrefabName, 1); } StackItem item = gMinInstanceItems [i].ToStackItem(); if (item != null) { if (State.AddCurrencyToBank && bank != null && item.Is("Currency")) { bank.Add(Mathf.FloorToInt(item.BaseCurrencyValue), item.CurrencyType); item.Clear(); } else { //add the generic item to the container as a stack item if (!Stacks.Add.Items(item, container, ref error)) { continueFilling = false; } else { numAdded++; } } } } gMinInstanceItems.Clear(); } yield return(null); while (continueFilling && category.GetItem(State.Flags, hashCode, ref lastItemIndex, out genericItem)) { //make sure we don't have a duplicate if (itemsSoFar.TryGetValue(genericItem.PrefabName, out numDuplicates)) { numDuplicates++; if (numDuplicates < maxDuplicates) { itemsSoFar [genericItem.PrefabName] = numDuplicates; } else { belowDuplicateThreshold = false; } } else { itemsSoFar.Add(genericItem.PrefabName, 1); } yield return(null); if (belowDuplicateThreshold) { //this might be a currency item - if it is, add it to the bank StackItem item = genericItem.ToStackItem(); if (State.AddCurrencyToBank && bank != null && item.Is("Currency")) { bank.Add(Mathf.FloorToInt(item.BaseCurrencyValue), item.CurrencyType); item.Clear(); } else { //add the generic item to the container as a stack item if (!Stacks.Add.Items(item, container, ref error)) { continueFilling = false; } else { numAdded++; } } } //are we done yet? if (numAdded >= numDesired || container.IsFull || !belowDuplicateThreshold) { continueFilling = false; } //wait a tick unless we need to finish this immediately //if (!immediately) { yield return(null); //} } } break; case ContainerFillMethod.OneRandomItemFromCategory: if (WorldItems.Get.Category(State.WICategoryName, out category)) { if (category.GetItem(State.Flags, hashCode, ref lastItemIndex, out genericItem)) { for (int i = 0; i < numDesired; i++) { if (!Stacks.Add.Items(genericItem.ToStackItem(), container, ref error)) { break; } else { numAdded++; } if (container.IsFull) { break; } } } } break; case ContainerFillMethod.SpecificItems: if (WorldItems.Get.Category(State.WICategoryName, out category)) { for (int i = 0; i < State.SpecificItems.Count; i++) { GenericWorldItem specificItem = State.SpecificItems [i]; Stacks.Add.Items(specificItem.ToStackItem(), container, ref error); } } break; } State.NumTimesFilled++; mIsFilling = false; yield return(null); if (worlditem.Is <Stolen> ()) { //the goods in a stolen container are also marked as stolen Stacks.Add.ScriptToItems(container, "Stolen"); } yield break; }
public override void OnClickSquare() { if (!IsEnabled) { return; } bool pickUp = false; bool playSound = false; bool showMenu = false; WIStackError error = WIStackError.None; if (InterfaceActionManager.LastMouseClick == 1) { showMenu = true; } if (showMenu) { if (mStack.HasTopItem) { WorldItem topItem = null; WorldItemUsable usable = null; if (!mStack.TopItem.IsWorldItem) { Stacks.Convert.TopItemToWorldItem(mStack, out topItem); } else { topItem = mStack.TopItem.worlditem; } if (mUsable != null) { mUsable.Finish(); mUsable = null; } usable = topItem.gameObject.GetOrAdd <WorldItemUsable>(); usable.ShowDoppleganger = false; usable.TryToSpawn(true, out mUsable, NGUICamera); usable.ScreenTarget = transform; usable.ScreenTargetCamera = NGUICamera; usable.RequirePlayerFocus = false; //the end result *should* affect the new item return; } } if (Player.Local.Inventory.SelectedStack.IsEmpty) { if (mStack.NumItems == 1) { playSound = Stacks.Add.Items(mStack, Player.Local.Inventory.SelectedStack, ref error); pickUp = true; } else { return; } } else if (Player.Local.Inventory.SelectedStack.NumItems == 1) { if (mStack.IsEmpty) { playSound = Stacks.Add.Items(Player.Local.Inventory.SelectedStack, mStack, ref error); } else { playSound = Stacks.Swap.Stacks(Player.Local.Inventory.SelectedStack, mStack, ref error); } } if (playSound) { if (pickUp) { MasterAudio.PlaySound(MasterAudio.SoundType.PlayerInterface, "InventoryPickUpStack"); } else { MasterAudio.PlaySound(MasterAudio.SoundType.PlayerInterface, "InventoryPlaceStack"); } } else { //we did nothing - show a help dialog GUIManager.PostIntrospection("This is a spot for containers. Containers let me carry things.", true); } Refresh(); }
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(); } } }
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(); }
public override void OnClickSquare() { if (!IsEnabled) { return; } bool result = false; bool pickUp = false; bool playSound = false; bool playErrorSound = false; WIStackError error = WIStackError.None; if (Player.Local.Inventory.SelectedStack.HasTopItem) { Wearable wearable = null; IWIBase topItem = Player.Local.Inventory.SelectedStack.TopItem; if (Wearable.CanWear(Type, BodyPart, Orientation, topItem)) { if (mStack.HasTopItem) { if (Stacks.Swap.Stacks(mStack, Player.Local.Inventory.SelectedStack, ref error)) { pickUp = true; playSound = true; result = true; } else { result = false; playSound = true; } } else { Stacks.Add.Items(Player.Local.Inventory.SelectedStack, mStack, ref error); playSound = true; result = true; } } else { result = false; playErrorSound = true; } } else { Stacks.Add.Items(mStack, Player.Local.Inventory.SelectedStack, ref error); pickUp = true; playSound = true; result = true; } if (playSound) { if (pickUp) { MasterAudio.PlaySound(MasterAudio.SoundType.PlayerInterface, "InventoryPickUpStack"); } else { MasterAudio.PlaySound(MasterAudio.SoundType.PlayerInterface, "InventoryPlaceStack"); } } else if (playErrorSound) { MasterAudio.PlaySound(MasterAudio.SoundType.PlayerInterface, "ButtonClickDisabled"); } RefreshRequest(); }
public void OnClickSquare() { Debug.Log("Clicking result square"); WIStackError error = WIStackError.None; if (ReadyForRetrieval) { Debug.Log("Is ready for retrieval"); while (NumItemsCrafted > 0) { StackItem craftedItem = CraftedItemTemplate.ToStackItem(); craftedItem.Group = WIGroups.Get.Player; if (craftedItem.CanEnterInventory) { if (Player.Local.Inventory.AddItems(craftedItem, ref error)) { Debug.Log("Added item to inventory"); NumItemsCrafted--; } else { Debug.Log("Couldn't add to inventory, what now?"); break; } } else { Debug.Log("We have to carry the item"); if (Player.Local.ItemPlacement.IsCarryingSomething) { Player.Local.ItemPlacement.PlaceOrDropCarriedItem(); } //turn it into a worlditem and have the player carry it WorldItem craftedWorldItem = null; if (WorldItems.CloneFromStackItem(craftedItem, WIGroups.GetCurrent(), out craftedWorldItem)) { craftedWorldItem.Props.Local.CraftedByPlayer = true; craftedWorldItem.Initialize(); craftedWorldItem.ActiveState = WIActiveState.Active; craftedWorldItem.Props.Local.FreezeOnStartup = false; craftedWorldItem.tr.rotation = Quaternion.identity; craftedWorldItem.SetMode(WIMode.World); craftedWorldItem.tr.position = Player.Local.ItemPlacement.GrabberIdealPosition; craftedWorldItem.LastActiveDistanceToPlayer = 0f; //if we have an interface open, close it now GUIInventoryInterface.Get.Minimize(); //then force the player to carry the item if (Player.Local.ItemPlacement.ItemCarry(craftedWorldItem, true)) { NumItemsCrafted--; } else { GUIManager.PostWarning("You have to drop what you're carrying first"); } //set placement mode to true immediately Player.Local.ItemPlacement.PlacementModeEnabled = true; } break; } } } else { Debug.Log("Not ready for retrieval"); } RefreshRequest(); }