This commit is contained in:
Putoo
2026-06-29 18:17:54 +08:00
parent e47a5a19a6
commit 93d21ba9fd
35 changed files with 1073 additions and 293 deletions

View File

@@ -47,5 +47,17 @@ namespace Application.Domain.Entity
/// </summary>
[SugarColumn(IsNullable = true)]
public int? copper { get; set; }
/// <summary>
/// 出售价格
/// </summary>
[SugarColumn(IsNullable = true)]
public long? sale { get; set; }
/// <summary>
/// remark
/// </summary>
[SugarColumn(Length = 255, IsNullable = true)]
public string? remark { get; set; }
}
}

View File

@@ -0,0 +1,63 @@
using SqlSugar;
using System;
namespace Application.Domain.Entity
{
[Tenant("Kg.SeaTime.Game")]
public class unit_user_state
{
/// <summary>
/// usId
/// </summary>
[SugarColumn(IsPrimaryKey = true, Length = 50)]
public string usId { get; set; }
/// <summary>
/// userId
/// </summary>
[SugarColumn(Length = 50, IsNullable = true)]
public string? userId { get; set; }
/// <summary>
/// goodsId
/// </summary>
[SugarColumn(Length = 50, IsNullable = true)]
public string? goodsId { get; set; }
/// <summary>
/// name
/// </summary>
[SugarColumn(Length = 50, IsNullable = true)]
public string? name { get; set; }
/// <summary>
/// 场景
/// </summary>
[SugarColumn(Length = 50, IsNullable = true)]
public string? scene { get; set; }
/// <summary>
/// tips
/// </summary>
[SugarColumn(Length = 50, IsNullable = true)]
public string? tips { get; set; }
/// <summary>
/// attr
/// </summary>
[SugarColumn(IsNullable = true,IsJson = true)]
public List<AttrItem> attr { 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,8 @@
namespace Application.Domain.Entity;
public class ChoiceGoods
{
public int id { get; set; }
public string name { get; set; }
public List<TowerGet> award { get; set; }
}

View File

@@ -0,0 +1,7 @@
namespace Application.Domain.Entity;
public class UserEquAttrModel
{
public UserAttrModel equ { get; set; }
public List<AttrItem> attr { get; set; }
}

View File

@@ -0,0 +1,10 @@
namespace Application.Domain.Entity;
public class UserStateModel
{
public string name { get; set; }
public int time { get; set; }
public string scene { get; set; }
public string tips { get; set; }
public List<AttrItem> attr { get; set; }
}

View File

@@ -1,75 +0,0 @@
using SqlSugar;
using System;
namespace Application.Domain.Entity
{
[Tenant("Kg.SeaTime.Resource")]
public class game_ship
{
/// <summary>
/// shipId
/// </summary>
[SugarColumn(IsPrimaryKey = true, Length = 50)]
public int shipId { get; set; }
/// <summary>
/// npc
/// </summary>
[SugarColumn(IsNullable = true)]
public int? npc { get; set; }
/// <summary>
/// shipName
/// </summary>
[SugarColumn(Length = 50, IsNullable = true)]
public string shipName { get; set; }
/// <summary>
/// img
/// </summary>
[SugarColumn(Length = 50, IsNullable = true)]
public string img { get; set; }
/// <summary>
/// price
/// </summary>
[SugarColumn(Length = 18, IsNullable = true)]
public decimal? price { get; set; }
/// <summary>
/// salePrice
/// </summary>
[SugarColumn(Length = 18, IsNullable = true)]
public decimal? salePrice { get; set; }
/// <summary>
/// payType
/// </summary>
[SugarColumn(Length = 50, IsNullable = true)]
public string payType { get; set; }
/// <summary>
/// weight
/// </summary>
[SugarColumn(IsNullable = true)]
public int? weight { get; set; }
/// <summary>
/// speed
/// </summary>
[SugarColumn(IsNullable = true)]
public int? speed { get; set; }
/// <summary>
/// neeGold
/// </summary>
[SugarColumn(IsNullable = true)]
public int? neeGold { get; set; }
/// <summary>
/// remark
/// </summary>
[SugarColumn(Length = 50, IsNullable = true)]
public string remark { get; set; }
}
}

View File

@@ -14,8 +14,10 @@ public static class GoodsEnum
Card,//附魔卡片
Mark,//圣痕
Pack,//宝箱
ChoicePack,//选择宝箱
Weight,//负重
Exp,//经验
State,//状态物品
Ship,//船只
}
}

View File

@@ -32,9 +32,10 @@ public interface IGameEquService
bool isAddAttr = false);
Task<List<unit_user_equ>> GetUserOnEqu(string userId);
Task<UserAttrModel> GetUserEquAttrModel(string userId);
Task<bool> EquOnOrDown(unit_user_equ data, int state);
Task<List<UserEquSuit>> GetUserEquSuit(string userId);
Task<List<AttrItem>> GetUserEquSuitAttrInfo(string userId);
#endregion
#region

View File

@@ -28,8 +28,4 @@ public interface IGameGoodsService
#endregion
#region
Task<game_ship> GetShipInfo(int shipId);
#endregion
}

View File

@@ -4,7 +4,7 @@ public interface IUnitUserAttrService
{
#region
Task<UserAttrModel> GetUserAttrModel(string userId);
Task<UserAttrModel> GetUserAttrModel(string userId, string scene = "Default");
Task<unit_user_attr> GetUserAttr(string userId);
Task<int> GetUserLev(string userId);
#endregion
@@ -51,5 +51,15 @@ public interface IUnitUserAttrService
Task<unit_user_drug> GetUserDrug(string userId);
Task<bool> UpdateUserDrug(unit_user_drug data);
#endregion
#region
Task<List<unit_user_state>> GetUserStateData(string userId, string scene = "Default");
Task<bool> AddUserState(string userId, string groupId, string name, string scene, string tips,
List<AttrItem> attr, int time, int count = 1);
#endregion
}

View File

@@ -19,7 +19,7 @@ public interface IUnitUserWeight
Task<bool> UpdateUserShipOnWeight(string userId, int op, int weight);
Task<bool> CheakUserShipWeight(string userId, int useWeight);
Task<bool> DeleteUserShip(string usId, string userId);
Task<bool> AddUserShip(string userId, string name, int goodsId, int speed, int weight);
Task<bool> AddUserShip(string userId, string name, int goodsId, int speed, int weight,int copper,long sale,string remark);
#endregion

View File

@@ -447,13 +447,50 @@ public class GameEquService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
}
}
public async Task<UserAttrModel> GetUserEquAttrModel(string userId)
{
var key = string.Format(UserCache.BaseCacheKeys, "EquData", "UserOnEquAttr");
if (await redis.HExistsHashAsync(key, userId))
{
return await redis.GetHashAsync<UserAttrModel>(key, userId);
}
long endTime = TimeExtend.GetTimeStampSeconds;
UserAttrModel result = new UserAttrModel();
var myEqu = await GetUserOnEqu(userId);
foreach (var equ in myEqu)
{
if (equ.durability > 0 || equ.useEndTime > endTime)
{
UserAttrModel equTemp = new UserAttrModel();
var equAttr = EquTool.GetUserEquByIntensify(equ);
equTemp.minAtk = (int)equAttr.minAtk;
equTemp.maxAtk = (int)equAttr.maxAtk;
equTemp.defense = (int)equAttr.Defense;
equTemp.agility = (int)equAttr.Agility;
equTemp.upBlood = (int)equAttr.Blood;
equTemp.upMorale = (int)equAttr.Morale;
List<AttrItem> equAttrData = EquTool.GetUserEquAttrData(equ);
equTemp = GameAttrTool.GetRoleAttrTempMerge(equTemp, equAttrData);
result = GameAttrTool.GetRoleAttrTempMerge(result, equTemp);
}
}
await redis.AddHashAsync(key, userId, result);
return result;
}
private async Task ClearUserOnEqu(string userId)
{
var key = string.Format(UserCache.BaseCacheKeys, "EquData", "UserOnEqu");
await redis.DelHashAsync(key, userId);
key = string.Format(UserCache.BaseCacheKeys, "EquData", "UserOnEquAttr");
await redis.DelHashAsync(key, userId);
//清理套装缓存
key = string.Format(UserCache.BaseCacheKeys, "EquData:UserEquSuit", userId);
await redis.DelAsync(key);
key = string.Format(UserCache.BaseCacheKeys, "EquData:UserEquSuitAttr", userId);
await redis.DelAsync(key);
}
public async Task<bool> EquOnOrDown(unit_user_equ data, int state)
@@ -544,6 +581,30 @@ public class GameEquService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
return result;
}
public async Task<List<AttrItem>> GetUserEquSuitAttrInfo(string userId)
{
List<AttrItem> result = new List<AttrItem>();
var key = string.Format(UserCache.BaseCacheKeys, "EquData:UserEquSuitAttr", userId);
if (await redis.ExistsAsync(key))
{
result = await redis.GetAsync<List<AttrItem>>(key);
}
else
{
var suitData = await GetUserEquSuit(userId);
foreach (var item in suitData)
{
foreach (var attr in item.SuitAttr)
{
result.AddRange(attr.AttrItem);
}
}
await redis.SetAsync(key, result, 300);
}
return result;
}
#endregion
#region
@@ -672,7 +733,7 @@ public class GameEquService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
foreach (var item in attrResult)
{
var onAttr = item as game_equ_attr;
AttrItem temp = new AttrItem();
temp.code = onAttr.code;
temp.compute = onAttr.compute;
@@ -708,7 +769,6 @@ public class GameEquService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
public async Task<unit_user_equ> GetUserEquAttr(unit_user_equ equ)
{
return equ;
}

View File

@@ -187,22 +187,6 @@ public class GameGoodsService(ISqlSugarClient DbClient, IRedisCache redis) : IGa
#endregion
#region
public async Task<game_ship> GetShipInfo(int shipId)
{
string key = string.Format(BaseCache.BaseCacheKey, "ShipData");
var data = await redis.GetHashAsync<game_ship>(key, shipId.ToString());
if (data == null)
{
var db = DbClient.AsTenant().GetConnectionWithAttr<game_ship>();
data = await db.Queryable<game_ship>().Where(it => it.shipId == shipId).SingleAsync();
await redis.AddHashAsync(key, shipId.ToString(), data);
}
return data;
}
#endregion
#region

View File

@@ -33,6 +33,7 @@ public class GameTeamService(ISqlSugarClient DbClient, IRedisCache redis) : IGam
await redis.AddHashAsync(key, userId, data);
return data;
}
public async Task<game_team> GetTeamInfo(string teamId)
{

View File

@@ -4,7 +4,7 @@ public class UnitUserAttrService(ISqlSugarClient DbClient, IRedisCache redis) :
{
#region
public async Task<UserAttrModel> GetUserAttrModel(string userId)
public async Task<UserAttrModel> GetUserAttrModel(string userId, string scene = "Default")
{
UserAttrModel result = new UserAttrModel();
result.id = userId;
@@ -24,11 +24,149 @@ public class UnitUserAttrService(ISqlSugarClient DbClient, IRedisCache redis) :
result.agility = (int)unitAttr.agility;
result.upBlood = (int)unitAttr.upBlood;
result.upMorale = (int)unitAttr.upMorale;
var bloodInfo = await GetUserBlood(userId);
result.blood = (int)bloodInfo.blood;
var moraleInfo = await GetUserMorale(userId);
result.morale = (int)moraleInfo.morale;
List<AttrItem> ExtendAttrData = new List<AttrItem>();
#region
UserAttrModel temp = new UserAttrModel();
temp.minAtk = (int)unitAttr.minAtk;
temp.maxAtk = (int)unitAttr.maxAtk;
temp.defense = (int)unitAttr.defense;
temp.agility = (int)unitAttr.agility;
temp.upBlood = (int)unitAttr.upBlood;
temp.upMorale = (int)unitAttr.upMorale;
var equService = App.GetService<IGameEquService>();
var equTemp = await equService.GetUserEquAttrModel(userId);
temp = GameAttrTool.GetRoleAttrTempMerge(temp, equTemp);
//套装加层
var suitAttr = await equService.GetUserEquSuitAttrInfo(userId);
ExtendAttrData.AddRange(suitAttr);
#endregion
#region
int minAtk = 0;
int maxAtk = 0;
int Agility = 0;
int Defense = 0;
int upBlood = 0;
int upMorale = 0;
#endregion
#region
var teamService = App.GetService<IGameTeamService>();
var MyTeam = await teamService.GetUserTeamInfo(userId);
if (MyTeam.state == 1)
{
int teamCount = MyTeam.user.Count(it => it.isOnline == 1);
if (teamCount > 0)
{
decimal teamAdd = 0.05m * teamCount;
teamAdd = teamAdd > 0.2m ? 0.2m : teamAdd;
minAtk += Convert.ToInt32(temp.minAtk * teamAdd);
maxAtk += Convert.ToInt32(temp.maxAtk * teamAdd);
Defense += Convert.ToInt32(temp.defense * teamAdd);
result.atkTips += $"(队+{Convert.ToInt32(teamAdd * 100)}%)";
result.defTips += $"(队+{Convert.ToInt32(teamAdd * 100)}%)";
}
}
#endregion
#region Buff加层
var MyState = await GetUserStateData(userId, scene);
if (MyState.Count > 0)
{
foreach (var item in MyState)
{
minAtk += Convert.ToInt32(GameAttrTool.GetAttrItemValue(GameEnum.AttrCode.Atk.ToString(), item.attr,
temp.minAtk));
maxAtk += Convert.ToInt32(GameAttrTool.GetAttrItemValue(GameEnum.AttrCode.Atk.ToString(), item.attr,
temp.maxAtk));
Defense += Convert.ToInt32(GameAttrTool.GetAttrItemValue(GameEnum.AttrCode.Defense.ToString(),
item.attr, temp.defense));
Agility += Convert.ToInt32(GameAttrTool.GetAttrItemValue(GameEnum.AttrCode.Agility.ToString(),
item.attr, temp.agility));
upBlood += Convert.ToInt32(GameAttrTool.GetAttrItemValue(GameEnum.AttrCode.Blood.ToString(), item.attr,
temp.upBlood));
upMorale += Convert.ToInt32(GameAttrTool.GetAttrItemValue(GameEnum.AttrCode.Morale.ToString(),
item.attr, temp.upMorale));
}
}
#endregion
#region
var otTemp = GameAttrTool.GetRoleAttrTemp(temp, ExtendAttrData);
result = GameAttrTool.GetRoleAttrTempMerge(result, otTemp); //加层其他
result = GameAttrTool.GetRoleAttrTempMerge(result, temp); //加层其他
result.minAtk += minAtk;
result.maxAtk += maxAtk;
result.defense += Defense;
result.agility += Agility;
result.upBlood += upBlood;
result.upMorale += upMorale;
#endregion
#region
var userBlood = await GetUserBlood(userId);
result.blood = (int)userBlood.blood;
//士气
var userMorale = await GetUserMorale(userId);
result.morale = (int)userMorale.morale;
//负面状态处理
//result = await GameAttrTool.CheakRoleLoadBuff(result);
result = await ReviseUserRoleAttr(result);
return result;
#endregion
return result;
}
private async Task<UserAttrModel> ReviseUserRoleAttr(UserAttrModel result)
{
//处理上限数据
if (result.blood > result.upBlood)
{
result.blood = result.upBlood;
await UpdateUserBlood(result.id, 2, result.blood, true);
}
if (result.morale > result.upMorale)
{
result.morale = result.upMorale;
await UpdateUserMorale(result.id, 2, Convert.ToInt32(result.morale));
}
if (result.NoHarm > 0.8M) //免伤上限
{
result.NoHarm = 0.8M;
}
if (result.Atk_Next > 0.3M) //连击上限
{
result.Atk_Next = 0.3M;
}
//评分
decimal _score = result.maxAtk + result.defense + result.agility + result.upBlood / 3.00M + result.upMorale;
result.score = Math.Round(_score, 2);
return result;
}
@@ -257,10 +395,11 @@ public class UnitUserAttrService(ISqlSugarClient DbClient, IRedisCache redis) :
string key = string.Format(UserCache.BaseCacheKeys, "Recover:Morale", userId);
return await redis.ExistsAsync(key);
}
public async Task LockRecoverMorale(string userId)
{
string key = string.Format(UserCache.BaseCacheKeys, "Recover:Morale", userId);
await redis.SetAsync(key, DateTime.Now,TimeAssist.GetDateTimeYMD(1));
await redis.SetAsync(key, DateTime.Now, TimeAssist.GetDateTimeYMD(1));
}
#endregion
@@ -334,7 +473,7 @@ public class UnitUserAttrService(ISqlSugarClient DbClient, IRedisCache redis) :
#endregion
#region 线
#region 线
public async Task<bool> UpdateOnLineTime(string userId, string code, int time)
{
@@ -347,10 +486,9 @@ public class UnitUserAttrService(ISqlSugarClient DbClient, IRedisCache redis) :
return result;
}
#endregion
#region
#region
public async Task<unit_user_drug> GetUserDrug(string userId)
{
@@ -359,6 +497,7 @@ public class UnitUserAttrService(ISqlSugarClient DbClient, IRedisCache redis) :
{
return await redis.GetHashAsync<unit_user_drug>(key, userId);
}
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_drug>();
var data = await db.Queryable<unit_user_drug>().Where(it => it.userId == userId).SingleAsync();
if (data == null)
@@ -379,7 +518,7 @@ public class UnitUserAttrService(ISqlSugarClient DbClient, IRedisCache redis) :
bool result = await db.Updateable<unit_user_drug>(data).ExecuteCommandAsync() > 0;
if (result)
{
await ClearUserDrug(data. userId);
await ClearUserDrug(data.userId);
}
return result;
@@ -392,4 +531,86 @@ public class UnitUserAttrService(ISqlSugarClient DbClient, IRedisCache redis) :
}
#endregion
#region
private async Task<List<unit_user_state>> GetUserStateData(string userId)
{
string key = string.Format(UserCache.BaseCacheKeys, "AttrData", "State");
var data = await redis.GetHashAsync<List<unit_user_state>>(key, userId);
if (data == null)
{
long endTime = TimeExtend.GetTimeStampSeconds;
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_state>();
data = await db.Queryable<unit_user_state>().Where(it => it.userId == userId && it.endTime > endTime)
.ToListAsync();
await redis.AddHashAsync(key, userId, data);
}
return data;
}
public async Task<List<unit_user_state>> GetUserStateData(string userId, string scene = "Default")
{
var data = await GetUserStateData(userId);
if (scene == "ALL")
{
return data;
}
data = data.FindAll(it => it.scene == "Default" || it.scene == scene);
return data;
}
public async Task<bool> AddUserState(string userId, string groupId, string name, string scene, string tips,
List<AttrItem> attr, int time, int count = 1)
{
bool result = false;
long onTime = TimeExtend.GetTimeStampSeconds;
string usId = $"{userId}_{groupId}";
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_state>();
var usData = await db.Queryable<unit_user_state>().Where(it => it.usId == usId).SingleAsync();
if (usData == null)
{
usData = new unit_user_state();
usData.usId = usId;
usData.userId = userId;
usData.goodsId = groupId;
usData.name = name;
usData.scene = scene;
usData.tips = tips;
usData.attr = attr;
usData.addTime = onTime;
usData.endTime = onTime + (time * 60 * count);
result = await db.Insertable(usData).ExecuteCommandAsync() > 0;
}
else
{
if (usData.endTime > onTime)
{
usData.endTime = usData.endTime + (time * 60 * count);
}
else
{
usData.addTime = onTime;
usData.endTime = onTime + (time * 60 * count);
}
result = await db.Updateable(usData).ExecuteCommandAsync() > 0;
}
if (result)
{
await ClearUserState(userId);
}
return result;
}
private async Task ClearUserState(string userId)
{
string key = string.Format(UserCache.BaseCacheKeys, "AttrData", "State");
await redis.DelHashAsync(key, userId);
}
#endregion
}

View File

@@ -204,7 +204,7 @@ public class UnitUserWeight(ISqlSugarClient DbClient, IRedisCache redis) : IUnit
return result;
}
public async Task<bool> AddUserShip(string userId, string name, int goodsId, int speed, int weight)
public async Task<bool> AddUserShip(string userId, string name, int goodsId, int speed, int weight,int copper,long sale,string remark)
{
unit_user_ship ship = new unit_user_ship();
ship.usId = StringAssist.NewGuid;
@@ -213,6 +213,9 @@ public class UnitUserWeight(ISqlSugarClient DbClient, IRedisCache redis) : IUnit
ship.name = name;
ship.speed = speed;
ship.weight = weight;
ship.copper = copper;
ship.sale = sale;
ship.remark = remark;
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_ship>();
bool result = await db.Insertable(ship).ExecuteCommandAsync() > 0;
if (result)

View File

@@ -7,19 +7,19 @@ public class EquTool
//强化
equ = GetIntensifyAttr(equ);
List<AttrItem> AttrData = GetUserEquAttrData(equ);
equ.minAtk += Convert.ToInt32(GetAttrItemValue(nameof(GameEnum.AttrCode.Atk), AttrData, (decimal)equ.minAtk));
equ.minAtk += Convert.ToInt32(GameAttrTool.GetAttrItemValue(nameof(GameEnum.AttrCode.Atk), AttrData, (decimal)equ.minAtk));
equ.minAtk +=
Convert.ToInt32(GetAttrItemValue(nameof(GameEnum.AttrCode.MinAtk), AttrData, (decimal)equ.minAtk));
equ.maxAtk += Convert.ToInt32(GetAttrItemValue(nameof(GameEnum.AttrCode.Atk), AttrData, (decimal)equ.maxAtk));
Convert.ToInt32(GameAttrTool.GetAttrItemValue(nameof(GameEnum.AttrCode.MinAtk), AttrData, (decimal)equ.minAtk));
equ.maxAtk += Convert.ToInt32(GameAttrTool.GetAttrItemValue(nameof(GameEnum.AttrCode.Atk), AttrData, (decimal)equ.maxAtk));
equ.maxAtk +=
Convert.ToInt32(GetAttrItemValue(nameof(GameEnum.AttrCode.MaxAtk), AttrData, (decimal)equ.minAtk));
equ.Blood += Convert.ToInt32(GetAttrItemValue(nameof(GameEnum.AttrCode.Blood), AttrData, (decimal)equ.Blood));
Convert.ToInt32(GameAttrTool.GetAttrItemValue(nameof(GameEnum.AttrCode.MaxAtk), AttrData, (decimal)equ.minAtk));
equ.Blood += Convert.ToInt32(GameAttrTool.GetAttrItemValue(nameof(GameEnum.AttrCode.Blood), AttrData, (decimal)equ.Blood));
equ.Defense +=
Convert.ToInt32(GetAttrItemValue(nameof(GameEnum.AttrCode.Defense), AttrData, (decimal)equ.Defense));
Convert.ToInt32(GameAttrTool.GetAttrItemValue(nameof(GameEnum.AttrCode.Defense), AttrData, (decimal)equ.Defense));
equ.Agility +=
Convert.ToInt32(GetAttrItemValue(nameof(GameEnum.AttrCode.Agility), AttrData, (decimal)equ.Agility));
Convert.ToInt32(GameAttrTool.GetAttrItemValue(nameof(GameEnum.AttrCode.Agility), AttrData, (decimal)equ.Agility));
equ.Morale +=
Convert.ToInt32(GetAttrItemValue(nameof(GameEnum.AttrCode.Morale), AttrData, (decimal)equ.Morale));
Convert.ToInt32(GameAttrTool.GetAttrItemValue(nameof(GameEnum.AttrCode.Morale), AttrData, (decimal)equ.Morale));
return equ;
}
@@ -123,7 +123,7 @@ public class EquTool
return Convert.ToInt32(result + onAttr);
}
private static List<AttrItem> GetUserEquAttrData(unit_user_equ equ)
public static List<AttrItem> GetUserEquAttrData(unit_user_equ equ)
{
List<AttrItem> AttrData = new List<AttrItem>();
//装备本身特性
@@ -162,37 +162,5 @@ public class EquTool
return AttrData;
}
public static decimal GetAttrItemValue(string attrCode, List<AttrItem> AttrData, decimal unit)
{
decimal result = 0.00M;
foreach (var item in AttrData)
{
if (attrCode == item.code)
{
if (string.IsNullOrEmpty(item.compute))
{
continue;
}
if (item.compute == nameof(GameEnum.ComputeType.Ride))
{
result += unit * Convert.ToDecimal(item.parameter);
}
else if (item.compute == nameof(GameEnum.ComputeType.Plus))
{
result += Convert.ToDecimal(item.parameter);
}
else if (item.compute == nameof(GameEnum.ComputeType.Reduce))
{
result = unit - Convert.ToDecimal(item.parameter);
}
else if (item.compute == nameof(GameEnum.ComputeType.Except))
{
result = unit / Convert.ToDecimal(item.parameter);
}
}
}
return result;
}
}

View File

@@ -0,0 +1,170 @@
namespace Application.Domain;
public class GameAttrTool
{
public static UserAttrModel GetRoleAttrTemp(UserAttrModel temp, List<AttrItem> attrData)
{
UserAttrModel result = new UserAttrModel();
result.minAtk =
Convert.ToInt32(GetAttrItemValue(GameEnum.AttrCode.Atk.ToString(), attrData, temp.minAtk));
result.maxAtk =
Convert.ToInt32(GetAttrItemValue(GameEnum.AttrCode.Atk.ToString(), attrData, temp.maxAtk));
result.defense =
Convert.ToInt32(GetAttrItemValue(GameEnum.AttrCode.Defense.ToString(), attrData, temp.defense));
result.agility =
Convert.ToInt32(GetAttrItemValue(GameEnum.AttrCode.Agility.ToString(), attrData, temp.agility));
result.upBlood =
Convert.ToInt32(GetAttrItemValue(GameEnum.AttrCode.Blood.ToString(), attrData, temp.upBlood));
result.upMorale =
Convert.ToInt32(GetAttrItemValue(GameEnum.AttrCode.Morale.ToString(), attrData, temp.upMorale));
result.InBlood = GetAttrItemValue(GameEnum.AttrCode.InBlood.ToString(), attrData, temp.InBlood);
result.Crit = GetAttrItemValue(GameEnum.AttrCode.Crit.ToString(), attrData, temp.Crit);
result.NoHarm = GetAttrItemValue(GameEnum.AttrCode.NoHarm.ToString(), attrData, temp.NoHarm);
result.Dodge = GetAttrItemValue(GameEnum.AttrCode.Dodge.ToString(), attrData, temp.Dodge);
result.Rebound = GetAttrItemValue(GameEnum.AttrCode.Rebound.ToString(), attrData, temp.Rebound);
result.ReboundLess =
GetAttrItemValue(GameEnum.AttrCode.ReboundLess.ToString(), attrData, temp.ReboundLess);
result.Punish = GetAttrItemValue(GameEnum.AttrCode.Punish.ToString(), attrData, temp.Punish);
result.Slow = GetAttrItemValue(GameEnum.AttrCode.Slow.ToString(), attrData, temp.Slow);
result.SlowLess = GetAttrItemValue(GameEnum.AttrCode.SlowLess.ToString(), attrData, temp.SlowLess);
result.Poison = GetAttrItemValue(GameEnum.AttrCode.Poison.ToString(), attrData, temp.Poison);
result.PoisonLess =
GetAttrItemValue(GameEnum.AttrCode.PoisonLess.ToString(), attrData, temp.PoisonLess);
result.Curse = GetAttrItemValue(GameEnum.AttrCode.Curse.ToString(), attrData, temp.Curse);
result.CurseLess = GetAttrItemValue(GameEnum.AttrCode.CurseLess.ToString(), attrData, temp.CurseLess);
result.Weaken = GetAttrItemValue(GameEnum.AttrCode.Weaken.ToString(), attrData, temp.Weaken);
result.WeakenLess =
GetAttrItemValue(GameEnum.AttrCode.WeakenLess.ToString(), attrData, temp.WeakenLess);
result.Deadly = GetAttrItemValue(GameEnum.AttrCode.Deadly.ToString(), attrData, temp.Deadly);
result.DeadlyLess =
GetAttrItemValue(GameEnum.AttrCode.DeadlyLess.ToString(), attrData, temp.DeadlyLess);
result.Depressed = GetAttrItemValue(GameEnum.AttrCode.Depressed.ToString(), attrData, temp.Depressed);
result.DepressedLess =
GetAttrItemValue(GameEnum.AttrCode.DepressedLess.ToString(), attrData, temp.DepressedLess);
result.Breach = GetAttrItemValue(GameEnum.AttrCode.Breach.ToString(), attrData, temp.Breach);
result.BreachLess =
GetAttrItemValue(GameEnum.AttrCode.BreachLess.ToString(), attrData, temp.BreachLess);
result.Del_Fashion =
GetAttrItemValue(GameEnum.AttrCode.Del_Fashion.ToString(), attrData, temp.Del_Fashion);
result.Atk_Next = GetAttrItemValue(GameEnum.AttrCode.Atk_Next.ToString(), attrData, temp.Atk_Next);
result.Harm_Add = GetAttrItemValue(GameEnum.AttrCode.Harm_Add.ToString(), attrData, temp.Harm_Add);
result.PalsyAtk = GetAttrItemValue(GameEnum.AttrCode.PalsyAtk.ToString(), attrData, temp.PalsyAtk);
result.PalsyAtkLess =
GetAttrItemValue(GameEnum.AttrCode.PalsyAtkLess.ToString(), attrData, temp.PalsyAtk);
return result;
}
public static UserAttrModel GetRoleAttrTempMerge(UserAttrModel result, List<AttrItem> attrData)
{
result.minAtk +=
Convert.ToInt32(GetAttrItemValue(GameEnum.AttrCode.Atk.ToString(), attrData, result.minAtk));
result.maxAtk +=
Convert.ToInt32(GetAttrItemValue(GameEnum.AttrCode.Atk.ToString(), attrData, result.maxAtk));
result.defense +=
Convert.ToInt32(GetAttrItemValue(GameEnum.AttrCode.Defense.ToString(), attrData, result.defense));
result.agility +=
Convert.ToInt32(GetAttrItemValue(GameEnum.AttrCode.Agility.ToString(), attrData, result.agility));
result.upBlood +=
Convert.ToInt32(GetAttrItemValue(GameEnum.AttrCode.Blood.ToString(), attrData, result.upBlood));
result.upMorale +=
Convert.ToInt32(GetAttrItemValue(GameEnum.AttrCode.Morale.ToString(), attrData, result.upMorale));
result.InBlood += GetAttrItemValue(GameEnum.AttrCode.InBlood.ToString(), attrData, 0);
result.Crit += GetAttrItemValue(GameEnum.AttrCode.Crit.ToString(), attrData, 0);
result.NoHarm += GetAttrItemValue(GameEnum.AttrCode.NoHarm.ToString(), attrData, 0);
result.Dodge += GetAttrItemValue(GameEnum.AttrCode.Dodge.ToString(), attrData, 0);
result.Rebound += GetAttrItemValue(GameEnum.AttrCode.Rebound.ToString(), attrData, 0);
result.ReboundLess += GetAttrItemValue(GameEnum.AttrCode.ReboundLess.ToString(), attrData, 0);
result.Punish += GetAttrItemValue(GameEnum.AttrCode.Punish.ToString(), attrData, 0);
result.Slow += GetAttrItemValue(GameEnum.AttrCode.Slow.ToString(), attrData, 0);
result.SlowLess += GetAttrItemValue(GameEnum.AttrCode.SlowLess.ToString(), attrData, 0);
result.Poison += GetAttrItemValue(GameEnum.AttrCode.Poison.ToString(), attrData, 0);
result.PoisonLess += GetAttrItemValue(GameEnum.AttrCode.PoisonLess.ToString(), attrData, 0);
result.Curse += GetAttrItemValue(GameEnum.AttrCode.Curse.ToString(), attrData, 0);
result.CurseLess += GetAttrItemValue(GameEnum.AttrCode.CurseLess.ToString(), attrData, 0);
result.Weaken += GetAttrItemValue(GameEnum.AttrCode.Weaken.ToString(), attrData, 0);
result.WeakenLess += GetAttrItemValue(GameEnum.AttrCode.WeakenLess.ToString(), attrData, 0);
result.Deadly += GetAttrItemValue(GameEnum.AttrCode.Deadly.ToString(), attrData, 0);
result.DeadlyLess += GetAttrItemValue(GameEnum.AttrCode.DeadlyLess.ToString(), attrData, 0);
result.Depressed += GetAttrItemValue(GameEnum.AttrCode.Depressed.ToString(), attrData, 0);
result.DepressedLess += GetAttrItemValue(GameEnum.AttrCode.DepressedLess.ToString(), attrData, 0);
result.Breach += GetAttrItemValue(GameEnum.AttrCode.Breach.ToString(), attrData, 0);
result.BreachLess += GetAttrItemValue(GameEnum.AttrCode.BreachLess.ToString(), attrData, 0);
result.Del_Fashion += GetAttrItemValue(GameEnum.AttrCode.Del_Fashion.ToString(), attrData, 0);
result.Atk_Next += GetAttrItemValue(GameEnum.AttrCode.Atk_Next.ToString(), attrData, 0);
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);
return result;
}
public static UserAttrModel GetRoleAttrTempMerge(UserAttrModel main, UserAttrModel vice)
{
main.minAtk += vice.minAtk;
main.maxAtk += vice.maxAtk;
main.defense += vice.defense;
main.agility += vice.agility;
main.upBlood += vice.upBlood;
main.upMorale += vice.upMorale;
main.InBlood += vice.InBlood;
main.Crit += vice.Crit;
main.NoHarm += vice.NoHarm;
main.Dodge += vice.Dodge;
main.Rebound += vice.Rebound;
main.ReboundLess += vice.ReboundLess;
main.Punish += vice.Punish;
main.Slow += vice.Slow;
main.Poison += vice.Poison;
main.PoisonLess += vice.PoisonLess;
main.Curse += vice.Curse;
main.CurseLess += vice.CurseLess;
main.Weaken += vice.Weaken;
main.WeakenLess += vice.WeakenLess;
main.Deadly += vice.Deadly;
main.DeadlyLess += vice.DeadlyLess;
main.Depressed += vice.Depressed;
main.DepressedLess += vice.DepressedLess;
main.Breach += vice.Breach;
main.BreachLess += vice.BreachLess;
main.Del_Fashion += vice.Del_Fashion;
main.Atk_Next += vice.Atk_Next;
main.Harm_Add += vice.Harm_Add;
main.PalsyAtk += vice.PalsyAtk;
main.PalsyAtkLess += vice.PalsyAtkLess;
return main;
}
public static decimal GetAttrItemValue(string attrCode, List<AttrItem> AttrData, decimal unit)
{
decimal result = 0.00M;
foreach (var item in AttrData)
{
if (attrCode == item.code)
{
if (string.IsNullOrEmpty(item.compute))
{
continue;
}
if (item.compute == nameof(GameEnum.ComputeType.Ride))
{
result += unit * Convert.ToDecimal(item.parameter);
}
else if (item.compute == nameof(GameEnum.ComputeType.Plus))
{
result += Convert.ToDecimal(item.parameter);
}
else if (item.compute == nameof(GameEnum.ComputeType.Reduce))
{
result = unit - Convert.ToDecimal(item.parameter);
}
else if (item.compute == nameof(GameEnum.ComputeType.Except))
{
result = unit / Convert.ToDecimal(item.parameter);
}
}
}
return result;
}
}

View File

@@ -280,6 +280,34 @@ namespace Application.Web.Controllers.Login
return PoAction.Ok(new
{ token = token, refToken = userInfo.token, userId = userInfo.userId });
}
[HttpPost]
public async Task<IPoAction> RefreshTokenByBook([FromBody] RefreshTokenParms parms)
{
if (string.IsNullOrEmpty(parms.refToken))
{
return PoAction.Message("刷新失败");
}
string Key = App.Configuration["JwtTokenOptions:SecurityKey"].ToString();
string Issuer = App.Configuration["JwtTokenOptions:Issuer"].ToString();
string Audience = App.Configuration["JwtTokenOptions:Audience"].ToString();
var userInfo = await _userService.GetUserInfoByToken(parms.refToken);
if (userInfo == null)
{
return PoAction.Message("刷新失败,用户不存在!");
}
Dictionary<string, object> loadData = new Dictionary<string, object>();
loadData.Add("userId", userInfo.userId);
loadData.Add("accId", userInfo.accId);
loadData.Add("areaId", userInfo.areaId);
string token = JwtHelper.CreateToken(Key, Issuer, Audience, loadData, TokenConfig.TokenTime);
return PoAction.Ok(new
{ token = token, refToken = userInfo.token, userId = userInfo.userId });
}
/// <summary>
/// 注册角色信息

View File

@@ -50,6 +50,15 @@ public class GoodsController : ControllerBase
case "Weight":
UseState = 1;
break;
case "State":
UseState = 1;
break;
case "Ship":
UseState = 2;
break;
case "ChoicePack":
UseState = 3;
break;
}
@@ -85,6 +94,19 @@ public class GoodsController : ControllerBase
return PoAction.Message($"该物品{goodsInfo.lev}级才可使用!");
}
#region
if (goodsInfo.code == nameof(GoodsEnum.Code.Ship))
{
var myShip = await _weightService.GetUserShip(userId);
if (myShip.Count >= 5)
{
return PoAction.Message($"每人最多拥有5个船只,您已达到上限!");
}
}
#endregion
if (await _goodsService.UpdateUserGoods(userId, 0, goodsId, count, "使用物品"))
{
string message = "";
@@ -119,6 +141,23 @@ public class GoodsController : ControllerBase
}
else if (goodsInfo.code == nameof(GoodsEnum.Code.State))
{
UserStateModel stateConfig = JsonConvert.DeserializeObject<UserStateModel>(goodsInfo.content);
await _attrService.AddUserState(userId, goodsInfo.goodsId.ToString(), stateConfig.name,
stateConfig.scene, stateConfig.tips, stateConfig.attr, stateConfig.time, count);
message = $"使用[{goodsInfo.goodsName}]×{count},状态时间+{stateConfig.time * count}分钟";
}
else if (goodsInfo.code == nameof(GoodsEnum.Code.Ship))
{
dynamic shipInfo = JsonConvert.DeserializeObject<dynamic>(goodsInfo.content);
string name = shipInfo.name;
int speed = shipInfo.speed;
int weight = shipInfo.weight;
int copper = shipInfo.copper;
long sale = shipInfo.sale;
string remark = shipInfo.remark;
await _weightService.AddUserShip(userId, name, goodsId, speed, weight, copper, sale, remark);
message = $"使用[{goodsInfo.goodsName}],获得{name}+1";
}
return PoAction.Ok(true, message);
@@ -128,4 +167,69 @@ public class GoodsController : ControllerBase
return PoAction.Message("使用失败,请稍后尝试!");
}
}
/// <summary>
/// 使用选择物品礼包
/// </summary>
/// <param name="goodsId"></param>
/// <param name="count"></param>
/// <returns></returns>
[HttpGet]
public async Task<IPoAction> UseChoiceGoods(int goodsId, int num)
{
string userId = StateHelper.userId;
var goodsInfo = await _goodsService.GetGoodsInfo(goodsId);
if (goodsInfo == null)
{
return PoAction.Message("物品不存在!");
}
var MyGoods = await _goodsService.GetUserGoodsCount(userId, goodsId);
if (MyGoods < 1)
{
return PoAction.Message("物品不足!");
}
var myLev = await _attrService.GetUserLev(userId);
if (myLev < (int)goodsInfo.lev)
{
return PoAction.Message($"该物品{goodsInfo.lev}级才可使用!");
}
if (goodsInfo.code != nameof(GoodsEnum.Code.ChoicePack))
{
return PoAction.Message("无法使用该物品!");
}
List<ChoiceGoods> choiceGoods = JsonConvert.DeserializeObject<List<ChoiceGoods>>(goodsInfo.content);
var onAward = choiceGoods.Find(it => it.id == num);
if (onAward == null)
{
return PoAction.Message("物品中不包含该选择!");
}
if (await _goodsService.UpdateUserGoods(userId, 0, goodsId, 1, "使用物品"))
{
if (await GameBus.UpdateBag(userId, 1, onAward.award, "打开礼包获取"))
{
string message = $"打开[{goodsInfo.goodsName}],获得:";
foreach (var item in onAward.award)
{
message += $"{item.name}+{item.count},";
}
message = message.TrimEnd(',');
await _messageService.SendBroadcast(userId, nameof(MessageEnum.BroadcastCode.Award), message);
return PoAction.Ok(true, message);
}
else
{
return PoAction.Message("使用失败,请稍后尝试!");
}
}
else
{
return PoAction.Message("使用失败,请稍后尝试!");
}
}
}

View File

@@ -10,14 +10,14 @@ namespace Application.Web.Controllers.Pub
[Authorize]
public class ShipController : ControllerBase
{
private readonly IUnitUserWeight weightService;
private readonly IGameGoodsService goodsService;
private readonly IUnitUserAccService accService;
public ShipController(IUnitUserWeight _weightService, IGameGoodsService _goodsService, IUnitUserAccService _accService)
private readonly IUnitUserWeight _weightService;
private readonly IUnitUserAccService _accService;
public ShipController(IUnitUserWeight weightService,
IUnitUserAccService accService)
{
accService = _accService;
goodsService = _goodsService;
weightService = _weightService;
_accService = accService;
_weightService = weightService;
}
/// <summary>
@@ -28,27 +28,11 @@ namespace Application.Web.Controllers.Pub
public async Task<IPoAction> GetUserShip()
{
string userId = StateHelper.userId;
var data = await weightService.GetUserShip(userId);
var data = await _weightService.GetUserShip(userId);
//个人负重
var weightInfo = await weightService.GetUserWeightInfo(userId);
return PoAction.Ok(new { data, weightInfo });
}
/// <summary>
/// 获取船只详情
/// </summary>
/// <param name="shipId"></param>
/// <returns></returns>
[HttpGet]
public async Task<IPoAction> GetShipInfo(int shipId)
{
var data = await goodsService.GetShipInfo(shipId);
if (data == null)
{
return PoAction.Message("船只详情不存在!");
}
return PoAction.Ok(new { data });
var weightInfo = await _weightService.GetUserWeightInfo(userId);
var maxShipWeight = await _weightService.GetUserShipMaxWeight(userId);
return PoAction.Ok(new { data, onShip = weightInfo.shipOnWeight, maxShip = maxShipWeight });
}
/// <summary>
@@ -57,46 +41,25 @@ namespace Application.Web.Controllers.Pub
/// <param name="usId"></param>
/// <returns></returns>
[HttpPost]
public async Task<IPoAction> BuyShip([FromBody] BuyShipParms parms)
public async Task<IPoAction> SaleShip([FromBody] BuyShipParms parms)
{
var userShip = await weightService.GetUserShipInfo(parms.usId);
var userShip = await _weightService.GetUserShipInfo(parms.usId);
if (userShip == null)
{
return PoAction.Message("船只不存在!");
}
string userId = StateHelper.userId;
if (userShip.userId != userId)
{
return PoAction.Message("船只不存在!");
}
var shipInfo = await goodsService.GetShipInfo((int)userShip.goodsId);
if (shipInfo == null)
if (await _weightService.DeleteUserShip(userShip.usId, userId))
{
return PoAction.Message("船只信息不存在!");
}
if (await weightService.DeleteUserShip(userShip.usId, userId))
{
if (shipInfo.payType == AccEnum.AccType.copper.ToString())
if (await _accService.UpdateUserCopper(userId, 1, Convert.ToInt64(userShip.sale), "出售船只获得!"))
{
if (await accService.UpdateUserCopper(userId, 1, Convert.ToInt64(shipInfo.salePrice), "出售船只获得!"))
{
return PoAction.Ok(new { price = shipInfo.salePrice });
}
else
{
return PoAction.Message("出售失败!");
}
}
else if (shipInfo.payType == AccEnum.AccType.gold.ToString())
{
if (await accService.UpdateUserAcc(userId, 1, AccEnum.AccType.gold.ToString(), Convert.ToInt64(shipInfo.salePrice)))
{
return PoAction.Ok(new { price = shipInfo.salePrice });
}
else
{
return PoAction.Message("出售失败!");
}
return PoAction.Ok(new { price = userShip.sale });
}
else
{
@@ -109,4 +72,4 @@ namespace Application.Web.Controllers.Pub
}
}
}
}
}

View File

@@ -100,6 +100,7 @@ public class BagController : ControllerBase
break;
case 4:
code.Add(nameof(GoodsEnum.Code.Pack));
code.Add(nameof(GoodsEnum.Code.ChoicePack));
break;
case 5:
code.Add(nameof(GoodsEnum.Code.Mak));

View File

@@ -17,11 +17,12 @@ public class UserController : ControllerBase
private readonly IGameChatService _chatService;
private readonly IGameSkillService _skillService;
private readonly IGameTeamService _teamService;
private readonly IGameEquService _equService;
public UserController(IUnitUserService userService, IUnitUserAttrService attrService,
IUnitUserAccService accService, IGameMapService mapService, IUnitUserRelationService relationService,
IGameGoodsService goodsService, IGameChatService chatService, IGameSkillService skillService,
IGameTeamService teamService)
IGameTeamService teamService, IGameEquService equService)
{
_userService = userService;
_attrService = attrService;
@@ -32,6 +33,7 @@ public class UserController : ControllerBase
_chatService = chatService;
_skillService = skillService;
_teamService = teamService;
_equService = equService;
}
@@ -52,7 +54,10 @@ public class UserController : ControllerBase
var vigourInfo = await _attrService.GetUserVigourInfo(userId);
var accInfo = await _accService.GetUserAccInfo(userId);
object acc = new { accInfo.gold, accInfo.cowry, accInfo.teach, accInfo.renown };
object result = new { user, attr = attrInfo, exp, vigourInfo.vitality, acc };
var buff = await _attrService.GetUserStateData(userId,"ALL");
object result = new { user, attr = attrInfo, exp, vigourInfo.vitality, acc,buff };
return PoAction.Ok(result);
}
@@ -165,7 +170,13 @@ public class UserController : ControllerBase
bool isFriend = await _relationService.CheckIsFriend(userId, userInfo.userId);
bool isEnemy = await _relationService.CheckUserEnemy(userId, userInfo.userId);
var team = await _teamService.GetUserTeamInfo(userInfo.userId);
object result = new { user, attr = new { attrInfo.lev }, acc, isOnline, onMapName, isFriend, isEnemy, team };
var equ = await _equService.GetUserOnEqu(userInfo.userId);
var suit = await _equService.GetUserEquSuit(userInfo.userId);
object result = new
{
user, attr = new { attrInfo.lev }, acc, isOnline, onMapName, isFriend, isEnemy, team, equ,suit
};
return PoAction.Ok(result);
}
@@ -408,7 +419,7 @@ public class UserController : ControllerBase
}
else
{
return PoAction.Message("添加失败,请稍后尝试!");
return PoAction.Message("添加失败,请稍后尝试!");
}
}
else

View File

@@ -13,5 +13,4 @@ global using Microsoft.AspNetCore.Authorization;
global using Microsoft.AspNetCore.Mvc;
global using Application.Web;