Repository navigation
Expand file tree
/
Copy pathDamageBoostModule.cs
More file actions
111 lines (97 loc) · 4 KB
/
Copy pathDamageBoostModule.cs
File metadata and controls
111 lines (97 loc) · 4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
using System;
using BepInEx.Configuration;
using HarmonyLib;
using UnityEngine;
namespace HTFToolkit
{
/// <summary>
/// 伤害倍率:Harmony 前缀改写 Server.HitCreature 的 damage —— 只放大本地玩家的攻击
/// (playerWhoHit == Player.LocalPlayer),其他玩家不受影响。爆头倍率在游戏内部
/// (TakeDamage 里 HeadShotDamageMulti)已先算好,此 patch 在其后叠加。
/// 近战/枪械/鱼叉等一切对生物的伤害都走 HitCreature 通道。可自行设置任意倍数。
/// </summary>
internal static class DamageBoostModule
{
public static bool Enabled;
private static float _mult = 3f;
/// <summary>最近一次设置的倍率。</summary>
public static float LastRequested => _mult;
public static void BindConfig(ConfigFile cfg)
{
}
public static void ApplyPatches(Harmony harmony)
{
try
{
var m = AccessTools.Method(typeof(Server), "HitCreature");
if (m != null)
{
harmony.Patch(m,
prefix: new HarmonyMethod(AccessTools.Method(typeof(DamageBoostModule), nameof(PrefixBoost))));
}
}
catch (Exception e)
{
Plugin.Log?.LogWarning($"DamageBoost patch failed: {e.Message}");
}
}
private static void PrefixBoost(Creature creature, Player playerWhoHit, ref int damage)
{
if (Enabled && damage > 0 && playerWhoHit != null && playerWhoHit == Player.LocalPlayer)
damage = Mathf.Max(1, Mathf.RoundToInt(damage * _mult));
}
public static void SetMultiplier(float mult)
{
if (mult <= 0f)
{
ToastModule.Show("伤害倍率需大于 0", Color.yellow);
return;
}
_mult = mult;
Enabled = true;
ToastModule.Show($"伤害倍率 ×{mult:0.##}", Color.white);
}
public static void Reset()
{
_mult = 1f;
Enabled = false;
ToastModule.Show("伤害倍率已恢复 ×1", Color.white);
}
// ---------------- 菜单 UI(工具页内嵌编辑器)----------------
private static string _inputMult = "3";
private static GUIStyle _fieldStyle;
private static GUIStyle _hintStyle;
public static void DrawEditor()
{
if (Event.current == null)
return;
if (_fieldStyle == null)
{
_fieldStyle = new GUIStyle(GUI.skin.textField)
{
fontSize = UIScale.TextFont,
alignment = TextAnchor.MiddleLeft
};
_hintStyle = new GUIStyle(GUI.skin.label)
{
normal = { textColor = new Color(0.75f, 0.75f, 0.75f) }
};
}
_fieldStyle.fontSize = UIScale.TextFont;
_hintStyle.fontSize = UIScale.HintFont;
GUILayout.BeginHorizontal();
_inputMult = GUILayout.TextField(_inputMult, _fieldStyle, GUILayout.Width(UIScale.W * 0.16f), GUILayout.Height(UIScale.ButtonH));
if (GUILayout.Button("设为该倍率", UIScale.ButtonStyle, GUILayout.Height(UIScale.ButtonH), GUILayout.Width(UIScale.W * 0.22f)))
{
if (float.TryParse((_inputMult ?? "").Trim(), out float v) && v > 0f)
SetMultiplier(v);
else
ToastModule.Show("倍率无效(需大于 0 的数字)", Color.yellow);
}
if (GUILayout.Button("恢复 ×1", UIScale.ButtonStyle, GUILayout.Height(UIScale.ButtonH), GUILayout.Width(UIScale.W * 0.18f)))
Reset();
GUILayout.EndHorizontal();
GUILayout.Label($"当前伤害倍率: ×{_mult:0.##}(对生物生效:近战/枪械/鱼叉)", _hintStyle);
}
}
}