Esempio n. 1
0
        /// <summary>
        /// Hides this <see cref="MmoObject"/> from a player's view
        /// </summary>
        /// <param name="playerGuid"></param>
        protected void HideFromPlayer(MmoGuid playerGuid)
        {
            // we cant hide ourselves
            if (playerGuid == this.guid)
            {
                return;
            }

            lock (hiddenPlayers)
            {
                // if the player is not added then he/she was already in the list
                // so skip the next step to save the overhead of lookup
                if (hiddenPlayers.Add(playerGuid) == false)
                {
                    return;
                }
            }

            WorldSession session;

            if (CurrentZone.World.SessionCache.TryGetSessionByPlayerGuid(playerGuid.Id, out session))
            {
                // telling that player to hide us
                session.Player.HideObjectFromView(this);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Removes reference for a(n) <see cref="IGroupMember"/>.
        /// </summary>
        public bool RemoveReference(MmoGuid referenceGuid)
        {
            // making sure that the reference exists
            Reference <IGroupMember> reference;

            if (!memberReferences.TryGetValue(referenceGuid, out reference))
            {
                return(false);
            }
            // removing and disposing the reference
            reference.Dispose();
            this.memberReferences.Remove(referenceGuid);

            // TODO: Send it via an event channel
            // notifying player offline
            if (IsFormed)
            {
                foreach (var world in social.Worlds)
                {
                    world.GroupManager.UpdateMemberStatus(guid, referenceGuid, OnlineStatus.Offline);
                }
            }

            return(true);
        }
Esempio n. 3
0
        /// <summary>
        /// Unhides this <see cref="MmoObject"/> from a player's view
        /// </summary>
        /// <param name="playerGuid"></param>
        protected void UnhideFromPlayer(MmoGuid playerGuid)
        {
            // we cant hide ourselves
            if (playerGuid == this.guid)
            {
                return;
            }

            lock (hiddenPlayers)
            {
                // if the player is not removed then he/she was not in the list in the first place
                // so skip the next step to save the overhead of lookup
                if (hiddenPlayers.Remove(playerGuid) == false)
                {
                    return;
                }
            }

            WorldSession player;

            if (CurrentZone.World.SessionCache.TryGetSessionByPlayerGuid(playerGuid.Id, out player))
            {
                // telling that player to unhide us
                player.Player.UnhideObjectFromView(this);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Removes a(n) <see cref="IGroupMember"/> from the group.
        /// </summary>
        public bool RemoveMember(MmoGuid memberToRemoveGuid)
        {
            // if the member does not exist, just return
            if (!members.Exists(m => m.Guid == memberToRemoveGuid))
            {
                return(false);
            }

            // TODO: Send it via an event channel
            // removing the member in every world groups
            if (IsFormed)
            {
                foreach (var world in social.Worlds)
                {
                    world.GroupManager.RemoveMember(guid, memberToRemoveGuid);
                }
            }

            Reference <IGroupMember> reference;

            if (memberReferences.TryGetValue(memberToRemoveGuid, out reference))
            {
                // the member is online send an uninvite event so the client will be notified that he or she has been removed from the group
                var memberToRemove = reference.Object;
                // send an uninvite event so the client will be notified he/she has been removed from the group
                memberToRemove.Peer.SendEvent(new GroupUninvited(), new MessageParameters {
                    ChannelId = PeerSettings.GroupEventChannel
                });
                memberToRemove.Group = null;

                reference.Dispose();
                this.memberReferences.Remove(memberToRemoveGuid);
            }

            // removing the member from the profiles
            this.members.RemoveAll(m => m.Guid == memberToRemoveGuid);

            // if there are active members notify all of them
            if (memberReferences.Count > 0)
            {
                var groupMemberRemoved = new GroupMemberRemoved {
                    ObjectId = memberToRemoveGuid
                };
                // let every online players know that a player has been removed
                foreach (var memberReference in memberReferences)
                {
                    memberReference.Value.Object.Peer.SendEvent(groupMemberRemoved, new MessageParameters {
                        ChannelId = PeerSettings.GroupEventChannel
                    });
                }
            }

            return(true);
        }
Esempio n. 5
0
        /// <summary>
        /// Forms a new group
        /// </summary>
        public void FormNewGroup(IGroupMember groupLeader)
        {
            // we are using the current zone id as the sub id so group ids created in different zones will not collide with each other
            this.guid   = new MmoGuid((byte)ObjectType.Group, GroupManager.Instance.GenerateGroupId());
            this.leader = new GroupMemberStructure(groupLeader.Guid, groupLeader.Name);

            // add the leader as our first member
            this.AddMember(groupLeader);
            // add the group to the group manager
            GroupManager.Instance.AddGroup(this);
        }
Esempio n. 6
0
 /// <summary>
 /// Removes a(n) <see cref="MmoObject"/> from the <see cref="MmoZone"/>.
 /// </summary>
 /// <returns></returns>
 public bool Remove(MmoGuid mmoGuid)
 {
     while (!objectCache.RemoveItem(mmoGuid))
     {
         MmoObject existingObject;
         if (!objectCache.TryGetItem(mmoGuid, out existingObject))
         {
             return(false);
         }
     }
     return(true);
 }
Esempio n. 7
0
        /// <summary>
        /// Removes a member's reference
        /// </summary>
        public bool RemoveReference(MmoGuid referenceGuid)
        {
            Reference <IGroupMember> reference;

            if (!memberReferences.TryGetValue(referenceGuid, out reference))
            {
                return(false);
            }

            reference.Dispose();
            this.memberReferences.Remove(referenceGuid);
            return(true);
        }
Esempio n. 8
0
        /// <summary>
        /// Tells whether this <see cref="MmoObject"/> is hidden for a certain player or not
        /// </summary>
        /// <param name="playerGuid"></param>
        /// <returns></returns>
        public virtual bool IsHiddenFor(MmoGuid playerGuid)
        {
            // we cant hide ourselves
            if (playerGuid == this.guid)
            {
                return(false);
            }

            lock (hiddenPlayers)
            {
                return(this.hiddenPlayers.Contains(playerGuid));
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Removes a(n) <see cref="IGroupMember"/> from the group.
        /// </summary>
        public bool RemoveMember(MmoGuid memberToRemoveGuid)
        {
            // if the member does not exist, just return
            if (!members.Exists(m => m.Guid == memberToRemoveGuid))
            {
                return(false);
            }

            // removes the member's reference
            this.RemoveReference(memberToRemoveGuid);
            // removing the member from the profiles
            this.members.RemoveAll(m => m.Guid == memberToRemoveGuid);
            return(true);
        }
Esempio n. 10
0
        /// <summary>
        /// Creates a new instance of the <see cref = "MmoObject" /> class.
        /// </summary>
        /// <param name="zone"> The <see cref="MmoZone"/> the <see cref="MmoObject"/> belongs to. </param>
        /// <param name="objectId"> A unique identifier used to distinguish between other <see cref="MmoObject"/>s of this type. </param>
        /// <param name="type"> The type of the object. </param>
        /// <param name="familyId"> The family id. This will be the same for all the objects of the same kind. For example, every wolves is of the family wolf.
        /// Used in quests and combat groups. </param>
        /// <param name="bounds"> The character bounds </param>
        /// <param name="properties"> The initial builtProperties. If it is <value>NULL</value> an empty <see cref="Hashtable"/> will be created. </param>
        /// <remarks>
        /// <paramref name="objectId"/>, <paramref name="type"/>, and <paramref name="familyId"/> will be compressed into a single <see cref="Guid"/> value.
        /// This value will (have to) be globally unique accross all <see cref="MmoObject"/>s across all <see cref="MmoZone"/>s, otherwise conflicts will occur.
        /// </remarks>
        protected MmoObject(MmoZone zone, ObjectType type, int objectId, short familyId, Bounds bounds, Hashtable properties)
        {
            this.eventChannel          = new MessageChannel <MmoObjectEventMessage>();
            this.disposeChannel        = new MessageChannel <MmoObjectDisposedMessage>();
            this.positionUpdateChannel = new MessageChannel <MmoObjectPositionMessage>();

            this.guid      = new MmoGuid((byte)type, objectId, familyId);
            this.zone      = zone;
            this.transform = new Transform(bounds);

            this.properties      = properties ?? new Hashtable();
            this.Revision        = this.properties.Count;
            this.DirtyProperties = PropertyFlags.None;
            this.Flags           = MmoObjectFlags.None;

            this.hiddenPlayers = new HashSet <MmoGuid>();
        }
Esempio n. 11
0
        /// <summary>
        /// Called when an object enters the doorway
        /// </summary>
        /// <param name="objectGuid"></param>
        void OnEnterDoorway(MmoGuid objectGuid)
        {
            if (objectGuid.Type != (byte)ObjectType.Player)
            {
                return;
            }

            MmoObject playerObject;

            if (CurrentZone.ObjectCache.TryGetItem(objectGuid, out playerObject))
            {
                var player = playerObject as Player;
                if (player != null)
                {
                    player.TeleportTo(teleportToLocation);
                }
            }
        }
Esempio n. 12
0
        /// <summary>
        /// Called when a(n) group member has disconnected
        /// </summary>
        void Member_OnDisconnect(MmoGuid memberGuid)
        {
            // making sure that the reference exists
            Reference <IGroupMember> reference;

            if (!memberReferences.TryGetValue(memberGuid, out reference))
            {
                return;
            }
            // removing and disposing the reference
            reference.Dispose();
            this.memberReferences.Remove(memberGuid);

            // TODO: Send it via an event channel
            // notifying player offline
            if (IsFormed)
            {
                foreach (var world in social.Worlds)
                {
                    world.GroupManager.UpdateMemberStatus(guid, memberGuid, OnlineStatus.Offline);
                }
            }

            // if there are no active members, just return
            if (memberReferences.Count == 0)
            {
                return;
            }
            // send the member disconnected message to all group members
            var groupMemberDisconnected = new GroupMemberDisconnected {
                ObjectId = memberGuid
            };

            foreach (var memberReference in memberReferences)
            {
                memberReference.Value.Object.Peer.SendEvent(groupMemberDisconnected, new MessageParameters {
                    ChannelId = PeerSettings.GroupEventChannel
                });
            }
        }
Esempio n. 13
0
        /// <summary>
        /// Forms an existing group
        /// </summary>
        public bool FormExistingGroup(MmoGuid groupGuid, GroupMemberStructure groupLeader)
        {
            this.guid   = groupGuid;
            this.leader = groupLeader;

            // making sure that we do not already have a group with the same id
            // if its already been added and its us then we dont have to do anything
            // otherwise throw error
            Group oldGroup;

            if (GroupManager.Instance.TryGetGroup(guid, out oldGroup))
            {
                if (oldGroup != this)
                {
                    throw new ArgumentException("ExistingGroupWithSameId");
                }
                return(true);
            }

            GroupManager.Instance.AddGroup(this);
            return(true);
        }
Esempio n. 14
0
 /// <summary>
 /// Tries to retrieve a group
 /// </summary>
 public bool TryGetGroup(MmoGuid guid, out Group group)
 {
     lock (this.groups)
         return(this.groups.TryGetValue(guid, out group));
 }
Esempio n. 15
0
 public GroupMemberStructure(MmoGuid guid, string name)
 {
     this.Guid = guid;
     this.Name = name;
 }
Esempio n. 16
0
 /// <summary>
 /// Creates a new instance of the <see cref="SocialStatusChangedMessage"/> message
 /// </summary>
 /// <param name="guid"></param>
 /// <param name="status"></param>
 public SocialStatusChangedMessage(MmoGuid guid, SocialStatus status)
 {
     this.guid   = guid;
     this.status = status;
 }
Esempio n. 17
0
 /// <summary>
 /// Tells whether a(n) object with the <see cref="guid"/> is visible for the <see cref="IGroupMember"/> or not.
 /// </summary>
 public bool IsVisible(MmoGuid guid)
 {
     return(false);
 }
Esempio n. 18
0
 /// <summary>
 /// Tries to retrieve an item
 /// </summary>
 public bool TryGetItem(MmoGuid guid, out MmoObject mmoObject)
 {
     return(objects.TryGetValue(guid.Type, guid.Id, out mmoObject));
 }
Esempio n. 19
0
 public GroupMemberReference(MmoGuid guid, int sessionId, string name, IServer server)
     : base(sessionId, name, server)
 {
     this.guid         = guid;
     this.onDisconnect = new AsyncEvent();
 }
Esempio n. 20
0
 /// <summary>
 /// Removes an item from the cache
 /// </summary>
 public bool RemoveItem(MmoGuid guid)
 {
     return(objects.Remove(guid.Type, guid.Id));
 }