-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add mobreward template loading, implement mobrewardmanager
- Loading branch information
Showing
10 changed files
with
207 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/common/Edelstein.Common.Gameplay.Game/Objects/Mob/Rewards/MobReward.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using Edelstein.Protocol.Gameplay.Game.Objects.Mob.Rewards; | ||
|
||
namespace Edelstein.Common.Gameplay.Game.Objects.Mob.Rewards; | ||
|
||
public record MobReward : IMobReward | ||
{ | ||
public int? ItemID { get; init; } | ||
|
||
public int? Money { get; init; } | ||
|
||
public int? NumberMin { get; init; } | ||
public int? NumberMax { get; init; } | ||
|
||
public int? ReqQuest { get; init; } | ||
|
||
public int? ReqLevelMin { get; init; } | ||
public int? ReqLevelMax { get; init; } | ||
|
||
public int? ReqMobLevelMin { get; init; } | ||
public int? ReqMobLevelMax { get; init; } | ||
|
||
public DateTime? DateStart { get; init; } | ||
public DateTime? DateEnd { get; init; } | ||
} |
46 changes: 46 additions & 0 deletions
46
src/common/Edelstein.Common.Gameplay.Game/Objects/Mob/Rewards/MobRewardManager.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using System.Collections.Immutable; | ||
using Edelstein.Protocol.Gameplay.Game.Objects.Mob; | ||
using Edelstein.Protocol.Gameplay.Game.Objects.Mob.Rewards; | ||
using Edelstein.Protocol.Gameplay.Game.Objects.User; | ||
|
||
namespace Edelstein.Common.Gameplay.Game.Objects.Mob.Rewards; | ||
|
||
public class MobRewardManager : IMobRewardManager | ||
{ | ||
private readonly IDictionary<int, MobRewards> _rewards; | ||
private readonly ICollection<IMobReward> _rewardsAll; | ||
|
||
public MobRewardManager() | ||
{ | ||
_rewards = new Dictionary<int, MobRewards>(); | ||
_rewardsAll = new List<IMobReward>(); | ||
} | ||
|
||
public Task Insert(int mobID, IMobReward reward) | ||
{ | ||
if (!_rewards.TryGetValue(mobID, out var rewards)) | ||
{ | ||
rewards = new MobRewards(); | ||
_rewards[mobID] = rewards; | ||
} | ||
|
||
rewards.Items.Add(reward); | ||
return Task.CompletedTask; | ||
} | ||
|
||
public Task InsertAll(IMobReward reward) | ||
{ | ||
_rewardsAll.Add(reward); | ||
return Task.CompletedTask; | ||
} | ||
|
||
public Task<ICollection<IMobReward>> RetrieveAll(int mobID) | ||
=> Task.FromResult<ICollection<IMobReward>>(_rewardsAll | ||
.Concat(_rewards.TryGetValue(mobID, out var rewards) ? rewards.Items : ImmutableArray<IMobReward>.Empty) | ||
.ToImmutableArray()); | ||
|
||
public async Task<ICollection<IMobReward>> RetrieveAvailable(IFieldUser user, IFieldMob mob) | ||
=> (await RetrieveAll(mob.Template.ID)) | ||
.Where(r => true) // TODO | ||
.ToImmutableArray(); | ||
} |
26 changes: 26 additions & 0 deletions
26
src/common/Edelstein.Common.Gameplay.Game/Objects/Mob/Rewards/MobRewardManagerInit.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using Edelstein.Common.Gameplay.Game.Objects.Mob.Templates; | ||
using Edelstein.Protocol.Gameplay.Contracts; | ||
using Edelstein.Protocol.Gameplay.Game.Objects.Mob.Rewards; | ||
using Edelstein.Protocol.Utilities.Pipelines; | ||
using Edelstein.Protocol.Utilities.Templates; | ||
|
||
namespace Edelstein.Common.Gameplay.Game.Objects.Mob.Rewards; | ||
|
||
public class MobRewardManagerInit : IPipelinePlug<StageStart> | ||
{ | ||
private readonly ITemplateManager<MobRewardsTemplate> _templates; | ||
private readonly IMobRewardManager _manager; | ||
|
||
public MobRewardManagerInit(ITemplateManager<MobRewardsTemplate> templates, IMobRewardManager manager) | ||
{ | ||
_templates = templates; | ||
_manager = manager; | ||
} | ||
|
||
public async Task Handle(IPipelineContext ctx, StageStart message) | ||
{ | ||
foreach (var rewards in await _templates.RetrieveAll()) | ||
foreach (var item in rewards.Items) | ||
await _manager.Insert(rewards.ID, item); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/common/Edelstein.Common.Gameplay.Game/Objects/Mob/Rewards/MobRewards.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using Edelstein.Protocol.Gameplay.Game.Objects.Mob.Rewards; | ||
|
||
namespace Edelstein.Common.Gameplay.Game.Objects.Mob.Rewards; | ||
|
||
public class MobRewards | ||
{ | ||
public ICollection<IMobReward> Items { get; } | ||
|
||
public MobRewards() | ||
=> Items = new List<IMobReward>(); | ||
} |
21 changes: 21 additions & 0 deletions
21
src/common/Edelstein.Common.Gameplay.Game/Objects/Mob/Templates/MobRewardsTemplate.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System.Collections.Immutable; | ||
using Duey.Abstractions; | ||
using Edelstein.Common.Gameplay.Game.Objects.NPC.Templates; | ||
using Edelstein.Protocol.Gameplay.Game.Objects.NPC; | ||
using Edelstein.Protocol.Utilities.Templates; | ||
|
||
namespace Edelstein.Common.Gameplay.Game.Objects.Mob.Templates; | ||
|
||
public class MobRewardsTemplate : ITemplate | ||
{ | ||
public int ID { get; } | ||
public ICollection<MobRewardsTemplateItem> Items { get; } | ||
|
||
public MobRewardsTemplate(int id, IDataNode property) | ||
{ | ||
ID = id; | ||
Items = property.Children | ||
.Select(p => new MobRewardsTemplateItem(Convert.ToInt32(p.Name), p.Cache())) | ||
.ToImmutableArray(); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/common/Edelstein.Common.Gameplay.Game/Objects/Mob/Templates/MobRewardsTemplateItem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using Duey.Abstractions; | ||
using Edelstein.Protocol.Gameplay.Game.Objects.Mob.Rewards; | ||
using Edelstein.Protocol.Utilities.Templates; | ||
|
||
namespace Edelstein.Common.Gameplay.Game.Objects.Mob.Templates; | ||
|
||
public class MobRewardsTemplateItem : ITemplate, IMobReward | ||
{ | ||
public int ID { get; } | ||
|
||
public int? ItemID { get; } | ||
|
||
public int? Money { get; } | ||
|
||
public int? NumberMin { get; } | ||
public int? NumberMax { get; } | ||
|
||
public int? ReqQuest { get; } | ||
|
||
public int? ReqLevelMin { get; } | ||
public int? ReqLevelMax { get; } | ||
|
||
public int? ReqMobLevelMin { get; } | ||
public int? ReqMobLevelMax { get; } | ||
|
||
public DateTime? DateStart { get; } | ||
public DateTime? DateEnd { get; } | ||
|
||
public MobRewardsTemplateItem(int id, IDataNode property) | ||
{ | ||
ID = id; | ||
|
||
ItemID = property.ResolveInt("item"); | ||
|
||
Money = property.ResolveInt("money"); | ||
|
||
NumberMin = property.ResolveInt("min"); | ||
NumberMax = property.ResolveInt("max"); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/common/Edelstein.Common.Gameplay.Game/Objects/Mob/Templates/MobRewardsTemplateLoader.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using Duey.Abstractions; | ||
using Edelstein.Common.Gameplay.Game.Objects.NPC.Templates; | ||
using Edelstein.Common.Utilities.Templates; | ||
using Edelstein.Protocol.Utilities.Templates; | ||
|
||
namespace Edelstein.Common.Gameplay.Game.Objects.Mob.Templates; | ||
|
||
public class MobRewardsTemplateLoader : ITemplateLoader | ||
{ | ||
private readonly IDataNamespace _data; | ||
private readonly ITemplateManager<MobRewardsTemplate> _manager; | ||
|
||
public MobRewardsTemplateLoader(IDataNamespace data, ITemplateManager<MobRewardsTemplate> manager) | ||
{ | ||
_data = data; | ||
_manager = manager; | ||
} | ||
|
||
public async Task<int> Load() | ||
{ | ||
await Task.WhenAll(_data.ResolvePath("Server/Reward.img")?.Children | ||
.Select(async n => | ||
{ | ||
var id = Convert.ToInt32(n.Name); | ||
await _manager.Insert(new TemplateProviderEager<MobRewardsTemplate>( | ||
id, | ||
new MobRewardsTemplate(id, n.Cache()) | ||
)); | ||
}) ?? Array.Empty<Task>()); | ||
|
||
return _manager.Count; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters