Exemple #1
0
        public ActionResult Create(MedicineItem items, MedicineCategory medicineCategory, IFormFile[] Image)
        {
            try
            {
                if (Image != null)
                {
                    if (medicineCategory.MedicineItems.Count == Image.Count())
                    {
                        for (int i = 0; i < medicineCategory.MedicineItems.Count; i++)
                        {
                            string picture    = System.IO.Path.GetFileName(Image[i].FileName);
                            var    file       = picture;
                            var    uploadFile = Path.Combine(_hostingEnvironment.WebRootPath, "images", picture);

                            using (MemoryStream ms = new MemoryStream())
                            {
                                Image[i].CopyTo(ms);
                                medicineCategory.MedicineItems[i].Image = ms.GetBuffer();
                            }
                        }
                    }
                    _context.MedicineCategories.Add(medicineCategory);
                    _context.SaveChanges();
                    TempData["id"] = medicineCategory.ID;
                    return(RedirectToAction("Index"));
                }

                return(View(medicineCategory));
            }
            catch (Exception)
            {
                return(View(medicineCategory));
            }
        }
Exemple #2
0
 public MedicineItem GetMedicineItem(string id)
 {
     try
     {
         if (string.IsNullOrEmpty(id))
         {
             return(null);
         }
         string ID = "'" + id + "'";
         SimpleSQL.SimpleDataTable dt = dbManager.QueryGeneric(
             "SELECT " + "*" +
             "FROM " +
             "MedicineItem " +
             "WHERE " + "ID LIKE " + ID
             );
         MedicineItem medicine = new MedicineItem(dt.rows[0]["ID"].ToString(), dt.rows[0]["Name"].ToString(), dt.rows[0]["Description"].ToString(), dt.rows[0]["Icon"].ToString(), (int)dt.rows[0]["MaxCount"],
                                                  float.Parse(dt.rows[0]["Weight"].ToString()), (int)dt.rows[0]["BuyPrice"], (int)dt.rows[0]["SellPrice"], (int)dt.rows[0]["SellAble"] == 1, (int)dt.rows[0]["Usable"] == 1,
                                                  dt.rows[0]["HP_Rec"] == null ? 0 : (int)dt.rows[0]["HP_Rec"], dt.rows[0]["MP_Rec"] == null ? 0 : (int)dt.rows[0]["MP_Rec"], dt.rows[0]["Endurance_Rec"] == null ? 0 : (int)dt.rows[0]["Endurance_Rec"]);
         if (dt.rows[0]["Materials"] != null)
         {
             medicine.MaterialsListInput = dt.rows[0]["Materials"].ToString();
         }
         medicine.SetMaterials(this);
         return(medicine);
     }
     catch (System.Exception ex)
     {
         Debug.Log("\"" + id + "\"" + ex.Message);
         return(null);
     }
 }
Exemple #3
0
        public IActionResult DeleteItem(long id)
        {
            MedicineItem item = _context.MedicineItems.Find(id);

            if (item != null)
            {
                _context.MedicineItems.Remove(item);
                _context.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(RedirectToAction("Index"));
        }
Exemple #4
0
 public int SaveItem(MedicineItem item)
 {
     lock (locker)
     {
         if (item.Id != 0)
         {
             database.Update(item);
             return(item.Id);
         }
         else
         {
             return(database.Insert(item));
         }
     }
 }
Exemple #5
0
 /// <summary>
 /// Saves the medicine item currently being edited.
 /// </summary>
 /// <returns>The item.</returns>
 /// <param name="item">Item.</param>
 public int SaveItem(MedicineItem item)
 {
     // Set a mutual-exclusive lock on our database, while
     // saving/updating our medicine item.
     lock (locker)
     {
         if (item.Id != 0)
         {
             database.Update(item);
             return(item.Id);
         }
         else
         {
             return(database.Insert(item));
         }
     }
 }
Exemple #6
0
        private static void CreateRegistry()
        {
            List <Item> items = new List <Item>();

            items.AddRange(PokeBall.GetRegistryItems());
            items.AddRange(BattleItem.GetRegistryItems());
            items.AddRange(MedicineItem.GetRegistryItems());
            items.AddRange(TMItem.GetRegistryItems());
            items.AddRange(GeneralItem.GetRegistryItems());

            Item[] itemsArray = items.ToArray();

            SetItemPrices(ref itemsArray);

            registry.SetValues(itemsArray);

            registrySet = true;
        }
        public override void StartChoosingAction(BattleData battleData)
        {
            base.StartChoosingAction(battleData);

            if (actionHasBeenChosen)
            {
                return;
            }

            int  actionItemTargetIndex = activePokemonIndex;
            Item actionItem;

            List <MedicineItem> validItems = new List <MedicineItem>();

            foreach (MedicineItem item in MedicineItem.registry)
            {
                if (item.CheckCompatibility(GetPokemon()[actionItemTargetIndex]))
                {
                    validItems.Add(item);
                }
            }

            if (validItems.Count > 0)
            {
                actionItem = validItems[battleData.RandomRange(0, validItems.Count)];
            }
            else
            {
                Debug.LogWarning("No valid item found. Choosing item with id 0");
                actionItem = MedicineItem.GetMedicineItemById(0);
            }

            int moveIndex = -1;

            if (actionItem is PPRestoreMedicineItem)
            {
                PPRestoreMedicineItem ppRestoreActionItem = (PPRestoreMedicineItem)actionItem;
                if (ppRestoreActionItem.isForSingleMove)
                {
                    for (int i = 0; i < GetPokemon()[actionItemTargetIndex].moveIds.Length; i++)
                    {
                        if (!Pokemon.Moves.PokemonMove.MoveIdIsUnset(GetPokemon()[actionItemTargetIndex].moveIds[i]))
                        {
                            Pokemon.Moves.PokemonMove move = Pokemon.Moves.PokemonMove.GetPokemonMoveById(GetPokemon()[actionItemTargetIndex].moveIds[i]);
                            if (GetPokemon()[actionItemTargetIndex].movePPs[i] < move.maxPP)
                            {
                                moveIndex = i;
                                break;
                            }
                        }
                    }
                }
            }

            chosenAction = new Action(this)
            {
                type                    = Action.Type.UseItem,
                useItemItemToUse        = actionItem,
                useItemTargetPartyIndex = actionItemTargetIndex,
                useItemTargetMoveIndex  = moveIndex
            };
            actionHasBeenChosen = true;
        }