121212
This commit is contained in:
@@ -19,10 +19,11 @@ public class GiveController : ControllerBase
|
||||
private readonly IUnitUserService _userService;
|
||||
private readonly IGameChatService _chatService;
|
||||
private readonly IMessageService _messageService;
|
||||
private readonly IUnitUserAttrService _attrService;
|
||||
|
||||
public GiveController(IGameGoodsService goodsService, IGameEquService equService, IUnitUserWeight weightService,
|
||||
IUnitUserRelationService relationService, IUnitUserService userService, IGameChatService chatService,
|
||||
IMessageService messageService)
|
||||
IMessageService messageService,IUnitUserAttrService attrService)
|
||||
{
|
||||
_goodsService = goodsService;
|
||||
_equService = equService;
|
||||
@@ -31,6 +32,7 @@ public class GiveController : ControllerBase
|
||||
_userService = userService;
|
||||
_chatService = chatService;
|
||||
_messageService = messageService;
|
||||
_attrService = attrService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -159,4 +161,286 @@ public class GiveController : ControllerBase
|
||||
return PoAction.Ok(new { data, total = total.Value });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取赠送物品列表
|
||||
/// </summary>
|
||||
/// <param name="npcId"></param>
|
||||
/// <param name="type"></param>
|
||||
/// <param name="query"></param>
|
||||
/// <param name="page"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<IPoAction> GetGoodsData(string no, int type, string? query, int page)
|
||||
{
|
||||
var fromInfo = await _userService.GetUserInfoByUserNo(no);
|
||||
if (fromInfo == null)
|
||||
{
|
||||
return PoAction.Message("玩家不存在!");
|
||||
}
|
||||
|
||||
string userId = StateHelper.userId;
|
||||
int areaId = StateHelper.areaId;
|
||||
if (areaId != fromInfo.areaId)
|
||||
{
|
||||
return PoAction.Message("玩家不存在!");
|
||||
}
|
||||
|
||||
RefAsync<int> total = 0;
|
||||
if (type == 0)
|
||||
{
|
||||
var data = await _equService.GetUserEquData(userId, 0, query, page, 10, total, 1);
|
||||
return PoAction.Ok(new
|
||||
{
|
||||
userNo = fromInfo.userNo,
|
||||
nick = fromInfo.nick, data, total = total.Value
|
||||
});
|
||||
}
|
||||
else if (type == 1)
|
||||
{
|
||||
List<string> code = new List<string>() { nameof(GoodsEnum.Code.Drug) };
|
||||
var data = await _goodsService.GetUserGoodsData(userId, code, new List<string>(), query, page, 10, total,
|
||||
1);
|
||||
return PoAction.Ok(new
|
||||
{
|
||||
userNo = fromInfo.userNo,
|
||||
nick = fromInfo.nick, data, total = total.Value
|
||||
});
|
||||
}
|
||||
else if (type == 2)
|
||||
{
|
||||
List<string> code = new List<string>();
|
||||
List<string> noCode = new List<string>() { nameof(GoodsEnum.Code.Drug) };
|
||||
var data = await _goodsService.GetUserGoodsData(userId, code, noCode, query, page, 10, total, 1);
|
||||
return PoAction.Ok(new
|
||||
{
|
||||
userNo = fromInfo.userNo,
|
||||
nick = fromInfo.nick, data, total = total.Value
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
return PoAction.Ok(new
|
||||
{
|
||||
userNo = fromInfo.userNo,
|
||||
nick = fromInfo.nick, data = new List<string>(), total = total.Value
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 赠送物品
|
||||
/// </summary>
|
||||
/// <param name="no"></param>
|
||||
/// <param name="type"></param>
|
||||
/// <param name="propId"></param>
|
||||
/// <param name="count"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<IPoAction> GiveGoods(string no, int type, string propId, int count)
|
||||
{
|
||||
string userId = StateHelper.userId;
|
||||
int myLev = await _attrService.GetUserLev(userId);
|
||||
if (myLev < 60)
|
||||
{
|
||||
return PoAction.Message("等级达到60级才可以赠送哦!");
|
||||
}
|
||||
|
||||
count = count < 1 ? 1 : count;
|
||||
var fromInfo = await _userService.GetUserInfoByUserNo(no);
|
||||
if (fromInfo == null)
|
||||
{
|
||||
return PoAction.Message("玩家不存在!");
|
||||
}
|
||||
|
||||
int areaId = StateHelper.areaId;
|
||||
if (areaId != fromInfo.areaId)
|
||||
{
|
||||
return PoAction.Message("玩家不存在!");
|
||||
}
|
||||
|
||||
if (type == 0)
|
||||
{
|
||||
var equInfo = await _equService.GetUserEquInfo(propId);
|
||||
if (equInfo == null)
|
||||
{
|
||||
return PoAction.Message("装备不存在!");
|
||||
}
|
||||
|
||||
if (equInfo.userId != userId || equInfo.isOn == 1 || equInfo.isLock == 1)
|
||||
{
|
||||
return PoAction.Message("该装备锁定或穿戴中!");
|
||||
}
|
||||
|
||||
if (equInfo.isDeal == 0 || equInfo.isGive == 0)
|
||||
{
|
||||
return PoAction.Message("该装备无法交易或不可赠送!");
|
||||
}
|
||||
|
||||
//验证负重
|
||||
if (await _weightService.CheckUserWeight(fromInfo.userId, (int)equInfo.weight) == false)
|
||||
{
|
||||
return PoAction.Message("对方负重不足!");
|
||||
}
|
||||
|
||||
if (await _equService.DeductUserEqu(userId, [equInfo], $"赠送给玩家:{fromInfo.userId}"))
|
||||
{
|
||||
equInfo.userId = fromInfo.userId;
|
||||
if (await _equService.AddUserEqu(equInfo, $"收到赠送,来源玩家:{userId}"))
|
||||
{
|
||||
var myInfo = await _userService.GetUserInfoByUserId(userId);
|
||||
string msg = $"收到[{UbbTool.HomeUbb(myInfo.userNo, myInfo.nick)}]赠送的装备[{equInfo.equName}]";
|
||||
await _chatService.SendChat(fromInfo.userId, (int)fromInfo.areaId, nameof(GameChatEnum.Code.Notice),
|
||||
msg);
|
||||
return PoAction.Ok(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
return PoAction.Message("赠送失败,请稍后尝试!");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return PoAction.Message("赠送失败,请稍后尝试!");
|
||||
}
|
||||
}
|
||||
else if (type == 1 || type == 2)
|
||||
{
|
||||
int goodsId = Convert.ToInt32(propId);
|
||||
var MyGoods = await _goodsService.GetUserGoodsInfo(userId, goodsId);
|
||||
if (MyGoods == null)
|
||||
{
|
||||
return PoAction.Message("物品数量不足!");
|
||||
}
|
||||
|
||||
if (MyGoods.count < count)
|
||||
{
|
||||
return PoAction.Message("物品数量不足!");
|
||||
}
|
||||
|
||||
if (MyGoods.isDeal == 0 || MyGoods.isGive == 0)
|
||||
{
|
||||
return PoAction.Message("该无法无法交易或不可赠送!");
|
||||
}
|
||||
|
||||
int useWeight = (int)MyGoods.weight * count;
|
||||
if (await _weightService.CheckUserWeight(fromInfo.userId, useWeight) == false)
|
||||
{
|
||||
return PoAction.Message("对方负重不足!");
|
||||
}
|
||||
|
||||
if (await _goodsService.UpdateUserGoods(userId, 0, goodsId, count, $"赠送给玩家:{fromInfo.userId}"))
|
||||
{
|
||||
if (await _goodsService.UpdateUserGoods(fromInfo.userId, 1, goodsId, count, $"收到赠送,来源玩家:{userId}"))
|
||||
{
|
||||
var myInfo = await _userService.GetUserInfoByUserId(userId);
|
||||
string msg = $"收到[{UbbTool.HomeUbb(myInfo.userNo, myInfo.nick)}]赠送的物品[{MyGoods.goodsName}]×{count}";
|
||||
await _chatService.SendChat(fromInfo.userId, (int)fromInfo.areaId, nameof(GameChatEnum.Code.Notice),
|
||||
msg);
|
||||
return PoAction.Ok(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
return PoAction.Message("赠送失败,请稍后尝试");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return PoAction.Message("赠送失败,请稍后尝试");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return PoAction.Message("赠送失败,请稍后尝试");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 逗一下物品列表
|
||||
/// </summary>
|
||||
/// <param name="no"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<IPoAction> GetUserDouGoods(string no)
|
||||
{
|
||||
var fromInfo = await _userService.GetUserInfoByUserNo(no);
|
||||
if (fromInfo == null)
|
||||
{
|
||||
return PoAction.Message("玩家不存在!");
|
||||
}
|
||||
|
||||
string userId = StateHelper.userId;
|
||||
int areaId = StateHelper.areaId;
|
||||
if (areaId != fromInfo.areaId)
|
||||
{
|
||||
return PoAction.Message("玩家不存在!");
|
||||
}
|
||||
|
||||
var data = await _goodsService.GetUserGoodsData(userId, nameof(GoodsEnum.Code.Tease));
|
||||
return PoAction.Ok(new
|
||||
{
|
||||
userNo = fromInfo.userNo,
|
||||
nick = fromInfo.nick,
|
||||
data = data
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 使用逗物品
|
||||
/// </summary>
|
||||
/// <param name="no"></param>
|
||||
/// <param name="goodsId"></param>
|
||||
/// <param name="count"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<IPoAction> UseDou(string no,int goodsId, int count)
|
||||
{
|
||||
var fromInfo = await _userService.GetUserInfoByUserNo(no);
|
||||
if (fromInfo == null)
|
||||
{
|
||||
return PoAction.Message("玩家不存在!");
|
||||
}
|
||||
|
||||
string userId = StateHelper.userId;
|
||||
int areaId = StateHelper.areaId;
|
||||
if (areaId != fromInfo.areaId)
|
||||
{
|
||||
return PoAction.Message("玩家不存在!");
|
||||
}
|
||||
|
||||
count = count < 1 ? 1 : count;
|
||||
var myGoods = await _goodsService.GetUserGoodsInfo(userId, goodsId);
|
||||
if (myGoods == null)
|
||||
{
|
||||
return PoAction.Message("您暂无该道具!");
|
||||
}
|
||||
|
||||
if (myGoods.count < count)
|
||||
{
|
||||
return PoAction.Message("您的道具不足!");
|
||||
}
|
||||
|
||||
if (myGoods.code != nameof(GoodsEnum.Code.Tease))
|
||||
{
|
||||
return PoAction.Message("该道具无法使用!");
|
||||
}
|
||||
|
||||
if (await _goodsService.UpdateUserGoods(userId, 0, goodsId, count, "使用道具"))
|
||||
{
|
||||
var goodsInfo = await _goodsService.GetGoodsInfo(goodsId);
|
||||
UserStateModel stateConfig = JsonConvert.DeserializeObject<UserStateModel>(goodsInfo.content);
|
||||
if(await _attrService.AddUserState(fromInfo.userId, goodsInfo.goodsId.ToString(), stateConfig.name,
|
||||
stateConfig.scene, stateConfig.tips, stateConfig.attr, stateConfig.time, count))
|
||||
{
|
||||
var myInfo = await _userService.GetUserInfoByUserId(userId);
|
||||
string msg = $"[{UbbTool.HomeUbb(myInfo.userNo, myInfo.nick)}]对您使用了[{goodsInfo.goodsName}]×{count}";
|
||||
await _chatService.SendChat(fromInfo.userId, (int)fromInfo.areaId, nameof(GameChatEnum.Code.Notice),
|
||||
msg);
|
||||
}
|
||||
return PoAction.Ok(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
return PoAction.Message("使用失败,请稍后尝试!");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user