-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathCotfUtils.cs
74 lines (64 loc) · 1.76 KB
/
CotfUtils.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
using System;
using System.Text.RegularExpressions;
using UnityEngine;
namespace ChampionsOfForest
{
public static class CotfUtils
{
//removes any non ascii characters from a name of the player
public static string TrimNonAscii(string value)
{
string pattern = "[^ -~]+";
Regex reg_exp = new Regex(pattern);
return reg_exp.Replace(value, "a");
}
public static void Log(string s, bool logFile = false)
{
if (logFile)
ModAPI.Log.Write(s);
ModAPI.Console.Write(s);
Debug.Log(s);
}
public static string ListAllChildren(Transform tr, string prefix)
{
string s = prefix + "•" + tr.name + " ";
var comps = tr.gameObject.GetComponents<Component>();
s += "( ";
foreach (var item in comps)
{
s += item.GetType().ToString() + ", ";
}
s += ")\n";
foreach (Transform child in tr)
{
s += ListAllChildren(child, prefix + " ");
}
return s;
}
}
public static class DamageMath
{
public const int SILENTattackerType = 2000000;
public const int SILENTattackerTypeMagic = 2000001;
public const int CONVERTEDFLOATattackerType = 1000000;
public const int PURE = 3000001;
/// <summary>
/// Takes a float input damage and returns a integer that is smaller than int.maxvalue and amount of times it has to be sent.
/// </summary>
public static void ReduceDamageToSendOverNet(float damage, out int outdamage, out int repetitions)
{
if (damage < int.MaxValue / 5)
{
outdamage = Mathf.FloorToInt(damage);
repetitions = 1;
return;
}
repetitions = Mathf.FloorToInt(damage / (int.MaxValue / 5f)) + 1;
outdamage = Mathf.RoundToInt(damage / repetitions);
}
public static int GetSendableDamage(float damage)
{
return BitConverter.ToInt32(BitConverter.GetBytes(damage), 0);
}
}
}