예제 #1
0
 public Head(IItem source, HeadDesc desc)
 {
     this.source     = source;
     this.desc       = desc;
     this.durability = desc.durability;
 }
예제 #2
0
    public void Initialize(TypeCollection collection, XElement e)
    {
        name = e.ExpectAtt("name");
        desc = e.ExpectAtt("desc");
        mass = e.TryAttDouble("mass", 0);
        var imageSource = e.TryAtt("image");

        if (imageSource.Length > 0)
        {
            image = ColorImage.FromFile(imageSource);
        }

        switch (e.Attribute("known")?.Value)
        {
        case "true":
            knownChance = 100;
            break;

        case "common":
            knownChance = 80;
            break;

        case "uncommon":
            knownChance = 60;
            break;

        case "rare":
            knownChance = 40;
            break;

        case "exotic":
            knownChance = 20;
            break;

        case "false":
            knownChance = 0;
            break;
        }
        string unknownType = e.TryAtt("unknownType");

        if (!string.IsNullOrWhiteSpace(unknownType))
        {
            if (collection.Lookup(unknownType, out DesignType d) && d is ItemType it)
            {
                this.unknownType = it;
            }
            else
            {
                throw new Exception($"Unknown DesignType: {unknownType}");
            }
        }
        if (e.HasElement(HeadDesc.Tag, out XElement xmlHead))
        {
            this.head = new HeadDesc(xmlHead);
        }
        if (e.HasElement(GrenadeType.Tag, out XElement xmlGrenade))
        {
            this.grenade = new GrenadeType(collection, xmlGrenade);
        }
        if (e.HasElement(GunDesc.Tag, out XElement xmlGun))
        {
            this.gun = new GunDesc(collection, xmlGun);
        }
        if (e.HasElement(AmmoDesc.Tag, out XElement xmlAmmo))
        {
            this.ammo = new AmmoDesc(xmlAmmo);
        }


        //Initialize our nested types now (they are not accessible to anyone else at bind time)
        foreach (var inner in e.Elements("ItemType"))
        {
            collection.ProcessElement(inner);
        }
    }