public void ChooseRandomShardState() { WIState state = worlditem.States.States[UnityEngine.Random.Range(0, worlditem.States.States.Count)]; worlditem.State = state.Name; State.HasChosenFragment = true; }
public void StartDimming( ) { Debug.Log("Dimming..."); State.Dimmed = true; FXManager.Get.SpawnFX(worlditem.Position, State.FXOnDimmed); if (worlditem.Light != null) { worlditem.Light.gameObject.SetActive(false); } WIState state = worlditem.States.GetState("Light"); DimmedRenderer = state.StateRenderer; Material[] sharedMaterials = DimmedRenderer.sharedMaterials; for (int i = 0; i < sharedMaterials.Length; i++) { if (sharedMaterials [i].name.Equals(State.LitMaterialName)) { LitMaterial = sharedMaterials [i]; DimmedMaterial = new Material(sharedMaterials [i]); DimmedMaterial.name = DimmedMaterial.name + " (Dimmed)"; sharedMaterials [i] = DimmedMaterial; break; } } DimmedMaterial.SetColor("_EmiTint", Colors.Alpha(DimmedMaterial.GetColor("_EmiTint"), 0f)); DimmedMaterial.SetFloat("_RefIntensity", 0.1f); DimmedRenderer.sharedMaterials = sharedMaterials; MasterAudio.PlaySound(State.DimmingSoundType, worlditem.tr, State.DimmingSound); }
public static void InitializeAvatar(PreparedFoodAvatar preparedFoodAvatar) { if (string.IsNullOrEmpty(preparedFoodAvatar.worlditem.Subcategory)) { //get a random category preparedFoodAvatar.worlditem.Props.Local.Subcategory = Get.PreparedFoodList[UnityEngine.Random.Range(0, Get.PreparedFoodList.LastIndex())].Name; } PreparedFood preparedFood = null; if (!mPreparedFoodLookup.TryGetValue(preparedFoodAvatar.worlditem.Subcategory, out preparedFood)) { Debug.Log("Couldn't initialize prepared food avatar " + preparedFoodAvatar.name); return; } preparedFoodAvatar.Props = preparedFood; //set up the prepared food states WIState rawState = preparedFoodAvatar.worlditem.States.GetState("Raw"); WIState cookedState = preparedFoodAvatar.worlditem.States.GetState("Cooked"); cookedState.Enabled = true; if (preparedFood.CanBeRaw) { //if it can be raw / cooked //indicate this with a suffix cookedState.Suffix = "Cooked"; rawState.Suffix = "Raw"; rawState.Enabled = true; preparedFoodAvatar.worlditem.States.DefaultState = "Raw"; } else { //otherwise just show up as the normal name cookedState.Suffix = string.Empty; rawState.Enabled = false; preparedFoodAvatar.worlditem.States.DefaultState = "Cooked"; } //set up the edible properties FoodStuff foodStuff = preparedFoodAvatar.worlditem.Get <FoodStuff>(); foodStuff.State.ConsumeOnEat = true; /*foodStuff.State.PotentialProps.Clear(); * if (preparedFood.CanBeRaw) { * foodStuff.State.PotentialProps.Add(preparedFood.RawProps); * } * //set the cook time regardless since food can still be burned */ foodStuff.CookTimeRTSeconds = preparedFood.RTCookDuration; //foodStuff.State.PotentialProps.Add(preparedFood.CookedProps); foodStuff.RefreshFoodStuffProps(); //the foodstuff will update itself based on whether the state is raw / cooked }
//this editor function does a bunch of sanity-check stuff //to make sure that the foodstuff is set up properly public override void InitializeTemplate() { base.InitializeTemplate(); if (NonStandardProps) { return; } mCurrentProps = null; if (State.PotentialProps.Count > 0) { WIStates states = null; if (gameObject.HasComponent <WIStates>(out states)) { for (int i = 0; i < State.PotentialProps.Count; i++) { if (State.PotentialProps[i].Name == states.DefaultState) { mCurrentProps = State.PotentialProps[i]; break; } } } if (mCurrentProps == null) { for (int i = 0; i < State.PotentialProps.Count; i++) { if (State.PotentialProps[i].Name == "Raw") { mCurrentProps = State.PotentialProps[i]; break; } } } if (mCurrentProps == null) { //f**k it mCurrentProps = State.PotentialProps[0]; } } return; if (Application.isPlaying) { return; } if (worlditem.Props.Global.MaterialType != WIMaterialType.Plant && worlditem.Props.Global.MaterialType != WIMaterialType.Flesh) { worlditem.Props.Global.MaterialType = WIMaterialType.Food; } if (State.PotentialProps.Count == 0) { Debug.Log("Didn't find any potential food props, creating 'Raw' now"); FoodStuffProps props = new FoodStuffProps(); props.Name = "Raw"; props.Type = FoodStuffEdibleType.Edible; props.HungerRestore = PlayerStatusRestore.B_OneFifth; props.Perishable = false; State.PotentialProps.Add(props); } else { Debug.Log("Found " + State.PotentialProps.Count.ToString() + " props"); } if (worlditem.States != null) { Debug.Log("worlditem has states"); foreach (WIState state in worlditem.States.States) { bool foundAccompanyingFoodState = false; foreach (FoodStuffProps props in this.State.PotentialProps) { if (props.Name == state.Name) { foundAccompanyingFoodState = true; } } if (!foundAccompanyingFoodState) { Debug.Log("Didn't find accompanying food state in " + worlditem.name + " for worlditem state: " + state.Name + ", adding now"); FoodStuffProps newProps = new FoodStuffProps(); newProps.Name = state.Name; //there are some common states that we can make guesses for switch (state.Name) { case "Rotten": newProps.Type = FoodStuffEdibleType.Edible; newProps.HungerRestore = PlayerStatusRestore.B_OneFifth; newProps.ConditionChance = 0.95f; newProps.ConditionName = "FoodPoisoning"; newProps.Perishable = false; break; case "Raw": newProps.Type = FoodStuffEdibleType.Edible; newProps.HungerRestore = PlayerStatusRestore.C_TwoFifths; newProps.Perishable = true; break; case "Cooked": newProps.Type = FoodStuffEdibleType.Edible; newProps.HungerRestore = PlayerStatusRestore.F_Full; newProps.Perishable = true; break; case "Burned": newProps.Type = FoodStuffEdibleType.Edible; newProps.HungerRestore = PlayerStatusRestore.B_OneFifth; newProps.Perishable = false; break; case "Preserved": case "Dried": newProps.Type = FoodStuffEdibleType.Edible; newProps.HungerRestore = PlayerStatusRestore.D_ThreeFifths; newProps.Perishable = false; break; default: newProps.Type = FoodStuffEdibleType.None; //make it inedible break; } State.PotentialProps.Add(newProps); } } } bool requiresRottenState = false; foreach (FoodStuffProps props in State.PotentialProps) { if (props.Name == "Raw") { bool foundCooked = false; foreach (FoodStuffProps cookedProps in State.PotentialProps) { if (cookedProps.Name == "Cooked") { foundCooked = true; props.ConditionName = "FoodPoisoning"; props.ConditionChance = 0.25f; break; } } if (!foundCooked) { props.ConditionName = string.Empty; props.ConditionChance = 0f; } else { gameObject.GetOrAdd <Photosensitive>(); } } requiresRottenState |= props.Perishable; if (props.Name == "Rotten") { requiresRottenState |= true; } } //check our states against our props and make sure there's parity if (State.PotentialProps.Count > 1) { if (worlditem.States == null) { worlditem.States = worlditem.gameObject.AddComponent <WIStates>(); worlditem.InitializeTemplate(); return; } //now attempt to match our props up against our states and make sure there's parity foreach (FoodStuffProps props in State.PotentialProps) { WIState existingState = null; bool foundAccompanyingState = false; foreach (WIState state in worlditem.States.States) { if (state.Name == props.Name) { if (!foundAccompanyingState) { existingState = state; foundAccompanyingState = true; } if (state.Name == "Rotten") { requiresRottenState = true; } } } if (!foundAccompanyingState) { WIState newState = null; Debug.Log("Didn't find accompanying worlditem state in " + worlditem.name + " for food state: " + props.Name + ", adding now"); if (worlditem.States.States.Count == 0) { //create a state from the base object - this will also strip the base object of renderers etc. newState = WorldItems.CreateTemplateState(worlditem, props.Name, worlditem.gameObject); } else { //otherwise just make a copy from the first existing state, we'll clean it up later newState = WorldItems.CreateTemplateState(worlditem, props.Name, worlditem.States.States[0].StateObject); } existingState = newState; } if (existingState != null) { existingState.IsInteractive = true; existingState.Suffix = props.Name; existingState.UnloadWhenStacked = true; existingState.CanEnterInventory = true; existingState.CanBePlaced = true; existingState.CanBeDropped = true; existingState.CanBeCarried = true; switch (existingState.Name) { case "Raw": existingState.IsPermanent = false; break; case "Cooked": existingState.IsPermanent = true; existingState.FXOnChange = "FoodstuffCookedSmoke"; break; case "Rotten": existingState.IsPermanent = true; break; case "Burned": existingState.IsPermanent = true; existingState.FXOnChange = "FoodstuffBurnedSmoke"; break; case "Preserved": case "Dried": existingState.IsPermanent = true; break; default: break; } } } } else { Debug.Log("Only 1 foodstuff props so no need for states"); if (worlditem.States != null && worlditem.States.States.Count == 0) { GameObject.DestroyImmediate(worlditem.States); } } if (requiresRottenState) { Debug.Log("Requires perishable, checking now"); bool hasRottenState = false; bool hasRawState = false; foreach (FoodStuffProps props in State.PotentialProps) { if (props.Name == "Raw") { props.Perishable = true; hasRawState = true; } else if (props.Name == "Rotten") { hasRottenState = true; } } if (!hasRawState) { FoodStuffProps newProps = new FoodStuffProps(); newProps.Name = "Raw"; newProps.Perishable = true; newProps.Type = FoodStuffEdibleType.Edible; newProps.HungerRestore = PlayerStatusRestore.C_TwoFifths; newProps.Perishable = true; State.PotentialProps.Add(newProps); } if (!hasRottenState) { FoodStuffProps newProps = new FoodStuffProps(); newProps.Name = "Rotten"; newProps.Type = FoodStuffEdibleType.Edible; newProps.HungerRestore = PlayerStatusRestore.C_TwoFifths; newProps.ConditionChance = 0.5f; newProps.ConditionName = "FoodPoisoning"; State.PotentialProps.Add(newProps); } } else { Debug.Log("Didn't require rotten state"); } if (worlditem.States != null) { bool foundDefaultState = false; foreach (WIState state in worlditem.States.States) { if (worlditem.States.DefaultState == state.Name) { foundDefaultState = true; break; } } if (!foundDefaultState) { Debug.Log("Didin't find default state " + worlditem.States.DefaultState + ", setting to Raw"); worlditem.States.DefaultState = "Raw"; } } if (worlditem.HasStates) { //now that the worlditem has states it shouldn't have its own mesh stuff //destroy the me now MeshFilter worldItemMF = null; if (worlditem.gameObject.HasComponent <MeshFilter>(out worldItemMF)) { GameObject.DestroyImmediate(worldItemMF); } MeshRenderer worldItemMR = null; if (worlditem.gameObject.HasComponent <MeshRenderer>(out worldItemMR)) { GameObject.DestroyImmediate(worldItemMR); } if (worlditem.GetComponent <Collider>() != null) { GameObject.DestroyImmediate(worlditem.GetComponent <Collider>()); } } foreach (FoodStuffProps props in State.PotentialProps) { if (props.IsLiquid) { props.EatFoodSound = "DrinkLiquidGeneric"; } else { props.EatFoodSound = "EatFoodGeneric"; } } mCurrentProps = null; base.InitializeTemplate(); }