コード例 #1
0
        /// <summary>
        /// Processes the slim-block, and provided its fat-block is a potential client-host, applies a client-base extension to it.
        /// </summary>
        /// <param name="slim">The slim block being processed for extension.</param>
        private void AttemptExtension(VRage.Game.ModAPI.IMySlimBlock slim)
        {
            // Set this to true/false to enabled/disable debug-logging in this method...
            bool watchMe = true;

            Note(watchMe, "Attempting extension...");
            Sandbox.ModAPI.IMyTerminalBlock block = slim.FatBlock as Sandbox.ModAPI.IMyTerminalBlock;
            if (block != null)
            {
                Note(watchMe, "Terminal block identified...");
                if (!CoreExtension.extensionSet.Any(kvp => kvp.Value.Host.EntityId == block.EntityId))
                {
                    DeployControlsForFatBlock(slim.FatBlock);
                    Note(watchMe, "Adding candidate extension to set...");
                    CoreExtension e = new CoreExtension(block);
                    CoreExtension.extensionSet.Add(block.EntityId, e);
                }
                else
                {
                    Note(watchMe, "Either incompatible or pre-extended block identified...");
                }
            }
            else
            {
                Note(watchMe, "Non-terminal block identified...");
            }
        }
コード例 #2
0
        private static void ToggleWeaponFire(IMyTerminalBlock weaponBlock, bool on, bool allWeapons = true, int weaponId = 0)
        {
            CoreComponent comp;

            if (weaponBlock.Components.TryGet(out comp) && comp.Platform.State == Ready && comp.Platform.Weapons.Length > weaponId)
            {
                for (int i = 0; i < comp.Platform.Weapons.Length; i++)
                {
                    if (!allWeapons && i != weaponId || !comp.Session.IsServer)
                    {
                        continue;
                    }

                    var w = comp.Platform.Weapons[i];

                    if (!on && w.State.Action == ShootOn)
                    {
                        w.State.WeaponMode(comp, ShootOff);
                        w.StopShooting();
                    }
                    else if (on && w.State.Action != ShootOff)
                    {
                        w.State.WeaponMode(comp, ShootOn);
                    }
                    else if (on)
                    {
                        w.State.WeaponMode(comp, ShootOn);
                    }
                }
            }
        }
コード例 #3
0
        private static void SetActiveAmmo(IMyTerminalBlock weaponBlock, int weaponId, string ammoTypeStr)
        {
            CoreComponent comp;

            if (weaponBlock.Components.TryGet(out comp) && comp.Session.IsServer && comp.Platform.State == Ready && comp.Platform.Weapons.Length > weaponId)
            {
                var w = comp.Platform.Weapons[weaponId];
                for (int i = 0; i < w.System.AmmoTypes.Length; i++)
                {
                    var ammoType = w.System.AmmoTypes[i];
                    if (ammoType.AmmoName == ammoTypeStr && ammoType.ConsumableDef.Const.IsTurretSelectable)
                    {
                        if (comp.Session.IsServer)
                        {
                            w.Ammo.AmmoTypeId = i;
                            if (comp.Session.MpActive)
                            {
                                comp.Session.SendWeaponReload(w);
                            }
                        }


                        break;
                    }
                }
            }
        }
コード例 #4
0
        public override void Init(MyObjectBuilder_EntityBase objectBuilder)
        {
            m_objectBuilder     = objectBuilder;
            Entity.NeedsUpdate |= MyEntityUpdateEnum.EACH_FRAME | MyEntityUpdateEnum.BEFORE_NEXT_FRAME;
            NeedsUpdate        |= MyEntityUpdateEnum.EACH_FRAME | MyEntityUpdateEnum.BEFORE_NEXT_FRAME;

            m_shieldType = getShieldType();

            IMyCubeBlock cubeBlock = Entity as IMyCubeBlock;


            cubeBlock.AddUpgradeValue("ShieldPoints", 1f);
            cubeBlock.AddUpgradeValue("ShieldRecharge", 1f);
            cubeBlock.AddUpgradeValue("PowerConsumption", 1f);

            Sandbox.ModAPI.IMyTerminalBlock terminalBlock = Entity as Sandbox.ModAPI.IMyTerminalBlock;

            terminalBlock.AppendingCustomInfo += UpdateBlockInfo;

            //debug
            if (!EnergyShieldsCore.shieldGenerators.ContainsKey(Entity.EntityId))
            {
                EnergyShieldsCore.shieldGenerators.TryAdd(Entity.EntityId, this);
            }
        }
コード例 #5
0
 public void appendCustomInfo(Sandbox.ModAPI.IMyTerminalBlock block, StringBuilder info)
 {
     info.Clear();
     info.AppendLine("Type: " + m_block.DefinitionDisplayNameText);
     info.AppendLine("Required input: " + _power.ToString("N") + " MW");
     info.AppendLine("Current input: " + _sink.CurrentInputByType(Electricity).ToString("N") + "MW");
 }
コード例 #6
0
 public void triggerEffect(IMyTerminalBlock block, Random rand)
 {
     if (runEffect != null && rand.Next(100) <= effectChance)
     {
         runEffect(block);
     }
 }
コード例 #7
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;
        }
コード例 #8
0
        private static void FireWeaponOnce(IMyTerminalBlock weaponBlock, bool allWeapons = true, int weaponId = 0)
        {
            CoreComponent comp;

            if (weaponBlock.Components.TryGet(out comp) && comp.Platform.State == Ready && comp.Platform.Weapons.Length > weaponId)
            {
                var foundWeapon = false;
                for (int i = 0; i < comp.Platform.Weapons.Length; i++)
                {
                    if (!allWeapons && i != weaponId)
                    {
                        continue;
                    }

                    foundWeapon = true;
                    comp.Platform.Weapons[i].State.WeaponMode(comp, ShootOnce);
                }

                if (foundWeapon)
                {
                    var weaponKey = allWeapons ? -1 : weaponId;
                    comp.ShootOnceCheck(weaponKey);
                }
            }
        }
コード例 #9
0
        public static MyCubeGrid GetLootboxGrid(Vector3 position, KothConfig config)
        {
            if (MyAPIGateway.Entities.GetEntityById(config.LootboxGridEntityId) != null)
            {
                if (MyAPIGateway.Entities.GetEntityById(config.LootboxGridEntityId) is MyCubeGrid grid)
                {
                    return(grid);
                }
            }
            BoundingSphereD sphere = new BoundingSphereD(position, config.CaptureRadiusInMetre + 5000);

            foreach (MyCubeGrid grid in MyAPIGateway.Entities.GetEntitiesInSphere(ref sphere).OfType <MyCubeGrid>())
            {
                IMyFaction fac = FacUtils.GetPlayersFaction(FacUtils.GetOwner(grid));
                if (fac != null && fac.Tag.Equals(config.KothBuildingOwner))
                {
                    Sandbox.ModAPI.IMyGridTerminalSystem gridTerminalSys = MyAPIGateway.TerminalActionsHelper.GetTerminalSystemForGrid(grid);

                    Sandbox.ModAPI.IMyTerminalBlock block = gridTerminalSys.GetBlockWithName(config.LootBoxTerminalName);
                    if (block != null)
                    {
                        return(grid);
                    }
                }
            }
            return(null);
        }
コード例 #10
0
ファイル: GeoThermal.cs プロジェクト: Blue64/Space_Engineers
 public override void Init(MyObjectBuilder_EntityBase objectBuilder)
 {
     //            base.Init(objectBuilder);
     Container.Entity.NeedsUpdate |= MyEntityUpdateEnum.EACH_FRAME | MyEntityUpdateEnum.EACH_100TH_FRAME;
     this.NeedsUpdate             |= MyEntityUpdateEnum.EACH_FRAME | MyEntityUpdateEnum.EACH_100TH_FRAME;
     turbine       = (Sandbox.ModAPI.IMyBatteryBlock)Entity;
     terminalBlock = Entity as Sandbox.ModAPI.IMyTerminalBlock;
 }
コード例 #11
0
        public void SaveBlockActions(IMyTerminalBlock block)
        {
            List <ITerminalAction> actions = new List <ITerminalAction>();
            var b = block;

            b.GetActions(actions);
            actions.ForEach(x => { Util.GetInstance().Log("[Drone.IsAlive] IMySmallGatlingGun actions -> " + x.Name, "actions.txt"); });
        }
コード例 #12
0
        public void UpdateBlockInfo(Sandbox.ModAPI.IMyTerminalBlock block, StringBuilder info)
        {
            info.Clear();
            info.AppendLine(" ");

            IMyCubeBlock cubeBlock = Entity as IMyCubeBlock;

            IMyGridTerminalSystem tsystem = MyAPIGateway.TerminalActionsHelper.GetTerminalSystemForGrid(cubeBlock.CubeGrid as IMyCubeGrid);


            if (tsystem != null)
            {
                List <IMyTerminalBlock> shieldsConnected = new List <IMyTerminalBlock> ();

                tsystem.GetBlocksOfType <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;
                }

                info.Append("Ship Shield: ");
                MyValueFormatter.AppendGenericInBestUnit(shipCurrentShieldPoints, info);
                info.Append("Pt/");
                MyValueFormatter.AppendGenericInBestUnit(shipMaximumShieldPoints, info);
                info.Append("Pt\n");
            }

            info.Append("Local Shield: ");
            MyValueFormatter.AppendGenericInBestUnit(m_currentShieldPoints, info);
            info.Append("Pt/");
            MyValueFormatter.AppendGenericInBestUnit(m_maximumShieldPoints, info);
            info.Append("Pt\n");

            info.Append("Recharge: ");
            MyValueFormatter.AppendGenericInBestUnit(m_pointsToRecharge * 60, info);
            info.Append("Pt/s ");
            if (EnergyShieldsCore.Config.AlternativeRechargeMode.Enable && (m_ticksUntilRecharge > 0))
            {
                info.Append("(" + (int)Math.Ceiling(m_ticksUntilRecharge / 60d) + "s)\n");
            }
            else
            {
                info.Append("\n");
            }

            info.Append("Effectivity: ");
            MyValueFormatter.AppendWorkInBestUnit(m_currentPowerConsumption, info);
            info.Append("/");
            MyValueFormatter.AppendWorkInBestUnit(m_setPowerConsumption, info);
            info.Append(" (" + (m_rechargeMultiplier * 100).ToString("N") + "%)");
        }
コード例 #13
0
        private static void DisableRequiredPower(IMyTerminalBlock weaponBlock)
        {
            CoreComponent comp;

            if (weaponBlock.Components.TryGet(out comp) && comp.Platform.State == Ready)
            {
                comp.UnlimitedPower = true;
            }
        }
コード例 #14
0
        private static void SetWeaponTarget(IMyTerminalBlock weaponBlock, IMyEntity target, int weaponId = 0)
        {
            CoreComponent comp;

            if (weaponBlock.Components.TryGet(out comp) && comp.Platform.State == Ready && comp.Platform.Weapons.Length > weaponId)
            {
                GridAi.AcquireTarget(comp.Platform.Weapons[weaponId], false, (MyEntity)target);
            }
        }
コード例 #15
0
 public void UpdatePrintBalanced()
 {
     if (!m_closed && Entity.InScene)
     {
         Sandbox.ModAPI.IMyTerminalBlock terminalBlock = Entity as Sandbox.ModAPI.IMyTerminalBlock;
         terminalBlock.RefreshCustomInfo();
         printShieldStatus();
     }
 }
コード例 #16
0
        public override void Init(MyObjectBuilder_EntityBase objectBuilder)
        {
            m_generator = Entity as Sandbox.ModAPI.IMyAssembler;
            builder     = objectBuilder;

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

            terminalBlock = Entity as Sandbox.ModAPI.IMyTerminalBlock;
        }
コード例 #17
0
        // Block EntityId, WeaponId, ProjectileId, LastHitId, LastPos, Start
        internal static void UnMonitorProjectileCallback(IMyTerminalBlock weaponBlock, int weaponId, Action <long, int, ulong, long, Vector3D, bool> callback)
        {
            CoreComponent comp;

            if (weaponBlock.Components.TryGet(out comp) && comp.Platform.Weapons.Length > weaponId)
            {
                comp.Monitors[weaponId].Remove(callback);
            }
        }
コード例 #18
0
        public static string VT_ETS_CORE_API(SM.IMyTerminalBlock b)
        {
            string documentation = @"
public class VT_ETS_CORE
{
    public static IMyGridTerminalSystem SYSTEM = null;

    bool initialized = false;

    const string Get_PID = ""VT.ETS.CORE.GetMethodSignatures"";

    const string Run_PID = ""VT.ETS.CORE.InvokeMethodSignature"";

    Delegate Get_DEL = null;

    Delegate Run_DEL = null;

    IMyTerminalBlock host = null;

    public IMyTerminalBlock Host { get { return host; } }

    protected VT_ETS_CORE() { }

    protected VT_ETS_CORE(long id)
    {
        if (SYSTEM != null)
        {
            host = SYSTEM.GetBlockWithId(id);
            if (host != null)
            {
                Get_DEL = host.GetValue<Delegate>(Get_PID);
                Run_DEL = host.GetValue<Delegate>(Run_PID);
                if (Get_DEL != null && Run_DEL != null) initialized = true;
            }
        }
    }

    public static bool Seek(long id, out VT_ETS_CORE target)
    {
        target = new VT_ETS_CORE(id);
        return target.initialized;
    }

    public List<string> GetSignatures()
    {
        return (List<string>)Get_DEL.DynamicInvoke();
    }

    public object RunSignature(string signature, params object[] arguments)
    {
        return Run_DEL.DynamicInvoke(signature, arguments);
    }
}";

            return(documentation);
        }
コード例 #19
0
        private static float GetHeatLevel(IMyTerminalBlock weaponBlock)
        {
            CoreComponent comp;

            if (weaponBlock.Components.TryGet(out comp) && comp.Platform.State == Ready && comp.MaxHeat > 0)
            {
                return(comp.CurrentHeat);
            }
            return(0f);
        }
コード例 #20
0
        public SavedTimedBlock(IMyTerminalBlock block, int time)
        {
            Position = block != null ? block.Position : new Vector3I(0, 0, 0);

            time *= 60;             //because 60 ticks per second, and this will be called every 100 ticks, with a -= 100 arg

            TotalTime      = time;
            TimeUntilReset = time;
            GridID         = block != null ? ((block.CubeGrid as IMyCubeGrid).EntityId) : -1;
        }
コード例 #21
0
        public override void Init(MyObjectBuilder_EntityBase objectBuilder)
        {
            m_generator = Entity as Sandbox.ModAPI.IMyCargoContainer;
            m_parent    = Entity as IMyCubeBlock;
            builder     = objectBuilder;

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

            terminalBlock = Entity as Sandbox.ModAPI.IMyTerminalBlock;
        }
コード例 #22
0
        internal long GetPlayerController(IMyTerminalBlock weaponBlock)
        {
            CoreComponent comp;

            if (weaponBlock.Components.TryGet(out comp) && comp.Platform.State == Ready)
            {
                return(comp.Data.Repo.Base.State.PlayerId);
            }

            return(-1);
        }
コード例 #23
0
 private void filterControls(IMyTerminalBlock block, List <IMyTerminalControl> controls)
 {
     foreach (IMyTerminalControl control in new List <IMyTerminalControl>(controls))
     {
         //MyAPIGateway.Utilities.ShowNotification(block.CustomName+" check "+control.Id+" > '"+lgc+"' & "+GetType());
         if (!ControlFuncs.isOptionApplicable(block, control, this))
         {
             controls.Remove(control);
         }
     }
 }
コード例 #24
0
        public static Delegate GetInclusionMethod(SM.IMyTerminalBlock b)
        {
            Delegate      value = null;
            CoreExtension e;

            if (extensionSet.TryGetValue(b.EntityId, out e))
            {
                value = e.includer;
            }
            return(value);
        }
コード例 #25
0
        private static float GetMaxWeaponRange(IMyTerminalBlock weaponBlock, int weaponId = 0)
        {
            CoreComponent comp;

            if (weaponBlock.Components.TryGet(out comp) && comp.Platform.State == Ready && comp.Platform.Weapons.Length > weaponId)
            {
                return((float)comp.Platform.Weapons[weaponId].MaxTargetDistance);
            }

            return(0f);
        }
コード例 #26
0
        public static bool isOptionApplicable(IMyTerminalBlock block, IMyTerminalControl control, LogicCore caller)
        {
            var    lgc  = block.GameLogic.GetAs <LogicCore>();
            string type = lgc != null?lgc.GetType().ToString() : null;

            string seek = getBlockTypeFilter(control);

            //if (seek != null)
            // MyAPIGateway.Utilities.ShowNotification(block.CustomName+" check "+control.Id+" > looking for '"+seek+"', have '"+type);
            return(seek == null || type == seek);
        }
コード例 #27
0
        private static float GetCurrentPower(IMyTerminalBlock weaponBlock)
        {
            CoreComponent comp;

            if (weaponBlock.Components.TryGet(out comp) && comp.Platform.State == Ready)
            {
                return(comp.SinkPower);
            }

            return(0f);
        }
コード例 #28
0
        private static string GetActiveAmmo(IMyTerminalBlock weaponBlock, int weaponId)
        {
            CoreComponent comp;

            if (weaponBlock.Components.TryGet(out comp) && comp.Platform.State == Ready && comp.Platform.Weapons.Length > weaponId)
            {
                return(comp.Platform.Weapons[weaponId].ActiveAmmoDef.ConsumableDef.AmmoRound);
            }

            return(null);
        }
コード例 #29
0
        internal MyTuple <Vector3D, Vector3D> GetWeaponScope(IMyTerminalBlock weaponBlock, int weaponId)
        {
            CoreComponent comp;

            if (weaponBlock.Components.TryGet(out comp) && comp.Platform.State == Ready && comp.Platform.Weapons.Length > weaponId)
            {
                var w    = comp.Platform.Weapons[weaponId];
                var info = w.GetScope.Info;
                return(new MyTuple <Vector3D, Vector3D>(info.Position, info.Direction));
            }
            return(new MyTuple <Vector3D, Vector3D>());
        }
コード例 #30
0
        internal Matrix GetWeaponElevationMatrix(IMyTerminalBlock weaponBlock, int weaponId = 0)
        {
            CoreComponent comp;

            if (weaponBlock.Components.TryGet(out comp) && comp.Platform.State == Ready)
            {
                var weapon = comp.Platform.Weapons[weaponId];
                var matrix = weapon.ElevationPart?.Entity?.PositionComp.LocalMatrixRef ?? Matrix.Zero;
                return(matrix);
            }

            return(Matrix.Zero);
        }
コード例 #31
0
 public void SaveBlockActions(IMyTerminalBlock block)
 {
     List<ITerminalAction> actions = new List<ITerminalAction>();
     var b = block;
     b.GetActions(actions);
     actions.ForEach(x => { Util.GetInstance().Log("[Drone.IsAlive] IMySmallGatlingGun actions -> " + x.Name, "actions.txt"); });
 }