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
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:
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 0..@menu.size - 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
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
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!