This commit is contained in:
Putoo
2026-07-03 18:16:47 +08:00
parent 5eb0bfd792
commit ea32e7046e
29 changed files with 390 additions and 75 deletions

View File

@@ -22,11 +22,12 @@ public class MapController : ControllerBase
private readonly IGameGoodsService _goodsService;
private readonly IGameTeamService _teamService;
private readonly IGameMonsterService _monsterService;
private readonly IGameFightService _fightService;
public MapController(IUnitUserService userService, IGameMapService mapService, IGameChatService chatService,
IUnitUserAttrService attrService, IMessageService messageService, IUnitUserWeight weightService,
IUnitUserAccService accService, IGameSkillService skillService, IGameGoodsService goodsService,
IGameTeamService teamService, IGameMonsterService monsterService)
IGameTeamService teamService, IGameMonsterService monsterService,IGameFightService fightService)
{
_userService = userService;
_mapService = mapService;
@@ -39,6 +40,7 @@ public class MapController : ControllerBase
_goodsService = goodsService;
_teamService = teamService;
_monsterService = monsterService;
_fightService = fightService;
}
#region
@@ -141,6 +143,9 @@ public class MapController : ControllerBase
var broadcast = await _messageService.GetBroadcastData(area);
var userFight = await _fightService.GetUserFight(userId);
string fightId = userFight.Count > 0 ? userFight[0] : "";
object ret = new
{
mapInfo,
@@ -153,7 +158,8 @@ public class MapController : ControllerBase
business,
mapRes,
broadcast,
monster = monsterData
monster = monsterData,
fightId
};
return PoAction.Ok(ret);

View File

@@ -0,0 +1,107 @@
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
namespace Application.Web.Controllers.Pub;
/// <summary>
/// 战斗接口
/// </summary>
[Route("[controller]/[action]")]
[ApiController]
[Authorize]
public class FightController : ControllerBase
{
private readonly IGameFightService _fightService;
private readonly IGameMonsterService _monsterService;
private readonly IUnitUserAttrService _attrService;
private readonly IGameMapService _mapService;
public FightController(IGameFightService fightService, IGameMonsterService monsterService,
IUnitUserAttrService attrService, IGameMapService mapService)
{
_fightService = fightService;
_monsterService = monsterService;
_attrService = attrService;
_mapService = mapService;
}
/// <summary>
/// 添加怪物战斗
/// </summary>
/// <param name="parms"></param>
/// <returns></returns>
[HttpPost]
public async Task<IPoAction> FightMonster([FromBody] FightMonsterParms parms)
{
string userId = StateHelper.userId;
if (await UserKeyTool.CheckUserThickenData(userId, parms.sign, parms.type.ToString(), parms.monsterId) == false)
{
return PoAction.Message("怪物不存在!", -1);
}
var mapInfo = await _mapService.GetUserOnToMapInfo(userId);
//添加怪物战斗
string fightId = StringAssist.NewGuid;
string areaCode = nameof(GameEnum.AreaCode.Own);
string keyId = fightId;
string mainId = string.Empty;
string code = nameof(GameEnum.FightCode.PVE);
string scene = mapInfo.code;
string mapId = mapInfo.mapId;
long exp = 0;
long copper = 0;
long petExp = 0;
string award = string.Empty;
string pars = "";
if (parms.type == 0)
{
var monster = await _monsterService.GetMapMonsterInfo(parms.monsterId);
mainId = monster.monsterId;
pars = JsonConvert.SerializeObject(new { type = "Default" });
}
else
{
var monster = await _monsterService.GetCreateMonsterInfo(parms.monsterId);
keyId = monster.umId;
mainId = monster.monsterId;
areaCode = monster.areaCode;
pars = JsonConvert.SerializeObject(new { type = "Create", code = monster.code, par = monster.par });
}
var monsterInfo = await _monsterService.GetMonsterInfo(mainId);
if (monsterInfo != null)
{
var userAttr = await _attrService.GetUserAttrModel(userId, scene);
//处理奖励和资源
exp = Convert.ToInt64(monsterInfo.exp * (1.0m + userAttr.addExp)) ;
copper = Convert.ToInt64(monsterInfo.copper * (1.0m + userAttr.addGold));
petExp = (long)monsterInfo.petExp;
if (!string.IsNullOrEmpty(monsterInfo.award))//生成奖励
{
var awardModel = JsonConvert.DeserializeObject<MonsterAwardModel>(monsterInfo.award);
if (awardModel.type == nameof(MonsterEnum.AwardCode.Default))
{
var getAward = GameBus.GetRandomGoods(awardModel.award, 1,userAttr.burst);
award = JsonConvert.SerializeObject(new FightAwardModel() { code = "Default", award = getAward });
}
}
}
bool result = await _fightService.AddFight(fightId, areaCode, keyId, mainId, code, scene, mapId, userId, exp,
copper, petExp, award, pars);
if (result)
{
return PoAction.Ok(fightId);
}
else
{
return PoAction.Message("战斗生成错误!");
}
}
[HttpPost]
public async Task<IPoAction> Fight([FromBody] FightParms parms)
{
return PoAction.Ok(true);
}
}