-
Notifications
You must be signed in to change notification settings - Fork 4
/
DamageNumbers.cs
106 lines (86 loc) · 3.69 KB
/
DamageNumbers.cs
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
using BrokeProtocol.Entities;
using BrokeProtocolClient.settings;
using BrokeProtocolClient.utils;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace BrokeProtocolClient.modules.render
{
class DamageNumbers : Module
{
static NumberSetting verticalOffset = new NumberSetting("Vertical offset", 0, 10, 1, 0.5);
BooleanSetting onlyPlayers = new BooleanSetting("Only players", true);
NumberSetting lifetime = new NumberSetting("Number lifetime", 0.1, 5, 1, 0.1);
NumberSetting size = new NumberSetting("Number size", 1, 64, 16, 1);
NumberSetting randomOffset = new NumberSetting("Random offset", 0, 5, 1, 0.5);
ColorSetting color = new ColorSetting("Number color", Color.green);
List<NumberParticle> numbers = new List<NumberParticle>();
public DamageNumbers() : base(Categories.Render, "Damage Numbers", "Shows taken damage")
{
addSetting(onlyPlayers);
addSetting(lifetime);
addSetting(verticalOffset);
addSetting(randomOffset);
addSetting(size);
addSetting(color);
}
public override void onRender()
{
foreach(NumberParticle number in numbers)
{
number.render();
}
}
public void TookDamage(ShDestroyable destroyable, float damage)
{
// if damage is positive destroyable got healed
if (damage <= 0) return;
if (onlyPlayers.isEnabled() && !(destroyable is ShPlayer)) return;
Vector3 position = destroyable.GetOrigin.Random(randomOffset.getValueFloat());
getClient().StartCoroutine(CreateDamageNumber(damage, position));
}
IEnumerator CreateDamageNumber(float number, Vector3 position)
{
NumberParticle particle = new NumberParticle(number, position, size.getValueInt(), lifetime.getValueFloat(), color.getColor());
numbers.Add(particle);
yield return new WaitForSeconds(particle.lifetime);
numbers.Remove(particle);
}
class NumberParticle
{
public float lifetime;
public float number;
Vector3 startPos;
Vector3 pos;
Vector3 endPos;
float timealive;
int size;
Color color;
public NumberParticle(float number, Vector3 startPos, int size, float lifetime, Color color)
{
this.number = number;
this.lifetime = lifetime;
this.startPos = startPos;
this.size = size;
this.color = color;
pos = startPos;
endPos = startPos;
endPos.y += verticalOffset.getValueFloat();
timealive = 0;
}
public void render()
{
pos = Vector3.Lerp(pos, endPos, Time.deltaTime / lifetime);
timealive += Time.deltaTime;
// Start to fade out after 75% of the lifetime
float timefraction = 0.75f;
if (timealive > lifetime * timefraction)
color.a = Mathf.Lerp(color.a, 0, Time.deltaTime / lifetime / (1 - timefraction));
Color backgroundColor = new Color(0, 0, 0, color.a);
string label = number.ToString("0.#");
Render.DrawWorldString(pos, label, backgroundColor, size + 2, true);
Render.DrawWorldString(pos, label, color, size, true);
}
}
}
}