1212
This commit is contained in:
@@ -89,11 +89,7 @@ namespace Application.Domain.Entity
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public string? award { get; set; }
|
||||
/// <summary>
|
||||
/// 伤害
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public long? harm { get; set; }
|
||||
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public string? pars { get; set; }
|
||||
/// <summary>
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Application.Domain.Entity;
|
||||
|
||||
public class FightAwardModel
|
||||
{
|
||||
public string code { get; set; }
|
||||
public object award { get; set; }
|
||||
}
|
||||
@@ -8,4 +8,6 @@ public class MapMonsterModel
|
||||
/// 0地图怪物 1生成怪物
|
||||
/// </summary>
|
||||
public int type { get; set; }
|
||||
|
||||
public string sign { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Application.Domain.Entity;
|
||||
|
||||
public class MonsterAwardModel
|
||||
{
|
||||
public string type { get; set; }
|
||||
public RandomModel award { get; set; }
|
||||
}
|
||||
@@ -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; }//最大攻击
|
||||
|
||||
7
Service/Application.Domain/Enum/FightEnum.cs
Normal file
7
Service/Application.Domain/Enum/FightEnum.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace Application.Domain;
|
||||
|
||||
public static class FightEnum
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
@@ -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,//队伍怪物
|
||||
}
|
||||
}
|
||||
@@ -2,14 +2,10 @@
|
||||
|
||||
public static class MonsterEnum
|
||||
{
|
||||
public enum Code
|
||||
public enum AwardCode
|
||||
{
|
||||
Default,
|
||||
|
||||
}
|
||||
public enum AreaCode
|
||||
{
|
||||
Own,//个人怪物
|
||||
Public,//公共怪物
|
||||
Team,//队伍怪物
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,14 +5,13 @@ public interface IGameFightService
|
||||
#region 用户战斗索引
|
||||
|
||||
Task<List<string>> GetUserFight(string userId);
|
||||
Task<bool> AddUserFight(string userId, string fightId);
|
||||
Task<bool> RemoveUserFight(string userId, string fightId);
|
||||
#endregion
|
||||
#region 战斗信息
|
||||
Task<game_fight_data> GetFightInfo(string fightId);
|
||||
Task<long> GetFightBlood(string keyId, long maxBlood);
|
||||
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,
|
||||
string scene, string mapId,
|
||||
string userId, long exp = 0, long copper = 0, long petExp = 0, string award = "", string pars = "");
|
||||
|
||||
@@ -18,6 +18,7 @@ public interface IGameMapService
|
||||
#region 用户地图
|
||||
|
||||
Task<string> GetUserOnMapId(string userId);
|
||||
Task<game_city_map> GetUserOnToMapInfo(string userId);
|
||||
Task<unit_user_online> GetUserOnMap(string userId);
|
||||
Task UpdateUserOnMap(string userId, string ip, string mapId);
|
||||
Task<bool> UpdateUserOnMap(unit_user_online data, string mapId);
|
||||
|
||||
@@ -2,13 +2,18 @@
|
||||
|
||||
public interface IGameMonsterService
|
||||
{
|
||||
#region 基础资源库
|
||||
|
||||
Task<game_monster> GetMonsterInfo(string monsterId);
|
||||
#endregion
|
||||
#region 地图怪物
|
||||
|
||||
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,
|
||||
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);
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -17,7 +17,7 @@ public class GameFightService(ISqlSugarClient DbClient, IRedisCache redis) : IGa
|
||||
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);
|
||||
data.Add(fightId);
|
||||
@@ -61,16 +61,35 @@ public class GameFightService(ISqlSugarClient DbClient, IRedisCache redis) : IGa
|
||||
if (await redis.ExistsAsync(key))
|
||||
{
|
||||
blood = await redis.GetAsync<long>(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<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 endTime = addTime + 24 * 60 * 60;
|
||||
|
||||
List<game_fight_data> fights = new List<game_fight_data>();
|
||||
|
||||
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<game_fight_data>();
|
||||
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;
|
||||
|
||||
@@ -148,6 +148,12 @@ public class GameMapService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
|
||||
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)
|
||||
{
|
||||
string key = string.Format(UserCache.BaseCacheKey, "UserOnline");
|
||||
|
||||
@@ -38,6 +38,20 @@ public class GameMonsterService(ISqlSugarClient DbClient, IRedisCache redis) : I
|
||||
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,
|
||||
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<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)
|
||||
{
|
||||
@@ -105,6 +126,7 @@ public class GameMonsterService(ISqlSugarClient DbClient, IRedisCache redis) : I
|
||||
|
||||
public async Task<List<MapMonsterModel>> GetMapMonster(string userId, string mapId, string teamId)
|
||||
{
|
||||
string userKey = await UserKeyTool.GetUserKey(userId);
|
||||
List<MapMonsterModel> result = new List<MapMonsterModel>();
|
||||
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<IGameTeamService>();
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -380,7 +380,7 @@ public static class GameBus
|
||||
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>();
|
||||
for (int i = 0; i < count; i++)
|
||||
@@ -419,11 +419,11 @@ public static class GameBus
|
||||
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();
|
||||
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)
|
||||
{
|
||||
return result;
|
||||
@@ -450,11 +450,11 @@ public static class GameBus
|
||||
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();
|
||||
List<RandomData> result = new List<RandomData>();
|
||||
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);
|
||||
|
||||
47
Service/Application.Domain/Tool/Base/UserKeyTool.cs
Normal file
47
Service/Application.Domain/Tool/Base/UserKeyTool.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
107
Service/Application.Web/Controllers/Pub/FightController.cs
Normal file
107
Service/Application.Web/Controllers/Pub/FightController.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
@@ -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; }
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace Application.Web;
|
||||
|
||||
public class FightParms
|
||||
{
|
||||
public string fightId { get; set; }
|
||||
}
|
||||
@@ -19,7 +19,9 @@ body {
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
.main {}
|
||||
.main {
|
||||
margin: 5px 2px;
|
||||
}
|
||||
|
||||
|
||||
div img {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<router-link :to="href" :class="_class">
|
||||
<router-link :to="href" :class="_class" style=" text-decoration: underline;">
|
||||
<slot></slot>
|
||||
</router-link>
|
||||
</template>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<template>
|
||||
<button class="kx-link-button" @click="handleClick">
|
||||
<slot></slot>
|
||||
</button>
|
||||
<span style="color: #1e5494;text-decoration: underline;font-size: 18px;cursor: pointer;" @click="handleClick">
|
||||
<slot></slot>
|
||||
</span>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<Abar href="/">首页</Abar>-
|
||||
<Abar href="/">挂机</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 class="timeService">
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
<template>
|
||||
<slot />
|
||||
<template>
|
||||
<div class="main">
|
||||
<slot />
|
||||
</div>
|
||||
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
// 空白布局 - 用于登录页、弹窗、独立页面等不需要导航栏的场景
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
</style>
|
||||
<style scoped></style>
|
||||
@@ -18,7 +18,7 @@
|
||||
</div>
|
||||
<div class="content">
|
||||
<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>
|
||||
</div>
|
||||
<div class="content">
|
||||
@@ -41,15 +41,18 @@
|
||||
<div class="content">
|
||||
请选择出口:<br />
|
||||
<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>
|
||||
</span>
|
||||
<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>
|
||||
</span>
|
||||
<br v-if="mapDong.mapId != '' || mapXi.mapId != ''">
|
||||
<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>
|
||||
</span>
|
||||
<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 class="content">
|
||||
@@ -67,7 +70,7 @@
|
||||
<!-- 自定义内容 -->
|
||||
<div class="" style="margin-top: 10px;">
|
||||
<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>
|
||||
<br v-if="(index + 1) % 4 == 0">
|
||||
</span>
|
||||
</div>
|
||||
@@ -140,6 +143,9 @@ onMounted(async () => {
|
||||
const BindData = async (map: string): Promise<void> => {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
【
|
||||
<span v-for="item in area">
|
||||
<Acheak @click="ChangeCity(item.cityId)" :on-value="cityId.toString()" :on-cheak="item.cityId.toString()">
|
||||
{{ item.cityName }}</Acheak>
|
||||
{{ item.cityName }}</Acheak>
|
||||
</span>
|
||||
】
|
||||
</div>
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
【
|
||||
<span v-for="item in area">
|
||||
<Acheak @click="ChangeCity(item.cityId)" :on-value="cityId.toString()" :on-cheak="item.cityId.toString()">
|
||||
{{ item.cityName }}</Acheak>
|
||||
{{ item.cityName }}</Acheak>
|
||||
</span>
|
||||
】
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user