228 lines
7.8 KiB
C#
228 lines
7.8 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using BITKit;
|
|
using BITKit.Entities;
|
|
using BITKit.UX;
|
|
using BITKit.UX.Hotkey;
|
|
using Cysharp.Threading.Tasks;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Net.BITKit.UX.SnackBar;
|
|
using Net.Project.B.Buff;
|
|
using Net.Project.B.Health;
|
|
using Net.Project.B.Item;
|
|
using Net.Project.B.Level;
|
|
using Net.Project.B.PDA;
|
|
using Net.Project.B.UX;
|
|
using Project.B.CharacterController;
|
|
using Project.B.Entities;
|
|
using Project.B.Item;
|
|
using Unity.Mathematics;
|
|
using UnityEngine;
|
|
using UnityEngine.InputSystem;
|
|
|
|
namespace Net.Project.B
|
|
{
|
|
public class CheatService:IDisposable
|
|
{
|
|
private readonly ISnackBar _snackBar;
|
|
private readonly IUXHotKey _hotKey;
|
|
private readonly IEntitiesService _entitiesService;
|
|
private readonly IPlayerFactory _playerFactory;
|
|
private readonly IHealthService _healthService;
|
|
private readonly IMainTicker _mainTicker;
|
|
private GameObject _playerGameObject;
|
|
private IPlayerCharacterController _playerCharacterController;
|
|
private IEntity _player;
|
|
|
|
private bool _hideHud;
|
|
private bool _noHunger;
|
|
|
|
private readonly HotkeyCollection _hotkeyCollection;
|
|
|
|
public CheatService(IPlayerFactory playerFactory, IHealthService healthService, IMainTicker mainTicker, IEntitiesService entitiesService, IUXHotKey hotKey, ISnackBar snackBar)
|
|
{
|
|
_playerFactory = playerFactory;
|
|
_healthService = healthService;
|
|
_mainTicker = mainTicker;
|
|
_entitiesService = entitiesService;
|
|
_hotKey = hotKey;
|
|
_snackBar = snackBar;
|
|
|
|
_playerFactory.OnEntityCreated += OnEntityCreated;
|
|
_mainTicker.Add(OnTick);
|
|
|
|
_hotkeyCollection = new HotkeyCollection();
|
|
|
|
_hotkeyCollection.Register(new HotkeyProvider()
|
|
{
|
|
Name = "切换HUD显示",
|
|
Description = "通常用于拍视频",
|
|
Enabled = true,
|
|
OnPerform = () =>
|
|
{
|
|
BITApp.ServiceProvider.QueryComponents(out IUXHud uxHud);
|
|
uxHud.InCinematicMode.SetElements(this,_hideHud=!_hideHud);
|
|
_snackBar.Add($"已切换HUD.HideHud:{_hideHud}");
|
|
}
|
|
});
|
|
|
|
_hotkeyCollection.Register(new HotkeyProvider()
|
|
{
|
|
Name = "切换不再饥饿",
|
|
Enabled = true,
|
|
Description = "保持所有生存数值为100",
|
|
OnPerform = ()=>
|
|
{
|
|
_noHunger = !_noHunger;
|
|
_snackBar.Add($"已切换不再饥饿.NoHunger:{_noHunger}");
|
|
}
|
|
});
|
|
|
|
_hotkeyCollection.Register(new HotkeyProvider()
|
|
{
|
|
Name = "传送到鼠标位置",
|
|
Enabled = true,
|
|
Description = "快速传送",
|
|
OnPerform = Teleport,
|
|
});
|
|
|
|
_hotkeyCollection.Register(new HotkeyProvider()
|
|
{
|
|
Name = "获取所有物品",
|
|
Enabled = true,
|
|
Description = "可能会很卡",
|
|
OnPerform = GetAllItem
|
|
});
|
|
}
|
|
|
|
private void GetAllItem()
|
|
{
|
|
var (_,characterController) = _entitiesService.QueryComponents<LocalPlayerComponent, ICharacterController>()[0];
|
|
|
|
BITApp.ServiceProvider.QueryComponents(out IManagedItemService managedItemService);
|
|
|
|
foreach (var scriptableItem in _entitiesService.QueryComponents<ScriptableItem>())
|
|
{
|
|
managedItemService.InstanceItem(characterController.Position, characterController.Rotation,
|
|
scriptableItem.CreateRuntimeItem());
|
|
}
|
|
|
|
_snackBar.Add("已获取所有物品");
|
|
}
|
|
|
|
private void Teleport()
|
|
{
|
|
var (_,characterController) = _entitiesService.QueryComponents<LocalPlayerComponent, ICharacterController>()[0];
|
|
|
|
if (Physics.Raycast(characterController.ViewPosition, (Quaternion)characterController.ViewRotation * Vector3.forward,
|
|
out var hit,1024,layerMask:LayerMask.GetMask("Default")))
|
|
{
|
|
characterController.Position = hit.point;
|
|
|
|
_snackBar.Add("已传送到鼠标位置");
|
|
}
|
|
else
|
|
{
|
|
_snackBar.Add("无法传送到鼠标位置");
|
|
}
|
|
|
|
}
|
|
|
|
private UniTask OnEntityCreated(string arg1, IEntity arg2)
|
|
{
|
|
_player = arg2;
|
|
|
|
_player.ServiceProvider.QueryComponents(out _playerCharacterController, out _playerGameObject);
|
|
|
|
return UniTask.CompletedTask;
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
_mainTicker.Remove(OnTick);
|
|
}
|
|
|
|
private void OnTick(float obj)
|
|
{
|
|
/*
|
|
if (Keyboard.current.upArrowKey.wasPressedThisFrame)
|
|
{
|
|
BITApp.ServiceProvider.QueryComponents(out IUXService uxService,out IPDAService pdaService);
|
|
if (pdaService is IUXPanel panel)
|
|
{
|
|
uxService.Entry(panel);
|
|
}
|
|
}
|
|
*/
|
|
|
|
if (_noHunger)
|
|
{
|
|
foreach (var (_,buffComponent) in _entitiesService.QueryComponents<LocalPlayerComponent,IBuffComponent>())
|
|
{
|
|
for (var i = 0; i < buffComponent.Buffs.Length; i++)
|
|
{
|
|
ref var buff =ref buffComponent.Buffs.Span[i];
|
|
|
|
buff.Value = 100;
|
|
}
|
|
}
|
|
}
|
|
|
|
if(!_playerGameObject)return;
|
|
|
|
|
|
if (Keyboard.current is { f12Key: { wasPressedThisFrame: true } })
|
|
{
|
|
_hotKey.Perform(_hotkeyCollection);
|
|
}
|
|
|
|
if (Keyboard.current.numpad8Key.wasPressedThisFrame)
|
|
{
|
|
|
|
_playerCharacterController.CharacterController.Velocity+=(float3)
|
|
(
|
|
(Quaternion) _playerCharacterController.CharacterController.ViewRotation * Vector3.forward * 8);
|
|
}
|
|
|
|
if (Keyboard.current.pageUpKey.wasPressedThisFrame)
|
|
{
|
|
foreach (var (_,levelComponent) in _entitiesService.QueryComponents<LocalPlayerComponent,LevelComponent>())
|
|
{
|
|
levelComponent.AddExp(10);
|
|
}
|
|
}
|
|
if (Keyboard.current.numpad5Key.wasPressedThisFrame)
|
|
{
|
|
var currentVelocity = _playerCharacterController.CharacterController.Velocity;
|
|
|
|
if (currentVelocity.y < 0)
|
|
{
|
|
currentVelocity = 0;
|
|
_playerCharacterController.CharacterController.Velocity = currentVelocity;
|
|
}
|
|
|
|
var y = _playerCharacterController.CharacterController.Velocity;
|
|
_playerCharacterController.CharacterController.Velocity += new float3(0, 8, 0);
|
|
}
|
|
if (Keyboard.current.numpad1Key.wasPressedThisFrame)
|
|
{
|
|
HealthService.SetHealth(_player.Id,-1);
|
|
}
|
|
if (Keyboard.current.numpad0Key.wasPressedThisFrame)
|
|
{
|
|
HealthService.SetHealth(_player.Id,100);
|
|
}
|
|
if (Keyboard.current.numpadMinusKey.wasPressedThisFrame)
|
|
{
|
|
HealthService.AddHealth(_player.Id,-30);
|
|
}
|
|
if (Keyboard.current.numpadPlusKey.wasPressedThisFrame)
|
|
{
|
|
HealthService.AddHealth(_player.Id,30);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|