/// <summary> /// 进行随机抽卡,有保底机制 /// </summary> /// <param name="cp"></param> /// <returns></returns> public static int RandomGacha(PoolInfo cp) { int probablity_total = 0; //计算概率和,作为取随机数的上限 //乘10000为了加大精度,不使用NextDouble是因为NextDouble局限于0.0-1.0,对填入概率有要求,友好度down foreach (var item in cp.PoolContents) { probablity_total += Convert.ToInt32(item.Probablity * 10000); } int pro = new Random(Helper.GetRandomSeed()).Next(probablity_total + 1); //用于标记遍历元素的概率之和 //若取到的随机数小于temp值,说明概率落在了上一个元素与这个元素之间 double temp = 0; //用于标记是第几个元素,由于foreach无标记进度的变量,所以需要构造一个变量 int count = 0; foreach (var item in cp.PoolContents) { //保底系统 if (Gacha_Baodi == cp.BaodiNum) { //取出所有是保底的元素 var c = cp.PoolContents.Where(x => x.IsBaodi == true).ToList(); foreach (var item_Baodi in c) { probablity_total += Convert.ToInt32(item_Baodi.Probablity * 10000); } pro = new Random(Helper.GetRandomSeed()).Next(probablity_total + 1); double temp2 = 0; //从保底中再次按照概率选取一个 foreach (var item2 in c) { temp2 += item2.Probablity; if ((double)pro / 10000 <= temp2) { //达到保底,重置保底进度 Gacha_Baodi = 1; return(cp.PoolContents.IndexOf(item2)); } } } temp += item.Probablity; if ((double)pro / 10000 <= temp) { //抽到角色,保底数目+1 Gacha_Baodi++; //对象是保底,保底进度清空 if (item.IsBaodi) { Gacha_Baodi = 1; } return(count); } count++; } return(cp.PoolContents.Count - 1); }
/// <summary> /// 按照抽卡结果生成图片 /// </summary> /// <param name="count">抽卡次数</param> /// <returns></returns> public static string GetPicPath(int count, PoolInfo poolInfo, QMGroupMessageEventArgs e) { List <PoolContent> ls = new List <PoolContent>(); for (int i = 0; i < count; i++) { var item = poolInfo.PoolContents[RandomGacha(poolInfo)]; ls = FoldItem(item, ls); } SQLHelper.SubDiamond(e, poolInfo.PerGachaConsumption * count); PicHelper combine = new PicHelper(); ls = ls.OrderByDescending(x => x.Value).ToList(); string CQAt = poolInfo.ResultAt ? $"[@{e.FromQQ.Id}]" : string.Empty; return(CQAt + combine.GeneratePic(poolInfo, ls, SQLHelper.GetDiamond(e))); }
/// <summary> /// 判断能否抽卡,并发送一定的自定义信息 /// </summary> /// <param name="e"></param> /// <param name="poolInfo"></param> /// <param name="count"></param> /// <returns></returns> public static bool CanGacha(QMGroupMessageEventArgs e, PoolInfo poolInfo, int count) { if (!Helper.GroupInConfig(e)) { return(false); } if (!SQLHelper.IDExist(e)) { QMApi.CurrentApi.SendGroupMessage(e.RobotQQ, e.FromGroup, PublicArgs.noReg.Replace ("<@>", $"[@{e.FromQQ.Id}]")); return(false); } int diamond = SQLHelper.GetDiamond(e); if (diamond < count * poolInfo.PerGachaConsumption) { QMApi.CurrentApi.SendGroupMessage(e.RobotQQ, e.FromGroup, PublicArgs.lowDiamond.Replace ("<@>", $"[@{e.FromQQ.Id}]").Replace("<#>", diamond.ToString())); return(false); } QMApi.CurrentApi.SendGroupMessage(e.RobotQQ, e.FromGroup, PublicArgs.BP10.Replace ("<@>", $"[@{e.FromQQ.Id}]")); return(true); }
/// <summary> /// 生成图片,返回图片CQ码路径 /// </summary> /// <param name="cp">存放池子信息的对象</param> /// <param name="ls">抽卡结果数组</param> /// <param name="Diamond">目标水晶数目</param> /// <returns></returns> public string GeneratePic(PoolInfo cp, List <PoolContent> ls, int Diamond) { try { int x, y; x = 160; y = 190; //$@"{dir}\装备卡\框\抽卡背景.png" Image background = Image.FromFile(cp.BackgroundImg); Image img = null; Random rd = new Random(); foreach (var item in ls) { img = GenerateCard(item); background = CombinImage(background, img, x, y); if (x < 1960) { x += 300; } else { if (y == 190) { x = 160; y = 530; } else { break; } } } background = CombinImage(background, Image.FromFile(cp.InfoPicPath), 126, 960); //金币 int money = rd.Next(100000, 100000000); Image img_1 = Money(money); int Width_Gold = 1620 + (164 - img_1.Width) / 2; background = CombinImage(background, img_1, Width_Gold, Height_1); //水晶 Image img_2 = this.Diamond(Diamond); int Width_Diamond = 1975 + (111 - img_2.Width) / 2; background = CombinImage(background, img_2, Width_Diamond, Height_1); //体力 int ap_Max = rd.Next(154, 165); int ap = rd.Next(0, ap_Max); Image img_3 = AP(ap, ap_Max); int Width_AP = 1319 + (127 - img_3.Width) / 2; background = CombinImage(background, img_3, Width_AP, Height_1); //水印 Point p = new Point(1471, 813); Font font = new Font("汉仪丫丫体简", 15F); Color color = Color.FromArgb(0, 0, 0); background = AddText2Image(background, "Powered by @水银之翼", p, font, color); string name = GetDate(); if (!Directory.Exists($@"{MainSave.ImageDirectory}\\装备结果")) { Directory.CreateDirectory($@"{MainSave.ImageDirectory}\\装备结果"); } ini = new IniConfig(dir + "\\Config.ini"); ini.Load(); if (ini.Object["ExtraConfig"]["ImageFormat"].GetValueOrDefault("jpg") == "jpg") { background.Save($@"{MainSave.ImageDirectory}\\装备结果\{name}.jpg", ImageFormat.Jpeg); return($"[pic=装备结果\\{name}.jpg]"); } else { background.Save($@"{dir}\\装备结果\{name}.png"); return($"[pic=装备结果\\{name}.png]"); } } catch (Exception e) { QMLog.CurrentApi.Info($"抽卡图片生成,生成错误,错误信息:{e.Message}"); return(null); } }