Ejemplo n.º 1
0
        // TODO Add ObjectType: PreExisting
        private void Instantiate(IPooledObject <ReplicatedObject> pooledObject, ObjectType?type, ObjectRole role,
                                 ObjectId objectId, ConnectionId connectionId)
        {
            var @object = pooledObject.Instance;

            @object.GameObjectNetworkInfo.ObjectType = type.HasValue ? type.Value : new ObjectType(0);
            @object.GameObjectNetworkInfo.ObjectId   = objectId;
            @object.GameObjectNetworkInfo.Role       = role;
            @object.Type          = type;
            @object.Role          = role;
            @object.Id            = objectId;
            @object.IsPreExisting = false;
            @object.GlobalObjectId.CopyFrom(Guid.Empty);
            @object.OwnerConnectionId     = role.IsOwner() ? ConnectionId.Self : connectionId;
            @object.AuthorityConnectionId = role.IsAuthority() ? ConnectionId.Self : connectionId;
            role.ApplyTo(@object.GameObject);
            if (!_instances.ContainsKey(@object.Id))
            {
                _instances[@object.Id] = pooledObject;
            }
            else
            {
                throw new Exception("Cannot replicate instance of " + type + " with " + objectId + " cause the object id is already assigned");
            }
        }
        private void AddReplicatedInstance(IPooledObject <ReplicatedObject> pooledObject, ObjectType?type, ObjectRole role,
                                           ObjectId objectId, ConnectionId connectionId)
        {
            var @object = pooledObject.Instance;

            @object.GameObjectNetworkInfo.ObjectType = type.HasValue ? type.Value : new ObjectType(0);
            @object.GameObjectNetworkInfo.ObjectId   = objectId;
            @object.GameObjectNetworkInfo.Role       = role;
            @object.Type          = type;
            @object.Role          = role;
            @object.Id            = objectId;
            @object.IsPreExisting = false;
            @object.GlobalObjectId.CopyFrom(Guid.Empty);
            @object.OwnerConnectionId     = role.IsOwner() ? ConnectionId.NoConnection : connectionId;
            @object.AuthorityConnectionId = role.IsAuthority() ? ConnectionId.NoConnection : connectionId;
            role.ApplyRoleTo(@object.GameObject);
            if (_instances[@object.Id.Value] == null)
            {
                _instances[@object.Id.Value] = pooledObject;
                _objectIds.Add(@object.Id);

                if (ObjectAdded != null)
                {
                    ObjectAdded(pooledObject.Instance);
                }
            }
            else
            {
                throw new Exception("Cannot replicate instance of " + type + " with " + objectId + " cause the object id is already assigned");
            }
        }
 public NetworkRole(ObjectRole roles)
 {
     _includedObjectRoles = roles;
     // Authority is mostly mutually exlusive with the Others role so
     // it is excluded unless it is explicitely included.
     if (roles.IsOther() && !roles.IsAuthority())
     {
         _excludedObjectRoles = ObjectRole.Authority;
     }
     else
     {
         _excludedObjectRoles = ObjectRole.Nobody;
     }
 }
Ejemplo n.º 4
0
 public static void IntoList(this ObjectRole role, IList <ObjectRole> roles)
 {
     roles.Clear();
     if (role.IsOwner())
     {
         roles.Add(ObjectRole.Owner);
     }
     if (role.IsAuthority())
     {
         roles.Add(ObjectRole.Authority);
     }
     if (role.IsOther())
     {
         roles.Add(ObjectRole.Others);
     }
 }