Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as C# by strix ( 15 years ago )
// Special version showing a bug in ActionLog

using System.Drawing;

using Styx;
using Styx.Combat.CombatRoutine;
using Styx.Helpers;
using Styx.WoWInternals.WoWObjects;

using TreeSharp;
using Action = TreeSharp.Action;

namespace ActionLogBug
{
    public partial class ActionLogBugRoutine : CombatRoutine
    {
        public override sealed string Name { get { return "ActionLogBug for Apoc"; } }
        public override WoWClass Class { get { return StyxWoW.Me.Class; } }

        public static WoWItem SomeWoWItem { get { return null; } }

        private Composite CreateRestBehavior()
        {
            return new Decorator(
                ret => false,
                // Should not even reach this, but if you use ActionLog it will produce error
                // if you use Action and Logging.Write it works as intended,

                //new Action(ret => Logging.Write("Applied " + SomeWoWItem.Name + " to main hand."))
                new ActionLog("Applied " + SomeWoWItem.Name + " to main hand.")
            );
        }

        private Composite _restBehavior;

        public override Composite RestBehavior
        {
            get { return _restBehavior ?? (_restBehavior = CreateRestBehavior()); }
        }
    }

    public class ActionLog : Action
    {
        public delegate string GetLogMessage(object ctx);
        private readonly bool _debug;

        private readonly string _message;

        private GetLogMessage _getMessage;
        public ActionLog(GetLogMessage getMessage)
        {
            _getMessage = getMessage;
        }

        public ActionLog(string message)
        {
            _message = message;
        }

        public ActionLog(string message, bool debug)
            : this(message)
        {
            _debug = debug;
        }

        protected override RunStatus Run(object context)
        {
            string msg = null;
            if (_getMessage != null)
                msg = _getMessage(context);
            else
                msg = _message;

            if (_debug)
            {
                Logging.WriteDebug(msg);
            }
            else
            {
                Logging.Write(Color.Orange, msg);
            }

            // Selectors continue when the node fails. So we want to let it continue.););
            if (Parent is Selector)
            {
                return RunStatus.Failure;
            }

            // Everything else only continues if we succeed. So do that.
            return RunStatus.Success;
        }
    }
}

 

Revise this Paste

Your Name: Code Language: