Пример #1
0
        public override void Init(MyObjectBuilder_EntityBase objectBuilder)
        {
            base.Init(objectBuilder);
            this.objectBuilder = objectBuilder;

            Entity.NeedsUpdate |= MyEntityUpdateEnum.BEFORE_NEXT_FRAME | MyEntityUpdateEnum.EACH_FRAME | MyEntityUpdateEnum.EACH_100TH_FRAME;

            functionalBlock = Entity as Sandbox.ModAPI.IMyFunctionalBlock;
            cubeBlock       = Entity as IMyCubeBlock;
            terminalBlock   = Entity as Sandbox.ModAPI.IMyTerminalBlock;

            subtypeName = functionalBlock.BlockDefinition.SubtypeName;

            getAttractorWeaponInfo(subtypeName);
            initCharges();

            cubeBlock.AddUpgradeValue("PowerEfficiency", 1.0f);
            cubeBlock.OnUpgradeValuesChanged += onUpgradeValuesChanged;

            terminalBlock.AppendingCustomInfo += appendCustomInfo;

            IMyCubeBlock cube = Entity as IMyCubeBlock;

            lastShootTime = ((MyObjectBuilder_LargeGatlingTurret)cube.GetObjectBuilderCubeBlock()).GunBase.LastShootTime;
        }
Пример #2
0
        private void printShieldStatus()
        {
            try
            {
                if (MyAPIGateway.Multiplayer.IsServer)
                {
                    if (Entity.InScene)
                    {
                        Sandbox.ModAPI.IMyFunctionalBlock funcBlock = Entity as Sandbox.ModAPI.IMyFunctionalBlock;

                        if (funcBlock.CustomName.Contains(":"))
                        {
                            String name   = funcBlock.CustomName;
                            long   gridID = funcBlock.CubeGrid.EntityId;
                            int    index  = name.IndexOf(':');

                            if ((index + 1) < name.Length)
                            {
                                name = name.Remove(index + 1);
                            }

                            IMyGridTerminalSystem   tsystem          = MyAPIGateway.TerminalActionsHelper.GetTerminalSystemForGrid(funcBlock.CubeGrid as IMyCubeGrid);
                            List <IMyTerminalBlock> shieldsConnected = new List <IMyTerminalBlock>();

                            if (tsystem != null)
                            {
                                tsystem.GetBlocksOfType <Sandbox.ModAPI.Ingame.IMyRefinery>(shieldsConnected, EnergyShieldsCore.shieldFilter);

                                float shipCurrentShieldPoints = 0f;
                                float shipMaximumShieldPoints = 0f;

                                foreach (var shield in shieldsConnected)
                                {
                                    ShieldGeneratorGameLogic generatorLogic = ((IMyTerminalBlock)shield).GameLogic.GetAs <ShieldGeneratorGameLogic>();

                                    shipCurrentShieldPoints += generatorLogic.m_currentShieldPoints;
                                    shipMaximumShieldPoints += generatorLogic.m_maximumShieldPoints;
                                }

                                name = name + " (" + Math.Round(shipCurrentShieldPoints) + "/" +
                                       Math.Round(shipMaximumShieldPoints) + ")";
                                funcBlock.SetCustomName(name);
                            }
                            else
                            {
                                name = name + " (" + Math.Round(m_currentShieldPoints) + "/" +
                                       Math.Round(m_maximumShieldPoints) + ")";
                                funcBlock.SetCustomName(name);
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            { }
        }
Пример #3
0
        private void damageOnlineShip()
        {
            List <IMySlimBlock> gridBlocks = new List <IMySlimBlock>();

            thisGrid.GetBlocks(gridBlocks, b => b.FatBlock is IMyFunctionalBlock && isValidForOnlineDamage(b.FatBlock as IMyFunctionalBlock));
            foreach (IMySlimBlock slim in gridBlocks)
            {
                IMyFunctionalBlock block = slim.FatBlock as IMyFunctionalBlock;
                empBlock(slim, block, 0, true, Configuration.getEMPReaction(block), true, true);
            }
        }
Пример #4
0
 private bool isValidForOnlineDamage(IMyFunctionalBlock block)      //build list first, then start damage, or it might damage the power supply first and then nothing else
 {
     if (block == thisBlock || block is IMyLandingGear)             //landing gear cannot be shut down, nor requires power, so always would incur damage
     {
         return(false);
     }
     if ((block as MyCubeBlock).BuiltBy != (thisBlock as MyCubeBlock).BuiltBy)             //since if different players, must be a "foreign" EMP leeched onto a station/ship, not a "self EMP"; use build-by, not owner, so that can affect things like thrusters
     {
         return(false);
     }
     return(block.IsWorking && block.Enabled);
 }
        protected void doSetup(string powerPriority, float smallGridMW, float largeGridMW, params MyEntityUpdateEnum[] updateCycles)
        {
            NeedsUpdate        |= MyEntityUpdateEnum.EACH_10TH_FRAME;
            Entity.NeedsUpdate |= MyEntityUpdateEnum.EACH_10TH_FRAME;
            NeedsUpdate        |= MyEntityUpdateEnum.BEFORE_NEXT_FRAME;
            Entity.NeedsUpdate |= MyEntityUpdateEnum.BEFORE_NEXT_FRAME;

            if (updateCycles.Length == 0)
            {
                IO.log("WARNING: " + this + " has no update cycles set!");
            }

            foreach (MyEntityUpdateEnum e in updateCycles)
            {
                NeedsUpdate        |= e;
                Entity.NeedsUpdate |= e;
            }

            thisBlock = Container.Entity as IMyFunctionalBlock;
            thisGrid  = thisBlock.CubeGrid as IMyCubeGrid;

            //thisBlock.Enabled = false; //causes it to turn off every time you load the game
            //Sandbox.ModAPI.Ingame.TerminalBlockExtentions.ApplyAction(thisBlock, "OnOff_Off");

            energySink = new MyResourceSinkComponent(1);
            energySink.Init(MyStringHash.GetOrCompute(powerPriority), thisGrid.GridSizeEnum == MyCubeSize.Small ? smallGridMW : largeGridMW, calcRequiredPower, (MyCubeBlock)thisBlock);
            if (thisBlock.Components.Contains(typeof(MyResourceSinkComponent)))
            {
                IO.log("Power sinks already present in " + this + " #" + Entity.EntityId + ":");
                List <MyResourceSinkComponent> li = new List <MyResourceSinkComponent>();
                Dictionary <Type, MyComponentBase> .ValueCollection.Enumerator e = thisBlock.Components.GetEnumerator();
                while (e.MoveNext())
                {
                    if (e.Current is MyResourceSinkComponent)
                    {
                        MyResourceSinkComponent req = e.Current as MyResourceSinkComponent;
                        IO.log(">> " + req.GetType() + " needing " + req.MaxRequiredInput + ", of " + req.AcceptedResources.ToString());
                    }
                }
                thisBlock.Components.Remove <MyResourceSinkComponent>();
            }
            thisBlock.Components.Add(energySink);
            energySink.Update();

            thisBlock.IsWorkingChanged    += onWorkingChanged;
            thisBlock.AppendingCustomInfo += updateInfo;
            MyAPIGateway.TerminalControls.CustomControlGetter += filterControls;

            soundSource = new MultiSoundSource(thisBlock);

            IO.log("Loaded logic script " + this + " for block '" + thisBlock.CustomName + "' / '" + Entity.DisplayName + "' #" + Entity.EntityId + "; update rate = " + NeedsUpdate);
        }
        public override void UpdateOnceBeforeFrame()
        {
            m_functionalBlock = Entity as Sandbox.ModAPI.IMyFunctionalBlock;

            m_inventory = ((Sandbox.ModAPI.Ingame.IMyTerminalBlock)Entity).GetInventory(0) as IMyInventory;

            m_remoteEnergyBuilder = new MyObjectBuilder_Ingot()
            {
                SubtypeName = "RemoteEnergy"
            };

            m_reactor = Entity as Sandbox.ModAPI.IMyReactor;

            m_remoteEnergyId = new SerializableDefinitionId(typeof(MyObjectBuilder_Ingot), "RemoteEnergy");
        }
Пример #7
0
 private bool empBlock(IMySlimBlock slimBlock, IMyTerminalBlock block, double distance, bool sameGrid, EMPReaction reaction, bool forceDamage, bool forceDestroy)
 {
     /*
      * if (reaction == null) {
      *      MyAPIGateway.Utilities.ShowNotification("Block "+block.CustomName+" pulled null reaction?!", 5000, MyFontEnum.Red);
      *      return false;
      * }
      * if (slimBlock == null) {
      *      MyAPIGateway.Utilities.ShowNotification("Block "+block.CustomName+" has null slimblock?!", 5000, MyFontEnum.Red);
      *      return false;
      * }
      * if (block == null) {
      *      MyAPIGateway.Utilities.ShowNotification("Block "+slimBlock.BlockDefinition+" has null terminal block?!", 5000, MyFontEnum.Red);
      *      return false;
      * }*/
     try {
         bool disabled = false;
         if ((slimBlock is IMyDestroyableObject) && (forceDamage || rand.Next(5) == 0))
         {
             disabled = damageBlock(slimBlock, block, distance, forceDestroy);
         }
         else
         {
             IMyFunctionalBlock func = block as IMyFunctionalBlock;
             //func.ApplyAction("OnOff_Off");
             func.Enabled = false;
             func.UpdateIsWorking();
             //MyAPIGateway.Utilities.ShowNotification("EMP'd (on/off) block "+block.CustomName+" @ "+distance, 5000, MyFontEnum.Red);
             disabled = true;                     //always successfully handled in the first cycle
         }
         if (disabled && !sameGrid && reaction.MaxDowntimeIfRemote >= 0)
         {
             blockReactivations.Add(new SavedTimedBlock(block, reaction));
         }
         reaction.triggerEffect(block, rand);
         return(disabled);
     }
     catch (Exception ex) {
         MyAPIGateway.Utilities.ShowNotification("Could not EMP block " + block.CustomName + ": " + ex.ToString(), 5000, MyFontEnum.Red);
         IO.log("Threw exception EMPing block " + block.CustomName + ": " + ex.ToString());
         return(true);                //shut down to avoid constantly throwing exceptions
     }
 }
Пример #8
0
        public override void Init(MyObjectBuilder_EntityBase objectBuilder)
        {
            base.Init(objectBuilder);
            this.objectBuilder = objectBuilder;

            Entity.NeedsUpdate |= MyEntityUpdateEnum.BEFORE_NEXT_FRAME | MyEntityUpdateEnum.EACH_FRAME;

            functionalBlock = Entity as Sandbox.ModAPI.IMyFunctionalBlock;
            cubeBlock       = Entity as IMyCubeBlock;
            terminalBlock   = Entity as Sandbox.ModAPI.IMyTerminalBlock;

            subtypeName = functionalBlock.BlockDefinition.SubtypeName;

            getPulseWeaponInfo(subtypeName);
            initCharges();

            terminalBlock.AppendingCustomInfo += appendCustomInfo;


            cubeBlock.AddUpgradeValue("PowerEfficiency", 1.0f);
            cubeBlock.OnUpgradeValuesChanged += onUpgradeValuesChanged;
        }