public static void onRespawnAlchemist(Player player, OrchidModPlayer modPlayer, Mod mod)
 {
     modPlayer.alchemistPotency             = modPlayer.alchemistPotencyMax;
     modPlayer.alchemistFlaskDamage         = 0;
     modPlayer.alchemistNbElements          = 0;
     modPlayer.alchemistPotencyDisplayTimer = 0;
     OrchidModAlchemistHelper.clearAlchemistElements(player, modPlayer, mod);
     OrchidModAlchemistHelper.clearAlchemistFlasks(player, modPlayer, mod);
     OrchidModAlchemistHelper.clearAlchemistColors(player, modPlayer, mod);
 }
        public static void ResetEffectsAlchemist(Player player, OrchidModPlayer modPlayer, Mod mod)
        {
            if (OrchidModAlchemistHelper.getNbAlchemistFlasks(player, modPlayer, mod) == 0)
            {
                OrchidModAlchemistHelper.clearAlchemistFlasks(player, modPlayer, mod);
                OrchidModAlchemistHelper.clearAlchemistElements(player, modPlayer, mod);
                OrchidModAlchemistHelper.clearAlchemistColors(player, modPlayer, mod);
            }

            if (modPlayer.alchemistHasBag < 1 && modPlayer.alchemistPotionBag[0].type != 0)
            {
                foreach (Item item in modPlayer.alchemistPotionBag)
                {
                    if (item.type != 0)
                    {
                        player.QuickSpawnItem(item.type, 1);
                        item.TurnToAir();
                    }
                }
            }

            modPlayer.alchemistDailyHint        = (Main.dayTime && Main.time == 0) ? false : modPlayer.alchemistDailyHint;
            modPlayer.alchemistLastAttackDelay += modPlayer.alchemistLastAttackDelay < 3600 ? 1 : 0;
            modPlayer.alchemistHasBag          -= modPlayer.alchemistHasBag > 0 ? 1 : 0;

            modPlayer.alchemistPotencyMax          = 8;
            modPlayer.alchemistRegenPotency        = 60;
            modPlayer.alchemistNbElementsMax       = 2;
            modPlayer.alchemistCrit                = 0;
            modPlayer.alchemistDamage              = 1.0f;
            modPlayer.alchemistVelocity            = 1.0f;
            modPlayer.alchemistSelectUIDisplay     = modPlayer.alchemistSelectUIItem ? modPlayer.alchemistSelectUIDisplay : false;
            modPlayer.alchemistSelectUIKeysDisplay = modPlayer.alchemistSelectUIKeysItem ? modPlayer.alchemistSelectUIKeysDisplay : false;
            modPlayer.alchemistSelectUIItem        = false;
            modPlayer.alchemistSelectUIKeysItem    = false;
            modPlayer.alchemistBookUIDisplay       = modPlayer.alchemistBookUIItem ? modPlayer.alchemistBookUIDisplay : false;
            modPlayer.alchemistBookUIItem          = false;
            modPlayer.alchemistEntryTextCooldown   = false;

            modPlayer.alchemistMeteor         = false;
            modPlayer.alchemistFlowerSet      = false;
            modPlayer.alchemistMushroomSpores = false;
            modPlayer.alchemistReactiveVials  = false;
            modPlayer.alchemistCovent         = false;
        }
        public static bool checkSubstitutes(int ingredientID, Mod mod, Player player, OrchidModPlayer modPlayer)
        {
            List <int> ingredientToCompare = new List <int>();

            ingredientToCompare.Add(ItemType <CloudInAVial>());
            ingredientToCompare.Add(ItemType <AttractiteFlask>());
            ingredientToCompare.Add(ItemType <BlinkrootFlask>());
            ingredientToCompare.Add(ItemType <ShiverthornFlask>());
            ingredientToCompare.Add(ItemType <CorruptionFlask>());
            ingredientToCompare.Add(ItemType <GoblinArmyFlask>());

            foreach (int ingredient in ingredientToCompare)
            {
                if (ingredientID == ItemType <CloudInAVial>())
                {
                    return(OrchidModAlchemistHelper.containsAlchemistFlask(ItemType <FartInAVial>(), player, modPlayer) ||
                           OrchidModAlchemistHelper.containsAlchemistFlask(ItemType <BlizzardInAVial>(), player, modPlayer) ||
                           OrchidModAlchemistHelper.containsAlchemistFlask(ItemType <TsunamiInAVial>(), player, modPlayer));
                }
                if (ingredientID == ItemType <AttractiteFlask>())
                {
                    return(OrchidModAlchemistHelper.containsAlchemistFlask(ItemType <GlowingAttractiteFlask>(), player, modPlayer));
                }
                if (ingredientID == ItemType <GoblinArmyFlask>())
                {
                    return(OrchidModAlchemistHelper.containsAlchemistFlask(ItemType <HellOil>(), player, modPlayer));
                }
                if (ingredientID == ItemType <BlinkrootFlask>())
                {
                    return(OrchidModAlchemistHelper.containsAlchemistFlask(ItemType <FireblossomFlask>(), player, modPlayer));
                }
                if (ingredientID == ItemType <ShiverthornFlask>())
                {
                    return(OrchidModAlchemistHelper.containsAlchemistFlask(ItemType <DeathweedFlask>(), player, modPlayer));
                }
                if (ingredientID == ItemType <CorruptionFlask>())
                {
                    return(OrchidModAlchemistHelper.containsAlchemistFlask(ItemType <CrimsonFlask>(), player, modPlayer));
                }
            }
            return(false);
        }
        public static void triggerAlchemistReaction(Mod mod, Player player, OrchidModPlayer modPlayer)
        {
            string floatingTextStr = "Failed reaction ...";
            AlchemistHiddenReactionRecipe hiddenReaction = new RecipeBlank();

            foreach (AlchemistHiddenReactionRecipe recipe in OrchidMod.alchemistReactionRecipes)
            {
                bool goodIngredients = true;
                if (modPlayer.alchemistNbElements == recipe.ingredients.Count)
                {
                    foreach (int ingredientID in recipe.ingredients)
                    {
                        if (!(OrchidModAlchemistHelper.containsAlchemistFlask(ingredientID, player, modPlayer)))
                        {
                            if (!AlchemistHiddenReactionHelper.checkSubstitutes(ingredientID, mod, player, modPlayer))
                            {
                                goodIngredients = false;
                                break;
                            }
                        }
                    }
                    if (goodIngredients)
                    {
                        hiddenReaction  = recipe;
                        floatingTextStr = recipe.name;

                        int  val  = 0;
                        Item item = new Item();
                        foreach (int ingredientID in recipe.ingredients)
                        {
                            item.SetDefaults(ingredientID);
                            OrchidModGlobalItem globalItem = item.GetGlobalItem <OrchidModGlobalItem>();
                            val += globalItem.alchemistPotencyCost;
                        }
                        val = (int)(val / 2);
                        CombatText.NewText(player.Hitbox, new Color(128, 255, 0), val);
                        modPlayer.alchemistPotency += modPlayer.alchemistPotency + val > modPlayer.alchemistPotencyMax ? modPlayer.alchemistPotencyMax : modPlayer.alchemistPotency;
                        break;
                    }
                }
            }

            Color floatingTextColor = hiddenReaction.typeName != "RecipeBlank" ? new Color(128, 255, 0) : new Color(255, 0, 0);

            CombatText.NewText(player.Hitbox, floatingTextColor, floatingTextStr);

            if (hiddenReaction.typeName == "RecipeBlank")
            {
                player.AddBuff((BuffType <Alchemist.Buffs.Debuffs.ReactionCooldown>()), 60 * 5);
                for (int i = 0; i < 15; i++)
                {
                    int dust = Dust.NewDust(player.Center, 10, 10, 37);
                    Main.dust[dust].noGravity = true;
                    Main.dust[dust].velocity *= 2f;
                    Main.dust[dust].scale    *= 1.2f;
                }
                for (int i = 0; i < 10; i++)
                {
                    int dust = Dust.NewDust(player.Center, 10, 10, 6);
                    Main.dust[dust].noGravity = true;
                    Main.dust[dust].velocity *= 2f;
                    Main.dust[dust].scale    *= 1.5f;
                }
                Main.PlaySound(2, (int)player.position.X, (int)player.position.Y, 16);
            }
            else
            {
                triggerAlchemistReactionEffects(hiddenReaction, mod, player, modPlayer);

                if (!(modPlayer.alchemistKnownReactions.Contains(hiddenReaction.typeName)))
                {
                    if (modPlayer.alchemistKnownHints.Contains(hiddenReaction.typeName))
                    {
                        modPlayer.alchemistKnownHints.Remove(hiddenReaction.typeName);
                    }
                    modPlayer.alchemistKnownReactions.Add(hiddenReaction.typeName);
                    floatingTextColor = new Color(255, 187, 0);
                    floatingTextStr   = "New Entry";
                    Rectangle rect = player.Hitbox;
                    rect.Y -= 50;
                    CombatText.NewText(rect, floatingTextColor, floatingTextStr);
                }
            }

            int colorRed   = modPlayer.alchemistColorR;
            int colorGreen = modPlayer.alchemistColorG;
            int colorBlue  = modPlayer.alchemistColorB;

            int rand = 2 + Main.rand.Next(3);

            for (int i = 0; i < rand; i++)
            {
                int     proj      = ProjectileType <Alchemist.Projectiles.AlchemistSmoke1>();
                Vector2 vel       = (new Vector2(0f, -((float)(2 + Main.rand.Next(5)))).RotatedByRandom(MathHelper.ToRadians(180)));
                int     smokeProj = Projectile.NewProjectile(player.Center.X, player.Center.Y, vel.X, vel.Y, proj, 0, 0f, player.whoAmI);
                Main.projectile[smokeProj].localAI[0] = colorRed;
                Main.projectile[smokeProj].localAI[1] = colorGreen;
                Main.projectile[smokeProj].ai[1]      = colorBlue;
            }
            rand = 1 + Main.rand.Next(3);
            for (int i = 0; i < rand; i++)
            {
                int     proj      = ProjectileType <Alchemist.Projectiles.AlchemistSmoke2>();
                Vector2 vel       = (new Vector2(0f, -((float)(2 + Main.rand.Next(5)))).RotatedByRandom(MathHelper.ToRadians(180)));
                int     smokeProj = Projectile.NewProjectile(player.Center.X, player.Center.Y, vel.X, vel.Y, proj, 0, 0f, player.whoAmI);
                Main.projectile[smokeProj].localAI[0] = colorRed;
                Main.projectile[smokeProj].localAI[1] = colorGreen;
                Main.projectile[smokeProj].ai[1]      = colorBlue;
            }
            rand = Main.rand.Next(2);
            for (int i = 0; i < rand; i++)
            {
                int     proj      = ProjectileType <Alchemist.Projectiles.AlchemistSmoke3>();
                Vector2 vel       = (new Vector2(0f, -((float)(2 + Main.rand.Next(5)))).RotatedByRandom(MathHelper.ToRadians(180)));
                int     smokeProj = Projectile.NewProjectile(player.Center.X, player.Center.Y, vel.X, vel.Y, proj, 0, 0f, player.whoAmI);
                Main.projectile[smokeProj].localAI[0] = colorRed;
                Main.projectile[smokeProj].localAI[1] = colorGreen;
                Main.projectile[smokeProj].ai[1]      = colorBlue;
            }

            AlchemistHiddenReactionHelper.bonusReactionEffects(mod, player, modPlayer);

            modPlayer.alchemistFlaskDamage = 0;
            modPlayer.alchemistNbElements  = 0;
            OrchidModAlchemistHelper.clearAlchemistElements(player, modPlayer, mod);
            OrchidModAlchemistHelper.clearAlchemistFlasks(player, modPlayer, mod);
            OrchidModAlchemistHelper.clearAlchemistColors(player, modPlayer, mod);
            modPlayer.alchemistSelectUIDisplay = false;
        }
        public static void alchemistPostUpdateEquips(Player player, OrchidModPlayer modPlayer, Mod mod)
        {
            int regenComparator = modPlayer.alchemistPotencyWait <= 120 ? modPlayer.alchemistPotencyWait <= 0 ? (int)(modPlayer.alchemistRegenPotency / 3) : (int)(modPlayer.alchemistRegenPotency / 2) : modPlayer.alchemistRegenPotency;

            if (modPlayer.alchemistPotency < modPlayer.alchemistPotencyMax && ((modPlayer.alchemistRegenPotency > 0) ? modPlayer.timer120 % regenComparator == 0 : true))
            {
                modPlayer.alchemistPotencyDisplayTimer = 180;
                modPlayer.alchemistPotency++;
                modPlayer.alchemistFlowerTimer = modPlayer.alchemistFlowerSet ? 600 : 0;
            }
            else
            {
                if (modPlayer.alchemistPotency > modPlayer.alchemistPotencyMax)
                {
                    modPlayer.alchemistPotency = modPlayer.alchemistPotencyMax;
                }
                modPlayer.alchemistPotencyDisplayTimer--;
            }

            modPlayer.alchemistResetTimer   = (modPlayer.alchemistPotencyDisplayTimer > 0) ? 300 : modPlayer.alchemistResetTimer - 1;
            modPlayer.alchemistResetTimer   = (modPlayer.alchemistResetTimer == -1) ? 0 : modPlayer.alchemistResetTimer;
            modPlayer.alchemistPotencyWait -= modPlayer.alchemistPotencyWait > 0 ? 1 : 0;

            if (modPlayer.alchemistResetTimer == 1)
            {
                modPlayer.alchemistFlaskDamage = 0;
                modPlayer.alchemistNbElements  = 0;
                OrchidModAlchemistHelper.clearAlchemistElements(player, modPlayer, mod);
                OrchidModAlchemistHelper.clearAlchemistFlasks(player, modPlayer, mod);
                OrchidModAlchemistHelper.clearAlchemistColors(player, modPlayer, mod);
            }

            if (modPlayer.alchemistColorRDisplay != modPlayer.alchemistColorR)
            {
                bool superior = modPlayer.alchemistColorRDisplay > modPlayer.alchemistColorR;
                int  abs      = Math.Abs(modPlayer.alchemistColorRDisplay - modPlayer.alchemistColorR);
                int  val      = (int)(abs / 10);
                if (abs > val)
                {
                    modPlayer.alchemistColorRDisplay += superior ? -val : val;
                }
                modPlayer.alchemistColorRDisplay += superior ? -1 : 1;
            }

            if (modPlayer.alchemistColorGDisplay != modPlayer.alchemistColorG)
            {
                bool superior = modPlayer.alchemistColorGDisplay > modPlayer.alchemistColorG;
                int  abs      = Math.Abs(modPlayer.alchemistColorGDisplay - modPlayer.alchemistColorG);
                int  val      = (int)(abs / 10);
                if (abs > val)
                {
                    modPlayer.alchemistColorGDisplay += superior ? -val : val;
                }
                modPlayer.alchemistColorGDisplay += superior ? -1 : 1;
            }

            if (modPlayer.alchemistColorBDisplay != modPlayer.alchemistColorB)
            {
                bool superior = modPlayer.alchemistColorBDisplay > modPlayer.alchemistColorB;
                int  abs      = Math.Abs(modPlayer.alchemistColorBDisplay - modPlayer.alchemistColorB);
                int  val      = (int)(abs / 10);
                if (abs > val)
                {
                    modPlayer.alchemistColorBDisplay += superior ? -val : val;
                }
                modPlayer.alchemistColorBDisplay += superior ? -1 : 1;
            }
        }