diff --git a/Service/Application.Domain.Entity/logdb/db/game_fight_data.cs b/Service/Application.Domain.Entity/logdb/db/game_fight_data.cs index f828c54..e376d71 100644 --- a/Service/Application.Domain.Entity/logdb/db/game_fight_data.cs +++ b/Service/Application.Domain.Entity/logdb/db/game_fight_data.cs @@ -89,11 +89,7 @@ namespace Application.Domain.Entity /// [SugarColumn(IsNullable = true)] public string? award { get; set; } - /// - /// 伤害 - /// - [SugarColumn(IsNullable = true)] - public long? harm { get; set; } + [SugarColumn(IsNullable = true)] public string? pars { get; set; } /// diff --git a/Service/Application.Domain.Entity/model/FightAwardModel.cs b/Service/Application.Domain.Entity/model/FightAwardModel.cs new file mode 100644 index 0000000..7cfcfb3 --- /dev/null +++ b/Service/Application.Domain.Entity/model/FightAwardModel.cs @@ -0,0 +1,7 @@ +namespace Application.Domain.Entity; + +public class FightAwardModel +{ + public string code { get; set; } + public object award { get; set; } +} \ No newline at end of file diff --git a/Service/Application.Domain.Entity/model/MapMonsterModel.cs b/Service/Application.Domain.Entity/model/MapMonsterModel.cs index 2b58f98..7c9d6cf 100644 --- a/Service/Application.Domain.Entity/model/MapMonsterModel.cs +++ b/Service/Application.Domain.Entity/model/MapMonsterModel.cs @@ -8,4 +8,6 @@ public class MapMonsterModel /// 0地图怪物 1生成怪物 /// public int type { get; set; } + + public string sign { get; set; } } \ No newline at end of file diff --git a/Service/Application.Domain.Entity/model/MonsterAwardModel.cs b/Service/Application.Domain.Entity/model/MonsterAwardModel.cs new file mode 100644 index 0000000..41df820 --- /dev/null +++ b/Service/Application.Domain.Entity/model/MonsterAwardModel.cs @@ -0,0 +1,7 @@ +namespace Application.Domain.Entity; + +public class MonsterAwardModel +{ + public string type { get; set; } + public RandomModel award { get; set; } +} \ No newline at end of file diff --git a/Service/Application.Domain.Entity/model/UserAttrModel.cs b/Service/Application.Domain.Entity/model/UserAttrModel.cs index a0fae81..168e436 100644 --- a/Service/Application.Domain.Entity/model/UserAttrModel.cs +++ b/Service/Application.Domain.Entity/model/UserAttrModel.cs @@ -8,11 +8,14 @@ public int isCopy { get; set; } public string viceId { get; set; } public string name { get; set; } - public int figState { get; set; } public string sex { get; set; } public string code { get; set; } - public string remark { get; set; } - public string TmImg { get; set; } + public string tips { get; set; } + public decimal addExp { get; set; } + public decimal addGold { get; set; } + public decimal burst { get; set; }//爆率 + public decimal luck { get; set; }//幸运 + public int weight { get; set; }//负重 public int lev { get; set; }//等级 public int minAtk { get; set; }//最小攻击 public int maxAtk { get; set; }//最大攻击 diff --git a/Service/Application.Domain/Enum/FightEnum.cs b/Service/Application.Domain/Enum/FightEnum.cs new file mode 100644 index 0000000..7014497 --- /dev/null +++ b/Service/Application.Domain/Enum/FightEnum.cs @@ -0,0 +1,7 @@ +namespace Application.Domain; + +public static class FightEnum +{ + + +} \ No newline at end of file diff --git a/Service/Application.Domain/Enum/GameEnum.cs b/Service/Application.Domain/Enum/GameEnum.cs index 2adf76b..ac93b6e 100644 --- a/Service/Application.Domain/Enum/GameEnum.cs +++ b/Service/Application.Domain/Enum/GameEnum.cs @@ -77,8 +77,6 @@ public static class GameEnum { AddExp,//经验 AddGold,//金币 - OnAtk,//真伤 - Durability,//耐久 MinAtk, MaxAtk, Atk,//攻击 @@ -86,22 +84,9 @@ public static class GameEnum Defense,//防御 Agility,//敏捷 Morale,//士气 - Light,//光 - LightLess,//光抗 - Dark,//暗 - DarkLess,//暗抗 - Star,//星 - StarLess,//星抗 - Thunder,//雷 - ThunderLess,//雷抗性 - Wind,//风 - WindLess,//风抗性 - Bolt,//电 - BoltLess,//电抗性 Burst,//爆率 InBlood,//吸血 Crit,//暴击 - disDefense,//无视防御 Dodge,//闪避 NoHarm,//免伤 Rebound,//反弹 @@ -129,11 +114,7 @@ public static class GameEnum SlowLess,//抗迟缓 Depth,//潜水深度 Height,//升空高度 - Weight,//负重 - RetBloodLimit,//限制回血特殊属性 - Stealth,//隐身效果 - DisStealth,//反隐效果 - TM,//天幕 + Weight//负重 } public enum GameStockCode @@ -147,4 +128,16 @@ public static class GameEnum Number,//数值 Time,//时间 } + + public enum FightCode + { + PVP,//人物对战 + PVE//NPC对战 + } + public enum AreaCode + { + Own,//个人怪物 + Public,//公共怪物 + Team,//队伍怪物 + } } \ No newline at end of file diff --git a/Service/Application.Domain/Enum/MonsterEnum.cs b/Service/Application.Domain/Enum/MonsterEnum.cs index 2ffb97d..cd501cf 100644 --- a/Service/Application.Domain/Enum/MonsterEnum.cs +++ b/Service/Application.Domain/Enum/MonsterEnum.cs @@ -2,14 +2,10 @@ public static class MonsterEnum { - public enum Code + public enum AwardCode { + Default, } - public enum AreaCode - { - Own,//个人怪物 - Public,//公共怪物 - Team,//队伍怪物 - } + } \ No newline at end of file diff --git a/Service/Application.Domain/Services/Interface/Fight/IGameFightService.cs b/Service/Application.Domain/Services/Interface/Fight/IGameFightService.cs index 4ed1590..725f65f 100644 --- a/Service/Application.Domain/Services/Interface/Fight/IGameFightService.cs +++ b/Service/Application.Domain/Services/Interface/Fight/IGameFightService.cs @@ -5,14 +5,13 @@ public interface IGameFightService #region 用户战斗索引 Task> GetUserFight(string userId); - Task AddUserFight(string userId, string fightId); Task RemoveUserFight(string userId, string fightId); #endregion #region 战斗信息 Task GetFightInfo(string fightId); Task GetFightBlood(string keyId, long maxBlood); Task SetFightBlood(string keyId, long blood); - + Task AddFightHarm(string fightId, string userId, long harm); Task AddFight(string fightId, string areaCode, string keyId, string mainId, string code, string scene, string mapId, string userId, long exp = 0, long copper = 0, long petExp = 0, string award = "", string pars = ""); diff --git a/Service/Application.Domain/Services/Interface/Map/IGameMapService.cs b/Service/Application.Domain/Services/Interface/Map/IGameMapService.cs index d4ec39b..34fc0c7 100644 --- a/Service/Application.Domain/Services/Interface/Map/IGameMapService.cs +++ b/Service/Application.Domain/Services/Interface/Map/IGameMapService.cs @@ -18,6 +18,7 @@ public interface IGameMapService #region 用户地图 Task GetUserOnMapId(string userId); + Task GetUserOnToMapInfo(string userId); Task GetUserOnMap(string userId); Task UpdateUserOnMap(string userId, string ip, string mapId); Task UpdateUserOnMap(unit_user_online data, string mapId); diff --git a/Service/Application.Domain/Services/Interface/Monster/IGameMonsterService.cs b/Service/Application.Domain/Services/Interface/Monster/IGameMonsterService.cs index 73df623..1ba4ca9 100644 --- a/Service/Application.Domain/Services/Interface/Monster/IGameMonsterService.cs +++ b/Service/Application.Domain/Services/Interface/Monster/IGameMonsterService.cs @@ -2,13 +2,18 @@ public interface IGameMonsterService { + #region 基础资源库 + + Task GetMonsterInfo(string monsterId); + #endregion #region 地图怪物 Task> GetMonsterDataByMap(string mapId); - + Task GetMapMonsterInfo(string mmId); Task CreateMonsterToMap(string userId, string mapId, string areaCode, string monsterId, int count = 1, int time = 0, string par = ""); + Task GetCreateMonsterInfo(string umId); Task> GetMapMonster(string userId, string mapId, string teamId); #endregion diff --git a/Service/Application.Domain/Services/Service/Fight/GameFightService.cs b/Service/Application.Domain/Services/Service/Fight/GameFightService.cs index 6d2f939..ea9c375 100644 --- a/Service/Application.Domain/Services/Service/Fight/GameFightService.cs +++ b/Service/Application.Domain/Services/Service/Fight/GameFightService.cs @@ -17,7 +17,7 @@ public class GameFightService(ISqlSugarClient DbClient, IRedisCache redis) : IGa return data; } - public async Task AddUserFight(string userId, string fightId) + private async Task AddUserFight(string userId, string fightId) { var data = await GetUserFight(userId); data.Add(fightId); @@ -61,16 +61,35 @@ public class GameFightService(ISqlSugarClient DbClient, IRedisCache redis) : IGa if (await redis.ExistsAsync(key)) { blood = await redis.GetAsync(key); + blood = blood > maxBlood ? maxBlood : blood; + } + else + { + await SetFightBlood(keyId, blood); } - blood = blood > maxBlood ? maxBlood : blood; return blood; } public async Task SetFightBlood(string keyId, long blood) { string key = string.Format(FightCache.FightCacheKeys, "FightData:Blood", keyId); - await redis.SetAsync(key, blood, 3600); + await redis.SetAsync(key, blood, 43200); + } + + public async Task AddFightHarm(string fightId,string userId, long harm) + { + string key = string.Format(FightCache.FightCacheKeys, "FightData:Harm", fightId); + if (await redis.HExistsHashAsync(key, userId)) + { + long sum = await redis.GetHashAsync(key, userId); + sum += harm; + await redis.AddHashAsync(key, userId, sum); + } + else + { + await redis.AddHashAsync(key, userId, harm); + } } @@ -88,6 +107,8 @@ public class GameFightService(ISqlSugarClient DbClient, IRedisCache redis) : IGa long addTime = TimeExtend.GetTimeStampSeconds; long endTime = addTime + 24 * 60 * 60; + List fights = new List(); + game_fight_data data = new game_fight_data() { fightId = fightId, @@ -104,17 +125,45 @@ public class GameFightService(ISqlSugarClient DbClient, IRedisCache redis) : IGa copper = copper, petExp = petExp, award = award, - harm = 0, pars = pars, addTime = addTime, okTime = 0, endTime = endTime }; + fights.Add(data); + if (code == nameof(GameEnum.FightCode.PVP)) + { + fights.Add(new game_fight_data() + { + fightId = StringAssist.NewGuid, + areaCode = areaCode, + keyId = keyId, + mainId = userId, + code = code, + scene = scene, + mapId = mapId, + userId = mainId, + state = 0, + winUser = "", + exp = exp, + copper = copper, + petExp = petExp, + award = award, + pars = pars, + addTime = addTime, + okTime = 0, + endTime = endTime + }); + } + var db = DbClient.AsTenant().GetConnectionWithAttr(); - bool result = await db.Insertable(data).ExecuteCommandAsync() > 0; + bool result = await db.Insertable(fights).ExecuteCommandAsync() > 0; if (result) { - await AddUserFight(userId, fightId); + foreach (var item in fights) + { + await AddUserFight(item.userId, item.fightId); + } } return result; diff --git a/Service/Application.Domain/Services/Service/Map/GameMapService.cs b/Service/Application.Domain/Services/Service/Map/GameMapService.cs index 5b25721..a93d16a 100644 --- a/Service/Application.Domain/Services/Service/Map/GameMapService.cs +++ b/Service/Application.Domain/Services/Service/Map/GameMapService.cs @@ -148,6 +148,12 @@ public class GameMapService(ISqlSugarClient DbClient, IRedisCache redis) : IGame return data.mapId; } + public async Task GetUserOnToMapInfo(string userId) + { + var onMap = await GetUserOnMapId(userId); + return await GetMapInfo(onMap); + } + public async Task GetUserOnMap(string userId) { string key = string.Format(UserCache.BaseCacheKey, "UserOnline"); diff --git a/Service/Application.Domain/Services/Service/Monster/GameMonsterService.cs b/Service/Application.Domain/Services/Service/Monster/GameMonsterService.cs index 603de1a..d9ede28 100644 --- a/Service/Application.Domain/Services/Service/Monster/GameMonsterService.cs +++ b/Service/Application.Domain/Services/Service/Monster/GameMonsterService.cs @@ -38,6 +38,20 @@ public class GameMonsterService(ISqlSugarClient DbClient, IRedisCache redis) : I return data; } + public async Task GetMapMonsterInfo(string mmId) + { + string key = string.Format(BaseCache.BaseCacheKeys, "MonsterData", "MapMonsterInfo"); + if (await redis.HExistsHashAsync(key, mmId)) + { + return await redis.GetHashAsync(key, mmId); + } + + var db = DbClient.AsTenant().GetConnectionWithAttr(); + var data = await db.Queryable().Where(it => it.mmId == mmId).SingleAsync(); + await redis.AddHashAsync(key, mmId, data); + return data; + } + public async Task CreateMonsterToMap(string userId, string mapId, string areaCode, string monsterId, int count = 1, int time = 0, string par = "") { @@ -96,6 +110,13 @@ public class GameMonsterService(ISqlSugarClient DbClient, IRedisCache redis) : I await redis.AddHashAsync(key, mapId, data); return data; } + + public async Task GetCreateMonsterInfo(string umId) + { + var db = DbClient.AsTenant().GetConnectionWithAttr(); + var data = await db.Queryable().Where(it => it.umId == umId).SingleAsync(); + return data; + } private async Task ClearCreateMonster(string mapId) { @@ -105,6 +126,7 @@ public class GameMonsterService(ISqlSugarClient DbClient, IRedisCache redis) : I public async Task> GetMapMonster(string userId, string mapId, string teamId) { + string userKey = await UserKeyTool.GetUserKey(userId); List result = new List(); var mapMonster = await GetMonsterDataByMap(mapId); if (mapMonster.Count > 0) @@ -123,7 +145,8 @@ public class GameMonsterService(ISqlSugarClient DbClient, IRedisCache redis) : I { monterId = item.mmId, name = item.monsterName, - type = 0 + type = 0, + sign = UserKeyTool.GetThickenDataByUserKey(userKey, "0", item.mmId) }; result.Add(temp); } @@ -141,7 +164,7 @@ public class GameMonsterService(ISqlSugarClient DbClient, IRedisCache redis) : I createMonster = createMonster.FindAll(it => it.endTime > onTime); createData.AddRange(createMonster.FindAll(it => - it.userId == userId || it.areaCode == nameof(MonsterEnum.AreaCode.Public))); + it.userId == userId || it.areaCode == nameof(GameEnum.AreaCode.Public))); if (!string.IsNullOrEmpty(teamId) && teamId != "0") { var teamService = App.GetService(); @@ -149,7 +172,7 @@ public class GameMonsterService(ISqlSugarClient DbClient, IRedisCache redis) : I teamMember = teamMember.FindAll(it => it.userId != userId); var onCreate = createMonster.FindAll(it => teamMember.Any(team => - team.userId == it.userId && it.areaCode == nameof(MonsterEnum.AreaCode.Team))); + team.userId == it.userId && it.areaCode == nameof(GameEnum.AreaCode.Team))); foreach (var item in onCreate) { if (createData.Any(it => it.umId == item.umId)) @@ -170,7 +193,8 @@ public class GameMonsterService(ISqlSugarClient DbClient, IRedisCache redis) : I { monterId = item.umId, name = item.monsterName, - type = 1 + type = 1, + sign = UserKeyTool.GetThickenDataByUserKey(userKey, "1", item.umId) }; result.Add(temp); } diff --git a/Service/Application.Domain/Tool/Base/GameAttrTool.cs b/Service/Application.Domain/Tool/Base/GameAttrTool.cs index bd73728..69f1a10 100644 --- a/Service/Application.Domain/Tool/Base/GameAttrTool.cs +++ b/Service/Application.Domain/Tool/Base/GameAttrTool.cs @@ -52,6 +52,16 @@ public class GameAttrTool result.PalsyAtk = GetAttrItemValue(GameEnum.AttrCode.PalsyAtk.ToString(), attrData, temp.PalsyAtk); result.PalsyAtkLess = GetAttrItemValue(GameEnum.AttrCode.PalsyAtkLess.ToString(), attrData, temp.PalsyAtk); + + result.addExp = + GetAttrItemValue(nameof(GameEnum.AttrCode.AddExp), attrData, temp.addExp); + result.addGold = + GetAttrItemValue(nameof(GameEnum.AttrCode.AddGold), attrData, temp.addGold); + result.burst = + GetAttrItemValue(nameof(GameEnum.AttrCode.Burst), attrData, temp.burst); + result.luck = + GetAttrItemValue(nameof(GameEnum.AttrCode.Luck), attrData, temp.luck); + result.weight = Convert.ToInt32(GetAttrItemValue(nameof(GameEnum.AttrCode.Weight), attrData, temp.weight)); return result; } @@ -96,6 +106,12 @@ public class GameAttrTool result.Harm_Add += GetAttrItemValue(GameEnum.AttrCode.Harm_Add.ToString(), attrData, 0); result.PalsyAtk += GetAttrItemValue(GameEnum.AttrCode.PalsyAtk.ToString(), attrData, 0); result.PalsyAtkLess += GetAttrItemValue(GameEnum.AttrCode.PalsyAtkLess.ToString(), attrData, 0); + + result.addExp += GetAttrItemValue(GameEnum.AttrCode.AddExp.ToString(), attrData, 0); + result.addGold += GetAttrItemValue(GameEnum.AttrCode.AddGold.ToString(), attrData, 0); + result.burst += GetAttrItemValue(GameEnum.AttrCode.Burst.ToString(), attrData, 0); + result.luck += GetAttrItemValue(GameEnum.AttrCode.Luck.ToString(), attrData, 0); + result.weight += Convert.ToInt32(GetAttrItemValue(GameEnum.AttrCode.Weight.ToString(), attrData, 0)) ; return result; } @@ -133,6 +149,12 @@ public class GameAttrTool main.Harm_Add += vice.Harm_Add; main.PalsyAtk += vice.PalsyAtk; main.PalsyAtkLess += vice.PalsyAtkLess; + + main.addExp += vice.addExp; + main.addGold += vice.addGold; + main.burst += vice.burst; + main.luck += vice.luck; + main.weight += vice.weight; return main; } diff --git a/Service/Application.Domain/Tool/Base/GameBus.cs b/Service/Application.Domain/Tool/Base/GameBus.cs index 82647b6..eff9b30 100644 --- a/Service/Application.Domain/Tool/Base/GameBus.cs +++ b/Service/Application.Domain/Tool/Base/GameBus.cs @@ -380,7 +380,7 @@ public static class GameBus return null; } - public static List GetRandomGoods(RandomModel random, int count = 1, int luck = 0) + public static List GetRandomGoods(RandomModel random, int count = 1, decimal luck = 0) { List result = new List(); for (int i = 0; i < count; i++) @@ -419,11 +419,11 @@ public static class GameBus return result; } - private static List RandomHandleByWeight(RandomModel random, int luck = 0) + private static List RandomHandleByWeight(RandomModel random, decimal luck = 0) { var _randomInstance = new Random(); List result = new List(); - int empty = random.empty - luck; + int empty = random.empty - Convert.ToInt32(luck * 100); if (_randomInstance.Next(0, 100) < empty) { return result; @@ -450,11 +450,11 @@ public static class GameBus return result; } - private static List RandomHandleByChance(RandomModel random, int luck = 0) + private static List RandomHandleByChance(RandomModel random, decimal luck = 0) { var _randomInstance = new Random(); List result = new List(); - int empty = random.empty - luck; + int empty = random.empty; if (_randomInstance.Next(0, 100) < empty) { return result; @@ -468,7 +468,7 @@ public static class GameBus foreach (var item in random.data) { double rnd = _randomInstance.NextDouble(); - double okChance = item.chance / 100; + double okChance = (item.chance / 100) * (1.0 + Convert.ToDouble(luck)); if (rnd < okChance) { result.Add(item); diff --git a/Service/Application.Domain/Tool/Base/UserKeyTool.cs b/Service/Application.Domain/Tool/Base/UserKeyTool.cs new file mode 100644 index 0000000..341defb --- /dev/null +++ b/Service/Application.Domain/Tool/Base/UserKeyTool.cs @@ -0,0 +1,47 @@ +namespace Application.Domain; + +public static class UserKeyTool +{ + public static async Task GetThickenData(string userId, params string[] data) + { + string key = await GetUserKey(userId); + return GetThickenDataByUserKey(key, data); + } + + public static string GetThickenDataByUserKey(string key, params string[] data) + { + string _data = string.Join("", data); + return EncryptAssist.Md5Encryption($"{key}_{_data}").ToLower(); + } + + + public static async Task CheckUserThickenData(string userId, string sign, params string[] data) + { + string key = await GetUserKey(userId); + string _sign = GetThickenDataByUserKey(key, data); + await ResetUserKey(userId); + return sign.ToLower() == _sign; + } + + public static async Task GetUserKey(string userId) + { + var key = string.Format(UserCache.BaseCacheKey, "UserKey"); + var redis = App.GetService(); + if (await redis.HExistsHashAsync(key, userId)) + { + return await redis.GetHashAsync(key, userId); + } + + string data = StringAssist.RandomString(12); + await redis.AddHashAsync(key, userId, data); + return data; + } + + private static async Task ResetUserKey(string userId) + { + string data = StringAssist.RandomString(12); + var key = string.Format(UserCache.BaseCacheKey, "UserKey"); + var redis = App.GetService(); + await redis.AddHashAsync(key, userId, data); + } +} \ No newline at end of file diff --git a/Service/Application.Web/Controllers/Map/MapController.cs b/Service/Application.Web/Controllers/Map/MapController.cs index 4ac2652..6d47836 100644 --- a/Service/Application.Web/Controllers/Map/MapController.cs +++ b/Service/Application.Web/Controllers/Map/MapController.cs @@ -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); diff --git a/Service/Application.Web/Controllers/Pub/FightController.cs b/Service/Application.Web/Controllers/Pub/FightController.cs new file mode 100644 index 0000000..1398cda --- /dev/null +++ b/Service/Application.Web/Controllers/Pub/FightController.cs @@ -0,0 +1,107 @@ +using Microsoft.AspNetCore.Mvc; +using Newtonsoft.Json; + +namespace Application.Web.Controllers.Pub; + +/// +/// 战斗接口 +/// +[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; + } + + /// + /// 添加怪物战斗 + /// + /// + /// + [HttpPost] + public async Task 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(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 Fight([FromBody] FightParms parms) + { + return PoAction.Ok(true); + } +} \ No newline at end of file diff --git a/Service/Application.Web/Model/RequestParms/Fight/FightMonsterParms.cs b/Service/Application.Web/Model/RequestParms/Fight/FightMonsterParms.cs new file mode 100644 index 0000000..cfa5fe1 --- /dev/null +++ b/Service/Application.Web/Model/RequestParms/Fight/FightMonsterParms.cs @@ -0,0 +1,8 @@ +namespace Application.Web; + +public class FightMonsterParms +{ + public int type { get; set; } + public string monsterId { get; set; } + public string sign { get; set; } +} \ No newline at end of file diff --git a/Service/Application.Web/Model/RequestParms/Fight/FightParms.cs b/Service/Application.Web/Model/RequestParms/Fight/FightParms.cs new file mode 100644 index 0000000..394459c --- /dev/null +++ b/Service/Application.Web/Model/RequestParms/Fight/FightParms.cs @@ -0,0 +1,6 @@ +namespace Application.Web; + +public class FightParms +{ + public string fightId { get; set; } +} \ No newline at end of file diff --git a/Web/src/assets/css/style.css b/Web/src/assets/css/style.css index 5d6b518..5f7ee99 100644 --- a/Web/src/assets/css/style.css +++ b/Web/src/assets/css/style.css @@ -19,7 +19,9 @@ body { font-size: 18px; } -.main {} +.main { + margin: 5px 2px; +} div img { diff --git a/Web/src/components/Base/Abar.vue b/Web/src/components/Base/Abar.vue index d87a99b..45ff170 100644 --- a/Web/src/components/Base/Abar.vue +++ b/Web/src/components/Base/Abar.vue @@ -1,5 +1,5 @@ diff --git a/Web/src/components/Base/Abutton.vue b/Web/src/components/Base/Abutton.vue index d487b6e..497b716 100644 --- a/Web/src/components/Base/Abutton.vue +++ b/Web/src/components/Base/Abutton.vue @@ -1,7 +1,7 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/Web/src/pages/map/index.vue b/Web/src/pages/map/index.vue index edd122b..97ade96 100644 --- a/Web/src/pages/map/index.vue +++ b/Web/src/pages/map/index.vue @@ -18,7 +18,7 @@
- {{ item.name }} + {{ item.name }}
@@ -41,15 +41,18 @@
请选择出口:
东:{{ mapDong.name }} - 🚩 + 🚩  西:{{ mapXi.name }} - 🚩 + 🚩  +
南:{{ mapNan.name }} - 🚩 + 🚩  + 北:{{ mapBei.name }} - 🚩 + 🚩 +
@@ -67,7 +70,7 @@
- {{ item.mapName }} + {{ item.mapName }}  
@@ -140,6 +143,9 @@ onMounted(async () => { const BindData = async (map: string): Promise => { let result = await MapService.GetMapData(map); if (result.code == 0) { + if (result.data.fightId != '') { + return PageExtend.Redirect("/fight?f=" + result.data.fightId); + } mapInfo.value = result.data.mapInfo; cityInfo.value = result.data.cityInfo; npcData.value = result.data.npcData; @@ -296,5 +302,20 @@ const CollectRes = async () => { } } +/**攻击 */ +const AddFight = async (type: number, monsterId: string, sign: string) => { + MessageExtend.LoadingToast("战斗初始化..."); + let result = await FightService.FightMonster(type, monsterId, sign); + MessageExtend.LoadingClose(); + if (result.code == 0) { + return PageExtend.Redirect("/fight?f=" + result.data); + } + else if (result.code == -1) { + await BindData(""); + } + else { + MessageExtend.ShowDialog("提示", result.msg); + } +} diff --git a/Web/src/pages/map/run.vue b/Web/src/pages/map/run.vue index 4561547..38f54ea 100644 --- a/Web/src/pages/map/run.vue +++ b/Web/src/pages/map/run.vue @@ -12,7 +12,7 @@ 【 - {{ item.cityName }} + {{ item.cityName }} 
diff --git a/Web/src/pages/map/to.vue b/Web/src/pages/map/to.vue index 3b923b4..373aca5 100644 --- a/Web/src/pages/map/to.vue +++ b/Web/src/pages/map/to.vue @@ -12,7 +12,7 @@ 【 - {{ item.cityName }} + {{ item.cityName }}