コード例 #1
0
        private static void FatBlock_OwnershipChanged(MyTerminalBlock block)
        {
            if ( block?.CubeGrid?.Physics == null || block.Closed )
            {
                //idfk
                Thread.Sleep( 500 );
                if ( block?.CubeGrid?.Physics == null || block.Closed )
                    return;
            }

            Task.Run( () =>
                      {
                          if ( block.OwnerId != 0 )
                          {
                              var owner = MySession.Static.Players.GetPlayerById( new MyPlayer.PlayerId( PlayerMap.Instance.GetSteamIdFromPlayerId( block.OwnerId ) ) );
                              if ( owner != null && MySession.Static.Players.IdentityIsNpc( block.OwnerId ) )
                              {
                                  if ( owner.DisplayName != "Space Pirates" )
                                  {
                                      lock ( BlockOwners )
                                          BlockOwners[block] = block.OwnerId;
                                      return;
                                  }
                              }
                          }

                          lock ( BlockOwners )
                          {
                              if ( BlockOwners.ContainsKey( block ) )
                                  MyAPIGateway.Utilities.InvokeOnGameThread( () => block.ChangeBlockOwnerRequest( BlockOwners[block], MyOwnershipShareModeEnum.Faction ) );
                              else if ( PluginSettings.Instance.PlayerBlockEnforcementChangeOwner )
                              {
                                  ChangeOwnershipToNearestPlayer( block );
                                  if ( block.OwnerId == 0 && block.CubeGrid.BigOwners.Count > 0 )
                                      MyAPIGateway.Utilities.InvokeOnGameThread(()=>block.ChangeBlockOwnerRequest( block.CubeGrid.BigOwners[0], MyOwnershipShareModeEnum.Faction ));

                                  if ( block.OwnerId != 0 )
                                      BlockOwners[block] = block.OwnerId;
                              }
                          }
                      } );

            ProcessEnforcement();
        }
コード例 #2
0
        private static void ChangeOwnershipToNearestPlayer( MyTerminalBlock block )
        {
            Wrapper.GameAction( () =>
                                {
                                    double minDist = 0;
                                    MyPlayer nearest = null;

                                    foreach ( var player in MySession.Static.Players.GetOnlinePlayers() )
                                    {
                                        var dist = Vector3D.DistanceSquared( player.GetPosition(), block.PositionComp.GetPosition() );

                                        if ( nearest == null )
                                        {
                                            nearest = player;
                                            minDist = dist;
                                        }
                                        else if ( dist < minDist )
                                            nearest = player;
                                    }

                                    if ( nearest == null )
                                        return;
                                    MyAPIGateway.Utilities.InvokeOnGameThread(()=>block.ChangeBlockOwnerRequest( nearest.Identity.IdentityId, MyOwnershipShareModeEnum.Faction ));
                                } );
        }