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 override void WakeUp() { base.WakeUp(); CurrentStartupPosition = null; CurrentClothingCategory = null; CurrentItemCategory = null; ControllingTabPage.OnSelected += Show; ControllingTabPage.OnDeselected += Hide; NextStartupPosition.target = gameObject; PrevStartupPosition.target = gameObject; NextClothingCategory.target = gameObject; PrevClothingCategory.target = gameObject; NextItemsCategory.target = gameObject; PrevItemsCategory.target = gameObject; NextItemsCategory.functionName = "OnClickNextItemsCategory"; PrevItemsCategory.functionName = "OnClickPrevItemsCategory"; NextClothingCategory.functionName = "OnClickNextClothingCategory"; PrevClothingCategory.functionName = "OnClickPrevClothingCategory"; NextStartupPosition.functionName = "OnClickNextStartupPosition"; PrevStartupPosition.functionName = "OnClickPrevStartupPosition"; }
public void OnClickNextClothingCategory() { int currentIndex = AvailableClothingCategories.IndexOf(CurrentClothingCategory); CurrentClothingCategory = AvailableClothingCategories.NextItem(currentIndex); CurrentStartupPosition.WearableFillCategory = CurrentClothingCategory.Name; Mods.Get.Runtime.SaveMod(CurrentStartupPosition, "PlayerStartupPosition", CurrentStartupPosition.Name); RefreshCategory(CurrentClothingCategory, ClothingLabel, ClothingDescriptionLabel); }
public void OnClickPrevItemsCategory() { int currentIndex = AvailableCategories.IndexOf(CurrentItemCategory); CurrentItemCategory = AvailableCategories.PrevItem(currentIndex); CurrentStartupPosition.InventoryFillCategory = CurrentItemCategory.Name; Mods.Get.Runtime.SaveMod(CurrentStartupPosition, "PlayerStartupPosition", CurrentStartupPosition.Name); RefreshCategory(CurrentItemCategory, CategoryLabel, CategoryDescriptionLabel); }
public void OnDepleted() { GenericWorldItem swap = null; WICategory category = null; if (WorldItems.Get.Category(State.CategoryName, out category) && category.GetItem(worlditem.GetHashCode(), out swap)) { WorldItems.ReplaceWorldItem(worlditem, swap); Finish(); } }
public void OnPlayerUseWorldItemSecondary(object secondaryResult) { WIListResult dialogResult = secondaryResult as WIListResult; switch (dialogResult.SecondaryResult) { case "Milk": LiquidContainer container = null; if (Player.Local.Tool.worlditem.Is <LiquidContainer>(out container)) { if (container.State.IsEmpty) { WICategory category = null; System.Random random = new System.Random(Profile.Get.CurrentGame.Seed); if (WorldItems.Get.Category(MilkCategory, out category)) { GenericWorldItem milkItem = null; if (category.GenericWorldItems.Count > 0) { milkItem = category.GenericWorldItems[random.Next(0, category.GenericWorldItems.Count)]; } else { milkItem = category.GenericWorldItems[0]; } container.State.Contents.CopyFrom(milkItem); container.State.Contents.InstanceWeight = container.State.Capacity; //make the cow make a noise worlditem.Get <Creature>().OnTakeDamage(); } } } break; case "Tip": worlditem.Get <Creature>().OnTakeDamage(); //make a noise and flip out worlditem.Get <Creature>().TryToStun(10f); break; default: break; } }
protected IEnumerator FillWearablesOverTime(string categoryName) { //wait a frame yield return(null); //Debug.Log("Filling wearables from category " + categoryName); WICategory category = null; STransform tr = new STransform(); if (WorldItems.Get.Category(categoryName, out category)) { //Debug.Log("Got category, filling now"); for (int i = 0; i < category.GenericWorldItems.Count; i++) { //get an instance of the item and try to wear it //Debug.Log("Adding wearable " + category.GenericWorldItems[i].DisplayName); for (int j = 0; j < category.GenericWorldItems[i].InstanceWeight; j++) { WorldItem newWorldItem = null; if (WorldItems.CloneWorldItem(category.GenericWorldItems[i], tr, false, WIGroups.Get.Player, out newWorldItem)) { newWorldItem.Initialize(); Wearable wearable = newWorldItem.Get <Wearable>(); if (!Wear(wearable)) { //if we can't wear it for some reason, drop it in front of the player player.ItemPlacement.ItemDropAtFeet(newWorldItem); } else { //Debug.Log("Player has been equipped with " + newWorldItem.DisplayName); } } } } } else { //Debug.Log("Couldn't find category " + categoryName); } yield break; }
public void RefreshCategory(WICategory category, UILabel nameLabel, UILabel descriptionLabel) { if (category != null) { nameLabel.text = Data.GameData.AddSpacesToSentence(category.Name); List <string> items = new List <string>(); for (int i = 0; i < category.GenericWorldItems.Count; i++) { string item = System.Text.RegularExpressions.Regex.Replace(category.GenericWorldItems[i].PrefabName, @" \d", ""); if (category.GenericWorldItems[i].InstanceWeight > 1) { item = category.GenericWorldItems[i].InstanceWeight.ToString() + " " + item; } items.Add(item); } descriptionLabel.text = Data.GameData.CommaJoinWithLast(items, "and"); } else { nameLabel.text = "(None)"; descriptionLabel.text = "(No items)"; } }
public void RefreshStartupPosition() { StartupPositionLabel.text = Data.GameData.AddSpacesToSentence(CurrentStartupPosition.Name); if (CurrentStartupPosition.Name == ParentDialog.CurrentWorld.FirstStartupPosition) { StartupPositionDescriptionLabel.text = "This is the default startup position for this world. Choose this if you want to experience the story from the beginning, complete with prologue."; Profile.Get.CurrentGame.CustomStartupPosition = string.Empty; } else { StartupPositionDescriptionLabel.text = CurrentStartupPosition.Description; Profile.Get.CurrentGame.CustomStartupPosition = CurrentStartupPosition.Name; } CurrentItemCategory = null; for (int i = 0; i < AvailableCategories.Count; i++) { if (AvailableCategories[i].Name == CurrentStartupPosition.InventoryFillCategory) { CurrentItemCategory = AvailableCategories[i]; break; } } CurrentClothingCategory = null; for (int i = 0; i < AvailableClothingCategories.Count; i++) { if (AvailableClothingCategories[i].Name == CurrentStartupPosition.WearableFillCategory) { CurrentClothingCategory = AvailableClothingCategories[i]; break; } } RefreshCategory(CurrentItemCategory, CategoryLabel, CategoryDescriptionLabel); RefreshCategory(CurrentClothingCategory, ClothingLabel, ClothingDescriptionLabel); }
public void OnDie() { Debug.Log("OnDie called in drop items on die"); if (gSpawnPointTransform == null) { gSpawnPointTransform = new STransform(); } string categoryName = WICategoryName; if (!string.IsNullOrEmpty(WICategoryNameBurned)) { if (worlditem.Get <Damageable> ().State.LastDamageSource == "Fire") { categoryName = WICategoryNameBurned; } } if (DropEveryItemInCategory) { WICategory category = null; if (WorldItems.Get.Category(categoryName, out category)) { for (int i = 0; i < category.GenericWorldItems.Count; i++) { //create one for each instance for (int j = 0; j < category.GenericWorldItems [i].InstanceWeight; j++) { gSpawnPointTransform.Position = worlditem.tr.TransformPoint(SpawnPoints [i % SpawnPoints.Count]); gSpawnPointTransform.Rotation.x = Random.Range(0f, 360f); gSpawnPointTransform.Rotation.y = Random.Range(0f, 360f); gSpawnPointTransform.Rotation.z = Random.Range(0f, 360f); if (WorldItems.CloneWorldItem(category.GenericWorldItems [i], gSpawnPointTransform, false, WIGroups.Get.World, out gDropItem)) { gDropItem.Props.Local.Mode = WIMode.World; gDropItem.Initialize(); gDropItem.SetMode(WIMode.World); if (!string.IsNullOrEmpty(DropEffect)) { FXManager.Get.SpawnFX(gDropItem, DropEffect); } } } } } } else { //we prefer spawn points first if (SpawnPoints.Count > 0) { for (int i = 0; i < SpawnPoints.Count; i++) { mSpawnPoint = SpawnPoints [i]; if (Random.value > RandomDropout) { if (WorldItems.CloneRandomFromCategory(categoryName, WIGroups.Get.World, out gDropItem)) ////Debug.Log ("Cloning item!"); { gDropItem.Props.Local.Transform.Position = worlditem.tr.TransformPoint(mSpawnPoint); //Debug.Log ("Worlditem at position " + worlditem.tr.position + " dropping item " + gDropItem.Props.Local.Transform.Position.ToString () + " from spawn point " + mSpawnPoint.ToString()); gDropItem.Props.Local.Transform.Rotation.x = Random.Range(0f, 360f); gDropItem.Props.Local.Transform.Rotation.y = Random.Range(0f, 360f); gDropItem.Props.Local.Transform.Rotation.z = Random.Range(0f, 360f); gDropItem.Props.Local.FreezeOnStartup = false; gDropItem.Props.Local.Mode = WIMode.World; gDropItem.Initialize(); gDropItem.SetMode(WIMode.World); if (!string.IsNullOrEmpty(DropEffect)) { FXManager.Get.SpawnFX(gDropItem, DropEffect); } } } } } else { //if no spawn points exist, spawn stuff using mesh vertices //System.Random random = new System.Random (Profile.Get.CurrentGame.Seed); int numToSpawn = UnityEngine.Random.Range(MinRandomItems, MaxRandomItems); //random.Next (MinRandomItems, MaxRandomItems); Renderer r = null; if (worlditem.HasStates) { r = worlditem.States.CurrentState.StateRenderer; } else { //just get the first renderer r = worlditem.Renderers [0]; } //TODO make this more safe? Mesh sharedMesh = r.GetComponent <MeshFilter> ().sharedMesh; Vector3[] vertices = sharedMesh.vertices; //Debug.Log ("Spawning from " + vertices.Length.ToString () + " vertices"); for (int i = 0; i < numToSpawn; i++) { if (WorldItems.CloneRandomFromCategory(categoryName, WIGroups.Get.World, out gDropItem)) { gDropItem.Props.Local.Transform.Position = worlditem.tr.TransformPoint(vertices [UnityEngine.Random.Range(0, vertices.Length)]); //Debug.Log ("Worlditem at position " + worlditem.tr.position + " dropping item " + gDropItem.Props.Local.Transform.Position.ToString () + " from mesh spawn point " + mSpawnPoint.ToString ()); gDropItem.Props.Local.Transform.Rotation.x = Random.Range(0f, 360f); gDropItem.Props.Local.Transform.Rotation.y = Random.Range(0f, 360f); gDropItem.Props.Local.Transform.Rotation.z = Random.Range(0f, 360f); gDropItem.Props.Local.FreezeOnStartup = false; gDropItem.Props.Local.Mode = WIMode.World; gDropItem.Initialize(); gDropItem.SetMode(WIMode.World); if (!string.IsNullOrEmpty(DropEffect)) { FXManager.Get.SpawnFX(gDropItem, DropEffect); } } else { Debug.Log("Couldn't clone item from category " + categoryName); } } } } Finish(); }
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 static IEnumerator Spawn(SpawnPoint spawnPoint, SpawnerStateSetting setting, Location location, WIGroup spawnGroup, System.Random random) { switch (setting.Type) { case SpawnerType.WorldItems: default: WorldItem newSpawnedItem = null; WICategory cat = null; if (WorldItems.Get.Category(setting.CategoryName, out cat)) { spawnPoint.Transform.Position.y += setting.UpVectorPadding; if (WorldItems.CloneRandomFromCategory(cat, spawnGroup, spawnPoint.Transform, setting.Flags, setting.NumTimesSpawned, setting.NumAttempts, out newSpawnedItem)) { //adjust spawn point spawnPoint.Transform.Rotation = spawnPoint.Transform.Rotation + newSpawnedItem.Props.Global.BaseRotation; spawnPoint.Transform.Position.y += setting.UpVectorPadding; //apply to newly spawned item newSpawnedItem.Props.Local.Transform.CopyFrom(spawnPoint.Transform); if (setting.DropThenFreeze) { newSpawnedItem.Props.Local.FreezeOnStartup = false; newSpawnedItem.Props.Local.FreezeOnSleep = true; newSpawnedItem.gameObject.AddComponent <FreezeOnSleep> ().worlditem = newSpawnedItem; } else { yield return(null); } if (!string.IsNullOrEmpty(setting.SendMessageToSpawnedItem)) { //Debug.Log ("Sending message to item: " + setting.SendMessageToSpawnedItem); newSpawnedItem.SendMessage(setting.SendMessageToSpawnedItem, SendMessageOptions.DontRequireReceiver); } } else { //Debug.Log ("Couldn't clone from category " + setting.CategoryName); } } else { //Debug.Log ("Couldn't get category " + setting.CategoryName); } break; case SpawnerType.Characters: //TEMP just use bandit camp since that's the only thing that uses spawners for characters BanditCamp camp = null; if (location.worlditem.Is <BanditCamp> (out camp)) { Character character = null; //if we've gotten this far we must have found or created a node, so assume it's there if (Characters.SpawnRandomCharacter(spawnPoint.nodeState.actionNode, camp.State.TemplateName, setting.Flags, location.LocationGroup, out character)) { camp.AddBandit(character); } } break; case SpawnerType.Creatures: spawnPoint.Transform.Position.y += setting.UpVectorPadding; CreatureDen den = null; if (location.worlditem.Is <CreatureDen> (out den)) { Creature creature = null; Creatures.SpawnCreature(den, spawnGroup, spawnPoint.Transform.Position, out creature); } break; } yield break; }