Example #1
0
		public static ClilocInfo Lookup(this ClilocLNG lng, Type t)
		{
			if (lng == ClilocLNG.NULL)
			{
				lng = DefaultLanguage;
			}

			return VitaNexCore.TryCatchGet(
				() =>
				{
					if (t == null)
					{
						return null;
					}

					PropertyInfo p = t.GetProperty("LabelNumber");

					if (p == null || !p.CanRead)
					{
						return null;
					}

					object o = t.CreateInstanceSafe<object>();

					if (o == null)
					{
						return null;
					}

					var index = (int)p.GetValue(o, null); // LabelNumber_get()

					MethodInfo m = t.GetMethod("Delete");

					if (m != null)
					{
						m.Invoke(o, new object[0]); // Delete_call()
					}

					return Lookup(lng, index);
				});
		}
Example #2
0
		public static void Deposit(Container cont, Type currencyType, int amount)
		{
			while (amount > 0)
			{
				Item item;

				if (amount < 5000)
				{
					item = currencyType.CreateInstanceSafe<Item>();

					item.Stackable = true;
					item.Amount = amount;

					amount = 0;
				}
				else if (amount <= 1000000)
				{
					item = new BankCheck(amount);
					amount = 0;
				}
				else
				{
					item = new BankCheck(1000000);
					amount -= 1000000;
				}

				cont.DropItem(item);
			}
		}
Example #3
0
		public static ClilocInfo Lookup(this ClilocLNG lng, Type t)
		{
			if (lng == ClilocLNG.NULL)
			{
				lng = DefaultLanguage;
			}

			int index;

			if (_TypeCache.TryGetValue(t, out index))
			{
				return Lookup(lng, index);
			}

			return VitaNexCore.TryCatchGet(
				() =>
				{
					if (t == null)
					{
						return null;
					}

					if (!_LabelNumberProp.IsSupported(t, typeof(int)))
					{
						return null;
					}

					var o = t.CreateInstanceSafe<object>();

					if (o == null)
					{
						return null;
					}

					index = (int)_LabelNumberProp.GetValue(o, -1); // LabelNumber_get()

					var m = t.GetMethod("Delete");

					if (m != null)
					{
						m.Invoke(o, new object[0]); // Delete_call()
					}

					_TypeCache.Add(t, index);

					return Lookup(lng, index);
				});
		}
Example #4
0
		public static int DepositUpTo(Mobile from, Type currencyType, int amount)
		{
			BankBox box = from.FindBankNoCreate();

			if (box != null)
			{
				int amountLeft = amount;

				while (amountLeft > 0)
				{
					Item item;
					int amountGiven;

					if (amountLeft < 5000)
					{
						item = currencyType.CreateInstanceSafe<Item>();

						item.Stackable = true;
						item.Amount = amountLeft;

						amountGiven = amountLeft;
					}
					else if (amountLeft <= 1000000)
					{
						item = new BankCheck(amountLeft);
						amountGiven = amountLeft;
					}
					else
					{
						item = new BankCheck(1000000);
						amountGiven = 1000000;
					}

					if (box.TryDropItem(from, item, false))
					{
						amountLeft -= amountGiven;
					}
					else
					{
						item.Delete();
						break;
					}
				}

				return amount - amountLeft;
			}

			return 0;
		}
Example #5
0
		public static bool Deposit(Mobile from, Type currencyType, int amount)
		{
			BankBox box = from.FindBankNoCreate();

			if (box != null)
			{
				var items = new List<Item>();

				while (amount > 0)
				{
					Item item;

					if (amount < 5000)
					{
						item = currencyType.CreateInstanceSafe<Item>();

						item.Stackable = true;
						item.Amount = amount;

						amount = 0;
					}
					else if (amount <= 1000000)
					{
						item = new BankCheck(amount);
						amount = 0;
					}
					else
					{
						item = new BankCheck(1000000);
						amount -= 1000000;
					}

				    BankCheck check = item as BankCheck;

				    if (currencyType.Equals(typeof(DonationCoin)) && item is BankCheck)
				    {
				        check.IsDonation = true;
				        check.Hue = 1153;
				    }
					if (box.TryDropItem(from, item, false))
					{
						items.Add(item);
					}
					else
					{
						item.Delete();

						foreach (Item curItem in items)
						{
							curItem.Delete();
						}

						return false;
					}
				}

				return true;
			}

			return false;
		}
Example #6
0
        public static string ResolveName(this Type t, params object[] args)
        {
            if (SimpleType.IsSimpleType(t))
            {
                return(FormatName(t.Name));
            }

            if (t.IsAbstract || !t.HasInterface <IEntity>())
            {
                return(FormatName(t.Name));
            }

            if (args.IsNullOrEmpty() ? !t.IsConstructable() : !t.IsConstructable(Type.GetTypeArray(args)))
            {
                return(FormatName(t.Name));
            }

            string value;

            if (_StringCache.TryGetValue(t, out value))
            {
                return(value);
            }

            value = String.Empty;

            var o = t.CreateInstanceSafe <IEntity>(args);

            if (o != null)
            {
                try
                {
                    if (o is Mobile)
                    {
                        value = ((Mobile)o).RawName;
                    }
                    else if (o is Item)
                    {
                        value = ((Item)o).ResolveName();
                    }
                    else
                    {
                        o.GetPropertyValue("Name", out value);
                    }
                }
                catch
                { }
                finally
                {
                    o.Delete();
                }
            }

            if (String.IsNullOrWhiteSpace(value))
            {
                value = FormatName(t.Name);
            }

            if (o == null || args.IsNullOrEmpty())
            {
                _StringCache[t] = value;
            }

            return(value);
        }
Example #7
0
		public static void Register(int spellID, Type type)
		{
			if (!Types.InBounds(spellID))
			{
				return;
			}

			var old = Types[spellID];

			if (old != null)
			{
				TypeIDs.Remove(old);
				TypeInfos.Remove(old);
			}

			Types[spellID] = type;

			//Console.WriteLine("Register: ID '{0}', replace '{1}' with '{2}'", spellID, old, type);

			if (type == null)
			{
				return;
			}

			TypeIDs.AddOrReplace(type, spellID);
			
			Spell s = type.CreateInstanceSafe<Spell>((Mobile)null, (Item)null);

			if (s != null && s.Info != null)
			{
				TypeInfos.AddOrReplace(type, s.Info);

				//Console.WriteLine("Register: Info resolved for '{0}'", s.Name);
			}
		}
Example #8
0
		public static Item Construct(Type type)
		{
			return type.CreateInstanceSafe<Item>();
		}