/// <summary>Get the fields to display for the trash bear.</summary> /// <param name="trashBear">The trash bear for which to show info.</param> /// <remarks>Derived from <see cref="TrashBear.checkAction"/>.</remarks> private IEnumerable <ICustomField> GetDataForTrashBear(TrashBear trashBear) { // get number of quests completed const int maxQuests = 4; int questsDone = 0; if (NetWorldState.checkAnywhereForWorldStateID("trashBear1")) { questsDone = 1; } if (NetWorldState.checkAnywhereForWorldStateID("trashBear2")) { questsDone = 2; } if (NetWorldState.checkAnywhereForWorldStateID("trashBear3")) { questsDone = 3; } if (NetWorldState.checkAnywhereForWorldStateID("trashBearDone")) { questsDone = 4; } // show item wanted if (questsDone < maxQuests) { this.Reflection.GetMethod(trashBear, "updateItemWanted").Invoke(); int itemWantedIndex = this.Reflection.GetField <int>(trashBear, "itemWantedIndex").GetValue(); yield return(new ItemIconField(this.GameHelper, L10n.TrashBear.ItemWanted(), new SObject(itemWantedIndex, 1))); } // show progress yield return(new GenericField(this.GameHelper, L10n.TrashBear.QuestProgress(), L10n.Generic.Ratio(questsDone, maxQuests))); }
private void updateItemWanted() { int which = 0; if (NetWorldState.checkAnywhereForWorldStateID("trashBear1")) { which = 1; } if (NetWorldState.checkAnywhereForWorldStateID("trashBear2")) { which = 2; } if (NetWorldState.checkAnywhereForWorldStateID("trashBear3")) { which = 3; } int randomSeed = 777111 + which; itemWantedIndex = Utility.getRandomPureSeasonalItem(Game1.currentSeason, randomSeed); if (which > 1) { int position = new Random((int)Game1.uniqueIDForThisGame + randomSeed).Next(CraftingRecipe.cookingRecipes.Count); int counter = 0; foreach (string v in CraftingRecipe.cookingRecipes.Values) { if (counter == position) { string craft_result2 = v.Split('/')[2]; craft_result2 = craft_result2.Split(' ')[0]; itemWantedIndex = Convert.ToInt32(craft_result2); break; } counter++; } } }
public override void tryToReceiveActiveObject(Farmer who) { updateItemWanted(); if (who.ActiveObject != null && !who.ActiveObject.bigCraftable && who.ActiveObject.ParentSheetIndex == itemWantedIndex) { Game1.currentLocation.playSound("coin"); if (NetWorldState.checkAnywhereForWorldStateID("trashBear3")) { NetWorldState.addWorldStateIDEverywhere("trashBearDone"); } else if (NetWorldState.checkAnywhereForWorldStateID("trashBear2")) { NetWorldState.addWorldStateIDEverywhere("trashBear3"); } else if (NetWorldState.checkAnywhereForWorldStateID("trashBear1")) { NetWorldState.addWorldStateIDEverywhere("trashBear2"); } else { NetWorldState.addWorldStateIDEverywhere("trashBear1"); } eatEvent.Fire(itemWantedIndex); who.reduceActiveItemByOne(); } }
private void doneAnimating(Farmer who) { sprite.Value.CurrentFrame = 8; if (NetWorldState.checkAnywhereForWorldStateID("trashBearDone") && Game1.currentLocation is Forest) { doCutsceneEvent(); } }
protected override void resetLocalState() { base.resetLocalState(); addFrog(); if (Game1.year > 2 && getCharacterFromName("TrashBear") != null && NetWorldState.checkAnywhereForWorldStateID("trashBearDone")) { characters.Remove(getCharacterFromName("TrashBear")); } }
public override void MakeMapModifications(bool force = false) { base.MakeMapModifications(force); if (force) { hasShownCCUpgrade = false; } if (NetWorldState.checkAnywhereForWorldStateID("trashBearDone")) { removeSewerTrash(); } if (Game1.MasterPlayer.mailReceived.Contains("communityUpgradeShortcuts")) { showCommunityUpgradeShortcuts(); } }
public override void MakeMapModifications(bool force = false) { base.MakeMapModifications(force); if (force) { hasShownCCUpgrade = false; } if ((bool)(Game1.getLocationFromName("Beach") as Beach).bridgeFixed || NetWorldState.checkAnywhereForWorldStateID("beachBridgeFixed")) { Beach.fixBridge(this); } if (Game1.MasterPlayer.mailReceived.Contains("communityUpgradeShortcuts")) { Beach.showCommunityUpgradeShortcuts(this, ref hasShownCCUpgrade); } }
protected override void resetLocalState() { base.resetLocalState(); addFrog(); if (Game1.year > 2 && getCharacterFromName("TrashBear") != null && NetWorldState.checkAnywhereForWorldStateID("trashBearDone")) { characters.Remove(getCharacterFromName("TrashBear")); } if (NetWorldState.checkAnywhereForWorldStateID("trashBearDone")) { removeSewerTrash(); } if (Game1.MasterPlayer.mailReceived.Contains("communityUpgradeShortcuts")) { showCommunityUpgradeShortcuts(); } }
public static void fixBridge(GameLocation location) { if (!NetWorldState.checkAnywhereForWorldStateID("beachBridgeFixed")) { NetWorldState.addWorldStateIDEverywhere("beachBridgeFixed"); } location.updateMap(); int whichTileSheet = ((!location.name.Value.Contains("Market")) ? 1 : 2); location.setMapTile(58, 13, 301, "Buildings", null, whichTileSheet); location.setMapTile(59, 13, 301, "Buildings", null, whichTileSheet); location.setMapTile(60, 13, 301, "Buildings", null, whichTileSheet); location.setMapTile(61, 13, 301, "Buildings", null, whichTileSheet); location.setMapTile(58, 14, 336, "Back", null, whichTileSheet); location.setMapTile(59, 14, 336, "Back", null, whichTileSheet); location.setMapTile(60, 14, 336, "Back", null, whichTileSheet); location.setMapTile(61, 14, 336, "Back", null, whichTileSheet); }
internal static bool updateItemWanted(TrashBear __instance) { int num1 = 0; if (NetWorldState.checkAnywhereForWorldStateID("trashBear1")) { num1 = 1; } if (NetWorldState.checkAnywhereForWorldStateID("trashBear2")) { num1 = 2; } if (NetWorldState.checkAnywhereForWorldStateID("trashBear3")) { num1 = 3; } int randomSeedAddition = 777111 + num1; var itemWantedIndex = DataLoader.Helper.Reflection.GetField <int>(__instance, "itemWantedIndex"); itemWantedIndex.SetValue(Utility.getRandomPureSeasonalItem(Game1.currentSeason, randomSeedAddition)); if (num1 <= 1) { return(false); } int num2 = new Random((int)Game1.uniqueIDForThisGame + randomSeedAddition).Next(CraftingRecipe.cookingRecipes.Count); int num3 = 0; foreach (string str in CraftingRecipe.cookingRecipes.Values) { if (num3 == num2) { itemWantedIndex.SetValue(Convert.ToInt32(str.Split('/')[2].Split(' ')[0])); break; } ++num3; } return(false); }
protected override void resetLocalState() { base.resetLocalState(); if ((bool)(Game1.getLocationFromName("Beach") as Beach).bridgeFixed || NetWorldState.checkAnywhereForWorldStateID("beachBridgeFixed")) { Beach.fixBridge(this); } if (Game1.timeOfDay >= 1700) { Game1.changeMusicTrack("night_market"); } else { Game1.changeMusicTrack("ocean"); } shopClosedTexture = Game1.temporaryContent.Load <Texture2D>("LooseSprites\\temporary_sprites_1"); temporarySprites.Add(new EmilysParrot(new Vector2(2968f, 2056f))); paintingMailKey = "NightMarketYear" + Game1.year + "Day" + getDayOfNightMarket() + "_paintingSold"; if (Game1.MasterPlayer.mailReceived.Contains("communityUpgradeShortcuts")) { Beach.showCommunityUpgradeShortcuts(this, ref hasShownCCUpgrade); } }
private Dictionary <int, SchedulePathDescription> MasterScheduleParse(string scheduleString) { NPC companion = this.StateMachine.Companion; int timeOfDay = Game1.timeOfDay; string[] split = scheduleString.Split(new char[] { '/' }); Dictionary <int, SchedulePathDescription> oneDaySchedule = new Dictionary <int, SchedulePathDescription>(); Type[] pathfinderTypes = new Type[] { typeof(string), typeof(int), typeof(int), typeof(string), typeof(int), typeof(int), typeof(int), typeof(string), typeof(string) }; MethodInfo pathfinder = typeof(NPC).GetMethod("pathfindToNextScheduleLocation", BindingFlags.NonPublic | BindingFlags.Instance, null, pathfinderTypes, null); int routesToSkip = 0; int previousTime = 0; if (split[0].Contains("GOTO")) { string newKey = split[0].Split(new char[] { ' ' })[1]; if (newKey.ToLower().Equals("season")) { newKey = Game1.currentSeason; } try { split = Game1.content.Load <Dictionary <string, string> >("Characters\\schedules\\" + companion.Name) [newKey].Split(new char[] { '/' }); } catch (Exception) { return(this.MasterScheduleParse( Game1.content.Load <Dictionary <string, string> >("Characters\\schedules\\" + companion.Name)[ "spring"])); } } if (split[0].Contains("NOT")) { string[] commandSplit = split[0].Split(new char[] { ' ' }); string a = commandSplit[1].ToLower(); if (a == "friendship") { string who = commandSplit[2]; int level = Convert.ToInt32(commandSplit[3]); bool conditionMet = false; using (IEnumerator <Farmer> enumerator = Game1.getAllFarmers().GetEnumerator()) { while (enumerator.MoveNext()) { if (enumerator.Current.getFriendshipLevelForNPC(who) >= level) { conditionMet = true; break; } } } if (conditionMet) { return(this.MasterScheduleParse(Game1.content.Load <Dictionary <string, string> >("Characters\\schedules\\" + companion.Name)["spring"])); } routesToSkip++; } } else if (split[0].Contains("MAIL")) { string id = split[0].Split(' ')[1]; if (Game1.MasterPlayer.mailReceived.Contains(id) || NetWorldState.checkAnywhereForWorldStateID(id)) { routesToSkip += 2; } else { routesToSkip++; } } if (split[routesToSkip].Contains("GOTO")) { string newKey2 = split[routesToSkip].Split(new char[] { ' ' })[1]; if (newKey2.ToLower().Equals("season")) { newKey2 = Game1.currentSeason; } return(this.MasterScheduleParse(Game1.content.Load <Dictionary <string, string> >("Characters\\schedules\\" + companion.Name)[newKey2])); } Point previousPosition = companion.isMarried() ? new Point(0, 23) : new Point((int)companion.DefaultPosition.X / 64, (int)companion.DefaultPosition.Y / 64); string previousGameLocation = companion.isMarried() ? "BusStop" : companion.DefaultMap; int i = routesToSkip; while (i < split.Length && split.Length > 1) { int index = 0; string[] newDestinationDescription = split[i].Split(new char[] { ' ' }); int time = Convert.ToInt32(newDestinationDescription[index]); index++; string location = newDestinationDescription[index]; string endOfRouteAnimation = null; string endOfRouteMessage = null; if (int.TryParse(location, out int tmp)) { location = previousGameLocation; index--; } index++; int xLocation = Convert.ToInt32(newDestinationDescription[index]); index++; int yLocation = Convert.ToInt32(newDestinationDescription[index]); index++; int localFacingDirection = 2; try { localFacingDirection = Convert.ToInt32(newDestinationDescription[index]); index++; } catch (Exception) { localFacingDirection = 2; } if (this.changeScheduleForLocationAccessibility(ref location, ref xLocation, ref yLocation, ref localFacingDirection)) { if (Game1.content.Load <Dictionary <string, string> >("Characters\\schedules\\" + companion.Name).ContainsKey("default")) { return(this.MasterScheduleParse(Game1.content.Load <Dictionary <string, string> >("Characters\\schedules\\" + companion.Name)["default"])); } return(this.MasterScheduleParse(Game1.content.Load <Dictionary <string, string> >("Characters\\schedules\\" + companion.Name)["spring"])); } else { if (index < newDestinationDescription.Length) { if (newDestinationDescription[index].Length > 0 && newDestinationDescription[index][0] == '"') { endOfRouteMessage = split[i].Substring(split[i].IndexOf('"')).Replace("\"", ""); } else { endOfRouteAnimation = newDestinationDescription[index]; index++; if (index < newDestinationDescription.Length && newDestinationDescription[index].Length > 0 && newDestinationDescription[index][0] == '"') { endOfRouteMessage = split[i].Substring(split[i].IndexOf('"')).Replace("\"", ""); } } } object[] parameters = new object[] { previousGameLocation, previousPosition.X, previousPosition.Y, location, xLocation, yLocation, localFacingDirection, endOfRouteAnimation, endOfRouteMessage }; SchedulePathDescription schedulePathDesc = (SchedulePathDescription)pathfinder.Invoke(companion, parameters); oneDaySchedule.Add(time, schedulePathDesc); previousPosition.X = xLocation; previousPosition.Y = yLocation; if (timeOfDay >= time && schedulePathDesc.route != null && schedulePathDesc.route.Count != 0) { Stack <Point> sp = oneDaySchedule[time].route; Point p = new Point(); while (sp.Count > 1) { sp.Pop(); } while (sp.Count != 0) { p = sp.Pop(); } if (previousTime < time) { this.companionRescheduleDestinationPoint = p; this.companionRescheduleDestinationLocation = location; this.companionRescheduleEndRouteBehavior = endOfRouteAnimation; this.companionRescheduleEndRouteDialogue = endOfRouteMessage; this.companionRescheduleFacingDirection = localFacingDirection; } } previousTime = time; previousGameLocation = location; i++; } } return(oneDaySchedule); }
protected override void resetSharedState() { base.resetSharedState(); if (Game1.year > 2 && !Game1.isRaining && !Utility.isFestivalDay(Game1.dayOfMonth, Game1.currentSeason) && getCharacterFromName("TrashBear") == null && !NetWorldState.checkAnywhereForWorldStateID("trashBearDone")) { characters.Add(new TrashBear()); } }
public static bool Prefix(NPC __instance, ref Dictionary <int, SchedulePathDescription> __result, string rawData, List <List <string> > ___routesFromLocationToLocation) { if (!ModEntry.IsChildNPC(__instance)) { return(true); } string[] events = rawData.Split('/'); int index = 0; Dictionary <int, SchedulePathDescription> dictionary = new Dictionary <int, SchedulePathDescription>(); Dictionary <string, string> scheduleFromName = null; try { scheduleFromName = Game1.content.Load <Dictionary <string, string> >("Characters\\schedules\\" + __instance.Name); } catch (Exception e) { ModEntry.monitor.Log("An error occurred in ParseMasterSchedule while trying to load the schedule for " + __instance.Name + ": " + e.Message); return(true); } //Example: "GOTO Tue" or "GOTO spring" says which entry to use //This replaces the rawData with whatever entry the GOTO requested if (events[0].Contains("GOTO")) { string whereToGo = events[0].Split(' ')[1]; if (whereToGo.ToLower().Equals("season")) { whereToGo = Game1.currentSeason; } try { events = scheduleFromName[whereToGo].Split('/'); } catch (Exception) { __result = ModEntry.helper.Reflection.GetMethod(__instance, "parseMasterSchedule", true).Invoke <Dictionary <int, SchedulePathDescription> >(new object[] { scheduleFromName["spring"] }); return(false); } } //Example: "NOT friendship Sam 6/" as first entry //Tells you to skip this entry if the friendship isn't set if (events[0].Contains("NOT")) { string[] friendshipData = events[0].Split(' '); if (friendshipData[1].ToLower() == "friendship") { string name = friendshipData[2]; int hearts = Convert.ToInt32(friendshipData[3]); bool farmerHasHearts = false; foreach (Farmer allFarmer in Game1.getAllFarmers()) { if (allFarmer.getFriendshipLevelForNPC(name) >= hearts) { farmerHasHearts = true; break; } } if (!farmerHasHearts) { __result = ModEntry.helper.Reflection.GetMethod(__instance, "parseMasterSchedule", true).Invoke <Dictionary <int, SchedulePathDescription> >(new object[] { scheduleFromName["spring"] }); return(false); } //Otherwise, increment index by 1, continue with schedule ++index; } } //Added in the 1.4 update, I haven't checked this dialogue yet else if (events[0].Contains("MAIL")) { string id = events[0].Split(' ')[1]; if (Game1.MasterPlayer.mailReceived.Contains(id) || NetWorldState.checkAnywhereForWorldStateID(id)) { index += 2; } else { ++index; } } //For the case of "NOT friendship Sam 6/GOTO 9" (I think) //Handles the GOTO if friendship change happened if (events[index].Contains("GOTO")) { string whereToGo = events[index].Split(' ')[1]; if (whereToGo.ToLower().Equals("season")) { whereToGo = Game1.currentSeason; } else if (whereToGo.ToLower().Equals("no_schedule")) { __instance.followSchedule = false; __result = null; return(false); } events = scheduleFromName[whereToGo].Split('/'); index = 1; } //Point point = this.isMarried() ? new Point(0, 23) : new Point((int)this.defaultPosition.X / 64, (int)this.defaultPosition.Y / 64); //string startingLocation = this.isMarried() ? "BusStop" : (string)((NetFieldBase<string, NetString>)this.defaultMap); Point point = new Point(0, 23); string startingLocation = "BusStop"; //Go through each of the events, parse them. for (int i = index; i < events.Length /* && events.Length > 1*/; ++i) { string[] currentEvent = events[i].Split(' '); int time = Convert.ToInt32(currentEvent[0]); string locationName = currentEvent[1]; string endBehavior = null; string endMessage = null; //If there is no location name, skips straight to position if (int.TryParse(locationName, out int result)) { locationName = startingLocation; } int positionX = Convert.ToInt32(currentEvent[2]); int positionY = Convert.ToInt32(currentEvent[3]); int endIndex = 4; int facingDirection; try { facingDirection = Convert.ToInt32(currentEvent[4]); ++endIndex; } catch (Exception) { facingDirection = 2; } object[] param = { locationName, positionX, positionY, facingDirection }; bool accessibleChange = ModEntry.helper.Reflection.GetMethod(__instance, "changeScheduleForLocationAccessibility", true).Invoke <bool>(param); if (accessibleChange) { if (scheduleFromName.ContainsKey("default")) { __result = ModEntry.helper.Reflection.GetMethod(__instance, "parseMasterSchedule", true).Invoke <Dictionary <int, SchedulePathDescription> >(new object[] { scheduleFromName["default"] }); return(false); } __result = ModEntry.helper.Reflection.GetMethod(__instance, "parseMasterSchedule", true).Invoke <Dictionary <int, SchedulePathDescription> >(new object[] { scheduleFromName["spring"] }); return(false); } //830 ArchaeologyHouse 17 9 2 penny_read \"Strings\\schedules\\Penny:marriageJob.000\" if (currentEvent.Length > endIndex) { if (currentEvent[endIndex].Length > 0 && currentEvent[endIndex][0] == '"') { endMessage = events[i].Substring(events[i].IndexOf('"')); } else { endBehavior = currentEvent[endIndex]; if (endIndex + 1 < currentEvent.Length && currentEvent[endIndex + 1].Length > 0 && currentEvent[endIndex + 1][0] == '"') { endMessage = events[i].Substring(events[i].IndexOf('"')).Replace("\"", ""); } } } //Add this time event to the dictionary dictionary.Add(time, ModEntry.helper.Reflection.GetMethod(__instance, "pathfindToNextScheduleLocation", true).Invoke <SchedulePathDescription>(new object[] { startingLocation, point.X, point.Y, locationName, positionX, positionY, facingDirection, endBehavior, endMessage })); //Then pretend this character has completed that appt, check next appt point.X = positionX; point.Y = positionY; startingLocation = locationName; } __result = dictionary; return(false); }