can you help me

12/27/2010 05:33 marlyandedsel#1
I have my confiscator.cs file but i got error everytime i redeem some items
heres the code. red color is the error. can you help me

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConquerSx.PacketHandling
{

public class Confiscator
{
public static int CpsItem(Game.Item I)
{
return I.Plus * 300;
}
public static void ClainItem(Main.GameClient GC, byte[] Data)
{
string P = ""; string Phex = "";
for (byte bit = 0; bit < Data.Length - 8; bit++)
{
int Pi = Data[bit];
P += Data[bit] + " ";
Phex += Pi.ToString("X") + " ";
}
//Console.WriteLine("packet: {0} ", P);


uint Uid = BitConverter.ToUInt32(Data, 4);
uint NPC1 = BitConverter.ToUInt32(Data, 6);
uint NPC = BitConverter.ToUInt32(Data, 12);
//Console.WriteLine("Npc {0} ID {1}", NPC, Uid);

if (NPC == 33)
{
GC.SendPacket(Packets.ItemPacket(Uid, 100, 33));
// return;
foreach (Game.Character C in Game.World.H_Chars.Values)
{

if (C.EntityID == GC.MyChar.EntityID)
{
foreach (Game.Item I in GC.MyChar.ConfiscatorClain.Values)
{
if (I.Position == 1)
{
GC.MyChar.CPs += (uint)PacketHandling.Confiscator.CpsItem(I);
GC.MyChar.ConfiscatorClain.Remove(I.UID);
Database.DeleteClain(I.UID, GC.MyChar);
}
}
}
else
{
foreach (KeyValuePair<uint, Game.Item> Item in GC.MyChar.ConfiscatorClain)
{
Game.Item I = Item.Value;
// Console.WriteLine("Npc {0} ID {1}", I.UID, Uid);
if (I.UID == Uid)
{
Console.WriteLine(I.NameReward);
if (I.NameClain == C.Name)
{
Console.WriteLine(C.Name);
if (I.Time == 0)
{
// foreach (Game.Item I in GC.MyChar.ConfiscatorClain.Values)

C.ConfiscatorReward.Remove(I.UID);
Database.DeleteReward(I.UID, C);
GC.MyChar.ConfiscatorClain.Remove(I.UID);
Database.DeleteClain(I.UID, GC.MyChar);
GC.SendPacket(Packets.ItemPacket(Uid, 1, 33));
C.MyClient.SendPacket(Packets.ItemPacket(Uid, 2, 32));
GC.MyChar.AddFullItem(I.ID, I.Bless, I.Plus, I.Enchant
, I.Soc1, I.Soc2, I.Color, I.Progress, I.TalismanProgress
, I.Effect, I.FreeItem, I.CurDur, I.MaxDur, I.Suspicious
, I.Locked, I.LockedDays, I.RBG[0], I.RBG[1], I.RBG[2], I.RBG[3]);
GC.SendPacket2(Data);
C.MyClient.SendPacket2(Data);
}
}
}
}
}
}
}
}
public static void RewardItem(Main.GameClient GC, byte[] Data)
{
string P = ""; string Phex = "";
for (byte bit = 0; bit < Data.Length - 8; bit++)
{
int Pi = Data[bit];
P += Data[bit] + " ";
Phex += Pi.ToString("X") + " ";
}
//Console.WriteLine("packet: {0} ", P);

uint Uid = BitConverter.ToUInt32(Data, 4);
uint NPC = BitConverter.ToUInt32(Data, 12);
//Console.WriteLine("Npc {0} ID {1}", NPC, Uid);
if (Data[12] == 32)
{
foreach (Game.Character C in Game.World.H_Chars)
{
if (C.EntityID != GC.MyChar.EntityID)
{
foreach (Game.Item Item in C.ConfiscatorClain.Values)
{
if (Item.UID == Uid)
{
if (Item.NameClain == C.Name)
{
if (Item.Time <= 7)
{
if (GC.MyChar.CPs >= (uint)PacketHandling.Confiscator.CpsItem(Item))
{

GC.MyChar.CPs -= (uint)PacketHandling.Confiscator.CpsItem(Item);
GC.MyChar.ConfiscatorReward.Remove(Item.UID);
Database.DeleteReward(Item.UID, GC.MyChar);
C.ConfiscatorClain.Remove(Item.UID);
Database.UpSac(Item.UID, C);
GC.SendPacket(Packets.ItemPacket(Uid, 2, 32));
C.MyClient.SendPacket(Packets.ItemPacket(Uid, 1, 32));
Item.Position = 1;
C.MyClient.SendPacket(Packets.Sac(Item, C, (ushort)PacketHandling.Confiscator.CpsItem(Item), GC.MyChar.Name));
C.ConfiscatorClain.Add(Item.UID, Item);
//Congratulation %s has detaine the items whit %d for player% s.
GC.LocalMessage(2000, System.Drawing.Color.Red, "Congratulation " + GC.MyChar.Name + " has detain the items " + Item.DBInfo.ID + " with " + (ushort)PacketHandling.Confiscator.CpsItem(Item) + " for player " + C.Name + " ");
}
else
GC.LocalMessage(2005, System.Drawing.Color.Red, "Sorry, you need " + (ushort)PacketHandling.Confiscator.CpsItem(Item) + " Cps to clain");
}
}
}
}
}
}//
}
}
}
}
12/27/2010 12:57 Korvacs#2
Whats the error?
12/27/2010 17:52 marlyandedsel#3
Quote:
Originally Posted by Korvacs View Post
Whats the error?
Hi, here is the error hope you can help me and thanks.

System.InvalidCastException: Unable to cast object of type 'System.Collections.DictionaryEntry' to type 'conquersx.Game.Character'.
at conquersx.PacketHandling.Confiscator.RewardItem(Ga meClient GC, Byte[] Data) in K:\source conquersx\conquersxv8\Conquer-Sx\PacketHandling\Confiscator.cs:line 103
at conquersx.PacketHandler.Handle(GameClient GC, Byte[] Data) in K:\source conquersx\conquersxv8\Conquer-Sx\PacketHandler.cs:line 946
System.InvalidCastException: Unable to cast object of type 'System.Collections.DictionaryEntry' to type 'conquersx.Game.Character'.
at conquersx.PacketHandling.Confiscator.RewardItem(Ga meClient GC, Byte[] Data) in K:\source conquersx\conquersxv8\Conquer-Sx\PacketHandling\Confiscator.cs:line 103
at conquersx.PacketHandler.Handle(GameClient GC, Byte[] Data) in K:\source conquersx\conquersxv8\Conquer-Sx\PacketHandler.cs:line 946
System.InvalidCastException: Unable to cast object of type 'System.Collections.DictionaryEntry' to type 'conquersx.Game.Character'.
at conquersx.PacketHandling.Confiscator.RewardItem(Ga meClient GC, Byte[] Data) in K:\source conquersx\conquersxv8\Conquer-Sx\PacketHandling\Confiscator.cs:line 103
at conquersx.PacketHandler.Handle(GameClient GC, Byte[] Data) in K:\source conquersx\conquersxv8\Conquer-Sx\PacketHandler.cs:line 946
12/27/2010 17:59 pro4never#4
Quote:
Originally Posted by marlyandedsel View Post
Hi, here is the error hope you can help me and thanks.

System.InvalidCastException: Unable to cast object of type 'System.Collections.DictionaryEntry' to type 'conquersx.Game.Character'.
at conquersx.PacketHandling.Confiscator.RewardItem(Ga meClient GC, Byte[] Data) in K:\source conquersx\conquersxv8\Conquer-Sx\PacketHandling\Confiscator.cs:line 103
at conquersx.PacketHandler.Handle(GameClient GC, Byte[] Data) in K:\source conquersx\conquersxv8\Conquer-Sx\PacketHandler.cs:line 946
System.InvalidCastException: Unable to cast object of type 'System.Collections.DictionaryEntry' to type 'conquersx.Game.Character'.
at conquersx.PacketHandling.Confiscator.RewardItem(Ga meClient GC, Byte[] Data) in K:\source conquersx\conquersxv8\Conquer-Sx\PacketHandling\Confiscator.cs:line 103
at conquersx.PacketHandler.Handle(GameClient GC, Byte[] Data) in K:\source conquersx\conquersxv8\Conquer-Sx\PacketHandler.cs:line 946
System.InvalidCastException: Unable to cast object of type 'System.Collections.DictionaryEntry' to type 'conquersx.Game.Character'.
at conquersx.PacketHandling.Confiscator.RewardItem(Ga meClient GC, Byte[] Data) in K:\source conquersx\conquersxv8\Conquer-Sx\PacketHandling\Confiscator.cs:line 103
at conquersx.PacketHandler.Handle(GameClient GC, Byte[] Data) in K:\source conquersx\conquersxv8\Conquer-Sx\PacketHandler.cs:line 946
Ok well you're trying to iterate through a dictionary... which is a key value pair (key and value as one object..)

So all you need to do is put

.Values to iterate through the dictionary VALUES rather than the pair.

Alternatively if you wanted to iterate through the uids you could do the .Keys

I'd STRONGLY recommend reading through a basic introductory C# book.

As it happens I still have a link to a pdf version of C# for dummies. I was looking through the book earlier and, while, rather basic, it contains stuff that every coder on epvp who is trying to work with C# proxies/pservers SHOULD KNOW

[Only registered and activated users can see links. Click Here To Register...]

This is not "high end" information but I guarentee if you read through all, or even most of this book and put into practice some of the materials then you will be in the top 5-10 percent of 'programmers' on epvp (a sad but true fact)