Exemple #1
0
        public void OnRemoveBeam()
        {
            ComponentInstance beam = SelectedAttachedBeam;


            if (SelectedFireControl == null || _fireControlList.SelectedIndex == -1)
            {
                return;
            }

            if (SelectedAttachedBeam == null || _attachedBeamList.SelectedIndex == -1)
            {
                return;
            }

            List <ComponentInstance> weaponList = SelectedFireControl.GetAbilityState <FireControlAbilityState>().AssignedWeapons;

            weaponList.Remove(SelectedAttachedBeam);

            // @todo: unset the fire control for the beam

            beam.GetAbilityState <WeaponState>().FireControl = null;

            RefreshBeamWeaponsList(0, 0);
        }
Exemple #2
0
 public void OnComponentInstallation(Entity parentEntity, ComponentInstance componentInstance)
 {
     if (!componentInstance.HasAblity <WeaponState>())
     {
         componentInstance.SetAbilityState <WeaponState>(new WeaponState());
     }
 }
Exemple #3
0
        internal void RemoveComponentInstance(ComponentInstance instance)
        {
            var design = instance.Design;

            AllDesigns.Remove(design.ID);
            AllComponents.Remove(instance.ID);
            ComponentsByDesign[design.ID].Remove(instance);

            foreach (var atbkvp in design.AttributesByType)
            {
                _designsByAtbType[atbkvp.Key].Remove(design);
                if (_designsByAtbType[atbkvp.Key].Count == 0)
                {
                    _designsByAtbType.Remove(atbkvp.Key);
                }
            }
            DesignsAndComponentCount[design] -= 1;
            if (DesignsAndComponentCount[design] == 0)
            {
                DesignsAndComponentCount.Remove(design);
            }

            foreach (var atbkvp in instance.Design.AttributesByType)
            {
                ComponentsByAttribute[atbkvp.Key].Remove(instance);
            }
        }
        internal override bool IsValidCommand(Game game)
        {
            //see if we can successfully turn the guids into entites.
            //the reason we use guids is to make it easier to serialise for network play.
            //getting the entites makes it a bit easier to ActionCommand though
            //it may also be a good idea to double check that the entites we're looking for have specific DBs to prevent a crash...
            //IsCommandValid also checks that the entity we're commanding is owned by our faction.
            if (CommandHelpers.IsCommandValid(game.GlobalManager, RequestingFactionGuid, EntityCommandingGuid, out _factionEntity, out _entityCommanding))
            {
                if (game.GlobalManager.FindEntityByGuid(TargetSensorEntityGuid, out _targetSensorEntity))
                {
                    if (_targetSensorEntity.HasDataBlob <SensorInfoDB>()) //we want to damage the actual entity, not the sensor clone.
                    {
                        _targetActualEntity = _targetSensorEntity.GetDataBlob <SensorInfoDB>().DetectedEntity;
                    }
                    else
                    {
                        _targetActualEntity = _targetSensorEntity;
                    }
                    var instancesdb = _entityCommanding.GetDataBlob <ComponentInstancesDB>();

                    if (instancesdb.AllComponents.TryGetValue(FireControlGuid, out var fc))
                    {
                        if (fc.HasAblity <FireControlAbilityState>())
                        {
                            _fireControlComponent = fc;

                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
 public void OnComponentInstallation(Entity parentEntity, ComponentInstance componentInstance)
 {
     if (!parentEntity.HasDataBlob <SensorProfileDB>())
     {
         parentEntity.SetDataBlob(new SensorProfileDB());
     }
 }
Exemple #6
0
        public void OnComponentInstallation(Entity parentEntity, ComponentInstance componentInstance)
        {
            NewtonThrustAbilityDB db;

            if (!parentEntity.HasDataBlob <NewtonThrustAbilityDB>())
            {
                db = new NewtonThrustAbilityDB(FuelType);
                parentEntity.SetDataBlob(db);
            }
            else
            {
                db = parentEntity.GetDataBlob <NewtonThrustAbilityDB>();
                if (db.FuelType != FuelType)
                {
                    throw new Exception("prime entity can only have thrusters which use the same fuel type");
                }
                //todo: fix so we can use different fuel types on the prime entity.
            }

            //db.ThrustInNewtons += ThrustInNewtons;
            db.ExhaustVelocity  = ExhaustVelocity;
            db.FuelBurnRate    += FuelBurnRate;
            db.ThrustInNewtons += ExhaustVelocity * FuelBurnRate;

            /*
             * var wetmass = parentEntity.GetDataBlob<MassVolumeDB>().Mass;
             * ProcessedMaterialSD foo = StaticRefLib.StaticData.CargoGoods.GetMaterials()[FuelType];
             * var cargo = parentEntity.GetDataBlob<CargoStorageDB>();
             * var fuelAmount = StorageSpaceProcessor.GetAmount(cargo, foo);
             * var dryMass = wetmass - fuelAmount;
             * db.DeltaV = OrbitMath.TsiolkovskyRocketEquation(wetmass, dryMass, ExhaustVelocity);
             */
        }
        internal override bool IsValidCommand(Game game)
        {
            if (CommandHelpers.IsCommandValid(game.GlobalManager, RequestingFactionGuid, EntityCommandingGuid, out _factionEntity, out _entityCommanding))
            {
                var instancesdb = _entityCommanding.GetDataBlob <ComponentInstancesDB>();

                if (instancesdb.AllComponents.TryGetValue(FireControlGuid, out var fc))
                {
                    if (fc.HasAblity <FireControlAbilityState>())
                    {
                        _fireControlComponent = fc;

                        foreach (var wpnGuid in WeaponsAssigned)
                        {
                            if (instancesdb.AllComponents.TryGetValue(wpnGuid, out var wpn))
                            {
                                if (wpn.HasAblity <WeaponState>())
                                {
                                    _weaponsAssigned.Add(wpn);
                                }
                            }
                        }
                        return(true);
                    }
                }
            }
            return(false);
        }
Exemple #8
0
        private static void BatchJobItemComplete(Entity colonyEntity, CargoStorageDB storage, ConstructionJob batchJob, ComponentDesign designInfo)
        {
            var colonyConstruction = colonyEntity.GetDataBlob <ConstructionDB>();

            batchJob.NumberCompleted++;
            batchJob.ProductionPointsLeft = designInfo.BuildPointCost;
            batchJob.MineralsRequired     = designInfo.MineralCosts;
            batchJob.MineralsRequired     = designInfo.MaterialCosts;
            batchJob.MineralsRequired     = designInfo.ComponentCosts;

            ComponentInstance specificComponent = new ComponentInstance(designInfo);

            if (batchJob.InstallOn != null)
            {
                if (batchJob.InstallOn == colonyEntity || StorageSpaceProcessor.HasEntity(storage, colonyEntity.GetDataBlob <CargoAbleTypeDB>()))
                {
                    EntityManipulation.AddComponentToEntity(batchJob.InstallOn, specificComponent);
                    ReCalcProcessor.ReCalcAbilities(batchJob.InstallOn);
                }
            }
            else
            {
                StorageSpaceProcessor.AddCargo(storage, specificComponent, 1);
            }

            if (batchJob.NumberCompleted == batchJob.NumberOrdered)
            {
                colonyConstruction.JobBatchList.Remove(batchJob);
                if (batchJob.Auto)
                {
                    colonyConstruction.JobBatchList.Add(batchJob);
                }
            }
        }
Exemple #9
0
 public void OnComponentInstallation(Entity parentEntity, ComponentInstance componentInstance)
 {
     if (!parentEntity.HasDataBlob <CargoAbleTypeDB>())
     {
         parentEntity.SetDataBlob(new CargoAbleTypeDB(this)); //basicaly just clone the design to the instance.
     }
 }
Exemple #10
0
 public void OnComponentInstallation(Entity parentEntity, ComponentInstance componentInstance)
 {
     if (!parentEntity.HasDataBlob <RefiningDB>())
     {
         parentEntity.SetDataBlob(new RefiningDB());
     }
     RefiningProcessor.ReCalcRefiningRate(parentEntity);
 }
Exemple #11
0
 public void OnComponentInstallation(Entity parentEntity, ComponentInstance componentInstance)
 {
     if (!parentEntity.HasDataBlob <ConstructionDB>())
     {
         parentEntity.SetDataBlob(new ConstructionDB());
     }
     ConstructionProcessor.ReCalcConstructionRate(parentEntity);
 }
 public void OnComponentInstallation(Entity parentEntity, ComponentInstance componentInstance)
 {
     if (!parentEntity.HasDataBlob <MiningDB>())
     {
         parentEntity.SetDataBlob(new MiningDB());
     }
     MineResourcesProcessor.CalcMaxRate(parentEntity);
 }
Exemple #13
0
 public ComponentInstance(ComponentInstance instance)
 {
     ID                   = instance.ID;
     Design               = instance.Design;
     IsEnabled            = instance.IsEnabled;
     ComponentLoadPercent = instance.ComponentLoadPercent;
     HTKRemaining         = instance.HTKRemaining;
     HTKMax               = instance.HTKMax;
 }
Exemple #14
0
 public void OnComponentInstallation(Entity parentEntity, ComponentInstance componentInstance)
 {
     if (!parentEntity.HasDataBlob <CargoStorageDB>())
     {
         var db = new CargoStorageDB();
         parentEntity.SetDataBlob(db);
         StorageSpaceProcessor.ReCalcCapacity(parentEntity);
     }
 }
 internal void RemoveWeapons(Guid[] wpnIds)
 {
     ComponentInstance[] wpnInstances = new ComponentInstance[wpnIds.Length];
     for (int i = 0; i < wpnIds.Length; i++)
     {
         wpnInstances[i] = OwningEntity.GetDataBlob <ComponentInstancesDB>().AllComponents[wpnIds[i]];
     }
     RemoveWeapons(wpnInstances);
 }
Exemple #16
0
 public void OnComponentInstallation(Entity parentEntity, ComponentInstance componentInstance)
 {
     if (!parentEntity.HasDataBlob <VolumeStorageDB>())
     {
         var newdb = new VolumeStorageDB();
         parentEntity.SetDataBlob(newdb);
     }
     StorageSpaceProcessor.RecalcVolumeCapacityAndRates(parentEntity);
 }
 public ComponentInstance[] GetChildrenInstances()
 {
     ComponentInstance[] instances = new ComponentInstance[ChildrenStates.Count];
     for (int i = 0; i < ChildrenStates.Count; i++)
     {
         instances[i] = ChildrenStates[i].ComponentInstance;
     }
     return(instances);
 }
 public void OnComponentInstallation(Entity parentEntity, ComponentInstance componentInstance)
 {
     if (!parentEntity.HasDataBlob <EntityResearchDB>())
     {
         parentEntity.SetDataBlob(new EntityResearchDB());
     }
     if (!parentEntity.HasDataBlob <TeamsHousedDB>())
     {
         parentEntity.SetDataBlob(new TeamsHousedDB());
     }
 }
Exemple #19
0
 public static void RemoveWeaponFromFC(ComponentInstance weaponInstance)
 {
     if (weaponInstance.TryGetAbilityState <WeaponState>(out var wpnState))
     {
         wpnState.FireControl = null;
     }
     else
     {
         throw new Exception("needs WeaponStateDB on weaponInstance");
     }
 }
Exemple #20
0
 public static void SetTarget(ComponentInstance fireControlInstance, Entity target)
 {
     if (fireControlInstance.TryGetAbilityState <FireControlAbilityState>(out var fcState))
     {
         fcState.Target = target;
     }
     else
     {
         throw new Exception("No FireContInstanceAbilityDB on entity");
     }
 }
        private static void AddComponentInstanceToEntity(Entity parentEntity, ComponentInstance componentInstance)
        {
            componentInstance.ParentEntity = parentEntity;
            ComponentInstancesDB instancesDict = parentEntity.GetDataBlob <ComponentInstancesDB>();

            instancesDict.AddComponentInstance(componentInstance);
            foreach (var atbkvp in componentInstance.Design.AttributesByType)
            {
                atbkvp.Value.OnComponentInstallation(parentEntity, componentInstance);
            }
        }
Exemple #22
0
 public static void SetWeaponToFC(ComponentInstance fireControlInstance, ComponentInstance weaponInstance)
 {
     if (fireControlInstance.HasAblity <FireControlAbilityState>() && weaponInstance.TryGetAbilityState <WeaponState>(out var wpnState))
     {
         wpnState.FireControl = fireControlInstance;
     }
     else
     {
         throw new Exception("needs FireContInstanceAbilityDB on fireControlInstance, and WeaponStateDB on weaponInstance");
     }
 }
Exemple #23
0
        internal void AddComponentInstance(ComponentInstance instance)
        {
            AllComponents.Add(instance.ID, instance);

            var design = instance.Design;

            AllDesigns[design.ID] = design;
            foreach (var attbkvp in design.AttributesByType)
            {
                //add the design to the dictionary if it's not already there.
                if (!_designsByAtbType.ContainsKey(attbkvp.Key))
                {
                    _designsByAtbType.Add(attbkvp.Key, new List <ComponentDesign>());
                }

                if (!_designsByAtbType[attbkvp.Key].Contains(design))
                {
                    _designsByAtbType[attbkvp.Key].Add(design);
                }
            }

            //add the component instance to the dictionary if it's not already there.
            if (!ComponentsByDesign.ContainsKey(design.ID))
            {
                ComponentsByDesign.Add(design.ID, new List <ComponentInstance>());
            }
            if (!ComponentsByDesign[design.ID].Contains(instance))
            {
                ComponentsByDesign[design.ID].Add(instance);
            }



            if (!DesignsAndComponentCount.ContainsKey(design))
            {
                DesignsAndComponentCount.Add(design, 1);
            }
            else
            {
                DesignsAndComponentCount[design] += 1;
            }

            foreach (var atbkvp in instance.Design.AttributesByType)
            {
                if (!ComponentsByAttribute.ContainsKey(atbkvp.Key))
                {
                    ComponentsByAttribute.Add(atbkvp.Key, new List <ComponentInstance>());
                }

                ComponentsByAttribute[atbkvp.Key].Add(instance);
            }
        }
        public void OnComponentInstallation(Entity parentEntity, ComponentInstance componentInstance)
        {
            Guid               resourceID      = EnergyTypeID;
            ICargoable         energyCargoable = StaticRefLib.StaticData.GetICargoable(resourceID);
            EnergyGenAbilityDB genDB;

            if (!parentEntity.HasDataBlob <EnergyGenAbilityDB>())
            {
                genDB            = new EnergyGenAbilityDB(parentEntity.StarSysDateTime);
                genDB.EnergyType = energyCargoable;
                parentEntity.SetDataBlob(genDB);
            }
            else
            {
                genDB = parentEntity.GetDataBlob <EnergyGenAbilityDB>();


                if (genDB.EnergyType == null)
                {
                    genDB.EnergyType = energyCargoable;
                }
                else if (genDB.EnergyType != energyCargoable)//this is just to reduce complexity. we can add this ability later.
                {
                    throw new Exception("PrimeEntity cannot use two different energy types");
                }
                if (genDB.TotalFuelUseAtMax.type == Guid.Empty)
                {
                    genDB.TotalFuelUseAtMax.type = FuelType;
                }
                else if (genDB.TotalFuelUseAtMax.type != FuelType)
                {
                    throw new Exception("PrimeEntity cannot have power plants that use different fuel types");
                }
            }

            genDB.TotalOutputMax += PowerOutputMax;
            double maxUse = genDB.TotalFuelUseAtMax.maxUse + FuelUsedAtMax;

            genDB.TotalFuelUseAtMax = (FuelType, maxUse);
            genDB.LocalFuel         = maxUse * Lifetime;

            //add enough energy store for 1s of running.
            if (genDB.EnergyStoreMax.ContainsKey(EnergyTypeID))
            {
                genDB.EnergyStoreMax[EnergyTypeID] += PowerOutputMax;
            }
            else
            {
                genDB.EnergyStored[EnergyTypeID]   = 0;
                genDB.EnergyStoreMax[EnergyTypeID] = PowerOutputMax;
            }
        }
Exemple #25
0
 public void OnComponentInstallation(Entity parentEntity, ComponentInstance componentInstance)
 {
     //we're cloning the design to the instance here. when we do another pass on the sensors we'll likely change this.
     if (!componentInstance.HasAblity <SensorReceverAbility>())
     {
         componentInstance.SetAbilityState <SensorReceverAbility>(new SensorReceverAbility());//'this' should be the instance's designs db.
     }
     if (!parentEntity.HasDataBlob <SensorAbilityDB>())
     {
         parentEntity.SetDataBlob(new SensorAbilityDB());
     }
     //SensorProcessorTools.(componentInstance);
 }
Exemple #26
0
        public void OnComponentInstallation(Entity parentEntity, ComponentInstance componentInstance)
        {
            if (!parentEntity.HasDataBlob <FireControlAbilityDB>())
            {
                parentEntity.SetDataBlob <FireControlAbilityDB>(new FireControlAbilityDB());
            }
            var ability = parentEntity.GetDataBlob <FireControlAbilityDB>();

            if (!componentInstance.HasAblity <FireControlAbilityState>())
            {
                componentInstance.SetAbilityState <FireControlAbilityState>(new FireControlAbilityState());
            }
            ability.FireControlInstances.Add(componentInstance);
        }
Exemple #27
0
        public void OnComponentInstallation(Entity parentEntity, ComponentInstance componentInstance)
        {
            var instancesDB = parentEntity.GetDataBlob <ComponentInstancesDB>();

            if (!parentEntity.HasDataBlob <FireControlAbilityDB>())
            {
                var fcdb = new FireControlAbilityDB();
                parentEntity.SetDataBlob(fcdb);
            }

            if (!componentInstance.HasAblity <WeaponState>())
            {
                var wpnState = new WeaponState(componentInstance, this);
                wpnState.WeaponType     = "Beam";
                wpnState.WeaponStats    = new (string name, double value, ValueTypeStruct valueType)[3];
Exemple #28
0
        public void OnComponentInstallation(Entity parentEntity, ComponentInstance componentInstance)
        {
            var instancesDB = parentEntity.GetDataBlob <ComponentInstancesDB>();

            if (!parentEntity.HasDataBlob <FireControlAbilityDB>())
            {
                var fcdb = new FireControlAbilityDB();
                parentEntity.SetDataBlob(fcdb);
            }

            if (!componentInstance.HasAblity <WeaponState>())
            {
                componentInstance.SetAbilityState <WeaponState>(new WeaponState());
            }
        }
 internal static void AddComponentToEntity(Entity parentEntity, List <ComponentDesign> componentDesign)
 {
     if (parentEntity.HasDataBlob <ComponentInstancesDB>())
     {
         foreach (var cd in componentDesign)
         {
             ComponentInstance instance = new ComponentInstance(cd);
             AddComponentInstanceToEntity(parentEntity, instance);
         }
         ReCalcProcessor.ReCalcAbilities(parentEntity);
     }
     else
     {
         throw new Exception("parentEntiy does not contain a ComponentInstanceDB");
     }
 }
Exemple #30
0
        internal override bool IsValidCommand(Game game)
        {
            if (CommandHelpers.IsCommandValid(game.GlobalManager, RequestingFactionGuid, EntityCommandingGuid, out _factionEntity, out _entityCommanding))
            {
                var instancesdb = _entityCommanding.GetDataBlob <ComponentInstancesDB>();

                if (instancesdb.AllComponents.TryGetValue(WeaponGuid, out ComponentInstance wpn))
                {
                    _ordnanceAssigned = _factionEntity.GetDataBlob <FactionInfoDB>().MissileDesigns[OrdnanceAssigned];
                    if (wpn.TryGetAbilityState(out WeaponState wpnState))
                    {
                        _weaponInstance = wpn;
                        return(wpnState.FireWeaponInstructions.CanLoadOrdnance(_ordnanceAssigned));
                    }
                }
            }
            return(false);
        }