Skip to content

Commit edf76ec

Browse files
authored
add coreplayer, core effect and some module minor change
1 parent e90048f commit edf76ec

File tree

6 files changed

+186
-0
lines changed

6 files changed

+186
-0
lines changed

EIV_Core/CorePlayer.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using EIV_Modules.Extensions;
2+
using EIV_Modules.Modules;
3+
4+
namespace EIV_Core;
5+
6+
public abstract class CorePlayer
7+
{
8+
public string PlayerName { get; set; }
9+
public string UserId { get; set; }
10+
public string UserToken { get; set; }
11+
12+
public HealthModule Health { get; private set; }
13+
public EnergyModule Energy { get; private set; }
14+
public HydrationModule Hydration { get; private set; }
15+
16+
public void InitModules()
17+
{
18+
Health = this.AddAndGetModuleNode<HealthModule>();
19+
Energy = this.AddAndGetModuleNode<EnergyModule>();
20+
Hydration = this.AddAndGetModuleNode<HydrationModule>();
21+
this.AddAndGetModuleNode<EffectModule>();
22+
this.AddAndGetModuleNode<InventoryModule>();
23+
}
24+
}

EIV_Core/Effects/CoreEffect.cs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
using EIV_Common.Coroutines;
2+
using EIV_JsonLib;
3+
using EIV_Modules.Modules;
4+
using System.Collections.Generic;
5+
6+
namespace EIV_Core.Effects;
7+
8+
public abstract class CoreEffect(Effect effect, object parent)
9+
{
10+
CoroutineHandle? TimeCoroutine;
11+
public Effect JsonEffect => effect;
12+
private object Parent => parent;
13+
14+
public virtual void StartEffect()
15+
{
16+
StartEffect(JsonEffect.Time.Initial, JsonEffect.Strength.Min);
17+
}
18+
19+
public virtual void StartEffect(double Seconds, int Strength)
20+
{
21+
TimeCoroutine = CoroutineStaticExt.StartCoroutine(TimeStuff(Seconds, Strength), "Effect");
22+
}
23+
24+
public virtual void StopEffect()
25+
{
26+
if (TimeCoroutine == null)
27+
return;
28+
CoroutineStaticExt.KillCoroutineInstance(TimeCoroutine.Value);
29+
}
30+
31+
public virtual void EffectTick(int Strength)
32+
{
33+
if (JsonEffect.Strength.ApplyTo.Contains("Health") && Parent.TryGetModule(out HealthModule healthModule))
34+
{
35+
healthModule.Damage(JsonEffect.Health.Negative * Strength, JsonEffect.Health.Cause);
36+
healthModule.Heal(JsonEffect.Health.Positive * Strength, true);
37+
}
38+
if (JsonEffect.Strength.ApplyTo.Contains("Energy") && Parent.TryGetModule(out EnergyModule energyModule))
39+
{
40+
energyModule.RemoveValue(JsonEffect.Energy.Negative * Strength);
41+
energyModule.AddValue(JsonEffect.Energy.Positive * Strength, false);
42+
}
43+
}
44+
45+
private IEnumerator<double> TimeStuff(double InitialTime, int Strength)
46+
{
47+
yield return JsonEffect.Time.WaitUntilApply;
48+
double time = InitialTime;
49+
yield return CoroutineStaticExt.WaitUntilZero(
50+
() =>
51+
{
52+
EffectTick(Strength);
53+
time--;
54+
return time;
55+
});
56+
TimeCoroutine = null;
57+
}
58+
}

EIV_Core/Modules/EffectModule.cs

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
using EIV_Common.JsonStuff;
2+
using EIV_JsonLib;
3+
using EIV_JsonLib.Base;
4+
using EIV_JsonLib.Extension;
5+
using EIV_Core.Effects;
6+
using System.Collections.Generic;
7+
using System.Linq;
8+
using EIV_Modules;
9+
10+
namespace EIV_Core.Modules;
11+
12+
public partial class EffectModule : IModule
13+
{
14+
internal List<EffectBase> Effects = [];
15+
16+
public void ApplyEffectFromItem(CoreItem item)
17+
{
18+
var sideEffects = item.GetProperty<List<SideEffect>>("SideEffects");
19+
if (sideEffects.Count == 0)
20+
return;
21+
foreach (var sideEffect in sideEffects)
22+
{
23+
EffectApply(sideEffect, item);
24+
}
25+
}
26+
27+
public void EffectApply(SideEffect sideEffect, CoreItem item)
28+
{
29+
var effect = EffectMaker.MakeNewEffect(sideEffect.EffectName);
30+
if (effect == null)
31+
return;
32+
// Cannot Apply from it.
33+
if (!effect.AppliedFrom.Contains(item.Id) || effect.AppliedFrom.Contains(item.ItemType))
34+
return;
35+
36+
if (effect.Strength.Max < sideEffect.EffectStrength)
37+
return;
38+
if (effect.Strength.Min > sideEffect.EffectStrength)
39+
return;
40+
/*
41+
TODO: API
42+
MakeEffectBase makeEffectBase = new(this, effect);
43+
V2Manager.TriggerEvent(makeEffectBase);
44+
// This means we couldnt made EffectBase
45+
if (makeEffectBase.EffectBase == null)
46+
return;
47+
makeEffectBase.EffectBase.StartEffect(sideEffect.EffectTime, sideEffect.EffectStrength);
48+
Effects.Add(makeEffectBase.EffectBase);
49+
*/
50+
}
51+
52+
53+
public void EffectApply(string EffectName)
54+
{
55+
var effect = EffectMaker.MakeNewEffect(EffectName);
56+
if (effect == null)
57+
return;
58+
EffectApply(effect, effect.Time.Initial, effect.Strength.Min);
59+
}
60+
61+
public void EffectApply(Effect effect, double time, int strength)
62+
{
63+
if (effect == null)
64+
return;
65+
/* TODO: API
66+
MakeEffectBase makeEffectBase = new(this, effect);
67+
V2Manager.TriggerEvent(makeEffectBase);
68+
// This means we couldnt made EffectBase
69+
if (makeEffectBase.EffectBase == null)
70+
return;
71+
makeEffectBase.EffectBase.StartEffect(time, strength);
72+
Effects.Add(makeEffectBase.EffectBase);
73+
*/
74+
}
75+
76+
public void DisableEffect(string EffectName)
77+
{
78+
var effect = Effects.SingleOrDefault(x => x.CoreEffect.EffectName == EffectName);
79+
if (effect == null)
80+
return;
81+
effect.StopEffect();
82+
}
83+
84+
public List<string> GetEffectNames() => Effects.Select(x => x.CoreEffect.EffectName).ToList();
85+
86+
}

EIV_Core/Using.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
using CoroutineStaticExt = EIV_Coroutines.CoroutineWorkers.CoroutineStaticExt<double>;

EIV_Modules/Extensions/ModuleExtensions.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,18 @@ public static bool TryGetModule<T>(this object obj, out T out_t) where T : IModu
2121
return out_t != null;
2222
}
2323

24+
public static void AddModule<T>(this object obj) where T : IModule, new()
25+
{
26+
ModuleSub.AddModule?.Invoke(obj, new T());
27+
}
28+
29+
public static T AddAndGetModule<T>(this object obj) where T : IModule, new()
30+
{
31+
T module = new();
32+
ModuleSub.AddModule?.Invoke(obj, module);
33+
return module;
34+
}
35+
2436
public static void AddModule<T>(this object obj, T module) where T : IModule
2537
{
2638
ModuleSub.AddModule?.Invoke(obj, module);

EIV_Modules/Modules/SimpleModules.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
namespace EIV_Modules.Modules;
2+
3+
public partial class EnergyModule() : BaseChangingModule<int>(0, 100);
4+
5+
public partial class HydrationModule() : BaseChangingModule<int>(0, 100);

0 commit comments

Comments
 (0)