#===========================================================================
# ** Game_TriadBattle
#===========================================================================
class Game_TriadBattle
#------------------------------------------------------------------------
# * Public Instance Variables
#------------------------------------------------------------------------
attr_reader :opponent_id
attr_reader :opponent
attr_accessor :player_cards
attr_accessor :opponent_cards
attr_accessor :visible_player_cards
attr_accessor :visible_opponent_cards
attr_accessor :player_panel_selections
attr_accessor :opponent_panel_selections
attr_accessor :player_select_index
attr_accessor :opponent_select_index
attr_accessor :dummy_card
attr_accessor :dummy_index
attr_accessor :boardpanels
#------------------------------------------------------------------------
# * Setup
#------------------------------------------------------------------------
def setup(opponent_id = 1)
@opponent_id = opponent_id
@opponent = $game_tripletriad.players[opponent_id]
@player_cards = []
@opponent_cards = []
@visible_player_cards = Array.new(5, true)
@visible_opponent_cards = Array.new(5, true)
@player_panel_selections = {}
@opponent_panel_selections = {}
@player_select_index = nil
@opponent_select_index = nil
@dummy_card = nil
@dummy_index = nil
@boardpanels = [ [], [], [] ]
for i in 0..2
3.times {@boardpanels[i] << Panel.new}
end
end
#------------------------------------------------------------------------
# * Select Opponent Cards
#------------------------------------------------------------------------
def select_opponent_cards
# Duplicates Opponent Cards
cards = @opponent.cards.dup
# Pick 5 Cards
5.times do
# Gets Random Deck Index
d_index = cards.keys[rand(cards.keys.size)]
l_index = cards[d_index].keys[rand(cards[d_index].keys.size)]
c_index = cards[d_index][l_index].keys[rand(cards[d_index][l_index].keys.size)]
# Repeat if Number of Cards < 1
redo if [0, nil].include?(cards[d_index][l_index][c_index])
# Subtract 1 From The List
cards[d_index][l_index][c_index] -= 1
# Set Opponent Card
set_opponent_card(d_index, l_index, c_index)
end
end
#------------------------------------------------------------------------
# * Set Player Card
#------------------------------------------------------------------------
def set_player_card(d_index, l_index, c_index)
card = $data_tripletriad_decks[d_index].cards[l_index][c_index]
@player_cards << [d_index, l_index, c_index, card]
end
#------------------------------------------------------------------------
# * Set Opponent Card
#------------------------------------------------------------------------
def set_opponent_card(d_index, l_index, c_index)
card = $data_tripletriad_decks[d_index].cards[l_index][c_index]
@opponent_cards << [d_index, l_index, c_index, card]
$game_tripletriad.see_card(d_index, l_index, c_index)
end
#------------------------------------------------------------------------
# * Player Score
#------------------------------------------------------------------------
def player_score
score = 0
for i in 0..2
for j in 0..2
unless boardpanels[i][j].card.nil?
score += 1 if boardpanels[i][j].players
end
end
end
return score
end
#------------------------------------------------------------------------
# * Opponent Score
#------------------------------------------------------------------------
def opponent_score
score = 0
for i in 0..2
for j in 0..2
unless boardpanels[i][j].card.nil?
score += 1 unless boardpanels[i][j].players
end
end
end
return score
end
#------------------------------------------------------------------------
# * Player Captured Cards
#------------------------------------------------------------------------
def player_captured_cards
captured = {}
for i in 0..4
if @opponent_panel_selections.has_key?(i)
x, y = @opponent_panel_selections[i] % 3, @opponent_panel_selections[i] / 3
captured[i] = @boardpanels[x][y].players ? true : false
else
captured[i] = false
end
end
return captured
end
#------------------------------------------------------------------------
# * Opponent Captured Cards
#------------------------------------------------------------------------
def opponent_captured_cards
captured = {}
for i in 0..4
if @player_panel_selections.has_key?(i)
x, y = @player_panel_selections[i] % 3, @player_panel_selections[i] / 3
captured[i] = @boardpanels[x][y].players ? false : true
else
captured[i] = false
end
end
return captured
end
#------------------------------------------------------------------------
# * Opponent Captured Cards
#------------------------------------------------------------------------
def select_opponent_victory_card
# Collects Card Levels
levels = []
@player_cards.each {|x| levels << x[1]}
# Gets Largest Level
index = levels.index(levels.max)
# Turn Test off
test = false
until test
# If Card Visible
if @visible_player_cards[index]
# Break If Not Capture Rule
test = true if $game_tripletriad.trade_rule < 4
# Break If Capture Rule & Card Captured
test = true if $game_tripletriad.trade_rule > 3 && opponent_captured_cards[index]
end
# Remove Index
levels.delete_at(index)
# Gets Largest Level
index = levels.index(levels.max)
end
# Collects Card Data
card = @player_cards[index]
# Player Loses Card
$game_tripletriad.player.lose_card(card[0], card[1], card[2])
$game_tripletriad.players[opponent_id].gain_card(card[0], card[1], card[2])
return card[3], index
end
end
end