public static CharacterCollection getBreedingCharacters(int gameId, int dynastyId, int turn) { CharacterCollection cc = new CharacterCollection(); using (SqlConnection cn = DataAccess.DataAccessFactory.GetDataAccess()) { SqlCommand cmd = new SqlCommand("GetBreedingCharacters", cn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter("@GameId", gameId)); cmd.Parameters.Add(new SqlParameter("@DynastyId", dynastyId)); cn.Open(); SqlDataReader reader; reader = cmd.ExecuteReader(); DataTable dt = new DataTable(); dt.Load(reader); if (dt != null) { foreach (DataRow dr in dt.Rows) { //Could be in the procedure but its simpler to add it here. So I do the filtering here for "age 50 yrs and younger" if (Convert.ToInt32(dr["Born"]) > turn - 11) { cc.Add(new Character(dr)); } } } return(cc); } }
public static CharacterCollection getAllHeirs(int id) { CharacterCollection cc = new CharacterCollection(); using (SqlConnection cn = DataAccess.DataAccessFactory.GetDataAccess()) { string query = "Select * FROM vCharacters WHERE (FatherId= " + id + " OR MotherId = " + id + ") ORDER BY Gender Desc, CharacterId Asc ;"; SqlCommand cmd = new SqlCommand(query, cn); cn.Open(); SqlDataReader reader; reader = cmd.ExecuteReader(); DataTable dt = new DataTable(); dt.Load(reader); if (dt != null) { foreach (DataRow dr in dt.Rows) { cc.Add(new Character(dr)); } } return(cc); } }
public static CharacterCollection getAllCharacters(int dynastyId) { CharacterCollection cc = new CharacterCollection(); using (SqlConnection cn = DataAccess.DataAccessFactory.GetDataAccess()) { string query = "Select * from vCharacters WHERE DynastyId = " + dynastyId + " AND Dead = 'FALSE'; "; SqlCommand cmd = new SqlCommand(query, cn); cn.Open(); SqlDataReader reader; reader = cmd.ExecuteReader(); DataTable dt = new DataTable(); dt.Load(reader); if (dt != null) { foreach (DataRow dr in dt.Rows) { cc.Add(new Character(dr)); } } return(cc); } }
public static CharacterCollection getAllAvailable(int gameId) //for all dynasties { CharacterCollection cc = new CharacterCollection(); using (SqlConnection cn = DataAccess.DataAccessFactory.GetDataAccess()) { SqlCommand cmd = new SqlCommand("GetAllAvailable", cn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter("@GameId", gameId)); cn.Open(); SqlDataReader reader; reader = cmd.ExecuteReader(); DataTable dt = new DataTable(); dt.Load(reader); if (dt != null) { foreach (DataRow dr in dt.Rows) { cc.Add(new Character(dr)); } } return(cc); } }
// public static bool passoverPossible = false; //dont mix in passover here, take care of it later just return a heir list //make it return void public static List <Character> FindHeir(int CharacterId) { List <Character> heirList = new List <Character>(); List <Character> kidsList = new List <Character>(); // all heirs dead or alive and ordered after male and then by Id BR.Model.CharacterCollection heirs = BR.Model.CharacterCollection.getAllHeirs(CharacterId); foreach (Character element in heirs) { if (!element.Dead) //alive { heirList.Add(element); } kidsList = FindHeir(element.characterId); foreach (Character kid in kidsList) { heirList.Add(kid); } } return(heirList); }
protected void btnDynasticSequence_Click(object sender, EventArgs e) { if (Session["GameId"] != null) { int gameId = Convert.ToInt32(Session["GameId"]); int ds = ExtraLib.Sql.getDynasticSequence(gameId); ds++; if (ds > 4) { ds = 1; } ExtraLib.Sql.increaseDynasticSequence(gameId, ds); switch (ds) { case 1: //Birth ExtraLib.Sql.increaseTurn(Convert.ToInt32(Session["GameId"])); Session["Turn"] = Convert.ToInt32(Session["Turn"]) + 1; this.lblYear.Text = "Year: " + ((Convert.ToInt32(Session["Turn"]) * 5) + 1300).ToString(); this.panelEventCombat.Visible = false; //breed all here so its only triggered when the button is clicked and not on every refresh of page. ExtraLib.DynasticSequence.BreedAll(gameId, Convert.ToInt32(Session["Turn"])); itsBirthPhase(); break; case 2: //survival itsSurvivalPhase(); List <List <Character> > theListOfLists = new List <List <Character> >(); Model.CharacterCollection allNewDeaths = ExtraLib.DynasticSequence.SurviveAll(Convert.ToInt32(Session["GameId"]), ref theListOfLists); Model.CharacterCollection englandNewDeaths = new Model.CharacterCollection(); Model.CharacterCollection franceNewDeaths = new Model.CharacterCollection(); Model.CharacterCollection germanyNewDeaths = new Model.CharacterCollection(); Model.CharacterCollection italyNewDeaths = new Model.CharacterCollection(); Model.CharacterCollection spainNewDeaths = new Model.CharacterCollection(); foreach (Character element in allNewDeaths) { if (element.country == 'E') { englandNewDeaths.Add(element); } if (element.country == 'F') { franceNewDeaths.Add(element); } if (element.country == 'G') { germanyNewDeaths.Add(element); } if (element.country == 'I') { italyNewDeaths.Add(element); } if (element.country == 'S') { spainNewDeaths.Add(element); } } gvEnglandNewDeath.DataSource = englandNewDeaths; gvEnglandNewDeath.DataBind(); gvFranceNewDeath.DataSource = franceNewDeaths; gvFranceNewDeath.DataBind(); gvGermanyNewDeath.DataSource = germanyNewDeaths; gvGermanyNewDeath.DataBind(); gvItalyNewDeath.DataSource = italyNewDeaths; gvGermanyNewDeath.DataBind(); gvSpainNewDeath.DataSource = spainNewDeaths; gvSpainNewDeath.DataBind(); PossibleHeirs ph = new PossibleHeirs(theListOfLists); Session["PassoverList"] = ph; showPassoverHeir(); break; case 3: // Marriages //show all available to all players this.panelSurvival.Visible = false; itsMarriagePhase(); refreshAvailableAndProposals(); break; case 4: ExtraLib.Sql.emptyMarriageOffers(Convert.ToInt32(Session["GameId"])); itsEventPhase(); this.panelMarriage.Visible = false; showNewDynasty(); break; } } else { Session["Error"] = "Session timed out"; Response.Redirect("default.aspx"); } }