public static Card ToUp(this DbCard dbCard) { return(new Card { Id = dbCard.Id, Name = dbCard.Name }); }
public ICard GetNewCard(int id) { using (SqlCeCommand cmd = MSSQLCEConn.CreateCommand(Parent.CurrentUser)) { cmd.CommandText = "INSERT INTO \"Cards\"(settings_id) VALUES (@sid); SELECT @@IDENTITY;"; cmd.Parameters.Add("@sid", MsSqlCeSettingsConnector.CreateNewSettings(Parent)); ICard card = new DbCard(Convert.ToInt32(MSSQLCEConn.ExecuteScalar(cmd)), false, Parent); List <ICard> cardsCache = Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.GetIdentifier(CacheObject.CardsList, id)] as List <ICard>; if (cardsCache != null) { cardsCache.Add(card); } return(card); } }
public async Task <bool> AddTopic(TopicUpsertion topicUpsertion, string loggedUser) { try { var currentUser = _userDbContext.NotesUsers.Where(z => z.Email == loggedUser) .Include(x => x.Topics).SingleOrDefault(); if (currentUser.Topics == null) { currentUser.Topics = new List <DbTopic>(); } var existingTopicCount = currentUser.Topics.Where(x => x.Name == topicUpsertion.Name).Count(); if (existingTopicCount == 0) { DbTopic dbTopic = new DbTopic(); dbTopic.Name = topicUpsertion.Name; dbTopic.Tag = topicUpsertion.Tag; if (dbTopic.Cards == null) { dbTopic.Cards = new List <DbCard>(); } foreach (Card card in topicUpsertion.Cards) { DbCard dbCard = new DbCard(); dbCard.Content = card.Content; dbCard.Index = card.Index; dbTopic.Cards.Add(dbCard); } currentUser.Topics.Add(dbTopic); await _userDbContext.SaveChangesAsync(); return(true); } return(false); } catch (Exception ex) { return(false); } }
public async Task <DbCard> CardAddAsync(DbCard card) { DbCard addedCard = new DbCard(); if (card != null) { try { addedCard = (await _context.Cards.AddAsync(card).ConfigureAwait(false)).Entity; _context.SaveChanges(); } catch { throw; } } return(addedCard); }
public ICard GetNewCard(int id) { using (NpgsqlConnection con = PostgreSQLConn.CreateConnection(Parent.CurrentUser)) { using (NpgsqlCommand cmd = con.CreateCommand()) { cmd.CommandText = "INSERT INTO \"Cards\" VALUES (default) RETURNING id;"; ICard card = new DbCard(Convert.ToInt32(PostgreSQLConn.ExecuteScalar(cmd, Parent.CurrentUser)), false, Parent); List <ICard> cardsCache = Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.GetIdentifier(CacheObject.CardsList, id)] as List <ICard>; if (cardsCache != null) { cardsCache.Add(card); } return(card); } } }
public async Task <bool> UpdateTopic(TopicUpsertion topicUpsertion, string currentLoggedUser) { try { var selectedTopic = _userDbContext.Topics.Where(x => x.Name == topicUpsertion.Name).Include(y => y.Cards).SingleOrDefault(); if (selectedTopic == null) { return(false); } selectedTopic.Name = topicUpsertion.Name; selectedTopic.Tag = topicUpsertion.Tag; if (selectedTopic.Cards == null) { selectedTopic.Cards = new List <DbCard>(); } foreach (Card card in topicUpsertion.Cards) { var currentCard = selectedTopic.Cards.Where(x => x.Index == card.Index).SingleOrDefault(); if (currentCard == null) { currentCard = new DbCard(); } currentCard.Content = card.Content; currentCard.Index = card.Index; } selectedTopic.Cards.RemoveAll(x => !topicUpsertion.Cards.Any(z => z.Index == x.Index)); await _userDbContext.SaveChangesAsync(); return(true); } catch (Exception ex) { return(false); } }
static void Main(string[] args) { var coll = new ServiceCollection(); coll.AddLogging(b => b.AddConsole()); var provider = coll.BuildServiceProvider(); var opt = new DbContextOptionsBuilder <CardContext>().UseMySql("server=localhost;port=3306;user=root;password=root;database=cardgame", x => x.ServerVersion("5.5.55-mysql")) .UseLoggerFactory((ILoggerFactory)provider.GetService(typeof(ILoggerFactory))); var p = new CardContext(opt.Options); var card = new DbCard { Name = "FatLooser" }; p.Cards.Add(card); p.SaveChanges(); var query = p.Cards.ToList(); foreach (var q in query) { Console.WriteLine($"{q.Name} : {q.Id}"); } }
public ICard GetNewCard(int id) { using (SqlCeCommand cmd = MSSQLCEConn.CreateCommand(Parent.CurrentUser)) { cmd.CommandText = "INSERT INTO \"Cards\"(settings_id) VALUES (@sid); SELECT @@IDENTITY;"; cmd.Parameters.Add("@sid", MsSqlCeSettingsConnector.CreateNewSettings(Parent)); ICard card = new DbCard(Convert.ToInt32(MSSQLCEConn.ExecuteScalar(cmd)), false, Parent); List<ICard> cardsCache = Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.GetIdentifier(CacheObject.CardsList, id)] as List<ICard>; if (cardsCache != null) cardsCache.Add(card); return card; } }
public ICard GetNewCard(int id) { using (NpgsqlConnection con = PostgreSQLConn.CreateConnection(Parent.CurrentUser)) { using (NpgsqlCommand cmd = con.CreateCommand()) { cmd.CommandText = "INSERT INTO \"Cards\" VALUES (default) RETURNING id;"; ICard card = new DbCard(Convert.ToInt32(PostgreSQLConn.ExecuteScalar(cmd, Parent.CurrentUser)), false, Parent); List<ICard> cardsCache = Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.GetIdentifier(CacheObject.CardsList, id)] as List<ICard>; if (cardsCache != null) cardsCache.Add(card); return card; } } }
public bool DrawCard(DbCard c ) { string typestring=""; for (int i = 0; i < cardtypeints.Length; i++) { if (c.type == cardtypeints[i]) typestring = cardtypenames[i]; } GUILayout.Label(typestring,GUILayout.Width(100)); return GUILayout.Button("Delete",GUILayout.Width(100)); }
public IndexModel(DbCard DbCard, IConfiguration Configuration) { _myDbCard = DbCard; _myConfiguration = Configuration; }
void WriteCard(StreamWriter writer, DbCard dbcard) { writer.Write ("<card "); Debug.Log ("dbcard name:" + dbcard.name); if (dbcard.id!=-1) writer.Write ("id={0} ", dbcard.id); if (dbcard.art!=null) writer.Write ("art={0} ", dbcard.art.ToString()); if (dbcard.name!="") writer.Write ("name=\"{0}\" ", dbcard.name); if (dbcard.type!=-1) writer.Write ("type={0} ", dbcard.type); // if (dbcard.color!=-1) writer.Write ("color={0} ", dbcard.color); // foreach (string m_name in dbcard.CustomInts.Keys) // writer.Write ("ci_{0}={1}", m_name, dbcard.CustomInts[m_name]); // foreach (string m_name in dbcard.CustomStrings.Keys) // writer.Write ("cs_{0}={1}", m_name, dbcard.CustomStrings[m_name]); // if (dbcard.cost!=-1) writer.Write ("cost={0} ", dbcard.cost); if (dbcard.discardcost!=-1) writer.Write ("discardcost={0} ", dbcard.discardcost); if (dbcard.text!="") writer.Write ("text=\"{0}\" ", dbcard.text); if (dbcard.type == 1) { if (dbcard.level!=-1) writer.Write ("level={0} ", dbcard.level); if (dbcard.growid!="") writer.Write ("growid=\"{0}\" ", dbcard.growid); if (dbcard.offense!=-1) writer.Write ("attack={0} ", dbcard.offense); if (dbcard.defense!=-1) writer.Write ("defense={0} ", dbcard.defense); } int i = 0; foreach (Effect effect in dbcard.effects) { WriteEffect(writer,effect, i); i++; } writer.Write ("/> \n"); //end of line }
List<DbCard> ReadFile(string fileName) { StreamReader sr = new StreamReader(fileName); string fileContents = sr.ReadToEnd(); sr.Close(); List<DbCard> output = new List<DbCard>(); int eot; string[] stringSeparators = new string[] {"<card"}; string[] lines = fileContents.Split(stringSeparators, System.StringSplitOptions.None); Debug.Log("lines length:"+lines.Length); int i = 0; string line = ""; int j; for (j = 1; j < lines.Count(); j++) { line = lines[j]; if (Regex.Match(line, "(?<=name=\")[a-zA-Z0-9 ]+").ToString()!="" || Regex.Match(line, "(?<=type=)[0-9]+").ToString()!="" || Regex.Match(line, "(?<=art=\")[a-zA-Z0-9 ]+").ToString()!="") { DbCard newcard = new DbCard(); newcard.effects = new List<Effect>(); if (Regex.Match(line, "(?<=name=\")[a-zA-Z0-9 ]+").ToString()!="") newcard.name = Regex.Match(line, "(?<=name=\")[a-zA-Z0-9 ]+").ToString(); if (Regex.Match(line, "(?<=text=\")[-a-zA-Z0-9,/:\n ]+").ToString()!="") newcard.text = Regex.Match(line, "(?<=text=\")[-a-zA-Z0-9,/:\n ]+").ToString(); if (Regex.Match(line, "(?<=type=)[0-9]+").ToString()!="") System.Int32.TryParse(Regex.Match(line, "(?<=type=)[0-9]+").ToString(), out newcard.type); // if (Regex.Match(line, "(?<=color=)[0-9]+").ToString()!="") System.Int32.TryParse(Regex.Match(line, "(?<=color=)[0-9]+").ToString(), out newcard.color); // if (Regex.Match(line, "(?<=art=\")[a-zA-Z0-9 ]+").ToString()!="") newcard.art = Regex.Match(line, "(?<=art=\")[a-zA-Z0-9 ]+").ToString(); newcard.id = output.Count; // if (Regex.Match(line, "(?<=cost=)[0-9]+").ToString()!="") System.Int32.TryParse(Regex.Match(line, "(?<=cost=)[0-9]+").ToString(), out newcard.cost); if (Regex.Match(line, "(?<=discardcost=)[0-9]+").ToString()!="") System.Int32.TryParse(Regex.Match(line, "(?<=discardcost=)[0-9]+").ToString(), out newcard.discardcost); Debug.Log (line); output.Add(newcard); if (newcard.type == 1) { //if it's a creature if (Regex.Match(line, "(?<=growid=\")[a-zA-Z0-9 ]+").ToString()!="") newcard.growid = Regex.Match(line, "(?<=growid=\")[a-zA-Z0-9 ]+").ToString(); if (Regex.Match(line, "(?<=level=)[0-9]+").ToString()!="") System.Int32.TryParse(Regex.Match(line, "(?<=level=)[0-9]+").ToString(), out newcard.level); if (Regex.Match(line, "(?<=attack=)[0-9]+").ToString()!="") System.Int32.TryParse(Regex.Match(line, "(?<=attack=)[0-9]+").ToString(), out newcard.offense); if (Regex.Match(line, "(?<=defense=)[0-9]+").ToString()!="") System.Int32.TryParse(Regex.Match(line, "(?<=defense=)[0-9]+").ToString(), out newcard.defense); } for (i = 0; i<10; i++) { Effect foundeffect = new Effect(newcard.type == 1); eot = -1; if (Regex.Match(line, "(?<=effect"+i+"=)[0-9]+").ToString() !="" ) { System.Int32.TryParse(Regex.Match(line, "(?<=effect"+i+"=)[0-9]+").ToString(), out foundeffect.type); Debug.Log("eot:" +foundeffect.eot); if (Regex.Match(line, "(?<=param"+i+"_0=)[0-9]+").ToString() != "") System.Int32.TryParse(Regex.Match(line, "(?<=param"+i+"_0=)[0-9]+").ToString(), out foundeffect.param0); if (Regex.Match(line, "(?<=param"+i+"_1=)[0-9]+").ToString() != "") System.Int32.TryParse(Regex.Match(line, "(?<=param"+i+"_1=)[0-9]+").ToString(), out foundeffect.param1); // if (Regex.Match(line, "(?<=cost"+i+"=)[0-9]+").ToString() != "") System.Int32.TryParse(Regex.Match(line, "(?<=cost"+i+"=)[0-9]+").ToString(), out foundeffect.cost); if (Regex.Match(line, "(?<=discardcost"+i+"=)[0-9]+").ToString() != "") System.Int32.TryParse(Regex.Match(line, "(?<=discardcost"+i+"=)[0-9]+").ToString(), out foundeffect.discardcost); if (Regex.Match(line, "(?<=target"+i+"=)[0-9]+").ToString() != "") System.Int32.TryParse(Regex.Match(line, "(?<=target"+i+"=)[0-9]+").ToString(), out foundeffect.target); if (Regex.Match(line, "(?<=target"+i+"param0=)[0-9]+").ToString() != "") System.Int32.TryParse(Regex.Match(line, "(?<=target"+i+"param0=)[0-9]+").ToString(), out foundeffect.targetparam0); if (Regex.Match(line, "(?<=target"+i+"param1=)[0-9]+").ToString() != "") System.Int32.TryParse(Regex.Match(line, "(?<=target"+i+"param1=)[0-9]+").ToString(), out foundeffect.targetparam1); if (Regex.Match(line, "(?<=bufftype"+i+"=)[0-9]+").ToString() != "") System.Int32.TryParse(Regex.Match(line, "(?<=bufftype"+i+"=)[0-9]+").ToString(), out foundeffect.bufftype); if (Regex.Match(line, "(?<=eot"+i+"=)[0-9]+").ToString() != "") System.Int32.TryParse(Regex.Match(line, "(?<=eot"+i+"=)[0-9]+").ToString(), out eot); if (eot == 1) foundeffect.eot = true; if (Regex.Match(line, "(?<=trigger"+i+"=)[0-9]+").ToString() != "") System.Int32.TryParse(Regex.Match(line, "(?<=trigger"+i+"=)[0-9]+").ToString(), out foundeffect.trigger); Debug.Log("eot after parse:" +foundeffect.eot); newcard.effects.Add(foundeffect); } else break; //if there's no next effect, stop reading effects } } } return output; }
public bool ViewCard(DbCard c) { int type = c.type; c.name = EditorGUILayout.TextField("Name:", c.name, GUILayout.MaxWidth(500)); GUILayout.BeginHorizontal(); int temptype = EditorGUILayout.IntPopup("Type: ", c.type, cardtypenames, cardtypeints, GUILayout.Width(300)); if (temptype != c.type) //if the type has been changed c.effects.Clear (); c.type = temptype; if (c.type == 1) { tempsubtype = c.subtype+1; //-1 becomes 0 tempsubtype = EditorGUILayout.IntPopup("Subtype: ", tempsubtype, subtypenamesnone, subtypeintsnone, GUILayout.Width(300)); c.subtype = tempsubtype-1; //0 ("none") becomes -1 } GUILayout.EndHorizontal(); if (colornames != null) //we allow to choose a color even if we don't use mana colors: for aestetic purposes: card frames, etc { if (c.color == null) c.color = MainMenu.TCGMaker.core.colors[0]; color_int = 0; for (int i=0; i<colornames.Length; i++) if (colornames[i] == c.color.name) color_int = colorints[i]; //if (MainMenu.TCGMaker.core.colors.Contains(c.color)) color_int = MainMenu.TCGMaker.core.colors.IndexOf(c.color); color_int = EditorGUILayout.IntPopup("Color: ", color_int, colornames, colorints, GUILayout.Width(300)); c.color = MainMenu.TCGMaker.core.colors[color_int]; } foreach (CustomStat customstat in MainMenu.TCGMaker.stats.CustomInts) { //we can't serialize dictionaries so going to use linq.. CustomInt intstat = c.CustomInts.Where(x => x.h_name == customstat.h_name).SingleOrDefault(); if (intstat == null) { intstat = new CustomInt(customstat.h_name); c.CustomInts.Add(intstat); } intstat.value = EditorGUILayout.IntField (customstat.h_name+": ", intstat.value); } foreach (CustomStat customstat in MainMenu.TCGMaker.stats.CustomStrings) { //we can't serialize dictionaries so going to use linq.. CustomString stringstat = c.CustomStrings.Where(x => x.h_name == customstat.h_name).SingleOrDefault(); if (stringstat == null) { stringstat = new CustomString(customstat.h_name); c.CustomStrings.Add(stringstat); } stringstat.value = EditorGUILayout.TextField (customstat.h_name+": ", stringstat.value); } if (type != 0) { GUILayout.BeginHorizontal (); if (MainMenu.TCGMaker.core.UseManaColors) { GUILayout.Label("Cost: "); if (c.cost.Count == 0) GUILayout.Label("<none>"); ManaColor color_to_delete = null; foreach (ManaColor foundcolor in c.cost) { GUILayout.BeginHorizontal (); if (foundcolor.icon) //if there is an icon, display it { if (!foundcolor.icon_texture) foundcolor.icon_texture = SpriteToTexture(foundcolor.icon); GUILayout.Label (foundcolor.icon_texture, GUILayout.Width(25), GUILayout.Height(25)); } else GUILayout.Label(foundcolor.name); if (GUILayout.Button("X")) color_to_delete = foundcolor; GUILayout.EndHorizontal (); } if (color_to_delete != null) c.cost.Remove(color_to_delete); GUILayout.BeginHorizontal (); mana_type = EditorGUILayout.IntPopup(mana_type, colornames, colorints); if (GUILayout.Button("Add cost")) c.cost.Add(MainMenu.TCGMaker.core.colors[mana_type]); GUILayout.EndHorizontal (); } else { cost_int = c.cost.Count; cost_int = EditorGUILayout.IntField ("Cost: ", cost_int); if (c.cost.Count != cost_int) { c.cost.Clear(); for (int i=0; i< cost_int; i++) c.cost.Add(MainMenu.TCGMaker.core.colors[0]); //add 1 colorless mana to cost } } bool has_discard_cost = (c.discardcost > 0)? true : false; GUILayout.EndHorizontal (); GUILayout.BeginHorizontal (); GUILayout.Label("Has a discard cost: "); has_discard_cost = EditorGUILayout.Toggle(has_discard_cost); if (has_discard_cost && c.discardcost == -1) c.discardcost = 1; if (!has_discard_cost) c.discardcost = -1; if (c.discardcost > 0) c.discardcost = EditorGUILayout.IntField ("Cards to discard: ", c.discardcost); else c.discardcost = -1; GUILayout.EndHorizontal (); } if (type == 1) { //if it's a creature c.hero = EditorGUILayout.Toggle("Is a hero:", c.hero); c.ranged = EditorGUILayout.Toggle("Ranged:", c.ranged); GUILayout.BeginHorizontal (); c.offense = EditorGUILayout.IntField ("Offense: ", c.offense); c.defense = EditorGUILayout.IntField ("Defense: ", c.defense); GUILayout.EndHorizontal (); GUI.skin.label.fontStyle = FontStyle.Bold; GUILayout.BeginHorizontal (); GUILayout.Label("Specials:"); GUILayout.EndHorizontal(); GUI.skin.label.fontStyle = FontStyle.Normal; GUILayout.BeginVertical ("box",GUILayout.Width(600)); GUILayout.BeginHorizontal (); c.cant_attack = EditorGUILayout.Toggle("Can't attack:", c.cant_attack); c.takes_no_combat_dmg = EditorGUILayout.Toggle("Takes no combat damage:", c.takes_no_combat_dmg); c.deals_no_combat_dmg = EditorGUILayout.Toggle("Deals no combat damage:", c.deals_no_combat_dmg); GUILayout.EndHorizontal (); GUILayout.BeginHorizontal (); c.no_first_turn_sickness = EditorGUILayout.Toggle("No first turn sickness:", c.no_first_turn_sickness); if (MainMenu.TCGMaker.core.UseGrid) c.extramovement = EditorGUILayout.Toggle("Extra movement:", c.extramovement); c.free_attack = EditorGUILayout.Toggle("First attack doesn't turn:", c.free_attack); GUILayout.EndHorizontal (); GUILayout.BeginHorizontal (); c.less_dmg_from_ranged = EditorGUILayout.Toggle("Less damage from ranged:", c.less_dmg_from_ranged); c.no_dmg_from_ranged = EditorGUILayout.Toggle("No damage from ranged:", c.no_dmg_from_ranged); c.takes_no_spell_dmg = EditorGUILayout.Toggle("No damage from spells:", c.takes_no_spell_dmg); GUILayout.EndHorizontal (); GUILayout.EndVertical(); GUILayout.BeginHorizontal (); c.growid = EditorGUILayout.TextField("Upgrade ID:", c.growid, GUILayout.MaxWidth(500)); if (c.growid != "") c.level = EditorGUILayout.IntField ("Level: ", c.level); GUILayout.EndHorizontal (); foreach (Effect foundeffect in c.effects) foundeffect.creatureability = true; } else if (type == 3 || type == 4 || type == 0) { foreach (Effect foundeffect in c.effects) foundeffect.hastrigger = true; //enchantments, lands and secrets } GUILayout.BeginHorizontal(); c.art = EditorGUILayout.ObjectField ("Art:",c.art, typeof(Sprite), false) as Sprite; GUILayout.EndHorizontal(); if (c.art != null) GUILayout.Label (SpriteToTexture (c.art)); GUILayout.BeginHorizontal(); GUILayout.Label("Text:"); c.text = EditorGUILayout.TextArea(c.text); if (c.effects.Count > 0 && GUILayout.Button ("Generate", GUILayout.Width (100))) GenerateCardText(c); GUILayout.EndHorizontal(); GUI.skin.label.fontStyle = FontStyle.Bold; GUILayout.BeginHorizontal (); GUILayout.Label("Sounds:"); GUILayout.EndHorizontal(); GUI.skin.label.fontStyle = FontStyle.Normal; GUILayout.BeginVertical ("box"); GUILayout.BeginHorizontal(); c.sfxentry = EditorGUILayout.ObjectField ("Entry:",c.sfxentry, typeof(AudioClip), false) as AudioClip; c.sfxability0 = EditorGUILayout.ObjectField ("Ability:",c.sfxability0, typeof(AudioClip), false) as AudioClip; GUILayout.EndHorizontal(); if (MainMenu.TCGMaker.core.UseGrid) { GUILayout.BeginHorizontal(); c.sfxmove1 = EditorGUILayout.ObjectField ("Move 2:",c.sfxmove1, typeof(AudioClip), false) as AudioClip; c.sfxmove0 = EditorGUILayout.ObjectField ("Move 1:",c.sfxmove0, typeof(AudioClip), false) as AudioClip; GUILayout.EndHorizontal(); } GUILayout.EndVertical(); if (c.effects.Count > 0 ) { GUI.skin.label.fontStyle = FontStyle.Bold; GUILayout.BeginHorizontal (); if (type == 1) GUILayout.Label("Abilities:"); else GUILayout.Label("Effects:"); GUILayout.EndHorizontal(); GUI.skin.label.fontStyle = FontStyle.Normal; } Effect effect_to_remove = null; foreach (Effect effect in c.effects) { GUILayout.BeginVertical ("box"); if (DrawEffect(effect)) effect_to_remove = effect; //it's the way to do it because otherwise we'll get "collection was modified" error GUILayout.EndVertical (); } if (effect_to_remove != null) c.effects.Remove(effect_to_remove); GUILayout.BeginVertical (); //GUILayout.Label(typestring,GUILayout.Width(150)); if (type == 1 && GUILayout.Button ("Add ability", GUILayout.Width (100))) //creature c.effects.Add (new Effect (false, true)); else if (type == 2 && GUILayout.Button ("Add effect", GUILayout.Width (100))) //spell c.effects.Add (new Effect ()); else if ((type == 3 || type == 4 || type == 0 ) && GUILayout.Button ("Add effect", GUILayout.Width (100))) //enchantment/secret/land c.effects.Add (new Effect (true)); if (GUILayout.Button ("Delete card", GUILayout.Width (100))) return true; GUILayout.EndVertical (); return false; }
public void GenerateCardText(DbCard c) { string text = ""; string temptext = ""; string targettext = ""; string param0text = ""; int type = c.type; int discardcost = c.discardcost; string name = c.name; foreach (Effect effect in c.effects) { // adding trigger text: if (effect.trigger == 0) text += "When " + name + " enters game, "; //"on enter" abilities else if (effect.trigger == 3) text += "When " + name + " kills an enemy, "; //"on kill" abilities else if (effect.trigger == 2) text += "When " + name + " attacks, "; //"on attack" abilities else if (effect.trigger == 1) text += "Ability: "; //activated abilities else if (effect.trigger >= 20) //triggers that are not specifir to this creature (when opponnent plays a spell, etc) { for (int i=0; i < triggerints.Length; i++) { if (triggerints[i] == effect.trigger) { text += triggernames[i]; text +=", "; } } } if (effect.trigger == 50) //replacing <type> with chosen creature type for (int i=0; i < subtypeints.Length; i++) { if (subtypeints[i] == effect.triggerparam0) { text = text.Replace("<type>", subtypenames[i]); } } //additing additional cost text: if (discardcost == 1 && type == 2) text+="Discard a card: "; //if it's a spell else if (discardcost > 0 && type == 2) text+="Discard "+discardcost+" cards: "; if (discardcost == 1 && type == 1) text += "As an additional cost to play "+name+ ", discard a card"; // if it's a creature else if (discardcost > 0 && type == 1) text += "As an additional cost to play "+name+ ", discard "+discardcost+" cards"; if (effect.discardcost == 1) text+="Discard a card: "; else if (effect.discardcost > 0) text+="Discard "+effect.discardcost+" cards: "; // adding target text: if (effect.target == 15) targettext = "it"; //this creature else for (int i=0; i < targetints.Length; i++) { if (targetints[i] == effect.target) { targettext = targetnames[i]; targettext = targettext.Replace("<x>", effect.targetparam0.ToString()); targettext = targettext.Replace("<y>", effect.targetparam1.ToString()); targettext = targettext.First().ToString().ToLower() + targettext.Substring(1); //making first letter lowercase } } if (effect.type == 10) temptext = debuffcardtext[effect.bufftype].Replace("<t>", targettext); //debuffs else if (effect.type == 11) temptext = buffcardtext[effect.bufftype].Replace("<t>", targettext); //buffs else temptext = typecardtext[effect.type].Replace("<t>", targettext); //adding target text such as "target player or creature" if (effect.type == 12) //put a new creature in game { for (int i=0; i < creatureints.Count(); i++) { if (creatureints[i] == effect.param0) param0text = creaturenames[i]; } } else if (effect.bufftype == 20) //assign ability for (int i=0; i < keywordints.Count(); i++) { if (keywordints[i] == effect.param0) param0text = keywordnames[i]; } else if (effect.param0type == 0) { param0text = effect.param0.ToString(); } else {//special parameters param0text = "X"; if (effect.param0type == 1) //number of player allies temptext += ", where X is the number of allies"; else if (effect.param0type == 2) //number of player allies destroyed this turn temptext += ", where X is the number of allies destroyed this turn"; } temptext = temptext.Replace("<p0>", param0text); //adding param0 text, it is currently either a number or a creature if (text!="") temptext = temptext.First().ToString().ToLower() + temptext.Substring(1); //making first letter lowercase text += temptext; if (effect.type == 10 || effect.type == 11) if (effect.eot) text += " until end of turn"; text += "\n"; text = text.First().ToString().ToUpper() + text.Substring(1); //making first character uppercase c.text = text; } }
public void DrawGUI() { if (cards == null) cards = new List<DbCard>(); GUILayout.BeginHorizontal(); GUILayout.BeginVertical(); //1st column scrollPosFirst = GUILayout.BeginScrollView(scrollPosFirst); GUI.skin.label.fontStyle = FontStyle.Bold; GUILayout.Label("Cards database"); GUILayout.BeginHorizontal("box"); //small box for load file if (GUILayout.Button("load from xml (optional)",GUILayout.Width(200)) ) OpenFile(); GUI.enabled = true; GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); if (cards.Count > 0) //displaying the cards' table { GUI.skin.label.alignment = TextAnchor.MiddleCenter; GUILayout.BeginHorizontal(); GUILayout.Label("name",GUILayout.MinWidth(150), GUILayout.MaxWidth(300)); GUILayout.Label("type",GUILayout.Width(100)); GUILayout.Label("",GUILayout.Width(100)); GUILayout.EndHorizontal(); GUI.skin.label.fontStyle = FontStyle.Normal; for (int i = 0; i < cards.Count; i++) { DbCard currentcard = cards[i]; GUILayout.BeginHorizontal(); if (GUILayout.Button(currentcard.name,GUILayout.MinWidth(150), GUILayout.MaxWidth(300))) { GUIUtility.keyboardControl = 0; //lose keyboard focus viewed_card = currentcard; } if (DrawCard(currentcard)) cards.RemoveAt(i); //deleting card from db GUILayout.EndHorizontal(); } } if (GUILayout.Button("new card",GUILayout.Width(100)) ) { DbCard newcard = new DbCard(); newcard.id = cards.Count; cards.Add(newcard); UpdateCreatures(cards); viewed_card = newcard; } GUILayout.EndScrollView(); GUILayout.EndVertical(); //1st column end GUILayout.BeginVertical(); //2d column scrollPos = GUILayout.BeginScrollView(scrollPos); GUI.skin.label.fontStyle = FontStyle.Bold; GUILayout.Label("Card view"); GUI.skin.label.fontStyle = FontStyle.Normal; GUILayout.BeginHorizontal("box"); GUILayout.Label("File:",GUILayout.Width(30)); GUILayout.TextField(fileName); GUILayout.EndHorizontal(); GUILayout.BeginVertical("box",GUILayout.Width(600)); if (viewed_card != null) //displaying the card's detailed info { GUILayout.BeginVertical(); if (ViewCard(viewed_card)) cards.Remove(viewed_card); //deleting card from db GUILayout.BeginVertical(); } GUILayout.EndVertical(); //detailed card box GUILayout.EndScrollView(); GUILayout.EndVertical(); //2d column: detailed card info GUILayout.EndHorizontal(); }