Esempio n. 1
0
 public static void PickFarmEvent_Postfix(ref FarmEvent __result)
 {
     try
     {
         if (__result == null)
         {
             if (Game1.random.NextDouble() < 0.45)
             {
                 __result = new WitchEvent();
             }
         }
     }
     catch (Exception ex)
     {
         HatService.Monitor.Log($"Failed in {nameof(PickFarmEvent_Postfix)}:\n{ex}");
     }
 }
        // Method that is used to postfix WitchEvent
        private static void WitchEvent_setUp_Postfix(WitchEvent __instance, bool __result, Building ___targetBuilding)
        {
            // If the event did not trigger, then no need to do anything
            if (__result)
            {
                return;
            }

            // Add the right witch event conversation topics depending on the witch visit
            try
            {
                // If the witch is visiting a coop, add one of the witch coop conversation topics
                if (___targetBuilding is Coop)
                {
                    // If the witch is a golden witch (post-perfection coop visit), add the golden witch conversation topic
                    if (__instance.goldenWitch)
                    {
                        MCTHelperFunctions.AddOrExtendCT("goldenWitchCoopVisit", Config.WitchVisitDuration);
                    }
                    // Otherwise add the normal witch coop visit conversation topic
                    else
                    {
                        MCTHelperFunctions.AddOrExtendCT("witchCoopVisit", Config.WitchVisitDuration);
                    }
                }
                // Otherwise, if the witch is visiting a Slime Hutch, add the witch slime hut conversation topic
                else if (___targetBuilding.buildingType.Equals("Slime Hutch"))
                {
                    MCTHelperFunctions.AddOrExtendCT("witchSlimeHutVisit", Config.WitchVisitDuration);
                }
            }
            catch (Exception ex)
            {
                Monitor.Log($"Failed to add witch visit conversation topic with exception: {ex}", LogLevel.Error);
            }
        }
Esempio n. 3
0
        public static void Utility_pickFarmEvent_Postfix(ref FarmEvent __result)
        {
            if (!Config.EnableMod)
            {
                return;
            }

            if (__result != null && !(__result is FairyEvent) && !(__result is WitchEvent))
            {
                if (!(__result is SoundInTheNightEvent))
                {
                    return;
                }
                int b = AccessTools.FieldRefAccess <SoundInTheNightEvent, NetInt>(__result as SoundInTheNightEvent, "behavior").Value;
                if (b != 0 && b != 1 && b != 3)
                {
                    return;
                }
            }
            SMonitor.Log("Checking for night event");
            Random r = new Random((int)(Game1.stats.DaysPlayed + (uint)((int)Game1.uniqueIDForThisGame / 2)));

            if (Config.CumulativeChance)
            {
                float  currentWeight = 0;
                double chance        = r.NextDouble();
                if (!Game1.currentSeason.Equals("winter"))
                {
                    currentWeight += Config.FairyChance;
                    if (chance < currentWeight / 100f)
                    {
                        __result = new FairyEvent();
                        SMonitor.Log("Setting fairy event");
                        return;
                    }
                }
                currentWeight += Config.WitchChance;
                if (chance < currentWeight / 100f)
                {
                    __result = new WitchEvent();
                    SMonitor.Log("Setting witch event");
                    return;
                }
                currentWeight += Config.MeteorChance;
                if (chance < currentWeight / 100f)
                {
                    __result = new SoundInTheNightEvent(1);
                    SMonitor.Log("Setting meteor event");
                    return;
                }
                currentWeight += Config.OwlChance;
                if (chance < currentWeight / 100f)
                {
                    __result = new SoundInTheNightEvent(3);
                    SMonitor.Log("Setting owl event");
                    return;
                }
                if (Game1.year > 1 && !Game1.MasterPlayer.mailReceived.Contains("Got_Capsule"))
                {
                    currentWeight += Config.CapsuleChance;
                    if (chance < currentWeight / 100f)
                    {
                        Game1.MasterPlayer.mailReceived.Add("Got_Capsule");
                        __result = new SoundInTheNightEvent(0);
                        SMonitor.Log("Setting capsule event");
                        return;
                    }
                }
            }
            else
            {
                if (r.NextDouble() < Config.FairyChance && !Game1.currentSeason.Equals("winter"))
                {
                    __result = new FairyEvent();
                    SMonitor.Log("Setting fairy event");
                    return;
                }
                if (r.NextDouble() < Config.WitchChance)
                {
                    __result = new WitchEvent();
                    SMonitor.Log("Setting witch event");
                    return;
                }
                if (r.NextDouble() < Config.MeteorChance)
                {
                    __result = new SoundInTheNightEvent(1);
                    SMonitor.Log("Setting meteor event");
                    return;
                }
                if (r.NextDouble() < Config.OwlChance)
                {
                    __result = new SoundInTheNightEvent(3);
                    SMonitor.Log("Setting owl event");
                    return;
                }
                if (r.NextDouble() < Config.CapsuleChance && Game1.year > 1 && !Game1.MasterPlayer.mailReceived.Contains("Got_Capsule"))
                {
                    Game1.MasterPlayer.mailReceived.Add("Got_Capsule");
                    __result = new SoundInTheNightEvent(0);
                    SMonitor.Log("Setting capsule event");
                    return;
                }
            }
            __result = null;
        }
Esempio n. 4
0
        internal void SetUp()
        {
            FailureMessage = $"Could not set tonight's event to {Name}: a condition for this event has not been fulfilled, or another event is taking precedence.";
            Conditions     = new List <KeyValuePair <Func <bool>, string> >();
            AddCondition(() => !Game1.weddingToday, "there's a wedding today");

            switch (Name)
            {
            case "capsule":
                FarmEvent         = new SoundInTheNightEvent(0);
                PersonalFarmEvent = null;
                SuccessMessage    = "A strange capsule event will occur tonight.";
                AddCondition(() => Game1.year > 1,
                             "the game year is 1");
                AddCondition(() => !Game1.MasterPlayer.mailReceived.Contains("Got_Capsule"),
                             "the strange capsule event has happened before");
                break;

            case "meteorite":
                FarmEvent         = new SoundInTheNightEvent(1);
                PersonalFarmEvent = null;
                SuccessMessage    = "A meteorite event will occur tonight.";
                break;

            case "wild_animal_attack":
                FarmEvent         = null;
                PersonalFarmEvent = new SoundInTheNightEvent(2);
                SuccessMessage    = "A wild animal attack event will occur tonight.";
                break;

            case "owl_statue":
                FarmEvent         = new SoundInTheNightEvent(3);
                PersonalFarmEvent = null;
                SuccessMessage    = "An owl statue event will occur tonight.";
                break;

            case "fairy":
                FarmEvent         = new FairyEvent();
                PersonalFarmEvent = null;
                SuccessMessage    = "A crop fairy event will occur tonight.";
                AddCondition(() => !Game1.currentSeason.Equals("winter"), "it's winter");
                break;

            case "witch":
                FarmEvent         = new WitchEvent();
                PersonalFarmEvent = null;
                SuccessMessage    = "A witch event will occur tonight.";
                break;

            case "NPC_child_request":
                FarmEvent         = null;
                PersonalFarmEvent = new QuestionEvent(1);
                SuccessMessage    = "Your NPC spouse will request a child tonight.";
                AddCondition(() => Game1.player.isMarried(),
                             "you are not married");
                AddCondition(() => Game1.player.spouse != null,
                             "you do not have a spouse");
                AddCondition(() => Game1.getCharacterFromName(Game1.player.spouse).canGetPregnant(),
                             "your spouse cannot have children (or is a roommate)");
                AddCondition(() => Game1.player.currentLocation == Game1.getLocationFromName(Game1.player.homeLocation),
                             "you are not at home");
                break;

            case "PC_child_request":
                FarmEvent         = null;
                PersonalFarmEvent = new QuestionEvent(3);
                SuccessMessage    = "You or your PC spouse will request a child tonight.";
                AddCondition(() => Context.IsMultiplayer, "this is a single-player game");
                AddCondition(() => Game1.player.isMarried(), "you are not married");
                AddCondition(() => Game1.player.team.GetSpouse(Game1.player.UniqueMultiplayerID).HasValue,
                             "you are not married to another farmer");
                AddCondition(() => Game1.player.GetSpouseFriendship().NextBirthingDate == null,
                             "you are already going to have a child");
                AddCondition(() => Game1.otherFarmers.ContainsKey(Game1.player.team.GetSpouse(Game1.player.UniqueMultiplayerID).Value),
                             "your spouse is not in the game");
                AddCondition(() => Game1.otherFarmers[Game1.player.team.GetSpouse(Game1.player.UniqueMultiplayerID).Value].currentLocation == Game1.player.currentLocation,
                             "you and your spouse are not in the same location");
                AddCondition(() => Game1.otherFarmers[Game1.player.team.GetSpouse(Game1.player.UniqueMultiplayerID).Value].currentLocation == Game1.getLocationFromName(Game1.otherFarmers[Game1.player.team.GetSpouse(Game1.player.UniqueMultiplayerID).Value].homeLocation) ||
                             Game1.otherFarmers[Game1.player.team.GetSpouse(Game1.player.UniqueMultiplayerID).Value].currentLocation == Game1.getLocationFromName(Game1.player.homeLocation),
                             "you and your spouse are not in either of your houses");
                AddCondition(() => Helper.Reflection.GetMethod(typeof(Utility), "playersCanGetPregnantHere").Invoke <bool>(Game1.otherFarmers[Game1.player.team.GetSpouse(Game1.player.UniqueMultiplayerID).Value].currentLocation as FarmHouse),
                             "you don't have a crib, your crib is already occupied, or you already have 2 children");
                break;

            case "animal_birth":
                FarmEvent         = null;
                PersonalFarmEvent = new QuestionEvent(2);
                SuccessMessage    = "An animal birth event will occur tonight.";
                break;

            case "giant_crop":
                if (tile == null)
                {
                    break;
                }

                // players can only specify a crop ID when conditions aren't being enforced
                if (id > -1)
                {
                    giantCrop = new GiantCrop(id, new Vector2((int)tile.X - 1, (int)tile.Y - 1));
                    giantCrop.modData.Add(ModEntry.mod.ModManifest.UniqueID, SDate.Now().ToString());
                    break;
                }

                // weddings don't prevent giant crops from spawning
                Conditions.Clear();

                // first check whether there's actually a crop there; this will be a hard condition regardless of config
                AddCondition(() => location.terrainFeatures.ContainsKey(tile) && location.terrainFeatures[tile] is HoeDirt,
                             $"there is no hoe dirt at ({(int)tile.X}, {(int)tile.Y})");
                AddCondition(() => (location.terrainFeatures[tile] as HoeDirt).crop != null,
                             $"there is no crop at ({(int)tile.X}, {(int)tile.Y})");
                if (!EnforceEventConditions(out string message))
                {
                    Monitor.Log($"Could not set giant crop spawn for tonight because {message}.", LogLevel.Info);
                    break;
                }

                SuccessMessage = $"A giant crop will spawn at ({(int)tile.X}, {(int)tile.Y}) tonight.";

                giantCrop = new GiantCrop((location.terrainFeatures[tile] as HoeDirt).crop.indexOfHarvest, new Vector2((int)tile.X - 1, (int)tile.Y - 1));
                giantCrop.modData.Add(ModEntry.mod.ModManifest.UniqueID, SDate.Now().ToString());

                if (!Helper.ModRegistry.IsLoaded("spacechase0.moregiantcrops") && !Helper.ModRegistry.IsLoaded("spacechase0.jsonassets"))
                {
                    AddCondition(() => (location.terrainFeatures[tile] as HoeDirt).crop.indexOfHarvest == 276 ||
                                 (location.terrainFeatures[tile] as HoeDirt).crop.indexOfHarvest == 190 ||
                                 (location.terrainFeatures[tile] as HoeDirt).crop.indexOfHarvest == 254,
                                 "this type of crop cannot be giant");
                }
                AddCondition(() => location is Farm,
                             "you are not in a farm location");
                AddCondition(() => (location.terrainFeatures[tile] as HoeDirt).state.Value == 1,
                             $"the crop at ({(int)tile.X}, {(int)tile.Y}) is not watered");
                AddCondition(() => (int)(location.terrainFeatures[tile] as HoeDirt).crop.currentPhase == (location.terrainFeatures[tile] as HoeDirt).crop.phaseDays.Count - 1,
                             $"the crop at ({(int)tile.X}, {(int)tile.Y}) is not fully grown");
                AddCondition(() => CheckGiantCropSquareForCrops(),
                             $"the crop at ({(int)tile.X}, {(int)tile.Y}) is not at the center of a 3x3 square of crops of the same type");
                AddCondition(() => CheckGiantCropSquareForCharacters(),
                             $"there is a character in the way");
                break;

            default:
                break;
            }
        }