public Squad(int inputID) { DatabaseConnection conn = new DatabaseConnection(); DatabaseReader reader = conn.QueryRowFromTableWithID("Squads", inputID); ID = inputID; if (reader.NextRow()) { Name = reader.GetStringFromCol("Name"); Description = reader.GetStringFromCol("Description"); FlavorText = reader.GetStringFromCol("Flavor_Text"); X = reader.GetIntFromCol("X"); Y = reader.GetIntFromCol("Y"); Route = reader.GetStringFromCol("Route"); reader.CloseReader(); reader = conn.QueryRowFromTableWhereColNameEqualsInt("Units", "Squads_FK", inputID); while (reader.NextRow()) { int dataUnitID = reader.GetIntFromCol("ID"); IUnit unitInSquad = new Unit(dataUnitID); Units.Add(unitInSquad); } } conn.CloseConnection(); reader.CloseReader(); }
public Town(int inputX, int inputY) { units = new List <IUnit>(); DatabaseConnection conn = new DatabaseConnection(); DatabaseReader reader = conn.ExecuteQuery($"SELECT * FROM Towns WHERE X = {inputX} AND Y = {inputY};"); X = inputX; Y = inputY; if (reader.NextRow()) { Name = reader.GetStringFromCol("Name"); Description = reader.GetStringFromCol("Description"); FlavorText = reader.GetStringFromCol("Flavor_Text"); PlayerOwned = reader.GetIntFromCol("Is_Player_Owned") > 0; ID = reader.GetIntFromCol("ID"); reader.CloseReader(); reader = conn.QueryRowFromTableWhereColNameEqualsInt("Units", "Towns_FK", ID); while (reader.NextRow()) { int dataUnitID = reader.GetIntFromCol("ID"); IUnit unitInSquad = new Unit(dataUnitID); units.Add(unitInSquad); } } conn.CloseConnection(); reader.CloseReader(); }
public Town(int inputID) { units = new List <IUnit>(); DatabaseConnection conn = new DatabaseConnection(); DatabaseReader reader = conn.QueryRowFromTableWithID("Towns", inputID); ID = inputID; if (reader.NextRow()) { Name = reader.GetStringFromCol("Name"); Description = reader.GetStringFromCol("Description"); FlavorText = reader.GetStringFromCol("Flavor_Text"); X = reader.GetIntFromCol("X"); Y = reader.GetIntFromCol("Y"); PlayerOwned = reader.GetIntFromCol("Is_Player_Owned") > 0; reader.CloseReader(); reader = conn.QueryRowFromTableWhereColNameEqualsInt("Units", "Towns_FK", inputID); while (reader.NextRow()) { int dataUnitID = reader.GetIntFromCol("ID"); IUnit unitInSquad = new Unit(dataUnitID); units.Add(unitInSquad); } } conn.CloseConnection(); reader.CloseReader(); }
public CombatAbilities(int inputID) { DatabaseConnection conn = new DatabaseConnection(); DatabaseReader reader = conn.QueryRowFromTableWithID("Abilities", inputID); ID = inputID; if (reader.NextRow()) { Name = reader.GetStringFromCol("Name"); Description = reader.GetStringFromCol("Description"); FlavorText = reader.GetStringFromCol("Flavor_Text"); int statusConditionsAttackID = reader.GetIntFromCol("Status_Conditions_Attack_FK"); StatusConditionsAttack = new StatusConditionsAttack(statusConditionsAttackID); Damage = reader.GetIntFromCol("Damage"); Accuracy = reader.GetIntFromCol("Accuracy"); Range = reader.GetIntFromCol("Range"); IsPhysical = reader.GetIntFromCol("Is_Physical") == 1; Length = reader.GetIntFromCol("Length"); Width = reader.GetIntFromCol("Width"); Shape = reader.GetIntFromCol("Shape"); Animation = reader.GetStringFromCol("Animation"); } reader.CloseReader(); conn.CloseConnection(); }
public int Save() { // New Entry if (ID == -1) { string queryString = "INSERT INTO Stats (Physical_Attack, Physical_Defense, Magic_Attack, Magic_Defense, Max_HP, Current_HP, Initiative, Movement) VALUES "; queryString += "( " + Physical_Attack + ", " + Physical_Defense + ", " + Magic_Attack + ", " + Magic_Defense + ", " + Max_HP + ", " + Current_HP + ", " + Initiative + ", " + Movement + ");"; DatabaseConnection conn = new DatabaseConnection(); conn.ExecuteNonQuery(queryString); //Sets new ID equal to new entry DatabaseReader reader = conn.ExecuteQuery("SELECT * FROM Stats ORDER BY ID Desc LIMIT 1;"); reader.NextRow(); ID = reader.GetIntFromCol("ID"); reader.CloseReader(); conn.CloseConnection(); return(ID); } else //Update { string queryString = $"UPDATE Stats SET Physical_Attack = {Physical_Attack}, Physical_Defense = {Physical_Defense}, Magic_Attack = {Magic_Attack}" + $", Magic_Defense = {Magic_Defense}, Max_HP = {Max_HP}, Current_HP = {Current_HP}, Initiative = {Initiative}, Movement = {Movement}" + $" WHERE ID = {ID};"; DatabaseConnection conn = new DatabaseConnection(); conn.ExecuteNonQuery(queryString); conn.CloseConnection(); return(ID); } }
public Unit(string RoleName) { ID = -1; XP = 0; Level = 1; IsDead = false; DatabaseConnection conn = new DatabaseConnection(); DatabaseReader reader = conn.QueryRowFromTableWhereColNameEqualsInputStr("Roles", "Name", RoleName); if (reader.NextRow()) { int roleID = reader.GetIntFromCol("ID"); Role = new Role(roleID); Stats = Role.RoleStats; Stats = new Stats(Role.RoleStats); Name = "No name/Random Default"; } else { // Default role none matched Role = new Role(1); Stats = Role.RoleStats; Stats = new Stats(Role.RoleStats); Name = "No name/Random Default/Wrong Role"; } reader.CloseReader(); conn.CloseConnection(); }
public InventoryItem(int inputID) { DatabaseConnection conn = new DatabaseConnection(); DatabaseReader reader = conn.QueryRowFromTableWithID("Inventory", inputID); ID = inputID; if (reader.NextRow()) { Quantity = reader.GetIntFromCol("Quantity"); int weaponID = reader.GetIntFromCol("Weapon_FK"); int armorID = reader.GetIntFromCol("Armor_FK"); int spellBookID = reader.GetIntFromCol("Spell_Book_FK"); if (weaponID >= 0) { Weapon = new Weapon(weaponID); } else if (armorID >= 0) { Armor = new Armor(armorID); } else if (spellBookID >= 0) { SpellBook = new SpellBook(spellBookID); } } reader.CloseReader(); conn.CloseConnection(); }
public int Save() { if (ID == -1) { string queryString = $"INSERT INTO Enemy_Squads (X, Y) VALUES ({X}, {Y});"; DatabaseConnection conn = new DatabaseConnection(); conn.ExecuteNonQuery(queryString); DatabaseReader reader = conn.ExecuteQuery("SELECT * FROM Enemy_Squads ORDER BY ID Desc LIMIT 1;"); reader.NextRow(); ID = reader.GetIntFromCol("ID"); reader.CloseReader(); conn.CloseConnection(); return(ID); } else { string queryString = $"UPDATE Enemy_Squads SET X = {X}, Y = {Y} WHERE ID = {ID};"; DatabaseConnection conn = new DatabaseConnection(); conn.ExecuteNonQuery(queryString); conn.CloseConnection(); return(ID); } }
public Enemy(int inputID) { DatabaseConnection conn = new DatabaseConnection(); DatabaseReader reader = conn.QueryRowFromTableWithID("Enemies", inputID); ID = inputID; if (reader.NextRow()) { Name = reader.GetStringFromCol("Name"); Description = reader.GetStringFromCol("Description"); FlavorText = reader.GetStringFromCol("Flavor_Text"); int statsID = reader.GetIntFromCol("Stats_FK"); Stats = new Stats(statsID); int weaponID = reader.GetIntFromCol("Weapon_FK"); Weapon = new Weapon(weaponID); int armorID = reader.GetIntFromCol("Armor_FK"); Armor = new Armor(armorID); int spellBookID = reader.GetIntFromCol("Spell_Book_FK"); SpellBook = new SpellBook(spellBookID); Tier = reader.GetIntFromCol("Tier"); PreferredAI = reader.GetStringFromCol("Preferred_AI"); Abilities = new List <IAbility>(); Abilities.AddRange(Weapon.Abilities); Abilities.AddRange(SpellBook.Abilities); } reader.CloseReader(); conn.CloseConnection(); }
public static int GetTurnNumber() { DatabaseConnection conn = new DatabaseConnection(); DatabaseReader reader = conn.ExecuteQuery($"SELECT Turn_Number From Resources WHERE ID = 1"); reader.NextRow(); int turnNum = reader.GetIntFromCol("Turn_Number"); conn.CloseConnection(); reader.CloseReader(); return(turnNum); }
public static string GetCreepTiles() { DatabaseConnection conn = new DatabaseConnection(); DatabaseReader reader = conn.ExecuteQuery($"SELECT Creep_Tiles From Resources WHERE ID = 1"); reader.NextRow(); string creepTiles = reader.GetStringFromCol("Creep_Tiles"); conn.CloseConnection(); reader.CloseReader(); return(creepTiles); }
public static int GetGoldAmount() { DatabaseConnection conn = new DatabaseConnection(); DatabaseReader reader = conn.ExecuteQuery($"SELECT Gold From Resources WHERE ID = 1"); reader.NextRow(); int goldAmount = reader.GetIntFromCol("Gold"); conn.CloseConnection(); reader.CloseReader(); return(goldAmount); }
public static string GetRandomNameFromDatabase() { DatabaseConnection conn = new DatabaseConnection(); int rInt = Random.Range(1, 30); DatabaseReader reader = conn.ExecuteQuery($"SELECT Name From Random_Names WHERE ID = {rInt}"); reader.NextRow(); string randName = reader.GetStringFromCol("Name"); conn.CloseConnection(); reader.CloseReader(); return(randName); }
public InventoryItem(IArmor armor) { DatabaseConnection conn = new DatabaseConnection(); DatabaseReader reader = conn.QueryRowFromTableWhereColNameEqualsInt("Inventory", "Armor_FK", armor.ID); Armor = armor; if (reader.NextRow()) { ID = reader.GetIntFromCol("ID"); Quantity = reader.GetIntFromCol("Quantity"); } else { string query = $"INSERT INTO Inventory (Armor_FK, Quantity) VALUES ({armor.ID}, 0);"; conn.ExecuteNonQuery(query); Quantity = 0; reader.CloseReader(); reader = conn.QueryRowFromTableWhereColNameEqualsInt("Inventory", "Armor_FK", armor.ID); ID = reader.GetIntFromCol("ID"); } reader.CloseReader(); conn.CloseConnection(); }
public InventoryItem(ISpellBook spellBook) { DatabaseConnection conn = new DatabaseConnection(); DatabaseReader reader = conn.QueryRowFromTableWhereColNameEqualsInt("Inventory", "Spell_Book_FK", spellBook.ID); SpellBook = spellBook; if (reader.NextRow()) { ID = reader.GetIntFromCol("ID"); Quantity = reader.GetIntFromCol("Quantity"); } else { string query = $"INSERT INTO Inventory (Spell_Book_FK, Quantity) VALUES ({spellBook.ID}, 0);"; conn.ExecuteNonQuery(query); Quantity = 0; reader.CloseReader(); reader = conn.QueryRowFromTableWhereColNameEqualsInt("Inventory", "Spell_Book_FK", spellBook.ID); ID = reader.GetIntFromCol("ID"); } reader.CloseReader(); conn.CloseConnection(); }
public EnemySquad(int inputID) { DatabaseConnection conn = new DatabaseConnection(); DatabaseReader reader = conn.QueryRowFromTableWithID("Enemy_Squads", inputID); ID = inputID; if (reader.NextRow()) { X = reader.GetIntFromCol("X"); Y = reader.GetIntFromCol("Y"); } conn.CloseConnection(); reader.CloseReader(); }
public SpellBook(int inputID) { DatabaseConnection conn = new DatabaseConnection(); DatabaseReader reader = conn.QueryRowFromTableWithID("Spell_Books", inputID); ID = inputID; if (reader.NextRow()) { Name = reader.GetStringFromCol("Name"); Description = reader.GetStringFromCol("Description"); FlavorText = reader.GetStringFromCol("Flavor_Text"); } reader.CloseReader(); reader = conn.QueryRowFromTableWhereColNameEqualsInt("Spell_Book_To_Ability", "Spell_Book_FK", inputID); Abilities = new List <IAbility>(); while (reader.NextRow()) { int abilityID = reader.GetIntFromCol("Abilities_FK"); Abilities.Add(new CombatAbilities(abilityID)); } reader.CloseReader(); conn.CloseConnection(); }
public StatusConditionsResistances(int inputID) { DatabaseConnection conn = new DatabaseConnection(); DatabaseReader reader = conn.QueryRowFromTableWithID("Status_Conditions_Resistances", inputID); ID = inputID; if (reader.NextRow()) { Fire_Resist = reader.GetIntFromCol("Fire_Resist"); Posion_Resist = reader.GetIntFromCol("Posion_Resist"); Bleed_Resist = reader.GetIntFromCol("Bleed_Resist"); Stun_Resist = reader.GetIntFromCol("Stun_Resist"); } reader.CloseReader(); conn.CloseConnection(); }
public static List <IEnemySquad> GetAllEnemySquads() { List <IEnemySquad> result = new List <IEnemySquad>(); DatabaseConnection conn = new DatabaseConnection(); DatabaseReader reader = conn.QueryAllFromTable("Enemy_Squads"); while (reader.NextRow()) { IEnemySquad dataSquad = new EnemySquad(reader.GetIntFromCol("ID")); result.Add(dataSquad); } reader.CloseReader(); conn.CloseConnection(); return(result); }
public static List <IUnit> GetAllUnits() { List <IUnit> result = new List <IUnit>(); DatabaseConnection conn = new DatabaseConnection(); DatabaseReader reader = conn.QueryAllFromTable("Units"); while (reader.NextRow()) { IUnit dataUnit = new Unit(reader.GetIntFromCol("ID")); result.Add(dataUnit); } reader.CloseReader(); conn.CloseConnection(); return(result); }
public static List <ITown> GetAllTowns() { List <ITown> result = new List <ITown>(); DatabaseConnection conn = new DatabaseConnection(); DatabaseReader reader = conn.QueryAllFromTable("Towns"); while (reader.NextRow()) { ITown dataSquad = new Town(reader.GetIntFromCol("ID")); result.Add(dataSquad); } reader.CloseReader(); conn.CloseConnection(); return(result); }
public static IEnemy GetEnemyFromTier(int tierInput) { DatabaseConnection conn = new DatabaseConnection(); DatabaseReader reader = conn.QueryRowFromTableWhereColNameEqualsInt("Enemies", "Tier", tierInput); List <IEnemy> enemiesFromTier = new List <IEnemy>(); while (reader.NextRow()) { int enemyID = reader.GetIntFromCol("ID"); enemiesFromTier.Add(new Enemy(enemyID)); } int randomIndex = Random.Range(0, enemiesFromTier.Count); conn.CloseConnection(); reader.CloseReader(); return(enemiesFromTier[randomIndex]); }
public int Save() { if (ID == -1) { string queryString = $"INSERT INTO Squads (Name, Description, Flavor_Text, X, Y, Route) VALUES ({DatabaseHelper.GetNullOrStringFromString(Name)}, " + $"{DatabaseHelper.GetNullOrStringFromString(Description)} , {DatabaseHelper.GetNullOrStringFromString(FlavorText)}, {X}, {Y}, {DatabaseHelper.GetNullOrStringFromString(Route)});"; DatabaseConnection conn = new DatabaseConnection(); conn.ExecuteNonQuery(queryString); DatabaseReader reader = conn.ExecuteQuery("SELECT * FROM Squads ORDER BY ID Desc LIMIT 1;"); reader.NextRow(); ID = reader.GetIntFromCol("ID"); reader.CloseReader(); conn.CloseConnection(); foreach (IUnit unit in units) { unit.Squad = this; unit.SquadID = ID; unit.Save(); } return(ID); } else { string queryString = $"UPDATE Squads SET Name = {DatabaseHelper.GetNullOrStringFromString(Name)}, Description = {DatabaseHelper.GetNullOrStringFromString(Description)}," + $" Flavor_Text = {DatabaseHelper.GetNullOrStringFromString(FlavorText)}, X = {X}, Y = {Y}, Route = {DatabaseHelper.GetNullOrStringFromString(Route)} WHERE ID = {ID};"; DatabaseConnection conn = new DatabaseConnection(); conn.ExecuteNonQuery(queryString); conn.CloseConnection(); foreach (IUnit unit in units ?? Units) { if (!(unit.Town == null) && !(unit.Town.Name == null) && unit.Town.Name.Length > 1) { unit.Squad = null; } else { unit.Squad = this; } unit.Save(); } return(ID); } }
public static List <IInventoryItem> GetAllInventoryItems() { List <IInventoryItem> items = new List <IInventoryItem>(); DatabaseConnection conn = new DatabaseConnection(); DatabaseReader reader = conn.QueryAllFromTable("Inventory"); while (reader.NextRow()) { int currentID = reader.GetIntFromCol("ID"); items.Add(new InventoryItem(currentID)); } reader.CloseReader(); conn.CloseConnection(); return(items); }
public static List <IInventoryItem> GetArmors() { List <IInventoryItem> items = new List <IInventoryItem>(); DatabaseConnection conn = new DatabaseConnection(); string query = "SELECT * FROM Inventory WHERE Armor_FK > 0;"; DatabaseReader reader = conn.ExecuteQuery(query); while (reader.NextRow()) { int currentID = reader.GetIntFromCol("ID"); items.Add(new InventoryItem(currentID)); } reader.CloseReader(); conn.CloseConnection(); return(items); }
public Role(int inputID) { DatabaseConnection conn = new DatabaseConnection(); DatabaseReader reader = conn.QueryRowFromTableWithID("Roles", inputID); ID = inputID; if (reader.NextRow()) { Name = reader.GetStringFromCol("Name"); Description = reader.GetStringFromCol("Description"); FlavorText = reader.GetStringFromCol("Flavor_Text"); int statsID = reader.GetIntFromCol("Base_Stats_FK"); RoleStats = new Stats(statsID); } reader.CloseReader(); conn.CloseConnection(); }
public StatusConditionsAttack(int inputID) { DatabaseConnection conn = new DatabaseConnection(); DatabaseReader reader = conn.QueryRowFromTableWithID("Status_Conditions_Attacks", inputID); ID = inputID; if (reader.NextRow()) { Fire_Damage = reader.GetIntFromCol("Fire_Damage"); Fire_Chance = reader.GetIntFromCol("Fire_Chance"); Posion_Damage = reader.GetIntFromCol("Posion_Damage"); Posion_Chance = reader.GetIntFromCol("Posion_Chance"); Bleed_Damage = reader.GetIntFromCol("Bleed_Damage"); Bleed_Chance = reader.GetIntFromCol("Bleed_Chance"); Stun_Chance = reader.GetIntFromCol("Stun_Chance"); } reader.CloseReader(); conn.CloseConnection(); }
public StatusConditionsActive(int inputID) { DatabaseConnection conn = new DatabaseConnection(); DatabaseReader reader = conn.QueryRowFromTableWithID("Status_Conditions_Active", inputID); ID = inputID; if (reader.NextRow()) { FireDamage = reader.GetIntFromCol("Fire_Damage"); IsOnFire = reader.GetIntFromCol("Is_On_Fire") > 0; PoisonDamage = reader.GetIntFromCol("Posion_Damage"); IsPoisoned = reader.GetIntFromCol("Is_Poisoned") > 0; BleedDamage = reader.GetIntFromCol("Bleed_Damage"); IsBleeding = reader.GetIntFromCol("Is_Bleeding") > 0; IsStunned = reader.GetIntFromCol("Is_Stunned") > 0; } reader.CloseReader(); conn.CloseConnection(); }
public Unit(int inputID) { DatabaseConnection conn = new DatabaseConnection(); DatabaseReader reader = conn.QueryRowFromTableWithID("Units", inputID); ID = inputID; if (reader.NextRow()) { Name = reader.GetStringFromCol("Name"); Description = reader.GetStringFromCol("Description"); FlavorText = reader.GetStringFromCol("Flavor_Text"); int roleID = reader.GetIntFromCol("Role_FK"); Role = new Role(roleID); int statsID = reader.GetIntFromCol("Stats_FK"); Stats = new Stats(statsID); int weaponID = reader.GetIntFromCol("Weapon_FK"); Weapon = new Weapon(weaponID); int armorID = reader.GetIntFromCol("Armor_FK"); Armor = new Armor(armorID); int spellBookID = reader.GetIntFromCol("Spell_Book_FK"); SpellBook = new SpellBook(spellBookID); int statusConditionActiveID = reader.GetIntFromCol("Status_Conditions_Acitve_FK"); StatusConditionsActive = new StatusConditionsActive(statusConditionActiveID); SquadID = reader.GetIntFromCol("Squads_FK"); TownID = reader.GetIntFromCol("Towns_FK"); IsDead = reader.GetIntFromCol("Is_Dead") > 0; abilities = new List <IAbility>(); abilities.AddRange(Weapon.Abilities); abilities.AddRange(SpellBook.Abilities); } reader.CloseReader(); conn.CloseConnection(); }
public Stats(int inputID) { DatabaseConnection conn = new DatabaseConnection(); DatabaseReader reader = conn.QueryRowFromTableWithID("Stats", inputID); ID = inputID; if (reader.NextRow()) { Physical_Attack = reader.GetIntFromCol("Physical_Attack"); Physical_Defense = reader.GetIntFromCol("Physical_Defense"); Magic_Attack = reader.GetIntFromCol("Magic_Attack"); Magic_Defense = reader.GetIntFromCol("Magic_Defense"); Max_HP = reader.GetIntFromCol("Max_HP"); Current_HP = reader.GetIntFromCol("Current_HP"); Initiative = reader.GetIntFromCol("Initiative"); Movement = reader.GetIntFromCol("Movement"); } reader.CloseReader(); conn.CloseConnection(); }