This commit is contained in:
Putoo
2026-06-18 18:54:22 +08:00
parent 4297019836
commit ad49fbb1b1
42 changed files with 1694 additions and 62 deletions

View File

@@ -0,0 +1,7 @@
namespace Application.Domain.Entity;
public class RandomDataBase
{
public double random { get; set; }
public object data { get; set; }
}

View File

@@ -0,0 +1,81 @@
using SqlSugar;
using System;
namespace Application.Domain.Entity
{
[Tenant("Kg.SeaTime.Resource")]
public class game_equ_attr
{
/// <summary>
/// erId
/// </summary>
[SugarColumn(IsPrimaryKey = true, Length = 50)]
public string erId { get; set; }
/// <summary>
/// equCode
/// </summary>
[SugarColumn(Length = 50, IsNullable = true)]
public string? equCode { get; set; }
/// <summary>
/// minLev
/// </summary>
[SugarColumn(IsNullable = true)]
public int? minLev { get; set; }
/// <summary>
/// maxLev
/// </summary>
[SugarColumn(IsNullable = true)]
public int? maxLev { get; set; }
/// <summary>
/// 权重
/// </summary>
[SugarColumn(IsNullable = true)]
public int? random { get; set; }
/// <summary>
/// 属性类型Number 数值 float 百分比
/// </summary>
[SugarColumn(Length = 50, IsNullable = true)]
public string? nt { get; set; }
/// <summary>
/// 属性
/// </summary>
[SugarColumn(Length = 50, IsNullable = true)]
public string? code { get; set; }
/// <summary>
/// compute
/// </summary>
[SugarColumn(Length = 50, IsNullable = true)]
public string? compute { get; set; }
/// <summary>
/// min_v
/// </summary>
[SugarColumn(Length = 18, IsNullable = true)]
public decimal? min_v { get; set; }
/// <summary>
/// max_v
/// </summary>
[SugarColumn(Length = 18, IsNullable = true)]
public decimal? max_v { get; set; }
/// <summary>
/// tips
/// </summary>
[SugarColumn(Length = 255, IsNullable = true)]
public string? tips { get; set; }
/// <summary>
/// remark
/// </summary>
[SugarColumn(Length = 255, IsNullable = true)]
public string? remark { get; set; }
}
}

View File

@@ -0,0 +1,45 @@
using SqlSugar;
using System;
namespace Application.Domain.Entity
{
[Tenant("Kg.SeaTime.Resource")]
public class game_equ_make
{
/// <summary>
/// mkId
/// </summary>
[SugarColumn(IsPrimaryKey = true, Length = 50)]
public string mkId { get; set; }
/// <summary>
/// goodsId
/// </summary>
[SugarColumn(IsNullable = true)]
public int? goodsId { get; set; }
/// <summary>
/// equId
/// </summary>
[SugarColumn(IsNullable = true)]
public int? equId { get; set; }
/// <summary>
/// equName
/// </summary>
[SugarColumn(Length = 50, IsNullable = true)]
public string? equName { get; set; }
/// <summary>
/// random
/// </summary>
[SugarColumn(IsNullable = true)]
public int? random { get; set; }
/// <summary>
/// 是否随机特性
/// </summary>
[SugarColumn(IsNullable = true)]
public int? rdAttr { get; set; }
}
}

View File

@@ -0,0 +1,7 @@
namespace Application.Domain.Entity;
public class MakePaperView
{
public game_goods goods { get; set; }
public long count { get; set; }
}

View File

@@ -17,4 +17,5 @@ public static class GameConfig
public const int GameAutoDrugGoodsId = 10001;//急救箱物品ID
public const int GameToMapNeedCopper = 5;//传送每海里费用
public const int TeamCacheTime = 300;//队伍缓存时间
public const int GameEquApprGoods = 10001;//鉴定装备道具
}

View File

@@ -55,11 +55,15 @@ public static class GameEnum
RetBlood,
RetMorale,
RetVigour,
RetEqu,
MapTo,
Store,
Make,
}
public enum DicCode
{
Awaken,//觉醒配置
Quality,//洗练配置
}
}

View File

@@ -20,7 +20,8 @@ public interface IGameEquService
Task<int> GetUserEquByEquIdCount(string userId, int equId);
Task<List<unit_user_equ>> GetUserEquByEquId(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 = "");
Task<bool> UpdateUserEquInfo(unit_user_equ equData, bool isAddLog = false, string code = "",
string remark = "");
@@ -44,14 +45,22 @@ public interface IGameEquService
#endregion
#region /
Task<List<AttrItem>> GetRandomEquAttr(string equCode, int lev);
#endregion
#region
Task<game_equ_up> GetUserEquUpData(int lev);
#endregion
#region
Task<int> GetUserEquWeightSum(string userId);
Task<game_equ_make> GetMakeEquByGoodsId(int goodsId);
#endregion
}

View File

@@ -180,6 +180,115 @@ public class GameEquService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
return result;
}
public async Task<bool> AddUserEqu(unit_user_equ equData, string remark)
{
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_equ>();
var result = await db.Insertable(equData).ExecuteCommandAsync() > 0;
if (result)
{
//添加日志
await AddEquLogs([equData], 1, remark, true);
//更新负重
int weightCount = Convert.ToInt32(equData.weight);
if (weightCount > 0)
{
var attrService = App.GetService<IUnitUserWeight>();
await attrService.UpdateUserWeight(equData.userId, 1, weightCount);
}
}
return result;
}
public async Task<unit_user_equ> AddUserEqu(string userId, int equId, bool rdAttr = false, string remark = "")
{
var equ = await GetEquInfo(equId);
if (equ == null)
{
return null;
}
unit_user_equ ue = new unit_user_equ();
string ueId = StringAssist.NewGuid;
ue.ueId = ueId;
ue.userId = userId;
ue.owerId = userId;
ue.equId = equ.equId;
ue.equName = equ.equName;
ue.unitEquName = equ.equName;
ue.img = equ.img;
ue.sign = "";
ue.isAppr = 1;
if (equ.isAppr == 0)
{
ue.minAtk = equ.minAtk;
ue.maxAtk = equ.maxAtk;
ue.Defense = Convert.ToInt32(equ.defense);
ue.Agility = Convert.ToInt32(equ.agility);
ue.Morale = Convert.ToInt32(equ.morale);
ue.Blood = Convert.ToInt32(equ.blood);
}
else
{
ue.minAtk = RandomAssist.GetFormatedNumeric((int)equ.minAtk, (int)equ.maxAtk);
ue.maxAtk = RandomAssist.GetFormatedNumeric((int)equ.minAtk, (int)equ.maxAtk);
string[] def = equ.defense.Split('-');
ue.Defense = RandomAssist.GetFormatedNumeric(Convert.ToInt32(def[0]), Convert.ToInt32(def[1]));
string[] agi = equ.agility.Split('-');
ue.Agility = RandomAssist.GetFormatedNumeric(Convert.ToInt32(agi[0]), Convert.ToInt32(agi[1]));
string[] mor = equ.morale.Split('-');
ue.Morale = RandomAssist.GetFormatedNumeric(Convert.ToInt32(mor[0]), Convert.ToInt32(mor[1]));
string[] blo = equ.blood.Split('-');
ue.Blood = RandomAssist.GetFormatedNumeric(Convert.ToInt32(blo[0]), Convert.ToInt32(blo[1]));
}
ue.code = equ.code;
ue.suitCode = equ.suitCode;
ue.lev = equ.lev;
ue.durability = equ.durability;
ue.maxdurability = equ.durability;
ue.isIntensify = equ.isIntensify;
ue.intensifyLev = 0;
ue.isLock = 0;
ue.holeCount = equ.holeCount;
ue.sex = equ.sex;
ue.weight = equ.weight;
ue.sysPrice = equ.sysPrice;
ue.qualityAttr = new List<AttrItem>();
if (rdAttr == false)
{
ue.quality = equ.quality;
ue.qualityName = GameTool.GetEquQualityName((int)ue.quality);
ue.EquAttr = equ.equAttr;
}
else
{
var randomAttr = await GetRandomEquAttr(equ.code, (int)equ.lev);
ue.quality = randomAttr.Count;
ue.qualityName = GameTool.GetEquQualityName((int)ue.quality);
ue.EquAttr = randomAttr;
}
ue.canEqualUp = equ.canEqualUp;
ue.isDeal = equ.isDeal;
ue.isGive = equ.isGive;
ue.opTime = 0;
ue.start = 0;
ue.EquMent = new EquMent();
ue.EquAwaken = new List<EquAwaken>();
ue.GemMent = new List<EquGem>();
ue.useEndTime = TimeExtend.GetTimeStampBySeconds(DateTime.Now.AddYears(20));
ue.isOn = 0;
if (await AddUserEqu(ue, remark))
{
return ue;
}
else
{
return null;
}
}
public async Task<bool> UpdateUserEquInfo(unit_user_equ equData, bool isAddLog = false, string code = "",
string remark = "")
{
@@ -507,6 +616,93 @@ public class GameEquService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
#endregion
#region /
private async Task<List<game_equ_attr>> GetEquAttrData(string erCode)
{
string key = string.Format(BaseCache.BaseCacheKeys, "EquData", "EquAttrData");
if (await redis.HExistsHashAsync(key, erCode))
{
return await redis.GetHashAsync<List<game_equ_attr>>(key, erCode);
}
var db = DbClient.AsTenant().GetConnectionWithAttr<game_equ_attr>();
var data = await db.Queryable<game_equ_attr>().Where(it => it.equCode == erCode).ToListAsync();
await redis.AddHashAsync(key, erCode, data);
return data;
}
public async Task<List<AttrItem>> GetRandomEquAttr(string equCode, int lev)
{
//计算出的数量
List<RandomDataBase> numData = new List<RandomDataBase>()
{
new RandomDataBase() { random = 100, data = 1 },
new RandomDataBase() { random = 90, data = 2 },
new RandomDataBase() { random = 80, data = 3 },
new RandomDataBase() { random = 50, data = 4 },
new RandomDataBase() { random = 30, data = 5 },
new RandomDataBase() { random = 15, data = 6 },
new RandomDataBase() { random = 5, data = 7 },
};
var numR = GameBus.GetRandomByWeight(numData);
int onNum = Convert.ToInt32(numR.data);
var attrData = await GetEquAttrData(equCode);
attrData = attrData.FindAll(it => it.minLev <= lev && it.maxLev >= lev);
//开始随机拿属性权重
List<object> data = new List<object>();
List<ushort> weights = new List<ushort>();
List<object> attrResult = new List<object>();
Random rand = new Random();
foreach (var item in attrData)
{
data.Add(item);
weights.Add(ushort.Parse(item.random.ToString()));
}
RandomAssist random = new RandomAssist(onNum);
attrResult = random.ControllerRandomExtract(rand, data, weights);
List<AttrItem> result = new List<AttrItem>();
if (attrResult.Count > 0)
{
foreach (var item in attrResult)
{
var onAttr = item as game_equ_attr;
AttrItem temp = new AttrItem();
temp.code = onAttr.code;
temp.compute = onAttr.compute;
if (onAttr.nt == "Number")
{
int onMin = Convert.ToInt32(onAttr.min_v);
int onMax = Convert.ToInt32(onAttr.max_v);
int onPar = RandomAssist.GetFormatedNumeric(onMin, onMax + 1);
temp.parameter = onPar;
string onTip = temp.parameter.ToString().TrimEnd('0').TrimEnd('.');
temp.tip = string.Format(onAttr.tips, onTip);
}
else
{
int onMin = Convert.ToInt32(onAttr.min_v * 100);
int onMax = Convert.ToInt32(onAttr.max_v * 100);
int onPar = RandomAssist.GetFormatedNumeric(onMin, onMax + 1);
temp.parameter = Math.Round(Convert.ToDecimal(onPar / 100.000M), 2);
string onTip = (temp.parameter * 100).ToString().TrimEnd('0').TrimEnd('.');
temp.tip = string.Format(onAttr.tips, onTip);
}
result.Add(temp);
}
}
return result;
}
#endregion
#region
public async Task<game_equ_up> GetUserEquUpData(int lev)
@@ -522,9 +718,9 @@ public class GameEquService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
await redis.AddHashAsync(key, lev.ToString(), data);
}
}
return data;
}
#endregion
@@ -537,5 +733,43 @@ public class GameEquService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
return data.Sum(it => (int)it.weight);
}
private async Task<List<game_equ_make>> GetEquMakeData(int goodsId)
{
string key = string.Format(BaseCache.BaseCacheKeys, "EquData", "EquUpData");
if (await redis.HExistsHashAsync(key, goodsId.ToString()))
{
return await redis.GetHashAsync<List<game_equ_make>>(key, goodsId.ToString());
}
var db = DbClient.AsTenant().GetConnectionWithAttr<game_equ_make>();
var data = await db.Queryable<game_equ_make>().Where(it => it.goodsId == goodsId).ToListAsync();
await redis.AddHashAsync(key, goodsId.ToString(), data);
return data;
}
public async Task<game_equ_make> GetMakeEquByGoodsId(int goodsId)
{
//构建随机数据
List<RandomDataBase> equBase = new List<RandomDataBase>();
var equData = await GetEquMakeData(goodsId);
foreach (var me in equData)
{
RandomDataBase temp = new RandomDataBase();
temp.random = (double)me.random;
temp.data = me;
equBase.Add(temp);
}
var makeEqu = GameBus.GetRandomByWeight(equBase);
if (makeEqu == null)
{
return null;
}
var onMakeEqu = makeEqu.data as game_equ_make;
return onMakeEqu;
}
#endregion
}

View File

@@ -64,6 +64,11 @@ public static class GameBus
isok = await accService.UpdateUserAcc(userId, operate, nameof(AccEnum.AccType.teach), count,
nameof(AccEnum.Name.), remark);
}
else if (goodsType.Equals(nameof(GameEnum.PropCode.map)))
{
var mapService = App.GetService<IGameMapService>();
isok = await mapService.AddUserCityMap(userId, Convert.ToInt32(parameter));
}
return isok;
}
@@ -338,6 +343,7 @@ public static class GameBus
isok = false;
}
}
result.Needs.Add(item);
}
@@ -351,6 +357,28 @@ public static class GameBus
#region
public static RandomDataBase GetRandomByWeight(List<RandomDataBase> data)
{
var _randomInstance = new Random();
if (data.Count == 0)
{
return null;
}
double totalWeight = data.Sum(it => it.random);
int rnd = _randomInstance.Next(Convert.ToInt32(totalWeight) + 1);
double current = 0;
foreach (var item in data)
{
current += item.random;
if (rnd < current)
{
return item;
}
}
return null;
}
public static List<TowerGet> GetRandomGoods(RandomModel random, int count = 1, int luck = 0)
{
List<TowerGet> result = new List<TowerGet>();

View File

@@ -138,7 +138,41 @@ public class GameTool
return result;
}
public static string GetEquQualityName(int count)
{
string result = "白";
switch (count)
{
case 1:
result = "红";
break;
case 2:
result = "橙";
break;
case 3:
result = "黄";
break;
case 4:
result = "绿";
break;
case 5:
result = "青";
break;
case 6:
result = "粉";
break;
case 7:
result = "紫";
break;
case 8:
result = "金";
break;
}
return result;
}
#region
/// <summary>

View File

@@ -50,6 +50,10 @@ public class StoreController : ControllerBase
{
return PoAction.Message("Npc不存在!");
}
if (!npcInfo.bus.Any(it => it.code == nameof(GameEnum.NpcBusCode.Store)))
{
return PoAction.Message("业务不可用!");
}
var onMap = await _mapService.GetUserOnMapId(userId);
if (npcInfo.mapId != onMap)
@@ -84,6 +88,10 @@ public class StoreController : ControllerBase
{
return PoAction.Message("Npc不存在!");
}
if (!npcInfo.bus.Any(it => it.code == nameof(GameEnum.NpcBusCode.Store)))
{
return PoAction.Message("业务不可用!");
}
var onMap = await _mapService.GetUserOnMapId(userId);
if (npcInfo.mapId != onMap)
@@ -157,7 +165,10 @@ public class StoreController : ControllerBase
{
return PoAction.Message("Npc不存在!");
}
if (!npcInfo.bus.Any(it => it.code == nameof(GameEnum.NpcBusCode.Store)))
{
return PoAction.Message("业务不可用!");
}
var onMap = await _mapService.GetUserOnMapId(userId);
if (npcInfo.mapId != onMap)
{

View File

@@ -0,0 +1,134 @@
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
namespace Application.Web.Controllers.Pub;
/// <summary>
/// 业务操作接口
/// </summary>
[Route("[controller]/[action]")]
[ApiController]
[Authorize]
public class BusinessController : ControllerBase
{
private readonly IGameMapService _mapService;
private readonly IGameEquService _equService;
private readonly IGameGoodsService _goodsService;
public BusinessController(IGameEquService equService, IGameGoodsService goodsService, IGameMapService mapService)
{
_equService = equService;
_goodsService = goodsService;
_mapService = mapService;
}
/// <summary>
/// 获取打造图纸
/// </summary>
/// <returns></returns>
[HttpGet]
public async Task<IPoAction> GetEquPaper()
{
string userId = StateHelper.userId;
var data = await _goodsService.GetUserGoodsData(userId, nameof(GoodsEnum.Code.Paper));
List<MakePaperView> result = new List<MakePaperView>();
foreach (var item in data)
{
MakePaperView temp = new MakePaperView();
temp.goods = await _goodsService.GetGoodsInfo((int)item.goodsId);
temp.count = (long)item.count;
result.Add(temp);
}
return PoAction.Ok(result);
}
/// <summary>
/// 打造装备
/// </summary>
/// <param name="npcId"></param>
/// <param name="goodsId"></param>
/// <returns></returns>
[HttpGet]
public async Task<IPoAction> HandleEquPaper(int npcId, int goodsId)
{
string userId = StateHelper.userId;
#region NPC验证
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.Make)))
{
return PoAction.Message("业务不可用!");
}
var onMap = await _mapService.GetUserOnMapId(userId);
if (npcInfo.mapId != onMap)
{
return PoAction.Message("Npc不存在!");
}
#endregion
var myGoods = await _goodsService.GetUserGoodsInfo(userId, goodsId);
if (myGoods == null)
{
return PoAction.Message("暂无图纸!");
}
if (myGoods.count < 1)
{
return PoAction.Message("暂无图纸!");
}
if (myGoods.code != nameof(GoodsEnum.Code.Paper))
{
return PoAction.Message("非图纸材料,无法打造!");
}
string needstr = await _goodsService.GetGoodsContent(goodsId);
var needs = JsonConvert.DeserializeObject<List<TowerNeed>>(needstr);
var check = await GameBus.CheckNeed(userId, needs);
if (check.result)
{
if (await GameBus.UpdateBag(userId, 0, needs, "装备打造"))
{
var onEqu = await _equService.GetMakeEquByGoodsId(goodsId);
if (onEqu == null)
{
return PoAction.Message("打造失败,请联系客服!");
}
//发放装备
bool isRd = onEqu.rdAttr != 0;
var getEqu = await _equService.AddUserEqu(userId, (int)onEqu.equId, isRd, "打造装备");
if (getEqu != null)
{
return PoAction.Ok(getEqu.ueId, $"打造成功,获得装备[{onEqu.equName}]");
}
else
{
return PoAction.Message("打造失败,请稍后尝试!");
}
}
else
{
return PoAction.Message("打造失败,请稍后尝试!");
}
}
else
{
return PoAction.Message("材料不足!");
}
}
}

View File

@@ -16,15 +16,17 @@ public class EquController : ControllerBase
private readonly IUnitUserService _userService;
private readonly IGameDicService _dicService;
private readonly IMessageService _messageService;
private readonly IGameGoodsService _goodsService;
public EquController(IGameEquService equService, IUnitUserAttrService attrService, IUnitUserService userService,
IGameDicService dicService, IMessageService messageService)
IGameDicService dicService, IMessageService messageService, IGameGoodsService goodsService)
{
_equService = equService;
_attrService = attrService;
_userService = userService;
_dicService = dicService;
_messageService = messageService;
_goodsService = goodsService;
}
/// <summary>
@@ -142,6 +144,71 @@ public class EquController : ControllerBase
return PoAction.Ok(new { data, suit });
}
/// <summary>
/// 鉴定装备
/// </summary>
/// <param name="ueId"></param>
/// <returns></returns>
[HttpGet]
public async Task<IPoAction> ApprEqu(string ueId)
{
string userId = StateHelper.userId;
var equInfo = await _equService.GetUserEquInfo(ueId);
if (equInfo == null)
{
return PoAction.Message("装备不存在!");
}
if (equInfo.userId != userId)
{
return PoAction.Message("装备不存在!");
}
if (equInfo.isAppr == 1)
{
return PoAction.Message("装备已鉴定!");
}
var resEqu = await _equService.GetEquInfo((int)equInfo.equId);
if (resEqu.isAppr == 0)
{
return PoAction.Message("装备数据异常,联系客服!");
}
var myGoods = await _goodsService.GetUserGoodsCount(userId, GameConfig.GameEquApprGoods);
if (myGoods < 1)
{
return PoAction.Message("暂无装备鉴定符!");
}
if (await _goodsService.UpdateUserGoods(userId, 0, GameConfig.GameEquApprGoods, 1, "鉴定装备"))
{
equInfo.minAtk = RandomAssist.GetFormatedNumeric((int)resEqu.minAtk, (int)resEqu.maxAtk);
equInfo.maxAtk = RandomAssist.GetFormatedNumeric((int)equInfo.minAtk, (int)resEqu.maxAtk);
string[] def = resEqu.defense.Split('-');
equInfo.Defense = RandomAssist.GetFormatedNumeric(Convert.ToInt32(def[0]), Convert.ToInt32(def[1]));
string[] agi = resEqu.agility.Split('-');
equInfo.Agility = RandomAssist.GetFormatedNumeric(Convert.ToInt32(agi[0]), Convert.ToInt32(agi[1]));
string[] mor = resEqu.morale.Split('-');
equInfo.Morale = RandomAssist.GetFormatedNumeric(Convert.ToInt32(mor[0]), Convert.ToInt32(mor[1]));
string[] blo = resEqu.blood.Split('-');
equInfo.Blood = RandomAssist.GetFormatedNumeric(Convert.ToInt32(blo[0]), Convert.ToInt32(blo[1]));
equInfo.isAppr = 1;
if (await _equService.UpdateUserEquInfo(equInfo))
{
return PoAction.Ok(true, "装备鉴定成功!");
}
else
{
return PoAction.Message("鉴定失败,请稍后尝试!");
}
}
else
{
return PoAction.Message("鉴定失败,请稍后尝试!");
}
}
/// <summary>
/// 穿/卸装备
/// </summary>
@@ -680,7 +747,7 @@ public class EquController : ControllerBase
}
var nextNeeds = await _equService.GetUserEquUpData((int)equInfo.intensifyLev + 1);
if (needs == null)
if (nextNeeds == null)
{
isMax = true;
}
@@ -693,7 +760,7 @@ public class EquController : ControllerBase
if (equInfo.intensifyLev >= 60)
{
string msg = $"[{equInfo.equName}]装备强化至{equInfo.intensifyLev}级!";
await _messageService.SendBroadcast(userId, nameof(MessageEnum.BroadcastCode.Promote), msg);
await _messageService.SendBroadcast(userId, nameof(MessageEnum.BroadcastCode.Promote), msg);
}
}
else //执行材料返还
@@ -708,7 +775,7 @@ public class EquController : ControllerBase
code = item.code,
name = item.name,
parameter = item.parameter,
count = item.count
count = item.retCount
};
retProp.Add(temp);
}
@@ -736,4 +803,122 @@ public class EquController : ControllerBase
return PoAction.Message("强化错误,请稍后尝试!");
}
}
/// <summary>
/// 获取洗练装备属性
/// </summary>
/// <param name="ueId"></param>
/// <returns></returns>
[HttpGet]
public async Task<IPoAction> GetEquQualityInfo(string ueId)
{
string userId = StateHelper.userId;
var equInfo = await _equService.GetUserEquInfo(ueId);
if (equInfo == null)
{
return PoAction.Message("装备不存在!");
}
if (equInfo.userId != userId)
{
return PoAction.Message("装备不存在!");
}
if (equInfo.isAppr == 0)
{
return PoAction.Message("装备未鉴定!");
}
long time = TimeExtend.GetTimeStampSeconds;
if (equInfo.useEndTime < time)
{
return PoAction.Message("装备已过期!");
}
List<string> CanOp = new List<string>()
{ "Hold", "Vice", "Head", "Wear", "Waist", "Foot", "Ornaments" };
if (!CanOp.Contains(equInfo.code))
{
return PoAction.Message("该部件不可洗练!");
}
var dicConfig = await _dicService.GetDicInfo(nameof(GameEnum.DicCode.Quality));
List<TowerNeed> need = JsonConvert.DeserializeObject<List<TowerNeed>>(dicConfig.sign);
CheckTowerNeed result = await GameBus.CheckNeed(userId, need);
return PoAction.Ok(new
{
equData = equInfo,
result
});
}
/// <summary>
/// 洗练装备
/// </summary>
/// <param name="ueId"></param>
/// <returns></returns>
[HttpGet]
public async Task<IPoAction> HandleEquQuality(string ueId)
{
string userId = StateHelper.userId;
var equInfo = await _equService.GetUserEquInfo(ueId);
if (equInfo == null)
{
return PoAction.Message("装备不存在!");
}
if (equInfo.userId != userId)
{
return PoAction.Message("装备不存在!");
}
if (equInfo.isAppr == 0)
{
return PoAction.Message("装备未鉴定!");
}
long time = TimeExtend.GetTimeStampSeconds;
if (equInfo.useEndTime < time)
{
return PoAction.Message("装备已过期!");
}
List<string> CanOp = new List<string>()
{ "Hold", "Vice", "Head", "Wear", "Waist", "Foot", "Ornaments" };
if (!CanOp.Contains(equInfo.code))
{
return PoAction.Message("该部件不可洗练!");
}
var dicConfig = await _dicService.GetDicInfo(nameof(GameEnum.DicCode.Quality));
List<TowerNeed> need = JsonConvert.DeserializeObject<List<TowerNeed>>(dicConfig.sign);
CheckTowerNeed result = await GameBus.CheckNeed(userId, need);
if (result.result)
{
if (await GameBus.UpdateBag(userId, 0, need, "洗练装备"))
{
var attr = await _equService.GetRandomEquAttr(equInfo.code, (int)equInfo.lev);
equInfo.quality = attr.Count;
equInfo.qualityName = GameTool.GetEquQualityName(attr.Count);
equInfo.EquAttr = attr;
if (await _equService.UpdateUserEquInfo(equInfo, true, "洗练装备", "洗练装备"))
{
return PoAction.Ok(true, "洗练成功!");
}
else
{
return PoAction.Message("洗练失败,请稍后尝试!");
}
}
else
{
return PoAction.Message("洗练失败,请稍后尝试!");
}
}
else
{
return PoAction.Message("洗练失败,请稍后尝试!");
}
}
}

View File

@@ -12,11 +12,15 @@ public class RecoverController : ControllerBase
{
private readonly IUnitUserAttrService _attrService;
private readonly IGameMapService _mapService;
private readonly IUnitUserAccService _accService;
private readonly IGameEquService _equService;
public RecoverController(IUnitUserAttrService attrService, IGameMapService mapService)
public RecoverController(IUnitUserAttrService attrService, IGameMapService mapService,IUnitUserAccService accService,IGameEquService equService)
{
_attrService = attrService;
_mapService = mapService;
_accService = accService;
_equService = equService;
}
/// <summary>
@@ -179,6 +183,194 @@ public class RecoverController : ControllerBase
#endregion
var data = await _attrService.GetUserVigourInfo(userId);
string time = TimeAssist.GetDateTimeYMDString(0);
if (data.upTime == time)
{
return PoAction.Message("今天已恢复过活力啦!");
}
if (data.vitality >= data.upVitality)
{
return PoAction.Message("活力满满,无需恢复!");
}
bool result = await _attrService.UpdateUserVigour(userId, 2, (long)data.upVitality,time);
if (result)
{
return PoAction.Ok(true);
}
else
{
return PoAction.Message("恢复失败,请稍后尝试!");
}
}
/// <summary>
/// 获取恢复耐久的装备
/// </summary>
/// <param name="npcId"></param>
/// <returns></returns>
[HttpGet]
public async Task<IPoAction> GetUserRecoverEqu(int npcId)
{
string userId = StateHelper.userId;
#region NPC验证
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.RetEqu)))
{
return PoAction.Message("业务不可用!");
}
var onMap = await _mapService.GetUserOnMapId(userId);
if (npcInfo.mapId != onMap)
{
return PoAction.Message("Npc不存在!");
}
#endregion
int need = 0;
var data = await _equService.GetUserOnEqu(userId);
var needData = data.FindAll(it =>
it.isAppr == 1 && it.durability < it.maxdurability && it.useEndTime > TimeExtend.GetTimeStampSeconds);
need = needData.Sum(it => (int)it.maxdurability - (int)it.durability);
return PoAction.Ok(new { data, need });
}
/// <summary>
/// 恢复装备耐久
/// </summary>
/// <param name="npcId"></param>
/// <param name="ueId"></param>
/// <returns></returns>
[HttpGet]
public async Task<IPoAction> RecoverEqu(int npcId,string? ueId)
{
string userId = StateHelper.userId;
#region NPC验证
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.RetEqu)))
{
return PoAction.Message("业务不可用!");
}
var onMap = await _mapService.GetUserOnMapId(userId);
if (npcInfo.mapId != onMap)
{
return PoAction.Message("Npc不存在!");
}
#endregion
if (string.IsNullOrEmpty(ueId))
{
var myEqu = await _equService.GetUserOnEqu(userId);
myEqu = myEqu.FindAll(it =>
it.isAppr == 1 && it.durability < it.maxdurability && it.useEndTime > TimeExtend.GetTimeStampSeconds);
int need = myEqu.Sum(it => (int)it.maxdurability - (int)it.durability);
if (need < 1)
{
return PoAction.Message("耐久已满,无需恢复!");
}
var myAcc = await _accService.GetUserAccInfo(userId, nameof(AccEnum.AccType.copper));
if (need > myAcc)
{
return PoAction.Message("铜贝不足!");
}
if (await _accService.UpdateUserCopper(userId, 0, need, "修复装备"))
{
foreach (var item in myEqu)
{
item.durability = item.maxdurability;
await _equService.UpdateUserEquInfo(item);
}
return PoAction.Ok(true, $"恢复成功,花费{need}铜贝!");
}
else
{
return PoAction.Message("恢复失败,请稍后尝试!");
}
}
else
{
var equInfo = await _equService.GetUserEquInfo(ueId);
if (equInfo == null)
{
return PoAction.Message("装备不存在!");
}
if (equInfo.userId != userId)
{
return PoAction.Message("装备不存在!");
}
if (equInfo.isAppr != 1)
{
return PoAction.Message("装备未鉴定!");
}
if (equInfo.useEndTime < TimeExtend.GetTimeStampSeconds)
{
return PoAction.Message("装备已过期!");
}
if (equInfo.durability >= equInfo.maxdurability)
{
return PoAction.Message("耐久已满,无需恢复!");
}
int need = (int)equInfo.maxdurability - (int)equInfo.durability;
var myAcc = await _accService.GetUserAccInfo(userId, nameof(AccEnum.AccType.copper));
if (need > myAcc)
{
return PoAction.Message("铜贝不足!");
}
if (await _accService.UpdateUserCopper(userId, 0, need, "修复装备"))
{
equInfo.durability = equInfo.maxdurability;
if (await _equService.UpdateUserEquInfo(equInfo))
{
return PoAction.Ok(true, $"恢复成功,花费{need}铜贝!");
}
else
{
return PoAction.Message("恢复失败,请稍后尝试!");
}
}
else
{
return PoAction.Message("恢复失败,请稍后尝试!");
}
}
var data = await _attrService.GetUserVigourInfo(userId);
string time = TimeAssist.GetDateTimeYMDString(0);
if (data.upTime == time)

View File

@@ -136,8 +136,18 @@ public class BagController : ControllerBase
public async Task<IPoAction> CheckUserProp([FromBody] CheckUserPropParms parms)
{
string userId = StateHelper.userId;
List<TowerNeeds> needs = JsonConvert.DeserializeObject<List<TowerNeeds>>(parms.needs);
var result = await GameBus.CheckNeeds(userId, needs, 1);
return PoAction.Ok(result);
parms.count = parms.count < 1 ? 1 : parms.count;
if (parms.type == 0)
{
List<TowerNeed> needs = JsonConvert.DeserializeObject<List<TowerNeed>>(parms.needs);
var result = await GameBus.CheckNeed(userId, needs, parms.count);
return PoAction.Ok(result);
}
else
{
List<TowerNeeds> needs = JsonConvert.DeserializeObject<List<TowerNeeds>>(parms.needs);
var result = await GameBus.CheckNeeds(userId, needs, parms.count);
return PoAction.Ok(result);
}
}
}

View File

@@ -2,5 +2,7 @@
public class CheckUserPropParms
{
public int type { get; set; }
public int count { get; set; }
public string needs { get; set; }
}