public static void Send(Client client, VendingMachine vendingMachine)
        {
            PacketWriter packetWriter = new PacketWriter();

            packetWriter.PushByte(0xdf);
            packetWriter.PushByte(0xdf);
            packetWriter.PushShort(0xa);
            packetWriter.PushShort(1);
            packetWriter.PushShort(0);
            packetWriter.PushInt(3086);
            packetWriter.PushInt(client.Character.Id);
            packetWriter.PushInt(0x7f544905); // 20
            packetWriter.PushIdentity(vendingMachine.Type, vendingMachine.Id);
            packetWriter.PushByte(0);
            packetWriter.PushInt(0xb); // Counter??
            packetWriter.PushInt(0);
            packetWriter.PushInt(0); // 41
            packetWriter.PushCoord(vendingMachine.Coordinates);
            packetWriter.PushQuat(vendingMachine.Heading); // 69
            packetWriter.PushInt(vendingMachine.PlayField);
            packetWriter.PushInt(1000015);
            packetWriter.PushInt(0);
            packetWriter.PushShort(0x6f);
            packetWriter.PushInt(0x2379);
            packetWriter.PushInt(0); // 91
            packetWriter.PushByte(0x80);
            packetWriter.PushByte(2);
            packetWriter.PushShort(0x3603);
            packetWriter.PushInt(0x17);
            packetWriter.PushInt(vendingMachine.TemplateId);
            packetWriter.PushInt(0x2bd);
            packetWriter.PushInt(0); // 111
            packetWriter.PushInt(0x2be);
            packetWriter.PushInt(0);
            packetWriter.PushInt(0x2bf);
            packetWriter.PushInt(0);
            packetWriter.PushInt(0x19c); // 131
            packetWriter.PushInt(1);
            packetWriter.PushInt(0x1f5);
            packetWriter.PushInt(2);
            packetWriter.PushInt(0x1f4);
            packetWriter.PushInt(0);
            packetWriter.PushInt(0);
            packetWriter.PushInt(2);
            packetWriter.PushInt(0x32); // 147
            packetWriter.Push3F1Count(0);
            packetWriter.PushInt(3); // 155<

            byte[] packet = packetWriter.Finish();
            client.SendCompressed(packet);
        }
 public static void Send(Client client)
 {
     PacketWriter packetWriter = new PacketWriter();
     packetWriter.PushByte(0xdf);
     packetWriter.PushByte(0xdf);
     packetWriter.PushShort(0xa);
     packetWriter.PushShort(1);
     packetWriter.PushShort(0); // Length
     packetWriter.PushInt(3086);
     packetWriter.PushInt(client.Character.Id);
     packetWriter.PushInt(0x343c287f);
     packetWriter.PushIdentity(50000, client.Character.Id);
     packetWriter.PushByte(1);
     packetWriter.PushInt(0);
     packetWriter.PushInt(0);
     packetWriter.PushInt(0);
     packetWriter.Push3F1Count(client.Character.Bank.Count);
     foreach (AOItem item in client.Character.Bank)
     {
         packetWriter.PushInt(item.Flags); // misused the flags for position in the bank
         short flags = 0;
         if (item.isInstanced())
         {
             flags |= 0xa0;
         }
         if (item.LowID == item.HighID)
         {
             flags |= 2;
         }
         else
         {
             flags |= 1;
         }
         // perhaps there are more flags...
         packetWriter.PushShort(flags);
         packetWriter.PushShort((short)item.MultipleCount);
         packetWriter.PushInt(item.Type);
         packetWriter.PushInt(item.Instance);
         packetWriter.PushInt(item.LowID);
         packetWriter.PushInt(item.HighID);
         packetWriter.PushInt(item.Quality);
         packetWriter.PushInt(0); // didnt encounter any other value
     }
     byte[] reply = packetWriter.Finish();
     client.SendCompressed(reply);
 }
        public override void ExecuteCommand(Client client, Identity target, string[] args)
        {
            // No check needed, its done by CheckCommandArguments
            int gfx = int.Parse(args[3]);

            //begin assembling packet here
            PacketWriter packet = new PacketWriter();
            packet.PushByte(0xDF);
            packet.PushByte(0xDF);
            packet.PushShort(10);
            packet.PushShort(1);
            packet.PushShort(0);
            packet.PushInt(3086);
            packet.PushInt(client.Character.Id);
            packet.PushInt(0x4D450114);
            packet.PushIdentity(target);
            packet.PushByte(0);
            packet.Push3F1Count(1); // effects count
            // effect starts
            packet.PushIdentity(53030, 0); // effect ID (53030 = GfxEffect)
            packet.PushInt(4); // ?
            packet.PushInt(0); // Criterion count
            packet.PushInt(1); // Hits
            packet.PushInt(0); // Delay
            packet.PushInt(0); // 
            packet.PushInt(0); // 
            // effect args
            packet.PushInt(gfx); // Value
            packet.PushInt(0); // GfxLife
            packet.PushInt(0); // GfxSize
            packet.PushInt(0); // GfxRed
            packet.PushInt(0); // GfxGreen
            packet.PushInt(0); // GfxBlue
            packet.PushInt(0); // GfxFade
            // effect args end
            // effect ends
            packet.PushIdentity(50000, client.Character.Id);
            byte[] reply = packet.Finish();
            //done creating the packet
            Announce.Playfield(client.Character.PlayField, reply);
        }
        public static void SendPlayField(Client client, VendingMachine vendingMachine, int itemNumber)
        {
            PacketWriter packetWriter = new PacketWriter();

            packetWriter.PushByte(0xdf);
            packetWriter.PushByte(0xdf);
            packetWriter.PushShort(0xa);
            packetWriter.PushShort(1);
            packetWriter.PushShort(0);
            packetWriter.PushInt(3086);
            packetWriter.PushInt(client.Character.Id);
            packetWriter.PushInt(0x3b11256f);
            packetWriter.PushIdentity(0xc76e, 0x021fa86f); // whats this one???
            packetWriter.PushByte(0);
            packetWriter.PushInt(11);
            packetWriter.PushIdentity(client.Character.Type, client.Character.Id);
            packetWriter.PushInt(client.Character.PlayField);
            packetWriter.PushInt(0x0f424f);
            packetWriter.PushInt(0);
            packetWriter.PushShort(0x656f); // ??????
            packetWriter.Push3F1Count(6);
            packetWriter.PushInt(0);
            packetWriter.PushByte(0x80);
            packetWriter.PushByte(0);
            packetWriter.PushShort(0x0203);
            packetWriter.PushInt(0x17);
            packetWriter.PushInt(vendingMachine.Inventory[itemNumber].Item.LowID); // TODO: 3 times lowID and no highID?
            packetWriter.PushInt(0x2bd);
            packetWriter.PushInt(1);
            packetWriter.PushInt(0x2be);
            packetWriter.PushInt(vendingMachine.Inventory[itemNumber].Item.LowID);
            packetWriter.PushInt(0x2bf);
            packetWriter.PushInt(vendingMachine.Inventory[itemNumber].Item.LowID);
            packetWriter.PushInt(0x19c);
            packetWriter.PushInt(1);
            packetWriter.PushInt(0);

            // TODO: Actually send the data, probably research needed
        }
        public static void Send(Client client, VendingMachine vendingMachine)
        {
            PacketWriter packetWriter = new PacketWriter();

            packetWriter.PushByte(0xdf);
            packetWriter.PushByte(0xdf);
            packetWriter.PushShort(0xa);
            packetWriter.PushShort(1);
            packetWriter.PushShort(0);
            packetWriter.PushInt(3086);
            packetWriter.PushInt(client.Character.Id);
            packetWriter.PushInt(0x58362220);
            packetWriter.PushIdentity(vendingMachine.Type, vendingMachine.Id);
            packetWriter.PushByte(1);
            packetWriter.Push3F1Count(vendingMachine.Inventory.Count);
            foreach (InventoryEntries ie in vendingMachine.Inventory)
            {
                packetWriter.PushInt(ie.Item.LowID);
                packetWriter.PushInt(ie.Item.HighID);
                packetWriter.PushInt(ie.Item.Quality);
            }
            byte[] packet = packetWriter.Finish();
            client.SendCompressed(packet);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="packet"></param>
        /// <param name="client"></param>
        public void Read(ref byte[] packet, Client client)
        {
            PacketReader reader = new PacketReader(ref packet);

            Header header = reader.PopHeader();
            reader.PopByte();
            byte cmd = reader.PopByte();
            Identity target = reader.PopIdentity();
            int unknown = reader.PopInt();
            string CmdStr = "";
            byte CmdByte = 0;

            #region cmd args
            switch (cmd)
            {
                case 1:
                case 7:
                case 9:
                case 13:
                case 17:
                case 19:
                case 20:
                case 21:
                case 23:
                case 24:
                case 25:
                case 26:
                case 27:
                case 28:
                    short CmdStrLen = reader.PopShort();
                    CmdStr = reader.PopString((int)CmdStrLen);
                    break;
                case 10:
                    CmdByte = reader.PopByte();
                    break;
                default:
                    break;
            }
            reader.Finish();
            #endregion
            DataTable dt;
            #region cmd handlers
            switch (cmd)
            {
                #region /org create <name>
                case 1:
                    {
                        // org create
                        /* client wants to create organization
                         * name of org is CmdStr
                         */

                        string SqlQuery = "SELECT * FROM organizations WHERE Name='" + CmdStr + "'";
                        string guild_name = null;
                        uint orgID = 0;
                        dt = ms.ReadDT(SqlQuery);
                        if (dt.Rows.Count > 0)
                        {
                            guild_name = (string)dt.Rows[0]["Name"];
                        }

                        if (guild_name == null)
                        {
                            client.SendChatText("You have created the guild: " + CmdStr);

                            string CurrDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                            string SqlQuery2 = "INSERT INTO organizations (Name, creation, LeaderID, GovernmentForm) VALUES ('" + CmdStr + "', '" + CurrDate + "', '" + client.Character.ID + "', '0')";
                            ms.SqlInsert(SqlQuery2);
                            string SqlQuery3 = "SELECT * FROM organizations WHERE Name='" + CmdStr + "'";
                            dt = ms.ReadDT(SqlQuery3);
                            if (dt.Rows.Count > 0)
                            {
                                orgID = (UInt32)dt.Rows[0]["ID"];
                            }

                            // Make sure the order of these next two lines is not swapped -NV
                            client.Character.Stats.ClanLevel.Set(0);
                            client.Character.orgId = orgID;
                            break;
                        }
                        else
                        {
                            client.SendChatText("This guild already <font color=#DC143C>exists</font>");
                            break;
                        }
                    }
                #endregion

                #region /org ranks
                case 2:
                    // org ranks
                    //Displays Org Rank Structure.
                    /* Select governingform from DB, Roll through display from GovForm */
                    if (client.Character.orgId == 0)
                    {
                        client.SendChatText("You're not in an organization!");
                        break;
                    }
                    string ranksSql = "SELECT GovernmentForm FROM organizations WHERE ID = " + client.Character.orgId;
                    int govForm = -1;
                    dt = ms.ReadDT(ranksSql);
                    if (dt.Rows.Count > 0)
                    {
                        govForm = (Int32)dt.Rows[0]["GovernmentForm"];
                    }
                    client.SendChatText("Current Rank Structure: " + GetRankList(govForm));
                    break;
                #endregion

                #region /org contract
                case 3:
                    // org contract
                    break;
                #endregion

                #region unknown org command 4
                case 4:
                    Console.WriteLine("Case 4 Started");
                    break;
                #endregion

                #region /org info
                case 5:
                    {
                        Client tPlayer = null;
                        if (Misc.FindClient.FindClientByID(target.Instance, out tPlayer))
                        {
                            string orgDescription = "", orgObjective = "", orgHistory = "", orgLeaderName = "";
                            int orgGoverningForm = 0, orgLeaderID = 0;
                            dt = ms.ReadDT("SELECT * FROM organizations WHERE ID=" + tPlayer.Character.orgId);

                            if (dt.Rows.Count > 0)
                            {
                                orgDescription = (string)dt.Rows[0]["Description"];
                                orgObjective = (string)dt.Rows[0]["Objective"];
                                orgHistory = (string)dt.Rows[0]["History"];
                                orgGoverningForm = (Int32)dt.Rows[0]["GovernmentForm"];
                                orgLeaderID = (Int32)dt.Rows[0]["LeaderID"];
                            }

                            dt = ms.ReadDT("SELECT Name FROM characters WHERE ID=" + orgLeaderID);
                            if (dt.Rows.Count > 0)
                            {
                                orgLeaderName = (string)dt.Rows[0][0];
                            }

                            string TextGovForm = null;
                            if (orgGoverningForm == 0) { TextGovForm = "Department"; }
                            else if (orgGoverningForm == 1) { TextGovForm = "Faction"; }
                            else if (orgGoverningForm == 2) { TextGovForm = "Republic"; }
                            else if (orgGoverningForm == 3) { TextGovForm = "Monarchy"; }
                            else if (orgGoverningForm == 4) { TextGovForm = "Anarchism"; }
                            else if (orgGoverningForm == 5) { TextGovForm = "Feudalism"; }
                            else { TextGovForm = "Department"; }
                            string orgRank = GetRank(orgGoverningForm, tPlayer.Character.Stats.ClanLevel.StatBaseValue);
                            PacketWriter writer = new PacketWriter();
                            writer.PushBytes(new byte[] { 0xDF, 0xDF });
                            writer.PushShort(10);
                            writer.PushShort(1);
                            writer.PushShort(0);
                            writer.PushInt(3086);
                            writer.PushInt(client.Character.ID);
                            writer.PushInt(0x64582A07);
                            writer.PushIdentity(50000, tPlayer.Character.ID);
                            writer.PushByte(0);
                            writer.PushByte(2);    // OrgServer case 0x02 (Org Info)
                            writer.PushInt(0);
                            writer.PushInt(0);
                            writer.PushInt(0xDEAA); // Type (org)
                            writer.PushUInt(tPlayer.Character.orgId);    // org ID
                            writer.PushShort((short)tPlayer.Character.orgName.Length);
                            writer.PushBytes(Encoding.ASCII.GetBytes(tPlayer.Character.orgName));
                            writer.PushShort((short)orgDescription.Length);
                            writer.PushBytes(Encoding.ASCII.GetBytes(orgDescription));
                            writer.PushShort((short)orgObjective.Length);
                            writer.PushBytes(Encoding.ASCII.GetBytes(orgObjective));
                            writer.PushShort((short)orgHistory.Length);
                            writer.PushBytes(Encoding.ASCII.GetBytes(orgHistory));
                            writer.PushShort((short)TextGovForm.Length);
                            writer.PushBytes(Encoding.ASCII.GetBytes(TextGovForm));
                            writer.PushShort((short)orgLeaderName.Length);
                            writer.PushBytes(Encoding.ASCII.GetBytes(orgLeaderName));
                            writer.PushShort((short)orgRank.Length);
                            writer.PushBytes(Encoding.ASCII.GetBytes(orgRank));
                            writer.Push3F1Count(0);
                            byte[] reply = writer.Finish();

                            client.SendCompressed(reply);
                        }
                    }
                    break;
                #endregion

                #region /org disband
                case 6:
                    break;
                #endregion

                #region /org startvote <text> <duration> <entries>
                case 7:
                    // org startvote <"text"> <duration(minutes)> <entries>
                    // arguments (<text> <duration> and <entries>) are in CmdStr
                    break;
                #endregion

                #region /org vote info
                case 8:
                    // org vote info
                    break;
                #endregion

                #region /org vote <entry>
                case 9:
                    // <entry> is CmdStr
                    break;
                #endregion

                #region /org promote
                case 10:
                    {
                        // some arg in CmdByte. No idea what it is

                        //create the target namespace t_promote
                        Client t_promote = null;
                        string promoteSql = "";
                        int targetOldRank = -1;
                        int targetNewRank = -1;
                        int newPresRank = -1;
                        int oldPresRank = 0;
                        if (Misc.FindClient.FindClientByID(target.Instance, out t_promote))
                        {
                            //First we check if target is in the same org as you
                            if (t_promote.Character.orgId != client.Character.orgId)
                            {
                                //not in same org
                                client.SendChatText("Target is not in your organization!");
                                break;
                            }
                            //Target is in same org, are you eligible to promote?  Promoter Rank has to be TargetRank-2 or == 0
                            if ((client.Character.Stats.ClanLevel.Value == (t_promote.Character.Stats.ClanLevel.Value - 2)) || (client.Character.Stats.ClanLevel.Value == 0))
                            {
                                //Promoter is eligible. Start the process

                                //First we get the details about the org itself
                                promoteSql = "SELECT * FROM organizations WHERE ID = " + client.Character.orgId;
                                dt = ms.ReadDT(promoteSql);

                                int promoteGovForm = -1;
                                string promotedToRank = "";
                                string demotedFromRank = "";

                                if (dt.Rows.Count > 0)
                                {
                                    promoteGovForm = (Int32)dt.Rows[0]["GovernmentForm"];
                                }

                                //Check if new rank == 0, if so, demote promoter
                                if ((targetOldRank - 1) == 0)
                                {
                                    /* This is a bit more complex.  Here we need to promote new president first
                                         * then we go about demoting old president
                                         * finally we set the new leader in SQL
                                         * Reset OrgName to set changes
                                         */

                                    // Set new President's Rank
                                    targetOldRank = t_promote.Character.Stats.ClanLevel.Value;
                                    targetNewRank = targetOldRank - 1;
                                    promotedToRank = GetRank(promoteGovForm, (uint)targetNewRank);
                                    t_promote.Character.Stats.ClanLevel.Set(targetNewRank);
                                    // Demote the old president
                                    oldPresRank = client.Character.Stats.ClanLevel.Value;
                                    newPresRank = oldPresRank + 1;
                                    demotedFromRank = GetRank(promoteGovForm, (uint)newPresRank);
                                    client.Character.Stats.ClanLevel.Set(newPresRank);
                                    //Change the leader id in SQL
                                    string newLeadSql = "UPDATE organizations SET LeaderID = " + t_promote.Character.ID + " WHERE ID = " + t_promote.Character.orgId;
                                    ms.SqlUpdate(newLeadSql);
                                    client.SendChatText("You've passed leadership of the organization to: " + t_promote.Character.Name);
                                    t_promote.SendChatText("You've been promoted to the rank of " + promotedToRank + " by " + client.Character.Name);
                                    break;
                                }
                                else
                                {
                                    //Just Promote
                                    targetOldRank = t_promote.Character.Stats.ClanLevel.Value;
                                    targetNewRank = targetOldRank - 1;
                                    promotedToRank = GetRank(promoteGovForm, (uint)targetNewRank);
                                    t_promote.Character.Stats.ClanLevel.Set(targetNewRank);
                                    client.SendChatText("You've promoted " + t_promote.Character.Name + " to " + promotedToRank);
                                    t_promote.SendChatText("You've been promoted to the rank of " + promotedToRank + " by " + client.Character.Name);
                                }
                            }
                            else
                            {
                                //Promoter not eligible to promote
                                client.SendChatText("Your Rank is not high enough to promote " + t_promote.Character.Name);
                                break;
                            }
                        }
                        break;
                    }
                #endregion

                #region /org demote
                case 11:
                    // demote target player
                    //create the target namespace t_demote
                    Client t_demote = null;
                    string demoteSql = "";
                    int targetCurRank = -1;
                    int targetNewerRank = -1;
                    if (Misc.FindClient.FindClientByID(target.Instance, out t_demote))
                    {
                        //First we check if target is in the same org as you
                        if (t_demote.Character.orgId != client.Character.orgId)
                        {
                            //not in same org
                            client.SendChatText("Target is not in your organization!");
                            break;
                        }
                        //Target is in same org, are you eligible to demote?  Promoter Rank has to be TargetRank-2 or == 0
                        if ((client.Character.Stats.GmLevel.Value == (t_demote.Character.Stats.ClanLevel.Value - 2)) || (client.Character.Stats.ClanLevel.Value == 0))
                        {
                            //Promoter is eligible. Start the process

                            //First we get the details about the org itself
                            demoteSql = "SELECT GovernmentForm FROM organizations WHERE ID = " + client.Character.orgId;
                            dt = ms.ReadDT(demoteSql);
                            int demoteGovForm = -1;
                            string demotedToRank = "";
                            if (dt.Rows.Count > 0)
                            {
                                demoteGovForm = (Int32)dt.Rows[0]["GovernmentForm"];
                            }

                            //Check whether new rank would be lower than lowest for current govform
                            if ((targetCurRank + 1) > GetLowestRank(demoteGovForm))
                            {
                                client.SendChatText("You can't demote character any lower!");
                                break;
                            }
                            targetCurRank = t_demote.Character.Stats.GmLevel.Value;
                            targetNewerRank = targetCurRank + 1;
                            demotedToRank = GetRank(demoteGovForm, (uint)targetNewerRank);
                            t_demote.Character.Stats.ClanLevel.Set(targetNewerRank);
                            client.SendChatText("You've demoted " + t_demote.Character.Name + " to " + demotedToRank);
                            t_demote.SendChatText("You've been demoted to the rank of " + demotedToRank + " by " + client.Character.Name);
                            break;
                        }
                        else
                        {
                            //Promoter not eligible to promote
                            client.SendChatText("Your Rank is not high enough to demote " + t_demote.Character.Name);
                            break;
                        }
                    }
                    break;
                #endregion

                #region unknown org command 12
                case 12:
                    Console.WriteLine("Case 12 Started");
                    break;
                #endregion

                #region /org kick <name>
                case 13:
                    // kick <name> from org
                    // <name> is CmdStr

                    //create the t_player Client namespace, using CmdStr to find character id, in replacement of target.Instance
                    uint kickedFrom = client.Character.orgId;
                    string kickeeSql = "SELECT * FROM characters WHERE Name = '" + CmdStr + "'";
                    int kickeeId = 0;
                    dt = ms.ReadDT(kickeeSql);
                    if (dt.Rows.Count > 0)
                    {
                        kickeeId = (Int32)dt.Rows[0]["ID"];
                    }

                    Client target_player = null;
                    if (Misc.FindClient.FindClientByID(kickeeId, out target_player))
                    {
                        //Check if CmdStr is actually part of the org
                        uint kickeeOrgId = target_player.Character.orgId;
                        if (kickeeOrgId != client.Character.orgId)
                        {
                            //Not part of Org. break out.
                            client.SendChatText(CmdStr + "is not a member of your organization!");
                            break;
                        }

                        //They are part of the org, so begin the processing...
                        //First we check if the player is online...
                        string onlineSql = "SELECT online FROM characters WHERE ID = " + client.Character.ID;
                        dt = ms.ReadDT(onlineSql);
                        int onlineStatus = 0;
                        if (dt.Rows.Count > 0)
                        {
                            onlineStatus = (Int32)dt.Rows[0][0];
                        }

                        if (onlineStatus == 0)
                        {
                            //Player isn't online. Org Kicks are processed in a different method
                            break;
                        }

                        //Player is online. Start the kick.
                        target_player.Character.Stats.ClanLevel.Set(0);
                        target_player.Character.orgId = 0;
                        string kickedFromSql = "SELECT Name FROM organizations WHERE ID = " + client.Character.orgId;
                        dt = ms.ReadDT(kickedFromSql);
                        string KickedFromName = "";
                        if (dt.Rows.Count > 0)
                        {
                            KickedFromName = (string)dt.Rows[0][0];
                        }
                        target_player.SendChatText("You've been kicked from the organization " + KickedFromName);

                    }
                    break;
                #endregion

                #region /org invite
                case 14:
                    {
                        Client t_player = null;
                        if (Misc.FindClient.FindClientByID(target.Instance, out t_player))
                        {
                            PacketWriter writer = new PacketWriter();
                            writer.PushBytes(new byte[] { 0xDF, 0xDF });
                            writer.PushShort(10);
                            writer.PushShort(1);
                            writer.PushShort(0);
                            writer.PushInt(3086); //Sender
                            writer.PushInt(t_player.Character.ID);  //Receiver
                            writer.PushInt(0x64582A07); //Packet ID
                            writer.PushIdentity(50000, t_player.Character.ID); //Target Identity
                            writer.PushByte(0);
                            writer.PushByte(5); //OrgServer Case 0x05 (Invite)
                            writer.PushInt(0);
                            writer.PushInt(0);
                            writer.PushIdentity(0xDEAA, (int)client.Character.orgId); // Type (org)
                            writer.PushShort((short)client.Character.orgName.Length);
                            writer.PushBytes(Encoding.ASCII.GetBytes(client.Character.orgName));
                            writer.PushInt(0);
                            byte[] reply = writer.Finish();

                            t_player.SendCompressed(reply);
                        }
                    }
                    break;
                #endregion

                #region Org Join
                case 15:
                    {
                        //target.Instance holds the OrgID of the Org wishing to be joined.
                        int orgIdtoJoin = target.Instance;
                        string JoinSql = "SELECT * FROM organizations WHERE ID = '" + orgIdtoJoin + "' LIMIT 1";
                        int gov_form = 0;
                        dt = ms.ReadDT(JoinSql);
                        if (dt.Rows.Count > 0)
                        {
                            gov_form = (Int32)dt.Rows[0]["GovernmentForm"];
                        }

                        // Make sure the order of these next two lines is not swapped -NV
                        client.Character.Stats.ClanLevel.Set(GetLowestRank(gov_form));
                        client.Character.orgId = (uint)orgIdtoJoin;
                    }
                    break;
                #endregion

                #region /org leave
                case 16:
                    // org leave
                    // TODO: Disband org if it was leader that left org. -Suiv-
                    // I don't think a Disband happens if leader leaves. I don't think leader -can- leave without passing lead to another
                    // Something worth testing on Testlive perhaps ~Chaz
                    // Just because something happens on TL, doesnt mean its a good idea. Really tbh id prefer it if you had to explicitly type /org disband to disband rather than /org leave doing it... -NV
                    // Agreeing with NV.  Org Leader can't leave without passing lead on.  org disband requires /org disband to specifically be issued, with a Yes/No box.
                    string LeaveSql = "SELECT * FROM organizations WHERE ID = " + client.Character.orgId;
                    int govern_form = 0;
                    dt = ms.ReadDT(LeaveSql);
                    if (dt.Rows.Count > 0)
                    {
                        govern_form = (Int32)dt.Rows[0]["GovernmentForm"];
                    }

                    if ((client.Character.Stats.ClanLevel.Value == 0) && (govern_form != 4))
                    {
                        client.SendChatText("Organization Leader cannot leave organization without Disbanding or Passing Leadership!");
                    }
                    else
                    {
                        client.Character.orgId = 0;
                        client.SendChatText("You left the guild");

                    }
                    break;
                #endregion

                #region /org tax | /org tax <tax>
                case 17:
                    // gets or sets org tax
                    // <tax> is CmdStr
                    // if no <tax>, then just send chat text with current tax info

                    if (CmdStr == null)
                    {
                        client.SendChatText("The current organization tax rate is: ");
                        break;
                    }
                    else
                    {
                        break;
                    }
                #endregion

                #region /org bank
                case 18:
                    {
                        // org bank
                        dt = ms.ReadDT("SELECT * FROM organizations WHERE ID=" + client.Character.orgId);
                        if (dt.Rows.Count > 0)
                        {
                            UInt64 bank_credits = (UInt64)dt.Rows[0]["Bank"];
                            client.SendChatText("Your bank has " + bank_credits + " credits in its account");
                        }
                    }
                    break;
                #endregion

                #region /org bank add <cash>
                case 19:
                    {
                        if (client.Character.orgId == 0)
                        {
                            client.SendChatText("You are not in an organisation.");

                            break;
                        }

                        // org bank add <cash>
                        int minuscredits_fromplayer = Convert.ToInt32(CmdStr);
                        int characters_credits = client.Character.Stats.Cash.Value;

                        if (characters_credits < minuscredits_fromplayer)
                        {
                            client.SendChatText("You do not have enough Credits");
                        }
                        else
                        {
                            int total_Creditsspent = characters_credits - minuscredits_fromplayer;
                            client.Character.Stats.Cash.Set(total_Creditsspent);

                            ms.SqlUpdate("UPDATE `organizations` SET `Bank` = `Bank` + " + minuscredits_fromplayer + " WHERE `ID` = " + client.Character.orgId);
                            client.SendChatText("You have donated " + minuscredits_fromplayer + " to the organization");
                        }
                    }

                    break;
                #endregion

                #region /org bank remove <cash>
                case 20:
                    // org bank remove <cash>
                    // <cash> is CmdStr
                    // player wants to take credits from org bank
                    // only leader can do that
                    if ((client.Character.Stats.ClanLevel.Value != 0) || (client.Character.orgId == 0))
                    {
                        client.SendChatText("You're not the leader of an Organization");
                        break;
                    }
                    int remove_credits = Convert.ToInt32(CmdStr);
                    long org_bank = 0;
                    dt = ms.ReadDT("SELECT Bank FROM organizations WHERE ID = " + client.Character.orgId);
                    if (dt.Rows.Count > 0)
                    {
                        org_bank = (Int64)dt.Rows[0][0];
                    }
                    if (remove_credits > org_bank)
                    {
                        client.SendChatText("Not enough credits in Organization Bank!");
                        break;
                    }
                    else
                    {
                        long neworgbank = org_bank - remove_credits;
                        int existingcreds = 0;
                        existingcreds = client.Character.Stats.Cash.Value;
                        int newcreds = existingcreds + remove_credits;
                        ms.SqlUpdate("UPDATE organizations SET Bank = " + neworgbank + " WHERE ID = " + client.Character.orgId);
                        client.Character.Stats.Cash.Set(newcreds);
                        client.SendChatText("You've removed " + remove_credits + " credits from the organization bank");
                    }
                    break;
                #endregion

                #region /org bank paymembers <cash>
                case 21:
                    // <cash> is CmdStr
                    // give <cash> credits to every org member
                    // credits are taken from org bank
                    // only leader can do it
                    break;
                #endregion

                #region /org debt
                case 22:
                    // send player text about how big is his/her tax debt to org
                    break;
                #endregion

                #region /org history <text>
                case 23:
                    {
                        if (client.Character.Stats.ClanLevel.Value == 0)
                        {
                            // org history <history text>
                            ms.SqlUpdate("UPDATE organizations SET history = '" + CmdStr + "' WHERE ID = '" + client.Character.orgId + "'");
                            client.SendChatText("History Updated");
                        }
                        else { client.SendChatText("You must be the Organization Leader to perform this command!"); }
                    }
                    break;
                #endregion

                #region /org objective <text>
                case 24:
                    {
                        if (client.Character.Stats.ClanLevel.Value == 0)
                        {
                            // org objective <objective text>
                            ms.SqlUpdate("UPDATE organizations SET objective = '" + CmdStr + "' WHERE ID = '" + client.Character.orgId + "'");
                            client.SendChatText("Objective Updated");
                        }
                        else { client.SendChatText("You must be the Organization Leader to perform this command!"); }
                    }
                    break;
                #endregion

                #region /org description <text>
                case 25:
                    {
                        if (client.Character.Stats.ClanLevel.Value == 0)
                        {
                            // org description <description text>
                            ms.SqlUpdate("UPDATE organizations SET description = '" + CmdStr + "' WHERE ID = '" + client.Character.orgId + "'");
                            client.SendChatText("Description Updated");
                        }
                        else { client.SendChatText("You must be the Organization Leader to perform this command!"); }
                    }
                    break;
                #endregion

                #region /org name <text>
                case 26:
                    {
                        // org name <name>
                        /* Renames Organization
                         * Checks for Existing Orgs with similar name to stop crash
                         * Chaz
                         */
                        if (client.Character.Stats.ClanLevel.Value == 0)
                        {
                            string SqlQuery26 = "SELECT * FROM organizations WHERE Name LIKE '" + CmdStr + "' LIMIT 1";
                            string CurrentOrg = null;
                            dt = ms.ReadDT(SqlQuery26);
                            if (dt.Rows.Count > 0)
                            {
                                CurrentOrg = (string)dt.Rows[0]["Name"];
                            }

                            if (CurrentOrg == null)
                            {
                                string SqlQuery27 = "UPDATE organizations SET Name = '" + CmdStr + "' WHERE ID = '" + client.Character.orgId + "'";
                                ms.SqlUpdate(SqlQuery27);
                                client.SendChatText("Organization Name Changed to: " + CmdStr);

                                // Forces reloading of org name and the like
                                // XXXX TODO: Make it reload for all other members in the org
                                client.Character.orgId = client.Character.orgId;
                                break;
                            }
                            else
                            {
                                client.SendChatText("An Organization already exists with that name");
                                break;
                            }
                        }
                        else { client.SendChatText("You must be the organization leader to perform this command!"); }
                        break;
                    }
                #endregion

                #region /org governingform <text>
                case 27:
                    {
                        // org governingform <form>
                        /* Current Governing Forms:
                         * Department, Faction, Republic, Monarchy, Anarchism, Feudalism
                         */
                        //Check on whether your President or not
                        if (client.Character.Stats.ClanLevel.Value == 0)
                        {
                            //first we drop the case on the input, just to be sure.
                            Int32 GovFormNum = -1;
                            if (CmdStr == null)
                            {
                                //list gov forms
                                client.SendChatText("List of Accepted Governing Forms is: department, faction, republic, monarchy, anarchism, feudalism");
                                break;
                            }
                            //was correct input passed?
                            switch (CmdStr.ToLower())
                            {
                                case "department":
                                    GovFormNum = 0;
                                    break;
                                case "faction":
                                    GovFormNum = 1;
                                    break;
                                case "republic":
                                    GovFormNum = 2;
                                    break;
                                case "monarchy":
                                    GovFormNum = 3;
                                    break;
                                case "anarchism":
                                    GovFormNum = 4;
                                    break;
                                case "feudalism":
                                    GovFormNum = 5;
                                    break;
                                default:
                                    client.SendChatText(CmdStr + " Is an invalid Governing Form!");
                                    client.SendChatText("Accepted Governing Forms are: department, faction, republic, monarchy, anarchism, feudalism");
                                    break;
                            }
                            if (GovFormNum != -1)
                            {
                                ms.SqlUpdate("UPDATE organizations SET GovernmentForm = '" + GovFormNum + "' WHERE ID = '" + client.Character.orgId + "'");
                                foreach (int currentCharId in OrgMisc.GetOrgMembers(client.Character.orgId, true))
                                {
                                    client.Character.Stats.ClanLevel.Set(GetLowestRank(GovFormNum));
                                }
                                client.SendChatText("Governing Form is now: " + CmdStr);
                                break;
                            }
                        }
                        else
                        {
                            //Haha! You're not the org leader!
                            client.SendChatText("You must be the Org Leader to perform this command");
                            break;
                        }
                    }
                    break;
                #endregion

                #region /org stopvote <text>
                case 28:
                    // <text> is CmdStr
                    break;
                #endregion

                #region unknown command
                default:
                    break;
                #endregion
            }
            #endregion

            reader.Finish();
        }
Exemple #7
0
 /// <summary>
 /// Write inventory data into packetwriter
 /// </summary>
 /// <param name="writer">ref of the packetwriter</param>
 public void writeInventorytoPacket(ref PacketWriter writer)
 {
     int count;
     lock (Inventory)
     {
         writer.Push3F1Count(Inventory.Count);
         for (count = 0; count < Inventory.Count; count++)
         {
             writer.PushInt(Inventory[count].Placement);
             writer.PushShort((short)Inventory[count].Item.flags);
             writer.PushShort((short)Inventory[count].Item.multiplecount);
             writer.PushIdentity(Inventory[count].Item.Type, Inventory[count].Item.Instance);
             writer.PushInt(Inventory[count].Item.lowID);
             writer.PushInt(Inventory[count].Item.highID);
             writer.PushInt(Inventory[count].Item.Quality);
             writer.PushInt(Inventory[count].Item.Nothing);
         }
     }
 }
        public static void AnnounceAppearanceUpdate(Character character)
        {
            List<AOMeshs> meshs;
            PacketWriter packetWriter = new PacketWriter();
            packetWriter.PushByte(0xDF);
            packetWriter.PushByte(0xDF);
            packetWriter.PushShort(10);
            packetWriter.PushShort(1);
            packetWriter.PushShort(0); // Packet size. writer will take care of this
            packetWriter.PushInt(3086);
            packetWriter.PushInt(character.Id);
            packetWriter.PushInt(0x41624F0D);
            packetWriter.PushIdentity(50000, character.Id);
            packetWriter.PushByte(0);
            packetWriter.Push3F1Count(5); // Textures are always transferred
            int c;

            bool socialonly;
            bool showsocial;
            /*
            bool showhelmet;
            bool LeftPadVisible;
            bool RightPadVisible;
            bool DoubleLeftPad;
            bool DoubleRightPad;

            int TexturesCount;
            int HairMeshValue;
            int WeaponMeshRightValue;
            int WeaponMeshLeftValue;

            uint HeadMeshBaseValue;
            int HeadMeshValue;

            int BackMeshValue;
            int ShoulderMeshRightValue;
             */
            //int ShoulderMeshRightValue;

            int VisualFlags;
            int PlayField;
            /*
            int OverrideTextureHead;
            int OverrideTextureWeaponRight;
            int OverrideTextureWeaponLeft;
            int OverrideTextureShoulderpadRight;
            int OverrideTextureShoulderpadLeft;
            int OverrideTextureBack;
            int OverrideTextureAttractor;
            */
            List<AOTextures> textures = new List<AOTextures>();

            Dictionary<int, int> socialTab = new Dictionary<int, int>();

            lock (character)
            {
                VisualFlags = character.Stats.VisualFlags.Value;

                socialonly = ((character.Stats.VisualFlags.Value & 0x40) > 0);
                showsocial = ((character.Stats.VisualFlags.Value & 0x20) > 0);
                /*
                showhelmet = ((character.Stats.VisualFlags.Value & 0x4) > 0);
                LeftPadVisible = ((character.Stats.VisualFlags.Value & 0x1) > 0);
                RightPadVisible = ((character.Stats.VisualFlags.Value & 0x2) > 0);
                DoubleLeftPad = ((character.Stats.VisualFlags.Value & 0x8) > 0);
                DoubleRightPad = ((character.Stats.VisualFlags.Value & 0x10) > 0);

                HairMeshValue = character.Stats.HairMesh.Value;
                TexturesCount = character.Textures.Count;
                HairMeshValue = character.Stats.HairMesh.Value;
                WeaponMeshRightValue = character.Stats.WeaponMeshRight.Value;
                WeaponMeshLeftValue = character.Stats.WeaponMeshLeft.Value;

                HeadMeshBaseValue = character.Stats.HeadMesh.StatBaseValue;
                HeadMeshValue = character.Stats.HeadMesh.Value;

                BackMeshValue = character.Stats.BackMesh.Value;
                ShoulderMeshRightValue = character.Stats.ShoulderMeshRight.Value;
                 */
                //ShoulderMeshLeftValue = character.Stats.ShoulderMeshLeft.Value;
                /*
                OverrideTextureHead = character.Stats.OverrideTextureHead.Value;
                OverrideTextureWeaponRight = character.Stats.OverrideTextureWeaponRight.Value;
                OverrideTextureWeaponLeft = character.Stats.OverrideTextureWeaponLeft.Value;
                OverrideTextureShoulderpadRight = character.Stats.OverrideTextureShoulderpadRight.Value;
                OverrideTextureShoulderpadLeft = character.Stats.OverrideTextureShoulderpadLeft.Value;
                OverrideTextureBack = character.Stats.OverrideTextureBack.Value;
                OverrideTextureAttractor = character.Stats.OverrideTextureAttractor.Value;
                */
                PlayField = character.PlayField;

                foreach (int num in character.SocialTab.Keys)
                {
                    socialTab.Add(num, character.SocialTab[num]);
                }

                foreach (AOTextures texture in character.Textures)
                {
                    textures.Add(new AOTextures(texture.place, texture.Texture));
                }

                meshs = MeshLayers.GetMeshs(character, showsocial, socialonly);
            }

            AOTextures aotemp = new AOTextures(0, 0);
            for (c = 0; c < 5; c++)
            {
                aotemp.Texture = 0;
                aotemp.place = c;
                int c2;
                for (c2 = 0; c2 < textures.Count; c2++)
                {
                    if (textures[c2].place == c)
                    {
                        aotemp.Texture = textures[c2].Texture;
                        break;
                    }
                }
                if (showsocial)
                {
                    if (socialonly)
                    {
                        aotemp.Texture = socialTab[c];
                    }
                    else
                    {
                        if (socialTab[c] != 0)
                        {
                            aotemp.Texture = socialTab[c];
                        }
                    }
                }

                packetWriter.PushInt(aotemp.place);
                packetWriter.PushInt(aotemp.Texture);
                packetWriter.PushInt(0);
            }

            c = meshs.Count;
            packetWriter.Push3F1Count(c);
            foreach (AOMeshs mesh in meshs)
            {
                packetWriter.PushByte((byte)mesh.Position);
                packetWriter.PushUInt(mesh.Mesh);
                packetWriter.PushInt(mesh.OverrideTexture); // Override Texture!!!!!!
                packetWriter.PushByte((byte)mesh.Layer);
            }

            packetWriter.PushShort((short)(VisualFlags)); // 673 = VisualFlags
            packetWriter.PushByte(0);

            byte[] reply = packetWriter.Finish();
            Announce.Playfield(PlayField, reply);
        }
 /// <summary>
 /// Write Textures to PacketWriter
 /// </summary>
 /// <param name="packet">Packet Writer</param>
 public void WriteTexturesToPacket(PacketWriter packet)
 {
     packet.Push3F1Count(this.Textures.Count);
     int count;
     for (count = 0; count < this.Textures.Count; count++)
     {
         packet.PushInt(this.Textures[count].place);
         packet.PushInt(this.Textures[count].Texture);
         packet.PushInt(0);
     }
 }
        public static void SpawnNpcToClient(
            NonPlayerCharacterClass nonPlayerCharacter, Client targetClient, bool wholePlayfield)
        {
            int unknown1 = 0;
            int unknown2 = 0;
            int unknown3 = 0;
            PacketWriter spawn = new PacketWriter();
            int counter;
            int packetflags = 0x0001; // We want to spawn a NPC
            packetflags |= 0x0200; // Heading flag
            packetflags |= 0x0040; // packet has playfield
            packetflags |= 0x1000; // push level as 2 byte
            //            if (mob.Stats.GetStat(466) <= 255)
            {
                packetflags |= 0x80000; // LOS Height 1 byte
            }

            if (nonPlayerCharacter.Attacking != 0)
            {
                packetflags |= 0x400;
            }

            packetflags |= 0x2000000;
            packetflags |= 0x0200000;
            packetflags |= 0x0000002;

            spawn.PushByte(0xDF);
            spawn.PushByte(0xDF);
            spawn.PushShort(10);
            spawn.PushShort(1);
            spawn.PushShort(0); // Length, packetwriter will take care of this
            spawn.PushInt(3086);
            if (targetClient == null)
            {
                spawn.PushInt(0); // will be sent to whole playfield
            }
            else
            {
                spawn.PushInt(targetClient.Character.Id);
            }
            spawn.PushInt(0x271B3A6B);
            spawn.PushIdentity(50000, nonPlayerCharacter.Id);
            spawn.PushByte(0);
            spawn.PushByte(0x39); // version 0x39
            spawn.PushInt(packetflags); // packetflags
            spawn.PushInt(nonPlayerCharacter.PlayField);
            spawn.PushCoord(nonPlayerCharacter.Coordinates);
            spawn.PushQuat(nonPlayerCharacter.Heading);
            // Side, Fatness, Breed, Sex, Race
            //   33,      47,     4,  59,    89
            spawn.PushUInt(
                nonPlayerCharacter.Stats.Side.Value + (nonPlayerCharacter.Stats.Fatness.Value * 8)
                + (nonPlayerCharacter.Stats.Breed.Value * 32) + (nonPlayerCharacter.Stats.Sex.Value * 256)
                + (nonPlayerCharacter.Stats.Race.Value * 1024));
            spawn.PushByte((byte)(nonPlayerCharacter.Name.Length + 1));
            spawn.PushBytes(Encoding.ASCII.GetBytes(nonPlayerCharacter.Name));
            spawn.PushByte(0);
            spawn.PushUInt(nonPlayerCharacter.Stats.Flags.Value);
            spawn.PushShort(0); // AccountFlags
            spawn.PushShort(0); // Expansion
            if (nonPlayerCharacter.Stats.NpcFamily.Value <= 255) // NPCFamily
            {
                packetflags |= 0x20000; // NPC Family 1 byte
                spawn.PushByte((byte)nonPlayerCharacter.Stats.NpcFamily.Value);
            }
            else
            {
                packetflags &= ~0x20000; // NPC Family 2 byte
                spawn.PushShort((short)nonPlayerCharacter.Stats.NpcFamily.Value);
            }

            spawn.PushByte(0);
            spawn.PushByte(0);
            spawn.PushShort(0);

            // TODO: set packetflag for levelsize
            spawn.PushShort((short)nonPlayerCharacter.Stats.Level.Value); // 54 = Level

            // TODO: set packetflag for Healthsize/damagesize
            spawn.PushUInt(nonPlayerCharacter.Stats.Life.Value); // 1 = Life (max HP)
            spawn.PushUInt(nonPlayerCharacter.Stats.Health.Value);
                // 27 = Health left?? (same Size as Health, flag for 1byte not set)

            // If NPC is in grid or fixer grid
            // make him look like nice upside down pyramid
            if ((nonPlayerCharacter.PlayField == 152) || (nonPlayerCharacter.PlayField == 4107))
            {
                spawn.PushInt(99902);
            }
            else
            {
                spawn.PushUInt(nonPlayerCharacter.Stats.MonsterData.Value); // 359=Monsterdata
            }

            spawn.PushShort((short)nonPlayerCharacter.Stats.MonsterScale.Value); // 360 = monsterscale
            spawn.PushShort(0x1F); // VisualFlags
            spawn.PushByte(0); // Visible title?
            spawn.PushInt(0x1C);
            spawn.PushInt(unknown1); // KnuBot values?
            spawn.PushInt(unknown2);
            spawn.PushInt(unknown3);

            // TODO: Movement Modes
            spawn.PushByte(1); // CurrentMovementMode
            spawn.PushByte(1); // Don't change
            spawn.PushShort(1);
            spawn.PushShort(1);
            spawn.PushShort(1);
            spawn.PushShort(1);
            spawn.PushShort(0);
            spawn.PushShort(2);
            spawn.PushShort(0);

            if (nonPlayerCharacter.Stats.HeadMesh.Value != 0) // 64 = headmesh
            {
                packetflags |= 0x80;
                spawn.PushUInt(nonPlayerCharacter.Stats.HeadMesh.Value);
            }

            // TODO: runspeedsize+flag
            if (nonPlayerCharacter.Stats.RunSpeed.Value > 255)
            {
                packetflags |= 0x2000;
                spawn.PushShort((short)nonPlayerCharacter.Stats.RunSpeed.Value); // 156 = RunSpeed
            }
            else
            {
                spawn.PushByte((byte)nonPlayerCharacter.Stats.RunSpeed.Value); // 156 = RunSpeed
            }

            if (nonPlayerCharacter.Attacking != 0)
            {
                spawn.PushInt(0xc350);
                spawn.PushInt(nonPlayerCharacter.Attacking);
            }

            if (nonPlayerCharacter.Meshs.Count > 0)
            {
                packetflags |= 0x10; // Meshs on mob
                spawn.Push3F1Count(nonPlayerCharacter.Meshs.Count);
                for (counter = 0; counter < nonPlayerCharacter.Meshs.Count; counter++)
                {
                    // Name for meshtemplate not needed, sending 32byte 00 instead, thx to Suiv
                    int counter2;
                    for (counter2 = 0; counter2 < 8; counter2++)
                    {
                        spawn.PushInt(0);
                    }
                    spawn.PushInt(nonPlayerCharacter.Meshs[counter].Position);
                    spawn.PushInt(nonPlayerCharacter.Meshs[counter].Mesh);
                    spawn.PushInt(nonPlayerCharacter.Meshs[counter].OverrideTexture);
                }
            }

            // Running Nanos/Nano Effects
            spawn.Push3F1Count(nonPlayerCharacter.ActiveNanos.Count);
            for (counter = 0; counter < nonPlayerCharacter.ActiveNanos.Count; counter++)
            {
                spawn.PushInt(nonPlayerCharacter.ActiveNanos[counter].Nanotype);
                spawn.PushInt(nonPlayerCharacter.ActiveNanos[counter].Instance);
                spawn.PushInt(nonPlayerCharacter.ActiveNanos[counter].Value3);
                spawn.PushInt(nonPlayerCharacter.ActiveNanos[counter].Time1);
                spawn.PushInt(nonPlayerCharacter.ActiveNanos[counter].Time2);
            }

            // Waypoints
            if (nonPlayerCharacter.Waypoints.Count > 0)
            {
                packetflags |= 0x10000; // Waypoints
                spawn.PushInt(0xc350);
                spawn.PushInt(nonPlayerCharacter.Id);
                spawn.Push3F1Count(nonPlayerCharacter.Waypoints.Count); // Waypoints
                for (counter = 0; counter < nonPlayerCharacter.Waypoints.Count; counter++)
                {
                    spawn.PushCoord(nonPlayerCharacter.Waypoints[counter]);
                }
            }

            // Textures have to be rewritten too
            // mobs should get a equip table
            // and get the textures from the equipped items

            spawn.Push3F1Count(nonPlayerCharacter.Textures.Count); // Texture count (should be 5 at all times iirc)
            int c;
            for (c = 0; c < nonPlayerCharacter.Textures.Count; c++)
            {
                spawn.PushInt(nonPlayerCharacter.Textures[c].place);
                spawn.PushInt(nonPlayerCharacter.Textures[c].Texture);
                spawn.PushInt(0);
            }

            // same as texture part, equip table should define the additional meshs
            // data could be stored with the item entries

            int addmeshs = 0;
            if (nonPlayerCharacter.Stats.WeaponMeshRight.Value != 0)
            {
                addmeshs++;
            }
            if (nonPlayerCharacter.Stats.WeaponMeshLeft.Value != 0)
            {
                addmeshs++;
            }
            if (nonPlayerCharacter.Stats.HeadMesh.Value != 0)
            {
                addmeshs++;
            }
            if (nonPlayerCharacter.Stats.BackMesh.Value != 0)
            {
                addmeshs++;
            }
            if (nonPlayerCharacter.Stats.ShoulderMeshRight.Value != 0)
            {
                addmeshs++;
            }
            if (nonPlayerCharacter.Stats.ShoulderMeshLeft.Value != 0)
            {
                addmeshs++;
            }
            if (nonPlayerCharacter.Stats.HairMesh.Value != 0)
            {
                addmeshs++;
            }
            //            if (mob.Stats.GetStat(42) != 0) // 42 = CATMesh, what is this?
            //                addmeshs++;
            if (nonPlayerCharacter.Stats.HairMesh.Value != 0)
            {
                addmeshs++;
            }

            spawn.Push3F1Count(addmeshs);
            if (addmeshs > 0)
            {
                // 0 head, 1 r_hand, 2 l_hand, 3 r_shoulder, 4 l_shoulder, 5 back, 6 hip, 7 r_thigh, 8 l_thigh, 9 r_crus, 10 l_crus, 11 r_arm, 12 l_arm, 13 r_forearm, 14 l_forearm
                if (nonPlayerCharacter.Stats.HeadMesh.Value != 0)
                {
                    spawn.PushByte(0);
                    spawn.PushUInt(nonPlayerCharacter.Stats.HeadMesh.Value);
                    spawn.PushInt(0);
                    spawn.PushByte(4);
                }
                if (nonPlayerCharacter.Stats.WeaponMeshRight.Value != 0)
                {
                    spawn.PushByte(1); // Position
                    spawn.PushUInt(nonPlayerCharacter.Stats.WeaponMeshRight.Value); // Mesh ID
                    spawn.PushInt(0); // Unknown
                    spawn.PushByte(4); // Priority
                }
                if (nonPlayerCharacter.Stats.WeaponMeshLeft.Value != 0)
                {
                    spawn.PushByte(2); // Position
                    spawn.PushUInt(nonPlayerCharacter.Stats.WeaponMeshLeft.Value); // Mesh ID
                    spawn.PushInt(0); // Unknown
                    spawn.PushByte(4); // Priority
                }
                if (nonPlayerCharacter.Stats.ShoulderMeshRight.Value != 0)
                {
                    spawn.PushByte(3);
                    spawn.PushUInt(nonPlayerCharacter.Stats.ShoulderMeshRight.Value);
                    spawn.PushInt(0);
                    spawn.PushByte(4);
                }
                if (nonPlayerCharacter.Stats.ShoulderMeshLeft.Value != 0)
                {
                    spawn.PushByte(4);
                    spawn.PushUInt(nonPlayerCharacter.Stats.ShoulderMeshLeft.Value);
                    spawn.PushInt(0);
                    spawn.PushByte(4);
                }
                if (nonPlayerCharacter.Stats.BackMesh.Value != 0)
                {
                    spawn.PushByte(5);
                    spawn.PushUInt(nonPlayerCharacter.Stats.BackMesh.Value);
                    spawn.PushInt(0);
                    spawn.PushByte(4);
                }
                if (nonPlayerCharacter.Stats.HairMesh.Value != 0)
                {
                    spawn.PushByte(0);
                    spawn.PushUInt(nonPlayerCharacter.Stats.HairMesh.Value);
                    spawn.PushInt(0);
                    spawn.PushByte(2); // Hairmesh is prio 2?
                }
                /*                if (mob.Stats.GetStat(20001) != 0)
                {
                    spawn.PushByte(0);
                    spawn.PushUInt(mob.Stats.GetStat(20001));
                    spawn.PushInt(0);
                    spawn.PushByte(0); // Attractor Mesh prio = 0
                }
 */
            }

            if (nonPlayerCharacter.Weaponpairs.Count > 0)
            {
                spawn.Push3F1Count(nonPlayerCharacter.Weaponpairs.Count);
                for (counter = 0; counter < nonPlayerCharacter.Weaponpairs.Count; counter++)
                {
                    spawn.PushInt(nonPlayerCharacter.Weaponpairs[counter].value1);
                    spawn.PushInt(nonPlayerCharacter.Weaponpairs[counter].value2);
                    spawn.PushInt(nonPlayerCharacter.Weaponpairs[counter].value3);
                    spawn.PushInt(nonPlayerCharacter.Weaponpairs[counter].value4);
                }
            }
            // Finishing output with 5byte 00
            spawn.PushInt(0);
            spawn.PushByte(0);

            byte[] spawnReply = spawn.Finish();

            // setting the packetflags
            spawnReply[30] = (byte)((packetflags >> 24) & 0xff);
            spawnReply[31] = (byte)((packetflags >> 16) & 0xff);
            spawnReply[32] = (byte)((packetflags >> 8) & 0xff);
            spawnReply[33] = (byte)(packetflags & 0xff);

            if (wholePlayfield)
            {
                Announce.Playfield(nonPlayerCharacter.PlayField, spawnReply);
            }
            else
            {
                targetClient.SendCompressed(spawnReply);
            }
        }
Exemple #11
0
 /// <summary>
 /// Write inventory data into packetwriter
 /// </summary>
 /// <param name="packetWriter">packet writer</param>
 public void WriteInventoryToPacket(PacketWriter packetWriter)
 {
     lock (this.inventory)
     {
         packetWriter.Push3F1Count(this.inventory.Count);
         int count;
         for (count = 0; count < this.inventory.Count; count++)
         {
             packetWriter.PushInt(this.inventory[count].Placement);
             packetWriter.PushShort((short)this.inventory[count].Item.Flags);
             packetWriter.PushShort((short)this.inventory[count].Item.MultipleCount);
             packetWriter.PushIdentity(this.inventory[count].Item.Type, this.inventory[count].Item.Instance);
             packetWriter.PushInt(this.inventory[count].Item.LowID);
             packetWriter.PushInt(this.inventory[count].Item.HighID);
             packetWriter.PushInt(this.inventory[count].Item.Quality);
             packetWriter.PushInt(this.inventory[count].Item.Nothing);
         }
     }
 }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="character"></param>
        /// <param name="receiver"></param>
        /// <returns></returns>
        public static Byte[] WritePacket(Character character, int receiver)
        {
            /*
             * To set a packetFlag use       packetFlags |= <flagHere>;
             * To unset a packetFlag use     packetFlags &= ~<flagHere>;
             * 
             * Wherever you set a flag conditionally, be sure to unset the same flag if the reverse
             * condition is true 'just in case'.
             */
            int packetFlags = 0; // Try setting to 0x042062C8 if you have problems (old value)

            //
            // Character Variables

            bool socialonly;
            bool showsocial;
            /*
            bool showhelmet;
            bool LeftPadVisible;
            bool RightPadVisible;
            bool DoubleLeftPad;
            bool DoubleRightPad;
            */

            int charPlayfield;
            AOCoord charCoord;
            int charId;
            Quaternion charHeading;

            uint sideValue;
            uint fatValue;
            uint breedValue;
            uint sexValue;
            uint raceValue;

            int nameLength;
            string charName;
            int charFlagsValue;
            int accFlagsValue;

            int expansionValue;
            int currentNano;
            int currentHealth;

            uint strengthBaseValue;
            uint staminaBaseValue;
            uint agilityBaseValue;
            uint senseBaseValue;
            uint intelligenceBaseValue;
            uint psychicBaseValue;

            int firstNameLength;
            int lastNameLength;
            string firstName;
            string lastName;
            int orgNameLength;
            string orgName;
            int levelValue;
            int healthValue;
            int losHeight;

            int monsterData;
            int monsterScale;
            int visualFlags;

            int currentMovementMode;
            uint runSpeedBaseValue;

            int texturesCount;
            /*
            int HairMeshValue;
            int WeaponMeshRightValue;
            int WeaponMeshLeftValue;

            uint HeadMeshBaseValue;
             */
            int headMeshValue;
            /*
            int BackMeshValue;
            int ShoulderMeshRightValue;
             */
            //int ShoulderMeshLeftValue;

            /*
            int OverrideTextureHead;
            int OverrideTextureWeaponRight;
            int OverrideTextureWeaponLeft;
            int OverrideTextureShoulderpadRight;
            int OverrideTextureShoulderpadLeft;
            int OverrideTextureBack;
            int OverrideTextureAttractor;
            */
            //NPC Values

            int NPCFamily;

            Dictionary<int, int> socialTab = new Dictionary<int, int>();

            List<AOTextures> textures = new List<AOTextures>();

            List<AOMeshs> meshs;

            List<AONano> nanos = new List<AONano>();

            lock (character)
            {
                socialonly = ((character.Stats.VisualFlags.Value & 0x40) > 0);
                showsocial = ((character.Stats.VisualFlags.Value & 0x20) > 0);
                /*
                showhelmet = ((character.Stats.VisualFlags.Value & 0x4) > 0);
                LeftPadVisible = ((character.Stats.VisualFlags.Value & 0x1) > 0);
                RightPadVisible = ((character.Stats.VisualFlags.Value & 0x2) > 0);
                DoubleLeftPad = ((character.Stats.VisualFlags.Value & 0x8) > 0);
                DoubleRightPad = ((character.Stats.VisualFlags.Value & 0x10) > 0);
                */

                charPlayfield = character.PlayField;
                charCoord = character.Coordinates;
                charId = character.Id;
                charHeading = character.Heading;

                sideValue = character.Stats.Side.StatBaseValue;
                fatValue = character.Stats.Fatness.StatBaseValue;
                breedValue = character.Stats.Breed.StatBaseValue;
                sexValue = character.Stats.Sex.StatBaseValue;
                raceValue = character.Stats.Race.StatBaseValue;

                nameLength = character.Name.Length;
                charName = character.Name;
                charFlagsValue = character.Stats.Flags.Value;
                accFlagsValue = character.Stats.AccountFlags.Value;

                expansionValue = character.Stats.Expansion.Value;
                currentNano = character.Stats.CurrentNano.Value;

                strengthBaseValue = character.Stats.Strength.StatBaseValue;
                staminaBaseValue = character.Stats.Strength.StatBaseValue;
                agilityBaseValue = character.Stats.Strength.StatBaseValue;
                senseBaseValue = character.Stats.Strength.StatBaseValue;
                intelligenceBaseValue = character.Stats.Strength.StatBaseValue;
                psychicBaseValue = character.Stats.Strength.StatBaseValue;

                firstNameLength = character.FirstName.Length;
                lastNameLength = character.LastName.Length;
                firstName = character.FirstName;
                lastName = character.LastName;
                orgNameLength = character.OrgName.Length;
                orgName = character.OrgName;
                levelValue = character.Stats.Level.Value;
                healthValue = character.Stats.Life.Value;

                monsterData = character.Stats.MonsterData.Value;
                monsterScale = character.Stats.MonsterScale.Value;
                visualFlags = character.Stats.VisualFlags.Value;

                currentMovementMode = character.Stats.CurrentMovementMode.Value;
                runSpeedBaseValue = character.Stats.RunSpeed.StatBaseValue;

                texturesCount = character.Textures.Count;
                /*
                HairMeshValue = character.Stats.HairMesh.Value;
                WeaponMeshRightValue = character.Stats.WeaponMeshRight.Value;
                WeaponMeshLeftValue = character.Stats.WeaponMeshLeft.Value;

                HeadMeshBaseValue = character.Stats.HeadMesh.StatBaseValue;
                 */
                headMeshValue = character.Stats.HeadMesh.Value;
                /*
                BackMeshValue = character.Stats.BackMesh.Value;
                ShoulderMeshRightValue = character.Stats.ShoulderMeshRight.Value;
                 */
                //ShoulderMeshLeftValue = character.Stats.ShoulderMeshLeft.Value;
                /*
                OverrideTextureHead = character.Stats.OverrideTextureHead.Value;
                OverrideTextureWeaponRight = character.Stats.OverrideTextureWeaponRight.Value;
                OverrideTextureWeaponLeft = character.Stats.OverrideTextureWeaponLeft.Value;
                OverrideTextureShoulderpadRight = character.Stats.OverrideTextureShoulderpadRight.Value;
                OverrideTextureShoulderpadLeft = character.Stats.OverrideTextureShoulderpadLeft.Value;
                OverrideTextureBack = character.Stats.OverrideTextureBack.Value;
                OverrideTextureAttractor = character.Stats.OverrideTextureAttractor.Value;
                 */
                foreach (int num in character.SocialTab.Keys)
                {
                    socialTab.Add(num, character.SocialTab[num]);
                }

                foreach (AOTextures at in character.Textures)
                {
                    textures.Add(new AOTextures(at.place, at.Texture));
                }

                meshs = MeshLayers.GetMeshs(character, showsocial, socialonly);

                foreach (AONano nano in character.ActiveNanos)
                {
                    AONano tempNano = new AONano();
                    tempNano.ID = nano.ID;
                    tempNano.Instance = nano.Instance;
                    tempNano.NanoStrain = nano.NanoStrain;
                    tempNano.Nanotype = nano.Nanotype;
                    tempNano.Time1 = nano.Time1;
                    tempNano.Time2 = nano.Time2;
                    tempNano.Value3 = nano.Value3;

                    nanos.Add(tempNano);
                }

                losHeight = character.Stats.LosHeight.Value;
                NPCFamily = character.Stats.NpcFamily.Value;
                currentHealth = character.Stats.Health.Value;
            }
            PacketWriter packetWriter = new PacketWriter();

            // Packet Header
            packetWriter.PushByte(0xDF);
            packetWriter.PushByte(0xDF);
            packetWriter.PushShort(10);
            packetWriter.PushShort(1);
            packetWriter.PushShort(0); // length. writer will take care of this
            packetWriter.PushInt(3086); // sender. our server ID
            packetWriter.PushInt(receiver); // receiver
            packetWriter.PushInt(0x271B3A6B); // packet ID
            packetWriter.PushIdentity(50000, charId); // affected identity
            packetWriter.PushByte(0); // Unknown?
            // End Packet Header

            packetWriter.PushByte(57); // SCFU packet version (57/0x39)
            packetWriter.PushInt(0); // packet flags (this is set later based on packetFlags variable above)

            packetFlags |= 0x40; // Has Playfield ID
            packetWriter.PushInt(charPlayfield); // playfield

            if (character.FightingTarget.Instance != 0)
            {
                packetFlags |= 20;
                packetWriter.PushIdentity(character.FightingTarget);
            }

            // Coordinates
            packetWriter.PushCoord(charCoord);

            // Heading Data
            packetFlags |= 0x200; // Has Heading Data Flag
            packetWriter.PushQuat(charHeading);

            uint appearance = sideValue + (fatValue * 8) + (breedValue * 32) + (sexValue * 256) + (raceValue * 1024);
            // Race
            packetWriter.PushUInt(appearance); // appearance

            // Name
            packetWriter.PushByte((byte)(nameLength + 1));
            packetWriter.PushBytes(Encoding.ASCII.GetBytes(charName));
            packetWriter.PushByte(0); // 0 terminator for name

            packetWriter.PushUInt(charFlagsValue); // Flags
            packetWriter.PushShort((short)accFlagsValue);
            packetWriter.PushShort((short)expansionValue);

            if (character is NonPlayerCharacterClass)
            {
                packetFlags |= 1;
            }

            packetFlags &= ~0x01; // We are a player
            if ((packetFlags & 0x01) != 0)
            {
                // Are we a NPC (i think anyway)? So far this is _NOT_ used at all

                if (NPCFamily < 256)
                {
                    packetWriter.PushByte((byte)NPCFamily);
                }
                else
                {
                    packetFlags |= 0x20000;
                    packetWriter.PushShort((Int16)NPCFamily);
                }

                if (losHeight < 256)
                {
                    packetWriter.PushByte((byte)losHeight);
                }
                else
                {
                    packetFlags |= 0x80000;
                    packetWriter.PushShort((Int16)losHeight);
                }

                //if (packetFlags & 0x2000000)
                //{
                //    char PetType;
                //}
                //else
                //{
                //    short PetType;
                //}

                //short TowerType;

                //if (TowerType > 0)
                //{
                //    char unknown;
                //}
            }
            else
            {
                // Are we a player?
                packetWriter.PushUInt(currentNano); // CurrentNano
                packetWriter.PushInt(0); // team?
                packetWriter.PushShort(5); // swim?

                // The checks here are to prevent the client doing weird things if the character has really large or small base attributes
                if (strengthBaseValue > 32767) // Strength
                {
                    packetWriter.PushShort(32767);
                }
                else
                {
                    packetWriter.PushShort((short)strengthBaseValue);
                }
                if (agilityBaseValue > 32767) // Agility
                {
                    packetWriter.PushShort(32767);
                }
                else
                {
                    packetWriter.PushShort((short)agilityBaseValue);
                }
                if (staminaBaseValue > 32767) //  Stamina
                {
                    packetWriter.PushShort(32767);
                }
                else
                {
                    packetWriter.PushShort((short)staminaBaseValue);
                }
                if (intelligenceBaseValue > 32767) // Intelligence
                {
                    packetWriter.PushShort(32767);
                }
                else
                {
                    packetWriter.PushShort((short)intelligenceBaseValue);
                }
                if (senseBaseValue > 32767) // Sense
                {
                    packetWriter.PushShort(32767);
                }
                else
                {
                    packetWriter.PushShort((short)senseBaseValue);
                }
                if (psychicBaseValue > 32767) // Psychic
                {
                    packetWriter.PushShort(32767);
                }
                else
                {
                    packetWriter.PushShort((short)psychicBaseValue);
                }

                if ((charFlagsValue & 0x400000) != 0) // has visible names? (Flags)
                {
                    packetWriter.PushShort((short)firstNameLength);
                    packetWriter.PushBytes(Encoding.ASCII.GetBytes(firstName));
                    packetWriter.PushShort((short)lastNameLength);
                    packetWriter.PushBytes(Encoding.ASCII.GetBytes(lastName));
                }

                if (orgNameLength != 0)
                {
                    packetFlags |= 0x4000000; // Has org name data

                    packetWriter.PushShort((short)orgNameLength);
                    packetWriter.PushBytes(Encoding.ASCII.GetBytes(orgName));
                }
                else
                {
                    packetFlags &= ~0x4000000; // Does not have org name data
                }
            }

            if (levelValue > 127) // Level
            {
                packetFlags |= 0x1000; // Has Extended Level
                packetWriter.PushShort((short)levelValue);
            }
            else
            {
                packetFlags &= ~0x1000; // Has Small Level
                packetWriter.PushByte((byte)levelValue);
            }

            if (healthValue > 32767) // Health
            {
                packetFlags &= ~0x800; // Has Extended Health
                packetWriter.PushUInt(healthValue);
            }
            else
            {
                packetFlags |= 0x800; // Has Small Health
                packetWriter.PushShort((short)healthValue);
            }
            int healthdamage = healthValue - currentHealth;
            if (healthdamage < 256)
            {
                packetFlags |= 0x4000;
                packetWriter.PushByte((byte)healthdamage);
            }
            else
            {
                packetFlags &= ~0x4000;
                if ((packetFlags & 0x800) == 0x800)
                {
                    packetWriter.PushShort((Int16)healthdamage);
                }
                else
                {
                    packetWriter.PushInt(healthdamage);
                }
            }

            // If player is in grid or fixer grid
            // make him/her/it a nice upside down pyramid
            if ((charPlayfield == 152) || (charPlayfield == 4107))
            {
                packetWriter.PushInt(99902);
            }
            else
            {
                packetWriter.PushUInt(monsterData); // Monsterdata
            }
            packetWriter.PushShort((short)monsterScale); // Monsterscale
            packetWriter.PushShort((short)visualFlags); // VisualFlags
            packetWriter.PushByte(0); // visible title?

            packetWriter.PushInt(42); // 'skipdata' length
            // Start 'skipdata'
            packetWriter.PushBytes(
                new Byte[] { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00 });
            packetWriter.PushByte((byte)currentMovementMode); // CurrentMovementMode
            packetWriter.PushByte(1); // don't change
            packetWriter.PushShort(1); // ?
            packetWriter.PushShort(1); // ?
            packetWriter.PushShort(1); // ?
            packetWriter.PushShort(1); // ?
            packetWriter.PushShort(0); // ?
            packetWriter.PushShort(3); // ?
            packetWriter.PushInt(0); //?
            packetWriter.PushInt(0); //?
            packetWriter.PushInt(0); //?
            packetWriter.PushInt(0); //?
            // End 'skipdata'

            if (headMeshValue != 0)
            {
                packetFlags |= 0x80; // Has HeadMesh Flag
                packetWriter.PushUInt(headMeshValue); // Headmesh
            }

            if ((runSpeedBaseValue > 127)) // Runspeed
            {
                packetFlags |= 0x2000;
                packetWriter.PushShort((short)runSpeedBaseValue);
            }
            else
            {
                packetFlags &= ~0x2000;
                packetWriter.PushByte((byte)runSpeedBaseValue);
            }

            //if (packetFlags & 0x400)
            //{
            //    // Pop2Long
            //    /*
            //     * Is this a Type:Instance pair?
            //     * Suspect so as it uses Pop2Long
            //     * which is used for Type:Instance
            //     * pairs. Perhaps pet master?
            //     * (Just a wild guess though that its pet master)
            //     */
            //    long unknown;
            //    long unknown;
            //}

            //if (packetFlags & 0x10)
            //{
            //    long counter;
            //    repeat (counter / 0x3F1 - 1) times
            //        char texturepositionname[32]; // Null padded at the end
            //        long textureid; // Or is this mesh id?
            //        long unknown;
            //        long unknown;
            //    end repeat
            //}

            // Is char/NPC in hide mode?
            //if (packetFlags & 0x100000)
            //{
            //    short Concealment;
            //}

            //if (packetFlags & 0x800000)
            //{
            //    char unknown;
            //}

            //if (packetFlags & 0x1000000)
            //{
            //    char unknown;
            //}

            packetWriter.Push3F1Count(nanos.Count); // running nanos count
            foreach (AONano nano in nanos)
            {
                packetWriter.PushInt(nano.ID);
                packetWriter.PushInt(nano.Instance);
                packetWriter.PushInt(nano.Time1);
                packetWriter.PushInt(nano.Time2);
            }
            // longx5: aoid, instance, unknown(0?), timer1, timer2

            //if (flags & 0x10000)
            //{
            //    // Waypoint Info
            //    // Pop2Long (1010E2D3)
            //    long type;
            //    long instance;
            //    // Waypoint Counter - 3x float per entry
            //    long counter;
            //    repeat counter times
            //        float x;
            //        float y;
            //        float z;
            //    end repeat
            //    // End Waypoint Counter
            //}

            // Texture/Cloth Data
            int c;
            packetWriter.Push3F1Count(5); // textures count

            AOTextures aotemp = new AOTextures(0, 0);
            for (c = 0; c < 5; c++)
            {
                aotemp.Texture = 0;
                aotemp.place = c;
                int c2;
                for (c2 = 0; c2 < texturesCount; c2++)
                {
                    if (textures[c2].place == c)
                    {
                        aotemp.Texture = textures[c2].Texture;
                        break;
                    }
                }
                if (showsocial)
                {
                    if (socialonly)
                    {
                        aotemp.Texture = socialTab[c];
                    }
                    else
                    {
                        if (socialTab[c] != 0)
                        {
                            aotemp.Texture = socialTab[c];
                        }
                    }
                }

                packetWriter.PushInt(aotemp.place);
                packetWriter.PushInt(aotemp.Texture);
                packetWriter.PushInt(0);
            }
            // End Textures

            // ############
            // # Meshs
            // ############

            c = meshs.Count;

            packetWriter.Push3F1Count(c);
            foreach (AOMeshs aoMeshs in meshs)
            {
                packetWriter.PushByte((byte)aoMeshs.Position);
                packetWriter.PushUInt(aoMeshs.Mesh);
                packetWriter.PushInt(aoMeshs.OverrideTexture); // Override Texture!!!!!!
                packetWriter.PushByte((byte)aoMeshs.Layer);
            }
            // End Meshs

            //if (packetFlags & 0x100)
            //{
            //    // 0x3F1 Unknown Counter - 4x long per entry
            //    long counter;
            //    repeat (counter / 0x3F1 - 1) times
            //        long unknown;
            //        long unknown;
            //        long unknown;
            //        long unknown;
            //    end repeat
            //}

            //if (packetFlags & 0x20000000)
            //{
            //    char ShadowBreed;
            //}

            //if (packetFlags & 0x40000000)
            //{
            //    // 0x3F1 Unknown Counter - 4x long per entry
            //    long counter;
            //    repeat (counter / 0x3F1 - 1) times
            //        Pop2Long (Type:Instance pair maybe?)
            //        long unknown;
            //        long unknown;
            //    end repeat
            //}

            packetWriter.PushInt(0); // packetFlags2

            // Some mech stuff
            //if (packetFlags2 & 0x01)
            //{
            //    long counter;
            //    repeat (counter) times
            //        long unknown;
            //        long unknown;
            //    end repeat

            //    long MechData;
            //    // Pop2Long (Type:Instance pair maybe?)
            //    long unknown;
            //    long unknown;
            //}

            // maybe check if we are in battlestation
            //if (packetFlags2 & 0x02)
            //{
            //    char BattleStationSide;
            //}

            // Are we a pet?
            //if (packetFlags2 & 0x04)
            //{
            //    long PetMaster;
            //}

            packetWriter.PushByte(0);

            Byte[] reply = packetWriter.Finish();

            // Set Packet Flags
            Byte[] packetFlagBytes;
            packetFlagBytes = BitConverter.GetBytes(packetFlags);
            Array.Reverse(packetFlagBytes);
            reply[30] = packetFlagBytes[0];
            reply[31] = packetFlagBytes[1];
            reply[32] = packetFlagBytes[2];
            reply[33] = packetFlagBytes[3];

            return reply;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="client"></param>
        public static void Send(Client client)
        {
            PacketWriter writer = new PacketWriter();

            #region Header
            writer.PushBytes(new byte[] { 0xDF, 0xDF });
            writer.PushShort(10);
            writer.PushShort(1);
            writer.PushShort(0);
            writer.PushInt(3086);
            writer.PushInt(client.Character.Id);
            writer.PushInt(0x29304349);
            writer.PushIdentity(50000, client.Character.Id);
            writer.PushByte(0);
            #endregion

            writer.PushInt(25);

            #region Data01 (Inventory)
            /* part 1 of data */
            int count;
            writer.Push3F1Count(client.Character.Inventory.Count);
            for (count = 0; count < client.Character.Inventory.Count; count++)
            {
                writer.PushInt(client.Character.Inventory[count].Placement);
                writer.PushShort((short)client.Character.Inventory[count].Item.Flags);
                writer.PushShort((short)client.Character.Inventory[count].Item.MultipleCount);
                writer.PushIdentity(
                    client.Character.Inventory[count].Item.Type, client.Character.Inventory[count].Item.Instance);
                writer.PushInt(client.Character.Inventory[count].Item.LowID);
                writer.PushInt(client.Character.Inventory[count].Item.HighID);
                writer.PushInt(client.Character.Inventory[count].Item.Quality);
                writer.PushInt(client.Character.Inventory[count].Item.Nothing);
            }
            #endregion

            #region Data02 (Uploaded nanos)
            /* part 2 of data */
            /* number of entries */
            writer.Push3F1Count(client.Character.UploadedNanos.Count);
            foreach (AOUploadedNanos au in client.Character.UploadedNanos)
            {
                writer.PushInt(au.Nano);
            }
            #endregion

            #region Data03 (Empty)
            /* part 3 of data */
            /* number of entries */
            writer.Push3F1Count(0);
            #endregion

            #region Unknown
            /* No idea what these are */
            /* used to be skill locks + some unknown data */
            // TODO: Find out what following 6 ints are
            writer.PushInt(1);
            writer.PushInt(0);
            writer.PushInt(1);
            writer.PushInt(0);
            writer.PushInt(1);
            writer.PushInt(0);
            #endregion

            #region Data06 (Stats 1) (32bit - 32bit)
            /* part 6 of data (1-st stats block) */

            /* Int32 stat number
               Int32 stat value */

            /* number of entries */
            writer.Push3F1Count(69);

            /* State */
            WriteStat3232(client, writer, 7);

            /* UnarmedTemplateInstance */
            WriteStat3232(client, writer, 418);

            /* Invaders Killed */
            WriteStat3232(client, writer, 615);

            /* KilledByInvaders */
            WriteStat3232(client, writer, 616);

            /* AccountFlags */
            WriteStat3232(client, writer, 660);

            /* VP */
            WriteStat3232(client, writer, 669);

            /* UnsavedXP */
            WriteStat3232(client, writer, 592);

            /* NanoFocusLevel */
            WriteStat3232(client, writer, 355);

            /* Specialization */
            WriteStat3232(client, writer, 182);

            /* ShadowBreedTemplate */
            WriteStat3232(client, writer, 579);

            /* ShadowBreed */
            WriteStat3232(client, writer, 532);

            /* LastPerkResetTime */
            WriteStat3232(client, writer, 577);

            /* SocialStatus */
            WriteStat3232(client, writer, 521);

            /* PlayerOptions */
            WriteStat3232(client, writer, 576);

            /* TempSaveTeamID */
            WriteStat3232(client, writer, 594);

            /* TempSavePlayfield */
            WriteStat3232(client, writer, 595);

            /* TempSaveX */
            WriteStat3232(client, writer, 596);

            /* TempSaveY */
            WriteStat3232(client, writer, 597);

            /* VisualFlags */
            WriteStat3232(client, writer, 673);

            /* PvPDuelKills */
            WriteStat3232(client, writer, 674);

            /* PvPDuelDeaths */
            WriteStat3232(client, writer, 675);

            /* PvPProfessionDuelKills */
            WriteStat3232(client, writer, 676);

            /* PvPProfessionDuelDeaths */
            WriteStat3232(client, writer, 677);

            /* PvPRankedSoloKills */
            WriteStat3232(client, writer, 678);

            /* PvPRankedSoloDeaths */
            WriteStat3232(client, writer, 679);

            /* PvPRankedTeamKills */
            WriteStat3232(client, writer, 680);

            /* PvPRankedTeamDeaths */
            WriteStat3232(client, writer, 681);

            /* PvPSoloScore */
            WriteStat3232(client, writer, 682);

            /* PvPTeamScore */
            WriteStat3232(client, writer, 683);

            /* PvPDuelScore */
            WriteStat3232(client, writer, 684);

            WriteStat3232(client, writer, 0x289);
            WriteStat3232(client, writer, 0x28a);

            /* SavedXP */
            WriteStat3232(client, writer, 334);

            /* Flags */
            WriteStat3232(client, writer, 0);

            /* Features */
            WriteStat3232(client, writer, 224);

            /* ApartmentsAllowed */
            WriteStat3232(client, writer, 582);

            /* ApartmentsOwned */
            WriteStat3232(client, writer, 583);

            /* MonsterScale */
            WriteStat3232(client, writer, 360);

            /* VisualProfession */
            WriteStat3232(client, writer, 368);

            /* NanoAC */
            WriteStat3232(client, writer, 168);

            WriteStat3232(client, writer, 214);
            WriteStat3232(client, writer, 221);
            /* LastConcretePlayfieldInstance */
            WriteStat3232(client, writer, 191);

            /* MapOptions */
            WriteStat3232(client, writer, 470);

            /* MapAreaPart1 */
            WriteStat3232(client, writer, 471);

            /* MapAreaPart2 */
            WriteStat3232(client, writer, 472);

            /* MapAreaPart3 */
            WriteStat3232(client, writer, 585);

            /* MapAreaPart4 */
            WriteStat3232(client, writer, 586);

            /* MissionBits1 */
            WriteStat3232(client, writer, 256);

            /* MissionBits2 */
            WriteStat3232(client, writer, 257);

            /* MissionBits3 */
            WriteStat3232(client, writer, 303);

            /* MissionBits4 */
            WriteStat3232(client, writer, 432);

            /* MissionBits5 */
            WriteStat3232(client, writer, 65);

            /* MissionBits6 */
            WriteStat3232(client, writer, 66);

            /* MissionBits7 */
            WriteStat3232(client, writer, 67);

            /* MissionBits8 */
            WriteStat3232(client, writer, 544);

            /* MissionBits9 */
            WriteStat3232(client, writer, 545);

            /* MissionBits10 */
            WriteStat3232(client, writer, 617);
            WriteStat3232(client, writer, 618);
            WriteStat3232(client, writer, 619);
            WriteStat3232(client, writer, 198);

            /* AutoAttackFlags */
            WriteStat3232(client, writer, 349);

            /* PersonalResearchLevel */
            WriteStat3232(client, writer, 263);

            /* GlobalResearchLevel */
            WriteStat3232(client, writer, 264);

            /* PersonalResearchGoal */
            WriteStat3232(client, writer, 265);

            /* GlobalResearchGoal */
            WriteStat3232(client, writer, 266);

            /* BattlestationSide */
            WriteStat3232(client, writer, 668);

            /* BattlestationRep */
            WriteStat3232(client, writer, 670);

            /* Members */
            WriteStat3232(client, writer, 300);
            #endregion

            #region Data07 (Stats 2) (32bit - 32bit)
            /* number of entries */
            writer.Push3F1Count(144);

            /* Int32 stat number
               Int32 stat value */

            /* VeteranPoints */
            WriteStat3232(client, writer, 68);

            /* MonthsPaid */
            WriteStat3232(client, writer, 69);

            /* PaidPoints */
            WriteStat3232(client, writer, 672);

            /* AutoAttackFlags */
            WriteStat3232(client, writer, 349);

            /* XPKillRange */
            WriteStat3232(client, writer, 275);

            /* InPlay */
            WriteStat3232(client, writer, 194);

            /* Health (current health)*/
            WriteStat3232(client, writer, 27);

            /* Life (max health)*/
            WriteStat3232(client, writer, 1);

            /* Psychic */
            WriteStat3232(client, writer, 21);

            /* Sense */
            WriteStat3232(client, writer, 20);

            /* Intelligence */
            WriteStat3232(client, writer, 19);

            /* Stamina */
            WriteStat3232(client, writer, 18);

            /* Agility */
            WriteStat3232(client, writer, 17);

            /* Strength */
            WriteStat3232(client, writer, 16);

            /* Attitude */
            WriteStat3232(client, writer, 63);

            /* Alignment (Clan Tokens) */
            WriteStat3232(client, writer, 62);

            /* Cash */
            WriteStat3232(client, writer, 61);

            /* Profession */
            WriteStat3232(client, writer, 60);

            /* AggDef */
            WriteStat3232(client, writer, 51);

            /* Icon */
            WriteStat3232(client, writer, 79);

            /* Mesh */
            WriteStat3232(client, writer, 12);

            /* RunSpeed */
            WriteStat3232(client, writer, 156);

            /* DeadTimer */
            WriteStat3232(client, writer, 34);

            /* Team */
            WriteStat3232(client, writer, 6);

            /* Breed */
            WriteStat3232(client, writer, 4);

            /* Sex */
            WriteStat3232(client, writer, 59);

            /* LastSaveXP */
            WriteStat3232(client, writer, 372);

            /* NextXP */
            WriteStat3232(client, writer, 350);

            /* LastXP */
            WriteStat3232(client, writer, 57);

            /* Level */
            WriteStat3232(client, writer, 54);

            /* XP */
            WriteStat3232(client, writer, 52);

            /* IP */
            WriteStat3232(client, writer, 53);

            /* CurrentMass */
            WriteStat3232(client, writer, 78);

            /* ItemType */
            WriteStat3232(client, writer, 72);

            /* PreviousHealth */
            WriteStat3232(client, writer, 11);

            /* CurrentState */
            WriteStat3232(client, writer, 423);

            /* Age */
            WriteStat3232(client, writer, 58);

            /* Side */
            WriteStat3232(client, writer, 33);

            /* WaitState */
            WriteStat3232(client, writer, 430);

            /* DriveWater */
            WriteStat3232(client, writer, 117);

            /* MeleeMultiple */
            WriteStat3232(client, writer, 101);

            /* LR_MultipleWeapon */
            WriteStat3232(client, writer, 134);

            /* LR_EnergyWeapon */
            WriteStat3232(client, writer, 133);

            /* RadiationAC */
            WriteStat3232(client, writer, 94);

            /* SenseImprovement */
            WriteStat3232(client, writer, 122);

            /* BowSpecialAttack */
            WriteStat3232(client, writer, 121);

            /* Burst */
            WriteStat3232(client, writer, 148);

            /* FullAuto */
            WriteStat3232(client, writer, 167);

            /* MapNavigation */
            WriteStat3232(client, writer, 140);

            /* DriveAir */
            WriteStat3232(client, writer, 139);

            /* DriveGround */
            WriteStat3232(client, writer, 166);

            /* BreakingEntry */
            WriteStat3232(client, writer, 165);

            /* Concealment */
            WriteStat3232(client, writer, 164);

            /* Chemistry */
            WriteStat3232(client, writer, 163);

            /* Psychology */
            WriteStat3232(client, writer, 162);

            /* ComputerLiteracy */
            WriteStat3232(client, writer, 161);

            /* NanoProgramming */
            WriteStat3232(client, writer, 160);

            /* Pharmaceuticals */
            WriteStat3232(client, writer, 159);

            /* WeaponSmithing */
            WriteStat3232(client, writer, 158);

            /* FieldQuantumPhysics */
            WriteStat3232(client, writer, 157);

            /* AttackSpeed */
            WriteStat3232(client, writer, 3);

            /* Evade */
            WriteStat3232(client, writer, 155);

            /* Dodge */
            WriteStat3232(client, writer, 154);

            /* Duck */
            WriteStat3232(client, writer, 153);

            /* BodyDevelopment */
            WriteStat3232(client, writer, 152);

            /* AimedShot */
            WriteStat3232(client, writer, 151);

            /* FlingShot */
            WriteStat3232(client, writer, 150);

            /* NanoProwessInitiative */
            WriteStat3232(client, writer, 149);

            /* FastAttack */
            WriteStat3232(client, writer, 147);

            /* SneakAttack */
            WriteStat3232(client, writer, 146);

            /* Parry */
            WriteStat3232(client, writer, 145);

            /* Dimach */
            WriteStat3232(client, writer, 144);

            /* Riposte */
            WriteStat3232(client, writer, 143);

            /* Brawl */
            WriteStat3232(client, writer, 142);

            /* Tutoring */
            WriteStat3232(client, writer, 141);

            /* Swim */
            WriteStat3232(client, writer, 138);

            /* Adventuring */
            WriteStat3232(client, writer, 137);

            /* Perception */
            WriteStat3232(client, writer, 136);

            /* DisarmTraps */
            WriteStat3232(client, writer, 135);

            /* NanoEnergyPool */
            WriteStat3232(client, writer, 132);

            /* MaterialLocation */
            WriteStat3232(client, writer, 131);

            /* MaterialCreation */
            WriteStat3232(client, writer, 130);

            /* PsychologicalModification */
            WriteStat3232(client, writer, 129);

            /* BiologicalMetamorphose */
            WriteStat3232(client, writer, 128);

            /* MaterialMetamorphose */
            WriteStat3232(client, writer, 127);

            /* ElectricalEngineering */
            WriteStat3232(client, writer, 126);

            /* MechanicalEngineering */
            WriteStat3232(client, writer, 125);

            /* Treatment */
            WriteStat3232(client, writer, 124);

            /* FirstAid */
            WriteStat3232(client, writer, 123);

            /* PhysicalProwessInitiative */
            WriteStat3232(client, writer, 120);

            /* DistanceWeaponInitiative */
            WriteStat3232(client, writer, 119);

            /* CloseCombatInitiative */
            WriteStat3232(client, writer, 118);

            /* AssaultRifle */
            WriteStat3232(client, writer, 116);

            /* Shotgun */
            WriteStat3232(client, writer, 115);

            /* SubMachineGun */
            WriteStat3232(client, writer, 114);

            /* Rifle */
            WriteStat3232(client, writer, 113);

            /* Pistol */
            WriteStat3232(client, writer, 112);

            /* Bow */
            WriteStat3232(client, writer, 111);

            /* ThrownGrapplingWeapons */
            WriteStat3232(client, writer, 110);

            /* Grenade */
            WriteStat3232(client, writer, 109);

            /* ThrowingKnife */
            WriteStat3232(client, writer, 108);

            /* 2HBluntWeapons */
            WriteStat3232(client, writer, 107);

            /* Piercing */
            WriteStat3232(client, writer, 106);

            /* 2HEdgedWeapons */
            WriteStat3232(client, writer, 105);

            /* MeleeEnergyWeapon */
            WriteStat3232(client, writer, 104);

            /* 1HEdgedWeapons */
            WriteStat3232(client, writer, 103);

            /* 1HBluntWeapons */
            WriteStat3232(client, writer, 102);

            /* MartialArts */
            WriteStat3232(client, writer, 100);

            /* Alignment (Clan Tokens) */
            WriteStat3232(client, writer, 62);

            /* MetaType (Omni Tokens) */
            WriteStat3232(client, writer, 75);

            /* TitleLevel */
            WriteStat3232(client, writer, 37);

            /* GmLevel */
            WriteStat3232(client, writer, 215);

            /* FireAC */
            WriteStat3232(client, writer, 97);

            /* PoisonAC */
            WriteStat3232(client, writer, 96);

            /* ColdAC */
            WriteStat3232(client, writer, 95);

            /* RadiationAC */
            WriteStat3232(client, writer, 94);

            /* ChemicalAC */
            WriteStat3232(client, writer, 93);

            /* EnergyAC */
            WriteStat3232(client, writer, 92);

            /* MeleeAC */
            WriteStat3232(client, writer, 91);

            /* ProjectileAC */
            WriteStat3232(client, writer, 90);

            /* RP */
            WriteStat3232(client, writer, 199);

            /* SpecialCondition */
            WriteStat3232(client, writer, 348);

            /* SK */
            WriteStat3232(client, writer, 573);

            /* Expansions */
            WriteStat3232(client, writer, 389);

            /* ClanRedeemed */
            WriteStat3232(client, writer, 572);

            /* ClanConserver */
            WriteStat3232(client, writer, 571);

            /* ClanDevoted */
            WriteStat3232(client, writer, 570);

            /* OTUnredeemed */
            WriteStat3232(client, writer, 569);

            /* OTOperator */
            WriteStat3232(client, writer, 568);

            /* OTFollowers */
            WriteStat3232(client, writer, 567);

            /* GOS */
            WriteStat3232(client, writer, 566);

            /* ClanVanguards */
            WriteStat3232(client, writer, 565);

            /* OTTrans */
            WriteStat3232(client, writer, 564);

            /* ClanGaia */
            WriteStat3232(client, writer, 563);

            /* OTMed*/
            WriteStat3232(client, writer, 562);

            /* ClanSentinels */
            WriteStat3232(client, writer, 561);

            /* OTArmedForces */
            WriteStat3232(client, writer, 560);

            /* SocialStatus */
            WriteStat3232(client, writer, 521);

            /* PlayerID */
            WriteStat3232(client, writer, 607);

            /* KilledByInvaders */
            WriteStat3232(client, writer, 616);

            /* InvadersKilled */
            WriteStat3232(client, writer, 615);

            /* AlienLevel */
            WriteStat3232(client, writer, 169);

            /* AlienNextXP */
            WriteStat3232(client, writer, 178);

            /* AlienXP */
            WriteStat3232(client, writer, 40);
            #endregion

            #region Data08 (Stats 3) (8bit - 8bit)
            /* number of entries */
            writer.Push3F1Count(8);

            /* Byte stat number
               Byte stat value */

            /* InsurancePercentage */
            WriteStat88(client, writer, 236);

            /* ProfessionLevel */
            WriteStat88(client, writer, 10);

            /* PrevMovementMode */
            WriteStat88(client, writer, 174);

            /* CurrentMovementMode */
            WriteStat88(client, writer, 173);

            /* Fatness */
            WriteStat88(client, writer, 47);

            /* Race */
            WriteStat88(client, writer, 89);

            /* TeamSide */
            WriteStat88(client, writer, 213);

            /* BeltSlots */
            WriteStat88(client, writer, 45);
            #endregion

            #region Data09 (Stats 4) (8bit - 16bit)
            /* number of stats */
            writer.Push3F1Count(16);

            /* Byte stat number
               Int16 (short) stat value */

            /* AbsorbProjectileAC */
            WriteStat816(client, writer, 238);

            /* AbsorbMeleeAC */
            WriteStat816(client, writer, 239);

            /* AbsorbEnergyAC */
            WriteStat816(client, writer, 240);

            /* AbsorbChemicalAC */
            WriteStat816(client, writer, 241);

            /* AbsorbRadiationAC */
            WriteStat816(client, writer, 242);

            /* AbsorbColdAC */
            WriteStat816(client, writer, 243);

            /* AbsorbNanoAC */
            WriteStat816(client, writer, 246);

            /* AbsorbFireAC */
            WriteStat816(client, writer, 244);

            /* AbsorbPoisonAC */
            WriteStat816(client, writer, 245);

            /* TemporarySkillReduction */
            WriteStat816(client, writer, 247);

            /* InsuranceTime */
            WriteStat816(client, writer, 49);

            /* CurrentNano */
            WriteStat816(client, writer, 214);

            /* MaxNanoEnergy */
            WriteStat816(client, writer, 221);

            /* MaxNCU */
            WriteStat816(client, writer, 181);

            /* MapFlags */
            WriteStat816(client, writer, 9);

            /* ChangeSideCount */
            WriteStat816(client, writer, 237);
            #endregion

            /* ? */
            writer.PushInt(0);
            /* ? */
            writer.PushInt(0);

            #region Data10 (Empty)
            /* number of entries */
            writer.Push3F1Count(0);
            #endregion

            #region Data11 (Empty)
            /* number of entries */
            writer.Push3F1Count(0);
            #endregion

            #region Data12 (Empty)
            /* number of entries */
            writer.Push3F1Count(0);
            #endregion

            byte[] reply = writer.Finish();
            client.SendCompressed(reply);
        }