What's new
  • Visit Rebornbuddy
  • Visit Panda Profiles
  • Visit LLamamMagic
  • Visit Resources
  • Visit Downloads
  • Visit Portal
RebornBuddy Forums

Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

GameEventManager

Maniacuz

Member
Joined
Mar 17, 2015
Messages
118
Can anybody advise how can i deal with replacing
private void GameEventManagerOnAreaChanged(object sender, AreaChangedEventArgs areaChangedEventArgs)

for new system without GameEventManager at all? CommonEvents as far as i saw. Just im bad with codes, trying to do something anyway :(.
 
You can catch the "core_area_changed_event" in Logic. Or simply emulate the old AreaChanged event.

Code:
    public class YOUR_PLUGIN_NAME : IPlugin
    {
        private static readonly ILog Log = Logger.GetLoggerInstanceForType();

        public static event EventHandler<AreaChangedArgs> AreaChanged;

        public async Task<bool> Logic(string type, params dynamic[] param)
        {
            if (type == "core_area_changed_event")
            {
                uint oldSeed = (uint) param[0];
                uint newSeed = (uint) param[1];
                DatWorldAreaWrapper oldArea = (DatWorldAreaWrapper) param[2];
                DatWorldAreaWrapper newArea = (DatWorldAreaWrapper) param[3];
                string oldAreaName = oldArea == null ? "null" : oldArea.Name;
                string newAreaName = newArea == null ? "null" : newArea.Name;

                Log.DebugFormat("[YOUR_PLUGIN_NAME] Rising AreaChangedEvent. Old seed: {0}, New seed: {1}, Old area: \"{2}\", New area: \"{3}\".",
                    oldSeed, newSeed, oldAreaName, newAreaName);

                OnAreaChanged(new AreaChangedArgs(oldSeed, newSeed, oldAreaName, newAreaName));
            }
            return false;
        }

        private static void OnAreaChanged(AreaChangedArgs e)
        {
            var handler = AreaChanged;
            if (handler != null) handler(null, e);
        }

        public class AreaChangedArgs : EventArgs
        {
            public uint OldSeed { get; private set; }
            public uint NewSeed { get; private set; }
            public string OldAreaName { get; private set; }
            public string NewAreaName { get; private set; }

            public AreaChangedArgs(uint oldSeed, uint newSeed, string oldAreaName, string newAreaName)
            {
                OldSeed = oldSeed;
                NewSeed = newSeed;
                OldAreaName = oldAreaName;
                NewAreaName = newAreaName;
            }
        }

... rest of IPlugin stuff
 
You can catch the "core_area_changed_event" in Logic. Or simply emulate the old AreaChanged event.

Code:
    public class YOUR_PLUGIN_NAME : IPlugin
    {
        private static readonly ILog Log = Logger.GetLoggerInstanceForType();

        public static event EventHandler<AreaChangedArgs> AreaChanged;

        public async Task<bool> Logic(string type, params dynamic[] param)
        {
            if (type == "core_area_changed_event")
            {
                uint oldSeed = (uint) param[0];
                uint newSeed = (uint) param[1];
                DatWorldAreaWrapper oldArea = (DatWorldAreaWrapper) param[2];
                DatWorldAreaWrapper newArea = (DatWorldAreaWrapper) param[3];
                string oldAreaName = oldArea == null ? "null" : oldArea.Name;
                string newAreaName = newArea == null ? "null" : newArea.Name;

                Log.DebugFormat("[YOUR_PLUGIN_NAME] Rising AreaChangedEvent. Old seed: {0}, New seed: {1}, Old area: \"{2}\", New area: \"{3}\".",
                    oldSeed, newSeed, oldAreaName, newAreaName);

                OnAreaChanged(new AreaChangedArgs(oldSeed, newSeed, oldAreaName, newAreaName));
            }
            return false;
        }

        private static void OnAreaChanged(AreaChangedArgs e)
        {
            var handler = AreaChanged;
            if (handler != null) handler(null, e);
        }

        public class AreaChangedArgs : EventArgs
        {
            public uint OldSeed { get; private set; }
            public uint NewSeed { get; private set; }
            public string OldAreaName { get; private set; }
            public string NewAreaName { get; private set; }

            public AreaChangedArgs(uint oldSeed, uint newSeed, string oldAreaName, string newAreaName)
            {
                OldSeed = oldSeed;
                NewSeed = newSeed;
                OldAreaName = oldAreaName;
                NewAreaName = newAreaName;
            }
        }

... rest of IPlugin stuff

TLDR;

Code:
if (type == "core_area_changed_event")
{
    // Do Your shit
    return true;
}
 
TLDR;

Code:
if (type == "core_area_changed_event")
{
    // Do Your shit
    return true;
}
That way you are limited to IPlugin class. With public event you can subscribe from any class within your project.
 
That way you are limited to IPlugin class. With public event you can subscribe from any class within your project.
Yup, but I really only see the need for it to be in a plugin class, unless there was other usages of it outside a plugin class. Anyhow, code to add to the library.
 
Both methods are great. :)

See the source for the CommonEvents plugin as well to know how you can make your own for other people to use!
 
Back
Top