Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

[RMXP] problem with Triple Triad Script

Hello everyone. I'm from germany, so sorry for my bad english. ^^

I tried something in the Triple Triad Script.
Code:
 

  #===========================================================================

  # ** 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

 

In line 164, I added a new "Code".
This should operates as follows:
If the opponent win the game, so the card he chose should switch to his ownership.

My RGSS skills are really low and this is just an "experiment".
I want to have unique cards in my game. Some certain NPC's will have these unique cards.
If the player lose a unique card to an opponent, i want that the player have the chance, to get back this card from this opponent.

Now the problem:
If the opponent gets one of these unique cards, he use these card only in the next card match. After that match, the card seems disappear from his ownership. He never use this card again.

Its the same problem when I give the NPC special cards with:
Code:
$game_tripletriad.players[npc_id].gain_card(deck_index, level_index, card_index)
They use this card only one time.

I hope somebody can help me. :)
Also i hope, that the post is unterstandable xD
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top