Exemple #1
0
        private static bool CheckConcealForce(IMyCubeGrid grid, ulong steamId)
        {
            List <IMySlimBlock> blocks = new List <IMySlimBlock>();

            // Live dangerously
            grid.GetBlocks(blocks, x => x.FatBlock != null);
            foreach (IMySlimBlock block in blocks)
            {
                IMyCubeBlock cubeBlock = block.FatBlock;

                if (cubeBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_MedicalRoom))
                {
                    MyObjectBuilder_MedicalRoom medical = (MyObjectBuilder_MedicalRoom)cubeBlock.GetObjectBuilderCubeBlock();

                    if (!medical.Enabled)
                    {
                        continue;
                    }

                    IMyTerminalBlock terminalBlock = (IMyTerminalBlock)cubeBlock;
                    long             playerId      = PlayerMap.Instance.GetFastPlayerIdFromSteamId(steamId);
                    if (medical.Owner == playerId || (medical.ShareMode == MyOwnershipShareModeEnum.Faction && Player.CheckPlayerSameFaction(medical.Owner, playerId)))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
        private bool Activate(Sandbox.ModAPI.Ingame.IMyTerminalBlock pbBlock)
        {
            var dict = pbBlock.GetProperty("WcPbAPI")?.As <Dictionary <string, Delegate> >().GetValue(pbBlock);

            if (dict == null)
            {
                throw new Exception($"WcPbAPI failed to activate");
            }
            return(ApiAssign(dict));
        }
Exemple #3
0
        public static ITerminalProperty GetVirtualProperty(this Sandbox.ModAPI.Ingame.IMyTerminalBlock block, string id, bool copy = false)
        {
            var key = block.GetVirtualBlockKey();

            if (key > 0)
            {
                SEASessionManager.IVirtualTerminalProperty property = virtualPropertis[key].FirstOrDefault(x => string.Equals(x.Id, id, StringComparison.OrdinalIgnoreCase));
                return(property == null ? null : (copy ? property.Copy(block) : property));
            }

            return(null);
        }
Exemple #4
0
        public static void GetVirtualProperties(this Sandbox.ModAPI.Ingame.IMyTerminalBlock block, List <ITerminalProperty> resultList, Func <ITerminalProperty, bool> collect = null)
        {
            if (resultList == null)
            {
                resultList = new List <ITerminalProperty>();
            }

            var key = block.GetVirtualBlockKey();

            if (key > 0)
            {
                resultList.AddRange(virtualPropertis[key].Where(collect));
            }
        }
Exemple #5
0
 public string GetStoreWord(Sandbox.ModAPI.Ingame.IMyTerminalBlock store, string word)
 {
     if (store.CustomData == null || !store.CustomData.Contains(word))
     {
         return(null);
     }
     string[] lines = store.CustomData.Split('\n');
     foreach (string l in lines)
     {
         if (l.StartsWith(word))
         {
             return(l.Replace(word, ""));
         }
     }
     return(null);
 }
Exemple #6
0
            private bool cacheBlock(IMyTerminalBlock block, Dictionary <string, List <IMyTerminalBlock> > blocks)
            {
                string sec = getSection(block);

                if (sec != null)
                {
                    List <IMyTerminalBlock> li = null;
                    blocks.TryGetValue(sec, out li);
                    if (li == null)
                    {
                        li = new List <IMyTerminalBlock>();
                        blocks.Add(sec, li);
                    }
                    li.Add(block);
                }
                return(false);                //never actually collect into discarded list
            }
Exemple #7
0
 private static uint GetVirtualBlockKey(this Sandbox.ModAPI.Ingame.IMyTerminalBlock block)
 {
     if (block is Sandbox.ModAPI.Ingame.IMyMotorStator)
     {
         return(1);
     }
     else if (block is Sandbox.ModAPI.Ingame.IMyMotorAdvancedStator)
     {
         return(2);
     }
     else if (block is Sandbox.ModAPI.Ingame.IMyPistonBase)
     {
         return(3);
     }
     else
     {
         return(0);
     }
 }
Exemple #8
0
        //parse Custom Data
        public static Dictionary <string, string> ParseCustomData(IMyTerminalBlock Block, Dictionary <string, string> Settings) //Get current CustomData and parse values requested by the dictionary.
        {
            var CustomData         = new Dictionary <string, string>();                                                         //Original Data
            var CustomDataSettings = new Dictionary <string, string>();                                                         //Parsed Data

            string[] CustomDataLines = Block.CustomData.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
            for (var i = 0; i < CustomDataLines.Length; i++)   //scan and prepare Custom Data for matching
            {
                var    line = CustomDataLines[i];
                string value;
                var    pos = line.IndexOf('=');
                if (pos > -1)
                {
                    value = line.Substring(pos + 1).Trim();
                    line  = line.Substring(0, pos).Trim();
                }
                else
                {
                    value = "";
                }

                CustomData.Add(line, value); //Save the setting
            }

            foreach (var Setting in Settings)
            {
                if (CustomData.ContainsKey(Setting.Key))
                {
                    CustomDataSettings.Add(Setting.Key, CustomData[Setting.Key]);
                }
                else
                {
                    CustomDataSettings.Add(Setting.Key, Setting.Value);
                    Block.CustomData += "\n" + Setting.Key + " = " + Setting.Value;
                }
            }

            return(CustomDataSettings);
        }
Exemple #9
0
            private string getSection(IMyTerminalBlock block)
            {
                if (block.CubeGrid != caller.Me.CubeGrid)
                {
                    return(null);
                }

                string id = null;

                if (block is IMyAirVent)
                {
                    id = VENT_ID;
                }
                else if (block is IMyLightingBlock)
                {
                    id = LIGHT_ID;
                }
                else if (block is IMySoundBlock)
                {
                    id = SOUND_ID;
                }

                if (id == null || !block.CustomName.Contains(id) || block.CustomName.Contains(EXTERNAL_BLOCK_ID))
                {
                    return(null);
                }

                string repl = block.CustomName.Replace(id, "");

                while (repl[0] == ' ' || repl[0] == ':' || repl[0] == '-')
                {
                    repl = repl.Substring(1);
                }
                while (repl[repl.Length - 1] == ' ' || repl[repl.Length - 1] == ':' || repl[repl.Length - 1] == '-' || char.IsNumber(repl[repl.Length - 1]))
                {
                    repl = repl.Substring(0, repl.Length - 1);
                }
                return(repl);
            }
Exemple #10
0
 public bool HasCoreWeapon(Sandbox.ModAPI.Ingame.IMyTerminalBlock weapon) => _hasCoreWeapon?.Invoke(weapon) ?? false;
Exemple #11
0
 public string GetActiveAmmo(Sandbox.ModAPI.Ingame.IMyTerminalBlock weapon, int weaponId) =>
 _getActiveAmmo?.Invoke(weapon, weaponId) ?? null;
Exemple #12
0
 public float GetHeatLevel(Sandbox.ModAPI.Ingame.IMyTerminalBlock weapon) => _getHeatLevel?.Invoke(weapon) ?? 0f;
Exemple #13
0
 public float GetCurrentPower(Sandbox.ModAPI.Ingame.IMyTerminalBlock weapon) => _currentPowerConsumption?.Invoke(weapon) ?? 0f;
Exemple #14
0
 public bool CanShootTarget(Sandbox.ModAPI.Ingame.IMyTerminalBlock weapon, long targetEnt, int weaponId) =>
 _canShootTarget?.Invoke(weapon, targetEnt, weaponId) ?? false;
Exemple #15
0
 public Vector3D?GetPredictedTargetPosition(Sandbox.ModAPI.Ingame.IMyTerminalBlock weapon, long targetEnt, int weaponId) =>
 _getPredictedTargetPos?.Invoke(weapon, targetEnt, weaponId) ?? null;
Exemple #16
0
 public Matrix GetWeaponElevationMatrix(Sandbox.ModAPI.Ingame.IMyTerminalBlock weapon, int weaponId) =>
 _getWeaponElevationMatrix?.Invoke(weapon, weaponId) ?? Matrix.Zero;
Exemple #17
0
 public bool GetBlockWeaponMap(Sandbox.ModAPI.Ingame.IMyTerminalBlock weaponBlock, IDictionary <string, int> collection) =>
 _getBlockWeaponMap?.Invoke(weaponBlock, collection) ?? false;
Exemple #18
0
 public float GetMaxWeaponRange(Sandbox.ModAPI.Ingame.IMyTerminalBlock weapon, int weaponId) =>
 _getMaxWeaponRange?.Invoke(weapon, weaponId) ?? 0f;
Exemple #19
0
 public void SetActiveAmmo(Sandbox.ModAPI.Ingame.IMyTerminalBlock weapon, int weaponId, string ammoType) =>
 _setActiveAmmo?.Invoke(weapon, weaponId, ammoType);
Exemple #20
0
 public bool IsWeaponReadyToFire(Sandbox.ModAPI.Ingame.IMyTerminalBlock weapon, int weaponId = 0, bool anyWeaponReady = true,
                                 bool shootReady = false) =>
 _isWeaponReadyToFire?.Invoke(weapon, weaponId, anyWeaponReady, shootReady) ?? false;
Exemple #21
0
 public void ToggleWeaponFire(Sandbox.ModAPI.Ingame.IMyTerminalBlock weapon, bool on, bool allWeapons, int weaponId = 0) =>
 _toggleWeaponFire?.Invoke(weapon, on, allWeapons, weaponId);
Exemple #22
0
 public void FireWeaponOnce(Sandbox.ModAPI.Ingame.IMyTerminalBlock weapon, bool allWeapons = true, int weaponId = 0) =>
 _fireWeaponOnce?.Invoke(weapon, allWeapons, weaponId);
Exemple #23
0
 public void SetWeaponTarget(Sandbox.ModAPI.Ingame.IMyTerminalBlock weapon, long target, int weaponId = 0) =>
 _setWeaponTarget?.Invoke(weapon, target, weaponId);
Exemple #24
0
 public MyDetectedEntityInfo?GetWeaponTarget(Sandbox.ModAPI.Ingame.IMyTerminalBlock weapon, int weaponId = 0) =>
 _getWeaponTarget?.Invoke(weapon, weaponId);
Exemple #25
0
 public long GetPlayerController(Sandbox.ModAPI.Ingame.IMyTerminalBlock weapon) => _getPlayerController?.Invoke(weapon) ?? -1;
Exemple #26
0
        private static bool CheckConcealBlockRules(IMyCubeGrid grid, List <IMyPlayer> players)
        {
            List <IMySlimBlock> blocks = new List <IMySlimBlock>();

            // Live dangerously
            grid.GetBlocks(blocks, x => x.FatBlock != null);
            //CubeGrids.GetAllConnectedBlocks(_processedGrids, grid, blocks, x => x.FatBlock != null);

            int beaconCount = 0;

            //bool found = false;
            //bool powered = false;
            foreach (IMySlimBlock block in blocks)
            {
                IMyCubeBlock cubeBlock = block.FatBlock;

                if (cubeBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_Beacon))
                {
                    IMyBeacon beacon = (IMyBeacon)cubeBlock;
                    //MyObjectBuilder_Beacon beacon = (MyObjectBuilder_Beacon)cubeBlock.GetObjectBuilderCubeBlock();
                    beaconCount++;
                    // Keep this return here, as 4 beacons always means true
                    if (beaconCount >= 4)
                    {
                        return(true);
                    }

                    if (!beacon.Enabled)
                    {
                        continue;
                    }

                    IMyTerminalBlock terminalBlock = (IMyTerminalBlock)cubeBlock;
//					Console.WriteLine("Found: {0} {1} {2}", beacon.BroadcastRadius, terminalBlock.IsWorking, terminalBlock.IsFunctional);
                    //if (!terminalBlock.IsWorking)
                    //{
//						continue;
                    //}

                    foreach (IMyPlayer player in players)
                    {
                        double distance = 0d;
                        if (Entity.GetDistanceBetweenPointAndPlayer(grid.GetPosition(), player, out distance))
                        {
                            if (distance < beacon.Radius)
                            {
//								Console.WriteLine("Not concealed due to broadcast radius");
                                //found = true;
                                //break;
                                return(true);
                            }
                        }
                    }
                }

                if (cubeBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_RadioAntenna))
                {
                    //MyObjectBuilder_RadioAntenna antenna = (MyObjectBuilder_RadioAntenna)cubeBlock.GetObjectBuilderCubeBlock();
                    IMyRadioAntenna antenna = (IMyRadioAntenna)cubeBlock;

                    if (!antenna.Enabled)
                    {
                        continue;
                    }

                    IMyTerminalBlock terminalBlock = (IMyTerminalBlock)cubeBlock;
                    //if (!terminalBlock.IsWorking)
                    //	continue;

                    foreach (IMyPlayer player in players)
                    {
                        double distance = 0d;
                        if (Entity.GetDistanceBetweenPointAndPlayer(grid.GetPosition(), player, out distance))
                        {
                            if (distance < antenna.Radius)
                            {
//								Console.WriteLine("Not concealed due to antenna broadcast radius");
                                //found = true;
                                //break;
                                return(true);
                            }
                        }
                    }
                }

                if (cubeBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_MedicalRoom))
                {
                    //MyObjectBuilder_MedicalRoom medical = (MyObjectBuilder_MedicalRoom)cubeBlock.GetObjectBuilderCubeBlock();
                    IMyMedicalRoom medical = (IMyMedicalRoom)cubeBlock;

                    if (!medical.Enabled)
                    {
                        continue;
                    }

                    IMyFunctionalBlock functionalBlock = (IMyFunctionalBlock)cubeBlock;
                    //if (!terminalBlock.IsWorking)
                    //	continue;

                    if (PluginSettings.Instance.DynamicConcealIncludeMedBays)
                    {
                        lock (Online)
                        {
                            foreach (ulong connectedPlayer in Online)
                            {
                                //if (PlayerMap.Instance.GetPlayerIdsFromSteamId(connectedPlayer).Count < 1)
                                //continue;

                                //long playerId = PlayerMap.Instance.GetPlayerIdsFromSteamId(connectedPlayer).First();
                                long playerId = PlayerMap.Instance.GetFastPlayerIdFromSteamId(connectedPlayer);

                                if (functionalBlock.OwnerId == playerId || (functionalBlock.GetUserRelationToOwner(playerId) == MyRelationsBetweenPlayerAndBlock.FactionShare))
                                //if (functionalBlock.Owner == playerId || (functionalBlock.ShareMode == MyOwnershipShareModeEnum.Faction && Player.CheckPlayerSameFaction(functionalBlock.Owner, playerId)))
                                //if (medical.HasPlayerAccess(playerId))
                                {
                                    return(true);
                                }
                            }
                        }

                        /*
                         * foreach (ulong connectedPlayer in PlayerManager.Instance.ConnectedPlayers)
                         * {
                         *      //if (PlayerMap.Instance.GetPlayerIdsFromSteamId(connectedPlayer).Count < 1)
                         *              //continue;
                         *
                         *      //long playerId = PlayerMap.Instance.GetPlayerIdsFromSteamId(connectedPlayer).First();
                         *      long playerId = PlayerMap.Instance.GetFastPlayerIdFromSteamId(connectedPlayer);
                         *      //if (medical.Owner == playerId || (medical.ShareMode == MyOwnershipShareModeEnum.Faction && Player.CheckPlayerSameFaction(medical.Owner, playerId)))
                         *      if(medical.HasPlayerAccess(playerId))
                         *      {
                         *              return true;
                         *      }
                         * }
                         */
                    }
                    else
                    {
                        return(true);
                    }
                }

                if (cubeBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_Refinery) || cubeBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_Assembler))
                {
                    //MyObjectBuilder_ProductionBlock production = (MyObjectBuilder_ProductionBlock)cubeBlock.GetObjectBuilderCubeBlock();
                    IMyProductionBlock production = (IMyProductionBlock)cubeBlock;
                    if (!production.Enabled)
                    {
                        continue;
                    }

                    if (production.IsProducing)
                    {
                        return(true);
                    }
                }

                foreach (string subType in PluginSettings.Instance.DynamicConcealIgnoreSubTypeList)
                {
                    if (cubeBlock.BlockDefinition.SubtypeName.Contains(subType))
                    {
//						Console.WriteLine("Not concealed due subtype");
                        //found = true;
                        return(true);
                    }
                }
            }

            return(false);
        }
Exemple #27
0
 public void SetBlockTrackingRange(Sandbox.ModAPI.Ingame.IMyTerminalBlock weapon, float range) =>
 _setBlockTrackingRange?.Invoke(weapon, range);
Exemple #28
0
 public static bool AccesIsAllowed(this Sandbox.ModAPI.Ingame.IMyTerminalBlock self, long playerId)
 {
     return(allowAcces.Contains(self.GetUserRelationToOwner(playerId)));
 }
Exemple #29
0
 public void SetTurretTargetTypes(Sandbox.ModAPI.Ingame.IMyTerminalBlock weapon, IList <string> collection, int weaponId = 0) =>
 _setTurretTargetTypes?.Invoke(weapon, collection, weaponId);
Exemple #30
0
 public bool IsTargetAligned(Sandbox.ModAPI.Ingame.IMyTerminalBlock weapon, long targetEnt, int weaponId) =>
 _isTargetAligned?.Invoke(weapon, targetEnt, weaponId) ?? false;