/// <summary> /// Exchange the flag of all parts that match the oldFlag. /// Party where it doesn't match, will not be changed. /// </summary> /// <param name="oldFlag">The old flag name to change</param> /// <param name="newFlag">The new flag name to apply</param> public void FlagExchange(string oldFlag, string newFlag) { if (Flags.All(x => x.ToLower() != oldFlag.ToLower())) { return; } Flags.Clear(); foreach (KmlPart part in Parts) { part.FlagExchange(oldFlag, newFlag); if (!Flags.Contains(part.Flag)) { Flags.Add(part.Flag); } } }
/// <summary> /// Saves the contents of this component to the database /// </summary> /// <param name="uchuContext">The context to save to</param> public async Task SaveAsync(UchuContext context) { var character = await context.Characters .Include(c => c.Flags) .Include(c => c.UnlockedEmotes) .FirstOrDefaultAsync(c => c.Id == GameObject.Id); if (character == default) { return; } character.Currency = Currency; character.UniverseScore = UniverseScore; character.Level = Level; character.BaseHealth = BaseHealth; character.BaseImagination = BaseImagination; character.LastZone = LastZone; character.HairColor = HairColor; character.HairStyle = HairStyle; character.ShirtColor = ShirtColor; character.PantsColor = PantsColor; character.EyebrowStyle = EyebrowStyle; character.EyeStyle = EyeStyle; character.MouthStyle = MouthStyle; character.TotalCurrencyCollected = TotalCurrencyCollected; character.TotalBricksCollected = TotalBricksCollected; character.TotalSmashablesSmashed = TotalSmashablesSmashed; character.TotalQuickBuildsCompleted = TotalQuickBuildsCompleted; character.TotalEnemiesSmashed = TotalEnemiesSmashed; character.TotalRocketsUsed = TotalRocketsUsed; character.TotalMissionsCompleted = TotalMissionsCompleted; character.TotalPetsTamed = TotalPetsTamed; character.TotalImaginationPowerUpsCollected = TotalImaginationPowerUpsCollected; character.TotalLifePowerUpsCollected = TotalLifePowerUpsCollected; character.TotalArmorPowerUpsCollected = TotalArmorPowerUpsCollected; character.TotalDistanceTraveled = TotalDistanceTraveled; character.TotalSuicides = TotalSuicides; character.TotalDamageTaken = TotalDamageTaken; character.TotalDamageHealed = TotalDamageHealed; character.TotalArmorRepaired = TotalArmorRepaired; character.TotalImaginationRestored = TotalImaginationRestored; character.TotalImaginationUsed = TotalImaginationUsed; character.TotalDistanceDriven = TotalDistanceDriven; character.TotalTimeAirborne = TotalTimeAirborne; character.TotalRacingImaginationPowerUpsCollected = TotalRacingImaginationPowerUpsCollected; character.TotalRacingImaginationCratesSmashed = TotalRacingImaginationCratesSmashed; character.TotalRacecarBoostsActivated = TotalRacecarBoostsActivated; character.TotalRacecarWrecks = TotalRacecarWrecks; character.TotalRacingSmashablesSmashed = TotalRacingSmashablesSmashed; character.TotalRacesFinished = TotalRacesFinished; character.TotalFirstPlaceFinishes = TotalFirstPlaceFinishes; character.LastActivity = LastActivity; character.FreeToPlay = FreeToPlay; character.LandingByRocket = LandingByRocket; character.Rocket = Rocket; character.LaunchedRocketFrom = LaunchedRocketFrom; character.InventorySize = InventorySize; character.VaultInventorySize = VaultInventorySize; character.Lh = Lh; character.Rh = Rh; character.Name = Name; character.SpawnLocationName = SpawnLocationName; character.SpawnPositionX = (SpawnPosition == default ? (float?)null : SpawnPosition.X); character.SpawnPositionY = (SpawnPosition == default ? (float?)null : SpawnPosition.Y); character.SpawnPositionZ = (SpawnPosition == default ? (float?)null : SpawnPosition.Z); character.SpawnRotationW = (SpawnRotation == default ? (float?)null : SpawnRotation.W); character.SpawnRotationX = (SpawnRotation == default ? (float?)null : SpawnRotation.X); character.SpawnRotationY = (SpawnRotation == default ? (float?)null : SpawnRotation.Y); character.SpawnRotationZ = (SpawnRotation == default ? (float?)null : SpawnRotation.Z); // Save all newly unlocked emotes foreach (var newlyUnlockedEmoteId in Emotes.Where(emoteId => character.UnlockedEmotes.All(emote => emote.EmoteId != emoteId))) { character.UnlockedEmotes.Add(new UnlockedEmote { EmoteId = newlyUnlockedEmoteId }); } // Save all newly unlocked and removed flags. foreach (var newlyUnlockedFlag in Flags.Where(flagId => character.Flags.All(flag => flag.Flag != flagId))) { character.Flags.Add(new CharacterFlag { Flag = newlyUnlockedFlag }); } foreach (var removedFlag in character.Flags.Where(flag => Flags.All(flagId => flag.Flag != flagId)).ToArray()) { character.Flags.Remove(removedFlag); } Logger.Debug($"Saved character for {GameObject}"); }