1212
This commit is contained in:
@@ -18,8 +18,8 @@ public interface IGameGoodsService
|
||||
Task<List<unit_user_goods>> GetUserGoodsData(string userId, List<string> code, List<string> noCode, string search, int page,
|
||||
int limit, RefAsync<int> total);
|
||||
|
||||
Task<List<unit_user_goods>> GetUserGoodsData(string userId, string code);
|
||||
Task<bool> UpdateUserGoods(string userId, int op, int goodsId, int count, string remark = "");
|
||||
|
||||
#endregion
|
||||
|
||||
#region 辅助
|
||||
|
||||
@@ -26,6 +26,7 @@ public interface IGameMapService
|
||||
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);
|
||||
Task<string> GetUserRunEvent(string userId);
|
||||
#endregion
|
||||
|
||||
#region 其他相关
|
||||
@@ -53,4 +54,18 @@ public interface IGameMapService
|
||||
Task<bool> UpdateUserRunInfo(unit_user_run data);
|
||||
|
||||
#endregion
|
||||
|
||||
#region 地图业务
|
||||
|
||||
Task<List<game_city_map_bus>> GetMapBus(string BusCode, int v, int l);
|
||||
Task<game_city_map_bus> GetMapBusInfo(int busId);
|
||||
Task<bool> CheckBusPower(game_city_map_bus bus, string userId);
|
||||
|
||||
#endregion
|
||||
|
||||
#region 地图资源
|
||||
|
||||
Task<List<game_city_map_res>> GetMapRes(string mapId);
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -37,5 +37,12 @@ public interface IUnitUserAttrService
|
||||
Task<bool> UpdateUserVigour(string userId, int op, long count, string UpTime = "");
|
||||
Task<bool> UpdateUserUpVigour(string userId, decimal count);
|
||||
|
||||
#endregion
|
||||
|
||||
#region 在线时间
|
||||
|
||||
Task<bool> UpdateOnLineTime(string userId, string code, int time);
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -68,7 +68,14 @@ public class GameGoodsService(ISqlSugarClient DbClient, IRedisCache redis) : IGa
|
||||
.OrderBy(it => it.count, OrderByType.Desc)
|
||||
.ToPageListAsync(page, limit, total);
|
||||
}
|
||||
|
||||
public async Task<List<unit_user_goods>> GetUserGoodsData(string userId, string code)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_goods>();
|
||||
return await db.Queryable<unit_user_goods>().Where(it => it.userId == userId && it.count > 0 && it.code == code)
|
||||
.OrderBy(it => it.lev, OrderByType.Desc)
|
||||
.OrderBy(it => it.count, OrderByType.Desc)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<bool> UpdateUserGoods(string userId, int op, int goodsId, int count, string remark = "")
|
||||
{
|
||||
@@ -156,6 +163,8 @@ public class GameGoodsService(ISqlSugarClient DbClient, IRedisCache redis) : IGa
|
||||
return await db.Insertable(bagLog).SplitTable().ExecuteCommandAsync() > 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region 辅助
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
namespace Application.Domain;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Application.Domain;
|
||||
|
||||
public class GameMapService(ISqlSugarClient DbClient, IRedisCache redis) : IGameMapService, ITransient
|
||||
{
|
||||
@@ -17,6 +19,7 @@ public class GameMapService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
public async Task<game_city> GetCityInfoByMapId(string mapId)
|
||||
{
|
||||
var data = await GetMapInfo(mapId);
|
||||
@@ -100,7 +103,7 @@ public class GameMapService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public async Task<List<game_city_npc>> GetMapNpc(string mapId)
|
||||
{
|
||||
@@ -594,7 +597,7 @@ public class GameMapService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
|
||||
var data = await db.Queryable<unit_user_run>().Where(it => it.userId == userId).SingleAsync();
|
||||
if (data == null)
|
||||
{
|
||||
data = await ResetUserRun(userId,false);
|
||||
data = await ResetUserRun(userId, false);
|
||||
}
|
||||
|
||||
await redis.AddHashAsync(key, userId, data);
|
||||
@@ -664,6 +667,7 @@ public class GameMapService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<bool> UpdateUserRunInfo(unit_user_run data)
|
||||
{
|
||||
string key = string.Format(UserCache.BaseCacheKey, "UserMapRun");
|
||||
@@ -676,5 +680,265 @@ public class GameMapService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private async Task<game_city_map_event> GetRandomOneMapRunEvent()
|
||||
{
|
||||
string key = string.Format(BaseCache.BaseCacheKey, "CityRunEvent");
|
||||
var data = await redis.GetAsync<List<game_city_map_event>>(key);
|
||||
if (data == null)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<game_city_map_event>();
|
||||
data = await db.Queryable<game_city_map_event>().ToListAsync();
|
||||
await redis.SetAsync(key, data);
|
||||
}
|
||||
|
||||
int index = RandomAssist.UnitRandomNum(0, data.Count);
|
||||
return data[index];
|
||||
}
|
||||
|
||||
public async Task<string> GetUserRunEvent(string userId)
|
||||
{
|
||||
string result = string.Empty;
|
||||
if (RandomAssist.CheakRandom(30))
|
||||
{
|
||||
var data = await GetRandomOneMapRunEvent();
|
||||
if (data != null)
|
||||
{
|
||||
if (string.IsNullOrEmpty(data.eventData))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
var eventData = JsonConvert.DeserializeObject<MapEventData>(data.eventData);
|
||||
if (data.evType == nameof(MapEnum.RunEvent.reduce_goods))
|
||||
{
|
||||
var goodsService = App.GetService<IGameGoodsService>();
|
||||
var cagioData = await goodsService.GetUserGoodsData(userId, nameof(GoodsEnum.Code.Cargo));
|
||||
if (cagioData.Count > 0)
|
||||
{
|
||||
bool isOp = await CheckOpEvent(userId, data.offsetData);
|
||||
if (isOp)
|
||||
{
|
||||
int index = RandomAssist.UnitRandomNum(0, cagioData.Count);
|
||||
int count = RandomAssist.UnitRandomNum((int)eventData.minCount,
|
||||
(int)eventData.maxCount + 1);
|
||||
var onGoods = cagioData[index];
|
||||
|
||||
if (onGoods.count >= count)
|
||||
{
|
||||
if (await goodsService.UpdateUserGoods(userId, 0, (int)onGoods.goodsId, count,
|
||||
"航海事件触发"))
|
||||
{
|
||||
result = String.Format(eventData.tips, onGoods.goodsName, count);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
result = eventData.offSetTips;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (data.evType == nameof(MapEnum.RunEvent.reduce_blood))
|
||||
{
|
||||
bool isOp = await CheckOpEvent(userId, data.offsetData);
|
||||
if (isOp)
|
||||
{
|
||||
int count = RandomAssist.UnitRandomNum((int)eventData.minCount, (int)eventData.maxCount + 1);
|
||||
var attrService = App.GetService<IUnitUserAttrService>();
|
||||
var myAttr = await attrService.GetUserAttrModel(userId);
|
||||
myAttr.blood = myAttr.blood - count;
|
||||
myAttr.blood = myAttr.blood < 1 ? 0 : myAttr.blood;
|
||||
if (await attrService.UpdateUserBlood(userId, 2, myAttr.blood))
|
||||
{
|
||||
if (myAttr.blood == 0)
|
||||
{
|
||||
if (await StopUserRun(userId))
|
||||
{
|
||||
var mapService = App.GetService<IGameMapService>();
|
||||
await mapService.SetUserMapDefult(userId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
result = String.Format(eventData.tips, count);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = eventData.offSetTips;
|
||||
}
|
||||
}
|
||||
else if (data.evType == nameof(MapEnum.RunEvent.add_blood))
|
||||
{
|
||||
bool isOp = await CheckOpEvent(userId, data.offsetData);
|
||||
if (isOp)
|
||||
{
|
||||
int count = RandomAssist.UnitRandomNum((int)eventData.minCount, (int)eventData.maxCount + 1);
|
||||
var attrService = App.GetService<IUnitUserAttrService>();
|
||||
var myAttr = await attrService.GetUserAttrModel(userId);
|
||||
myAttr.blood = myAttr.blood + count;
|
||||
myAttr.blood = myAttr.blood > myAttr.upBlood ? myAttr.upBlood : myAttr.blood;
|
||||
|
||||
await attrService.UpdateUserBlood(userId, 2, myAttr.blood);
|
||||
result = String.Format(eventData.tips, count);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = eventData.offSetTips;
|
||||
}
|
||||
}
|
||||
else if (data.evType == nameof(MapEnum.RunEvent.reduce_vigour))
|
||||
{
|
||||
bool isOp = await CheckOpEvent(userId, data.offsetData);
|
||||
if (isOp)
|
||||
{
|
||||
int count = RandomAssist.UnitRandomNum((int)eventData.minCount, (int)eventData.maxCount + 1);
|
||||
var attrService = App.GetService<IUnitUserAttrService>();
|
||||
var myVigour = await attrService.GetUserVigourInfo(userId);
|
||||
myVigour.vitality = myVigour.vitality - count;
|
||||
myVigour.vitality = myVigour.vitality < 1 ? 0 : myVigour.vitality;
|
||||
await attrService.UpdateUserVigour(userId, 2, (long)myVigour.vitality);
|
||||
result = String.Format(eventData.tips, count);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = eventData.offSetTips;
|
||||
}
|
||||
}
|
||||
else if (data.evType == nameof(MapEnum.RunEvent.add_copper))
|
||||
{
|
||||
bool isOp = await CheckOpEvent(userId, data.offsetData);
|
||||
if (isOp)
|
||||
{
|
||||
int count = RandomAssist.UnitRandomNum((int)eventData.minCount, (int)eventData.maxCount + 1);
|
||||
var accService = App.GetService<IUnitUserAccService>();
|
||||
await accService.UpdateUserCopper(userId, 1, count, "航海事件");
|
||||
result = String.Format(eventData.tips, count);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = eventData.offSetTips;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private async Task<bool> CheckOpEvent(string userId, string offSet)
|
||||
{
|
||||
bool isOp = true;
|
||||
if (!string.IsNullOrEmpty(offSet))
|
||||
{
|
||||
var offsetData = JsonConvert.DeserializeObject<TowerNeed>(offSet);
|
||||
var chekResult = await GameBus.CheakNeed(userId, offsetData, "");
|
||||
if (chekResult.result)
|
||||
{
|
||||
if (offsetData.isOp == 0)
|
||||
{
|
||||
isOp = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
var result = await GameBus.UpdateBag(userId, 0, offsetData.code, offsetData.parameter,
|
||||
offsetData.count,
|
||||
"航海事件");
|
||||
isOp = !result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return isOp;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 地图业务
|
||||
|
||||
public async Task<List<game_city_map_bus>> GetMapBus(string BusCode, int v, int l)
|
||||
{
|
||||
string key = string.Format(BaseCache.BaseCacheKeys, "CITY_MAP_BUS", BusCode);
|
||||
var data = await redis.GetAsync<List<game_city_map_bus>>(key);
|
||||
if (data == null)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<game_city_map_bus>();
|
||||
data = await db.Queryable<game_city_map_bus>().Where(it => it.busCode == BusCode).ToListAsync();
|
||||
await redis.SetAsync(key, data);
|
||||
}
|
||||
|
||||
if (data != null)
|
||||
{
|
||||
data = data.FindAll(it => it.bus_s <= v && it.bus_e >= v && it.bus_l == l);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
public async Task<game_city_map_bus> GetMapBusInfo(int busId)
|
||||
{
|
||||
string key = string.Format(BaseCache.BaseCacheKeys, "CITY_MAP_BUS","BUS_INFO");
|
||||
if (await redis.HExistsHashAsync(key, busId.ToString()))
|
||||
{
|
||||
return await redis.GetHashAsync<game_city_map_bus>(key, busId.ToString());
|
||||
}
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<game_city_map_bus>();
|
||||
var data = await db.Queryable<game_city_map_bus>().Where(it => it.busId == busId).SingleAsync();
|
||||
await redis.AddHashAsync(key,busId.ToString(), data);
|
||||
return data;
|
||||
}
|
||||
|
||||
public async Task<bool> CheckBusPower(game_city_map_bus bus, string userId)
|
||||
{
|
||||
bool result = false;
|
||||
var onMap = await GetUserOnMapId(userId);
|
||||
var runInfo = await GetUserRun(userId);
|
||||
if (onMap == bus.busCode)
|
||||
{
|
||||
if (runInfo == null)
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
else if (runInfo.status == 0)
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (result == false)
|
||||
{
|
||||
if (runInfo != null)
|
||||
{
|
||||
if (bus.busCode == String.Format("{0}_{1}", runInfo.onMap, runInfo.toMap) &&
|
||||
runInfo.position >= bus.bus_s && runInfo.position <= bus.bus_e && bus.bus_l == runInfo.depth &&
|
||||
runInfo.status == 1)
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 地图资源
|
||||
|
||||
public async Task<List<game_city_map_res>> GetMapRes(string mapId)
|
||||
{
|
||||
string key = string.Format(BaseCache.BaseCacheKeys, "CityData", "MapRes");
|
||||
var data = await redis.GetHashAsync<List<game_city_map_res>>(key, mapId);
|
||||
if (data == null)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<game_city_map_res>();
|
||||
data = await db.Queryable<game_city_map_res>().Where(it => it.mapId == mapId).ToListAsync();
|
||||
await redis.AddHashAsync(key, mapId,data);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -336,4 +336,20 @@ public class UnitUserAttrService(ISqlSugarClient DbClient, IRedisCache redis) :
|
||||
}
|
||||
|
||||
#endregion 活力
|
||||
|
||||
#region 在线时间
|
||||
|
||||
public async Task<bool> UpdateOnLineTime(string userId, string code, int time)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_online_time>();
|
||||
bool result = await db.Updateable<unit_user_online_time>()
|
||||
.SetColumns(it => it.dayTime == it.dayTime + time)
|
||||
.SetColumns(it => it.monthTime == it.monthTime + time)
|
||||
.SetColumns(it => it.totalTime == it.totalTime + time)
|
||||
.Where(it => it.userId == userId).ExecuteCommandAsync() > 0;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -250,6 +250,13 @@ public class UnitUserService(ISqlSugarClient DbClient, IRedisCache redis) : IUni
|
||||
online.upTime = TimeAssist.GetTimeStampNum;
|
||||
db.Insertable(online).AddQueue();
|
||||
|
||||
unit_user_online_time onlineTime = new unit_user_online_time();
|
||||
onlineTime.userId = userId;
|
||||
onlineTime.dayTime = 0;
|
||||
onlineTime.monthTime = 0;
|
||||
onlineTime.totalTime = 0;
|
||||
db.Insertable(onlineTime).AddQueue();
|
||||
|
||||
await db.SaveQueuesAsync(false);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user