Exemple #1
0
        public void OnPlayerUseWorldItemSecondary(object secondaryResult)
        {
            OptionsListDialogResult dialogResult = secondaryResult as OptionsListDialogResult;

            if (dialogResult.SecondaryResult.Contains("Drink"))
            {
                WorldItem worlditem = null;
                if (WorldItems.Get.PackPrefab(mGenericLiquid.PackName, mGenericLiquid.PrefabName, out worlditem))
                {
                    FoodStuff foodStuff = null;
                    if (worlditem.gameObject.HasComponent <FoodStuff>(out foodStuff))
                    {
                        FoodStuff.Drink(foodStuff);
                    }
                }
            }
            else
            {
                LiquidContainer liquidContainer = null;
                if (Player.Local.Tool.IsEquipped && Player.Local.Tool.worlditem.Is <LiquidContainer>(out liquidContainer))
                {
                    LiquidContainerState liquidContainerState = liquidContainer.State;
                    int    numFilled    = 0;
                    string errorMessage = string.Empty;
                    if (liquidContainerState.TryToFillWith(mGenericLiquid, Int32.MaxValue, out numFilled, out errorMessage))
                    {
                        GUIManager.PostInfo("Filled " + liquidContainer.worlditem.DisplayName + " with " + numFilled.ToString() + " " + mGenericLiquid.PrefabName + "(s)");
                        MasterAudio.PlaySound(MasterAudio.SoundType.PlayerInterface, "FillLiquidContainer");
                    }
                }
//				IWIBase qsItem = null;
//				if (mOptionsListItems.TryGetValue (dialogResult.SecondaryResult, out qsItem)) {
//					System.Object liquidContainerStateObject = null;
//					if (qsItem.GetStateOf <LiquidContainer> (out liquidContainerStateObject)) {
//						LiquidContainerState liquidContainerState = liquidContainerStateObject as LiquidContainerState;
//						if (liquidContainerState != null) {
//							int numFilled = 0;
//							string errorMessage = string.Empty;
//							if (liquidContainerState.TryToFillWith (mGenericLiquid, Int32.MaxValue, out numFilled, out errorMessage)) {
//								GUIManager.PostInfo ("Filled " + qsItem.DisplayName + " with " + numFilled.ToString () + " " + mGenericLiquid.PrefabName + "(s)");
//								MasterAudio.PlaySound (MasterAudio.SoundType.PlayerInterface, "FillLiquidContainer");
//							}
//						}
//					}
//				}
            }
            mOptionsListItems.Clear();
        }
Exemple #2
0
        public override void OnInitialized()
        {
            worlditem.ActiveStateLocked = false;
            worlditem.ActiveState       = WIActiveState.Active;
            worlditem.ActiveStateLocked = true;

            Detectable detectable = worlditem.Get <Detectable>();

            detectable.OnPlayerDetect += OnPlayerDetect;

            FoodStuff foodStuff = worlditem.Get <FoodStuff>();

            foodStuff.OnEat += OnEat;
            foodStuff.State.ConsumeOnEat = false;                                    //we'll handle consumption

            Damageable damageable = worlditem.Get <Damageable>();

            damageable.OnDie += OnDie;

            if (HasBeenPicked)
            {
                RefreshPlantProps();
            }
        }
Exemple #3
0
        public void OnPlayerUseWorldItemSecondary(object secondaryResult)
        {
            OptionsListDialogResult dialogResult = secondaryResult as OptionsListDialogResult;

            switch (dialogResult.SecondaryResult)
            {
            case "PourOnSelf":
                MasterAudio.PlaySound(MasterAudio.SoundType.PlayerInterface, "FillLiquidContainer");
                Player.Local.Status.RemoveCondition("BurnedByFire");
                Player.Local.Status.AddCondition("Wet");
                State.Contents.Clear();
                break;

            case "Drink":
                WorldItem liquid = null;
                if (WorldItems.Get.PackPrefab(State.Contents.PackName, State.Contents.PrefabName, out liquid))                                                                  //this is tricky - we want to drink it without destroying the prefab
                {
                    FoodStuff foodstuff = null;
                    if (liquid.Is <FoodStuff>(out foodstuff))                                                                                   //DON'T consume the foodstuff!
                    {
                        FoodStuff.Drink(foodstuff);
                        State.Contents.InstanceWeight--;
                        GUIManager.PostInfo("Drank 1 " + State.Contents.PrefabName + ", " + State.Contents.InstanceWeight.ToString() + "/" + State.Capacity.ToString() + " left.");
                    }
                }
                break;

            case "Pour Out":
                //two options here
                //if we're in the inventory then we want to add our contents to the selected stack
                //if we're in the world we want to dump it into the world
                bool playSound = false;
                if (PrimaryInterface.IsMaximized("Inventory"))
                {
                    WIStack selectedStack = Player.Local.Inventory.SelectedStack;
                    if (Stacks.Can.Stack(selectedStack, State.Contents))
                    {
                        WIStackError error = WIStackError.None;
                        for (int i = 0; i < State.Contents.InstanceWeight; i++)
                        {
                            StackItem contents = State.Contents.ToStackItem();
                            if (!Stacks.Push.Item(selectedStack, contents, ref error))
                            {
                                break;
                            }
                            else
                            {
                                playSound = true;
                            }
                        }
                    }
                }
                else
                {
                    State.Contents.Clear();
                    GUIManager.PostInfo("Discarded contents");
                    if (Player.Local.Surroundings.IsWorldItemInRange)
                    {
                        Flammable flammable = null;
                        if (Player.Local.Surroundings.WorldItemFocus.worlditem.Is <Flammable>(out flammable) && flammable.IsOnFire)
                        {
                            flammable.Extinguish();
                        }
                    }
                    playSound = true;
                }
                if (playSound)
                {
                    MasterAudio.PlaySound(MasterAudio.SoundType.PlayerInterface, "FillLiquidContainer");
                }
                break;

            default:
                break;
            }
        }
Exemple #4
0
        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);
                }
            }
        }
Exemple #5
0
 public static void Drink(FoodStuff foodstuff)
 {
     Eat(foodstuff);
 }