Ejemplo n.º 1
0
        public static CombatEventTree Parse(CombatEvent evt)
        {
            CombatEventTree root = new CombatEventTree();

            root.Event     = evt;
            root.NodeState = CombatEventTreeState.INITED;
            root.TreeState = CombatEventTreeState.INITED;

            if (evt.Children == null)
            {
                return(root);
            }

            // children are CombatEffectEvent
            for (int i = 0, cnt = evt.Children.Count; i < cnt; ++i)
            {
                CombatEffectEvent effect   = evt.Children[i] as CombatEffectEvent;
                CombatEventTree   sub_tree = Parse(effect);

                if (effect.Parent < 0)
                {
                    root.AddChild(sub_tree);
                }
                else
                {
                    CombatEvent     parent_effect = evt.Children[effect.Parent];
                    CombatEventTree parent        = root.FindInChildren(parent_effect);
                    parent.AddChild(sub_tree);
                }
            }

            return(root);
        }
Ejemplo n.º 2
0
 public virtual void Init(Combatant combatant, CombatEvent combat_event)
 {
     Combatant = combatant;
     Event     = combat_event;
     Disabled  = true;
     StartTime = Time.time;
 }
Ejemplo n.º 3
0
        public CombatEventTree FindInSiblings(CombatEvent evt)
        {
            if (m_parent == null)
            {
                return(null);
            }

            // speed up
            CombatEventTree found = null;

            if (s_nodeCache.TryGetValue(evt.GetHashCode(), out found))
            {
                if (found.IsAncestor(m_parent) && found != this)
                {
                    return(found);
                }
            }
            EB.Debug.LogWarning("CombatEventTree.FindInSiblings: cache miss");

            var iter = m_parent.GetChildrenNonAlloc();

            while (iter.MoveNext())
            {
                CombatEventTree sibling = iter.Current;

                if (sibling == this)
                {
                    continue;
                }

                if (sibling.Event.Equals(evt))
                {
                    iter.Dispose();
                    return(sibling);
                }
            }
            iter.Dispose();

            iter = m_parent.GetChildrenNonAlloc();
            while (iter.MoveNext())
            {
                CombatEventTree sibling = iter.Current;

                if (sibling == this)
                {
                    continue;
                }

                found = sibling.FindInChildren(evt);
                if (found != null)
                {
                    iter.Dispose();
                    return(found);
                }
            }
            iter.Dispose();

            return(null);
        }
Ejemplo n.º 4
0
        public override void Init(Combatant combatant, CombatEvent combat_event)
        {
            //Debug.Assert(combat_event is ReactionEffectEvent, "invalid event type");

            base.Init(combatant, combat_event);

            ReactionEvent = combat_event as ReactionEffectEvent;
        }
Ejemplo n.º 5
0
        public CombatEventState(Combatant combatant, CombatEvent combat_event)
        {
            Combatant = combatant;
            Event     = combat_event;

            Disabled  = true;
            StartTime = Time.time;
        }
Ejemplo n.º 6
0
        public static CombatEvent CreateEventInstance(eCombatEventType type)
        {
            Dictionary <int, System.Type> class_type_dic = sEventClassDic;

            if (!class_type_dic.ContainsKey((int)type))
            {
                return(null);
            }

            System.Type class_type = class_type_dic[(int)type];
            CombatEvent instance   = System.Activator.CreateInstance(class_type) as CombatEvent;

            return(instance);
        }
Ejemplo n.º 7
0
        public CombatEventTree FindInParents(CombatEvent evt)
        {
            if (m_parent == null)
            {
                return(null);
            }

            if (m_parent.Event.Equals(evt))
            {
                return(m_parent);
            }

            return(m_parent.FindInParents(evt));
        }
Ejemplo n.º 8
0
        public bool Equals(CombatEvent cmp_evt)
        {
            if (cmp_evt == null)
            {
                return(false);
            }

            if (cmp_evt == this)
            {
                return(true);
            }

            return(cmp_evt.GetUniqueCode() == GetUniqueCode());
        }
Ejemplo n.º 9
0
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }

            if (obj == this)
            {
                return(true);
            }

            if (obj is CombatEvent == false)
            {
                return(false);
            }

            CombatEvent cmp_evt = obj as CombatEvent;

            return(cmp_evt.GetUniqueCode() == GetUniqueCode());
        }
Ejemplo n.º 10
0
        public CombatEventTree Find(CombatEvent evt)
        {
            // speed up
            CombatEventTree found = null;

            if (s_nodeCache.TryGetValue(evt.GetHashCode(), out found))
            {
                if (found == this || found.IsAncestor(this))
                {
                    return(found);
                }
            }

            if (m_event.Equals(evt))
            {
                return(this);
            }

            EB.Debug.LogWarning("CombatEventTree.Find: cache miss");

            var iter = m_children.GetEnumerator();

            while (iter.MoveNext())
            {
                var pair = iter.Current;
                List <CombatEventTree> tree_list = pair.Value;
                for (int i = 0, cnt = tree_list.Count; i < cnt; ++i)
                {
                    found = tree_list[i].Find(evt);
                    if (found != null)
                    {
                        iter.Dispose();
                        return(found);
                    }
                }
            }
            iter.Dispose();

            return(null);
        }
Ejemplo n.º 11
0
        public CombatEventTree FindInChildren(CombatEvent evt)
        {
            // speed up
            CombatEventTree found = null;

            if (s_nodeCache.TryGetValue(evt.GetHashCode(), out found))
            {
                if (found.IsAncestor(this))
                {
                    return(found);
                }
            }
            EB.Debug.LogWarning("CombatEventTree.FindInChildren: cache miss");

            var iter = GetChildrenNonAlloc();

            while (iter.MoveNext())
            {
                CombatEventTree child = iter.Current;

                if (child.Event.Equals(evt))
                {
                    iter.Dispose();
                    return(child);
                }

                found = child.FindInChildren(evt);
                if (found != null)
                {
                    iter.Dispose();
                    return(found);
                }
            }
            iter.Dispose();

            return(null);
        }