void HandleLeave(Player p, string[] args) { string prefix = "%dParties> %S"; string noParty = prefix + "You are not in a party."; Team team = Team.GetData(p).Team; if (team == null) { p.Message(noParty); return; } // Handle '/party leave me alone', for example if (args.Length > 1) { team.Message(p, args.Join(" ")); return; } team.Action(p, "has left the party."); team.Remove(p.name); Team.GetData(p).Team = null; team.OwnerLeft(p); Team.SaveList(); }
void HandleJoin(Player p, string[] args) { string prefix = "%dParties> %S"; string noParty = prefix + "You are not in a party."; Team team = Team.GetData(p).Team; string invite = Team.GetData(p).Invite; if (invite == null) { p.Message(prefix + "You have not been invited to any parties."); return; } if (team != null) { p.Message(prefix + "You need to leave your current party before you can join another one."); return; } team = Team.Find(invite); if (team == null) { p.Message(prefix + "The party you were invited to no longer exists."); return; } Team.GetData(p).Team = team; Team.GetData(p).Invite = null; team.Members.Add(p.name); team.Action(p, "joined the party."); Team.SaveList(); }
void HandleOwner(Player p, string[] args) { string prefix = "%dParties> %S"; string noParty = prefix + "You are not in a party."; Team team = Team.GetData(p).Team; if (team == null) { p.Message(noParty); return; } if (args.Length == 1) { p.Message(prefix + "The current owner of the party is: " + team.Owner); return; } Player who = PlayerInfo.FindMatches(p, args[1]); if (who == null) { return; } if (!p.name.CaselessEq(team.Owner)) { p.Message(prefix + "Only the party owner can set the new party owner."); return; } team.Owner = who.name; team.Action(p, "set the party owner to " + who.ColoredName + "%S."); Team.SaveList(); }
void LeaveServer(Player p, string reason) { Team team = Team.GetData(p).Team; if (team == null) { return; } if (p.name.CaselessEq(team.Owner)) { team.OwnerLeft(p); return; } team.Action(p, "has left the party (disconnected)."); team.Remove(p.name); Team.GetData(p).Team = null; Team.SaveList(); }
void HandleInvite(Player p, string[] args) { string prefix = "%dParties> %S"; string noParty = prefix + "You are not in a party."; Team team = Team.GetData(p).Team; if (team == null) { p.Message(prefix + "You need to be in a party to invite players."); return; } if (args.Length == 1) { p.Message(prefix + "You need to provide the name of the person to invite."); return; } Player who = PlayerInfo.FindMatches(p, args[1]); if (who == null) { return; } DateTime cooldown = Team.GetData(p).NextInvite; DateTime now = DateTime.UtcNow; if (now < cooldown) { p.Message(prefix + "You can invite a player to join your party in another {0} seconds", (int)(cooldown - now).TotalSeconds); return; } Team.GetData(p).NextInvite = now.AddSeconds(5); team.Action(p, "invited " + who.ColoredName + "%S to join the party."); who.Message(prefix + p.ColoredName + " %Shas sent you a party request."); who.Message("To join, type %b/party join%S or ignore this message to decline."); Team.GetData(who).Invite = team.Name; }
void HandleKick(Player p, string[] args) { string prefix = "%dParties> %S"; string noParty = prefix + "You are not in a party."; Team team = Team.GetData(p).Team; if (team == null) { p.Message(noParty); return; } if (args.Length == 1) { p.Message(prefix + "You need to provide the name of the player to kick."); return; } if (!p.name.CaselessEq(team.Owner)) { p.Message(prefix + "Only the party owner can kick players from the party."); return; } if (team.Remove(args[1])) { team.Action(p, "kicked " + args[1] + " %Sfrom the party."); Player who = PlayerInfo.FindExact(args[1]); if (who != null) { Team.GetData(who).Team = null; } team.OwnerLeft(p); Team.SaveList(); } else { p.Message(prefix + "Player not found. You need to use their full account name."); } }
public void OwnerLeft(Player p) { Team team = Team.GetData(p).Team; if (Members.Count > 0) { // Choose a new owner at random team.Action(p, "has left the party (disconnected)."); team.Remove(p.name); Team.SaveList(); Team.GetData(p).Team = null; var random = new Random(); int index = random.Next(team.Members.Count); team.Message(p, "%dThe new party owner is %b" + team.Members[index]); team.Owner = team.Members[index]; Team.SaveList(); return; } Teams.Remove(this); // Remove empty }