public bool RetrieveAccountVault(out VaultView vaultView, out string message, out HttpStatusCode code) { message = ErrorCode.CONNECTION_FAILED; vaultView = null; Api().CreateAuthenticated("api/account/vault", "get") .Execute(out HttpWebResponse response); if (response.TryGetStatusCode(out code) && code == HttpStatusCode.OK) { ValidatedView <VaultView> validatedView = response.GetReponseString() .DeserializeJsonSafe <ValidatedView <VaultView> >(); if (validatedView == null) { message = ErrorCode.ERROR_WHILE_READING_RESULT; } else { vaultView = validatedView.Object; message = validatedView.Message; return(validatedView.IsValid); } } return(false); }
protected internal void Equipment(Ship ship) { if (!EquipmentDashboardVisible) { Loading = true; Selected = ship; StateHasChanged(); if (!HangarService.RetrieveHangarDetailView(ship.ID, out HangarDetailView hangarDetailView, out string message)) { NotificationService.ShowError(message, "Failed to load equipment!"); } else { if (!AccountService.RetrieveAccountVault(out VaultView vaultView, out message, out _)) { NotificationService.ShowError(message, "Failed to load vault!"); } else { Hangar = hangarDetailView; Vault = vaultView; EquipmentDashboardVisible = true; } } Loading = false; StateHasChanged(); }
private void CheckShip(IGameLogger logger, int accountId, VaultView vault, Ship ship) { // check ship if (!vault.Ships.Contains(ship.ID)) { throw logger.LogError(new Exception($"Check for player {accountId} on hangar with ship {ship.ID} resulted in a assigned ship which is not even owned!")); } // check amount of items packed into the ship if (Weapons.Count > ship.WeaponSlots) { Weapons = Weapons.Take(ship.WeaponSlots).ToList(); } if (Generators.Count + Shields.Count > ship.GeneratorSlots) { int diff = Math.Abs((Generators.Count + Shields.Count) - ship.GeneratorSlots); int generatorsToRemove = Math.Min(diff, Generators.Count); int shieldsToRemove = Math.Min(diff - generatorsToRemove, Shields.Count); Generators = Generators.Take(Generators.Count - generatorsToRemove).ToList(); Shields = Shields.Take(Shields.Count - shieldsToRemove).ToList(); if (diff != 0) { logger.LogWarning($"Check for player {accountId} on hangar with ship {ship.ID} resulted with a problematic difference of {diff}"); } } }
private void CheckAvailableGenerators(IGameLogger logger, int accountId, VaultView vault, Ship ship) { if (Generators == null) { Generators = new List <int>(); } var tempGeneratorsGroup = Generators.GroupBy(x => x).ToList(); foreach (var grouping in tempGeneratorsGroup) { if (!vault.Generators.ContainsKey(grouping.Key)) { logger.LogWarning($"Check for player {accountId} on hangar with ship {ship.ID} resulted with equipped generators id:{grouping.Key} which are not owned!"); Generators.RemoveAll(x => x == grouping.Key); } else if (grouping.Count() > vault.Generators[grouping.Key]) { int diff = grouping.Count() - vault.Generators[grouping.Key]; Generators.RemoveAll(x => x == grouping.Key && diff-- > 0); if (diff != 0) { logger.LogWarning($"Check for player {accountId} on hangar with ship {ship.ID} resulted with a problematic difference of {diff} (generator check)"); } } } }
public void Check(IGameLogger logger, int accountId, VaultView vault, Ship ship) { CheckShip(logger, accountId, vault, ship); CheckDrones(logger, accountId, vault, ship); CheckAvailableWeapons(logger, accountId, vault, ship); CheckAvailableShields(logger, accountId, vault, ship); CheckAvailableGenerators(logger, accountId, vault, ship); }
public static async Task <ValidatedView> UpdateVault(int accountId, VaultView vault) { try { ReplaceOneResult result = await Model <AccountVaultModel> .AsCollection() .ReplaceOneAsync(x => x.AccountID == accountId, Mapper <VaultView> .Map(vault, new AccountVaultModel { AccountID = accountId })); if (result.IsModifiedCountAvailable && result.ModifiedCount == 1) { return(ValidatedView.Valid()); } } catch (Exception e) { GameContext.Logger.LogError(e); } return(ValidatedView.Invalid(ErrorCode.OPERATION_FAILED)); }
public VaultViewModel(VaultView view) { _view = view; _autoLockTimer = new System.Timers.Timer(1000); _autoLockTimer.Elapsed += _autoLockTimer_Elapsed; _searchRefresh = new System.Timers.Timer(1000); _searchRefresh.Elapsed += _searchRefresh_Elapsed; _duplicateCredentialCommand = new Command(new Action <Object>(DuplicateCredentialCommandAction)); _editCredentialCommand = new Command(new Action <Object>(EditCredentialCommandAction)); _removeCredentialCommand = new Command(new Action <Object>(RemoveCredentialCommandAction)); _credentialSelectedCommand = new Command(new Action <Object>(CredentialSelectedCommandAction)); _viewCredentialAuditLogCommand = new Command(new Action <Object>(ViewCredentialAuditLogCommandAction)); _searchTextChangedCommand = new Command(new Action <Object>(SearchTextChangedCommandAction)); _searchCompletedCommand = new Command(new Action <Object>(SearchCompletedCommandAction)); _clipboardFieldCopyCommand = new Command(new Action <Object>(ClipboardFieldCopyCommandAction)); _clipboardFieldRevealCommand = new Command(new Action <Object>(ClipboardFieldRevealCommandAction)); _openInBrowserCommand = new Command(new Action <Object>(OpenInBrowserCommandAction)); _closeCredentialListTipCommand = new Command(new Action <Object>(CloseCredentialListTipCommandAction)); }
private void CheckAvailableShields(IGameLogger logger, int accountId, VaultView vault, Ship ship) { if (Shields == null) { Shields = new List <int>(); } var tempShieldsGroup = Shields.Union(Drones.SelectMany(x => x.ShieldItems)).GroupBy(x => x).ToList(); foreach (var grouping in tempShieldsGroup) { if (!vault.Shields.ContainsKey(grouping.Key)) { logger.LogWarning($"Check for player {accountId} on hangar with ship {ship.ID} resulted with equipped shields id:{grouping.Key} which are not owned!"); Shields.RemoveAll(x => x == grouping.Key); } else if (grouping.Count() > vault.Shields[grouping.Key]) { int diff = grouping.Count() - vault.Shields[grouping.Key]; Shields.RemoveAll(x => x == grouping.Key && diff-- > 0); foreach (var drone in Drones) { if (diff <= 0) { break; } drone.ShieldItems.RemoveAll(x => x == grouping.Key && diff-- > 0); } if (diff != 0) { logger.LogWarning($"Check for player {accountId} on hangar with ship {ship.ID} resulted with a problematic difference of {diff} (shield check)"); } } } }
public bool RetrieveAccountVault(out VaultView vaultView, out string message) { return(RetrieveAccountVault(out vaultView, out message, out _)); }
private void CheckDrones(IGameLogger logger, int accountId, VaultView vault, Ship ship) { if (Drones == null) { Drones = new List <DroneView>(); } // check drones, items and upgrades List <DroneView> tempDrones = Drones.ToList(); foreach (var dronePair in Drones) { int newDroneId = vault.Drones[dronePair.Position]; if (!vault.Drones.ContainsKey(dronePair.Position)) { logger.LogInformation($"Check for player {accountId} on hangar with ship {ship.ID} resulted with a drone [Position: {dronePair.Position}, ID: {dronePair.DroneID}] equipped which is not even owned!"); tempDrones.RemoveAll(x => x.Position == dronePair.Position); } else if (newDroneId != dronePair.DroneID) { int index = tempDrones.FindIndex(x => x.Position == dronePair.Position); if ((dronePair.DroneID / 10) == (newDroneId / 10)) // check same class, if true -> Drone lvl changed! { tempDrones[index] = new DroneView(newDroneId, dronePair.StatsDesignID, dronePair.VisualDesignID, dronePair.Position, dronePair.WeaponItems, dronePair.ShieldItems); } else { if (ItemsExtension <Drone> .Lookup(newDroneId).Slots < ItemsExtension <Drone> .Lookup(dronePair.DroneID).Slots) { int diff = Math.Abs(dronePair.ShieldItems.Count + dronePair.WeaponItems.Count - ItemsExtension <Drone> .Lookup(newDroneId).Slots); int weaponsToRemove = Math.Min(diff, dronePair.WeaponItems.Count); int shieldsToRemove = Math.Min(diff - weaponsToRemove, dronePair.ShieldItems.Count); tempDrones[index] = new DroneView(newDroneId, dronePair.StatsDesignID, dronePair.VisualDesignID, dronePair.Position, dronePair.WeaponItems.Take(dronePair.WeaponItems.Count - weaponsToRemove).ToList(), dronePair.ShieldItems.Take(dronePair.ShieldItems.Count - shieldsToRemove).ToList()); } else { tempDrones[index] = new DroneView(newDroneId, dronePair.StatsDesignID, dronePair.VisualDesignID, dronePair.Position, dronePair.WeaponItems, dronePair.ShieldItems); } } } } // add new drones, which are not present in the hangar if (tempDrones.Count < vault.Drones.Count) { foreach (var drone in vault.Drones) { int count = tempDrones.Count(x => x.Position == drone.Key); if (count > 1) // saftiges problem { logger.LogWarning($"Check for player {accountId} on hangar with ship {ship.ID} resulted with multiple drones at the same position {drone.Key}!"); } if (count <= 0) { tempDrones.Add(new DroneView(drone.Value, DroneDesign.NONE.ID, 0, drone.Key, new List <int>(), new List <int>())); } } } // Check designs foreach (var design in tempDrones.GroupBy(x => x.StatsDesignID)) { if (design.Key != 0 && (!vault.DroneDesigns.TryGetValue(design.Key, out int count) || count < design.Count())) { int toRemove = design.Count() - count; for (int i = 0; i < tempDrones.Count; i++) { if (tempDrones[i].StatsDesignID == design.Key) { if (toRemove-- == 0) { break; } var tempDrone = tempDrones[i]; tempDrones[i] = new DroneView(tempDrone.DroneID, DroneDesign.NONE.ID, tempDrone.VisualDesignID, tempDrone.Position, tempDrone.WeaponItems, tempDrone.ShieldItems); } } } } Drones = tempDrones; }