Net.Like.Xue.Tokyo/Assets/Artists/Scripts/GodMod.cs

61 lines
1.5 KiB
C#
Raw Normal View History

2025-04-23 14:48:45 +08:00
using System;
using System.Collections;
using System.Collections.Generic;
using BITKit;
using Microsoft.Extensions.Logging;
using Net.Project.B.Health;
using UnityEngine;
using UnityEngine.InputSystem;
namespace Net.Like.Xue.Tokyo
{
public class GodMode:IDisposable
{
private readonly IHealthService _healthService;
private readonly ITicker _ticker;
private readonly ValidHandle _allow = new();
private readonly ILogger<GodMode> _logger;
public GodMode(ITicker ticker, IHealthService healthService, ILogger<GodMode> logger)
{
_ticker = ticker;
_healthService = healthService;
_logger = logger;
_ticker.Add(OnTick);
_healthService.OnHealthPlus += OnHealthPlus;
_allow.AddListener(x =>
{
logger.LogInformation(x ? "开启无敌" : "关闭无敌");
});
}
private int OnHealthPlus(int arg1, int arg2, int arg3, object arg4)
{
if (_allow.Allow)
{
return 0;
}
return arg3;
}
private void OnTick(float obj)
{
if (Keyboard.current is { homeKey: { wasPressedThisFrame: true } })
{
_allow.SetElements(this,!_allow.Allow);
}
}
public void Dispose()
{
_ticker.Remove(OnTick);
}
}
}