1212
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
namespace Application.Domain;
|
||||
using Dm.util;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Application.Domain;
|
||||
|
||||
public class GameFightService(ISqlSugarClient DbClient, IRedisCache redis) : IGameFightService, ITransient
|
||||
{
|
||||
@@ -164,7 +167,7 @@ public class GameFightService(ISqlSugarClient DbClient, IRedisCache redis) : IGa
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<bool> SetFightWin(game_fight_data fightData, string winUser)
|
||||
public async Task<bool> SetFightWin(game_fight_data fightData, string winUser,bool setDefMap=true)
|
||||
{
|
||||
bool result = false;
|
||||
long okTime = TimeExtend.GetTimeStampSeconds;
|
||||
@@ -213,6 +216,10 @@ public class GameFightService(ISqlSugarClient DbClient, IRedisCache redis) : IGa
|
||||
if (result)
|
||||
{
|
||||
await RemoveUserFight(fightData.userId);
|
||||
if (setDefMap)
|
||||
{
|
||||
await UserStateTool.SetUserMapDefault(fightData.userId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -224,6 +231,10 @@ public class GameFightService(ISqlSugarClient DbClient, IRedisCache redis) : IGa
|
||||
if (result)
|
||||
{
|
||||
await RemoveUserFight(lowUser);
|
||||
if (setDefMap)
|
||||
{
|
||||
await UserStateTool.SetUserMapDefault(lowUser);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -306,6 +317,8 @@ public class GameFightService(ISqlSugarClient DbClient, IRedisCache redis) : IGa
|
||||
await redis.AddHashAsync(key, userId, harm);
|
||||
}
|
||||
|
||||
#region 战斗地图掉落
|
||||
|
||||
public async Task HandleFight(game_fight_data fightData)
|
||||
{
|
||||
string winUser = fightData.winUser;
|
||||
@@ -328,8 +341,227 @@ public class GameFightService(ISqlSugarClient DbClient, IRedisCache redis) : IGa
|
||||
{
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(fightData.award)) //发放物品奖励
|
||||
{
|
||||
await PutFightAwardGoods(fightData);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
private async Task PutFightAwardGoods(game_fight_data fightData)
|
||||
{
|
||||
var fightAward = JsonConvert.DeserializeObject<FightAwardModel>(fightData.award);
|
||||
if (fightAward.code == "Default")
|
||||
{
|
||||
var userService = App.GetService<IUnitUserService>();
|
||||
var userConfig = await userService.GetUserConfigInfo(fightData.winUser);
|
||||
List<TowerGet> AddMapGoods = new List<TowerGet>();
|
||||
var opGoods = JsonConvert.DeserializeObject<List<TowerGet>>(fightAward.award.ToString());
|
||||
string addGoodsUser = fightData.areaCode == nameof(GameEnum.AreaCode.Public) ? "0" : fightData.winUser;
|
||||
if (userConfig.autoBag == 1)
|
||||
{
|
||||
var weightService = App.GetService<IUnitUserWeight>();
|
||||
bool auto = true;
|
||||
foreach (var item in opGoods)
|
||||
{
|
||||
if (auto == false)
|
||||
{
|
||||
AddMapGoods.Add(item);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (await weightService.CheckUserWeight(fightData.winUser, item))
|
||||
{
|
||||
await GameBus.UpdateBag(fightData.winUser, 1, item.code, item.parameter, item.count,
|
||||
"战斗获得");
|
||||
}
|
||||
else
|
||||
{
|
||||
auto = false;
|
||||
AddMapGoods.add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
AddMapGoods = opGoods;
|
||||
}
|
||||
|
||||
if (AddMapGoods.Count > 0)
|
||||
{
|
||||
await AddMapFightGoods(addGoodsUser, fightData.mapId, AddMapGoods);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<List<game_map_goods>> GetMapFightGoods(string mapId)
|
||||
{
|
||||
List<game_map_goods> result = new List<game_map_goods>();
|
||||
string key = string.Format(FightCache.FightCacheKeys, "MapGoods", mapId);
|
||||
if (await redis.ExistsAsync(key))
|
||||
{
|
||||
result = await redis.GetAsync<List<game_map_goods>>(key);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<game_map_goods> GetFightGoodsInfo(string mapId, string mgId)
|
||||
{
|
||||
var data = await GetMapFightGoods(mapId);
|
||||
var result = data.Find(it => it.mgId == mgId);
|
||||
return result;
|
||||
}
|
||||
|
||||
private async Task AddMapFightGoods(string userId, string mapId, List<TowerGet> goods)
|
||||
{
|
||||
var data = await GetMapFightGoods(mapId);
|
||||
List<game_map_goods> addData = new List<game_map_goods>();
|
||||
foreach (var item in goods)
|
||||
{
|
||||
game_map_goods temp = new game_map_goods()
|
||||
{
|
||||
mgId = StringAssist.NewGuid,
|
||||
userId = userId,
|
||||
mapId = mapId,
|
||||
name = item.name,
|
||||
code = item.code,
|
||||
par = item.parameter,
|
||||
count = item.count
|
||||
};
|
||||
addData.Add(temp);
|
||||
}
|
||||
|
||||
data.AddRange(addData);
|
||||
string key = string.Format(FightCache.FightCacheKeys, "MapGoods", mapId);
|
||||
await redis.SetAsync(key, data, 600);
|
||||
}
|
||||
|
||||
public async Task RemoveFightGoods(string mapId, string mgId)
|
||||
{
|
||||
var data = await GetMapFightGoods(mapId);
|
||||
data = data.FindAll(it => it.mgId != mgId);
|
||||
string key = string.Format(FightCache.FightCacheKeys, "MapGoods", mapId);
|
||||
await redis.SetAsync(key, data, 600);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 自动使用药品
|
||||
|
||||
public async Task AutoUseDrug(UserAttrModel user, game_fight_data fight)
|
||||
{
|
||||
var userService = App.GetService<IUnitUserService>();
|
||||
var userConfig = await userService.GetUserConfigInfo(user.id);
|
||||
await UseBloodDrug(user, fight, userConfig.autoDrug == 1, user.upBlood - user.blood);
|
||||
if (userConfig.autoDrug == 1)
|
||||
{
|
||||
var attrService = App.GetService<IUnitUserAttrService>();
|
||||
var myDrug = await attrService.GetUserDrug(user.id);
|
||||
var loadDrug = myDrug.drug.Find(it => it.code == nameof(GoodsEnum.DrugCls.LoadBuff) && it.count > 0);
|
||||
if (loadDrug != null)
|
||||
{
|
||||
var goodsService = App.GetService<IGameGoodsService>();
|
||||
var _drugConfig = await goodsService.GetGoodsContent(loadDrug.goodsId);
|
||||
string check = await goodsService.CheckUseDrug(user.id, loadDrug.goodsId, _drugConfig, fight.fightId);
|
||||
if (string.IsNullOrEmpty(check))
|
||||
{
|
||||
if (await attrService.UpdateUserDrug(user.id, loadDrug.id, 0, 1))
|
||||
{
|
||||
await goodsService.UseDrug(user.id, loadDrug.goodsId, _drugConfig, fight.fightId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async Task UseBloodDrug(UserAttrModel user, game_fight_data fight, bool isAuto, int addBlood)
|
||||
{
|
||||
//先判断储存状态
|
||||
var attrService = App.GetService<IUnitUserAttrService>();
|
||||
var goodsService = App.GetService<IGameGoodsService>();
|
||||
var bloodStock = await attrService.GetUserStock(user.id, "Blood");
|
||||
var myDrug = await attrService.GetUserDrug(user.id);
|
||||
if (bloodStock.Count > 0)
|
||||
{
|
||||
foreach (var item in bloodStock)
|
||||
{
|
||||
string[] config = item.par.split("|");
|
||||
if (config[0] == fight.code || config[0] == "ALL")
|
||||
{
|
||||
decimal okLimit = Convert.ToDecimal(config[1]);
|
||||
if ((Convert.ToDecimal(addBlood) / Convert.ToDecimal(user.upBlood) ) > okLimit)
|
||||
{
|
||||
if (item.type == "Number")
|
||||
{
|
||||
int opCount = item.sign > addBlood ? addBlood : Convert.ToInt32(item.sign);
|
||||
item.sign = item.sign - opCount;
|
||||
if (await attrService.UpdateUserStock(item))
|
||||
{
|
||||
addBlood -= opCount;
|
||||
await attrService.UpdateUserBlood(user.id, 1, opCount);
|
||||
if (addBlood < 1)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (item.type == "Time")
|
||||
{
|
||||
await attrService.UpdateUserBlood(user.id, 1, addBlood);
|
||||
addBlood = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isAuto && addBlood > 0)
|
||||
{
|
||||
//优先开放储存
|
||||
var stockDrug = myDrug.drug.Find(it => it.code == nameof(GoodsEnum.DrugCls.BloodStock) && it.count > 0);
|
||||
if (stockDrug != null)
|
||||
{
|
||||
var _drugConfig = await goodsService.GetGoodsContent(stockDrug.goodsId);
|
||||
string check = await goodsService.CheckUseDrug(user.id, stockDrug.goodsId, _drugConfig, fight.fightId);
|
||||
if (string.IsNullOrEmpty(check))
|
||||
{
|
||||
if (await attrService.UpdateUserDrug(user.id, stockDrug.id, 0, 1))
|
||||
{
|
||||
if (await goodsService.UseDrug(user.id, stockDrug.goodsId, _drugConfig, fight.fightId))
|
||||
{
|
||||
await UseBloodDrug(user, fight, isAuto, addBlood);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//使用普通药品
|
||||
if (addBlood > 0)
|
||||
{
|
||||
var unitDrug = myDrug.drug.Find(it => it.code == nameof(GoodsEnum.DrugCls.Blood) && it.count > 0);
|
||||
if (unitDrug != null)
|
||||
{
|
||||
var _drugConfig = await goodsService.GetGoodsContent(unitDrug.goodsId);
|
||||
string check =
|
||||
await goodsService.CheckUseDrug(user.id, unitDrug.goodsId, _drugConfig, fight.fightId);
|
||||
if (string.IsNullOrEmpty(check))
|
||||
{
|
||||
if (await attrService.UpdateUserDrug(user.id, unitDrug.id, 0, 1))
|
||||
{
|
||||
await goodsService.UseDrug(user.id, unitDrug.goodsId, _drugConfig, fight.fightId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
}
|
||||
Reference in New Issue
Block a user