Exemplo n.º 1
0
        public bool IsEnabled(DynamicTokenManager manager)
        {
            switch (this.Name.ToLower())
            {
            case "hasmod": return(true);    // TODO: Add support for checking UniqueID of installed mods

            case "hasfile": return(File.Exists(Path.Combine(HDSpritesMod.ModHelper.DirectoryPath, this.Condition.Parse(manager.DynamicTokens).ToCleanString())) == this.Values[0].ToLower().Equals("true"));

            case "hasvalue": return(!this.Condition.Parse(manager.DynamicTokens).ToCleanString().Equals("") == this.Values[0].ToLower().Equals("true"));
            }

            DynamicToken token = null;

            foreach (var entry in manager.DynamicTokens)
            {
                if (entry.Key.ToLower().Equals(this.Name.ToLower()))
                {
                    token = entry.Value;
                    break;
                }
            }

            if (token != null)
            {
                if (!this.IsConditional)
                {
                    foreach (string value in this.Values)
                    {
                        if (token.GetValue().ToLower().Equals(value.ToLower()))
                        {
                            return(true);
                        }
                    }
                }
                else
                {
                    string condition = this.Condition.Parse(manager.DynamicTokens).ToCleanString().ToLower();
                    foreach (var value in token.GetValues())
                    {
                        if (value.SubValues.Count > 0)
                        {
                            // "SkillLevel:Combat": "1, 2, 3"
                            //
                            // this.Values should be ~ 1, 2, 3
                            // value.SubValues should be 1, 2, 3, 4, 5

                            if (value.Value.ToLower().Equals(condition))
                            {
                                foreach (string condVal in this.Values)
                                {
                                    bool found = false;
                                    foreach (string subVal in value.SubValues)
                                    {
                                        if (condVal.ToLower().Equals(subVal.ToLower()))
                                        {
                                            found = true;
                                            break;
                                        }
                                    }
                                    if (found)
                                    {
                                        return(true);
                                    }
                                }
                            }
                        }
                        else
                        {
                            // "PlayerGender:Male": "true"
                            //
                            // this.Values should be "true" or "false"
                            // this.SubValues should be empty
                            if (value.Value.ToLower().Equals(condition) == this.Values[0].ToLower().Equals("true"))
                            {
                                return(true);
                            }
                        }
                    }
                }
            }
            return(false);
        }