private static Weapon[] LoadWeapons(string path, Texture2D texture) { if (File.Exists(path)) { object result = null; XmlSerializer xml = new XmlSerializer(typeof(WeaponContainer)); using (FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read)) { result = xml.Deserialize(stream); } if (result != null) { WeaponContainer container = (WeaponContainer)result; Projectile[] projectiles = new Projectile[container.Projectiles.Length]; for (int i = 0; i < container.Projectiles.Length; i++) { ProjectileInformation proji = container.Projectiles[i]; projectiles[i] = new Projectile(proji.Damage, proji.SuspressedDamage, proji.DamageReductionPerUnit, proji.Speed, proji.LifeTime, Game1.CurrentGame.GameMode == GameScene.GameMode.PlayAble ? proji.RayCastShot : true, false, texture, 0, 0, Vector2.One, Color.White, proji.Name, Vector2.Zero); } Weapon[] weapons = new Weapon[container.Weapons.Length]; for (int i = 0; i < container.Weapons.Length; i++) { WeaponInformation weaponInfo = container.Weapons[i]; weapons[i] = new Weapon(weaponInfo.Name, Vector2.Zero, weaponInfo.EquipmentType, weaponInfo.Firerate, SearchProjectile(projectiles, weaponInfo.ProjectileName), weaponInfo.AmmoType, weaponInfo.Slot, weaponInfo.ClipCount * weaponInfo.ClipSize, weaponInfo.ClipSize, weaponInfo.ReloadTime, weaponInfo.Mobility); } return(weapons); } } return(null); }
private void CreateWeaponFile() { WeaponInformation[] weapons = new WeaponInformation[14]; weapons[0] = new WeaponInformation("416-c", 30, 4, 740, 3140f, 41, Weapon.AmmoTyp.Clip, Weapon.WeaponSlot.Primary, Equipment.EquipmentType.Useable, "416-c_proj"); //mobility = 41, dmg = 42, susp = 35 weapons[2] = new WeaponInformation("m1014", 8, 8, 500, 1040f, 42, Weapon.AmmoTyp.Shell, Weapon.WeaponSlot.Primary, Equipment.EquipmentType.Useable, "m1014_proj"); //mobility = 42, dmg = 42 weapons[3] = new WeaponInformation("mp5", 30, 4, 800, 2290, 45, Weapon.AmmoTyp.Clip, Weapon.WeaponSlot.Primary, Equipment.EquipmentType.Useable, "mp5_proj"); //mobility = 45, dmg = 29, susp = 21 weapons[4] = new WeaponInformation("p90", 50, 3, 970, 2290, 45, Weapon.AmmoTyp.Clip, Weapon.WeaponSlot.Primary, Equipment.EquipmentType.Useable, "p90_proj"); //mobility = 45, dmg = 20, susp = 15 weapons[5] = new WeaponInformation("sniper", 10, 4, 100, 3120, 20, Weapon.AmmoTyp.Clip, Weapon.WeaponSlot.Primary, Equipment.EquipmentType.Useable, "sniper_proj"); //mobility = 20, dmg = 75 weapons[6] = new WeaponInformation("ak12", 30, 4, 850, 3130, 40, Weapon.AmmoTyp.Clip, Weapon.WeaponSlot.Primary, Equipment.EquipmentType.Useable, "ak12_proj"); //dmg = 44. 33 weapons[7] = new WeaponInformation("f2", 30, 4, 980, 3040, 40, Weapon.AmmoTyp.Clip, Weapon.WeaponSlot.Primary, Equipment.EquipmentType.Useable, "f2_proj"); //dmg = 39, 29 weapons[8] = new WeaponInformation("g36c", 30, 4, 780, 3100, 41, Weapon.AmmoTyp.Clip, Weapon.WeaponSlot.Primary, Equipment.EquipmentType.Useable, "g36c_proj"); //dmg = 38, 28 weapons[11] = new WeaponInformation("ump45", 25, 4, 600, 2290, 45, Weapon.AmmoTyp.Clip, Weapon.WeaponSlot.Primary, Equipment.EquipmentType.Useable, "ump45_proj"); //mobility = 20, dmg = 38, 28 weapons[12] = new WeaponInformation("super", 8, 6, 350, 1190, 40, Weapon.AmmoTyp.Shell, Weapon.WeaponSlot.Primary, Equipment.EquipmentType.Useable, "super_proj"); //mobility = 40, dmg = 90, 36 weapons[13] = new WeaponInformation("m249", 100, 2, 870, 3290, 20, Weapon.AmmoTyp.Clip, Weapon.WeaponSlot.Primary, Equipment.EquipmentType.Useable, "m249_proj"); //mobility = 20, dmg = 33, 24 weapons[1] = new WeaponInformation("deagle", 7, 8, 330, 3000f, 45, Weapon.AmmoTyp.Clip, Weapon.WeaponSlot.Secondary, Equipment.EquipmentType.Useable, "deagle_proj"); //mobility = 45, dmg = 57 weapons[9] = new WeaponInformation("p9", 16, 5, 360, 2120, 60, Weapon.AmmoTyp.Clip, Weapon.WeaponSlot.Secondary, Equipment.EquipmentType.Useable, "p9_proj"); //mobility = 20, dmg = 30, 25 weapons[10] = new WeaponInformation("p12", 15, 5, 420, 2200, 60, Weapon.AmmoTyp.Clip, Weapon.WeaponSlot.Secondary, Equipment.EquipmentType.Useable, "p12_proj"); //mobility = 20, dmg = 43, 36 ProjectileInformation[] projectiles = new ProjectileInformation[14]; projectiles[0] = new ProjectileInformation("416-c_proj", 42, 35, 0, 3f, 10000f, false); projectiles[1] = new ProjectileInformation("deagle_proj", 57, 0, 0, 3f, 10000f, false); projectiles[2] = new ProjectileInformation("m1014_proj", 42, 0, 0, 3f, 10000f, false); projectiles[3] = new ProjectileInformation("mp5_proj", 29, 21, 0, 3f, 10000f, false); projectiles[4] = new ProjectileInformation("p90_proj", 20, 15, 0, 3f, 10000f, false); projectiles[5] = new ProjectileInformation("sniper_proj", 75, 0, 0, 3f, 10000f, false); projectiles[6] = new ProjectileInformation("ak12_proj", 44, 33, 0, 3f, 10000f, false); projectiles[7] = new ProjectileInformation("f2_proj", 39, 29, 0, 3f, 10000f, false); projectiles[8] = new ProjectileInformation("g36c_proj", 38, 28, 0, 3f, 10000f, false); projectiles[9] = new ProjectileInformation("p9_proj", 30, 25, 0, 3f, 10000f, false); projectiles[10] = new ProjectileInformation("p12_proj", 43, 36, 0, 3f, 10000f, false); projectiles[11] = new ProjectileInformation("ump45_proj", 38, 28, 0, 3f, 10000f, false); projectiles[12] = new ProjectileInformation("super_proj", 90, 46, 0, 3f, 10000f, false); projectiles[13] = new ProjectileInformation("m249_proj", 33, 24, 0, 3f, 10000f, false); WeaponContainer container = new WeaponContainer(weapons, projectiles); string path = "Content/Weapons/weapons.xml"; if (File.Exists(path)) { File.Delete(path); } XmlSerializer xml = new XmlSerializer(typeof(WeaponContainer)); using (FileStream stream = new FileStream(path, FileMode.CreateNew, FileAccess.ReadWrite)) { xml.Serialize(stream, container); } }