Skip to content

Commit 1d084f2

Browse files
committed
技能系统重写加部分问题修复
1 parent 27e2890 commit 1d084f2

11 files changed

+62
-50
lines changed

Players/FramePlayer.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ internal void UpdateShowInfoList()
131131
}
132132
else
133133
{
134-
if (!string.IsNullOrEmpty(CustomRolePlus.NameColor))
134+
if (CustomRolePlus != null)
135135
{
136136
ExPlayer.RankColor = CustomRolePlus.NameColor;
137137
}
@@ -141,7 +141,7 @@ internal void UpdateShowInfoList()
141141
}
142142
}
143143

144-
if (!string.IsNullOrEmpty(CustomRolePlus.Name))
144+
if (CustomRolePlus != null)
145145
{
146146
ExPlayer.RankName = $"{CustomRolePlus.Name} *{usingRankTitles.Name}*";
147147
}
@@ -170,11 +170,11 @@ internal void UpdateShowInfoList()
170170
}
171171
else
172172
{
173-
if (!string.IsNullOrEmpty(CustomRolePlus.Name))
173+
if (CustomRolePlus != null)
174174
{
175175
ExPlayer.RankName = CustomRolePlus.Name;
176176
}
177-
if (!string.IsNullOrEmpty(CustomRolePlus.NameColor))
177+
if (CustomRolePlus != null)
178178
{
179179
ExPlayer.RankColor = CustomRolePlus.NameColor;
180180
}
@@ -191,7 +191,7 @@ private IEnumerator<float> DynamicProTitlesShow(string name = null)
191191
{
192192
if (name != null)
193193
{
194-
ExPlayer.RankName = $"{name ?? name} *{command[0]}*";
194+
ExPlayer.RankName = $"{name} *{command[0]}*";
195195
}
196196
else
197197
{

Players/HintManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public IEnumerator<float> Update()
4242
used++;
4343
foreach (string data in CustomText1)
4444
{
45-
text[used] = data;
45+
text[used] = data ?? string.Empty;
4646
used++;
4747
}
4848
used++;

Roles/CustomRolePlus.cs

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ public abstract class CustomRolePlus : CustomRole
3030
public virtual RoleTypeId OldRole { get; set; } = RoleTypeId.None;
3131

3232
#region Static
33-
public static List<FramePlayer> RespawnTeamPlayer { get; private set; } = [];
3433
public static int SpawnChanceNum { get; private set; } = Loader.Random.StrictNext(1, 101);
3534
public static int RespawnWave { get; private set; } = 0;
3635
public static void SubscribeStaticEvents()
@@ -61,7 +60,7 @@ private static void OnStaticRoundStarted()
6160
}
6261
private static void OnStaticRespawningTeam(RespawningTeamEventArgs args)
6362
{
64-
RespawnTeamPlayer = args.Players.Select(FramePlayer.Get).ToList();
63+
RespawnWave++;
6564
}
6665
#endregion
6766

@@ -104,11 +103,15 @@ public virtual void AddRole(FramePlayer fPlayer)
104103
}
105104
public virtual void AddRoleData(FramePlayer fPlayer)
106105
{
107-
BaseData.Add(fPlayer, new CustomRolePlusProperties());
106+
CustomRolePlusProperties properties = new();
107+
BaseData.Add(fPlayer, properties);
108108
if (this is ISkill skill)
109109
{
110-
SkillManager skillsManager = new(fPlayer, skill);
111-
BaseData[fPlayer].SkillsManager = skillsManager;
110+
properties.SkillManagers = new SkillManager[skill.SkillProperties.Length];
111+
for (int i = 0; i < skill.SkillProperties.Length; i++)
112+
{
113+
properties.SkillManagers[i] = new(fPlayer, skill, (byte)(i + 1));
114+
}
112115
}
113116
}
114117
public override void RemoveRole(Player player)
@@ -184,7 +187,7 @@ private void OnSpawning(SpawningEventArgs args)
184187
break;
185188
case RefreshTeamType.MTF:
186189
case RefreshTeamType.CI:
187-
if (SpawnProperties.RefreshTeam != RefreshTeamType.Start && RespawnTeamPlayer.Contains(fPlayer) && SpawnProperties.StartWave <= RespawnWave)
190+
if (SpawnProperties.StartWave <= RespawnWave)
188191
{
189192
TrySpawn(fPlayer);
190193
}
@@ -197,22 +200,26 @@ private void OnDroppingItem(DroppingItemEventArgs args)
197200
FramePlayer fPlayer = args.Player.ToFPlayer();
198201
if (Check(fPlayer, out CustomRolePlusProperties data))
199202
{
200-
if (args.Item.Type == ItemType.Coin && data.SkillsManager != null)
203+
foreach (var skillsManager in data.SkillManagers)
201204
{
202-
if (data.SkillsManager.IsActive)
205+
if (skillsManager != null && args.Item.Type == skillsManager.SkillProperties.UseItem)
203206
{
204-
fPlayer.HintManager.MessageTexts.Add(new HintManager.Text("技能正在持续", 5));
205-
}
206-
else if (data.SkillsManager.IsBurial)
207-
{
208-
fPlayer.HintManager.MessageTexts.Add(new HintManager.Text($"技能正在冷却(CD:{data.SkillsManager.BurialRemainingTime})", 5));
209-
}
210-
else
211-
{
212-
data.SkillsManager.Run(0);
207+
if (skillsManager.IsActive)
208+
{
209+
fPlayer.HintManager.MessageTexts.Add(new HintManager.Text("技能正在持续", 5));
210+
}
211+
else if (skillsManager.IsBurial)
212+
{
213+
fPlayer.HintManager.MessageTexts.Add(new HintManager.Text($"技能正在冷却(CD:{skillsManager.BurialRemainingTime})", 5));
214+
}
215+
else
216+
{
217+
skillsManager.Run();
218+
}
219+
args.IsAllowed = false;
213220
}
214-
args.IsAllowed = false;
215221
}
222+
216223
}
217224
}
218225
private void OnHurting(HurtingEventArgs args)
@@ -345,11 +352,15 @@ public virtual bool Check(FramePlayer player, out T data)
345352

346353
public override void AddRoleData(FramePlayer fPlayer)
347354
{
348-
BaseData.Add(fPlayer, new T());
355+
T properties = new T();
356+
BaseData.Add(fPlayer, properties);
349357
if (this is ISkill skill)
350358
{
351-
SkillManager skillsManager = new(fPlayer, skill);
352-
BaseData[fPlayer].SkillsManager = skillsManager;
359+
properties.SkillManagers = new SkillManager[skill.SkillProperties.Length];
360+
for (int i = 0; i < skill.SkillProperties.Length; i++)
361+
{
362+
properties.SkillManagers[i] = new(fPlayer, skill, (byte)(i + 1));
363+
}
353364
}
354365
}
355366
}

Roles/Interfaces/ISkillActiveEnd.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ public interface ISkillActiveEnd : ISkill
99
/// </summary>
1010
/// <param name="yPlayer"></param>
1111
/// <returns>方法的音乐文件名称</returns>
12-
string ActiveEnd(FramePlayer yPlayer);
12+
string ActiveEnd(FramePlayer yPlayer,byte id);
1313
}
1414
}

Roles/Interfaces/ISkillActiveStart.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ namespace YongAnFrame.Roles.Interfaces
44
{
55
public interface ISkillActiveStart : ISkill
66
{
7-
string ActiveStart(FramePlayer yPlayer);
7+
string ActiveStart(FramePlayer yPlayer,byte id);
88
}
99
}

Roles/Interfaces/ISkillBurialEnd.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ namespace YongAnFrame.Roles.Interfaces
44
{
55
public interface ISkillBurialEnd : ISkill
66
{
7-
string BurialEnd(FramePlayer yPlayer);
7+
string BurialEnd(FramePlayer yPlayer,byte id);
88
}
99
}

Roles/MusicManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public AudioPlayerBase Play(string musicFile, string npcName, TrackEvent trackEv
5959
AudioPlayerBase audioPlayerBase = null;
6060
try
6161
{
62-
OnTrackLoaded += trackEvent.TrackLoaded ?? trackEvent.TrackLoaded;
62+
OnTrackLoaded += trackEvent.TrackLoaded;
6363
if (!MusicNpc.TryGetValue(npcName, out ReferenceHub npc))
6464
{
6565
npc = CreateMusicNpc(npcName);

Roles/Properties/CustomRolePlusProperties.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class CustomRolePlusProperties
1010
/// <summary>
1111
/// 技能管理器
1212
/// </summary>
13-
public SkillManager SkillsManager { get; set; }
13+
public SkillManager[] SkillManagers { get; set; }
1414
/// <summary>
1515
/// 是否正常死亡
1616
/// </summary>

Roles/Properties/SkillProperties.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,20 @@
22
{
33
public struct SkillProperties
44
{
5-
public SkillProperties(string name, string statement, string description, float activeMaxTime, float burialMaxTime)
5+
public SkillProperties(string name, string statement, string description, float activeMaxTime, float burialMaxTime, ItemType useItem = ItemType.Coin)
66
{
77
Name = name;
88
Statement = statement;
99
Description = description;
1010
ActiveMaxTime = activeMaxTime;
1111
BurialMaxTime = burialMaxTime;
12+
UseItem = useItem;
1213
}
1314
public string Name { get; }
15+
public ItemType UseItem { get; }
1416
public string Statement { get; }
1517
public string Description { get; }
16-
public float ActiveMaxTime { get; set; }
17-
public float BurialMaxTime { get; set; }
18+
public float ActiveMaxTime { get; }
19+
public float BurialMaxTime { get; }
1820
}
1921
}

Roles/SkillManager.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public class SkillManager
1212
private readonly FramePlayer fPlayer;
1313

1414
private readonly ISkill skill;
15+
public byte Id { get; }
1516
private ISkillActiveStart SkillActiveStart
1617
{
1718
get
@@ -45,7 +46,7 @@ private ISkillBurialEnd SkillBurialEnd
4546
return null;
4647
}
4748
}
48-
public SkillProperties[] SkillProperties { get => skill.SkillProperties; }
49+
public SkillProperties SkillProperties { get => skill.SkillProperties[Id]; }
4950

5051
public int SkillsEffectSwitchId { get; set; }
5152
/// <summary>
@@ -59,50 +60,49 @@ private ISkillBurialEnd SkillBurialEnd
5960
public float ActiveRemainingTime { get; private set; }
6061
public float BurialRemainingTime { get; private set; }
6162

62-
private CoroutineHandle[] coroutineHandle;
63+
private CoroutineHandle coroutineHandle;
6364

64-
public SkillManager(FramePlayer fPlayer, ISkill skill)
65+
public SkillManager(FramePlayer fPlayer, ISkill skill,byte Id)
6566
{
6667
this.fPlayer = fPlayer;
6768
this.skill = skill;
68-
coroutineHandle = new CoroutineHandle[SkillProperties.Length];
69+
this.Id = Id;
6970
}
7071

7172

7273
/// <summary>
7374
/// 有计时任务会直接覆盖
7475
/// </summary>
75-
public void Run(int id)
76+
public void Run()
7677
{
7778
if (coroutineHandle != null)
7879
{
79-
Timing.KillCoroutines(coroutineHandle[id]);
80-
coroutineHandle = null;
80+
Timing.KillCoroutines(coroutineHandle);
8181
}
8282

83-
ActiveRemainingTime = SkillProperties[id].ActiveMaxTime;
84-
BurialRemainingTime = SkillProperties[id].BurialMaxTime;
83+
ActiveRemainingTime = SkillProperties.ActiveMaxTime;
84+
BurialRemainingTime = SkillProperties.BurialMaxTime;
8585

86-
coroutineHandle[id] = Timing.RunCoroutine(Timer(id));
86+
coroutineHandle = Timing.RunCoroutine(Timer());
8787
}
8888

89-
private IEnumerator<float> Timer(int id)
89+
private IEnumerator<float> Timer()
9090
{
91-
string musicFileName = SkillActiveStart?.ActiveStart(fPlayer);
91+
string musicFileName = SkillActiveStart?.ActiveStart(fPlayer, Id);
9292
if (musicFileName != null) Instance.Play(musicFileName, $"技能发动语音", new TrackEvent(), fPlayer, 10);
9393
while (IsActive)
9494
{
9595
ActiveRemainingTime--;
9696
yield return Timing.WaitForSeconds(1f);
9797
}
98-
musicFileName = SkillActiveEnd?.ActiveEnd(fPlayer);
98+
musicFileName = SkillActiveEnd?.ActiveEnd(fPlayer, Id);
9999
if (musicFileName != null) Instance.Play(musicFileName, $"技能结束语音", new TrackEvent(), fPlayer, 10);
100100
while (IsBurial)
101101
{
102102
BurialRemainingTime--;
103103
yield return Timing.WaitForSeconds(1f);
104104
}
105-
musicFileName = SkillBurialEnd?.BurialEnd(fPlayer);
105+
musicFileName = SkillBurialEnd?.BurialEnd(fPlayer,Id);
106106
if (musicFileName != null) Instance.Play(musicFileName, $"技能准备好语音", new TrackEvent(), fPlayer, 10);
107107
}
108108
}

0 commit comments

Comments
 (0)