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

namespace Assets.Scripts.Events
{
    public class Act1Events : EventBuilder
    {
        public Act1Events() : base(Act.Act_1) {}

        protected override void AddEvents() {
            AddRecurringEvent(
                new Node("In front of you, you see the unmistakable silhouette of three zombies, doing what zombies do to a helpless ex-peasant. You consider your options.",
                    new Option("Charge!") {
                        NextNode = new Node("You do what adventurers do, and draw your weapons, charging the zombies. In all their undead awareness, they do not react until you are upon them.") {
                            PostEffect = c => c.StartBattle(MobFactory.MakeZombie(), MobFactory.MakeZombie(), MobFactory.MakeZombie()),
                            AfterResume = new Node("Well, that was a fun battle. The zombies had some pocket change, which you've nabbed. [+5 gold]") {
                                Effect = c => c.PlayerStats.Gold += 5
                            }
                        }
                    },
                    new Option("Keep moving, ignoring them") {
                        NextNode = new Node("You do what cowardly adventurers do, and keep on riding the comfy insides of your wagon. The next band of adventurers can handle those zombies. [-1 Sanity to all]") {
                            PostEffect = c => c.PlayerStats.ForAllHeroes(d => d.LoseSanity(1))
                        }
                    }
                )
            );

            AddRecurringEvent(
                new Node("The guard ahead signals you to stop. The grey lion in her white tunic betrays her true role: a toll collector. This is a classic model wagon, and will be required to pay some hefty gold to go through.",
                    new Option("Stop and pay [5 gold]") {
                        Condition = p => p.Gold >= 5,
                        NextNode = new Node("Well, the law is the law. You are happy that the current situation of the world isn't bad enough that it turns you into a bandit, and you are grateful to the government for pretending to maintain the road with your toll money. [-5 gold, +1 sanity all]") {
                            Effect = core => core.PlayerStats.Gold -= 5
                        }
                    },
                    new Option("Break through!") {
                        NextNode = new Node("Life is too short for paying taxes. You speed through, dodging the guard, who signals her colleagues to shoot at you. As much as you try to dodge them, one of the arrows hits you. [-5 HP on one character]") {
                            Effect = c => c.PlayerStats.RandomHero().TakeDamage(5)
                        }
                    }
                )
            );

            AddEvent(
                new Node("As the temperature plunges, the mist turns into fog, and you proceed slowly through the night. As the fog starts to clean up, you see two figures hunched in the side of the road. You hail them, to no reply. You wonder if they're deaf, wounded, or simply unable to understand human language...",
                    new Option("Approach them, they might be in need") { 
                        NextNode = new Node("You approach them cautiously, repeating your attempts at hailing them. They don't seem to respond to your calls, but as you get closer it becomes clear that they are not wounded. You realize what's going on when it's too late, and the zombies rise to attack you.") {
                            PostEffect = c => c.StartBattle(MobFactory.MakeZombie(), MobFactory.MakeZombie())
                        }
                    },
                    new Option("Keep moving, ignoring them") {
                        NextNode = new Node("You wonder what horrors they might have faced, and what condition now afflicts them. You decide that it's best not to think very much about it, though the very thought has filled you with regret. [-2 Sanity to all]") {
                            PostEffect = c => c.PlayerStats.ForAllHeroes(d => d.LoseSanity(2))
                        }
                    }
                )
            );

            AddEvent(
                new Node("You think that there might be a trap ahead. This is both due to your years of experience, which have refined your observation skills to match that of a wild beast, and because the poorly concealed pit on the road ahead contains significant amounts of blood stains around it.",
                    new Option("Try to be clever to catch the culprit") {
                        NextNode = new Node("The trap is very poorly designed and amateurish, but you do notice a rope extending from it, presumably to notify the culprit of the capture of an incredibly stupid victim. You roll a large boulder into the trap, triggering it, and run for cover on the side of the road.",
                            new Option("Continue") {
                                NextNode = new Node("The plan works, and the incredibly unintelligent lowlife emerges, eagerness visible in his grey eyes. As he approaches the trap, the marginally more intelligent you attempts to grab him from behind, but he recoils like a trapped animal, stabbing you in the side, before you snap his neck. He leaves behind his spoils. [+40 gold] [-3 HP to one character]") {
                                    Effect = c => {
                                        c.PlayerStats.RandomHero().TakeDamage(3);
                                        c.PlayerStats.Gold += 40;
                                    }
                                }
                            }
                        )
                    },
                    new Option("Ignore the trap and leave") {
                        NextNode = new Node("You decide that nothing good would come out of that situation, and you proceed on your travels.")
                    }
                )
            );

            AddSpecificEvent("OldWoman1",
                new Node("\"Please, spare some coins for a sick woman\", says the old, skinny old lady. Her eyes are grey, and her white hair contrasts with her black robe. She approached as you stopped for a short break, seemingly coming from nowhere.",
                    new Option("Give her 30 coins") {
                        Condition = p => p.Gold >= 30,
                        NextNode = new Node("Her face can hardly contain her shock as you give her the incredibly generous gift. \"Your generosity shall not go unrewarded.\" As she says that, a great silver light envelops you, and you feel mighty. [+1 Damage to all]") {
                            Effect = c => {
                                c.PlayerStats.ForAllHeroes(h => h.AddBuff(new Buff {Attribute = MobAttribute.Damage, Value = 1}));
                                c.PlayerStats.SetFlag("OldWoman1:Helped", true);
                            }
                        }
                    },
                    new Option("Give her 5 coins") {
                        Condition = p => p.Gold >= 5,
                        NextNode = new Node("\"Thank you for your generosity. May your bodies and souls find good rest.\" You feel a great refreshment through your body, but as you turn to thank the woman, she is gone. [+1 Health/Sanity to all]") {
                            Effect = c => {
                                c.PlayerStats.ForAllHeroes(h => {
                                    h.HealSanity(1);
                                    h.Heal(1);
                                });
                                c.PlayerStats.SetFlag("OldWoman1:Helped", true);
                            }
                        }
                    },
                    new Option("Tell her to go away") {
                        NextNode = new Node("The woman is visibly upset by your discourtesy. Though she goes away quietly, your mind starts going to dark places, and you wonder if you've been cursed. [-1 Sanity to all]") {
                            Effect = c => c.PlayerStats.ForAllHeroes(h => h.LoseSanity(1))
                        }
                    },
                    new Option("Steal her coin bag") {
                        NextNode = new Node("Really? Have you not read like, ANY fairy tales, ever? Her fury rises like a storm surge as you grab her coin bag. Her scream is mighty and causes your ears to bleed and your heart to tremble. Your bones feel excruciating pain... you think that you can take it no more, and then she is gone. All that remains is her purse. [-3 Health/Sanity all, +12 Gold]") {
                            Effect = c => {
                                c.PlayerStats.ForAllHeroes(h => {
                                    h.LoseSanity(3);
                                    h.TakeDamage(3);
                                });
                                c.PlayerStats.Gold += 12;
                            }
                        }
                    }
                )
            );

            AddEvent(
                new Node("The night gets darker and colder by the minute. From deep within the woods, you hear a very weak, high-pitched sound. It doesn't speak with words, but you know it's crying for help. Wait, could that be... the voice of a poor, harmless, lost child?!",
                    new Option("Go investigate, of course!") {
                        NextNode = new Node("Not being a complete pessimistic pays off sometimes! It was, in fact, an innocent child. You bring him to his desperate parents, who reward you with some delicious (although a bit overdone for your taste) roasted duck. [+5 health to all]") {
                            Effect = c => c.PlayerStats.ForAllHeroes(h => h.Heal(5))
                        }
                    },
                    new Option("Nah... It's probably a demon in disguise or something.") {
                        NextNode = new Node("You've learned your lesson. Trust no one from this stupid, deceiving forest! You ignore the voice as it faints away in apparent never-ending despair. [-1 Sanity to all]") {
                            Effect = c => c.PlayerStats.ForAllHeroes(h => h.LoseSanity(1))
                        }
                    }
                )
            );

            AddEvent(
                new Node("A very strange woman is laying on the middle of the road, just a few meters away from the wagon. Her gray, torn clothes dancing in the weak wind as if they were trying to tell you something.",
                    new Option("Go help her!") {
                        NextNode = new Node("As you approach the body, you notice she has a big, scary smile on her face. Her eyes blank, the bright light of the moon reflecting on her pointy teeth. Just when you're about to give her a proper burial, she suddenly comes back to life. Her teeth grow even bigger, there's now black, thick fur from her head down to her feet. It's a werewolf, you soon conclude.") {
                            PostEffect = c => c.StartBattle(MobFactory.MakeWerewolf())
                        }
                    },
                    new Option("Run over her.") {
                        NextNode = new Node("The wagon moves forward as you try to pretend you didn't see anything, when suddenly... there's actually nothing there anymore. The woman is gone! Leaving only a few torn pieces of cloth behind, and... some black fur?")
                    }
                )
            );

            AddSpecificEvent("City1",
                new Node("Your travels lead you to Stygia, where you can finally rest from the low-level encounters you've had. Stumbling through the cold, dark alleys, you find a suitable inn, the Stone Bed, where you may spend the night - but you are surprised that the innkeeper does not offer discounts for heroes-to-be.",
                    new Option("Rest [20 gold]") {
                        Condition = p => p.Gold >= 20,
                        NextNode = new Node("The quasi-comfortable beds of this aptly-named inn welcome you, and despite lacking in comfort, the warm food and shelter refreshes you, and you feel ready to march onwards. [+3 health/sanity to all] [-20 gold]") {
                            Effect = c => {
                                c.PlayerStats.Gold -= 20;
                                c.PlayerStats.Rest();
                            }
                        }
                    },
                    new Option("The wagon will be a perfectly adequate hotel room") {
                        NextNode = new Node("...or so you thought. The cold of the night got even colder as the night got night...er. You got some rest, but at the cost of bitter regret. [+1 health/-1 sanity to all]") {
                            Effect = c => c.PlayerStats.ForAllHeroes(p => {
                                p.Heal(1);
                                p.LoseSanity(1);
                            })
                        }
                    }
                )
            );

            AddSpecificEvent("Healer1",
                new Node("A young girl, probably no older than 10, approaches you. Her black skin softly reflects the moonlight, and her eyes seem to sparkle with inner light. \"You are weary from your travels. I can provide divine help... for a cost.\". It's rare to see a Priestess of Ak'tul this far from their home.",
                    new Option("Ask for healing [10 gold]") {
                        Condition = p => p.Gold >= 10,
                        NextNode = new Node("She whispers enchantments in an ancient, unknown language. You instantly feel much better. [+3 health to all] [-10 gold]") {
                            Effect = c => {
                                c.PlayerStats.Gold -= 10;
                                c.PlayerStats.ForAllHeroes(h => h.Heal(3));
                            }
                        }
                    },
                    new Option("Ask for a blessing healing [20 gold]") {
                        Condition = p => p.Gold >= 10,
                        NextNode = new Node("She whispers enchantments in an ancient, unknown language. You feel blessed with divine guidance. [+10% accuracy to all] [-10 gold]") {
                            Effect = c => {
                                c.PlayerStats.Gold -= 10;
                                c.PlayerStats.ForAllHeroes(p => p.AddBuff(new Buff {Attribute = MobAttribute.Accuracy, Value = 0.1f}));
                            }
                        }
                    },
                    new Option("Dismiss her services, but give her a donation [5 gold]") {
                        Condition = p => p.Gold >= 5,
                        NextNode = new Node("She seems surprised by your gesture. \"Never before have I encountered generosity like this. Please, accept this gift.\" She whispers enchantments in an ancient, unknown language. You feel irradiated with divine power. [+3 HP to all] [+10% accuracy to all] [-5 gold]") {
                            Effect = c => {
                                c.PlayerStats.Gold -= 5;
                                c.PlayerStats.ForAllHeroes(p => {
                                    p.AddBuff(new Buff {Attribute = MobAttribute.Accuracy, Value = 0.1f});
                                    p.Heal(3);
                                });
                            }
                        }
                    },
                    new Option("Dismiss her services") {
                        NextNode = new Node("\"I understand that you are fighting against the evil that rises against this land. Please, take this, it might be of help to you\", she says, as she hands you a charm. [+10% accuracy for one character]") {
                            Effect = c => c.PlayerStats.RandomHero().AddBuff(new Buff { Attribute = MobAttribute.Accuracy, Value = 0.1f })
                        }
                    }
                )
            );

            AddSpecificEvent("Boss1",
                new Node("After countless hours on the road leading from home to your destiny, you come upon the hill which marks the end of the road. From here on, the forces of evil rule unchallenged. Until now.",
                    new Option("Continue") {
                        NextNode = new Node("However, as you climb the hill, you feel a chilling presence surrounding you. \"Welcome, human.\", said the chilly, raspid voice of a skeletal warrior. His silver sword glimmered, and with an inhuman yell, they descended upon you.") {
                            PostEffect = c => c.StartBattle(MobFactory.MakeZombie(), MobFactory.MakeZombie(), MobFactory.MakeZombie(), MobFactory.MakeSkeleton()),
                            AfterResume = new Node("Somehow, you seem to have survived the undead horde. Their bodies now lying broken upon the dead grass of the hill, you step upon the skull of the skeletal warrior, shattering it as you gaze towards the grey town beyond: the village of the damned itself. You'll have to cross it. [-1 Sanity to all]")
                        }
                    }
                )
            );
        }
    }
}
