Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function onload()
- masterCardTable = {
- {name="Potion", xp="1", type=""},
- {name="Boulder Badge", xp="4", type="Challenge"},
- --etc etc etc
- }
- scoreZoneTable = {
- {scoreZone=getObjectFromGUID(""), color="Green"},
- {scoreZone=getObjectFromGUID(""), color="Red"},
- {scoreZone=getObjectFromGUID(""), color="White"},
- {scoreZone=getObjectFromGUID(""), color="Blue"},
- {scoreZone=getObjectFromGUID(""), color="Red"},
- }
- --insert button creation here
- end
- --Gets 1 deck from each scripting zone, adds it to deckToScoreList
- --Along with that zone's color
- function onButtonPress()
- deckToScoreList = {}
- for i, zone in pairs(scoreZoneTable) do
- local objectsInZone = zone.scoreZone.getObjects()
- for j, deck in ipairs(objectsInZone) do
- if deck.tag == "Deck" then
- table.insert(deckToScoreList, {deck=deck, color=zone.color})
- break
- end
- end
- end
- getDeckValues(deckToScoreList)
- end
- --Obtains total values into a table.
- --Totals xp, # of challenge cards and # of evolution cards
- function getDeckValues(deckToScoreList)
- = {}
- for i, deck in ipairs(deckToScoreList) do
- local cardsInDeck = deck.deck.getObjects()
- for j, card in ipairs(cardsInDeck) do
- table.insert(deckValueList, {xp=0, challenge=0, pokemon=0, , cards=0, color=deck.color})
- for k, master in ipairs(masterCardTable) do
- if master.name == card.nickname then
- deckValueList[i].xp = deckValueList[i].xp + master.xp
- deckValueList[i].cards = deckValueList[i].cards + 1
- if master.type == "Challenge" then
- deckValueList[i].challenge = deckValueList[i].challenge + 1
- elseif master.type == "Pokemon" then
- deckValueList[i].pokemon = deckValueList[i].pokemon + 1
- end
- end
- end
- end
- end
- --At this point, we have a deckValueList that looks like:
- --deckValueList = { {xp=#, challenge=#, pokemon=#, color="ColorName"}, {etc etc}, etc etc}
- findWinner(deckValueList)
- end
- function findWinner(deckValueList)
- --Sort by XP
- local sort_func = function( a,b ) return a.xp > b.xp end
- table.sort( deckValueList, sort_func )
- if deckValueList[1].xp > deckValueList[2].xp then
- --Winner is deckValueList[1].color
- printToAll("Winner is: " .. deckValueList[1].color .. " with XP: " .. deckValueList[1].xp, {1,1,1})
- else
- --Make a new table with only tied XP players
- tieList1 = {}
- for i=1, #deckValueList do
- if deckValueList[1] == deckValueList[i] then
- table.insert(tieList1, deckValueList[i])
- end
- end
- --Prints tie report line
- local nameString = ""
- for i=1, #tieList1 do
- nameString = nameString .. Player[tieList1[i].color].steam_name .. " "
- end
- printToAll(nameString .. "were tied for first in XP at : " .. tostring(tieList1[1].xp), {1,1,1})
- --Sorts them by challenge
- local sort_func = function( a,b ) return a.challenge > b.challenge end
- table.sort( tieList1, sort_func )
- --check for a winner
- if tieList1[1].challenge > tieList1[2].challenge then
- --Winner is tieList1[1].color
- printToAll("Winner is: " .. tieList1[1].color .. " with XP: " .. tieList1[1].xp, {1,1,1})
- else
- --Make a new table with only tied Challenge players
- tieList2 = {}
- for i=1, #tieList1 do
- if tieList1[1] == tieList1[i] then
- table.insert(tieList2, tieList1[i])
- end
- end
- --Sorts them by pokemon
- local sort_func = function( a,b ) return a.pokemon > b.pokemon end
- table.sort( tieList2, sort_func )
- --check for a winner
- if tieList2[1].pokemon > tieList2[2].pokemon then
- --Winner is tieList2[1].color
- else
- --Make a new table with only tied Pokemon players
- tieList3 = {}
- for i=1, #tieList2 do
- if tieList2[1] == tieList2[i] then
- table.insert(tieList3, tieList2[i])
- end
- end
- --Sorts them by pokemon
- local sort_func = function( a,b ) return a.cards > b.cards end
- table.sort( tieList2, sort_func )
- --check for a winner
- if tieList2[1].cards > tieList2[2].cards then
- --Winenr is tieList3[1].color
- else
- --4 way tie, what the eff are the odds of that?!
- end
- end
- end
- end
- end
- if deckValueList[1].xp > deckValueList[2].xp then
- --Winner is deckValueList[1].color
- local ct = stringColorToRGB(deckValueList[1].color)
- printToAll("With a total of " .. deckValueList[1].xp .. " XP, " .. Player[deckValueList[1].color].steam_name .. " has proven to be the Pokémon Master this time!", ct)
- else
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement