public bool PlaceFurniture(Furniture furn) { if (furn == null) { return(UnplaceFurniture()); } if (furn.IsValidPosition(this) == false) { Debug.LogError("Trying to assign a Furniture to a Tile that isn't valid."); return(false); } for (var xOff = X; xOff < X + furn.Width; xOff++) { for (var yOff = Y; yOff < Y + furn.Height; yOff++) { var t = World.Instance.GetTileAt(xOff, yOff); t.Furniture = furn; } } return(true); }
public static void CallFunctionsWithFurniture(IEnumerable <string> functionNames, Furniture furn, float deltaTime) { foreach (var fname in functionNames) { var func = _instance.myLuaScript.Globals[fname]; if (func == null) { Debug.LogErrorFormat("Function {0} is not a LUA function.", fname); return; } var result = _instance.myLuaScript.Call(func, new object[] { furn, deltaTime }); if (result.Type != DataType.Void) { if (result.Type == DataType.Number) { Debug.LogFormat("{0} {1}", fname, result.Number); } if (result.Type == DataType.String) { Debug.LogFormat("{0} {1}", fname, result.String); } if (result.Type == DataType.UserData) { Debug.LogFormat("{0} {1}", fname, result.UserData.Object.ToString()); } } } }
private void CreateFurniturePrototypes() { LoadFurnitureLua(); this.FurniturePrototypes = new Dictionary <string, Furniture>(); this.FurnitureJobPrototypes = new Dictionary <string, Job>(); var filepath = Application.streamingAssetsPath; filepath = Path.Combine(filepath, "Base"); filepath = Path.Combine(filepath, "Data"); filepath = Path.Combine(filepath, "Furniture.xml"); var furnText = System.IO.File.ReadAllText(filepath); var xml = new XmlDocument(); xml.LoadXml(furnText); var furnitures = xml.DocumentElement.SelectSingleNode("/Furnitures"); foreach (XmlNode furniture in furnitures.ChildNodes) { var objectType = XmlParser.ParseAttributeString(furniture, "objectType"); // Debug.LogFormat("Loading Furniture {0}...", ObjectType); var furn = new Furniture( objectType: objectType, movementCost: XmlParser.ParseFloat(furniture, ".//MovementCost", 1), width: XmlParser.ParseInt(furniture, ".//Width", 1), height: XmlParser.ParseInt(furniture, ".//Height", 1), linksToNeighbour: XmlParser.ParseBool(furniture, ".//LinksToNeighbours", false), isRoomEnclosure: XmlParser.ParseBool(furniture, ".//EnclosesRoom", false) ); furn.IdleSprites = XmlParser.ParseInt(furniture, ".//IdleSprites", 0); furn.Name = XmlParser.ParseString(furniture, ".//Name"); furn.JobSpotOffset = XmlParser.ParseVector2(furniture, ".//JobSpotOffset"); furn.JobSpawnOffset = XmlParser.ParseVector2(furniture, ".//JobSpawnOffset"); // Debug.Log("Adding Furniture Prototype " + objectType); this.FurniturePrototypes.Add(objectType, furn); var parameters = furniture.SelectSingleNode(".//Params"); if (parameters != null) { foreach (XmlNode param in parameters.ChildNodes) { if (param.Attributes == null) { continue; } var name = param.Attributes["name"].InnerText; var value = float.Parse(param.InnerText); this.FurniturePrototypes[objectType].SetParameter(name, value); } } var callbacks = furniture.SelectNodes(".//OnUpdate"); if (callbacks != null) { foreach (XmlNode callback in callbacks) { var name = callback.InnerText; furn.RegisterUpdateAction(name); } } callbacks = furniture.SelectNodes(".//IsEnterable"); if (callbacks != null) { foreach (XmlNode callback in callbacks) { var name = callback.InnerText; furn.RegisterIsEnterableAction(name); } } foreach (XmlNode buildJob in furniture.SelectNodes(".//BuildingJob")) { // Debug.LogFormat("Adding Job to Furniture {0}...", objectType); var time = float.Parse(buildJob.Attributes["time"].InnerText); var inventory = new List <Inventory>(); foreach (XmlNode inv in buildJob.SelectNodes(".//Inventory")) { var newReq = new Inventory( objectType: inv.Attributes["objectType"].InnerText, maxStackSize: int.Parse(inv.Attributes["amount"].InnerText), stackSize: 0 ); inventory.Add(newReq); } var newJob = new Job( tile: null, jobObjectType: objectType, cbJobComplete: FurnitureActions.JobComplete_FurnitureBuilding, jobTime: time, inventoryRequirements: inventory.ToArray() ) { Name = "Build_" + objectType, Description = "Building " + furn.Name }; this.FurnitureJobPrototypes.Add( key: objectType, value: newJob ); } // Debug.LogFormat("Loaded Furniture {0} succeeded.", objectType); } }
public void OnFurnitureRemoved(Furniture furn) { Furnitures.Remove(furn); }
public void SetFurnitureJobPrototype(Job j, Furniture f) { FurnitureJobPrototypes[f.ObjectType] = j; }