Skip to content

Commit

Permalink
技能系统重写加部分问题修复
Browse files Browse the repository at this point in the history
  • Loading branch information
YongAn404 committed Aug 30, 2024
1 parent 27e2890 commit 1d084f2
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 50 deletions.
10 changes: 5 additions & 5 deletions Players/FramePlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ internal void UpdateShowInfoList()
}
else
{
if (!string.IsNullOrEmpty(CustomRolePlus.NameColor))
if (CustomRolePlus != null)
{
ExPlayer.RankColor = CustomRolePlus.NameColor;
}
Expand All @@ -141,7 +141,7 @@ internal void UpdateShowInfoList()
}
}

if (!string.IsNullOrEmpty(CustomRolePlus.Name))
if (CustomRolePlus != null)
{
ExPlayer.RankName = $"{CustomRolePlus.Name} *{usingRankTitles.Name}*";
}
Expand Down Expand Up @@ -170,11 +170,11 @@ internal void UpdateShowInfoList()
}
else
{
if (!string.IsNullOrEmpty(CustomRolePlus.Name))
if (CustomRolePlus != null)
{
ExPlayer.RankName = CustomRolePlus.Name;
}
if (!string.IsNullOrEmpty(CustomRolePlus.NameColor))
if (CustomRolePlus != null)
{
ExPlayer.RankColor = CustomRolePlus.NameColor;
}
Expand All @@ -191,7 +191,7 @@ private IEnumerator<float> DynamicProTitlesShow(string name = null)
{
if (name != null)
{
ExPlayer.RankName = $"{name ?? name} *{command[0]}*";
ExPlayer.RankName = $"{name} *{command[0]}*";
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion Players/HintManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public IEnumerator<float> Update()
used++;
foreach (string data in CustomText1)
{
text[used] = data;
text[used] = data ?? string.Empty;
used++;
}
used++;
Expand Down
53 changes: 32 additions & 21 deletions Roles/CustomRolePlus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public abstract class CustomRolePlus : CustomRole
public virtual RoleTypeId OldRole { get; set; } = RoleTypeId.None;

#region Static
public static List<FramePlayer> RespawnTeamPlayer { get; private set; } = [];
public static int SpawnChanceNum { get; private set; } = Loader.Random.StrictNext(1, 101);
public static int RespawnWave { get; private set; } = 0;
public static void SubscribeStaticEvents()
Expand Down Expand Up @@ -61,7 +60,7 @@ private static void OnStaticRoundStarted()
}
private static void OnStaticRespawningTeam(RespawningTeamEventArgs args)
{
RespawnTeamPlayer = args.Players.Select(FramePlayer.Get).ToList();
RespawnWave++;
}
#endregion

Expand Down Expand Up @@ -104,11 +103,15 @@ public virtual void AddRole(FramePlayer fPlayer)
}
public virtual void AddRoleData(FramePlayer fPlayer)
{
BaseData.Add(fPlayer, new CustomRolePlusProperties());
CustomRolePlusProperties properties = new();
BaseData.Add(fPlayer, properties);
if (this is ISkill skill)
{
SkillManager skillsManager = new(fPlayer, skill);
BaseData[fPlayer].SkillsManager = skillsManager;
properties.SkillManagers = new SkillManager[skill.SkillProperties.Length];
for (int i = 0; i < skill.SkillProperties.Length; i++)
{
properties.SkillManagers[i] = new(fPlayer, skill, (byte)(i + 1));
}
}
}
public override void RemoveRole(Player player)
Expand Down Expand Up @@ -184,7 +187,7 @@ private void OnSpawning(SpawningEventArgs args)
break;
case RefreshTeamType.MTF:
case RefreshTeamType.CI:
if (SpawnProperties.RefreshTeam != RefreshTeamType.Start && RespawnTeamPlayer.Contains(fPlayer) && SpawnProperties.StartWave <= RespawnWave)
if (SpawnProperties.StartWave <= RespawnWave)
{
TrySpawn(fPlayer);
}
Expand All @@ -197,22 +200,26 @@ private void OnDroppingItem(DroppingItemEventArgs args)
FramePlayer fPlayer = args.Player.ToFPlayer();
if (Check(fPlayer, out CustomRolePlusProperties data))
{
if (args.Item.Type == ItemType.Coin && data.SkillsManager != null)
foreach (var skillsManager in data.SkillManagers)
{
if (data.SkillsManager.IsActive)
if (skillsManager != null && args.Item.Type == skillsManager.SkillProperties.UseItem)
{
fPlayer.HintManager.MessageTexts.Add(new HintManager.Text("技能正在持续", 5));
}
else if (data.SkillsManager.IsBurial)
{
fPlayer.HintManager.MessageTexts.Add(new HintManager.Text($"技能正在冷却(CD:{data.SkillsManager.BurialRemainingTime})", 5));
}
else
{
data.SkillsManager.Run(0);
if (skillsManager.IsActive)
{
fPlayer.HintManager.MessageTexts.Add(new HintManager.Text("技能正在持续", 5));
}
else if (skillsManager.IsBurial)
{
fPlayer.HintManager.MessageTexts.Add(new HintManager.Text($"技能正在冷却(CD:{skillsManager.BurialRemainingTime})", 5));
}
else
{
skillsManager.Run();
}
args.IsAllowed = false;
}
args.IsAllowed = false;
}

}
}
private void OnHurting(HurtingEventArgs args)
Expand Down Expand Up @@ -345,11 +352,15 @@ public virtual bool Check(FramePlayer player, out T data)

public override void AddRoleData(FramePlayer fPlayer)
{
BaseData.Add(fPlayer, new T());
T properties = new T();
BaseData.Add(fPlayer, properties);
if (this is ISkill skill)
{
SkillManager skillsManager = new(fPlayer, skill);
BaseData[fPlayer].SkillsManager = skillsManager;
properties.SkillManagers = new SkillManager[skill.SkillProperties.Length];
for (int i = 0; i < skill.SkillProperties.Length; i++)
{
properties.SkillManagers[i] = new(fPlayer, skill, (byte)(i + 1));
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Roles/Interfaces/ISkillActiveEnd.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ public interface ISkillActiveEnd : ISkill
/// </summary>
/// <param name="yPlayer"></param>
/// <returns>方法的音乐文件名称</returns>
string ActiveEnd(FramePlayer yPlayer);
string ActiveEnd(FramePlayer yPlayer,byte id);
}
}
2 changes: 1 addition & 1 deletion Roles/Interfaces/ISkillActiveStart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ namespace YongAnFrame.Roles.Interfaces
{
public interface ISkillActiveStart : ISkill
{
string ActiveStart(FramePlayer yPlayer);
string ActiveStart(FramePlayer yPlayer,byte id);
}
}
2 changes: 1 addition & 1 deletion Roles/Interfaces/ISkillBurialEnd.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ namespace YongAnFrame.Roles.Interfaces
{
public interface ISkillBurialEnd : ISkill
{
string BurialEnd(FramePlayer yPlayer);
string BurialEnd(FramePlayer yPlayer,byte id);
}
}
2 changes: 1 addition & 1 deletion Roles/MusicManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public AudioPlayerBase Play(string musicFile, string npcName, TrackEvent trackEv
AudioPlayerBase audioPlayerBase = null;
try
{
OnTrackLoaded += trackEvent.TrackLoaded ?? trackEvent.TrackLoaded;
OnTrackLoaded += trackEvent.TrackLoaded;
if (!MusicNpc.TryGetValue(npcName, out ReferenceHub npc))
{
npc = CreateMusicNpc(npcName);
Expand Down
2 changes: 1 addition & 1 deletion Roles/Properties/CustomRolePlusProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class CustomRolePlusProperties
/// <summary>
/// 技能管理器
/// </summary>
public SkillManager SkillsManager { get; set; }
public SkillManager[] SkillManagers { get; set; }
/// <summary>
/// 是否正常死亡
/// </summary>
Expand Down
8 changes: 5 additions & 3 deletions Roles/Properties/SkillProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@
{
public struct SkillProperties
{
public SkillProperties(string name, string statement, string description, float activeMaxTime, float burialMaxTime)
public SkillProperties(string name, string statement, string description, float activeMaxTime, float burialMaxTime, ItemType useItem = ItemType.Coin)
{
Name = name;
Statement = statement;
Description = description;
ActiveMaxTime = activeMaxTime;
BurialMaxTime = burialMaxTime;
UseItem = useItem;
}
public string Name { get; }
public ItemType UseItem { get; }
public string Statement { get; }
public string Description { get; }
public float ActiveMaxTime { get; set; }
public float BurialMaxTime { get; set; }
public float ActiveMaxTime { get; }
public float BurialMaxTime { get; }
}
}
28 changes: 14 additions & 14 deletions Roles/SkillManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class SkillManager
private readonly FramePlayer fPlayer;

private readonly ISkill skill;
public byte Id { get; }
private ISkillActiveStart SkillActiveStart
{
get
Expand Down Expand Up @@ -45,7 +46,7 @@ private ISkillBurialEnd SkillBurialEnd
return null;
}
}
public SkillProperties[] SkillProperties { get => skill.SkillProperties; }
public SkillProperties SkillProperties { get => skill.SkillProperties[Id]; }

public int SkillsEffectSwitchId { get; set; }
/// <summary>
Expand All @@ -59,50 +60,49 @@ private ISkillBurialEnd SkillBurialEnd
public float ActiveRemainingTime { get; private set; }
public float BurialRemainingTime { get; private set; }

private CoroutineHandle[] coroutineHandle;
private CoroutineHandle coroutineHandle;

public SkillManager(FramePlayer fPlayer, ISkill skill)
public SkillManager(FramePlayer fPlayer, ISkill skill,byte Id)
{
this.fPlayer = fPlayer;
this.skill = skill;
coroutineHandle = new CoroutineHandle[SkillProperties.Length];
this.Id = Id;
}


/// <summary>
/// 有计时任务会直接覆盖
/// </summary>
public void Run(int id)
public void Run()
{
if (coroutineHandle != null)
{
Timing.KillCoroutines(coroutineHandle[id]);
coroutineHandle = null;
Timing.KillCoroutines(coroutineHandle);
}

ActiveRemainingTime = SkillProperties[id].ActiveMaxTime;
BurialRemainingTime = SkillProperties[id].BurialMaxTime;
ActiveRemainingTime = SkillProperties.ActiveMaxTime;
BurialRemainingTime = SkillProperties.BurialMaxTime;

coroutineHandle[id] = Timing.RunCoroutine(Timer(id));
coroutineHandle = Timing.RunCoroutine(Timer());
}

private IEnumerator<float> Timer(int id)
private IEnumerator<float> Timer()
{
string musicFileName = SkillActiveStart?.ActiveStart(fPlayer);
string musicFileName = SkillActiveStart?.ActiveStart(fPlayer, Id);
if (musicFileName != null) Instance.Play(musicFileName, $"技能发动语音", new TrackEvent(), fPlayer, 10);
while (IsActive)
{
ActiveRemainingTime--;
yield return Timing.WaitForSeconds(1f);
}
musicFileName = SkillActiveEnd?.ActiveEnd(fPlayer);
musicFileName = SkillActiveEnd?.ActiveEnd(fPlayer, Id);
if (musicFileName != null) Instance.Play(musicFileName, $"技能结束语音", new TrackEvent(), fPlayer, 10);
while (IsBurial)
{
BurialRemainingTime--;
yield return Timing.WaitForSeconds(1f);
}
musicFileName = SkillBurialEnd?.BurialEnd(fPlayer);
musicFileName = SkillBurialEnd?.BurialEnd(fPlayer,Id);
if (musicFileName != null) Instance.Play(musicFileName, $"技能准备好语音", new TrackEvent(), fPlayer, 10);
}
}
Expand Down
1 change: 0 additions & 1 deletion YongAnFrame.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@
</ItemGroup>
<ItemGroup>
<Folder Include="Components\" />
<Folder Include="Roles\Manager\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
Expand Down

0 comments on commit 1d084f2

Please sign in to comment.