/// <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> protected void configListBox_SelectedIndexChanged(object sender, EventArgs e) { if (this.configListBox.SelectedIndex < 0) { return; } mw.RandConfig config = RandTable.GetConfig(this.configListBox.SelectedIndex, (mw.Enums.RandType) int.Parse(this.randTypeDropDownList.SelectedValue)); if (config == null) { return; } for (int i = 0; i < this.rewardTypeDropDownList.Items.Count; ++i) { if (this.rewardTypeDropDownList.Items[i].Value == ((int)config.reward_idx).ToString()) { this.rewardTypeDropDownList.SelectedIndex = i; break; } } this.UpdateRewordId(); for (int i = 0; i < this.idDropDownList.Items.Count; ++i) { if (this.idDropDownList.Items[i].Value == config.reward_type.ToString()) { this.idDropDownList.SelectedIndex = i; break; } } if (config.reward_count > 0) { this.minCountTextBox.Text = config.reward_count.ToString(); this.countTextBox.Text = config.reward_count.ToString(); } else { this.minCountTextBox.Text = config.reward_min_count.ToString(); this.countTextBox.Text = config.reward_max_count.ToString(); } if (config.rand_type != mw.Enums.RandType.RAND_TYPE_LUCK) { this.counterIndexTextBox.Text = config.check_idx.ToString(); this.counterValueTextBox.Text = config.limit_count.ToString(); } this.limitTextBox.Text = config.limit_count.ToString(); this.minTextBox.Text = config.min_rand.ToString(); this.maxTextBox.Text = config.max_rand.ToString(); }
/// <summary> /// 修改按钮响应 /// </summary> protected void modifyButton_Click(object sender, EventArgs e) { if (this.configListBox.SelectedIndex < 0) { return; } mw.RandConfig config = RandTable.GetConfig(this.configListBox.SelectedIndex, (mw.Enums.RandType) int.Parse(this.randTypeDropDownList.SelectedValue)); if (!this.UpdateConfig(config)) { return; } TableManager.Save(RandTable.RandList); this.configListBox.SelectedItem.Text = this.GetConfigText(config); this.configListBox.SelectedItem.Value = this.configListBox.SelectedItem.Text + this.configListBox.SelectedIndex; }
/// <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> /// <param name="config">配置</param> /// <returns>文本</returns> private string GetConfigText(mw.RandConfig config) { StringBuilder builder = new StringBuilder(config.index.ToString()); builder.Append(" | "); for (int i = 0; i < this.rewardTypeDropDownList.Items.Count; ++i) { ListItem item = this.rewardTypeDropDownList.Items[i]; if (item.Value == ((int)config.reward_idx).ToString()) { builder.Append(item.Text); break; } } builder.Append(" | "); switch (config.reward_idx) { case mw.Enums.RewardType.RWD_TYPE_ECONOMIC: for (int i = 0; i < this.costDropDownList.Items.Count; ++i) { ListItem item = this.costDropDownList.Items[i]; if (config.reward_type.ToString() == item.Value) { builder.Append(item.Text); break; } } break; case mw.Enums.RewardType.RWD_TYPE_ITEM: builder.Append(TableManager.ItemTable[config.reward_type].name); break; case mw.Enums.RewardType.RWD_TYPE_CARD: case mw.Enums.RewardType.RWD_TYPE_CHIP: builder.Append(TableManager.CardTable[config.reward_type].name); break; case mw.Enums.RewardType.RWD_TYPE_PET: builder.Append(TableManager.PetTable[config.reward_type].name); break; } builder.Append(" ").Append(config.reward_count); if (config.rand_type == mw.Enums.RandType.RAND_TYPE_YUANBAO_ACTIVITY) { builder.Append(" | ").Append(config.cost_val).Append(" "); for (int i = 0; i < this.costDropDownList.Items.Count; ++i) { ListItem item = this.costDropDownList.Items[i]; if (config.cost_type.ToString() == item.Value) { builder.Append(item.Text); break; } } builder.Append(" | 限购 ").Append(config.limit_count); } else { builder.Append(" | ").Append(config.min_rand).Append("~").Append(config.max_rand); } builder.Append(" | 限制分组 ").Append(config.check_idx); return(builder.ToString()); }
/// <summary> /// 更新配置 /// </summary> /// <param name="config">配置</param> /// <returns>是否成功</returns> private bool UpdateConfig(mw.RandConfig config) { int intValue; if (!int.TryParse(this.indexTextBox.Text, out intValue) || intValue < 0) { this.errorLabel.Text = "位置索引输入错误"; return(false); } config.index = intValue; config.reward_idx = (mw.Enums.RewardType) int.Parse(this.rewardTypeDropDownList.SelectedValue); config.reward_type = int.Parse(this.idDropDownList.SelectedItem.Value); if (!int.TryParse(this.countTextBox.Text, out intValue) || intValue <= 0) { this.errorLabel.Text = "数量输入错误"; return(false); } switch (config.reward_idx) { case mw.Enums.RewardType.RWD_TYPE_ITEM: case mw.Enums.RewardType.RWD_TYPE_CHIP: if (intValue > 99) { this.errorLabel.Text = "数量不能大于99"; return(false); } break; case mw.Enums.RewardType.RWD_TYPE_CARD: case mw.Enums.RewardType.RWD_TYPE_PET: if (intValue > 1) { this.errorLabel.Text = "数量不能大于1"; return(false); } break; } config.reward_count = intValue; if (config.rand_type == mw.Enums.RandType.RAND_TYPE_YUANBAO_ACTIVITY) { config.cost_type = int.Parse(this.costDropDownList.SelectedItem.Value); if (!int.TryParse(this.costTextBox.Text, out intValue) || intValue <= 0) { this.errorLabel.Text = "费用输入错误"; return(false); } if (intValue > 9999999) { this.errorLabel.Text = "费用不能大于9999999"; return(false); } config.cost_val = intValue; if (!int.TryParse(this.limitTextBox.Text, out intValue) || intValue < 0) { this.errorLabel.Text = "限购数量输入错误"; return(false); } //if (intValue != 0 && config.reward_count > intValue) //{ // this.errorLabel.Text = "数量不能大于限制购买次数"; // return false; //} config.limit_count = intValue; config.min_rand = 1; config.max_rand = 10000; } else { config.cost_type = 0; config.cost_val = 0; if (!int.TryParse(this.minTextBox.Text, out intValue) || intValue < 0) { this.errorLabel.Text = "最小随机输入错误"; return(false); } config.min_rand = intValue; if (!int.TryParse(this.maxTextBox.Text, out intValue) || intValue < 0) { this.errorLabel.Text = "最大随机输入错误"; return(false); } config.max_rand = intValue; config.limit_count = 0; } if (!int.TryParse(this.groupTextBox.Text, out intValue) || ((intValue < 65 || intValue > 127) && intValue != 0)) { this.errorLabel.Text = "限制分组只能在 65~127 之间, 或为 0"; return(false); } config.check_idx = intValue; return(true); }
/// <summary> /// 获取配置的文本 /// </summary> /// <param name="config">配置</param> /// <returns>文本</returns> private string GetConfigText(mw.RandConfig config) { StringBuilder builder = new StringBuilder(); if (config.rand_type != mw.Enums.RandType.RAND_TYPE_LUCK) { builder.Append(config.index.ToString()); builder.Append(" | "); } for (int i = 0; i < this.rewardTypeDropDownList.Items.Count; ++i) { ListItem item = this.rewardTypeDropDownList.Items[i]; if (item.Value == ((int)config.reward_idx).ToString()) { builder.Append(item.Text); break; } } builder.Append(" | "); switch (config.reward_idx) { case mw.Enums.RewardType.RWD_TYPE_ECONOMIC: if (config.reward_type == 2) { builder.Append("金钱"); } else if (config.reward_type == 3) { builder.Append("元宝"); } break; case mw.Enums.RewardType.RWD_TYPE_ITEM: builder.Append(TableManager.ItemTable[config.reward_type].name); break; case mw.Enums.RewardType.RWD_TYPE_CARD: case mw.Enums.RewardType.RWD_TYPE_CHIP: builder.Append(TableManager.CardTable[config.reward_type].name); break; case mw.Enums.RewardType.RWD_TYPE_PET: builder.Append(TableManager.PetTable[config.reward_type].name); break; } builder.Append(" "); if (config.reward_count > 0) { builder.Append(config.reward_count); } else { builder.Append(config.reward_min_count).Append("~").Append(config.reward_max_count); } builder.Append(" | ").Append(config.min_rand).Append("~").Append(config.max_rand); builder.Append(" | ").Append((config.max_rand - config.min_rand + 1) / 100f).Append("%"); if (config.rand_type != mw.Enums.RandType.RAND_TYPE_LUCK) { builder.Append(" | ").Append(config.check_idx).Append(" ").Append(config.limit_count); } return(builder.ToString()); }
/// <summary> /// 更新配置 /// </summary> /// <param name="config">配置</param> /// <returns>是否成功</returns> private bool UpdateConfig(mw.RandConfig config) { int intValue; config.reward_idx = (mw.Enums.RewardType) int.Parse(this.rewardTypeDropDownList.SelectedValue); config.reward_type = int.Parse(this.idDropDownList.SelectedItem.Value); if (!int.TryParse(this.countTextBox.Text, out intValue) || intValue <= 0) { this.errorLabel.Text = "数量输入错误"; return(false); } switch (config.reward_idx) { case mw.Enums.RewardType.RWD_TYPE_ITEM: case mw.Enums.RewardType.RWD_TYPE_CHIP: if (intValue > 99) { this.errorLabel.Text = "数量不能大于99"; return(false); } break; case mw.Enums.RewardType.RWD_TYPE_CARD: case mw.Enums.RewardType.RWD_TYPE_PET: if (intValue > 1) { this.errorLabel.Text = "数量不能大于1"; return(false); } break; } if (config.rand_type == mw.Enums.RandType.RAND_TYPE_LUCK) { config.reward_max_count = intValue; if (!int.TryParse(this.minCountTextBox.Text, out intValue) || intValue <= 0 || intValue > config.reward_max_count) { this.errorLabel.Text = "数量输入错误"; return(false); } if (config.reward_max_count == intValue) { config.reward_count = intValue; config.reward_min_count = 0; config.reward_max_count = 0; } else { config.reward_count = 0; config.reward_min_count = intValue; } } else { config.reward_count = intValue; config.reward_min_count = 0; config.reward_max_count = 0; } config.cost_type = 0; config.cost_val = 0; if (!int.TryParse(this.minTextBox.Text, out intValue) || intValue < 0) { this.errorLabel.Text = "最小随机输入错误"; return(false); } config.min_rand = intValue; if (!int.TryParse(this.maxTextBox.Text, out intValue) || intValue < 0) { this.errorLabel.Text = "最大随机输入错误"; return(false); } config.max_rand = intValue; config.limit_count = 0; if (config.max_rand <= config.min_rand) { this.errorLabel.Text = "随机输入错误"; return(false); } if (config.rand_type != mw.Enums.RandType.RAND_TYPE_LUCK) { if (!int.TryParse(this.counterIndexTextBox.Text, out intValue) || intValue < 0 || intValue > 5) { this.errorLabel.Text = "必抽计数器必需为 0~6"; return(false); } config.check_idx = intValue; if (!int.TryParse(this.counterValueTextBox.Text, out intValue) || intValue < 0) { this.errorLabel.Text = "必抽数量输入错误"; return(false); } config.limit_count = intValue; } return(true); }
/// <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(); }