internal static Entity NewInstanceFromDesignEntity(Entity design, Entity faction) { List <BaseDataBlob> blobs = new List <BaseDataBlob>(); ComponentInstanceInfoDB info = new ComponentInstanceInfoDB(design); OwnedDB owned = new OwnedDB(faction); blobs.Add(info); blobs.Add(owned); blobs.Add(new DesignInfoDB(design)); // Added because each component instance needs its own copy of this datablob //Components have a mass and volume. MassVolumeDB mvDB = new MassVolumeDB(); blobs.Add(mvDB); if (design.HasDataBlob <BeamFireControlAtbDB>()) { blobs.Add(new FireControlInstanceAbilityDB()); } if (design.HasDataBlob <BeamWeaponAtbDB>() || design.HasDataBlob <SimpleBeamWeaponAtbDB>()) { blobs.Add(new WeaponStateDB()); } Entity newInstance = new Entity(design.Manager, blobs); return(newInstance); }
internal static Entity NewInstanceFromDesignEntity(Entity design, Entity faction, FactionOwnerDB ownerdb, EntityManager manager) { List <BaseDataBlob> blobs = new List <BaseDataBlob>(); ComponentInstanceInfoDB info = new ComponentInstanceInfoDB(design); blobs.Add(info); blobs.Add(new DesignInfoDB(design)); // Added because each component instance needs its own copy of this datablob //Components have a mass and volume. MassVolumeDB mvDB = new MassVolumeDB(); blobs.Add(mvDB); //TODO: this seems ugly, consider using an Interface on the datablobs for this? if (design.HasDataBlob <BeamFireControlAtbDB>()) { blobs.Add(new FireControlInstanceAbilityDB()); } if (design.HasDataBlob <BeamWeaponAtbDB>() || design.HasDataBlob <SimpleBeamWeaponAtbDB>()) { blobs.Add(new WeaponStateDB()); } if (design.HasDataBlob <SensorReceverAtbDB>()) { blobs.Add((SensorReceverAtbDB)design.GetDataBlob <SensorReceverAtbDB>().Clone()); } Entity newInstance = new Entity(manager, blobs); new OwnedDB(faction, newInstance); //the constructor of OwnedDB sets itself to the entity return(newInstance); }
public ComponentInstanceInfoDB(ComponentInstanceInfoDB instance) { DesignEntity = instance.DesignEntity; IsEnabled = instance.IsEnabled; ComponentLoadPercent = instance.ComponentLoadPercent; HTKRemaining = instance.HTKRemaining; HTKMax = instance.HTKMax; }
internal static Entity NewInstanceFromDesignEntity(Entity design, Guid factionID, EntityManager manager) { List <BaseDataBlob> blobs = new List <BaseDataBlob>(); ComponentInstanceInfoDB info = new ComponentInstanceInfoDB(design); NameDB name = new NameDB(design.GetDataBlob <NameDB>().DefaultName); name.SetName(factionID, design.GetDataBlob <NameDB>().GetName(factionID)); blobs.Add(info); blobs.Add(name); blobs.Add(new DesignInfoDB(design)); // Added because each component instance needs its own copy of this datablob //Components have a mass and volume. MassVolumeDB mvDB = (MassVolumeDB)design.GetDataBlob <MassVolumeDB>().Clone(); blobs.Add(mvDB); Entity newInstance = new Entity(manager, factionID, blobs); return(newInstance); }
/// <summary> /// This will work for missiles, ships, asteroids, and populations at some point. /// Damage type may eventually be required. /// </summary> /// <param name="damageableEntity"></param> /// <param name="damageAmount"></param> public static void OnTakingDamage(Entity damageableEntity, int damageAmount, DateTime atDateTime) { if (damageableEntity.HasDataBlob <AsteroidDamageDB>()) { AsteroidDamageDB AstDmgDB = damageableEntity.GetDataBlob <AsteroidDamageDB>(); AstDmgDB.Health = AstDmgDB.Health - damageAmount; if (AstDmgDB.Health <= 0) { SpawnSubAsteroids(damageableEntity, atDateTime); } } else if (damageableEntity.HasDataBlob <ShipInfoDB>()) { //do shield damage //do armor damage //for components: Game game = damageableEntity.Manager.Game; PositionDB ShipPosition = damageableEntity.GetDataBlob <PositionDB>(); StarSystem mySystem; if (!game.Systems.TryGetValue(ShipPosition.SystemGuid, out mySystem)) { throw new GuidNotFoundException(ShipPosition.SystemGuid); } ComponentInstancesDB ShipInst = damageableEntity.GetDataBlob <ComponentInstancesDB>(); //These are ship components in this context int damageAttempt = 0; while (damageAmount > 0) { int randValue = mySystem.RNG.Next((int)(damageableEntity.GetDataBlob <MassVolumeDB>().VolumeM3)); //volume in m^3 foreach (KeyValuePair <Entity, double> pair in ShipInst.ComponentDictionary) { if (pair.Value > randValue) { //check if this component is destroyed //if it isn't get density MassVolumeDB mvDB = pair.Key.GetDataBlob <MassVolumeDB>(); double DensityThreshold = 1.0; //what should this be? double dmgPercent = DensityThreshold * mvDB.Density * 1000; int dmgDone = (int)(damageAmount * dmgPercent); ComponentInfoDB ciDB = pair.Key.GetDataBlob <ComponentInfoDB>(); ComponentInstanceInfoDB ciiDB = pair.Key.GetDataBlob <ComponentInstanceInfoDB>(); if (ciiDB.HTKRemaining > 0) //component is not destroyed yet { if (dmgDone >= ciiDB.HTKRemaining) //component is definitely wrecked { damageAmount = damageAmount - ciiDB.HTKRemaining; ciiDB.HTKRemaining = 0; } else { ciiDB.HTKRemaining = ciiDB.HTKRemaining - damageAmount; damageAmount = 0; } } else { damageAttempt++; if (damageAttempt == 20) // Aurora default, seems like an ok number to use for now. { break; } /// <summary> /// Need to pick a new component to try and destroy. /// Should any damage get absorbed by the wreck? /// How many of these failures should I run into before declaring the ship destroyed? /// Should ship distruction happen differently? /// </summary> continue; } //compare this density to some density value to calculate how much to modify damage by //if damage is greater than the HTK then the component is destroyed. modify damageAmount and move onto the next component. //leave this loop if damage is zero. break; } } if (damageAttempt == 20) // need to copy this to fully break out of the loop; { break; } } if (damageAttempt == 20) // the ship is destroyed. how to mark it as such? { SpawnWreck(damageableEntity); } else { ReCalcProcessor.ReCalcAbilities(damageableEntity); } } else if (damageableEntity.HasDataBlob <ColonyInfoDB>()) { //Think about how to unify this one and shipInfoDB if possible. //do Terraforming/Infra/Pop damage Game game = damageableEntity.Manager.Game; ColonyInfoDB ColIDB = damageableEntity.GetDataBlob <ColonyInfoDB>(); SystemBodyInfoDB SysInfoDB = ColIDB.PlanetEntity.GetDataBlob <SystemBodyInfoDB>(); PositionDB ColonyPosition = ColIDB.PlanetEntity.GetDataBlob <PositionDB>(); StarSystem mySystem; //I need all of this to get to the rng. if (!game.Systems.TryGetValue(ColonyPosition.SystemGuid, out mySystem)) { throw new GuidNotFoundException(ColonyPosition.SystemGuid); } //How should damage work here? //quarter million dead per strength of nuclear attack? 1 radiation/1 dust per strength? //Same chance to destroy components as ship destruction? //I need damage type for these. Missiles/bombs(missile damage but no engine basically) will be the only thing that causes this damage. //ColIDB.Population //SysInfoDB.AtmosphericDust //SysInfoDB.RadiationLevel //Installation Damage section: ComponentInstancesDB ColInst = damageableEntity.GetDataBlob <ComponentInstancesDB>(); //These are installations in this context int damageAttempt = 0; while (damageAmount > 0) { int randValue = mySystem.RNG.Next((int)damageableEntity.GetDataBlob <MassVolumeDB>().Volume); foreach (KeyValuePair <Entity, double> pair in ColInst.ComponentDictionary) { if (pair.Value > randValue) //This installation was targeted { //check if this Installation is destroyed //if it isn't get density MassVolumeDB mvDB = pair.Key.GetDataBlob <MassVolumeDB>(); double DensityThreshold = 1.0; //what should this be? double dmgPercent = DensityThreshold * mvDB.Density; int dmgDone = (int)(damageAmount * dmgPercent); ComponentInfoDB ciDB = pair.Key.GetDataBlob <ComponentInfoDB>(); ComponentInstanceInfoDB ciiDB = pair.Key.GetDataBlob <ComponentInstanceInfoDB>(); if (ciiDB.HTKRemaining > 0) //Installation is not destroyed yet { if (dmgDone >= ciiDB.HTKRemaining) //Installation is definitely wrecked { damageAmount = damageAmount - ciiDB.HTKRemaining; ciiDB.HTKRemaining = 0; } else { ciiDB.HTKRemaining = ciiDB.HTKRemaining - damageAmount; damageAmount = 0; } } else { damageAttempt++; if (damageAttempt == 20) // The planet won't blow up because of this, but no more attempts to damage installations should be made here. { break; } continue; } } } if (damageAttempt == 20) // need to copy this to fully break out of the loop; { break; } } //This will need to be updated to deal with colonies. ReCalcProcessor.ReCalcAbilities(damageableEntity); } }
public ComponentSpecificInstanceVM(Entity instance) { _componentEntity = instance; _instanceInfoDB = instance.GetDataBlob <ComponentInstanceInfoDB>(); }