Exemplo n.º 1
0
    public static void Deserialize(List <Lump> lumps)
    {
        int i = 0;

        CurrentLocal.RPGName         = Encoding.ASCII.GetString(lumps[i++].data);
        CurrentLocal.RPGProfession   = Encoding.ASCII.GetString(lumps[i++].data);
        CurrentLocal.Portrait        = BitConverter.ToInt32(lumps[i++].data, 0);
        CurrentLocal.Badge           = BitConverter.ToInt32(lumps[i++].data, 0);
        CurrentLocal.Level           = BitConverter.ToInt32(lumps[i++].data, 0);
        Difficulty.CurrentDifficulty = BitConverter.ToInt32(lumps[i++].data, 0);
        CurrentLocal.CurrentMap      = Encoding.ASCII.GetString(lumps[i++].data);

        Difficulty.SharedStash    = BitConverter.ToBoolean(lumps[i++].data, 0);
        Difficulty.PermanentDeath = BitConverter.ToBoolean(lumps[i++].data, 0);
        Difficulty.PlayerDamage   = BitConverter.ToInt32(lumps[i++].data, 0);
        Difficulty.EnemyDamage    = BitConverter.ToInt32(lumps[i++].data, 0);

        //faction colors
        {
            MemoryStream stream = new MemoryStream(lumps[i].data);
            BinaryReader br     = new BinaryReader(stream);

            List <Color> colors = new List <Color>();
            for (int p = 0; p < lumps[i].data.Length / 16; p++)
            {
                colors.Add(new Color(br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle()));
            }

            CurrentLocal.FactionColors = colors.ToArray();

            br.Close();
            stream.Close();

            i++;
        }

        for (int w = 0; w < CurrentLocal.PlayerWeapons.Length; w++, i++)
        {
            if (lumps[i].lumpName == "null")
            {
                CurrentLocal.PlayerWeapons[w] = null;
                continue;
            }

            if (!ThingDesignator.Designations.ContainsKey(lumps[i].lumpName))
            {
                Debug.LogError("PlayerInfo: Deserialize: weaponslot[" + w + "] designation \"" + lumps[i].lumpName + "\" not found in designator");
                continue;
            }

            GameObject prefab = ThingDesignator.Designations[lumps[i].lumpName];
            Weapon     weapon = prefab.GetComponent <Weapon>();

            if (weapon == null)
            {
                Debug.LogError("PlayerInfo: Deserialize: weaponslot[" + w + "] designation \"" + lumps[i].lumpName + "\" does not contain <Weapon> component");
                continue;
            }

            //(weapon as InventoryGUIObject).Deserialize(lumps[i].data);
            CurrentLocal.PlayerWeapons[w] = weapon;
        }

        for (int s = 0; s < CurrentLocal.PlayerSkills.Length; s++, i++)
        {
            if (lumps[i].lumpName == "null")
            {
                CurrentLocal.PlayerSkills[s] = null;
                continue;
            }

            if (!ThingDesignator.Designations.ContainsKey(lumps[i].lumpName))
            {
                Debug.LogError("PlayerInfo: Deserialize: skillslot[" + s + "] designation \"" + lumps[i].lumpName + "\" not found in designator");
                continue;
            }

            GameObject prefab = ThingDesignator.Designations[lumps[i].lumpName];
            Skill      skill  = prefab.GetComponent <Skill>();

            if (skill == null)
            {
                Debug.LogError("PlayerInfo: Deserialize: skillslot[" + s + "] designation \"" + lumps[i].lumpName + "\" does not contain <Skill> component");
                continue;
            }

            //(skill as InventoryGUIObject).Deserialize(lumps[i].data);
            CurrentLocal.PlayerSkills[s] = skill;
        }

        for (int a = 0; a < CurrentLocal.PlayerAccessories.Length; a++, i++)
        {
            if (lumps[i].lumpName == "null")
            {
                CurrentLocal.PlayerAccessories[a] = null;
                continue;
            }

            if (!ThingDesignator.Designations.ContainsKey(lumps[i].lumpName))
            {
                Debug.LogError("PlayerInfo: Deserialize: accessoryslot[" + a + "] designation \"" + lumps[i].lumpName + "\" not found in designator");
                continue;
            }

            GameObject prefab    = ThingDesignator.Designations[lumps[i].lumpName];
            Accessory  accessory = prefab.GetComponent <Accessory>();

            if (accessory == null)
            {
                Debug.LogError("PlayerInfo: Deserialize: accessoryslot[" + a + "] designation \"" + lumps[i].lumpName + "\" does not contain <Accessory> component");
                continue;
            }

            //(accessory as InventoryGUIObject).Deserialize(lumps[i].data);
            CurrentLocal.PlayerAccessories[a] = accessory;
        }

        if (lumps[i].lumpName == "null")
        {
            CurrentLocal.CursorItem = null;
        }
        else
        {
            if (!ThingDesignator.Designations.ContainsKey(lumps[i].lumpName))
            {
                Debug.LogError("PlayerInfo: Deserialize: cursoritem designation \"" + lumps[i].lumpName + "\" not found in designator");
                return;
            }

            GameObject         prefab = ThingDesignator.Designations[lumps[i].lumpName];
            InventoryGUIObject g      = prefab.GetComponent <InventoryGUIObject>();

            if (g == null)
            {
                Debug.LogError("PlayerInfo: Deserialize: cursoritem designation \"" + lumps[i].lumpName + "\" does not contain <InventoryGUIObject> component");
                return;
            }

            //g.Deserialize(lumps[i].data);
            CurrentLocal.CursorItem = g;
        }

        CurrentLocal.LastPlayerWeaponSwap = BitConverter.ToInt32(lumps[++i].data, 0);

        //talents
        {
            CurrentLocal.Talents.Clear();

            MemoryStream stream = new MemoryStream(lumps[++i].data);
            BinaryReader br     = new BinaryReader(stream);

            CurrentLocal.TalentPoints = br.ReadInt32();

            for (int t = 0; t < (lumps[i].data.Length - 1) / 12; t++)
            {
                string referenceName = Wad.ByteString(br.ReadBytes(12));

                if (!ThingDesignator.Designations.ContainsKey(referenceName))
                {
                    Debug.LogError("PlayerInfo: Deserialize: talent designation \"" + referenceName + "\" not found in designator");
                    return;
                }

                GameObject prefab = ThingDesignator.Designations[referenceName];
                Talent     talent = prefab.GetComponent <Talent>();

                if (talent == null)
                {
                    Debug.LogError("PlayerInfo: Deserialize: talent designation \"" + referenceName + "\" does not contain <Talent> component");
                    return;
                }

                CurrentLocal.Talents.Add(talent);
            }

            br.Close();
            stream.Close();

            i++;
        }
    }