public AsyncBaseObjectRef(IBaseObject baseObject)
 {
     if (baseObject == null)
     {
         this.baseObject = null;
     }
     else
     {
         lock (baseObject)
         {
             this.baseObject = baseObject.AddRef() ? baseObject : null;
         }
     }
 }
Ejemplo n.º 2
0
        public bool CreateRef(IBaseObject baseObject, bool safe)
        {
            if (baseObject == null)
            {
                return(false);
            }
            if (!createRefAutomatically)
            {
                return(true);
            }
            try
            {
                if (!baseObject.AddRef())
                {
                    // Check safe to prevent throw on TryToAsync calls
                    if (!safe && throwOnExistsCheck)
                    {
                        throw baseObject switch
                              {
                                  IEntity entity => new EntityRemovedException(entity),
                                  IWorldObject worldObject => new WorldObjectRemovedException(worldObject),
                                  _ => new BaseObjectRemovedException(baseObject)
                              };
                    }

                    return(false);
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
                return(false);
            }

            Alt.CoreImpl.CountUpRefForCurrentThread(baseObject);
            baseObjectRefs.AddLast(baseObject);
            return(true);
        }
Ejemplo n.º 3
0
 public BaseObjectRef(IBaseObject baseObject)
 {
     this.baseObject = baseObject?.AddRef() == true ? baseObject : null;
 }