1212
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
|
||||
namespace Application.Domain.Entity
|
||||
{
|
||||
[Tenant("Kg.SeaTime.Game")]
|
||||
public class unit_user_online_time
|
||||
{
|
||||
/// <summary>
|
||||
/// userId
|
||||
/// </summary>
|
||||
[SugarColumn(IsPrimaryKey = true, Length = 50)]
|
||||
public string userId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// dayTime
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public long? dayTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// monthTime
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public long? monthTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// totalTime
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public long? totalTime { get; set; }
|
||||
}
|
||||
}
|
||||
30
Service/Application.Domain.Entity/model/CheckTowerNeed.cs
Normal file
30
Service/Application.Domain.Entity/model/CheckTowerNeed.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
namespace Application.Domain.Entity;
|
||||
|
||||
public class CheckTowerNeed
|
||||
{
|
||||
private bool _result;
|
||||
|
||||
public bool result
|
||||
{ get { return this._result; } set { this._result = value; } }
|
||||
|
||||
private System.Int32 _isDeal;
|
||||
|
||||
/// <summary>
|
||||
/// 0不可交易1可交易
|
||||
/// </summary>
|
||||
public System.Int32 isDeal
|
||||
{ get { return this._isDeal; } set { this._isDeal = value; } }
|
||||
|
||||
private System.Int32 _isGive;
|
||||
|
||||
/// <summary>
|
||||
/// 0不可交易1可交易
|
||||
/// </summary>
|
||||
public System.Int32 isGive
|
||||
{ get { return this._isGive; } set { this._isGive = value; } }
|
||||
|
||||
private List<TowerNeed> _Needs;
|
||||
|
||||
public List<TowerNeed> Needs
|
||||
{ get { return this._Needs; } set { this._Needs = value; } }
|
||||
}
|
||||
9
Service/Application.Domain.Entity/model/MapEventData.cs
Normal file
9
Service/Application.Domain.Entity/model/MapEventData.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace Application.Domain.Entity;
|
||||
|
||||
public class MapEventData
|
||||
{
|
||||
public int minCount { get; set; }
|
||||
public int maxCount { get; set;}
|
||||
public string tips { get; set; }
|
||||
public string offSetTips { get; set; }
|
||||
}
|
||||
60
Service/Application.Domain.Entity/model/TowerNeed.cs
Normal file
60
Service/Application.Domain.Entity/model/TowerNeed.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
namespace Application.Domain.Entity;
|
||||
|
||||
public class TowerNeed
|
||||
{
|
||||
private System.String _code;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public System.String code
|
||||
{ get { return this._code; } set { this._code = value; } }
|
||||
|
||||
private System.String _name;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public System.String name
|
||||
{ get { return this._name; } set { this._name = value; } }
|
||||
|
||||
private System.String _parameter;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public System.String parameter
|
||||
{ get { return this._parameter; } set { this._parameter = value; } }
|
||||
|
||||
private System.Int32 _count;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public System.Int32 count
|
||||
{ get { return this._count; } set { this._count = value; } }
|
||||
|
||||
private System.Int32 _retCount;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public System.Int32 retCount
|
||||
{ get { return this._retCount; } set { this._retCount = value; } }
|
||||
|
||||
private System.Int32 _isOp;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public System.Int32 isOp
|
||||
{ get { return this._isOp; } set { this._isOp = value; } }
|
||||
|
||||
private System.Int32 _isAsk;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public System.Int32 isAsk
|
||||
{ get { return this._isAsk; } set { this._isAsk = value; } }
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
|
||||
namespace Application.Domain.Entity
|
||||
{
|
||||
[Tenant("Kg.SeaTime.Resource")]
|
||||
public class game_city_map_bus
|
||||
{
|
||||
/// <summary>
|
||||
/// busId
|
||||
/// </summary>
|
||||
[SugarColumn(IsPrimaryKey = true)]
|
||||
public int busId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// busCode
|
||||
/// </summary>
|
||||
[SugarColumn(Length = 50, IsNullable = true)]
|
||||
public string? busCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// busName
|
||||
/// </summary>
|
||||
[SugarColumn(Length = 50, IsNullable = true)]
|
||||
public string? busName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// busType
|
||||
/// </summary>
|
||||
[SugarColumn(Length = 50, IsNullable = true)]
|
||||
public string? busType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// bus_s
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public int? bus_s { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// bus_e
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public int? bus_e { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// bus_l
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public int? bus_l { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// busTips
|
||||
/// </summary>
|
||||
[SugarColumn(Length = 255, IsNullable = true)]
|
||||
public string? busTips { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// busNeed
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public string? busNeed { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// busContent
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public string? busContent { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
|
||||
namespace Application.Domain.Entity
|
||||
{
|
||||
[Tenant("Kg.SeaTime.Resource")]
|
||||
public class game_city_map_event
|
||||
{
|
||||
/// <summary>
|
||||
/// evId
|
||||
/// </summary>
|
||||
[SugarColumn(IsPrimaryKey = true)]
|
||||
public int evId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// evType
|
||||
/// </summary>
|
||||
[SugarColumn(Length = 255, IsNullable = true)]
|
||||
public string? evType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// eventData
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public string? eventData { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// offsetData
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public string? offsetData { get; set; }
|
||||
}
|
||||
}
|
||||
13
Service/Application.Domain/Enum/MapEnum.cs
Normal file
13
Service/Application.Domain/Enum/MapEnum.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
namespace Application.Domain;
|
||||
|
||||
public class MapEnum
|
||||
{
|
||||
public enum RunEvent
|
||||
{
|
||||
reduce_goods,
|
||||
reduce_blood,
|
||||
reduce_vigour,
|
||||
add_blood,
|
||||
add_copper,
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
@@ -16,13 +16,15 @@ namespace Application.Web.Controllers.Login
|
||||
private readonly IGameAccountService _accountService;
|
||||
private readonly IAreaService _areaService;
|
||||
private readonly IUnitUserService _userService;
|
||||
private readonly IUnitUserAttrService _attrService;
|
||||
|
||||
public LoginController(IGameAccountService accountService, IAreaService areaService,
|
||||
IUnitUserService userService)
|
||||
IUnitUserService userService,IUnitUserAttrService attrService)
|
||||
{
|
||||
_accountService = accountService;
|
||||
_areaService = areaService;
|
||||
_userService = userService;
|
||||
_attrService = attrService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -271,6 +273,10 @@ namespace Application.Web.Controllers.Login
|
||||
loadData.Add("accId", userInfo.accId);
|
||||
loadData.Add("areaId", userInfo.areaId);
|
||||
string token = JwtHelper.CreateToken(Key, Issuer, Audience, loadData, TokenConfig.TokenTime);
|
||||
|
||||
//记录在线时间
|
||||
await _attrService.UpdateOnLineTime(userInfo.userId, "Default", TokenConfig.TokenTime);
|
||||
|
||||
return PoAction.Ok(new
|
||||
{ token = token, refToken = userInfo.token, userId = userInfo.userId });
|
||||
}
|
||||
|
||||
@@ -46,7 +46,8 @@ public class MapController : ControllerBase
|
||||
int area = StateHelper.areaId;
|
||||
game_city_map mapInfo = new game_city_map();
|
||||
|
||||
#region 前置条件处理
|
||||
#region 前置条件处理
|
||||
|
||||
var userRunInfo = await _mapService.GetUserRun(userId);
|
||||
if (userRunInfo.status != 0)
|
||||
{
|
||||
@@ -104,10 +105,26 @@ public class MapController : ControllerBase
|
||||
string ip = ComHelper.GetClientUserIp(HttpContext);
|
||||
await _mapService.UpdateUserOnMap(userId, ip, mapInfo.mapId);
|
||||
|
||||
//地图业务
|
||||
IEnumerable<object> business = new List<object>();
|
||||
if (mapInfo.isBus == 1)
|
||||
{
|
||||
var busData = await _mapService.GetMapBus(mapInfo.mapId, 0, 0);
|
||||
business = busData.Select(it => new
|
||||
{
|
||||
busId = it.busId,
|
||||
busName = it.busName
|
||||
});
|
||||
}
|
||||
//地图资源
|
||||
List<game_city_map_res> mapRes = new List<game_city_map_res>();
|
||||
if (mapInfo.isRes==1)
|
||||
{
|
||||
mapRes = await _mapService.GetMapRes(mapInfo.mapId);
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
object ret = new
|
||||
{
|
||||
mapInfo,
|
||||
@@ -116,7 +133,9 @@ public class MapController : ControllerBase
|
||||
chatData,
|
||||
cityShow,
|
||||
nearUser,
|
||||
noReadMsg = noReadMsg[3]
|
||||
noReadMsg = noReadMsg[3],
|
||||
business,
|
||||
mapRes
|
||||
};
|
||||
|
||||
return PoAction.Ok(ret);
|
||||
@@ -495,6 +514,13 @@ public class MapController : ControllerBase
|
||||
var toCity = await _mapService.GetCityInfoByMapId(runInfo.toMap);
|
||||
int isShip = 0;
|
||||
int safety = 0;
|
||||
string busCode = $"{runInfo.onMap}_{runInfo.toMap}";
|
||||
var busData = await _mapService.GetMapBus(busCode, (int)runInfo.position, (int)runInfo.depth);
|
||||
var business = busData.Select(it => new
|
||||
{
|
||||
busId = it.busId,
|
||||
busName = it.busName
|
||||
});
|
||||
|
||||
return PoAction.Ok(new
|
||||
{
|
||||
@@ -503,7 +529,8 @@ public class MapController : ControllerBase
|
||||
distance = runInfo.distance,
|
||||
position = runInfo.position,
|
||||
isShip = isShip,
|
||||
safety = safety
|
||||
safety = safety,
|
||||
business
|
||||
});
|
||||
}
|
||||
|
||||
@@ -540,6 +567,7 @@ public class MapController : ControllerBase
|
||||
{
|
||||
return PoAction.Message("不在航行状态", 100);
|
||||
}
|
||||
|
||||
var userShip = await _weightService.GetUserShip(userId);
|
||||
if (userShip.Count == 0)
|
||||
{
|
||||
@@ -560,7 +588,8 @@ public class MapController : ControllerBase
|
||||
runInfo.upTime = TimeExtend.GetTimeStampSeconds;
|
||||
if (await _mapService.UpdateUserRunInfo(runInfo))
|
||||
{
|
||||
return PoAction.Ok(true);
|
||||
string msg = await _mapService.GetUserRunEvent(userId);
|
||||
return PoAction.Ok(true, msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
1
Web/src/pages/map/business.vue
Normal file
1
Web/src/pages/map/business.vue
Normal file
@@ -0,0 +1 @@
|
||||
<template></template>
|
||||
@@ -23,6 +23,17 @@
|
||||
<Abar :href='"/map/npc?npc=" + item.npcId'>{{ item.npcName }}{{ item.tips }}</Abar>
|
||||
</div>
|
||||
</div>
|
||||
<div class="content" v-if="business.length > 0">
|
||||
<div class="item" v-for="item in business">
|
||||
<Abar :href='"/map/business?id=" + item.busId'>{{ item.busName }}</Abar>
|
||||
</div>
|
||||
</div>
|
||||
<div class="content" v-if="mapRes.length > 0">
|
||||
特产:<br>
|
||||
<div class="item" v-for="item in mapRes">
|
||||
<Abutton>{{item.resName}}</Abutton>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="content">
|
||||
请选择出口:<br />
|
||||
@@ -91,6 +102,8 @@ const npcData = ref<Array<any>>([]);
|
||||
const chatData = ref<Array<any>>([]);
|
||||
const cityShow = ref<Array<any>>([]);
|
||||
const mapUser = ref<Array<any>>([]);
|
||||
const business = ref<Array<any>>([]);
|
||||
const mapRes = ref<Array<any>>([]);
|
||||
const messageCount = ref(0);
|
||||
// 城内地图显示
|
||||
const showCity = ref(false);
|
||||
@@ -115,6 +128,8 @@ const BindData = async (map: string): Promise<void> => {
|
||||
cityShow.value = result.data.cityShow;
|
||||
mapUser.value = result.data.nearUser;
|
||||
messageCount.value = result.data.noReadMsg;
|
||||
business.value = result.data.business;
|
||||
mapRes.value = result.data.mapRes;
|
||||
MapVent(result.data.mapInfo.near);
|
||||
onMap.value = mapInfo.value.mapId;
|
||||
console.log(result.data);
|
||||
|
||||
@@ -14,6 +14,11 @@
|
||||
</div>
|
||||
<div class="content">
|
||||
您看到:<br>
|
||||
<div class="common">
|
||||
<span v-for="item in business">
|
||||
<Abar :href='"/map/business?id="+item.busId'>{{ item.busName }}</Abar>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
@@ -28,6 +33,7 @@ const position = ref(0);
|
||||
const isShip = ref(0);
|
||||
const safety = ref(0);
|
||||
const runState = ref(0);
|
||||
const business = ref<Array<any>>([]);
|
||||
onMounted(async () => {
|
||||
try {
|
||||
await BindData();
|
||||
@@ -47,6 +53,7 @@ const BindData = async (): Promise<void> => {
|
||||
position.value = result.data.position;
|
||||
isShip.value = result.data.isShip;
|
||||
safety.value = result.data.safety;
|
||||
business.value = result.data.business;
|
||||
if (runState.value == 1) {
|
||||
setTimeout(async () => {
|
||||
await Runing();
|
||||
@@ -64,12 +71,17 @@ const BindData = async (): Promise<void> => {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
let runLock = false;
|
||||
const Runing = async () => {
|
||||
MessageExtend.LoadingToast("航行中...");
|
||||
if (runLock) {
|
||||
return;
|
||||
}
|
||||
runLock = true;
|
||||
let result = await MapService.UserMapRuning();
|
||||
MessageExtend.LoadingClose();
|
||||
if (result.code == 0) {
|
||||
if (result.msg != '') {
|
||||
MessageExtend.ShowToast(result.msg);
|
||||
}
|
||||
await BindData();
|
||||
}
|
||||
else if (result.code == 100) {
|
||||
@@ -78,6 +90,7 @@ const Runing = async () => {
|
||||
else {
|
||||
MessageExtend.ShowDialog("提示", result.msg);
|
||||
}
|
||||
runLock = false;
|
||||
}
|
||||
|
||||
const StopRun = async () => {
|
||||
|
||||
Reference in New Issue
Block a user