221 lines
7.3 KiB
C#
221 lines
7.3 KiB
C#
namespace Application.Domain;
|
|
|
|
public class GameBus
|
|
{
|
|
#region 物品资源操作
|
|
|
|
public static async Task<bool> UpdateBag(string userId, int operate, string goodsType, string parameter, long count,
|
|
string remark)
|
|
{
|
|
bool isok = false;
|
|
if (goodsType.Equals(nameof(GameEnum.PropCode.Goods)))
|
|
{
|
|
var goodsService = App.GetService<IGameGoodsService>();
|
|
isok = await goodsService.UpdateUserGoods(userId, operate, Convert.ToInt32(parameter), (int)count, remark);
|
|
}
|
|
else if (goodsType.Equals(nameof(GameEnum.PropCode.Equ)))
|
|
{
|
|
var equService = App.GetService<IGameEquService>();
|
|
if (operate == 1)
|
|
{
|
|
isok = await equService.AddUserEqu(userId, Convert.ToInt32(parameter), (int)count, remark);
|
|
}
|
|
else
|
|
{
|
|
isok = await equService.DeductUserEqu(userId, Convert.ToInt32(parameter), (int)count, remark);
|
|
}
|
|
}
|
|
else if (goodsType.Equals(nameof(GameEnum.PropCode.copper)))
|
|
{
|
|
var accService = App.GetService<IUnitUserAccService>();
|
|
isok = await accService.UpdateUserCopper(userId, operate, count);
|
|
}
|
|
else if (goodsType.Equals(nameof(GameEnum.PropCode.gold)))
|
|
{
|
|
var accService = App.GetService<IUnitUserAccService>();
|
|
isok = await accService.UpdateUserAcc(userId, operate, nameof(AccEnum.AccType.gold), count,
|
|
nameof(AccEnum.Name.其他), remark);
|
|
}
|
|
else if (goodsType.Equals(nameof(GameEnum.PropCode.cowry)))
|
|
{
|
|
var accService = App.GetService<IUnitUserAccService>();
|
|
isok = await accService.UpdateUserAcc(userId, operate, nameof(AccEnum.AccType.cowry), count,
|
|
nameof(AccEnum.Name.其他), remark);
|
|
}
|
|
else if (goodsType.Equals(nameof(GameEnum.PropCode.vigour)))
|
|
{
|
|
var attrService = App.GetService<IUnitUserAttrService>();
|
|
isok = await attrService.UpdateUserVigour(userId, operate, count);
|
|
}
|
|
else if (goodsType.Equals(nameof(GameEnum.PropCode.exp)))
|
|
{
|
|
var attrService = App.GetService<IUnitUserAttrService>();
|
|
isok = await attrService.UpdateUserExp(userId, count, operate);
|
|
}
|
|
else if (goodsType.Equals(nameof(GameEnum.PropCode.renown)))
|
|
{
|
|
var accService = App.GetService<IUnitUserAccService>();
|
|
isok = await accService.UpdateUserAcc(userId, operate, nameof(AccEnum.AccType.renown), count,
|
|
nameof(AccEnum.Name.其他), remark);
|
|
}
|
|
else if (goodsType.Equals(nameof(GameEnum.PropCode.teach)))
|
|
{
|
|
var accService = App.GetService<IUnitUserAccService>();
|
|
isok = await accService.UpdateUserAcc(userId, operate, nameof(AccEnum.AccType.teach), count,
|
|
nameof(AccEnum.Name.其他), remark);
|
|
}
|
|
|
|
return isok;
|
|
}
|
|
|
|
public static async Task<bool> UpdateBag(string userId, int operate, dynamic Reward, string remark = "",
|
|
long count = 1)
|
|
{
|
|
try
|
|
{
|
|
foreach (var item in Reward)
|
|
{
|
|
long num = Convert.ToInt64(item.count) * count;
|
|
if (num <= 0)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
await UpdateBag(userId, operate, item.code, item.parameter, num, remark);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
catch
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
#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
|
|
} |