Example #1
0
File: Bag.cs Project: 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;
        }
Example #2
0
 public virtual void RemoveResident(TownInterfaces.ICitizen h)
 {
     residents.Remove(h);
 }
Example #3
0
        public bool Sell(ICitizen buyer, TownInterfaces.ThingType type)
        {
            float percent = (float)ProfLevels["trader"] / Config.MaxLevel;
            IThing thing = Bag.GetWithPriceLower(buyer.Money, percent, (TownInterfaces.ThingType)type);

            if (thing != null)
            {
                float priceWithPercent = thing.Price * (1 + percent);
                buyer.Money -= priceWithPercent;
                Money += priceWithPercent;
                try
                {
                    buyer.Bag.Add(thing);
                }
                catch (OverloadedBagExeption ex)
                {
                    Log.Add("citizens:Human " + buyer.Name + " haven't enougth place for new thing after buying");
                }

                string typeName = thing.GetType().Name;
                Log.Add("other:Human " + Name + " sold " + typeName + " with price: " + priceWithPercent +
                    " to " + buyer.Name );

                return true;
            }
            return false;
        }