Пример #1
0
        /// <summary>
        /// Run once per frame in order to manage the actor
        /// </summary>
        protected virtual void Update()
        {
            // Process each of the reactors effects
            for (int i = 0; i < _Reactors.Count; i++)
            {
                ReactorAction lReactor = _Reactors[i];
                if (lReactor._IsEnabled && lReactor._IsActive)
                {
                    lReactor.Update();
                }
            }

            // Process each of the active effects
            for (int i = 0; i < _Effects.Count; i++)
            {
                ActorCoreEffect lEffect   = _Effects[i];
                bool            lIsActive = lEffect.Update();

                // If the effect is no longer active, remove it
                if (!lIsActive)
                {
                    _Effects.RemoveAt(i);
                    i--;

                    lEffect.Release();
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Adds a reactor to the list
        /// </summary>
        /// <param name="rReactor">ReactorAction to add</param>
        public virtual void AddReactor(ReactorAction rReactor)
        {
            _Reactors.Add(rReactor);
            _ReactorDefinitions.Add(rReactor.Serialize());

            rReactor.Owner = this.gameObject;
            rReactor.Awake();
        }
Пример #3
0
    /// <summary>
    /// Allows us to draw each item in the list
    /// </summary>
    /// <param name="rRect"></param>
    /// <param name="rIndex"></param>
    /// <param name="rIsActive"></param>
    /// <param name="rIsFocused"></param>
    private void DrawReactorListItem(Rect rRect, int rIndex, bool rIsActive, bool rIsFocused)
    {
        if (rIndex < mTarget._Reactors.Count)
        {
            ReactorAction lItem = mTarget._Reactors[rIndex];
            if (lItem == null)
            {
                EditorGUI.LabelField(rRect, "NULL");
                return;
            }

            rRect.y += 2;

            bool  lIsDirty    = false;
            float lHSpace     = 5f;
            float lFlexVSpace = rRect.width - lHSpace - lHSpace - 40f - lHSpace - 16f;

            string lType = BaseNameAttribute.GetName(lItem.GetType());

            EditorGUILayout.BeginHorizontal();

            Rect lTypeRect = new Rect(rRect.x, rRect.y, lFlexVSpace / 2f, EditorGUIUtility.singleLineHeight);
            EditorGUI.LabelField(lTypeRect, lType);

            Rect   lNameRect = new Rect(lTypeRect.x + lTypeRect.width + lHSpace, lTypeRect.y, lFlexVSpace / 2f, EditorGUIUtility.singleLineHeight);
            string lNewName  = EditorGUI.TextField(lNameRect, lItem.Name);
            if (lNewName != lItem.Name)
            {
                lIsDirty   = true;
                lItem.Name = lNewName;
            }

            Rect  lPriorityRect = new Rect(lNameRect.x + lNameRect.width + lHSpace, lNameRect.y, 40f, EditorGUIUtility.singleLineHeight);
            float lNewPriority  = EditorGUI.FloatField(lPriorityRect, lItem.Priority);
            if (lNewPriority != lItem.Priority)
            {
                lIsDirty       = true;
                lItem.Priority = lNewPriority;
            }

            Rect lIsEnabledRect = new Rect(lPriorityRect.x + lPriorityRect.width + lHSpace, lPriorityRect.y, 16f, 16f);
            bool lNewIsEnabled  = EditorGUI.Toggle(lIsEnabledRect, lItem.IsEnabled);
            if (lNewIsEnabled != lItem.IsEnabled)
            {
                lIsDirty        = true;
                lItem.IsEnabled = lNewIsEnabled;
            }

            EditorGUILayout.EndHorizontal();

            // Update the item if there's a change
            if (lIsDirty)
            {
                mIsDirty = true;
                mTarget._ReactorDefinitions[rIndex] = lItem.Serialize();
            }
        }
    }
Пример #4
0
        /// <summary>
        /// Processes the reactor definitions and update the reactors to match the definitions.
        /// </summary>
        public void InstantiateReactors()
        {
            int lDefCount = _ReactorDefinitions.Count;

            // First, remove any extra items that may exist
            for (int i = _Reactors.Count - 1; i >= lDefCount; i--)
            {
                _Reactors.RemoveAt(i);
            }

            // We need to match the definitions to the item
            for (int i = 0; i < lDefCount; i++)
            {
                string lDefinition = _ReactorDefinitions[i];

                Type lType = JSONSerializer.GetType(lDefinition);
                if (lType == null)
                {
                    continue;
                }

                ReactorAction lReactor = null;

                // If we don't have an item matching the type, we need to create one
                if (_Reactors.Count <= i || !lType.Equals(_Reactors[i].GetType()))
                {
                    lReactor       = Activator.CreateInstance(lType) as ReactorAction;
                    lReactor.Owner = this.gameObject;

                    if (_Reactors.Count <= i)
                    {
                        _Reactors.Add(lReactor);
                    }
                    else
                    {
                        _Reactors[i] = lReactor;
                    }
                }
                // Grab the matching item
                else
                {
                    lReactor = _Reactors[i];
                }

                // Fill the item with data from the definition
                if (lReactor != null)
                {
                    lReactor.Deserialize(lDefinition);
                }
            }

            // Allow each item to initialize now that it has been deserialized
            for (int i = 0; i < _Reactors.Count; i++)
            {
                _Reactors[i].Owner = this.gameObject;
                _Reactors[i].Awake();
            }
        }
Пример #5
0
        // Callbacks
        public void register_callback(ReactorAction callback, double waketime = NOW)
        {
            if (callback == null)
            {
                throw new ArgumentNullException(nameof(callback));
            }

            new ReactorCallback(this, callback, waketime);
        }
Пример #6
0
 /// <summary>
 /// Occurs after the character has been killed
 /// </summary>
 /// <param name="rAction"></param>
 public void OnKilled(ReactorAction rAction)
 {
     if (rAction.Message is CombatMessage)
     {
         if (((CombatMessage)rAction.Message).Defender == gameObject)
         {
             mActorCore.SetStateValue("State", KILLED);
         }
     }
 }
Пример #7
0
 public void register_async_callback(ReactorAction callback)
 {
     _async_queue.Enqueue(callback);
     try
     {
         //os.write(this._pipe_fds[1], ".");
     }
     catch
     {
     }
 }
Пример #8
0
        public ReactorTimer register_timer(ReactorAction callback, double waketime = NEVER)
        {
            var handler = new ReactorTimer(callback, waketime);

            lock (_timers)
            {
                _timers.Add(handler);
                _note_time(handler);
            }
            return(handler);
        }
Пример #9
0
        /// <summary>
        /// Removes the specified reactor from the list
        /// </summary>
        /// <param name="rReactor">ReactorAction to remove</param>
        public virtual void RemoveReactor(ReactorAction rReactor)
        {
            for (int i = 0; i < _Reactors.Count; i++)
            {
                if (_Reactors[i] == rReactor)
                {
                    _Reactors.RemoveAt(i);
                    _ReactorDefinitions.RemoveAt(i);

                    return;
                }
            }
        }
Пример #10
0
    /// <summary>
    /// Renders the currently selected step
    /// </summary>
    /// <param name="rStep"></param>
    private bool DrawReactorDetailItem(ReactorAction rItem)
    {
        bool lIsDirty = false;

        if (rItem == null)
        {
            EditorGUILayout.LabelField("NULL");
            return(false);
        }

        if (rItem.Name.Length > 0)
        {
            EditorHelper.DrawSmallTitle(rItem.Name.Length > 0 ? rItem.Name : "Actor Core Reactor");
        }
        else
        {
            string lName = BaseNameAttribute.GetName(rItem.GetType());
            EditorHelper.DrawSmallTitle(lName.Length > 0 ? lName : "Actor Core Reactor");
        }

        string lDescription = BaseDescriptionAttribute.GetDescription(rItem.GetType());

        if (lDescription.Length > 0)
        {
            EditorHelper.DrawInspectorDescription(lDescription, MessageType.None);
        }

        if (EditorHelper.TextField("Name", "Friendly name of the reactor", rItem.Name, mTarget))
        {
            lIsDirty   = true;
            rItem.Name = EditorHelper.FieldStringValue;
        }

        // Render out the Reactor specific inspectors
        bool lIsReactorDirty = rItem.OnInspectorGUI(mTargetSO, mTarget);

        if (lIsReactorDirty)
        {
            lIsDirty = true;
        }

        if (lIsDirty)
        {
            mTarget._ReactorDefinitions[mReactorList.index] = rItem.Serialize();
        }

        return(lIsDirty);
    }
Пример #11
0
        /// <summary>
        /// Allows us to choose the attack style we'll attack with
        /// </summary>
        /// <param name="rAction"></param>
        public void SelectAttackStyle(ReactorAction rAction)
        {
            if (rAction == null || rAction.Message == null)
            {
                return;
            }

            CombatMessage lCombatMessage = rAction.Message as CombatMessage;

            if (lCombatMessage == null)
            {
                return;
            }

            //lCombatMessage.StyleIndex = 2;
        }
Пример #12
0
        /// <summary>
        /// Allows us to choose the attack style we'll attack with
        /// </summary>
        /// <param name="rAction"></param>
        public void OnPostAttack(ReactorAction rAction)
        {
            mActorCore.SetStateValue("State", IDLE);

            if (rAction == null || rAction.Message == null)
            {
                return;
            }

#if USE_ARCHERY_MP || OOTII_AYMP
            // Decrease the arrows
            CombatMessage lCombatMessage = rAction.Message as CombatMessage;
            if (lCombatMessage.CombatMotion is BasicRangedAttack)
            {
                ArrowCount--;
            }
#endif
        }
Пример #13
0
    /// <summary>
    /// Allows us to add to a list
    /// </summary>
    /// <param name="rList"></param>
    private void OnReactorListItemAdd(ReorderableList rList)
    {
        if (mReactorIndex >= mReactorTypes.Count)
        {
            return;
        }

        ReactorAction lItem = Activator.CreateInstance(mReactorTypes[mReactorIndex]) as ReactorAction;

        lItem.Owner = mTarget.gameObject;

        mTarget._Reactors.Add(lItem);
        mTarget._ReactorDefinitions.Add(lItem.Serialize());

        mReactorList.index = mTarget._Reactors.Count - 1;
        OnReactorListItemSelect(rList);

        mIsDirty = true;
    }
Пример #14
0
        // CDL 08/13/2018 - added this method to streamline the process of setting up reactors via script
        /// <summary>
        /// Gets a reactor with a name and type that match and creates a new reactor if no
        /// match is found
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="rName"></param>
        /// <returns></returns>
        public virtual T GetOrAddReactor <T>(string rName = null) where T : ReactorAction
        {
            ReactorAction lReactor = GetReactor <T>(rName);

            if (lReactor == null)
            {
                lReactor = Activator.CreateInstance(typeof(T)) as ReactorAction;
                if (lReactor != null)
                {
                    if (!string.IsNullOrEmpty(rName))
                    {
                        lReactor.Name = rName;
                    }
                    AddReactor(lReactor);
                }
            }

            return((T)lReactor);
        }
Пример #15
0
        /// <summary>
        /// Allows us to choose the attack style we'll attack with
        /// </summary>
        /// <param name="rAction"></param>
        public void OnPreAttack(ReactorAction rAction)
        {
            mActorCore.SetStateValue("State", ATTACKING);

            if (rAction == null || rAction.Message == null)
            {
                return;
            }

#if USE_SWORD_SHIELD_MP || OOTII_SSMP
            // Choose the attack style
            CombatMessage lCombatMessage = rAction.Message as CombatMessage;
            if (lCombatMessage == null)
            {
                return;
            }

            if (lCombatMessage.CombatMotion is BasicMeleeAttack)
            {
                //lCombatMessage.StyleIndex = 2;
            }
#endif
        }
Пример #16
0
 public ReactorCallback(SelectReactor reactor, ReactorAction callback, double waketime)
 {
     this.reactor  = reactor;
     this.timer    = reactor.register_timer(this.invoke, waketime);
     this.callback = callback;
 }
Пример #17
0
 public ReactorTimer(ReactorAction callback, double waketime)
 {
     this.callback = callback;
     this.waketime = waketime;
 }
Пример #18
0
        /// <summary>
        /// Processes the reactor definitions and update the reactors to match the definitions.
        /// </summary>
        public void InstantiateReactors()
        {
            int lDefCount = _ReactorDefinitions.Count;

            // First, remove any extra items that may exist
            for (int i = _Reactors.Count - 1; i >= lDefCount; i--)
            {
                _Reactors.RemoveAt(i);
            }

            // CDL 07/27/2018 - keep track of any invalid reactor definitions
            List <int> lInvalidDefinitions = new List <int>();

            // We need to match the definitions to the item
            for (int i = 0; i < lDefCount; i++)
            {
                string   lDefinition     = _ReactorDefinitions[i];
                JSONNode lDefinitionNode = JSONNode.Parse(lDefinition);
                if (lDefinitionNode == null)
                {
                    continue;
                }

                string lTypeString = lDefinitionNode["__Type"].Value;

                // CDL 07/27/2018 - Use AssemblyHelper.ResolveType() intead so that the Type can still
                // be obtained if the reactor was serialized as belonging to a different assembly
                bool lUpdateType;
                Type lType = AssemblyHelper.ResolveType(lTypeString, out lUpdateType);
                if (lType == null)
                {
                    // CDL 07/27/2018 - save this definition for removal afterwards, as we can't resolve the Type from any assembly.
                    lInvalidDefinitions.Add(i);
                    continue;
                }

                ReactorAction lReactor = null;

                // If we don't have an item matching the type, we need to create one
                if (_Reactors.Count <= i || !lType.Equals(_Reactors[i].GetType()))
                {
                    lReactor       = Activator.CreateInstance(lType) as ReactorAction;
                    lReactor.Owner = this.gameObject;

                    if (_Reactors.Count <= i)
                    {
                        _Reactors.Add(lReactor);
                    }
                    else
                    {
                        _Reactors[i] = lReactor;
                    }
                }
                // Grab the matching item
                else
                {
                    lReactor = _Reactors[i];
                }

                // Fill the item with data from the definition
                if (lReactor != null)
                {
                    lReactor.Deserialize(lDefinition);

                    // CDL 07/27/2018 - update the serialized Type if necessary
                    if (lUpdateType)
                    {
                        _ReactorDefinitions[i] = lReactor.Serialize();
                    }
                }
            }

            // CDL 07/27.2018 - Clean up any invalid Motion Definitions
            // this is causing an error, but maybe not needed, as I don't think there are
            // many people who have been using custom reactors
            //if (lInvalidDefinitions.Count > 0)
            //{
            //    for (int i = 0; i < lInvalidDefinitions.Count; i++)
            //    {
            //        int lIndex = lInvalidDefinitions[i];
            //        _ReactorDefinitions.RemoveAt(lIndex);
            //    }
            //}

            // Allow each item to initialize now that it has been deserialized
            for (int i = 0; i < _Reactors.Count; i++)
            {
                _Reactors[i].Owner = this.gameObject;
                _Reactors[i].Awake();
            }
        }
Пример #19
0
 /// <summary>
 /// Occurs after the character has been damaged
 /// </summary>
 /// <param name="rAction"></param>
 public void OnDamaged(ReactorAction rAction)
 {
     // This is primarily done to clear any block that is up
     mActorCore.SetStateValue("State", IDLE);
 }
Пример #20
0
 /// <summary>
 /// Reports when the weapon style is equipped
 /// </summary>
 /// <param name="rAction"></param>
 public void OnWeaponSetEquipped(ReactorAction rAction)
 {
     mActorCore.SetStateValue("State", IDLE);
 }