Exemplo n.º 1
0
        /// <summary>
        /// Purges Effects that negate each other and combines effects of the same type.
        /// TODO: This function could use a rework to increase efficiency. Currently it runs in O(n^2)
        /// </summary>
        /// <param name="effects"></param>
        private List <Effect> processEffects(List <Effect> effects)
        {
            if (effects.Count == 1)
            {
                return(effects);
            }
            List <Effect> processedList = new List <Effect>();

            for (int i = 0; i < effects.Count - 1; i++)
            {
                bool   addCurrentEffect = true;
                Effect iEffect          = effects.ElementAt(i);
                for (int k = i + 1; k < effects.Count; k++)
                {
                    Effect kEffect = effects.ElementAt(k);
                    if (iEffect.isNegatedBy(kEffect))
                    {
                        effects[i]       = new NoEffect();
                        effects[k]       = new NoEffect();
                        addCurrentEffect = false;
                        break;
                    }
                    if (iEffect.canCombine(kEffect))
                    {
                        iEffect.combine(kEffect);
                        effects[i]       = new NoEffect();
                        effects[k]       = new NoEffect();
                        addCurrentEffect = true;
                        break;
                    }
                }
                if (addCurrentEffect)
                {
                    processedList.Add(iEffect);
                }
            }
            if (processedList.Count == 0)
            {
                processedList.Add(new NoEffect());
            }
            return(processedList);
        }
Exemplo n.º 2
0
        /// <summary>
        /// /Inserts a list of effects into the Database.
        /// </summary>
        /// <param name="effects"></param>
        public void insertNewEffects(List <Effect> effects, string typeId, int id)
        {
            connection = new SqlConnection(connectionString);
            connection.Open();

            string queryIdSubstring = "";

            switch (typeId)
            {
            case "BaseId":
                queryIdSubstring = "@BaseId, NULL, NULL";
                break;

            case "IngredientId":
                queryIdSubstring = "NULL, @IngredientId, NULL";
                break;

            case "PotionId":
                queryIdSubstring = "NULL, NULL, @PotionId";
                break;
            }

            foreach (Effect e in effects)
            {
                string     query = "";
                EffectType type  = e.getEffectEnumType();
                SqlCommand command;
                switch (type)
                {
                case EffectType.NONE:
                    NoEffect ne = (NoEffect)e;
                    query = "INSERT INTO Effect VALUES(@Name, @EffectType, NULL, NULL, NULL, " + queryIdSubstring + ", NULL)";
                    Console.WriteLine(query);
                    command = new SqlCommand(query, connection);
                    command.Parameters.AddWithValue("@Name", ne.name);
                    command.Parameters.AddWithValue("@EffectType", (int)type);
                    command.Parameters.AddWithValue("@" + typeId, id);
                    command.ExecuteNonQuery();
                    break;

                case EffectType.STAT:
                    StatEffect se = (StatEffect)e;
                    query   = "INSERT INTO Effect VALUES(@Name, @EffectType, @StatType, NULL, NULL, " + queryIdSubstring + ", @Intensity)";
                    command = new SqlCommand(query, connection);
                    command.Parameters.AddWithValue("@Name", se.name);
                    command.Parameters.AddWithValue("@EffectType", (int)type);
                    command.Parameters.AddWithValue("@StatType", (int)se.getAffectedStat());
                    command.Parameters.AddWithValue("@" + typeId, id);
                    command.Parameters.AddWithValue("@Intensity", se.getIntensity());
                    command.ExecuteNonQuery();
                    break;

                case EffectType.BUFF:
                    BuffEffect be = (BuffEffect)e;
                    query   = "INSERT INTO Effect VALUES(@Name, @EffectType, NULL, @BuffType, NULL, " + queryIdSubstring + ", @Intensity)";
                    command = new SqlCommand(query, connection);
                    command.Parameters.AddWithValue("@Name", be.name);
                    command.Parameters.AddWithValue("@EffectType", (int)type);
                    command.Parameters.AddWithValue("@BuffType", (int)be.getBuff());
                    command.Parameters.AddWithValue("@" + typeId, id);
                    command.Parameters.AddWithValue("@Intensity", be.getIntensity());
                    command.ExecuteNonQuery();
                    break;

                case EffectType.DEBUFF:
                    DebuffEffect de = (DebuffEffect)e;
                    query   = "INSERT INTO Effect VALUES(@Name, @EffectType, NULL, NULL, @DebuffType, " + queryIdSubstring + ", @Intensity)";
                    command = new SqlCommand(query, connection);
                    command.Parameters.AddWithValue("@Name", de.name);
                    command.Parameters.AddWithValue("@EffectType", (int)type);
                    command.Parameters.AddWithValue("@DebuffType", (int)de.getDebuff());
                    command.Parameters.AddWithValue("@" + typeId, id);
                    command.Parameters.AddWithValue("@Intensity", de.getIntensity());
                    command.ExecuteNonQuery();
                    break;
                }
            }
            connection.Close();
        }