Skip to content

Commit

Permalink
Merge pull request #512 from pacampbell/enable_subgroup_support
Browse files Browse the repository at this point in the history
feat: Add support for enemy subgroups
  • Loading branch information
pacampbell authored Aug 31, 2024
2 parents 6838532 + ac930b5 commit 8ddd730
Show file tree
Hide file tree
Showing 8 changed files with 155 additions and 150 deletions.
40 changes: 36 additions & 4 deletions Arrowgene.Ddon.GameServer/Enemies/InstanceEnemyManager.cs
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
using Arrowgene.Ddon.GameServer;
using Arrowgene.Ddon.GameServer.GatheringItems;
using Arrowgene.Ddon.GameServer.Quests;
using Arrowgene.Ddon.Shared.Model;
using System;
using System.Collections.Generic;

public class InstanceEnemyManager : InstanceAssetManager<byte, Enemy, InstancedEnemy>
{
private readonly DdonGameServer _server;
private readonly DdonGameServer _Server;
private Dictionary<StageId, ushort> _CurrentSubgroup { get; set; }

public InstanceEnemyManager(DdonGameServer server) : base()
{
_server = server;
_Server = server;
_CurrentSubgroup = new Dictionary<StageId, ushort>();
}

protected override List<Enemy> FetchAssetsFromRepository(StageId stage, byte subGroupId)
{
return _server.AssetRepository.EnemySpawnAsset.Enemies.GetValueOrDefault((stage, subGroupId)) ?? new List<Enemy>();
return _Server.AssetRepository.EnemySpawnAsset.Enemies.GetValueOrDefault((stage, subGroupId)) ?? new List<Enemy>();
}

protected override List<InstancedEnemy> InstanceAssets(List<Enemy> originals)
{
List<InstancedEnemy> filteredEnemyList = new List<InstancedEnemy>();

// Calculate current game time
long gameTimeMSec = _server.WeatherManager.RealTimeToGameTimeMS(DateTimeOffset.UtcNow);
long gameTimeMSec = _Server.WeatherManager.RealTimeToGameTimeMS(DateTimeOffset.UtcNow);

foreach (Enemy original in originals)
{
Expand All @@ -43,4 +46,33 @@ protected override List<InstancedEnemy> InstanceAssets(List<Enemy> originals)
}
return filteredEnemyList;
}

public ushort GetInstanceSubgroupId(StageId stageId)
{
lock (_CurrentSubgroup)
{
if (!_CurrentSubgroup.ContainsKey(stageId))
{
return 0;
}
return _CurrentSubgroup[stageId];
}
}

public void SetInstanceSubgroupId(StageId stageId, ushort subgroupId)
{
lock (_CurrentSubgroup)
{
_CurrentSubgroup[stageId] = subgroupId;
}
}

public override void Clear()
{
base.Clear();
lock (_CurrentSubgroup)
{
_CurrentSubgroup.Clear();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public InstanceDropItemManager(GameClient client)

protected override List<GatheringItem> FetchAssetsFromRepository(StageId stage, uint setId)
{
List<InstancedEnemy> enemiesInSet = _client.Party.InstanceEnemyManager.GetAssets(stage, 0);
List<InstancedEnemy> enemiesInSet = _client.Party.InstanceEnemyManager.GetAssets(stage, (byte) setId);
if(enemiesInSet != null && setId < enemiesInSet.Count)
{
Enemy enemy = enemiesInSet[(int) setId];
Expand Down
6 changes: 2 additions & 4 deletions Arrowgene.Ddon.GameServer/Handler/InstanceEnemyKillHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,15 @@ public override void Handle(GameClient client, StructurePacket<C2SInstanceEnemyK
{
CDataStageLayoutId layoutId = packet.Structure.LayoutId;
StageId stageId = StageId.FromStageLayoutId(layoutId);
ushort subGroupId = 0;
ushort subGroupId = client.Party.InstanceEnemyManager.GetInstanceSubgroupId(stageId);

Quest quest = null;
bool IsQuestControlled = false;
foreach (var questId in client.Party.QuestState.StageQuests(stageId))
{
quest = QuestManager.GetQuest(questId);
var qSubGroupId = client.Party.QuestState.GetInstanceSubgroupId(quest, stageId);
if (client.Party.QuestState.HasEnemiesInCurrentStageGroup(quest, stageId, qSubGroupId))
if (client.Party.QuestState.HasEnemiesInCurrentStageGroup(quest, stageId, subGroupId))
{
subGroupId = qSubGroupId;
IsQuestControlled = true;
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public override void Handle(GameClient client, StructurePacket<C2SInstanceGetEne
RandomSeed = CryptoRandom.Instance.GetRandomUInt32(),
};

client.Party.InstanceEnemyManager.SetInstanceSubgroupId(stageId, subGroupId);
if (IsQuestControlled && quest != null)
{
response.QuestId = (uint) quest.QuestId;
Expand All @@ -54,8 +55,6 @@ public override void Handle(GameClient client, StructurePacket<C2SInstanceGetEne
PositionIndex = (byte)(enemy.Index),
EnemyInfo = enemy.asCDataStageLayoutEnemyPresetEnemyInfoClient()
}).ToList();

client.Party.QuestState.SetInstanceSubgroupId(quest, stageId, subGroupId);
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions Arrowgene.Ddon.GameServer/InstanceAssetManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public List<T3> GetAssets(StageId stageId, T1 subGroupId)
return _instancedAssetsDictionary[(stageId, subGroupId)];
}

public void Clear()
public virtual void Clear()
{
_instancedAssetsDictionary.Clear();
}
Expand All @@ -50,4 +50,4 @@ public void Clear()

protected abstract List<T3> InstanceAssets(List<T2> originals);
}
}
}
25 changes: 0 additions & 25 deletions Arrowgene.Ddon.GameServer/Party/PartyQuestState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,13 @@ public class QuestState

public Dictionary<ushort, QuestProcessState> ProcessState { get; set; }
public Dictionary<StageId, Dictionary<uint, List<InstancedEnemy>>> QuestEnemies { get; set; }
public Dictionary<StageId, ushort> CurrentSubgroup { get; set; }

public Dictionary<uint, QuestDeliveryRecord> DeliveryRecords { get; set; }

public QuestState()
{
ProcessState = new Dictionary<ushort, QuestProcessState>();
QuestEnemies = new Dictionary<StageId, Dictionary<uint, List<InstancedEnemy>>>();
DeliveryRecords = new Dictionary<uint, QuestDeliveryRecord>();
CurrentSubgroup = new Dictionary<StageId, ushort>();
}

public uint UpdateDeliveryRequest(uint itemId, uint amount)
Expand Down Expand Up @@ -214,28 +211,6 @@ public InstancedEnemy GetInstancedEnemy(QuestId questId, StageId stageId, ushort
return GetInstancedEnemy(quest, stageId, subGroupId, index);
}

public void SetInstanceSubgroupId(Quest quest, StageId stageId, ushort subgroupId)
{
lock (ActiveQuests)
{
var questState = ActiveQuests[quest.QuestId];
questState.CurrentSubgroup[stageId] = subgroupId;
}
}

public ushort GetInstanceSubgroupId(Quest quest, StageId stageId)
{
lock (ActiveQuests)
{
var questState = ActiveQuests[quest.QuestId];
if (!questState.CurrentSubgroup.ContainsKey(stageId))
{
return 0;
}
return questState.CurrentSubgroup[stageId];
}
}

public void AddNewQuest(QuestId questId, uint step)
{
var quest = QuestManager.GetQuest(questId);
Expand Down
Loading

0 comments on commit 8ddd730

Please sign in to comment.