Esempio n. 1
0
        public static Entity CreateShip(Entity classEntity, EntityManager systemEntityManager, Entity ownerFaction, Vector3 pos, StarSystem starsys, string shipName = null)
        {
            // @todo replace ownerFaction with formationDB later. Now ownerFaction used just to add name
            // @todo: make sure each component design and component instance is unique, not duplicated
            ProtoEntity protoShip = classEntity.Clone();

            ShipInfoDB shipInfoDB = protoShip.GetDataBlob <ShipInfoDB>();

            shipInfoDB.ShipClassDefinition = classEntity.Guid;

            if (shipName == null)
            {
                shipName = "Ship Name";
            }

            NameDB nameDB = new NameDB(shipName);

            nameDB.SetName(ownerFaction.Guid, shipName);
            protoShip.SetDataBlob(nameDB);

            OrderableDB orderableDB = new OrderableDB();

            protoShip.SetDataBlob(orderableDB);

            PositionDB position = new PositionDB(pos, starsys.Guid);

            protoShip.SetDataBlob(position);


            protoShip.SetDataBlob(new DesignInfoDB(classEntity));

            //replace the ships references to the design's specific instances with shiny new specific instances

            ComponentInstancesDB classInstances = classEntity.GetDataBlob <ComponentInstancesDB>();


            Entity shipEntity = new Entity(systemEntityManager, ownerFaction.Guid, protoShip);

            shipEntity.RemoveDataBlob <ComponentInstancesDB>();
            shipEntity.SetDataBlob(new ComponentInstancesDB());
            if (shipEntity.HasDataBlob <FireControlAbilityDB>())
            {
                shipEntity.RemoveDataBlob <FireControlAbilityDB>();
            }

            foreach (var designKVP in classInstances.DesignsAndComponentCount)
            {
                for (int i = 0; i < designKVP.Value; i++)
                {
                    Entity newInstance = ComponentInstanceFactory.NewInstanceFromDesignEntity(designKVP.Key, ownerFaction.Guid, systemEntityManager);
                    EntityManipulation.AddComponentToEntity(shipEntity, newInstance);
                }
            }



            FactionOwnerDB factionOwner = ownerFaction.GetDataBlob <FactionOwnerDB>();

            factionOwner.SetOwned(shipEntity);
            ComponentInstancesDB shipComponentInstanceDB = shipEntity.GetDataBlob <ComponentInstancesDB>();

            //TODO: do this somewhere else, recalcprocessor maybe?
            foreach (var design in shipComponentInstanceDB.GetDesignsByType(typeof(SensorReceverAtbDB)))
            {
                foreach (var instance in shipComponentInstanceDB.GetComponentsBySpecificDesign(design.Guid))
                {
                    var      sensor       = design.GetDataBlob <SensorReceverAtbDB>();
                    DateTime nextDatetime = shipEntity.Manager.ManagerSubpulses.StarSysDateTime + TimeSpan.FromSeconds(sensor.ScanTime);
                    shipEntity.Manager.ManagerSubpulses.AddEntityInterupt(nextDatetime, new SensorScan().TypeName, instance.OwningEntity);
                }
            }


            ReCalcProcessor.ReCalcAbilities(shipEntity);
            return(shipEntity);
        }
Esempio n. 2
0
        /// <summary>
        /// called by ReCalcProcessor
        /// </summary>
        /// <param name="colonyEntity"></param>
        public static void ReCalcRefiningRate(Entity colonyEntity)
        {
            //    Dictionary<Entity, int> installations = colonyEntity.GetDataBlob<ColonyInfoDB>().Installations;
            //    Dictionary<Entity, int> Refinerys = installations.Where(kvp => kvp.Key.HasDataBlob<RefineResourcesDB>()).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

            //    int pointsRate = 0;
            //    Dictionary<Guid, int> matRate = new Dictionary<Guid, int>();
            //    foreach (var RefineryKvp in Refinerys)
            //    {
            //        int points = RefineryKvp.Key.GetDataBlob<RefineResourcesDB>().RefineryPoints;

            //        foreach (var mat in RefineryKvp.Key.GetDataBlob<RefineResourcesDB>().RefinableMatsList)
            //        {
            //           matRate.SafeValueAdd(mat, points * RefineryKvp.Value);
            //        }
            //        pointsRate += points;
            //    }

            Dictionary <Guid, int> rates       = new Dictionary <Guid, int>();
            ComponentInstancesDB   instancesDB = colonyEntity.GetDataBlob <ComponentInstancesDB>();

            var designs = instancesDB.GetDesignsByType(typeof(RefineResourcesAtbDB));

            foreach (var design in designs)
            {
                var componentDesign = design.GetDataBlob <RefineResourcesAtbDB>();
                foreach (var instanceInfo in instancesDB.GetComponentsBySpecificDesign(design.Guid))
                {
                    //TODO: need to check availible workers.
                    if (instanceInfo.IsEnabled)
                    {
                        var healthPercent = instanceInfo.HealthPercent();
                        foreach (var item in componentDesign.RefinableMatsList)
                        {
                            rates.SafeValueAdd(item, (int)(componentDesign.RefineryPoints * healthPercent));
                        }
                    }
                }
            }



            /*
             * List<KeyValuePair<Entity, PrIwObsList<Entity>>> refineingEntities = instancesDB.SpecificInstances.GetInternalDictionary().Where(item => item.Key.HasDataBlob<RefineResourcesAtbDB>()).ToList();
             * foreach (var refiningComponentDesignList in refineingEntities)
             * {
             *  RefineResourcesAtbDB refineblob = refiningComponentDesignList.Key.GetDataBlob<RefineResourcesAtbDB>();
             *  foreach (var mineInstance in refiningComponentDesignList.Value)
             *  {
             *      //todo check if it's damaged, check if it's enabled, check if there's enough workers here to.
             *      foreach (var item in refineblob.RefinableMatsList)
             *      {
             *          rates.SafeValueAdd(item, refineblob.RefineryPoints);
             *      }
             *  }
             * }
             */
            int maxPoints = 0;

            foreach (int p in rates.Values)
            {
                if (p > maxPoints)
                {
                    maxPoints = p;
                }
            }

            var refining = colonyEntity.GetDataBlob <RefiningDB>();

            refining.RefiningRates = rates;
            refining.PointsPerTick = maxPoints;
        }