Example #1
0
 void UpdateHealthBar()
 {
     if (healthBar)
     {
         if (CurrentHealthPoints > MaxHealthpoints)
         {
             CurrentHealthPoints = MaxHealthpoints;
         }
         if (gameObject.GetComponent <PlayerControl>())
         {
             healthDisplayText.text = (CurrentHealthPoints.ToString() + "/" + MaxHealthpoints.ToString());
         }
         healthBar.fillAmount = HealthAsPercentage;
     }
 }
Example #2
0
        public void WriteXml(XmlWriter writer)
        {
            //new XmlDocument().Save(writer);
            if (Name != null)
            {
                writer.WriteAttributeString("Name", Name);
            }
            if (PlayerName != null)
            {
                writer.WriteAttributeString("PlayerName", PlayerName);
            }
            if (Class != null)
            {
                writer.WriteStartElement("Class");
                writer.WriteAttributeString("Level", ClassLevel.ToString());
                writer.WriteString(Class.Name);
                writer.WriteEndElement();
            }
            if (SecondaryClass != null)
            {
                writer.WriteStartElement("SecondaryClass");
                writer.WriteAttributeString("Level", SecondaryClassLevel.ToString());
                writer.WriteString(SecondaryClass.Name);
                writer.WriteEndElement();
            }
            if (Race != null)
            {
                writer.WriteElementString("Race", Race.Name);
            }
            writer.WriteElementString("Speed", Speed.ToString());
            writer.WriteElementString("Size", Size.ToString());
            writer.WriteElementString("MaxHealthPoints", MaxHealthPoints.ToString());
            writer.WriteElementString("CurrentHealthPoints", CurrentHealthPoints.ToString());
            writer.WriteElementString("Bruise", Bruise.ToString());
            XmlSerializerNamespaces ns = new XmlSerializerNamespaces();

            ns.Add("", "");
            XmlSerializer otherSer;

            {
                writer.WriteStartElement("Inventory");
                writer.WriteAttributeString("Name", Inventory.Name);
                if (_mainWeapon != null)
                {
                    otherSer = new XmlSerializer(typeof(Weapon));
                    writer.WriteStartElement("MainWeapon");
                    otherSer.Serialize(writer, _mainWeapon, ns);
                    writer.WriteEndElement();
                }
                otherSer = new XmlSerializer(typeof(Armor));
                if (_mainArmor != null)
                {
                    writer.WriteStartElement("MainArmor");
                    otherSer.Serialize(writer, _mainArmor, ns);
                    writer.WriteEndElement();
                }
                if (_mainShield != null)
                {
                    writer.WriteStartElement("MainShield");
                    otherSer.Serialize(writer, _mainShield, ns);
                    writer.WriteEndElement();
                }
                otherSer = new XmlSerializer(typeof(Pouch));
                otherSer.Serialize(writer, Inventory.Pouch, ns);
                {
                    writer.WriteStartElement("Bag");
                    XmlSerializer serItem = new XmlSerializer(typeof(Item));
                    XmlSerializer serArmo = new XmlSerializer(typeof(Armor));
                    XmlSerializer serWeap = new XmlSerializer(typeof(Weapon));
                    foreach (object it in Inventory.Bag.Where((i) => i != MainWeapon && i != MainArmor && i != MainShield))
                    {
                        if (it.GetType() == typeof(Item))
                        {
                            serItem.Serialize(writer, it, ns);
                        }
                        else if (it.GetType() == typeof(Weapon))
                        {
                            serWeap.Serialize(writer, it, ns);
                        }
                        else if (it.GetType() == typeof(Armor))
                        {
                            serArmo.Serialize(writer, it, ns);
                        }
                    }
                    writer.WriteEndElement();
                }
                writer.WriteEndElement();
            }
            writer.WriteStartElement("Attributes");
            foreach (HeroAttribute.Type t in Enum.GetValues(typeof(HeroAttribute.Type)))
            {
                writer.WriteStartElement(t.ToString());
                writer.WriteAttributeString("Value", _atr[(int)t].ToString());
                writer.WriteEndElement();
            }
            writer.WriteEndElement();
            writer.WriteStartElement("SkillMarks");
            foreach (Skill.Type t in Enum.GetValues(typeof(Skill.Type)))
            {
                //writer.WriteComment(Skill.GetPolishName(t));
                writer.WriteStartElement(t.ToString());
                writer.WriteAttributeString("Value", _marks[(int)t].ToString());
                writer.WriteEndElement();
            }
            writer.WriteEndElement();
            writer.WriteElementString("Age", Age.ToString());
            writer.WriteElementString("Height", Height.ToString());
            writer.WriteElementString("Weight", Weight.ToString());
            if (Sex != null)
            {
                writer.WriteElementString("Sex", Sex);
            }
            if (EyesColor != null)
            {
                writer.WriteElementString("EyesColor", EyesColor);
            }
            if (HairColor != null)
            {
                writer.WriteElementString("HairColor", HairColor);
            }
        }