12121
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
|
||||
namespace Application.Domain.Entity
|
||||
{
|
||||
[Tenant("Kg.SeaTime.Log")]
|
||||
public class game_exchange_log
|
||||
{
|
||||
/// <summary>
|
||||
/// ueId
|
||||
/// </summary>
|
||||
[SugarColumn(IsPrimaryKey = true, Length = 50)]
|
||||
public string ueId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// userId
|
||||
/// </summary>
|
||||
[SugarColumn(Length = 50, IsNullable = true)]
|
||||
public string? userId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// exId
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public int? exId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// count
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public int? count { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// addTime
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public long? addTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// endTime
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public long? endTime { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
|
||||
namespace Application.Domain.Entity
|
||||
{
|
||||
[Tenant("Kg.SeaTime.Resource")]
|
||||
public class game_exchange
|
||||
{
|
||||
/// <summary>
|
||||
/// exId
|
||||
/// </summary>
|
||||
[SugarColumn(IsPrimaryKey = true)]
|
||||
public int exId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// areaId
|
||||
/// </summary>
|
||||
[SugarColumn(Length = 50, IsNullable = true)]
|
||||
public string? areaId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// npcId
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public int? npcId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// name
|
||||
/// </summary>
|
||||
[SugarColumn(Length = 50, IsNullable = true)]
|
||||
public string? name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// tips
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public string? tips { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// exType
|
||||
/// </summary>
|
||||
[SugarColumn(Length = 50, IsNullable = true)]
|
||||
public string? exType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// count
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public int? count { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// needData
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true,IsJson = true)]
|
||||
public List<TowerNeed> needData { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// getData
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true,IsJson = true)]
|
||||
public List<TowerGet> getData { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// startTime
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public DateTime? startTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// endTime
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public DateTime? endTime { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -4,18 +4,18 @@ public static class GameConfig
|
||||
{
|
||||
public const int GameMaxLev = 320;//最大等级
|
||||
public const int OnLineTime = 30;//在线延迟时间(分钟)
|
||||
public const int SendChatGoodsBase = 10014;//小海螺
|
||||
public const int SendChatGoodsBase = 10000;//小海螺
|
||||
public const int SendChatGoodsArea = 10001;//大海螺
|
||||
public const int SendChatGoodsService = 10002;//金海螺
|
||||
public const int UpLevAddWeight = 10;//升级增加负重
|
||||
public const int GameBaseVigour = 50;//初始活力
|
||||
public const int GameRelationEnemyNeedGold = 300;//添加仇人所需金元
|
||||
public const int GameUpdateNickNeedGoods = 10001;//更新昵称所需道具
|
||||
public const int GameUpdateSexNeedGoods = 10001;//更新性别所需道具
|
||||
public const int GameUpdateNickNeedGoods = 10018;//更新昵称所需道具
|
||||
public const int GameUpdateSexNeedGoods = 10065;//更新性别所需道具
|
||||
public const int GameUserFriendMaxCount = 50;//好友最大上限人数
|
||||
public const int GameAutoBagGoodsId = 10001;//百宝箱物品ID
|
||||
public const int GameAutoDrugGoodsId = 10001;//急救箱物品ID
|
||||
public const int GameAutoBagGoodsId = 10022;//百宝箱物品ID
|
||||
public const int GameAutoDrugGoodsId = 10023;//急救箱物品ID
|
||||
public const int GameToMapNeedCopper = 5;//传送每海里费用
|
||||
public const int TeamCacheTime = 300;//队伍缓存时间
|
||||
public const int GameEquApprGoods = 10001;//鉴定装备道具
|
||||
public const int GameEquApprGoods = 10019;//鉴定装备道具
|
||||
}
|
||||
@@ -59,6 +59,7 @@ public static class GameEnum
|
||||
MapTo,
|
||||
Store,
|
||||
Make,
|
||||
Exchange,
|
||||
}
|
||||
|
||||
public enum DicCode
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace Application.Domain;
|
||||
|
||||
public interface IExchangeService
|
||||
{
|
||||
Task<List<game_exchange>> GetExchangeData(int npcId);
|
||||
Task<game_exchange> GetExchangeInfo(int exId);
|
||||
Task<int> GetExchangeCount(string userId, int exId);
|
||||
Task<bool> AddUserExchangeLog(string userId, int exId, int count, long endTime);
|
||||
}
|
||||
@@ -18,7 +18,7 @@ public interface IGameEquService
|
||||
Task<List<unit_user_equ>> GetUserEquData(string userId, string code, List<string> noUeId);
|
||||
Task<unit_user_equ> GetUserEquInfo(string ueId);
|
||||
Task<int> GetUserEquByEquIdCount(string userId, int equId);
|
||||
Task<List<unit_user_equ>> GetUserEquByEquId(string userId, int equId);
|
||||
Task<List<unit_user_equ>> GetUserEquByEquIdToDeduct(string userId, int equId);
|
||||
Task<bool> AddUserEqu(string userId, int equId, int count, string remark);
|
||||
Task<bool> AddUserEqu(unit_user_equ equData, string remark);
|
||||
Task<unit_user_equ> AddUserEqu(string userId, int equId, bool rdAttr = false, string remark = "");
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
namespace Application.Domain;
|
||||
|
||||
public class ExchangeService(ISqlSugarClient DbClient, IRedisCache redis) : IExchangeService, ITransient
|
||||
{
|
||||
public async Task<List<game_exchange>> GetExchangeData(int npcId)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<game_exchange>();
|
||||
var data = await db.Queryable<game_exchange>().Where(it => it.npcId == npcId).ToListAsync();
|
||||
return data;
|
||||
}
|
||||
|
||||
public async Task<game_exchange> GetExchangeInfo(int exId)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<game_exchange>();
|
||||
return await db.Queryable<game_exchange>().Where(it => it.exId == exId).SingleAsync();
|
||||
}
|
||||
|
||||
public async Task<int> GetExchangeCount(string userId, int exId)
|
||||
{
|
||||
int result = 0;
|
||||
string key = $"{userId}_{exId}";
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<game_exchange_log>();
|
||||
return await db.Queryable<game_exchange_log>().Where(it => it.userId == userId && it.exId == exId)
|
||||
.SumAsync(it => (int)it.count);
|
||||
}
|
||||
|
||||
public async Task<bool> AddUserExchangeLog(string userId, int exId, int count,long endTime)
|
||||
{
|
||||
game_exchange_log log = new game_exchange_log();
|
||||
log.ueId = StringAssist.NewGuid;
|
||||
log.userId = userId;
|
||||
log.exId = exId;
|
||||
log.count = count;
|
||||
log.addTime = TimeExtend.GetTimeStampSeconds;
|
||||
log.endTime = endTime;
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<game_exchange_log>();
|
||||
bool result = await db.Insertable(log).ExecuteCommandAsync() > 0;
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -78,16 +78,21 @@ public class GameEquService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
|
||||
public async Task<int> GetUserEquByEquIdCount(string userId, int equId)
|
||||
{
|
||||
int result = 0;
|
||||
var data = await GetUserEquByEquId(userId, equId);
|
||||
var data = await GetUserEquData(userId, equId);
|
||||
result = data.Count;
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<List<unit_user_equ>> GetUserEquByEquId(string userId, int equId)
|
||||
public async Task<List<unit_user_equ>> GetUserEquByEquIdToDeduct(string userId, int equId)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_equ>();
|
||||
return await db.Queryable<unit_user_equ>().Where(i => i.userId == userId && i.equId == equId).ToListAsync();
|
||||
var userEqu = await GetUserEquData(userId, equId);
|
||||
userEqu = userEqu.FindAll(it => it.isLock == 0 && it.isOn == 0);
|
||||
userEqu = userEqu.OrderBy(it => (int)it.intensifyLev)
|
||||
.ThenBy(it => it.quality)
|
||||
.ToList();
|
||||
return userEqu;
|
||||
}
|
||||
|
||||
|
||||
public async Task<bool> AddUserEqu(string userId, int equId, int count, string remark)
|
||||
{
|
||||
@@ -358,21 +363,11 @@ public class GameEquService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
|
||||
|
||||
public async Task<bool> DeductUserEqu(string userId, int equId, int count, string remark)
|
||||
{
|
||||
var userEqu = await GetUserEquData(userId, equId);
|
||||
var userEqu = await GetUserEquByEquIdToDeduct(userId, equId);
|
||||
if (userEqu.Count < 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
userEqu = userEqu.FindAll(it => it.isLock == 0 && it.isOn == 0);
|
||||
if (userEqu.Count < count)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
userEqu = userEqu.OrderBy(it => (int)it.intensifyLev)
|
||||
.OrderBy(it => it.quality)
|
||||
.ToList();
|
||||
var opData = userEqu.Take(count).ToList();
|
||||
return await DeductUserEqu(userId, opData, remark);
|
||||
}
|
||||
|
||||
@@ -48,42 +48,42 @@ public class EquTool
|
||||
return onAttr;
|
||||
}
|
||||
|
||||
int result = onLev * 3;
|
||||
result = result > 57 ? 57 : result;
|
||||
int result = onLev;
|
||||
result = result > 19 ? 19 : result;
|
||||
|
||||
if (onLev > 19)
|
||||
{
|
||||
int addLev = onLev - 19;
|
||||
addLev = addLev > 10 ? 10 : addLev;
|
||||
result += addLev * 5;
|
||||
result += addLev * 3;
|
||||
}
|
||||
|
||||
if (onLev > 29)
|
||||
{
|
||||
int addLev = onLev - 29;
|
||||
addLev = addLev > 10 ? 10 : addLev;
|
||||
result += addLev * 10;
|
||||
result += addLev * 5;
|
||||
}
|
||||
|
||||
if (onLev > 39)
|
||||
{
|
||||
int addLev = onLev - 39;
|
||||
addLev = addLev > 10 ? 10 : addLev;
|
||||
result += addLev * 15;
|
||||
result += addLev * 10;
|
||||
}
|
||||
|
||||
if (onLev > 49)
|
||||
{
|
||||
int addLev = onLev - 49;
|
||||
addLev = addLev > 10 ? 10 : addLev;
|
||||
result += addLev * 20;
|
||||
result += addLev * 15;
|
||||
}
|
||||
|
||||
if (onLev > 59)
|
||||
{
|
||||
int addLev = onLev - 59;
|
||||
addLev = addLev > 10 ? 10 : addLev;
|
||||
result += addLev * 25;
|
||||
result += addLev * 20;
|
||||
}
|
||||
|
||||
if (onLev > 69)
|
||||
@@ -91,7 +91,7 @@ public class EquTool
|
||||
int addLev = onLev - 69;
|
||||
addLev = addLev > 10 ? 10 : addLev;
|
||||
int unitAdd = Convert.ToInt32(onAttr * 0.05);
|
||||
unitAdd = unitAdd < 30 ? 30 : unitAdd;
|
||||
unitAdd = unitAdd < 25 ? 25 : unitAdd;
|
||||
result += addLev * unitAdd;
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ public class EquTool
|
||||
int addLev = onLev - 79;
|
||||
addLev = addLev > 10 ? 10 : addLev;
|
||||
int unitAdd = Convert.ToInt32(onAttr * 0.1);
|
||||
unitAdd = unitAdd < 35 ? 35 : unitAdd;
|
||||
unitAdd = unitAdd < 30 ? 30 : unitAdd;
|
||||
result += addLev * unitAdd;
|
||||
}
|
||||
|
||||
@@ -109,7 +109,7 @@ public class EquTool
|
||||
int addLev = onLev - 89;
|
||||
addLev = addLev > 10 ? 10 : addLev;
|
||||
int unitAdd = Convert.ToInt32(onAttr * 0.15);
|
||||
unitAdd = unitAdd < 40 ? 40 : unitAdd;
|
||||
unitAdd = unitAdd < 35 ? 35 : unitAdd;
|
||||
result += addLev * unitAdd;
|
||||
}
|
||||
|
||||
|
||||
@@ -112,7 +112,8 @@ public static class GameBus
|
||||
if (item.code == nameof(GameEnum.PropCode.Equ))
|
||||
{
|
||||
var equService = App.GetService<IGameEquService>();
|
||||
int MyCount = await equService.GetUserEquByEquIdCount(userId, Convert.ToInt32(item.parameter));
|
||||
var myOpEqu = await equService.GetUserEquByEquIdToDeduct(userId, Convert.ToInt32(item.parameter));
|
||||
int MyCount = myOpEqu.Count;
|
||||
long needCount = item.count * count;
|
||||
item.count = needCount;
|
||||
item.onCount = MyCount;
|
||||
|
||||
169
Service/Application.Web/Controllers/Pub/ExchangeController.cs
Normal file
169
Service/Application.Web/Controllers/Pub/ExchangeController.cs
Normal file
@@ -0,0 +1,169 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Application.Web.Controllers.Pub;
|
||||
|
||||
/// <summary>
|
||||
/// 兑换接口
|
||||
/// </summary>
|
||||
[Route("[controller]/[action]")]
|
||||
[ApiController]
|
||||
[Authorize]
|
||||
public class ExchangeController : ControllerBase
|
||||
{
|
||||
private readonly IGameMapService _mapService;
|
||||
private readonly IExchangeService _exchangeService;
|
||||
|
||||
public ExchangeController(IGameMapService mapService, IExchangeService exchangeService)
|
||||
{
|
||||
_mapService = mapService;
|
||||
_exchangeService = exchangeService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取兑换信息
|
||||
/// </summary>
|
||||
/// <param name="npcId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<IPoAction> GetExchangeData(int npcId)
|
||||
{
|
||||
string userId = StateHelper.userId;
|
||||
int areaId = StateHelper.areaId;
|
||||
var npcInfo = await _mapService.GetNpcInfo(npcId);
|
||||
if (npcInfo == null)
|
||||
{
|
||||
return PoAction.Message("Npc不存在!");
|
||||
}
|
||||
|
||||
if (npcInfo.status != 1)
|
||||
{
|
||||
return PoAction.Message("Npc不存在!");
|
||||
}
|
||||
|
||||
if (!npcInfo.bus.Any(it => it.code == nameof(GameEnum.NpcBusCode.Exchange)))
|
||||
{
|
||||
return PoAction.Message("业务不可用!");
|
||||
}
|
||||
|
||||
var onMap = await _mapService.GetUserOnMapId(userId);
|
||||
if (npcInfo.mapId != onMap)
|
||||
{
|
||||
return PoAction.Message("Npc不存在!");
|
||||
}
|
||||
|
||||
var data = await _exchangeService.GetExchangeData(npcId);
|
||||
data = data.FindAll(it => GameTool.AreaVerify(areaId, it.areaId) && it.endTime > DateTime.Now);
|
||||
|
||||
return PoAction.Ok(data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 兑换物品
|
||||
/// </summary>
|
||||
/// <param name="npcId"></param>
|
||||
/// <param name="exId"></param>
|
||||
/// <param name="count"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<IPoAction> ExchangeOk(int npcId, int exId, int count)
|
||||
{
|
||||
count = count < 1 ? 1 : count;
|
||||
string userId = StateHelper.userId;
|
||||
int areaId = StateHelper.areaId;
|
||||
var npcInfo = await _mapService.GetNpcInfo(npcId);
|
||||
if (npcInfo == null)
|
||||
{
|
||||
return PoAction.Message("Npc不存在!");
|
||||
}
|
||||
|
||||
if (npcInfo.status != 1)
|
||||
{
|
||||
return PoAction.Message("Npc不存在!");
|
||||
}
|
||||
|
||||
if (!npcInfo.bus.Any(it => it.code == nameof(GameEnum.NpcBusCode.Exchange)))
|
||||
{
|
||||
return PoAction.Message("业务不可用!");
|
||||
}
|
||||
|
||||
var onMap = await _mapService.GetUserOnMapId(userId);
|
||||
if (npcInfo.mapId != onMap)
|
||||
{
|
||||
return PoAction.Message("Npc不存在!");
|
||||
}
|
||||
|
||||
var exInfo = await _exchangeService.GetExchangeInfo(exId);
|
||||
if (exInfo == null)
|
||||
{
|
||||
return PoAction.Message("兑换不存在!");
|
||||
}
|
||||
|
||||
if (exInfo.endTime < DateTime.Now)
|
||||
{
|
||||
return PoAction.Message("兑换已结束!");
|
||||
}
|
||||
|
||||
if (GameTool.AreaVerify(areaId, exInfo.areaId) == false)
|
||||
{
|
||||
return PoAction.Message("兑换不存在!");
|
||||
}
|
||||
|
||||
int sumCount = await _exchangeService.GetExchangeCount(userId, exId);
|
||||
if ((sumCount + count) > exInfo.count)
|
||||
{
|
||||
int endCount = (int)exInfo.count - sumCount;
|
||||
if (endCount == 0)
|
||||
{
|
||||
return PoAction.Message("您已达到兑换上限!");
|
||||
}
|
||||
else
|
||||
{
|
||||
return PoAction.Message($"您最多还能兑换{endCount}次!");
|
||||
}
|
||||
}
|
||||
|
||||
var result = await GameBus.CheckNeed(userId, exInfo.needData, count);
|
||||
if (result.result)
|
||||
{
|
||||
if (await GameBus.UpdateBag(userId, 0, exInfo.needData, "兑换", count))
|
||||
{
|
||||
long endTime = 0;
|
||||
switch (exInfo.exType)
|
||||
{
|
||||
case "Long":
|
||||
endTime = TimeExtend.GetTimeStampBySeconds((DateTime)exInfo.endTime);
|
||||
break;
|
||||
case "Day":
|
||||
endTime = TimeExtend.GetTimeStampBySeconds(TimeAssist.GetDateTimeYMD(1));
|
||||
break;
|
||||
case "Month":
|
||||
DateTime nt = DateTime.Now.AddMonths(1);
|
||||
nt = Convert.ToDateTime($"{nt.Year}-{nt.Month}-01");
|
||||
endTime = TimeExtend.GetTimeStampBySeconds(nt);
|
||||
break;
|
||||
case "Week":
|
||||
endTime = TimeExtend.GetTimeStampBySeconds(TimeAssist.WeekEndTime);
|
||||
break;
|
||||
}
|
||||
|
||||
if (await _exchangeService.AddUserExchangeLog(userId, exId, count, endTime))
|
||||
{
|
||||
await GameBus.UpdateBag(userId, 1, exInfo.getData, "兑换", count);
|
||||
return PoAction.Ok(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
return PoAction.Message("兑换失败,请稍后尝试!");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return PoAction.Message("兑换失败,请稍后尝试!");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return PoAction.Message("兑换失败,请稍后尝试!");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user