Ejemplo n.º 1
0
        public bool Buy(ICitizen trader, TownInterfaces.ThingType type)
        {
            float  percent = (float)trader.ProfLevels["trader"] / Config.MaxLevel;
            IThing thing   = trader.Bag.GetWithPriceLower(Money, percent, type);

            if (thing != null)
            {
                float priceWithPercent = thing.Price * (1 + percent);
                Money        -= priceWithPercent;
                trader.Money += priceWithPercent;

                try
                {
                    Bag.Add(thing);
                }
                catch (OverloadedBagExeption ex)
                {
                    Log.Add("citizens:Human " + Name + " haven't enougth place for new thing after buying");
                }

                string typeName = thing.GetType().Name;
                Log.Add("other:Human " + Name + " bought " + typeName + " with price: " + priceWithPercent +
                        " at " + trader.Name);

                return(true);
            }
            return(false);
        }
Ejemplo n.º 2
0
Archivo: Bag.cs Proyecto: sword36/town
        public IThing GetWithPriceLower(float price, float percect, TownInterfaces.ThingType type)
        {
            IThing thing;

            if (type == TownInterfaces.ThingType.ANY)
            {
                thing = things.Find(t => t.Price * (1 + percect) < price);
            }
            else
            {
                thing = things.Find(t => t.Price * (1 + percect) < price &&
                                    ((t.GetType().Name == "Food" && type == TownInterfaces.ThingType.FOOD) ||
                                     (t.GetType().Name == "Product" && type == TownInterfaces.ThingType.PRODUCT)));
            }

            if (things.Contains(thing))
            {
                things.Remove(thing);
                return(thing);
            }
            return(null);
        }