예제 #1
0
 public WeaponComponentData(ItemObject item, WeaponClass weaponClass = WeaponClass.Undefined, WeaponFlags weaponFlags = (WeaponFlags)0)
 {
     this.BodyArmor         = 0;
     this.PhysicsMaterial   = "";
     this.FlyingSoundCode   = "";
     this.PassbySoundCode   = "";
     this.ItemUsage         = (string)null;
     this.SwingSpeed        = 0;
     this.ThrustSpeed       = 0;
     this.MissileSpeed      = 0;
     this.WeaponLength      = 0;
     this.ThrustDamage      = 0;
     this.SwingDamage       = 0;
     this.AmmoOffset        = Vec3.Zero;
     this.Accuracy          = 0;
     this.StickingFrame     = MatrixFrame.Identity;
     this.TrailParticleName = "";
     this.WeaponClass       = weaponClass;
     this.WeaponFlags       = weaponFlags;
     this.Frame             = MatrixFrame.Identity;
     this.RotationSpeed     = Vec3.Zero;
 }
예제 #2
0
 internal static ItemObject InitializeTradeGood(
     ItemObject item,
     TextObject name,
     string meshName,
     ItemCategory category,
     int value,
     float weight,
     ItemObject.ItemTypeEnum itemType,
     bool isFood)
 {
     item.Initialize();
     item.Name          = name;
     item.MultiMeshName = meshName;
     item.ItemCategory  = category;
     item.Value         = value;
     item.Weight        = weight;
     item.ItemType      = itemType;
     item.IsFood        = isFood;
     item.ItemComponent = (ItemComponent) new TradeItemComponent();
     item.AfterInitialized();
     item.ItemFlags |= ItemFlags.Civilian;
     return(item);
 }
예제 #3
0
        private float CalculateTierNonCraftedWeapon(WeaponComponent weaponComponent)
        {
            ItemObject itemObject = weaponComponent.Item;

            switch (itemObject != null ? itemObject.ItemType : ItemObject.ItemTypeEnum.Invalid)
            {
            case ItemObject.ItemTypeEnum.Arrows:
            case ItemObject.ItemTypeEnum.Bolts:
            case ItemObject.ItemTypeEnum.Bullets:
                return(this.CalculateAmmoTier(weaponComponent));

            case ItemObject.ItemTypeEnum.Shield:
                return(this.CalculateShieldTier(weaponComponent));

            case ItemObject.ItemTypeEnum.Bow:
            case ItemObject.ItemTypeEnum.Crossbow:
            case ItemObject.ItemTypeEnum.Pistol:
            case ItemObject.ItemTypeEnum.Musket:
                return(this.CalculateRangedWeaponTier(weaponComponent));

            default:
                return(0.0f);
            }
        }
예제 #4
0
        private float CalculateRangedWeaponTier(WeaponComponent weaponComponent)
        {
            WeaponComponentData weapon     = weaponComponent.Weapons[0];
            ItemObject          itemObject = weaponComponent.Item;
            double num1;

            switch (itemObject != null ? itemObject.ItemType : ItemObject.ItemTypeEnum.Invalid)
            {
            case ItemObject.ItemTypeEnum.Crossbow:
                num1 = 0.699999988079071;
                break;

            case ItemObject.ItemTypeEnum.Musket:
                num1 = 0.5;
                break;

            default:
                num1 = 1.0;
                break;
            }
            double num2 = (double)weapon.ThrustDamage * 0.200000002980232 + (double)weapon.ThrustSpeed * 0.0199999995529652 + (double)weapon.Accuracy * 0.0199999995529652;

            return((float)(num1 * num2 - 11.0));
        }
예제 #5
0
 public ImageIdentifier(ItemObject itemObject)
 {
     this.ImageTypeCode  = ImageIdentifierType.Item;
     this.Id             = itemObject.StringId;
     this.AdditionalArgs = "";
 }
예제 #6
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();
        }
예제 #7
0
 public static void InitAsPlayerCraftedItem(ref ItemObject itemObject) => itemObject.IsCraftedByPlayer = true;
 public EquipmentElement(ItemObject item, ItemModifier itemModifier = null)
 {
     this.Item         = item;
     this.ItemModifier = itemModifier;
 }
예제 #9
0
 private float GetWeaponPriceFactor(ItemObject item) => 100f;
예제 #10
0
 public WeaponComponent(ItemObject item) => this.Item = item;
예제 #11
0
        public void Deserialize(ItemObject item, XmlNode node)
        {
            this.BodyArmor = node.Attributes["body_armor"] != null?int.Parse(node.Attributes["body_armor"].Value) : 0;

            this.PhysicsMaterial = node.Attributes["physics_material"]?.Value;
            this.FlyingSoundCode = node.Attributes["flying_sound_code"]?.Value;
            this.PassbySoundCode = node.Attributes["passby_sound_code"]?.Value;
            this.ItemUsage       = node.Attributes["item_usage"]?.Value;
            this.WeaponBalance   = node.Attributes["weapon_balance"] != null ? (float)int.Parse(node.Attributes["weapon_balance"].Value) * 0.01f : 0.0f;
            this.SwingSpeed      = node.Attributes["speed_rating"] != null?int.Parse(node.Attributes["speed_rating"].Value) : 0;

            this.ThrustSpeed = node.Attributes["thrust_speed"] != null?int.Parse(node.Attributes["thrust_speed"].Value) : 0;

            this.MissileSpeed = node.Attributes["missile_speed"] != null?int.Parse(node.Attributes["missile_speed"].Value) : 0;

            this.WeaponLength = node.Attributes["weapon_length"] != null?int.Parse(node.Attributes["weapon_length"].Value) : 0;

            this.ThrustDamage = node.Attributes["thrust_damage"] != null?int.Parse(node.Attributes["thrust_damage"].Value) : 0;

            this.SwingDamage = node.Attributes["swing_damage"] != null?int.Parse(node.Attributes["swing_damage"].Value) : 0;

            this.Accuracy = node.Attributes["accuracy"] != null?int.Parse(node.Attributes["accuracy"].Value) : 100;

            this.ThrustDamageType = node.Attributes["thrust_damage_type"] != null ? (DamageTypes)Enum.Parse(typeof(DamageTypes), node.Attributes["thrust_damage_type"].Value) : DamageTypes.Blunt;
            this.SwingDamageType  = node.Attributes["swing_damage_type"] != null ? (DamageTypes)Enum.Parse(typeof(DamageTypes), node.Attributes["swing_damage_type"].Value) : DamageTypes.Blunt;
            this.WeaponClass      = node.Attributes["weapon_class"] != null ? (WeaponClass)Enum.Parse(typeof(WeaponClass), node.Attributes["weapon_class"].Value) : WeaponClass.Undefined;
            this.AmmoClass        = node.Attributes["ammo_class"] != null ? (WeaponClass)Enum.Parse(typeof(WeaponClass), node.Attributes["ammo_class"].Value) : WeaponClass.Undefined;
            this.CenterOfMass     = (float)((double)this.WeaponLength * 0.5 * 0.00999999977648258);
            this.CenterOfMass3D   = node.Attributes["center_of_mass"] != null?Vec3.Parse(node.Attributes["center_of_mass"].Value) : Vec3.Zero;

            if (this.WeaponClass != WeaponClass.Bow && this.WeaponClass != WeaponClass.Crossbow && (this.WeaponClass != WeaponClass.SmallShield && this.WeaponClass != WeaponClass.LargeShield) && (this.WeaponClass != WeaponClass.Arrow && this.WeaponClass != WeaponClass.Bolt && (this.WeaponClass != WeaponClass.ThrowingKnife && this.WeaponClass != WeaponClass.ThrowingAxe)) && (this.WeaponClass != WeaponClass.Javelin && this.WeaponClass != WeaponClass.Stone))
            {
                int weaponClass = (int)this.WeaponClass;
            }
            XmlAttribute attribute1 = node.Attributes["ammo_limit"];
            XmlAttribute attribute2 = node.Attributes["stack_amount"];
            XmlAttribute attribute3 = node.Attributes["hit_points"];

            this.MaxDataValue = attribute1 == null ? (attribute2 == null ? (attribute3 == null ? (short)0 : short.Parse(attribute3.Value)) : short.Parse(attribute2.Value)) : short.Parse(attribute1.Value);
            Vec3    vec3       = new Vec3();
            Mat3    identity1  = Mat3.Identity;
            XmlNode attribute4 = (XmlNode)node.Attributes["sticking_position"];

            if (attribute4 != null)
            {
                string[] strArray = attribute4.Value.Split(',');
                if (strArray.Length == 3)
                {
                    float.TryParse(strArray[0], out vec3.x);
                    float.TryParse(strArray[1], out vec3.y);
                    float.TryParse(strArray[2], out vec3.z);
                }
            }
            XmlNode attribute5 = (XmlNode)node.Attributes["sticking_rotation"];

            if (attribute5 != null)
            {
                string[] strArray = attribute5.Value.Split(',');
                if (strArray.Length == 3)
                {
                    float result1;
                    float.TryParse(strArray[0], out result1);
                    float result2;
                    float.TryParse(strArray[1], out result2);
                    float result3;
                    float.TryParse(strArray[2], out result3);
                    identity1.RotateAboutSide(result1.ToRadians());
                    identity1.RotateAboutUp(result2.ToRadians());
                    identity1.RotateAboutForward(result3.ToRadians());
                }
            }
            vec3 = identity1.TransformToParent(vec3);
            this.StickingFrame = new MatrixFrame(identity1, vec3);
            Vec3    o          = new Vec3();
            Mat3    identity2  = Mat3.Identity;
            XmlNode attribute6 = (XmlNode)node.Attributes["position"];

            if (attribute6 != null)
            {
                string[] strArray = attribute6.Value.Split(',');
                if (strArray.Length == 3)
                {
                    float.TryParse(strArray[0], out o.x);
                    float.TryParse(strArray[1], out o.y);
                    float.TryParse(strArray[2], out o.z);
                }
            }
            XmlNode attribute7 = (XmlNode)node.Attributes["rotation"];

            if (attribute7 != null)
            {
                string[] strArray = attribute7.Value.Split(',');
                if (strArray.Length == 3)
                {
                    float result1;
                    float.TryParse(strArray[0], out result1);
                    float result2;
                    float.TryParse(strArray[1], out result2);
                    float result3;
                    float.TryParse(strArray[2], out result3);
                    identity2.RotateAboutUp(result3.ToRadians());
                    identity2.RotateAboutSide(result1.ToRadians());
                    identity2.RotateAboutForward(result2.ToRadians());
                }
            }
            this.Frame         = new MatrixFrame(identity2, o);
            this.RotationSpeed = node.Attributes["rotation_speed"] != null?Vec3.Parse(node.Attributes["rotation_speed"].Value) : Vec3.Zero;

            this.TrailParticleName = node.Attributes["trail_particle_name"]?.Value;
            foreach (XmlNode childNode in node.ChildNodes)
            {
                if (childNode.Name == "WeaponFlags")
                {
                    foreach (WeaponFlags weaponFlags in Enum.GetValues(typeof(WeaponFlags)))
                    {
                        if (childNode.Attributes[weaponFlags.ToString()] != null)
                        {
                            this.WeaponFlags |= weaponFlags;
                        }
                    }
                }
            }
            this.Inertia        = item.Weight * 0.05f;
            this.Handling       = this.ThrustSpeed;
            this.SweetSpotReach = 0.93f;
            this.SetDamageFactors(item.Weight);
        }
 public ArmorComponent(ItemObject item) => this.Item = item;