require 'herorealms'
require 'decks'
require 'stdlib'
require 'timeoutai'
require 'hardai_2'
require 'aggressiveai'
--=======================================================================================================
--This lua file builds on the one from lesson #1, Player 1 and 2 were swapped from before so the 2nd player
--would be an AI bot witha random charcter/build and player 1 would have a custom loadout.
--
--The new thing here is the creation and use of a custom Action card in player 1's deck.
--I removed most of the comments form lesson #1 so i could add new ones to call attention to
--all the things that you have to do to make a new action card.
--=======================================================================================================
function setupGame(g)
	registerCards(g, {
        --Anytime you make a new card/skill/ability/armor you need to put them here to be registered before you can use it.
        teach_them_a_lesson_carddef()
	})

    standardSetup(g, {
        description = "Lesson #2: Custom Action Cards<br>Created by WardenSlayer.",
        playerOrder = { plid1, plid2 },
        ai = ai.CreateKillSwitchAi(createAggressiveAI(),  createHardAi2()),
        timeoutAi = createTimeoutAi(),
        opponents = { { plid1, plid2 } },
        players = {
            {
                id = plid1,
                startDraw = 3,
                name = "Lua Lesson Warrior",
                avatar="assassin",
                health = 50,
                cards = {
                    deck = {
                        --Here the custom action card is added to player 1's deck
                        { qty=4, card=teach_them_a_lesson_carddef()},
                        { qty=8, card=gold_carddef() },
                    },
                    skills = {
                        {qty = 1, card = thief_lift_carddef() },
                        {qty = 1, card = fighter_devastating_blow_carddef()},
                        {qty = 1, card = ranger_hunters_cloak_carddef()},
                    },
                    buffs = {
                        drawCardsCountAtTurnEndDef(5),
                        discardCardsAtTurnStartDef(),
                        fatigueCount(40, 1, "FatigueP1")
                    }
                }
            }, 
            {
                --Player 2 is an AI controlled player. They will have a random class/build each time
                --The AI is always the same level as the player's character.
                id = plid2,
                isAi = true,
                startDraw = 5,
				init = {
                    fromEnv = plid2
                },
                cards = {
					buffs = {
                        drawCardsCountAtTurnEndDef(5),
                        discardCardsAtTurnStartDef(),
						fatigueCount(40, 1, "FatigueP2"),
					}
                }
            },          
        }
    })
end

--=======================================================================================================
--When making a custom card of any type, it starts with a declaration function like this.
--There are 2 main steps to making a custom card.
--     1) Designing the layout of the card (to include the actual abilities the card has)
--     2) Coding the functionality of card
function teach_them_a_lesson_carddef()
    --This first section creates a card layout for use later on
	local cardLayout = createLayout({
        --This is the dispaly text ont he card title
		name = "Teach Them a Lesson",
        --This sets the art that displays on card (you can find these in the art section of the Lua Doc)
		art = "art/T_Seek_Revenge",
        --This sets the card frame/border art that displays on card (you can find these in the frames section of the Lua Doc)
		frame = "frames/Ranger_CardFrame",
        --This is the card type display text that appears at the top center of the card
		cardTypeLabel = "Action",
        --This part generates the card ability text that tells you what the card does
        --This xmlText was generated by using the card designer
        xmlText = [[
                    <vlayout>
                        <box flexibleheight="1">
                            <tmpro text="&lt;cspace=1.0em&gt;{combat_2}&lt;/cspace&gt;" fontsize="48"/>
                            <tmpro text="&lt;cspace=-1em&gt;{gold_2}&lt;/cspace&gt;" fontsize="48"/>
                        </box>
                        <divider/>
                        <hlayout flexibleheight="1">
                            <box flexiblewidth="1">
                                <tmpro text="{scrap}" fontsize="36"/>
                            </box>
                            <box flexiblewidth="7">
                                <tmpro text="Opponent discards 2." fontsize="22" />
                            </box>
                        </hlayout>
                    </vlayout>
                ]]
	})
	--This next section populated the object data for the card l
    --and is how you controwhat the card can do
	return createActionDef({
        --The cards ID which can be used t identify it in other places
		id = "teach_them_a_lesson_card",
        --The card's name but not the one you see on the card image.
		name = "Teach Them a Lesson",
        --If you were to buy the card how much would it cost
		acquireCost = 0,
        --This is the card type display text that appears at the top center of the card
		cardTypeLabel = "Action",
        --Here you define what types the card has so it can interact with other cards
        --that do different things base don type
        --ActionType for actions, noStealType is for starter cards or cards you dont want a thief to be able to steal
        --other exmaples (like meleeWeaponType or bowType) can befound in the card subtypes section of the Lua document)
		types = { actionType, noStealType },
        --Here we finally use the layout created above to set the visual display for the card
		layout = cardLayout,
        --Where the card is played, for actions that is castPloc which is different then where champions are played
		playLocation = castPloc,
        --This last section creates object data to make the card work.
        --A card can have any number of abilities but this one has two.
		abilities = {
            --This ability triggers any time the card is played and gives 2 combat and 2 gold.
			createAbility({
				id = "teachMain",
                --Auto trigger means it triggers as soon as it played (other trigger options can be found in the Lua Doc)
				trigger = autoTrigger,
				effect = gainCombatEffect(2).seq(gainGoldEffect(2)),
			}),
            --This ability only tiggers when the user tells it to, it sacrifices the card
            --for an ability (like a fire gem)
            createAbility({
				id = "teachSac",
                --requires player interaction to trigger
				trigger = uiTrigger,
                --the prompt is what you see when you click on a card to make it bigger to read it
				promptType = showPrompt,
                --The prompt layout does not automatically use the same layout as the card. Here they are forced to be the same thing.
				layout = cardLayout,
                --Cost is used to make the player pay something to activate the effect. Here the cost is the card itself is sacrificed.
				cost = sacrificeSelfCost,
				effect = oppDiscardEffect(2)
			}),
		}
	})
end

--=======================================================================================================
function endGame(g)
end

--=======================================================================================================
function setupMeta(meta)
    meta.name = "lesson_2"
    meta.minLevel = 0
    meta.maxLevel = 0
    meta.introbackground = ""
    meta.introheader = ""
    meta.introdescription = ""
    meta.path = "C:/Users/xTheC/Desktop/Git Repositories/Hero-Realms-Lua-Lessons/Lua Lesson #2/lesson_2.lua"
     meta.features = {
}

end