[Release] Character Events System (Any version)

04/19/2011 16:33 12tails#1
Yo guys!

I called it events cuz i mean things like Blessing, OfflineTG, Expball, Dayly Quests and many others....

well it's very simple and easy to understand. First create this class at any place of the current source you're using (i'm using a custom one self maked so i can`t give any example... sorry)

Code:
    public class Event_State
    {
        public string Event_Name;
        public uint Event_Count;
        public Event_Type Type;
        public DateTime End;
    }
and put this enum at same file or at an Enum class (like the one used for impulse)

Code:
    public enum Event_Type : byte
    {
        ExpBall = 1,
        PowerExpBall = 2,
        Exterminator = 3,
        Blessing = 4,
        UnknownMan = 5,
        OfflineTG = 6,
        Enlight = 7,
        Enlight_Points = 8,
    }
and finally ... here is the whole class :

Code:
    public class Events
    {
        uint __Owner = 0;
        Character Owner { get { return Server.Pool[__Owner]; } }
        public Dictionary<string, Event_State> Values;
        public Dictionary<string, Event_State> LoadValues;

        public Events(uint _Owner)
        {
            Values = new Dictionary<string, Event_State>();
            LoadValues = new Dictionary<string, Event_State>();
            __Owner = _Owner;
        }

        public void AppendEvent(Event_State Event)
        {
            if (!Values.ContainsKey(Event.Event_Name))
                Values.Add(Event.Event_Name, Event);
            else
            {
                Values[Event.Event_Name] = Event;
                Database.DeleteEvent(__Owner, Event.Event_Name);
            }

            switch (Event.Type)
            {
                case Event_Type.Blessing:
                    Owner.AddFlag(Struct.StatusEffect.Blessed);
                    Owner.Update_Type2(Struct.StatusTypes.BlessTimer, (uint)(Event.End - DateTime.Now).TotalSeconds);
                    Owner.Update_Type2(Struct.StatusTypes.OnlineTraining, 0);
                    Database.CreateEvent(Event, __Owner);
                    break;
                case Event_Type.ExpBall:
                case Event_Type.Enlight:
                case Event_Type.OfflineTG:
                case Event_Type.UnknownMan:
                    Database.CreateEvent(Event, __Owner);
                    break;
            }
        }

        public void AppendRemoveEvent(Event_State Event)
        {
            if (Values.ContainsKey(Event.Event_Name))
                Values.Remove(Event.Event_Name);

            switch (Event.Type)
            {
                case Event_Type.Blessing:
                    Owner.RemoveFlag(Struct.StatusEffect.Blessed);
                    Owner.Update_Type2(Struct.StatusTypes.BlessTimer, (uint)(Event.End - DateTime.Now).TotalSeconds);
                    Owner.Update_Type2(Struct.StatusTypes.OnlineTraining, 0);
                    Database.DeleteEvent(__Owner, Event.Event_Name);
                    break;
                case Event_Type.Enlight:
                case Event_Type.OfflineTG:
                case Event_Type.ExpBall:
                case Event_Type.UnknownMan:
                    Database.DeleteEvent(__Owner, Event.Event_Name);
                    break;
            }
        }

        public void AppendLoad()
        {
            foreach (Event_State Event in LoadValues.Values)
            {
                if (!Values.ContainsKey(Event.Event_Name))
                    Values.Add(Event.Event_Name, Event);

                switch (Event.Type)
                {
                    case Event_Type.Blessing:
                        Owner.Update_Type2(Struct.StatusTypes.BlessTimer, (uint)(Event.End - DateTime.Now).TotalSeconds);
                    Owner.Update_Type2(Struct.StatusTypes.OnlineTraining, 0);
                        break;
                    case Event_Type.Enlight:
                    case Event_Type.ExpBall:
                    case Event_Type.UnknownMan:
                        if (DateTime.Now.Ticks > Event.End.Ticks)
                            AppendRemoveEvent(Event);
                        break;
                    case Event_Type.OfflineTG://do nothing
                        break;
                }
            }

            LoadValues.Clear();
            LoadValues = null;
        }
    }
//Edit:
I let some of the codes used by me inside... so you could use as an example...

let me explain a simple way to use it. first you name the event like do you want... Blessing, Expball or whatever....
then use a type for something you want (i'm not using it yet so far... but it is there for future uses)
the eventcount is for example, the expballs use today, for blessing the event duration in seconds or minutes (i'm using in seconds this case)...
The Event End you can use or for mark when the event begin or when you want it to end...
for expballs i use this way:
End = DateTime.Now.AddHours(24 - DateTime.Now.Hour);// that way you can use it at the next day right before 1 AM...

well... its not a big release but should help some ppl >D

Cya... any question just post here :P

Obs.: For who think its unusefull... rembember when u create for blessing, luckytime and others a field at db and a variable? that way you can use a class and just add new events :D

Sorry for the english... and good luck!
04/19/2011 21:22 koko20#2
thank you very good can you upload impulse source monster ? or fix nobility ? this all people need it and thank you
04/20/2011 06:59 thesamuraivega#3
i have problems in
Character Owner { get { return Server.Pool[__Owner]; } }

Database.DeleteEvent(__Owner, Event.Event_Name);
i used hellmouthco source
why?
04/20/2011 10:53 _DreadNought_#4
I just lol'd.
04/20/2011 11:38 12tails#5
Quote:
Originally Posted by _DreadNought_ View Post
I just lol'd.
Yeah... me too...

FOR GOD SAKE thats not for hellmounth source!

you have to edit somethings and create the database voids.... i released just the class... should be a great start.... -.-''

Quote:
"(i'm using a custom one self maked so i can`t give any example... sorry)"
04/21/2011 23:45 Secrets-man#6
Nice job :P
05/20/2011 06:34 eleven#7
@thesamuraivega
Quote:
i have problems in
Character Owner { get { return Server.Pool[__Owner]; } }

Database.DeleteEvent(__Owner, Event.Event_Name);
i used hellmouthco source
why?
not for hellmouth this is leo not chris lol noob
05/20/2011 06:37 Spirited42#8
Quote:
Originally Posted by _DreadNought_ View Post
I just lol'd.
I lol'd because your post has more "thanks" than the op's.