示例#1
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);
                }
            }
        }
示例#2
0
        public WITemplate(WorldItem worlditem)
        {
            Name = worlditem.Props.Name.PrefabName;
            StackItem si = worlditem.GetTemplate();

            Props.CopyLocalNames(si.Props);
            Props.CopyGlobalNames(si.Props);
            Props.CopyLocal(si.Props);
            Props.Global             = worlditem.Props.Global;
            SaveState                = si.SaveState;
            Props.Local.Mode         = WIMode.Unloaded;
            Props.Local.PreviousMode = WIMode.Unloaded;
            WIStates states = null;

            if (worlditem.gameObject.HasComponent <WIStates>(out states))
            {
                ObjectStates.AddRange(states.States);
            }
        }
示例#3
0
        //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();
        }