92 lines
3.2 KiB
C#
92 lines
3.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Cielonos.MainGame.Inventory;
|
|
using SLSUtilities.General;
|
|
using UnityEngine;
|
|
|
|
namespace Cielonos.MainGame.Characters
|
|
{
|
|
public class ReflectionSubmodule : SubmoduleBase<ReactionSubcontroller>
|
|
{
|
|
public List<ReflectionSource> reflectionSources;
|
|
public bool canReflect;
|
|
public bool isReflecting => reflectionSources.Count > 0;
|
|
|
|
public ReflectionSubmodule(ReactionSubcontroller owner) : base(owner)
|
|
{
|
|
reflectionSources = new List<ReflectionSource>();
|
|
canReflect = true;
|
|
}
|
|
|
|
public void ApplyReflection(ReflectionSource source)
|
|
{
|
|
if (canReflect)
|
|
{
|
|
ReflectionSource existingSource = reflectionSources.Find(x => x.sourceName == source.sourceName);
|
|
if (existingSource != null)
|
|
{
|
|
if (source.reflectTime > existingSource.reflectTime)
|
|
{
|
|
existingSource.reflectTime = source.reflectTime;
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
reflectionSources.AddByPriority(source);
|
|
}
|
|
}
|
|
|
|
public void ApplyReflection(CharacterBase sourceCharacter, ItemBase sourceItem, string sourceName,
|
|
int priority = 0, float reflectTime = Mathf.Infinity,
|
|
Func<AttackAreaBase, bool> condition = null, Action<AttackAreaBase> onReflection = null)
|
|
{
|
|
ReflectionSource newSource = new ReflectionSource(sourceCharacter, sourceItem, sourceName, priority, reflectTime, condition, onReflection);
|
|
ApplyReflection(newSource);
|
|
}
|
|
|
|
public void RemoveReflection(string sourceName)
|
|
{
|
|
reflectionSources.RemoveAll(source => source.sourceName == sourceName);
|
|
}
|
|
|
|
public ReflectionSource GetCurrentReflectionSource()
|
|
{
|
|
return reflectionSources.Count == 0 ? null : reflectionSources[0];
|
|
}
|
|
|
|
public void Update()
|
|
{
|
|
reflectionSources.ForEach(source =>
|
|
{
|
|
source.reflectTime -= owner.owner.selfTimeSm.DeltaTime;
|
|
});
|
|
|
|
reflectionSources.RemoveAll(source => source.reflectTime <= 0);
|
|
}
|
|
}
|
|
|
|
public class ReflectionSource : IPrioritized
|
|
{
|
|
public int Priority { get; private set; }
|
|
public CharacterBase sourceCharacter;
|
|
public ItemBase sourceItem;
|
|
public string sourceName;
|
|
|
|
public float reflectTime;
|
|
public Func<AttackAreaBase, bool> condition;
|
|
public Action<AttackAreaBase> onReflection;
|
|
|
|
public ReflectionSource(CharacterBase sourceCharacter, ItemBase sourceItem, string sourceName,
|
|
int priority, float reflectTime, Func<AttackAreaBase, bool> condition, Action<AttackAreaBase> onReflection)
|
|
{
|
|
this.sourceCharacter = sourceCharacter;
|
|
this.sourceItem = sourceItem;
|
|
this.sourceName = sourceName;
|
|
this.reflectTime = reflectTime;
|
|
this.Priority = priority;
|
|
this.condition = condition;
|
|
this.onReflection = onReflection;
|
|
}
|
|
}
|
|
} |