Register for your free account! | Forgot your password?

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

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

Advertisement



Alternate Equipment (Packet 1009: 45)

Discussion on Alternate Equipment (Packet 1009: 45) within the CO2 Private Server forum part of the Conquer Online 2 category.

Reply
 
Old 01/23/2013, 13:49   #31
 
elite*gold: 21
Join Date: Jul 2005
Posts: 9,193
Received Thanks: 5,376
Let me try to explain one last time where I feel you're making a mistake (not a huge one, just something that can be easily corrected)


#1: there's no reason to loop through ALL slots. We only care what is in the alternate gear position. If something is equipped in alternate headgear, we want it to be swapped with the current headgear. Simple as that.

#2: Certain stats cannot be accurately calculated until all gear slots have been updated. As such it's not a good plan to calculate stats inside the gear swap. Yes, there are ways you can write this all properly and leave it inside the loop... but it's easier and good practice to write re-usable code. The way you're describing is not reusable and is poor practice.


So yes... Here's some sample code (excuse the albetros references. It was the source I had handy)


Code:
#region Alternate Gear
                                    case ItemAction.SwapAltGears:
                                    case ItemAction.SwapStandardGears:
                                        for (ItemLocation slot = ItemLocation.ALTHead; slot < ItemLocation.ALTSteed; slot++)
                                        {
                                            var altItm = user.Equipment.GetItemBySlot(slot);
                                            if (altItm != null)
                                            {
                                                //Move current item into alternate gear slot (we don't care if it's null)
                                                user.Equipment.ChangeItemSlot(user.Equipment.GetItemBySlot(slot - 20), slot);
                                                //Move alternate item into current gear slot
                                                user.Equipment.ChangeItemSlot(altItm, slot - 20);
                                            }
                                        }
                                        //Now that we know ALL the items and their location. We can recalculate. 
                                        user.Recalculate();
                                        //Update your equipment to local players. 
                                        user.SendToScreen(Packet.SpawnPlayerPacket.Create(user), false);
                                        break;
                                    #endregion
pro4never is offline  
Thanks
3 Users
Old 01/23/2013, 14:36   #32
 
elite*gold: 0
Join Date: Sep 2012
Posts: 775
Received Thanks: 327
Quote:
Originally Posted by pro4never View Post
Let me try to explain one last time where I feel you're making a mistake (not a huge one, just something that can be easily corrected)


#1: there's no reason to loop through ALL slots. We only care what is in the alternate gear position. If something is equipped in alternate headgear, we want it to be swapped with the current headgear. Simple as that.

#2: Certain stats cannot be accurately calculated until all gear slots have been updated. As such it's not a good plan to calculate stats inside the gear swap. Yes, there are ways you can write this all properly and leave it inside the loop... but it's easier and good practice to write re-usable code. The way you're describing is not reusable and is poor practice.


So yes... Here's some sample code (excuse the albetros references. It was the source I had handy)


Code:
#region Alternate Gear
                                    case ItemAction.SwapAltGears:
                                    case ItemAction.SwapStandardGears:
                                        for (ItemLocation slot = ItemLocation.ALTHead; slot < ItemLocation.ALTSteed; slot++)
                                        {
                                            var altItm = user.Equipment.GetItemBySlot(slot);
                                            if (altItm != null)
                                            {
                                                //Move current item into alternate gear slot (we don't care if it's null)
                                                user.Equipment.ChangeItemSlot(user.Equipment.GetItemBySlot(slot - 20), slot);
                                                //Move alternate item into current gear slot
                                                user.Equipment.ChangeItemSlot(altItm, slot - 20);
                                            }
                                        }
                                        //Now that we know ALL the items and their location. We can recalculate. 
                                        user.Recalculate();
                                        //Update your equipment to local players. 
                                        user.SendToScreen(Packet.SpawnPlayerPacket.Create(user), false);
                                        break;
                                    #endregion
and that's how alt. gears were released :P
go for it is offline  
Old 01/23/2013, 16:09   #33
 
{ Angelius }'s Avatar
 
elite*gold: 0
Join Date: Aug 2010
Posts: 991
Received Thanks: 1,107
Quote:
Originally Posted by pro4never View Post
Code:
#region Alternate Gear
                                    case ItemAction.SwapAltGears:
                                    case ItemAction.SwapStandardGears:
                                        for (ItemLocation slot = ItemLocation.ALTHead; slot < ItemLocation.ALTSteed; slot++)
                                        {
                                            var altItm = user.Equipment.GetItemBySlot(slot);
                                            [B]//this line alone loops through all gears to find an item with the slot X 
                                            //How many freaking cpu cycle does that waste lets say 9 alt slots 9*9 = [SIZE="4"]81[/SIZE] cycle? even worse when its standard slots[/B] 
                                            if (altItm != null)
                                            [B]//Why does it have to be null in the first place why wouldn't it just not be 
                                            //there at all i mean for real whats [B]efficient[/B] null stuff all over the server or keeping a 
                                            //sorteddictionary that contains only the items that are equipped and doesn't loop through null items for fun   [/B]
                                            {
                                                user.Equipment.ChangeItemSlot(user.Equipment.GetItemBySlot(slot - 20), slot);
                                                user.Equipment.ChangeItemSlot(altItm, slot - 20);
[B]                                                //Why wold you keep switching the items location instead of changing the item location on equip/un-equip and keeping 
                                                //them in a sorteddictionary with the location as a key like i did and 
                                                //how is it any better then a sorteddictionary [/B]
                                            }
[B]                                            [COLOR="Red"]//Every time the altItm = null its a wasted cpu cycle and we all know it
                                            //so if i am waring 1 single item which is the head gear your loop will test
                                            //every slot to find out that its = null except for the headgear
                                            //how is that [B]efficient[/B] and how does that help save cpu cycles? [/COLOR][/B]
                                        }
                                        user.Recalculate();
                                        user.SendToScreen(Packet.SpawnPlayerPacket.Create(user), false);
                                        break;
                                    #endregion
Quote:
Originally Posted by pro4never View Post
#1: there's no reason to loop through ALL slots. We only care what is in the alternate gear position. If something is equipped in alternate headgear, we want it to be swapped with the current headgear. Simple as that.
So you are saying its better to loop through all slots and waste precious cpu cycles that you are so concerned about the way you did it rather then having a dictionary that's always updated and contains no null items and keeps up with the number of items you are waring and doesn't waste cpu cycles when you loop through it?

Quote:
Originally Posted by pro4never View Post
#2: Certain stats cannot be accurately calculated until all gear slots have been updated. As such it's not a good plan to calculate stats inside the gear swap.
Yes it can be accurately calculated... And you should be able to calculate it whenever you need them that's A good advantage in cases 4/6 aka equip/un-equip in case 1009 and you don't have to wait until the user switch's to alt/standard gears to get a hold of the items stats to be able to accurately calculate them all together. And when/where the code user decides to do so... that's not my concern

After all it turns out your code is horribly inefficient. and it doesn't even worth looking at. And don't blame albetros references, Because you had the chance too clean/make all kind of changes to that code before you post it.

By the way my very first post was meant to help the thread owner nothing more and its not my fault if he/they misuse that few lines of coded that i posted..
{ Angelius } is offline  
Old 01/23/2013, 16:29   #34
 
elite*gold: 21
Join Date: Jul 2005
Posts: 9,193
Received Thanks: 5,376
Quote:
Originally Posted by { Angelius } View Post
...
Ooh sweet lord...


GetItemBySlot is case statement, not a loop. This code is only run once (when swapping gear). GetItemBySlot is ANY way you wish to match up slot ID with the item structure. This can be a dictionary (perfectly valid way of doing things). There are no loops involved though.

Anyways, so done with this as you refuse to take any constructive criticism. This was a 2 minute sample for how the loop could be written without changing anything else in the source.
pro4never is offline  
Thanks
1 User
Old 03/15/2013, 23:26   #35
 
.Xori^'s Avatar
 
elite*gold: 0
Join Date: Mar 2013
Posts: 58
Received Thanks: 7
Quote:
Originally Posted by pro4never View Post
Ooh sweet lord...


GetItemBySlot is case statement, not a loop. This code is only run once (when swapping gear). GetItemBySlot is ANY way you wish to match up slot ID with the item structure. This can be a dictionary (perfectly valid way of doing things). There are no loops involved though.

Anyways, so done with this as you refuse to take any constructive criticism. This was a 2 minute sample for how the loop could be written without changing anything else in the source.
Hey there, I managed to fix the headgear not changing in the SwapGear function in albetros. I currently have the function 100% working using a command /swapgear but would like to get the button working. Little help? Heres what I got.

Code:
#region Swap Gear
                                    case ItemAction.SwapToAltGears:
                                    case ItemAction.SwapToMainGears:
                                        user.Equipment.SwapGear();
                                        break;
                                    #endregion
into Packethandler under case 1009.

What am I missing?

#edit, is the button controlled under DataAction.cs? if so what is the data type?
.Xori^ is offline  
Old 03/16/2013, 01:07   #36
 
EOS 60D's Avatar
 
elite*gold: 0
Join Date: Feb 2013
Posts: 94
Received Thanks: 13
its itemusage type = 45
EOS 60D is offline  
Old 03/16/2013, 01:57   #37
 
.Xori^'s Avatar
 
elite*gold: 0
Join Date: Mar 2013
Posts: 58
Received Thanks: 7
Quote:
Originally Posted by EOS 60D View Post
its itemusage type = 45
Yea.. I already have that set. It's not working lol.

In fact, pressing the button doesn't even set off a breakpoint in packethandler.. What could the problem be?

-using Albetros source.
.Xori^ is offline  
Old 03/16/2013, 03:03   #38
 
EOS 60D's Avatar
 
elite*gold: 0
Join Date: Feb 2013
Posts: 94
Received Thanks: 13
Wait , what version you are currently working on?
EOS 60D is offline  
Old 03/17/2013, 04:02   #39
 
.Xori^'s Avatar
 
elite*gold: 0
Join Date: Mar 2013
Posts: 58
Received Thanks: 7
Quote:
Originally Posted by EOS 60D View Post
Wait , what version you are currently working on?
Version 5518.
.Xori^ is offline  
Reply


Similar Threads Similar Threads
Alternate equipment.
04/11/2012 - CO2 Private Server - 6 Replies
Has anyone added it? For some reason when I try to switch to the alternate equipment the client doesn't send anything to the server so I think maybe I should send another packet first ... has anyone got an idea which that would be?
Packet type 1009(item) subtype 52
04/05/2011 - CO2 Programming - 2 Replies
Does anyone know how to handle this packet? It's what makes this happen : http://img685.imageshack.us/img685/9016/prtscrcap turex.jpg Sending data back doesn't work. Help?
Alternate Equipment glitch
03/13/2010 - CO2 Exploits, Hacks & Tools - 19 Replies
This glitch allows you to have the effects of a poison blade, mana backsword or health backsword without actually having them equipped. All you have to do is equip either a poison blade, mana backsword or health backsword (Whichever effect you want) into your alternate equipment weapon slot. *Note* if you press the button which swaps it from one type of equipment to the other and then back, you'll have to re-do this. Archer verses archer helps a lot if you have a health backsword...
Alternate equipment glitch
01/27/2010 - CO2 Guides & Templates - 6 Replies
Yo, since i want it to get patched ill post it :P, Requirments: 1.Rb above lvl 70 and claimed level 70 promotion(This is for strong tros level 130 with 2 sdg gears) 2.Any lvl bow for 1 - 70 (Bow level 70 would be the best) 3.Put the bow in your alternate equipment,Buy a fire arrow(U can buy it from ape city) 4.Put the arrow in the alternate equipment. 5.Drag the alternative equipment button and put it on any F keys which u like. How to use:



All times are GMT +2. The time now is 22:10.


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.