public Bataille() { YACE.YACEParameters parameters = new YACEParameters(); CardDefinition battailDefinition = new CardDefinition() { Name = "BatailleCard", }; parameters.ResourceDefinitions = new ResourceDefinition[] { new ResourceDefinition { Name = "Multiplier", BaseValue = 1, IsPlayerBound = true, MinValue = 1, }, new ResourceDefinition { Name = "Score", BaseValue = 0, IsPlayerBound = true, } }; parameters.ZoneDefinitions = new ZoneDefinition[] { new ZoneDefinition { Name = "MainDeck", IsPlayerBound = false, IsOrdered = false, }, new ZoneDefinition { Name = "PlayerHand", IsPlayerBound = true, IsOrdered = false, }, new ZoneDefinition { Name = "DiscardPile", }, }; yace = new YACE.YACE(parameters); CardInstance lastCard = null; for (int i = 0; i < 10; ++i) { CardInstance card = new CardInstance(battailDefinition); card.AddTag("Value", i + 1); yace.SetCardToZone(card, "MainDeck"); lastCard = card; } yace.ShuffleZone("MainDeck"); }
public void SetUp() { _cardDefinition = new CardDefinition() { CardType = CardType.Battlefield, }; }
/// <summary> /// Damage of other card against me. /// </summary> public double GetDamage(Card card) { CardDefinition def = card.definition; double value = 0; switch (definition.type.type) { case CardTypes.TYPE.RANGED: value = def.archerAttackDamage; break; case CardTypes.TYPE.FLYING: value = def.flyingAttackDamage; break; case CardTypes.TYPE.MELEE: value = def.meleeAttackDamage; break; default: break; } if (hasShield) { value *= definition.shieldReduction; } return(value); }
private List <Card> SpawnEnemyCards(BoardPlayer me, BoardPlayer enemy, CardDefinitionHolder[] cardHoldersToSpawn, GameObject[] spawnPoints, Vector3 offset) { List <Card> cards = new List <Card>(); for (int i = 0; i < cardHoldersToSpawn.Length; i++) { CardDefinition cardDefinition = cardHoldersToSpawn[i].CardDefinition; int index = cardHoldersToSpawn[i].Position; Card card = Summon(cardDefinition); card.owner = me; card.enemy = enemy; card.gameManager = GameManager; card.slotNumber = index; GameObject cardGO = card.gameObject; card.SpawnPointImage = spawnPoints[index].GetComponent <Image>(); cardGO.transform.SetParent(spawnPoints[index].transform, false); cardGO.transform.localPosition = offset; cards.Add(card); } return(cards); }
// public void Load(CardDefinition def) { this.def = def; // Meta duration = def.json["duration"].AsInt; try { shotType = (ShotType)Enum.Parse(typeof(ShotType), def.json["shotType"]); } catch { } try { cardType = (CardType)Enum.Parse(typeof(CardType), def.json["cardType"]); } catch { } // // Projectiles shotCount = def.json["shotCount"].AsInt; shotSpeed = def.json["projectileSpeed"].AsFloat; shotCountScalar = def.json["shotCountScalar"].AsFloat; shotCountModifier = def.json["shotCountModifier"].AsInt; shotFrequency = def.json["shotFrequency"].AsFloat; shotFrequencyScalar = def.json["shotFrequencyScalar"].AsFloat; shotFrequencyModifier = def.json["shotFrequencyModifier"].AsFloat; shotSpread = def.json["shotSpread"].AsFloat; shotSpreadScalar = def.json["shotSpreadScalar"].AsFloat; shotSpreadModifier = def.json["shotSpreadModifier"].AsFloat; // // Player Stats recieveDamageScalar = def.json["recieveDamageScalar"].AsFloat; receiveDamageModifier = def.json["receiveDamageModifier"].AsInt; }
public void Load(CardDefinition def) { definition = def; switch (definition.type) { case CardDefinition.TYPE.POWER: tabColor.color = UIManager.instance.powerPallet.primary; handleColor.color = UIManager.instance.powerPallet.primary; baseColor = UIManager.instance.powerPallet.primary; hueColor = UIManager.instance.powerPallet.hue; break; case CardDefinition.TYPE.MOVEMENT: tabColor.color = UIManager.instance.movementPallet.primary; handleColor.color = UIManager.instance.movementPallet.primary; baseColor = UIManager.instance.movementPallet.primary; hueColor = UIManager.instance.movementPallet.hue; break; case CardDefinition.TYPE.UTILITY: tabColor.color = UIManager.instance.utilityPallet.primary; handleColor.color = UIManager.instance.utilityPallet.primary; baseColor = UIManager.instance.utilityPallet.primary; hueColor = UIManager.instance.utilityPallet.hue; break; } SetSize(def.cost); }
internal void RemoveProjectile(CardDefinition def) { for (int i = projectileEffects.Count - 1; i >= 0; i--) { if (projectileEffects[i].Value == null) { projectileEffects.RemoveAt(i); continue; } if (projectileEffects[i].Value.def != def) { continue; } for (int obj = timeObjectList.Count - 1; obj >= 0; obj--) { if (timeObjectList[obj] == null) { timeObjectList.RemoveAt(obj); continue; } if (timeObjectList[obj].effect == projectileEffects[i].Value) { timeObjectList[obj].TotalCleanup(); } } projectileEffects.RemoveAt(i); } }
// Use this for initialization public List <Card> SpawnPlayerCards(BoardPlayer me, BoardPlayer enemy, CardDefinitionHolder[] cardHolders) { List <Card> cards = new List <Card>(); for (int i = 0; i < cardHolders.Length; i++) { CardDefinition cardDefinition = cardHolders[i].CardDefinition; Card card = Summon(cardDefinition); card.owner = me; card.enemy = enemy; card.gameManager = GameManager; card.slotNumber = i; card.SpawnPointImage = playerSpawnPoints[i].GetComponent <Image>(); GameObject cardGO = card.gameObject; cardGO.transform.SetParent(playerSpawnPoints[i].transform, false); cardGO.transform.localPosition = playerOffset; cards.Add(card); } return(cards); }
public void ReadDeck(string deckXMLText) { xmlr = new PT_XMLReader(); xmlr.Parse(deckXMLText); string s = "xml[0] decorator [0]"; s += "type=" + xmlr.xml["xml"][0]["decorator"][0].att("type"); s += "x=" + xmlr.xml["xml"][0]["decorator"][0].att("x"); s += "y=" + xmlr.xml["xml"][0]["decorator"][0].att("y"); s += "scale=" + xmlr.xml["xml"][0]["decorator"][0].att("scale"); //print (s); decorators = new List <Decorator>(); PT_XMLHashList xDecos = xmlr.xml["xml"][0]["decorator"]; Decorator deco; for (int i = 0; i < xDecos.Count; i++) { deco = new Decorator(); deco.type = xDecos[i].att("type"); deco.flip = (xDecos[i].att("flip") == "1"); deco.scale = float.Parse(xDecos[i].att("scale")); deco.loc.x = float.Parse(xDecos[i].att("x")); deco.loc.y = float.Parse(xDecos[i].att("y")); deco.loc.z = float.Parse(xDecos[i].att("z")); decorators.Add(deco); } cardDefs = new List <CardDefinition> (); PT_XMLHashList xCardDefs = xmlr.xml["xml"][0]["card"]; for (int i = 0; i < xCardDefs.Count; i++) { CardDefinition cDef = new CardDefinition(); cDef.rank = int.Parse(xCardDefs[i].att("rank")); PT_XMLHashList xPips = xCardDefs[i]["pip"]; if (xPips != null) { for (int j = 0; j < xPips.Count; j++) { deco = new Decorator(); deco.type = "pip"; deco.flip = (xPips[j].att("flip") == "1"); deco.loc.x = float.Parse(xPips[j].att("x")); deco.loc.y = float.Parse(xPips[j].att("y")); deco.loc.z = float.Parse(xPips[j].att("z")); if (xPips[j].HasAtt("scale")) { deco.scale = float.Parse(xPips[j].att("scale")); } cDef.pips.Add(deco); } } if (xCardDefs[i].HasAtt("face")) { cDef.face = xCardDefs[i].att("face"); } cardDefs.Add(cDef); } }
/*** 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); }
private void CmdPlayerPlaysCard(int cardID, bool playedByHost) { CardDefinition card = CardDefinition.GetCardDefinitionWithID(cardID); if (ServerSidePlayCard(card, playedByHost)) { RpcPlayerSuccessfullyPlaysCard(cardID, playedByHost); } }
public void Load(CardDefinition def) { definition = def; Navigation nav = selectable.navigation; nav.selectOnUp = UICenter.instance.selectable; selectable.navigation = nav; apply(); }
public static IEnumerator MoveBy(CardDefinition definition, Card card, Player player) { var count = GetIntParam(definition, card, "count", 0); if (count == 0) { yield break; } var allPlayers = GetIntParam(definition, card, "allPlayers", 0); if (allPlayers != 0) { FollowCamera.Push(Board.instance.ground); yield return(new WaitForCamera()); var game = GameController.instance; var routines = new UnityCoroutine[game.playersCount]; for (int i = 0; i < game.playersCount; ++i) { var currentPlayer = game.players[i]; routines[i] = new UnityCoroutine(currentPlayer.MoveBy(count)); currentPlayer.StartCoroutineEx(routines[i].Start()); while (routines[i].state != UnityCoroutine.CoroutineState.Finished) { yield return(null); //buggy all moving but just the first one get card effect from moving } } foreach (var routine in routines) { yield return(new WaitForRoutine(routine)); } FollowCamera.Pop(); } else { var playerIdx = GetIntParam(definition, card, "playerIdx", player.playerNumber); if (playerIdx < 0 || playerIdx >= GameController.instance.playersCount) { yield break; } var targetPlayer = GameController.instance.players[playerIdx]; FollowCamera.Push(targetPlayer); yield return(new WaitForCamera()); yield return(targetPlayer.MoveBy(count)); FollowCamera.Pop(); } }
private void OnGUI() { text = EditorGUILayout.TextArea(text); if (GUILayout.Button("Validate")) { json = JSON.Parse(text)["data"]; } bool valid = (json != null && json.IsArray); EditorGUI.BeginDisabledGroup(!valid); if (GUILayout.Button("Clear")) { cardList.Clear(); } GUILayout.Space(20f); if (GUILayout.Button("Process")) { DirectoryCheck(); Texture2D tex = new Texture2D(256, 256); Color[] color = tex.GetPixels(); for (int y = 0; y < tex.width; y++) { if (y > 42 && y < tex.width - 42) { continue; } for (int x = 0; x < tex.height; x++) { color[x + (y * tex.width)] = Color.black; } } tex.SetPixels(color); byte[] data = tex.EncodeToPNG(); for (int i = 0; i < json.Count; i++) { CardDefinition card = CreateInstance <CardDefinition>(); card.FromJSON(json[i]); AssetDatabase.CreateAsset(card, "Assets/CardDefinitions/" + card.assetName + ".asset"); if (!File.Exists(Application.dataPath + "/CardDefinitions/Resources/" + card.assetName + ".png")) { File.Create(Application.dataPath + "/CardDefinitions/Resources/" + card.assetName + ".png").Close(); File.WriteAllBytes(Application.dataPath + "/CardDefinitions/Resources/" + card.assetName + ".png", data); } } } GUILayout.Space(20f); for (int i = 0; i < cardList.Count; i++) { EditorGUILayout.LabelField(cardList[i].name); } EditorGUI.EndDisabledGroup(); }
internal static CardDefinition Create(Card card) { CardDefinition def = ScriptableObject.CreateInstance <CardDefinition>(); def.Initialize(card.definition); // TODO if upgraded, should be done directly by changing card definition // This might be redundant return(def); }
public void DisplayAllTest() { CardDefinition.Load(); var sb = new StringBuilder(); foreach (var c in CardDefinition.GetAll()) { sb.AppendLine(c.DisplayString()); } Console.WriteLine(sb.ToString()); }
public Character Build(CardDefinition card, int numberOfDice) { if (card.CardType != Domain.CardType.Character) { throw new Exception("Card is not a character."); } var character = new Character(card.Name, card.Faction, card.Affiliation, card.Health.Value, card.DieDefinition, card.IsUnique, card.Points.Value, card.ElitePoints); Enumerable.Range(1, numberOfDice).ToList().ForEach(i => { character.AddDie(); }); return(character); }
public Support Build(CardDefinition card) { if (card.CardType != Domain.CardType.Support) { throw new Exception("Card is not a support."); } var support = new Support(card.Name, card.Faction, card.Affiliation, card.Cost.Value, card.SubType, card.DieDefinition); //TODO - add behaviors return(support); }
public EventCard Build(CardDefinition card) { if (card.CardType != Domain.CardType.Event) { throw new Exception("Card is not an event."); } var @event = new EventCard(card.Name, card.Faction, card.Affiliation, card.Cost.Value); //TODO - add behaviors return(@event); }
public static IEnumerator ShowBoard(CardDefinition definition, Card card, Player player) { var time = GetIntParam(definition, card, "time", 5); FollowCamera.Push(Board.instance.ground); yield return(new WaitForCamera()); yield return(new WaitForSeconds(time)); FollowCamera.Pop(); }
public Battlefield Build(CardDefinition card) { if (card.CardType != Domain.CardType.Battlefield) { throw new Exception("Card is not a Battlefield."); } var battlefield = new Battlefield(card.Name); //TODO - add behaviors return(battlefield); }
private static string GetStringParam(CardDefinition definition, Card card, string key, string defaultValue = "") { var data = card.ReadData(key) as string; if (!string.IsNullOrEmpty(data)) { return(data); } return(definition.GetParameter(key, defaultValue)); }
public Upgrade Build(CardDefinition card) { if (card.CardType != Domain.CardType.Upgrade) { throw new Exception("Card is not an Upgrade."); } var upgrade = new Upgrade(card.Name, card.Faction, card.Affiliation, card.Cost.Value, card.SubType, card.DieDefinition); //TODO - add behaviors return(upgrade); }
public void SetUp() { _cardDefinition = new CardDefinition() { CardType = CardType.Event, Faction = Faction.Command, Cost = 4, SubType = SubType.Vehicle, Affiliation = Affiliation.Villian, HasDie = true, }; }
public static IEnumerator ModifyTurns(CardDefinition definition, Card card, Player player) { var playerIdx = GetIntParam(definition, card, "playerIdx", player.playerNumber); var count = GetIntParam(definition, card, "turns", 1); if (playerIdx >= 0 && playerIdx < GameController.instance.playersCount) { GameController.instance.players[playerIdx].numberOfTurns += count; } return(null); }
private Card SpawnCard(CardDefinition definition) { var rotation = transform.rotation * Quaternion.Euler(0, 0, 180); var position = transform.position + Vector3.up * 2; var newCardObj = Instantiate(cardPrefab, position, rotation); var newCard = newCardObj.GetComponent <Card>() ?? newCardObj.AddComponent <Card>(); newCard.deck = this; definition.ApplyDefinition(newCard); return(newCard); }
public void TimeLoadTest() { var maxLoadTime = TimeSpan.FromSeconds(1); using (new TimeTracker(t => { Console.WriteLine("CardDefinition.Load() took {0} to complete.", t); Assert.IsTrue(t < maxLoadTime); })) { CardDefinition.Load(); } }
public CardDefinition GetCardDefinition() { CardDefinition card = null; if (m_Cards.Count > 0) { int cardIndex = Random.Range(0, m_Cards.Count); card = m_Cards[cardIndex]; m_Cards.RemoveAt(cardIndex); } return(card); }
public void SetUp() { _cardDefinition = new CardDefinition() { CardType = CardType.Upgrade, Faction = Faction.Command, Cost = 2, SubType = SubType.Equipment, Affiliation = Affiliation.Villian, HasDie = true, DieDefinition = TestUtils.GetValidDieDefinition() }; }
internal static void CardTriggered(CardDefinition definition) { int slot = UIManager.skillManager.PlaceTab(definition, GameManager.instance.percentThroughTurn); if (slot == -1) { return; } CardEffect effect = new CardEffect(); effect.Load(definition); UIManager.CETurnManager.AddEffect(UISkillBar.SlotToGT(slot), effect); }
// ReadDeck parses the XML file passed to it into CardDefinitions public void ReadDeck(string deckXMLText) { xmlr = new PT_XMLReader(); // Create a new PT_XMLReader xmlr.Parse(deckXMLText); // Use that PT_XMLReader to parse DeckXML // This prints a test line to show you how xmlr can be used. // For more information read about XML in the Useful Concepts Appendix string s = "xml[0] decorator[0] "; s += "type=" + xmlr.xml["xml"][0]["decorator"][0].att("type"); s += " x=" + xmlr.xml["xml"][0]["decorator"][0].att("x"); s += " y=" + xmlr.xml["xml"][0]["decorator"][0].att("y"); s += " scale=" + xmlr.xml["xml"][0]["decorator"][0].att("scale"); //print(s); // Comment out this line, since we're done with the test // Read decorators for all Cards decorators = new List<Decorator>(); // Init the List of Decorators // Grab a PT_XMLHashList of all <decorator>s in the XML file PT_XMLHashList xDecos = xmlr.xml["xml"][0]["decorator"]; Decorator deco; for (int i = 0; i < xDecos.Count; i++) { // For each <decorator> in the XML deco = new Decorator(); // Make a new Decorator // Copy the attributes of the <decorator> to the Decorator deco.type = xDecos[i].att("type"); // Set the bool flip based on whether the text of the attribute is // "1" or something else. This is an atypical but perfectly fine // use of the == comparison operator. It will return a true or // false, which will be assigned to deco.flip. deco.flip = (xDecos[i].att("flip") == "1"); // floats need to be parsed from the attribute strings deco.scale = float.Parse(xDecos[i].att("scale")); // Vector3 loc initializes to [0,0,0], so we just need to modify it deco.loc.x = float.Parse(xDecos[i].att("x")); deco.loc.y = float.Parse(xDecos[i].att("y")); deco.loc.z = float.Parse(xDecos[i].att("z")); // Add the temporary deco to the List decorators decorators.Add(deco); } // Read pip locations for each card number cardDefs = new List<CardDefinition>(); // Init the List of Cards // Grab a PT_XMLHashList of all the <card>s in the XML file PT_XMLHashList xCardDefs = xmlr.xml["xml"][0]["card"]; for (int i = 0; i < xCardDefs.Count; i++) { // For each of the <card>s // Create a new CardDefinition CardDefinition cDef = new CardDefinition(); // Parse the attribute values and add them to cDef cDef.rank = int.Parse(xCardDefs[i].att("rank")); // Grab a PT_XMLHashList of all the <pip>s on this <card> PT_XMLHashList xPips = xCardDefs[i]["pip"]; if (xPips != null) { for (int j = 0; j < xPips.Count; j++) { // Iterate through all the <pip>s deco = new Decorator(); // <pip>s on the <card> are handled via the Decorator Class deco.type = "pip"; deco.flip = (xPips[j].att("flip") == "1"); deco.loc.x = float.Parse(xPips[j].att("x")); deco.loc.y = float.Parse(xPips[j].att("y")); deco.loc.z = float.Parse(xPips[j].att("z")); if (xPips[j].HasAtt("scale")) { deco.scale = float.Parse(xPips[j].att("scale")); } cDef.pips.Add(deco); } } // Face cards (Jack, Queen, & King) have a face attribute // cDef.face is the base name of the face card Sprite // e.g., FaceCard_11 is the base name for the Jack face Sprites // the Jack of Clubs is FaceCard_11C, hearts is FaceCard_11H, etc. if (xCardDefs[i].HasAtt("face")) { cDef.face = xCardDefs[i].att("face"); } cardDefs.Add(cDef); } }
public void ReadDeck(string deckXMLText) { xmlr = new PT_XMLReader(); xmlr.Parse(deckXMLText); string s = "xml[0] decorator[0] "; s += "type="+xmlr.xml["xml"][0]["decorator"][0].att ("type"); s += " x="+xmlr.xml["xml"][0]["decorator"][0].att ("x"); s += " y="+xmlr.xml["xml"][0]["decorator"][0].att ("y"); s += " scale="+xmlr.xml["xml"][0]["decorator"][0].att ("scale"); decorators = new List<Decorator>(); PT_XMLHashList xDecos = xmlr.xml["xml"][0]["decorator"]; Decorator deco; for (int i=0; i<xDecos.Count; i++) { deco = new Decorator(); deco.type = xDecos[i].att("type"); deco.flip = (xDecos[i].att ("flip") == "1"); deco.scale = float.Parse (xDecos[i].att ("scale")); deco.loc.x = float.Parse (xDecos[i].att ("x")); deco.loc.y = float.Parse (xDecos[i].att ("y")); deco.loc.z = float.Parse (xDecos[i].att ("z")); decorators.Add (deco); } cardDefs = new List<CardDefinition>(); PT_XMLHashList xCardDefs = xmlr.xml["xml"][0]["card"]; for (int i=0; i<xCardDefs.Count; i++){ CardDefinition cDef = new CardDefinition(); cDef.rank = int.Parse(xCardDefs[i].att ("rank")); PT_XMLHashList xPips = xCardDefs[i]["pip"]; if (xPips != null) { for (int j=0; j<xPips.Count; j++) { deco = new Decorator(); deco.type = "pip"; deco.flip = (xPips[j].att ("flip") == "1"); deco.loc.x = float.Parse(xPips[j].att ("x")); deco.loc.y = float.Parse(xPips[j].att ("y")); deco.loc.z = float.Parse(xPips[j].att ("z")); if (xPips[j].HasAtt("scale")){ deco.scale = float.Parse(xPips[j].att ("scale")); } cDef.pips.Add(deco); } } if (xCardDefs[i].HasAtt("face")) { cDef.face = xCardDefs[i].att ("face"); } cardDefs.Add(cDef); } }
//ReadDeck parses the XML file passed to it into CardDefinitions public void ReadDeck(string deckXMLText) { xmlr = new PT_XMLReader(); //Create a new PT_XMLReader xmlr.Parse(deckXMLText); //use that PT_XMLREeader to parse DeckXML //This prints a test line to show you how xmlr can be used string s = "xml[0] decorator[0] "; s += "type="+xmlr.xml["xml"][0]["decorator"][0].att ("type"); s += " x="+xmlr.xml["xml"][0]["decorator"][0].att ("x"); s += " y="+xmlr.xml["xml"][0]["decorator"][0].att ("y"); s += " scale="+xmlr.xml["xml"][0]["decorator"][0].att ("scale"); //print (s); //Read decorators for all Cards decorators = new List<Decorator>(); //Grab a PT_XMLHasList of all <decorators> in the XML file PT_XMLHashList xDecos = xmlr.xml["xml"][0]["decorator"]; Decorator deco; for (int i=0; i<xDecos.Count; i++) { deco = new Decorator(); //Make a new decorator //Copy the attributes of the <decorator> to the Decorator deco.type = xDecos[i].att("type"); //Set the bool flip based on whether the text of the attribute is "1" or //something else. This is an atypical but perfectly fine use of the == comparison //operator. It will return a true or false, which will be assigned to deco.flip deco.flip = (xDecos[i].att ("flip") == "1"); //floats need to be parsed from the attributes strings deco.scale = float.Parse (xDecos[i].att ("scale")); //Vector3 loc initalizes to [0,0,0], so we just need to modify it deco.loc.x = float.Parse (xDecos[i].att ("x")); deco.loc.y = float.Parse (xDecos[i].att ("y")); deco.loc.z = float.Parse (xDecos[i].att ("z")); //add the temp deco to the List decorators decorators.Add (deco); } //Read pip locations for each card number cardDefs = new List<CardDefinition>(); //init the list of cards //grab a PT_XMLHashList of all the <cards>s in the XML file PT_XMLHashList xCardDefs = xmlr.xml["xml"][0]["card"]; for (int i=0; i<xCardDefs.Count; i++){ //For each of the <card>s //Create a new CArdDefinition CardDefinition cDef = new CardDefinition(); //Parse the attribute values and add them to cDef cDef.rank = int.Parse(xCardDefs[i].att ("rank")); //Grab a PT_XMLHashList of all the <pip>s on this <card> PT_XMLHashList xPips = xCardDefs[i]["pip"]; if (xPips != null) { for (int j=0; j<xPips.Count; j++) { //Iterate through all the <pip>s deco = new Decorator(); //<pip>s on the card> are handled via the DEcorator Class deco.type = "pip"; deco.flip = (xPips[j].att ("flip") == "1"); deco.loc.x = float.Parse(xPips[j].att ("x")); deco.loc.y = float.Parse(xPips[j].att ("y")); deco.loc.z = float.Parse(xPips[j].att ("z")); if (xPips[j].HasAtt("scale")){ deco.scale = float.Parse(xPips[j].att ("scale")); } cDef.pips.Add(deco); } } //FAce cards have a face attribute //cDef.face is the base name of the face card Sprite //e.g. FAceCard_11 is the base name for the Jack face Sprites //the Jack of Clubs is FaceCard_11C, hearts is FaceCard_11H, etc. if (xCardDefs[i].HasAtt("face")) { cDef.face = xCardDefs[i].att ("face"); } cardDefs.Add(cDef); } }
// ReadDeck parses the XML file passed to it into Card Definitions public void ReadDeck(string deckXMLText) { xmlr = new PT_XMLReader (); xmlr.Parse (deckXMLText); // print a test line string s = "xml[0] decorator [0] "; s += "type=" + xmlr.xml ["xml"] [0] ["decorator"] [0].att ("type"); s += " x=" + xmlr.xml ["xml"] [0] ["decorator"] [0].att ("x"); s += " y=" + xmlr.xml ["xml"] [0] ["decorator"] [0].att ("y"); s += " scale=" + xmlr.xml ["xml"] [0] ["decorator"] [0].att ("scale"); print (s); //Read decorators for all cards // these are the small numbers/suits in the corners decorators = new List<Decorator>(); // grab all decorators from the XML file PT_XMLHashList xDecos = xmlr.xml["xml"][0]["decorator"]; Decorator deco; for (int i=0; i<xDecos.Count; i++) { // for each decorator in the XML, copy attributes and set up location and flip if needed deco = new Decorator(); deco.type = xDecos[i].att ("type"); deco.flip = (xDecos[i].att ("flip") == "1"); // too cute by half - if it's 1, set to 1, else set to 0 deco.scale = float.Parse (xDecos[i].att("scale")); deco.loc.x = float.Parse (xDecos[i].att("x")); deco.loc.y = float.Parse (xDecos[i].att("y")); deco.loc.z = float.Parse (xDecos[i].att("z")); decorators.Add (deco); } // read pip locations for each card rank // read the card definitions, parse attribute values for pips cardDefs = new List<CardDefinition>(); PT_XMLHashList xCardDefs = xmlr.xml["xml"][0]["card"]; for (int i=0; i<xCardDefs.Count; i++) { // for each carddef in the XML, copy attributes and set up in cDef CardDefinition cDef = new CardDefinition(); cDef.rank = int.Parse(xCardDefs[i].att("rank")); PT_XMLHashList xPips = xCardDefs[i]["pip"]; if (xPips != null) { for (int j = 0; j < xPips.Count; j++) { deco = new Decorator(); deco.type = "pip"; deco.flip = (xPips[j].att ("flip") == "1"); // too cute by half - if it's 1, set to 1, else set to 0 deco.loc.x = float.Parse (xPips[j].att("x")); deco.loc.y = float.Parse (xPips[j].att("y")); deco.loc.z = float.Parse (xPips[j].att("z")); if(xPips[j].HasAtt("scale") ) { deco.scale = float.Parse (xPips[j].att("scale")); } cDef.pips.Add (deco); } // for j }// if xPips // if it's a face card, map the proper sprite // foramt is ##A, where ## in 11, 12, 13 and A is letter indicating suit if (xCardDefs[i].HasAtt("face")){ cDef.face = xCardDefs[i].att ("face"); } cardDefs.Add (cDef); } // for i < xCardDefs.Count }
//ReadDeck parses the XML file passed to it into CardDefinitions public void ReadDeck(string deckXMLText) { xmlr = new PT_XMLReader(); //Create a new PT_XMLReader xmlr.Parse(deckXMLText); //Use that PT_XMLReader to parse DeckXML //This prints a test line to show you how xmlr can be used. //For more info read about XML in the Useful Concepts section of book string s = "xmlr.xml[0] decorator[0]"; s += "type="+xmlr.xml["xml"][0]["decorator"][0].att("type"); s += " x="+xmlr.xml["xml"][0]["decorator"][0].att("x"); s += " y="+xmlr.xml["xml"][0]["decorator"][0].att("y"); s += " scale="+xmlr.xml["xml"][0]["decorator"][0].att("scale"); //print(s); //Done with this test now //Read decorators for all Cards decorators = new List<Decorator>(); //Init the list of Decorator //Grab a PT_XMLHashList of all <decorator>s in the XML file PT_XMLHashList xDecos = xmlr.xml["xml"][0]["decorator"]; Decorator deco; for (int i=0; i<xDecos.Count; i++) { //For each decorator in the xml deco = new Decorator(); //Make new Decorator //Copy the attributes of the <decorator> to the Decorator deco.type = xDecos[i].att("type"); //Set the bool flip based on bwether the text of the attribute is //"1" or something else. This is an atypical but perfectly fine //use of the == comparison operator. It will return a true or //false, which will be assigned to deco.flip. deco.flip = (xDecos[i].att ("flip") == "1"); //floats need to be parsed from the attribute strings deco.scale = float.Parse(xDecos[i].att ("scale")); //Vector3 loc initializes to [0,0,0], so we just need to modify it deco.loc.x = float.Parse(xDecos[i].att ("x")); deco.loc.y = float.Parse(xDecos[i].att ("y")); deco.loc.z = float.Parse(xDecos[i].att ("z")); //Add the temporary deco to the list decorators decorators.Add (deco); } //Read pip locations for each card number cardDefs = new List<CardDefinition>(); //Init the list of cards //Grab a PT_XMLHashList of all the <card>s in the xml file PT_XMLHashList xCardDefs = xmlr.xml["xml"][0]["card"]; for (int i=0; i<xCardDefs.Count; i++) { //for each of the <card>s //create new CardDefinition CardDefinition cDef = new CardDefinition(); //parse the attribute values and add them to cDef cDef.rank = int.Parse(xCardDefs[i].att ("rank")); //Grab a PT_XMLHashList of all the <pip>s on this <card> PT_XMLHashList xPips = xCardDefs[i]["pip"]; if (xPips != null) { for (int j=0; j<xPips.Count; j++) { //Iterate through all of the <pip>s deco = new Decorator(); //<pip>s on the <card> are handled via the decorator class deco.type = "pip"; deco.flip = (xPips[j].att ("flip") == "1"); deco.loc.x = float.Parse(xPips[j].att ("x")); deco.loc.y = float.Parse(xPips[j].att ("y")); deco.loc.z = float.Parse(xPips[j].att ("z")); if (xPips[j].HasAtt("scale")) { deco.scale = float.Parse(xPips[j].att ("scale")); } cDef.pips.Add(deco); } } //Face cards (Jack, King, Queen) have a face attribute //cDef.face is the name of the face card Sprite //e.g., Jack of clubs is FaceCard_11c, hearts is FaceCard_11H, etc. if (xCardDefs[i].HasAtt("face")) { cDef.face = xCardDefs[i].att ("face"); } cardDefs.Add(cDef); } }
private CardDefinition completeCardWithLevelDependentValue(HtmlNode cardNode, CardDefinition cardToComplete) { HtmlDocument cardHtml = new HtmlDocument(); HtmlDocument cardDetailHtml = new HtmlDocument(); String Regexp; Match match; String matchResult; String creaturetype; String cardType; String cardtext; int lvlattack = 0; int lvlhealth = 0; int cardLevel = 0; cardHtml.LoadHtml((cardNode.InnerHtml.Replace("<br />", "").Replace("<br>", "").Replace("\t", ""))); cardHtml.DocumentNode.SelectNodes("//div[@class='mobiletrigger']"); cardDetailHtml.LoadHtml(cardHtml.DocumentNode.SelectNodes("//div[@class='mobiletrigger']")[0].InnerHtml); Regexp = "(Level ([1234]))"; match = Regex.Match(cardDetailHtml.DocumentNode.InnerHtml, Regexp); if (match.Success) { matchResult = match.Groups[2].Value; cardLevel = int.Parse(matchResult); } creaturetype = ""; cardtext = ""; Regexp = "((Creature)[ +]-[ +]([a-zA-Z. ,]+))"; match = Regex.Match(cardDetailHtml.DocumentNode.InnerHtml, Regexp); if (match.Success) { matchResult = match.Groups[3].Value; creaturetype = matchResult.Trim(); cardType = "Creature"; Regexp = "((" + creaturetype + ")([a-zA-Z1-9:.\\-\\+,' ]+))"; String html = @cardDetailHtml.DocumentNode.InnerHtml; String result = Regex.Replace(html.Replace("\r\n", "").Replace("\"", ""), @"<[^>]*>", String.Empty); match = Regex.Match(result, Regexp); if (match.Success) { matchResult = match.Groups[3].Value; cardtext = matchResult.Trim(); } } else { cardType = "Spell"; Regexp = "((Spell)([a-zA-Z1-9:.\\-\\+,' ]+))"; String html = @cardDetailHtml.DocumentNode.InnerHtml; String result = Regex.Replace(html.Replace("\r\n", "").Replace("\"", ""), @"<[^>]*>", String.Empty); match = Regex.Match(result, Regexp); if (match.Success) { matchResult = match.Groups[3].Value; cardtext = matchResult.Trim(); } } if (cardHtml.DocumentNode.SelectNodes("//div[@class='mobiletrigger']")[0].InnerText.Contains("Creature")) { lvlattack = int.Parse(cardHtml.DocumentNode.SelectNodes("//span[@class='ico attack']")[0].InnerText); lvlhealth = int.Parse(cardHtml.DocumentNode.SelectNodes("//span[@class='ico health']")[0].InnerText); } switch (cardLevel) { case 1: if (cardType == "Creature") { cardToComplete.Level1Attack = lvlattack; cardToComplete.Level1Health = lvlhealth; } cardToComplete.Level1Description = cardtext; break; case 2: if (cardType == "Creature") { cardToComplete.Level2Attack = lvlattack; cardToComplete.Level2Health = lvlhealth; } cardToComplete.Level2Description = cardtext; break; case 3: if (cardType == "Creature") { cardToComplete.Level3Attack = lvlattack; cardToComplete.Level3Health = lvlhealth; } cardToComplete.Level3Description = cardtext; break; case 4: if (cardType == "Creature") { cardToComplete.Level4Attack = lvlattack; cardToComplete.Level4Health = lvlhealth; } cardToComplete.Level4Description = cardtext; break; } return cardToComplete; }
public static void LoadDefinitionFromFile() { m_ListOfCards = new List<CardDefinition>(); String CardName; String ClassName; CardDefinition CurrCard; StreamReader reader; Assembly ass = Assembly.GetExecutingAssembly(); string path = System.IO.Path.GetDirectoryName(ass.Location); String pathDownloaded = Path.Combine(path, "CardDatabase"); if (File.Exists(Path.Combine(pathDownloaded, "DownloadedCardDatabase.csv"))) { reader = new StreamReader(File.OpenRead(Path.Combine(pathDownloaded, "DownloadedCardDatabase.csv"))); } else { reader = new StreamReader(File.OpenRead(Path.Combine(path, "CardDatabase.csv"))); } while (!reader.EndOfStream) { var line = reader.ReadLine(); var values = line.Split(';'); CardName = values[0]; ClassName = CardName.Replace(" ", "_").Replace("'", "_").Replace(",", "_").Replace(".", "_"); CurrCard = new CardDefinition(); try { var type = Type.GetType("Solforge_Helper.Cards." + ClassName); if (type != null) { CurrCard = (CardDefinition)Activator.CreateInstance(type); } } catch (Exception e) { MessageBoxResult result = MessageBox.Show(e.ToString() + " " + line); } if (values[3] == "Creature") { try { if (values[4] == "Forgeborn") { CurrCard.Initialize(values[0], values[1], values[2], values[3], values[4], Convert.ToInt32(DefaultValue(values[5],"0")), Convert.ToInt32(DefaultValue(values[6],"0")), Convert.ToInt32(DefaultValue(values[8],"0")), Convert.ToInt32(DefaultValue(values[9],"0")), Convert.ToInt32(DefaultValue(values[11],"0")), Convert.ToInt32(DefaultValue(values[12],"0")), Convert.ToInt32(DefaultValue(values[14],"0")), Convert.ToInt32(DefaultValue(values[15],"0"))); CurrCard.Level1Description = values[7]; CurrCard.Level2Description = values[10]; CurrCard.Level3Description = values[13]; CurrCard.Level4Description = values[16]; m_ListOfCards.Add(CurrCard); } else { CurrCard.Initialize(values[0], values[1], values[2], values[3], values[4], Convert.ToInt32(DefaultValue(values[5], "0")), Convert.ToInt32(DefaultValue(values[6],"0")), Convert.ToInt32(DefaultValue(values[8],"0")), Convert.ToInt32(DefaultValue(values[9],"0")), Convert.ToInt32(DefaultValue(values[11],"0")), Convert.ToInt32(DefaultValue(values[12],"0"))); CurrCard.Level1Description = values[7]; CurrCard.Level2Description = values[10]; CurrCard.Level3Description = values[13]; m_ListOfCards.Add(CurrCard); } } catch (Exception e) { MessageBoxResult result = MessageBox.Show(e.ToString() + " " + line); } } else { try { CurrCard.Initialize(values[0], values[1], values[2], values[3]); CurrCard.Level1Description = values[7]; CurrCard.Level2Description = values[10]; CurrCard.Level3Description = values[13]; m_ListOfCards.Add(CurrCard); } catch (Exception e) { MessageBoxResult result = MessageBox.Show(e.ToString() + " " + line); } } } reader.Close(); }
private CardDefinition ExtractCardFromHtml(HtmlNode cardNode) { HtmlDocument cardHtml = new HtmlDocument(); HtmlDocument cardDetailHtml = new HtmlDocument(); String Regexp; Match match; String matchResult; CardDefinition currCard; currCard = new CardDefinition(); String alternate; String cardName; String rarity; String faction; String creaturetype; String cardType; String cardtext; int lvlattack = 0; int lvlhealth = 0; int cardLevel = 0; cardHtml.LoadHtml((cardNode.InnerHtml.Replace("<br />", "").Replace("<br>", "").Replace("\t", ""))); cardHtml.DocumentNode.SelectNodes("//div[@class='mobiletrigger']"); cardDetailHtml.LoadHtml(cardHtml.DocumentNode.SelectNodes("//div[@class='mobiletrigger']")[0].InnerHtml); alternate = ""; cardtext = ""; rarity = ""; if (cardHtml.DocumentNode.SelectNodes("//span[@class='alternate_art']") != null) { alternate = cardHtml.DocumentNode.SelectNodes("//span[@class='alternate_art']")[0].InnerText; } cardName = cardHtml.DocumentNode.SelectNodes("//h6")[0].InnerText; if (alternate == "(Alternate Art)") { return null; } Regexp = "(Level ([1234]))"; match = Regex.Match(cardDetailHtml.DocumentNode.InnerHtml, Regexp); if (match.Success) { matchResult = match.Groups[2].Value; cardLevel = int.Parse(matchResult); } Regexp = "((Common)|(Legendary)|(Rare)|(Heroic))"; match = Regex.Match(cardDetailHtml.DocumentNode.InnerHtml, Regexp); if (match.Success) { matchResult = match.Groups[1].Value; rarity = matchResult; } faction = ""; Regexp = "((Tempys)|(Alloyin)|(Nekrium)|(Uterra))"; match = Regex.Match(cardDetailHtml.DocumentNode.InnerHtml, Regexp); if (match.Success) { matchResult = match.Groups[1].Value; faction = matchResult; } creaturetype = ""; Regexp = "((Creature)[ +]-[ +]([a-zA-Z. ,]+))"; match = Regex.Match(cardDetailHtml.DocumentNode.InnerHtml, Regexp); if (match.Success) { matchResult = match.Groups[3].Value; creaturetype = matchResult.Trim(); cardType = "Creature"; Regexp = "(("+creaturetype+")([a-zA-Z1-9:.\\-\\+,' ]+))"; String html = @cardDetailHtml.DocumentNode.InnerHtml; String result = Regex.Replace(html.Replace("\r\n", "").Replace("\"", ""), @"<[^>]*>", String.Empty); match = Regex.Match(result, Regexp); if (match.Success) { matchResult = match.Groups[3].Value; cardtext = matchResult.Trim(); } } else { cardType = "Spell"; Regexp = "((Spell)([a-zA-Z1-9:.\\-\\+,' ]+))"; String html = @cardDetailHtml.DocumentNode.InnerHtml; String result = Regex.Replace(html.Replace("\r\n", "").Replace("\"", ""), @"<[^>]*>", String.Empty); match = Regex.Match(result, Regexp); if (match.Success) { matchResult = match.Groups[3].Value; cardtext = matchResult.Trim(); } } if (cardHtml.DocumentNode.SelectNodes("//div[@class='mobiletrigger']")[0].InnerText.Contains("Creature")) { lvlattack = int.Parse(cardHtml.DocumentNode.SelectNodes("//span[@class='ico attack']")[0].InnerText); lvlhealth = int.Parse(cardHtml.DocumentNode.SelectNodes("//span[@class='ico health']")[0].InnerText); } currCard.CardType = cardType; currCard.Name = cardName.Trim(); currCard.Faction = faction; currCard.CreatureType = creaturetype; currCard.Rarity = rarity; switch (cardLevel) { case 1: if (cardType == "Creature") { currCard.Level1Attack = lvlattack; currCard.Level1Health = lvlhealth; } currCard.Level1Description = cardtext; break; case 2: if (cardType == "Creature") { currCard.Level2Attack = lvlattack; currCard.Level2Health = lvlhealth; } currCard.Level2Description = cardtext; break; case 3: if (cardType == "Creature") { currCard.Level3Attack = lvlattack; currCard.Level3Health = lvlhealth; } currCard.Level3Description = cardtext; break; case 4: if (cardType == "Creature") { currCard.Level4Attack = lvlattack; currCard.Level4Health = lvlhealth; } currCard.Level4Description = cardtext; break; } return currCard; }