using System.Linq;
using Assets.Scripts.Player;
using Node = Assets.Scripts.Events.GameEvent.Node;
using Option = Assets.Scripts.Events.GameEvent.Option;

namespace Assets.Scripts.Events
{
    public class Act3Events : EventBuilder
    {
        public Act3Events () : base(Act.Act_3) { }

        protected override void AddEvents() {
            AddRecurringEvent(
                new Node("An ornate statue, rooted to the ground by a massive pedestal, fills the room with a dark aura. \"Halt!\", it commands. You feel strangely compelled to obey, despite suspecting that you could outrun it. Passage requires a sacrifice.",
                    new Option("Sacrifice the Body") {
                        NextNode = new Node("A great eviscerating pain runs through your body, as the statue seems to take perverse enjoyment out of the situation. [-3 HP to random hero]") {
                            Effect = c => c.PlayerStats.RandomHero().TakeDamage(3)
                        }
                    },
                    new Option("Sacrifice the Mind") {
                        NextNode = new Node("Your mind seems to be on fire, while you are tormented by dreadful visions of worlds beyond this realm of reality. The visions eventually go, but they take some of your will with them. [-3 Sanity to random hero]") {
                            Effect = c => c.PlayerStats.RandomHero().LoseSanity(3)
                        }
                    },
                    new Option("Sacrifi- RUN!!") {
                        NextNode = new Node("You turn to flee, but the commanding voice of the statue rings loudly: \"Fools! You shall be cursed for your disrespect!\". As the words stop reverberating, you feel your legs losing strength, and your whole body responding slowly. [+1s cooldown to all]") {
                            Effect = c => c.PlayerStats.ForAllHeroes(h => h.AddBuff(new Buff { Attribute = MobAttribute.Cooldown, Value = 1 }))
                        }
                    }
                )
            );

            AddSpecificEvent("Cultists1",
                new Node("Cultists are here.",
                    new Option("Fight them!") {
                        NextNode = new Node("Well then, it's on.") {
                            Effect = c => c.PlayerStats.CultistsDefeated++,
                            PostEffect = c => c.StartBattle(MobFactory.MakeCultist(), MobFactory.MakeCultist())
                        }
                    },
                    new Option("Leave them be.") {
                        NextNode = new Node("Meh. You go away.")
                    }
                )
            );

            AddSpecificEvent("Cultists2",
                new Node("More cultists are here.",
                    new Option("Fight them!") {
                        NextNode = new Node("Well then, it's on.") {
                            Effect = c => c.PlayerStats.CultistsDefeated++,
                            PostEffect = c => c.StartBattle(MobFactory.MakeCultist(), MobFactory.MakeCultist())
                        }
                    },
                    new Option("Leave them be.") {
                        NextNode = new Node("Meh. You go away.")
                    }
                )
            ).TriggerCondition = stats => stats.CultistsDefeated == 1;

            AddSpecificEvent("Cultists3",
                new Node("Even more cultists are here.",
                    new Option("Fight them!") {
                        NextNode = new Node("Well then, it's on.") {
                            Effect = c => c.PlayerStats.CultistsDefeated++,
                            PostEffect = c => c.StartBattle(MobFactory.MakeCultist(), MobFactory.MakeCultist())
                        }
                    },
                    new Option("Leave them be.") {
                        NextNode = new Node("Meh. You go away.")
                    }
                )
            ).TriggerCondition = stats => stats.CultistsDefeated == 2;

            AddSpecificEvent("City4",
                new Node("A place to rest",
                    new Option("Rest [20 gold]") {
                        Condition = p => p.Gold >= 20,
                        NextNode = new Node("You rest.") {
                            Effect = c => {
                                c.PlayerStats.Gold -= 20;
                                c.PlayerStats.Rest();
                            }
                        }
                    },
                    new Option("Don't rest") {
                        NextNode = new Node("Your loss.")
                    }
                )
            );

            AddSpecificEvent("Dracula",
                new Node("Finally, as you step through the castle, you reach your objective. Dracula. The source of all evil in the land, and your ultimate goal in your mission given by the Queen. \"This is the land of men, Dracula. Begone!\", you yell, attempting to sound cool."
                    , new Option("Continue") {
                        NextNode = new Node("\"What is a man?\", the vampire lord asks, speaking as if reading a script for the first time. \"A miserable little pile of clichés and old references. You shall join the pile of corpses from the previous heroes.\" He motions to the side, nonchalantly, to the pile of corpses from the previous heroes.") {
                            PostEffect = c => c.StartBattle(MobFactory.MakeDracula())
                        }
                    }
                )
            );

            AddSpecificEvent("Necromancer2WithoutDead",
                new Node("Something seems off. Dracula lies defeated, yet evil lingers. Suddenly, a nearby statue cracks, and a woman emerges from within. Tall, pale, beautiful, wearing black robes - there's no mistake, it's the necromancer from before. \"Curse those cultists! They should be hiding my presence!\", she shouts."
                    , new Option("\"About those cultists...\"") {
                        NextNode = new Node("\"You have what!?\", she yells, incredulous. Yes, so I am behind bringing Dracula back. But fair enough. You have cornered me. It's time for one last entertaining battle...") {
                            PostEffect = c => c.StartBattle(MobFactory.MakeSkeleton(), MobFactory.MakeNecromancer())
                        }
                    }
                )
            ).TriggerCondition = stats => stats.CultistsDefeated == 3 && stats.DeadCharacters.Length == 0;

            AddSpecificEvent("Necromancer2WithDead",
                new Node("Something seems off. Dracula lies defeated, yet evil lingers. Suddenly, a nearby statue cracks, and a woman emerges from within. Tall, pale, beautiful, wearing black robes - there's no mistake, it's the necromancer from before. \"Curse those cultists! They should be hiding my presence!\", she shouts."
                    , new Option("\"About those cultists...\"") {
                        NextNode = new Node("\"You have what!?\", she yells, incredulous. \"Yes, so I am behind bringing Dracula back. But fair enough. You have cornered me. It's time for one last entertaining battle... But first...\" She points her fingers at your fallen comrades, and they rise back to life... though they're not quite the same.") {
                            PostEffect = c => {
                                var enemies = c.PlayerStats.DeadCharacters.Concat(new[] { MobFactory.MakeSkeleton(), MobFactory.MakeNecromancer() }).ToArray();
                                c.PlayerStats.RemoveDead();
                                c.StartBattle(enemies);
                            }
                        }
                    }
                )
            ).TriggerCondition = stats => stats.CultistsDefeated == 3 && stats.DeadCharacters.Length > 0;
        }
    }
}
