private Dropped GetRandomDrop(DropLevel drop) { Dropped dropped = new Dropped(); PotentialDrop potentialDrop = SelectDrop(drop); dropped.item = potentialDrop.item; dropped.number = potentialDrop.GetRandomNumber(); return(dropped); }
private bool ShouldRandomDrop(DropLevel drop) { float randomRoll = Random.Range(0, 100); if (randomRoll < drop.dropChancePercentage) { return(true); } return(false); }
private float GetTotalChance(DropLevel drop) { float total = 0; foreach (PotentialDrop potentialDrop in drop.potentialDrops) { total += potentialDrop.relativeChance; } return(total); }
public IEnumerable <Dropped> GetRandomDrops(int level) { DropLevel drop = GetDropLevel(level); if (ShouldRandomDrop(drop)) { for (int i = 0; i < GetRandomNoOfDrops(drop); i++) { yield return(GetRandomDrop(drop)); } } }
PotentialDrop SelectDrop(DropLevel drop) { float randomRoll = Random.Range(0, GetTotalChance(drop)); float chanceTotal = 0; foreach (PotentialDrop potentialDrop in drop.potentialDrops) { chanceTotal += potentialDrop.relativeChance; if (chanceTotal > randomRoll) { return(potentialDrop); } } return(null); }
protected void DropEducation_SelectedIndexChanged(object sender, EventArgs e) { if (DropEducation.SelectedIndex != 0) { DropLevel.Enabled = true; } SqlConnection con = new SqlConnection(conString); SqlCommand cmd = new SqlCommand("SELECT * FROM [Tbl_Level] WHERE [EduLevelID] = '" + DropEducation.SelectedValue + "'", con); con.Open(); //education droplist DropLevel.DataSource = cmd.ExecuteReader(); DropLevel.DataValueField = "LevelID"; DropLevel.DataTextField = "LevelNumber"; DropLevel.DataBind(); DropLevel.Items.Insert(0, new ListItem("Select Level", "0")); con.Close(); }
private int GetRandomNoOfDrops(DropLevel drop) { return(Random.Range(drop.minNoOfDrops, drop.maxNoOfDrops + 1)); }