ID:161869
 
In Magic The Gathering cards cost mana to play, which can be drawn from "land" cards (Swamps, Mountains, Forests, Islands, Plains). Some cards require specific land cards only, specific lands and colorless, or simply colorless. Colorless means you can use any type of land. For instance, if you need 1 Mountain and 1 Colorless, you must tap at least 1 Mountain, and 1 of any other type of land (including Mountains!) to play the card.

How would I go about coding this in BYOND, preferably the most easiest and noob-programmer friendly way? The way I was going to code it is varibles such as mob/var/swamplands, etc, etc, with mob/var/landtotals and subtracting the swamplands.. and then checking to see if landtotals are positive, etc, etc, but that is WAY too amatuer.
I don't personally code in BYOND, but your question is more or less answerable in a psuedo-code fashion, since you seem more interested in a design aspect.

You'd be looking for some kind of action to tap the lands, first.

Input: Either Click Event or a Verb
Check what I'm clicking on. Is it tapped already?
No? Then is it a Mountain? Is it a Swamp? Etcetera.
I know what the object is, so now I'll add to a counter that tracks my mana pool. (IE; I just tapped a mountain; so..)
Change the icon state of the clicked land to tapped. Designate somehow that this specific item instance is now tapped, and now can not be clicked on again.
+1 mountain resource counter.
Query other players; interrupt effect in response to the land tap? (IE; land destruction)
Code is now completed.

Casting a Spell:
Find the spell I'm casting. What is the cost associated with it? (IE; Firebolt. Cost: 1 mountain resource/ R)
Bring up an interface that shows my available mana pool, and then display how much mana is required to cast the spell.
In this case, you click on the Fire resource indicator, and the available mountain cost indicator shows a -1.
Would this bring the mana pool below 0? If so, prevent this.
Does the spell meet minimum mana costs? If so, make a note.
Allow players the add extra mana if needed.
Does the spell use extra mana? If so, make a note of this.
If all checks out, allow the spell to be cast by making a value available.

Player Has paid mana, and wishes to finalize the spell cast. Click a prompt to attempt to cast:
Is there enough mana?
Yes? Is there extra mana?
No? Pick target.
Deduct mana as indicated above for mana pools.
Target picked; Query other players for interrupt effects.
Does spell resolve? (IE; is it defeated on the stack?)
Spell resolved, so deal the effect. Remove the card from the stack.
Did not resolve? Remove it from the stack.
Clean up. Clean out the prompt box for spell casting.

End Phase
Is there mana in the mana pool?
Yes? How much?
Calculate the remains values left inside each of the mana type variables (IE, if > 0, then, etc)
Player is dealt that much damage for mana burn.

So in this case, you'd need the following values tracked:
blackmana
redmana
greenmana
bluemana
whitemana

This tracks your current mana values, and will go up/down as you track mana taps and costs.

Then, for spell casting:
blackcost
redcost
greencost
bluecost
whitecost
colorlesscost
blackused
redused
greenused
blueused
whiteused

This tracks the cost value of the spell queried for cost, and then the amount you're allocating. You'd just do a check of mana used, versus mana cost to confirm the spell requirements are met - and then again compare used to available totals, to make sure you have that much mana to begin with.

Then when you have X cost spells, you'd use the colorless cost.
In response to SeijiTataki
What I have so far:

mob
var
blackmana
bluemana
redmana
whitemana
greenmana
spentmana // How much they legally spend to play something


Let's say they need 1 mountain to play the card:

mob
verb
play_card_one_mountain()
if(redmana >= 1)
// Play the card
else
// You can't play the card!


Let's say you need 2 mountains and 1 colorless:

        play_card_two_mountain_one_colorless()
if(redmana >= 2 && blackmana >= 1 || whitemana >= 1 || greenmana >= 1 || bluemana >= 1 || redmana >= 3)
// Play the card
else
// Don't play the card!


And perhaps for mana burn:

proc
manaburn(var/mob/player)
var/usedmana = player.blackmana + player.bluemana + player.redmana + player.whitemana + player.greenmana
var/burn = usedmana - player.spentmana
player <<"You mana burn for [burn]."


I figured I'd post it for someone who actually does code.
Thank you for the suggestions, they've made it clear how I could code this. :)

Let's use a card for example:

        Play_Sage_Owl()
// The cost of Sage Owl is 1 Island and 1 Colorless!
if(bluemana >= 1 && blackmana >= 1 || whitemana >= 1 || greenmana >= 1 || redmana >= 1 || bluemana >= 2)
spentmana += 2 // They've spent 2 mana, legally. Do not burn them for this.
src <<"Sage Owl comes into play."
manaburn(src) // This usually doesn't happen in a real game, but we'll do it anyway for testing purposes.
else
src <<"You do not have enough lands tapped to play Sage Owl!"


Works for me!
I've tried no lands, two swamps, different lands and it works as expected and according to rule.
Mana burn works properly; I don't see any problems I might run in to, do you? I might need to transfer legimate spent mana to another variable so the player can only use the tapped mana once. :P
In response to Siientxx
In terms of magic the gathering, mana burn doesn't take effect unless you've ended your turn with extra mana in the pool.

As a result of this, you should actually check for mana burn when the player ends their turn, instead of each casting.

Because, for example, a strategic advantage of magic can be tapping more lands than is needed for a particular spell - that way your opponent doesn't know exactly how much mana your spell that's being cost actually costs.

You're also not tracking the mana used, which is why you've some concern about using a land more than once. Though, how you'd like to check for that is dependant on how you're setting up the actual card useage interface.
In response to Siientxx
Thats a very bad way to go about it. Make cards into datums, give them a costs list of some sort, and then make procedures to both count the amount of mana a player has and tap a specific amount of mana.