This commit is contained in:
Putoo
2026-06-08 18:56:28 +08:00
parent 1927e3f960
commit 9f3e4871a4
23 changed files with 1113 additions and 19 deletions

View File

@@ -158,7 +158,7 @@ public class GameBus
isok = false;
}
}
else if (item.code ==nameof( GameEnum.PropCode.vigour)) //活力
else if (item.code == nameof(GameEnum.PropCode.vigour)) //活力
{
var attrService = App.GetService<IUnitUserAttrService>();
var MyAcc = await attrService.GetUserVigourInfo(userId);
@@ -168,7 +168,7 @@ public class GameBus
isok = false;
}
}
else if (item.code ==nameof( GameEnum.PropCode.lev))
else if (item.code == nameof(GameEnum.PropCode.lev))
{
var attrService = App.GetService<IUnitUserAttrService>();
var MyLev = await attrService.GetUserLev(userId);
@@ -177,6 +177,7 @@ public class GameBus
isok = false;
}
}
result.result = isok;
result.isDeal = isDeal;
result.isGive = isGive;
@@ -218,4 +219,102 @@ public class GameBus
}
#endregion
#region
public static List<TowerGet> GetRandomGoods(RandomModel random, int count = 1, int luck = 0)
{
List<TowerGet> result = new List<TowerGet>();
for (int i = 0; i < count; i++)
{
List<RandomData> timeAward = new List<RandomData>();
if (random.code == nameof(RandomModel.RandomCode.Weight))
{
timeAward = RandomHandleByWeight(random, luck);
}
else
{
timeAward = RandomHandleByChance(random, luck);
}
foreach (var item in timeAward)
{
var onAward = result.FindIndex(it => it.code == item.code && it.parameter == item.par);
if(onAward>-1)
{
result[onAward].count += item.count;
}
else
{
TowerGet add = new TowerGet()
{
code = item.code,
name = item.name,
parameter = item.par,
count = item.count
};
result.Add(add);
}
}
}
return result;
}
private static List<RandomData> RandomHandleByWeight(RandomModel random, int luck = 0)
{
var _randomInstance = new Random();
List<RandomData> result = new List<RandomData>();
int empty = random.empty - luck;
if (_randomInstance.Next(0, 100) < empty)
{
return result;
}
if (random.data.Count == 0)
{
return result;
}
double totalWeight = random.data.Sum(it => it.chance);
int rnd = _randomInstance.Next(Convert.ToInt32(totalWeight) + 1);
double current = 0;
foreach (var item in random.data)
{
current += item.chance;
if (rnd < current)
{
result.Add(item);
return result;
}
}
return result;
}
private static List<RandomData> RandomHandleByChance(RandomModel random, int luck = 0)
{
var _randomInstance = new Random();
List<RandomData> result = new List<RandomData>();
int empty = random.empty - luck;
if (_randomInstance.Next(0, 100) < empty)
{
return result;
}
if (random.data.Count == 0)
{
return result;
}
foreach (var item in random.data)
{
double rnd = _randomInstance.NextDouble();
double okChance = item.chance / 100;
if (rnd < okChance)
{
result.Add(item);
}
}
return result;
}
#endregion
}

View File

@@ -13,6 +13,7 @@ public class UserModelTool
UserModel result = new UserModel();
if (userId == "0")
{
result.userId = "0";
result.userNo = "0";
result.nick = "海精灵";
result.sex = "女";
@@ -29,6 +30,7 @@ public class UserModelTool
var userInfo = await userService.GetUserInfoByUserId(userId);
if (userInfo != null)
{
result.userId = userInfo.userId;
result.userNo = userInfo.userNo;
result.nick = userInfo.nick;
result.sex = userInfo.sex;