This commit is contained in:
Putoo
2026-06-25 18:39:45 +08:00
parent 9cf2c50298
commit c374f27d16
13 changed files with 571 additions and 16 deletions

View File

@@ -0,0 +1,69 @@
using SqlSugar;
using System;
namespace Application.Domain.Entity
{
[Tenant("Kg.SeaTime.Game")]
public class unit_user_monster
{
/// <summary>
/// umId
/// </summary>
[SugarColumn(IsPrimaryKey = true, Length = 50)]
public string umId { get; set; }
/// <summary>
/// userId
/// </summary>
[SugarColumn(Length = 50, IsNullable = true)]
public string? userId { get; set; }
/// <summary>
/// areaCode
/// </summary>
[SugarColumn(Length = 255, IsNullable = true)]
public string? areaCode { get; set; }
/// <summary>
/// mapId
/// </summary>
[SugarColumn(Length = 50, IsNullable = true)]
public string? mapId { get; set; }
/// <summary>
/// monsterId
/// </summary>
[SugarColumn(Length = 50, IsNullable = true)]
public string? monsterId { get; set; }
/// <summary>
/// monsterName
/// </summary>
[SugarColumn(Length = 50, IsNullable = true)]
public string? monsterName { get; set; }
/// <summary>
/// code
/// </summary>
[SugarColumn(Length = 50, IsNullable = true)]
public string? code { get; set; }
/// <summary>
/// par
/// </summary>
[SugarColumn(Length = 255, IsNullable = true)]
public string? par { get; set; }
/// <summary>
/// addTime
/// </summary>
[SugarColumn(IsNullable = true)]
public long? addTime { get; set; }
/// <summary>
/// endTime
/// </summary>
[SugarColumn(IsNullable = true)]
public long? endTime { get; set; }
}
}

View File

@@ -0,0 +1,11 @@
namespace Application.Domain.Entity;
public class MapMonsterModel
{
public string monterId { get; set; }
public string name { get; set; }
/// <summary>
/// 0地图怪物 1生成怪物
/// </summary>
public int type { get; set; }
}

View File

@@ -0,0 +1,117 @@
using SqlSugar;
using System;
namespace Application.Domain.Entity
{
[Tenant("Kg.SeaTime.Resource")]
public class game_monster
{
/// <summary>
/// monsterId
/// </summary>
[SugarColumn(IsPrimaryKey = true, Length = 50)]
public string monsterId { get; set; }
/// <summary>
/// name
/// </summary>
[SugarColumn(Length = 50, IsNullable = true)]
public string? name { get; set; }
/// <summary>
/// 怪物应用区域
/// </summary>
[SugarColumn(Length = 50, IsNullable = true)]
public string? code { get; set; }
/// <summary>
/// lev
/// </summary>
[SugarColumn(IsNullable = true)]
public int? lev { get; set; }
/// <summary>
/// exp
/// </summary>
[SugarColumn(IsNullable = true)]
public long? exp { get; set; }
/// <summary>
/// copper
/// </summary>
[SugarColumn(IsNullable = true)]
public long? copper { get; set; }
/// <summary>
/// petExp
/// </summary>
[SugarColumn(IsNullable = true)]
public long? petExp { get; set; }
/// <summary>
/// minAtk
/// </summary>
[SugarColumn(IsNullable = true)]
public int? minAtk { get; set; }
/// <summary>
/// maxAtk
/// </summary>
[SugarColumn(IsNullable = true)]
public int? maxAtk { get; set; }
/// <summary>
/// defense
/// </summary>
[SugarColumn(IsNullable = true)]
public int? defense { get; set; }
/// <summary>
/// agility
/// </summary>
[SugarColumn(IsNullable = true)]
public int? agility { get; set; }
/// <summary>
/// blood
/// </summary>
[SugarColumn(Length = 62, IsNullable = true)]
public decimal? blood { get; set; }
/// <summary>
/// 怪物属性
/// </summary>
[SugarColumn(IsNullable = true,IsJson = true)]
public List<AttrItem> attr { get; set; }
/// <summary>
/// 怪物技能
/// </summary>
[SugarColumn(IsNullable = true)]
public string? skill { get; set; }
/// <summary>
/// award
/// </summary>
[SugarColumn(Length = 3000, IsNullable = true)]
public string? award { get; set; }
/// <summary>
/// 支持复制战斗0不支持 1支持
/// </summary>
[SugarColumn(IsNullable = true)]
public int? isCopy { get; set; }
/// <summary>
/// 怪物说明
/// </summary>
[SugarColumn(Length = 255, IsNullable = true)]
public string? remark { get; set; }
/// <summary>
/// 用于后台操作标记,无其他作用
/// </summary>
[SugarColumn(Length = 255, IsNullable = true)]
public string? markTips { get; set; }
}
}

View File

@@ -0,0 +1,57 @@
using SqlSugar;
using System;
namespace Application.Domain.Entity
{
[Tenant("Kg.SeaTime.Resource")]
public class game_monster_map
{
/// <summary>
/// mmId
/// </summary>
[SugarColumn(IsPrimaryKey = true, Length = 50)]
public string mmId { get; set; }
/// <summary>
/// mapId
/// </summary>
[SugarColumn(Length = 50, IsNullable = true)]
public string? mapId { get; set; }
/// <summary>
/// monsterId
/// </summary>
[SugarColumn(Length = 50, IsNullable = true)]
public string? monsterId { get; set; }
/// <summary>
/// monsterName
/// </summary>
[SugarColumn(Length = 50, IsNullable = true)]
public string? monsterName { get; set; }
/// <summary>
/// addCount
/// </summary>
[SugarColumn(IsNullable = true)]
public int? addCount { get; set; }
/// <summary>
/// chance
/// </summary>
[SugarColumn(IsNullable = true)]
public int? chance { get; set; }
/// <summary>
/// sTime
/// </summary>
[SugarColumn(IsNullable = true)]
public int? sTime { get; set; }
/// <summary>
/// eTime
/// </summary>
[SugarColumn(IsNullable = true)]
public int? eTime { get; set; }
}
}

View File

@@ -0,0 +1,15 @@
namespace Application.Domain;
public static class MonsterEnum
{
public enum Code
{
}
public enum AreaCode
{
Own,//个人怪物
Public,//公共怪物
Team,//队伍怪物
}
}

View File

@@ -12,7 +12,7 @@ public interface IGameEquService
#region
Task<List<unit_user_equ>> GetUserEquData(string userId, int type, string equName, int PageIndex, int PageSize,
RefAsync<int> Total, bool isRemOn = false);
RefAsync<int> Total, bool isRemOn = false, bool isRemLock = false);
Task<List<unit_user_equ>> GetUserEquData(string userId, int equId);
Task<List<unit_user_equ>> GetUserEquData(string userId, string code, List<string> noUeId);

View File

@@ -0,0 +1,15 @@
namespace Application.Domain;
public interface IGameMonsterService
{
#region
Task<List<game_monster_map>> GetMonsterDataByMap(string mapId);
Task<bool> CreateMonsterToMap(string userId, string mapId, string areaCode, string monsterId,
int count = 1, int time = 0, string par = "");
Task<List<MapMonsterModel>> GetMapMonster(string userId, string mapId, string teamId);
#endregion
}

View File

@@ -39,7 +39,7 @@ public class GameEquService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
#region
public async Task<List<unit_user_equ>> GetUserEquData(string userId, int type, string equName, int PageIndex,
int PageSize, RefAsync<int> Total, bool isRemOn = false)
int PageSize, RefAsync<int> Total, bool isRemOn = false, bool isRemLock = false)
{
long onTime = TimeExtend.GetTimeStampSeconds;
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_equ>();
@@ -48,6 +48,7 @@ public class GameEquService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
.WhereIF(type == 1, it => it.isOn == 1)
.WhereIF(type == 3, it => it.isAppr == 0)
.WhereIF(isRemOn, it => it.isOn == 0)
.WhereIF(isRemLock, it => it.isLock == 0)
.WhereIF(!string.IsNullOrEmpty(equName),
it => it.equName.Contains(equName) || it.unitEquName.Contains(equName))
.OrderByDescending(it => it.lev)

View File

@@ -0,0 +1,183 @@
using Microsoft.VisualBasic.CompilerServices;
namespace Application.Domain;
public class GameMonsterService(ISqlSugarClient DbClient, IRedisCache redis) : IGameMonsterService, ITransient
{
#region
public async Task<game_monster> GetMonsterInfo(string monsterId)
{
string key = string.Format(BaseCache.BaseCacheKeys, "MonsterData", "MonsterInfo");
if (await redis.HExistsHashAsync(key, monsterId))
{
return await redis.GetHashAsync<game_monster>(key, monsterId);
}
var db = DbClient.AsTenant().GetConnectionWithAttr<game_monster>();
var data = await db.Queryable<game_monster>().Where(it => it.monsterId == monsterId).SingleAsync();
await redis.AddHashAsync(key, monsterId, data);
return data;
}
#endregion
#region
public async Task<List<game_monster_map>> GetMonsterDataByMap(string mapId)
{
string key = string.Format(BaseCache.BaseCacheKeys, "MonsterData", "MonsterOnMap");
if (await redis.HExistsHashAsync(key, mapId))
{
return await redis.GetHashAsync<List<game_monster_map>>(key, mapId);
}
var db = DbClient.AsTenant().GetConnectionWithAttr<game_monster_map>();
var data = await db.Queryable<game_monster_map>().Where(it => it.mapId == mapId).ToListAsync();
await redis.AddHashAsync(key, mapId, data);
return data;
}
public async Task<bool> CreateMonsterToMap(string userId, string mapId, string areaCode, string monsterId,
int count = 1, int time = 0, string par = "")
{
bool result = false;
var monsterInfo = await GetMonsterInfo(monsterId);
if (monsterInfo != null)
{
time = time <= 0 ? 7 * 24 * 60 : time;
long onTime = TimeExtend.GetTimeStampSeconds;
long endTime = onTime + time * 60;
List<unit_user_monster> data = new List<unit_user_monster>();
for (int i = 0; i < count; i++)
{
data.Add(new unit_user_monster()
{
umId = StringAssist.NewGuid,
userId = userId,
areaCode = areaCode,
mapId = mapId,
monsterId = monsterId,
monsterName = monsterInfo.name,
code = monsterInfo.code,
par = par,
addTime = onTime,
endTime = endTime
});
}
if (data.Count > 0)
{
var createDb = DbClient.AsTenant().GetConnectionWithAttr<unit_user_monster>();
await createDb.Insertable(data).ExecuteCommandAsync();
}
result = true;
}
if (result)
{
await ClearCreateMonster(mapId);
}
return result;
}
private async Task<List<unit_user_monster>> GetCreateMonsterByMapId(string mapId)
{
string key = string.Format(BaseCache.BaseCacheKeys, "MonsterData", "CreateMonsterOnMap");
if (await redis.HExistsHashAsync(key, mapId))
{
return await redis.GetHashAsync<List<unit_user_monster>>(key, mapId);
}
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_monster>();
var data = await db.Queryable<unit_user_monster>().Where(it => it.mapId == mapId).ToListAsync();
await redis.AddHashAsync(key, mapId, data);
return data;
}
private async Task ClearCreateMonster(string mapId)
{
string key = string.Format(BaseCache.BaseCacheKeys, "MonsterData", "CreateMonsterOnMap");
await redis.DelHashAsync(key, mapId);
}
public async Task<List<MapMonsterModel>> GetMapMonster(string userId, string mapId, string teamId)
{
List<MapMonsterModel> result = new List<MapMonsterModel>();
var mapMonster = await GetMonsterDataByMap(mapId);
if (mapMonster.Count > 0)
{
int random = 0; //此处需要判断用户状态中的几率
int onTime = TimeAssist.GetHourNum;
foreach (var item in mapMonster)
{
if (item.sTime < onTime && item.eTime > onTime)
{
if (RandomAssist.CheakRandom((int)item.chance + random))
{
for (int i = 0; i < item.addCount; i++)
{
MapMonsterModel temp = new MapMonsterModel()
{
monterId = item.mmId,
name = item.monsterName,
type = 0
};
result.Add(temp);
}
}
}
}
}
//此处追加个人生成怪物
List<unit_user_monster> createData = new List<unit_user_monster>();
var createMonster = await GetCreateMonsterByMapId(mapId);
if (createMonster.Count > 0)
{
long onTime = TimeExtend.GetTimeStampSeconds;
createMonster = createMonster.FindAll(it => it.endTime > onTime);
createData.AddRange(createMonster.FindAll(it =>
it.userId == userId || it.areaCode == nameof(MonsterEnum.AreaCode.Public)));
if (!string.IsNullOrEmpty(teamId) && teamId != "0")
{
var teamService = App.GetService<IGameTeamService>();
var teamMember = await teamService.GetTeamMember(teamId);
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)));
foreach (var item in onCreate)
{
if (createData.Any(it => it.umId == item.umId))
{
continue;
}
createData.Add(item);
}
}
}
if (createData.Count > 0)
{
foreach (var item in createData)
{
MapMonsterModel temp = new MapMonsterModel()
{
monterId = item.umId,
name = item.monsterName,
type = 1
};
result.Add(temp);
}
}
return result;
}
#endregion
}

View File

@@ -21,9 +21,12 @@ public class MapController : ControllerBase
private readonly IGameSkillService _skillService;
private readonly IGameGoodsService _goodsService;
private readonly IGameTeamService _teamService;
private readonly IGameMonsterService _monsterService;
public MapController(IUnitUserService userService, IGameMapService mapService, IGameChatService chatService,
IUnitUserAttrService attrService, IMessageService messageService, IUnitUserWeight weightService,
IUnitUserAccService accService, IGameSkillService skillService,IGameGoodsService goodsService,IGameTeamService teamService)
IUnitUserAccService accService, IGameSkillService skillService, IGameGoodsService goodsService,
IGameTeamService teamService, IGameMonsterService monsterService)
{
_userService = userService;
_mapService = mapService;
@@ -35,6 +38,7 @@ public class MapController : ControllerBase
_skillService = skillService;
_goodsService = goodsService;
_teamService = teamService;
_monsterService = monsterService;
}
#region
@@ -89,14 +93,17 @@ public class MapController : ControllerBase
#endregion
//公聊信息
var myTeam = await _teamService.GetUserTeamData(userId);
string teamId =myTeam.teamId ;
var myTeam = await _teamService.GetUserTeamData(userId);
string teamId = myTeam.teamId;
string groupId = "";
var chatData = await _chatService.GetChatTop(userId, area, 2, teamId, groupId);
var npcData = await _mapService.GetMapNpc(mapInfo.mapId); //NPC信息
npcData = npcData.FindAll(it => GameTool.AreaVerify(StateHelper.areaId, it.areaId));
//获取怪物
var monsterData = await _monsterService.GetMapMonster(userId, mapInfo.mapId, teamId);
var nearUser =
await _mapService.GetMapUser(mapInfo.mapId, area, (int)mapInfo.lookArea, [userId],
3); //获取附近的人
@@ -145,7 +152,8 @@ public class MapController : ControllerBase
noReadMsg = noReadMsg[3],
business,
mapRes,
broadcast
broadcast,
monster = monsterData
};
return PoAction.Ok(ret);

View File

@@ -50,6 +50,7 @@ public class StoreController : ControllerBase
{
return PoAction.Message("Npc不存在!");
}
if (!npcInfo.bus.Any(it => it.code == nameof(GameEnum.NpcBusCode.Store)))
{
return PoAction.Message("业务不可用!");
@@ -88,6 +89,7 @@ public class StoreController : ControllerBase
{
return PoAction.Message("Npc不存在!");
}
if (!npcInfo.bus.Any(it => it.code == nameof(GameEnum.NpcBusCode.Store)))
{
return PoAction.Message("业务不可用!");
@@ -165,10 +167,12 @@ public class StoreController : ControllerBase
{
return PoAction.Message("Npc不存在!");
}
if (!npcInfo.bus.Any(it => it.code == nameof(GameEnum.NpcBusCode.Store)))
{
return PoAction.Message("业务不可用!");
}
var onMap = await _mapService.GetUserOnMapId(userId);
if (npcInfo.mapId != onMap)
{
@@ -179,25 +183,25 @@ public class StoreController : ControllerBase
if (type == 0)
{
var data = await _equService.GetUserEquData(userId, 0, query, page, 10, total, true);
return PoAction.Ok(new { data, total.Value });
var data = await _equService.GetUserEquData(userId, 0, query, page, 10, total, true, true);
return PoAction.Ok(new { data, total = total.Value });
}
else if (type == 1)
{
List<string> code = new List<string>() { nameof(GoodsEnum.Code.Drug) };
var data = await _goodsService.GetUserGoodsData(userId, code, new List<string>(), query, page, 10, total);
return PoAction.Ok(new { data, total.Value });
return PoAction.Ok(new { data, total = total.Value });
}
else if (type == 2)
{
List<string> code = new List<string>();
List<string> noCode = new List<string>() { nameof(GoodsEnum.Code.Drug) };
var data = await _goodsService.GetUserGoodsData(userId, code, noCode, query, page, 10, total);
return PoAction.Ok(new { data, total.Value });
return PoAction.Ok(new { data, total = total.Value });
}
else
{
return PoAction.Ok(new { data = new List<string>(), total.Value });
return PoAction.Ok(new { data = new List<string>(), total = total.Value });
}
}
@@ -229,7 +233,7 @@ public class StoreController : ControllerBase
return PoAction.Message("Npc不存在!");
}
if (parms.type == 0)//装备
if (parms.type == 0) //装备
{
var equInfo = await _equService.GetUserEquInfo(parms.id);
if (equInfo == null)
@@ -259,7 +263,7 @@ public class StoreController : ControllerBase
}
else
{
return PoAction.Message("出售失败,请稍后尝试!");
return PoAction.Message("出售失败,请稍后尝试!");
}
}
else //物品
@@ -288,7 +292,7 @@ public class StoreController : ControllerBase
}
else
{
return PoAction.Message("出售失败,请稍后尝试!");
return PoAction.Message("出售失败,请稍后尝试!");
}
}
}