예제 #1
0
 public void OnComponentInstallation(Entity parentEntity, ComponentInstance componentInstance)
 {
     if (!parentEntity.HasDataBlob <WarpAbilityDB>())
     {
         var ablty = new WarpAbilityDB();
         ablty.EnergyType         = EnergyType;
         ablty.BubbleCreationCost = BubbleCreationCost;
         ablty.BubbleSustainCost  = BubbleSustainCost;
         ablty.BubbleCollapseCost = BubbleCollapseCost;
         parentEntity.SetDataBlob(ablty);
     }
     else
     {
         var ablty = parentEntity.GetDataBlob <WarpAbilityDB>();
         ablty.BubbleCreationCost += BubbleCreationCost;
         ablty.BubbleSustainCost  += BubbleSustainCost;
         ablty.BubbleCollapseCost += BubbleCollapseCost;
     }
     ShipMovementProcessor.CalcMaxWarpAndEnergyUsage(parentEntity);
 }
        public static void ReCalculateShipTonnaageAndHTK(Entity shipEntity)
        {
            ShipInfoDB           shipInfo           = shipEntity.GetDataBlob <ShipInfoDB>();
            ComponentInstancesDB componentInstances = shipEntity.GetDataBlob <ComponentInstancesDB>();
            float  totalTonnage = 0;
            int    totalHTK     = 0;
            double totalVolume  = 0;

            foreach (KeyValuePair <Guid, List <ComponentInstance> > instance in componentInstances.GetComponentsByDesigns())
            {
                var componentVolume  = componentInstances.AllDesigns[instance.Key].VolumePerUnit;
                var componentTonnage = componentInstances.AllDesigns[instance.Key].MassPerUnit;

                foreach (var componentInstance in instance.Value)
                {
                    totalHTK     += componentInstance.HTKRemaining;
                    totalVolume  += componentVolume;
                    totalTonnage += componentTonnage;
                }
            }
            if (shipInfo.Tonnage != totalTonnage)
            {
                shipInfo.Tonnage = totalTonnage;
                if (shipEntity.HasDataBlob <WarpAbilityDB>())
                {
                    ShipMovementProcessor.CalcMaxWarpAndEnergyUsage(shipEntity);
                }
            }
            shipInfo.InternalHTK = totalHTK;
            MassVolumeDB mvDB = shipEntity.GetDataBlob <MassVolumeDB>();

            mvDB.MassDry     = totalTonnage;
            mvDB.Volume_m3   = totalVolume;
            mvDB.Density_gcm = MassVolumeDB.CalculateDensity(totalTonnage, totalVolume);
            mvDB.RadiusInAU  = MassVolumeDB.CalculateRadius_Au(totalTonnage, mvDB.Density_gcm);
        }