static public Furniture PlaceInstance(Furniture prototype, Tile tile) { if (prototype.funcPositionValidation(tile) == false) { Debug.LogError("PlaceInstance -- Position Validity Function returned FALSE."); return(null); } // Place of destination is valid at this point. Furniture furn = prototype.Clone(); furn.tile = tile; // FIXME: This assumes we are 1x1 if (tile.PlaceFurniture(furn) == false) { // Probably already occupied return(null); } if (furn.linksToNeighbour) { // Must inform neighbours there is a new furniture coming and they should trigger their OnChangedCallback furn.UpdateNeighbours(furn); } return(furn); }
public static Furniture PlaceInstance(Furniture proto, Tile tile) { if (proto.funcPositionValidation(tile) == false) { Debug.ULogErrorChannel("Furniture", "PlaceInstance -- Position Validity Function returned FALSE."); return(null); } // We know our placement destination is valid. Furniture obj = proto.Clone(); obj.Tile = tile; // FIXME: This assumes we are 1x1! if (tile.PlaceFurniture(obj) == false) { // For some reason, we weren't able to place our object in this tile. // (Probably it was already occupied.) // Do NOT return our newly instantiated object. // (It will be garbage collected.) return(null); } if (obj.LinksToNeighbour) { // This type of furniture links itself to its neighbours, // so we should inform our neighbours that they have a new // buddy. Just trigger their OnChangedCallback. int x = tile.X; int y = tile.Y; for (int xpos = x - 1; xpos < x + proto.Width + 1; xpos++) { for (int ypos = y - 1; ypos < y + proto.Height + 1; ypos++) { Tile tileAt = World.Current.GetTileAt(xpos, ypos); if (tileAt != null && tileAt.Furniture != null && tileAt.Furniture.Changed != null) { tileAt.Furniture.Changed(tileAt.Furniture); } } } } // Call LUA install scripts obj.EventActions.Trigger("OnInstall", obj); // Update thermalDiffusifity using coefficient float thermalDiffusivity = Temperature.defaultThermalDiffusivity; if (obj.furnParameters.ContainsKey("thermal_diffusivity")) { thermalDiffusivity = obj.furnParameters["thermal_diffusivity"].ToFloat(); } World.Current.temperature.SetThermalDiffusivity(tile.X, tile.Y, thermalDiffusivity); return(obj); }
static public Furniture PlaceInstance(Furniture proto, Tile tile) { if (proto.funcPositionValidation(tile) == false) { //Debug.LogError("PlaceInstance -- Position Validity Function returned FALSE."); return(null); } // We know our placement destination is valid. Furniture obj = proto.Clone(); obj.tile = tile; // FIXME: This assumes we are 1x1! if (tile.PlaceFurniture(obj) == false) { // For some reason, we weren't able to place our object in this tile. // (Probably it was already occupied.) // Do NOT return our newly instantiated object. // (It will be garbage collected.) return(null); } if (obj.linksToNeighbour) { // This type of furniture links itself to its neighbours, // so we should inform our neighbours that they have a new // buddy. Just trigger their OnChangedCallback. Tile t; int x = tile.X; int y = tile.Y; t = tile.world.GetTileAt(x, y + 1); if (t != null && t.Furniture != null && t.Furniture.cbOnChanged != null && t.Furniture.objectType == obj.objectType) { // We have a Northern Neighbour with the same object type as us, so // tell it that it has changed by firing is callback. t.Furniture.cbOnChanged(t.Furniture); } t = tile.world.GetTileAt(x + 1, y); if (t != null && t.Furniture != null && t.Furniture.cbOnChanged != null && t.Furniture.objectType == obj.objectType) { t.Furniture.cbOnChanged(t.Furniture); } t = tile.world.GetTileAt(x, y - 1); if (t != null && t.Furniture != null && t.Furniture.cbOnChanged != null && t.Furniture.objectType == obj.objectType) { t.Furniture.cbOnChanged(t.Furniture); } t = tile.world.GetTileAt(x - 1, y); if (t != null && t.Furniture != null && t.Furniture.cbOnChanged != null && t.Furniture.objectType == obj.objectType) { t.Furniture.cbOnChanged(t.Furniture); } } return(obj); }
// Create furniture from parameter -- this will probably only be used for prototypes //public Furniture(string objectType, float movementCost = 1f, int width = 1, int height = 1, bool linksToNeighbour = false, bool roomEnclosure = false) //{ // this.objectType = objectType; // this.movementCost = movementCost; // this.roomEnclosure = roomEnclosure; // this.Width = width; // this.Height = height; // this.linksToNeighbour = linksToNeighbour; // this.funcPositionValidation = this.DEFAULT__IsValidPosition; // furnParameters = new Dictionary<string, float>(); //} static public Furniture PlaceInstance(Furniture proto, Tile tile) { if (proto.funcPositionValidation(tile) == false) { Debug.LogError("PlaceInstance -- Position Validity function returned false."); return(null); } // We know our placement destination is valid Furniture furn = proto.Clone(); //new Furniture(proto); furn.tile = tile; // FIXME: this assumes 1x1 if (tile.PlaceFurniture(furn) == false) { // For some reason we weren't able t place the object in this tile // (probably already occupied) // Do not return our newly instantiated object // (it will be garbage) return(null); } if (furn.linksToNeighbour) { // This type of furniture links itself to its neighbours, // so we should inform our neighbours of a new neighbour. // Trigger their OnChangedCallback Tile t; int x = tile.X; int y = tile.Y; t = World.Current.GetTileAt(x, y + 1); if (t != null && t.furniture != null && t.furniture.cbOnChanged != null && t.furniture.objectType == furn.objectType) { // We have a northern neighbour with the same object type as us, so // tell it that it has changed by firing its callback t.furniture.cbOnChanged(t.furniture); } t = World.Current.GetTileAt(x + 1, y); if (t != null && t.furniture != null && t.furniture.cbOnChanged != null && t.furniture.objectType == furn.objectType) { t.furniture.cbOnChanged(t.furniture); } t = World.Current.GetTileAt(x, y - 1); if (t != null && t.furniture != null && t.furniture.cbOnChanged != null && t.furniture.objectType == furn.objectType) { t.furniture.cbOnChanged(t.furniture); } t = World.Current.GetTileAt(x - 1, y); if (t != null && t.furniture != null && t.furniture.cbOnChanged != null && t.furniture.objectType == furn.objectType) { t.furniture.cbOnChanged(t.furniture); } } return(furn); }
/// <summary> /// Used to place furniture in a certain position. /// </summary> /// <param name="proto">The prototype furniture to place.</param> /// <param name="tile">The base tile to place the furniture on, The tile will be the bottom left corner of the furniture (to check).</param> /// <returns>Furniture object.</returns> public static Furniture PlaceInstance(Furniture proto, Tile tile) { if (proto.IsValidPosition(tile) == false) { UnityDebugger.Debugger.LogWarning("Furniture", "PlaceInstance :: Position Validity Function returned FALSE. " + proto.Type + " " + tile.X + ", " + tile.Y + ", " + tile.Z); return(null); } // We know our placement destination is valid. Furniture furnObj = proto.Clone(); furnObj.Tile = tile; if (tile.PlaceFurniture(furnObj) == false) { // For some reason, we weren't able to place our object in this tile. // (Probably it was already occupied.) // Do NOT return our newly instantiated object. // (It will be garbage collected.) return(null); } // need to update reference to furniture and call Initialize (so components can place hooks on events there) foreach (BuildableComponent component in furnObj.components) { component.Initialize(furnObj); } if (furnObj.LinksToNeighbour != string.Empty) { // This type of furniture links itself to its neighbours, // so we should inform our neighbours that they have a new // buddy. Just trigger their OnChangedCallback. int x = tile.X; int y = tile.Y; for (int xpos = x - 1; xpos < x + proto.Width + 1; xpos++) { for (int ypos = y - 1; ypos < y + proto.Height + 1; ypos++) { Tile tileAt = World.Current.GetTileAt(xpos, ypos, tile.Z); if (tileAt != null && tileAt.Furniture != null && tileAt.Furniture.Changed != null) { tileAt.Furniture.Changed(tileAt.Furniture); } } } } // Let our workspot tile know it is reserved for us World.Current.ReserveTileAsWorkSpot(furnObj); // Call LUA install scripts furnObj.EventActions.Trigger("OnInstall", furnObj); return(furnObj); }
static public Furniture PlaceInstance(Furniture proto, Tile tile) { if (proto.funcPositionValidation(tile) == false) { Debug.LogError("PlaceInstance -- Furniture Position is not valid"); return(null); } //We know our placement destination is valid Furniture objFurniture = proto.Clone(); objFurniture.tile = tile; //Todo Fixme this assumes we are 1x1 if (tile.PlaceFurniture(objFurniture) == false) { //for some reason we weren't able to place our object in this tile //Probably it was already occupied //Do not return our newly instantiated object. //(it will be garbage collected) return(null); } if (objFurniture.linksToNeighbour) { //This type of furniture links itself to its neighbours //Informs furniture that they have a new buddy by triggering onchangedcallback Tile tempTile; int x = tile.X; int y = tile.Y; tempTile = tile.world.GetTileAt(x, y + 1); if (tempTile != null && tempTile.furniture != null && tempTile.furniture.callBackOnChanged != null && tempTile.furniture.objectType == objFurniture.objectType) { //We have a northern neighbour with the same object type as us //tell the furniture to change by firing the callback tempTile.furniture.callBackOnChanged(tempTile.furniture); } tempTile = tile.world.GetTileAt(x, y - 1); if (tempTile != null && tempTile.furniture != null && tempTile.furniture.callBackOnChanged != null && tempTile.furniture.objectType == objFurniture.objectType) { tempTile.furniture.callBackOnChanged(tempTile.furniture); } tempTile = tile.world.GetTileAt(x + 1, y); if (tempTile != null && tempTile.furniture != null && tempTile.furniture.callBackOnChanged != null && tempTile.furniture.objectType == objFurniture.objectType) { tempTile.furniture.callBackOnChanged(tempTile.furniture); } tempTile = tile.world.GetTileAt(x - 1, y); if (tempTile != null && tempTile.furniture != null && tempTile.furniture.callBackOnChanged != null && tempTile.furniture.objectType == objFurniture.objectType) { tempTile.furniture.callBackOnChanged(tempTile.furniture); } } return(objFurniture); }
static public Furniture PlaceInstance(Furniture proto, Tile tile) { if (proto.funcPositionValidation(tile) == false) { //Debug.LogError("Cannot place furniture here."); return(null); } Furniture instance = proto.Clone(); instance.tile = tile; //TODO Assumes 1x1 size. if (tile.PlaceObject(instance) == false) { //Not able to place, probably already occupied. return(null); } if (instance.linksToNeighbour == true) { Tile t; int x = tile.X; int y = tile.Y; t = tile.world.GetTileAt(x, y + 1); if (t != null && t.furniture != null && t.furniture.cbOnChanged != null && t.furniture.furnitureType == instance.furnitureType) { t.furniture.cbOnChanged(t.furniture); } t = tile.world.GetTileAt(x + 1, y); if (t != null && t.furniture != null && t.furniture.cbOnChanged != null && t.furniture.furnitureType == instance.furnitureType) { t.furniture.cbOnChanged(t.furniture); } t = tile.world.GetTileAt(x, y - 1); if (t != null && t.furniture != null && t.furniture.cbOnChanged != null && t.furniture.furnitureType == instance.furnitureType) { t.furniture.cbOnChanged(t.furniture); } t = tile.world.GetTileAt(x - 1, y); if (t != null && t.furniture != null && t.furniture.cbOnChanged != null && t.furniture.furnitureType == instance.furnitureType) { t.furniture.cbOnChanged(t.furniture); } } return(instance); }
public static Furniture PlaceInstance(Furniture proto, Tile tile) { if (!proto.funcPositionValidation(tile)) { Debug.LogError("Place instance - couldn't place item here"); return(null); } //now know it's valid. Furniture obj = (Furniture)proto.Clone(); //obj.objectType = proto.objectType; //obj.movementCost = proto.movementCost; //obj.width = proto.width; //obj.height = proto.height; //obj.linksToNeighbour = proto.linksToNeighbour; obj.tile = tile; if (!tile.InstallFurniture(obj)) { //we couldn't place the object here. Probs already occupied return(null); } if (obj.linksToNeighbour) { int x = tile.X; int y = tile.Y; //Orthogonals TriggerOnChanged(tile.world.GetTileAt(x, y + 1), obj.objectType); TriggerOnChanged(tile.world.GetTileAt(x + 1, y), obj.objectType); TriggerOnChanged(tile.world.GetTileAt(x, y - 1), obj.objectType); TriggerOnChanged(tile.world.GetTileAt(x - 1, y), obj.objectType); //Diagonals TriggerOnChanged(tile.world.GetTileAt(x + 1, y + 1), obj.objectType); TriggerOnChanged(tile.world.GetTileAt(x + 1, y - 1), obj.objectType); TriggerOnChanged(tile.world.GetTileAt(x - 1, y - 1), obj.objectType); TriggerOnChanged(tile.world.GetTileAt(x - 1, y + 1), obj.objectType); } return(obj); }
/// <summary> /// 放置对象 /// </summary> /// <param name="proto"></param> /// <param name="tile"></param> /// <returns></returns> public static Furniture PlaceObject(Furniture proto, Tile tile) { if (proto.funcPositionValidation != null && !proto.funcPositionValidation(tile)) { //Debug.LogError("PlaceObject - 位置有效性函数返回FALSE。"); return(null); } Furniture info = proto.Clone(); info.tile = tile; if (tile.PlaceObject(info) == false) { return(null); } if (info.linksToNeighbour) { // 这种类型的家具与其邻居相连, //所以我们应该通知你的邻居他们有一个新的伙伴。 只需触发他们的OnChange回调。 int x = tile.x; int y = tile.y; var t = tile.world.GetTileAt(x, y + 1); if (t != null && t.furniture != null && t.furniture.objectType == info.objectType) { //我们有一个与我们相同的对象类型的北方邻居,所以 //通过触发告诉它已经改变了回调。 t.furniture.cbOnChanged(t.furniture); } t = tile.world.GetTileAt(x + 1, y); if (t != null && t.furniture != null && t.furniture.cbOnChanged != null && t.furniture.objectType == info.objectType) { t.furniture.cbOnChanged(t.furniture); } t = tile.world.GetTileAt(x, y - 1); if (t != null && t.furniture != null && t.furniture.cbOnChanged != null && t.furniture.objectType == info.objectType) { t.furniture.cbOnChanged(t.furniture); } t = tile.world.GetTileAt(x - 1, y); if (t != null && t.furniture != null && t.furniture.cbOnChanged != null && t.furniture.objectType == info.objectType) { t.furniture.cbOnChanged(t.furniture); } } return(info); }
public static Furniture PlaceInstance(Furniture prototype, Tile tile) { if (prototype.funcPositionValidation(tile) == false) { //Debug.LogError ("placeInstance -- position validity function returned false"); return(null); } Furniture furniture = prototype.Clone(); furniture.tile = tile; if (tile.placeFurniture(furniture) == false) { return(null); } if (furniture.linksToNeighboors == true) { Tile t; int x = tile.X; int y = tile.Y; for (int i = -1; i <= 1; i++) { for (int j = -1; j <= 1; j++) { if (i != 0 || j != 0) { t = World.worldInstance.getTileAt(x + i, y + j); //Debug.Log (t.X + " , " + t.Y); if (t != null && t.furniture != null && t.furniture.onChangedCallback != null && t.furniture.furnitureType == furniture.furnitureType) { t.furniture.onChangedCallback(t.furniture); } } } } } return(furniture); }
private void Add_Click(object sender, RoutedEventArgs e) { int quant = Int32.Parse(cbQuantity.Text); bool firstTime = true; foreach (var f in Project.Instance.Bill.FurnitureForSaleList) { var price = f.Price; if (f.PriceOnSale != 0) { price = f.PriceOnSale; } if (furniture.ID == f.ID) { firstTime = false; f.Quantity = f.Quantity + quant; Project.Instance.Bill.FullPrice = Project.Instance.Bill.FullPrice + (price * quant); } } if (firstTime) { Furniture selledFurniture = (Furniture)furniture.Clone(); selledFurniture.Quantity = quant; Project.Instance.Bill.FurnitureForSaleList.Add(selledFurniture); foreach (var f in Project.Instance.Bill.FurnitureForSaleList) { var price = f.Price; if (f.PriceOnSale != 0) { price = f.PriceOnSale; Project.Instance.Bill.FullPrice = Project.Instance.Bill.FullPrice + (price * quant); } } } this.Close(); }
/// <summary> /// Used to place furniture in a certain position. /// </summary> /// <param name="proto">The prototype furniture to place.</param> /// <param name="tile">The base tile to place the furniture on, The tile will be the bottom left corner of the furniture (to check).</param> /// <returns>Furniture object.</returns> public static Furniture PlaceInstance(Furniture proto, Tile tile) { if (proto.IsValidPosition(tile) == false) { Debug.ULogErrorChannel("Furniture", "PlaceInstance -- Position Validity Function returned FALSE. " + proto.Name + " " + tile.X + ", " + tile.Y + ", " + tile.Z); return(null); } // We know our placement destination is valid. Furniture furnObj = proto.Clone(); furnObj.Tile = tile; if (tile.PlaceFurniture(furnObj) == false) { // For some reason, we weren't able to place our object in this tile. // (Probably it was already occupied.) // Do NOT return our newly instantiated object. // (It will be garbage collected.) return(null); } // plug-in furniture only when it is placed in world if (furnObj.PowerConnection != null) { World.Current.PowerNetwork.PlugIn(furnObj.PowerConnection); } // need to update reference to furniture and call Initialize (so components can place hooks on events there) foreach (var comp in furnObj.components) { comp.Initialize(furnObj); } if (furnObj.LinksToNeighbour != string.Empty) { // This type of furniture links itself to its neighbours, // so we should inform our neighbours that they have a new // buddy. Just trigger their OnChangedCallback. int x = tile.X; int y = tile.Y; for (int xpos = x - 1; xpos < x + proto.Width + 1; xpos++) { for (int ypos = y - 1; ypos < y + proto.Height + 1; ypos++) { Tile tileAt = World.Current.GetTileAt(xpos, ypos, tile.Z); if (tileAt != null && tileAt.Furniture != null && tileAt.Furniture.Changed != null) { tileAt.Furniture.Changed(tileAt.Furniture); } } } } // Let our workspot tile know it is reserved for us World.Current.ReserveTileAsWorkSpot(furnObj); // Call LUA install scripts furnObj.EventActions.Trigger("OnInstall", furnObj); // Update thermalDiffusivity using coefficient float thermalDiffusivity = Temperature.defaultThermalDiffusivity; if (furnObj.Parameters.ContainsKey("thermal_diffusivity")) { thermalDiffusivity = furnObj.Parameters["thermal_diffusivity"].ToFloat(); } World.Current.temperature.SetThermalDiffusivity(tile.X, tile.Y, tile.Z, thermalDiffusivity); return(furnObj); }
static public Furniture PlaceInstance(Furniture proto, Tile tile) { if (tile == null) { Debug.LogError("PlaceInstance -- tile is null"); } if (proto.funcPositionValidation(tile) == false) { Debug.LogError("PlaceInstance -- Position Validity Function returned FALSE."); return(null); } //We know our placement destination is valid Furniture obj = proto.Clone(); obj.Tile = tile; //FIXME:This assumes we are 1x1! if (!tile.PlaceObject(obj)) { //For some reason, we weren't able to place our object in this tile. //Probably it was already occupied. //Do not return our newly instantiated object, instead it will be garbage collected. return(null); } if (obj.LinksToNeighbour) { //Notify neighbours that i am here Tile t; int x = tile.X, y = tile.Y; /*for (int i = -1; i <= 1; i++) { * for (int j = -1; j <= 1; j++) { * Debug.Log("Getting tile at: " + (i + x) + "," + ) * t = tile.world.GetTileAt(i + x, j + y); * if (t != null && t.furniture != null && t.furniture.ObjectType == obj.ObjectType) * t.furniture.cbOnChanged(t.furniture); * } * }*/ t = tile.world.GetTileAt(x, y + 1); if (t != null && t.furniture != null && t.furniture.cbOnChanged != null && t.furniture.ObjectType == obj.ObjectType) { t.furniture.cbOnChanged(t.furniture); } t = tile.world.GetTileAt(x + 1, y); if (t != null && t.furniture != null && t.furniture.cbOnChanged != null && t.furniture.ObjectType == obj.ObjectType) { t.furniture.cbOnChanged(t.furniture); } t = tile.world.GetTileAt(x, y - 1); if (t != null && t.furniture != null && t.furniture.cbOnChanged != null && t.furniture.ObjectType == obj.ObjectType) { t.furniture.cbOnChanged(t.furniture); } t = tile.world.GetTileAt(x - 1, y); if (t != null && t.furniture != null && t.furniture.cbOnChanged != null && t.furniture.ObjectType == obj.ObjectType) { t.furniture.cbOnChanged(t.furniture); } } return(obj); }