/
cd_monster_properties.zs
93 lines (74 loc) · 2.8 KB
/
cd_monster_properties.zs
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
/* Copyright Alexander 'm8f' Kromm (mmaulwurff@gmail.com) 2019, 2021
*
* This file is a part of Ultimate Custom Doom.
*
* Ultimate Custom Doom is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* Ultimate Custom Doom is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* Ultimate Custom Doom. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* This class provides the monster manipulation functions.
*/
class cd_Monsters play
{
static
void applyMonsterMultipliersTo(Actor thing, cd_MonsterSettings settings)
{
applyHealthMultiplierTo(thing, settings.healthMultiplier(), settings.healthCap());
applySpeedMultiplierTo (thing, settings.speedMultiplier ());
}
static
void applyMonsterMultipliersToAll(cd_MonsterSettings settings)
{
let iterator = ThinkerIterator.Create();
Actor a;
while (a = Actor(iterator.Next()))
{
if (!a.bIsMonster) { continue; }
applyMonsterMultipliersTo(a, settings);
}
}
// private: ////////////////////////////////////////////////////////////////////////////////////////
private static
void applyHealthMultiplierTo(Actor thing, double multiplier, int cap)
{
if (multiplier <= 0) { multiplier = 1; }
// LegenDoom Lite
string ldlToken = "LDLegendaryMonsterToken";
int ldlMultiplier = (thing.CountInv(ldlToken) > 0) ? 3 : 1;
int defStartHealth = getDefault(thing).SpawnHealth();
int oldStartHealth = thing.SpawnHealth();
int oldHealth = thing.health;
double relativeHealth = double(oldHealth) / oldStartHealth;
int newStartHealth = cd_math.round(defStartHealth * multiplier * ldlMultiplier);
int newHealth = cd_math.round(newStartHealth * relativeHealth);
if (cap > 0 && newStartHealth > cap) newStartHealth = cap;
if (cap > 0 && newHealth > cap) newHealth = cap;
thing.StartHealth = newStartHealth;
thing.A_SetHealth(newHealth);
}
private static
void applySpeedMultiplierTo(Actor thing, double multiplier)
{
if (multiplier <= 0) { multiplier = 1; }
double spawnSpeed = getDefault(thing).Speed;
int speed = cd_math.round(spawnSpeed * multiplier);
thing.Speed = speed;
}
private static
readonly<Actor> getDefault(Actor thing)
{
class<Actor> type = thing.GetClassName();
let tmp = GetDefaultByType(type);
return tmp;
}
} // class cd_Monsters