public async Task <ActionResult <BuildingItem> > PostBuildingItem(BuildingItem item) { _context.BuildingsItems.Add(item); await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(GetBuildingItem), new { id = item.Id }, item)); }
public void RemoveBuilding(BuildingItem item) { if (allBuildings.Contains(item)) { allBuildings.Remove(item); } }
public void AddNewBuiliding(BuildingItem item) { if (!allBuildings.Contains(item)) { allBuildings.Add(item); } }
public void changeBuildingSprite(GameObject targetBuildingObject, BuildingData buildingDataTemp) { BuildingItem buildingItem = FarmDataManager._Instance.dataManager.GetBuildingItemByID((int)buildingDataTemp.buildingType); string SpriteName = buildingItem.SpriteName[buildingDataTemp.nowLevel]; Sprite sprites = Resources.Load("Map/Buildings/" + SpriteName, typeof(Sprite)) as Sprite; targetBuildingObject.GetComponent <SpriteRenderer>().sprite = sprites; }
/// <summary> /// /// </summary> /// <returns></returns> public BuildingItem GetBuildItem() { BuildingItem bitem = gameObject.GetComponentSecure <BuildingItem>(); bitem.buildingInfo = buildInfo; bitem.Init(); return(bitem); }
public async Task <ContactItem> GetContactForBuilding(BuildingItem buildingItem) { MRModel context = new MRModel(); var toReturn = await(from item in context.ContactItems where item.id == buildingItem.Owner.id select item).SingleOrDefaultAsync(); return(toReturn); }
public BuildingItem GetBuildingItemByID(Int32 id) { BuildingItem t = null; p_Building.Dict.TryGetValue(id, out t); if (t == null) { Debug.LogWarning("can't find the id " + id + " in Building"); } return(t); }
public async Task <IActionResult> PutBuildingItem(long id, BuildingItem item) { if (id != item.Id) { return(BadRequest()); } _context.Entry(item).State = EntityState.Modified; await _context.SaveChangesAsync(); return(NoContent()); }
public void Build() { if (AppManager.Instance.SelectedItem != null) { BuildingItem selectedItem = AppManager.Instance.SelectedItem.GetComponent <BuildingItem>(); if (selectedItem != null) { selectedItem.Build(); } } }
private void UpdatePlacing() { if (!InBuildMode) { return; } if (!InputManager.InputPressed("Shoot")) { return; } int x = (int)InputManager.GetMousePos().x; int y = (int)InputManager.GetMousePos().y; if (CanPlace(x, y) != null) { return; } if (Player.Local == null) { return; } if (BuildingUI.Instance == null) { return; } BuildingItem item = GetSelectedItem(); if (item != null) { // Place tile using the pending building system. // My god the code in this project is horrible :/ string layer = "Foreground"; switch (item.Type) { case BuildingItemType.FURNITURE: Furniture f = item.GetFurniture(); layer = f.Layer; break; case BuildingItemType.TILE: BaseTile tile = item.GetTile(); layer = tile.Layer; break; } PendingBuildingManager.Instance.AddPending(x, y, item.Prefab, item.Type, layer); } }
public BuildingItem GetSelectedItem() { int index = BuildingUI.Instance.Bar.SelectedIndex; if (index < 0 || index >= BuildingUI.Instance.Bar.Items.Count) { return(null); } BuildingItem item = BuildingUI.Instance.Bar.Items[index]; return(item); }
public string CanPlace(int x, int y) { bool inBounds = World.Instance.TileMap.InBounds(x, y); if (!inBounds) { return("Out of world bounds!"); } bool placementMode = InBuildMode && !menuOpen; if (!placementMode) { return("Not in placement mode!"); } BuildingItem item = GetSelectedItem(); bool hasSelected = item != null; if (!hasSelected) { return("No buildable selected! Hold [" + InputManager.GetInput("Toggle Build Mode") + "] to open menu."); } if (item.Type == BuildingItemType.TILE) { BaseTile oldTile = World.Instance.TileMap.GetLayer(item.GetTile().Layer).GetTile(x, y); if (oldTile != null) { return("Space already occupied!"); } bool canPlaceTile = World.Instance.TileMap.GetLayer(item.GetTile().Layer).CanPlaceTile(x, y); if (!canPlaceTile) { return("Space already occupied!"); } } else if (item.Type == BuildingItemType.FURNITURE) { bool canPlaceFurniture = !World.Instance.Furniture.IsFurnitureAt(x, y) && World.Instance.TileMap.GetLayer(item.GetFurniture().Layer).GetTile(x, y) == null; if (!canPlaceFurniture) { return("Space already occupied!"); } } return(null); }
public void AddItems(BaseTile tile, int count) { if (count <= 0) { return; } if (tile == null) { return; } BuildingItem item = new BuildingItem(tile, count); AddItem(item); }
public void AddItems(Furniture furn, int count) { if (count <= 0) { return; } if (furn == null) { return; } BuildingItem item = new BuildingItem(furn, count); AddItem(item); }
private void AddItem(BuildingItem item) { // Assumes that the item.Count value has already been assigned. // We might already have this item in our inventory. if (items.ContainsKey(item.Prefab)) { items[item.Prefab].Count += item.Count; } else { // We don't already have it, so add it! items.Add(item.Prefab, item); } ActionID++; }
public void RemoveItems(string prefab, int count) { if (count < 0) { count *= -1; } if (items.ContainsKey(prefab)) { BuildingItem i = items[prefab]; i.Count -= count; if (i.Count <= 0) { items.Remove(prefab); } } }
private static long _tickThreashold = 3; //number of ticks before output is generated //TODO: SAMPLE VALUE, also wrong type, a tick is not a long #endregion Fields #region Methods //TODO: decide the best way to pass back errors public static void Run(InventoryManager inventory, BuildingItem item, long ticks) { for (long tick = item.CurrentTicks; tick == _tickThreashold; tick++) //TODO: loop through ticks { if (HasEnoughEnergy()) { //consumablematerials = KeyValuePair<ItemTypeBase, long> foreach (KeyValuePair<ItemTypeBase, long> consumable in ((BuildingItemType)item.ItemType).ConsumableMaterials) { //first pass - make sure inventory has enough of everything needed for this building if (!inventory.HasEnoughItems(consumable.Key, consumable.Value)) { break; //throw? } } //all necessary input is available in inventory, so subtract it for this pass. foreach (KeyValuePair<ItemTypeBase, long> consumable in ((BuildingItemType)item.ItemType).ConsumableMaterials) { inventory.RemoveItems(consumable.Key, consumable.Value); } //if this process has run the necessary number of ticks if (item.CurrentTicks == _tickThreashold) { foreach (KeyValuePair<ItemTypeBase, long> output in ((BuildingItemType)item.ItemType).OutputMaterials) { inventory.AddItems(output.Key, output.Value); } item.ResetCurrentTicks(); } else { item.IncrementCurrentTicks(); } } } }
/// <summary> /// 预建造 /// </summary> /// <param name="commandType"></param> /// <param name="item"></param> /// <param name="contents">建造物所包含的格子(房间等占多个格子)</param> public void PreBuild(BuildCommandType commandType, BuildingItem item, List <TileItem> contents = null) { //生成新的建造物并放置在指定层 switch (commandType) { case BuildCommandType.BuildGroundwork: mGroundworkItem = (GroundworkItem)item; mGroundworkItem.BindTileItem(this); break; case BuildCommandType.BuildWall: WallItem = (WallItem)item; WallItem.BindTileItem(this); if (BelongRoom) //在已有房间内建墙,墙壁不属于房间的一部分 { RoomItem.UnBindTileItem(this); RoomItem = null; } break; case BuildCommandType.BuildDoor: DoorItem = (DoorItem)item; DoorItem.BindTileItem(this); break; case BuildCommandType.BuildRoom: RoomItem = (RoomItem)item; RoomItem.BindTileItem(contents); break; case BuildCommandType.BuildDecorate: break; } mPreBuildingItem = item; mPreBuildingItem.PreBuild(); }
public bool HaveBuild(Vector3 pos) { for (int k = 0; k < allBuildings.Count; k++) { BuildingItem build = allBuildings[k]; //print(build); for (int i = 0; i < build.buildingInfo.locat.GetLength(0); i++) { for (int j = 0; j < build.buildingInfo.locat.GetLength(1); j++) { Grid grid = build.buildingInfo.locat[i, j]; if (grid.pos.x == pos.x && grid.pos.z == pos.z) { //垂直距离 if (build.buildingInfo.height > Mathf.Abs(pos.y - build.transform.position.y)) { return(false); } } } } } return(true); }
public BuildingItem(BuildingItem ai) : base(ai) { this.StaminaCost = ai.StaminaCost; this.ChannelDuration = ai.ChannelDuration; this.Consumable = ai.Consumable; }