Esempio n. 1
0
 public List <GameProperty> GetProperties(string id)
 {
     return
         (GetType()
          .GetProperties()
          .Where(x => x.GetCustomAttribute <GamePropertyAttribute>()?.Id == id)
          .Select(x => GameProperty.Create(x.GetCustomAttribute <GamePropertyAttribute>()?.Id, x.GetValue(this), true))
          .ToList());
 }
Esempio n. 2
0
        public T ValueOf <T>(string id)
        {
            GameProperty property = GetProperty(id);

            if (property.ValueType?.IsEquivalentTo(typeof(T)) ?? false)
            {
                return((T)property.Value);
            }

            throw new Exception($"The specified property '{id}' does not match the implicit type reference of {typeof(T).Name}");
        }
Esempio n. 3
0
        public T ValueOf <T>(string id)
        {
            GameProperty property = GetProperty(id);

            if (property.ValueType == null || !property.ValueType.IsEquivalentTo(typeof(T)))
            {
                throw new Exception("The specified type within the property does not match the implicit type reference");
            }

            return((T)property.Value);
        }
Esempio n. 4
0
        public void AddToValue(string id, int value)
        {
            GameProperty property = GetProperty(id);

            if (property.ValueType != typeof(int))
            {
                throw new Exception($"Cannot add to the specified property '{id}' as it is not a type of Int32");
            }

            property.Value = (int)property.Value + value;
        }
Esempio n. 5
0
        public void AddToValue(string id, int value)
        {
            Console.WriteLine($"[{Format.Time(DateTime.UtcNow)}] Adding {value} to property {id}");

            if (Properties.All(x => x.Id != id))
            {
                throw new Exception($"Could not find the specified property '{id}'");
            }

            GameProperty property = Properties.First(x => x.Id == id);

            if (property.ValueType != typeof(int))
            {
                throw new Exception($"Cannot add to attribute '{id}' as it is not a type of Int32");
            }

            property.Value = (int)property.Value + value;
        }