Ejemplo n.º 1
0
        public override bool Run()
        {
            bool  result       = false;
            IPond nearestWater = GetNearestWater(Actor.Position, float.MaxValue);

            if (nearestWater == null)
            {
                return(false);
            }
            ulong notUsed = 10u;             // Not used by the method. I don't know what it was supposed to be.

            if (!DrinkFromPondHelper.RouteToDrinkLocation(nearestWater.RepresentativePondPosition(), Actor,
                                                          GameObjectHitType.WaterPond, notUsed))
            {
                return(false);
            }
            mossBall = GlobalFunctions.CreateObjectOutOfWorld("petToyBallFoil", ProductVersion.EP5);
            //bool isChaining = Actor.CurrentInteraction is ITendGarden;
            mossBall.SetColorTint(74, 93, 35, 0);              // RGB value for Dark Moss Green
            mossBall.AddToWorld();
            mossBall.SetPosition(Actor.Position);
            CarryUtils.Acquire(Actor, mossBall);
            EnterCarry(Actor, mossBall);
            CarryUtils.Request(Actor, "PickUp");
            CarryUtils.Request(Actor, "Carry");
            //if (!PetCarrySystem.PickUpWithoutRouting(Actor, mossBall as IPetCarryable))
            //         {
            //	return false;
            //         }
            EnterStateMachine("DrinkFromPond", "Enter", "x");
            AnimateSim("Loop");
            AnimateSim("Loop");
            AnimateSim("Exit");

            if (Target.RouteSimToMeAndCheckInUse(Actor) && WaterTestDisregardGardeningSkill(Target, Actor))
            {
                ConfigureInteraction();
                //TryConfigureTendGardenInteraction(Actor.CurrentInteraction);
                result = DoWater();
            }
            CarryUtils.Request(Actor, "PutDown");
            CarryUtils.ExitCarry(Actor);
            mossBall.Destroy();
            //if (IsChainingPermitted(flag))
            //{
            //	IgnorePlants.Add(Target);
            //	if (flag2)
            //	{
            //		PushNextInteractionInChain(Singleton, WaterTest, Target.LotCurrent);
            //	}
            //	else
            //	{
            //		PushNextInteractionInChain(Singleton, WaterTestDisregardGardeningSkill, Target.LotCurrent);
            //	}
            //}
            return(result);
        }
Ejemplo n.º 2
0
        public static GameObject RecreateSoldObject(RestockItem restockItem, SimDescription actor)
        {
            try
            {
                IGameObject      gameObject       = null;
                bool             restockBuyMode   = false;
                bool             restockCraftable = false;
                StoreSetRegister register         = null;

                bool         isRug;
                StoreSetBase shopBase = ReturnStoreSetBase(restockItem, out isRug);

                if (shopBase != null)
                {
                    if (shopBase.Info.RegisterId != ObjectGuid.InvalidObjectGuid)
                    {
                        register = CMStoreSet.ReturnRegister(shopBase.Info.RegisterId, shopBase.LotCurrent);
                    }

                    restockBuyMode   = shopBase.Info.RestockBuyMode;
                    restockCraftable = shopBase.Info.RestockCraftable;

                    #region Find the slot

                    bool slotFound = false;
                    Slot slot      = Slot.ContainmentSlot_0;
                    if (!isRug)
                    {
                        Slot[] containmentSlots = shopBase.GetContainmentSlots();

                        if (containmentSlots != null)
                        {
                            for (int i = 0; i < containmentSlots.Length; i++)
                            {
                                GameObject o = shopBase.GetContainedObject(containmentSlots[i]) as GameObject;

                                if (o != null && o.ObjectId == restockItem.ObjectId)
                                {
                                    slotFound = true;
                                    slot      = containmentSlots[i];
                                    break;
                                }
                            }
                        }
                    }
                    #endregion

                    //Restock from inventory only, if not buy object and linked to register
                    bool restockFromInventory = RestockFromInventory(restockItem, restockCraftable);

                    //Restock from buy mode
                    #region Buy Mode
                    if (!restockFromInventory)
                    {
                        if (restockItem.info.Type == ItemType.Buy || restockItem.info.Type == ItemType.Craftable)
                        {
                            gameObject = GlobalFunctions.CreateObject(restockItem.info.Key, restockItem.Position, restockItem.mLevel, restockItem.ForwardVector);
                            if (!(gameObject is FailureObject))
                            {
                                if (!string.IsNullOrEmpty(restockItem.info.DesignPreset))
                                {
                                    SortedList <string, bool>     enabledStencils = new SortedList <string, bool>();
                                    SortedList <string, Complate> patterns        = StoreHelperClass.ExtractPatterns(restockItem.info.DesignPreset, enabledStencils);
                                    DesignModeSwap designModeSwap = Complate.SetupDesignSwap(gameObject.ObjectId, patterns, false, enabledStencils);
                                    if (designModeSwap != null)
                                    {
                                        designModeSwap.ApplyToObject();
                                    }
                                }
                            }
                        }
                        else
                        {
                            gameObject = ReturnShoppingObject(restockItem, actor, register);
                            gameObject.AddToWorld();
                            gameObject.SetPosition(restockItem.Position);
                        }
                        #region Pay for Restock

                        //Reduce from base owner or register's owner
                        if (shopBase.Info.Owner != 0uL)
                        {
                            SimDescription sd = CMStoreSet.ReturnSim(shopBase.Info.Owner);
                            if (sd != null)
                            {
                                sd.ModifyFunds(-restockItem.info.Price);
                            }
                            else
                            {
                                CMStoreSet.PrintMessage("Couldn't find owner sim");
                            }
                        }
                        else if (shopBase.Info.RegisterId != ObjectGuid.InvalidObjectGuid)
                        {
                            //StoreSetRegister register = CMStoreSet.ReturnRegister(shopBase.Info.RegisterId, shopBase.LotCurrent);
                            if (register != null && register.Info.OwnerId != 0uL)
                            {
                                SimDescription sd = CMStoreSet.ReturnSim(register.Info.OwnerId);
                                if (sd != null)
                                {
                                    sd.ModifyFunds(-restockItem.info.Price);
                                }
                            }
                        }

                        #endregion
                    }
                    #endregion Buy Mode

                    #region Inventory
                    else
                    {
                        //Restock from Inventory
                        if (shopBase != null && shopBase.Info.RegisterId != ObjectGuid.InvalidObjectGuid)
                        {
                            gameObject = ReturnRestocableObject(restockItem, shopBase.Info.RegisterId);

                            if (gameObject != null)
                            {
                                gameObject.AddToWorld();
                                gameObject.SetPosition(restockItem.Position);
                                gameObject.SetForward(restockItem.ForwardVector);
                            }
                            else
                            {
                                CMStoreSet.PrintMessage("Restockable object null");
                            }
                        }
                    }
                    #endregion Inventory

                    //Delete restock object
                    if (restockItem != null)
                    {
                        restockItem.Destroy();
                    }

                    //Add restocked item back to slot
                    if (slotFound)
                    {
                        IGameObject io = (IGameObject)shopBase;
                        gameObject.ParentToSlot(io, slot);
                    }


                    return((GameObject)gameObject);
                }
                else
                {
                    return(null);
                }
            }
            catch (System.Exception ex)
            {
                CMStoreSet.PrintMessage("RecreateSoldObject: " + ex.Message);
                return(null);
            }
        }
Ejemplo n.º 3
0
        public static void RestockDisplay(CraftersConsignmentDisplay display, out Common.StringBuilder debug)
        {
            debug = new Common.StringBuilder("Display: " + display.CatalogName + Common.NewLine + "ObjectID:" + display.ObjectId);
            if (qualites.Count == 0)
            {
                InitLists();
            }

            List <int> slotsToSkipForWeddingCakeSetupOnChiller = new List <int> {
                23, 25
            };
            List <int> slotsToSkipForWeddingCakeSetupOnRack = new List <int> {
                0, 2, 4
            };
            List <int> slotsForWeddingCakesChiller = new List <int> {
                21, 22, 24
            };
            List <int> slotsForWeddingCakesOnRack = new List <int> {
                1, 3
            };
            // wedding cake slots are included in these so they get stocked... if the cakes are disabled, they will be skipped properly
            List <int> slotsForElegantStockingOnRack = new List <int> {
                1, 3, 5, 8, 9, 11, 13, 14, 17, 18, 20, 22, 23, 26
            };
            List <int> slotsForElegantStockingOnChiller = new List <int> {
                0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 21, 22, 24
            };
            Recipe randomRestockRecipe = null;

            if (display.LotCurrent != null)
            {
                debug += Common.NewLine + "LotCurrent: " + display.LotCurrent.Name;
            }

            if (!display.InWorld)
            {
                debug += Common.NewLine + "Display not in world";
                return;
            }

            if (Cupcake.Settings.IsDisplayExempt(display.ObjectId))
            {
                debug += Common.NewLine + "Display has auto restock disabled";
                return;
            }

            bool random = false;

            if (!Cupcake.Settings.HasSettings(display.ObjectId))
            {
                debug += Common.NewLine + "Display has no user defined settings.";
                random = true;
            }

            if (!Cupcake.Settings.mAffectActive && random)
            {
                if (display.LotCurrent == null)
                {
                    debug += Common.NewLine + "LotCurrent null";
                    return;
                }

                if (display.LotCurrent.LotId == Household.ActiveHousehold.LotId)
                {
                    debug += Common.NewLine + "On active household lot";
                    return;
                }

                List <PropertyData> list = RealEstateManager.AllPropertiesFromAllHouseholds();
                for (int i = 0; i < list.Count; i++)
                {
                    if (list[i] != null && display.LotCurrent.LotId == list[i].LotId && list[i].Owner != null && list[i].Owner.OwningHousehold == Household.ActiveHousehold)
                    {
                        debug += Common.NewLine + "On owned lot";
                        return;
                    }
                }
            }

            DisplayHelper.DisplayTypes displayType;
            Dictionary <int, Slot>     slots = DisplayHelper.GetEmptyOrFoodSlots(display, out displayType);

            foreach (KeyValuePair <int, Slot> slot in slots)
            {
                debug += Common.NewLine + "Slot: " + slot.Key;
                if (displayType == DisplayHelper.DisplayTypes.Chiller)
                {
                    if (!Cupcake.Settings.SlotHasSettings(display.ObjectId, slot.Key))
                    {
                        if (slot.Key > 20 && !Cupcake.Settings.mStockWeddingCakes)
                        {
                            debug += Common.NewLine + "Wedding cakes disabled, skipping top shelf";
                            continue;
                        }

                        if (Cupcake.Settings.mStockWeddingCakes && slotsToSkipForWeddingCakeSetupOnChiller.Contains(slot.Key))
                        {
                            debug += Common.NewLine + "Skipping slots for presentable wedding cake setup";
                            continue;
                        }

                        if (Cupcake.Settings.mElegantRestock && !slotsForElegantStockingOnChiller.Contains(slot.Key))
                        {
                            debug += Common.NewLine + "Skipping slot for elegant restocking";
                            continue;
                        }
                    }
                }

                if (displayType == DisplayHelper.DisplayTypes.Rack)
                {
                    if (!Cupcake.Settings.SlotHasSettings(display.ObjectId, slot.Key))
                    {
                        if (Cupcake.Settings.mStockWeddingCakes && slotsToSkipForWeddingCakeSetupOnRack.Contains(slot.Key))
                        {
                            debug += Common.NewLine + "Skipping slots for presentable wedding cake setup";
                            continue;
                        }

                        if (Cupcake.Settings.mElegantRestock && !slotsForElegantStockingOnRack.Contains(slot.Key))
                        {
                            debug += Common.NewLine + "Skipping slot for elegant restocking";
                            continue;
                        }
                    }
                }

                GameObject containedObject = display.GetContainedObject(slot.Value) as GameObject;
                if (containedObject == null)
                {
                    Dictionary <string, List <Quality> > settings = Cupcake.Settings.GetDisplaySettingsForSlot(display.ObjectId, slot.Key);

                    Recipe         recipe    = null;
                    IFoodContainer container = null;
                    Quality        quality   = Quality.Perfect;
                    if (random && !Cupcake.Settings.mDisableRandomAutoRestock && (!Cupcake.Settings.mOneRecipePerDisplayOnRandom || (Cupcake.Settings.mOneRecipePerDisplayOnRandom && randomRestockRecipe == null)))
                    {
                        debug += Common.NewLine + "Random";
                        if (Cupcake.Settings.mRandomRestockSettings.Count > 0)
                        {
                            if (Cupcake.Settings.Debugging)
                            {
                                debug += Common.NewLine + "Choices:";
                                foreach (KeyValuePair <string, List <Quality> > val in Cupcake.Settings.mRandomRestockSettings)
                                {
                                    debug += Common.NewLine + val.Key;
                                    foreach (Quality val2 in val.Value)
                                    {
                                        debug += Common.NewLine + val2.ToString();
                                    }
                                }
                            }

                            if (Recipe.NameToRecipeHash.Count > 0)
                            {
                                string pick = RandomUtil.GetRandomObjectFromList <string>(new List <string>(Cupcake.Settings.mRandomRestockSettings.Keys));
                                if (Recipe.NameToRecipeHash.ContainsKey(pick))
                                {
                                    recipe = Recipe.NameToRecipeHash[pick];

                                    debug += Common.NewLine + "Fetching random recipe...";
                                    debug += Common.NewLine + "Pick: " + recipe.Key;

                                    quality = RandomUtil.GetRandomObjectFromList <Quality>(Cupcake.Settings.mRandomRestockSettings[pick]);
                                    debug  += Common.NewLine + "Fetching random quality...";
                                    debug  += Common.NewLine + "Pick: " + quality.ToString();
                                }
                                else
                                {
                                    debug += Common.NewLine + "Failed to find defined recipe";
                                    continue;
                                }
                            }
                        }
                        else
                        {
                            if (goodies.Count > 0)
                            {
                                recipe = RandomUtil.GetRandomObjectFromList <Recipe>(goodies);
                                debug += Common.NewLine + "Fetching random bakery recipe...";
                                debug += Common.NewLine + "Pick: " + recipe.SpecificNameKey;
                                debug += Common.NewLine + "Quality: Always Perfect";
                            }
                        }

                        randomRestockRecipe = recipe;
                    }

                    if (random && Cupcake.Settings.mOneRecipePerDisplayOnRandom && randomRestockRecipe != null)
                    {
                        debug += Common.NewLine + "OneRecipePerDisplayOnRandom = true" + Common.NewLine + "Last Recipe: " + randomRestockRecipe.GenericName;
                        recipe = randomRestockRecipe;
                    }

                    if (settings != null)
                    {
                        debug += Common.NewLine + "Reading user settings...";

                        if (Cupcake.Settings.Debugging)
                        {
                            debug += Common.NewLine + "Choices:";
                            foreach (KeyValuePair <string, List <Quality> > val in settings)
                            {
                                debug += Common.NewLine + val.Key;
                                foreach (Quality val2 in val.Value)
                                {
                                    debug += Common.NewLine + val2.ToString();
                                }
                            }
                        }

                        string pick = "";
                        if (settings.Count > 0)
                        {
                            List <string> tempList = new List <string>();
                            tempList.AddRange(settings.Keys);

                            pick = RandomUtil.GetRandomObjectFromList <string>(tempList);

                            if (Recipe.NameToRecipeHash.ContainsKey(pick))
                            {
                                recipe = Recipe.NameToRecipeHash[pick];
                                debug += Common.NewLine + "Fetching random recipe...";
                                debug += Common.NewLine + "Pick: " + recipe.Key;
                            }
                            else
                            {
                                debug += Common.NewLine + "Failed to find defined recipe: " + pick;
                                continue;
                            }
                        }
                        else
                        {
                            debug += Common.NewLine + "Settings for slot was 0 count.";
                            continue;
                        }

                        quality = RandomUtil.GetRandomObjectFromList <Quality>(Cupcake.Settings.mDisplayRestockSettings[display.ObjectId][slot.Key][pick]);
                        debug  += Common.NewLine + "Fetching random quality...";
                        debug  += Common.NewLine + "Pick: " + quality.ToString();
                    }

                    bool tryCake = false;
                    if (random && Cupcake.Settings.mStockWeddingCakes && !Cupcake.Settings.SlotHasSettings(display.ObjectId, slot.Key))
                    {
                        List <string> cakes = new List <string> {
                            "BSBakeWeddingCake", "WeddingCakeSliceDOT07"
                        };
                        tryCake = true;

                        if (GameUtils.IsInstalled(ProductVersion.EP4))
                        {
                            cakes.Add("Wedding Cake Slice");
                        }

                        if ((displayType == DisplayHelper.DisplayTypes.Chiller && slotsForWeddingCakesChiller.Contains(slot.Key)) || (displayType == DisplayHelper.DisplayTypes.Rack && slotsForWeddingCakesOnRack.Contains(slot.Key)))
                        {
                            debug += Common.NewLine + "Wedding cake slot";
                            recipe = null;
                            while (recipe == null)
                            {
                                string pick = RandomUtil.GetRandomObjectFromList <string>(cakes);
                                if (!Recipe.NameToRecipeHash.TryGetValue(pick, out recipe))
                                {
                                    // for folks with out of date mods
                                    if (pick == "BSBakeWeddingCake")
                                    {
                                        break;
                                    }
                                }
                            }
                        }
                    }

                    if (recipe != null)
                    {
                        if (quality == Quality.Any)
                        {
                            // EA standard apparently doesn't handle this correctly...
                            quality = RandomUtil.GetRandomObjectFromList <Quality>(qualites);
                        }

                        // Catalog recipes
                        IGameObject cake = null;
                        if (recipe.Key == "WeddingCakeSliceDOT07")
                        {
                            debug += Common.NewLine + "Attempt at Monte Vista cake";
                            cake   = GlobalFunctions.CreateObjectOutOfWorld("foodServeCakeWeddingDOT07", ~ProductVersion.Undefined);
                            if (cake is FailureObject)
                            {
                                cake = GlobalFunctions.CreateObjectOutOfWorld("foodServeCakeWeddingDOT07", ProductVersion.BaseGame);
                            }
                        }
                        else if (recipe.Key == "Wedding Cake Slice")
                        {
                            debug += Common.NewLine + "Attempt at Generations cake";
                            cake   = GlobalFunctions.CreateObjectOutOfWorld("foodServeCakeWeddingTraditional", ProductVersion.EP4);
                            if (cake is FailureObject)
                            {
                                cake = GlobalFunctions.CreateObjectOutOfWorld("foodServeCakeWeddingTraditional", ProductVersion.BaseGame);
                            }
                        }
                        else if (((tryCake && cake is FailureObject) || recipe.Key == "BSBakeWeddingCake"))
                        {
                            debug += Common.NewLine + "Attempt at Store Wedding cake";
                            cake   = GlobalFunctions.CreateObjectOutOfWorld("foodServeCakeWeddingBakery", ~ProductVersion.Undefined);
                            if (cake is FailureObject)
                            {
                                cake = GlobalFunctions.CreateObjectOutOfWorld("foodServeCakeWeddingBakery", ProductVersion.BaseGame);
                            }
                        }
                        else if (recipe.Key == "BSBakeBirthdayCake")
                        {
                            debug += Common.NewLine + "Attempt at Store Birthday cake";
                            cake   = GlobalFunctions.CreateObjectOutOfWorld("FoodBirthdayCakeBakery", ~ProductVersion.Undefined);
                            if (cake is FailureObject)
                            {
                                cake = GlobalFunctions.CreateObjectOutOfWorld("FoodBirthdayCakeBakery", ProductVersion.BaseGame);
                            }
                        }
                        else
                        {
                            container = recipe.CreateFinishedFood(recipe.CanMakeGroupServing ? Recipe.MealQuantity.Group : Recipe.MealQuantity.Single, quality);
                        }

                        if (cake != null)
                        {
                            if (cake is FailureObject)
                            {
                                debug += Common.NewLine + "Cake was FailureObject";
                                try
                                {
                                    cake.Destroy();
                                }
                                catch { }
                                continue;
                            }

                            debug += Common.NewLine + "Cake success";
                            DisplayHelper.ParentToSlot(cake as GameObject, slot.Value, display);
                            cake.AddToWorld();
                            InitInteractions(cake as GameObject);
                        }

                        if (container != null)
                        {
                            if (container is FailureObject)
                            {
                                debug += Common.NewLine + "Container was FailureObject";
                                try
                                {
                                    container.Destroy();
                                }
                                catch { }
                                continue;
                            }

                            DisplayHelper.ParentToSlot(container as GameObject, slot.Value, display);
                            container.SetGeometryState(recipe.SingleServingContainer); // this is how EA sets it, don't ask
                            container.AddToWorld();

                            ServingContainer container2 = container as ServingContainer;
                            if (container2 != null)
                            {
                                int[] numArray = new int[] { 0, 0, 0, 0, 0, 0, 15, 30, 0x2d, 60, 0x4b, 100, 0x65 };
                                container2.CookingProcess.FoodPoints = numArray[(int)quality];
                                container2.CookingProcess.FoodState  = FoodCookState.Cooked;
                                container2.FoodCookStateChanged(container2.CookingProcess.FoodState);
                            }

                            InitInteractions(container as GameObject);

                            debug += Common.NewLine + "Success: " + recipe.GenericName + Common.NewLine + quality.ToString();
                        }
                    }
                }
                else
                {
                    debug += Common.NewLine + "Slot contained object: " + containedObject.CatalogName;
                }
            }
            display.AddInteractionsToChildObjects();
        }