/** * Debug writeout */ public override string ToString() { string name = ItemClass.GetForId(itemStack.itemValue.type).GetItemName(); string count = this.itemStack.count.ToString(); string prob = this.prob.ToString(); return("Transformer Input: " + name + " (" + count + ") with probability " + prob); }
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); }
public override void Execute(List <string> _params, CommandSenderInfo _senderInfo) { try { if (_params.Count < 1) { SdtdConsole.Instance.Output("Usage: ShowEquipment <steamid|playername|entityid>"); SdtdConsole.Instance.Output(" or: ShowEquipment <steamid|playername|entityid> <1>"); return; } string steamid = PersistentContainer.Instance.Players.GetSteamID(_params [0], true); if (steamid == null) { SdtdConsole.Instance.Output("Playername or entity/steamid id not found or no inventory saved (first saved after a player has been online for 30s)."); return; } Player p = PersistentContainer.Instance.Players [steamid, false]; PersistentData.Inventory inv = p.Inventory; if (p.IsOnline == true) { EntityPlayer ply = p.Entity; int num = 0; int vc = ply.equipment.GetSlotCount(); SdtdConsole.Instance.Output("**** Equipment of player " + ply.EntityName + " ****"); for (int i = 0; i < vc; i++) { //ib[k].itemValue.type = ItemValue gg = p.Entity.equipment.GetSlotItem(i); if (gg != null) { try { if (gg.type >= 1) { ItemClass itemClass = ItemClass.GetForId(gg.type); string name = itemClass.GetItemName(); //ib..GetItemName (); if (name != null) { num++; SdtdConsole.Instance.Output(num + ". * Slot # " + i + "/" + vc + " => " + name + " *"); } } }catch (Exception e) { } } } SdtdConsole.Instance.Output("**** Total of " + num + " slots equiped ****"); } } catch (Exception e) { Log.Out("Error in ShowEquipment.Run: " + e); } }
// Adapted from ItemAction.AddSkillExp() public void AddSkillExp(EntityPlayer _player, int _itemType, int _exp) { if (_player == null || destroyXPFactor == 0) { return; } if (entityVehicle.player.Skills != null) { Skill skill = _player.Skills.GetSkill(_itemType, false); ItemClass forId = ItemClass.GetForId(_itemType); if (skill != null && forId != null) { skill.AddExperience(Mathf.RoundToInt((float)_exp * destroyXPFactor), _player is EntityPlayerLocal, _player.entityId, true); } } }
public static bool Prefix(ItemActionEntryRepair __instance, StateTypes ___state, string ___lblReadBook, string ___lblNeedMaterials) { // Check if this feature is enabled. if (!Configuration.CheckFeatureStatus(AdvFeatureClass, Feature)) { return(true); } StateTypes stateTypes = ___state; if (stateTypes == StateTypes.RecipeLocked) { GameManager.ShowTooltip(__instance.ItemController.xui.playerUI.entityPlayer, ___lblReadBook); return(false); } if (stateTypes != StateTypes.NotEnoughMaterials) { return(false); } GameManager.ShowTooltip(__instance.ItemController.xui.playerUI.entityPlayer, ___lblNeedMaterials); List <ItemStack> stack = new List <ItemStack>(); ItemClass forId = ItemClass.GetForId(((XUiC_ItemStack)__instance.ItemController).ItemStack.itemValue.type); if (forId.Properties.Classes.ContainsKey("RepairItems")) { DynamicProperties dynamicProperties3 = forId.Properties.Classes["RepairItems"]; stack = ItemsUtilities.ParseProperties(dynamicProperties3); ItemsUtilities.CheckIngredients(stack, __instance.ItemController.xui.playerUI.entityPlayer); return(false); } else if (forId.Properties.Contains("RepairItems")) // to support <property name="RepairItems" value="resourceWood,10,resourceForgedIron,10" /> { string strData = forId.Properties.Values["RepairItems"].ToString(); stack = ItemsUtilities.ParseProperties(strData); ItemsUtilities.CheckIngredients(stack, __instance.ItemController.xui.playerUI.entityPlayer); return(false); } else if (forId.RepairTools == null || forId.RepairTools.Length <= 0) { Recipe recipe = ItemsUtilities.GetReducedRecipes(forId.GetItemName(), 2); ItemsUtilities.CheckIngredients(recipe.ingredients, __instance.ItemController.xui.playerUI.entityPlayer); return(false); } return(true); }
protected virtual void SetupStartingItems() { for (int i = 0; i < this.itemsOnEnterGame.Count; i++) { ItemStack itemStack = this.itemsOnEnterGame[i]; ItemClass forId = ItemClass.GetForId(itemStack.itemValue.type); if (forId.HasQuality) { itemStack.itemValue = new ItemValue(itemStack.itemValue.type, 1, 6, false, null, 1f); } else { itemStack.count = forId.Stacknumber.Value; } this.inventory.SetItem(i, itemStack); } }
public static void SetupStartingItems(EntityAlive __instance, List <ItemStack> ___itemsOnEnterGame) { for (int i = 0; i < ___itemsOnEnterGame.Count; i++) { ItemStack itemStack = ___itemsOnEnterGame[i]; ItemClass forId = ItemClass.GetForId(itemStack.itemValue.type); if (forId.HasQuality) { itemStack.itemValue = new ItemValue(itemStack.itemValue.type, 1, 6, false, null, 1f); } else { itemStack.count = forId.Stacknumber.Value; } __instance.inventory.SetItem(i, itemStack); } }
public static bool GetItemStack(BCMCmdArea command) { var quality = -1; var count = 1; if (command.Opts.ContainsKey("q")) { if (!int.TryParse(command.Opts["q"], out quality)) { BCCommandAbstract.SendOutput("Unable to parse quality, using random value"); } } if (command.Opts.ContainsKey("c")) { if (!int.TryParse(command.Opts["c"], out count)) { BCCommandAbstract.SendOutput($"Unable to parse count, using default value of {count}"); } } var ic = int.TryParse(command.Opts["item"], out var id) ? ItemClass.GetForId(id) : ItemData.GetForName(command.Opts["item"]); if (ic == null) { BCCommandAbstract.SendOutput($"Unable to get item or block from given value '{command.Opts["item"]}'"); return(false); } command.ItemStack = new ItemStack { itemValue = new ItemValue(ic.Id, true), count = count <= ic.Stacknumber.Value ? count : ic.Stacknumber.Value }; if (command.ItemStack.count < count) { BCCommandAbstract.SendOutput("Using max stack size for " + ic.Name + " of " + command.ItemStack.count); } if (command.ItemStack.itemValue.HasQuality && quality > 0) { command.ItemStack.itemValue.Quality = quality; } return(true); }
public static bool IsGroup(ItemValue item) { return(IsGroup(ItemClass.GetForId(item.type))); }
private static void LoadXml() { if (!Utils.FileExists(filePath)) { UpdateXml(); } XmlDocument xmlDoc = new XmlDocument(); try { xmlDoc.Load(filePath); } catch (XmlException e) { Log.Error(string.Format("[SERVERTOOLS] Failed loading {0}: {1}", file, e.Message)); return; } XmlNode _XmlNode = xmlDoc.DocumentElement; foreach (XmlNode childNode in _XmlNode.ChildNodes) { if (childNode.Name == "Items") { dict.Clear(); foreach (XmlNode subChild in childNode.ChildNodes) { if (subChild.NodeType == XmlNodeType.Comment) { continue; } if (subChild.NodeType != XmlNodeType.Element) { Log.Warning(string.Format("[SERVERTOOLS] Unexpected XML node found in 'Items' section: {0}", subChild.OuterXml)); continue; } XmlElement _line = (XmlElement)subChild; if (!_line.HasAttribute("itemName")) { Log.Warning(string.Format("[SERVERTOOLS] Ignoring Item entry because of missing 'itemName' attribute: {0}", subChild.OuterXml)); continue; } string _item = _line.GetAttribute("itemName"); ItemClass _class; Block _block; int _id; if (int.TryParse(_item, out _id)) { _class = ItemClass.GetForId(_id); _block = Block.GetBlockByName(_item, true); } else { _class = ItemClass.GetItemClass(_item, true); _block = Block.GetBlockByName(_item, true); } if (_class == null && _block == null) { Log.Out(string.Format("[SERVERTOOLS] Invalid item entry skipped. Item or block not found: {0}", _item)); continue; } if (!dict.Contains(_item)) { dict.Add(_item); } } } } }
public static void LoadXml() { if (!Utils.FileExists(filePath)) { UpdateXml(); } XmlDocument xmlDoc = new XmlDocument(); try { xmlDoc.Load(filePath); } catch (XmlException e) { Log.Error(string.Format("[SERVERTOOLS] Failed loading {0}: {1}", file, e.Message)); return; } XmlNode _XmlNode = xmlDoc.DocumentElement; foreach (XmlNode childNode in _XmlNode.ChildNodes) { if (childNode.Name == "Rewards") { dict.Clear(); list.Clear(); foreach (XmlNode subChild in childNode.ChildNodes) { if (subChild.NodeType == XmlNodeType.Comment) { continue; } if (subChild.NodeType != XmlNodeType.Element) { Log.Warning(string.Format("[SERVERTOOLS] Unexpected XML node found in 'Rewards' section: {0}", subChild.OuterXml)); continue; } XmlElement _line = (XmlElement)subChild; if (!_line.HasAttribute("itemOrBlock")) { Log.Warning(string.Format("[SERVERTOOLS] Ignoring reward entry because of missing itemOrBlock attribute: {0}", subChild.OuterXml)); continue; } if (!_line.HasAttribute("countMin")) { Log.Warning(string.Format("[SERVERTOOLS] Ignoring reward entry because of missing countMin attribute: {0}", subChild.OuterXml)); continue; } if (!_line.HasAttribute("countMax")) { Log.Warning(string.Format("[SERVERTOOLS] Ignoring reward entry because of missing countMax attribute: {0}", subChild.OuterXml)); continue; } if (!_line.HasAttribute("qualityMin")) { Log.Warning(string.Format("[SERVERTOOLS] Ignoring reward entry because of missing qualityMin attribute: {0}", subChild.OuterXml)); continue; } if (!_line.HasAttribute("qualityMax")) { Log.Warning(string.Format("[SERVERTOOLS] Ignoring reward entry because of missing qualityMax attribute: {0}", subChild.OuterXml)); continue; } int _countMin = 1; int _countMax = 1; int _qualityMin = 1; int _qualityMax = 1; if (!int.TryParse(_line.GetAttribute("countMin"), out _countMin)) { Log.Out(string.Format("[SERVERTOOLS] Ignoring reward entry because of invalid (non-numeric) value for 'count' attribute: {0}", subChild.OuterXml)); continue; } if (!int.TryParse(_line.GetAttribute("countMax"), out _countMax)) { Log.Out(string.Format("[SERVERTOOLS] Ignoring reward entry because of invalid (non-numeric) value for 'count' attribute: {0}", subChild.OuterXml)); continue; } if (!int.TryParse(_line.GetAttribute("qualityMin"), out _qualityMin)) { Log.Out(string.Format("[SERVERTOOLS] Ignoring reward entry because of invalid (non-numeric) value for 'quality' attribute: {0}", subChild.OuterXml)); continue; } if (!int.TryParse(_line.GetAttribute("qualityMax"), out _qualityMax)) { Log.Out(string.Format("[SERVERTOOLS] Ignoring reward entry because of invalid (non-numeric) value for 'quality' attribute: {0}", subChild.OuterXml)); continue; } string _item = _line.GetAttribute("itemOrBlock"); ItemClass _class; Block _block; int _id; if (int.TryParse(_item, out _id)) { _class = ItemClass.GetForId(_id); _block = Block.GetBlockByName(_item, true); } else { _class = ItemClass.GetItemClass(_item, true); _block = Block.GetBlockByName(_item, true); } if (_class == null && _block == null) { SdtdConsole.Instance.Output(string.Format("Unable to find item or block {0}", _item)); return; } else { if (!dict.ContainsKey(_item)) { int[] _c = new int[] { _countMin, _countMax, _qualityMin, _qualityMax }; dict.Add(_item, _c); } } } } } list = new List <string>(dict.Keys); if (updateConfig) { updateConfig = false; UpdateXml(); } }
public override void Execute(List <string> _params, CommandSenderInfo _senderInfo) { try { if (_params.Count != 3) { SdtdConsole.Instance.Output(string.Format("Wrong number of arguments, expected 3, found {0}", _params.Count)); return; } if (_params[0].Length < 1 || _params[0].Length > 17) { SdtdConsole.Instance.Output(string.Format("Can not give block to all players or player with Id: Invalid \"all\" or Id {0}", _params[0])); return; } if (_params[1].Length < 1 || _params[0].Length > 4) { SdtdConsole.Instance.Output(string.Format("Can not give block: Invalid blockId {0}", _params[1])); return; } if (_params[2].Length < 1 || _params[2].Length > 1) { SdtdConsole.Instance.Output(string.Format("Can not give block: Invalid count {0}", _params[2])); return; } else { ItemValue _itemValue; ItemClass _class; Block _block; int _id; if (int.TryParse(_params[1], out _id)) { _class = ItemClass.GetForId(_id); _block = Block.GetBlockByName(_params[1], true); } else { _class = ItemClass.GetItemClass(_params[1], true); _block = Block.GetBlockByName(_params[1], true); } if (_class == null && _block == null) { SdtdConsole.Instance.Output(string.Format("Unable to find block {0}", _params[1])); return; } else { _itemValue = new ItemValue(ItemClass.GetItem(_params[1]).type, 1, 1, true, default(FastTags), 1); } if (_params[0].ToLower() == "all") { List <ClientInfo> _cInfoList = ConnectionManager.Instance.Clients.List.ToList(); foreach (var _cInfo in _cInfoList) { int count = 1; int _count; if (int.TryParse(_params[2], out _count)) { if (_count > 0 & _count < 100000) { count = _count; } } World world = GameManager.Instance.World; if (world.Players.dict[_cInfo.entityId].IsSpawned()) { var entityItem = (EntityItem)EntityFactory.CreateEntity(new EntityCreationData { entityClass = EntityClass.FromString("item"), id = EntityFactory.nextEntityID++, itemStack = new ItemStack(_itemValue, count), pos = world.Players.dict[_cInfo.entityId].position, rot = new Vector3(20f, 0f, 20f), lifetime = 60f, belongsPlayerId = _cInfo.entityId }); world.SpawnEntityInWorld(entityItem); _cInfo.SendPackage(new NetPackageEntityCollect(entityItem.entityId, _cInfo.entityId)); world.RemoveEntity(entityItem.entityId, EnumRemoveEntityReason.Killed); SdtdConsole.Instance.Output(string.Format("Gave {0} to {1}.", _itemValue.ItemClass.GetLocalizedItemName() ?? _itemValue.ItemClass.Name, _cInfo.playerName)); string _phrase804; if (!Phrases.Dict.TryGetValue(804, out _phrase804)) { _phrase804 = "{Count} {ItemName} was sent to your inventory. If your bag is full, check the ground."; } _phrase804 = _phrase804.Replace("{Count}", count.ToString()); _phrase804 = _phrase804.Replace("{ItemName}", _itemValue.ItemClass.GetLocalizedItemName() ?? _itemValue.ItemClass.Name); ChatHook.ChatMessage(_cInfo, ChatHook.Player_Name_Color + _cInfo.playerName + _phrase804 + "[-]", _cInfo.entityId, LoadConfig.Server_Response_Name, EChatType.Whisper, null); } else { SdtdConsole.Instance.Output(string.Format("Player with steamdId {0} is not spawned", _params[0])); } } } else { ClientInfo _cInfo = ConsoleHelper.ParseParamIdOrName(_params[0]); if (_cInfo != null) { int count = 1; int _count; if (int.TryParse(_params[2], out _count)) { if (_count > 0 & _count < 10000) { count = _count; } } World world = GameManager.Instance.World; if (world.Players.dict[_cInfo.entityId].IsSpawned()) { var entityItem = (EntityItem)EntityFactory.CreateEntity(new EntityCreationData { entityClass = EntityClass.FromString("item"), id = EntityFactory.nextEntityID++, itemStack = new ItemStack(_itemValue, count), pos = world.Players.dict[_cInfo.entityId].position, rot = new Vector3(20f, 0f, 20f), lifetime = 60f, belongsPlayerId = _cInfo.entityId }); world.SpawnEntityInWorld(entityItem); _cInfo.SendPackage(new NetPackageEntityCollect(entityItem.entityId, _cInfo.entityId)); world.RemoveEntity(entityItem.entityId, EnumRemoveEntityReason.Killed); string _phrase804; if (!Phrases.Dict.TryGetValue(804, out _phrase804)) { _phrase804 = "{Count} {ItemName} was sent to your inventory. If your bag is full, check the ground."; } _phrase804 = _phrase804.Replace("{Count}", count.ToString()); _phrase804 = _phrase804.Replace("{ItemName}", _itemValue.ItemClass.GetLocalizedItemName() ?? _itemValue.ItemClass.Name); ChatHook.ChatMessage(_cInfo, ChatHook.Player_Name_Color + _cInfo.playerName + _phrase804 + "[-]", _cInfo.entityId, LoadConfig.Server_Response_Name, EChatType.Whisper, null); } else { SdtdConsole.Instance.Output(string.Format("Player with Id {0} is not spawned", _params[0])); } } else { SdtdConsole.Instance.Output(string.Format("Player with steamdId {0} does not exist", _params[0])); } } } } catch (Exception e) { Log.Out(string.Format("[SERVERTOOLS] Error in GiveItemDirectConsole.Run: {0}.", e)); } }
public static void LoadXml() { if (!Utils.FileExists(filePath)) { UpdateXml(); } XmlDocument xmlDoc = new XmlDocument(); try { xmlDoc.Load(filePath); } catch (XmlException e) { Log.Error(string.Format("[SERVERTOOLS] Failed loading {0}: {1}", file, e.Message)); return; } XmlNode _XmlNode = xmlDoc.DocumentElement; foreach (XmlNode childNode in _XmlNode.ChildNodes) { if (childNode.Name == "items") { dict.Clear(); dict1.Clear(); categories.Clear(); foreach (XmlNode subChild in childNode.ChildNodes) { if (subChild.NodeType == XmlNodeType.Comment) { continue; } if (subChild.NodeType != XmlNodeType.Element) { Log.Warning(string.Format("[SERVERTOOLS] Unexpected XML node found in 'Market' section: {0}", subChild.OuterXml)); continue; } XmlElement _line = (XmlElement)subChild; if (!_line.HasAttribute("item")) { Log.Warning(string.Format("[SERVERTOOLS] Ignoring Market entry because of missing item attribute: {0}", subChild.OuterXml)); continue; } if (!_line.HasAttribute("name")) { Log.Warning(string.Format("[SERVERTOOLS] Ignoring Market entry because of missing name attribute: {0}", subChild.OuterXml)); continue; } if (!_line.HasAttribute("secondaryname")) { updateConfig = true; } if (!_line.HasAttribute("count")) { Log.Warning(string.Format("[SERVERTOOLS] Ignoring Market entry because of missing count attribute: {0}", subChild.OuterXml)); continue; } if (!_line.HasAttribute("quality")) { Log.Warning(string.Format("[SERVERTOOLS] Ignoring Market entry because of missing quality attribute: {0}", subChild.OuterXml)); continue; } if (!_line.HasAttribute("price")) { Log.Warning(string.Format("[SERVERTOOLS] Ignoring Market entry because of missing price attribute: {0}", subChild.OuterXml)); continue; } if (!_line.HasAttribute("category")) { Log.Warning(string.Format("[SERVERTOOLS] Ignoring Market entry because of missing category attribute: {0}", subChild.OuterXml)); continue; } int _item = 1; int _count = 1; int _quality = 1; int _price = 1; if (!int.TryParse(_line.GetAttribute("item"), out _item)) { Log.Out(string.Format("[SERVERTOOLS] Ignoring Market entry because of invalid (non-numeric) value for 'item' attribute: {0}", subChild.OuterXml)); continue; } if (!int.TryParse(_line.GetAttribute("count"), out _count)) { Log.Out(string.Format("[SERVERTOOLS] Ignoring Market entry because of invalid (non-numeric) value for 'count' attribute: {0}", subChild.OuterXml)); continue; } if (!int.TryParse(_line.GetAttribute("quality"), out _quality)) { Log.Out(string.Format("[SERVERTOOLS] Ignoring Market entry because of invalid (non-numeric) value for 'quality' attribute: {0}", subChild.OuterXml)); continue; } if (!int.TryParse(_line.GetAttribute("price"), out _price)) { Log.Out(string.Format("[SERVERTOOLS] Ignoring Market Item entry because of invalid (non-numeric) value for 'price' attribute: {0}", subChild.OuterXml)); continue; } if (_quality > 6) { _quality = 1; } string _name = _line.GetAttribute("name"); string _secondaryname; if (_line.HasAttribute("secondaryname")) { _secondaryname = _line.GetAttribute("secondaryname"); } else { _secondaryname = _name; } ItemClass _class; Block _block; int _id; if (int.TryParse(_name, out _id)) { _class = ItemClass.GetForId(_id); _block = Block.GetBlockByName(_name, true); } else { _class = ItemClass.GetItemClass(_name, true); _block = Block.GetBlockByName(_name, true); } if (_class == null && _block == null) { Log.Out(string.Format("[SERVERTOOLS] Market entry skipped. Item not found: {0}", _name)); continue; } string _category = _line.GetAttribute("category"); _category = _category.ToLower(); if (!categories.Contains(_category)) { categories.Add(_category); } if (!dict.ContainsKey(_item)) { string[] _n = new string[] { _name, _secondaryname, _category }; dict.Add(_item, _n); int[] _c = new int[] { _count, _quality, _price }; dict1.Add(_item, _c); } } } } if (updateConfig) { updateConfig = false; UpdateXml(); } }
public override void OnActivated() { XUi xui = base.ItemController.xui; XUiM_PlayerInventory playerInventory = xui.PlayerInventory; ItemValue itemValue = ((XUiC_ItemStack)base.ItemController).ItemStack.itemValue; ItemClass forId = ItemClass.GetForId(itemValue.type); XUiC_CraftingWindowGroup childByType = xui.FindWindowGroupByName("crafting").GetChildByType <XUiC_CraftingWindowGroup>(); if (itemValue.HasQuality) { if (itemValue.PercentUsesLeft < 0.30) { String text = "This item is too worn out to be resharpened."; GameManager.ShowTooltip(ItemController.xui.playerUI.entityPlayer, text); return; } if (itemValue.PercentUsesLeft > 0.8) { String text = "This item is still in pretty good shape."; GameManager.ShowTooltip(ItemController.xui.playerUI.entityPlayer, text); return; } } if (forId.Properties.Contains("SharpenItem")) { String strSharpenItem = String.Empty; forId.Properties.ParseString("SharpenItem", ref strSharpenItem); if (String.IsNullOrEmpty(strSharpenItem)) { return; } Recipe recipe = new Recipe(); recipe.count = 1; ItemClass itemClass = ItemClass.GetItemClass(strSharpenItem, false); if (itemClass == null) { return; } int Count = playerInventory.GetItemCount(new ItemValue(itemClass.Id, false)); if (Count < 1) { String text = "Not enough " + strSharpenItem + " to craft this: " + Count + " / 1"; GameManager.ShowTooltip(ItemController.xui.playerUI.entityPlayer, text); return; } if (childByType != null) { recipe.ingredients.Add(new ItemStack(new ItemValue(itemClass.Id, false), 1)); recipe.itemValueType = itemValue.type; recipe.craftingTime = 1; recipe.craftExpGain = 1; } // ItemClass.GetForId(recipe.itemValueType); GameRandom random = GameRandomManager.Instance.CreateGameRandom(); float flRandom = random.RandomRange((int)itemValue.UseTimes, ((float)itemValue.MaxUseTimes / 1.20f)); if (!childByType.AddRepairItemToQueue(recipe.craftingTime, itemValue.Clone(), (int)flRandom)) { WarnQueueFull(ItemController); return; } ((XUiC_ItemStack)ItemController).ItemStack = ItemStack.Empty.Clone(); playerInventory.RemoveItems(recipe.ingredients, 1); } }
public static void LoadXml() { if (!Utils.FileExists(filePath)) { UpdateXml(); } XmlDocument xmlDoc = new XmlDocument(); try { xmlDoc.Load(filePath); } catch (XmlException e) { Log.Error(string.Format("[SERVERTOOLS] Failed loading {0}: {1}", file, e.Message)); return; } XmlNode _XmlNode = xmlDoc.DocumentElement; foreach (XmlNode childNode in _XmlNode.ChildNodes) { if (childNode.Name == "Items") { ItemList.Clear(); foreach (XmlNode subChild in childNode.ChildNodes) { if (subChild.NodeType == XmlNodeType.Comment) { continue; } if (subChild.NodeType != XmlNodeType.Element) { Log.Warning(string.Format("[SERVERTOOLS] Unexpected XML node found in 'StartingItems' section: {0}", subChild.OuterXml)); continue; } XmlElement _line = (XmlElement)subChild; if (!_line.HasAttribute("Name")) { Log.Warning(string.Format("[SERVERTOOLS] Ignoring starting item entry because of missing Name attribute: {0}", subChild.OuterXml)); continue; } if (!_line.HasAttribute("Count")) { Log.Warning(string.Format("[SERVERTOOLS] Ignoring starting item entry because of missing Count attribute: {0}", subChild.OuterXml)); continue; } if (!_line.HasAttribute("Quality")) { Log.Warning(string.Format("[SERVERTOOLS] Ignoring starting item entry because of missing Quality attribute: {0}", subChild.OuterXml)); continue; } if (!int.TryParse(_line.GetAttribute("Count"), out int _count)) { Log.Out(string.Format("[SERVERTOOLS] Ignoring starting item entry because of invalid (non-numeric) value for 'Count' attribute: {0}", subChild.OuterXml)); continue; } if (!int.TryParse(_line.GetAttribute("Quality"), out int _quality)) { Log.Out(string.Format("[SERVERTOOLS] Ignoring starting item entry because of invalid (non-numeric) value for 'Quality' attribute: {0}", subChild.OuterXml)); continue; } if (_quality < 1) { _quality = 1; } string _item = _line.GetAttribute("Name"); ItemClass _class; Block _block; int _id; if (int.TryParse(_item, out _id)) { _class = ItemClass.GetForId(_id); _block = Block.GetBlockByName(_item, true); } else { _class = ItemClass.GetItemClass(_item, true); _block = Block.GetBlockByName(_item, true); } if (_class == null && _block == null) { Log.Out(string.Format("[SERVERTOOLS] Starting item entry skipped. Item not found: {0}", _item)); continue; } if (!ItemList.ContainsKey(_item)) { int[] _c = new int[] { _count, _quality }; ItemList.Add(_item, _c); } } } } if (updateConfig) { updateConfig = false; UpdateXml(); } }
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); }
/** * Gets the stack number for an item stack. */ public static int TotalStackSizeFor(ItemStack itemStack) { return(ItemClass.GetForId(itemStack.itemValue.type).Stacknumber.Value); }