コード例 #1
0
 private static void UpgradeXml()
 {
     try
     {
         FileWatcher.EnableRaisingEvents = false;
         using (StreamWriter sw = new StreamWriter(FilePath, false, Encoding.UTF8))
         {
             sw.WriteLine("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
             sw.WriteLine("<KillNotice>");
             sw.WriteLine(string.Format("<ST Version=\"{0}\" />", Config.Version));
             sw.WriteLine("    <!-- <Weapon Name=\"\" NewName=\"\" /> -->");
             for (int i = 0; i < OldNodeList.Count; i++)
             {
                 if (OldNodeList[i].NodeType == XmlNodeType.Comment && !OldNodeList[i].OuterXml.Contains("<!-- <Weapon Name=\"\""))
                 {
                     sw.WriteLine(OldNodeList[i].OuterXml);
                 }
             }
             sw.WriteLine();
             sw.WriteLine();
             bool blank = true;
             for (int i = 0; i < OldNodeList.Count; i++)
             {
                 if (OldNodeList[i].NodeType != XmlNodeType.Comment)
                 {
                     XmlElement line = (XmlElement)OldNodeList[i];
                     if (line.HasAttributes && line.Name == "Weapon")
                     {
                         blank = false;
                         string name = "", newName = "";
                         if (line.HasAttribute("Name"))
                         {
                             name = line.GetAttribute("Name");
                         }
                         if (line.HasAttribute("NewName"))
                         {
                             newName = line.GetAttribute("NewName");
                         }
                         sw.WriteLine(string.Format("    <Weapon Name=\"{0}\" NewName=\"{1}\" />", name, newName));
                     }
                 }
             }
             if (blank)
             {
                 List <ItemClass> _itemClassMelee  = ItemClass.GetItemsWithTag(FastTags.Parse("melee"));
                 List <ItemClass> _itemClassRanged = ItemClass.GetItemsWithTag(FastTags.Parse("ranged"));
                 for (int i = 0; i < _itemClassMelee.Count; i++)
                 {
                     ItemClass     _itemClass = _itemClassMelee[i];
                     List <string> _tags      = _itemClass.ItemTags.GetTagNames();
                     if (_itemClass.CreativeMode != EnumCreativeMode.None && _itemClass.CreativeMode != EnumCreativeMode.Dev && !_tags.Contains("ammo"))
                     {
                         sw.WriteLine(string.Format("    <Weapon Name=\"{0}\" NewName=\"{1}\" />", _itemClass.GetItemName(), _itemClass.GetLocalizedItemName() ?? _itemClass.GetItemName()));
                     }
                 }
                 for (int i = 0; i < _itemClassRanged.Count; i++)
                 {
                     ItemClass     _itemClass = _itemClassRanged[i];
                     List <string> _tags      = _itemClass.ItemTags.GetTagNames();
                     if (_itemClass.CreativeMode != EnumCreativeMode.None && _itemClass.CreativeMode != EnumCreativeMode.Dev && !_tags.Contains("ammo"))
                     {
                         sw.WriteLine(string.Format("    <Weapon Name=\"{0}\" NewName=\"{1}\" />", _itemClass.GetItemName(), _itemClass.GetLocalizedItemName() ?? _itemClass.GetItemName()));
                     }
                 }
             }
             sw.WriteLine("</KillNotice>");
             sw.Flush();
             sw.Close();
         }
     }
     catch (Exception e)
     {
         Log.Out(string.Format("[SERVERTOOLS] Error in KillNotice.UpgradeXml: {0}", e.Message));
     }
     FileWatcher.EnableRaisingEvents = true;
     LoadXml();
 }
コード例 #2
0
 private static void UpdateXml()
 {
     try
     {
         FileWatcher.EnableRaisingEvents = false;
         using (StreamWriter sw = new StreamWriter(FilePath, false, Encoding.UTF8))
         {
             sw.WriteLine("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
             sw.WriteLine("<KillNotice>");
             sw.WriteLine(string.Format("<ST Version=\"{0}\" />", Config.Version));
             sw.WriteLine("    <!-- <Weapon Name=\"\" NewName=\"\" /> -->");
             sw.WriteLine();
             sw.WriteLine();
             if (Dict.Count > 0)
             {
                 foreach (KeyValuePair <string, string> kvp in Dict)
                 {
                     sw.WriteLine(string.Format("    <Weapon Name=\"{0}\" NewName=\"{1}\" />", kvp.Key, kvp.Value));
                 }
             }
             else
             {
                 List <ItemClass> _itemClassMelee  = ItemClass.GetItemsWithTag(FastTags.Parse("melee"));
                 List <ItemClass> _itemClassRanged = ItemClass.GetItemsWithTag(FastTags.Parse("ranged"));
                 for (int i = 0; i < _itemClassMelee.Count; i++)
                 {
                     ItemClass     _itemClass = _itemClassMelee[i];
                     List <string> _tags      = _itemClass.ItemTags.GetTagNames();
                     if (_itemClass.CreativeMode != EnumCreativeMode.None && _itemClass.CreativeMode != EnumCreativeMode.Dev && !_tags.Contains("ammo"))
                     {
                         sw.WriteLine(string.Format("    <Weapon Name=\"{0}\" NewName=\"{1}\" />", _itemClass.GetItemName(), _itemClass.GetLocalizedItemName() ?? _itemClass.GetItemName()));
                     }
                 }
                 for (int i = 0; i < _itemClassRanged.Count; i++)
                 {
                     ItemClass     _itemClass = _itemClassRanged[i];
                     List <string> _tags      = _itemClass.ItemTags.GetTagNames();
                     if (_itemClass.CreativeMode != EnumCreativeMode.None && _itemClass.CreativeMode != EnumCreativeMode.Dev && !_tags.Contains("ammo"))
                     {
                         sw.WriteLine(string.Format("    <Weapon Name=\"{0}\" NewName=\"{1}\" />", _itemClass.GetItemName(), _itemClass.GetLocalizedItemName() ?? _itemClass.GetItemName()));
                     }
                 }
             }
             sw.WriteLine("</KillNotice>");
             sw.Flush();
             sw.Close();
         }
     }
     catch (Exception e)
     {
         Log.Out(string.Format("[SERVERTOOLS] Error in KillNotice.UpdateXml: {0}", e.Message));
     }
     FileWatcher.EnableRaisingEvents = true;
 }
コード例 #3
0
        public static bool Prefix(ItemActionEntryScrap __instance)
        {
            // Check if this feature is enabled.
            if (!Configuration.CheckFeatureStatus(AdvFeatureClass, Feature))
            {
                return(true);
            }
            #region vanilla_code
            XUi            xui            = __instance.ItemController.xui;
            XUiC_ItemStack xuiC_ItemStack = (XUiC_ItemStack)__instance.ItemController;

            ItemStack itemStack       = xuiC_ItemStack.ItemStack.Clone();
            Recipe    scrapableRecipe = CraftingManager.GetScrapableRecipe(itemStack.itemValue, itemStack.count);
            if (scrapableRecipe == null)
            {
                return(true);
            }

            XUiController xuiController = __instance.ItemController.xui.FindWindowGroupByName("workstation_workbench");
            if (xuiController == null || !xuiController.WindowGroup.isShowing)
            {
                xuiController = xui.FindWindowGroupByName("crafting");
            }

            XUiC_CraftingWindowGroup childByType = xuiController.GetChildByType <XUiC_CraftingWindowGroup>();
            if (childByType == null)
            {
                return(true);
            }
            #endregion  vanilla_code

            LocalPlayerUI    uiforPlayer = LocalPlayerUI.GetUIForPlayer(__instance.ItemController.xui.playerUI.entityPlayer);
            List <ItemStack> scrapItems  = new List <ItemStack>();

            ItemClass forId = ItemClass.GetForId(itemStack.itemValue.type);
            // Check if ScrapItems is specified
            if (forId.Properties.Classes.ContainsKey("ScrapItems"))
            {
                DynamicProperties dynamicProperties3 = forId.Properties.Classes["ScrapItems"];
                scrapItems = ItemsUtilities.ParseProperties(dynamicProperties3);
                ItemsUtilities.Scrap(scrapItems, itemStack, __instance.ItemController);
                return(false);
            }
            else if (forId.Properties.Contains("ScrapItems")) // Support for <property name="ScrapItems" value="resourceWood,0,resourceLeather,2" />
            {
                string strData = forId.Properties.Values["ScrapItems"].ToString();
                scrapItems = ItemsUtilities.ParseProperties(strData);
                ItemsUtilities.Scrap(scrapItems, itemStack, __instance.ItemController);
                return(false);
            }
            // Check if Repair Items is specified, if the ScrapItems wasn't.
            else if (forId.Properties.Classes.ContainsKey("RepairItems"))
            {
                DynamicProperties dynamicProperties3 = forId.Properties.Classes["RepairItems"];
                scrapItems = ItemsUtilities.ParseProperties(dynamicProperties3);
                ItemsUtilities.Scrap(scrapItems, itemStack, __instance.ItemController);
                return(false);
            }
            else if (forId.RepairTools == null || forId.RepairTools.Length <= 0)
            {
                if (CraftingManager.GetRecipe(forId.GetItemName()) == null)
                {
                    return(true);
                }

                if (CraftingManager.GetRecipe(forId.GetItemName()).tags.Test_AnySet(FastTags.Parse("usevanillascrap")))
                {
                    return(true);
                }

                // If there's a recipe, reduce it
                Recipe recipe = ItemsUtilities.GetReducedRecipes(forId.GetItemName(), 2);

                ItemsUtilities.Scrap(recipe.ingredients, itemStack, __instance.ItemController);
                return(false);
            }
            return(true);
        }
コード例 #4
0
        public static void Postfix(ItemActionAttack __instance, ItemActionAttack.AttackHitInfo _attackDetails, ref float _weaponCondition, int _attackerEntityId, ItemValue damagingItemValue)
        {
            // Check if this feature is enabled.
            if (!Configuration.CheckFeatureStatus(AdvFeatureClass, Feature))
            {
                return;
            }

            EntityAlive entityAlive = GameManager.Instance.World.GetEntity(_attackerEntityId) as EntityAlive;

            if (entityAlive)
            {
                bool isWearingGloves = false;

                // Throw weapon, skipping
                if (damagingItemValue != null && damagingItemValue.ItemClass.HasAnyTags(FastTags.Parse("thrownWeapon")))
                {
                    return;
                }

                // Check if its the player hand
                if (entityAlive.inventory.holdingItem.GetItemName() == "meleeHandPlayer" && _attackDetails.damageGiven > 0 && !isWearingGloves)
                {
                    AdvLogging.DisplayLog(AdvFeatureClass, "Attacking Entity is an EntityAlive: " + entityAlive.inventory.holdingItemItemValue.ItemClass.GetItemName() + " Inflicting Damage");
                    DamageSource dmg = new DamageSource(EnumDamageSource.Internal, EnumDamageTypes.Bashing);
                    entityAlive.DamageEntity(dmg, 1, false, 1f);
                }
            }

            return;
        }
コード例 #5
0
        public static bool Prefix(ItemActionEntryRepair __instance)
        {
            // Check if this feature is enabled.
            if (!Configuration.CheckFeatureStatus(AdvFeatureClass, Feature))
            {
                return(true);
            }

            XUi               xui       = __instance.ItemController.xui;
            ItemValue         itemValue = ((XUiC_ItemStack)__instance.ItemController).ItemStack.itemValue;
            ItemClass         forId     = ItemClass.GetForId(itemValue.type);
            EntityPlayerLocal player    = xui.playerUI.entityPlayer;

            XUiC_CraftingWindowGroup childByType = xui.FindWindowGroupByName("crafting").GetChildByType <XUiC_CraftingWindowGroup>();

            List <ItemStack> repairItems = new List <ItemStack>();

            // If the item has a repairItems, use that, instead of the vanilla version.
            if (forId.Properties.Classes.ContainsKey("RepairItems"))
            {
                Recipe            recipe             = new Recipe();
                DynamicProperties dynamicProperties3 = forId.Properties.Classes["RepairItems"];
                recipe.ingredients = ItemsUtilities.ParseProperties(dynamicProperties3);

                // Get an adjusted Craftint time from the player.
                recipe.craftingTime = (int)EffectManager.GetValue(PassiveEffects.CraftingTime, null, recipe.craftingTime, xui.playerUI.entityPlayer, recipe, FastTags.Parse(recipe.GetName()), true, true, true, true, 1, true);
                ItemsUtilities.ConvertAndCraft(recipe, player, __instance.ItemController);
                return(false);
            }
            else if (forId.Properties.Contains("RepairItems")) // to support <property name="RepairItems" value="resourceWood,10,resourceForgedIron,10" />
            {
                Recipe recipe  = new Recipe();
                string strData = forId.Properties.Values["RepairItems"].ToString();
                recipe.ingredients = ItemsUtilities.ParseProperties(strData);

                // Get an adjusted Craftint time from the player.
                recipe.craftingTime = (int)EffectManager.GetValue(PassiveEffects.CraftingTime, null, recipe.craftingTime, xui.playerUI.entityPlayer, recipe, FastTags.Parse(recipe.GetName()), true, true, true, true, 1, true);
                ItemsUtilities.ConvertAndCraft(recipe, player, __instance.ItemController);
                return(false);
            }
            // If there's no RepairTools defined, then fall back to recipe reduction
            else if (forId.RepairTools == null || forId.RepairTools.Length <= 0)
            {
                // Determine, based on percentage left,
                int RecipeCountReduction = 2;
                if (itemValue.PercentUsesLeft < 0.2)
                {
                    RecipeCountReduction = 3;
                }

                // Use the helper method to reduce the recipe count, and control displaying on the UI for consistenncy.
                ItemsUtilities.ConvertAndCraft(forId.GetItemName(), RecipeCountReduction, player, __instance.ItemController);
                return(false);
            }

            // Fall back to possible RepairTools
            return(true);
        }