61 lines
1.5 KiB
C#
61 lines
1.5 KiB
C#
|
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);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|