public async Task <IActionResult> UpdateItem(int id, [FromBody] ItemResource itemResource) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } //primeiro vamos achar o item no banco var item = await _repository.GetItem(id); //Se nao existir esse objeto no banco if (item == null) { return(NotFound()); } Mapper.Map <ItemResource, Item>(itemResource, item); await _unitOfWork.CompleteAsync(); item = await _repository.GetItem(item.ItemId); var result = _mapper.Map <Item, ItemResource>(item); return(Ok(result)); }
/// <summary> /// Equip item in inventory. /// </summary> /// <param name="item"> Item is picked in Inventory.</param> /// <returns></returns> public bool AddToEquip(ItemResource item, Action reloadData = null) { var equipSlot = GetSlot(item); if (equipSlot == null) { return(false); } if (equipSlot.itemResource != null) { playerInventory.RemoveEquipmentItem(currentCharacter.characterId, equipSlot.itemResource); playerInventory.AddItem(equipSlot.itemResource); } equipSlot.SetupItem(item); playerInventory.AddEquipmentItem(currentCharacter.characterId, equipSlot.itemResource); playerInventory.RemoveItem(equipSlot.itemResource); // reload data in Inventory reloadData?.Invoke(); return(true); }
public HttpResponseMessage PostItem([FromBody] ItemResource candidate) { SurveyBAL s = new SurveyBAL(); s.PostItemResource(candidate); return(new HttpResponseMessage()); }
private void _serverAddItem(String info) { String[] splitInfo = info.Split(";"); int infoIndex = 0; ItemResource itemResource = _inventoryDatabase.GetItemByID(splitInfo[infoIndex]); infoIndex++; TeamMapAI teamMapAI = _gameWorld.GetTeamMapAIs()[int.Parse(splitInfo[infoIndex])]; infoIndex++; Agent agent = teamMapAI.GetUnit(splitInfo[infoIndex]); infoIndex++; if (agent != null && IsInstanceValid(agent) && itemResource != null && IsInstanceValid(itemResource)) { Inventory inventory = agent.GetInventory(); if (inventory != null && IsInstanceValid(inventory)) { inventory.AddItem(itemResource); // Sync the client no matter if is passing (if not passing, it may indicate cliet is out of sync with server inventory so need to sync) if (GetTree().NetworkPeer != null && GetTree().IsNetworkServer()) { SyncInventory(-1, agent); } } } }
public async Task <IActionResult> CreateItem([FromBody] SaveItemResource saveItemResource) { saveItemResource.SellerId = getUserId(); var validator = new SaveItemResourceValidator(); ValidationResult results = validator.Validate(saveItemResource); if (!results.IsValid) { return(BadRequest(results.Errors)); } Item itemToCreate = _mapper.Map <SaveItemResource, Item>(saveItemResource); var newItem = await _itemService.CreateItem(itemToCreate); if (newItem == null) { return(NotFound()); } var item = await _itemService.GetItemById(newItem.Id); // map item to itemResource before returning in an OkResult object ItemResource itemResource = _mapper.Map <Item, ItemResource>(item); return(Ok(itemResource)); }
public async Task <IActionResult> UpdateItem(int id, [FromBody] SaveItemResource saveItemResource) { var currentItem = await _itemService.GetItemById(id); if (currentItem == null) { return(NotFound()); } bool IsValid = await CheckIfUserIsItemSeller(id); if (!IsValid) { return(Unauthorized()); } var validator = new SaveItemResourceValidator(); ValidationResult results = await validator.ValidateAsync(saveItemResource); if (!results.IsValid) { return(BadRequest(results.Errors)); } Item modifiedItem = _mapper.Map <SaveItemResource, Item>(saveItemResource); await _itemService.UpdateItem(currentItem, modifiedItem); Item updatedItem = await _itemService.GetItemById(id); ItemResource updatedItemResource = _mapper.Map <Item, ItemResource>(updatedItem); return(Ok(updatedItemResource)); }
private void GetItemInfo() { ItemResource item = ResourceManager.Instance.GetItemResource(stat.curItemIndex); stat.curItemMax = item.max; curItemSkill = item.skillprefab; }
private void populatedStorePanel(ItemPanel itemPanel, ItemResource itemResource, int itemIndex) { itemPanel.Initialize(itemResource, ItemPanel.ItemPanelType.PURCHASE, itemIndex, Weapon.WeaponOrder.Right, -1); itemPanel.Show(); itemPanel.Connect(nameof(ItemPanel.ItemPanelPurchaseClickSignal), this, nameof(_purchaseItem)); }
void PickUp(GameObject thisItem) { if (Input.GetKeyDown(KeyCode.F)) { ItemResource resorce = thisItem.GetComponent <ItemScene>().thisItem; //pega o componenete de itemScene do item que esta na mão. Player.singleton.carterScene.inventoryInScene.VerificationItem(resorce, thisItem); //adiciona esse item ao inventario. } }
private void Unequip(ItemResource item) { if (equipmentView.RemoveToUnequip(item, () => inventoryView.ReloadData())) { characterInfoView.UpdateCharacterView(); playerInventory.Save(); } }
private void _createPickUp(ItemResource itemResource, Vector2 itemPosition) { Pickup pickup = (Pickup)((PackedScene)GD.Load("res://items/Pickup.tscn")).Instance(); _gameWorld.AddChild(pickup); pickup.Initialize(this, itemResource); pickup.GlobalPosition = itemPosition; }
public UserService(IUser user) : base() { this.user = user; logoutResource = new LogoutResource(); itemResource = new ItemResource(); allItemsResource = new AllItemsResource(); CheckService(!IsLogged(), "User " + user.ToString() + " Login Unsuccessful."); }
public void RemoveItem() { if (!open) { open = true; itemImage.sprite = nothing; item = null; } }
private void Equip(ItemResource item) { var inventoryId = item.inventoryId; if (equipmentView.AddToEquip(item, () => inventoryView.ReloadDataWithInventoryId(inventoryId))) { characterInfoView.UpdateCharacterView(); playerInventory.Save(); } }
public async Task UpdateItem_ReturnItemResourceInOkObjectResult_WhenUpdateIsSuccess() { //Arrange var itemId = 1; var saveItemResource = new SaveItemResource() { Title = "Updated Item 1", Price = 30.00M, Condition = "New", IsAuction = false, Quantity = 1, SellerId = 1 }; var currentItem = GetTestItems().FirstOrDefault( i => i.Id == itemId); var expectedItemResource = new ItemResource() { Id = itemId, Title = "Updated Item 1", Price = 30.00M, Condition = "New", IsAuction = false, Quantity = 1, SellerId = 1, ImageUrl = new List <FilePath>() }; var updatedItem = _mapper.Map <ItemResource, Item>(expectedItemResource); // subsequent call to GetItemById method to return updatedItem bool firstCall = true; _mockItemService.Setup(service => service.GetItemById(itemId)) .ReturnsAsync(() => { if (firstCall) { firstCall = false; return(currentItem); } return(updatedItem); }); var controller = new ItemsController(_mockItemService.Object, _mapper); SetupHttpContextUser(controller, _user); // Act var result = await controller.UpdateItem(itemId, saveItemResource); var objectResult = result as OkObjectResult; var value = objectResult.Value as ItemResource; // Assert Assert.IsType <OkObjectResult>(result); Assert.Equal(serializeObject(expectedItemResource), serializeObject(value)); }
private void _serverRemoveItem(String info) { String[] splitInfo = info.Split(";"); int infoIndex = 0; int inventoryIndex = int.Parse(splitInfo[infoIndex]); infoIndex++; TeamMapAI teamMapAI = _gameWorld.GetTeamMapAIs()[int.Parse(splitInfo[infoIndex])]; infoIndex++; Agent agent = teamMapAI.GetUnit(splitInfo[infoIndex]); infoIndex++; int dropItem = int.Parse(splitInfo[infoIndex]); infoIndex++; if (agent != null && IsInstanceValid(agent)) { Inventory inventory = agent.GetInventory(); if (inventory != null && IsInstanceValid(inventory)) { if (inventory.GetItem(inventoryIndex) != null && !inventory.IsItemIndexInUsed(inventoryIndex)) { ItemResource itemResource = inventory.GetItem(inventoryIndex); inventory.RemoveItem(inventoryIndex); // Will drop item even if local client not able to remove it, as to sync up state with other servers if (dropItem == 1) { Vector2 itemPosition = agent.GlobalPosition + new Vector2(200f, 200f); _createPickUp(itemResource, itemPosition); if (GetTree().NetworkPeer != null && GetTree().IsNetworkServer()) { String dropItemInfo = itemResource.ItemID + ";" + itemPosition.x + ";" + itemPosition.y + ";"; Rpc(nameof(_clientCreatePickUp), dropItemInfo); } } } // Sync the client no matter if is passing (if not passing, it may indicate cliet is out of sync with server inventory so need to sync) if (GetTree().NetworkPeer != null && GetTree().IsNetworkServer()) { SyncInventory(-1, agent); } } } }
public async Task <IActionResult> CreateItem([FromBody] ItemResource itemResource) { var item = Mapper.Map <ItemResource, Item>(itemResource); _repository.Add(item); await _unitOfWork.CompleteAsync(); var result = _mapper.Map <Item, ItemResource>(item); return(Ok(result)); }
private void populatedInventoryPanel(ItemPanel itemPanel, ItemResource itemResource, int inventoryItemIndex) { itemPanel.Initialize(itemResource, ItemPanel.ItemPanelType.INVENTORY, inventoryItemIndex, Weapon.WeaponOrder.Right, -1); itemPanel.SetUsed(_inventory.IsItemIndexInUsed(inventoryItemIndex)); itemPanel.Connect(nameof(ItemPanel.ItemPanelSaleClickSignal), this, nameof(_sellItem)); itemPanel.Show(); itemPanel.Connect(nameof(ItemPanel.ItemPanelInventoryUseClickSignal), this, nameof(_useItem)); itemPanel.Connect(nameof(ItemPanel.ItemPanelInventoryDropClickSignal), this, nameof(_dropItem)); }
/// <summary> /// Get equipment slot with item type. /// </summary> /// <param name="item"> ItemResource pick in inventory or equipment.</param> /// <returns></returns> private UIModuleInventoryItemView GetSlot(ItemResource item) { foreach (UIModuleEquipmentItemView itemSlot in equipments) { if (PlayerMoney.GetRealItemId(item.id) == (int)itemSlot.id) { return(itemSlot); } } return(null); }
private void populateWeaponChoicePanel(ItemPanel itemPanel, ItemResource itemResource, int inventoryItemIndex, Weapon.WeaponOrder weaponOrder, int weaponIndex) { itemPanel.Initialize(itemResource, ItemPanel.ItemPanelType.WEAPON, inventoryItemIndex, weaponOrder, weaponIndex); itemPanel.SetUsed(_inventory.IsItemIndexInUsed(inventoryItemIndex)); itemPanel.SetEquipped(_inventory.GetEquipItemIndex(weaponOrder, weaponIndex) == inventoryItemIndex); itemPanel.Show(); itemPanel.Connect(nameof(ItemPanel.ItemPanelWeaponEquipClickSignal), this, nameof(_equipWeapon)); itemPanel.Connect(nameof(ItemPanel.ItemPanelWeaponUnequipClickSignal), this, nameof(_unequipWeapon)); }
private static void CreateItem(CategoryResource aCategory, string aTitle, string aInfo) { ItemResource item = new ItemResource { Title = aTitle, Content = new XmlDocument().CreateCDataSection(aInfo), }; Assert.Check(item.Valid()); aCategory.Items.Add(item); }
public void Initialize(ItemResource itemResource, ItemPanelType itemPanelType, int inventoryIndex, Weapon.WeaponOrder weaponOrder, int weaponIndex) { SelfModulate = _exitedColor; _itemResource = itemResource; _isOnPanel = false; _isUsed = false; _isEquipped = false; _itemPanelType = itemPanelType; _inventoryIndex = inventoryIndex; _weaponOrder = weaponOrder; _weaponIndex = weaponIndex; ((RichTextLabel)(GetNode("Name"))).Text = "[" + _inventoryIndex + "] " + _itemResource.ItemID + " " + _itemResource.Name; ((Label)(GetNode("Price"))).Text = "COST: " + _itemResource.Price; ((RichTextLabel)(GetNode("Description"))).Text = _itemResource.Description; ((TextureRect)(GetNode("Image"))).Texture = _itemResource.ReferenceTexture; ((TextureRect)(GetNode("Image"))).RectScale = new Vector2(0.5f, 0.5f); if (ItemPanelType.PURCHASE == itemPanelType) { Button btn = ((Button)GetNode("Purchase")); btn.Show(); btn.Connect("pressed", this, nameof(_purchase)); } if (ItemPanelType.WEAPON == itemPanelType) { Button btn = ((Button)GetNode("Equip")); btn.Show(); btn.Connect("pressed", this, nameof(_equip)); btn = ((Button)GetNode("Unequip")); btn.Connect("pressed", this, nameof(_unequip)); } if (ItemPanelType.INVENTORY == itemPanelType) { Button btn = ((Button)GetNode("Drop")); btn.Show(); btn.Connect("pressed", this, nameof(_drop)); btn = ((Button)GetNode("Sell")); btn.Show(); btn.Connect("pressed", this, nameof(_sell)); if (_itemResource.CurrentItemType == ItemResource.ItemType.USABLE) { btn = ((Button)GetNode("Use")); btn.Show(); btn.Connect("pressed", this, nameof(_use)); } } }
public void AddItem(ItemResource itemResource, Inventory inventory) { // Add item only process at master if (GetTree().NetworkPeer == null || GetTree().IsNetworkServer()) { if (inventory != null && itemResource != null && IsInstanceValid(inventory) && IsInstanceValid(itemResource)) { String info = itemResource.ItemID + ";" + (int)inventory.GetAgent().GetCurrentTeam() + ";" + inventory.GetAgent().GetUnitName(); _serverAddItem(info); } } }
public ItemResource GetItemResource(byte _itemindex) { ItemResource item = new ItemResource(); string _path = objectDataList[_itemindex][(int)OBJECTDATA.ITEMNAME]; item.sprite = Resources.Load <Sprite>("Prefab/ActiveItem/Image/" + _path); item.image = Resources.Load("Prefab/ActiveItem/Image/" + _path, typeof(Texture2D)) as Texture2D; item.skillprefab = Resources.Load("Prefab/ActiveItem/Object/" + _path) as GameObject; item.max = byte.Parse(objectDataList[_itemindex][(int)OBJECTDATA.MAXSTACK]); return(item); }
public async Task <ItemResource> CreateItem(ItemResource newItemResource) { var item = _mapper.Map <ItemResource, Item>(newItemResource); _itemRepo.Add(item); await _unitOfWork.Complete(); var itemInDb = await GetItem(item.Id); var result = _mapper.Map <Item, ItemResource>(itemInDb); return(result); }
public bool AddItem(ItemResource itemResource) { if (itemResource == null) { return(false); } ItemResource resource = itemResource; inventoryDic.Add(resource.inventoryId, resource); resourceList.AddData(resource); return(true); }
public bool GetItem(ItemResource itemResource, int qnt) { for (int i = 1; i <= qnt; i++) { inventory.AddItem(itemResource.idItem); } GameObject item = Instantiate(getItem, gameObject.transform.position + new Vector3(0, 5, 0), Quaternion.identity); item.GetComponent <SpriteRenderer>().sprite = inventory.FindItem(itemResource.idItem).Sprite; item.gameObject.transform.GetChild(0).GetComponent <TextMesh>().text = "+" + qnt; return(VerifyQuest(itemResource)); }
public void PostItemResource(ItemResource item) { using (var context = new SurveyEntities()) { tbl_Questions que = new tbl_Questions { itemScript = item.questionScript, createdBy = "Ravi", createdDate = System.DateTime.Now, state = 1, status = "live" }; context.tbl_Questions.Add(que); context.SaveChanges(); } }
public bool AddNewItem(ItemResource itemResource) { if (itemResource == null) { return(false); } ItemResource resource = itemResource; resource.inventoryId = resourceList.inventoryIdMax + 1; inventoryDic.Add(resource.inventoryId, resource); resourceList.AddNewData(resource); Save(); return(true); }
// Add item through unit cost in team public void PurchaseItem(ItemResource itemResource, Inventory inventory) { if (inventory != null && itemResource != null && IsInstanceValid(inventory) && IsInstanceValid(itemResource)) { String info = itemResource.ItemID + ";" + (int)inventory.GetAgent().GetCurrentTeam() + ";" + inventory.GetAgent().GetUnitName(); if (GetTree().NetworkPeer != null && !GetTree().IsNetworkServer()) { RpcId(1, nameof(_serverPurchaseItem), info); } else { _serverPurchaseItem(info); } } }