/*** Server Side Actions ***/ private bool ServerSidePlayCard(CardDefinition cardDefinition, bool playedByHost) { if (!isServer) { Debug.LogError("Server side play card ran on not the server."); return(false); } if (cardDefinition is ResourceCardDefinition) { Debug.Log("Player playing a resource card."); if (hasPlayedAResourceThisTurn) { Debug.Log("Player has already played a resource card this turn."); return(false); } maxResourcesPerTurn += ((ResourceCardDefinition)cardDefinition).ResourcesGiven; currentResources += ((ResourceCardDefinition)cardDefinition).ResourcesGiven; hasPlayedAResourceThisTurn = true; } else if (cardDefinition is SpellCardDefinition) { SpellCardDefinition spellCard = (SpellCardDefinition)cardDefinition; if (spellCard.ManaCost > currentResources) { Debug.Log("Player doesn't have enough resources (current = " + currentResources.ToString() + ") to cast that spell with cost: " + spellCard.ManaCost.ToString()); return(false); } currentResources -= spellCard.ManaCost; if (cardDefinition is CreatureCardDefinition) { Debug.Log("Player playing a creature card."); NetworkedGameManager.SingletonGameManager.PlayCreature((CreatureCardDefinition)cardDefinition, playedByHost); } else { Debug.Log("Player playing a spell card."); NetworkedGameManager.SingletonGameManager.PlaySpell((SpellCardDefinition)cardDefinition, playedByHost); } } if (isLocalPlayer) { LocalSideRemovedPlayedCardFromHand(); } else { RpcRemovePlayedCardFromHand(); } RpcPlayerSuccessfullyPlaysCard(cardDefinition.CardID, playedByHost); return(true); }
public void PlaySpell(SpellCardDefinition spellCardDefinition, bool playedByLocalPlayer) { Debug.Log("Executing effects of spell card: " + spellCardDefinition.CardName); //TODO if (playedByLocalPlayer) { opponentPlayer.ChangeLifeTotal(-10); } else { localPlayer.ChangeLifeTotal(-10); } }
public SpellCard(SpellCardDefinition spellCardDefinition) { baseDefinition = spellCardDefinition; }
//initialze the list of cards private void InitializeCardDatabase() { Debug.Log("Initialize cards database."); string XMLLocale = Path.Combine(Application.dataPath, "CardsWithAIData.xml"); XNamespace nameSpace = "http://example.com/Cards"; try { XDocument xmlDoc = XDocument.Load(XMLLocale); //get resource cards from file IEnumerable <XElement> resources = from item in xmlDoc.Root.Descendants(nameSpace + "Card") where item.Attribute("type").Value == "resource" select item; foreach (XElement resource in resources) { string resourceCardName = resource.Attribute("name").Value; int resourceValue = int.Parse(resource.Element(nameSpace + "resources").Value); int thresholdType = int.Parse(resource.Element(nameSpace + "threshold").Value); new ResourceCardDefinition(resourceCardName, resourceValue, thresholdType); Debug.Log("Loaded a resource card: " + resourceCardName + ", " + resourceValue.ToString() + ", " + thresholdType.ToString()); } //get spell cards IEnumerable <XElement> spells = from item in xmlDoc.Root.Descendants(nameSpace + "Card") where item.Attribute("type").Value == "spell" select item; foreach (XElement spell in spells) { string spellCardName = spell.Attribute("name").Value; int spellCost = int.Parse(spell.Element(nameSpace + "cost").Value); string spellText = spell.Element(nameSpace + "text").Value; float cardStrength = float.Parse(spell.Attribute("strength").Value); IEnumerable <XElement> effects = from item in spell.Descendants(nameSpace + "Card") select item; Dictionary <SpellEffect, int[]> spellEffects = new Dictionary <SpellEffect, int[]>(); foreach (XElement effect in effects) { string code = effect.Attribute("code").Value; SpellEffect spellEffect = SpellCardDefinition.StringToSpellEffect(code); IEnumerable <XElement> variables = from item in effect.Descendants(nameSpace + "variable") select item; List <int> variableValues = new List <int>(); foreach (XElement variable in variables) { variableValues.Add(int.Parse(variable.Value)); } spellEffects.Add(spellEffect, variableValues.ToArray()); } new SpellCardDefinition(spellCardName, spellCost, spellText, spellEffects, cardStrength); Debug.Log("Loaded a spell card: " + spellCardName + ", " + spellCost.ToString() + ", " + spellText); } //get creature cards IEnumerable <XElement> creatures = from item in xmlDoc.Root.Descendants(nameSpace + "Card") where item.Attribute("type").Value == "creature" select item; foreach (XElement creature in creatures) { string creatureCardName = creature.Attribute("name").Value; float cardStrength = float.Parse(creature.Attribute("strength").Value); int creatureCost = int.Parse(creature.Element(nameSpace + "cost").Value); int creaturePower = int.Parse(creature.Element(nameSpace + "power").Value); int creatureToughness = int.Parse(creature.Element(nameSpace + "toughness").Value); string creatureText = creature.Element(nameSpace + "text").Value; new CreatureCardDefinition(creatureCardName, creatureCost, creatureText, creaturePower, creatureToughness, cardStrength); Debug.Log("Loaded a creature card: " + creatureCardName + ", " + creatureCost.ToString() + ", " + creaturePower.ToString() + ", " + creatureToughness.ToString() + ", " + creatureText); } } catch (XmlException ex) { Debug.LogError("Could not load card game data."); Debug.LogError(ex.StackTrace); return; } }