/// <summary> /// 检查必出 /// </summary> /// <param name="type">抽奖类型</param> /// <returns>是否正确</returns> private bool CheckCertainly(mw.Enums.RandType type) { List <int> itemList = new List <int>(); foreach (var config in RandTable.RandList) { if (config.rand_type != type || config.limit_count == 0) { continue; } itemList.Add(config.check_idx); } for (int i = 0; i < itemList.Count; ++i) { for (int j = i + 1; j < itemList.Count; ++j) { if (itemList[i] == itemList[j]) { return(false); } } } return(true); }
/// <summary> /// 检查重复 /// </summary> /// <param name="type">抽奖类型</param> /// <returns>是否正确</returns> private bool CheckRepeat(mw.Enums.RandType type) { List <int[]> itemList = new List <int[]>(); foreach (var config in RandTable.RandList) { if (config.rand_type != type) { continue; } itemList.Add(new int[] { (int)config.reward_idx, config.reward_type }); } for (int i = 0; i < itemList.Count; ++i) { for (int j = i + 1; j < itemList.Count; ++j) { if (itemList[i][0] == itemList[j][0] && itemList[i][1] == itemList[j][1]) { return(false); } } } return(true); }
/// <summary> /// 添加按钮响应 /// </summary> protected void addButton_Click(object sender, EventArgs e) { mw.Enums.RandType type = (mw.Enums.RandType) int.Parse(this.randTypeDropDownList.SelectedValue); if (this.configListBox.Items.Count >= LuckDraw.GetRandTypeLimit(type)) { return; } mw.RandConfig config = new mw.RandConfig(); config.rand_type = (mw.Enums.RandType) int.Parse(this.randTypeDropDownList.SelectedValue); if (!this.UpdateConfig(config)) { return; } config.index = this.CreateIndex(); RandTable.RandList.Add(config); TableManager.Save(RandTable.RandList); string text = this.GetConfigText(config); this.configListBox.Items.Add(new ListItem(text, text + this.configListBox.Items.Count)); this.addButton.Enabled = this.configListBox.Items.Count < LuckDraw.GetRandTypeLimit(type); }
/// <summary> /// 获取配置 /// </summary> /// <param name="index">配置索引</param> /// <param name="type">商城类型</param> /// <returns>配置</returns> public static mw.RandConfig GetConfig(int index, mw.Enums.RandType type) { int realIndex = RandTable.GetRealIndex(index, type); if (realIndex >= 0) { return(RandTable.RandList[realIndex]); } else { return(null); } }
/// <summary> /// 获取商城类型数量限制 /// </summary> /// <param name="type">商城类型</param> /// <returns>商城类型数量限制</returns> private static int GetRandTypeLimit(mw.Enums.RandType type) { int limit; if (Mall.RandTypeLimitDictionary.TryGetValue(type, out limit)) { return(limit); } else { return(int.MaxValue); } }
/// <summary> /// 删除按钮响应 /// </summary> protected void deleteButton_Click(object sender, EventArgs e) { if (this.configListBox.SelectedIndex < 0) { return; } mw.Enums.RandType type = (mw.Enums.RandType) int.Parse(this.randTypeDropDownList.SelectedValue); RandTable.RandList.RemoveAt(RandTable.GetRealIndex(this.configListBox.SelectedIndex, type)); this.configListBox.Items.RemoveAt(this.configListBox.SelectedIndex); TableManager.Save(RandTable.RandList); this.addButton.Enabled = this.configListBox.Items.Count < Mall.GetRandTypeLimit(type); }
/// <summary> /// 检查数量 /// </summary> /// <param name="type">抽奖类型</param> /// <returns>是否正确</returns> private bool CheckCount(mw.Enums.RandType type) { int count = 0; foreach (var config in RandTable.RandList) { if (config.rand_type != type) { continue; } ++count; } return(LuckDraw.RandTypeLimitDictionary[type] == count); }
/// <summary> /// 刷新商店列表 /// </summary> private void RefreshRandList() { mw.Enums.RandType type = (mw.Enums.RandType) int.Parse(this.randTypeDropDownList.SelectedValue); if (type == mw.Enums.RandType.RAND_TYPE_LUCK) { this.costLabel.Visible = false; this.costTextBox.Visible = false; this.costDropDownList.Visible = false; } else { this.costLabel.Visible = true; this.costTextBox.Visible = true; this.costDropDownList.Visible = true; } if (type == mw.Enums.RandType.RAND_TYPE_YUANBAO_ACTIVITY) { this.limitTextBox.Visible = true; this.minTextBox.Visible = false; this.maxTextBox.Visible = false; this.numberLabel.Text = "限制购买次数"; } else { this.limitTextBox.Visible = false; this.minTextBox.Visible = true; this.maxTextBox.Visible = true; this.numberLabel.Text = "随机范围"; } this.configListBox.Items.Clear(); foreach (var config in RandTable.RandList) { if (config.rand_type != type) { continue; } string text = this.GetConfigText(config); this.configListBox.Items.Add(new ListItem(text, text + this.configListBox.Items.Count.ToString())); } this.addButton.Enabled = this.configListBox.Items.Count < Mall.GetRandTypeLimit(type); }
/// <summary> /// 创建索引 /// </summary> /// <returns>索引</returns> private int CreateIndex() { mw.Enums.RandType type = (mw.Enums.RandType) int.Parse(this.randTypeDropDownList.SelectedValue); if (type == mw.Enums.RandType.RAND_TYPE_LUCK) { return(0); } int index = 0; switch (type) { case mw.Enums.RandType.RAND_TYPE_XINGYUN: index = 68; break; case mw.Enums.RandType.RAND_TYPE_HAOHUA: index = 74; break; case mw.Enums.RandType.RAND_TYPE_ZHIZUN: index = 80; break; } for (int i = 0; i < LuckDraw.RandTypeLimitDictionary[type]; ++i) { bool isFind = false; foreach (var config in RandTable.RandList) { if (config.rand_type == type && config.index == index + i) { isFind = true; break; } } if (!isFind) { return(index + i); } } return(0); }
/// <summary> /// 检查几率 /// </summary> /// <param name="type">抽奖类型</param> /// <returns>是否正确</returns> private bool CheckRate(mw.Enums.RandType type) { List <int[]> rateList = new List <int[]>(); foreach (var config in RandTable.RandList) { if (config.rand_type != type) { continue; } rateList.Add(new int[] { config.min_rand, config.max_rand }); } if (rateList.Count == 0) { return(false); } while (rateList.Count > 1) { int count = rateList.Count; for (int i = 1; i < rateList.Count; ++i) { if (rateList[0][0] == rateList[i][1] + 1) { rateList[0][0] = rateList[i][0]; rateList.RemoveAt(i); break; } else if (rateList[0][1] + 1 == rateList[i][0]) { rateList[0][1] = rateList[i][1]; rateList.RemoveAt(i); break; } } if (count == rateList.Count) { return(false); } } return(rateList[0][0] == 1 && rateList[0][1] == 10000); }
/// <summary> /// 发送按钮响应 /// </summary> protected void sendButton_Click(object sender, EventArgs e) { for (int i = 0; i < this.randTypeDropDownList.Items.Count; ++i) { ListItem item = this.randTypeDropDownList.Items[i]; mw.Enums.RandType type = (mw.Enums.RandType) int.Parse(item.Value); if (!this.CheckRepeat(type)) { this.errorLabel.Text = item.Text + "分页奖励重复"; return; } if (!this.CheckCount(type)) { this.errorLabel.Text = item.Text + "分页数量不是" + LuckDraw.RandTypeLimitDictionary[type]; return; } if (!this.CheckRate(type)) { this.errorLabel.Text = item.Text + "分页随机区间错误"; return; } if (type != mw.Enums.RandType.RAND_TYPE_LUCK) { if (!this.CheckCertainly(type)) { this.errorLabel.Text = item.Text + "分页必出计数器重复"; return; } } } List <mw.RandConfig> list = new List <mw.RandConfig>(); foreach (var config in RandTable.RandList) { if (config.rand_type != mw.Enums.RandType.RAND_TYPE_YUANBAO_ACTIVITY) { list.Add(config); } } this.errorLabel.Text = TableManager.Send(list, (int)mw.EGMTSettintType.E_GMT_SETTINT_RAND); }
/// <summary> /// 获取精确索引 /// </summary> /// <param name="index">配置索引</param> /// <param name="type">商城类型</param> /// <returns>精确索引</returns> public static int GetRealIndex(int index, mw.Enums.RandType type) { int currentIndex = 0; for (int i = 0; i < RandTable.RandList.Count; ++i) { mw.RandConfig listConfig = RandTable.RandList[i]; if (listConfig.rand_type != type) { continue; } if (currentIndex == index) { return(i); } else { ++currentIndex; } } return(-1); }
/// <summary> /// 刷新商店列表 /// </summary> private void RefreshRandList() { mw.Enums.RandType type = (mw.Enums.RandType) int.Parse(this.randTypeDropDownList.SelectedValue); this.rewardTypeDropDownList.Items.Clear(); if (type == mw.Enums.RandType.RAND_TYPE_LUCK) { this.rewardTypeDropDownList.Items.Add(new ListItem("碎片", ((int)mw.Enums.RewardType.RWD_TYPE_CHIP).ToString())); this.minCountTextBox.Visible = true; this.certainlyLabel.Visible = false; this.counterIndexTextBox.Visible = false; this.counterValueTextBox.Visible = false; } else { //this.rewardTypeDropDownList.Items.Add(new ListItem("经济", ((int)mw.Enums.RewardType.RWD_TYPE_ECONOMIC).ToString())); this.rewardTypeDropDownList.Items.Add(new ListItem("物品", ((int)mw.Enums.RewardType.RWD_TYPE_ITEM).ToString())); this.rewardTypeDropDownList.Items.Add(new ListItem("卡牌", ((int)mw.Enums.RewardType.RWD_TYPE_CARD).ToString())); this.rewardTypeDropDownList.Items.Add(new ListItem("碎片", ((int)mw.Enums.RewardType.RWD_TYPE_CHIP).ToString())); this.rewardTypeDropDownList.Items.Add(new ListItem("宠物", ((int)mw.Enums.RewardType.RWD_TYPE_PET).ToString())); this.minCountTextBox.Visible = false; this.certainlyLabel.Visible = true; this.counterIndexTextBox.Visible = true; this.counterValueTextBox.Visible = true; } if (type == mw.Enums.RandType.RAND_TYPE_YUANBAO_ACTIVITY) { this.limitTextBox.Visible = true; this.minTextBox.Visible = false; this.maxTextBox.Visible = false; this.numberLabel.Text = "限制购买次数"; } else { this.limitTextBox.Visible = false; this.minTextBox.Visible = true; this.maxTextBox.Visible = true; this.numberLabel.Text = "随机范围"; } this.configListBox.Items.Clear(); for (int i = 0; i < RandTable.RandList.Count;) { mw.RandConfig config = RandTable.RandList[i]; if (config.rand_type != type) { ++i; continue; } if (this.configListBox.Items.Count < LuckDraw.GetRandTypeLimit(type)) { string text = this.GetConfigText(config); this.configListBox.Items.Add(new ListItem(text, text + this.configListBox.Items.Count)); ++i; } else { RandTable.RandList.RemoveAt(i); } } this.addButton.Enabled = this.configListBox.Items.Count < LuckDraw.GetRandTypeLimit(type); this.UpdateRewordId(); }