示例#1
0
        public bool InterpretCondition(string condition)
        {
            if (condition == "true")
            {
                return(true);
            }
            if (condition == "false")
            {
                return(false);
            }

            string[] terms = condition.Split('.');

            if (terms.Length == 2 && terms[0] == "Base") // example: Base.downedMoonlord
            {
                switch (terms[1])
                {
                case "always":
                    return(true);

                case "never":
                    return(false);

                case "moonlord":
                case "downedMoonlord":
                    return(NPC.downedMoonlord);

                case "golem":
                case "downedGolemBoss":
                    return(NPC.downedGolemBoss);

                case "plantera":
                case "downedPlantBoss":
                    return(NPC.downedPlantBoss);

                case "mechAny":
                case "downedMechBossAny":
                    return(NPC.downedMechBossAny);

                case "mechAll":
                case "downedMechBossAll":
                    return(NPC.downedMechBoss1 && NPC.downedMechBoss2 && NPC.downedMechBoss3);

                case "cultist":
                case "downedAncientCultist":
                    return(NPC.downedAncientCultist);

                // miscellaneous
                case "expert":
                case "expertMode":
                    return(Main.expertMode);

                case "crimson":
                    return(WorldGen.crimson);

                case "corruption":     // equivalent to "not Base.crimson"
                    return(!WorldGen.crimson);
                }
                throw new InvalidConfigException("Invalid condition \"" + terms[1] + "\" under list \"Base\"");
            }
            else if (terms.Length == 2 && terms[0] == "Invasion")
            {
                switch (terms[1])
                {
                case "goblins":
                case "downedGoblins":
                    return(NPC.downedGoblins);

                case "frost":
                case "frostLegion":
                case "downedFrost":
                    return(NPC.downedFrost);

                case "pirates":
                case "downedPirates":
                    return(NPC.downedPirates);

                case "martians":
                case "downedMartians":
                    return(NPC.downedMartians);
                }
                throw new InvalidConfigException("Invalid condition \"" + terms[1] + "\" under list \"Invasion\"");
            }
            else if (terms.Length == 2)
            {
                string chosen_list      = terms[0];
                string chosen_condition = terms[1];

                // delegate system
                if (ModHandler.delegates.ContainsKey(chosen_list))
                {
                    Dictionary <string, Func <bool> > checkers = ModHandler.delegates[chosen_list];
                    if (checkers != null)
                    {
                        if (!checkers.ContainsKey(chosen_condition))
                        {
                            throw new InvalidConfigException("Invalid condition \"" + chosen_condition + "\" under list \"" + chosen_list + "\"");
                        }
                        return(checkers[chosen_condition]());
                    }
                    return(false);
                }

                // special case for calamity
                if (chosen_list == "Calamity")
                {
                    return(ModHandler.RunConditionByCalamity(chosen_condition));
                }
                return(false);
            }
            throw new InvalidConfigException("Failed to parse key \"" + condition + "\"");
        }
示例#2
0
 public static bool AddStatement(string statement, int rent) => ModHandler.AddRecommended(statement, rent);
示例#3
0
 /// <summary>
 /// Creates a new key.
 /// </summary>
 /// <param name="listName">The name of the list.</param>
 /// <param name="conditionName">The name of the condition.</param>
 /// <param name="deleg">A delegate function which returns a boolean corresponding to whether or not the condition is true.</param>
 /// <param name="recommended">The recommended value of this key in copper coins. If this is set to -1, the condition will not be shown to the user.</param>
 /// <returns>A boolean representing whether or not the operation succeeded.</returns>
 public static bool AddKey(string listName, string conditionName, Func <bool> deleg, int recommended) => ModHandler.NewCondition(listName, conditionName, deleg, recommended);
示例#4
0
 public static bool AddKey(string listName, string conditionName, Func <bool> deleg) => ModHandler.NewCondition(listName, conditionName, deleg, 0);
示例#5
0
 /// <summary>
 /// Creates a new list.
 /// </summary>
 /// <param name="listName">The name of the list.</param>
 /// <returns>A boolean representing whether or not the operation succeeded.</returns>
 public static bool AddList(string listName) => ModHandler.NewList(listName);