init
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 55debdd894df4bfeba2fb204d1998ab1
|
||||
timeCreated: 1772973840
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b922caefac514b5ea200716720d102ee
|
||||
timeCreated: 1773354906
|
||||
@@ -0,0 +1,47 @@
|
||||
using System.Linq;
|
||||
using RPGCore.StatusEffect.ObjectModules.StatusObjectModule;
|
||||
using UnityEditor;
|
||||
using UnityEditor.UIElements;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace RPGCore.StatusEffect.Editor.Drawers
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(StatusModule))]
|
||||
public class StatusModuleDrawer : PropertyDrawer
|
||||
{
|
||||
public override VisualElement CreatePropertyGUI(SerializedProperty property)
|
||||
{
|
||||
var root = new VisualElement();
|
||||
|
||||
if (Application.isPlaying) root.Add(CreateDebugBox(property));
|
||||
root.Add(new PropertyField(property));
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
private HelpBox CreateDebugBox(SerializedProperty property)
|
||||
{
|
||||
var debugBox = new HelpBox();
|
||||
debugBox.style.flexDirection = FlexDirection.Column;
|
||||
debugBox.style.alignItems = Align.Stretch;
|
||||
debugBox.SetEnabled(false);
|
||||
|
||||
debugBox.Add(new Label("RUNTIME DEBUG:"));
|
||||
|
||||
var statusList = new VisualElement();
|
||||
debugBox.Add(statusList);
|
||||
|
||||
debugBox.schedule.Execute(() =>
|
||||
{
|
||||
var module = property.boxedValue as StatusModule;
|
||||
|
||||
statusList.Clear();
|
||||
foreach (var status in module.statuses)
|
||||
statusList.Add(new Label(status.definition.name));
|
||||
}).Every(100);
|
||||
|
||||
return debugBox;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cc1db66de924411e8d07dea47af563c3
|
||||
timeCreated: 1773354908
|
||||
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"name": "RPGCore.StatusEffect.Editor",
|
||||
"rootNamespace": "RPGCore.StatusEffect.Editor",
|
||||
"references": [
|
||||
"RPGCore",
|
||||
"RPGCore.StatusEffect",
|
||||
"RPGCoreCommon.Helpers"
|
||||
],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 67ce347e38e048b4922477b1733406e3
|
||||
timeCreated: 1772973849
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8573345b7c004fc7a3e038ce235d4610
|
||||
timeCreated: 1772973844
|
||||
@@ -0,0 +1,8 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
[assembly: InternalsVisibleTo("RPGCore.StatusEffect.Editor")]
|
||||
|
||||
namespace RPGCore.StatusEffect
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e29a252ace124f5ba8afb1d172ca2120
|
||||
timeCreated: 1773355062
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d08f53aeb92f4bcdae8e0c29370e948b
|
||||
timeCreated: 1772998256
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 370696f1a9194fcc81f2462fb0fd3c75
|
||||
timeCreated: 1762633154
|
||||
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using RPGCore.Core.Objects;
|
||||
|
||||
namespace RPGCore.StatusEffect.ObjectModules.StatusObjectModule
|
||||
{
|
||||
/// <summary>
|
||||
/// Extend this to make custom effect that can be used by <see cref="StatusDefinitionSO"/>.
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class Effect
|
||||
{
|
||||
public BaseObject obj { get; internal set; }
|
||||
public Status status { get; internal set; }
|
||||
|
||||
internal void OnApply_Internal() => OnApply();
|
||||
internal void OnEnd_Internal() => OnEnd();
|
||||
internal void OnRemove_Internal() => OnRemove();
|
||||
|
||||
protected virtual void OnApply() {}
|
||||
protected virtual void OnEnd() {}
|
||||
protected virtual void OnRemove() {}
|
||||
|
||||
protected void EndStatus()
|
||||
{
|
||||
status.statusModule.End(status);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 930348137c8044d5bbbb64dcf54ae953
|
||||
timeCreated: 1772974582
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3c6b215386e14a38afa090853d1e7e84
|
||||
timeCreated: 1772974553
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
namespace RPGCore.StatusEffect.ObjectModules.StatusObjectModule.Effects
|
||||
{
|
||||
public class NotControllableEffect : Effect
|
||||
{
|
||||
}
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dccc3743dc3e4a67b738d8ac3c8e8347
|
||||
timeCreated: 1773175390
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 74fcfad35dc74866831cc42cdcfbbe44
|
||||
timeCreated: 1764884979
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
using RPGCore.Core.Objects;
|
||||
using RPGCore.ObjectModules.EventObjectModule;
|
||||
|
||||
namespace RPGCore.StatusEffect.ObjectModules.StatusObjectModule.Events
|
||||
{
|
||||
/// <summary>
|
||||
/// Executed when <see cref="Status"/> ends normally - by timer or by <see cref="Effect"/>.
|
||||
/// </summary>
|
||||
public class StatusEndEvent : BaseEvent<BaseObject>
|
||||
{
|
||||
public BaseObject target;
|
||||
public Status status;
|
||||
}
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a41609619e254d8a98ce6805b3d3edf8
|
||||
timeCreated: 1762636552
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
using RPGCore.Core.Objects;
|
||||
using RPGCore.ObjectModules.EventObjectModule;
|
||||
|
||||
namespace RPGCore.StatusEffect.ObjectModules.StatusObjectModule.Events
|
||||
{
|
||||
/// <summary>
|
||||
/// Executed when <see cref="Status"/> ends forcefully - by something else than timer or <see cref="Effect"/>.
|
||||
/// </summary>
|
||||
public class StatusRemoveEvent : BaseEvent<BaseObject>
|
||||
{
|
||||
public BaseObject target;
|
||||
public Status status;
|
||||
}
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c16881cb8c65431b97b97cd8956ed455
|
||||
timeCreated: 1773264987
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
using RPGCore.Core.Objects;
|
||||
using RPGCore.ObjectModules.EventObjectModule;
|
||||
|
||||
namespace RPGCore.StatusEffect.ObjectModules.StatusObjectModule.Events
|
||||
{
|
||||
/// <summary>
|
||||
/// Executed when <see cref="Status"/> is applied.
|
||||
/// </summary>
|
||||
public class StatusStartEvent : BaseEvent<BaseObject>
|
||||
{
|
||||
public BaseObject target;
|
||||
public Status status;
|
||||
}
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e35d6b98b192496ea8853d49de0b0790
|
||||
timeCreated: 1762636360
|
||||
@@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RPGCore.StatusEffect.ObjectModules.StatusObjectModule
|
||||
{
|
||||
public sealed class Status
|
||||
{
|
||||
public StatusDefinitionSO definition { get; private set; }
|
||||
public StatusModule statusModule { get; private set; }
|
||||
|
||||
public float timeRemaining { get; private set; }
|
||||
public List<Effect> effects { get; private set; }
|
||||
|
||||
internal Status(StatusDefinitionSO definition, StatusModule statusModule)
|
||||
{
|
||||
this.definition = definition;
|
||||
this.statusModule = statusModule;
|
||||
|
||||
timeRemaining = definition.time;
|
||||
effects = definition.effects.Select(e =>
|
||||
{
|
||||
var copy = JsonUtility.FromJson<Effect>(JsonUtility.ToJson(e));
|
||||
copy.obj = statusModule.parent;
|
||||
copy.status = this;
|
||||
return copy;
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
internal void UpdateTime_Internal(float deltaTime)
|
||||
{
|
||||
if (definition.permanent) return;
|
||||
|
||||
timeRemaining -= deltaTime;
|
||||
|
||||
if (timeRemaining <= 0) statusModule.End(this);
|
||||
}
|
||||
|
||||
internal void OnApply_Internal() => effects.ForEach(effect => effect.OnApply_Internal());
|
||||
|
||||
internal void OnEnd_Internal() => effects.ForEach(effect => effect.OnEnd_Internal());
|
||||
|
||||
internal void OnRemove_Internal() => effects.ForEach(effect => effect.OnRemove_Internal());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f4785e633dfa471082b97be16fb90522
|
||||
timeCreated: 1767359048
|
||||
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using RPGCore.Core.Objects;
|
||||
using RPGCore.StatusEffect.ObjectModules.StatusObjectModule.Effects;
|
||||
using RPGCoreCommon.DynamicValues;
|
||||
using RPGCoreCommon.Helpers.CustomTypes;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RPGCore.StatusEffect.ObjectModules.StatusObjectModule
|
||||
{
|
||||
[Serializable]
|
||||
[CreateAssetMenu(menuName = "RPG Core/Status")]
|
||||
public class StatusDefinitionSO : ScriptableObject
|
||||
{
|
||||
[Header("Connected to:")]
|
||||
[SerializableType(typeof(BaseObject), allowAbstract: true)] public SerializableType forType;
|
||||
|
||||
[Header("Display")]
|
||||
public string displayName;
|
||||
public bool hidden;
|
||||
public Texture2D displayIcon;
|
||||
[DynamicValue(DynamicValueType.ByDynamicTypes)] public DynamicValue description;
|
||||
|
||||
[Header("Duration")]
|
||||
public bool permanent;
|
||||
[Min(0)] public float time;
|
||||
|
||||
[Header("Effects")]
|
||||
[SerializeReference] public List<Effect> effects = new();
|
||||
|
||||
private void OnValidate()
|
||||
{
|
||||
description.RemoveDynamicTypes();
|
||||
description.SetDynamicType("object", forType);
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9e1852531ea144a181ad7f23cfa40991
|
||||
timeCreated: 1762633180
|
||||
@@ -0,0 +1,98 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using RPGCore.Core;
|
||||
using RPGCore.Core.Objects;
|
||||
using RPGCore.ObjectModules.EventObjectModule;
|
||||
using RPGCore.StatusEffect.ObjectModules.StatusObjectModule.Effects;
|
||||
using RPGCore.StatusEffect.ObjectModules.StatusObjectModule.Events;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RPGCore.StatusEffect.ObjectModules.StatusObjectModule
|
||||
{
|
||||
[Serializable]
|
||||
[RequireComponent(typeof(BaseObject))]
|
||||
public class StatusModule : ObjectModule<BaseObject>
|
||||
{
|
||||
internal List<Status> statuses { get; private set; } = new();
|
||||
[SerializeField] internal StatusUpdateType updateType;
|
||||
|
||||
/// <summary>Checks if any <see cref="Status"/> has <see cref="NotControllableEffect"/>.</summary>
|
||||
public virtual bool IsControllable()
|
||||
{
|
||||
return !statuses.Any(status => status.definition.effects.Any(effect => effect is NotControllableEffect));
|
||||
}
|
||||
|
||||
/// <summary>Checks if any active <see cref="Status"/> that uses <see cref="StatusDefinitionSO"/> is present.</summary>
|
||||
public bool Check(StatusDefinitionSO definition)
|
||||
{
|
||||
return statuses.Any(status => status.definition == definition);
|
||||
}
|
||||
|
||||
/// <summary>Adds new <see cref="Status"/>.</summary>
|
||||
public Status Apply(StatusDefinitionSO definition)
|
||||
{
|
||||
var status = new Status(definition, this);
|
||||
statuses.Add(status);
|
||||
status.OnApply_Internal();
|
||||
parent.events.Invoke(new StatusStartEvent { status = status, target = parent });
|
||||
return status;
|
||||
}
|
||||
|
||||
/// <summary>Removes given <see cref="Status"/> forcefully.</summary>
|
||||
public void Remove(Status status)
|
||||
{
|
||||
if (status == null) return;
|
||||
if (!statuses.Contains(status)) return;
|
||||
status.OnRemove_Internal();
|
||||
statuses.Remove(status);
|
||||
parent.events.Invoke(new StatusRemoveEvent { status = status, target = parent });
|
||||
}
|
||||
|
||||
/// <summary>Removes all <see cref="Status"/>es forcefully that uses <see cref="StatusDefinitionSO"/>.</summary>
|
||||
public void Remove(StatusDefinitionSO definition)
|
||||
{
|
||||
GetStatuses(definition).ForEach(Remove);
|
||||
}
|
||||
|
||||
/// <summary>Executed internally when status ending itself (by timer or effect).</summary>
|
||||
internal void End(Status status)
|
||||
{
|
||||
if (status == null) return;
|
||||
if (!statuses.Contains(status)) return;
|
||||
status.OnEnd_Internal();
|
||||
statuses.Remove(status);
|
||||
parent.events.Invoke(new StatusEndEvent { status = status, target = parent });
|
||||
}
|
||||
|
||||
/// <summary>Returns all active <see cref="Status"/>es.</summary>
|
||||
public List<Status> GetStatuses()
|
||||
{
|
||||
return statuses.ToList();
|
||||
}
|
||||
|
||||
/// <summary>Returns all active <see cref="Status"/>es that uses <see cref="StatusDefinitionSO"/>.</summary>
|
||||
public List<Status> GetStatuses(StatusDefinitionSO definition)
|
||||
{
|
||||
return statuses.Where(status => status.definition == definition).ToList();
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
if (updateType is StatusUpdateType.Automatically)
|
||||
statuses.ToList().ForEach(status => status.UpdateTime_Internal(Time.fixedDeltaTime));
|
||||
}
|
||||
|
||||
/// <summary>Update each status timer, decreases them by given seconds.</summary>
|
||||
public void UpdateTime(float deltaTime)
|
||||
{
|
||||
if (updateType is not StatusUpdateType.Manually)
|
||||
{
|
||||
Debug.LogError($"Updating status time available only when: {nameof(StatusUpdateType)} = {nameof(StatusUpdateType.Manually)}");
|
||||
return;
|
||||
}
|
||||
|
||||
statuses.ForEach(status => status.UpdateTime_Internal(deltaTime));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0ce33596b3d549c7b86629c1d1e6532c
|
||||
timeCreated: 1762633163
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace RPGCore.StatusEffect.ObjectModules.StatusObjectModule
|
||||
{
|
||||
public enum StatusUpdateType
|
||||
{
|
||||
Automatically,
|
||||
Manually,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5585782dbfae4ea6bc631cb2038e51f1
|
||||
timeCreated: 1773176713
|
||||
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"name": "RPGCore.StatusEffect",
|
||||
"rootNamespace": "RPGCore.StatusEffect",
|
||||
"references": [
|
||||
"RPGCore",
|
||||
"RPGCoreCommon.Settings",
|
||||
"RPGCoreCommon.Helpers",
|
||||
"RPGCoreCommon.DynamicValues",
|
||||
"Unity.InputSystem"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5173dd49ef4441a69ee4ad8069af2c60
|
||||
timeCreated: 1772973851
|
||||
Reference in New Issue
Block a user