// 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); }
private string calculateOwner() { string ret = "["; List <IMyPlayer> li = new List <IMyPlayer>(); MyAPIGateway.Players.GetPlayers(li); foreach (long id in grid.BigOwners) { string name = null; IMyFaction fac = MyAPIGateway.Session.Factions.TryGetFactionById(id); if (fac != null) { name = fac.Name; } else { foreach (IMyPlayer ep in li) { if (ep.Identity.IdentityId == id) { name = ep.DisplayName; break; } } } if (name != null) { ret = ret + name + ", "; } } ret = ret + "]"; return(ret); }
public static bool IsNpc(this IMyFaction faction) { try { IMyPlayer owner = MyAPIGateway.Players.GetPlayerById(faction.FounderId); if (owner != null) { return(owner.IsBot); } if (!faction.Members.Any()) { return(true); } foreach (KeyValuePair <long, MyFactionMember> myMember in faction.Members) { IMyPlayer member = MyAPIGateway.Players.GetPlayerById(myMember.Value.PlayerId); if (member == null) { continue; } if (!member.IsBot) { return(false); } } return(true); } catch (Exception scrap) { AiSessionCore.LogError("Faction.IsNPC", scrap); return(false); } }
public static void DeclareWar(IMyFaction OwnFaction, IMyFaction HostileFaction, TimeSpan TruceDelay) { if (!PeaceTimers.ContainsKey(OwnFaction)) { if (AllowThrowingErrors) { throw new Exception($"PeaceTimers dictionary error: can't find {OwnFaction.Tag} key!"); } return; } DateTime PeaceTime = DateTime.Now.Add(TruceDelay); var timerdict = PeaceTimers[OwnFaction]; if (!timerdict.ContainsKey(HostileFaction)) { timerdict.Add(HostileFaction, PeaceTime); } else { timerdict[HostileFaction] = PeaceTime; } if (!OwnFaction.IsHostileTo(HostileFaction)) { OwnFaction.DeclareWar(HostileFaction, Print: true); } DebugWrite($"DeclareWarTimer[{OwnFaction.Tag}]", $"Added peace timer. Current time: {DateTime.Now.ToString("HH:mm:ss")} | Calmdown at: {PeaceTime.ToString("HH:mm:ss")} | Calmdown delay: {TruceDelay.ToString()}"); }
public void FactionForceJoin(string PlayerName) { long id = 0; foreach (var identity in MySession.Static.Players.GetAllIdentities()) { if (identity.DisplayName == PlayerName) { id = identity.IdentityId; } } // Check if player is already in a faction var playerFaction = MyAPIGateway.Session.Factions.TryGetPlayerFaction(id); if (playerFaction != null) { Context.Respond(PlayerName + " is already in a faction!"); return; } if (Context.Player.PromoteLevel > MyPromoteLevel.None) { Context.Respond("You need to join a faction manually"); return; } // Work out which faction to assign player (one with least amount of players) var pairs = new List <KeyValuePair <string, int> >(); foreach (string Tag in Plugin.Config.FactionTags) { try { IMyFaction tempFaction = MyAPIGateway.Session.Factions.TryGetFactionByTag(Tag); int playerCount = tempFaction.Members.Count; var pair = new KeyValuePair <string, int>(Tag, playerCount); pairs.Add(pair); } catch (Exception) { Plugin.Logger.Warn(Tag + " doesn't exist!"); } } var minFactionPair = pairs.MinBy(e => e.Value); // Put player in faction IMyFaction targetFaction = MyAPIGateway.Session.Factions.TryGetFactionByTag(minFactionPair.Key); MyAPIGateway.Session.Factions.SendJoinRequest(targetFaction.FactionId, id); // Adds player to faction MyAPIGateway.Session.Factions.AcceptJoin(targetFaction.FactionId, id); // Accept player to faction // Report back to player Context.Respond("Added to faction: " + minFactionPair.Key); Plugin.Logger.Info("Assigned " + PlayerName + " to faction " + targetFaction.Tag); }
private void OnFactionCreated(long id) { IMyFaction faction = MyAPIGateway.Session.Factions.TryGetFactionById(id); if (faction != null) { ActivityCollector.Log.Info($"New Faction Created: {faction.Tag} | {faction.Name}"); SQLQueryData.WriteToDatabase(new FactionActivityDescription() { FromFactionId = id, ToFactionId = id, PlayerId = faction.FounderId, SenderId = faction.FounderId, Action = "CreateFaction", Timestamp = Tools.DateTime }); SQLQueryData.WriteToDatabase(new FactionNameDescription() { FactionId = id, Tag = faction.Tag, Name = faction.Name, Description = faction.Description, Timestamp = Tools.DateTime }); } }
public void FactionPlayerCount() { // Work out which faction to assign player (one with least amount of players) var pairs = new List <KeyValuePair <string, int> >(); foreach (string Tag in Plugin.Config.FactionTags) { try { IMyFaction tempFaction = MyAPIGateway.Session.Factions.TryGetFactionByTag(Tag); int playerCount = tempFaction.Members.Count; var pair = new KeyValuePair <string, int>(Tag, playerCount); pairs.Add(pair); } catch (Exception) { Context.Respond(Tag + " doesn't exist!"); Plugin.Logger.Warn(Tag + " doesn't exist!"); } } Context.Respond("Players in each faction: "); foreach (var pair in pairs) { Context.Respond("Faction: " + pair.Key + " Players: " + pair.Value); } }
private void MessageRecieved(TorchChatMessage msg, ref bool consumed) { if (!Config.Enabled) { return; } if (msg.AuthorSteamId != null) { switch (msg.Channel) { case ChatChannel.Global: DDBridge.SendChatMessage(msg.Author, msg.Message); break; case ChatChannel.GlobalScripted: DDBridge.SendChatMessage(msg.Author, msg.Message); break; case ChatChannel.Faction: IMyFaction fac = MySession.Static.Factions.TryGetFactionById(msg.Target); DDBridge.SendFacChatMessage(msg.Author, msg.Message, fac.Name); break; } } else if (Config.ServerToDiscord && msg.Channel.Equals(ChatChannel.Global) && !msg.Message.StartsWith(Config.CommandPrefix) && msg.Target.Equals(0)) { DDBridge.SendChatMessage(msg.Author, msg.Message); } }
public static void RecreateFaction(FactionData data, long requester) { if (string.IsNullOrEmpty(data?.Tag)) { return; } IMyFaction current = MyAPIGateway.Session.Factions.TryGetFactionByTag(data.Tag); if (current == null) { MyAPIGateway.Session.Factions.CreateFaction(requester, data.Tag, data.Name, data.Description, data.PrivateInfo); IMyFaction current2 = MyAPIGateway.Session.Factions.TryGetFactionByTag(data.Tag); MyAPIGateway.Session.Factions.SendJoinRequest(current2.FactionId, requester); MyAPIGateway.Session.Factions.AcceptJoin(current2.FactionId, requester); return; } if (current.IsMember(requester)) { return; } MyAPIGateway.Session.Factions.SendJoinRequest(current.FactionId, requester); MyAPIGateway.Session.Factions.AcceptJoin(current.FactionId, requester); }
private static void SetDefaultFactionStates(long recivedFactionId) { IMyFaction recievedFaction = MySession.Static.Factions.TryGetFactionById(recivedFactionId); MyFactionDefinition recievedFactionDefiniton = MyDefinitionManager.Static.TryGetFactionDefinition(recievedFaction.Tag); foreach (var factionPair in MySession.Static.Factions) { MyFaction faction = factionPair.Value; if (faction.FactionId == recivedFactionId) { continue; } if (recievedFactionDefiniton != null) // If I have definition, force my relations on everyone. { SetDefaultFactionStateInternal(faction.FactionId, recievedFaction, recievedFactionDefiniton); } else // Otherwise search for default factions and set their relations on me. { MyFactionDefinition factionDefiniton = MyDefinitionManager.Static.TryGetFactionDefinition(faction.Tag); if (factionDefiniton == null) { continue; } SetDefaultFactionStateInternal(recivedFactionId, faction, factionDefiniton); } } }
virtual protected void BlockPlacedHandler(IMySlimBlock Block) { if (Block == null) { return; } try { IMyPlayer Builder = null; IMyFaction Faction = null; if (Block.IsPlayerBlock(out Builder)) { Faction = Builder.GetFaction(); if (Faction != null) { RegisterHostileAction(Faction, CalmdownTime); } } } catch (Exception Scrap) { Grid.LogError("BlokPlaedHandler", Scrap); } }
private void Factions_FactionStateChanged(MyFactionCollection.MyFactionStateChange action, long fromFactionId, long toFactionId, long playerId, long senderId) { if (MySession.Static.LocalHumanPlayer == null) { return; } // get player id long localPlayerID = MySession.Static.LocalHumanPlayer.Identity.IdentityId; // get player faction IMyFaction myFaction = MySession.Static.Factions.TryGetPlayerFaction(MySession.Static.LocalHumanPlayer.Identity.IdentityId); if (myFaction == null) { return; } if ((myFaction.IsLeader(localPlayerID) || myFaction.IsFounder(localPlayerID)) && // is leader or founder (myFaction.FactionId == fromFactionId || myFaction.FactionId == toFactionId) && // its our faction in this deal action == MyFactionCollection.MyFactionStateChange.AcceptPeace) // is it peace? { NotifyAchieved(); MySession.Static.Factions.FactionStateChanged -= Factions_FactionStateChanged; } }
public static void Login(IPlayer p) { if (p == null) { return; } MyIdentity id = AlliancePlugin.GetIdentityByNameOrId(p.SteamId.ToString()); if (id == null) { return; } IMyFaction playerFac = MySession.Static.Factions.GetPlayerFaction(id.IdentityId); MyFaction arrr = MySession.Static.Factions.TryGetFactionByTag("arrr"); if (arrr != null) { if (playerFac != null && !MySession.Static.Factions.AreFactionsEnemies(arrr.FactionId, FacUtils.GetPlayersFaction(id.IdentityId).FactionId)) { Sandbox.Game.Multiplayer.MyFactionCollection.DeclareWar(playerFac.FactionId, arrr.FactionId); } } MyFaction ACME = MySession.Static.Factions.TryGetFactionByTag("ACME"); if (ACME != null) { MySession.Static.Factions.SetReputationBetweenPlayerAndFaction(id.IdentityId, ACME.FactionId, 0); MySession.Static.Factions.AddFactionPlayerReputation(id.IdentityId, ACME.FactionId, 0); } MyFaction GAIA = MySession.Static.Factions.TryGetFactionByTag("GAIA"); if (GAIA != null) { MySession.Static.Factions.SetReputationBetweenPlayerAndFaction(id.IdentityId, GAIA.FactionId, 0); MySession.Static.Factions.AddFactionPlayerReputation(id.IdentityId, GAIA.FactionId, 0); } MyFaction wolf = MySession.Static.Factions.TryGetFactionByTag("WOLF"); if (wolf != null) { if (playerFac != null && !MySession.Static.Factions.AreFactionsEnemies(wolf.FactionId, FacUtils.GetPlayersFaction(id.IdentityId).FactionId)) { Sandbox.Game.Multiplayer.MyFactionCollection.DeclareWar(playerFac.FactionId, wolf.FactionId); } } if (File.Exists(AlliancePlugin.path + "//PlayerData//" + p.SteamId + ".xml") && playerFac != null) { PlayerData data = utils.ReadFromXmlFile <PlayerData>(AlliancePlugin.path + "//PlayerData//" + p.SteamId + ".xml"); if (data.InAllianceChat) { if (AlliancePlugin.GetAllianceNoLoading(playerFac as MyFaction) != null) { PeopleInAllianceChat.Remove(p.SteamId); PeopleInAllianceChat.Add(p.SteamId, AlliancePlugin.GetAllianceNoLoading(playerFac as MyFaction).AllianceId); } } } }
private void LogGrid(MyCubeGrid grid) { try { long ownerId = OwnershipUtils.GetOwner(grid); string name = PlayerUtils.GetPlayerNameById(ownerId); IMyFaction faction = GetFactionForPlayer(ownerId); string factionString = ""; if (faction != null) { factionString = "[" + faction.Tag + "]"; } string ownedString = "Owned by: " + name + " " + factionString; long gridId = grid.EntityId; string gridName = grid.DisplayName; Log.Info("Broadcasted " + gridId + " " + gridName + " " + ownedString); } catch (Exception e) { Log.Error(e); } }
public void AddFactionBalance() { if (Context.Args.Count != 2) { Context.Respond("try !addbalance faction [factionTag] [amount]"); return; } //Try find the faction by name IMyFaction faction = MyAPIGateway.Session.Factions.Factions .FirstOrDefault(f => string.Compare(f.Value.Tag, Context.Args[0], true) == 0).Value; if (faction == null) { Context.Respond($"faction {Context.Args[0]} not found"); return; } //Try parse amount long amount; if (!long.TryParse(Context.Args[1], out amount)) { Context.Respond($"{Context.Args[1]} is not a valid amount"); return; } faction.RequestChangeBalance(amount); Context.Respond($"Faction {Context.Args[0]} balance changed by {amount}"); }
private bool TryParseCmd(string s) { int start = s.IndexOf("[cmd:"); if (start > 0) { int end = s.IndexOf(']', start); if (end > 0) { int len = end - (start + 5); if (len > 0) { string cmd = s.Substring(start + 5, len).TrimStart(' ', '/').TrimEnd().ToLower(); if (IsValid(cmd)) { this.cmd = cmd; fac = null; block.RefreshCustomInfo(); if (!fake) { MySession.Instance.Register(this.cmd, cmdBlock); } return(true); } } } } return(false); }
static void Postfix(long playerId1, long playerId2, ref MyRelationsBetweenPlayerAndBlock __result) { if (playerId1 == playerId2) { return; } IMyFaction playerFaction1 = MySession.Static.Factions.TryGetPlayerFaction(playerId1); IMyFaction playerFaction2 = MySession.Static.Factions.TryGetPlayerFaction(playerId2); if (playerFaction1 != null && playerFaction2 != null) { if (AlliancePlugin.GetAllianceNoLoading(playerFaction1 as MyFaction) != null && AlliancePlugin.GetAllianceNoLoading(playerFaction2 as MyFaction) != null) { if (AlliancePlugin.GetAllianceNoLoading(playerFaction1 as MyFaction) == AlliancePlugin.GetAllianceNoLoading(playerFaction2 as MyFaction)) { // AlliancePlugin.Log.Info("Same alliance?"); __result = MyRelationsBetweenPlayerAndBlock.Friends; return; } } if (MySession.Static.Factions.AreFactionsFriends(playerFaction1.FactionId, playerFaction2.FactionId)) { __result = MyRelationsBetweenPlayerAndBlock.Friends; return; } } return; // make sure you only skip if really necessary }
public virtual bool Init(IMyRemoteControl rc = null) { Rc = rc ?? Term.GetBlocksOfType <IMyRemoteControl>(collect: x => x.IsFunctional).FirstOrDefault(); if (rc == null) { return(false); } DroneName = DroneNameProvider; Antennae = Term.GetBlocksOfType <IMyRadioAntenna>(collect: x => x.IsFunctional); bool hasSetup = ParseSetup(); if (!hasSetup) { return(false); } AiSessionCore.AddDamageHandler(Grid, (block, damage) => { OnDamaged?.Invoke(block, damage); }); Grid.OnBlockAdded += block => { OnBlockPlaced?.Invoke(block); }; _ownerFaction = Grid.GetOwnerFaction(true); BotOperable = true; return(true); }
public void RestoreFaction(string factionTag, string gridNameOrEntityId, int backupNumber = 1, bool keepOriginalPosition = false, bool force = false) { IMyFaction faction = FactionUtils.GetIdentityByTag(factionTag); if (faction == null) { Context.Respond("Player not found!"); return; } var factionMembers = faction.Members; var relevantGrids = Utilities.FindRelevantGrids(Plugin, factionMembers.Keys); Utilities.FindPathToRestore(Plugin, relevantGrids, gridNameOrEntityId, backupNumber, out string path, out bool gridFound, out bool outOfBounds); if (outOfBounds) { Context.Respond("Backup not found! Check if the number is in range!"); return; } if (!gridFound) { Context.Respond("Grid not found!"); return; } ImportPath(path, keepOriginalPosition, force); }
// Get pilot of a ship // var playerEnt = MyAPIGateway.Session.ControlledObject?.Entity as MyEntity; // if (playerEnt?.Parent != null) playerEnt = playerEnt.Parent; protected void BlockPlacedHandler(IMySlimBlock block) { if (block == null) { return; } try { IMyPlayer builder; if (!block.IsPlayerBlock(out builder)) { return; } IMyFaction faction = builder.GetFaction(); if (faction != null) { DeclareWar(faction); } } catch (Exception scrap) { Grid.LogError("BlockPlacedHandler", scrap); } }
public void FactionChange(MyFactionStateChange type, long fromFaction, long toFaction, long playerId, long senderId) { if (type == MyFactionStateChange.SendPeaceRequest) { IMyFaction faction = MyAPIGateway.Session.Factions.TryGetFactionById(toFaction); if (faction == null || !faction.IsEveryoneNpc() || faction.Tag.Length <= 3) { return; } foreach (var npcId in NpcFactionPairs.Values) { if (MyAPIGateway.Session.Factions.GetRelationBetweenFactions(fromFaction, toFaction) != VRage.Game.MyRelationsBetweenFactions.Enemies) { return; } } foreach (var npcId in NpcFactionPairs.Values) { if (npcId == toFaction) { if (MyAPIGateway.Session.Factions.GetReputationBetweenPlayerAndFaction(senderId, npcId) >= AllowPeaceAmt) { MyAPIGateway.Session.Factions.AcceptPeace(fromFaction, toFaction); break; } } } } }
public void GenericDamageHandler(object target, MyDamageInformation info) { if (target == null || !(target is IMySlimBlock)) { return; } IMySlimBlock block = target as IMySlimBlock; IMyCubeGrid grid = block.CubeGrid; long gridId = grid.GetTopMostParent().EntityId; IMyFaction damageeFaction = grid.GetOwningFaction(); IMyPlayer damagerPlayer; IMyFaction damagerFaction; IMyCubeGrid damagerShip; if (damageeFaction != null && info.GetSource(out damagerPlayer, out damagerFaction, out damagerShip)) { if (damagerFaction == null) { return; } EmpireData damagerEmpire = damagerFaction.GetEmpire(); foreach (EmpireManager empire in m_empireManagers) { if (empire.GetData().empireTag == damageeFaction.Tag) { empire.TakeStandingsHit(damagerEmpire); break; } } } }
private void Factions_FactionStateChanged(MyFactionCollection.MyFactionStateChange action, long fromFactionId, long toFactionId, long playerId, long senderId) { if (MySession.Static.LocalHumanPlayer == null) { return; } // get player id long localPlayerID = MySession.Static.LocalHumanPlayer.Identity.IdentityId; // get player faction IMyFaction myFaction = MySession.Static.Factions.TryGetPlayerFaction(localPlayerID); if (myFaction == null) { return; } // Player declaring war if ((myFaction.IsFounder(localPlayerID) || myFaction.IsLeader(localPlayerID)) && // is player leader/fouder of faction myFaction.FactionId == fromFactionId && // is sending war not recieving action == MyFactionCollection.MyFactionStateChange.DeclareWar) // is it war? { NotifyAchieved(); MySession.Static.Factions.FactionStateChanged -= Factions_FactionStateChanged; } }
public static bool InSameFaction(long player1, long player2) { IMyFaction faction1 = GetPlayersFaction(player1); IMyFaction faction2 = GetPlayersFaction(player2); return(faction1 == faction2); }
public FactionsAtWar(IMyFaction aiFaction, IMyFaction playerFaction) { aiFaction.DeclareWar(playerFaction); AiFaction = aiFaction; PlayerFaction = playerFaction; CooldownTime = Constants.FactionCooldown; }
public static byte[] SerializeAndSign(IMyCubeGrid grid, IMyPlayer player, Vector3I block) { var c = grid.GetCubeBlock(block)?.FatBlock as IMyCockpit; IMyCharacter pilot = c?.Pilot; c?.RemovePilot(); var ob = (MyObjectBuilder_CubeGrid)grid.GetObjectBuilder(); if (pilot != null) { c.AttachPilot(pilot); } IMyFaction fac = MyAPIGateway.Session.Factions.TryGetPlayerFaction(player.IdentityId); var data = new ClientData(ob, fac, block, Settings.Instance.HubIP); string obStr = MyAPIGateway.Utilities.SerializeToXML(data); string totalStr = DateTime.UtcNow.Ticks + obStr; string evalStr = totalStr + Settings.Instance.Password; var m = new MD5(); m.Value = evalStr; totalStr += m.FingerPrint; return(Encoding.UTF8.GetBytes(totalStr)); }
public void Close() { UnregisterEvents(); // left controls m_selectedFaction = null; m_tableFactions = null; m_buttonCreate = null; m_buttonJoin = null; m_buttonCancelJoin = null; m_buttonLeave = null; m_buttonSendPeace = null; m_buttonCancelPeace = null; m_buttonAcceptPeace = null; m_buttonMakeEnemy = null; // right controls m_labelFactionName = null; m_labelFactionDesc = null; m_labelFactionPriv = null; m_labelMembers = null; m_labelAutoAcceptMember = null; m_labelAutoAcceptPeace = null; m_checkAutoAcceptMember = null; m_checkAutoAcceptPeace = null; m_textFactionDesc = null; m_textFactionPriv = null; m_tableMembers = null; m_buttonKick = null; m_buttonAcceptJoin = null; m_controlsParent = null; }
/// <summary> /// Checks whether a grid is owned only by one faction /// If a single block is owned by another player, returns false /// </summary> /// <param name="grid">Grid to check</param> /// <returns></returns> public static bool ownedBySingleFaction(this IMyCubeGrid grid) { // No one owns the grid if (grid.BigOwners.Count == 0) { return(false); } // Guaranteed to have at least 1 owner after previous check IMyFactionCollection facs = MyAPIGateway.Session.Factions; IMyFaction fac = facs.TryGetPlayerFaction(grid.BigOwners[0]); // Test big owners for (int i = 1; i < grid.BigOwners.Count; ++i) { IMyFaction newF = facs.TryGetPlayerFaction(grid.BigOwners[i]); if (newF != fac) { return(false); } } // Test small owners for (int i = 0; i < grid.SmallOwners.Count; ++i) { IMyFaction newF = facs.TryGetPlayerFaction(grid.SmallOwners[i]); if (newF != fac) { return(false); } } // Didn't encounter any factions different from the BigOwner[0] faction return(true); }
public static FactionRelationship GetRelationBetweenGridAndCharacter(IMyCubeGrid npcGrid, IMyCharacter character) { long npcGridOwner = npcGrid.BigOwners.FirstOrDefault(); IMyFaction npcFaction = MyAPIGateway.Session.Factions.TryGetPlayerFaction(npcGridOwner); return(MyAPIGateway.Session.Factions.GetReputationBetweenPlayerAndFaction(character.EntityId, npcFaction.FactionId) >= -500 ? FactionRelationship.Friends : FactionRelationship.Enemies); }
public FactionData(IMyFaction faction) { Tag = faction.Tag; Name = faction.Name; PrivateInfo = faction.PrivateInfo; Description = faction.Description; }
public MyGuiScreenCreateOrEditFaction(ref IMyFaction editData) : base(size: new Vector2(0.5f, 0.5f), position: MyGuiManager.ComputeFullscreenGuiCoordinate(MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER), backgroundColor: MyGuiConstants.SCREEN_BACKGROUND_COLOR, backgroundTexture: MyGuiConstants.TEXTURE_SCREEN_BACKGROUND.Texture) { CanHideOthers = false; EnabledBackgroundFade = false; m_editFaction = editData; RecreateControls(true); }
private void OnMemberStateChanged(MyFactionCollection.MyFactionStateChange action, IMyFaction fromFaction, long playerId) { var identity = Sync.Players.TryGetIdentity(playerId); System.Diagnostics.Debug.Assert(identity != null, "Identity does not exist!"); if (identity == null) { MyLog.Default.WriteLine("ERROR: Faction " + fromFaction.Name + " member " + playerId + " does not exists! "); return; } RemoveMember(playerId); switch (action) { case MyFactionCollection.MyFactionStateChange.FactionMemberPromote: AddMember(playerId, identity.DisplayName, true, MyMemberComparerEnum.Leader, MyCommonTexts.Leader); break; case MyFactionCollection.MyFactionStateChange.FactionMemberCancelJoin: case MyFactionCollection.MyFactionStateChange.FactionMemberLeave: case MyFactionCollection.MyFactionStateChange.FactionMemberKick: break; case MyFactionCollection.MyFactionStateChange.FactionMemberAcceptJoin: case MyFactionCollection.MyFactionStateChange.FactionMemberDemote: AddMember(playerId, identity.DisplayName, false, MyMemberComparerEnum.Member, MyCommonTexts.Member); break; case MyFactionCollection.MyFactionStateChange.FactionMemberSendJoin: AddMember(playerId, identity.DisplayName, false, MyMemberComparerEnum.Applicant, MyCommonTexts.Applicant, COLOR_CUSTOM_GREY); break; } RefreshUserInfo(); RefreshTableFactions(); m_tableMembers.Sort(false); }
private void AddFaction(IMyFaction faction, Color? color = null, MyGuiHighlightTexture? icon = null, String iconToolTip = null) { System.Diagnostics.Debug.Assert(m_tableFactions != null); if (m_tableFactions == null) return; var row = new MyGuiControlTable.Row(faction); var tag = new StringBuilder(faction.Tag); var name = new StringBuilder(faction.Name); row.AddCell(new MyGuiControlTable.Cell(text: tag, userData: tag, textColor: color)); row.AddCell(new MyGuiControlTable.Cell(text: name, userData: name, textColor: color, toolTip: faction.Name)); row.AddCell(new MyGuiControlTable.Cell(text: new StringBuilder(), icon: icon, toolTip: iconToolTip)); m_tableFactions.Add(row); }
private void RefreshFactionProperties() { m_checkAutoAcceptMember.IsCheckedChanged -= OnAutoAcceptChanged; m_checkAutoAcceptPeace.IsCheckedChanged -= OnAutoAcceptChanged; m_labelFactionName.Visible = false; m_labelFactionDesc.Visible = false; m_labelFactionPriv.Visible = false; m_labelMembers.Visible = false; m_labelAutoAcceptMember.Visible = false; m_labelAutoAcceptPeace.Visible = false; m_checkAutoAcceptMember.Visible = false; m_checkAutoAcceptPeace.Visible = false; m_textFactionDesc.Visible = false; m_textFactionPriv.Visible = false; m_tableMembers.Visible = false; m_buttonEdit.Visible = false; m_buttonKick.Visible = false; m_buttonPromote.Visible = false; m_buttonDemote.Visible = false; m_buttonAcceptJoin.Visible = false; m_buttonAddNpc.Visible = false; if (m_tableFactions.SelectedRow != null) { m_selectedFaction = (MyFaction)m_tableFactions.SelectedRow.UserData; m_labelFactionName.Text = string.Format("{0}.{1}", m_selectedFaction.Tag, m_selectedFaction.Name); m_textFactionDesc.Text = new StringBuilder(m_selectedFaction.Description); m_textFactionPriv.Text = new StringBuilder(m_selectedFaction.PrivateInfo); m_checkAutoAcceptMember.IsChecked = m_selectedFaction.AutoAcceptMember; m_checkAutoAcceptPeace.IsChecked = m_selectedFaction.AutoAcceptPeace; m_labelFactionName.Visible = true; m_labelFactionDesc.Visible = true; m_textFactionDesc.Visible = true; m_labelMembers.Visible = true; m_tableMembers.Visible = true; if (m_userFaction != null && m_userFaction.FactionId == m_selectedFaction.FactionId) { m_labelFactionPriv.Visible = true; m_textFactionPriv.Visible = true; if (m_userIsLeader) { m_labelAutoAcceptMember.Visible = true; m_labelAutoAcceptPeace.Visible = true; m_checkAutoAcceptMember.Visible = true; m_checkAutoAcceptPeace.Visible = true; m_buttonKick.Visible = true; m_buttonAcceptJoin.Visible = true; m_buttonEdit.Visible = true; m_buttonPromote.Visible = true; m_buttonDemote.Visible = true; if (MySession.Static.Settings.ScenarioEditMode) m_buttonAddNpc.Visible = true; } } } else m_tableMembers.Clear(); m_checkAutoAcceptMember.IsCheckedChanged += OnAutoAcceptChanged; m_checkAutoAcceptPeace.IsCheckedChanged += OnAutoAcceptChanged; }
private void RefreshUserInfo() { m_userIsFounder = false; m_userIsLeader = false; m_userFaction = MySession.Static.Factions.TryGetPlayerFaction(MySession.Static.LocalPlayerId); if (m_userFaction != null) { m_userIsFounder = m_userFaction.IsFounder(MySession.Static.LocalPlayerId); m_userIsLeader = m_userFaction.IsLeader(MySession.Static.LocalPlayerId); } }
private void LeaveFaction() { if (m_userFaction == null) // player can be kicked while confirming leave return; MyFactionCollection.MemberLeaves(m_userFaction.FactionId, MySession.Static.LocalPlayerId); m_userFaction = null; Refresh(); }
private void OnFactionsTableItemSelected(MyGuiControlTable sender, Sandbox.Graphics.GUI.MyGuiControlTable.EventArgs args) { if (sender.SelectedRow != null) { m_selectedFaction = (MyFaction)sender.SelectedRow.UserData; m_labelFactionName.Text = string.Format("{0}.{1}", m_selectedFaction.Tag, m_selectedFaction.Name); m_textFactionDesc.Text = new StringBuilder(m_selectedFaction.Description); m_textFactionPriv.Text = new StringBuilder(m_selectedFaction.PrivateInfo); RefreshTableMembers(); } m_tableMembers.Sort(false); RefreshJoinButton(); RefreshDiplomacyButtons(); RefreshFactionProperties(); }
void SendToFaction(string message, IMyFaction plFaction, IMyPlayer Me) { var listplayers = new List<IMyPlayer>(); MyAPIGateway.Players.GetPlayers(listplayers); IMyPlayer Receiver; foreach (IMyPlayer pl in listplayers) { if (plFaction.IsMember(pl.PlayerID)) { Receiver = pl; if (Me.DisplayName != Receiver.DisplayName) { if (MyAPIGateway.Players.TryGetPlayer(Receiver.DisplayName, out Receiver)) { SendFactionMessage(Receiver, message); break; } } } } }
bool IMyFactionCollection.FactionNameExists(string name, IMyFaction doNotCheck) { return FactionNameExists(name, doNotCheck); }
bool IMyFactionCollection.FactionTagExists(string tag, IMyFaction doNotCheck) { return FactionTagExists(tag, doNotCheck); }
public void Init(ref IMyFaction editData) { m_editFaction = editData; RecreateControls(true); }
public MyGuiScreenCreateOrEditFactionSpace(ref IMyFaction editData) : base(ref editData) { }