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

@@ -89,11 +89,7 @@ namespace Application.Domain.Entity
/// </summary> /// </summary>
[SugarColumn(IsNullable = true)] [SugarColumn(IsNullable = true)]
public string? award { get; set; } public string? award { get; set; }
/// <summary>
/// 伤害
/// </summary>
[SugarColumn(IsNullable = true)]
public long? harm { get; set; }
[SugarColumn(IsNullable = true)] [SugarColumn(IsNullable = true)]
public string? pars { get; set; } public string? pars { get; set; }
/// <summary> /// <summary>

View File

@@ -0,0 +1,7 @@
namespace Application.Domain.Entity;
public class FightAwardModel
{
public string code { get; set; }
public object award { get; set; }
}

View File

@@ -8,4 +8,6 @@ public class MapMonsterModel
/// 0地图怪物 1生成怪物 /// 0地图怪物 1生成怪物
/// </summary> /// </summary>
public int type { get; set; } public int type { get; set; }
public string sign { get; set; }
} }

View File

@@ -0,0 +1,7 @@
namespace Application.Domain.Entity;
public class MonsterAwardModel
{
public string type { get; set; }
public RandomModel award { get; set; }
}

View File

@@ -8,11 +8,14 @@
public int isCopy { get; set; } public int isCopy { get; set; }
public string viceId { get; set; } public string viceId { get; set; }
public string name { get; set; } public string name { get; set; }
public int figState { get; set; }
public string sex { get; set; } public string sex { get; set; }
public string code { get; set; } public string code { get; set; }
public string remark { get; set; } public string tips { get; set; }
public string TmImg { 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 lev { get; set; }//等级
public int minAtk { get; set; }//最小攻击 public int minAtk { get; set; }//最小攻击
public int maxAtk { get; set; }//最大攻击 public int maxAtk { get; set; }//最大攻击

View File

@@ -0,0 +1,7 @@
namespace Application.Domain;
public static class FightEnum
{
}

View File

@@ -77,8 +77,6 @@ public static class GameEnum
{ {
AddExp,//经验 AddExp,//经验
AddGold,//金币 AddGold,//金币
OnAtk,//真伤
Durability,//耐久
MinAtk, MinAtk,
MaxAtk, MaxAtk,
Atk,//攻击 Atk,//攻击
@@ -86,22 +84,9 @@ public static class GameEnum
Defense,//防御 Defense,//防御
Agility,//敏捷 Agility,//敏捷
Morale,//士气 Morale,//士气
Light,//光
LightLess,//光抗
Dark,//暗
DarkLess,//暗抗
Star,//星
StarLess,//星抗
Thunder,//雷
ThunderLess,//雷抗性
Wind,//风
WindLess,//风抗性
Bolt,//电
BoltLess,//电抗性
Burst,//爆率 Burst,//爆率
InBlood,//吸血 InBlood,//吸血
Crit,//暴击 Crit,//暴击
disDefense,//无视防御
Dodge,//闪避 Dodge,//闪避
NoHarm,//免伤 NoHarm,//免伤
Rebound,//反弹 Rebound,//反弹
@@ -129,11 +114,7 @@ public static class GameEnum
SlowLess,//抗迟缓 SlowLess,//抗迟缓
Depth,//潜水深度 Depth,//潜水深度
Height,//升空高度 Height,//升空高度
Weight,//负重 Weight//负重
RetBloodLimit,//限制回血特殊属性
Stealth,//隐身效果
DisStealth,//反隐效果
TM,//天幕
} }
public enum GameStockCode public enum GameStockCode
@@ -147,4 +128,16 @@ public static class GameEnum
Number,//数值 Number,//数值
Time,//时间 Time,//时间
} }
public enum FightCode
{
PVP,//人物对战
PVE//NPC对战
}
public enum AreaCode
{
Own,//个人怪物
Public,//公共怪物
Team,//队伍怪物
}
} }

View File

@@ -2,14 +2,10 @@
public static class MonsterEnum public static class MonsterEnum
{ {
public enum Code public enum AwardCode
{ {
Default,
} }
public enum AreaCode
{
Own,//个人怪物
Public,//公共怪物
Team,//队伍怪物
}
} }

View File

@@ -5,14 +5,13 @@ public interface IGameFightService
#region #region
Task<List<string>> GetUserFight(string userId); Task<List<string>> GetUserFight(string userId);
Task<bool> AddUserFight(string userId, string fightId);
Task<bool> RemoveUserFight(string userId, string fightId); Task<bool> RemoveUserFight(string userId, string fightId);
#endregion #endregion
#region #region
Task<game_fight_data> GetFightInfo(string fightId); Task<game_fight_data> GetFightInfo(string fightId);
Task<long> GetFightBlood(string keyId, long maxBlood); Task<long> GetFightBlood(string keyId, long maxBlood);
Task SetFightBlood(string keyId, long blood); Task SetFightBlood(string keyId, long blood);
Task AddFightHarm(string fightId, string userId, long harm);
Task<bool> AddFight(string fightId, string areaCode, string keyId, string mainId, string code, Task<bool> AddFight(string fightId, string areaCode, string keyId, string mainId, string code,
string scene, string mapId, string scene, string mapId,
string userId, long exp = 0, long copper = 0, long petExp = 0, string award = "", string pars = ""); string userId, long exp = 0, long copper = 0, long petExp = 0, string award = "", string pars = "");

View File

@@ -18,6 +18,7 @@ public interface IGameMapService
#region #region
Task<string> GetUserOnMapId(string userId); Task<string> GetUserOnMapId(string userId);
Task<game_city_map> GetUserOnToMapInfo(string userId);
Task<unit_user_online> GetUserOnMap(string userId); Task<unit_user_online> GetUserOnMap(string userId);
Task UpdateUserOnMap(string userId, string ip, string mapId); Task UpdateUserOnMap(string userId, string ip, string mapId);
Task<bool> UpdateUserOnMap(unit_user_online data, string mapId); Task<bool> UpdateUserOnMap(unit_user_online data, string mapId);

View File

@@ -2,13 +2,18 @@
public interface IGameMonsterService public interface IGameMonsterService
{ {
#region
Task<game_monster> GetMonsterInfo(string monsterId);
#endregion
#region #region
Task<List<game_monster_map>> GetMonsterDataByMap(string mapId); Task<List<game_monster_map>> GetMonsterDataByMap(string mapId);
Task<game_monster_map> GetMapMonsterInfo(string mmId);
Task<bool> CreateMonsterToMap(string userId, string mapId, string areaCode, string monsterId, Task<bool> CreateMonsterToMap(string userId, string mapId, string areaCode, string monsterId,
int count = 1, int time = 0, string par = ""); int count = 1, int time = 0, string par = "");
Task<unit_user_monster> GetCreateMonsterInfo(string umId);
Task<List<MapMonsterModel>> GetMapMonster(string userId, string mapId, string teamId); Task<List<MapMonsterModel>> GetMapMonster(string userId, string mapId, string teamId);
#endregion #endregion

View File

@@ -17,7 +17,7 @@ public class GameFightService(ISqlSugarClient DbClient, IRedisCache redis) : IGa
return data; return data;
} }
public async Task<bool> AddUserFight(string userId, string fightId) private async Task<bool> AddUserFight(string userId, string fightId)
{ {
var data = await GetUserFight(userId); var data = await GetUserFight(userId);
data.Add(fightId); data.Add(fightId);
@@ -61,16 +61,35 @@ public class GameFightService(ISqlSugarClient DbClient, IRedisCache redis) : IGa
if (await redis.ExistsAsync(key)) if (await redis.ExistsAsync(key))
{ {
blood = await redis.GetAsync<long>(key); blood = await redis.GetAsync<long>(key);
blood = blood > maxBlood ? maxBlood : blood;
}
else
{
await SetFightBlood(keyId, blood);
} }
blood = blood > maxBlood ? maxBlood : blood;
return blood; return blood;
} }
public async Task SetFightBlood(string keyId, long blood) public async Task SetFightBlood(string keyId, long blood)
{ {
string key = string.Format(FightCache.FightCacheKeys, "FightData:Blood", keyId); 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<long>(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 addTime = TimeExtend.GetTimeStampSeconds;
long endTime = addTime + 24 * 60 * 60; long endTime = addTime + 24 * 60 * 60;
List<game_fight_data> fights = new List<game_fight_data>();
game_fight_data data = new game_fight_data() game_fight_data data = new game_fight_data()
{ {
fightId = fightId, fightId = fightId,
@@ -104,17 +125,45 @@ public class GameFightService(ISqlSugarClient DbClient, IRedisCache redis) : IGa
copper = copper, copper = copper,
petExp = petExp, petExp = petExp,
award = award, award = award,
harm = 0,
pars = pars, pars = pars,
addTime = addTime, addTime = addTime,
okTime = 0, okTime = 0,
endTime = endTime 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<game_fight_data>(); var db = DbClient.AsTenant().GetConnectionWithAttr<game_fight_data>();
bool result = await db.Insertable(data).ExecuteCommandAsync() > 0; bool result = await db.Insertable(fights).ExecuteCommandAsync() > 0;
if (result) if (result)
{ {
await AddUserFight(userId, fightId); foreach (var item in fights)
{
await AddUserFight(item.userId, item.fightId);
}
} }
return result; return result;

View File

@@ -148,6 +148,12 @@ public class GameMapService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
return data.mapId; return data.mapId;
} }
public async Task<game_city_map> GetUserOnToMapInfo(string userId)
{
var onMap = await GetUserOnMapId(userId);
return await GetMapInfo(onMap);
}
public async Task<unit_user_online> GetUserOnMap(string userId) public async Task<unit_user_online> GetUserOnMap(string userId)
{ {
string key = string.Format(UserCache.BaseCacheKey, "UserOnline"); string key = string.Format(UserCache.BaseCacheKey, "UserOnline");

View File

@@ -38,6 +38,20 @@ public class GameMonsterService(ISqlSugarClient DbClient, IRedisCache redis) : I
return data; return data;
} }
public async Task<game_monster_map> GetMapMonsterInfo(string mmId)
{
string key = string.Format(BaseCache.BaseCacheKeys, "MonsterData", "MapMonsterInfo");
if (await redis.HExistsHashAsync(key, mmId))
{
return await redis.GetHashAsync<game_monster_map>(key, mmId);
}
var db = DbClient.AsTenant().GetConnectionWithAttr<game_monster_map>();
var data = await db.Queryable<game_monster_map>().Where(it => it.mmId == mmId).SingleAsync();
await redis.AddHashAsync(key, mmId, data);
return data;
}
public async Task<bool> CreateMonsterToMap(string userId, string mapId, string areaCode, string monsterId, public async Task<bool> CreateMonsterToMap(string userId, string mapId, string areaCode, string monsterId,
int count = 1, int time = 0, string par = "") 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); await redis.AddHashAsync(key, mapId, data);
return data; return data;
} }
public async Task<unit_user_monster> GetCreateMonsterInfo(string umId)
{
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_monster>();
var data = await db.Queryable<unit_user_monster>().Where(it => it.umId == umId).SingleAsync();
return data;
}
private async Task ClearCreateMonster(string mapId) private async Task ClearCreateMonster(string mapId)
{ {
@@ -105,6 +126,7 @@ public class GameMonsterService(ISqlSugarClient DbClient, IRedisCache redis) : I
public async Task<List<MapMonsterModel>> GetMapMonster(string userId, string mapId, string teamId) public async Task<List<MapMonsterModel>> GetMapMonster(string userId, string mapId, string teamId)
{ {
string userKey = await UserKeyTool.GetUserKey(userId);
List<MapMonsterModel> result = new List<MapMonsterModel>(); List<MapMonsterModel> result = new List<MapMonsterModel>();
var mapMonster = await GetMonsterDataByMap(mapId); var mapMonster = await GetMonsterDataByMap(mapId);
if (mapMonster.Count > 0) if (mapMonster.Count > 0)
@@ -123,7 +145,8 @@ public class GameMonsterService(ISqlSugarClient DbClient, IRedisCache redis) : I
{ {
monterId = item.mmId, monterId = item.mmId,
name = item.monsterName, name = item.monsterName,
type = 0 type = 0,
sign = UserKeyTool.GetThickenDataByUserKey(userKey, "0", item.mmId)
}; };
result.Add(temp); result.Add(temp);
} }
@@ -141,7 +164,7 @@ public class GameMonsterService(ISqlSugarClient DbClient, IRedisCache redis) : I
createMonster = createMonster.FindAll(it => it.endTime > onTime); createMonster = createMonster.FindAll(it => it.endTime > onTime);
createData.AddRange(createMonster.FindAll(it => 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") if (!string.IsNullOrEmpty(teamId) && teamId != "0")
{ {
var teamService = App.GetService<IGameTeamService>(); var teamService = App.GetService<IGameTeamService>();
@@ -149,7 +172,7 @@ public class GameMonsterService(ISqlSugarClient DbClient, IRedisCache redis) : I
teamMember = teamMember.FindAll(it => it.userId != userId); teamMember = teamMember.FindAll(it => it.userId != userId);
var onCreate = createMonster.FindAll(it => var onCreate = createMonster.FindAll(it =>
teamMember.Any(team => 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) foreach (var item in onCreate)
{ {
if (createData.Any(it => it.umId == item.umId)) if (createData.Any(it => it.umId == item.umId))
@@ -170,7 +193,8 @@ public class GameMonsterService(ISqlSugarClient DbClient, IRedisCache redis) : I
{ {
monterId = item.umId, monterId = item.umId,
name = item.monsterName, name = item.monsterName,
type = 1 type = 1,
sign = UserKeyTool.GetThickenDataByUserKey(userKey, "1", item.umId)
}; };
result.Add(temp); result.Add(temp);
} }

View File

@@ -52,6 +52,16 @@ public class GameAttrTool
result.PalsyAtk = GetAttrItemValue(GameEnum.AttrCode.PalsyAtk.ToString(), attrData, temp.PalsyAtk); result.PalsyAtk = GetAttrItemValue(GameEnum.AttrCode.PalsyAtk.ToString(), attrData, temp.PalsyAtk);
result.PalsyAtkLess = result.PalsyAtkLess =
GetAttrItemValue(GameEnum.AttrCode.PalsyAtkLess.ToString(), attrData, temp.PalsyAtk); 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; return result;
} }
@@ -96,6 +106,12 @@ public class GameAttrTool
result.Harm_Add += GetAttrItemValue(GameEnum.AttrCode.Harm_Add.ToString(), attrData, 0); result.Harm_Add += GetAttrItemValue(GameEnum.AttrCode.Harm_Add.ToString(), attrData, 0);
result.PalsyAtk += GetAttrItemValue(GameEnum.AttrCode.PalsyAtk.ToString(), attrData, 0); result.PalsyAtk += GetAttrItemValue(GameEnum.AttrCode.PalsyAtk.ToString(), attrData, 0);
result.PalsyAtkLess += GetAttrItemValue(GameEnum.AttrCode.PalsyAtkLess.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; return result;
} }
@@ -133,6 +149,12 @@ public class GameAttrTool
main.Harm_Add += vice.Harm_Add; main.Harm_Add += vice.Harm_Add;
main.PalsyAtk += vice.PalsyAtk; main.PalsyAtk += vice.PalsyAtk;
main.PalsyAtkLess += vice.PalsyAtkLess; 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; return main;
} }

View File

@@ -380,7 +380,7 @@ public static class GameBus
return null; return null;
} }
public static List<TowerGet> GetRandomGoods(RandomModel random, int count = 1, int luck = 0) public static List<TowerGet> GetRandomGoods(RandomModel random, int count = 1, decimal luck = 0)
{ {
List<TowerGet> result = new List<TowerGet>(); List<TowerGet> result = new List<TowerGet>();
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
@@ -419,11 +419,11 @@ public static class GameBus
return result; return result;
} }
private static List<RandomData> RandomHandleByWeight(RandomModel random, int luck = 0) private static List<RandomData> RandomHandleByWeight(RandomModel random, decimal luck = 0)
{ {
var _randomInstance = new Random(); var _randomInstance = new Random();
List<RandomData> result = new List<RandomData>(); List<RandomData> result = new List<RandomData>();
int empty = random.empty - luck; int empty = random.empty - Convert.ToInt32(luck * 100);
if (_randomInstance.Next(0, 100) < empty) if (_randomInstance.Next(0, 100) < empty)
{ {
return result; return result;
@@ -450,11 +450,11 @@ public static class GameBus
return result; return result;
} }
private static List<RandomData> RandomHandleByChance(RandomModel random, int luck = 0) private static List<RandomData> RandomHandleByChance(RandomModel random, decimal luck = 0)
{ {
var _randomInstance = new Random(); var _randomInstance = new Random();
List<RandomData> result = new List<RandomData>(); List<RandomData> result = new List<RandomData>();
int empty = random.empty - luck; int empty = random.empty;
if (_randomInstance.Next(0, 100) < empty) if (_randomInstance.Next(0, 100) < empty)
{ {
return result; return result;
@@ -468,7 +468,7 @@ public static class GameBus
foreach (var item in random.data) foreach (var item in random.data)
{ {
double rnd = _randomInstance.NextDouble(); double rnd = _randomInstance.NextDouble();
double okChance = item.chance / 100; double okChance = (item.chance / 100) * (1.0 + Convert.ToDouble(luck));
if (rnd < okChance) if (rnd < okChance)
{ {
result.Add(item); result.Add(item);

View File

@@ -0,0 +1,47 @@
namespace Application.Domain;
public static class UserKeyTool
{
public static async Task<string> 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<bool> 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<string> GetUserKey(string userId)
{
var key = string.Format(UserCache.BaseCacheKey, "UserKey");
var redis = App.GetService<IRedisCache>();
if (await redis.HExistsHashAsync(key, userId))
{
return await redis.GetHashAsync<string>(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<IRedisCache>();
await redis.AddHashAsync(key, userId, data);
}
}

View File

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

View File

@@ -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; }
}

View File

@@ -0,0 +1,6 @@
namespace Application.Web;
public class FightParms
{
public string fightId { get; set; }
}

View File

@@ -19,7 +19,9 @@ body {
font-size: 18px; font-size: 18px;
} }
.main {} .main {
margin: 5px 2px;
}
div img { div img {

View File

@@ -1,5 +1,5 @@
<template> <template>
<router-link :to="href" :class="_class"> <router-link :to="href" :class="_class" style=" text-decoration: underline;">
<slot></slot> <slot></slot>
</router-link> </router-link>
</template> </template>

View File

@@ -1,7 +1,7 @@
<template> <template>
<button class="kx-link-button" @click="handleClick"> <span style="color: #1e5494;text-decoration: underline;font-size: 18px;cursor: pointer;" @click="handleClick">
<slot></slot> <slot></slot>
</button> </span>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>

View File

@@ -5,7 +5,7 @@
<Abar href="/">首页</Abar>- <Abar href="/">首页</Abar>-
<Abar href="/">挂机</Abar>- <Abar href="/">挂机</Abar>-
<!-- <Abar href="/treasure">聚宝盆</Abar>- --> <!-- <Abar href="/treasure">聚宝盆</Abar>- -->
<a target="_blank" href="https://work.weixin.qq.com/kfid/kfc86bc348120aea3e7">反馈</a> <a target="_blank" href="https://work.weixin.qq.com/kfid/kfc86bc348120aea3e7" style="text-decoration: underline;">反馈</a>
</div> </div>
<div class="timeService"> <div class="timeService">

View File

@@ -1,11 +1,12 @@
<template> <template>
<slot /> <div class="main">
<slot />
</div>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
// 空白布局 - 用于登录页、弹窗、独立页面等不需要导航栏的场景 // 空白布局 - 用于登录页、弹窗、独立页面等不需要导航栏的场景
</script> </script>
<style scoped> <style scoped></style>
</style>

View File

@@ -18,7 +18,7 @@
</div> </div>
<div class="content"> <div class="content">
<span class="item" v-for="item in monster"> <span class="item" v-for="item in monster">
<Abutton>{{ item.name }}</Abutton> <Abutton @click="AddFight(item.type, item.monterId, item.sign)">{{ item.name }}</Abutton>
</span> </span>
</div> </div>
<div class="content"> <div class="content">
@@ -41,15 +41,18 @@
<div class="content"> <div class="content">
请选择出口:<br /> 请选择出口:<br />
<span v-if="mapDong.mapId != ''">东:<Abutton @click="BindData(mapDong.mapId)">{{ mapDong.name }}</Abutton> <span v-if="mapDong.mapId != ''">东:<Abutton @click="BindData(mapDong.mapId)">{{ mapDong.name }}</Abutton>
<b v-if="toMapPathData.some(it => it.mapId == mapDong.mapId)">🚩</b> <b v-if="toMapPathData.some(it => it.mapId == mapDong.mapId)">🚩</b>&nbsp;
</span> </span>
<span v-if="mapXi.mapId != ''">西:<Abutton @click="BindData(mapXi.mapId)">{{ mapXi.name }}</Abutton> <span v-if="mapXi.mapId != ''">西:<Abutton @click="BindData(mapXi.mapId)">{{ mapXi.name }}</Abutton>
<b v-if="toMapPathData.some(it => it.mapId == mapXi.mapId)">🚩</b></span> <b v-if="toMapPathData.some(it => it.mapId == mapXi.mapId)">🚩</b>&nbsp;
</span>
<br v-if="mapDong.mapId != '' || mapXi.mapId != ''"> <br v-if="mapDong.mapId != '' || mapXi.mapId != ''">
<span v-if="mapNan.mapId != ''">南:<Abutton @click="BindData(mapNan.mapId)">{{ mapNan.name }}</Abutton> <span v-if="mapNan.mapId != ''">南:<Abutton @click="BindData(mapNan.mapId)">{{ mapNan.name }}</Abutton>
<b v-if="toMapPathData.some(it => it.mapId == mapNan.mapId)">🚩</b></span> <b v-if="toMapPathData.some(it => it.mapId == mapNan.mapId)">🚩</b>&nbsp;
</span>
<span v-if="mapBei.mapId != ''">北:<Abutton @click="BindData(mapBei.mapId)">{{ mapBei.name }}</Abutton> <span v-if="mapBei.mapId != ''">北:<Abutton @click="BindData(mapBei.mapId)">{{ mapBei.name }}</Abutton>
<b v-if="toMapPathData.some(it => it.mapId == mapBei.mapId)">🚩</b></span> <b v-if="toMapPathData.some(it => it.mapId == mapBei.mapId)">🚩</b>
</span>
</div> </div>
<div class="content"> <div class="content">
@@ -67,7 +70,7 @@
<!-- 自定义内容 --> <!-- 自定义内容 -->
<div class="" style="margin-top: 10px;"> <div class="" style="margin-top: 10px;">
<span v-for="(item, index) in cityShow" :key="index"> <span v-for="(item, index) in cityShow" :key="index">
<Abutton @click="ChangeMap(item.mapId)">{{ item.mapName }}</Abutton> <Abutton @click="ChangeMap(item.mapId)">{{ item.mapName }}</Abutton>&nbsp;&nbsp;
<br v-if="(index + 1) % 4 == 0"> <br v-if="(index + 1) % 4 == 0">
</span> </span>
</div> </div>
@@ -140,6 +143,9 @@ onMounted(async () => {
const BindData = async (map: string): Promise<void> => { const BindData = async (map: string): Promise<void> => {
let result = await MapService.GetMapData(map); let result = await MapService.GetMapData(map);
if (result.code == 0) { if (result.code == 0) {
if (result.data.fightId != '') {
return PageExtend.Redirect("/fight?f=" + result.data.fightId);
}
mapInfo.value = result.data.mapInfo; mapInfo.value = result.data.mapInfo;
cityInfo.value = result.data.cityInfo; cityInfo.value = result.data.cityInfo;
npcData.value = result.data.npcData; 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);
}
}
</script> </script>

View File

@@ -12,7 +12,7 @@
<span v-for="item in area"> <span v-for="item in area">
<Acheak @click="ChangeCity(item.cityId)" :on-value="cityId.toString()" :on-cheak="item.cityId.toString()"> <Acheak @click="ChangeCity(item.cityId)" :on-value="cityId.toString()" :on-cheak="item.cityId.toString()">
{{ item.cityName }}</Acheak> {{ item.cityName }}</Acheak>&nbsp;
</span> </span>
</div> </div>

View File

@@ -12,7 +12,7 @@
<span v-for="item in area"> <span v-for="item in area">
<Acheak @click="ChangeCity(item.cityId)" :on-value="cityId.toString()" :on-cheak="item.cityId.toString()"> <Acheak @click="ChangeCity(item.cityId)" :on-value="cityId.toString()" :on-cheak="item.cityId.toString()">
{{ item.cityName }}</Acheak> {{ item.cityName }}</Acheak>&nbsp;
</span> </span>
</div> </div>