private static void checkAnimal(FarmAnimal animal) { FarmAnimalState state = new FarmAnimalState(animal); if (!animals.ContainsKey(animal.myID)) { animals.Add(animal.myID, state); if (!ignoreUpdates) { Log.trace("Sending animal creation packet"); Multiplayer.sendFunc(new FarmAnimalPacket(animal)); } return; } FarmAnimalState oldState = animals[animal.myID]; if (state.isDifferentEnoughFromOldStateToSend(oldState)) { animals[animal.myID] = state; if (!ignoreUpdates) { Multiplayer.sendFunc(new FarmAnimalUpdatePacket(animal)); } } }
public static void updateAnimal(long id, FarmAnimalState state) { foreach (GameLocation loc in Game1.locations) { if (!(loc is Farm)) { continue; } Farm farm = loc as Farm; foreach (KeyValuePair <long, FarmAnimal> pair in farm.animals) { if (pair.Key == id) { updateAnimal(farm, pair.Value, state); return; } } foreach (Building building in farm.buildings) { AnimalHouse house = building.indoors as AnimalHouse; if (house != null) { foreach (KeyValuePair <long, FarmAnimal> animal in house.animals) { if (animal.Key == id) { updateAnimal(farm, animal.Value, state); return; } } } } } }
private static void updateAnimal(BuildableGameLocation farm, FarmAnimal animal, FarmAnimalState state) {/* * Log.Async("Updating animal " + animal.myID); * Log.Async("Name: " + animal.name + " -> " + state.name); * Log.Async("Reproduction: " + animal.allowReproduction + " -> " + state.reproduce); * Log.Async("Fullness: " + animal.fullness + " -> " + state.fullness); * Log.Async("Product: " + animal.currentProduce + " -> " + state.product); * Log.Async("Petted: " + animal.wasPet + " -> " + state.pet); * Log.Async("Affection: " + animal.friendshipTowardFarmer + " -> " + state.friendship); * Log.Async("Home: (" + animal.homeLocation.X + ", " + animal.homeLocation.Y + ") -> (" + state.homeLoc.X + ", " + state.homeLoc.Y + ")"); */ animal.name = state.name; animal.allowReproduction = state.reproduce; animal.fullness = (byte)state.fullness; animal.currentProduce = state.product; animal.wasPet = state.pet; animal.friendshipTowardFarmer = state.friendship; if (animal.homeLocation.X != state.homeLoc.X && animal.homeLocation.Y != state.homeLoc.Y) { Building buildingAt = null; foreach (Building building in farm.buildings) { if (building.tileX == state.homeLoc.X && building.tileY == state.homeLoc.Y) { buildingAt = building; break; } } if (buildingAt != null) { // From AnimalQueryMenu (animal.home.indoors as AnimalHouse).animalsThatLiveHere.Remove(animal.myID); if ((animal.home.indoors as AnimalHouse).animals.ContainsKey(animal.myID)) { (buildingAt.indoors as AnimalHouse).animals.Add(animal.myID, animal); (animal.home.indoors as AnimalHouse).animals.Remove(animal.myID); } animal.home = buildingAt; animal.homeLocation = state.homeLoc; (buildingAt.indoors as AnimalHouse).animalsThatLiveHere.Add(animal.myID); } } animals[animal.myID] = state; }
public FarmAnimalUpdatePacket(FarmAnimal animal) : this() { id = animal.myID; state = new FarmAnimalState(animal); }