Esempio 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();
 }
Esempio 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();
     }
 }
Esempio 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();
     }
 }
Esempio 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();
     }
 }
Esempio 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;
                    }
                }
            }
        }
Esempio 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();
     }
 }
Esempio 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");
     }
 }
Esempio 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");
     }
 }
Esempio 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();
         }
     }
 }
Esempio n. 10
0
 protected virtual void OnObjectRemoved(BaseGameObject obj)
 {
 }
Esempio n. 11
0
 protected virtual void OnObjectAdded(BaseGameObject obj)
 {
 }
Esempio n. 12
0
 internal virtual void OnObjectRemovedInternal(BaseGameObject obj)
 {
     OnObjectRemoved(obj);
 }