public void OnLocationGroupLoaded() { Structures.AddMinorToload(State.GraveyardStructure, 0, worlditem); if (!State.CreatedHeadstones) { //create headstones the first time we load the location group //after that they'll just load and unload normally WorldItem headstoneWorldItem = null; State.CreatedHeadstones = true; for (int i = 0; i < State.HeadstoneSpawnPoints.Count; i++) { if (WorldItems.CloneRandomFromCategory(State.HeadstoneCategory, location.LocationGroup, State.HeadstoneSpawnPoints[i], out headstoneWorldItem)) { headstoneWorldItem.Initialize(); HeadstoneAvatar hsa = headstoneWorldItem.Get <HeadstoneAvatar>(); if (i < State.Headstones.Count) { hsa.State.HeadstoneName = State.Headstones[i]; } hsa.RefreshProps(); } } } }
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; }
public void OnPowerSourceRemoved() { if (mSpawnedDeactivatedOrb) { return; } //this will swap it out for an item that can be carried mSpawnedDeactivatedOrb = true; WorldItem deactivatedOrb = null; STransform orbSpawnPoint = new STransform(LuminiteGemPivot.position, LuminiteGemPivot.rotation.eulerAngles, Vector3.zero); if (WorldItems.CloneWorldItem(DeactivatedOrbGenericWorldItem, orbSpawnPoint, false, WIGroups.Get.World, out deactivatedOrb)) { deactivatedOrb.Props.Local.Mode = WIMode.World; deactivatedOrb.Initialize(); deactivatedOrb.SetMode(WIMode.World); worlditem.RemoveFromGame(); } }
public void OnDie() { PowerSource.HasPower = false; if (PowerSource.HasPowerSource) { //drop the crystal into the world WorldItem droppedGem = null; STransform gemSpawnPoint = new STransform(LuminiteGemPivot.position, LuminiteGemPivot.rotation.eulerAngles, Vector3.zero); if (WorldItems.CloneWorldItem(PowerSource.PowerSourceDopplegangerProps, gemSpawnPoint, false, WIGroups.Get.World, out droppedGem)) { droppedGem.Props.Local.Mode = WIMode.World; droppedGem.Initialize(); droppedGem.SetMode(WIMode.World); FXManager.Get.SpawnFX(droppedGem.tr, "DrawAttentionToItem"); } FXManager.Get.SpawnExplosion(ExplosionType.Simple, worlditem.Position, 1f, 1f, 0.1f, 0.5f, OrbExplosionDamage); } OrbSpeak(OrbSpeakUnit.UnitExpiring, worlditem.tr); }
public void OnPlayerUseWorldItemSecondary(object secondaryResult) { WIListResult dialogResult = secondaryResult as WIListResult; switch (dialogResult.SecondaryResult) { case "Shear": State.LastTimeSheared = WorldClock.AdjustedRealTime; //spawn a random number of wool items //make it pop off the chest body part, upwards WorldItem shearedWorldItem = null; BodyPart chestBodyPart = null; creature.Body.GetBodyPart(BodyPartType.Chest, out chestBodyPart); Bounds colliderBounds = chestBodyPart.PartCollider.bounds; Vector3 popPosition; Vector3 popDirection; System.Random random = new System.Random(Profile.Get.CurrentGame.Seed); int numShearedItems = random.Next(MinShearedItems, MaxShearedItems); Debug.Log("Shearing " + numShearedItems.ToString() + " Items in " + name); for (int i = 0; i < numShearedItems; i++) { popPosition = (UnityEngine.Random.onUnitSphere * 5f) + chestBodyPart.tr.position; popPosition = chestBodyPart.PartCollider.ClosestPointOnBounds(popPosition); //give it a push in a direction away from the body popDirection = Vector3.Normalize(chestBodyPart.tr.position - popPosition); if (WorldItems.CloneWorldItem(ShearedItem, STransform.zero, false, WIGroups.GetCurrent(), out shearedWorldItem)) { shearedWorldItem.Initialize(); shearedWorldItem.SetMode(WIMode.World); shearedWorldItem.tr.position = popPosition; shearedWorldItem.ApplyForce(popDirection, popPosition); } //let them all fall away } //the creature freaks out but doesn't actually take damage creature.OnTakeDamage(); break; default: break; } }
public void OnDie() { switch (worlditem.State) { case "Mined": Debug.Log("DIED in luminite node with state mined"); worlditem.Get <Damageable> ().ResetDamage(); State.TimeMined = WorldClock.AdjustedRealTime; break; default: Debug.Log("DIED in luminite node with state " + worlditem.State); worlditem.Get <Damageable> ().ResetDamage(); //set luminite type to mined raw, then get a stack item for the player //add that to player inventory WorldItem rawLuminite = null; GenericWorldItem rawLuminiteItem = RawLuminiteLight; if (worlditem.State == "Dark") { rawLuminiteItem = RawLuminiteDark; } if (WorldItems.CloneWorldItem( rawLuminiteItem, new STransform(worlditem.tr), false, worlditem.Group, out rawLuminite)) { //this will drop to the players' feet rawLuminite.Props.Local.FreezeOnStartup = false; rawLuminite.Initialize(); rawLuminite.SetMode(WIMode.World); rawLuminite.GetComponent <Rigidbody>().AddForce(worlditem.tr.up * 0.25f); } State.TimeMined = WorldClock.AdjustedRealTime; State.AbsorbedDarkRot = 0f; worlditem.State = "Mined"; break; } Debug.Log("State is now " + worlditem.State); }
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 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 static Signboard GetOrCreateSignboard(Signboard sign, WorldItem owner, WIGroup locationGroup, STransform offset, string textureName, string type) { if (sign == null) { WorldItem newSignWorldItem = null; WorldItems.CloneWorldItem("Decorations", "Signboard", offset, false, locationGroup, out newSignWorldItem); newSignWorldItem.Initialize(); //offset.ApplyTo (newSignWorldItem.transform, false); sign = newSignWorldItem.GetOrAdd <Signboard>(); sign.Owner = owner; sign.TextureName = textureName; sign.Style = SignboardStyle.A; if (!string.IsNullOrEmpty(textureName)) { if (textureName.StartsWith("B_")) { sign.Style = SignboardStyle.B; } //Debug.Log ("Setting signoboard state to " + type + sign.Style.ToString ()); newSignWorldItem.State = type + sign.Style.ToString(); } } return(sign); }
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(); }
protected void StartupStructureLoaded(WorldItem mStartupStructureWorldItem) { mStartupStructureWorldItem.Initialize(); mStartupStructure = mStartupStructureWorldItem.Get <Structure> (); }
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(); }
public void Update() { if (!SpawnMeteors) { return; } RecentMeteorMaterial.color = Color.Lerp(GlowMaterialColorDark, GlowMaterialColor, Mathf.Abs(Mathf.Sin(Time.time))); #if UNITY_EDITOR if (Input.GetKeyDown(KeyCode.O)) { if (InactiveMeteors.Count > 0) { //yay spawn a new one FallingMeteor f = InactiveMeteors [0]; InactiveMeteors.RemoveAt(0); ActiveMeteors.Add(f); f.Activate(); } } #endif if (Player.Local == null || !Player.Local.HasSpawned || !GameManager.Is(FGameState.InGame)) { return; } if (GameWorld.Get.CurrentBiome.OuterSpace) { return; } if (WorldClock.IsDay) { mMeteorsFallenTonight = 0; mCheckedTonight = false; mCheckMeteors++; if (mCheckMeteors > 30) { mCheckMeteors = 0; if (mMeteorsFallenToday < Globals.MaxMeteorsPerDay) { if (InactiveMeteors.Count > 0 && UnityEngine.Random.value < Globals.MeteorSpawnProbabilityDaytime && WorldClock.AdjustedRealTime > mLastMeteorSpawnTime + Globals.MeteorMinimumSpawnTime) { //yay spawn a new one FallingMeteor f = InactiveMeteors [0]; InactiveMeteors.RemoveAt(0); ActiveMeteors.Add(f); f.Activate(); mMeteorsFallenToday++; mLastMeteorSpawnTime = WorldClock.AdjustedRealTime; } } if (ActiveMeteors.Count > 0) { for (int i = ActiveMeteors.LastIndex(); i >= 0; i--) { //remove any that have been killed FallingMeteor f = ActiveMeteors [i]; if (f.IsDepleted) { InactiveMeteors.Add(f); ActiveMeteors.RemoveAt(i); } } } } return; } else { mMeteorsFallenToday = 0; if (!mCheckedTonight) { mCheckedTonight = true; if (Globals.OscillateMeteorSpawnAmount) { float period = (float)((WorldClock.AdjustedRealTime % Globals.MeteorSpawnOscillateDuration) / Globals.MeteorSpawnOscillateDuration); AdjustedMaxMeteorsPerNight = Mathf.Clamp(Mathf.CeilToInt(Mathf.Sin(period) * Globals.MaxMeteorsPerNight), Globals.MinMeteorsPerNight, Globals.MaxMeteorsPerNight); } else { AdjustedMaxMeteorsPerNight = Globals.MaxMeteorsPerNight; } } mCheckMeteors++; if (mCheckMeteors > 30) { mCheckMeteors = 0; if (mMeteorsFallenTonight < Globals.MaxMeteorsPerNight) { if (InactiveMeteors.Count > 0 && UnityEngine.Random.value < Globals.MeteorSpawnProbability && WorldClock.AdjustedRealTime > mLastMeteorSpawnTime + Globals.MeteorMinimumSpawnTime) { //yay spawn a new one FallingMeteor f = InactiveMeteors [0]; InactiveMeteors.RemoveAt(0); ActiveMeteors.Add(f); f.Activate(); mMeteorsFallenTonight++; mLastMeteorSpawnTime = WorldClock.AdjustedRealTime; OnMeteorSpawned.SafeInvoke(); } } for (int i = ActiveMeteors.LastIndex(); i >= 0; i--) { //remove any that have been killed FallingMeteor f = ActiveMeteors [i]; if (f.IsDepleted) { InactiveMeteors.Add(f); ActiveMeteors.RemoveAt(i); if (f.SpawnMeteor) { WorldChunk p = GameWorld.Get.PrimaryChunk; f.transform.parent = p.AboveGroundGroup.tr; mActiveMeteorPosition.Position = f.transform.localPosition; WorldItem newMeteorWorldItem = null; WorldItems.CloneWorldItem("Crystals", "Falling Meteor", mActiveMeteorPosition, false, p.AboveGroundGroup, out newMeteorWorldItem); newMeteorWorldItem.Initialize(); newMeteorWorldItem.ActiveState = WIActiveState.Active; newMeteorWorldItem.ActiveStateLocked = true; MeteorsSpawned.Add(newMeteorWorldItem.Get <Meteor> ()); //get rid of dead meteors to make it easier on orbs for (int j = MeteorsSpawned.LastIndex(); j >= 0; j--) { if (MeteorsSpawned [j] == null || MeteorsSpawned [j].IsDestroyed) { MeteorsSpawned.RemoveAt(j); } } OnMeteorSpawned.SafeInvoke(); } } } } } }