Ejemplo n.º 1
0
 internal void AddObject(BaseGameObject obj)
 {
     // called only from within World class so no lock is required
     // GameDebugger.Log("Map added object");
     m_Objects.Add(obj.UID, obj);
     OnObjectAddedInternal(obj);
     obj.OnMapEnterInternal();
 }
Ejemplo n.º 2
0
 internal void ActivateObject(BaseGameObject obj)
 {
     // called only from within World class so no lock is required
     if (!obj.m_ObjectActive)
     {
         // GameDebugger.Log("Map activated object");
         ActiveObjects.Add(obj);
         obj.m_ObjectActive = true;
         obj.OnActivateObjectInternal();
     }
 }
Ejemplo n.º 3
0
 internal void DeactivateObject(BaseGameObject obj)
 {
     // called only from within World class and RemoveObject method so no lock is required
     if (obj.m_ObjectActive)
     {
         // GameDebugger.Log("Map deactivated object");
         ActiveObjects.Remove(obj);
         obj.m_ObjectActive = false;
         obj.OnDeactivateObjectInternal();
     }
 }
Ejemplo n.º 4
0
 internal void RemoveObject(BaseGameObject obj)
 {
     // called only from within World class so no lock is required
     if (m_Objects.ContainsKey(obj.UID))
     {
         // GameDebugger.Log("Map removed object");
         m_Objects.Remove(obj.UID);
         DeactivateObject(obj);
         OnObjectRemovedInternal(obj);
         obj.OnMapLeaveInternal();
     }
 }
Ejemplo n.º 5
0
        internal static void MoveObjectAcrossMaps(BaseGameObject obj, BaseGameMap map)
        {
            lock ( Objects ) {
                if (obj.BaseGameMap != map)
                {
                    if (Objects.ContainsKey(obj.UID))
                    {
                        // GameDebugger.Log("World moved object across maps");
                        bool wasActive = obj.m_ObjectActive;
                        if (obj.m_BaseGameMap != null)
                        {
                            obj.m_BaseGameMap.RemoveObject(obj);
                        }
                        else if (wasActive)
                        {
                            // GameDebugger.Log("World deactivated object (moam)");
                            ActiveObjects.Remove(obj);
                            obj.m_ObjectActive = false;
                            obj.OnDeactivateObjectInternal();
                        }

                        obj.m_BaseGameMap = map;

                        if (map != null)
                        {
                            map.AddObject(obj);
                            if (wasActive)
                            {
                                map.ActivateObject(obj);
                            }
                        }
                        else if (wasActive)
                        {
                            // GameDebugger.Log("World activated object (moam)");
                            ActiveObjects.Add(obj);
                            obj.m_ObjectActive = true;
                            obj.OnActivateObjectInternal();
                        }
                    }
                    else
                    {
                        // GameDebugger.Log("World updated object map");
                        obj.m_BaseGameMap = map;
                    }
                }
            }
        }
Ejemplo n.º 6
0
 public static void AddObject(BaseGameObject obj)
 {
     lock ( Objects ) {
         if (Objects.ContainsKey(obj.UID))
         {
             throw new UserFriendlyException(String.Format("Object {0} is already in the world", obj.UID), "The game tried to add same object into the world twice");
         }
         obj.OnBeforeAddObjectInternal();
         // GameDebugger.Log("World added object");
         Objects.Add(obj.UID, obj);
         if (obj.BaseGameMap != null)
         {
             obj.BaseGameMap.AddObject(obj);
         }
         obj.OnAfterAddObjectInternal();
     }
 }
Ejemplo n.º 7
0
 public static void DeactivateObject(BaseGameObject obj)
 {
     lock ( Objects ) {
         if (Objects.ContainsKey(obj.UID))
         {
             if (obj.BaseGameMap != null)
             {
                 obj.BaseGameMap.DeactivateObject(obj);
             }
             else if (obj.m_ObjectActive)
             {
                 // GameDebugger.Log("World deactivated object");
                 ActiveObjects.Remove(obj);
                 obj.m_ObjectActive = false;
                 obj.OnDeactivateObjectInternal();
             }
         }
         // else
         // throw new UserFriendlyException(String.Format("Cannot deactivate object {0}: it is not added to the world yet", obj.UID), "The game tried to deactivate that was not added into the world");
     }
 }
Ejemplo n.º 8
0
 public static void ActivateObject(BaseGameObject obj)
 {
     lock ( Objects ) {
         if (Objects.ContainsKey(obj.UID))
         {
             if (obj.BaseGameMap != null)
             {
                 obj.BaseGameMap.ActivateObject(obj);
             }
             else if (!obj.m_ObjectActive)
             {
                 // GameDebugger.Log("World activated object");
                 ActiveObjects.Add(obj);
                 obj.m_ObjectActive = true;
                 obj.OnActivateObjectInternal();
             }
         }
         // else
         // throw new UserFriendlyException(String.Format("Cannot activate object {0}: it is not in the world", obj.UID), "The game tried to activate an object that was not added into the world");
     }
 }
Ejemplo n.º 9
0
 public static void RemoveObject(BaseGameObject obj)
 {
     lock ( Objects ) {
         if (Objects.ContainsKey(obj.UID))
         {
             obj.OnBeforeRemoveObjectInternal();
             // GameDebugger.Log("World removed object");
             Objects.Remove(obj.UID);
             BaseGameMap map = obj.BaseGameMap;
             if (map != null)
             {
                 map.RemoveObject(obj);
             }
             else if (obj.m_ObjectActive)
             {
                 // GameDebugger.Log("World deactivated object (on remove)");
                 ActiveObjects.Remove(obj);
                 obj.m_ObjectActive = false;
                 obj.OnDeactivateObjectInternal();
             }
             obj.OnAfterRemoveObjectInternal();
         }
     }
 }
Ejemplo n.º 10
0
 protected virtual void OnObjectRemoved(BaseGameObject obj)
 {
 }
Ejemplo n.º 11
0
 protected virtual void OnObjectAdded(BaseGameObject obj)
 {
 }
Ejemplo n.º 12
0
 internal virtual void OnObjectRemovedInternal(BaseGameObject obj)
 {
     OnObjectRemoved(obj);
 }