| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- using System.Collections.Generic;
- using MongoDB.Bson.Serialization.Attributes;
- using MongoDB.Bson.Serialization.Options;
- namespace Model
- {
- public class NumericComponent : ComponentDB
- {
- [BsonDictionaryOptions(DictionaryRepresentation.ArrayOfArrays)]
- public readonly Dictionary<NumericType, int> NumericDic = new Dictionary<NumericType, int>();
- public float GetAsFloat(NumericType numericType)
- {
- return (float)GetByKey(numericType) / 10000;
- }
- public int GetAsInt(NumericType numericType)
- {
- return this[numericType];
- }
- public void Set(NumericType nt, float value)
- {
- this[nt] = (int)(value * 10000);
- }
- public void Set(NumericType nt, int value)
- {
- this[nt] = value;
- }
- public int this[NumericType numericType]
- {
- get
- {
- return this.GetByKey(numericType);
- }
- set
- {
- int v = this.GetByKey(numericType);
- if (v == value)
- {
- return;
- }
- NumericDic[numericType] = value;
- Game.Scene.GetComponent<EventComponent>().Run(EventIdType.NumbericChange, this.Entity.Id, numericType, value);
- }
- }
- private int GetByKey(NumericType key)
- {
- int value;
- this.NumericDic.TryGetValue(key, out value);
- return value;
- }
- }
- }
|