45 lines
1.4 KiB
C#
45 lines
1.4 KiB
C#
using Sandbox.Game.Entities;
|
|
using Sandbox.Game.World;
|
|
using VRage.Game.ModAPI;
|
|
|
|
namespace Global.API.Util
|
|
{
|
|
public static class FacUtils
|
|
{
|
|
public static IMyFaction GetPlayersFaction(long playerId)
|
|
{
|
|
return MySession.Static.Factions.TryGetPlayerFaction(playerId);
|
|
}
|
|
|
|
public static bool InSameFaction(long player1, long player2)
|
|
{
|
|
return GetPlayersFaction(player1) == GetPlayersFaction(player2);
|
|
}
|
|
|
|
public static string GetFactionTag(long playerId)
|
|
{
|
|
var faction = MySession.Static.Factions.TryGetPlayerFaction(playerId);
|
|
|
|
return faction == null ? "" : faction.Tag;
|
|
}
|
|
|
|
public static long GetOwner(MyCubeGrid grid)
|
|
{
|
|
var ownersList = grid.BigOwners;
|
|
var totalOwners = ownersList.Count;
|
|
|
|
if (totalOwners > 0 && ownersList[0] != 0) return ownersList[0];
|
|
return totalOwners > 1 ? ownersList[1] : 0L;
|
|
}
|
|
|
|
public static bool IsOwnerOrFactionOwned(MyCubeGrid grid, long playerId, bool doFactionCheck)
|
|
{
|
|
if (grid.BigOwners.Contains(playerId)) return true;
|
|
|
|
if (!doFactionCheck) return false;
|
|
var ownerId = GetOwner(grid);
|
|
//check if the owner is a faction member, i honestly dont know the difference between grid.BigOwners and grid.SmallOwners
|
|
return InSameFaction(playerId, ownerId);
|
|
}
|
|
}
|
|
} |