This commit is contained in:
Putoo
2026-07-08 19:13:55 +08:00
parent 5d0ebe5077
commit fe2696074b
59 changed files with 1448 additions and 112 deletions

View File

@@ -19,10 +19,12 @@ public class FightController : ControllerBase
private readonly IGameGoodsService _goodsService;
private readonly IUnitUserService _userService;
private readonly IOnHookService _hookService;
private readonly IUnitUserRelationService _relationService;
public FightController(IGameFightService fightService, IGameMonsterService monsterService,
IUnitUserAttrService attrService, IGameMapService mapService, IUnitUserAccService accService,
IGameGoodsService goodsService, IUnitUserService userService,IOnHookService hookService)
IGameGoodsService goodsService, IUnitUserService userService, IOnHookService hookService,
IUnitUserRelationService relationService)
{
_fightService = fightService;
_monsterService = monsterService;
@@ -32,6 +34,7 @@ public class FightController : ControllerBase
_goodsService = goodsService;
_userService = userService;
_hookService = hookService;
_relationService = relationService;
}
/// <summary>
@@ -110,6 +113,77 @@ public class FightController : ControllerBase
}
}
/// <summary>
/// 角色战斗生成
/// </summary>
/// <param name="no"></param>
/// <returns></returns>
[HttpGet]
public async Task<IPoAction> FightPerson(string? no)
{
string userId = StateHelper.userId;
var onMapInfo = await _mapService.GetUserOnToMapInfo(userId);
var otUser = await _userService.GetUserInfoByUserNo(no);
if (otUser == null)
{
return PoAction.Message("玩家不存在!");
}
if (onMapInfo.isPk == 0)
{
if (onMapInfo.retMap != onMapInfo.mapId)
{
if (await _relationService.CheckUserEnemy(userId, otUser.userId) == false)
{
return PoAction.Message("该场景不允许PK!");
}
}
else
{
return PoAction.Message("该场景不允许PK!");
}
}
var otUserOnMap = await _mapService.GetUserOnMapInfo(otUser.userId);
if (onMapInfo.mapId != otUserOnMap.mapId)
{
return PoAction.Message("玩家不存在!");
}
if (otUserOnMap.isOnline == 0)
{
return PoAction.Message("玩家已下线!");
}
if (onMapInfo.lookArea == 1)
{
if (otUser.areaId != StateHelper.areaId)
{
return PoAction.Message("该地图不允许跨服战斗!");
}
}
string fightId = StringAssist.NewGuid;
string areaCode = nameof(GameEnum.AreaCode.Own);
string code = nameof(GameEnum.FightCode.PVP);
string keyId = StringAssist.GetSortKey(userId,otUser.userId);
long exp = 0;
long copper = 0;
long petExp = 0;
string award = string.Empty;
string pars = "";
bool result = await _fightService.AddFight(fightId, areaCode, keyId, otUser.userId, code, onMapInfo.code, onMapInfo.mapId, userId, exp,
copper, petExp, award, pars);
if (result)
{
await _hookService.StopOnHook(userId);
return PoAction.Ok(fightId);
}
else
{
return PoAction.Message("战斗生成错误!");
}
}
/// <summary>
/// 战斗接口
/// </summary>
@@ -194,7 +268,6 @@ public class FightController : ControllerBase
//结束战斗都此处直接返回
if (otAttr.blood < 1 || myAttr.blood < 1)
{
await _fightService.RemoveUserFight(userId, fightId);
if (otAttr.blood < 1)
{
await _fightService.SetFightWin(fight, userId);
@@ -343,13 +416,11 @@ public class FightController : ControllerBase
var fight = await _fightService.GetFightInfo(fightId);
if (fight == null)
{
await _fightService.RemoveUserFight(userId, fightId);
return PoAction.Message("战斗不存在!");
}
if (fight.state == 1)
{
await _fightService.RemoveUserFight(userId, fightId);
return PoAction.Message("战斗结束!");
}

View File

@@ -43,7 +43,7 @@ public class GoodsController : ControllerBase
int count = await _goodsService.GetUserGoodsCount(userId, goodsId);
int UseState = 0;
string[] ShowViewNum = ["Pack", "Weight", "State"]; //显示带数量窗口
string[] ShowView = ["Ship","Drug"]; //显示只能使用1个的窗口
string[] ShowView = ["Ship", "Drug", "Durability"]; //显示只能使用1个的窗口
if (ShowViewNum.Any(it => it == goodsInfo.code))
{
UseState = 1;
@@ -113,7 +113,7 @@ public class GoodsController : ControllerBase
return PoAction.Message(ck);
}
}
#endregion
if (await _goodsService.UpdateUserGoods(userId, 0, goodsId, count, "使用物品"))
@@ -168,11 +168,24 @@ public class GoodsController : ControllerBase
await _weightService.AddUserShip(userId, name, goodsId, speed, weight, copper, sale, remark);
message = $"使用[{goodsInfo.goodsName}],获得{name}+1";
}
if (goodsInfo.code == nameof(GoodsEnum.Code.Drug))
{
message = "使用成功!";
await _goodsService.UseDrug(userId, goodsId, goodsInfo.content);
}
if (goodsInfo.code == nameof(GoodsEnum.Code.Durability))
{
message = "使用成功!";
dynamic _drugConfig = JsonConvert.DeserializeObject<dynamic>(goodsInfo.content);
await _attrService.AddUserStock(userId, goodsId.ToString(), Convert.ToString(_drugConfig.name),
Convert.ToString(_drugConfig.type),
Convert.ToString(_drugConfig.code),
Convert.ToInt64(_drugConfig.num), Convert.ToString(_drugConfig.par),
Convert.ToInt32(_drugConfig.minute));
}
return PoAction.Ok(true, message);
}
else

View File

@@ -0,0 +1,50 @@
using Microsoft.AspNetCore.Mvc;
namespace Application.Web.Controllers.Pub;
/// <summary>
/// 排行接口
/// </summary>
[Route("[controller]/[action]")]
[ApiController]
[Authorize]
public class RankController : ControllerBase
{
private readonly IRankService _rankService;
public RankController(IRankService rankService)
{
_rankService = rankService;
}
/// <summary>
/// 获取排名数据
/// </summary>
/// <param name="type"></param>
/// <param name="page"></param>
/// <returns></returns>
[HttpGet]
public async Task<IPoAction> GetRankData(int type, int page)
{
List<GameRankModel> data = new List<GameRankModel>();
RefAsync<int> total = 0;
string upTime = $"更新时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}";
int area = StateHelper.areaId;
if (type is >= 0 and < 8)
{
data = await _rankService.GetGameRank(type, area, page, 10, total);
upTime = await _rankService.GetRankUpdateTime();
}
else if (type == 8)
{
data = await _rankService.GetGameCopperRank(area, page, 10, total);
}
else if (type == 9 || type == 10 || type == 11)
{
data = await _rankService.GetGameTeachAndRenownRank(type, area, page, 10, total);
}
return PoAction.Ok(new { upTime, data, total = total.Value });
}
}