Exemplo n.º 1
0
 public void AddWeapon(
     WeaponComponentData weaponComponentData,
     ItemModifierGroup itemModifierGroup)
 {
     this.ItemModifierGroup = itemModifierGroup;
     this._weaponList.Add(weaponComponentData);
 }
Exemplo n.º 2
0
 public void AddWeapon(WeaponComponentData weapon, ItemModifierGroup itemModifierGroup)
 {
     if (this.WeaponComponent == null)
     {
         this.ItemComponent = (ItemComponent) new WeaponComponent(this);
     }
     this.WeaponComponent.AddWeapon(weapon, itemModifierGroup);
 }
Exemplo n.º 3
0
        public ItemModifier GetRandomModifierWithTarget(float targetQuality = 1f, float variance = 1f)
        {
            float num1 = 0.0f;

            foreach (ItemModifierProbability modifierProbability in this.ItemModifiersWithProbability.Values)
            {
                num1 += ItemModifierGroup.GetProb(modifierProbability.ItemModifier, targetQuality);
            }
            float num2 = MBRandom.RandomFloat * num1;

            foreach (ItemModifierProbability modifierProbability in this.ItemModifiersWithProbability.Values)
            {
                float prob = ItemModifierGroup.GetProb(modifierProbability.ItemModifier, targetQuality);
                num2 -= prob;
                if ((double)num2 < -1.0000000116861E-07)
                {
                    return(modifierProbability.ItemModifier);
                }
            }
            return((ItemModifier)null);
        }
Exemplo n.º 4
0
        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();
        }