Exemple #1
0
    public void CreateShopCards()
    {
        availableOptions = new Option[3];

        for (int i = 0; i < 3; i++)
        {
            availableOptions[i] = GetOption(i);

            GameObject costGO = Instantiate(CardManager.instance.cardPrefab, costCardTransform[i]);
            costGO.transform.localPosition = Vector3.zero;
            costGO.transform.localRotation = Quaternion.identity;
            Card costGOCard = costGO.GetComponent <Card>();
            costGOCard.cardInfo = new CardInfo((Rank)availableOptions[i].cost - 1, Suit.diamonds);
            costGOCard.flipUp   = true;
            costGOCard.UpdateSprite();
            ForSale forSaleCard = costGO.AddComponent <ForSale>();
            forSaleCard.SetSale(this, i);

            int qty = 0;

            foreach (CardInfo cardInfo in availableOptions[i].cards)
            {
                GameObject newCardToBuy = Instantiate(CardManager.instance.cardPrefab, battleboard.GetChild(i));
                newCardToBuy.transform.localPosition = new Vector3(0, qty * 0.5f, 0);
                Card newCard = newCardToBuy.GetComponent <Card>();
                newCard.cardInfo = new CardInfo(cardInfo);
                newCard.position = i;
                newCard.flipUp   = true;
                newCardToBuy.AddComponent <ForSale>().SetSale(this, i);
                qty++;
            }
        }
    }
 /// <summary>
 /// Get's the purchasing power of the population, returned in order of
 /// prefered buying order (most durable to least)
 /// </summary>
 /// <returns>The Items for sale in Descending chance of breaking.</returns>
 public IProductAmountCollection PurchasingPower()
 { // TODO delete this, it's not used.
     // Get the products for sale and order them by the chance of failure
     // (how long they last)
     // Maybe give a special sorting to put Currency Up Front?
     return(ForSale.OrderProductsBy(x => x.DailyFailureChance));
 }
Exemple #3
0
        public ActionResult DeleteConfirmed(int id)
        {
            ForSale forsale = db.ForSale.Find(id);

            db.ForSale.Remove(forsale);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemple #4
0
 public ActionResult Edit([Bind(Include = "ID,Description,phone")] ForSale forsale)
 {
     if (ModelState.IsValid)
     {
         db.Entry(forsale).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(forsale));
 }
Exemple #5
0
        public ActionResult Create([Bind(Include = "ID,Description,phone,price")] ForSale forsale, HttpPostedFileBase image1, HttpPostedFileBase image2)
        {
            try

            {
                if (image1 == null && image2 == null)
                {
                    db.ForSale.Add(forsale);
                    db.SaveChanges();
                    return(RedirectToAction("Index", "ForSale"));
                }
                else if (image1 == null && image2 != null)
                {
                    ViewBag.Ms = "Please upload image #1 first";
                    return(View());
                }
                else if (CreateHelper.pictureNotImage1(image1))
                {
                    ViewBag.Ms = "Only Image can be uploaded";
                    return(View());
                }
                else if (image1 != null && image2 == null)
                {
                    forsale.image = new byte[image1.ContentLength];
                    image1.InputStream.Read(forsale.image, 0, image1.ContentLength);
                    db.ForSale.Add(forsale);
                    db.SaveChanges();
                    return(RedirectToAction("Index", "ForSale"));
                }
                else if (CreateHelper.pictureNotImage(image1, image2))
                {
                    ViewBag.Ms = "Only Image can be uploaded";
                    return(View());
                }

                else
                if (ModelState.IsValid)
                {
                    forsale.image = new byte[image1.ContentLength];
                    image1.InputStream.Read(forsale.image, 0, image1.ContentLength);
                    forsale.image1 = new byte[image2.ContentLength];
                    image2.InputStream.Read(forsale.image1, 0, image2.ContentLength);
                    db.ForSale.Add(forsale);
                    db.SaveChanges();
                    return(RedirectToAction("Index", "ForSale"));
                }
            }
            catch
            {
                return(View());
            }
            return(View(forsale));
        }
Exemple #6
0
        public void Setup()
        {
            Car ford    = new Car("Ford", "F350", 2019, "leather seats and all the bells and whistles", 50000.89, "New", "whatever", "truck", "gas");
            Car honda   = new Car("Honda", "Civic", 1989, "how dare you", 1000, "Sorta New", "whatever", "car", "gas");
            Car toyota  = new Car("Toyota", "Tacoma", 2011, "full of trash", 12000, "old", "whatever", "truck", "gas");
            Car tracker = new Car("Darryl", "Frankenstein", 1989, "mostly a tracker", 1000000, "New Parts....", "whatever", "truck", "gas");

            Furniture couch = new Furniture(2011, "its a brown leather couch", 100, "Its very cracked and warn", "n______n", "Couch");

            Listings.AddRange(new Listing[] { ford, honda, toyota, tracker, couch });

            ForSale.AddRange(new IPurchasable[] { ford, couch });
        }
Exemple #7
0
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ForSale forsale = db.ForSale.Find(id);

            if (forsale == null)
            {
                return(HttpNotFound());
            }
            return(View(forsale));
        }
        public void CompleteTransaction(IProductAmountCollection transaction)
        {
            if (transaction is null)
            {
                throw new ArgumentNullException(nameof(transaction));
            }

            // add and remove the trasaction to storage
            Storage.AddProducts(transaction);
            // Add to for sale, rather than recalculating it entirely
            ForSale.AddProducts(transaction);

            // quickly remove any products from for sale that are 0 or less.
            if (ForSale.Any(x => x.Item2 <= 0))
            {
                var gone = ForSale.Where(x => x.Item2 == 0).ToList();
                foreach (var product in gone)
                {
                    ForSale.DeleteProduct(product.Item1);
                }
            }
        }
Exemple #9
0
 public void RemoveItem(Item toRemove)
 {
     ForSale.Remove(toRemove);
 }
        /// <summary>
        /// Buys good via barter.
        /// </summary>
        /// <param name="buyerStock">The buyer's goods up for trade.</param>
        /// <param name="good">The good being traded for.</param>
        /// <param name="amount">The amount of the good being bought.</param>
        /// <param name="market">The market that the barter is taking place in.</param>
        /// <returns>The resulting change in goods for the buyer.</returns>
        public IProductAmountCollection BarterGood(IProductAmountCollection buyerStock,
                                                   IProduct good, double amount, IMarket market)
        {
            // TODO, update to use the coincidence of wants,
            // it will discourage barter more than anything.
            if (buyerStock == null)
            {
                throw new ArgumentNullException(nameof(buyerStock));
            }
            if (good == null)
            {
                throw new ArgumentNullException(nameof(good));
            }
            if (market == null)
            {
                throw new ArgumentNullException(nameof(market));
            }
            if (amount <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(amount));
            }

            // the return result of the barter
            var result = new ProductAmountCollection();

            // TODO a barter modifier, to discourage or encourage bartering.
            // This should become more flexible later.
            var BarterMod = 1;

            // Get how much we can or want to get
            amount = Math.Min(amount, ForSale.GetProductValue(good));

            // get the price of the good.
            var totalPrice = GetPrice(good, market.GetPrice(good)) * amount * BarterMod;

            // get the total price of what's offered.
            double barterVal = 0;

            foreach (var product in buyerStock)
            {
                barterVal += market.GetPrice(product.Item1) * product.Item2;
            }

            // the barter we're trading for the goods.
            IProductAmountCollection barter;

            // if the available barter is greater than the price, begin bartering
            if (barterVal >= totalPrice)
            {
                // Use get change for the easiest option.
                barter = market.ChangeForPrice(buyerStock, totalPrice);

                // don't go more accurate, barter isn't supposed to be more accurate to coins,
                // no one would accept change in bits of wheat.

                // Add the goods being bought
                result.AddProducts(good, amount);

                // Remove the goods being traded.
                result.AddProducts(barter.Multiply(-1));
            }
            else
            {
                // if it's not enough, throw it all in, and buy what you can.
                double buyableUnits = 0;

                // if the good is fractional
                if (good.Fractional)
                {
                    // just divide
                    buyableUnits = barterVal / (market.GetPrice(good) * BarterMod);
                }
                else
                {
                    // round down
                    buyableUnits = Math.Floor(barterVal / (market.GetPrice(good) * BarterMod));
                }

                // If we can buy anything, do so.
                if (buyableUnits > 0)
                {
                    // add the goods
                    result.AddProducts(good, buyableUnits);
                    // subtract the goods
                    result.AddProducts(buyerStock.Multiply(-1));
                }
            }

            // No change, this is bartering.

            // We've done what we can, move on.
            return(result);
        }
        public IProductAmountCollection BuyGood(IProductAmountCollection cash,
                                                IProduct good, double amount, IMarket market)
        {
            // Sanity check for nulls.
            if (cash is null)
            {
                throw new ArgumentNullException(nameof(cash));
            }
            if (good is null)
            {
                throw new ArgumentNullException(nameof(good));
            }
            if (market is null)
            {
                throw new ArgumentNullException(nameof(market));
            }
            if (amount <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(amount));
            }

            // The collection we're returning.
            var result = new ProductAmountCollection();

            // get how much to buy, what's available, or what's desired.
            var available = Math.Min(amount, ForSale.GetProductValue(good));

            // get the price of that good
            var totalPrice = GetPrice(good, market.GetPrice(good)) * available;

            // get the cash needed for the goods
            var money = market.ChangeForPrice(cash, totalPrice);

            // get our available money total
            var totalMoney = money.Sum(x => market.GetPrice(x.Item1, x.Item2));

            // if the money is enough, just buy outright
            if (totalMoney >= totalPrice)
            {
                // Add what they're buying.
                result.AddProducts(good, available);
                // remove what they spent
                result.AddProducts(money.Multiply(-1));
            }
            else if (!good.Fractional && totalMoney < market.GetPrice(good))
            {// If the total money is not enough for a single unit, and the good can't be divided
                // we can't actually buy anything, so just return an empty transaction
                return(new ProductAmountCollection());
            }
            else // if it's not enough
            {
                // get the buyable units of the good
                double buyableUnits = 0;

                // if we can buy fractionally
                if (good.Fractional)
                {
                    // just do the math straight.
                    buyableUnits = totalMoney / market.GetPrice(good);
                }
                else // if we can't
                {
                    // take what we can and round down, seller should always make more than the buyer here.
                    buyableUnits = Math.Floor(totalMoney / market.GetPrice(good));
                }

                // if we can buy any units
                if (buyableUnits > 0)
                {
                    // buy them add the units to the results
                    result.AddProducts(good, buyableUnits);
                    // subtract the cash.
                    result.AddProducts(money.Multiply(-1));
                }
            }

            // Get change, if any.
            var change = totalMoney - market.GetPrice(good) * result.GetProductValue(good);

            // get the change, if any
            IProductAmountCollection buyersChange = new ProductAmountCollection();

            // if change is greater than 0.
            if (change > 0) // Make said change.
            {
                buyersChange = market.ChangeForPrice(GetCash(market.AcceptedCurrencies), change);
            }

            // add back the buyer's change
            result.AddProducts(buyersChange);

            // TODO, maybe add check to see if the seller shortchanged the buyer.

            // complete the transaction for the seller, and subtract the result.
            CompleteTransaction(result.Multiply(-1));

            // we're done, return the change in the buyer's goods.
            return(result);
        }
 /// <summary>
 /// Retrieve the Currency the population holds.
 /// </summary>
 /// <param name="Currencies">What counts as currency.</param>
 /// <returns></returns>
 public IProductAmountCollection GetCash(IList <IProduct> Currencies)
 {
     // TODO this will most likely be changed when products
     // have more implementations.
     return(ForSale.GetProducts(Currencies));
 }