public static bool Prefix( ref StardewValley.FarmAnimal __instance, ref GameTime time, ref GameLocation location, ref bool __result) { var moddedAnimal = new Decorators.FarmAnimal(__instance); if (!moddedAnimal.HasHome() || moddedAnimal.IsEating() || Game1.IsClient || __instance.controller != null) { return(true); } var moddedLocation = new Location(location); HandleFindGrassToEat(ref moddedAnimal, ref moddedLocation); if (HandleNightTimeRoutine(ref moddedAnimal, ref moddedLocation)) { __result = true; } else { HandleFindProduce(ref moddedAnimal, ref moddedLocation); __result = false; } return(false); }
public static bool RollDeluxeProduceChance(SDV.FarmAnimal animal, double luck, int seed) { if (IsBaby(animal) || !IsProduceAnItem(GetDeluxeProduce(animal))) { return(false); } var random = new System.Random(seed); var happiness = GetHappiness(animal); if (random.NextDouble() >= happiness / 150.0) { return(false); } var num = 0.0; var friendship = GetFriendship(animal); if (happiness > 200) { num = happiness * 1.5; } else if (happiness <= 100) { num = happiness - 100; } if (luck != 0.0) { return(Random.NextDouble() < (friendship + num) / 5000.0 + luck); } return(friendship >= 200 && Random.NextDouble() < (friendship + num) / 1200.0); }
public static Object.Quality RollProduceQuality( SDV.FarmAnimal animal, SDV.Farmer farmer, int seed) { var num = GetFriendship(animal) / 1000.0 - (1.0 - GetHappiness(animal) / 225.0); var flag1 = IsCoopDweller(animal); var flag2 = Farmer.HasProfession(farmer, Farmer.Profession.Shepherd); var flag3 = Farmer.HasProfession(farmer, Farmer.Profession.Butcher); if (!flag1 & flag2 || flag1 & flag3) { num += 0.33; } var random = new System.Random(seed); if (num >= 0.95 && random.NextDouble() < num / 2.0) { return(Object.Quality.Best); } if (random.NextDouble() < num / 2.0) { return(Object.Quality.High); } return(random.NextDouble() < num ? Object.Quality.Medium : Object.Quality.Low); }
public static string SetRandomName(SDV.FarmAnimal animal) { var randomName = Dialogue.GetRandomName(); SetName(animal, randomName); return(randomName); }
public static string GetRandomTypeFromProduce( SDV.FarmAnimal animal, Dictionary <string, List <string> > restrictions) => GetRandomTypeFromProduce(new int[2] { GetDefaultProduce(animal), GetDeluxeProduce(animal) }, restrictions);
public void RemoveAnimal(StardewValley.FarmAnimal animal) { if (!GetOriginal().IsFarm) { return; } Paritee.StardewValley.Core.Locations.Location.RemoveAnimal(GetOriginal() as Farm, animal); }
public static bool SetRandomPositionInHome(SDV.FarmAnimal animal) { if (!HasHome(animal)) { return(false); } animal.setRandomPosition(animal.home.indoors.Value); return(true); }
public static void AddAnimal(SDV.AnimalHouse animalHouse, SDV.FarmAnimal animal) { animalHouse.animals.Add(animal.myID.Value, animal); if (animalHouse.animalsThatLiveHere.Contains(animal.myID.Value)) { return; } animalHouse.animalsThatLiveHere.Add(animal.myID.Value); }
public static bool Prefix(ref StardewValley.FarmAnimal __instance, ref Farmer who) { var moddedAnimal = new Decorators.FarmAnimal(__instance); AttemptToSpawnProduce(ref moddedAnimal, Game.GetMasterPlayer()); if (ShouldStopFindingProduce(ref moddedAnimal)) { moddedAnimal.SetCurrentProduce(-1); } return(false); }
public static int RollProduce( SDV.FarmAnimal animal, int seed, SDV.Farmer farmer = null, double deluxeProduceLuck = 0.0) { var luck = farmer == null ? 0.0 : Farmer.GetDailyLuck(farmer) * deluxeProduceLuck; return(RollDeluxeProduceChance(animal, luck, seed) ? GetDeluxeProduce(animal) : GetDefaultProduce(animal)); }
public static bool ReturnHome(SDV.FarmAnimal animal) { if (!HasHome(animal)) { return(false); } AnimalHouse.AddAnimal(animal.home, animal); SetRandomPositionInHome(animal); SetRandomFacingDirection(animal); animal.controller = null; return(true); }
public static void SetFindHomeDoorPathController(SDV.FarmAnimal animal, SDV.GameLocation location) { if (HasHome(animal)) { return; } animal.controller = new SDV.PathFindController(animal, location, SDV.PathFindController.isAtEndPoint, 0, false, null, 200, new Point(animal.home.tileX.Value + animal.home.animalDoor.X, animal.home.tileY.Value + animal.home.animalDoor.Y)); }
public StardewValley.FarmAnimal AddToAnimalHouse(AnimalHouse animalHouse) { // !!! @WARNING // !!! We have to convert to a base Farm Animal due to exceptions // !!! thrown by the day's save XML functions StardewValley.FarmAnimal BaseFarmAnimal = this.ToFarmAnimal(); animalHouse.animals.Add(BaseFarmAnimal.myID, BaseFarmAnimal); animalHouse.animalsThatLiveHere.Add(BaseFarmAnimal.myID); return(BaseFarmAnimal); }
public static string BuildSpriteAssetName(SDV.FarmAnimal animal) { var isBaby = IsBaby(animal); var isSheared = !isBaby && IsSheared(animal); string assetName; if (!TryBuildSpriteAssetName(GetType(animal), isBaby, isSheared, out assetName)) { assetName = BuildSpriteAssetName(GetDefaultType(IsCoopDweller(animal)), isBaby, isSheared); } return(assetName); }
public static byte GetDaysToLay(SDV.FarmAnimal animal, SDV.Farmer farmer = null) { var num = animal.daysToLay.Value; if (farmer == null) { return(num); } var flag1 = IsType(animal, Sheep); var flag2 = Farmer.HasProfession(farmer, Farmer.Profession.Shepherd); return((byte)Math.Min(byte.MaxValue, Math.Max(0, num + (flag1 & flag2 ? -1 : 0)))); }
public static void Postfix(ref StardewValley.FarmAnimal __instance, ref GameLocation environtment) { if (__instance.pushAccumulator == 1) { __instance.pushAccumulator = 0; } else { __instance.daysToLay.Value = (byte)__instance.pauseTimer; var moddedAnimal = new Decorators.FarmAnimal(__instance); moddedAnimal.SetPauseTimer(0); var hitGlowTimer = (byte)moddedAnimal.GetHitGlowTimer(); moddedAnimal.SetHitGlowTimer(0); HandleCurrentProduce(ref moddedAnimal, hitGlowTimer); } }
public static void AnimateFindingProduce(SDV.FarmAnimal animal) { int frame1; int frame2; switch (animal.FacingDirection) { case 0: frame1 = 9; frame2 = 11; break; case 1: frame1 = 5; frame2 = 7; break; case 2: frame1 = 1; frame2 = 2; break; default: frame1 = 5; frame2 = 7; break; } var frameBehavior = (SDV.AnimatedSprite.endOfAnimationBehavior)Delegate.CreateDelegate( typeof(SDV.AnimatedSprite.endOfAnimationBehavior), animal, Reflection.GetMethod(animal, "findTruffle")); var animation = new List <SDV.FarmerSprite.AnimationFrame> { new SDV.FarmerSprite.AnimationFrame(frame1, 250), new SDV.FarmerSprite.AnimationFrame(frame2, 250), new SDV.FarmerSprite.AnimationFrame(frame1, 250), new SDV.FarmerSprite.AnimationFrame(frame2, 250), new SDV.FarmerSprite.AnimationFrame(frame1, 250), new SDV.FarmerSprite.AnimationFrame(frame2, 250, false, false, frameBehavior) }; animal.Sprite.setCurrentAnimation(animation); animal.Sprite.loop = false; }
public static bool Prefix(ref StardewValley.FarmAnimal __instance, ref GameLocation environtment) { var flag = __instance.home != null && !(__instance.home.indoors.Value as StardewValley.AnimalHouse).animals.ContainsKey( __instance.myID.Value) && environtment is Farm && __instance.home.animalDoorOpen.Value; __instance.pushAccumulator = flag ? 1 : 0; if (flag) { return(true); } __instance.hitGlowTimer = __instance.fullness.Value >= (byte)200 && Game1.timeOfDay >= 1700 || !(environtment is StardewValley.AnimalHouse) || !environtment.objects.Pairs.Where(kvp => kvp.Value.Name == "Hay").Any() ? __instance.fullness.Value : (int)byte.MaxValue; __instance.pauseTimer = __instance.daysToLay.Value; __instance.daysToLay.Value = byte.MaxValue; return(true); }
public static SDV.FarmAnimal CreateFarmAnimal( string type, long ownerId, string name = null, Building home = null, long myId = 0) { if (myId == 0L) { myId = Game.GetNewId(); } var farmAnimal = new SDV.FarmAnimal(type, myId, ownerId) { Name = name, displayName = name, home = home }; var animal = farmAnimal; UpdateFromData(animal, type); return(animal); }
public FarmAnimals.FarmAnimal CreateFromParent(StardewValley.FarmAnimal parent, string name) { string type; // ex. Bulls don't produce anything, but may still exist in the Dairy Cow category if (this.RandomizeNewbornFromCategory) { List <string> types = this.ConsiderTypesFromCategory(new List <string>() { parent.type }, new string[] { parent.defaultProduceIndex.ToString(), parent.deluxeProduceIndex.ToString() }); // Check the count in case someone messed up and removed the parent from the config type = types.Count > 0 ? types.ElementAt(Game1.random.Next(types.Count)) : parent.type; } else { // Don't randomize within the parent's category // This means the baby will always match the parent's type type = parent.type; } return(this.CreateBaby(name, type, (StardewValley.AnimalHouse)parent.home.indoors, parent.myID)); }
public StardewValley.FarmAnimal ToFarmAnimal() { // Create a new resource StardewValley.FarmAnimal BaseFarmAnimal = new StardewValley.FarmAnimal(this.type, this.myID, this.ownerID); // Copy the identification ((NetFieldBase <string, NetString>)BaseFarmAnimal.type).Set(this.type); ((NetFieldBase <long, NetLong>)BaseFarmAnimal.myID).Set(this.myID); ((NetFieldBase <long, NetLong>)BaseFarmAnimal.ownerID).Set(this.ownerID); // Copy the name BaseFarmAnimal.Name = this.Name; BaseFarmAnimal.displayName = this.displayName; // Copy the biology ((NetFieldBase <int, NetInt>)BaseFarmAnimal.health).Set(this.health); ((NetFieldBase <long, NetLong>)BaseFarmAnimal.parentId).Set(this.parentId); // Copy the data ((NetFieldBase <byte, NetByte>)BaseFarmAnimal.daysToLay).Set(this.daysToLay); ((NetFieldBase <byte, NetByte>)BaseFarmAnimal.ageWhenMature).Set(this.ageWhenMature); ((NetFieldBase <int, NetInt>)BaseFarmAnimal.defaultProduceIndex).Set(this.defaultProduceIndex); ((NetFieldBase <int, NetInt>)BaseFarmAnimal.deluxeProduceIndex).Set(this.deluxeProduceIndex); ((NetFieldBase <string, NetString>)BaseFarmAnimal.sound).Set(this.sound); ((NetFieldBase <Rectangle, NetRectangle>)BaseFarmAnimal.frontBackBoundingBox).Set(this.frontBackBoundingBox); ((NetFieldBase <Rectangle, NetRectangle>)BaseFarmAnimal.sidewaysBoundingBox).Set(this.sidewaysBoundingBox); ((NetFieldBase <byte, NetByte>)BaseFarmAnimal.harvestType).Set(this.harvestType); ((NetFieldBase <bool, NetBool>)BaseFarmAnimal.showDifferentTextureWhenReadyForHarvest).Set(this.showDifferentTextureWhenReadyForHarvest); ((NetFieldBase <string, NetString>)BaseFarmAnimal.buildingTypeILiveIn).Set(this.buildingTypeILiveIn); BaseFarmAnimal.Sprite = this.Sprite; ((NetFieldBase <Rectangle, NetRectangle>)BaseFarmAnimal.frontBackSourceRect).Set(this.frontBackSourceRect); ((NetFieldBase <Rectangle, NetRectangle>)BaseFarmAnimal.sidewaysSourceRect).Set(this.sidewaysSourceRect); ((NetFieldBase <byte, NetByte>)BaseFarmAnimal.fullnessDrain).Set(this.fullnessDrain); ((NetFieldBase <byte, NetByte>)BaseFarmAnimal.happinessDrain).Set(this.happinessDrain); ((NetFieldBase <byte, NetByte>)BaseFarmAnimal.happiness).Set(this.happiness); ((NetFieldBase <byte, NetByte>)BaseFarmAnimal.fullness).Set(this.fullness); ((NetFieldBase <string, NetString>)BaseFarmAnimal.toolUsedForHarvest).Set(this.toolUsedForHarvest); ((NetFieldBase <int, NetInt>)BaseFarmAnimal.meatIndex).Set(this.meatIndex); ((NetFieldBase <int, NetInt>)BaseFarmAnimal.price).Set(this.price); // Copy the location information BaseFarmAnimal.home = this.home; BaseFarmAnimal.homeLocation.Set(this.homeLocation); if (this.home != null) { // Reset their position // !!! They will get stuck not moving if this is just copied over BaseFarmAnimal.setRandomPosition(this.home.indoors); } // Copy the misc information ((NetFieldBase <int, NetInt>)BaseFarmAnimal.friendshipTowardFarmer).Set(this.friendshipTowardFarmer); ((NetFieldBase <int, NetInt>)BaseFarmAnimal.daysSinceLastFed).Set(this.daysSinceLastFed); BaseFarmAnimal.uniqueFrameAccumulator = this.uniqueFrameAccumulator; ((NetFieldBase <int, NetInt>)BaseFarmAnimal.age).Set(this.age); ((NetFieldBase <int, NetInt>)BaseFarmAnimal.produceQuality).Set(this.produceQuality); ((NetFieldBase <byte, NetByte>)BaseFarmAnimal.daysSinceLastLay).Set(this.daysSinceLastLay); ((NetFieldBase <bool, NetBool>)BaseFarmAnimal.wasPet).Set(this.wasPet); ((NetFieldBase <bool, NetBool>)BaseFarmAnimal.allowReproduction).Set(this.allowReproduction); ((NetFieldBase <int, NetInt>)BaseFarmAnimal.moodMessage).Set(this.moodMessage); return(BaseFarmAnimal); }
public static int GetMeatIndex(SDV.FarmAnimal animal) => animal.meatIndex.Value;
public static void SetDaysSinceLastLay(SDV.FarmAnimal animal, byte days) => animal.daysSinceLastLay.Value = Math.Max((byte)0, Math.Min(byte.MaxValue, days));
public static string GetDefaultType(SDV.FarmAnimal animal) => GetDefaultType(IsCoopDweller(animal));
public static void Reload(SDV.FarmAnimal animal, Building home) => animal.reload(home);
public static bool IsType(SDV.FarmAnimal animal, string type) => IsType(animal.type.Value, type);
public static bool IsType(SDV.FarmAnimal animal, Livestock type) => IsType(animal, type.ToString());
public static string GetDisplayType(SDV.FarmAnimal animal) => animal.displayType;
public static string GetType(SDV.FarmAnimal animal) => animal.type.Value;
public static void SetType(SDV.FarmAnimal animal, string type) => animal.type.Value = type;