Exemple #1
0
        public static MyRelationsBetweenPlayerAndBlock GetRelationBetweenPlayers(long playerId1, long playerId2)
        {
            if (playerId1 == playerId2)
            {
                return(MyRelationsBetweenPlayerAndBlock.Owner);
            }

            var faction1 = MySession.Static.Factions.TryGetPlayerFaction(playerId1);
            var faction2 = MySession.Static.Factions.TryGetPlayerFaction(playerId2);

            if (faction1 == null || faction2 == null)
            {
                return(MyRelationsBetweenPlayerAndBlock.Enemies);
            }

            if (faction1 == faction2)
            {
                return(MyRelationsBetweenPlayerAndBlock.FactionShare);
            }

            MyRelationsBetweenFactions relation = MySession.Static.Factions.GetRelationBetweenFactions(faction1.FactionId, faction2.FactionId);

            if (relation == MyRelationsBetweenFactions.Neutral)
            {
                return(MyRelationsBetweenPlayerAndBlock.Neutral);
            }

            return(MyRelationsBetweenPlayerAndBlock.Enemies);
        }
Exemple #2
0
        public static MyRelationsBetweenPlayers GetRelationsBetweenPlayers(long playerId1, long playerId2)
        {
            if (playerId1 == 0 || playerId2 == 0)
            {
                return(MyRelationsBetweenPlayers.Neutral);
            }
            if (playerId1 == playerId2)
            {
                return(MyRelationsBetweenPlayers.Self);
            }

            var faction1 = MySession.Static.Factions.TryGetPlayerFaction(playerId1);
            var faction2 = MySession.Static.Factions.TryGetPlayerFaction(playerId2);

            if (faction1 == null || faction2 == null)
            {
                return(MyRelationsBetweenPlayers.Enemies);
            }

            if (faction1 == faction2)
            {
                return(MyRelationsBetweenPlayers.Allies);
            }

            MyRelationsBetweenFactions relation = MySession.Static.Factions.GetRelationBetweenFactions(faction1.FactionId, faction2.FactionId);

            if (relation == MyRelationsBetweenFactions.Neutral)
            {
                return(MyRelationsBetweenPlayers.Neutral);
            }

            return(MyRelationsBetweenPlayers.Enemies);
        }
        public Boolean CheckGrids(Vector3 Position, long PlayerIdentityId)
        {
            MyFaction       PlayersFaction = MySession.Static.Factions.GetPlayerFaction(PlayerIdentityId);
            BoundingSphereD sphere         = new BoundingSphereD(Position, 15000);

            foreach (MyCubeGrid grid in MyAPIGateway.Entities.GetEntitiesInSphere(ref sphere).OfType <MyCubeGrid>())
            {
                if (FacUtils.IsOwnerOrFactionOwned(grid, PlayerIdentityId, true))
                {
                    continue;
                }

                if (grid.Projector != null)
                {
                    continue;
                }

                MyFaction CheckFaction = MySession.Static.Factions.GetPlayerFaction(FacUtils.GetOwner(grid));
                if (PlayersFaction != null && CheckFaction != null)
                {
                    MyRelationsBetweenFactions Relation = MySession.Static.Factions.GetRelationBetweenFactions(PlayersFaction.FactionId, CheckFaction.FactionId).Item1;
                    if (Relation == MyRelationsBetweenFactions.Neutral || Relation == MyRelationsBetweenFactions.Friends)
                    {
                        continue;
                    }
                }

                if (Vector3D.Distance(Position, grid.PositionComp.GetPosition()) <= 15000)
                {
                    return(false);
                }
            }
            return(true);
        }
Exemple #4
0
        // NOTE copied from Sandbox.Game.World.MyPlayer because it's not exposed
        static MyRelationsBetweenPlayerAndBlock GetRelationBetweenPlayers(long id1, long id2)
        {
            if (id1 == id2)
            {
                return(MyRelationsBetweenPlayerAndBlock.Owner);
            }

            IMyFaction f1 = MyAPIGateway.Session.Factions.TryGetPlayerFaction(id1);
            IMyFaction f2 = MyAPIGateway.Session.Factions.TryGetPlayerFaction(id2);

            if (f1 == null || f2 == null)
            {
                return(MyRelationsBetweenPlayerAndBlock.Enemies);
            }

            if (f1 == f2)
            {
                return(MyRelationsBetweenPlayerAndBlock.FactionShare);
            }

            MyRelationsBetweenFactions factionRelation = MyAPIGateway.Session.Factions.GetRelationBetweenFactions(f1.FactionId, f2.FactionId);

            if (factionRelation == MyRelationsBetweenFactions.Neutral)
            {
                return(MyRelationsBetweenPlayerAndBlock.Neutral);
            }

            return(MyRelationsBetweenPlayerAndBlock.Enemies);
        }
Exemple #5
0
        protected override void Init(MyObjectBuilder_DefinitionBase builder)
        {
            base.Init(builder);
            MyObjectBuilder_FactionDefinition definition = builder as MyObjectBuilder_FactionDefinition;

            this.Tag                = definition.Tag;
            this.Name               = definition.Name;
            this.Founder            = definition.Founder;
            this.AcceptHumans       = definition.AcceptHumans;
            this.AutoAcceptMember   = definition.AutoAcceptMember;
            this.EnableFriendlyFire = definition.EnableFriendlyFire;
            this.IsDefault          = definition.IsDefault;
            this.DefaultRelation    = definition.DefaultRelation;
        }
Exemple #6
0
        protected override void Init(MyObjectBuilder_DefinitionBase builder)
        {
            base.Init(builder);

            var ob = builder as MyObjectBuilder_FactionDefinition;

            Tag                = ob.Tag;
            Name               = ob.Name;
            Founder            = ob.Founder;
            AcceptHumans       = ob.AcceptHumans;
            AutoAcceptMember   = ob.AutoAcceptMember;
            EnableFriendlyFire = ob.EnableFriendlyFire;
            IsDefault          = ob.IsDefault;
            DefaultRelation    = ob.DefaultRelation;
        }
Exemple #7
0
        /// <summary>
        /// Determines what kind of faction change request should be used depending on default faction
        /// relation to other ones.
        /// </summary>
        /// <returns></returns>
        private static MyFactionStateChange DetermineRequestFromRelation(MyRelationsBetweenFactions relation)
        {
            MyFactionStateChange stateChange;

            if (relation == MyRelationsBetweenFactions.Enemies)
            {
                stateChange = MyFactionStateChange.DeclareWar;
            }
            else
            {
                stateChange = MyFactionStateChange.SendPeaceRequest;
            }

            return(stateChange);
        }
        protected override void Init(MyObjectBuilder_DefinitionBase builder)
        {
            base.Init(builder);

            var ob = builder as MyObjectBuilder_FactionDefinition;

            Tag = ob.Tag;
            Name = ob.Name;
            Founder = ob.Founder;
            AcceptHumans = ob.AcceptHumans;
            AutoAcceptMember = ob.AutoAcceptMember;
            EnableFriendlyFire = ob.EnableFriendlyFire;
            IsDefault = ob.IsDefault;
            DefaultRelation = ob.DefaultRelation;
        }
        public Boolean CheckCharacters(Vector3 Position, long PlayerIdentityId)
        {
            MyFaction PlayersFaction = MySession.Static.Factions.GetPlayerFaction(PlayerIdentityId);

            foreach (MyCharacter Player in MyEntities.GetEntities().OfType <MyCharacter>())
            {
                if (Player == null || Player.MarkedForClose)
                {
                    continue;
                }

                long PlayerID = Player.GetPlayerIdentityId();
                if (PlayerID == 0L || PlayerID == PlayerIdentityId)
                {
                    continue;
                }


                MyFaction CheckFaction = MySession.Static.Factions.GetPlayerFaction(PlayerID);
                if (PlayersFaction != null && CheckFaction != null)
                {
                    if (PlayersFaction.FactionId == CheckFaction.FactionId)
                    {
                        continue;
                    }

                    MyRelationsBetweenFactions Relation = MySession.Static.Factions.GetRelationBetweenFactions(PlayersFaction.FactionId, CheckFaction.FactionId).Item1;
                    if (Relation == MyRelationsBetweenFactions.Neutral || Relation == MyRelationsBetweenFactions.Friends)
                    {
                        continue;
                    }
                }

                if (Vector3D.Distance(Position, Player.PositionComp.GetPosition()) <= 15000)
                {
                    return(false);
                }
            }
            return(true);
        }
Exemple #10
0
    protected IMyEntity GetClosestEnemy(float maxSearchRadius) {
      if (!Active) {
        return null;
      }
      IMyFaction selfFaction = m_remote.CubeGrid.GetOwningFaction();

      BoundingSphereD bounds = new BoundingSphereD(m_remote.GetPosition(), maxSearchRadius);
      List<IMyEntity> possibleEnemies = MyAPIGateway.Entities.GetEntitiesInSphere(ref bounds);
      double minDist = double.MaxValue;
      IMyEntity closest = null;
      foreach (IMyEntity entity in possibleEnemies) {
        if(entity == m_remote.CubeGrid) {
          continue;
        }
        Vector3D position = entity.GetPosition();
        IMyFaction objectFaction = null;
        if (entity is IMyCubeGrid) {
          IMyCubeGrid grid = entity as IMyCubeGrid;
          objectFaction = grid.GetOwningFaction();
        } else if (entity is IMyPlayer) {
          IMyPlayer player = entity as IMyPlayer;
          objectFaction = MyAPIGateway.Session.Factions.TryGetPlayerFaction(player.IdentityId);
        }

        if (objectFaction == null) {
          continue;
        }
        MyRelationsBetweenFactions relation = MyAPIGateway.Session.Factions.GetRelationBetweenFactions(selfFaction.FactionId, objectFaction.FactionId);
        if (relation.Equals(MyRelationsBetweenFactions.Enemies)) {
          double dist = m_remote.GetPosition().DistanceTo(position);
          if(dist < minDist) {
            minDist = dist;
            closest = entity;
          }
        }
      }
      return closest;
    }
Exemple #11
0
 void ChangeRelation(long fromFactionId, long toFactionId, MyRelationsBetweenFactions relation)
 {
     m_relationsBetweenFactions[new MyFactionPair(fromFactionId, toFactionId)] = relation;
 }
Exemple #12
0
        private bool CheckEnemyDistance(LoadType LoadingAtSavePoint, Vector3D Position = new Vector3D())
        {
            if (LoadingAtSavePoint == LoadType.ForceLoadMearPlayer)
            {
                Position = PlayerPosition;
            }

            MyFaction PlayersFaction = MySession.Static.Factions.GetPlayerFaction(IdentityID);
            bool      EnemyFoundFlag = false;



            if (Config.DistanceCheck > 0)
            {
                //Check enemy location! If under limit return!

                foreach (MyPlayer P in MySession.Static.Players.GetOnlinePlayers())
                {
                    if (P.Character == null || P.Character.MarkedForClose)
                    {
                        continue;
                    }

                    Vector3D Pos;
                    if (P.Character.IsUsing is MyCryoChamber || P.Character.IsUsing is MyCockpit)
                    {
                        Pos = (P.Character.IsUsing as MyCockpit).PositionComp.GetPosition();
                    }
                    else
                    {
                        Pos = P.GetPosition();
                    }


                    long PlayerID = P.Identity.IdentityId;
                    if (PlayerID == 0L)
                    {
                        continue;
                    }
                    if (PlayerID == IdentityID)
                    {
                        continue;
                    }

                    MyFaction TargetPlayerFaction = MySession.Static.Factions.GetPlayerFaction(PlayerID);
                    if (PlayersFaction != null && TargetPlayerFaction != null)
                    {
                        if (PlayersFaction.FactionId == TargetPlayerFaction.FactionId)
                        {
                            continue;
                        }

                        //Neutrals count as allies not friends for some reason
                        MyRelationsBetweenFactions Relation = MySession.Static.Factions.GetRelationBetweenFactions(PlayersFaction.FactionId, TargetPlayerFaction.FactionId).Item1;
                        if (Relation == MyRelationsBetweenFactions.Neutral || Relation == MyRelationsBetweenFactions.Friends)
                        {
                            continue;
                        }
                    }


                    if (Vector3D.Distance(Position, Pos) == 0)
                    {
                        continue;
                    }

                    if (Vector3D.Distance(Position, Pos) <= Config.DistanceCheck)
                    {
                        Chat?.Respond("Unable to load grid! Enemy within " + Config.DistanceCheck + "m!");
                        GpsSender.SendGps(Position, "Failed Hangar Load! (Enemy nearby)", IdentityID);
                        EnemyFoundFlag = true;
                        break;
                    }
                }
            }


            if (Config.GridDistanceCheck > 0 && Config.GridCheckMinBlock > 0 && EnemyFoundFlag == false)
            {
                BoundingSphereD SpawnSphere = new BoundingSphereD(Position, Config.GridDistanceCheck);

                List <MyEntity> entities = new List <MyEntity>();
                MyGamePruningStructure.GetAllTopMostEntitiesInSphere(ref SpawnSphere, entities);



                //This is looping through all grids in the specified range. If we find an enemy, we need to break and return/deny spawning
                foreach (MyCubeGrid Grid in entities.OfType <MyCubeGrid>())
                {
                    if (Grid == null || Grid.MarkedForClose)
                    {
                        continue;
                    }

                    if (Grid.BigOwners.Count <= 0 || Grid.CubeBlocks.Count < Config.GridCheckMinBlock)
                    {
                        continue;
                    }

                    if (Grid.BigOwners.Contains(IdentityID))
                    {
                        continue;
                    }



                    //if the player isnt big owner, we need to scan for faction mates
                    bool FoundAlly = true;
                    foreach (long Owner in Grid.BigOwners)
                    {
                        MyFaction TargetPlayerFaction = MySession.Static.Factions.GetPlayerFaction(Owner);


                        if (PlayersFaction != null && TargetPlayerFaction != null)
                        {
                            if (PlayersFaction.FactionId == TargetPlayerFaction.FactionId)
                            {
                                continue;
                            }

                            MyRelationsBetweenFactions Relation = MySession.Static.Factions.GetRelationBetweenFactions(PlayersFaction.FactionId, TargetPlayerFaction.FactionId).Item1;
                            if (Relation == MyRelationsBetweenFactions.Enemies)
                            {
                                FoundAlly = false;
                                break;
                            }
                        }
                        else
                        {
                            FoundAlly = false;
                            break;
                        }
                    }


                    if (!FoundAlly)
                    {
                        //Stop loop
                        Chat?.Respond("Unable to load grid! Enemy within " + Config.GridDistanceCheck + "m!");
                        GpsSender.SendGps(Position, "Failed Hangar Load! (Enemy nearby)", IdentityID);
                        EnemyFoundFlag = true;
                        break;
                    }
                }
            }
            return(!EnemyFoundFlag);
        }