public override void Init(MyObjectBuilder_EntityBase objectBuilder)
        {
            try
            {
                npcCrewBlock = Entity as IMyUpgradeModule;
                //MyAPIGateway.Utilities.ShowMessage("DEBUG", "Init Ran");
                NeedsUpdate = MyEntityUpdateEnum.EACH_FRAME;
                npcCrewBlock.CubeGrid.ColorBlocks(npcCrewBlock.SlimBlock.Position, npcCrewBlock.SlimBlock.Position, Color.Red.ColorToHSV());

                NPCCrewConfig loadconfig = NPCCrewConfig.LoadConfigFile();
                forceColor = loadconfig.forceColor;

                if (Sink == null)
                {
                    Sink = new MyResourceSinkComponent();
                }
                ResourceInfo = new MyResourceSinkInfo()
                {
                    ResourceTypeId    = GId,
                    MaxRequiredInput  = 0.02f,
                    RequiredInputFunc = () => Power
                };
                Sink.Init(MyStringHash.GetOrCompute("Utility"), ResourceInfo);
                Sink.AddType(ref ResourceInfo);
                Entity.Components.Add(Sink);
                Sink.Update();
            }
            catch (Exception e)
            {
                MyVisualScriptLogicProvider.ShowNotificationToAll("Init Error" + e, 10000, "Red");
            }
        }
 public override void UpdateBeforeSimulation()
 {
     if (Setup == false)
     {
         Setup        = true;
         UpgradeBlock = Entity as IMyUpgradeModule;
         UpgradeBlock.IsWorkingChanged += WorkingChanged;
         NeedsUpdate = MyEntityUpdateEnum.EACH_100TH_FRAME;
     }
 }
Example #3
0
 protected void GetMaxPower()
 {
     try
     {
         IMyUpgradeModule           block = Entity as IMyUpgradeModule;
         List <MyUpgradeModuleInfo> Info;
         block.GetUpgradeList(out Info);
         MaxPower = Info.First(x => x.UpgradeType == "Radar").Modifier;
     }
     catch (Exception Scrap)
     {
         RadarCore.LogError($"{RadarBlock.CustomName}.Load().GetMaxPower", Scrap);
     }
 }
        public override void Init(MyObjectBuilder_EntityBase objectBuilder)
        {
            NeedsUpdate   |= MyEntityUpdateEnum.EACH_FRAME | MyEntityUpdateEnum.BEFORE_NEXT_FRAME;
            _objectBuilder = objectBuilder;

            hyperDriveBlock = Entity as IMyUpgradeModule;

            if (!hyperDriveBlock.Components.TryGet <MyResourceSinkComponent>(out ResourceSink))
            {
                ResourceSink = new MyResourceSinkComponent();
                var sinkInfo = new MyResourceSinkInfo();
                sinkInfo.ResourceTypeId = _electricity;
                ResourceSink.AddType(ref sinkInfo);

                hyperDriveBlock.Components.Add(ResourceSink);
            }
        }
        public override void Init(MyObjectBuilder_EntityBase objectBuilder)
        {
            if (_isInit)
            {
                return;
            }
            m_block = Container.Entity as IMyTerminalBlock;
            m_block.AppendingCustomInfo += appendCustomInfo;
            _imyUM = Entity as IMyUpgradeModule;
            if (!_imyUM.Components.TryGet(out _sink))
            {
                _sink = new MyResourceSinkComponent();
                MyResourceSinkInfo info = new MyResourceSinkInfo();
                info.ResourceTypeId = Electricity;
                _sink.AddType(ref info);
                _imyUM.Components.Add(_sink);
            }
            this.NeedsUpdate |= MyEntityUpdateEnum.BEFORE_NEXT_FRAME;
//	deprecated	Container.Entity.NeedsUpdate |=  MyEntityUpdateEnum.BEFORE_NEXT_FRAME;
        }
Example #6
0
        //Debug.Enabled = true;
        public override void Init(MyObjectBuilder_EntityBase objectBuilder)
        {
            NeedsUpdate |= MyEntityUpdateEnum.BEFORE_NEXT_FRAME;
            base.Init(objectBuilder);
            RadarBlock = Entity as IMyUpgradeModule;

            ScanModule        = new GridScanModule(this);
            MarkerModule      = new RadarMarkerModule(this);
            DetectorModule    = new RadarDetectorModule(this);
            PersistenceModule = new RadarPersistenceModule(this);
            PowerModule       = new RadarPowerModule(this);
            RadarCore.SaveRegister(PersistenceModule.Save);

            /*if (!RadarBlock.HasComponent<MyModStorageComponent>())
             * {
             *  RadarBlock.Storage = new MyModStorageComponent();
             *  RadarBlock.Components.Add(RadarBlock.Storage);
             *  RadarCore.DebugWrite($"{RadarBlock.CustomName}.Init()", "Block doesn't have a Storage component!", IsExcessive: false);
             * }*/
        }
Example #7
0
 public override void Init(MyObjectBuilder_EntityBase objectBuilder)
 {
     if (_isInit)
     {
         return;
     }
     Container.Entity.NeedsUpdate |= MyEntityUpdateEnum.BEFORE_NEXT_FRAME;
     _tblock = Container.Entity as IMyTerminalBlock;
     _tblock.AppendingCustomInfo += appendCustomInfo;
     _ublock   = Entity as IMyUpgradeModule;
     _maxrange = 1000f;
     if (!_ublock.Components.TryGet(out _sink))
     {
         _sink = new MyResourceSinkComponent();
         MyResourceSinkInfo info = new MyResourceSinkInfo();
         info.ResourceTypeId = Electricity;
         _sink.AddType(ref info);
         _ublock.Components.Add(_sink);
     }
     Shields.Add(Entity.EntityId, this);
     _isInit = true;
 }
        private static void ShieldBlockGridOwnershipChanged(IMyCubeGrid cubeGrid)
        {
            IMyUpgradeModule shield = null;

            if (!_activeNpcShields.TryGetValue(cubeGrid, out shield))
            {
                return;
            }

            if (shield?.SlimBlock?.CubeGrid != null || !MyAPIGateway.Entities.Exist(shield?.SlimBlock?.CubeGrid) || !cubeGrid.IsSameConstructAs(shield.SlimBlock.CubeGrid))
            {
                _activeNpcShields.Remove(cubeGrid);
                return;
            }

            bool npcOwned = true;

            if (cubeGrid.BigOwners.Count == 0)
            {
                npcOwned = false;
            }
            else
            {
                foreach (var owner in cubeGrid.BigOwners)
                {
                    if (!IsNPC(owner))
                    {
                        npcOwned = false;
                    }
                }
            }

            if (npcOwned)
            {
                return;
            }

            //TODO: Set LoS Requirement to True
        }
Example #9
0
 public override void OnAddedToContainer()
 {
     if (!ContainerInited)
     {
         PowerPreInit();
         NeedsUpdate |= MyEntityUpdateEnum.BEFORE_NEXT_FRAME;
         if (!MyAPIGateway.Utilities.IsDedicated)
         {
             NeedsUpdate |= MyEntityUpdateEnum.EACH_FRAME;
         }
         else
         {
             NeedsUpdate |= MyEntityUpdateEnum.EACH_10TH_FRAME;
         }
         Modulator       = (IMyUpgradeModule)Entity;
         ContainerInited = true;
     }
     if (Entity.InScene)
     {
         OnAddedToScene();
     }
 }
        private static void ShieldGridSplit(IMyCubeGrid gridA, IMyCubeGrid gridB)
        {
            IMyUpgradeModule shield = null;

            gridA.OnGridSplit -= ShieldGridSplit;
            gridB.OnGridSplit -= ShieldGridSplit;

            if (!_activeNpcShields.TryGetValue(gridA, out shield) && !_activeNpcShields.TryGetValue(gridA, out shield))
            {
                return;
            }

            if (shield?.SlimBlock?.CubeGrid == null || !MyAPIGateway.Entities.Exist(shield?.SlimBlock?.CubeGrid))
            {
                return;
            }

            if (!_activeNpcShields.ContainsKey(shield.SlimBlock.CubeGrid))
            {
                if (shield.SlimBlock.CubeGrid == gridA)
                {
                    gridB.OnBlockOwnershipChanged -= ShieldBlockGridOwnershipChanged;
                    _activeNpcShields.Remove(gridB);
                }
                else
                {
                    gridA.OnBlockOwnershipChanged -= ShieldBlockGridOwnershipChanged;
                    _activeNpcShields.Remove(gridA);
                }

                shield.SlimBlock.CubeGrid.OnBlockOwnershipChanged += ShieldBlockGridOwnershipChanged;
                _activeNpcShields.Add(shield.SlimBlock.CubeGrid, shield);
            }

            shield.SlimBlock.CubeGrid.OnGridSplit += ShieldGridSplit;
            ShieldBlockGridOwnershipChanged(shield.SlimBlock.CubeGrid);
        }