public static List <ItemAmount> ConvertList_ItemBuy_to_ItemAmount(List <ItemCheckNeed> itbs)
        {
            List <ItemAmount> listIta = new List <ItemAmount>();

            foreach (var itb in itbs)
            {
                listIta.Add(ItemCheckNeed.Convert_ItemBuy_to_ItemAmount(itb));
            }
            return(listIta);
        }
        public IEnumerator AssignWork()
        {
            yield return(new WaitForSeconds(1f));

            while (Controller.BatIsActive())
            {
                var list_EmpWorking = List_Employe.Where(x => x.IsWorking).ToList();


                var list_itemRefBuy = new List <ItemCheckNeed>();
                foreach (var it in List_ItemNeedBuy.Where(x => x.IsCurrentActivate == false))
                {
                    var itAmount = Controller.GetStock().GetAmount(it.ItemRef);
                    int StockMax = Controller.GetStockMAx();
                    if (itAmount < StockMax * 0.3f)
                    {
                        it.Amount = Convert.ToInt32(StockMax - itAmount);

                        list_itemRefBuy.Add(it);
                    }
                    else if (itAmount < StockMax * 0.7f)
                    {
                        if (List_Employe.Count(x => x.IsWorking && x.IsDoMainAssign()) / NumberPosteMax > 0.7f)
                        {
                            it.Amount = Convert.ToInt32(StockMax - itAmount);
                            list_itemRefBuy.Add(it);
                        }
                    }
                }

                if (list_itemRefBuy.Count > 0)
                {
                    List <Assignement> list_Ass = new List <Assignement>();
                    int TotalMoneyNeed          = 0;
                    foreach (var irb in list_itemRefBuy)
                    {
                        var Shop          = Controller.GetShopLowerPriceForItem(irb.ItemRef); // a amélioré en une fonction
                        var PriceForItem  = Controller.GetLowerPriceForItem(irb.ItemRef);
                        int TotalMoneyAss = 0;
                        if (PriceForItem.HasValue && Shop != null)
                        {
                            var ite = List_ItemNeedBuy.FirstOrDefault(x => x.ItemRef == irb.ItemRef);
                            if (ite != null)
                            {
                                ite.IsCurrentActivate = true;
                            }
                            TotalMoneyAss = irb.Amount * PriceForItem.Value;

                            TotalMoneyNeed += TotalMoneyAss;
                            Buy ass = (Buy)list_Ass.Find(x => ((Buy)x).Shop == Shop);
                            if (ass != null)
                            {
                                ass.List_Item.Add(ItemCheckNeed.Convert_ItemBuy_to_ItemAmount(irb));
                                ass.Money += TotalMoneyAss;
                            }
                            else
                            {
                                var v = new Buy()
                                {
                                    IsMainAssignement = false,
                                    TypeAssignement   = TypeAssignement.Buy,
                                    Money             = TotalMoneyAss,
                                    Shop               = Shop,
                                    TypeBuy            = TypeBuy.Share,
                                    Pos_Batiment       = Controller.transform.position,
                                    BatimentProduction = this
                                };
                                v.List_Item.Add(ItemCheckNeed.Convert_ItemBuy_to_ItemAmount(irb));
                                list_Ass.Add(v);
                            }
                        }
                    }

                    int  currentMoney  = Controller.GetMoneyComponement().GetMoney();
                    int  moneyByAssign = -1;
                    bool DoAssignEmp   = true;
                    if (!NeedMoney && TotalMoneyNeed > currentMoney)
                    {
                        NeedMoney = true;

                        moneyByAssign = currentMoney / list_Ass.Count;
                        if (moneyByAssign < 10)
                        {
                            DoAssignEmp = false;
                        }
                    }
                    if (DoAssignEmp)
                    {
                        foreach (var assT in list_Ass)
                        {
                            if (moneyByAssign > -1)
                            {
                                ((Buy)assT).Money = moneyByAssign;
                            }
                            var emp = GetFreeNPCController();
                            if (emp != null)
                            {
                                emp.Assign(assT);
                            }
                            else
                            {
                                AssignEnd(assT, false);
                            }
                        }
                    }
                    else
                    {
                        foreach (var assT in list_Ass)
                        {
                            AssignEnd(assT, false);
                        }
                    }
                }

                yield return(new WaitForSeconds(1f));



                //Assign to Sell
                var list_itemRefSell = new List <ItemCheckNeed>();
                var list_SellAssign  = new List <Sell>();

                foreach (var it in List_ItemNeedSell.Where(x => x.IsCurrentActivate == false))
                {
                    int itAmount = Controller.GetStock().GetAmount(it.ItemRef);
                    int StockMax = Controller.GetStockMAx();
                    if (itAmount > 0.7f * StockMax || NeedMoney && itAmount > 0)
                    {
                        it.Amount = itAmount;
                        list_itemRefSell.Add(it);
                        it.IsCurrentActivate = true;
                    }
                    else if (itAmount > 0.5f * StockMax)
                    {
                        if (List_Employe.Count(x => x.IsWorking && x.IsDoMainAssign()) / NumberPosteMax > 0.7f)
                        {
                            it.Amount = itAmount;
                            list_itemRefSell.Add(it);
                            it.IsCurrentActivate = true;
                        }
                    }
                }

                if (list_itemRefSell.Count > 0)
                {
                    var v = new Sell()
                    {
                        IsMainAssignement  = false,
                        BatimentProduction = this,
                        TypeAssignement    = TypeAssignement.Sell,
                        Pos_Batiment       = Controller.transform.position,
                        Money = 0,
                        Shop  = Controller.GetShopHigherPriceForItem(list_itemRefSell[0].ItemRef) //ATTENTION ICI A REFAIRE  !! ! oui oui on veux que le premier au plus chère
                    };
                    v.List_Item = ItemCheckNeed.ConvertList_ItemBuy_to_ItemAmount(list_itemRefSell);
                    var emp = GetFreeNPCController();
                    if (emp != null)
                    {
                        emp.Assign(v);
                    }
                    else
                    {
                        AssignEnd(v, false);
                    }
                }
                //Assing CheckPrice

                if (DateTime.Now - DateLastTime_CheckPrice > TimerMax_CheckInfo && !b_SearchInfo)
                {
                    b_SearchInfo = true;
                    var searchInfo = new SearchInfo()
                    {
                        IsMainAssignement  = false,
                        BatimentProduction = this,
                        TypeAssignement    = TypeAssignement.SearchInfo,
                        Pos_Batiment       = Controller.transform.position,
                        List_Shop          = Controller.GetAllShop()
                    };
                    var emp = GetFreeNPCController();
                    if (emp != null)
                    {
                        emp.Assign(searchInfo);
                    }
                    else
                    {
                        AssignEnd(searchInfo, false);
                    }
                    DateLastTime_CheckPrice = DateTime.Now;
                }



                yield return(new WaitForSeconds(1f));
            }
        }
 public static ItemAmount Convert_ItemBuy_to_ItemAmount(ItemCheckNeed itb)
 {
     return(new ItemAmount(itb.ItemRef, itb.Amount));
 }