public void LeaveParty(SMCharacter invokingCharacter, bool suppressMessages = false) { // Find the current party if they have one (and it's not just at "invited" stage). if ((invokingCharacter.PartyReference == null) || (invokingCharacter.PartyReference.Status != "Invited")) { // Remove them from the party reference. // Get the list of parties List <SMParty> smp = (List <SMParty>)HttpContext.Current.Application["Parties"]; // Find the relevant party SMParty sp = smp.FirstOrDefault(p => p.PartyID == invokingCharacter.PartyReference.PartyID); if (!suppressMessages) { sp.SendMessageToAllPartyMembers(sp, "[i]" + invokingCharacter.GetFullName() + " left the party[/i]"); } // Remove the party from the global list element. smp.Remove(sp); // Find the relevant member SMPartyMember pm = sp.PartyMembers.FirstOrDefault(p => p.CharacterName == invokingCharacter.GetFullName()); sp.PartyMembers.Remove(pm); // Check there are still people in the party if (sp.PartyMembers.Count > 0) { // Add the member back to the list smp.Add(sp); } // Save it out to the global list again HttpContext.Current.Application["Parties"] = smp; // Remove the party reference from the character file invokingCharacter.PartyReference = null; // Save the player information to the application. invokingCharacter.SaveToApplication(); } else { if (!suppressMessages) { invokingCharacter.sendMessageToPlayer("[i]You are not in a party so can't leave one[/i]"); } } }
public void JoinParty(SMCharacter invokingCharacter, bool suppressMessages = false) { // Check the character has an open invite if ((invokingCharacter.PartyReference != null) && (invokingCharacter.PartyReference.Status == "Invited")) { // Find the party in the list of parties List <SMParty> smp = (List <SMParty>)HttpContext.Current.Application["Parties"]; // Find the relevant party SMParty sp = smp.FirstOrDefault(p => p.PartyID == invokingCharacter.PartyReference.PartyID); // If it exists... if (sp != null) { // Remove the party from the global list for a mo.. smp.Remove(sp); // ... add the character to the party. SMPartyMember smpm = new SMPartyMember(); smpm.CharacterName = invokingCharacter.GetFullName(); smpm.UserID = invokingCharacter.UserID; sp.PartyMembers.Add(smpm); // Add the party to the list again.. smp.Add(sp); // .. and save the list out HttpContext.Current.Application["Parties"] = smp; // ... send a message to all the people in the party. if (!suppressMessages) { sp.SendMessageToAllPartyMembers(sp, "[i]" + smpm.CharacterName + " joined the party[/i]"); } // ... change the status of the party element on the character to "joined" invokingCharacter.PartyReference.Status = "Joined"; // Save the player information to the application. invokingCharacter.SaveToApplication(); } else // .. the party no longer exists, so can't be joined { // Tell the player if (!suppressMessages) { invokingCharacter.sendMessageToPlayer("[i]That party no longer exists.[/i]"); } // Remove the reference from their party invite list. invokingCharacter.PartyReference = null; // Save the player information to the application. invokingCharacter.SaveToApplication(); } } else // No party { if (!suppressMessages) { invokingCharacter.sendMessageToPlayer("[i]You have no open party invites.[/i]"); } } }