Exemple #1
0
        public IChore GetChore(ChoreData choreData)
        {
            choreData.Config.TryGetValue("ChoreType", out var choreTypeObject);
            var choreType = (string)choreTypeObject;

            if (choreType.Equals("FeedTheAnimals", StringComparison.CurrentCultureIgnoreCase))
            {
                return(new FeedTheAnimalsChore(choreData));
            }
            if (choreType.Equals("LoveThePets", StringComparison.CurrentCultureIgnoreCase))
            {
                return(new LoveThePetsChore(choreData));
            }
            if (choreType.Equals("GiveAGift", StringComparison.CurrentCultureIgnoreCase))
            {
                return(new GiveAGiftChore(choreData));
            }
            if (choreType.Equals("PetTheAnimals", StringComparison.CurrentCultureIgnoreCase))
            {
                return(new PetTheAnimalsChore(choreData));
            }
            if (choreType.Equals("RepairTheFences", StringComparison.CurrentCultureIgnoreCase))
            {
                return(new RepairTheFencesChore(choreData));
            }
            if (choreType.Equals("WaterTheCrops", StringComparison.CurrentCultureIgnoreCase))
            {
                return(new WaterTheCropsChore(choreData));
            }
            if (choreType.Equals("WaterTheSlimes", StringComparison.CurrentCultureIgnoreCase))
            {
                return(new WaterTheSlimesChore(choreData));
            }
            return(null);
        }
        internal ChoreHandler(ChoreData chore, int price)
        {
            Chore = chore;
            Price = price;

            var choreTokens = HelpForHireMod.CustomChoresApi.GetChoreTokens(chore.ChoreName);

            choreTokens.Add("Mod", () => "HelpForHire");

            // get display name
            _displayName = (
                from translation in chore.Translations
                where translation.Key.Equals("DisplayName", StringComparison.CurrentCultureIgnoreCase) &&
                translation.Filter(choreTokens)
                select translation)?.First();

            // get description
            _description = (
                from translation in chore.Translations
                where translation.Key.Equals("Description", StringComparison.CurrentCultureIgnoreCase) &&
                translation.Filter(choreTokens)
                select translation)?.First();

            // get work needed token
            _workNeeded = (choreTokens.TryGetValue("WorkNeeded", out var workNeededFn)) ? workNeededFn : () => "1";

            // get work done token
            _workDone = (choreTokens.TryGetValue("WorkDone", out var workDoneFn)) ? workDoneFn : () => "1";
        }
Exemple #3
0
        public GiveAGiftChore(ChoreData choreData) : base(choreData)
        {
            ChoreData.Config.TryGetValue("GiftType", out var giftType);
            ChoreData.Config.TryGetValue("MaxGifts", out var maxGifts);
            ChoreData.Config.TryGetValue("EnableUniversal", out var enableUniversal);
            ChoreData.Config.TryGetValue("ChanceForLove", out var chanceForLove);

            _giftType = giftType is string s && !string.IsNullOrWhiteSpace(s) ? s : "Birthday";
            _maxGifts = maxGifts is int n ? n : 1;

            if (!_giftType.Equals("Birthday", StringComparison.CurrentCultureIgnoreCase))
            {
                return;
            }

            _enableUniversal = enableUniversal is bool b && b;
            _chanceForLove   = chanceForLove is double d ? d : 0.1;

            if (Game1.NPCGiftTastes.TryGetValue("Universal_Love", out var universalLoves))
            {
                _universalLoves.AddRange(
                    from a in universalLoves.Split(' ')
                    select Convert.ToInt32(a, CultureInfo.InvariantCulture));
            }

            if (Game1.NPCGiftTastes.TryGetValue("Universal_Like", out var universalLikes))
            {
                _universalLikes.AddRange(
                    from a in universalLikes.Split(' ')
                    select Convert.ToInt32(a, CultureInfo.InvariantCulture));
            }
        }
Exemple #4
0
        public LoveThePetsChore(ChoreData choreData) : base(choreData)
        {
            ChoreData.Config.TryGetValue("FillWaterBowl", out var waterBowl);
            ChoreData.Config.TryGetValue("EnablePetting", out var enablePetting);

            _fillWaterBowl = !(waterBowl is bool b1) || b1;
            _enablePetting = !(enablePetting is bool b2) || b2;
        }
Exemple #5
0
        public FeedTheAnimalsChore(ChoreData choreData) : base(choreData)
        {
            ChoreData.Config.TryGetValue("EnableBarns", out var enableBarns);
            ChoreData.Config.TryGetValue("EnableCoops", out var enableCoops);

            _enableBarns = !(enableBarns is bool b1) || b1;
            _enableCoops = !(enableCoops is bool b2) || b2;
        }
Exemple #6
0
        public WaterTheCropsChore(ChoreData choreData) : base(choreData)
        {
            ChoreData.Config.TryGetValue("EnableFarm", out var enableFarm);
            ChoreData.Config.TryGetValue("EnableBuildings", out var enableBuildings);
            ChoreData.Config.TryGetValue("EnableGreenhouse", out var enableGreenhouse);

            _enableFarm = !(enableFarm is bool b1) || b1;
            _enableBuildings = !(enableBuildings is bool b2) || b2;
            _enableGreenhouse = !(enableGreenhouse is bool b3) || b3;
        }
        public RepairTheFencesChore(ChoreData choreData) : base(choreData)
        {
            ChoreData.Config.TryGetValue("EnableFarm", out var enableFarm);
            ChoreData.Config.TryGetValue("EnableBuildings", out var enableBuildings);
            ChoreData.Config.TryGetValue("EnableOutdoors", out var enableOutdoors);

            _enableFarm      = !(enableFarm is bool b1) || b1;
            _enableBuildings = !(enableBuildings is bool b2) || b2;
            _enableOutdoors  = !(enableOutdoors is bool b3) || b3;
        }
Exemple #8
0
        /// <summary>The event called after a save slot is loaded.</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        private void OnSaveLoaded(object sender, SaveLoadedEventArgs e)
        {
            _chores.Clear();

            // create chore instances from content packs
            foreach (var contentPack in Helper.ContentPacks.GetOwned())
            {
                if (!contentPack.HasFile("chore.json"))
                {
                    Monitor.Log($"Missing chores.json from {contentPack.Manifest.UniqueID}. Skipping.", LogLevel.Warn);
                    continue;
                }

                Monitor.Log($"Loading chore.json from {contentPack.Manifest.UniqueID}.");

                var translations = (
                    from translation in contentPack.Translation.GetTranslations()
                    select new TranslationData(translation)).ToList();

                var choreData = new ChoreData(
                    contentPack.Manifest.UniqueID,
                    contentPack.ReadJsonFile <IDictionary <string, object> >("chore.json"),
                    translations,
                    contentPack.HasFile("assets/image.png") ? contentPack.LoadAsset <Texture2D>("assets/image.png") : null);

                var chore = _choreBuilder.GetChore(choreData);
                if (chore == null)
                {
                    Monitor.Log($"Failed to create chore from {contentPack.Manifest.UniqueID}. Skipping.", LogLevel.Warn);
                    continue;
                }

                _chores.Add(contentPack.Manifest.UniqueID, chore);
                Monitor.Log($"Loaded chore {contentPack.Manifest.UniqueID}.", LogLevel.Debug);
            }
        }
 public WaterTheSlimesChore(ChoreData choreData) : base(choreData)
 {
 }
Exemple #10
0
 protected BaseChore(ChoreData choreData)
 {
     ChoreData = choreData;
 }
 /// <summary>Returns an instance of a chore from the first factory that returns a non-null value.</summary>
 /// <param name="choreData">Chore content pack data.</param>
 public IChore GetChore(ChoreData choreData)
 {
     return(_choreFactories.Select(choreFactory => choreFactory.GetChore(choreData))
            .FirstOrDefault(chore => chore != null));
 }