private static VillagerData AdaptVillager(VillagerInfo exist, VillagerData replace, bool prepMoveOut = false) { var ov = exist.Villager; var oh = exist.House; var nv = new Villager2(replace.Villager); _ = new VillagerHouse1(replace.House) { NPC1 = oh.NPC1, NPC2 = oh.NPC2, BuildPlayer = oh.BuildPlayer }; // Copy Memories var om = nv.GetMemory(0); var nm = ov.GetMemory(0); nm.PlayerId = om.PlayerId; nv.SetMemory(nm, 0); if (!prepMoveOut) { return(replace); } nv.MovingOut = true; return(replace); }
private void B_ReplaceVillager_Click(object sender, EventArgs e) { if (!Clipboard.ContainsText()) { WinFormsUtil.Error(MessageStrings.MsgVillagerReplaceNoText); return; } var internalName = Clipboard.GetText(); if (!VillagerResources.IsVillagerDataKnown(internalName)) { internalName = GameInfo.Strings.VillagerMap.FirstOrDefault(z => string.Equals(z.Value, internalName, StringComparison.InvariantCultureIgnoreCase)).Key; if (internalName == default) { WinFormsUtil.Error(string.Format(MessageStrings.MsgVillagerReplaceUnknownName, internalName)); return; } } var index = VillagerIndex; var villager = Villagers[index]; if (villager is not Villager2 v2) { WinFormsUtil.Error(MessageStrings.MsgVillagerReplaceOutdatedSaveFormat); return; } var houses = SAV.GetVillagerHouses(); var houseIndex = Array.FindIndex(houses, z => z.NPC1 == index); var exist = new VillagerInfo(v2, houses[houseIndex]); var replace = VillagerSwap.GetReplacementVillager(exist, internalName); var nh = new VillagerHouse1(replace.House); SAV.SetVillagerHouse(nh, houseIndex); var nv = new Villager2(replace.Villager); LoadVillager(Villagers[index] = nv); System.Media.SystemSounds.Asterisk.Play(); }