Example #1
0
        public void Test()
        {
            IThingFactory factory = Registry.Factory.Create <IThingFactory>();
            IThing        thing   = factory.CreateItem();

            Assert.AreEqual(typeof(Thing), thing.GetType());
            Assert.IsInstanceOf(typeof(IThing), thing);

            thing = factory.CreateItem <object>(null);
            Assert.AreEqual(typeof(Thing), thing.GetType());
            Assert.IsInstanceOf(typeof(IThing), thing);

            thing = factory.CreateItem <Empty>(new Empty());
            Assert.AreEqual(typeof(Thing), thing.GetType());
            Assert.IsInstanceOf(typeof(IThing), thing);

            thing = factory.CreateItem(new Empty());
            Assert.AreEqual(typeof(Thing), thing.GetType());
            Assert.IsInstanceOf(typeof(IThing), thing);

            thing = factory.CreateItem("");
            Assert.IsInstanceOf(typeof(IThing <string>), thing);
            thing = factory.CreateItem <object>("");
            Assert.IsInstanceOf(typeof(IThing <string>), thing);

            thing = factory.CreateItem(0);
            Assert.IsInstanceOf(typeof(INumberThing), thing);
            thing = factory.CreateItem <object>(0);
            Assert.IsInstanceOf(typeof(INumberThing), thing);

            thing = factory.CreateItem(0f);
            Assert.IsInstanceOf(typeof(INumberThing), thing);
            thing = factory.CreateItem <object>(0f);
            Assert.IsInstanceOf(typeof(INumberThing), thing);

            thing = factory.CreateItem(0d);
            Assert.IsInstanceOf(typeof(INumberThing), thing);
            thing = factory.CreateItem <object>(0d);
            Assert.IsInstanceOf(typeof(INumberThing), thing);

            thing = factory.CreateItem(DateTime.Now);
            Assert.IsInstanceOf(typeof(INumberThing), thing);
            thing = factory.CreateItem <object>(DateTime.Now);
            Assert.IsInstanceOf(typeof(INumberThing), thing);

            thing = factory.CreateItem(new Quad16(0, 0, 0, 0));
            Assert.IsInstanceOf(typeof(INumberThing), thing);
            thing = factory.CreateItem <object>(new Quad16(0, 0, 0, 0));
            Assert.IsInstanceOf(typeof(INumberThing), thing);

            using (var stream = new MemoryStream()) {
                thing = factory.CreateItem(stream);
                Assert.IsInstanceOf(typeof(IStreamThing), thing);
                thing = factory.CreateItem <object> (stream);
                Assert.IsInstanceOf(typeof(IStreamThing), thing);
            }

            thing = factory.CreateItem <Stream>(null);
            Assert.IsInstanceOf(typeof(IStreamThing), thing);
        }
Example #2
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);
        }
Example #3
0
 internal static Boolean GetInterface(IThing Object, Type Interface)
 {
     try
     {
         Object.GetType().GetInterfaceMap(Interface);
         return(true);
     }
     catch (ArgumentException) { return(false); }
 }
Example #4
0
        public static bool DescriptionableThing(IThing thing)
        {
            if (thing == null)
            {
                return(false);
            }

            return(thing.GetType().Equals(typeof(Thing)) || (thing is IStreamThing) || thing.Data == null);
        }
Example #5
0
        protected void LoadThingField(XmlElement Node, IThing T)
        {
            XmlElement ThingRoot =
                Node.SelectSingleNode(String.Format("./child::thing[@type = '{0}']", T.GetType().Name)) as XmlElement;

            if (ThingRoot != null)
            {
                T.Load(ThingRoot);
            }
            else
            {
                throw new ArgumentException(String.Format(I18N.GetText("InvalidThingField"), T.TypeName));
            }
        }
Example #6
0
        public void WhenDies()
        {
            if (Loot != null && Loot.GetType() != typeof(EThing))
            {
                DrawerLine Line = new DrawerLine();
                Line.DefaultBackgroundColor = ConsoleColor.DarkGreen;
                Line.DefaultForegroundColor = ConsoleColor.White;
                Line += DCLine.New("You", State.Current.Hero.Color, State.Current.Hero.Back);
                Line += " get a ";
                Line += DCLine.New(Loot.Name, Loot.Color, Loot.Back);
                Line += " !";
                State.Current.Chat.Message(Line);
                Loot.Action();
            }

            State.Current.Hero.Cexp += Exp;

            if (this.GetType().GetInterface("IThing") != null)
            {
                DrawerLine Line = new DrawerLine();
                Line.DefaultBackgroundColor = ConsoleColor.DarkGreen;
                Line.DefaultForegroundColor = ConsoleColor.Black;
                Line += DCLine.New((this as IThing).Name, (this as IThing).Color, (this as IThing).Back);
                Line += " died! ";
                Line += DCLine.New("You", State.Current.Hero.Color, State.Current.Hero.Back);
                Line += " get ";
                Line += DCLine.New(Exp.ToString(), ConsoleColor.Blue, ConsoleColor.White);
                Line += " exp!";
                State.Current.Chat.Message(Line);
            }
            else
            {
                State.Current.Chat.Message(new DrawerLine("Monster died! You get " + Exp.ToString() + " exp!", ConsoleColor.Magenta));
            }

            if (this.GetType().GetInterface("IThing") != null)
            {
                State.Current.GameField.Map[(this as IThing).Position.X, (this as IThing).Position.Y] = new Mapped.EThing();
            }

            State.Current.GameField.Draw();
            State.Current.Info.Draw();
        }
Example #7
0
        public object ThingDataToDisplay(IGraph <IThing, ILink> graph, IThing thing)
        {
            if (thing == null)
            {
                return(CommonSchema.NullString);
            }

            thing = ThingToDisplay(graph, thing);
            object result = null;

            if (thing is IProxy)
            {
                result = CommonSchema.ProxyString;
            }
            else
            {
                result = thing.Data;
            }

            if (thing is ILink)
            {
                result = thing.ToString();
            }
            else if (thing.Id == CommonSchema.EmptyMarker.Id)
            {
                result = CommonSchema.EmtpyMarkerString;
            }
            else if (thing.GetType() == typeof(Thing))
            {
                result = CommonSchema.ThingString;
            }
            if (result == null)
            {
                return(CommonSchema.NullString);
            }
            return(result);
        }
Example #8
0
 protected void LoadThingField(XmlElement Node, IThing T)
 {
     XmlElement ThingRoot = Node.SelectSingleNode(String.Format("./child::thing[@type = '{0}']", T.GetType().Name)) as XmlElement;
       if (ThingRoot != null)
     T.Load(ThingRoot);
       else
     throw new ArgumentException(String.Format(I18N.GetText("InvalidThingField"), T.TypeName));
 }