1212121
This commit is contained in:
@@ -50,6 +50,15 @@ public class GoodsController : ControllerBase
|
||||
case "Weight":
|
||||
UseState = 1;
|
||||
break;
|
||||
case "State":
|
||||
UseState = 1;
|
||||
break;
|
||||
case "Ship":
|
||||
UseState = 2;
|
||||
break;
|
||||
case "ChoicePack":
|
||||
UseState = 3;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -85,6 +94,19 @@ public class GoodsController : ControllerBase
|
||||
return PoAction.Message($"该物品{goodsInfo.lev}级才可使用!");
|
||||
}
|
||||
|
||||
#region 必要判定
|
||||
|
||||
if (goodsInfo.code == nameof(GoodsEnum.Code.Ship))
|
||||
{
|
||||
var myShip = await _weightService.GetUserShip(userId);
|
||||
if (myShip.Count >= 5)
|
||||
{
|
||||
return PoAction.Message($"每人最多拥有5个船只,您已达到上限!");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
if (await _goodsService.UpdateUserGoods(userId, 0, goodsId, count, "使用物品"))
|
||||
{
|
||||
string message = "";
|
||||
@@ -119,6 +141,23 @@ public class GoodsController : ControllerBase
|
||||
}
|
||||
else if (goodsInfo.code == nameof(GoodsEnum.Code.State))
|
||||
{
|
||||
UserStateModel stateConfig = JsonConvert.DeserializeObject<UserStateModel>(goodsInfo.content);
|
||||
await _attrService.AddUserState(userId, goodsInfo.goodsId.ToString(), stateConfig.name,
|
||||
stateConfig.scene, stateConfig.tips, stateConfig.attr, stateConfig.time, count);
|
||||
message = $"使用[{goodsInfo.goodsName}]×{count},状态时间+{stateConfig.time * count}分钟";
|
||||
}
|
||||
else if (goodsInfo.code == nameof(GoodsEnum.Code.Ship))
|
||||
{
|
||||
dynamic shipInfo = JsonConvert.DeserializeObject<dynamic>(goodsInfo.content);
|
||||
string name = shipInfo.name;
|
||||
int speed = shipInfo.speed;
|
||||
int weight = shipInfo.weight;
|
||||
int copper = shipInfo.copper;
|
||||
long sale = shipInfo.sale;
|
||||
string remark = shipInfo.remark;
|
||||
|
||||
await _weightService.AddUserShip(userId, name, goodsId, speed, weight, copper, sale, remark);
|
||||
message = $"使用[{goodsInfo.goodsName}],获得{name}+1";
|
||||
}
|
||||
|
||||
return PoAction.Ok(true, message);
|
||||
@@ -128,4 +167,69 @@ public class GoodsController : ControllerBase
|
||||
return PoAction.Message("使用失败,请稍后尝试!");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 使用选择物品礼包
|
||||
/// </summary>
|
||||
/// <param name="goodsId"></param>
|
||||
/// <param name="count"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<IPoAction> UseChoiceGoods(int goodsId, int num)
|
||||
{
|
||||
string userId = StateHelper.userId;
|
||||
var goodsInfo = await _goodsService.GetGoodsInfo(goodsId);
|
||||
if (goodsInfo == null)
|
||||
{
|
||||
return PoAction.Message("物品不存在!");
|
||||
}
|
||||
|
||||
var MyGoods = await _goodsService.GetUserGoodsCount(userId, goodsId);
|
||||
if (MyGoods < 1)
|
||||
{
|
||||
return PoAction.Message("物品不足!");
|
||||
}
|
||||
|
||||
var myLev = await _attrService.GetUserLev(userId);
|
||||
if (myLev < (int)goodsInfo.lev)
|
||||
{
|
||||
return PoAction.Message($"该物品{goodsInfo.lev}级才可使用!");
|
||||
}
|
||||
|
||||
if (goodsInfo.code != nameof(GoodsEnum.Code.ChoicePack))
|
||||
{
|
||||
return PoAction.Message("无法使用该物品!");
|
||||
}
|
||||
List<ChoiceGoods> choiceGoods = JsonConvert.DeserializeObject<List<ChoiceGoods>>(goodsInfo.content);
|
||||
var onAward = choiceGoods.Find(it => it.id == num);
|
||||
if (onAward == null)
|
||||
{
|
||||
return PoAction.Message("物品中不包含该选择!");
|
||||
}
|
||||
|
||||
|
||||
if (await _goodsService.UpdateUserGoods(userId, 0, goodsId, 1, "使用物品"))
|
||||
{
|
||||
if (await GameBus.UpdateBag(userId, 1, onAward.award, "打开礼包获取"))
|
||||
{
|
||||
string message = $"打开[{goodsInfo.goodsName}],获得:";
|
||||
foreach (var item in onAward.award)
|
||||
{
|
||||
message += $"{item.name}+{item.count},";
|
||||
}
|
||||
message = message.TrimEnd(',');
|
||||
|
||||
await _messageService.SendBroadcast(userId, nameof(MessageEnum.BroadcastCode.Award), message);
|
||||
return PoAction.Ok(true, message);
|
||||
}
|
||||
else
|
||||
{
|
||||
return PoAction.Message("使用失败,请稍后尝试!");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return PoAction.Message("使用失败,请稍后尝试!");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,14 +10,14 @@ namespace Application.Web.Controllers.Pub
|
||||
[Authorize]
|
||||
public class ShipController : ControllerBase
|
||||
{
|
||||
private readonly IUnitUserWeight weightService;
|
||||
private readonly IGameGoodsService goodsService;
|
||||
private readonly IUnitUserAccService accService;
|
||||
public ShipController(IUnitUserWeight _weightService, IGameGoodsService _goodsService, IUnitUserAccService _accService)
|
||||
private readonly IUnitUserWeight _weightService;
|
||||
private readonly IUnitUserAccService _accService;
|
||||
|
||||
public ShipController(IUnitUserWeight weightService,
|
||||
IUnitUserAccService accService)
|
||||
{
|
||||
accService = _accService;
|
||||
goodsService = _goodsService;
|
||||
weightService = _weightService;
|
||||
_accService = accService;
|
||||
_weightService = weightService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -28,27 +28,11 @@ namespace Application.Web.Controllers.Pub
|
||||
public async Task<IPoAction> GetUserShip()
|
||||
{
|
||||
string userId = StateHelper.userId;
|
||||
var data = await weightService.GetUserShip(userId);
|
||||
var data = await _weightService.GetUserShip(userId);
|
||||
//个人负重
|
||||
var weightInfo = await weightService.GetUserWeightInfo(userId);
|
||||
return PoAction.Ok(new { data, weightInfo });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取船只详情
|
||||
/// </summary>
|
||||
/// <param name="shipId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<IPoAction> GetShipInfo(int shipId)
|
||||
{
|
||||
var data = await goodsService.GetShipInfo(shipId);
|
||||
if (data == null)
|
||||
{
|
||||
return PoAction.Message("船只详情不存在!");
|
||||
}
|
||||
|
||||
return PoAction.Ok(new { data });
|
||||
var weightInfo = await _weightService.GetUserWeightInfo(userId);
|
||||
var maxShipWeight = await _weightService.GetUserShipMaxWeight(userId);
|
||||
return PoAction.Ok(new { data, onShip = weightInfo.shipOnWeight, maxShip = maxShipWeight });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -57,46 +41,25 @@ namespace Application.Web.Controllers.Pub
|
||||
/// <param name="usId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<IPoAction> BuyShip([FromBody] BuyShipParms parms)
|
||||
public async Task<IPoAction> SaleShip([FromBody] BuyShipParms parms)
|
||||
{
|
||||
var userShip = await weightService.GetUserShipInfo(parms.usId);
|
||||
var userShip = await _weightService.GetUserShipInfo(parms.usId);
|
||||
if (userShip == null)
|
||||
{
|
||||
return PoAction.Message("船只不存在!");
|
||||
}
|
||||
|
||||
string userId = StateHelper.userId;
|
||||
if (userShip.userId != userId)
|
||||
{
|
||||
return PoAction.Message("船只不存在!");
|
||||
}
|
||||
var shipInfo = await goodsService.GetShipInfo((int)userShip.goodsId);
|
||||
if (shipInfo == null)
|
||||
|
||||
if (await _weightService.DeleteUserShip(userShip.usId, userId))
|
||||
{
|
||||
return PoAction.Message("船只信息不存在!");
|
||||
}
|
||||
if (await weightService.DeleteUserShip(userShip.usId, userId))
|
||||
{
|
||||
if (shipInfo.payType == AccEnum.AccType.copper.ToString())
|
||||
if (await _accService.UpdateUserCopper(userId, 1, Convert.ToInt64(userShip.sale), "出售船只获得!"))
|
||||
{
|
||||
if (await accService.UpdateUserCopper(userId, 1, Convert.ToInt64(shipInfo.salePrice), "出售船只获得!"))
|
||||
{
|
||||
return PoAction.Ok(new { price = shipInfo.salePrice });
|
||||
}
|
||||
else
|
||||
{
|
||||
return PoAction.Message("出售失败!");
|
||||
}
|
||||
}
|
||||
else if (shipInfo.payType == AccEnum.AccType.gold.ToString())
|
||||
{
|
||||
if (await accService.UpdateUserAcc(userId, 1, AccEnum.AccType.gold.ToString(), Convert.ToInt64(shipInfo.salePrice)))
|
||||
{
|
||||
return PoAction.Ok(new { price = shipInfo.salePrice });
|
||||
}
|
||||
else
|
||||
{
|
||||
return PoAction.Message("出售失败!");
|
||||
}
|
||||
return PoAction.Ok(new { price = userShip.sale });
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -109,4 +72,4 @@ namespace Application.Web.Controllers.Pub
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user