public static WeaponDesignElement CreateUsablePiece( CraftingPiece craftingPiece, int scalePercentage = 100) { return(new WeaponDesignElement(craftingPiece, scalePercentage)); }
private WeaponDesignElement(CraftingPiece craftingPiece, int scalePercentage = 100) { this._craftingPiece = craftingPiece; this.ScalePercentage = scalePercentage; }
public override void Deserialize(MBObjectManager objectManager, XmlNode node) { base.Deserialize(objectManager, node); if (node.Name == "CraftedItem") { XmlNode attribute1 = (XmlNode)node.Attributes["multiplayer_item"]; if (attribute1 != null && !string.IsNullOrEmpty(attribute1.InnerText)) { this.MultiplayerItem = attribute1.InnerText == "true"; } XmlNode attribute2 = (XmlNode)node.Attributes["is_merchandise"]; if (attribute2 != null && !string.IsNullOrEmpty(attribute2.InnerText)) { this.NotMerchandise = attribute2.InnerText != "true"; } TextObject weaponName = new TextObject(node.Attributes["name"].InnerText); string innerText1 = node.Attributes["crafting_template"].InnerText; int num = node.Attributes["has_modifier"] == null ? 1 : (node.Attributes["has_modifier"].InnerText != "false" ? 1 : 0); string objectName = node.Attributes["item_modifier_group"]?.Value; ItemModifierGroup itemModifierGroup = (ItemModifierGroup)null; if (num != 0) { itemModifierGroup = objectName != null?Game.Current.ObjectManager.GetObject <ItemModifierGroup>(objectName) : CraftingTemplate.GetTemplateFromId(innerText1).ItemModifierGroup; } WeaponDesignElement[] usedPieces = new WeaponDesignElement[4]; XmlNode xmlNode = (XmlNode)null; for (int i = 0; i < node.ChildNodes.Count; ++i) { if (node.ChildNodes[i].Name == "Pieces") { xmlNode = node.ChildNodes[i]; break; } } foreach (XmlNode childNode in xmlNode.ChildNodes) { if (childNode.Name == "Piece") { XmlAttribute attribute3 = childNode.Attributes["id"]; XmlAttribute attribute4 = childNode.Attributes["Type"]; XmlAttribute attribute5 = childNode.Attributes["scale_factor"]; string innerText2 = attribute3.InnerText; CraftingPiece.PieceTypes pieceTypes = (CraftingPiece.PieceTypes)Enum.Parse(typeof(CraftingPiece.PieceTypes), attribute4.InnerText); CraftingPiece craftingPiece = MBObjectManager.Instance.GetObject <CraftingPiece>(innerText2); usedPieces[(int)pieceTypes] = WeaponDesignElement.CreateUsablePiece(craftingPiece); if (attribute5 != null) { usedPieces[(int)pieceTypes].SetScale(int.Parse(attribute5.Value)); } } } float weightOverriden = node.Attributes["weight"] != null?float.Parse(node.Attributes["weight"].Value) : 0.0f; int swingSpeedOverriden = node.Attributes["swing_speed"] != null?int.Parse(node.Attributes["swing_speed"].Value) : 0; int thrustSpeedOverriden = node.Attributes["thrust_speed"] != null?int.Parse(node.Attributes["thrust_speed"].Value) : 0; int swingDamageOverriden = node.Attributes["swing_damage"] != null?int.Parse(node.Attributes["swing_damage"].Value) : 0; int thrustDamageOverriden = node.Attributes["thrust_damage"] != null?int.Parse(node.Attributes["thrust_damage"].Value) : 0; ItemObject preCraftedWeapon = Crafting.CreatePreCraftedWeapon(this, usedPieces, innerText1, weaponName, new Crafting.OverrideData(weightOverriden, swingSpeedOverriden, thrustSpeedOverriden, swingDamageOverriden, thrustDamageOverriden), itemModifierGroup); if (DefaultItems.Instance != null && preCraftedWeapon == DefaultItems.Trash) { MBObjectManager.Instance.UnregisterObject((MBObjectBase)this); return; } this.Effectiveness = this.CalculateEffectiveness(); this.Value = node.Attributes["value"] != null?int.Parse(node.Attributes["value"].Value) : this.CalculateValue(); if (node.Attributes["culture"] != null) { this.Culture = (BasicCultureObject)objectManager.ReadObjectReferenceFromXml("culture", typeof(BasicCultureObject), node); } this.PrerequisiteItem = node.Attributes["prerequisite_item"] != null ? (ItemObject)objectManager.ReadObjectReferenceFromXml("prerequisite_item", typeof(ItemObject), node) : (ItemObject)null; } else { this.Name = new TextObject(node.Attributes["name"].InnerText); XmlNode attribute1 = (XmlNode)node.Attributes["multiplayer_item"]; if (attribute1 != null && !string.IsNullOrEmpty(attribute1.InnerText)) { this.MultiplayerItem = attribute1.InnerText == "true"; } XmlNode attribute2 = (XmlNode)node.Attributes["is_merchandise"]; if (attribute2 != null && !string.IsNullOrEmpty(attribute2.InnerText)) { this.NotMerchandise = attribute2.InnerText != "true"; } this.PrerequisiteItem = node.Attributes["prerequisite_item"] != null ? (ItemObject)objectManager.ReadObjectReferenceFromXml("prerequisite_item", typeof(ItemObject), node) : (ItemObject)null; XmlNode attribute3 = (XmlNode)node.Attributes["mesh"]; if (attribute3 != null && !string.IsNullOrEmpty(attribute3.InnerText)) { this.MultiMeshName = attribute3.InnerText; } this.HolsterMeshName = node.Attributes["holster_mesh"] != null ? node.Attributes["holster_mesh"].Value : (string)null; this.HolsterWithWeaponMeshName = node.Attributes["holster_mesh_with_weapon"] != null ? node.Attributes["holster_mesh_with_weapon"].Value : (string)null; this.FlyingMeshName = node.Attributes["flying_mesh"] != null ? node.Attributes["flying_mesh"].Value : (string)null; this.HasLowerHolsterPriority = false; if (node.Attributes["item_holsters"] != null) { this.ItemHolsters = node.Attributes["item_holsters"].Value.Split(':'); if (node.Attributes["has_lower_holster_priority"] != null) { this.HasLowerHolsterPriority = bool.Parse(node.Attributes["has_lower_holster_priority"].Value); } } this.HolsterPositionShift = node.Attributes["holster_position_shift"] != null?Vec3.Parse(node.Attributes["holster_position_shift"].Value) : Vec3.Zero; this.BodyName = node.Attributes["body_name"] != null ? node.Attributes["body_name"].Value : (string)null; this.HolsterBodyName = node.Attributes["holster_body_name"] != null ? node.Attributes["holster_body_name"].Value : (string)null; this.CollisionBodyName = node.Attributes["shield_body_name"] != null ? node.Attributes["shield_body_name"].Value : (string)null; this.RecalculateBody = node.Attributes["recalculate_body"] != null && bool.Parse(node.Attributes["recalculate_body"].Value); XmlNode attribute4 = (XmlNode)node.Attributes["prefab"]; this.PrefabName = attribute4 == null || string.IsNullOrEmpty(attribute4.InnerText) ? "" : attribute4.InnerText; this.Culture = (BasicCultureObject)objectManager.ReadObjectReferenceFromXml("culture", typeof(BasicCultureObject), node); string objectName = node.Attributes["item_category"] != null ? node.Attributes["item_category"].Value : (string)null; if (!string.IsNullOrEmpty(objectName)) { this.ItemCategory = Game.Current.ObjectManager.GetObject <ItemCategory>(objectName); } this.Weight = node.Attributes["weight"] != null?float.Parse(node.Attributes["weight"].Value) : 1f; this.LodAtlasIndex = node.Attributes["lod_atlas_index"] != null?int.Parse(node.Attributes["lod_atlas_index"].Value) : -1; XmlAttribute attribute5 = node.Attributes["difficulty"]; if (attribute5 != null) { this.Difficulty = int.Parse(attribute5.Value); } XmlAttribute attribute6 = node.Attributes["appearance"]; this.Appearance = attribute6 != null?float.Parse(attribute6.Value) : 0.5f; XmlAttribute attribute7 = node.Attributes["IsFood"]; if (attribute7 != null) { this.IsFood = Convert.ToBoolean(attribute7.InnerText); } this.IsUsingTableau = node.Attributes["using_tableau"] != null && Convert.ToBoolean(node.Attributes["using_tableau"].InnerText); XmlNode attribute8 = (XmlNode)node.Attributes["using_arm_band"]; if (attribute8 != null) { this.ArmBandMeshName = Convert.ToString(attribute8.InnerText); } this.ScaleFactor = node.Attributes["scale_factor"] != null?float.Parse(node.Attributes["scale_factor"].Value) : 1f; this.ItemFlags = (ItemFlags)0; foreach (XmlNode childNode1 in node.ChildNodes) { if (childNode1.Name == "ItemComponent") { foreach (XmlNode childNode2 in childNode1.ChildNodes) { if (childNode2.NodeType != XmlNodeType.Comment) { string name = childNode2.Name; ItemComponent itemComponent; if (!(name == "Armor")) { if (!(name == "Weapon")) { if (!(name == "Horse")) { if (!(name == "Trade")) { if (!(name == "Food")) { throw new Exception("Wrong ItemComponent type."); } itemComponent = (ItemComponent)null; } else { itemComponent = (ItemComponent) new TradeItemComponent(); } } else { itemComponent = (ItemComponent) new HorseComponent(); } } else { itemComponent = (ItemComponent) new WeaponComponent(this); } } else { itemComponent = (ItemComponent) new ArmorComponent(this); } if (itemComponent != null) { itemComponent.Deserialize(objectManager, childNode2); this.ItemComponent = itemComponent; } } } } else if (childNode1.Name == "Flags") { foreach (ItemFlags itemFlags in Enum.GetValues(typeof(ItemFlags))) { XmlAttribute attribute9 = childNode1.Attributes[itemFlags.ToString()]; if (attribute9 != null && attribute9.Value.ToLowerInvariant() != "false") { this.ItemFlags |= itemFlags; } } } } XmlAttribute attribute10 = node.Attributes["Type"]; if (attribute10 != null) { this.Type = (ItemObject.ItemTypeEnum)Enum.Parse(typeof(ItemObject.ItemTypeEnum), attribute10.Value, true); if (this.WeaponComponent != null) { ItemObject.ItemTypeEnum itemType = this.WeaponComponent.GetItemType(); if (this.Type != itemType) { TaleWorlds.Library.Debug.Print("ItemType for \"" + this.StringId + "\" has been overridden by WeaponClass from \"" + (object)this.Type + "\" to \"" + (object)itemType + "\"", color: TaleWorlds.Library.Debug.DebugColor.Red, debugFilter: 64UL); } this.Type = itemType; } } XmlAttribute attribute11 = node.Attributes["AmmoOffset"]; if (attribute11 != null) { string[] strArray = attribute11.Value.Split(','); this.WeaponComponent.PrimaryWeapon.SetAmmoOffset(new Vec3()); if (strArray.Length == 3) { try { this.WeaponComponent.PrimaryWeapon.SetAmmoOffset(new Vec3(float.Parse(strArray[0], (IFormatProvider)CultureInfo.InvariantCulture), float.Parse(strArray[1], (IFormatProvider)CultureInfo.InvariantCulture), float.Parse(strArray[2], (IFormatProvider)CultureInfo.InvariantCulture))); } catch (Exception ex) { } } } this.Effectiveness = this.CalculateEffectiveness(); this.Value = node.Attributes["value"] != null?int.Parse(node.Attributes["value"].Value) : this.CalculateValue(); if (this.PrimaryWeapon != null) { if (this.PrimaryWeapon.IsMeleeWeapon || this.PrimaryWeapon.IsRangedWeapon) { if (!string.IsNullOrEmpty(this.BodyName)) { ; } } else if (this.PrimaryWeapon.IsConsumable) { string.IsNullOrEmpty(this.HolsterBodyName); if (!string.IsNullOrEmpty(this.BodyName)) { ; } } else if (this.PrimaryWeapon.IsShield) { if (!string.IsNullOrEmpty(this.BodyName)) { int num = this.RecalculateBody ? 1 : 0; } string.IsNullOrEmpty(this.CollisionBodyName); } } } this.DetermineItemCategoryForItem(); }
public ImageIdentifier(CraftingPiece craftingPiece, string pieceUsageId) { this.ImageTypeCode = ImageIdentifierType.CraftingPiece; this.Id = craftingPiece != null ? craftingPiece.StringId + "$" + pieceUsageId : ""; this.AdditionalArgs = ""; }
public override void Deserialize(MBObjectManager objectManager, XmlNode node) { base.Deserialize(objectManager, node); this._hiddenPieceTypesOnHolsteredMesh = new bool[4]; string objectName = node.Attributes["item_modifier_group"] != null ? node.Attributes["item_modifier_group"].Value : (string)null; if (objectName != null) { this.ItemModifierGroup = Game.Current.ObjectManager.GetObject <ItemModifierGroup>(objectName); } this.ItemHolsters = node.Attributes["item_holsters"].Value.Split(':'); this.ItemHolsterPositionShift = Vec3.Parse(node.Attributes["default_item_holster_position_offset"].Value); this.UseWeaponAsHolsterMesh = XmlHelper.ReadBool(node, "use_weapon_as_holster_mesh"); this.AlwaysShowHolsterWithWeapon = XmlHelper.ReadBool(node, "always_show_holster_with_weapon"); this.RotateWeaponInHolster = XmlHelper.ReadBool(node, "rotate_weapon_in_holster"); XmlAttribute attribute1 = node.Attributes["piece_type_to_scale_holster_with"]; this.PieceTypeToScaleHolsterWith = attribute1 != null ? (CraftingPiece.PieceTypes)Enum.Parse(typeof(CraftingPiece.PieceTypes), attribute1.Value) : CraftingPiece.PieceTypes.Invalid; XmlAttribute attribute2 = node.Attributes["hidden_piece_types_on_holster"]; if (attribute2 != null) { string str1 = attribute2.Value; char[] chArray = new char[1] { ',' }; foreach (string str2 in str1.Split(chArray)) { this._hiddenPieceTypesOnHolsteredMesh[(int)Enum.Parse(typeof(CraftingPiece.PieceTypes), str2)] = true; } } foreach (XmlNode childNode1 in node.ChildNodes) { if (childNode1.Attributes != null) { string name = childNode1.Name; if (!(name == "PieceDatas")) { if (!(name == "WeaponUsageDatas")) { if (!(name == "UsablePieces")) { if (name == "StatsData") { XmlAttribute attribute3 = childNode1.Attributes["usage_data"]; float[] numArray = new float[10]; for (int index = 0; index < numArray.Length; ++index) { numArray[index] = float.MinValue; } foreach (XmlNode childNode2 in childNode1.ChildNodes) { if (childNode2.NodeType == XmlNodeType.Element) { XmlAttribute attribute4 = childNode2.Attributes["stat_type"]; XmlAttribute attribute5 = childNode2.Attributes["max_value"]; CraftingTemplate.CraftingStatTypes craftingStatTypes = (CraftingTemplate.CraftingStatTypes)Enum.Parse(typeof(CraftingTemplate.CraftingStatTypes), attribute4.Value); float num = float.Parse(attribute5.Value); numArray[(int)craftingStatTypes] = num; } } if (attribute3 != null) { this._statDataValues[this.GetIndexOfUsageDataWithId(attribute3.Value)] = numArray; } else { for (int index = 0; index < this._statDataValues.Length; ++index) { this._statDataValues[index] = numArray; } } } } else { this._craftingPieces = new List <CraftingPiece>(); foreach (XmlNode childNode2 in childNode1.ChildNodes) { CraftingPiece craftingPiece = MBObjectManager.Instance.GetObject <CraftingPiece>(childNode2.Attributes["piece_id"].Value); if (craftingPiece != null) { this._craftingPieces.Add(craftingPiece); } } } } else { List <WeaponUsageData> weaponUsageDataList = new List <WeaponUsageData>(); foreach (XmlNode childNode2 in childNode1.ChildNodes) { string id = childNode2.Attributes["id"].Value; weaponUsageDataList.Add(WeaponUsageDataManager.All.First <WeaponUsageData>((Func <WeaponUsageData, bool>)(wud => wud.WeaponUsageDataId == id))); } this._weaponUsageDatas = weaponUsageDataList.ToArray(); this._statDataValues = new float[this._weaponUsageDatas.Length][]; } } else { List <PieceData> pieceDataList = new List <PieceData>(); foreach (XmlNode childNode2 in childNode1.ChildNodes) { XmlAttribute attribute3 = childNode2.Attributes["piece_type"]; XmlAttribute attribute4 = childNode2.Attributes["build_order"]; CraftingPiece.PieceTypes pieceType = (CraftingPiece.PieceTypes)Enum.Parse(typeof(CraftingPiece.PieceTypes), attribute3.Value); int order = int.Parse(attribute4.Value); pieceDataList.Add(new PieceData(pieceType, order)); } this._buildOrders = pieceDataList.ToArray(); } } } this.TemplateName = GameTexts.FindText("str_crafting_template", this.StringId); }