Пример #1
0
        public override cWeapon Instantiate()
        {
            cProjectile wep = new cProjectile();

            base.SetProps(wep);
            return(wep);
        }
Пример #2
0
        public void LoadWeapon(string name)
        {
            GraphicsDevice gd = GraphicsDevice;
            ContentManager cm = PrimalDevistation.Instance.CM;

            // Load the XML doc
            XmlDocument doc = new XmlDocument();

            doc.Load(@"Resources/Weapons/" + name);

            // Create the weapon and set its name
            XmlNode node;
            XmlNode weaponNode = doc.SelectSingleNode("weapon");
            string  wepName    = weaponNode.Attributes["name"].Value.ToLower();
            string  type       = weaponNode.Attributes["type"].Value.ToLower();

            XmlNode properties = weaponNode.SelectSingleNode("properties");

            if (properties == null)
            {
                throw new Exception("There needs to be atleast some properties for the '" + name + "' weapon");
            }

            cWeapon wep;

            if (type == "projectile")
            {
                wep = new cProjectile(properties);
            }
            else if (type == "grenade")
            {
                wep = new cGrenade(properties);
            }
            else if (type == "vortex")
            {
                wep = new cVortex(properties);
            }
            else if (type == "grapple")
            {
                _grappleBP = new cGrapple(properties); wep = _grappleBP;
            }
            else
            {
                throw new Exception("Weapon type not valid");
            }

            wep.Name = wepName;
            wep.Type = type;
            if (!(wep is cGrapple))
            {
                _blueprints.Add(wep);
            }

            // Load the various properties
            node = properties.SelectSingleNode("texture");
            if (node != null)
            {
                wep.Texture = cm.Load <Texture2D>(@"Weapons/" + node.InnerText);
            }
            node = properties.SelectSingleNode("trail");
            if (node != null)
            {
                wep.TrailTexture = cm.Load <Texture2D>(@"Weapons/" + node.InnerText);
            }
            node = properties.SelectSingleNode("friction");
            if (node != null)
            {
                wep.Friction = float.Parse(node.InnerText);
            }
            node = properties.SelectSingleNode("maxAmmo");
            if (node != null)
            {
                wep.MaxAmmo = int.Parse(node.InnerText);
            }
            node = properties.SelectSingleNode("reloadTime");
            if (node != null)
            {
                wep.ReloadTime = int.Parse(node.InnerText);
            }
            node = properties.SelectSingleNode("rateOfFire");
            if (node != null)
            {
                wep.RateOfFire = int.Parse(node.InnerText);
            }
            node = properties.SelectSingleNode("launchPower");
            if (node != null)
            {
                wep.LaunchPower = float.Parse(node.InnerText);
            }
            node = properties.SelectSingleNode("numToFire");
            if (node != null)
            {
                wep.NumToFire = int.Parse(node.InnerText);
            }
            node = properties.SelectSingleNode("fireRangeAngle");
            if (node != null)
            {
                wep.FireRangeAngle = float.Parse(node.InnerText);
            }


            // Load the events and thier commands (if there are any)
            XmlNode eventsNode = weaponNode.SelectSingleNode("events");

            if (eventsNode != null)
            {
                XmlNodeList events;

                // Load the on collision events
                events = eventsNode.SelectNodes("onTerrainCollide");
                foreach (XmlNode eventNode in events)
                {
                    wep.OnCollisionEvents.Add(new cOnCollisionEvent(eventNode));
                }

                // Load the on age events
                events = eventsNode.SelectNodes("onAge");
                foreach (XmlNode eventNode in events)
                {
                    wep.OnAgeEvents.Add(new cOnAgeEvent(eventNode));
                }
            }
        }