Register for your free account! | Forgot your password?

Go Back   elitepvpers > MMORPGs > Conquer Online 2 > CO2 Private Server
You last visited: Today at 03:14

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



Is that a good screen class?

Discussion on Is that a good screen class? within the CO2 Private Server forum part of the Conquer Online 2 category.

Reply
 
Old   #1
 
12tails's Avatar
 
elite*gold: 0
Join Date: Apr 2009
Posts: 773
Received Thanks: 441
Is that a good screen class?

yo...
i had worked into this screen class...
maybe it's not the best one, but i wan't to get some opinions about how to do it better...

NOTE: ANY STUPID POST WILL BE REPORTED -.-''

Code:
    public class Screen
    {
        uint Uid;
        Character mOwner { get { return Server.Pool[Uid]; } }
        Dictionary<uint, object> List = null;
        public Screen(uint _uid)
        {
            List = new Dictionary<uint, object>();
            Uid = _uid;
        }

        public void Send(byte[] Data, bool m_nTo)
        {
            if (m_nTo) mOwner.Owner.Send(Data);
            object[] Objs = null;
        again:
            try
            {
                Objs = new object[List.Count];
                List.Values.CopyTo(Objs, 0);
            }
            catch { goto again; }

            foreach (object Obj in Objs)
                if (Obj is Character)
                    (Obj as Character).Owner.Send(Data);
        }

        public void Add(uint UID, object Obj)
        {
            if (!List.ContainsKey(UID) && UID != Uid)
            {
                lock (List)
                    List.Add(UID, Obj);

                #region [Client]
                if (Obj is Character)
                {
                    Character Client = (Obj as Character);
                    mOwner.Owner.Send(Client.Spawn);
                }
                #endregion
                #region [Monster]
                if (Obj is Monster)
                {
                    Monster Mob = (Obj as Monster);
                    mOwner.Owner.Send(Packets.ConquerPacket.SpawnMonster(Mob));
                }
                #endregion
                #region [Npc]
                if (Obj is Struct.NPC)
                {
                    Struct.NPC Npc = (Obj as Struct.NPC);
                    mOwner.Owner.Send(Packets.ConquerPacket.SpawnNPC(Npc));
                }
                #endregion
                #region [Terrain]
                if (Obj is Struct.Terrain)
                {
                    Struct.Terrain Terrain = (Obj as Struct.Terrain);
                    mOwner.Owner.Send(Packets.ConquerPacket.TerrainNPC(Terrain));
                }
                #endregion
            }
        }

        public void Remove(uint UID)
        {
            if (Uid != UID && List.ContainsKey(UID)) List.Remove(UID);
            mOwner.Owner.Send(Packets.ConquerPacket.General(UID, 0, 0, 0, 0, 0, Struct.DataType.EntityRemove));
        }

        public object Get(uint UID)
        {
            object Return = null;
            if (List.ContainsKey(UID))
                lock (List)
                    Return = List[UID];

            return Return;
        }

        public bool TryGetValue(uint key, out object value)
        {
            value = null;
            try
            {
                object ob = null;
                if (List.ContainsKey(key))
                {
                    ob = List[key];
                    #region [Client]
                    if (ob is Character)
                    {
                        value = ob as Character;
                        return true;
                    }
                    #endregion
                    #region [Monster]
                    if (ob is Monster)
                    {
                        value = ob as Monster;
                        return true;
                    }
                    #endregion
                    #region [Npc]
                    if (ob is Struct.NPC)
                    {
                        value = ob as Struct.NPC;
                        return true;
                    }
                    #endregion
                    #region [Terrain]
                    if (ob is Struct.Terrain)
                    {
                        value = ob as Struct.Terrain;
                        return true;
                    }
                    #endregion
                }
            }
            catch { return false; }
            return false;
        }

        public void CheckUp()
        {
            object[] Objs = null;
        again:
            try
            {
                Objs = new object[List.Count];
                List.Values.CopyTo(Objs, 0);
            }
            catch { goto again; }

            foreach (object Obj in Objs)
            {
                #region [Client]
                if (Obj is Character)
                {
                    Character Client = (Obj as Character);
                    if (!Calculation.CanSee(Client.X, Client.Y, mOwner.X, mOwner.Y))
                        Remove(Client.UID);
                }
                #endregion
                #region [Monster]
                if (Obj is Monster)
                {
                    Monster Mob = (Obj as Monster);
                    if (!Calculation.CanSee(Mob.X, Mob.Y, mOwner.X, mOwner.Y))
                        Remove(Mob.UID);
                }
                #endregion
                #region [Npc]
                if (Obj is Struct.NPC)
                {
                    Struct.NPC Npc = (Obj as Struct.NPC);
                    if (!Calculation.CanSee(Npc.X, Npc.Y, mOwner.X, mOwner.Y))
                        Remove(Npc.Type);
                }
                #endregion
                #region [Terrain]
                if (Obj is Struct.Terrain)
                {
                    Struct.Terrain Terrain = (Obj as Struct.Terrain);
                    if (!Calculation.CanSee(Terrain.X, Terrain.Y, mOwner.X, mOwner.Y))
                        Remove(Terrain.UID);
                }
                #endregion
            }
        }
    }
thanks in advance.
12tails is offline  
Old 05/09/2011, 22:52   #2
 
nTL3fTy's Avatar
 
elite*gold: 0
Join Date: Jun 2005
Posts: 692
Received Thanks: 353
C# naming conventions prefix interfaces with an uppercase I, not classes: ,

nTL3fTy is offline  
Old 05/09/2011, 22:54   #3
 
12tails's Avatar
 
elite*gold: 0
Join Date: Apr 2009
Posts: 773
Received Thanks: 441
oh.. yeah that was just a wrong typo haha
changed already :P
12tails is offline  
Old 05/09/2011, 23:18   #4
 
elite*gold: 0
Join Date: Jun 2009
Posts: 787
Received Thanks: 314
Class portrays a poor understanding of OOP.

Not much else to say
_tao4229_ is offline  
Old 05/10/2011, 06:44   #5
 
InfamousNoone's Avatar
 
elite*gold: 20
Join Date: Jan 2008
Posts: 2,012
Received Thanks: 2,882
I agree with what tao side. Major things I'd point out:

- mOwner property accesses what seems to be a dictionary each time it's invoked (this is CPU heavy where you could simply retrieve the value once, and store it).
- Instead Dictionary<uint, object> look into interfaces and what they're used for.
InfamousNoone is offline  
Thanks
1 User
Old 05/10/2011, 11:17   #6
 
12tails's Avatar
 
elite*gold: 0
Join Date: Apr 2009
Posts: 773
Received Thanks: 441
okay tkx
12tails is offline  
Reply


Similar Threads Similar Threads
WTT/WTS GOOD ITEMS (ALL CLASS) [SIZ]
12/23/2010 - Dekaron Trading - 4 Replies
HEY I HAVE A LOT OF ITEMS TO SELL! ALL ARE ON SIZ! JUST OFFER WHAT YOU GOT! in pm or here i'll take -dils on siz or hellion (preferably hellion) -items on hellion Accesoirs/upgrade stuff/gems
[wtb]any class 138+ good acc +7...pay whit PSC!!!!!!!!!!!!!!!!
04/16/2010 - Dekaron Trading - 0 Replies
add me: [email protected] * if u sell poste ur character whit,lvl, haw much €, items,server tnx.
Warrior/walrock is a good class? for pvps and pves.
02/05/2010 - Silkroad Online - 4 Replies
some body can tell if warrior walrock is a good class for pvps. and all becasue i can make it Warrior/cleric but i need to know.
whats a good pvp class?
04/06/2009 - Conquer Online 2 - 5 Replies
hi there. i've played this game a long while ago and thought i might give it a try once more. since i don't know what's going on atm, i'd like to know what's a good pvp class, also considering reborn combinations. when i played last time, i was a fire tao, made an autoaim bot casting fire meteor or whatever that name was. actually, most people couldn't even hit me since i was jumping all the time and letting my bot autoaim. are there any new skills for non mages that make it easier to...
Im trading Good accounts for good but other class
04/14/2006 - Conquer Online 2 - 7 Replies
Hi, Im looking to buy a high level account , any lvl i dont care what class it is. I dont know if this is all worth it but i tell you offer Level 81 archer Lvl 40+archer Lvl 40+ fire tao Lvl 40+Tro got lvl 58 black name in jail also (no info for it) I have elites, +1's Gems



All times are GMT +2. The time now is 03:14.


Powered by vBulletin®
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2024 elitepvpers All Rights Reserved.