-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #304 from Lacyway/item-events-healing
Item events healing
- Loading branch information
Showing
11 changed files
with
245 additions
and
31 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
This file was deleted.
Oops, something went wrong.
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.Runtime.Serialization; | ||
using Fuyu.Backend.BSG.ItemTemplates; | ||
using Fuyu.Common.Hashing; | ||
|
||
namespace Fuyu.Backend.BSG.Models.ItemEvents; | ||
|
||
[DataContract] | ||
public class HealItemEvent : BaseItemEvent | ||
{ | ||
[DataMember(Name = "item")] | ||
public MongoId Item { get; set; } | ||
|
||
[DataMember(Name = "part")] | ||
public EBodyPart BodyPart { get; set; } | ||
|
||
[DataMember(Name = "count")] | ||
public int Count { get; set; } | ||
|
||
[DataMember(Name = "time")] | ||
public int Time { get; set; } | ||
} |
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 |
---|---|---|
@@ -1,11 +1,14 @@ | ||
using System.Collections.Generic; | ||
using System.Runtime.Serialization; | ||
using Fuyu.Backend.BSG.Models.Common; | ||
|
||
namespace Fuyu.Backend.BSG.Models.Profiles.Health; | ||
|
||
[DataContract] | ||
public class BodyPart | ||
{ | ||
[DataMember] | ||
public CurrentMaximum<float> Health { get; set; } | ||
public ClampedHealthStat<float> Health { get; set; } | ||
|
||
[DataMember(EmitDefaultValue = false)] | ||
public Dictionary<string, BodyPartEffect> Effects { get; set; } | ||
} |
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,10 @@ | ||
using System.Runtime.Serialization; | ||
|
||
namespace Fuyu.Backend.BSG.Models.Profiles.Health; | ||
|
||
[DataContract] | ||
public class BodyPartEffect | ||
{ | ||
[DataMember] | ||
public float Time { get; set; } = -1f; | ||
} |
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
39 changes: 39 additions & 0 deletions
39
Fuyu.Backend.BSG/Models/Profiles/Health/ClampedHealthStat.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,39 @@ | ||
using System.Numerics; | ||
using System.Runtime.Serialization; | ||
|
||
namespace Fuyu.Backend.BSG.Models.Profiles.Health; | ||
|
||
/// <summary> | ||
/// Class used to automatically clamp <see cref="Minimum"/> and <see cref="Maximum"/> values | ||
/// </summary> | ||
/// <typeparam name="T"></typeparam> | ||
[DataContract] | ||
public class ClampedHealthStat<T> where T : INumber<T> | ||
{ | ||
[DataMember] | ||
public T Current | ||
{ | ||
get | ||
{ | ||
return _current; | ||
} | ||
set | ||
{ | ||
_current = T.Clamp(value, Minimum, Maximum); | ||
} | ||
} | ||
|
||
private T _current; | ||
|
||
[DataMember] | ||
public T Minimum { get; set; } | ||
|
||
[DataMember] | ||
public T Maximum { get; set; } | ||
|
||
[DataMember] | ||
public T OverDamageReceivedMultiplier { get; set; } | ||
|
||
[DataMember] | ||
public T EnvironmentDamageMultiplier { get; set; } | ||
} |
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
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
68 changes: 68 additions & 0 deletions
68
Fuyu.Backend.EFT/Controllers/ItemEvents/HealItemEventController.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,68 @@ | ||
using System.Threading.Tasks; | ||
using Fuyu.Backend.BSG.ItemTemplates; | ||
using Fuyu.Backend.BSG.Models.ItemEvents; | ||
using Fuyu.Backend.BSG.Models.Items; | ||
using Fuyu.Backend.BSG.Networking; | ||
using Fuyu.Backend.BSG.Services; | ||
using Fuyu.Common.IO; | ||
|
||
namespace Fuyu.Backend.EFT.Controllers.ItemEvents; | ||
|
||
public class HealItemEventController : AbstractItemEventController<HealItemEvent> | ||
{ | ||
private readonly EftOrm _eftOrm; | ||
private readonly ItemFactoryService _itemFactoryService; | ||
|
||
public HealItemEventController() : base("Heal") | ||
{ | ||
_eftOrm = EftOrm.Instance; | ||
_itemFactoryService = ItemFactoryService.Instance; | ||
} | ||
|
||
public override Task RunAsync(ItemEventContext context, HealItemEvent request) | ||
{ | ||
var profile = _eftOrm.GetActiveProfile(context.SessionId); | ||
var item = profile.Pmc.Inventory.FindItem(request.Item); | ||
|
||
if (item == null) | ||
{ | ||
Terminal.WriteLine($"Failed to find item {request.Item}"); | ||
return Task.CompletedTask; | ||
} | ||
|
||
var medKit = item.GetOrCreateUpdatable<ItemMedKitComponent>(); | ||
|
||
var bodyPart = profile.Pmc.Health.GetBodyPart(request.BodyPart); | ||
float toHeal = request.Count; | ||
|
||
if (profile.Pmc.Health.HasEffects) | ||
{ | ||
var itemProperties = _itemFactoryService.GetItemProperties<MedsItemProperties>(item.TemplateId); | ||
|
||
if (itemProperties.DamageEffects.IsValue1) | ||
{ | ||
foreach (var (effectName, effect) in itemProperties.DamageEffects.Value1) | ||
{ | ||
if (bodyPart.Effects.ContainsKey(effectName)) | ||
{ | ||
toHeal -= effect.Cost; | ||
bodyPart.Effects.Remove(effectName); | ||
} | ||
} | ||
} | ||
} | ||
|
||
bodyPart.Health.Current += toHeal; | ||
medKit.HpResource -= request.Count; | ||
|
||
if (medKit.HpResource <= 0) | ||
{ | ||
profile.Pmc.Inventory.RemoveItem(item); | ||
} | ||
|
||
// TODO: | ||
// Check BackendConfig for 'HealExperience' and add to PMC profile | ||
|
||
return Task.CompletedTask; | ||
} | ||
} |