Advertisement
ossimc82

FameStats.cs

Jan 31st, 2015
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 22.29 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.IO;
  6. using System.Xml.Serialization;
  7. using System.Xml;
  8.  
  9. [Serializable, XmlRoot("Fame"), XmlType(TypeName = "Fame")]
  10. public class FameStats
  11. {
  12.     //-_-||
  13.     [XmlElement("Char")]
  14.     public Char __Char { get; set; }
  15.  
  16.  
  17.     public int Shots { get; set; }
  18.     public int ShotsThatDamage { get; set; }
  19.     public int SpecialAbilityUses { get; set; }
  20.     public int TilesUncovered { get; set; }
  21.     public int Teleports { get; set; }
  22.     public int PotionsDrunk { get; set; }
  23.     public int MonsterKills { get; set; }
  24.     public int MonsterAssists { get; set; }
  25.     public int GodKills { get; set; }
  26.     public int GodAssists { get; set; }
  27.     public int CubeKills { get; set; }
  28.     public int OryxKills { get; set; }
  29.     public int QuestsCompleted { get; set; }
  30.     public int PirateCavesCompleted { get; set; }
  31.     public int UndeadLairsCompleted { get; set; }
  32.     public int AbyssOfDemonsCompleted { get; set; }
  33.     public int SnakePitsCompleted { get; set; }
  34.     public int SpiderDensCompleted { get; set; }
  35.     public int SpriteWorldsCompleted { get; set; }
  36.     public int LevelUpAssists { get; set; }
  37.     public int MinutesActive { get; set; }
  38.     public int TombsCompleted { get; set; }
  39.     public int TrenchesCompleted { get; set; }
  40.     public int JunglesCompleted { get; set; }
  41.     public int ManorsCompleted { get; set; }
  42.  
  43.     public void Read(byte[] bytes)
  44.     {
  45.         NReader reader = new NReader(new MemoryStream(bytes));
  46.         byte id;
  47.         do
  48.         {
  49.             if (reader.BaseStream.Length == 0 || reader.BaseStream.Position >= reader.BaseStream.Length - 1) break;
  50.             id = reader.ReadByte();
  51.             switch (id)
  52.             {
  53.                 case 0: Shots = reader.ReadInt32(); break;
  54.                 case 1: ShotsThatDamage = reader.ReadInt32(); break;
  55.                 case 2: SpecialAbilityUses = reader.ReadInt32(); break;
  56.                 case 3: TilesUncovered = reader.ReadInt32(); break;
  57.                 case 4: Teleports = reader.ReadInt32(); break;
  58.                 case 5: PotionsDrunk = reader.ReadInt32(); break;
  59.                 case 6: MonsterKills = reader.ReadInt32(); break;
  60.                 case 7: MonsterAssists = reader.ReadInt32(); break;
  61.                 case 8: GodKills = reader.ReadInt32(); break;
  62.                 case 9: GodAssists = reader.ReadInt32(); break;
  63.                 case 10: CubeKills = reader.ReadInt32(); break;
  64.                 case 11: OryxKills = reader.ReadInt32(); break;
  65.                 case 12: QuestsCompleted = reader.ReadInt32(); break;
  66.                 case 13: PirateCavesCompleted = reader.ReadInt32(); break;
  67.                 case 14: UndeadLairsCompleted = reader.ReadInt32(); break;
  68.                 case 15: AbyssOfDemonsCompleted = reader.ReadInt32(); break;
  69.                 case 16: SnakePitsCompleted = reader.ReadInt32(); break;
  70.                 case 17: SpiderDensCompleted = reader.ReadInt32(); break;
  71.                 case 18: SpriteWorldsCompleted = reader.ReadInt32(); break;
  72.                 case 19: LevelUpAssists = reader.ReadInt32(); break;
  73.                 case 20: MinutesActive = reader.ReadInt32(); break;
  74.                 case 21: TombsCompleted = reader.ReadInt32(); break;
  75.                 case 22: TrenchesCompleted = reader.ReadInt32(); break;
  76.                 case 23: JunglesCompleted = reader.ReadInt32(); break;
  77.                 case 24: ManorsCompleted = reader.ReadInt32(); break;
  78.             }
  79.         } while (reader.PeekChar() != -1);
  80.     }
  81.  
  82.     public byte[] Write()
  83.     {
  84.         var dat = new Tuple<byte, int>[]
  85.             {
  86.                 new Tuple<byte, int>(0, Shots),
  87.                 new Tuple<byte, int>(1, ShotsThatDamage),
  88.                 new Tuple<byte, int>(2, SpecialAbilityUses),
  89.                 new Tuple<byte, int>(3, TilesUncovered),
  90.                 new Tuple<byte, int>(4, Teleports),
  91.                 new Tuple<byte, int>(5, PotionsDrunk),
  92.                 new Tuple<byte, int>(6, MonsterKills),
  93.                 new Tuple<byte, int>(7, MonsterAssists),
  94.                 new Tuple<byte, int>(8, GodKills),
  95.                 new Tuple<byte, int>(9, GodAssists),
  96.                 new Tuple<byte, int>(10, CubeKills),
  97.                 new Tuple<byte, int>(11, OryxKills),
  98.                 new Tuple<byte, int>(12, QuestsCompleted),
  99.                 new Tuple<byte, int>(13, PirateCavesCompleted),
  100.                 new Tuple<byte, int>(14, UndeadLairsCompleted),
  101.                 new Tuple<byte, int>(15, AbyssOfDemonsCompleted),
  102.                 new Tuple<byte, int>(16, SnakePitsCompleted),
  103.                 new Tuple<byte, int>(17, SpiderDensCompleted),
  104.                 new Tuple<byte, int>(18, SpriteWorldsCompleted),
  105.                 new Tuple<byte, int>(19, LevelUpAssists),
  106.                 new Tuple<byte, int>(20, MinutesActive),
  107.                 new Tuple<byte, int>(21, TombsCompleted),
  108.                 new Tuple<byte, int>(22, TrenchesCompleted),
  109.                 new Tuple<byte, int>(23, JunglesCompleted),
  110.                 new Tuple<byte, int>(24, ManorsCompleted)
  111.             };
  112.  
  113.         MemoryStream ret = new MemoryStream();
  114.         using (NWriter wtr = new NWriter(ret))
  115.         {
  116.             foreach (var i in dat)
  117.             {
  118.                 wtr.Write(i.Item1);
  119.                 wtr.Write(i.Item2);
  120.             }
  121.         }
  122.         return ret.ToArray();
  123.     }
  124.  
  125.     public int CalculateTotal(Account acc, Char chr, int baseFame, out bool firstBorn)
  126.     {
  127.         int bonus = 0;
  128.         if (chr.CharacterId < 2)            //Ancestor
  129.         {
  130.             bonus += (int)(baseFame * 0.1) + 20;
  131.         }
  132.         //Legacy Builder???
  133.         if (ShotsThatDamage == 0)           //Pacifist
  134.         {
  135.             bonus += (int)(baseFame * 0.25);
  136.         }
  137.         if (PotionsDrunk == 0)              //Thirsty
  138.         {
  139.             bonus += (int)(baseFame * 0.25);
  140.         }
  141.         if (SpecialAbilityUses == 0)        //Mundane
  142.         {
  143.             bonus += (int)(baseFame * 0.25);
  144.         }
  145.         if (Teleports == 0)                 //Boots on the Ground
  146.         {
  147.             bonus += (int)(baseFame * 0.25);
  148.         }
  149.         if (PirateCavesCompleted > 0 &&
  150.             UndeadLairsCompleted > 0 &&
  151.             AbyssOfDemonsCompleted > 0 &&
  152.             SnakePitsCompleted > 0 &&
  153.             SpiderDensCompleted > 0 &&
  154.             SpriteWorldsCompleted > 0 &&
  155.             TombsCompleted > 0 &&
  156.             TrenchesCompleted > 0 &&
  157.             JunglesCompleted > 0 &&
  158.             ManorsCompleted > 0)            //Tunnel Rat
  159.         {
  160.             bonus += (int)(baseFame * 0.1);
  161.         }
  162.         if ((double)GodKills / (GodKills + MonsterKills) > 0.1)   //Enemy of the Gods
  163.         {
  164.             bonus += (int)(baseFame * 0.1);
  165.         }
  166.         if ((double)GodKills / (GodKills + MonsterKills) > 0.5)   //Slayer of the Gods
  167.         {
  168.             bonus += (int)(baseFame * 0.1);
  169.         }
  170.         if (OryxKills > 0)                  //Oryx Slayer
  171.         {
  172.             bonus += (int)(baseFame * 0.1);
  173.         }
  174.         if ((double)ShotsThatDamage / Shots > 0.25)     //Accurate
  175.         {
  176.             bonus += (int)(baseFame * 0.1);
  177.         }
  178.         if ((double)ShotsThatDamage / Shots > 0.5)      //Sharpshooter
  179.         {
  180.             bonus += (int)(baseFame * 0.1);
  181.         }
  182.         if ((double)ShotsThatDamage / Shots > 0.75)     //Sniper
  183.         {
  184.             bonus += (int)(baseFame * 0.1);
  185.         }
  186.         if (TilesUncovered > 1000000)       //Explorer
  187.         {
  188.             bonus += (int)(baseFame * 0.05);
  189.         }
  190.         if (TilesUncovered > 4000000)       //Cartographer
  191.         {
  192.             bonus += (int)(baseFame * 0.05);
  193.         }
  194.         if (LevelUpAssists > 100)           //Team Player
  195.         {
  196.             bonus += (int)(baseFame * 0.1);
  197.         }
  198.         if (LevelUpAssists > 1000)          //Leader of Men
  199.         {
  200.             bonus += (int)(baseFame * 0.1);
  201.         }
  202.         if (QuestsCompleted > 1000)         //Doer of Deeds
  203.         {
  204.             bonus += (int)(baseFame * 0.1);
  205.         }
  206.         if (CubeKills == 0)                 //Friend of the Cubes
  207.         {
  208.             bonus += (int)(baseFame * 0.1);
  209.         }
  210.         for (int i = 0; i < 4; i++)         //Well Equipped
  211.         {
  212.             if (chr.Equipment[i] == -1) continue;
  213.             var b = XmlDatas.ItemDescs[chr.Equipment[i]].FameBonus;
  214.             if (b > 0)
  215.                 bonus += baseFame * b / 100;
  216.         }
  217.         if (baseFame + bonus > acc.Stats.BestCharFame)   //First Born
  218.         {
  219.             bonus += (int)(baseFame * 0.1);
  220.             firstBorn = true;
  221.         }
  222.         else
  223.             firstBorn = false;
  224.  
  225.         return (int)(baseFame + bonus);
  226.     }
  227.  
  228.     void SerializeBonus(XmlDocument doc, Account acc, Char chr, int baseFame, bool firstBorn)
  229.     {
  230.         if (chr.CharacterId < 2)            //Ancestor
  231.         {
  232.             XmlElement x = doc.CreateElement("Bonus");
  233.             XmlAttribute idAttr = doc.CreateAttribute("id");
  234.             idAttr.Value = "Ancestor";
  235.             x.Attributes.Append(idAttr);
  236.             XmlAttribute descAttr = doc.CreateAttribute("desc");
  237.             descAttr.Value = "First death of any of your characters";
  238.             x.Attributes.Append(descAttr);
  239.             x.InnerText = ((int)(baseFame * 0.1 + 20)).ToString();
  240.             doc.DocumentElement.AppendChild(x);
  241.         }
  242.         //Legacy Builder???
  243.         if (ShotsThatDamage == 0)           //Pacifist
  244.         {
  245.             XmlElement x = doc.CreateElement("Bonus");
  246.             XmlAttribute idAttr = doc.CreateAttribute("id");
  247.             idAttr.Value = "Pacifist";
  248.             x.Attributes.Append(idAttr);
  249.             XmlAttribute descAttr = doc.CreateAttribute("desc");
  250.             descAttr.Value = "Never shot a bullet which hit an enemy";
  251.             x.Attributes.Append(descAttr);
  252.             x.InnerText = ((int)(baseFame * 0.25)).ToString();
  253.             doc.DocumentElement.AppendChild(x);
  254.         }
  255.         if (PotionsDrunk == 0)              //Thirsty
  256.         {
  257.             XmlElement x = doc.CreateElement("Bonus");
  258.             XmlAttribute idAttr = doc.CreateAttribute("id");
  259.             idAttr.Value = "Thirsty";
  260.             x.Attributes.Append(idAttr);
  261.             XmlAttribute descAttr = doc.CreateAttribute("desc");
  262.             descAttr.Value = "Never drank a potion from inventory";
  263.             x.Attributes.Append(descAttr);
  264.             x.InnerText = ((int)(baseFame * 0.25)).ToString();
  265.             doc.DocumentElement.AppendChild(x);
  266.         }
  267.         if (SpecialAbilityUses == 0)        //Mundane
  268.         {
  269.             XmlElement x = doc.CreateElement("Bonus");
  270.             XmlAttribute idAttr = doc.CreateAttribute("id");
  271.             idAttr.Value = "Mundane";
  272.             x.Attributes.Append(idAttr);
  273.             XmlAttribute descAttr = doc.CreateAttribute("desc");
  274.             descAttr.Value = "Never used special ability (requires level 20)";
  275.             x.Attributes.Append(descAttr);
  276.             x.InnerText = ((int)(baseFame * 0.25)).ToString();
  277.             doc.DocumentElement.AppendChild(x);
  278.         }
  279.         if (Teleports == 0)                 //Boots on the Ground
  280.         {
  281.             XmlElement x = doc.CreateElement("Bonus");
  282.             XmlAttribute idAttr = doc.CreateAttribute("id");
  283.             idAttr.Value = "Boots on the Ground";
  284.             x.Attributes.Append(idAttr);
  285.             XmlAttribute descAttr = doc.CreateAttribute("desc");
  286.             descAttr.Value = "Never teleported";
  287.             x.Attributes.Append(descAttr);
  288.             x.InnerText = ((int)(baseFame * 0.25)).ToString();
  289.             doc.DocumentElement.AppendChild(x);
  290.         }
  291.         if (PirateCavesCompleted > 0 &&
  292.             UndeadLairsCompleted > 0 &&
  293.             AbyssOfDemonsCompleted > 0 &&
  294.             SnakePitsCompleted > 0 &&
  295.             SpiderDensCompleted > 0 &&
  296.             SpriteWorldsCompleted > 0 &&
  297.             TombsCompleted > 0 &&
  298.             TrenchesCompleted > 0 &&
  299.             JunglesCompleted > 0 &&
  300.             ManorsCompleted > 0)            //Tunnel Rat
  301.         {
  302.             XmlElement x = doc.CreateElement("Bonus");
  303.             XmlAttribute idAttr = doc.CreateAttribute("id");
  304.             idAttr.Value = "Tunnel Rat";
  305.             x.Attributes.Append(idAttr);
  306.             XmlAttribute descAttr = doc.CreateAttribute("desc");
  307.             descAttr.Value = "Completed every dungeon type";
  308.             x.Attributes.Append(descAttr);
  309.             x.InnerText = ((int)(baseFame * 0.1)).ToString();
  310.             doc.DocumentElement.AppendChild(x);
  311.         }
  312.         if ((double)GodKills / (GodKills + MonsterKills) > 0.1)   //Enemy of the Gods
  313.         {
  314.             XmlElement x = doc.CreateElement("Bonus");
  315.             XmlAttribute idAttr = doc.CreateAttribute("id");
  316.             idAttr.Value = "Enemy of the Gods";
  317.             x.Attributes.Append(idAttr);
  318.             XmlAttribute descAttr = doc.CreateAttribute("desc");
  319.             descAttr.Value = "More than 10% of kills are gods (requires level 20)";
  320.             x.Attributes.Append(descAttr);
  321.             x.InnerText = ((int)(baseFame * 0.1)).ToString();
  322.             doc.DocumentElement.AppendChild(x);
  323.         }
  324.         if ((double)GodKills / (GodKills + MonsterKills) > 0.5)   //Slayer of the Gods
  325.         {
  326.             XmlElement x = doc.CreateElement("Bonus");
  327.             XmlAttribute idAttr = doc.CreateAttribute("id");
  328.             idAttr.Value = "Slayer of the Gods";
  329.             x.Attributes.Append(idAttr);
  330.             XmlAttribute descAttr = doc.CreateAttribute("desc");
  331.             descAttr.Value = "More than 50% of kills are gods (requires level 20)";
  332.             x.Attributes.Append(descAttr);
  333.             x.InnerText = ((int)(baseFame * 0.1)).ToString();
  334.             doc.DocumentElement.AppendChild(x);
  335.         }
  336.         if (OryxKills > 0)                  //Oryx Slayer
  337.         {
  338.             XmlElement x = doc.CreateElement("Bonus");
  339.             XmlAttribute idAttr = doc.CreateAttribute("id");
  340.             idAttr.Value = "Oryx Slayer";
  341.             x.Attributes.Append(idAttr);
  342.             XmlAttribute descAttr = doc.CreateAttribute("desc");
  343.             descAttr.Value = "Dealt Killing blow to Oryx";
  344.             x.Attributes.Append(descAttr);
  345.             x.InnerText = ((int)(baseFame * 0.1)).ToString();
  346.             doc.DocumentElement.AppendChild(x);
  347.         }
  348.         if ((double)ShotsThatDamage / Shots > 0.25)     //Accurate
  349.         {
  350.             XmlElement x = doc.CreateElement("Bonus");
  351.             XmlAttribute idAttr = doc.CreateAttribute("id");
  352.             idAttr.Value = "Accurate";
  353.             x.Attributes.Append(idAttr);
  354.             XmlAttribute descAttr = doc.CreateAttribute("desc");
  355.             descAttr.Value = "Accuracy of better than 25% (requires level 20)";
  356.             x.Attributes.Append(descAttr);
  357.             x.InnerText = ((int)(baseFame * 0.1)).ToString();
  358.             doc.DocumentElement.AppendChild(x);
  359.         }
  360.         if ((double)ShotsThatDamage / Shots > 0.5)      //Sharpshooter
  361.         {
  362.             XmlElement x = doc.CreateElement("Bonus");
  363.             XmlAttribute idAttr = doc.CreateAttribute("id");
  364.             idAttr.Value = "Sharpshooter";
  365.             x.Attributes.Append(idAttr);
  366.             XmlAttribute descAttr = doc.CreateAttribute("desc");
  367.             descAttr.Value = "Accuracy of better than 50% (requires level 20)";
  368.             x.Attributes.Append(descAttr);
  369.             x.InnerText = ((int)(baseFame * 0.1)).ToString();
  370.             doc.DocumentElement.AppendChild(x);
  371.         }
  372.         if ((double)ShotsThatDamage / Shots > 0.75)     //Sniper
  373.         {
  374.             XmlElement x = doc.CreateElement("Bonus");
  375.             XmlAttribute idAttr = doc.CreateAttribute("id");
  376.             idAttr.Value = "Sniper";
  377.             x.Attributes.Append(idAttr);
  378.             XmlAttribute descAttr = doc.CreateAttribute("desc");
  379.             descAttr.Value = "Accuracy of better than 75% (requires level 20)";
  380.             x.Attributes.Append(descAttr);
  381.             x.InnerText = ((int)(baseFame * 0.1)).ToString();
  382.             doc.DocumentElement.AppendChild(x);
  383.         }
  384.         if (TilesUncovered > 1000000)       //Explorer
  385.         {
  386.             XmlElement x = doc.CreateElement("Bonus");
  387.             XmlAttribute idAttr = doc.CreateAttribute("id");
  388.             idAttr.Value = "Explorer";
  389.             x.Attributes.Append(idAttr);
  390.             XmlAttribute descAttr = doc.CreateAttribute("desc");
  391.             descAttr.Value = "More than 1 million tiles uncovered";
  392.             x.Attributes.Append(descAttr);
  393.             x.InnerText = ((int)(baseFame * 0.05)).ToString();
  394.             doc.DocumentElement.AppendChild(x);
  395.         }
  396.         if (TilesUncovered > 4000000)       //Cartographer
  397.         {
  398.             XmlElement x = doc.CreateElement("Bonus");
  399.             XmlAttribute idAttr = doc.CreateAttribute("id");
  400.             idAttr.Value = "Cartographer";
  401.             x.Attributes.Append(idAttr);
  402.             XmlAttribute descAttr = doc.CreateAttribute("desc");
  403.             descAttr.Value = "More than 4 million tiles uncovered";
  404.             x.Attributes.Append(descAttr);
  405.             x.InnerText = ((int)(baseFame * 0.05)).ToString();
  406.             doc.DocumentElement.AppendChild(x);
  407.         }
  408.         if (LevelUpAssists > 100)           //Team Player
  409.         {
  410.             XmlElement x = doc.CreateElement("Bonus");
  411.             XmlAttribute idAttr = doc.CreateAttribute("id");
  412.             idAttr.Value = "Team Player";
  413.             x.Attributes.Append(idAttr);
  414.             XmlAttribute descAttr = doc.CreateAttribute("desc");
  415.             descAttr.Value = "More than 100 party member level ups";
  416.             x.Attributes.Append(descAttr);
  417.             x.InnerText = ((int)(baseFame * 0.1)).ToString();
  418.             doc.DocumentElement.AppendChild(x);
  419.         }
  420.         if (LevelUpAssists > 1000)          //Leader of Men
  421.         {
  422.             XmlElement x = doc.CreateElement("Bonus");
  423.             XmlAttribute idAttr = doc.CreateAttribute("id");
  424.             idAttr.Value = "Leader of Men";
  425.             x.Attributes.Append(idAttr);
  426.             XmlAttribute descAttr = doc.CreateAttribute("desc");
  427.             descAttr.Value = "More than 1000 party member level ups";
  428.             x.Attributes.Append(descAttr);
  429.             x.InnerText = ((int)(baseFame * 0.1)).ToString();
  430.             doc.DocumentElement.AppendChild(x);
  431.         }
  432.         if (QuestsCompleted > 1000)         //Doer of Deeds
  433.         {
  434.             XmlElement x = doc.CreateElement("Bonus");
  435.             XmlAttribute idAttr = doc.CreateAttribute("id");
  436.             idAttr.Value = "Doer of Deeds";
  437.             x.Attributes.Append(idAttr);
  438.             XmlAttribute descAttr = doc.CreateAttribute("desc");
  439.             descAttr.Value = "More than 1000 quests completed";
  440.             x.Attributes.Append(descAttr);
  441.             x.InnerText = ((int)(baseFame * 0.1)).ToString();
  442.             doc.DocumentElement.AppendChild(x);
  443.         }
  444.         if (CubeKills == 0)                 //Friend of the Cubes
  445.         {
  446.             XmlElement x = doc.CreateElement("Bonus");
  447.             XmlAttribute idAttr = doc.CreateAttribute("id");
  448.             idAttr.Value = "Friend of the Cubes";
  449.             x.Attributes.Append(idAttr);
  450.             XmlAttribute descAttr = doc.CreateAttribute("desc");
  451.             descAttr.Value = "Never killed a cube (requires level 20)";
  452.             x.Attributes.Append(descAttr);
  453.             x.InnerText = ((int)(baseFame * 0.1)).ToString();
  454.             doc.DocumentElement.AppendChild(x);
  455.         }
  456.         double bo = 0;
  457.         for (int i = 0; i < 4; i++)         //Well Equipped
  458.         {
  459.             if (chr.Equipment[i] == -1) continue;
  460.             var b = XmlDatas.ItemDescs[chr.Equipment[i]].FameBonus;
  461.             if (b > 0)
  462.                 bo += baseFame * b / 100;
  463.         }
  464.         if (bo > 0)
  465.         {
  466.             XmlElement x = doc.CreateElement("Bonus");
  467.             XmlAttribute idAttr = doc.CreateAttribute("id");
  468.             idAttr.Value = "Well Equipped";
  469.             x.Attributes.Append(idAttr);
  470.             XmlAttribute descAttr = doc.CreateAttribute("desc");
  471.             descAttr.Value = "Bonus for equipment";
  472.             x.Attributes.Append(descAttr);
  473.             x.InnerText = ((int)bo).ToString();
  474.             doc.DocumentElement.AppendChild(x);
  475.         }
  476.         if (firstBorn)
  477.         {
  478.             XmlElement x = doc.CreateElement("Bonus");
  479.             XmlAttribute idAttr = doc.CreateAttribute("id");
  480.             idAttr.Value = "First Born";
  481.             x.Attributes.Append(idAttr);
  482.             XmlAttribute descAttr = doc.CreateAttribute("desc");
  483.             descAttr.Value = "Best fame of any of your previous incarnations";
  484.             x.Attributes.Append(descAttr);
  485.             x.InnerText = ((int)(baseFame * 0.1)).ToString();
  486.             doc.DocumentElement.AppendChild(x);
  487.         }
  488.     }
  489.     public string Serialize(Account acc, Char chr, int time, string killer, bool firstBorn)
  490.     {
  491.         __Char = chr;
  492.         XmlDocument xmlDoc = new XmlDocument();
  493.         {
  494.             XmlSerializer serializer = new XmlSerializer(this.GetType());
  495.             using (var wtr = xmlDoc.CreateNavigator().AppendChild())
  496.                 serializer.Serialize(wtr, this);
  497.             xmlDoc.DocumentElement.Attributes.RemoveAll();
  498.         }
  499.         XmlElement ac = xmlDoc.CreateElement("Account");
  500.         XmlElement name = xmlDoc.CreateElement("Name");
  501.         name.InnerText = acc.Name;
  502.         ac.AppendChild(name);
  503.  
  504.         xmlDoc.SelectSingleNode("/Fame/Char").AppendChild(ac);
  505.  
  506.         SerializeBonus(xmlDoc, acc, chr, chr.CurrentFame, firstBorn);
  507.  
  508.         XmlElement basFame = xmlDoc.CreateElement("BaseFame");
  509.         basFame.InnerText = chr.CurrentFame.ToString();
  510.         xmlDoc.DocumentElement.AppendChild(basFame);
  511.         XmlElement totalFame = xmlDoc.CreateElement("TotalFame");
  512.         totalFame.InnerText = CalculateTotal(acc, chr, chr.CurrentFame, out firstBorn).ToString();
  513.         xmlDoc.DocumentElement.AppendChild(totalFame);
  514.         XmlElement deathTime = xmlDoc.CreateElement("CreatedOn");
  515.         deathTime.InnerText = time.ToString();
  516.         xmlDoc.DocumentElement.AppendChild(deathTime);
  517.         XmlElement killed = xmlDoc.CreateElement("KilledBy");
  518.         killed.InnerText = killer;
  519.         xmlDoc.DocumentElement.AppendChild(killed);
  520.  
  521.  
  522.         StringWriter result = new StringWriter();
  523.         xmlDoc.Save(result);
  524.         return result.ToString();
  525.     }
  526. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement