12121
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
namespace Application.Domain;
|
||||
|
||||
public class GameBus
|
||||
public static class GameBus
|
||||
{
|
||||
#region 物品资源操作
|
||||
|
||||
@@ -96,20 +96,24 @@ public class GameBus
|
||||
|
||||
#region 验证
|
||||
|
||||
public static async Task<CheckTowerNeed> CheakNeed(string userId, TowerNeed item, string sid, int count = 1)
|
||||
public static async Task<CheckTowerNeed> CheckNeed(string userId, TowerNeed item, int count = 1)
|
||||
{
|
||||
CheckTowerNeed result = new CheckTowerNeed();
|
||||
result.Needs = new List<TowerNeed>();
|
||||
bool isok = true;
|
||||
int isDeal = 1;
|
||||
int isGive = 1;
|
||||
|
||||
item.isAsk = 1;
|
||||
if (item.code == nameof(GameEnum.PropCode.Equ))
|
||||
{
|
||||
var equService = App.GetService<IGameEquService>();
|
||||
int MyCount = await equService.GetUserEquByEquIdCount(userId, Convert.ToInt32(item.parameter));
|
||||
int neecCount = item.count * count;
|
||||
if (MyCount < neecCount)
|
||||
long needCount = item.count * count;
|
||||
item.count = needCount;
|
||||
item.onCount = MyCount;
|
||||
if (MyCount < needCount)
|
||||
{
|
||||
item.isAsk = 0;
|
||||
isok = false;
|
||||
}
|
||||
}
|
||||
@@ -132,29 +136,38 @@ public class GameBus
|
||||
}
|
||||
}
|
||||
|
||||
int needCount = item.count * count;
|
||||
long needCount = item.count * count;
|
||||
item.count = needCount;
|
||||
item.onCount = MyCount;
|
||||
if (MyCount < needCount)
|
||||
{
|
||||
isok = false;
|
||||
item.isAsk = 0;
|
||||
}
|
||||
}
|
||||
else if (item.code == nameof(GameEnum.PropCode.copper))
|
||||
{
|
||||
var accService = App.GetService<IUnitUserAccService>();
|
||||
var MyAcc = await accService.GetUserAccInfo(userId, nameof(AccEnum.AccType.copper));
|
||||
decimal needAcc = item.count * count;
|
||||
long needAcc = item.count * count;
|
||||
item.count = needAcc;
|
||||
item.onCount = MyAcc;
|
||||
if (MyAcc < needAcc)
|
||||
{
|
||||
isok = false;
|
||||
item.isAsk = 0;
|
||||
}
|
||||
}
|
||||
else if (item.code == nameof(GameEnum.PropCode.gold))
|
||||
{
|
||||
var accService = App.GetService<IUnitUserAccService>();
|
||||
var MyAcc = await accService.GetUserAccInfo(userId, nameof(AccEnum.AccType.gold));
|
||||
decimal needAcc = item.count * count;
|
||||
long needAcc = item.count * count;
|
||||
item.count = needAcc;
|
||||
item.onCount = MyAcc;
|
||||
if (MyAcc < needAcc)
|
||||
{
|
||||
item.isAsk = 0;
|
||||
isok = false;
|
||||
}
|
||||
}
|
||||
@@ -162,9 +175,12 @@ public class GameBus
|
||||
{
|
||||
var attrService = App.GetService<IUnitUserAttrService>();
|
||||
var MyAcc = await attrService.GetUserVigourInfo(userId);
|
||||
decimal neecAcc = item.count * count;
|
||||
if (MyAcc.vitality < neecAcc)
|
||||
long needAcc = item.count * count;
|
||||
item.count = needAcc;
|
||||
item.onCount = (long)MyAcc.vitality;
|
||||
if (MyAcc.vitality < needAcc)
|
||||
{
|
||||
item.isAsk = 0;
|
||||
isok = false;
|
||||
}
|
||||
}
|
||||
@@ -172,6 +188,8 @@ public class GameBus
|
||||
{
|
||||
var attrService = App.GetService<IUnitUserAttrService>();
|
||||
var MyLev = await attrService.GetUserLev(userId);
|
||||
item.count = item.count;
|
||||
item.onCount = MyLev;
|
||||
if (MyLev < item.count)
|
||||
{
|
||||
isok = false;
|
||||
@@ -181,18 +199,20 @@ public class GameBus
|
||||
result.result = isok;
|
||||
result.isDeal = isDeal;
|
||||
result.isGive = isGive;
|
||||
result.Needs.Add(item);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async Task<CheckTowerNeed> CheakNeed(string userId, List<TowerNeed> needs, string sid, int count = 1)
|
||||
public static async Task<CheckTowerNeed> CheckNeed(string userId, List<TowerNeed> needs, int count = 1)
|
||||
{
|
||||
CheckTowerNeed result = new CheckTowerNeed();
|
||||
result.Needs = new List<TowerNeed>();
|
||||
bool isok = true;
|
||||
int isDeal = 1;
|
||||
int isGive = 1;
|
||||
foreach (var item in needs)
|
||||
{
|
||||
var cheakResult = await CheakNeed(userId, item, sid, count);
|
||||
var cheakResult = await CheckNeed(userId, item, count);
|
||||
if (isok)
|
||||
{
|
||||
isok = cheakResult.result;
|
||||
@@ -208,7 +228,116 @@ public class GameBus
|
||||
isGive = 0;
|
||||
}
|
||||
|
||||
item.isAsk = cheakResult.result ? 1 : 0;
|
||||
result.Needs.AddRange(cheakResult.Needs);
|
||||
}
|
||||
|
||||
result.result = isok;
|
||||
result.isDeal = isDeal;
|
||||
result.isGive = isGive;
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async Task<CheckTowerNeeds> CheckNeeds(string userId, List<TowerNeeds> needs, int count = 1)
|
||||
{
|
||||
CheckTowerNeeds result = new CheckTowerNeeds();
|
||||
bool isok = true;
|
||||
int isDeal = 1;
|
||||
int isGive = 1;
|
||||
result.Needs = new List<TowerNeeds>();
|
||||
foreach (var item in needs)
|
||||
{
|
||||
item.isAsk = 1;
|
||||
if (item.code == nameof(GameEnum.PropCode.Equ))
|
||||
{
|
||||
var equService = App.GetService<IGameEquService>();
|
||||
int MyCount = await equService.GetUserEquByEquIdCount(userId, Convert.ToInt32(item.parameter));
|
||||
long needCount = item.count * count;
|
||||
item.count = needCount;
|
||||
item.onCount = MyCount;
|
||||
if (MyCount < needCount)
|
||||
{
|
||||
item.isAsk = 0;
|
||||
isok = false;
|
||||
}
|
||||
}
|
||||
else if (item.code == nameof(GameEnum.PropCode.Goods))
|
||||
{
|
||||
int MyCount = 0;
|
||||
var goodsService = App.GetService<IGameGoodsService>();
|
||||
var goodsInfo = await goodsService.GetUserGoodsInfo(userId, Convert.ToInt32(item.parameter));
|
||||
if (goodsInfo != null)
|
||||
{
|
||||
MyCount = (int)goodsInfo.count;
|
||||
if (goodsInfo.isDeal == 0)
|
||||
{
|
||||
isDeal = 0;
|
||||
}
|
||||
|
||||
if (goodsInfo.isGive == 0)
|
||||
{
|
||||
isGive = 0;
|
||||
}
|
||||
}
|
||||
|
||||
long needCount = item.count * count;
|
||||
item.count = needCount;
|
||||
item.onCount = MyCount;
|
||||
if (MyCount < needCount)
|
||||
{
|
||||
isok = false;
|
||||
item.isAsk = 0;
|
||||
}
|
||||
}
|
||||
else if (item.code == nameof(GameEnum.PropCode.copper))
|
||||
{
|
||||
var accService = App.GetService<IUnitUserAccService>();
|
||||
var MyAcc = await accService.GetUserAccInfo(userId, nameof(AccEnum.AccType.copper));
|
||||
long needAcc = item.count * count;
|
||||
item.count = needAcc;
|
||||
item.onCount = MyAcc;
|
||||
if (MyAcc < needAcc)
|
||||
{
|
||||
isok = false;
|
||||
item.isAsk = 0;
|
||||
}
|
||||
}
|
||||
else if (item.code == nameof(GameEnum.PropCode.gold))
|
||||
{
|
||||
var accService = App.GetService<IUnitUserAccService>();
|
||||
var MyAcc = await accService.GetUserAccInfo(userId, nameof(AccEnum.AccType.gold));
|
||||
long needAcc = item.count * count;
|
||||
item.count = needAcc;
|
||||
item.onCount = MyAcc;
|
||||
if (MyAcc < needAcc)
|
||||
{
|
||||
item.isAsk = 0;
|
||||
isok = false;
|
||||
}
|
||||
}
|
||||
else if (item.code == nameof(GameEnum.PropCode.vigour)) //活力
|
||||
{
|
||||
var attrService = App.GetService<IUnitUserAttrService>();
|
||||
var MyAcc = await attrService.GetUserVigourInfo(userId);
|
||||
long needAcc = item.count * count;
|
||||
item.count = needAcc;
|
||||
item.onCount = (long)MyAcc.vitality;
|
||||
if (MyAcc.vitality < needAcc)
|
||||
{
|
||||
item.isAsk = 0;
|
||||
isok = false;
|
||||
}
|
||||
}
|
||||
else if (item.code == nameof(GameEnum.PropCode.lev))
|
||||
{
|
||||
var attrService = App.GetService<IUnitUserAttrService>();
|
||||
var MyLev = await attrService.GetUserLev(userId);
|
||||
item.count = item.count;
|
||||
item.onCount = MyLev;
|
||||
if (MyLev < item.count)
|
||||
{
|
||||
isok = false;
|
||||
}
|
||||
}
|
||||
result.Needs.Add(item);
|
||||
}
|
||||
|
||||
@@ -240,7 +369,7 @@ public class GameBus
|
||||
foreach (var item in timeAward)
|
||||
{
|
||||
var onAward = result.FindIndex(it => it.code == item.code && it.parameter == item.par);
|
||||
if(onAward>-1)
|
||||
if (onAward > -1)
|
||||
{
|
||||
result[onAward].count += item.count;
|
||||
}
|
||||
@@ -256,7 +385,6 @@ public class GameBus
|
||||
result.Add(add);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -271,10 +399,12 @@ public class GameBus
|
||||
{
|
||||
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;
|
||||
@@ -290,6 +420,7 @@ public class GameBus
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static List<RandomData> RandomHandleByChance(RandomModel random, int luck = 0)
|
||||
{
|
||||
var _randomInstance = new Random();
|
||||
@@ -299,11 +430,12 @@ public class GameBus
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
if (random.data.Count == 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
foreach (var item in random.data)
|
||||
{
|
||||
double rnd = _randomInstance.NextDouble();
|
||||
@@ -313,6 +445,7 @@ public class GameBus
|
||||
result.Add(item);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user