Пример #1
0
        public void AddParty(Party party)
        {
            _parties.Add(party);

                        if (Game.State == GameState.Playing)
                        {
                                party.Create();

                                party.SendPreActiveInformation();
                        }
        }
Пример #2
0
        public void AddInvite(Party party)
        {
            if (party.ParentZone != ParentZone)
                        {
                                Debug.ThrowException(new Exception("incompatible parties: not the same parent zone"));
                        }

                        if (party == this)
                        {
                                Debug.ThrowException(new Exception("cannot invite party to itself"));
                        }

                        _invites.Add(party);

                        if (Created && ParentZone == Game.Zone && _members.Contains(Game.Player.Character))
                        {
                                Network.GameServer.Send(GameServerMessage.InviteParty, IdManager.GetId(party));
                        }
        }
Пример #3
0
        public void AddJoinRequest(Party party)
        {
            if (party.ParentZone != ParentZone)
                        {
                                Debug.ThrowException(new Exception("incompatible parties: not the same parent zone"));
                        }

                        if (party == this)
                        {
                                Debug.ThrowException(new Exception("cannot join request party on itself"));
                        }

                        _joinRequests.Add(party);

                        if (Created && ParentZone == Game.Zone && _members.Contains(Game.Player.Character))
                        {
                                Network.GameServer.Send(GameServerMessage.AddPartyJoinRequest, IdManager.GetId(party));
                        }
        }
Пример #4
0
        public override void HandleMessage(Message message)
        {
            PlayerCharacter groupLeader;
            Party party;
            switch (message.Event)
            {
                case "update":
                    {
                        try
                        {
                            bool newParty = false;
                            groupLeader = Entity.GetEntity<Player>(Guid.Parse(message.Payload.leader.ToString())).Character;
                            party = Game.Zone.Parties.FirstOrDefault(x => x.Leader == groupLeader);
                            if (party == null)
                            {
                                party = new Party(groupLeader);
                                newParty = true;
                            }

                            AddMembersToParty(party, message.Payload.members);
                            AddOrRemoveInvites(party, message.Payload.invited);
                            GenerateJoinRequests(groupLeader, message.Payload.invited);

                            if (newParty)
                                Game.Zone.AddParty(party);
                        }
                        catch (Exception ex)
                        {
                        }
                    }
                    break;

                case "remove":
                    {
                        //party.RemoveMember();
                    }
                    break;

                case "map:change":
                    break;
            }
        }
Пример #5
0
        private void AddMembersToParty(Party party, JArray members)
        {
            if (members == null) return;
            string[] items = members.Select(jv => (string)jv).ToArray();
            if (items.Length != party.Members.Length)
            {
                foreach (string member in items)
                {
                    PlayerCharacter character = Entity.GetEntity<Player>(Guid.Parse(member)).Character;

                    if (party.Leader == character) continue;

                    if (party.Members.Contains(character)) continue;
                    party.RemoveMember(character);
                }

                if (!items.Any())
                {
                    // Remove all members
                    foreach (PlayerCharacter member in party.Members)
                    {
                        if (party.Leader == member) continue;
                        party.RemoveMember(member);
                    }
                }
            }
            else
            {
                foreach (string entityId in items)
                {
                    PlayerCharacter groupmember = Entity.GetEntity<Player>(Guid.Parse(entityId)).Character;
                    Party groupMembersParty = Game.Zone.Parties.FirstOrDefault(x => x.Leader == groupmember);
                    party.RemoveInvite(groupMembersParty); // remove added Group from invites
                    party.MergeParty(groupMembersParty);
                }
            }
        }
Пример #6
0
        public void RemoveParty(Party party)
        {
            _parties.Remove(party);

                        if (Game.State == GameState.Playing)
                        {
                                party.Destroy();
                        }
        }
Пример #7
0
        public void RemoveMember(PlayerCharacter agent)
        {
            if (!_members.Contains(agent))
                        {
                                Debug.ThrowException(new Exception("agent " + agent.Name + " not part of this party"));
                        }

                        if (_members.Count <= 1)
                        {
                                Debug.ThrowException(new Exception("cannot remove last member of group"));
                        }

                        _members.Remove(agent);

                        if (Created && ParentZone == Game.Zone)
                        {
                                if (agent != Leader)
                                {
                                        Network.GameServer.Send(GameServerMessage.RemovePartyMember, IdManager.GetId(this), (ushort) IdManager.GetId(agent));

                                        if (agent == Game.Player.Character)
                                        {
                                                Game.Zone.AddParty(new Party(Game.Player.Character));
                                        }
                                }
                                else
                                {
                                        Game.Zone.RemoveParty(this);

                                        var restParty = new Party(_members[0]);

                                        Game.Zone.AddParty(restParty);

                                        foreach (PlayerCharacter member in _members)
                                        {
                                                if (member == restParty.Leader) continue;

                                                restParty.AddMember(member);
                                        }

                                        foreach (Party invite in _invites)
                                        {
                                                restParty.AddInvite(invite);
                                        }

                                        foreach (Party joinRequest in _joinRequests)
                                        {
                                                restParty.AddJoinRequest(joinRequest);
                                        }

                                        Game.Zone.AddParty(new Party(Leader));
                                }
                        }
        }
Пример #8
0
        public void RemoveJoinRequest(Party party)
        {
            if (party.ParentZone != ParentZone)
                        {
                                Debug.ThrowException(new Exception("incompatible parties: not the same parent zone"));
                        }

                        if (!_joinRequests.Contains(party))
                        {
                                Debug.ThrowException(new Exception("party not a join request of this party"));
                        }

                        _joinRequests.Remove(party);

                        if (Created && ParentZone == Game.Zone && _members.Contains(Game.Player.Character))
                        {
                                Network.GameServer.Send(GameServerMessage.KickPartyJoinRequest, IdManager.GetId(party));
                        }
        }
Пример #9
0
        public void RemoveInvite(Party party)
        {
            if (party.ParentZone != ParentZone)
                        {
                                Debug.ThrowException(new Exception("incompatible parties: not the same parent zone"));
                        }

                        if (!_invites.Contains(party))
                        {
                                Debug.ThrowException(new Exception("party not invited to this party"));
                        }

                        _invites.Remove(party);

                        if (Created && ParentZone == Game.Zone && _members.Contains(Game.Player.Character))
                        {
                                Network.GameServer.Send(GameServerMessage.KickInvitedParty, IdManager.GetId(party));
                        }
        }
Пример #10
0
        public void MergeParty(Party otherParty)
        {
            Game.Zone.RemoveParty(otherParty);

                        foreach (PlayerCharacter member in otherParty._members)
                        {
                                AddMember(member);
                        }
        }
Пример #11
0
 private void AddOrRemoveInvites(Party party, JArray invites)
 {
     if (invites == null) return;
     string[] items = invites.Select(jv => (string)jv).ToArray();
     foreach (string entityId in items)
     {
         PlayerCharacter invite = Entity.GetEntity<Player>(Guid.Parse(entityId)).Character;
         Party partyOfInvitedMember =
             Game.Zone.Parties.FirstOrDefault(x => x.Members.Contains(invite) || x.Leader == invite);
         party.AddInvite(partyOfInvitedMember);
     }
 }