Exemplo n.º 1
0
        public void NotifyGeneratorDestroyAndRemoveAllListeners()
        {
            if (m_all_type_listeners == null)
            {
                return;
            }
            var all_type_listeners = m_all_type_listeners;

            m_all_type_listeners = null;
            LogicWorld    logic_world = GetLogicWorldForSignal();
            var           enumerator  = all_type_listeners.GetEnumerator();
            HashSet <int> notified    = new HashSet <int>();

            while (enumerator.MoveNext())
            {
                List <SignalListenerContext> listeners = enumerator.Current.Value;
                for (int i = 0; i < listeners.Count; ++i)
                {
                    SignalListenerContext context = listeners[i];
                    if (notified.Contains(context.ID))
                    {
                        continue;
                    }
                    notified.Add(context.ID);
                    ISignalListener listener = context.GetListener(logic_world);
                    if (listener != null)
                    {
                        listener.OnGeneratorDestroyed(this);
                    }
                }
            }
        }
Exemplo n.º 2
0
 public override void ResetNode()
 {
     if (m_listener_context != null)
     {
         Entity owner = m_context.GetData <Entity>(BTContextKey.OwnerEntity);
         for (int i = 0; i < m_signal_datas.Count; ++i)
         {
             owner.RemoveListener(m_signal_datas[i].m_signal_id, m_listener_context.ID);
         }
         SignalListenerContext.Recycle(m_listener_context);
         m_listener_context = null;
         m_context.GetLogicWorld().UnregisterBehaviorTree(this);
         m_register_id = 0;
     }
     ClearRunningTrace();
     base.ResetNode();
     if (m_context != null)
     {
         BTContext context = m_context;
         SetContext(null);
         RecyclableObject.Recycle(context);
     }
     m_current_running_entry_index = -1;
     if (m_task != null)
     {
         m_task.Cancel();
         LogicTask.Recycle(m_task);
         m_task = null;
     }
 }
Exemplo n.º 3
0
 protected override void PostInitializeComponent()
 {
     if (m_die_with_master)
     {
         m_listener_context = SignalListenerContext.CreateForEntityComponent(GetLogicWorld().GenerateSignalListenerID(), ParentObject.ID, m_component_type_id);
     }
 }
 protected override void PostInitializeComponent()
 {
     if (m_attributes.Count > 0)
     {
         m_listener_context = SignalListenerContext.CreateForEntityComponent(GetLogicWorld().GenerateSignalListenerID(), ParentObject.ID, m_component_type_id);
         ParentObject.AddListener(SignalType.ChangeLevel, m_listener_context);
     }
 }
Exemplo n.º 5
0
        public static SignalListenerContext CreateForBehaviorTree(int listener_id, int tree_id)
        {
            SignalListenerContext context = RecyclableObject.Create <SignalListenerContext>();

            context.m_context_type = SignalListenerContextType.BehaviorTree;
            context.m_listener_id  = listener_id;
            context.m_object_id    = tree_id;
            return(context);
        }
Exemplo n.º 6
0
        public static SignalListenerContext CreateForEffectComponent(int listener_id, int effect_id, int component_type_id)
        {
            SignalListenerContext context = RecyclableObject.Create <SignalListenerContext>();

            context.m_context_type      = SignalListenerContextType.EffectComponent;
            context.m_listener_id       = listener_id;
            context.m_object_id         = effect_id;
            context.m_component_type_id = component_type_id;
            return(context);
        }
Exemplo n.º 7
0
 protected override void OnDestruct()
 {
     SignalListenerContext.Recycle(m_listener_context);
     m_listener_context = null;
     if (m_task != null)
     {
         m_task.Cancel();
         LogicTask.Recycle(m_task);
         m_task = null;
     }
 }
Exemplo n.º 8
0
 protected override void PostInitializeComponent()
 {
     m_target_gathering_param           = new TargetGatheringParam();
     m_target_gathering_param.m_type    = TargetGatheringType.SurroundingRing;
     m_target_gathering_param.m_param1  = m_guard_range;
     m_target_gathering_param.m_faction = FactionRelation.Enemy;
     m_targeting_component = ParentObject.GetComponent(TargetingComponent.ID) as TargetingComponent;
     if (m_targeting_component == null)
     {
         return;
     }
     m_listener_context = SignalListenerContext.CreateForEntityComponent(GetLogicWorld().GenerateSignalListenerID(), ParentObject.ID, m_component_type_id);
     Schedule();
 }
Exemplo n.º 9
0
 protected override void OnDestruct()
 {
     m_targeting_component = null;
     SignalListenerContext.Recycle(m_listener_context);
     m_listener_context = null;
     if (m_task != null)
     {
         m_task.Cancel();
         LogicTask.Recycle(m_task);
         m_task = null;
     }
     ClearTargets();
     m_current_enemy = null;
 }
Exemplo n.º 10
0
        protected override void PostInitializeComponent()
        {
            LogicWorld logic_world = GetLogicWorld();
            var        enumerator  = m_index2id.GetEnumerator();

            while (enumerator.MoveNext())
            {
                int skill_index = enumerator.Current.Key;
                int skill_cfgid = enumerator.Current.Value;
                CreateSkill(skill_index, skill_cfgid);
            }
            m_locomotor_cmp    = ParentObject.GetComponent(LocomotorComponent.ID) as LocomotorComponent;
            m_listener_context = SignalListenerContext.CreateForEntityComponent(logic_world.GenerateSignalListenerID(), ParentObject.ID, m_component_type_id);
            ParentObject.AddListener(SignalType.StartMoving, m_listener_context);
        }
Exemplo n.º 11
0
 protected override void OnDestruct()
 {
     if (m_listener_context != null)
     {
         if (m_master_id > 0)
         {
             Entity master = GetLogicWorld().GetEntityManager().GetObject(m_master_id);
             if (master != null)
             {
                 master.RemoveListener(SignalType.Die, m_listener_context.ID);
             }
         }
         SignalListenerContext.Recycle(m_listener_context);
         m_listener_context = null;
     }
 }
Exemplo n.º 12
0
        protected override void OnDestruct()
        {
            m_locomotor_cmp = null;
            ParentObject.RemoveListener(SignalType.StartMoving, m_listener_context.ID);
            SignalListenerContext.Recycle(m_listener_context);
            m_listener_context = null;

            SkillManager skill_manager = GetLogicWorld().GetSkillManager();
            var          enumerator    = m_index2id.GetEnumerator();

            while (enumerator.MoveNext())
            {
                int skill_id = enumerator.Current.Value;
                skill_manager.DestroyObject(skill_id);
            }
        }
        protected override void OnDestruct()
        {
            if (m_listener_context != null)
            {
                ParentObject.RemoveListener(SignalType.ChangeLevel, m_listener_context.ID);
                SignalListenerContext.Recycle(m_listener_context);
                m_listener_context = null;
            }

            var enumerator = m_attributes.GetEnumerator();

            while (enumerator.MoveNext())
            {
                RecyclableObject.Recycle(enumerator.Current.Value);
            }
            m_attributes.Clear();
        }
Exemplo n.º 14
0
        protected override void PostInitializeComponent()
        {
            ResetSpawnAreaRange();
            if (m_update_interval < FixPoint.One)
            {
                m_update_interval = FixPoint.One;
            }
            m_listener_context = SignalListenerContext.CreateForEntityComponent(GetLogicWorld().GenerateSignalListenerID(), ParentObject.ID, m_component_type_id);
            m_task             = LogicTask.Create <ComponentCommonTask>();
            m_task.Construct(this);
            var schedeler = GetLogicWorld().GetTaskScheduler();

            schedeler.Schedule(m_task, GetCurrentTime(), m_update_interval, m_update_interval);
            for (int i = 0; i < m_init_count; ++i)
            {
                SpawnOneObject();
            }
        }
Exemplo n.º 15
0
        public void SendSignal(int signal_type, System.Object signal = null)
        {
            if (m_all_type_listeners == null)
            {
                return;
            }
            List <SignalListenerContext> listeners;

            if (!m_all_type_listeners.TryGetValue(signal_type, out listeners))
            {
                return;
            }
            int cur_count = listeners.Count;

            if (cur_count == 0)
            {
                return;
            }
            LogicWorld logic_world = GetLogicWorldForSignal();
            int        index       = 0;

            while (index < cur_count)
            {
                SignalListenerContext context  = listeners[index];
                ISignalListener       listener = context.GetListener(logic_world);
                if (listener == null)
                {
                    listeners.RemoveAt(index);
                }
                else
                {
                    listener.ReceiveSignal(this, signal_type, signal);
                }
                int new_count = listeners.Count;
                if (new_count < cur_count)
                {
                    cur_count = new_count;
                }
                else
                {
                    ++index;
                }
            }
        }
Exemplo n.º 16
0
        public void AddListener(int signal_type, SignalListenerContext listener_context)
        {
            if (m_all_type_listeners == null)
            {
                m_all_type_listeners = new SortedDictionary <int, List <SignalListenerContext> >();
            }
            List <SignalListenerContext> listeners;

            if (!m_all_type_listeners.TryGetValue(signal_type, out listeners))
            {
                listeners = new List <SignalListenerContext>();
                m_all_type_listeners[signal_type] = listeners;
            }
            for (int i = 0; i < listeners.Count; ++i)
            {
                if (listeners[i].m_listener_id == listener_context.m_listener_id)
                {
                    return;
                }
            }
            listeners.Add(listener_context);
        }
Exemplo n.º 17
0
        public void Active()
        {
            if (m_signal_datas == null || m_signal_datas.Count == 0)
            {
                return;
            }
            if (m_context == null)
            {
                return;
            }
            Entity owner = m_context.GetData <Entity>(BTContextKey.OwnerEntity);

            if (owner == null)
            {
                return;
            }
            m_context.GetLogicWorld().RegisterBehaviorTree(this);
            m_listener_context = SignalListenerContext.CreateForBehaviorTree(GetLogicWorld().GenerateSignalListenerID(), m_register_id);
            for (int i = 0; i < m_signal_datas.Count; ++i)
            {
                owner.AddListener(m_signal_datas[i].m_signal_id, m_listener_context);
            }
        }
Exemplo n.º 18
0
 public static void Recycle(SignalListenerContext instance)
 {
     RecyclableObject.Recycle(instance);
 }