Improve: Better code format

This commit is contained in:
WatchAndyTW
2024-05-22 19:26:21 +08:00
parent 487ad7c8b7
commit ffa8344316
10 changed files with 29 additions and 29 deletions

View File

@@ -67,7 +67,7 @@ namespace EggLink.DanhengServer.Game.Battle
return list;
}
public void AddBattleTarget(int key, int targetId, int progress, int totalProgress)
public void AddBattleTarget(int key, int targetId, int progress, int totalProgress = 0)
{
if (!BattleTargets.ContainsKey(key))
{

View File

@@ -161,6 +161,7 @@ namespace EggLink.DanhengServer.Game.Battle
// call battle start
Player.RogueManager!.GetRogueInstance()?.OnBattleStart(battleInstance);
Player.ChallengeManager!.ChallengeInstance?.OnBattleStart(battleInstance);
Player.BattleInstance = battleInstance;
Player.SendPacket(new PacketSceneCastSkillScRsp(req.CastEntityId, battleInstance));
@@ -206,6 +207,7 @@ namespace EggLink.DanhengServer.Game.Battle
// call battle start
Player.RogueManager!.GetRogueInstance()?.OnBattleStart(battleInstance);
Player.ChallengeManager!.ChallengeInstance?.OnBattleStart(battleInstance);
Player.BattleInstance = battleInstance;

View File

@@ -17,8 +17,8 @@ namespace EggLink.DanhengServer.Game.Challenge
if (Scene.IsLoaded) return;
// Get challenge instance
if (Player.ChallengeInstance == null) return;
ChallengeInstance instance = Player.ChallengeInstance;
if (Player.ChallengeManager!.ChallengeInstance == null) return;
ChallengeInstance instance = Player.ChallengeManager.ChallengeInstance;
// Setup first stage
var excel = instance.Excel;
@@ -52,12 +52,10 @@ namespace EggLink.DanhengServer.Game.Challenge
{
return null;
}
Console.WriteLine(0);
// Get challenge instance
if (Player.ChallengeInstance == null) return null;
ChallengeInstance instance = Player.ChallengeInstance;
Console.WriteLine(1);
if (Player.ChallengeManager!.ChallengeInstance == null) return null;
ChallengeInstance instance = Player.ChallengeManager.ChallengeInstance;
// Get current stage monster infos
Dictionary<int, ChallengeConfigExcel.ChallengeMonsterInfo> challengeMonsters;
@@ -73,17 +71,14 @@ namespace EggLink.DanhengServer.Game.Challenge
{
return null;
}
Console.WriteLine(2);
// Get challenge monster info
if (!challengeMonsters.ContainsKey(info.ID)) return null;
var challengeMonsterInfo = challengeMonsters[info.ID];
Console.WriteLine(3);
// Get excels from game data
if (!GameData.NpcMonsterDataData.ContainsKey(challengeMonsterInfo.NpcMonsterId)) return null;
NPCMonsterDataExcel npcMonsterExcel = GameData.NpcMonsterDataData[challengeMonsterInfo.NpcMonsterId];
Console.WriteLine(4);
// Create monster from group monster info
EntityMonster entity = new EntityMonster(scene, info.ToPositionProto(), info.ToRotationProto(), group.Id, info.ID, npcMonsterExcel, info);

View File

@@ -128,19 +128,21 @@ namespace EggLink.DanhengServer.Game.Challenge
{
battle.Buffs.Add(new MazeBuff(Excel.MazeBuffID, -1, -1));
if (StoryBuffs.Contains(CurrentStage - 1))
if (StoryBuffs.Count >= CurrentStage)
{
battle.Buffs.Add(new MazeBuff((CurrentStage - 1), -1, -1));
int buffId = CurrentStage - 1;
battle.Buffs.Add(new MazeBuff(buffId, -1, -1));
}
}
if (Excel.StoryExcel != null)
{
battle.AddBattleTarget(1, 10001, GetTotalScore(), 0);
battle.AddBattleTarget(1, 10001, GetTotalScore());
foreach (var id in Excel.StoryExcel.BattleTargetID!)
{
battle.AddBattleTarget(5, id, GetTotalScore(), 0);
Console.WriteLine(id);
battle.AddBattleTarget(5, id, GetTotalScore());
}
}
}
@@ -150,7 +152,7 @@ namespace EggLink.DanhengServer.Game.Challenge
// End challenge if its done
if (Status != (int)ChallengeStatus.ChallengeDoing)
{
Player.ChallengeInstance = null;
Player.ChallengeManager!.ChallengeInstance = null;
}
}

View File

@@ -10,8 +10,13 @@ namespace EggLink.DanhengServer.Game.Challenge
{
public class ChallengeManager(PlayerInstance player) : BasePlayerManager(player)
{
#region Properties
public ChallengeInstance? ChallengeInstance { get; set; }
public ChallengeData ChallengeData { get; private set; } = DatabaseHelper.Instance!.GetInstanceOrCreateNew<ChallengeData>(player.Uid);
#endregion
#region Management
public void StartChallenge(int challengeId, HDLDGEPFMGL? /*StartChallengeStoryBuffInfo*/ storyBuffs)
@@ -73,7 +78,7 @@ namespace EggLink.DanhengServer.Game.Challenge
// Set challenge data for player
ChallengeInstance instance = new ChallengeInstance(Player, Excel);
Player.ChallengeInstance = instance;
this.ChallengeInstance = instance;
// Set first lineup before we enter scenes
Player.LineupManager!.SetCurLineup(instance.CurrentExtraLineup);
@@ -86,7 +91,7 @@ namespace EggLink.DanhengServer.Game.Challenge
catch
{
// Reset lineup/instance if entering scene failed
Player.ChallengeInstance = null;
this.ChallengeInstance = null;
// Send error packet
Player.SendPacket(new PacketStartChallengeScRsp(2801));
@@ -133,14 +138,11 @@ namespace EggLink.DanhengServer.Game.Challenge
ChallengeData.Instance.ScoreStage2 = instance.ScoreStage2;
ChallengeData.Instance.StoryBuffs = instance.StoryBuffs;
ChallengeData.Instance.BossBuffs = instance.BossBuffs;
DatabaseHelper.Instance?.UpdateInstance(ChallengeData);
}
public void ClearInstance()
{
ChallengeData.Instance.ChallengeId = 0;
DatabaseHelper.Instance?.UpdateInstance(ChallengeData);
}
public void ResurrectInstance()
@@ -152,7 +154,7 @@ namespace EggLink.DanhengServer.Game.Challenge
{
ChallengeConfigExcel Excel = GameData.ChallengeConfigData[ChallengeId];
ChallengeInstance instance = new ChallengeInstance(Player, Excel, ChallengeData.Instance);
Player.ChallengeInstance = instance;
this.ChallengeInstance = instance;
}
}
}

View File

@@ -63,7 +63,6 @@ namespace EggLink.DanhengServer.Game.Player
public TutorialData? TutorialData { get; private set; }
public TutorialGuideData? TutorialGuideData { get; private set; }
public SceneInstance? SceneInstance { get; private set; }
public ChallengeInstance? ChallengeInstance { get; set; }
public ushort Uid { get; set; }
public Connection? Connection { get; set; }
public bool Initialized { get; set; } = false;

View File

@@ -14,9 +14,9 @@ namespace EggLink.DanhengServer.Server.Packet.Recv.Battle
connection.SendPacket(new PacketGetCurChallengeScRsp(connection.Player!));
// Update data
if (connection.Player!.ChallengeInstance != null)
if (connection.Player!.ChallengeManager.ChallengeInstance != null)
{
connection.Player.ChallengeInstance.OnUpdate();
connection.Player.ChallengeManager.ChallengeInstance.OnUpdate();
}
}
}

View File

@@ -19,7 +19,7 @@ namespace EggLink.DanhengServer.Server.Packet.Recv.Challenge
player.LineupManager!.SetExtraLineup(ExtraLineupType.LineupChallenge, []);
player.LineupManager.SetExtraLineup(ExtraLineupType.LineupChallenge2, []);
player.ChallengeInstance = null;
player.ChallengeManager!.ChallengeInstance = null;
player.ChallengeManager!.ClearInstance();
// Leave scene

View File

@@ -10,9 +10,9 @@ namespace EggLink.DanhengServer.Server.Packet.Send.Battle
{
var proto = new GetCurChallengeScRsp() { };
if (player.ChallengeInstance != null)
if (player.ChallengeManager!.ChallengeInstance != null)
{
proto.CurChallenge = player.ChallengeInstance.ToProto();
proto.CurChallenge = player.ChallengeManager.ChallengeInstance.ToProto();
}
else
{

View File

@@ -19,9 +19,9 @@ namespace EggLink.DanhengServer.Server.Packet.Send.Challenge
{
StartChallengeScRsp proto = new StartChallengeScRsp() { };
if (player.ChallengeInstance != null)
if (player.ChallengeManager!.ChallengeInstance != null)
{
proto.CurChallenge = player.ChallengeInstance!.ToProto();
proto.CurChallenge = player.ChallengeManager.ChallengeInstance.ToProto();
proto.Lineup = player.LineupManager!.GetExtraLineup(ExtraLineupType.LineupChallenge)!.ToProto();
}
else