public bool IsResearchUnlocked(MyCharacter character, MyDefinitionId id)
        {
            if (character == null)
            {
                return(true);
            }

            return(IsResearchUnlocked(character.GetPlayerIdentityId(), id));
        }
        public bool CanUse(MyCharacter character, MyDefinitionId id)
        {
            if (character == null)
            {
                return(true);
            }

            return(CanUse(character.GetPlayerIdentityId(), id));
        }
        public void ResetResearch(MyCharacter character)
        {
            if (character == null)
            {
                return;
            }

            ResetResearch(character.GetPlayerIdentityId());
        }
        public bool TryGetResearch(MyCharacter character, out HashSet <MyDefinitionId> research)
        {
            if (character == null)
            {
                research = null;
                return(false);
            }

            return(TryGetResearch(character.GetPlayerIdentityId(), out research));
        }
예제 #5
0
        private void OnFactionUse(UseActionEnum actionEnum, MyCharacter user)
        {
            bool readOnlyNotification = false;

            if (actionEnum == UseActionEnum.Manipulate)
            {
                var relation = GetUserRelationToOwner(user.GetPlayerIdentityId());

                if (relation == MyRelationsBetweenPlayerAndBlock.FactionShare)
                {
                    OpenWindow(true, true, true);
                }
                else
                {
                    OpenWindow(false, true, true);
                }
            }
            else if (actionEnum == UseActionEnum.OpenTerminal)
            {
                var relation = GetUserRelationToOwner(user.GetPlayerIdentityId());

                if (relation == MyRelationsBetweenPlayerAndBlock.FactionShare)
                {
                    MyGuiScreenTerminal.Show(MyTerminalPageEnum.ControlPanel, user, this);
                }
                else
                {
                    readOnlyNotification = true;
                }
            }

            if (user.ControllerInfo.Controller.Player == MySession.Static.LocalHumanPlayer)
            {
                if (readOnlyNotification)
                {
                    MyHud.Notifications.Add(MyNotificationSingletons.TextPanelReadOnly);
                }
            }
        }
        public bool UnlockResearch(MyCharacter character, MyDefinitionId id)
        {
            Debug.Assert(Sync.IsServer);
            if (character == null)
            {
                return(false);
            }

            var definition = MyDefinitionManager.Static.GetDefinition(id);
            SerializableDefinitionId serializableId = id;

            if (CanUnlockResearch(character.GetPlayerIdentityId(), definition))
            {
                MyMultiplayer.RaiseStaticEvent(x => UnlockResearchSuccess, character.GetPlayerIdentityId(), serializableId);
                return(true);
            }
            else if (character.ControllerInfo.Controller != null)
            {
                var endpoint = new EndpointId(character.ControllerInfo.Controller.Player.Client.SteamUserId);
                MyMultiplayer.RaiseStaticEvent(x => UnlockResearchFailed, serializableId, targetEndpoint: endpoint);
            }

            return(false);
        }
예제 #7
0
        void MyCharacter_OnCharacterDied(MyCharacter character)
        {
            MyEntity attacker;

            MyEntities.TryGetEntityById(character.StatComp.LastDamage.AttackerId, out attacker);

            if (character.GetPlayerIdentityId() != MySession.Static.LocalHumanPlayer.Identity.IdentityId &&                            //filter my dead
                character.StatComp.LastDamage.Type == MyDamageType.Bullet &&                                                           //filter dead by bullet
                (attacker is MyAutomaticRifleGun) &&                                                                                   //attacking by riflegun
                (attacker as MyAutomaticRifleGun).Owner.GetPlayerIdentityId() == MySession.Static.LocalHumanPlayer.Identity.IdentityId //Im attacker
                )
            {
                NotifyAchieved();
                MyCharacter.OnCharacterDied -= MyCharacter_OnCharacterDied;
            }
        }
예제 #8
0
        public bool GetGrids(Chat Response, MyCharacter character, string GridNameOREntityID = null)
        {
            if (!GridUtilities.FindGridList(GridNameOREntityID, character, out Grids))
            {
                Response.Respond("No grids found. Check your viewing angle or make sure you spelled right!");
                return(false);
            }

            if (!GridUtilities.BiggestGrid(Grids, out BiggestGrid))
            {
                Response.Respond("Grid incompatible!");
                return(false);
            }


            if (!IsAdmin && !BiggestGrid.BigOwners.Contains(character.GetPlayerIdentityId()))
            {
                Response.Respond("You are not the owner of the biggest grid!");
                return(false);
            }


            if (BiggestGrid.BigOwners.Count == 0)
            {
                BiggestOwner = 0;
            }
            else
            {
                BiggestOwner = BiggestGrid.BigOwners[0];
            }


            if (!GetOwner(BiggestOwner, out OwnerSteamID))
            {
                Response.Respond("Unable to get owners SteamID");
                return(false);
            }


            GridName = BiggestGrid.DisplayName;
            return(true);
        }
        public void DebugUnlockAllResearch(MyCharacter character)
        {
            if (character == null)
            {
                return;
            }

            long identityId = character.GetPlayerIdentityId();
            HashSet <MyDefinitionId> unlockedItems;

            if (!m_unlockedResearch.TryGetValue(identityId, out unlockedItems))
            {
                unlockedItems = new HashSet <MyDefinitionId>();
            }

            foreach (var research in m_requiredResearch)
            {
                unlockedItems.Add(research);
            }

            m_unlockedResearch[identityId] = unlockedItems;
        }
예제 #10
0
        private void MyCharacter_OnCharacterDied(MyCharacter character)
        {
            if (character.StatComp.LastDamage.Type != MyDamageType.Explosion) //Not an explosion
            {
                return;
            }

            //detect new explosion
            long lastAttackerID = character.StatComp.LastDamage.AttackerId;

            if (lastAttackerID != m_lastAttackerID)
            {
                m_someoneIsDead  = false;
                m_imDead         = false;
                m_lastAttackerID = lastAttackerID;
            }

            if (character.GetPlayerIdentityId() == MySession.Static.LocalHumanPlayer.Identity.IdentityId) //I died
            {
                m_imDead = true;
            }
            else if (character.IsPlayer)//someone died
            {
                m_someoneIsDead = true;
            }

            if (m_imDead &&                            // Im already dead
                m_someoneIsDead &&                     //someone died also
                m_lastAttackerID == lastAttackerID &&  //and we died by one explosion
                m_lastWarheadGrid == m_lastAttackerID) //and it is MY warhead what cause it
            {
                NotifyAchieved();
                MyCharacter.OnCharacterDied        -= MyCharacter_OnCharacterDied;
                MyWarhead.OnWarheadDetonatedClient -= MyWarhead_OnWarheadDetonatedClient;
            }
        }
        public override void UpdateGpsForPlayer(MyEntityTracker entity)
        {
            if (!(entity.Entity is MyCharacter))
            {
                return;
            }

            var settings = MySettingsSession.Static.Settings.GeneratorSettings.GPSSettings;

            if (settings.AsteroidGPSMode != MyGPSGenerationMode.DISCOVERY)
            {
                return;
            }

            var         objects = MyStarSystemGenerator.Static.StarSystem.GetAllObjects();
            MyCharacter player  = entity.Entity as MyCharacter;

            foreach (var obj in objects)
            {
                if (obj.Type != MySystemObjectType.ASTEROIDS)
                {
                    continue;
                }

                MySystemAsteroids asteroid       = obj as MySystemAsteroids;
                Vector3D          entityPosition = player.PositionComp.GetPosition();
                var provider = MyAsteroidObjectsManager.Static.AsteroidObjectProviders[asteroid.AsteroidTypeName];

                IMyAsteroidObjectShape shape = provider.GetAsteroidObjectShape(asteroid);

                if (shape == null)
                {
                    continue;
                }

                if (shape.Contains(entityPosition) != ContainmentType.Disjoint)
                {
                    MyGPSManager.Static.RemoveDynamicGps(player.GetPlayerIdentityId(), asteroid.Id);
                }

                Vector3D closestPos = shape.GetClosestPoint(entityPosition);
                double   distance   = Vector3D.Subtract(entityPosition, closestPos).Length();
                if (distance > 5000000)
                {
                    MyGPSManager.Static.RemoveDynamicGps(player.GetPlayerIdentityId(), asteroid.Id);
                }
                else if (distance > 5)
                {
                    if (MyGPSManager.Static.DynamicGpsExists(asteroid.Id, player.GetPlayerIdentityId()))
                    {
                        MyGPSManager.Static.ModifyDynamicGps(asteroid.DisplayName, Color.Yellow, closestPos, player.GetPlayerIdentityId(), asteroid.Id);
                        continue;
                    }
                    MyGPSManager.Static.AddDynamicGps(asteroid.DisplayName, Color.Yellow, closestPos, player.GetPlayerIdentityId(), asteroid.Id);
                }
                else
                {
                    MyGPSManager.Static.RemoveDynamicGps(player.GetPlayerIdentityId(), asteroid.Id);
                }
            }
        }
예제 #12
0
        public static void TestPatchMethod(MyDrillBase __instance, MyVoxelMaterialDefinition material,
                                           VRageMath.Vector3 hitPosition,
                                           int removedAmount,
                                           bool onlyCheck)
        {
            if (__instance.OutputInventory != null && __instance.OutputInventory.Owner != null)
            {
                if (__instance.OutputInventory.Owner.GetBaseEntity() is MyShipDrill shipDrill)
                {
                    if (drill == null)
                    {
                        drill = __instance.GetType();
                    }

                    if (string.IsNullOrEmpty(material.MinedOre))
                    {
                        return;
                    }

                    if (!onlyCheck)
                    {
                        long playerId    = 0;
                        bool HasContract = false;
                        foreach (IMyCockpit cockpit in shipDrill.CubeGrid.GetFatBlocks().OfType <IMyCockpit>())
                        {
                            if (cockpit.Pilot != null)
                            {
                                MyCharacter pilot = cockpit.Pilot as MyCharacter;
                                if (playerWithContract.ContainsKey(pilot.GetPlayerIdentityId()))
                                {
                                    PlayerStorage storage = playerWithContract[pilot.GetPlayerIdentityId()];
                                    if (storage.CheckIfInMiningArea(hitPosition, material.MinedOre))
                                    {
                                        playerId    = pilot.GetPlayerIdentityId();
                                        HasContract = true;
                                        break;
                                    }
                                }
                            }
                        }
                        if (!HasContract)
                        {
                            return;
                        }


                        MyObjectBuilder_Ore newObject = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_Ore>(material.MinedOre);
                        newObject.MaterialTypeName = new MyStringHash?(material.Id.SubtypeId);
                        float num = (float)((double)removedAmount / (double)byte.MaxValue * 1.0) * __instance.VoxelHarvestRatio * material.MinedOreRatio;
                        if (!MySession.Static.AmountMined.ContainsKey(material.MinedOre))
                        {
                            MySession.Static.AmountMined[material.MinedOre] = (MyFixedPoint)0;
                        }
                        MySession.Static.AmountMined[material.MinedOre] += (MyFixedPoint)num;
                        MyPhysicalItemDefinition physicalItemDefinition = MyDefinitionManager.Static.GetPhysicalItemDefinition((MyObjectBuilder_Base)newObject);
                        MyFixedPoint             amountItems1           = (MyFixedPoint)(num / physicalItemDefinition.Volume);
                        MyFixedPoint             maxAmountPerDrop       = (MyFixedPoint)(float)(0.150000005960464 / (double)physicalItemDefinition.Volume);


                        MyFixedPoint collectionRatio = (MyFixedPoint)drill.GetField("m_inventoryCollectionRatio", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(__instance);
                        MyFixedPoint b            = amountItems1 * ((MyFixedPoint)1 - collectionRatio);
                        MyFixedPoint amountItems2 = MyFixedPoint.Min(maxAmountPerDrop * 10 - (MyFixedPoint)0.001, b);
                        MyFixedPoint totalAmount  = amountItems1 * collectionRatio - amountItems2;
                        if (playerWithContract[playerId].AddToContractAmount(material.MinedOre, totalAmount.ToIntSafe()))
                        {
                            foreach (ContractHolder contractHolder in playerWithContract[playerId].MiningContracts.Values)
                            {
                                if (contractHolder.contract.subTypeId.Equals(material.MinedOre))
                                {
                                    ShipyardCommands.SendMessage("Big Boss Dave", "Contract progress :" + material.MinedOre + " " + contractHolder.minedAmount + " / " + contractHolder.amountToMine, Color.Gold, (long)MySession.Static.Players.TryGetSteamId(playerId));
                                }
                            }
                        }
                    }
                }
                else
                {
                    return;
                }
            }
        }
예제 #13
0
        public static bool IsRecievedByPlayer(MyCubeBlock cubeBlock)
        {
            MyCharacter localCharacter = MySession.Static.LocalCharacter;

            if (localCharacter == null)
            {
                return(false);
            }
            MyRadioReceiver radioReceiver = localCharacter.RadioReceiver;

            return(MyAntennaSystem.Static.CheckConnection((MyDataReceiver)radioReceiver, (VRage.Game.Entity.MyEntity)cubeBlock, localCharacter.GetPlayerIdentityId(), false));
        }
예제 #14
0
        public bool GetGrids(Chat Response, MyCharacter character, string GridNameOrEntity = null)
        {
            if (!GridUtilities.FindGridList(GridNameOrEntity, character, out Grids))
            {
                Response.Respond("No grids found. Check your viewing angle or make sure you spelled right!");
                return(false);
            }


            Grids.BiggestGrid(out BiggestGrid);
            if (BiggestGrid == null)
            {
                Response.Respond("Grid incompatible!");
                return(false);
            }


            if (!IsAdmin)
            {
                var  FatBlocks = BiggestGrid.GetFatBlocks().ToList();
                long OwnerID   = character.GetPlayerIdentityId();

                int TotalFatBlocks = 0;
                int OwnedFatBlocks = 0;


                foreach (var fat in FatBlocks)
                {
                    //Only count blocks with ownership
                    if (!fat.IsFunctional || fat.IDModule == null)
                    {
                        continue;
                    }


                    //WTF happened here?
                    //if (fat.OwnerId == 0)
                    //   Log.Error($"WTF: {fat.BlockDefinition.Id} - {fat.GetType()} - {fat.OwnerId}");


                    TotalFatBlocks++;

                    if (fat.OwnerId == OwnerID)
                    {
                        OwnedFatBlocks++;
                    }
                }


                double Percent = Math.Round((double)OwnedFatBlocks / TotalFatBlocks * 100, 3);
                int    TotalBlocksLeftNeeded = (TotalFatBlocks / 2) + 1 - (OwnedFatBlocks);

                if (Percent <= 50)
                {
                    Response.Respond($"You own {Percent}% of the biggest grid! Need {TotalBlocksLeftNeeded} more blocks to be the majority owner!");
                    return(false);
                }
            }
            else
            {
                //Compute biggest owner
            }


            if (BiggestGrid.BigOwners.Count == 0)
            {
                BiggestOwner = 0;
            }
            else
            {
                BiggestOwner = BiggestGrid.BigOwners[0];
            }


            if (!GetOwner(BiggestOwner, out OwnerSteamID))
            {
                Response.Respond("Unable to get owners SteamID! Are you an NPC?");
                return(false);
            }


            GridName = BiggestGrid.DisplayName;
            return(true);
        }
예제 #15
0
        protected bool CanHit(IMyHandToolComponent toolComponent, MyCharacterDetectorComponent detectorComponent, ref bool isBlock, out float hitEfficiency)
        {
            bool canHit = true;

            hitEfficiency = 1.0f;
            MyTuple <ushort, MyStringHash> message;

            // TODO(GoodAI/HonzaS): Take care when merging this line.
            // The null check was not encountered with hand tools different from the reward/punishment tool.
            if (detectorComponent.HitBody != null && detectorComponent.HitBody.UserObject is MyBlockingBody)
            {
                var blocking = detectorComponent.HitBody.UserObject as MyBlockingBody;
                if (blocking.HandTool.IsBlocking && blocking.HandTool.m_owner.StatComp != null &&
                    blocking.HandTool.m_owner.StatComp.CanDoAction(blocking.HandTool.m_shotHitCondition.StatsActionIfHit, out message))
                {
                    blocking.HandTool.m_owner.StatComp.DoAction(blocking.HandTool.m_shotHitCondition.StatsActionIfHit);
                    if (!string.IsNullOrEmpty(blocking.HandTool.m_shotHitCondition.StatsModifierIfHit))
                    {
                        blocking.HandTool.m_owner.StatComp.ApplyModifier(blocking.HandTool.m_shotHitCondition.StatsModifierIfHit);
                    }
                    isBlock = true;

                    if (!string.IsNullOrEmpty(blocking.HandTool.m_shotToolAction.Value.StatsEfficiency))
                    {
                        hitEfficiency = 1.0f - blocking.HandTool.m_owner.StatComp.GetEfficiencyModifier(blocking.HandTool.m_shotToolAction.Value.StatsEfficiency);
                    }
                    canHit = hitEfficiency > 0.0f;
                    MyEntityContainerEventExtensions.RaiseEntityEventOn(blocking.HandTool, MyStringHash.GetOrCompute("Hit"), new MyEntityContainerEventExtensions.HitParams(MyStringHash.GetOrCompute("Block"), this.PhysicalItemDefinition.Id.SubtypeId));
                }
            }
            if (!canHit)
            {
                hitEfficiency = 0.0f;
                return(canHit);
            }

            if (!string.IsNullOrEmpty(m_shotHitCondition.StatsActionIfHit))
            {
                canHit = m_owner.StatComp != null && m_owner.StatComp.CanDoAction(m_shotHitCondition.StatsActionIfHit, out message);
                if (!canHit)
                {
                    hitEfficiency = 0.0f;
                    return(canHit);
                }
            }

            float hitDistance = Vector3.Distance(detectorComponent.HitPosition, PositionComp.GetPosition());

            canHit = hitDistance <= m_toolItemDef.HitDistance;
            if (!canHit)
            {
                hitEfficiency = 0.0f;
                return(canHit);
            }

            // checking of player factions
            MyEntity attacker           = m_owner.Entity;
            long     attackerPlayerId   = m_owner.GetPlayerIdentityId();
            var      localPlayerFaction = MySession.Static.Factions.TryGetPlayerFaction(attackerPlayerId) as MyFaction;

            if (localPlayerFaction != null && !localPlayerFaction.EnableFriendlyFire)
            {
                // friendy fire isn't enabled in attacker faction
                IMyEntity   otherPlayerEntity = detectorComponent.DetectedEntity;
                MyCharacter otherPlayer       = otherPlayerEntity as MyCharacter;
                if (otherPlayer != null)
                {
                    bool sameFaction = localPlayerFaction.IsMember(otherPlayer.GetPlayerIdentityId());
                    canHit        = !sameFaction;
                    hitEfficiency = canHit ? hitEfficiency : 0.0f;
                }
            }
            return(canHit);
        }
예제 #16
0
        public static MyDetectedEntityInfo Create(MyEntity entity, long sensorOwner, Vector3D?hitPosition = new Vector3D?())
        {
            MyDetectedEntityType             type;
            MyRelationsBetweenPlayerAndBlock neutral;
            string displayName;

            if (entity == null)
            {
                return(new MyDetectedEntityInfo());
            }
            MatrixD      zero     = MatrixD.Zero;
            Vector3      velocity = (Vector3)Vector3D.Zero;
            int          totalGamePlayTimeInMilliseconds = MySandboxGame.TotalGamePlayTimeInMilliseconds;
            BoundingBoxD worldAABB = entity.PositionComp.WorldAABB;

            if (entity.Physics != null)
            {
                zero     = entity.Physics.GetWorldMatrix().GetOrientation();
                velocity = entity.Physics.LinearVelocity;
            }
            MyCubeGrid topMostParent = entity.GetTopMostParent(null) as MyCubeGrid;

            if (topMostParent != null)
            {
                type    = (topMostParent.GridSizeEnum != MyCubeSize.Small) ? MyDetectedEntityType.LargeGrid : MyDetectedEntityType.SmallGrid;
                neutral = (topMostParent.BigOwners.Count != 0) ? MyIDModule.GetRelation(sensorOwner, topMostParent.BigOwners[0], MyOwnershipShareModeEnum.Faction, MyRelationsBetweenPlayerAndBlock.Enemies, MyRelationsBetweenFactions.Enemies, MyRelationsBetweenPlayerAndBlock.FactionShare) : MyRelationsBetweenPlayerAndBlock.NoOwnership;
                if ((neutral == MyRelationsBetweenPlayerAndBlock.Owner) || (neutral == MyRelationsBetweenPlayerAndBlock.FactionShare))
                {
                    displayName = topMostParent.DisplayName;
                }
                else
                {
                    displayName = (topMostParent.GridSizeEnum != MyCubeSize.Small) ? MyTexts.GetString(MySpaceTexts.DetectedEntity_LargeGrid) : MyTexts.GetString(MySpaceTexts.DetectedEntity_SmallGrid);
                }
                zero = topMostParent.WorldMatrix.GetOrientation();
                return(new MyDetectedEntityInfo(topMostParent.EntityId, displayName, type, hitPosition, zero, topMostParent.Physics.LinearVelocity, neutral, worldAABB, (long)totalGamePlayTimeInMilliseconds));
            }
            MyCharacter character = entity as MyCharacter;

            if (character != null)
            {
                type    = !character.IsPlayer ? MyDetectedEntityType.CharacterOther : MyDetectedEntityType.CharacterHuman;
                neutral = MyIDModule.GetRelation(sensorOwner, character.GetPlayerIdentityId(), MyOwnershipShareModeEnum.Faction, MyRelationsBetweenPlayerAndBlock.Enemies, MyRelationsBetweenFactions.Enemies, MyRelationsBetweenPlayerAndBlock.FactionShare);
                if ((neutral == MyRelationsBetweenPlayerAndBlock.Owner) || (neutral == MyRelationsBetweenPlayerAndBlock.FactionShare))
                {
                    displayName = character.DisplayNameText;
                }
                else
                {
                    displayName = !character.IsPlayer ? MyTexts.GetString(MySpaceTexts.DetectedEntity_CharacterOther) : MyTexts.GetString(MySpaceTexts.DetectedEntity_CharacterHuman);
                }
                return(new MyDetectedEntityInfo(entity.EntityId, displayName, type, hitPosition, zero, velocity, neutral, character.Model.BoundingBox.Transform(character.WorldMatrix), (long)totalGamePlayTimeInMilliseconds));
            }
            neutral = MyRelationsBetweenPlayerAndBlock.Neutral;
            MyFloatingObject obj2 = entity as MyFloatingObject;

            if (obj2 != null)
            {
                displayName = obj2.Item.Content.SubtypeName;
                return(new MyDetectedEntityInfo(entity.EntityId, displayName, MyDetectedEntityType.FloatingObject, hitPosition, zero, velocity, neutral, worldAABB, (long)totalGamePlayTimeInMilliseconds));
            }
            MyInventoryBagEntity entity2 = entity as MyInventoryBagEntity;

            if (entity2 != null)
            {
                displayName = entity2.DisplayName;
                return(new MyDetectedEntityInfo(entity.EntityId, displayName, MyDetectedEntityType.FloatingObject, hitPosition, zero, velocity, neutral, worldAABB, (long)totalGamePlayTimeInMilliseconds));
            }
            MyPlanet planet = entity as MyPlanet;

            if (planet != null)
            {
                displayName = MyTexts.GetString(MySpaceTexts.DetectedEntity_Planet);
                return(new MyDetectedEntityInfo(entity.EntityId, displayName, MyDetectedEntityType.Planet, hitPosition, zero, velocity, neutral, BoundingBoxD.CreateFromSphere(new BoundingSphereD(planet.PositionComp.GetPosition(), (double)planet.MaximumRadius)), (long)totalGamePlayTimeInMilliseconds));
            }
            MyVoxelPhysics physics = entity as MyVoxelPhysics;

            if (physics != null)
            {
                displayName = MyTexts.GetString(MySpaceTexts.DetectedEntity_Planet);
                return(new MyDetectedEntityInfo(entity.EntityId, displayName, MyDetectedEntityType.Planet, hitPosition, zero, velocity, neutral, BoundingBoxD.CreateFromSphere(new BoundingSphereD(physics.Parent.PositionComp.GetPosition(), (double)physics.Parent.MaximumRadius)), (long)totalGamePlayTimeInMilliseconds));
            }
            if (entity is MyVoxelMap)
            {
                displayName = MyTexts.GetString(MySpaceTexts.DetectedEntity_Asteroid);
                return(new MyDetectedEntityInfo(entity.EntityId, displayName, MyDetectedEntityType.Asteroid, hitPosition, zero, velocity, neutral, worldAABB, (long)totalGamePlayTimeInMilliseconds));
            }
            if (entity is MyMeteor)
            {
                displayName = MyTexts.GetString(MySpaceTexts.DetectedEntity_Meteor);
                return(new MyDetectedEntityInfo(entity.EntityId, displayName, MyDetectedEntityType.Meteor, hitPosition, zero, velocity, neutral, worldAABB, (long)totalGamePlayTimeInMilliseconds));
            }
            if (entity is MyMissile)
            {
                return(new MyDetectedEntityInfo(entity.EntityId, entity.DisplayName, MyDetectedEntityType.Missile, hitPosition, zero, velocity, neutral, worldAABB, (long)totalGamePlayTimeInMilliseconds));
            }
            Vector3D?nullable    = null;
            MatrixD  orientation = new MatrixD();
            Vector3  vector2     = new Vector3();

            return(new MyDetectedEntityInfo(0L, string.Empty, MyDetectedEntityType.Unknown, nullable, orientation, vector2, MyRelationsBetweenPlayerAndBlock.NoOwnership, new BoundingBoxD(), (long)MySandboxGame.TotalGamePlayTimeInMilliseconds));
        }
예제 #17
0
        public static List <MyCubeGrid> FindGridList(string gridNameOrEntityId, MyCharacter character, Settings Config)
        {
            List <MyCubeGrid> grids = new List <MyCubeGrid>();

            if (gridNameOrEntityId == null && character == null)
            {
                return(new List <MyCubeGrid>());
            }



            if (Config.EnableSubGrids)
            {
                //If we include subgrids in the grid grab

                long EntitiyID = character.Entity.EntityId;


                ConcurrentBag <MyGroups <MyCubeGrid, MyGridPhysicalGroupData> .Group> groups;

                if (gridNameOrEntityId == null)
                {
                    groups = GridFinder.FindLookAtGridGroup(character);
                }
                else
                {
                    groups = GridFinder.FindGridGroup(gridNameOrEntityId);
                }

                if (groups.Count() > 1)
                {
                    return(null);
                }


                foreach (var group in groups)
                {
                    foreach (var node in group.Nodes)
                    {
                        MyCubeGrid Grid = node.NodeData;

                        if (Grid.Physics == null)
                        {
                            continue;
                        }

                        grids.Add(Grid);
                    }
                }



                for (int i = 0; i < grids.Count(); i++)
                {
                    MyCubeGrid grid = grids[i];

                    if (Config.AutoDisconnectGearConnectors && !grid.BigOwners.Contains(character.GetPlayerIdentityId()))
                    {
                        //This disabels enemy grids that have clamped on
                        Action ResetBlocks = new Action(delegate
                        {
                            foreach (MyLandingGear gear in grid.GetFatBlocks <MyLandingGear>())
                            {
                                gear.AutoLock = false;
                                gear.RequestLock(false);
                            }
                        });

                        Task Bool = GameEvents.InvokeActionAsync(ResetBlocks);
                        if (!Bool.Wait(1000))
                        {
                            return(null);
                        }
                    }
                    else if (Config.AutoDisconnectGearConnectors && grid.BigOwners.Contains(character.GetPlayerIdentityId()))
                    {
                        //This will check to see
                        Action ResetBlocks = new Action(delegate
                        {
                            foreach (MyLandingGear gear in grid.GetFatBlocks <MyLandingGear>())
                            {
                                IMyEntity Entity = gear.GetAttachedEntity();
                                if (Entity == null || Entity.EntityId == 0)
                                {
                                    continue;
                                }


                                //Should prevent entity attachments with voxels
                                if (!(Entity is MyCubeGrid))
                                {
                                    //If grid is attacted to voxel or something
                                    gear.AutoLock = false;
                                    gear.RequestLock(false);

                                    continue;
                                }

                                MyCubeGrid attactedGrid = (MyCubeGrid)Entity;

                                //If the attaced grid is enemy
                                if (!attactedGrid.BigOwners.Contains(character.GetPlayerIdentityId()))
                                {
                                    gear.AutoLock = false;
                                    gear.RequestLock(false);
                                }
                            }
                        });

                        Task Bool = GameEvents.InvokeActionAsync(ResetBlocks);
                        if (!Bool.Wait(1000))
                        {
                            return(null);
                        }
                    }
                }


                for (int i = 0; i < grids.Count(); i++)
                {
                    if (!grids[i].BigOwners.Contains(character.GetPlayerIdentityId()))
                    {
                        grids.RemoveAt(i);
                    }
                }
            }
            else
            {
                ConcurrentBag <MyGroups <MyCubeGrid, MyGridMechanicalGroupData> .Group> groups;

                if (gridNameOrEntityId == null)
                {
                    groups = GridFinder.FindLookAtGridGroupMechanical(character);
                }
                else
                {
                    groups = GridFinder.FindGridGroupMechanical(gridNameOrEntityId);
                }


                if (groups.Count > 1)
                {
                    return(null);
                }



                Action ResetBlocks = new Action(delegate
                {
                    foreach (var group in groups)
                    {
                        foreach (var node in group.Nodes)
                        {
                            MyCubeGrid grid = node.NodeData;


                            foreach (MyLandingGear gear in grid.GetFatBlocks <MyLandingGear>())
                            {
                                gear.AutoLock = false;
                                gear.RequestLock(false);
                            }


                            if (grid.Physics == null)
                            {
                                continue;
                            }

                            grids.Add(grid);
                        }
                    }
                });

                Task Bool = GameEvents.InvokeActionAsync(ResetBlocks);
                if (!Bool.Wait(1000))
                {
                    return(null);
                }
            }

            return(grids);
        }