1212
This commit is contained in:
@@ -15,7 +15,7 @@ public interface IGameFightService
|
||||
string scene, string mapId,
|
||||
string userId, long exp = 0, long copper = 0, long petExp = 0, string award = "", string pars = "");
|
||||
|
||||
Task<bool> SetFightWin(game_fight_data fightData, string winUser);
|
||||
Task<bool> SetFightWin(game_fight_data fightData, string winUser,bool setDefMap=true);
|
||||
|
||||
|
||||
#endregion
|
||||
@@ -24,6 +24,10 @@ public interface IGameFightService
|
||||
Task<int> GetUserFightHarm(string userId);
|
||||
Task SetUserFightHarm(string userId, int harm);
|
||||
Task HandleFight(game_fight_data eventData);
|
||||
Task<List<game_map_goods>> GetMapFightGoods(string mapId);
|
||||
Task<game_map_goods> GetFightGoodsInfo(string mapId, string mgId);
|
||||
Task RemoveFightGoods(string mapId, string mgId);
|
||||
Task AutoUseDrug(UserAttrModel user, game_fight_data fight);
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -32,8 +32,9 @@ public interface IGameGoodsService
|
||||
#region 药品
|
||||
|
||||
Task<string> CheckUseDrug(string userId, int goodsId, string drugConfig, string scene = "");
|
||||
Task<string> CheckUseDrug(string userId, int goodsId, string scene = "");
|
||||
Task<bool> UseDrug(string userId, int goodsId, string drugConfig, string scene = "");
|
||||
|
||||
Task<bool> UseDrug(string userId, int goodsId, string scene = "");
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -23,7 +23,7 @@ public interface IGameMapService
|
||||
Task UpdateUserOnMap(string userId, string ip, string mapId);
|
||||
Task<bool> UpdateUserOnMap(unit_user_online data, string mapId);
|
||||
Task<UserOnMap> GetUserOnMapInfo(string userId);
|
||||
Task SetUserMapDefult(string userId);
|
||||
Task SetUserMapDefault(string userId);
|
||||
Task<game_city_map> GetToMapInfo(string userId, string toMap, bool isUpUserMap = true, bool isChangeCity = false);
|
||||
Task<List<unit_user_map>> GetUserCityMapData(string userId);
|
||||
Task<bool> AddUserCityMap(string userId, int cityId);
|
||||
|
||||
@@ -51,7 +51,7 @@ public interface IUnitUserAttrService
|
||||
|
||||
Task<unit_user_drug> GetUserDrug(string userId);
|
||||
Task<bool> UpdateUserDrug(unit_user_drug data);
|
||||
|
||||
Task<bool> UpdateUserDrug(string userId, string drugId, int op, int count);
|
||||
#endregion
|
||||
|
||||
#region BUFF状态
|
||||
|
||||
@@ -11,7 +11,8 @@ public interface IUnitUserWeight
|
||||
|
||||
Task<List<unit_user_weight_log>> GetUserWeightLog(string userId);
|
||||
Task<bool> CheckUserWeight(string userId, int useWeight);
|
||||
|
||||
Task<bool> CheckUserWeight(string userId, TowerGet data);
|
||||
Task<bool> CheckUserWeight(string userId, string code, string par, long count);
|
||||
#region 船只相关
|
||||
Task<unit_user_ship> GetUserShipInfo(string usId);
|
||||
Task<List<unit_user_ship>> GetUserShip(string userId);
|
||||
|
||||
@@ -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
|
||||
}
|
||||
@@ -283,6 +283,16 @@ public class GameGoodsService(ISqlSugarClient DbClient, IRedisCache redis) : IGa
|
||||
|
||||
return result;
|
||||
}
|
||||
public async Task<string> CheckUseDrug(string userId, int goodsId,string scene = "")
|
||||
{
|
||||
string result = string.Empty;
|
||||
var goodsInfo = await GetGoodsContent(goodsId);
|
||||
if (!string.IsNullOrEmpty(goodsInfo))
|
||||
{
|
||||
result = await CheckUseDrug(userId,goodsId, goodsInfo, scene);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<bool> UseDrug(string userId, int goodsId, string drugConfig, string scene = "")
|
||||
{
|
||||
@@ -323,6 +333,17 @@ public class GameGoodsService(ISqlSugarClient DbClient, IRedisCache redis) : IGa
|
||||
|
||||
return result;
|
||||
}
|
||||
public async Task<bool> UseDrug(string userId, int goodsId, string scene = "")
|
||||
{
|
||||
bool result = false;
|
||||
var goodsInfo = await GetGoodsContent(goodsId);
|
||||
if (!string.IsNullOrEmpty(goodsInfo))
|
||||
{
|
||||
result = await UseDrug(userId,goodsId, goodsInfo, scene);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -213,7 +213,7 @@ public class GameMapService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
|
||||
return true;
|
||||
}
|
||||
|
||||
public async Task SetUserMapDefult(string userId)
|
||||
public async Task SetUserMapDefault(string userId)
|
||||
{
|
||||
var userMap = await GetUserOnMap(userId);
|
||||
var MapInfo = await GetMapInfo(userMap.mapId);
|
||||
@@ -762,7 +762,7 @@ public class GameMapService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
|
||||
if (await StopUserRun(userId))
|
||||
{
|
||||
var mapService = App.GetService<IGameMapService>();
|
||||
await mapService.SetUserMapDefult(userId);
|
||||
await mapService.SetUserMapDefault(userId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -256,10 +256,7 @@ public class UnitUserAttrService(ISqlSugarClient DbClient, IRedisCache redis) :
|
||||
if (mustUp)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_blood>();
|
||||
result = await db.Updateable<unit_user_blood>()
|
||||
.SetColumnsIF(op == 0, it => it.blood == it.blood - count)
|
||||
.SetColumnsIF(op == 1, it => it.blood == it.blood + count)
|
||||
.SetColumnsIF(op == 2, it => it.blood == count)
|
||||
result = await db.Updateable<unit_user_blood>().SetColumns(it => it.blood == data.blood)
|
||||
.Where(it => it.userId == userId).ExecuteCommandAsync() > 0;
|
||||
}
|
||||
|
||||
@@ -539,6 +536,30 @@ public class UnitUserAttrService(ISqlSugarClient DbClient, IRedisCache redis) :
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<bool> UpdateUserDrug(string userId, string drugId, int op, int count)
|
||||
{
|
||||
var data = await GetUserDrug(userId);
|
||||
foreach (var item in data.drug)
|
||||
{
|
||||
if (item.id == drugId)
|
||||
{
|
||||
if (op == 0)
|
||||
{
|
||||
item.count = item.count - count;
|
||||
}
|
||||
else
|
||||
{
|
||||
item.count = item.count + count;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool result = await UpdateUserDrug(data);
|
||||
return result;
|
||||
}
|
||||
|
||||
private async Task ClearUserDrug(string userId)
|
||||
{
|
||||
string key = string.Format(UserCache.BaseCacheKeys, "UserTool", "DrugColumn");
|
||||
|
||||
@@ -122,6 +122,46 @@ public class UnitUserWeight(ISqlSugarClient DbClient, IRedisCache redis) : IUnit
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<bool> CheckUserWeight(string userId, TowerGet data)
|
||||
{
|
||||
bool result = await CheckUserWeight(userId, data.code, data.parameter, data.count);
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<bool> CheckUserWeight(string userId, string code, string par, long count)
|
||||
{
|
||||
bool result = true;
|
||||
if (code == nameof(GameEnum.PropCode.Goods))
|
||||
{
|
||||
var goodsService = App.GetService<IGameGoodsService>();
|
||||
var goodsInfo = await goodsService.GetGoodsInfo(Convert.ToInt32(par));
|
||||
if (goodsInfo != null)
|
||||
{
|
||||
int needCount = (int)goodsInfo.weight * Convert.ToInt32(count) ;
|
||||
if (goodsInfo.code == nameof(GoodsEnum.Code.Cargo))
|
||||
{
|
||||
result =await CheakUserShipWeight(userId, needCount);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = await CheckUserWeight(userId, needCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (code == nameof(GameEnum.PropCode.Equ))
|
||||
{
|
||||
var equService = App.GetService<IGameEquService>();
|
||||
var equInfo = await equService.GetEquInfo(Convert.ToInt32(par));
|
||||
if (equInfo != null)
|
||||
{
|
||||
int needCount = (int)equInfo.weight * Convert.ToInt32(count) ;
|
||||
result = await CheckUserWeight(userId, needCount);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#region 船只相关
|
||||
|
||||
public async Task<unit_user_ship> GetUserShipInfo(string usId)
|
||||
|
||||
Reference in New Issue
Block a user