public async Task <IActionResult> PutFreeItem([FromRoute] int id, [FromBody] FreeItem freeItem) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != freeItem.Id) { return(BadRequest()); } _context.Entry(freeItem).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!FreeItemExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task DoesReturnOk_GivenFreeItemExists() { //Arrange var item = new FreeItem { Description = "Item", Name = "Name" }; _testContext.DbContext.FreeItems.Add(item); _testContext.DbContext.SaveChanges(); var editedItem = new FreeItem { Description = "EditedItem", Name = "EditedName" }; var stringEditedItem = new StringContent(JsonConvert.SerializeObject(editedItem), Encoding.UTF8, "application/json"); //Act var response = await _testContext.HttpClient.PutAsync($"api/FreeItems/{item.Id}", stringEditedItem); string jsonResult = await response.Content.ReadAsStringAsync(); var freeItemFromJson = JsonConvert.DeserializeObject <FreeItem>(jsonResult); //Assert Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.Equal(editedItem.Name, freeItemFromJson.Name); Assert.Equal(editedItem.Description, freeItemFromJson.Description); }
private void handleFromGround(string from, string to, ServerRoom room, FreeData fd) { if (from.StartsWith(Ground) && !to.StartsWith(Ground)) { SimpleItemInfo info = PickupItemUtil.GetGroundItemInfo(room, fd, from); if (info.cat > 0) { ItemInventory inv = fd.freeInventory.GetInventoryManager().GetInventory("ground"); if (inv != null) { inv.Clear(); FreeItem item = FreeItemManager.GetItem(room.FreeArgs, FreeItemConfig.GetItemKey(info.cat, info.id), info.count); item.GetParameters().AddPara(new IntPara("entityId", info.entityId)); inv.AddItem(room.FreeArgs, item, false); DragGroundOne(fd, room, to); } else { Debug.LogErrorFormat("inventory {0} not existed.", from); } } } }
public override void DoAction(IEventArgs args) { FreeRuleEventArgs fr = (FreeRuleEventArgs)args; if (StringUtil.IsNullOrEmpty(count) || count.Equals("0")) { count = INI_COUNT; } int c = FreeUtil.ReplaceInt(count, args); FreeItem item = FreeItemManager.GetItem(fr, FreeUtil.ReplaceVar(key, args), c); if (item != null) { if (!StringUtil.IsNullOrEmpty(time)) { ((FreeGameItem)item).SetTime(time); } item.Drop(fr, pos.Select(args)); if (action != null) { args.TempUse(ParaConstant.PARA_ITEM, item); action.Act(args); args.Resume(ParaConstant.PARA_ITEM); } } }
public async Task DoesReturnOk_GivenFreeItemExists() { //Arrange var item = new FreeItem { Description = "Description", Id = 1, Name = "Item1" }; _testContext.DbContext.FreeItems.Add(item); _testContext.DbContext.SaveChanges(); //Act var response = await _testContext.HttpClient.GetAsync($"/api/FreeItems/{item.Id}"); //Assert Assert.Equal(HttpStatusCode.OK, response.StatusCode); string jsonResult = await response.Content.ReadAsStringAsync(); FreeItem itemFromJson = JsonConvert.DeserializeObject <FreeItem>(jsonResult); Assert.Equal(item.Id, itemFromJson.Id); Assert.Equal(item.Description, itemFromJson.Description); Assert.Equal(item.Name, itemFromJson.Name); }
public async Task DoesReturnOk_GivenFreeItemIsValidAsync() { //Arrange var item = new FreeItem() { Description = "privet", Id = 23, Name = "Privet" }; var stringContent = new StringContent(JsonConvert.SerializeObject(item), Encoding.UTF8, "application/json"); //Act var response = await _testContext.HttpClient.PostAsync("/api/FreeItems/", stringContent); //Assert Assert.Equal(HttpStatusCode.Created, response.StatusCode); string jsonResult = await response.Content.ReadAsStringAsync(); FreeItem itemFromJson = JsonConvert.DeserializeObject <FreeItem>(jsonResult); Assert.Equal(item.Id, itemFromJson.Id); Assert.Equal(item.Description, itemFromJson.Description); Assert.Equal(item.Name, itemFromJson.Name); }
private void Update() { hit2D = Physics2D.Raycast(new Vector2(transform.position.x - 15, transform.position.y + 5), Vector2.right, 30f); if (hit2D && Input.GetKeyDown(KeyCode.E) && !WorldVariables.dialogueActive) { if (hit2D.collider.gameObject.tag == "Door") { Door door = hit2D.collider.gameObject.GetComponent <Door>(); door.Interact(this.gameObject); } else if (hit2D.collider.gameObject.tag == "Interactable") { Interactable inter = hit2D.collider.gameObject.GetComponent <Interactable>(); if (ps.Interact()) { inv.AddItem(inter.GetItem()); inter.CanInteract(false); } } else if (hit2D.collider.gameObject.tag == "Item") { FreeItem item = hit2D.collider.gameObject.GetComponent <FreeItem>(); inv.AddItem(item.id); Destroy(hit2D.collider.gameObject); } else if (hit2D.collider.gameObject.tag == "BackDoor") { BackDoor door = hit2D.collider.gameObject.GetComponent <BackDoor>(); door.Interact(this.gameObject); } } }
public IActionResult AddFreeItem([FromBody] FreeItem freeItem) { _context.FreeItems.Add(freeItem); _context.SaveChanges(); var result = CreatedAtAction("GetFreeItem", new { id = freeItem.Id }, freeItem); return(result); }
public static void AddItem(IEventArgs args, string rule, FreeItem item) { item = item.Clone(); if (!map.ContainsKey(rule)) { map[rule] = new MyDictionary <string, FreeItem>(); } map[rule][item.GetKey()] = item; }
public IActionResult GetFreeItem([FromRoute] int id) { FreeItem freeItem = _context.FreeItems.FirstOrDefault(item => item.Id == id); if (freeItem == null) { return(NotFound()); } return(Ok(freeItem)); }
public override void DoAction(IEventArgs args) { if (addtimePara == null) { addtimePara = new IntPara(ParaConstant.PARA_ITEM_ADD_TIME, 0); } FreeRuleEventArgs fr = (FreeRuleEventArgs)args; if (StringUtil.IsNullOrEmpty(count)) { count = INI_COUNT; } FreeItem fi = FreeItemManager.GetItem(fr, FreeUtil.ReplaceVar(key, args), FreeUtil.ReplaceInt(count, args)); if (StringUtil.IsNullOrEmpty(name)) { name = InventoryManager.DEFAULT; } IGameUnit player = GetPlayer(args); if (player != null) { FreeData fd = (FreeData)player; args.TempUse(ParaConstant.PARA_PLAYER_CURRENT, fd); args.TempUse(ParaConstant.PARA_ITEM, fi); args.TempUsePara(new StringPara("from", ChickenConstant.BagGround)); if (action != null) { action.Act(args); } if (fd.freeInventory.GetInventoryManager().GetInventory(FreeUtil.ReplaceVar(name, args)).AddItem((ISkillArgs)args, fi, true)) { //addtimePara.setValue(fr.room.getServerTime()); fi.GetParameters().AddPara(addtimePara); } else { if (failAction != null) { fr.TempUse(ParaConstant.PARA_ITEM, fi); failAction.Act(args); fr.Resume(ParaConstant.PARA_ITEM); } } fr.ResumePara("from"); fr.Resume(ParaConstant.PARA_PLAYER_CURRENT); fr.Resume(ParaConstant.PARA_ITEM); } }
public async Task <IActionResult> PostFreeItem([FromBody] FreeItem freeItem) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.FreeItems.Add(freeItem); await _context.SaveChangesAsync(); return(CreatedAtAction("GetFreeItem", new { id = freeItem.Id }, freeItem)); }
public async Task DoesReturnOk_GivenFreeItemExists() { var item = new FreeItem { Description = "Delete", Id = 1, Name = "Delete" }; _testContext.DbContext.FreeItems.Add(item); _testContext.DbContext.SaveChanges(); HttpResponseMessage response = await _testContext.HttpClient.DeleteAsync($"api/FreeItems/{item.Id}"); Assert.Equal(HttpStatusCode.OK, response.StatusCode); }
public HttpResponseMessage add(FreeItem item) { logger.Info("start Return: "); try { var identity = User.Identity as ClaimsIdentity; int compid = 0, userid = 0; foreach (Claim claim in identity.Claims) { if (claim.Type == "compid") { compid = int.Parse(claim.Value); } if (claim.Type == "userid") { userid = int.Parse(claim.Value); } } if (item != null) { item.CreationDate = indianTime; item.Deleted = false; CurrentStock stok = context.DbCurrentStock.Where(x => x.ItemNumber == item.itemNumber && x.Warehouseid == item.WarehouseId).SingleOrDefault(); if (stok != null) { stok.CurrentInventory = stok.CurrentInventory + item.TotalQuantity; if (stok.CurrentInventory < 0) { stok.CurrentInventory = 0; } context.DbCurrentStock.Attach(stok); context.Entry(stok).State = EntityState.Modified; context.SaveChanges(); context.FreeItemDb.Add(item); context.SaveChanges(); } else { return(Request.CreateResponse(HttpStatusCode.OK, "item Updation Failed")); } } return(Request.CreateResponse(HttpStatusCode.OK, item)); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message)); } }
public override void DoAction(IEventArgs args) { FreeRuleEventArgs fr = (FreeRuleEventArgs)args; IParable pe = args.GetUnit(item); if (pe != null && pe is FreeItem) { FreeItem fi = (FreeItem)pe; if (!StringUtil.IsNullOrEmpty(time)) { ((FreeGameItem)fi).SetTime(time); } fi.Drop(fr, pos.Select(args)); } }
public async Task DoesReturnNotFound_GivenFreeItemDoesNotExist() { //Arrange var item = new FreeItem { Description = "Item", Name = "Item" }; var stringEditedItem = new StringContent(JsonConvert.SerializeObject(item), Encoding.UTF8, "application/json"); //Act var response = await _testContext.HttpClient.PutAsync($"api/FreeItems/5555", stringEditedItem); //Assert Assert.Equal(HttpStatusCode.NotFound, response.StatusCode); }
public IActionResult EditFreeItem([FromRoute] int id, FreeItem freeItem) { var freeItemInDb = _context.FreeItems.FirstOrDefault(item => item.Id == id); if (freeItemInDb == null) { return(NotFound()); } freeItemInDb.Name = freeItem.Name; freeItemInDb.Description = freeItem.Description; _context.SaveChanges(); return(Ok(freeItemInDb)); }
public virtual ItemPosition GetItemPosition(FreeItem item) { foreach (string invName in inventoryManager.GetInventoryNames()) { ItemInventory ii = inventoryManager.GetInventory(invName); foreach (ItemPosition ip in ii.GetItems()) { if (ip.GetKey().GetId() == item.GetId()) { return ip; } } } return null; }
public override void DoAction(IEventArgs args) { FreeRuleEventArgs fr = (FreeRuleEventArgs)args; IGameUnit player = GetPlayer(args); if (StringUtil.IsNullOrEmpty(item)) { item = "item"; } if (player != null) { FreeData fd = (FreeData)player; FreeItem fi = (FreeItem)fr.GetUnit(FreeUtil.ReplaceVar(item, args)); FreeItemManager.UseItem(fd.GetFreeInventory().GetItemPosition(fi), fd, fr); } }
public static FreeItem GetItem(FreeRuleEventArgs args, string key, int count) { string rule = args.Rule.FreeType; if (map.ContainsKey(rule) && map[rule].ContainsKey(key)) { FreeItem fi = map[rule][key]; fi = fi.Clone(); fi.SetCount(count); if (fi.GetId() == 0) { fi.SetId(); } return(fi); } else { throw new GameConfigExpception("item '" + key + "' is not defined."); } }
public static void AddClip(int count, int clipType, FreeData fd, IEventArgs args) { if (BagCapacityUtil.CanAddToBag(args, fd, (int)ECategory.GameItem, clipType, count)) { int leftCount = count; ItemPosition[] ips = fd.freeInventory.GetInventoryManager().GetDefaultInventory().GetItems(); foreach (ItemPosition ip in ips) { FreeItemInfo info = FreeItemConfig.GetItemInfo(ip.key.GetKey()); if (ip.GetParameters().HasPara("ClipType") && (int)ip.GetParameters().Get("ClipType").GetValue() == clipType) { int added = Math.Min(leftCount, info.stack - ip.count); leftCount -= added; ip.SetCount(ip.GetCount() + added); ip.GetInventory().GetInventoryUI().UpdateItem((FreeRuleEventArgs)args, ip.GetInventory(), ip); } } if (leftCount > 0) { FreeItem item = FreeItemManager.GetItem((FreeRuleEventArgs)args, FreeItemConfig.GetItemKey((int)ECategory.GameItem, clipType), leftCount); if (item != null) { fd.freeInventory.GetInventoryManager().GetDefaultInventory().AddItem((ISkillArgs)args, item, true); } } } else { FreeItem item = FreeItemManager.GetItem((FreeRuleEventArgs)args, FreeItemConfig.GetItemKey((int)ECategory.GameItem, clipType), count); if (item != null) { fd.freeInventory.GetInventoryManager().GetInventory(ChickenConstant.BagGround).AddItem((ISkillArgs)args, item, true); } } }
public virtual void AddSceneItem(FreeItem item) { itemMap[item.GetId()] = item; }
public virtual void Remove(FreeItem item) { itemMap.Remove(item.GetId()); }
public static int GetSing(FreeItem item) { FreeItemInfo info = GetItemInfo(item.GetKey()); return(info.sing); }