public static readonly Dictionary <int, Party> Invites = new Dictionary <int, Party>(); //invitee -> party public static void CreateParty(Character leader) { if (leader == null) { return; } if (leader.Job == 0) { _log.Warn($"Cannot create party because the leader would be a beginner. Leader {leader.ID}"); leader.SendPacket(PartyPacket.PartyError(PartyFunction.CREATE_NEW_BEGINNER_DISALLOWED)); return; } if (leader.PartyID != 0) { _log.Warn($"Cannot create party because the leader is already in a party. Leader {leader.ID}"); leader.SendPacket(PartyPacket.PartyError(PartyFunction.CREATE_NEW_ALREADY_JOINED)); return; } PartyMember ldr = new PartyMember(leader.ID, leader.Name, true); int id = IdGenerator.NextValue(); Party pty = new Party(id, ldr); _log.Info($"Created party {id} with leader {leader.ID}"); Parties.Add(pty.partyId, pty); leader.PartyID = pty.partyId; leader.SendPacket(PartyPacket.PartyCreated(leader.ID, pty.partyId)); }
public void TryJoin(Character chr) { if (!Invites.ContainsKey(chr.ID)) { Program.MainForm.LogAppend("Trying to join party while no invite. CharacterID: {0}, party ID {1}", chr.ID, partyId); chr.SendPacket(PartyPacket.PartyError(PartyFunction.UNABLE_TO_FIND_PLAYER)); return; } Invites.Remove(chr.ID); if (IsFull()) { _log.Warn($"Invite accepted to party {partyId} by {chr.ID}, but its already full."); chr.SendPacket(PartyPacket.PartyError(PartyFunction.JOIN_ALREADY_FULL)); return; } if (chr.PartyID != 0) { _log.Warn($"Invite accepted to party {partyId} by {chr.ID}, the person is already in a party"); chr.SendPacket(PartyPacket.PartyError(PartyFunction.JOIN_ALREADY_JOINED)); return; } if (leader.GetMap() != chr.MapID) { _log.Warn($"Invite accepted to party {partyId} by {chr.ID}, but is not in the same map."); chr.SendPacket(PartyPacket.PartyError(PartyFunction.UNABLE_TO_FIND_PLAYER)); return; } Join(chr); }
public void Leave(Character f****r) { var slot = GetCharacterSlot(f****r.ID); if (slot == -1 || f****r.PartyID == 0) { _log.Error($"{f****r.ID} tried to get out of party {partyId}, but is not in it?"); f****r.SendPacket(PartyPacket.PartyError(PartyFunction.WITHDRAW_NOT_JOINED)); } else if (f****r.ID == leader.id) { _log.Debug($"Disbanding because {f****r.ID} left the party {partyId} (leader)"); Disband(f****r); } else { _log.Debug($"{f****r.ID} left the party {partyId} from slot {slot}"); var leaving = members[slot]; members[slot] = null; ForAllMembers(m => m.SendPacket(PartyPacket.MemberLeft(m, leaving, this, false, false))); leaving.SendPacket(PartyPacket.MemberLeft(leaving, leaving, this, false, false)); f****r.PartyID = 0; SendUpdatePartyData(); UpdateAllDoors(); } }
public void Invite(int invitor, int invitee) => OnlyWithLeader(invitor, ldr => { var toInvite = CenterServer.Instance.FindCharacter(invitee); if (toInvite == null) { ldr.SendPacket(PartyPacket.PartyError(PartyFunction.UNABLE_TO_FIND_PLAYER)); } else if (Invites.ContainsKey(toInvite.ID)) { ldr.SendPacket(PartyPacket.PartyErrorWithName(PartyFunction.INVITE_USER_ALREADY_HAS_INVITE, toInvite.Name)); } else if (toInvite.PartyID != 0) { ldr.SendPacket(PartyPacket.PartyError(PartyFunction.JOIN_ALREADY_JOINED)); } else if (IsFull()) { ldr.SendPacket(PartyPacket.PartyError(PartyFunction.JOIN_ALREADY_FULL)); } else { _log.Debug($"Sending invite from party {partyId} from character {invitor} to {invitee}"); toInvite.SendPacket(PartyPacket.PartyInvite(this)); Invites.Add(toInvite.ID, this); //TODO do invites expire? } });