Ejemplo n.º 1
0
        private object GetSubject(StringVariableContext context)
        {
            switch (Data.EntityType)
            {
            case "Effect":
                var effect = Container.Instance.Resolve <IEffectRepository>().FindOrFail(Data.EntityId);
                effect.StackCount = context.StackCount;
                effect.Skill      = context.Skill;
                return(effect);

            case "Behaviour":
                var behaviour = Container.Instance.Resolve <IBehaviourRepository>().FindOrFail(Data.EntityId);
                behaviour.StackCount = context.StackCount;
                return(behaviour);

            case "Mastery":
                var mastery = CharacterManager.Instance.Character.Entity.GetComponent <MasteriesComponent>().Find(Data.EntityId);
                return(mastery);

            case "Property":
                return(CharacterManager.Instance.Character.Entity.GetComponent <PropertiesComponent>());

            default:
                throw new Exception($"Invalid entity type {Data.EntityType}");
            }
        }
Ejemplo n.º 2
0
        private Delegate CreateMethodDelegate(StringVariableContext context)
        {
            var key = GetCacheKey();

            if (Cache.ContainsKey(key))
            {
                return(Cache[key]);
            }

            var subject = GetSubject(context);
            var method  = subject.GetType().GetMethod(Data.PropertyName, BindingFlags);

            if (method == null)
            {
                throw new Exception($"{subject.GetType()} doesn't have method with name {Data.PropertyName}");
            }

            return(Cache[key] = Delegate.CreateDelegate(typeof(Func <GameObject, string>), subject, method));
        }
Ejemplo n.º 3
0
 public string ToString(StringVariableContext context)
 {
     return(Variables.Count > 0
         ? ToString(Variables.Select(variable => variable.GetValue(context)))
         : ToString());
 }
Ejemplo n.º 4
0
 public object GetValue(StringVariableContext context)
 {
     return(CreateMethodDelegate(context).Method.Invoke(GetSubject(context), new object[] { context.Entity }));
 }