1212
This commit is contained in:
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user