public void RefreshFoodStuffProps() { //some food stuff has states if (worlditem.HasStates) { string newStateName = worlditem.State; bool foundState = false; for (int i = 0; i < State.PotentialProps.Count; i++) { FoodStuffProps potentialProps = State.PotentialProps[i]; if (potentialProps.Name == newStateName) { mCurrentProps = potentialProps; foundState = true; } } if (!foundState) { ////Debug.Log ("Didn't find state " + worlditem.State + " in foodstuff " + name); } } else { //others are just standalone //the first state is the default in this case mCurrentProps = State.PotentialProps[0]; } }
//editor function to quickly set up a new foodstuff object public void EditorCreateProps() { if (State.PotentialProps.Count == 0) { WIStates states = gameObject.GetComponent <WIStates>(); if (states != null) { foreach (WIState state in states.States) { FoodStuffProps props = new FoodStuffProps(); props.Name = state.Name; switch (props.Name) { case "Raw": props.HungerRestore = PlayerStatusRestore.D_ThreeFifths; props.Type = FoodStuffEdibleType.Edible; break; case "Rotten": props.ConditionName = "FoodPoisoning"; props.HungerRestore = PlayerStatusRestore.C_TwoFifths; props.ConditionChance = 0.75f; props.Type = FoodStuffEdibleType.Edible; break; case "Cooked": props.HealthRestore = PlayerStatusRestore.F_Full; props.Type = FoodStuffEdibleType.Edible; break; case "Preserved": props.HungerRestore = PlayerStatusRestore.F_Full; props.Type = FoodStuffEdibleType.Edible; break; case "Burned": props.HungerRestore = PlayerStatusRestore.D_ThreeFifths; props.Type = FoodStuffEdibleType.Edible; break; } State.PotentialProps.Add(props); } } else { FoodStuffProps props = new FoodStuffProps(); props.HungerRestore = PlayerStatusRestore.C_TwoFifths; props.Type = FoodStuffEdibleType.Edible; State.PotentialProps.Add(props); } } }
public void SetProps(FoodStuffProps props) { State.PotentialProps.Clear(); State.PotentialProps.Add(props); mCurrentProps = props; }
//this editor function does a bunch of sanity-check stuff //to make sure that the foodstuff is set up properly public override void InitializeTemplate() { 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.StackName = props.Name + " " + worlditem.Props.Name.StackName; 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.collider != null) { GameObject.DestroyImmediate(worlditem.collider); } } foreach (FoodStuffProps props in State.PotentialProps) { if (props.IsLiquid) { props.EatFoodSound = "DrinkLiquidGeneric"; } else { props.EatFoodSound = "EatFoodGeneric"; } } mCurrentProps = null; base.InitializeTemplate(); }
public static string DescribeProperties(FoodStuffProps props, string stateName) { //TODO use a f'ing string builder string description = "When " + stateName + ", it's"; if (Flags.Check((uint)props.Type, (uint)FoodStuffEdibleType.Edible, Flags.CheckType.MatchAny)) { description += " edible,"; if (Flags.Check((uint)props.Type, (uint)FoodStuffEdibleType.Poisonous, Flags.CheckType.MatchAny)) { description += " and can make for a"; switch (props.HungerRestore) { case PlayerStatusRestore.F_Full: case PlayerStatusRestore.E_FourFifths: description += " full meal,"; break; case PlayerStatusRestore.D_ThreeFifths: case PlayerStatusRestore.C_TwoFifths: description += " large snack,"; break; default: description += " small snack,"; break; } description += " but it's also"; switch (props.HealthReduce) { case PlayerStatusRestore.F_Full: case PlayerStatusRestore.E_FourFifths: description += " seriously"; break; case PlayerStatusRestore.D_ThreeFifths: case PlayerStatusRestore.C_TwoFifths: description += " moderately"; break; default: description += " mildly"; break; } description += " poisonous"; } else { description += " and it's good for a"; switch (props.HungerRestore) { case PlayerStatusRestore.F_Full: case PlayerStatusRestore.E_FourFifths: description += " full meal"; break; case PlayerStatusRestore.D_ThreeFifths: case PlayerStatusRestore.C_TwoFifths: description += " large snack"; break; default: description += " small snack"; break; } } if (Flags.Check((uint)props.Type, (uint)FoodStuffEdibleType.Medicinal, Flags.CheckType.MatchAny)) { description += " It also has"; switch (props.HealthRestore) { case PlayerStatusRestore.F_Full: case PlayerStatusRestore.E_FourFifths: description += " powerful."; break; case PlayerStatusRestore.D_ThreeFifths: case PlayerStatusRestore.C_TwoFifths: description += " moderate."; break; default: description += " mild."; break; } description += " medicinal properties"; } if (Flags.Check((uint)props.Type, (uint)FoodStuffEdibleType.Hallucinogen, Flags.CheckType.MatchAny)) { description += ", but it's a "; switch (props.Hallucinogen) { case HallucinogenicStrength.Strong: description += " string"; break; case HallucinogenicStrength.Moderate: description += " moderate"; break; default: description += " mild"; break; } description += " hallucinogen so I'd better be careful."; } else { description += "."; } } else { description += " inedible."; } return(description); }
public static void Eat(FoodStuff foodstuff) { if (foodstuff == null) { return; } FoodStuffProps Props = foodstuff.Props; if (!string.IsNullOrEmpty(Props.ConditionName)) { if (UnityEngine.Random.value <= Props.ConditionChance) { Player.Local.Status.AddCondition(Props.ConditionName); } } PlayerStatusRestore hungerRestore = PlayerStatusRestore.A_None; PlayerStatusRestore healthRestore = PlayerStatusRestore.A_None; PlayerStatusRestore healthReduce = PlayerStatusRestore.A_None; HallucinogenicStrength hallucinogen = HallucinogenicStrength.None; bool wellFed = false; if (Flags.Check((uint)Props.Type, (uint)FoodStuffEdibleType.Edible, Flags.CheckType.MatchAny)) { hungerRestore = Props.HungerRestore; } if (Flags.Check((uint)Props.Type, (uint)FoodStuffEdibleType.Hallucinogen, Flags.CheckType.MatchAny)) { hallucinogen = Props.Hallucinogen; } if (Flags.Check((uint)Props.Type, (uint)FoodStuffEdibleType.Medicinal, Flags.CheckType.MatchAny)) { healthRestore = Props.HealthRestore; } if (Flags.Check((uint)Props.Type, (uint)FoodStuffEdibleType.Poisonous, Flags.CheckType.MatchAny)) { healthReduce = Props.HealthReduce; } if (Flags.Check((uint)Props.Type, (uint)FoodStuffEdibleType.WellFed, Flags.CheckType.MatchAny)) { hungerRestore = PlayerStatusRestore.F_Full; wellFed = true; } Player.Local.Status.ReduceStatus(healthReduce, "Health"); if (foodstuff.Props.IsLiquid) { Player.Local.Status.RestoreStatus(hungerRestore, "Thirst"); } else { Player.Local.Status.RestoreStatus(hungerRestore, "Hunger"); } Player.Local.Status.RestoreStatus(healthRestore, "Health"); if (wellFed) { Player.Local.Status.AddCondition("WellFed"); } MasterAudio.PlaySound(MasterAudio.SoundType.PlayerVoice, Props.EatFoodSound); if (!string.IsNullOrEmpty(Props.CustomStatusKeeperRestore)) { Player.Local.Status.RestoreStatus(Props.CustomRestore, Props.CustomStatusKeeperRestore); } if (!string.IsNullOrEmpty(Props.CustomStatusKeeperReduce)) { Player.Local.Status.RestoreStatus(Props.CustomRestore, Props.CustomStatusKeeperReduce); } if (foodstuff.worlditem != null && !foodstuff.worlditem.IsTemplate) { foodstuff.OnEat.SafeInvoke(); if (foodstuff.State.ConsumeOnEat) { //Debug.Log ("FOODSTUFF: Setting mode to RemovedFromGame"); foodstuff.worlditem.SetMode(WIMode.RemovedFromGame); } } }