public ItemContainer(Item item, XElement element) : base(item, element) { Inventory = new ItemInventory(item, this, capacity, SlotsPerRow); foreach (XElement subElement in element.Elements()) { switch (subElement.Name.ToString().ToLowerInvariant()) { case "containable": RelatedItem containable = RelatedItem.Load(subElement, returnEmpty: false, parentDebugName: item.Name); if (containable == null) { DebugConsole.ThrowError("Error in item config \"" + item.ConfigFile + "\" - containable with no identifiers."); continue; } ContainableItems.Add(containable); break; } } InitProjSpecific(element); itemsWithStatusEffects = new List <Pair <Item, StatusEffect> >(); }
public void SetRequiredItems(XElement element) { bool returnEmpty = false; #if CLIENT returnEmpty = Screen.Selected == GameMain.SubEditorScreen; #endif RelatedItem ri = RelatedItem.Load(element, returnEmpty, item.Name); if (ri != null) { if (ri.Identifiers.Length == 0) { DisabledRequiredItems.Add(ri); } else { if (!requiredItems.ContainsKey(ri.Type)) { requiredItems.Add(ri.Type, new List <RelatedItem>()); } requiredItems[ri.Type].Add(ri); } } else { DebugConsole.ThrowError("Error in item config \"" + item.ConfigFile + "\" - component " + GetType().ToString() + " requires an item with no identifiers."); } }
public ItemContainer(Item item, XElement element) : base(item, element) { Inventory = new ItemInventory(item, this, capacity, hudPos, slotsPerRow); containableItems = new List <RelatedItem>(); foreach (XElement subElement in element.Elements()) { switch (subElement.Name.ToString().ToLowerInvariant()) { case "containable": RelatedItem containable = RelatedItem.Load(subElement); if (containable == null) { continue; } containableItems.Add(containable); break; } } itemsWithStatusEffects = new List <Pair <Item, StatusEffect> >(); }
private void OverrideRequiredItems(XElement element) { var prevRequiredItems = new Dictionary <RelatedItem.RelationType, List <RelatedItem> >(requiredItems); requiredItems.Clear(); foreach (XElement subElement in element.Elements()) { switch (subElement.Name.ToString().ToLowerInvariant()) { case "requireditem": RelatedItem newRequiredItem = RelatedItem.Load(subElement, item.Name); if (newRequiredItem == null) { continue; } var prevRequiredItem = prevRequiredItems.ContainsKey(newRequiredItem.Type) ? prevRequiredItems[newRequiredItem.Type].Find(ri => ri.JoinedIdentifiers == newRequiredItem.JoinedIdentifiers) : null; if (prevRequiredItem != null) { newRequiredItem.statusEffects = prevRequiredItem.statusEffects; newRequiredItem.Msg = prevRequiredItem.Msg; newRequiredItem.IsOptional = prevRequiredItem.IsOptional; } if (!requiredItems.ContainsKey(newRequiredItem.Type)) { requiredItems[newRequiredItem.Type] = new List <RelatedItem>(); } requiredItems[newRequiredItem.Type].Add(newRequiredItem); break; } } }
public virtual void Load(XElement componentElement) { if (componentElement == null) { return; } foreach (XAttribute attribute in componentElement.Attributes()) { SerializableProperty property = null; if (!properties.TryGetValue(attribute.Name.ToString().ToLowerInvariant(), out property)) { continue; } property.TrySetValue(attribute.Value); } List <RelatedItem> prevRequiredItems = new List <RelatedItem>(requiredItems); bool overrideRequiredItems = false; foreach (XElement subElement in componentElement.Elements()) { switch (subElement.Name.ToString().ToLowerInvariant()) { case "requireditem": if (!overrideRequiredItems) { requiredItems.Clear(); } overrideRequiredItems = true; RelatedItem newRequiredItem = RelatedItem.Load(subElement); if (newRequiredItem == null) { continue; } var prevRequiredItem = prevRequiredItems.Find(ri => ri.JoinedNames == newRequiredItem.JoinedNames); if (prevRequiredItem != null) { newRequiredItem.statusEffects = prevRequiredItem.statusEffects; newRequiredItem.Msg = prevRequiredItem.Msg; } requiredItems.Add(newRequiredItem); break; } } }
private void OverrideRequiredItems(XElement element) { var prevRequiredItems = new Dictionary <RelatedItem.RelationType, List <RelatedItem> >(requiredItems); requiredItems.Clear(); bool returnEmptyRequirements = false; #if CLIENT returnEmptyRequirements = Screen.Selected == GameMain.SubEditorScreen; #endif foreach (XElement subElement in element.Elements()) { switch (subElement.Name.ToString().ToLowerInvariant()) { case "requireditem": case "requireditems": RelatedItem newRequiredItem = RelatedItem.Load(subElement, returnEmptyRequirements, item.Name); if (newRequiredItem == null) { continue; } var prevRequiredItem = prevRequiredItems.ContainsKey(newRequiredItem.Type) ? prevRequiredItems[newRequiredItem.Type].Find(ri => ri.JoinedIdentifiers == newRequiredItem.JoinedIdentifiers) : null; if (prevRequiredItem != null) { newRequiredItem.statusEffects = prevRequiredItem.statusEffects; newRequiredItem.Msg = prevRequiredItem.Msg; newRequiredItem.IsOptional = prevRequiredItem.IsOptional; newRequiredItem.IgnoreInEditor = prevRequiredItem.IgnoreInEditor; } if (!requiredItems.ContainsKey(newRequiredItem.Type)) { requiredItems[newRequiredItem.Type] = new List <RelatedItem>(); } requiredItems[newRequiredItem.Type].Add(newRequiredItem); break; } } }
public ItemComponent(Item item, XElement element) { this.item = item; properties = ObjectProperty.GetProperties(this); //canBePicked = ToolBox.GetAttributeBool(element, "canbepicked", false); //canBeSelected = ToolBox.GetAttributeBool(element, "canbeselected", false); //msg = ToolBox.GetAttributeString(element, "msg", ""); requiredItems = new List <RelatedItem>(); requiredSkills = new List <Skill>(); #if CLIENT sounds = new Dictionary <ActionType, List <ItemSound> >(); #endif SelectKey = InputType.Select; try { string selectKeyStr = ToolBox.GetAttributeString(element, "selectkey", "Select"); selectKeyStr = ToolBox.ConvertInputType(selectKeyStr); SelectKey = (InputType)Enum.Parse(typeof(InputType), selectKeyStr, true); } catch (Exception e) { DebugConsole.ThrowError("Invalid select key in " + element + "!", e); } PickKey = InputType.Select; try { string pickKeyStr = ToolBox.GetAttributeString(element, "selectkey", "Select"); pickKeyStr = ToolBox.ConvertInputType(pickKeyStr); PickKey = (InputType)Enum.Parse(typeof(InputType), pickKeyStr, true); } catch (Exception e) { DebugConsole.ThrowError("Invalid pick key in " + element + "!", e); } properties = ObjectProperty.InitProperties(this, element); foreach (XElement subElement in element.Elements()) { switch (subElement.Name.ToString().ToLowerInvariant()) { case "requireditem": case "requireditems": RelatedItem ri = RelatedItem.Load(subElement); if (ri != null) { requiredItems.Add(ri); } break; case "requiredskill": case "requiredskills": string skillName = ToolBox.GetAttributeString(subElement, "name", ""); requiredSkills.Add(new Skill(skillName, ToolBox.GetAttributeInt(subElement, "level", 0))); break; case "statuseffect": var statusEffect = StatusEffect.Load(subElement); if (statusEffectLists == null) { statusEffectLists = new Dictionary <ActionType, List <StatusEffect> >(); } List <StatusEffect> effectList; if (!statusEffectLists.TryGetValue(statusEffect.type, out effectList)) { effectList = new List <StatusEffect>(); statusEffectLists.Add(statusEffect.type, effectList); } effectList.Add(statusEffect); break; default: if (LoadElemProjSpecific(subElement)) { break; } ItemComponent ic = Load(subElement, item, item.ConfigFile, false); if (ic == null) { break; } ic.Parent = this; item.components.Add(ic); break; } } }
public ItemComponent(Item item, XElement element) { this.item = item; properties = ObjectProperty.GetProperties(this); //canBePicked = ToolBox.GetAttributeBool(element, "canbepicked", false); //canBeSelected = ToolBox.GetAttributeBool(element, "canbeselected", false); //msg = ToolBox.GetAttributeString(element, "msg", ""); requiredItems = new List <RelatedItem>(); requiredSkills = new List <Skill>(); sounds = new Dictionary <ActionType, List <ItemSound> >(); SelectKey = InputType.Select; try { string selectKeyStr = ToolBox.GetAttributeString(element, "selectkey", "Select"); selectKeyStr = ToolBox.ConvertInputType(selectKeyStr); SelectKey = (InputType)Enum.Parse(typeof(InputType), selectKeyStr, true); } catch (Exception e) { DebugConsole.ThrowError("Invalid select key in " + element + "!", e); } PickKey = InputType.Select; try { string pickKeyStr = ToolBox.GetAttributeString(element, "selectkey", "Select"); pickKeyStr = ToolBox.ConvertInputType(pickKeyStr); PickKey = (InputType)Enum.Parse(typeof(InputType), pickKeyStr, true); } catch (Exception e) { DebugConsole.ThrowError("Invalid pick key in " + element + "!", e); } properties = ObjectProperty.InitProperties(this, element); foreach (XElement subElement in element.Elements()) { switch (subElement.Name.ToString().ToLowerInvariant()) { case "requireditem": case "requireditems": RelatedItem ri = RelatedItem.Load(subElement); if (ri != null) { requiredItems.Add(ri); } break; case "requiredskill": case "requiredskills": string skillName = ToolBox.GetAttributeString(subElement, "name", ""); requiredSkills.Add(new Skill(skillName, ToolBox.GetAttributeInt(subElement, "level", 0))); break; case "statuseffect": var statusEffect = StatusEffect.Load(subElement); if (statusEffectLists == null) { statusEffectLists = new Dictionary <ActionType, List <StatusEffect> >(); } List <StatusEffect> effectList; if (!statusEffectLists.TryGetValue(statusEffect.type, out effectList)) { effectList = new List <StatusEffect>(); statusEffectLists.Add(statusEffect.type, effectList); } effectList.Add(statusEffect); break; case "guiframe": string rectStr = ToolBox.GetAttributeString(subElement, "rect", "0.0,0.0,0.5,0.5"); string[] components = rectStr.Split(','); if (components.Length < 4) { continue; } Vector4 rect = ToolBox.GetAttributeVector4(subElement, "rect", Vector4.One); if (components[0].Contains(".")) { rect.X *= GameMain.GraphicsWidth; } if (components[1].Contains(".")) { rect.Y *= GameMain.GraphicsHeight; } if (components[2].Contains(".")) { rect.Z *= GameMain.GraphicsWidth; } if (components[3].Contains(".")) { rect.W *= GameMain.GraphicsHeight; } string style = ToolBox.GetAttributeString(subElement, "style", ""); Vector4 color = ToolBox.GetAttributeVector4(subElement, "color", Vector4.One); Alignment alignment = Alignment.Center; try { alignment = (Alignment)Enum.Parse(typeof(Alignment), ToolBox.GetAttributeString(subElement, "alignment", "Center"), true); } catch { DebugConsole.ThrowError("Error in " + element + "! \"" + element.Attribute("type").Value + "\" is not a valid alignment"); } guiFrame = new GUIFrame( new Rectangle((int)rect.X, (int)rect.Y, (int)rect.Z, (int)rect.W), new Color(color.X, color.Y, color.Z) * color.W, alignment, style); break; case "sound": string filePath = ToolBox.GetAttributeString(subElement, "file", ""); if (filePath == "") { filePath = ToolBox.GetAttributeString(subElement, "sound", ""); } if (filePath == "") { DebugConsole.ThrowError("Error when instantiating item \"" + item.Name + "\" - sound with no file path set"); continue; } if (!filePath.Contains("/") && !filePath.Contains("\\") && !filePath.Contains(Path.DirectorySeparatorChar)) { filePath = Path.Combine(Path.GetDirectoryName(item.Prefab.ConfigFile), filePath); } ActionType type; try { type = (ActionType)Enum.Parse(typeof(ActionType), ToolBox.GetAttributeString(subElement, "type", ""), true); } catch (Exception e) { DebugConsole.ThrowError("Invalid sound type in " + subElement + "!", e); break; } Sound sound = Sound.Load(filePath); float range = ToolBox.GetAttributeFloat(subElement, "range", 800.0f); bool loop = ToolBox.GetAttributeBool(subElement, "loop", false); ItemSound itemSound = new ItemSound(sound, type, range, loop); itemSound.VolumeProperty = ToolBox.GetAttributeString(subElement, "volume", ""); itemSound.VolumeMultiplier = ToolBox.GetAttributeFloat(subElement, "volumemultiplier", 1.0f); List <ItemSound> soundList = null; if (!sounds.TryGetValue(itemSound.Type, out soundList)) { soundList = new List <ItemSound>(); sounds.Add(itemSound.Type, soundList); } soundList.Add(itemSound); break; default: ItemComponent ic = Load(subElement, item, item.ConfigFile, false); if (ic == null) { break; } ic.Parent = this; item.components.Add(ic); break; } } }
public ItemComponent(Item item, XElement element) { this.item = item; originalElement = element; name = element.Name.ToString(); SerializableProperties = SerializableProperty.GetProperties(this); requiredItems = new Dictionary <RelatedItem.RelationType, List <RelatedItem> >(); requiredSkills = new List <Skill>(); #if CLIENT sounds = new Dictionary <ActionType, List <ItemSound> >(); #endif SelectKey = InputType.Select; try { string selectKeyStr = element.GetAttributeString("selectkey", "Select"); selectKeyStr = ToolBox.ConvertInputType(selectKeyStr); SelectKey = (InputType)Enum.Parse(typeof(InputType), selectKeyStr, true); } catch (Exception e) { DebugConsole.ThrowError("Invalid select key in " + element + "!", e); } PickKey = InputType.Select; try { string pickKeyStr = element.GetAttributeString("pickkey", "Select"); pickKeyStr = ToolBox.ConvertInputType(pickKeyStr); PickKey = (InputType)Enum.Parse(typeof(InputType), pickKeyStr, true); } catch (Exception e) { DebugConsole.ThrowError("Invalid pick key in " + element + "!", e); } SerializableProperties = SerializableProperty.DeserializeProperties(this, element); ParseMsg(); foreach (XElement subElement in element.Elements()) { switch (subElement.Name.ToString().ToLowerInvariant()) { case "requireditem": case "requireditems": RelatedItem ri = RelatedItem.Load(subElement, item.Name); if (ri != null) { if (!requiredItems.ContainsKey(ri.Type)) { requiredItems.Add(ri.Type, new List <RelatedItem>()); } requiredItems[ri.Type].Add(ri); } else { DebugConsole.ThrowError("Error in item config \"" + item.ConfigFile + "\" - component " + GetType().ToString() + " requires an item with no identifiers."); } break; case "requiredskill": case "requiredskills": if (subElement.Attribute("name") != null) { DebugConsole.ThrowError("Error in item config \"" + item.ConfigFile + "\" - skill requirement in component " + GetType().ToString() + " should use a skill identifier instead of the name of the skill."); continue; } string skillIdentifier = subElement.GetAttributeString("identifier", ""); requiredSkills.Add(new Skill(skillIdentifier, subElement.GetAttributeInt("level", 0))); break; case "statuseffect": var statusEffect = StatusEffect.Load(subElement, item.Name); if (statusEffectLists == null) { statusEffectLists = new Dictionary <ActionType, List <StatusEffect> >(); } List <StatusEffect> effectList; if (!statusEffectLists.TryGetValue(statusEffect.type, out effectList)) { effectList = new List <StatusEffect>(); statusEffectLists.Add(statusEffect.type, effectList); } effectList.Add(statusEffect); break; case "aitarget": AITarget = new AITarget(item, subElement) { Enabled = isActive }; break; default: if (LoadElemProjSpecific(subElement)) { break; } ItemComponent ic = Load(subElement, item, item.ConfigFile, false); if (ic == null) { break; } ic.Parent = this; item.AddComponent(ic); break; } } }
public ItemContainer(Item item, XElement element) : base(item, element) { int totalCapacity = capacity; List <RelatedItem> containableItems = null; foreach (XElement subElement in element.Elements()) { switch (subElement.Name.ToString().ToLowerInvariant()) { case "containable": RelatedItem containable = RelatedItem.Load(subElement, returnEmpty: false, parentDebugName: item.Name); if (containable == null) { DebugConsole.ThrowError("Error in item config \"" + item.ConfigFile + "\" - containable with no identifiers."); continue; } containableItems ??= new List <RelatedItem>(); containableItems.Add(containable); break; case "subcontainer": totalCapacity += subElement.GetAttributeInt("capacity", 1); break; } } Inventory = new ItemInventory(item, this, totalCapacity, SlotsPerRow); slotRestrictions = new SlotRestrictions[totalCapacity]; for (int i = 0; i < capacity; i++) { slotRestrictions[i] = new SlotRestrictions(maxStackSize, containableItems); } int subContainerIndex = capacity; foreach (XElement subElement in element.Elements()) { if (subElement.Name.ToString().ToLowerInvariant() != "subcontainer") { continue; } int subCapacity = subElement.GetAttributeInt("capacity", 1); int subMaxStackSize = subElement.GetAttributeInt("maxstacksize", maxStackSize); List <RelatedItem> subContainableItems = null; foreach (XElement subSubElement in subElement.Elements()) { if (subSubElement.Name.ToString().ToLowerInvariant() != "containable") { continue; } RelatedItem containable = RelatedItem.Load(subSubElement, returnEmpty: false, parentDebugName: item.Name); if (containable == null) { DebugConsole.ThrowError("Error in item config \"" + item.ConfigFile + "\" - containable with no identifiers."); continue; } subContainableItems ??= new List <RelatedItem>(); subContainableItems.Add(containable); } for (int i = subContainerIndex; i < subContainerIndex + subCapacity; i++) { slotRestrictions[i] = new SlotRestrictions(subMaxStackSize, subContainableItems); } subContainerIndex += subCapacity; } capacity = totalCapacity; InitProjSpecific(element); }