public CargoTypeStoreVM(StaticDataStore staticDataStore, Guid typeGuid, CargoTypeStore typeStore) { TypeID = typeGuid; _staticData = staticDataStore; _typeStore = typeStore; var _cargoTypeSD = staticDataStore.CargoTypes[typeGuid]; StorageTypeName = _cargoTypeSD.Name; StorageTypeDescription = _cargoTypeSD.Description; Update(); }
internal static void ReCalcCapacity(Entity parentEntity) { CargoStorageDB cargoStorageDB = parentEntity.GetDataBlob <CargoStorageDB>(); Dictionary <Guid, CargoTypeStore> storageDBStoredCargos = cargoStorageDB.StoredCargoTypes; Dictionary <Guid, long> calculatedMaxStorage = new Dictionary <Guid, long>(); var instancesDB = parentEntity.GetDataBlob <ComponentInstancesDB>(); double transferRate = 0; double transferRange = 0; int i = 0; if (instancesDB.TryGetComponentsByAttribute <CargoStorageAtbDB>(out var componentInstances)) { foreach (var instance in componentInstances) { var design = instance.Design; var atbdata = design.GetAttribute <CargoStorageAtbDB>(); if (instance.HealthPercent() > 0.75) { if (!calculatedMaxStorage.ContainsKey(atbdata.CargoTypeGuid)) { calculatedMaxStorage[atbdata.CargoTypeGuid] = atbdata.StorageCapacity; } else { calculatedMaxStorage[atbdata.CargoTypeGuid] += atbdata.StorageCapacity; } transferRate += atbdata.TransferRate; transferRange += atbdata.TransferRange; i++; } } } //transfer rate and ranges are averaged. cargoStorageDB.TransferRateInKgHr = (int)(transferRate / i); cargoStorageDB.TransferRangeDv = (transferRange / i); //List<KeyValuePair<Entity, PrIwObsList<Entity>>> storageComponents = parentEntity.GetDataBlob<ComponentInstancesDB>().SpecificInstances.GetInternalDictionary().Where(item => item.Key.HasDataBlob<CargoStorageAtbDB>()).ToList(); /* * foreach (var kvp in storageComponents) //first loop through the component types * { * Entity componentDesign = kvp.Key; * ID cargoTypeID = componentDesign.GetDataBlob<CargoStorageAtbDB>().CargoTypeGuid; * long alowableSpace = 0; * foreach (var specificComponent in kvp.Value) //then loop through each specific component * {//checking the helth... * var healthPercent = specificComponent.GetDataBlob<ComponentInstanceInfoDB>().HealthPercent(); * if (healthPercent > 0.75) //hardcoded health percent at 3/4, cargo is delecate? todo: streach goal make this modable * alowableSpace = componentDesign.GetDataBlob<CargoStorageAtbDB>().StorageCapacity; * } * //then add the amount to our tempory dictionary * if (!calculatedMaxStorage.ContainsKey(cargoTypeID)) * calculatedMaxStorage.Add(cargoTypeID, alowableSpace); * else * calculatedMaxStorage[cargoTypeID] += alowableSpace; * } */ //now loop through our tempory dictionary and match it up with the real one. foreach (var kvp in calculatedMaxStorage) { Guid cargoTypeID = kvp.Key; long validMaxCapacity = kvp.Value; if (!storageDBStoredCargos.ContainsKey(cargoTypeID)) { var newStore = new CargoTypeStore(); newStore.MaxCapacityKg = validMaxCapacity; newStore.FreeCapacityKg = validMaxCapacity; storageDBStoredCargos.Add(cargoTypeID, newStore); } else if (storageDBStoredCargos[cargoTypeID].MaxCapacityKg != validMaxCapacity) { CargoTypeStore typeStore = storageDBStoredCargos[cargoTypeID]; if (typeStore.ItemsAndAmounts.Count == 0 && typeStore.SpecificEntites.Count == 0) { typeStore.FreeCapacityKg = validMaxCapacity; } else { long usedSpace = typeStore.MaxCapacityKg - typeStore.FreeCapacityKg; typeStore.MaxCapacityKg = validMaxCapacity; if (!(usedSpace <= validMaxCapacity)) { long overweight = usedSpace - validMaxCapacity; DropRandomCargo(typeStore, overweight); } } } } }
internal static void ReCalcCapacity(Entity parentEntity) { Dictionary <Guid, CargoTypeStore> storageDBStoredCargos = parentEntity.GetDataBlob <CargoStorageDB>().StoredCargoTypes; Dictionary <Guid, long> calculatedMaxStorage = new Dictionary <Guid, long>(); List <KeyValuePair <Entity, PrIwObsList <Entity> > > storageComponents = parentEntity.GetDataBlob <ComponentInstancesDB>().SpecificInstances.GetInternalDictionary().Where(item => item.Key.HasDataBlob <CargoStorageAtbDB>()).ToList(); foreach (var kvp in storageComponents) //first loop through the component types { Entity componentDesign = kvp.Key; Guid cargoTypeID = componentDesign.GetDataBlob <CargoStorageAtbDB>().CargoTypeGuid; long alowableSpace = 0; foreach (var specificComponent in kvp.Value) //then loop through each specific component { //checking the helth... var healthPercent = specificComponent.GetDataBlob <ComponentInstanceInfoDB>().HealthPercent(); if (healthPercent > 0.75) //hardcoded health percent at 3/4, cargo is delecate? todo: streach goal make this modable { alowableSpace = componentDesign.GetDataBlob <CargoStorageAtbDB>().StorageCapacity; } } //then add the amount to our tempory dictionary if (!calculatedMaxStorage.ContainsKey(cargoTypeID)) { calculatedMaxStorage.Add(cargoTypeID, alowableSpace); } else { calculatedMaxStorage[cargoTypeID] += alowableSpace; } } //now loop through our tempory dictionary and match it up with the real one. foreach (var kvp in calculatedMaxStorage) { Guid cargoTypeID = kvp.Key; long validMaxCapacity = kvp.Value; if (!storageDBStoredCargos.ContainsKey(cargoTypeID)) { var newStore = new CargoTypeStore(); newStore.MaxCapacity = validMaxCapacity; newStore.FreeCapacity = validMaxCapacity; storageDBStoredCargos.Add(cargoTypeID, newStore); } else if (storageDBStoredCargos[cargoTypeID].MaxCapacity != validMaxCapacity) { long usedSpace = storageDBStoredCargos[cargoTypeID].MaxCapacity - storageDBStoredCargos[cargoTypeID].FreeCapacity; storageDBStoredCargos[cargoTypeID].MaxCapacity = validMaxCapacity; if (!(usedSpace <= validMaxCapacity)) { long overweight = usedSpace - validMaxCapacity; DropRandomCargo(storageDBStoredCargos[cargoTypeID], overweight); } } } }