当前位置:   article > 正文

[WinForm开源]概率计算器 - Genshin Impact(V1.0)

[WinForm开源]概率计算器 - Genshin Impact(V1.0)

创作目的:为方便旅行者估算自己拥有的纠缠之缘能否达到自己的目的,作者使用C#开发了一款小型软件供旅行者参考使用。

创作说明:此软件所涉及到的一切概率与规则完全按照游戏《原神》(V4.4.0)内公示的概率与规则(包括保底机制)进行编写,仅用于计模拟已知纠缠之缘数量对已知抽取五星目标的成功频率(可看作成功率),无任何暗箱操作。


目录

一、软件介绍

1.软件主页面展示

2.软件适用范围

3.软件使用方法

二、获取途径

1.软件获取

2.项目获取

三、项目开源

1.MainForm页面(软件主页面)

2.Form_Poster页面(祈愿海报页面)

3.README页面(说明页面)

4. 应用程序清单文件

四、其他说明


一、软件介绍

1.软件主页面展示

2.软件适用范围

该软件适用范围为:2位UP角色不同卡池但一同保底计数、2把专武在同一卡池且只能定轨一把武器。[说通俗点就是目前能够支持到4.4下半版本,后期如开启混池,作者将会对软件进行更新]

3.软件使用方法

点击顶部卡池选择」下拉框可切换当前的卡池信息,目前支持4.3与4.4上下半卡池总计4期卡池。

点击顶部点击查看卡池海报」按钮可以查看选择的当期卡池的海报。

左侧计划抽取」一栏可以选择旅行者计划抽取的角色、武器的数量,默认为0,角色最大为7,武器最大为5 。当旅行者四栏全部选择为0时,将不被允许进行模拟。

左侧「当前资源」一栏填写旅行者计划投入的纠缠之缘与原石的数量,当填入的资源不足1抽时将不被允许进行模拟,最大支持999抽。

左侧「其他情况」一栏旅行者可以勾选自己对应的情况,若不清楚对于情况,可进入游戏进行查看;旅行者勾选的选项将影响到模拟结果。

中间「用户须知」一栏为简要的用户须知,如页面过小可点击放大到新窗口。旅行者阅读完毕请勾选其下方的“我已认真阅读上述内容”。

点击中间「仅将原石转化为纠缠之缘」按钮,软件将根据用户填入的原石数量,转化为纠缠之缘并将合计的纠缠之缘数量、剩余的原石数量展现给旅行者。

点击中间「开始模拟」按钮,软件将进行10,000次模拟,每次模拟到抽取到目标为止,若有纠缠之缘剩余,则计入剩余总数,最终计算平均剩余数。软件最终将给出「达成预期频率」「超越预期频率」「综合成功频率」(后面介绍)。模拟的计算速度取决于旅行者的纠缠之缘数量与计算机的运算速度。

右侧「达成预期频率」一栏将展示软件对旅行者给出的资源数量与目标进行1W次模拟后得到的恰好达到目标的情况的数量与模拟总量的比值。“达成预期”判定标准:在达成所有抽取目标后,纠缠之缘剩余量不小于0时,所获得的所有5星物品(含常驻)与填写的抽取目标完全一致。

右侧「超出预期频率」一栏将展示软件对旅行者给出的资源数量与目标进行1W次模拟后得到的超出预期目标的情况的数量与模拟总量的比值。“超出预期”判定标准:在达成所有抽取目标后,纠缠之缘剩余量不小于0时,所获得的所有5星物品(含常驻)超出填写的抽取目标(常驻默认为0)。

右侧「综合成功频率」一栏将展示软件对旅行者给出的资源数量与目标进行1W次模拟后得到的能够完成给定的抽取目标的情况的数量与模拟总量的比值。该栏为上述两栏之和。

点击右侧「保存为图片」按钮,软件将会把当前页面保存为PNG图片。

二、获取途径

1.软件获取

(1)CSDN站内下载:https://download.csdn.net/download/qq_64516527/88817489

(2)百度网盘下载:https://pan.baidu.com/s/1Uw1mMIONUh9-heMUHRgOOQ?pwd=SLLH 提取码:SLLH

(3)123云盘下载:https://www.123pan.com/s/Il2bVv-CwvQh.html

2.项目获取

(1)CSDN站内下载:https://download.csdn.net/download/qq_64516527/88817874

(2)123云盘下载:https://www.123pan.com/s/Il2bVv-NwvQh.html

三、项目开源

注:接下来的代码主要按页面进行分栏,代码中注释比较全,可直接阅读。

1.MainForm页面(软件主页面)

设计器:

页面代码:

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Threading;
  11. using System.Diagnostics;
  12. using System.Security.Cryptography;
  13. using System.IO;
  14. namespace 概率计算器___Genshin_Impact
  15. {
  16. public partial class MainForm : Form
  17. {
  18. public MainForm()
  19. {
  20. InitializeComponent();
  21. }
  22. #region 变量的声明
  23. public bool Avaluable = true;
  24. Thread Thread_Load = null;//淡入淡出的线程
  25. Thread Thread_DataDetection = null;//用于检测数据并调控Enable属性的线程
  26. Thread T_Imitate = null;//用于进行模拟的线程
  27. public int NUM_Ball = 0, NUM_Stone = 0;//纠缠之缘与原石的数量
  28. public int[] Success = new int[2] { 0, 0 };//分别表示恰好达到预期与超出预期的次数
  29. public int Success_Sum = 0;//表示综合成功次数
  30. public bool NextRoleIsBig = false;//表示下次角色池是否为大保底
  31. public bool NextWeaponIsUp = false;//表示下次武器池是否为UP武器
  32. public int Num_Weapon_Base = 0;//表示武器池定轨数
  33. string[,] RoleName = new string[4, 2] {
  34. {"娜维娅", "神里绫华" },//4.3上半卡池,卡池编码为0
  35. {"雷电将军", "宵宫" },//4.3下半卡池,卡池编码为1
  36. { "闲云", "纳西妲" }, //4.4上半卡池,卡池编码为2
  37. { "魈", "八重神子" }//4.4下半卡池,卡池编码为3
  38. };
  39. //第一维度为版本编号,第二维度为卡池序号
  40. //比如4.4上半对应第一维度,而角色祈愿-2对应第二维度
  41. //角色头像图片名称为RoleName[m,n] + "·头像.png"
  42. //专武图片名称为RoleName[m,n] + "专武.png"
  43. #endregion
  44. private void MainForm_Load(object sender, EventArgs e)
  45. {
  46. panelMain.BackColor = Color.FromArgb(191, 0, 0, 0);
  47. panelMain.Height = 0;
  48. Thread_Load = new Thread(() => LoadThread());
  49. Thread_Load.Start();
  50. Thread_DataDetection = new Thread(() => T_DataDetection());
  51. Thread_DataDetection.Start();
  52. foreach (Control control in panelMain.Controls)//遍历panel中的所有控件
  53. if (!((control is ComboBox) || (control is TextBox) || (control is RichTextBox)))
  54. control.BackColor = Color.FromArgb(0, 0, 0, 0);
  55. else if (control is ComboBox)
  56. {
  57. ComboBox CB = (ComboBox)control;
  58. CB.SelectedIndex = 0;
  59. }
  60. pictureBox_README.BackColor = Color.FromArgb(64, 0, 0, 0);
  61. comboBox_VersionChoose.SelectedIndex = 0;//设置初始选择值
  62. #region 关于SelectedIndex的说明
  63. /* 0为4.4上半(闲云 纳西妲)
  64. * 1为4.4下半(魈 八重神子)
  65. */
  66. #endregion
  67. label1.Text = "还未进行过模拟";
  68. }
  69. private void T_DataDetection()
  70. {
  71. bool B = false;//用于判断能否抽卡
  72. while(true)
  73. {
  74. if (NUM_Stone >= 160)
  75. Invoke(new Action(() => { button_Transport.Enabled = true; }));//跨线程操作
  76. else Invoke(new Action(() => { button_Transport.Enabled = false; }));//跨线程操作
  77. B = ((NUM_Ball > 0) && (NUM_Stone >= 0)) || ((NUM_Ball == 0) && (NUM_Stone >= 160));
  78. if (B && Avaluable)
  79. Invoke(new Action(() => { button_Start.Enabled = true; }));//跨线程操作
  80. else Invoke(new Action(() => { button_Start.Enabled = false; }));//跨线程操作
  81. Thread.Sleep(50);
  82. }
  83. }//用于检测数据并调控Enable属性的线程
  84. private void LoadThread()
  85. {
  86. do
  87. {
  88. Invoke(new Action(() =>
  89. {
  90. panelMain.Height += 20;
  91. }));//跨线程操作
  92. Thread.Sleep(2);
  93. } while (panelMain.Height <= 750);
  94. }//黑色半透明下降的动画的线程
  95. #region 为获取comboBox控件的SelectedIndex属性而定义的内容
  96. // 定义一个委托来执行操作
  97. delegate int GetSelectedIndexDelegate();
  98. // 在主线程中执行操作的方法
  99. private int GetCBWNSelectedIndex()
  100. {
  101. if (comboBox_WeaponN.InvokeRequired)
  102. {
  103. // 如果需要跨线程调用,则使用Invoke
  104. return (int)comboBox_WeaponN.Invoke(new GetSelectedIndexDelegate(GetCBWNSelectedIndex));
  105. }
  106. else
  107. {
  108. // 直接返回SelectedIndex
  109. return comboBox_WeaponN.SelectedIndex;
  110. }
  111. }
  112. #endregion
  113. private void imitate(int N,int[] Target,CheckBox[] CB, ComboBox comboBox_WN)
  114. {
  115. //Target储存四者的抽取目标
  116. double Average_Residue = 0;//平均剩余的粉球
  117. for (int i=1;i<=10000;i++)
  118. {
  119. NextRoleIsBig = CB[2].Checked;
  120. #region 获取并储存comboBox_WN的SelectedIndex属性值的代码段
  121. int CB_WN_SI;//储存comboBox_WN的SelectedIndex属性值
  122. CB_WN_SI = GetCBWNSelectedIndex();
  123. #endregion
  124. if (CB[3].Checked)//定轨不为0/2的情况
  125. Num_Weapon_Base = CB_WN_SI + 1;
  126. if (CB[3].Checked && CB_WN_SI == 0 && CB[4].Checked)
  127. NextWeaponIsUp = true;//定轨0/2歪常驻变成1/2的情况,下次必定是UP武器
  128. int N_Ball;
  129. if (CB[0].Checked) N_Ball = (int)(N / 0.9);
  130. else N_Ball = N;
  131. bool[] Process_Role_Weapon = new bool[4] { false, false, false, false };//记录四者的抽取目标达成情况
  132. int[] Reality = new int[5] { 0, 0, 0, 0, 0};//记录实际抽取到的数量,第五个表示歪的常驻(包括角色与武器)
  133. for (int j = 0; j < 4; j++)
  134. if (Target[j] == 0)
  135. Process_Role_Weapon[j] = true;//抽取目标为0的直接标记为已达成目标
  136. //然后调用方法进行模拟并通过返回值得到消耗的纠缠之缘数量
  137. if (!CB[1].Checked)
  138. {
  139. for (int j = 0; j <= 1; j++)
  140. if (!Process_Role_Weapon[j])
  141. N_Ball -= RolePrayer(Target[j], Reality, Process_Role_Weapon, j);
  142. for (int j = 2; j <= 3; j++)
  143. if (!Process_Role_Weapon[j])
  144. N_Ball -= WeaponPrayer(Target[j], Reality, Process_Role_Weapon, j);
  145. }
  146. else
  147. {//如果勾选了checkBox2,那么优先抽取武器
  148. for (int j = 2; j <= 3; j++)
  149. if (!Process_Role_Weapon[j])
  150. N_Ball -= WeaponPrayer(Target[j], Reality, Process_Role_Weapon, j);
  151. for (int j = 0; j <= 1; j++)
  152. if (!Process_Role_Weapon[j])
  153. N_Ball -= RolePrayer(Target[j], Reality, Process_Role_Weapon, j);
  154. }
  155. //然后对该次模拟结果进行统计
  156. if (i == 1 && N_Ball >= 0) Average_Residue = N_Ball;
  157. else if (N_Ball >= 0) Average_Residue = (double)(Average_Residue * (i - 1) + N_Ball) / i;
  158. else Average_Residue = (double)(Average_Residue * (i - 1)) / i;//统计平均剩余粉球
  159. if (Process_Role_Weapon[0] &&
  160. Process_Role_Weapon[1] &&
  161. Process_Role_Weapon[2] &&
  162. Process_Role_Weapon[3] &&
  163. N_Ball>=0)
  164. {//说明达成目标
  165. bool NotOver = true;
  166. for (int j = 0; j < 4; j++)
  167. NotOver = NotOver && (Reality[j] == Target[j]);
  168. NotOver = NotOver && (Reality[4] == 0);
  169. if (NotOver) Success[0]++;//这里是恰好达成目标
  170. else Success[1]++;//这里是超出预期
  171. Success_Sum++;
  172. }
  173. Invoke(new Action(() =>
  174. {
  175. if (i != 10000)
  176. label1.Text = "已进行" + i.ToString() + "次模拟……";
  177. else label1.Text = "已进行10000次模拟,每次模拟投入" + N.ToString() + "纠缠。";
  178. label_Succ_1_3.Text = "共计" + Success[0].ToString() + "次出现";
  179. label_Succ_2_3.Text = "共计" + Success[1].ToString() + "次出现";
  180. label_Succ_3_3.Text = "共计" + Success_Sum.ToString() + "次出现";
  181. }));
  182. }
  183. Avaluable = true;
  184. double[] Rate = new double[3] { (double)Success[0] / 10000,
  185. (double)Success[1] / 10000,
  186. (double)Success_Sum / 10000 };
  187. Invoke(new Action(() =>
  188. {
  189. button_Start.Text = "开始模拟";
  190. label_Succ_1_3.Text = "共计" + Success[0].ToString() + "次出现";
  191. label_Succ_2_3.Text = "共计" + Success[1].ToString() + "次出现";
  192. label_Succ_3_3.Text = "共计" + Success_Sum.ToString() + "次出现";
  193. label_Succ_1_2.Text = (Rate[0]*100).ToString() + "%";
  194. label_Succ_2_2.Text = (Rate[1]*100).ToString() + "%";
  195. label_Succ_3_2.Text = (Rate[2]*100).ToString() + "%";
  196. label_Remain.Text = "平均剩余纠缠之缘" + Average_Residue.ToString("F2") + "个";
  197. if (Rate[2] >= 0 && Rate[2] <= 0.2)
  198. label_Label.Text = "白日做梦";
  199. else if (Rate[2] > 0.2 && Rate[2] <= 0.4)
  200. label_Label.Text = "考验人品";
  201. else if (Rate[2] > 0.4 && Rate[2] <= 0.6)
  202. label_Label.Text = "成败参半";
  203. else if (Rate[2] > 0.6 && Rate[2] <= 0.8)
  204. label_Label.Text = "值得一试";
  205. else if (Rate[2] > 0.8 && Rate[2] < 1)
  206. label_Label.Text = "十拿九稳";
  207. else label_Label.Text = "板上钉钉";
  208. label_Remain.Visible = label2.Visible = label_Label.Visible = true;
  209. }));//跨线程操作
  210. Success[0] = Success[1] = Success_Sum = 0;
  211. }//进行抽卡模拟的线程
  212. private int RolePrayer(int N,int[] Re, bool[] PRW, int Code)
  213. { /* N表示目标抽取数量
  214. * Re[5]是储存实际抽到数量的数组
  215. * PRW[4]是记录目标达成情况的bool型数组
  216. */
  217. int N_Used = 0;//使用的纠缠之缘数量
  218. int RandomNumber = 0;
  219. int BaoDi = 0;//保底计数器
  220. while(Re[Code] < N)
  221. {
  222. RandomNumber = randomNum(1000);
  223. BaoDi++;
  224. N_Used++;
  225. if ((RandomNumber>=1 && RandomNumber<=6)||(BaoDi == 90))
  226. {//抽到了5星的情况
  227. if (NextRoleIsBig)//如果是大保底
  228. {
  229. Re[Code]++;
  230. NextRoleIsBig = false;
  231. }
  232. else//小保底但是不确定会不会歪常驻
  233. {
  234. RandomNumber = randomNum(1000);
  235. if (RandomNumber >= 1 && RandomNumber <= 500)//没歪
  236. Re[Code]++;
  237. else//歪了
  238. {
  239. Re[4]++;//R[4]表示歪的常驻的数量
  240. NextRoleIsBig = true;//下次就是大保底了
  241. }
  242. }
  243. BaoDi = 0;
  244. }
  245. }
  246. PRW[Code] = true;
  247. return N_Used;
  248. }//角色池祈愿的方法
  249. private int WeaponPrayer(int N, int[] Re, bool[] PRW, int Code)
  250. { /* N表示目标抽取数量
  251. * Re[5]是储存实际抽到数量的数组
  252. * PRW[4]是记录目标达成情况的bool型数组
  253. */
  254. int N_Used = 0;//使用的纠缠之缘数量
  255. int RandomNumber = 0;
  256. int BaoDi = 0;//保底计数器
  257. if (Code == 3 && Num_Weapon_Base != 0)
  258. Num_Weapon_Base = 0;//抽第二把武器的时候更换定轨,归零
  259. while (Re[Code] < N)
  260. {
  261. RandomNumber = randomNum(1000);
  262. BaoDi++;
  263. N_Used++;
  264. if ((RandomNumber >= 1 && RandomNumber <= 7) || (BaoDi == 80))
  265. {//出金的情况
  266. if (Num_Weapon_Base==2)//满定轨的情况
  267. {
  268. Re[Code]++;//必定出定轨武器
  269. Num_Weapon_Base = 0;//定轨归零
  270. }
  271. else//非满定轨
  272. {
  273. if (NextWeaponIsUp)//上一次出金歪的常驻
  274. {
  275. RandomNumber = randomNum(10);//两个UP武器中随机一个出
  276. if (RandomNumber>=1 && RandomNumber<=5)
  277. {//出了定轨武器
  278. Re[Code]++;
  279. Num_Weapon_Base = 0;
  280. }
  281. else
  282. {//歪了另一把UP武器
  283. Num_Weapon_Base++;
  284. if (Code == 2) Re[3]++;
  285. else Re[2]++;
  286. }
  287. NextWeaponIsUp = false;
  288. }
  289. else//上一次没歪常驻,包括定轨0/2时的情况
  290. {
  291. RandomNumber = randomNum(20);
  292. if (RandomNumber >= 1 && RandomNumber <= 15)//75%的概率出UP武器
  293. {
  294. RandomNumber = randomNum(10);
  295. if (RandomNumber >= 1 && RandomNumber <= 5)
  296. {//没歪
  297. Re[Code]++;
  298. Num_Weapon_Base = 0;
  299. }
  300. else
  301. {//歪了另一把UP武器
  302. Num_Weapon_Base++;
  303. if (Code == 2) Re[3]++;
  304. else Re[2]++;
  305. }
  306. }
  307. else//25%概率歪常驻了!
  308. {
  309. NextWeaponIsUp = true;
  310. Re[4]++;//获得的常驻数量+1
  311. }
  312. }
  313. }
  314. BaoDi = 0;
  315. }
  316. }
  317. PRW[Code] = true;
  318. NextWeaponIsUp = false;
  319. return N_Used;
  320. }//武器池祈愿的方法
  321. private int randomNum(int N)//使用RNGCryptoServiceProvider类生成随机数
  322. {
  323. Random r = new Random();
  324. int randomNumber;
  325. using (var rng = new RNGCryptoServiceProvider())
  326. {
  327. // 生成一个随机字节数组
  328. byte[] randomBytes = new byte[4]; // 4 bytes for a uint32
  329. rng.GetBytes(randomBytes);
  330. // 将字节数组转换为整数
  331. randomNumber = BitConverter.ToInt32(randomBytes, 0);
  332. randomNumber += r.Next();
  333. randomNumber = Math.Abs(randomNumber) % N + 1;
  334. return randomNumber;
  335. }
  336. }//生成一个范围在[1,N]的随机数的方法
  337. private void comboBox_VersionChoose_SelectedIndexChanged(object sender, EventArgs e)
  338. {
  339. ReTry://如果用户丢失了文件并选择了重试,就跳回这里
  340. //label_VersionChoose.Text = comboBox_VersionChoose.SelectedIndex.ToString();//调试用
  341. string path;
  342. bool FileLose = false;//没有文件丢失就是false
  343. path = "bins\\" + RoleName[comboBox_VersionChoose.SelectedIndex, 0] + "·头像.png";
  344. if (File.Exists(path))
  345. PB_Role_1.Image = Image.FromFile(path);
  346. else MessageBox.Show("文件丢失:" + path, "文件丢失", MessageBoxButtons.OK, MessageBoxIcon.Error);
  347. FileLose = FileLose || (!File.Exists(path));
  348. path = "bins\\" + RoleName[comboBox_VersionChoose.SelectedIndex, 1] + "·头像.png";
  349. if (File.Exists(path))
  350. PB_Role_2.Image = Image.FromFile(path);
  351. else MessageBox.Show("文件丢失:" + path, "文件丢失", MessageBoxButtons.OK, MessageBoxIcon.Error);
  352. FileLose = FileLose || (!File.Exists(path));
  353. path = "bins\\" + RoleName[comboBox_VersionChoose.SelectedIndex, 0] + "专武.png";
  354. if (File.Exists(path))
  355. PB_Weapon_1.Image = Image.FromFile(path);
  356. else MessageBox.Show("文件丢失:" + path, "文件丢失", MessageBoxButtons.OK, MessageBoxIcon.Error);
  357. FileLose = FileLose || (!File.Exists(path));
  358. path = "bins\\" + RoleName[comboBox_VersionChoose.SelectedIndex, 1] + "专武.png";
  359. if (File.Exists(path))
  360. PB_Weapon_2.Image = Image.FromFile(path);
  361. else MessageBox.Show("文件丢失:" + path, "文件丢失", MessageBoxButtons.OK, MessageBoxIcon.Error);
  362. FileLose = FileLose || (!File.Exists(path));
  363. if (FileLose)
  364. {
  365. DialogResult DR=MessageBox.Show("文件已丢失,建议旅行者找回丢失资源或尝试卸载并重新安装。", "温馨提示", MessageBoxButtons.RetryCancel, MessageBoxIcon.Information);
  366. if (DR == DialogResult.Retry)
  367. goto ReTry;
  368. else
  369. {
  370. if (Thread_Load != null)
  371. Thread_Load.Abort();
  372. if (T_Imitate != null)
  373. T_Imitate.Abort();
  374. Thread_DataDetection.Abort();
  375. Application.Exit();
  376. }
  377. }
  378. foreach (Control C in panelMain.Controls)
  379. if ((C is ComboBox) && (C!=comboBox_VersionChoose))
  380. {
  381. ComboBox CB = (ComboBox)C;
  382. CB.SelectedIndex = 0;
  383. }
  384. }//卡池选择改变时触发
  385. private void button_More_Click(object sender, EventArgs e)
  386. {
  387. Form_Poster FP = new Form_Poster(comboBox_VersionChoose.SelectedIndex);
  388. FP.Show();
  389. }
  390. private void panelMain_Paint(object sender, PaintEventArgs e)
  391. {
  392. }
  393. private void pictureBox_Exit_Click(object sender, EventArgs e)
  394. {
  395. DialogResult DR = MessageBox.Show("确认退出软件?", "询问", MessageBoxButtons.OKCancel);
  396. if (DR == DialogResult.OK)
  397. {
  398. DialogResult Dr = MessageBox.Show("祝屏幕前的旅行者十连多金、小保底不歪!", "诚挚的祝福", MessageBoxButtons.OK);
  399. if (Dr==DialogResult.OK)
  400. {
  401. if (Thread_Load != null)
  402. Thread_Load.Abort();
  403. if (T_Imitate != null)
  404. T_Imitate.Abort();
  405. Thread_DataDetection.Abort();
  406. Application.Exit();
  407. }
  408. }
  409. }
  410. private void textBox_Ball_TextChanged(object sender, EventArgs e)
  411. {
  412. if (textBox_Ball.Text == "") textBox_Ball.Text = "0";
  413. else if ((textBox_Ball.Text[0]=='0') && (textBox_Ball.Text.Length == 2))//去掉多余的0,包括光标在0右侧时输入的情况
  414. textBox_Ball.Text = textBox_Ball.Text[1].ToString();
  415. //接下来将Text属性转化为数据并存储入NUM_Ball
  416. try
  417. {
  418. NUM_Ball = int.Parse(textBox_Ball.Text);
  419. }
  420. catch (FormatException)
  421. {// 转换失败,用户可能输入了非数字字符
  422. MessageBox.Show("包含非法字符,该输入框已清空,请输入有效的数字以表示拥有的纠缠之缘的数量!", "数据无效",MessageBoxButtons.OK,MessageBoxIcon.Warning);
  423. textBox_Ball.Text = "0";
  424. NUM_Ball = 0;
  425. return;
  426. }
  427. textBox_Ball.SelectionStart = textBox_Ball.Text.Length;//每次将光标移动到末尾
  428. }
  429. private void textBox_Stone_TextChanged(object sender, EventArgs e)
  430. {
  431. if (textBox_Stone.Text == "") textBox_Stone.Text = "0";
  432. else if ((textBox_Stone.Text[0] == '0') && (textBox_Stone.Text.Length == 2))//去掉多余的0,包括光标在0右侧时输入的情况
  433. textBox_Stone.Text = textBox_Stone.Text[1].ToString();
  434. //接下来将Text属性转化为数据并存储入NUM_Stone
  435. try
  436. {
  437. NUM_Stone = int.Parse(textBox_Stone.Text);
  438. }
  439. catch (FormatException)
  440. {// 转换失败,用户可能输入了非数字字符
  441. MessageBox.Show("包含非法字符,该输入框已清空,请输入有效的数字以表示拥有的原石的数量!", "数据无效", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  442. textBox_Stone.Text = "0";
  443. NUM_Stone = 0;
  444. return;
  445. }
  446. textBox_Stone.SelectionStart = textBox_Stone.Text.Length;//每次将光标移动到末尾
  447. }
  448. private void checkBox4_CheckedChanged(object sender, EventArgs e)
  449. {
  450. if (checkBox4.Checked)
  451. comboBox_WeaponN.Enabled = true;
  452. else comboBox_WeaponN.Enabled = false;
  453. if (checkBox4.Checked && comboBox_WeaponN.SelectedIndex == 0)
  454. checkBox5.Enabled = true;
  455. else checkBox5.Enabled = false;
  456. }
  457. private void comboBox_Weapon_1_SelectedIndexChanged(object sender, EventArgs e)
  458. {
  459. if (comboBox_Weapon_1.SelectedIndex + comboBox_Weapon_2.SelectedIndex == 0)
  460. checkBox5.Enabled = checkBox4.Enabled = false;
  461. else checkBox5.Enabled = checkBox4.Enabled = true;//不计划抽取武器,则无法选取武器池定轨选项
  462. if ((comboBox_Weapon_1.SelectedIndex + comboBox_Weapon_2.SelectedIndex == 0) ||
  463. (comboBox_Role_1.SelectedIndex + comboBox_Role_2.SelectedIndex == 0))
  464. checkBox2.Enabled = false;
  465. else checkBox2.Enabled = true;//武器角色二种只抽取一种则无法选取“优先抽取武器”
  466. }
  467. private void comboBox_Weapon_2_SelectedIndexChanged(object sender, EventArgs e)
  468. {
  469. if (comboBox_Weapon_1.SelectedIndex + comboBox_Weapon_2.SelectedIndex == 0)
  470. checkBox5.Enabled = checkBox4.Enabled = false;
  471. else checkBox5.Enabled = checkBox4.Enabled = true;//不计划抽取武器,则无法选取武器池定轨选项
  472. if ((comboBox_Weapon_1.SelectedIndex + comboBox_Weapon_2.SelectedIndex == 0) ||
  473. (comboBox_Role_1.SelectedIndex + comboBox_Role_2.SelectedIndex == 0))
  474. checkBox2.Enabled = false;
  475. else checkBox2.Enabled = true;//武器角色二种只抽取一种则无法选取“优先抽取武器”
  476. }
  477. private void comboBox_Role_1_SelectedIndexChanged(object sender, EventArgs e)
  478. {
  479. if ((comboBox_Weapon_1.SelectedIndex + comboBox_Weapon_2.SelectedIndex == 0) ||
  480. (comboBox_Role_1.SelectedIndex + comboBox_Role_2.SelectedIndex == 0))
  481. checkBox2.Enabled = false;
  482. else checkBox2.Enabled = true;//武器角色二种只抽取一种则无法选取“优先抽取武器”
  483. if (comboBox_Role_1.SelectedIndex + comboBox_Role_2.SelectedIndex == 0)
  484. checkBox1.Enabled = checkBox3.Enabled = false;
  485. else checkBox1.Enabled = checkBox3.Enabled = true;//不抽取角色则无法选择“角色卡池为9折”
  486. }
  487. private void comboBox_Role_2_SelectedIndexChanged(object sender, EventArgs e)
  488. {
  489. if ((comboBox_Weapon_1.SelectedIndex + comboBox_Weapon_2.SelectedIndex == 0) ||
  490. (comboBox_Role_1.SelectedIndex + comboBox_Role_2.SelectedIndex == 0))
  491. checkBox2.Enabled = false;
  492. else checkBox2.Enabled = true;//武器角色二种只抽取一种则无法选取“优先抽取武器”
  493. if (comboBox_Role_1.SelectedIndex + comboBox_Role_2.SelectedIndex == 0)
  494. checkBox1.Enabled = checkBox3.Enabled = false;
  495. else checkBox1.Enabled = checkBox3.Enabled = true;//不抽取角色则无法选择“角色卡池为9折”
  496. }
  497. private void button_Transport_Click(object sender, EventArgs e)
  498. {
  499. if (NUM_Stone>=160)
  500. {
  501. NUM_Ball += NUM_Stone / 160;
  502. NUM_Stone = NUM_Stone - NUM_Stone / 160 * 160;
  503. textBox_Ball.Text = NUM_Ball.ToString();
  504. textBox_Stone.Text = NUM_Stone.ToString();
  505. }
  506. }
  507. private void button_Start_Click(object sender, EventArgs e)
  508. {
  509. int Ball = NUM_Ball + NUM_Stone / 160;//抽取的次数
  510. bool NotSelectedTarget = (comboBox_Role_1.SelectedIndex == 0) &&
  511. (comboBox_Role_2.SelectedIndex == 0) &&
  512. (comboBox_Weapon_1.SelectedIndex == 0) &&
  513. (comboBox_Weapon_2.SelectedIndex == 0);//如果全部为0,就说明没有选择,那么值为true
  514. if ((Ball>0 && Ball<=999)&&(checkBox_Ensure.Checked)&&(!NotSelectedTarget))
  515. {
  516. //先将数据清空表示所有给出的资源全部用于抽卡
  517. NUM_Ball = 0;
  518. NUM_Stone -= NUM_Stone / 160 * 160;
  519. textBox_Ball.Text = NUM_Ball.ToString();
  520. textBox_Stone.Text = NUM_Stone.ToString();
  521. label_Succ_1_3.Visible = label_Succ_2_3.Visible = label_Succ_3_3.Visible = true;
  522. //接下来调用线程进行模拟
  523. int[] Temp = new int[4] {comboBox_Role_1.SelectedIndex,
  524. comboBox_Role_2.SelectedIndex,
  525. comboBox_Weapon_1.SelectedIndex,
  526. comboBox_Weapon_2.SelectedIndex};//简单粗暴地避免跨线程访问问题
  527. NextRoleIsBig = checkBox3.Checked;
  528. if (checkBox4.Checked)//定轨不为0/2的情况
  529. Num_Weapon_Base = comboBox_WeaponN.SelectedIndex + 1;
  530. if (checkBox4.Checked && comboBox_WeaponN.SelectedIndex == 0 && checkBox5.Checked)
  531. NextWeaponIsUp = true;//定轨0/2歪常驻变成1/2的情况,下次必定是UP武器
  532. CheckBox[] CB = new CheckBox[5] { checkBox1, checkBox2, checkBox3, checkBox4, checkBox5 };
  533. T_Imitate = new Thread(() => imitate(Ball,Temp, CB, comboBox_WeaponN));
  534. T_Imitate.Start();
  535. Avaluable = false;
  536. button_Start.Text = "正在模拟,请稍等……";
  537. }
  538. else if (!(checkBox_Ensure.Checked))
  539. MessageBox.Show("请仔细阅读用户须知并勾选下方选项!");
  540. else
  541. {
  542. if (NotSelectedTarget)
  543. MessageBox.Show("请选择你的抽取目标!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information);
  544. else
  545. {
  546. MessageBox.Show("填入的已有资源超过允许模拟的最大限度!", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  547. NUM_Ball = NUM_Stone = 0;
  548. textBox_Ball.Text = textBox_Stone.Text = "0";
  549. }
  550. }
  551. textBox_Ball.SelectionStart = textBox_Ball.Text.Length;
  552. }
  553. private void linkLabel_ScreenShot_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  554. {
  555. try
  556. {
  557. linkLabel_ScreenShot.Visible = false;
  558. //接下来开始截图与保存操作
  559. Bitmap BM = new Bitmap(this.ClientSize.Width, this.ClientSize.Height);
  560. using (Graphics G = Graphics.FromImage(BM))
  561. {
  562. G.CopyFromScreen(this.PointToScreen(new Point(0, 0)), Point.Empty, this.ClientSize);
  563. }
  564. DateTime CurruntTime = DateTime.Now;
  565. string FileName = "ScreenShot_" + CurruntTime.ToString("yyyyMMddHHmmss") + ".png";
  566. BM.Save("bins\\ScreenShot\\" + FileName, System.Drawing.Imaging.ImageFormat.Png);
  567. //到此
  568. linkLabel_ScreenShot.Visible = true;
  569. MessageBox.Show("截图已保存至 安装目录/bins/ScreenShot/" + FileName);
  570. }
  571. catch(Exception Ex)
  572. {
  573. MessageBox.Show("发生错误:" + Ex.Message);
  574. }
  575. }
  576. private void label_Succ_2_2_Click(object sender, EventArgs e)
  577. {
  578. }
  579. private void label_Succ_2_3_Click(object sender, EventArgs e)
  580. {
  581. }
  582. private void label_Succ_2_1_Click(object sender, EventArgs e)
  583. {
  584. }
  585. private void comboBox_WeaponN_SelectedIndexChanged(object sender, EventArgs e)
  586. {
  587. if (checkBox4.Checked && comboBox_WeaponN.SelectedIndex == 0)
  588. checkBox5.Enabled = true;
  589. else checkBox5.Enabled = false;
  590. }
  591. private void checkBox1_CheckedChanged(object sender, EventArgs e)
  592. {
  593. }
  594. private void pictureBox_README_Click(object sender, EventArgs e)
  595. {
  596. README RM = new README();
  597. RM.Show();
  598. }
  599. }
  600. }

2.Form_Poster页面(祈愿海报页面)

设计器:

页面代码:

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Threading;
  11. using System.IO;
  12. namespace 概率计算器___Genshin_Impact
  13. {
  14. public partial class Form_Poster : Form
  15. {
  16. public Form_Poster(int N_Mode)
  17. {
  18. InitializeComponent();
  19. Mode = N_Mode;
  20. pictureBox_Down.DoubleClick += pictureBox_Down_Click;
  21. pictureBox_Up.DoubleClick += pictureBox_Up_Click;
  22. }
  23. #region 变量的声明
  24. public int Mode = 0;
  25. Thread TTF = null;
  26. public int CurruntPage = 1;
  27. string[,] RoleName = new string[4, 2] {
  28. {"娜维娅", "神里绫华" },//4.3上半卡池,卡池编码为0
  29. {"雷电将军", "宵宫" },//4.3下半卡池,卡池编码为1
  30. { "闲云", "纳西妲" }, //4.4上半卡池,卡池编码为2
  31. { "魈", "八重神子" }//4.4下半卡池,卡池编码为3
  32. };
  33. //第一维度为版本编号,第二维度为卡池序号
  34. //比如4.4上半对应第一维度,而角色祈愿-2对应第二维度
  35. //角色池图片名称为RoleName[m,n] + ".png"
  36. //武器池图片名称为RoleName[m,0] + "-" + RoleName[m,1] + "-专武.png"
  37. #endregion
  38. private void Form_Poster_Load(object sender, EventArgs e)
  39. {
  40. this.Opacity = 0;
  41. TTF = new Thread(() => Thread_TransparencyFade());
  42. TTF.Start();
  43. foreach (Control Con in this.Controls)
  44. Con.BackColor = Color.FromArgb(0, 0, 0, 0);
  45. ReTrySearchFile://如果选择ReTry就跳回这里
  46. string path;
  47. bool FileLose = false;//文件没丢失就是false
  48. path = "bins\\" + RoleName[Mode, 0] + ".png";
  49. if (File.Exists(path))
  50. pictureBox_Role_1.Image = Image.FromFile(path);
  51. else MessageBox.Show("文件丢失:" + path, "文件丢失", MessageBoxButtons.OK, MessageBoxIcon.Error);
  52. FileLose = FileLose || (!File.Exists(path));
  53. path = "bins\\" + RoleName[Mode, 1] + ".png";
  54. if (File.Exists(path))
  55. pictureBox_Role_2.Image = Image.FromFile(path);
  56. else MessageBox.Show("文件丢失:" + path, "文件丢失", MessageBoxButtons.OK, MessageBoxIcon.Error);
  57. FileLose = FileLose || (!File.Exists(path));
  58. path = "bins\\" + RoleName[Mode, 0] + "-" + RoleName[Mode, 1] + "-专武.png";
  59. if (File.Exists(path))
  60. pictureBox_Weapon.Image = Image.FromFile(path);
  61. else MessageBox.Show("文件丢失:" + path, "文件丢失", MessageBoxButtons.OK, MessageBoxIcon.Error);
  62. FileLose = FileLose || (!File.Exists(path));
  63. if (FileLose)
  64. {//文件已丢失
  65. DialogResult DR = MessageBox.Show("文件已丢失,建议旅行者找回丢失资源或尝试卸载并重新安装。", "温馨提示", MessageBoxButtons.RetryCancel, MessageBoxIcon.Information);
  66. if (DR == DialogResult.Retry)
  67. goto ReTrySearchFile;
  68. else
  69. {
  70. if (TTF != null)
  71. TTF.Abort();
  72. Application.Exit();
  73. }
  74. }
  75. pictureBox_Role_2.Location = pictureBox_Weapon.Location = pictureBox_Role_1.Location;
  76. pictureBox_Role_2.Visible = pictureBox_Weapon.Visible = false;
  77. }
  78. private void Thread_TransparencyFade()
  79. {
  80. int transparency = -5;
  81. do
  82. {
  83. transparency += 5;
  84. Invoke(new Action(() =>
  85. {
  86. this.Opacity = (double)transparency / 100;
  87. }));//跨线程操作
  88. Thread.Sleep(5);
  89. } while (transparency < 100);
  90. }//透明淡入的线程
  91. private void Thread_Out()
  92. {
  93. int transparency = 105;
  94. do
  95. {
  96. transparency -= 5;
  97. Invoke(new Action(() =>
  98. {
  99. this.Opacity = (double)transparency / 100;
  100. }));//跨线程操作
  101. Thread.Sleep(5);
  102. } while (transparency > 0);
  103. Invoke(new Action(() =>
  104. {
  105. this.Close();
  106. }));//跨线程操作
  107. }//透明淡出的线程
  108. private void pictureBox_Out_Click(object sender, EventArgs e)
  109. {
  110. if (TTF != null)
  111. {
  112. TTF.Abort();
  113. TTF = new Thread(() => Thread_Out());
  114. TTF.Start();
  115. }
  116. }
  117. private void pictureBox_Up_Click(object sender, EventArgs e)
  118. {
  119. if (CurruntPage >= 2) CurruntPage--;
  120. else CurruntPage = 3;
  121. switch(CurruntPage)
  122. {
  123. case 1:
  124. pictureBox_Role_2.Visible = false;
  125. pictureBox_Role_1.Visible = true;
  126. break;
  127. case 2:
  128. pictureBox_Weapon.Visible = false;
  129. pictureBox_Role_2.Visible = true;
  130. break;
  131. case 3:
  132. pictureBox_Role_1.Visible = false;
  133. pictureBox_Weapon.Visible = true;
  134. break;
  135. }
  136. }
  137. private void pictureBox_Down_Click(object sender, EventArgs e)
  138. {
  139. if (CurruntPage <= 3) CurruntPage++;
  140. else CurruntPage = 1;
  141. switch (CurruntPage)
  142. {
  143. case 1:
  144. pictureBox_Weapon.Visible = false;
  145. pictureBox_Role_1.Visible = true;
  146. break;
  147. case 2:
  148. pictureBox_Role_1.Visible = false;
  149. pictureBox_Role_2.Visible = true;
  150. break;
  151. case 3:
  152. pictureBox_Role_2.Visible = false;
  153. pictureBox_Weapon.Visible = true;
  154. break;
  155. }
  156. }
  157. }
  158. }

3.README页面(说明页面)

设计器:

页面代码:

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Diagnostics;
  11. namespace 概率计算器___Genshin_Impact
  12. {
  13. public partial class README : Form
  14. {
  15. public README()
  16. {
  17. InitializeComponent();
  18. }
  19. private void README_Load(object sender, EventArgs e)
  20. {
  21. }
  22. private void label_Link_Click(object sender, EventArgs e)
  23. {
  24. try
  25. {
  26. Process.Start("http://sherrychou.blog.csdn.net");
  27. }
  28. catch (Exception E)
  29. {
  30. MessageBox.Show("出现错误:" + E.Message, "出错啦", MessageBoxButtons.OK, MessageBoxIcon.Error);
  31. }
  32. this.Close();
  33. }
  34. private void pictureBox1_Click(object sender, EventArgs e)
  35. {
  36. }
  37. }
  38. }

4. 应用程序清单文件

将以下代码取消注释。

  1. <application xmlns="urn:schemas-microsoft-com:asm.v3">
  2. <windowsSettings>
  3. <dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
  4. </windowsSettings>
  5. </application>

四、其他说明

1.本软件不用于盈利,也不允许被用于盈利,如发现用该软件盈利的行为,欢迎举报!

2.本软件内的一切图片素材版权仍归 上海米哈游网络科技股份有限公司 与 上海米哈游天命科技有限公司 所有。

3.使用过程中如发现任何不应该出现的技术问题,欢迎联系作者反馈!

文章字数统计君:22565字

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/201923?site
推荐阅读
相关标签
  

闽ICP备14008679号