コード例 #1
0
ファイル: Character.cs プロジェクト: Invertika/server
        //        /** Sets the value of a base attribute of the character. */
        //        void setAttribute(unsigned int id, double value)
        //        { mAttributes[id].base = value; }
        //        
        //        void setModAttribute(unsigned int id, double value)
        //        { mAttributes[id].modified = value; }
        public void deserializeCharacterData(MessageIn msg)
        {
            // general character properties
            setAccountLevel(msg.readInt8());
            setGender((BeingGender)msg.readInt8());
            setHairStyle(msg.readInt8());
            setHairColor(msg.readInt8());
            setLevel(msg.readInt16());
            setCharacterPoints(msg.readInt16());
            setCorrectionPoints(msg.readInt16());

            // character attributes
            uint attrSize=(uint)msg.readInt16();
            for(uint i = 0;i < attrSize;++i)
            {
                uint id=(uint)msg.readInt16();
                double @base=msg.readDouble(),
                mod=msg.readDouble();
                setAttribute(id,  @base);
                setModAttribute(id, mod);
            }

            // character skills
            int skillSize=msg.readInt16();

            for(int i = 0;i < skillSize;++i)
            {
                int skill=msg.readInt16();
                int level=msg.readInt32();
                setExperience(skill, level);
            }

            // status effects currently affecting the character
            int statusSize=msg.readInt16();

            for(int i = 0;i < statusSize;i++)
            {
                int status=msg.readInt16();
                int time=msg.readInt16();
                applyStatusEffect(status, time);
            }

            // location
            setMapId(msg.readInt16());

            Point temporaryPoint=new Point();
            temporaryPoint.x=msg.readInt16();
            temporaryPoint.y=msg.readInt16();
            setPosition(temporaryPoint);

            // kill count
            int killSize=msg.readInt16();
            for(int i = 0;i < killSize;i++)
            {
                int monsterId=msg.readInt16();
                int kills=msg.readInt32();
                setKillCount(monsterId, kills);
            }

            // character specials
            int specialSize=msg.readInt16();
            clearSpecials();
            for(int i = 0;i < specialSize;i++)
            {
                giveSpecial(msg.readInt32());
            }

            Possessions poss=getPossessions();
            Dictionary< uint, EquipmentItem > equipData=new Dictionary<uint, EquipmentItem>();
            int equipSlotsSize=msg.readInt16();
            uint eqSlot;
            EquipmentItem equipItem=new EquipmentItem();
            for(int j = 0;j < equipSlotsSize;++j)
            {
                eqSlot=(uint)msg.readInt16();
                equipItem.itemId=(uint)msg.readInt16();
                equipItem.itemInstance=(uint)msg.readInt16();
                equipData.Add(eqSlot, equipItem);
            }
            poss.setEquipment(equipData);

            // Loads inventory - must be last because size isn't transmitted
            Dictionary<uint, InventoryItem > inventoryData=new Dictionary<uint, InventoryItem>();
            while(msg.getUnreadLength()>0)
            {
                InventoryItem i=new InventoryItem();
                int slotId=msg.readInt16();
                i.itemId=(uint)msg.readInt16();
                i.amount=(uint)msg.readInt16();
                inventoryData.Add((uint)slotId, i);
            }

            poss.setInventory(inventoryData);
        }
コード例 #2
0
ファイル: Storage.cs プロジェクト: Invertika/server
        Character getCharacterBySQL(ISL.Server.Account.Account owner)
        {
            Character character=null;

            string sql=String.Format("SELECT * FROM {0} WHERE user_id = {1}", CHARACTERS_TBL_NAME, owner.getID());
            DataTable charInfo=mDb.ExecuteQuery(sql);

            // If the character is not even in the database then
            // we have no choice but to return nothing.
            if(charInfo.Rows.Count==0)
                return null;

            character=new Character(charInfo.Rows[0]["name"].ToString(), Convert.ToInt32(charInfo.Rows[0]["id"]));
            character.setGender(Convert.ToInt32(charInfo.Rows[0]["gender"]));
            character.setHairStyle(Convert.ToInt32(charInfo.Rows[0]["hair_style"]));
            character.setHairColor(Convert.ToInt32(charInfo.Rows[0]["hair_color"]));
            character.setLevel(Convert.ToInt32(charInfo.Rows[0]["level"]));
            character.setCharacterPoints(Convert.ToInt32(charInfo.Rows[0]["char_pts"]));
            character.setCorrectionPoints(Convert.ToInt32(charInfo.Rows[0]["correct_pts"]));

            Point pos=new Point(Convert.ToInt32(charInfo.Rows[0]["x"]), Convert.ToInt32(charInfo.Rows[0]["y"]));
            character.setPosition(pos);

            int mapId=Convert.ToInt32(charInfo.Rows[0]["map_id"]);
            if(mapId>0)
            {
                character.setMapId(mapId);
            }
            else
            {
                // Set character to default map and one of the default location
                // Default map is to be 1, as not found return value will be 0.
                character.setMapId(Configuration.getValue("char_defaultMap", 1));
            }

            character.setCharacterSlot(Convert.ToUInt32(charInfo.Rows[0]["slot"]));

            // Fill the account-related fields. Last step, as it may require a new
            // SQL query.
            if(owner!=null)
            {
                character.setAccount(owner);
            }
            else
            {
                int id=Convert.ToInt32(charInfo.Rows[0]["user_id"]);
                character.setAccountID(id);

                string s=String.Format("SELECT level FROM {0} WHERE id = '{1}';", ACCOUNTS_TBL_NAME, id);
                DataTable levelInfo=mDb.ExecuteQuery(s);

                character.setAccountLevel(Convert.ToInt32(levelInfo.Rows[0]["level"]), true);
            }

            // Load attributes."
            string s2=String.Format("SELECT attr_id, attr_base, attr_mod FROM {0} WHERE char_id = {1};", CHAR_ATTR_TBL_NAME, character.getDatabaseID());
            DataTable attrInfo=mDb.ExecuteQuery(s2);

            if(attrInfo.Rows.Count>0)
            {
                uint nRows=(uint)attrInfo.Rows.Count;

                for(uint row = 0;row < nRows;++row)
                {
                    uint id=Convert.ToUInt32(charInfo.Rows[0]["attr_id"]);
                    character.setAttribute(id, Convert.ToDouble(charInfo.Rows[0]["attr_base"]));
                    character.setModAttribute(id, Convert.ToDouble(charInfo.Rows[0]["attr_mod"]));
                }
            }

            // Load the skills of the char from CHAR_SKILLS_TBL_NAME
            string s3=String.Format("SELECT status_id, status_time FROM {0} WHERE char_id = {1};", CHAR_STATUS_EFFECTS_TBL_NAME, character.getDatabaseID());
            DataTable skillInfo=mDb.ExecuteQuery(s3);

            if(skillInfo.Rows.Count>0)
            {
                uint nRows=(uint)skillInfo.Rows.Count;
                for(uint row = 0;row < nRows;row++)
                {
                    character.setExperience(
                            Convert.ToInt32(skillInfo.Rows[0]["status_id"]),  // Skill Id
                            Convert.ToInt32(skillInfo.Rows[0]["status_time"])); // Experience
                }
            }

            // Load the status effect
            string s4=String.Format("SELECT status_id, status_time FROM {0} WHERE char_id = {1};", CHAR_STATUS_EFFECTS_TBL_NAME, character.getDatabaseID());
            DataTable statusInfo=mDb.ExecuteQuery(s4);

            if(statusInfo.Rows.Count>0)
            {
                uint nRows=(uint)statusInfo.Rows.Count;
                for(uint row = 0;row < nRows;row++)
                {
                    character.applyStatusEffect(
                            Convert.ToInt32(statusInfo.Rows[0]["status_id"]), // Status Id
                            Convert.ToInt32(statusInfo.Rows[0]["status_time"])); // Time
                }
            }

            // Load the kill stats
            string s5=String.Format("SELECT monster_id, kills FROM {0} WHERE char_id = {1};", CHAR_KILL_COUNT_TBL_NAME, character.getDatabaseID());
            DataTable killsInfo=mDb.ExecuteQuery(s5);

            if(killsInfo.Rows.Count>0)
            {
                uint nRows=(uint)killsInfo.Rows.Count;
                for(uint row = 0;row < nRows;row++)
                {
                    character.setKillCount(
                            Convert.ToInt32(killsInfo.Rows[0]["monster_id"]), // MonsterID
                            Convert.ToInt32(killsInfo.Rows[0]["kills"])); // Kills
                }
            }

            // Load the special status
            string s6=String.Format("SELECT special_id FROM {0} WHERE char_id = {1};", CHAR_SPECIALS_TBL_NAME, character.getDatabaseID());
            DataTable specialsInfo=mDb.ExecuteQuery(s6);

            if(specialsInfo.Rows.Count>0)
            {
                uint nRows=(uint)specialsInfo.Rows.Count;
                for(uint row = 0;row < nRows;row++)
                {
                    character.giveSpecial(Convert.ToInt32(specialsInfo.Rows[0]["special_id"]));
                }
            }

            Possessions poss=character.getPossessions();

            string s7=String.Format("SELECT slot_type, item_id, item_instance FROM {0} WHERE owner_id = '{1}' ORDER BY slot_type desc;", CHAR_EQUIPS_TBL_NAME, character.getDatabaseID());
            DataTable equipInfo=mDb.ExecuteQuery(s7);

            Dictionary< uint, EquipmentItem > equipData=new Dictionary<uint, EquipmentItem>();

            if(equipInfo.Rows.Count>0)
            {
                EquipmentItem equipItem=new EquipmentItem();

                for(int k = 0, size = equipInfo.Rows.Count;k < size;++k)
                {
                    equipItem.itemId=Convert.ToUInt32(equipInfo.Rows[0]["item_id"]);
                    equipItem.itemInstance=Convert.ToUInt32(equipInfo.Rows[0]["item_instance"]);
                    equipData.Add(Convert.ToUInt32(equipInfo.Rows[0]["slot_type"]), equipItem);
                }
            }

            poss.setEquipment(equipData);

            string s8=String.Format("SELECT * FROM {0} WHERE owner_id = '{1}' ORDER by slot ASC", INVENTORIES_TBL_NAME, character.getDatabaseID());
            DataTable itemInfo=mDb.ExecuteQuery(s8);

            Dictionary<uint, InventoryItem > inventoryData=new Dictionary<uint, InventoryItem>();

            if(itemInfo.Rows.Count>0)
            {
                for(int k = 0, size = itemInfo.Rows.Count;k < size;++k)
                {
                    InventoryItem item=new InventoryItem();
                    ushort slot=Convert.ToUInt16(itemInfo.Rows[0]["slot"]);
                    item.itemId=Convert.ToUInt32(itemInfo.Rows[0]["class_id"]);
                    item.amount=Convert.ToUInt32(itemInfo.Rows[0]["amount"]);
                    inventoryData[slot]=item;
                }
            }

            poss.setInventory(inventoryData);

            return character;
        }