-
Notifications
You must be signed in to change notification settings - Fork 0
/
UnitExtras.cs
97 lines (87 loc) · 3.11 KB
/
UnitExtras.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
using System;
using System.Collections.Generic;
using System.Text;
using static War3Api.Common;
using static War3Api.Blizzard;
using System.Numerics;
using War3Api;
namespace NoxRaven
{
/// <summary>
/// Some really special utilities that do not really belong (or may be not yet) in NUnit
/// </summary>
public static class UnitExperimentals
{
static List<PushedUnit> pushedList = new List<PushedUnit>();
internal static void InitUnitExperimentals()
{
Master.s_globalTick.Add((delta) =>
{
if (pushedList.Count > 0)
foreach (PushedUnit pu in pushedList)
if (pu.Move(delta))
{
pushedList.Remove(pu);
}
});
}
/// <summary>
/// Pulls targets from range over duration with power stress. <br />
/// Power - how hard this algortihm tries to pull targets. power = 1 means everyone in range will gets slowly pulled towards center.
/// </summary>
/// <param name="range"></param>
/// <param name="duration"></param>
/// <param name="power"></param>
//public static void PullTargets(float range, float duration, float power)
//{
//}
public static void Dash(unit target, float duration, Vector2 targetPosition, bool actionBlocked)
{
Vector2 currentPosition = new Vector2(GetUnitX(target), GetUnitY(target));
float range = Maffs.GetDistance(currentPosition, targetPosition);
float angle = Maffs.GetFacingTowardsAngle(targetPosition, currentPosition);
PushTarget(target, duration, angle, range, actionBlocked);
}
public static void PushTarget(unit target, float duration, float angle, float range, bool actionBlocked)
{
pushedList.Add(new PushedUnit(target, duration, angle, range, actionBlocked));
}
}
public class PushedUnit
{
unit Unit;
public float TimeLeft;
public float Sin;
public float Cos;
public bool ActionsBlocked;
public PushedUnit(unit Unit, float duration, float angle, float range, bool actionBlocked)
{
this.Unit = Unit;
TimeLeft = duration;
float push = range / duration * Master.TICK_DELTA;
Sin = push * Sin(angle * bj_DEGTORAD);
Cos = push * Cos(angle * bj_DEGTORAD);
ActionsBlocked = actionBlocked;
}
public bool Move(float delta)
{
float xi = GetUnitX(Unit) + Cos;
float yi = GetUnitY(Unit) + Sin;
if (Utils.IsCurrentlyWalkable(xi, yi))
if (ActionsBlocked)
{
SetUnitPosition(Unit, xi, yi);
}
else
{
SetUnitX(Unit, xi);
SetUnitY(Unit, yi);
}
if (IsUnitDeadBJ(Unit))
{
return true;
}
return (TimeLeft -= delta) <= 0;
}
}
}