Skip to content

Commit 6ee0fe9

Browse files
authored
improve snake script (#350)
* add: cut countdown * update version, refactor
1 parent f683873 commit 6ee0fe9

File tree

1 file changed

+50
-33
lines changed

1 file changed

+50
-33
lines changed

SplatoonScripts/Duties/Dawntrail/M12S P1 Snake.cs

Lines changed: 50 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace SplatoonScriptsOfficial.Duties.Dawntrail;
2020

2121
public class M12S_P1_Snake : SplatoonScript
2222
{
23-
public override Metadata Metadata { get; } = new(4, "NightmareXIV, Garume");
23+
public override Metadata Metadata { get; } = new(5, "NightmareXIV, Garume");
2424
public override HashSet<uint>? ValidTerritories { get; } = [1327];
2525

2626
public enum Debuff
@@ -147,12 +147,13 @@ public sealed class BlackTowerInfo
147147

148148
public override void OnSetup()
149149
{
150-
Controller.RegisterElementFromCode("TowerWaiting", """{"Name":"","refX":96.0,"refY":96.0,"radius":4.5,"Donut":0.5,"color":3355508719,"fillIntensity":0.281}""");
150+
Controller.RegisterElementFromCode("TowerWaiting", """{"Name":"","refX":96.0,"refY":96.0,"radius":2,"Donut":0.5,"color":3355508719,"fillIntensity":0.281}""");
151151
Controller.RegisterElementFromCode("TowerGet", """
152-
{"Name":"","refX":96.0,"refY":96.0,"radius":4.5,"Donut":0.5,"color":3357277952,"fillIntensity":1.0,"thicc":5.0,"tether":true}
152+
{"Name":"","refX":96.0,"refY":96.0,"radius":2,"Donut":0.5,"color":3357277952,"fillIntensity":1.0,"thicc":4.0,"tether":true}
153153
""");
154154
Controller.RegisterElementFromCode("CutGuide", """{"Name":"","type":0,"radius":2.0,"thicc":10.0,"tether":true}""");
155155
Controller.RegisterElementFromCode("ExitDoor", """{"Name":"","type":1,"offY":10.0,"radius":2.35,"refActorDataID":19195,"refActorComparisonType":3,"includeRotation":true,"color":4294967040,"fillIntensity":0.25,"thicc":3.0}""");
156+
Controller.RegisterElementFromCode("CutCountdown", """{"Name":"","type":1,"radius":0.0,"fillIntensity":0.5,"overlayBGColor":3355443200,"overlayTextColor":4294967295,"overlayVOffset":2.0,"overlayFScale":2.0,"thicc":0.0,"overlayText":"3","refActorType":1}""");
156157
}
157158

158159
bool MechanicActive => Controller.GetPartyMembers().Any(x => x.StatusList.Any(s => HasStatus(x, Debuff.Pos4)));
@@ -180,6 +181,7 @@ public override void OnReset()
180181
public override void OnUpdate()
181182
{
182183
Controller.Hide();
184+
UpdateCutCountdown();
183185
var exitActor = GetExitActor();
184186
if(exitActor != null )
185187
{
@@ -235,7 +237,7 @@ public override void OnUpdate()
235237
if(x.IsCasting(46259))
236238
{
237239
activeBlackCastingIds.Add(x.EntityId);
238-
if(!BlackTowers.Any(a => a.EntityId == x.EntityId))
240+
if(BlackTowers.All(a => a.EntityId != x.EntityId))
239241
{
240242
BlackTowers.Add(new BlackTowerInfo
241243
{
@@ -273,7 +275,6 @@ public override void OnUpdate()
273275
{
274276
var close = Controller.GetElementByName("Close");
275277
var cutGuide = Controller.GetElementByName("CutGuide");
276-
var blackWait = Controller.GetElementByName("TowerWaiting");
277278
var blackGet = Controller.GetElementByName("TowerGet");
278279
var nextColor = C.NextColor.ToUint();
279280
var nowColor = GradientColor.Get(C.NowColorA, C.NowColorB).ToUint();
@@ -286,10 +287,15 @@ public override void OnUpdate()
286287
int idx = me.TowerOrder.Value - 1;
287288
if(Towers.SafeSelect(idx) != default)
288289
{
289-
var te = RotationCount >= me.SoakRotation ? Controller.GetElementByName("TowerGet") : Controller.GetElementByName("TowerWaiting");
290+
var forceNow = me.PosNumber is 3 or 4;
291+
var ready = RotationCount >= me.SoakRotation;
292+
var forceGet = forceNow && RotationStarted;
293+
var afterCut = (me.PosNumber is 1 or 2) && RotationCount >= me.CutRotation + 1;
294+
var useGet = ready || forceGet || afterCut;
295+
var te = useGet ? Controller.GetElementByName("TowerGet") : Controller.GetElementByName("TowerWaiting");
290296
if(te != null)
291297
{
292-
te.color = RotationCount >= me.SoakRotation ? nowColor : nextColor;
298+
te.color = useGet ? nowColor : nextColor;
293299
te.SetRefPosition(Towers.SafeSelect(idx));
294300
te.Enabled = true;
295301
}
@@ -302,11 +308,6 @@ public override void OnUpdate()
302308
}
303309
else if(me.Group == DebuffGroup.Beta)
304310
{
305-
// var bt = GetBlackTowerInfo(me.TowerOrder);
306-
// var soakDone = (bt != null && bt.Removed) || (me.SoakRotation != null && RotationCount > me.SoakRotation);
307-
// var allowCut = soakDone || me.SoakRotation == null || me.CutRotation <= me.SoakRotation;
308-
// var hasBetaNow = BasePlayer != null && HasStatus(Debuff.Beta);
309-
// if(allowCut && hasBetaNow)
310311
var betaRemaining = GetRemainingTime(Debuff.Beta);
311312
if ((betaRemaining < 3f && betaRemaining != 0f) || HasStatus(Debuff.AfterBeta))
312313
{
@@ -321,14 +322,11 @@ public override void OnUpdate()
321322
}
322323
else if(IsBlackTowerActive(idx))
323324
{
324-
var spawnRot = GetBlackTowerSpawnRotation(idx);
325-
var shouldGet = me.SoakRotation != null && RotationCount >= me.SoakRotation && RotationCount > spawnRot;
326-
var be = shouldGet ? blackGet : blackWait;
327-
if(be != null)
325+
if(blackGet != null)
328326
{
329-
be.color = shouldGet ? nowColor : nextColor;
330-
be.SetRefPosition(GetBlackTowerPos(idx));
331-
be.Enabled = true;
327+
blackGet.color = nowColor;
328+
blackGet.SetRefPosition(GetBlackTowerPos(idx));
329+
blackGet.Enabled = true;
332330
}
333331
}
334332
}
@@ -354,26 +352,12 @@ void UpdatePlayerDatas()
354352
return BasePlayer != null && PlayerDatas.TryGetValue(BasePlayer.EntityId, out var pd) ? pd : null;
355353
}
356354

357-
BlackTowerInfo? GetBlackTowerInfo(int? order)
358-
{
359-
if(order == null) return null;
360-
int idx = order.Value - 1;
361-
if(idx < 0 || idx >= BlackTowers.Count) return null;
362-
return BlackTowers[idx];
363-
}
364-
365355
Vector3 GetBlackTowerPos(int idx)
366356
{
367357
if(idx < 0 || idx >= BlackTowers.Count) return default;
368358
return BlackTowers[idx].Position;
369359
}
370360

371-
int GetBlackTowerSpawnRotation(int idx)
372-
{
373-
if(idx < 0 || idx >= BlackTowers.Count) return -1;
374-
return BlackTowers[idx].SpawnRotation;
375-
}
376-
377361
bool IsBlackTowerActive(int idx)
378362
{
379363
if(idx < 0 || idx >= BlackTowers.Count) return false;
@@ -451,6 +435,36 @@ bool HasStatus(IBattleChara b, Debuff d)
451435
return b.StatusList.Any(x => x.StatusId == (uint)d);
452436
}
453437

438+
void UpdateCutCountdown()
439+
{
440+
var countdown = Controller.GetElementByName("CutCountdown");
441+
if(countdown == null || BasePlayer == null) return;
442+
if(C.CutCountdownSeconds <= 0f)
443+
{
444+
countdown.Enabled = false;
445+
return;
446+
}
447+
float remaining = 0f;
448+
if(HasStatus(Debuff.Alpha))
449+
{
450+
remaining = GetRemainingTime(Debuff.Alpha);
451+
}
452+
else if(HasStatus(Debuff.Beta))
453+
{
454+
remaining = GetRemainingTime(Debuff.Beta);
455+
}
456+
457+
if(remaining > 0f && remaining <= C.CutCountdownSeconds)
458+
{
459+
countdown.overlayText = MathF.Ceiling(remaining).ToString();
460+
countdown.Enabled = true;
461+
}
462+
else
463+
{
464+
countdown.Enabled = false;
465+
}
466+
}
467+
454468
public override void OnSettingsDraw()
455469
{
456470
ImGui.Separator();
@@ -466,6 +480,8 @@ public override void OnSettingsDraw()
466480
ImGui.ColorEdit4("Next (Waiting)", ref C.NextColor, ImGuiColorEditFlags.NoInputs);
467481
ImGui.ColorEdit4("Now Color A", ref C.NowColorA, ImGuiColorEditFlags.NoInputs);
468482
ImGui.ColorEdit4("Now Color B", ref C.NowColorB, ImGuiColorEditFlags.NoInputs);
483+
ImGui.SetNextItemWidth(150);
484+
ImGui.DragFloat("Cut countdown seconds", ref C.CutCountdownSeconds, 0.1f, 0f, 10f);
469485

470486
if(ImGui.CollapsingHeader("Debug"))
471487
{
@@ -497,5 +513,6 @@ public class Config : IEzConfig
497513
public Vector4 NextColor = ImGuiColors.DalamudYellow;
498514
public Vector4 NowColorA = 0xFF00FF00.ToVector4();
499515
public Vector4 NowColorB = 0xFF0000FF.ToVector4();
516+
public float CutCountdownSeconds = 3f;
500517
}
501518
}

0 commit comments

Comments
 (0)