This commit is contained in:
Putoo
2026-06-04 18:25:31 +08:00
parent 8b8eb732ae
commit 1a1f12abf5
20 changed files with 772 additions and 18 deletions

View File

@@ -93,4 +93,129 @@ public class GameBus
}
#endregion
#region
public static async Task<CheckTowerNeed> CheakNeed(string userId, TowerNeed item, string sid, int count = 1)
{
CheckTowerNeed result = new CheckTowerNeed();
bool isok = true;
int isDeal = 1;
int isGive = 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)
{
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;
}
}
int needCount = item.count * count;
if (MyCount < needCount)
{
isok = false;
}
}
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;
if (MyAcc < needAcc)
{
isok = false;
}
}
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;
if (MyAcc < needAcc)
{
isok = false;
}
}
else if (item.code ==nameof( GameEnum.PropCode.vigour)) //活力
{
var attrService = App.GetService<IUnitUserAttrService>();
var MyAcc = await attrService.GetUserVigourInfo(userId);
decimal neecAcc = item.count * count;
if (MyAcc.vitality < neecAcc)
{
isok = false;
}
}
else if (item.code ==nameof( GameEnum.PropCode.lev))
{
var attrService = App.GetService<IUnitUserAttrService>();
var MyLev = await attrService.GetUserLev(userId);
if (MyLev < item.count)
{
isok = false;
}
}
result.result = isok;
result.isDeal = isDeal;
result.isGive = isGive;
return result;
}
public static async Task<CheckTowerNeed> CheakNeed(string userId, List<TowerNeed> needs, string sid, int count = 1)
{
CheckTowerNeed result = new CheckTowerNeed();
bool isok = true;
int isDeal = 1;
int isGive = 1;
foreach (var item in needs)
{
var cheakResult = await CheakNeed(userId, item, sid, count);
if (isok)
{
isok = cheakResult.result;
}
if (cheakResult.isDeal == 0)
{
isDeal = 0;
}
if (cheakResult.isGive == 0)
{
isGive = 0;
}
item.isAsk = cheakResult.result ? 1 : 0;
result.Needs.Add(item);
}
result.result = isok;
result.isDeal = isDeal;
result.isGive = isGive;
return result;
}
#endregion
}