private void ImportPrototypeSettings(int defaulMaxStackSize, float defaultBasePrice, string defaultCategory) { if (PrototypeManager.Inventory.Has(Type)) { InventoryCommon prototype = PrototypeManager.Inventory.Get(Type); MaxStackSize = prototype.maxStackSize; BasePrice = prototype.basePrice; Category = prototype.category; } else { MaxStackSize = defaulMaxStackSize; BasePrice = defaultBasePrice; Category = defaultCategory; } }
void LoadInventoryPrototypesFromFile(string inventoryXmlText) { XmlTextReader reader = new XmlTextReader(new StringReader(inventoryXmlText)); int inventoryCount = 0; if (reader.ReadToDescendant("Inventories")) { if (reader.ReadToDescendant("Inventory")) { do { inventoryCount++; InventoryCommon inv = new InventoryCommon(); try { inv.ReadXmlPrototype(reader); } catch (Exception e) { Debug.LogError("Error reading inventory prototype for: " + inv.objectType + Environment.NewLine + "Exception: " + e.Message + Environment.NewLine + "StackTrace: " + e.StackTrace); } inventoryPrototypes[inv.objectType] = inv; } while (reader.ReadToNextSibling("Inventory")); } else { Debug.LogError("The inventory prototype definition file doesn't have any 'Inventory' elements."); } } else { Debug.LogError("Did not find a 'Inventories' element in the prototype definition file."); } // This bit will come from parsing a LUA file later, but for now we still need to // implement furniture behaviour directly in C# code. //furniturePrototypes["Door"].RegisterUpdateAction( FurnitureActions.Door_UpdateAction ); //furniturePrototypes["Door"].IsEnterable = FurnitureActions.Door_IsEnterable; //Logger.LogError("Did not find a 'Inventories' element in the prototype definition file."); }
/// <summary> /// Reads the prototype furniture from XML. /// </summary> /// <param name="readerParent">The XML reader to read from.</param> public void ReadXmlPrototype(XmlReader readerParent) { Type = readerParent.GetAttribute("type"); XmlReader reader = readerParent.ReadSubtree(); while (reader.Read()) { switch (reader.Name) { case "TypeTag": reader.Read(); typeTags.Add(reader.ReadContentAsString()); break; case "MovementCost": reader.Read(); MovementCost = reader.ReadContentAsFloat(); break; case "PathfindingModifier": reader.Read(); PathfindingModifier = reader.ReadContentAsFloat(); break; case "PathfindingWeight": reader.Read(); PathfindingWeight = reader.ReadContentAsFloat(); break; case "Width": reader.Read(); Width = reader.ReadContentAsInt(); break; case "Height": reader.Read(); Height = reader.ReadContentAsInt(); break; case "Health": reader.Read(); health = new HealthSystem(reader.ReadContentAsFloat(), false, true, false, false); break; case "LinksToNeighbours": reader.Read(); LinksToNeighbour = reader.ReadContentAsString(); break; case "EnclosesRooms": reader.Read(); RoomEnclosure = reader.ReadContentAsBoolean(); break; case "CanReplaceFurniture": replaceableFurniture.Add(reader.GetAttribute("typeTag").ToString()); break; case "CanRotate": reader.Read(); CanRotate = reader.ReadContentAsBoolean(); break; case "DragType": reader.Read(); DragType = reader.ReadContentAsString(); break; case "CanBeBuiltOn": tileTypeBuildPermissions.Add(reader.GetAttribute("tileType")); break; case "Animations": XmlReader animationReader = reader.ReadSubtree(); ReadAnimationXml(animationReader); break; case "Action": XmlReader subtree = reader.ReadSubtree(); EventActions.ReadXml(subtree); subtree.Close(); break; case "ContextMenuAction": contextMenuLuaActions.Add(new ContextMenuLuaAction { LuaFunction = reader.GetAttribute("FunctionName"), LocalizationKey = reader.GetAttribute("LocalizationKey"), RequireCharacterSelected = bool.Parse(reader.GetAttribute("RequireCharacterSelected")), DevModeOnly = bool.Parse(reader.GetAttribute("DevModeOnly") ?? "false") }); break; case "IsEnterable": isEnterableAction = reader.GetAttribute("FunctionName"); break; case "GetProgressInfo": getProgressInfoNameAction = reader.GetAttribute("functionName"); break; case "JobWorkSpotOffset": Jobs.ReadWorkSpotOffset(reader); break; case "JobInputSpotOffset": Jobs.ReadInputSpotOffset(reader); break; case "JobOutputSpotOffset": Jobs.ReadOutputSpotOffset(reader); break; case "Params": ReadXmlParams(reader); // Read in the Param tag break; case "LocalizationCode": reader.Read(); LocalizationCode = reader.ReadContentAsString(); break; case "UnlocalizedDescription": reader.Read(); UnlocalizedDescription = reader.ReadContentAsString(); break; case "Component": BuildableComponent component = BuildableComponent.Deserialize(reader); if (component != null) { component.InitializePrototype(this); components.Add(component); } break; case "OrderAction": OrderAction orderAction = OrderAction.Deserialize(reader); if (orderAction != null) { orderActions[orderAction.Type] = orderAction; } break; } } if (orderActions.ContainsKey("Uninstall")) { InventoryCommon asInventory = new InventoryCommon(); asInventory.type = Type; asInventory.maxStackSize = 1; asInventory.basePrice = 0f; asInventory.category = "crated_furniture"; PrototypeManager.Inventory.Add(asInventory); } }