RGSS TCG (In Pieces)

RGSS TCG


Hello. As some may know, I have been working for a few months on a special Toolkit for people who want a Trading Card Game-esque Battle System. Unfortunately, I have been having some personal issues and a case of stupidity, and so I the system is not complete, nor perfect, and is in fact only partially a script. The larger part of the script is Event Based. I plan on writing a complete Scene for this someday, but for today I shall only release one of four scripts.

As I complete each one, I shall release it, and when they are all complete, I will create a Demo with a sample map, manual, and a bunch of special features that aren't in the "core" release.

The Core TCG Script is made of four scripts that are called in Event Call Script commands. These scripts are held in Module TCG, which is in Module OS.

Here is Release One: Attack Core v1.0.0
Attack Spoiler

module OS
  module TCG
    class Attack
      def initialize(user, target)
        @user = user
        @target = target
        main
      end
     
      def main
        if @user.position == 0 # Attack Position
          if @target.position == 0 # Attack Position
            if @user.attack > @target.attack
              if !usable_effects?(@target, "AtDeath")
                return true
              elsif usable_effects?(@target, "AtDeath")
                e = get_usable_effects(@target, "AtDeath")
                return e
              end
            elsif @user.attack < @target.attack
              if !usable_effects?(@user, "AtDeath")
                return false
              elsif usable_effects?(@user, "AtDeath")
                e = get_usable_effects(@user, "AtDeath")
                return e
              end
            end
          elsif @target.position == 1 # Defence Position
            if @user.attack > @target.defence
              if !usable_effects?(@target, "AtDeath")
                return true
              elsif usable_effects?(@target, "AtDeath")
                e = get_usable_effects(@target, "AtDeath")
                return e
              end
            elsif @user.attack < @target.defence
              if !usable_effects?(@user, "AtDeath")
                return false
              elsif usable_effects?(@user, "AtDeath")
                e = get_usable_effects(@user, "AtDeath")
                return e
              end
            end
          end
        elsif @user.position == 1 # Defence Position
          return nil
        end
      end
     
      def usable_affects?(who, what)
        ret = []
        if what == "AtDeath"
          for i in 0..who.effects.keys.size - 1
            if who.effects.keys[i] == "AtDeath"
              ret.push(i)
            end
          end
        end
        return true if ret.size > 0
        return false
      end
     
      def get_usable_effects?(who, what)
        ret = []
        if what == "AtDeath"
          for i in 0..who.effects.keys.size - 1
            if who.effects.keys[i] == "AtDeath"
              ret.push(i)
            end
          end
        end
        return ret if ret.size > 0
        return nil
      end
    end
  end
end

Expand to see the code.

It should work of tested, but I'm not positive. It only has one Custom Tag (AtDeath), and that is all the Core System will have. The Demo will have the following:


module OS
  module TCG
    #=Data======================================================================
    # Data
    MaxHand = 7
    MaxDeck = 120
    MinHand = 1 # If greater than 0, duelist will draw until they have this many
                # cards if their Hand is under this value.
    MaxLife = 10000
    StartLife = 5000
    MinLife = 0 # If Life reaches this, the duelist fails.
    FieldWidth = 5
    FieldHieght = 2
    #=ID Custom Tags============================================================
    # Commands:
    Atk  = 0   # Attack Opponent
    Dfn  = 1   # Block Attack
    Set  = 3   # Set Card on Field (Face Down)
    Play = 4   # Set Card on Field (Face Up)
    Tap  = 5   # Tap a card on the field
    Draw = 6   # Draw a card from the Deck
    ResG = 7   # Restore a card from the Grave to the Field
    Rem  = 8   # Remove a card from the Duel entirely
    ResR = 9   # Restore a card from Removed to the Field
    TapO = 10  # Tap an Opponent's card on the Field
    Grav = 11  # Send a card to the Grave
    ToHn = 12  # Send a card to its owner's hand
    ToDk = 13  # Send a card to its owner's deck
    # Targets:
    MonS   = 0 # User's Monster
    MonO   = 1 # Opponent's Monster
    SplS   = 2 # User's Spell
    SplO   = 3 # Opponent's Spell
    ItmS   = 4 # User's Item
    ItmO   = 5 # Opponent's Item
    UsHn   = 6 # User's Hand
    OpHn   = 7 # Opponent's Hand
    RndHnS = 8 # Random Card from User's Hand
    RndHnO = 9 # Random Card from Opponent's Hand
    UsDk   = 10 # User's Deck
    OpDk   = 11 # Opponent's Deck
    RndDkS = 12 # Random Card from User's Deck
    RndHnO = 13 # Random Card from Opponent's Deck
    RndMnS = 14 # Random Monster from the User's Field
    RndMnO = 15 # Random Monster from the Opponent's Field
    RndSpS = 16 # Random Spell from the User's Field
    RndSpO = 17 # Random Spell from the Opponent's Field
    RndItS = 18 # Random Item from the User's Field
    RndItO = 19 # Random Item from the Opponent's Field
    # Target Attributes:
      # Atk and Dfn will work here as well!
    # Status:
    NoDuel  = 0 # All cards not in a duel have this stat! (slot 0)
    InHand  = 1 # Card is in a Hand (slot 1)
    InDeck  = 2 # Card is in a Deck (slot 1)
    OnField = 3 # Card is on the Field (slot 1)
    Removed = 4 # Removed from play (slot 1)
    Altered = 5 # Atk, Dfn, and/or Effects have been altered (slot 2)
    InGrave = 6 # Card is in a Grave (slot 1)
    AtDeath = 7 # Card has just died...
    #=Label Custom Tags=========================================================
    # Card Types:
    Monster = "Creature"
    Spell   = "Spell"
    Item    = "Equipment"
    # Elements:
    Fire   = "Pyro"
    Water  = "Aqua"
    Stone  = "Terra"
    Plant  = "Gaia"
    Soul   = "Spirit"
    Undead = "Cursed"
    # Attributes:
    Attack = "Atk Power"
    Defend = "Dfn Power"
  end
end
=begin
  There are two types of Custom Tags; ID and Label.
    *ID Tags are used in Card and Command declarations. Each ID Custom Tag
    equals an integer.
    *Label Tags are used in Menus, Descriptions, etc. These are just common
    names for things, as well as directories for graphics.
  A description of each Custom Tag and its use can be found in the Manual.
 
  When you see the Status CTs, you might notice the (slot #) at the end
of each description. This is to show where in the Array this data will stay.
I did this so you could understand that some States can't occur at the same time,
so they share a slot. If one state has the slot, an other state can't. If the slot
is given a new state, the first one will erase.
=end

Expand to see the code.


You may notice a short description at the end of these Tags that explain what Custom Tags (CT) are. For more information, and a list of other possible Tags, please check the New Projects forum for the RGSS TCG Toolkit thread.

Peace!

Here is Release 2: Activate Effect:
Activate Spoiler
module OS
  module TCG
    class Activate
      def initialize(card)
        $spriteset = Spriteset_Map.new
        @card = card
        ef_keys = @card.effects.keys
        ef_vals = @card.effects.values
        @menu = []
        for i in 0..ef_keys.size - 1
          @menu.push(ef_keys[i])
          @id_m.push(ef_vals[i])
        end
      end
     
      def main
        @activate = Window_Command.new(160, @menu)
        Graphics.transition
        loop do
          Graphics.update
          Input.update
          update
          if $scene != self
            break
          end
        end
        Graphics.freeze
        $spriteset.dispose
        @activate.dispose
      end
     
      def update
        $spriteset.update
        @activate.update
        if Input.trigger?(Input::B)
          $scene = Scene_Map.new
        end
        if Input.trigger?(Input::C)
          for i in [email hidden] - 1
            if @activate.index == @menu[i]
              activate_effect(i)
            end
          end
        end
      end
     
      def activate_effect(effect)
        if @menu[effect] == "Atk"
          if @id_m[effect][0] == "MonS"
            out = ["Atk", "MonS", @id_m[effect][1]]
          elsif @id_m[effect][0] == "MonO"
            out = ["Atk", "MonO", @id_m[effect][1]]
          end
        end
        $game_system.activate_effect = out # Check in a Call Script Command
        return
      end
    end
  end
end
Expand to see the code.


Here is Release 3: Card #1
Card Spoiler

module OS
  module TCG
    class Card
      def initialize(name, type = 0, s1 = 100, s2 = 100, s3 = [])
        #if type == 0 Monster s1 = Atk s2 = Dfn s3 = effects
        #if type == 1 Item s1 = target_card s2 = target_attribute s3 = alter_by/how
        #if type == 2 Spell s1 = target_card s2 = target_attribute s3 = alter_by/how
        # The difference is Spells go away after use. Items stay until destroyed.
        @name = name
        @type = type if type == 0 || type == 1 || type == 2
        if @type == 0
          @atk = s1
          @dfn = s2
          @effects = s3
        else
          @target = s1
          @attribute = s2
          @alterate = s3
        end
      end
     
      def atk
        return @atk if @type == 0
        return nil
      end
     
      def dfn
        return @dfn if @type == 0
        return nil
      end
     
      def effects
        return @effects if @type == 0
        return nil
      end
     
      def target
        return @target if @type != 0
        return nil
      end
     
      def attribute
        return @attribute if @type != 0
        return nil
      end
     
      def alterate
        return @alterate if @type != 0
        return nil
      end
    end
  end
end

Expand to see the code.

[/spoiler='Player v.1.0.1']

Here is Release 4: Player
Content Hidden Spoiler
module OS
  module TCG
    class Player
      def initialize(name, deck, library = nil)
        @name = name
        @library = library
        @deck = deck
        @wins = 0
        @losses = 0
      end
     
      def wins?
        return @wins
      end
     
      def losses?
        return @losses
      end
     
      def total?
        return @wins + @losses
      end
     
      def name
        return @name
      end
     
      def deck
        return @deck
      end
     
      def library
        return @library
      end
    end
  end
end
Expand to see the code.


[spoiler='Library']
module OS
  module TCG
    class Lib
      # Here you will create the Effects
      DrawCards = "DrawCards"
      # Here you will create the Cards
      Cards = {"draw3" => Card.new("Draw X3", 2, "UserDeck", DrawCards, 3)}
      # Here you will create the Player's Library and Deck
      PlayerLibrary = [Cards["draw3"]]
      PlayerStarterDeck = [Cards["draw3"]]
      # Here you will create Enemy Decks and Libraries
      Enemy1Deck = [Cards["draw3"]]
      Enemy2Deck = [Cards["draw3"]]
      # And here will be the players
      Players = {"Protagonist" => ["OScriptor", PlayerStartDeck, PlayerLibrary], "Antagonist" => ["OverflowS", Enemy1Deck], "Antagonist" => ["OceanS", Enemy2Deck]}
      # Methods for creating the Players
      def setup_players
        keys = Players.keys
        vals = Players.values
        for i in 0..keys.size - 1
          if keys[i] == "Protagonist"
            $tcg_player = Player.new(vals[i][0], vals[i][1], vals[i][2])
          elsif keys[i] == "Antagonist"
            $tcg_badies.push(Player.new(vals[i][0], vals[i][1]))
          end
        end
      end
    end
  end
end

class Scene_Title
  alias os_cng command_new_game
  def command_new_game
    $tcg_player = nil
    $tcg_badies = []
    os_cng
  end
end
Expand to see the code.


The Player Class is not just for the actual Player. You must use it to create all of the Duelists in the game, PC or NPC.

The DEMO version will come in either LITE or LOADED. LITE edition uses the above scripts, several Custom Tags, and has enough cards for two duelists. LOADED edition will come with newer versions of the above scripts, new Menu options that allow one to look at their Library, change cards in their decks, etc., and will also have enough cards for a full game (not a very long one, but I estimate 300 cards).

Peace!

NOTE: Sorry for taking so long. I am working on the Lite Demo now! If anyone wants to help, PM me with ideas for cards, graphics, etc. Peace!
Cool. We greatly anticipate the full release.
yeah me too,
as I got a little tcg project in my mind... ;p will be great ;p, take your time and improve again and again
Okay. I'm about to write Part II for tonight's release. I really am sorry I am releasing it this way, but in the end I think it will be very good.

Peace!

UPDATE--Added Release II. Sorry for Double Post, but that was a comment and this is an UPDATE. Peace!
woo! cant wait for all 4 releases, really want to make a tcg game now
It will be very difficult, I must admit, for you to make one right after the Final Release. But when the Demo Version becomes available, it will hopefully become much easier. Peace!
sorry yes thats what i meant, after the demo version
Interesting. TCG Games are awesome as long as they aren't n00b-filled and stuff or too liscensed ':| , but I hope this gets finished soon. You have my support. :thumb:
UPDATE: Release 3: Card #1 has been added!

Peace!
W00t! And I don't even understand a single thing on the card script! XD I think I should stick for the demo...:D :D :D
UPDATE: Player Script Released!

I was wrong about the amount of scripts to be released. There is just one more to write before I start on the DEMO.

So pray I finish the Library class soon so I can get started on the demo, cuz that'll take me a few days, if not weeks (the last weeks of school are full of work, however easy, but still loads of work.) Peace!
Hum, I hope there will be a deck management scene?
something between the item and equip scene will be perfect isn't it?

When I'll get some time, I'll try to play a bit with your scripts, and if needed improve it :p by adding some features :p
(and later try, maybe, an online version :p)


EDIT... >_< the : p for is usually a funny smiley...
If you look at the LOADED DEMO version features you will see Deck and Library management (I might have worded it differently, but it is there.)

As for Online, I won't have anything to do with it just yet, so good luck if you want to.

And on a final note, I may be making a Card Utility that allows you to create Cards, Custom Tags, and Effects easily so I don't have to write a manual on scripting it for you nonscriptors. But this is a big maybe! Peace!
cool, i am so looking forward to this when its done, keep it up!
[QUOTE=trebor777;204549]Hum, I hope there will be a deck management scene?
something between the item and equip scene will be perfect isn't it?[/QUOTE]

This or else the game will be sort of MtG 4th Edition for PC. You could research also a way to when you defeat someone, you pick a random card of his deck, just like MtG 4th edition for PC. There was a script around here about setting random parameters BTW.
ahh ^^ true, I read too fast sorry ^^

Well as a dev from Netplay+ ^^ i think i can handle the online part, if i need ^^
trebor -- okee, dokee.

foxbuster -- What? If I understand you correctly, then I think I could do that very easily. I happen to be a very successful Random Generator Scriptor. You may have seen my Random Weather generator, or the begginings of a Lock Pick system (which failed due to poor windows and graphics handling :( )

I post the next release soon. Peace!
just wanted to know is this still in the works?
I think is working on the demo, and the event system. It should take more time than in Ruby.
But having some news even, just to give some progress would be cool.
Oh, man, sorry guys! If this is too much of a late post, then I'm sorry, but I've been so busy with stuff that I forgot about finishing Library! It is done now, and I will begin on the demo tonight. Sorry about being so late...

Final Release of Script Sections. Updating first post.
Woohoo, the demo is about to be here! I can't wait! >w<
After all this waiting, it's about to come. I'm anxiously waiting for this, like I previously said.
Don't count on a release tonight, or even this weekend. But it should be out within the next week (hopefully). Getting started. Bye!
yeah ^^ news!
great! Hey don't be sorry, you got a life too. :p
I do? Never realized...Well, today was the last day of school, and I was looking through my desktop, and I found about ten+ TCG Attempts, all failures, and remembered I had one in the works to finish :) It feels good doing something productive again!

EDIT: The Demo is nearly complete! (I had no idea how easy parts of it would be to make!) All that is left to be made is the Updating portion of the Battle, in other words the part that switches turns, checks for alterations of cards, etc.

The demo has one battle, no cards (yet; I am going to make at least 40 cards for this one), and it shows a very basic version of battle. The battle will have the player walking around on the field, stepping onto cards to select them. This will change in the next demo if I ever get started on it.

I plan to release this demo real soon; if I work on this hard enough, I should be able to produce a decent version by Saturday night! Peace out, everyone.
Some neat thing I remembered...
IF you'll use MtG-like cards, I think I have some graphics for you to use...
Beyond that, you could set just like Ragnarok Online's card showing system. That would be cool too.
Sorry, folks. It seems that the final part of the demo is being an ass to me.

I've discovered a few errors in the scripts I already posted, and it seems that the original idea for the demo (making it primarily event based) was a horrible idea. I'm afraid the only way to really make this script any good is to make it entirely script based. The problem with that is, I am not that good at graphics handling. I am working hard on it, but I'm just not used to it yet. If anyone wants to, they can take what I've made and alter it, mash it, squish it, and fix it, so that everyone here can enjoy it.

Sorry for the crappy way things turned out this time. If anyone wants, I can rewrite the other scripts to be used by total noobs in their own event systems. Sorry guys.

*kicks self in face
thats what the rgss support forum is for :) or even the irc chat im sure plenty of people wouldnt mind helping you if you knew what it was that you wanted to do it never hurts to ask
What be htestatus?
The status be Under Construction. I have started on it again, but I won't be finishing it any time soon.
Never give up! :P

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=20302