is that a to large Packet ?

01/25/2011 21:02 { Angelius }#1
so i though about adding some cases to this packet an im not sure how bad it is or the The consequences of what i have added to the packet and i though that it might be to large to be sent everytime the player use the skill but im not sure so i need some advice .

this is how the packet looks like and what i have added is to fix the archerban/PoisonStar

PHP Code:
public static byte[] Action(uint EntityIDDictionary<uintintTargetsushort SkillIdbyte SkillLvlushort Xushort Y)
        {
            
byte[] Packet;
            
Packet = new byte[32 + (Targets.Count) * 12];
            
COPacket P = new COPacket(Packet);
            
P.WriteUshortAddPos2((ushort)(Packet.Length 8));
            
P.WriteUshortAddPos2((ushort)0x451);
            
P.WriteUintAddPos4(EntityID);
            
P.WriteUshortAddPos2(X);
            
P.WriteUshortAddPos2(Y);
            
P.WriteUshortAddPos2(SkillId);
            
P.WriteUshortAddPos2(SkillLvl);
            if (
Targets == null)
            {
                
P.WriteUintAddPos4(0);
            }
            else
                
P.WriteUintAddPos4((uint)(Targets.Count));
            if (
Targets != null)
                if (
SkillId != 6002 && SkillId != 6004)
                {
                   foreach (
KeyValuePair<uintintDE in Targets)
                    {
                        
P.WriteUintAddPos4(((uint)DE.Key));
                        
P.WriteUintAddPos4((uint)DE.Value);
                        
P.WriteUintAddPos4(0);
                    }
                }
                else
                {
                    foreach (
KeyValuePair<uintintDE in Targets)
                    {
                        
NPC N = (NPC)WorldTables.H_NPCs[DE.Key];
                        
Character Attacker = (Character)WorldTables.H_Chars[EntityID];
                        
Character Target = (Character)WorldTables.H_Chars[DE.Key];
                        if (
== null)
                        {
                            if (
SkillId == 6002)
                            {
                                
P.WriteUintAddPos4(((uint)DE.Key));
                                
P.WriteUintAddPos4((uint)DE.Value);
                                if ((
Target.Potency) > (Attacker.Potency))
                                {
                                    switch (
SkillLvl)
                                    {
                                        case 
0:
                                            {
                                                if (
MyMath.ChanceSuccess(10))
                                                {
                                                    
P.WriteUintAddPos4(1);
                                                    
Target.AintUseDrugs SkillId;
                                                    
Target.UseDrugs DateTime.Now;
                                                }
                                                break;
                                            }
                                        case 
1:
                                            {
                                                if (
MyMath.ChanceSuccess(13))
                                                {
                                                    
P.WriteUintAddPos4(1);
                                                    
Target.AintUseDrugs SkillId;
                                                    
Target.UseDrugs DateTime.Now;
                                                }
                                                break;
                                            }
                                        case 
2:
                                            {
                                                if (
MyMath.ChanceSuccess(16))
                                                {
                                                    
P.WriteUintAddPos4(1);
                                                    
Target.AintUseDrugs SkillId;
                                                    
Target.UseDrugs DateTime.Now;
                                                }
                                                break;
                                            }
                                        case 
3:
                                            {
                                                if (
MyMath.ChanceSuccess(19))
                                                {
                                                    
P.WriteUintAddPos4(1);
                                                    
Target.AintUseDrugs SkillId;
                                                    
Target.UseDrugs DateTime.Now;
                                                }
                                                break;
                                            }
                                        case 
4:
                                            {
                                                if (
MyMath.ChanceSuccess(23))
                                                {
                                                    
P.WriteUintAddPos4(1);
                                                    
Target.AintUseDrugs SkillId;
                                                    
Target.UseDrugs DateTime.Now;
                                                }
                                                break;
                                            }
                                    }
                                    
                                }
                                else
                                {
                                    switch (
SkillLvl)
                                    {
                                        case 
0:
                                            {
                                                if (
MyMath.ChanceSuccess(15))
                                                {
                                                    
P.WriteUintAddPos4(1);
                                                    
Target.AintUseDrugs SkillId;
                                                    
Target.UseDrugs DateTime.Now;
                                                }
                                                break;
                                            }
                                        case 
1:
                                            {
                                                if (
MyMath.ChanceSuccess(20))
                                                {
                                                    
P.WriteUintAddPos4(1);
                                                    
Target.AintUseDrugs SkillId;
                                                    
Target.UseDrugs DateTime.Now;
                                                }
                                                break;
                                            }
                                        case 
2:
                                            {
                                                if (
MyMath.ChanceSuccess(25))
                                                {
                                                    
P.WriteUintAddPos4(1);
                                                    
Target.AintUseDrugs SkillId;
                                                    
Target.UseDrugs DateTime.Now;
                                                }
                                                break;
                                            }
                                        case 
3:
                                            {
                                                if (
MyMath.ChanceSuccess(30))
                                                {
                                                    
P.WriteUintAddPos4(1);
                                                    
Target.AintUseDrugs SkillId;
                                                    
Target.UseDrugs DateTime.Now;
                                                }
                                                break;
                                            }
                                        case 
4:
                                            {
                                                if (
MyMath.ChanceSuccess(35))
                                                {
                                                    
P.WriteUintAddPos4(1);
                                                    
Target.AintUseDrugs SkillId;
                                                    
Target.UseDrugs DateTime.Now;
                                                }
                                                break;
                                            }
                                    }
                                }
                            }
                            else
                            {
                                if ((
Target.Potency) > (Attacker.Potency))
                                {
                                    switch (
SkillLvl)
                                    {
                                        case 
0:
                                            {
                                                if (
MyMath.ChanceSuccess(10))
                                                {
                                                    
P.WriteUintAddPos4(1);
                                                    
Target.Flying false;
                                                }
                                                break;
                                            }
                                        case 
1:
                                            {
                                                if (
MyMath.ChanceSuccess(13))
                                                {
                                                    
P.WriteUintAddPos4(1);
                                                    
Target.Flying false;
                                                }
                                                break;
                                            }
                                        case 
2:
                                            {
                                                if (
MyMath.ChanceSuccess(16))
                                                {
                                                    
P.WriteUintAddPos4(1);
                                                    
Target.Flying false;
                                                }
                                                break;
                                            }
                                        case 
3:
                                            {
                                                if (
MyMath.ChanceSuccess(19))
                                                {
                                                    
P.WriteUintAddPos4(1);
                                                    
Target.Flying false;
                                                }
                                                break;
                                            }
                                        case 
4:
                                            {
                                                if (
MyMath.ChanceSuccess(23))
                                                {
                                                    
P.WriteUintAddPos4(1);
                                                    
Target.Flying false;
                                                }
                                                break;
                                            }
                                    }
                                }
                                else
                                {
                                    switch (
SkillLvl)
                                    {
                                        case 
0:
                                            {
                                                if (
MyMath.ChanceSuccess(15))
                                                {
                                                    
P.WriteUintAddPos4(1);
                                                    
Target.Flying false;
                                                }
                                                break;
                                            }
                                        case 
1:
                                            {
                                                if (
MyMath.ChanceSuccess(20))
                                                {
                                                    
P.WriteUintAddPos4(1);
                                                    
Target.Flying false;
                                                }
                                                break;
                                            }
                                        case 
2:
                                            {
                                                if (
MyMath.ChanceSuccess(25))
                                                {
                                                    
P.WriteUintAddPos4(1);
                                                    
Target.Flying false;
                                                }
                                                break;
                                            }
                                        case 
3:
                                            {
                                                if (
MyMath.ChanceSuccess(30))
                                                {
                                                    
P.WriteUintAddPos4(1);
                                                    
Target.Flying false;
                                                }
                                                break;
                                            }
                                        case 
4:
                                            {
                                                if (
MyMath.ChanceSuccess(35))
                                                {
                                                    
P.WriteUintAddPos4(1);
                                                    
Target.Flying false;
                                                }
                                                break;
                                            }
                                    }
                                }
                            }
                        }
                        else
                        {
                            
uint Chance 0;
                            switch(
SkillLvl)
                            {
                                case 
0:
                                    {
                                        
Chance 20;
                                        break;
                                    }
                                case 
2:
                                    {
                                        
Chance 30;
                                        break;
                                    }
                                case 
3:
                                    {
                                        
Chance 50;
                                        break;
                                    }
                                case 
4:
                                    {
                                        
Chance 70;
                                        break;
                                    }
                            }
                            if (
MyMath.ChanceSuccess(Chance))
                            {
                                
P.WriteUintAddPos4(((uint)DE.Key));
                                
P.WriteUintAddPos4((uint)DE.Value);
                                
P.WriteUintAddPos4(1);
                            }
                            else
                            {
                                
P.WriteUintAddPos4(((uint)DE.Key));
                                
P.WriteUintAddPos4((uint)DE.Value);
                                
P.WriteUintAddPos4(0);
                            }
                        }
                    }
                }
            return 
P.AddTQServer8Byte();
        } 
also i wold like to ask,
Should i keep the cases/if statements in a sided void or its fine to have it like what it is

SORRY ITS TO DAMN LONG .
01/25/2011 22:28 taylor2846#2
what source are you using.
01/25/2011 22:29 7upguy123#3
please cud sum 1 help me set up a mir server :)?
01/25/2011 22:30 Basser#4
Why did you name those methods like that? Instead you could have used an extra parameter for 'how much to add to the position' LOL.
01/25/2011 22:37 Korvacs#5
I seriously would take out all of that processing and do it somewhere else, the packet is meant to be a template, you drop data in and send it, thats as far as it goes really.
01/25/2011 23:06 { Angelius }#6
@ taylor2846

Creating My own source :xD

@Basser

That packet is the Result of a quick packet testing it's meant to fix the poisonstar/archerban with out using any other resources (THE PACKET IS THE SKILL)
so far....
i do care about yeah its working but also paying attention the packet size and other stuff .
the less = more Theory and than i can clean/sort shit out

@Korvacs

Thank you :)
01/26/2011 02:58 pro4never#7
Completely agree with korv. There is WAY too much coded into that packet.


Packets should be used for ONE thing in my mind... sending the damn effect. Any other server side stuff should be done in your spell handler which calls the packet.


Personally I use a sendspell class and a Target class (which controls the target uid, dmg and the hit bool)


Example usage..

SendSpell S = new SendSpell(Attacker, X, Y, Skill)
S.Targets.Add(new Target(TargetUID, Dmg, Hit));

Then when ready just do

S.Send();

Simplifies my multi target spells significantly. The class itself is also quite simple just allowing for a list of targets and then construct the packet (size and all) when I run the Send method. Send also does the actual sending of the packet (so it's a void, not a byte[] return type) which further simplifies things. If you think about it though I already have the targets and attacker information so it's easy to determine who all needs to receive the packet. Just ToScreen(Packet, Attacker);