require "prawn"
require "prawn/table"
require "prawn/grouping"
require "pry"

require_relative "spell"
require_relative "spells"

require_relative "merit"
require_relative "merits"

require_relative "primitive_adds"

class Prawn::Document
	def background_color(color)
	  tmp_color = fill_color
	  canvas do
	    fill_color color
	    fill_rectangle [bounds.left, bounds.top], bounds.right, bounds.top
	  end
	  fill_color tmp_color
	end
end

class Awakened2069
	FONT_SIZE_CHAPTER = 48
	FONT_SIZE_BODY = 11
	FONT_SIZE_SECTION = 24
	FONT_SIZE_SUBSECTION = 18

	INDENT_SIZE = 25
	attr_accessor :pdf, :chapter_title, :section_name

	def start_chapter(chapter_name)
		@chapter_title = chapter_name
		puts "Starting #{chapter_title}"

		pdf.start_new_page

		pdf.outline.update do
			puts "\tAdding #{@awakened2069.chapter_title} on page #{page_number}"
			section(@awakened2069.chapter_title, :destination => page_number)
		end

		puts "\tSetting font size"
		pdf.font_size Awakened2069::FONT_SIZE_CHAPTER
		pdf.font "Ultramarines"
		puts "\tPrinting chapter to document"
		pdf.text chapter_title, :align => :center

		puts "\tRestoring body text"
		pdf.font "Goudy"
		pdf.font_size FONT_SIZE_BODY
	end

	def start_section(section_name)
		puts "Beginning section #{section_name}: "

		@section_name = section_name

		pdf.outline.add_subsection_to(chapter_title) do
			@pdf.outline.section section_name, :destination => @pdf.page_number
		end

		puts "\tSetting font size"
		pdf.font "Ultramarines"
		pdf.font_size FONT_SIZE_SECTION
		pdf.text section_name, :align => :center

		puts "\tRestoring body text"
		pdf.font_size FONT_SIZE_BODY
		pdf.font "Goudy"

	end

	def generate
		@pdf = Prawn::Document.new(:margin => 0)
		pdf.font_families.update(
			"Goudy"  => {
				:normal => "goudy.ttf",
				:bold   => "goudy-bold.ttf",
				:italic => "goudy-italic.ttf"
			},
			"Abess"  => {
				:normal => "abess.ttf"
			},
			"Lilith" => {
				:normal => "lilith.ttf"
			},
			"Goblin Hand" => {
				:normal => "VTCGoblinHand.ttf",
				:bold   => "VTCGoblinHandBold.ttf",
				:italic => "VTCGoblinHandItalic.ttf"
			},
			"Ultramarines"  => {
				:normal => "ultramarines.ttf"
			},
			"Unispace"  => {
				:normal => "unispace rg.ttf"
			}
		)

		pdf.outline.instance_variable_set(:@awakened2069, self)

		pdf.image("cover.png", :width => 612, :height => 792)

		pdf.start_new_page(:margin => 50)

		pdf.font "Ultramarines"
		pdf.font_size 72
		pdf.text "Awakened 2069", :align => :center

		pdf.font "Goudy"
		pdf.font_size 36
		pdf.text "\nGuide To The Mage: the Awakening, Second Edition Game On Discord. \n\nInvite Code:", :align => :center

		pdf.font "Unispace"
		pdf.text "25MpfjP", :align => :center

		pdf.font "Goudy"
		pdf.font_size 24
		pdf.text "\n\nAll content in this manual is inspired by the Storyteller and the players", :align => :center

		start_chapter "Introduction"

		pdf.default_leading 5

		pdf.column_box([0, pdf.cursor], :columns => 2, :width => pdf.bounds.width) do
			start_section "So Last Century"
			pdf.text "In the year 2020, they said that \"the future is now!\" In some ways, they were right, but in others they were decidedly incorrect. A lot of the technological promises that were made in past decades never realized, and others entirely unconceived materialized instead. The optimism of the 1950's and 1960's gave way to the policies of the 1990's that would lead to the economic collapse in the 2000's, and from there into the first serious Internet-aged political conflict in the 2010's. The conflict emerged as a combination of bottom-up, grass-roots submovements, and as a consequence of various entities from above meddling in the affairs of the populace.\nNobody was prepared for that conflict, as sociopathic social justice advocates and their opposition, the frustrated, nihilistic dank memers took control of the mainstream institutions. While some of this came about on their own, everybody wanted to blame some higher authority, some foreign government, some ethnic group, or political minority. These people were not entirely off, since only so much can come from above or below, but instead of grand conspiracies of Russian governments, most of the deterioration of society was generated opportunistically by malignant spirits, by Elder Kindred, by Changelings and the True Fae, and, yes, by <b>the Exarchs</b>.\nYouTube,  Facebook, Twitter, and every other social media company banned noteworthy voices in the time's contemporary discourse. Universities put a hard clamp down on which perspectives their undergraduate students were allowed to hold, and large corporations mass terminated people who failed to toe the party line. Sure, the political party these institutions were playing favorites with were surely controlled by the Exarchs themselves, but the <i>real</i> thing they were desperately trying to keep under wraps is that the world people lived in was a Lie. A direct consequence of freedom of speech in practice combined with hundreds of millions of smartphones is that people are one idiot supernatural away from turning large swathes of the population into Sleepwalkers, and a decent chunk of them into the Awakened. These Exarchs could have none of that.", :inline_format => true, :indent_paragraphs => INDENT_SIZE

			start_section "Changing Times"

			pdf.text "The Guardians of the Veil played right into the plans of the Exarchs. They tried to distract the Sleeping world with two approaches. One, they did the standard controlled opposition stunts, where they created immense Labyrinths of nonsensical conspiracy theories that ultimately meant nothing. However, they also tried to distract the Sleeping world with the banning of Holocaust denial videos and the termination of everybody with a wacky conspiracy theory from any form of conventional employment (which is a departure from their historical <i>modus operandi</i>), since they were also frantically deleting videos of vampires coercing children to give them their blood, posts describing exactly how to eliminate Uratha who predated the wives and daughters of the citizenry, and, most importantly, any content betraying or, heaven forbid, detailing the way Supernal magic functioned. Too many were appearing too quickly; it was almost as though supernatural entities became more brazen about exposing their true natures as people's personal recording technology and communication skills increased.\nThe views of the people who knew they were being shut up for political reasons mixed with the realities that politically unaligned people were uploading. The two groups intermingled creating bizarre supernatural conspiracy theories that got many details right, but never quite got the whole picture. There was always something off, something missing or incorrect. The pace of this mixture increased as Guardian and Exarch alike lost control of the conversation. Everybody knew that <i>something fucking huge</i> was up, but very few people knew exactly what. Those holding taboo political views banded together with those openly discussing the supernatural, and began retaliating against this suppression. As the world entered 2020's, the United States fell into civil war from all of this, descending into a Weimerica scenario borne directly of the nightmarish rants of every no-name YouTuber with thirty to fifty subscribers.\n\n", :inline_format => true, :indent_paragraphs => INDENT_SIZE

				start_section "The Hammer Comes Down"

				pdf.text "During that civil war, the videos stopped. The Internet went black. Cell phone networks suddenly got shut off without explanation. People were plunged into a long-term media blackout as every mainstream institution insisted that nothing out of the ordinary was taking place. This went on for a decade, where Internet access was considered a privilege that could be revoked for any or no reason, at the discretion of one's employer, university, or the government. Almost nobody was granted this access because unrestricted Internet access was considered \"dangerous.\" When it became normal for regular citizens to gain access to this service again, there were no conspiracy theories on the Internet anymore. Everything was normal again.\nThe 2030's were when different corporate entities became the new feudal lords of American society. It was the decade that travel between continents became trivial if you had the money, and a trip to the grocery store became untenable if you did not. Compulsory tracking devices were installed in every newborn American citizen as well as the European Union. The Chinese were even more severe, installing chips that could neural override their citizens on a whim. It was the decade that sophisticated cybernetics and brain-computer-interfaces became commonplace for the wealthy, and cheaper, crappier versions of the same, riddled with bugs, problems, and advertisements became legally mandatory for the poor. It was the decade that all of humankind forever traded away wonder for reason. Or so it seemed...", :inline_format => true, :indent_paragraphs => INDENT_SIZE

				start_section "A Dark Age In The Computing Era"

				pdf.text "The 2040's and 2050's are now a blur. Nobody knows what really happened. Every week, the news, the university professors, the government, insists something different happened in those two decades. Yet everybody just plays along. It's hard to tell for the Awakened if these people are fully brainwashed or if they are merely pretending so as to avoid getting into some sort of trouble. Possession of books is forbidden, since they are less mutable than websites.\nOne thing is understood, however, is that Pentacle society more or less collapsed in this period. Some people think that the civil war and its consequences were responsible. However, the lack of any known Pentacle Mages born in the 2020's or earlier is an indication that the ones existing in the 2030's through the 2050's either jumped ships to the Seers or were disappeared. Blaming the Seers of the Throne directly for this phenomena is common, but unconfirmed. It's also speculated that Exarchs, Oracles, and other Archmages essentially destroyed the world during this period, and the one that people live in for 2069 is a cheap facsimile of what once was, hence the gap and the nonsensical \"history\" everybody gets fed.\nIt took until the late 2060's for Awakened society to even partially recover. That recovery is ongoing. The old Pentacle Orders have re-emerged, in part due to forbidden records of their existence and histories being uncovered. However, it also seems as though these Orders exist naturally. Maybe they were re-seeded by the Oracles. Maybe it's just the way of the world. People were on the brink of a global Awakening in 2020, but as with all things, the more things change, they more they stay the same. Awakened society in 2069 is easily the most underground of the noteworthy supernatural entities. Demons and Beasts appear to be largely defeated, while Vampires and Werewolves appear to be given a deliberate <i>carte blanche</i>. When an Awakened individual gets too arrogant and betrays what they're <i>actually</i> about, they have a habit of disappearing; not every time, but often enough for \"it's a coincidence\" to be a big reach. It's uncanny the efficiency with which this happens.\nWhat is known, however, is that no Awakened soul today appears to be born before 2030. The young scholars that have emerged seem to have formed a consensus that they were all disappeared much in the way their new friends will be if they get too Hubristic, but nobody seems to have concrete proof of this. It's one of those things that \"everybody knows\" in the Awakened community, yet nobody can prove. This may be because it's total hogwash, but it seems plausible enough that nobody questions it.", :inline_format => true, :indent_paragraphs => INDENT_SIZE
		end

		start_chapter "Orders"
		pdf.column_box([0, pdf.cursor], :columns => 2, :width => pdf.bounds.width) do
			pdf.text "The Five Pentacle Orders have re-emerged in spirit if not in the specifics from the previous generations, or at least the ones before 2020. This short chapter should detail the ways in which they are unique to Awakened 2069.", :inline_format => true, :indent_paragraphs => INDENT_SIZE

			start_section "The Free Council"

			pdf.text "The Free Council is easily the largest Order that has re-emerged. While they were the young bucks, the punks before 2020, they borderline on the norm outright in 2069. Technomages through the 2000's, but pro-LGBT activists in the 2010's, their resurgence has restored them to their more dignified pre-2010 roots. The Free Council are the foremost authorities on cybernetics, artificial intelligence, brain computer interfaces among the Awakened community. Their claim to this domain carries Supernal weight. As such, all such Supernal Cybernetics that are permanent must be acquired through a member of the Free Council of appropriate status. This is no orthopractic issue; it carries such weight that losing one's stature in the Free Council seems to remove one's ability to create permanent Supernal Cybernetics. One simply cannot cast their way into Lasting cybernetic technology. Period.\n<b>Sample Character Concepts:</b> transhumanist ideologue, corporate saboteur, cryptocurrency thief, digital grimoire seeder, cryptographic cracker", :inline_format => true, :indent_paragraphs => INDENT_SIZE

			start_section "The Guardians of the Veil"

			pdf.text "The Guardians of the Veil hold the least graceful position among the Pentacle Orders due to the fact that they were ultimately Seer pawns in the 2020's. However, they play an important role in 2069 that is not to be disregarded. Since Mages are routinely disappeared whenever they get a bit too obnoxious with their magic in public, the Veil isn't just to protect Sleepers from noticing, but more importantly, Pentacle Mages from Seers and other such malicious entities. Guardians in 2069, as a consequence of being duped in the past, are likely the most rabidly anti-Seer among the Awakened, in that fascists have historically been reformed socialists.\n<b>Sample Character Concepts:</b> safehouse manager, anti-Paradox ideologue, abyssal removal specialist, forcer of memes, good cop/bad cop dualist", :inline_format => true, :indent_paragraphs => INDENT_SIZE

			start_section "The Mysterium"

			pdf.text "The Mysterium's core beliefs have definitely come to the fore for many Mages, and one thing that has caught the attention of its current members more than any other Order is the verifiable existence of lost history. It is up for debate if Sleepers know that the history from recent decades is entirely lost or if they are merely deluded. Mind-readers seem to get different reads from person to person. However, it is not up for debate to Awakened society; most of what people are told about these decades is completely fabricated. The Mysterium takes particular note of this and Obsessions to the effect of \"what actually happened, here?\" are common themes among its scholarly class.\n<b>Sample Character Concepts:</b> technoarchaeologist, digital archivist, Obsession-addler, secret broker, Artifact hoarder", :inline_format => true, :indent_paragraphs => INDENT_SIZE

			start_section "The Silver Ladder"

			pdf.text "The Silver Ladder has not lost faith in the possibility of a global Awakening, and will consistently cite the late 2010's as an example of this. They insist that if Awakened society creates conditions similar to it, but precludes more authoritarian elements from cropping up, that this global Awakening will realize. Sometimes this gets derided by the rest of Awakened society, but never to an extent that they are denounced or discarded completely. These people often lead worthy Mystery Cults, and endeavor to create as many Sleepwalkers as possible to in turn maximize their chance of Awakening. So far, this has created mixed results, partly due to the fact that Guardians create their own Mystery Cults that are about distracting the unworthy and stupid with nonsensical gibberish and forced memes.\n<b>Sample Character Concepts:</b> redpilled Internet personality, intersplat negotiator, cult leader, newbie mentor, Awakened judicial watchdog", :inline_format => true, :indent_paragraphs => INDENT_SIZE

			start_section "The Adamantine Arrow"

			pdf.text "The Adamantine Arrow continues in its old footsteps, but that doesn't mean every single thing is the same. They know that these days, there are too many well-equipped enemy combatants out there to simply go at them hand-to-hand, or to be so simple in their approach as to start shooting fireballs out of their eyes. They know to manipulate the crowd to come for them. They know to be agile, and stealthy, and appear where they are not expected. Ensuring that someone they intend to protect can escape is often more important than looking like a hero, and using a magically-enhanced drone to kill someone from afar is more important than the satisfaction they might gain by looking them in the eye as they sink their knife into that quarry.\n<b>Sample Character Concepts:</b> stochastic terrorist, urban guerrilla, drone general, trojan horse, technothug", :inline_format => true, :indent_paragraphs => INDENT_SIZE
		end

		start_chapter "New Merits"


		pdf.column_box([0, pdf.cursor], :columns => 2, :width => pdf.bounds.width) do
			Merit.merits(pdf).each(&:render)
		end

		start_chapter "Rules & Guidelines"

		pdf.column_box([0, pdf.cursor], :columns => 2, :width => pdf.bounds.width) do
			pdf.text "These rules are a combination of my own ideas, plus some other people's ideas. Many are designed with making the game grittier. Some of these are <i>inspired</i> by other people's ideas, but aren't theirs directly.", :inline_format => true

			start_section "Withstand"

			pdf.table([ ["•", "All supernatural entities can spend their Mana, Essence, Vitae, Glamour or similar stat to boost their Withstand rating against any aggressive spell and know to do so intuitively if they so desire"],
        			["•", "Add Withstand to the required number of successes for an Exceptional Success. For example, a Praxis requires three successes for an exceptional success, and if that Praxis is used on someone who Withstands at four, then seven successes are needed for an exceptional success on the casting of that spell."],
        			["•", "Withstand reduces the Potency of the spell being cast on it. Players should not be told what the Withstand rating of a spell is directly; they need to find out on their own through some other means, or take a guess."] ]) do
				row(0..3).border_width = 0
			end

			start_section "Paradox"

			pdf.table([ ["•", "All willworkers in the same scene share a single Paradox pool. Once one has overreached, everybody runs the risk of Paradox on further castings of spells."],
        			["•", "When containing a Paradox, successes on the Wisdom roll deal resistant bashing as normal. However, after Wisdom is rolled, the willworker may choose to forcefully contain as much as whatever is left as he likes; they may take one resistant lethal damage to absorb one success from the Paradox roll."],
        			["•", "Whenever a Paradox roll is made, the Abyss forces the Magic used to be obvious. Dissonance occurs to all Sleepers present."],
        			["•", "Demesnes do not fully obviate Paradox. Instead, they reduce the Paradox dice pool by the number of soul stones used to create it. Additionally, if the Paradox dice pool is reduced to a chance die, it does not occur, even if Sleepers are present."],
        			["•", "The first Paradox roll must have a dice pool of at least one. The accumulation of additional Paradox dice begins once a finalized Paradox dice pool is at least one."] ]) do
				row(0..1000).border_width = 0
			end

			start_section "Spellcasting"

			pdf.table([ ["•", "Successive attempts do not yield a cumulative dice pool penalty. Instead, they yield a cumulative +1 Reach penalty. Spells that are functionally the same as determined by the Storyteller qualify as successive."],
				["•", "Spellcasting dice pools may not fall below zero. You can Reach to increase the dice pool of a spell by +2, until the spell is at least zero. This Reach option cannot be used to boost a spell's dice pool past a non-negative dice pool."],
				["•", "You may use Creative Thaumaturgy to change the primary factor in a spell without using a Reach."],
				["•", "You my use Scale as the primary factor."],
				["•", "For +1 Reach, you may distribute the spell factor table advances however you please."],
				["•", "Infinite loop combos don't work. Period."]
			] ) do
				row(0..1000).border_width = 0
			end

		end

		pdf.render_file("writeup.pdf")
	end
end


awakened2069 = Awakened2069.new
awakened2069.generate