Beispiel #1
0
        public static bool Prefix(Sign __instance, Farmer who, bool justCheckingForActivity, ref bool __result)
        {
            if (justCheckingForActivity)
            {
                return(true);
            }
            var owner = MapUtility.Owner(__instance);

            MarketDay.Log(
                $"Prefix_Sign_checkForAction checking {__instance} {__instance.DisplayName} owner {owner} at {__instance.TileLocation}",
                LogLevel.Debug, true);

            if (owner is null || owner == $"Farmer:{who.Name}")
            {
                return(true);
            }

            MarketDay.Log(
                $"Prefix_Sign_checkForAction preventing action on object at {__instance.TileLocation} owned by {owner}",
                LogLevel.Debug, true);

            who.currentLocation.playSound("clank");
            __instance.shakeTimer = 500;
            __result = false;
            return(false);
        }
Beispiel #2
0
        /// <summary>
        /// Loads the portrait, if it exists, and use the seasonal version if one is found for the current season
        /// </summary>
        public void UpdatePortrait()
        {
            if (PortraitPath == null)
            {
                return;
            }

            //construct seasonal path to the portrait
            string seasonalPath = PortraitPath.Insert(PortraitPath.IndexOf('.'), "_" + Game1.currentSeason);

            try
            {
                //if the seasonal version exists, load it
                if (ContentPack.HasFile(seasonalPath))
                {
                    _portrait = ContentPack.ModContent.Load <Texture2D>(seasonalPath);
                }
                //if the seasonal version doesn't exist, try to load the default
                else if (ContentPack.HasFile(PortraitPath))
                {
                    _portrait = ContentPack.ModContent.Load <Texture2D>(PortraitPath);
                }
            }
            catch (Exception ex) //couldn't load the image
            {
                MarketDay.Log(ex.Message + ex.StackTrace, LogLevel.Error);
            }
        }
Beispiel #3
0
        public static bool Prefix(Object __instance, GameLocation location, ref bool __result)
        {
            var owner = MapUtility.Owner(__instance);

            MarketDay.Log(
                $"Prefix_Object_performToolAction checking {__instance} {__instance.DisplayName} owner {owner} at {__instance.TileLocation}",
                LogLevel.Debug, true);

            if (MarketDay.Config.RuinTheFurniture)
            {
                return(true);
            }
            if (owner is null)
            {
                return(true);
            }

            MarketDay.Log(
                $"Prefix_Object_performToolAction preventing damage to object at {__instance.TileLocation} owned by {owner}",
                LogLevel.Debug, true);
            location.playSound("clank");
            __instance.shakeTimer = 100;
            __result = false;
            return(false);
        }
Beispiel #4
0
        public static void Postfix(Chest __instance, SpriteBatch spriteBatch, int x, int y)
        {
            if (!__instance.modData.TryGetValue($"{MarketDay.SMod.ModManifest.UniqueID}/{GrangeShop.StockChestKey}",
                                                out var ShopKey))
            {
                return;
            }

            // get shop for ShopKey
            if (!ShopManager.GrangeShops.TryGetValue(ShopKey, out var grangeShop))
            {
                MarketDay.Log(
                    $"Postfix_draw: shop '{ShopKey}' not found in ShopManager.GrangeShops, can't draw",
                    LogLevel.Error);
                return;
            }

            var tileLocation = grangeShop.Origin;

            if (tileLocation == Vector2.Zero)
            {
                return;
            }

            var drawLayer = Math.Max(0f, (tileLocation.Y * Game1.tileSize - 24) / 10000f) + tileLocation.X * 1E-05f;

            grangeShop.drawGrangeItems(tileLocation, spriteBatch, drawLayer);

            drawLayer = Math.Max(0f, (tileLocation.Y + 3) * Game1.tileSize / 10000f) + tileLocation.X * 1E-05f;
            grangeShop.DrawSign(tileLocation, spriteBatch, drawLayer);
        }
Beispiel #5
0
        /// <summary>
        /// Initialize the ItemStock, doing error checking on the quality, and setting the price to the store price
        /// if none is given specifically for this stock.
        /// Creates the builder
        /// </summary>
        /// <param name="shopName"></param>
        /// <param name="price"></param>
        /// <param name="defaultSellPriceMultiplier"></param>
        /// <param name="priceMultiplierWhen"></param>
        internal void Initialize(string shopName, int price, double defaultSellPriceMultiplier, Dictionary <double, string[]> priceMultiplierWhen)
        {
            ShopName = shopName;
            DefaultSellPriceMultiplier = defaultSellPriceMultiplier;
            PriceMultiplierWhen        = priceMultiplierWhen;

            if (Quality is < 0 or 3 or > 4)
            {
                Quality = 0;
                MarketDay.Log("Item quality can only be 0,1,2, or 4. Defaulting to 0", LogLevel.Warn);
            }

            CurrencyObjectId = ItemsUtil.GetIndexByName(StockItemCurrency);

            //sets price to the store price if no stock price is given
            if (StockPrice == -1)
            {
                StockPrice = price;
            }
            _priceMultiplierWhen = priceMultiplierWhen;

            if (IsRecipe)
            {
                Stock = 1;
            }

            _builder = new ItemBuilder(this);
        }
Beispiel #6
0
        public static bool Prefix(Object __instance, GameLocation location, ref bool __result)
        {
            var owner = MapUtility.Owner(__instance);

            MarketDay.Log(
                $"Prefix_Object_performUseAction checking {__instance} {__instance.DisplayName} owner {owner} at {__instance.TileLocation}",
                LogLevel.Debug, true);

            if (owner is null)
            {
                return(true);
            }
            if (owner == $"Farmer:{Game1.player.Name}" || MarketDay.Config.PeekIntoChests)
            {
                return(true);
            }

            MarketDay.Log(
                $"Prefix_Object_performUseAction preventing use of object at {__instance.TileLocation} owned by {owner}",
                LogLevel.Debug, true);

            location.playSound("clank");
            __instance.shakeTimer = 500;
            __result = false;
            return(false);
        }
Beispiel #7
0
        public static ISalable GetDGAObjectByName(string name, string itemType = "Object")
        {
            if (APIs.dgaApi.Value is not {
            } dgaApi)
            {
                MarketDay.Log($"{name}/{itemType}: could not get DGA API", LogLevel.Trace);
                return(null);
            }

            var obj = dgaApi.SpawnDGAItem(name);

            switch (obj)
            {
            case null:
                MarketDay.Log($"{name}/{itemType}: not a DGA object", LogLevel.Trace);
                return(null);

            case ISalable item:
                return(item);

            default:
                MarketDay.Log($"{name}/{itemType}: not a saleable object", LogLevel.Trace);
                return(null);
            }
        }
        internal void CheckItems()
        {
            MarketDay.Log("Checking progression data", LogLevel.Debug);
            if (Levels.Count == 0)
            {
                MarketDay.Log($"    No levels loaded", LogLevel.Error);
            }
            foreach (var level in Levels)
            {
                foreach (var prizeLevel in level.Prizes)
                {
                    var name = prizeLevel.Object;

                    var item = ItemsUtil.GetIndexByName(name);
                    if (item == -1)
                    {
                        MarketDay.Log($"    Could not get index for object: {name}", LogLevel.Warn);
                    }

                    if (name is "Wine" or "Jelly" or "Juice" or "Pickle" or "Roe" or "Aged Roe")
                    {
                        var preservedGoods = prizeLevel.Flavor;
                        var item1          = ItemsUtil.GetIndexByName(preservedGoods);
                        if (item1 == -1)
                        {
                            MarketDay.Log($"    Could not get index for flavor: {preservedGoods}", LogLevel.Warn);
                        }
                    }
                }
            }
        }
Beispiel #9
0
        /// <summary>
        /// Resets the items of this item stock, with condition checks and randomization
        /// </summary>
        /// <returns></returns>
        public Dictionary <ISalable, int[]> Update()
        {
            if (When != null && !APIs.Conditions.CheckConditions(When))
            {
                return(null);                       //did not pass conditions
            }
            if (!ItemsUtil.CheckItemType(ItemType)) //check that itemtype is valid
            {
                MarketDay.Log($"\t\"{ItemType}\" is not a valid ItemType. No items from this stock will be added."
                              , LogLevel.Warn);
                return(null);
            }

            _itemPriceAndStock = new Dictionary <ISalable, int[]>();
            _builder.SetItemPriceAndStock(_itemPriceAndStock);

            double priceMultiplier = 1;

            if (_priceMultiplierWhen != null)
            {
                foreach (KeyValuePair <double, string[]> kvp in _priceMultiplierWhen)
                {
                    if (APIs.Conditions.CheckConditions(kvp.Value))
                    {
                        priceMultiplier = kvp.Key;
                        break;
                    }
                }
            }

            if (ItemType != "Seed")
            {
                AddById(priceMultiplier);
                AddByName(priceMultiplier);
            }
            else
            {
                if (ItemIDs != null)
                {
                    MarketDay.Log(
                        "ItemType of \"Seed\" is a special itemtype used for parsing Seeds from JA Pack crops and trees and does not support input via ID. If adding seeds via ID, please use the ItemType \"Object\" instead to directly sell the seeds/saplings", LogLevel.Trace);
                }
                if (ItemNames != null)
                {
                    MarketDay.Log(
                        "ItemType of \"Seed\" is a special itemtype used for parsing Seeds from JA Pack crops and trees and does not support input via Name. If adding seeds via Name, please use the ItemType \"Object\" instead to directly sell the seeds/saplings", LogLevel.Trace);
                }
            }

            AddByJAPack(priceMultiplier);

            ItemsUtil.RandomizeStock(_itemPriceAndStock, MaxNumItemsSoldInItemStock);
            return(_itemPriceAndStock);
        }
Beispiel #10
0
        internal static bool Equal(ISalable a, ISalable b)
        {
            if (a is null || b is null)
            {
                return(false);
            }

            var dgaApi = APIs.dgaApi.Value;

            if (dgaApi is not null)
            {
                var aID = dgaApi.GetDGAItemId(a);
                var bID = dgaApi.GetDGAItemId(b);
                if (aID is not null && bID is not null)
                {
                    return(aID == bID);
                }
            }

            switch (a)
            {
            case Hat aHat when b is Hat bHat:
                return(aHat.which.Value == bHat.which.Value);

            case Tool aTool when b is Tool bTool:      // includes weapons
                return(aTool.InitialParentTileIndex == bTool.InitialParentTileIndex);

            case Boots aBoots when b is Boots bBoots:
                return(aBoots.indexInTileSheet == bBoots.indexInTileSheet);

            case Item aItem when b is Item bItem:
            {
                if (aItem.ParentSheetIndex > -1 && bItem.ParentSheetIndex > -1)
                {
                    return(aItem.ParentSheetIndex == bItem.ParentSheetIndex && aItem.Category == bItem.Category);
                }
                break;
            }
            }

            if (a is not Item)
            {
                MarketDay.Log($"Equal: {a.Name} not an item", LogLevel.Warn);
            }
            if (b is not Item)
            {
                MarketDay.Log($"Equal: {b.Name} not an item", LogLevel.Warn);
            }
            return(a.Name == b.Name);
        }
Beispiel #11
0
        private static void LoadOneMail(string mailKey)
        {
            var deserializeKey = $"Mail/{mailKey}";
            var Text           = MarketDay.GetSharedString($"{deserializeKey}/Text");
            var player         = MarketDay.GetSharedString($"{deserializeKey}/Player");
            var TextColor      = MarketDay.GetSharedValue($"{deserializeKey}/TextColor");
            var whichBG        = MarketDay.GetSharedValue($"{deserializeKey}/BG");
            var ObjName        = MarketDay.GetSharedString($"{deserializeKey}/ObjName");
            var Flavor         = MarketDay.GetSharedString($"{deserializeKey}/Flavor");
            var Stack          = MarketDay.GetSharedValue($"{deserializeKey}/Stack");
            var Quality        = MarketDay.GetSharedValue($"{deserializeKey}/Quality");

            if (player is not null && Game1.player.Name != player)
            {
                return;
            }

            if (ObjName is not null)
            {
                MarketDay.Log($"Loading prize mail {mailKey}", LogLevel.Trace);
                var attachment = AttachmentForPrizeMail(ObjName, Flavor, Stack, Quality);
                MailDao.SaveLetter(
                    new Letter(mailKey, Text, new List <Item> {
                    attachment
                },
                               l => !Game1.player.mailReceived.Contains(l.Id),
                               l => Game1.player.mailReceived.Add(l.Id),
                               whichBG
                               )
                {
                    TextColor = TextColor
                }
                    );
            }
            else
            {
                MarketDay.Log($"Loading non-prize mail {mailKey}", LogLevel.Trace);
                MailDao.SaveLetter(
                    new Letter(mailKey, Text,
                               l => !Game1.player.mailReceived.Contains(l.Id),
                               l => Game1.player.mailReceived.Add(l.Id),
                               whichBG
                               )
                {
                    TextColor = TextColor
                }
                    );
            }
        }
Beispiel #12
0
        private static Object AttachmentForPrizeMail(string ObjName, string Flavor, int Stack, int Quality = 0)
        {
            var idx = ItemsUtil.GetIndexByName(ObjName);

            if (idx < 0)
            {
                MarketDay.Log($"Could not find prize object {ObjName}", LogLevel.Error);
                idx = 169;
            }

            var stack      = Math.Max(Stack, 1);
            var attachment = new Object(idx, stack);

            if (Quality is 0 or 1 or 2 or 4)
            {
                attachment.Quality = Quality;
            }
            if (Flavor is null || Flavor.Length <= 0)
            {
                return(attachment);
            }

            var prIdx = ItemsUtil.GetIndexByName(Flavor);

            if (prIdx < 0)
            {
                MarketDay.Log($"Could not find flavor object {Flavor}", LogLevel.Error);
                prIdx = 258;
            }
            attachment.preservedParentSheetIndex.Value = prIdx;
            attachment.preserve.Value = ObjName switch
            {
                "Wine" => Object.PreserveType.Wine,
                "Jelly" => Object.PreserveType.Jelly,
                "Juice" => Object.PreserveType.Juice,
                "Pickle" => Object.PreserveType.Pickle,
                "Roe" => Object.PreserveType.Roe,
                "Aged Roe" => Object.PreserveType.AgedRoe,
                _ => Object.PreserveType.Jelly
            };

            return(attachment);
        }
    }
Beispiel #13
0
        /// <summary>
        /// Refreshes the stock of all items, doing condition checking and randomization
        /// </summary>
        public void Update()
        {
            ItemPriceAndStock = new Dictionary <ISalable, int[]>();
            MarketDay.Log($"Updating {_shopName}", LogLevel.Trace, true);

            foreach (ItemStock stock in _itemStocks)
            {
                var priceAndStock = stock.Update();
                //null is returned if conhditions aren't met, skip adding this stock
                if (priceAndStock == null)
                {
                    continue;
                }

                Add(priceAndStock);
            }

            //randomly reduces the stock of the whole store down to maxNumItemsSoldInStore
            ItemsUtil.RandomizeStock(ItemPriceAndStock, _maxNumItemsSoldInStore);
        }
Beispiel #14
0
 /// <summary>
 /// Refreshes the contents of all stores
 /// and sets the flag for if the store has been opened yet today to false
 /// </summary>
 public void UpdateItemPriceAndStock()
 {
     _shopOpenedToday = false;
     MarketDay.Log($"Generating stock for {ShopName}", LogLevel.Trace, true);
     StockManager.Update();
 }
Beispiel #15
0
        /// <summary>
        /// Add all items from the JA Packs listed in the JAPacks section
        /// </summary>
        private void AddByJAPack(double priceMultiplier)
        {
            if (JAPacks == null)
            {
                return;
            }

            if (APIs.JsonAssets == null)
            {
                return;
            }

            foreach (var JAPack in JAPacks)
            {
                MarketDay.Log($"Adding all {ItemType}s from {JAPack}", LogLevel.Trace);

                if (ItemType == "Seed")
                {
                    var crops = APIs.JsonAssets.GetAllCropsFromContentPack(JAPack);
                    var trees = APIs.JsonAssets.GetAllFruitTreesFromContentPack(JAPack);


                    if (crops != null)
                    {
                        foreach (string crop in crops)
                        {
                            if (ExcludeFromJAPacks != null && ExcludeFromJAPacks.Contains(crop))
                            {
                                continue;
                            }
                            int id = ItemsUtil.GetSeedId(crop);
                            if (id > 0)
                            {
                                _builder.AddItemToStock(id, priceMultiplier);
                            }
                        }
                    }

                    if (trees != null)
                    {
                        foreach (string tree in trees)
                        {
                            if (ExcludeFromJAPacks != null && ExcludeFromJAPacks.Contains(tree))
                            {
                                continue;
                            }
                            int id = ItemsUtil.GetSaplingId(tree);
                            if (id > 0)
                            {
                                _builder.AddItemToStock(id, priceMultiplier);
                            }
                        }
                    }

                    continue; //skip the rest of the loop so we don't also add the none-seed version
                }

                var packs = GetJaItems(JAPack);
                if (packs == null)
                {
                    MarketDay.Log($"No {ItemType} from {JAPack} could be found", LogLevel.Trace);
                    continue;
                }

                foreach (string itemName in packs)
                {
                    if (ExcludeFromJAPacks != null && ExcludeFromJAPacks.Contains(itemName))
                    {
                        continue;
                    }
                    _builder.AddItemToStock(itemName, priceMultiplier);
                }
            }
        }
Beispiel #16
0
 /// <summary>
 /// Update the selectedLanguage to the current language on save loaded, in case it has been changed
 /// </summary>
 internal static void UpdateSelectedLanguage()
 {
     _selectedLanguage = LocalizedContentManager.CurrentLanguageCode;
     MarketDay.Log($"Updating current language settings: {_selectedLanguage}", LogLevel.Trace);
 }