diff --git a/Arrowgene.Ddon.GameServer/GatheringItems/InstanceEventDropItemManager.cs b/Arrowgene.Ddon.GameServer/GatheringItems/InstanceEventDropItemManager.cs index 636ea08cd..aee15dacb 100644 --- a/Arrowgene.Ddon.GameServer/GatheringItems/InstanceEventDropItemManager.cs +++ b/Arrowgene.Ddon.GameServer/GatheringItems/InstanceEventDropItemManager.cs @@ -38,6 +38,16 @@ private bool DropEnabled(Character character, EventItem item, Enemy enemy, Stage return false; } + if (item.EmLvConstraint != EventItemConstraint.None && !EvaluateEmLvConstraint(item, enemy)) + { + return false; + } + + if (!EvaluateEmClassConstraint(item, enemy)) + { + return false; + } + if (item.RequiredItemsEquipped.Count > 0) { if (item.ItemConstraint == EventItemConstraint.All) @@ -79,6 +89,52 @@ private bool DropEnabled(Character character, EventItem item, Enemy enemy, Stage return true; } + private bool EvaluateEmLvConstraint(EventItem item, Enemy enemy) + { + if (item.EmLvConstraint == EventItemConstraint.InRange) + { + return enemy.Lv >= item.EmLvConstraintParams.MinLv && enemy.Lv <= item.EmLvConstraintParams.MaxLv; + } + else if (item.EmLvConstraint == EventItemConstraint.LessThan) + { + return enemy.Lv < item.EmLvConstraintParams.Lv; + } + else if (item.EmLvConstraint == EventItemConstraint.LessThanOrEqual) + { + return enemy.Lv <= item.EmLvConstraintParams.Lv; + } + else if (item.EmLvConstraint == EventItemConstraint.GreaterThan) + { + return enemy.Lv > item.EmLvConstraintParams.Lv; + } + else if (item.EmLvConstraint == EventItemConstraint.GreaterThanOrEqual) + { + return enemy.Lv >= item.EmLvConstraintParams.Lv; + } + + // An invalid constraint type was passed + return false; + } + + private bool EvaluateEmClassConstraint(EventItem item, Enemy enemy) + { + if (item.EmClassConstraint == EventItemConstraint.None) + { + return true; + } + else if (item.EmClassConstraint == EventItemConstraint.IsBoss) + { + return enemy.IsBossGauge; + } + else if (item.EmClassConstraint == EventItemConstraint.IsNotBoss) + { + return !enemy.IsBossGauge; + } + + // An invalid constraint type was passed + return false; + } + public List FetchEventItems(GameClient client, CDataStageLayoutId layoutId, uint posId) { var stageId = layoutId.AsStageId(); diff --git a/Arrowgene.Ddon.Shared/Asset/EventDropsAsset.cs b/Arrowgene.Ddon.Shared/Asset/EventDropsAsset.cs index a3e5be8dc..a4c311097 100644 --- a/Arrowgene.Ddon.Shared/Asset/EventDropsAsset.cs +++ b/Arrowgene.Ddon.Shared/Asset/EventDropsAsset.cs @@ -23,6 +23,11 @@ public EventItem() public HashSet StageIds { get; set; } public HashSet EnemyIds { get; set; } + public EventItemConstraint EmClassConstraint; // Boss or Regular Enemy + + public EventItemConstraint EmLvConstraint; + public (uint Lv, uint MinLv, uint MaxLv) EmLvConstraintParams { get; set; } + public bool RequiresLanternLit { get; set; } public EventItemConstraint ItemConstraint { get; set; } diff --git a/Arrowgene.Ddon.Shared/AssetReader/EventDropAssetDeserializer.cs b/Arrowgene.Ddon.Shared/AssetReader/EventDropAssetDeserializer.cs index 115dfcf0b..ea9d0dbb0 100644 --- a/Arrowgene.Ddon.Shared/AssetReader/EventDropAssetDeserializer.cs +++ b/Arrowgene.Ddon.Shared/AssetReader/EventDropAssetDeserializer.cs @@ -79,9 +79,85 @@ public EventDropsAsset ReadPath(string path) else { Logger.Error($"Failed to parse item constraint {jConstraint.GetString()}"); + continue; } } } + + eventItem.EmClassConstraint = EventItemConstraint.None; + if (jRequirements.TryGetProperty("enemy_class", out JsonElement jEnemyClass)) + { + if (!Enum.TryParse(jEnemyClass.ToString(), out eventItem.EmClassConstraint)) + { + Logger.Error("Failed to parse the 'enemy_class' constraint."); + continue; + } + + if (eventItem.EmClassConstraint != EventItemConstraint.None || + eventItem.EmClassConstraint != EventItemConstraint.IsBoss || + eventItem.EmClassConstraint != EventItemConstraint.IsNotBoss) + { + Logger.Error($"The constraint '{eventItem.EmClassConstraint}' is not a valid constraint for 'enemy_class'."); + continue; + } + } + + eventItem.EmLvConstraint = EventItemConstraint.None; + if (jRequirements.TryGetProperty("enemy_level", out JsonElement jEnemyLevel)) + { + if (!Enum.TryParse(jEnemyLevel.GetProperty("constraint").ToString(), out eventItem.EmLvConstraint)) + { + Logger.Error("Required element 'constraint' does not exist or is an invalid value."); + continue; + } + + switch (eventItem.EmLvConstraint) + { + case EventItemConstraint.LessThan: + case EventItemConstraint.LessThanOrEqual: + case EventItemConstraint.GreaterThan: + case EventItemConstraint.GreaterThanOrEqual: + case EventItemConstraint.InRange: + break; + default: + Logger.Error($"The constraint '{eventItem.EmLvConstraint}' is not a valid constraint for 'enemy_level'."); + continue; + } + + uint Lv = 0; + if (jEnemyLevel.TryGetProperty("min_lv", out JsonElement jEmLv)) + { + Lv = jEmLv.GetUInt32(); + } + + uint minLv = 0; + if (jEnemyLevel.TryGetProperty("min_lv", out JsonElement jEmMinLv)) + { + minLv = jEmMinLv.GetUInt32(); + } + + uint maxLv = 0; + if (jEnemyLevel.TryGetProperty("max_lv", out JsonElement jEmMaxLv)) + { + maxLv = jEmMaxLv.GetUInt32(); + } + + if ((eventItem.EmLvConstraint == EventItemConstraint.LessThan || + eventItem.EmLvConstraint == EventItemConstraint.LessThanOrEqual || + eventItem.EmLvConstraint == EventItemConstraint.GreaterThan || + eventItem.EmLvConstraint == EventItemConstraint.GreaterThanOrEqual) && Lv == 0) + { + Logger.Error($"The constraint '{eventItem.EmLvConstraint}' requires the field 'lv' to be present with a value > 0."); + continue; + } + else if(eventItem.EmLvConstraint == EventItemConstraint.InRange && (minLv == 0 || maxLv == 0)) + { + Logger.Error($"The constraint '{eventItem.EmLvConstraint}' requires the field 'min_lv' and 'max_lv' to be present with a value > 0."); + continue; + } + + eventItem.EmLvConstraintParams = (Lv, minLv, maxLv); + } } asset.EventItems.Add(eventItem); diff --git a/Arrowgene.Ddon.Shared/Files/Assets/EventDrops.json b/Arrowgene.Ddon.Shared/Files/Assets/EventDrops.json index 67f7d90e5..063f645fd 100644 --- a/Arrowgene.Ddon.Shared/Files/Assets/EventDrops.json +++ b/Arrowgene.Ddon.Shared/Files/Assets/EventDrops.json @@ -112,6 +112,23 @@ "quest_ids": [60301057], "stage_ids": [], "enemy_ids": [] + }, + { + "item_id": 7790, + "comment": "Adds randomized gold drop of 10-200 gold to all enemies between level 1-10", + "min_num": 1, + "max_num": 20, + "drop_chance": 0.3, + "quest_ids": [], + "stage_ids": [], + "enemy_ids": [], + "requirements": { + "enemy_level": { + "constraint": "InRange", + "min_lv": 1, + "max_lv": 10 + } + } } ] diff --git a/Arrowgene.Ddon.Shared/Model/EventItemConstraint.cs b/Arrowgene.Ddon.Shared/Model/EventItemConstraint.cs index daa3c9db2..4012085f6 100644 --- a/Arrowgene.Ddon.Shared/Model/EventItemConstraint.cs +++ b/Arrowgene.Ddon.Shared/Model/EventItemConstraint.cs @@ -10,6 +10,13 @@ public enum EventItemConstraint { None, All, - AtLeastOne + AtLeastOne, + LessThan, // The value is < a + LessThanOrEqual, // The value <= a + GreaterThan, // The value is > a + GreaterThanOrEqual, // The value is >= a + InRange, // The Value is in the range [a, b] + IsBoss, + IsNotBoss, } }