Deltarune (Chapter 3) script viewer

← back to main script listing

gml_GlobalScript_scr_damage_maxhp

(view raw script w/o annotations or w/e)
1
function 
scr_damage_maxhp
scr_damage_maxhp

function
scr_damage_maxhp(arg0 = 1, arg1 = false, arg2 = false)
{ if (global.inv < 0) {
scr_damage_cache();
var __element = 0; if (variable_instance_exists(id, "element")) { if (is_real(element)) __element = element; } if (target < 3) { if (global.hp[global.char[target]] <= 0) {
scr_randomtarget_old();
target = mytarget; with (global.charinstance[target]) { image_blend = c_white; darkify = 0; } } } var __remtarget = -1; if (target == 4) { __remtarget = 4;
scr_randomtarget_old();
target = mytarget; if ((global.hp[global.char[target]] / global.maxhp[global.char[target]]) < (
scr_party_hpaverage() / 2))
{
scr_randomtarget_old();
target = mytarget; } if ((global.hp[global.char[target]] / global.maxhp[global.char[target]]) < (
scr_party_hpaverage() / 2))
{
scr_randomtarget_old();
target = mytarget; } if (target == 0 && (global.hp[global.char[target]] / global.maxhp[global.char[target]]) < 0.35) {
scr_randomtarget_old();
target = mytarget; } with (global.charinstance[target]) { image_blend = c_white; darkify = 0; } } chartarget = 3; if (global.chapter == 3 && i_ex(obj_knight_enemy) && !i_ex(obj_knight_roaring2)) { if (obj_knight_enemy.aoedamage == false) { if (target == 0) { if (global.hp[2] > 0 && global.hp[3] > 0) target = choose(1, 2); else if (global.hp[2] > 0) target = 1; else if (global.hp[3] > 0) target = 2; } if (obj_knight_enemy.myattackchoice != 13) { if (global.chararmor1[1] == 23 || global.chararmor2[1] == 23 || global.chararmor1[2] == 23 || global.chararmor2[2] == 23 || global.chararmor1[3] == 23 || global.chararmor2[3] == 23) { obj_knight_enemy.damagecounter++; if (obj_knight_enemy.damagecounter < 3) { if (global.hp[1] > 0 && (global.chararmor1[1] == 23 || global.chararmor2[1] == 23)) target = 0; if (global.hp[2] > 0 && (global.chararmor1[2] == 23 || global.chararmor2[2] == 23)) target = 1; if (global.hp[3] > 0 && (global.chararmor1[3] == 23 || global.chararmor2[3] == 23)) target = 2; } else { target = choose(0, 1, 2); repeat (2) { if (global.hp[1] < 1 && target == 0) target++; if (global.hp[2] < 1 && target == 1) target++; if (global.hp[3] < 1 && target == 2) target++; if (target > 2) target = 0; } if (target == 0 && (global.chararmor1[1] == 23 || global.chararmor2[1] == 23)) { } else if (target == 1 && (global.chararmor1[2] == 23 || global.chararmor2[2] == 23)) { } else if (target == 2 && (global.chararmor1[3] == 23 || global.chararmor2[3] == 23)) { ...
(arg0 = 1, arg1 = false, arg2 = false)
2
{
3
    if (global.inv < 0)
4
    {
5
        
scr_damage_cache
scr_damage_cache

function
scr_damage_cache()
{ global.damage_cache = []; for (var i = 0; i < 3; i++) global.damage_cache[array_length(global.damage_cache)] = global.hp[global.char[i]]; } function scr_damage_check() { if (!variable_global_exists("damage_cache")) global.damage_cache = []; var took_damage = false; for (var i = 0; i < array_length(global.damage_cache); i++) { var hp_cache = global.damage_cache[i]; if (global.hp[global.char[i]] < hp_cache) { took_damage = true; break; } } if (took_damage) { with (obj_event_manager) trigger_event(UnknownEnum.Value_1); } } enum UnknownEnum { Value_1 = 1 }
();
6
        var __element = 0;
7
        if (variable_instance_exists(id, "element"))
8
        {
9
            if (is_real(element))
10
                __element = element;
11
        }
12
        if (target < 3)
13
        {
14
            if (global.hp[global.char[target]] <= 0)
15
            {
16
                
scr_randomtarget_old
scr_randomtarget_old

function
scr_randomtarget_old()
{ abletotarget = 1; if (global.charcantarget[0] == 0 && global.charcantarget[1] == 0 && global.charcantarget[2] == 0) abletotarget = 0; mytarget = choose(0, 1, 2); if (abletotarget == 1) { while (global.charcantarget[mytarget] == 0) mytarget = choose(0, 1, 2); } else { mytarget = 3; } global.targeted[mytarget] = 1; }
();
17
                target = mytarget;
18
                with (global.charinstance[target])
19
                {
20
                    image_blend = c_white;
21
                    darkify = 0;
22
                }
23
            }
24
        }
25
        var __remtarget = -1;
26
        if (target == 4)
27
        {
28
            __remtarget = 4;
29
            
scr_randomtarget_old
scr_randomtarget_old

function
scr_randomtarget_old()
{ abletotarget = 1; if (global.charcantarget[0] == 0 && global.charcantarget[1] == 0 && global.charcantarget[2] == 0) abletotarget = 0; mytarget = choose(0, 1, 2); if (abletotarget == 1) { while (global.charcantarget[mytarget] == 0) mytarget = choose(0, 1, 2); } else { mytarget = 3; } global.targeted[mytarget] = 1; }
();
30
            target = mytarget;
31
            if ((global.hp[global.char[target]] / global.maxhp[global.char[target]]) < (
scr_party_hpaverage
scr_party_hpaverage

function
scr_party_hpaverage()
{ var _totalhp = 0; var _totalmaxhp = 0; var _members = 0; for (var _hpi = 0; _hpi < 3; _hpi++) { if (global.char[_hpi] > 0) { _members++; _totalhp += global.hp[global.char[_hpi]]; _totalmaxhp += global.maxhp[global.char[_hpi]]; } } if (_totalhp > 0) return floor(_totalhp / _totalmaxhp); else return 0; }
() / 2))
32
            {
33
                
scr_randomtarget_old
scr_randomtarget_old

function
scr_randomtarget_old()
{ abletotarget = 1; if (global.charcantarget[0] == 0 && global.charcantarget[1] == 0 && global.charcantarget[2] == 0) abletotarget = 0; mytarget = choose(0, 1, 2); if (abletotarget == 1) { while (global.charcantarget[mytarget] == 0) mytarget = choose(0, 1, 2); } else { mytarget = 3; } global.targeted[mytarget] = 1; }
();
34
                target = mytarget;
35
            }
36
            if ((global.hp[global.char[target]] / global.maxhp[global.char[target]]) < (
scr_party_hpaverage
scr_party_hpaverage

function
scr_party_hpaverage()
{ var _totalhp = 0; var _totalmaxhp = 0; var _members = 0; for (var _hpi = 0; _hpi < 3; _hpi++) { if (global.char[_hpi] > 0) { _members++; _totalhp += global.hp[global.char[_hpi]]; _totalmaxhp += global.maxhp[global.char[_hpi]]; } } if (_totalhp > 0) return floor(_totalhp / _totalmaxhp); else return 0; }
() / 2))
37
            {
38
                
scr_randomtarget_old
scr_randomtarget_old

function
scr_randomtarget_old()
{ abletotarget = 1; if (global.charcantarget[0] == 0 && global.charcantarget[1] == 0 && global.charcantarget[2] == 0) abletotarget = 0; mytarget = choose(0, 1, 2); if (abletotarget == 1) { while (global.charcantarget[mytarget] == 0) mytarget = choose(0, 1, 2); } else { mytarget = 3; } global.targeted[mytarget] = 1; }
();
39
                target = mytarget;
40
            }
41
            if (target == 0 && (global.hp[global.char[target]] / global.maxhp[global.char[target]]) < 0.35)
42
            {
43
                
scr_randomtarget_old
scr_randomtarget_old

function
scr_randomtarget_old()
{ abletotarget = 1; if (global.charcantarget[0] == 0 && global.charcantarget[1] == 0 && global.charcantarget[2] == 0) abletotarget = 0; mytarget = choose(0, 1, 2); if (abletotarget == 1) { while (global.charcantarget[mytarget] == 0) mytarget = choose(0, 1, 2); } else { mytarget = 3; } global.targeted[mytarget] = 1; }
();
44
                target = mytarget;
45
            }
46
            with (global.charinstance[target])
47
            {
48
                image_blend = c_white;
49
                darkify = 0;
50
            }
51
        }
52
        chartarget = 3;
53
        if (global.chapter == 3 && i_ex(obj_knight_enemy) && !i_ex(obj_knight_roaring2))
54
        {
55
            if (obj_knight_enemy.aoedamage == false)
56
            {
57
                if (target == 0)
58
                {
59
                    if (global.hp[2] > 0 && global.hp[3] > 0)
60
                        target = choose(1, 2);
61
                    else if (global.hp[2] > 0)
62
                        target = 1;
63
                    else if (global.hp[3] > 0)
64
                        target = 2;
65
                }
66
                if (obj_knight_enemy.myattackchoice != 13)
67
                {
68
                    if (global.chararmor1[1] == 23 || global.chararmor2[1] == 23 || global.chararmor1[2] == 23 || global.chararmor2[2] == 23 || global.chararmor1[3] == 23 || global.chararmor2[3] == 23)
69
                    {
70
                        obj_knight_enemy.damagecounter++;
71
                        if (obj_knight_enemy.damagecounter < 3)
72
                        {
73
                            if (global.hp[1] > 0 && (global.chararmor1[1] == 23 || global.chararmor2[1] == 23))
74
                                target = 0;
75
                            if (global.hp[2] > 0 && (global.chararmor1[2] == 23 || global.chararmor2[2] == 23))
76
                                target = 1;
77
                            if (global.hp[3] > 0 && (global.chararmor1[3] == 23 || global.chararmor2[3] == 23))
78
                                target = 2;
79
                        }
80
                        else
81
                        {
82
                            target = choose(0, 1, 2);
83
                            repeat (2)
84
                            {
85
                                if (global.hp[1] < 1 && target == 0)
86
                                    target++;
87
                                if (global.hp[2] < 1 && target == 1)
88
                                    target++;
89
                                if (global.hp[3] < 1 && target == 2)
90
                                    target++;
91
                                if (target > 2)
92
                                    target = 0;
93
                            }
94
                            if (target == 0 && (global.chararmor1[1] == 23 || global.chararmor2[1] == 23))
95
                            {
96
                            }
97
                            else if (target == 1 && (global.chararmor1[2] == 23 || global.chararmor2[2] == 23))
98
                            {
99
                            }
100
                            else if (target == 2 && (global.chararmor1[3] == 23 || global.chararmor2[3] == 23))
101
                            {
102
                            }
103
                            else
104
                            {
105
                                obj_knight_enemy.damagecounter = 0;
106
                            }
107
                        }
108
                    }
109
                }
110
                if (target == 0 && (global.chararmor1[1] == 23 || global.chararmor2[1] == 23))
111
                    arg0 /= 2;
112
                else if (target == 1 && (global.chararmor1[2] == 23 || global.chararmor2[2] == 23))
113
                    arg0 /= 2;
114
                else if (target == 2 && (global.chararmor1[3] == 23 || global.chararmor2[3] == 23))
115
                    arg0 /= 2;
116
            }
117
        }
118
        var oldcalculation = 0;
119
        chartarget = global.char[target];
120
        tdamage = ceil(global.maxhp[chartarget] * arg0);
121
        if (global.charaction[target] == 10 && !arg1)
122
            tdamage = ceil(tdamage / 1.5);
123
        if (arg2)
124
            tdamage = clamp(tdamage, 1, global.hp[chartarget] - 1);
125
        if (!instance_exists(obj_shake))
126
            instance_create(0, 0, obj_shake);
127
        with (global.charinstance[target])
128
        {
129
            hurt = 1;
130
            hurttimer = 0;
131
        }
132
        hpdiff = tdamage;
133
        with (obj_dmgwriter)
134
        {
135
            if (delaytimer >= 1)
136
                killactive = 1;
137
        }
138
        doomtype = -1;
139
        with (obj_heart)
140
            dmgnoise = 1;
141
        if (target < 3)
142
        {
143
            if (global.hp[chartarget] <= 0)
144
            {
145
                doomtype = 4;
146
                global.hp[chartarget] -= round(tdamage / 4);
147
                hpdiff = round(tdamage / 4);
148
            }
149
            else
150
            {
151
                global.hp[chartarget] -= tdamage;
152
                if (global.hp[chartarget] <= 0)
153
                {
154
                    if (global.chapter == 3 && i_ex(obj_knight_enemy))
155
                    {
156
                        if (global.hp[1] < 0)
157
                        {
158
                            global.hp[1] = 1;
159
                            hpdiff = round(global.hp[chartarget] - 1);
160
                            doomtype = 4;
161
                            
scr_battle_sprite_set
scr_battle_sprite_set

function
scr_battle_sprite_set(arg0, arg1, arg2, arg3)
{ _charactor = arg0; _charinstance = obj_herokris; if (_charactor == "noelle") { _charinstance = obj_heronoelle; _charnum = 4; } if (_charactor == "ralsei") { _charinstance = obj_heroralsei; _charnum = 3; } if (_charactor == "susie") { _charinstance = obj_herosusie; _charnum = 2; } if (_charactor == "kris") { _charinstance = obj_herokris; _charnum = 1; } if (instance_exists(_charinstance)) { with (_charinstance) { state = 8; hurt = 0; attacktimer = 0; sprite_index = arg1; image_speed = arg2; image_index = 0; if (arg3 == 0) maxframes = image_number; global.faceaction[myself] = 0; } } }
("kris", spr_kris_fallen_dark, 0.25, true);
162
                        }
163
                        else
164
                        {
165
                            doomtype = 12;
166
                            hpdiff = round(global.hp[chartarget] + 999);
167
                            global.hp[chartarget] = -999;
168
                            
scr_dead
scr_dead

function
scr_dead(arg0)
{ global.charmove[arg0] = 0; global.charcantarget[arg0] = 0; global.chardead[arg0] = 1; global.charaction[arg0] = 0; global.charspecial[arg0] = 0; }
(target);
169
                        }
170
                    }
171
                    else
172
                    {
173
                        hpdiff = abs(global.hp[chartarget] - (global.maxhp[chartarget] / 2));
174
                        doomtype = 4;
175
                        global.hp[chartarget] = round(-global.maxhp[chartarget] / 2);
176
                        
scr_dead
scr_dead

function
scr_dead(arg0)
{ global.charmove[arg0] = 0; global.charcantarget[arg0] = 0; global.chardead[arg0] = 1; global.charaction[arg0] = 0; global.charspecial[arg0] = 0; }
(target);
177
                    }
178
                }
179
            }
180
            dmgwriter = instance_create(global.charinstance[target].x, (global.charinstance[target].y + global.charinstance[target].myheight) - 24, obj_dmgwriter);
181
            dmgwriter.damage = hpdiff;
182
            dmgwriter.type = doomtype;
183
        }
184
        if (target == 3)
185
        {
186
            for (hpi = 0; hpi < 3; hpi += 1)
187
            {
188
                chartarget = global.char[hpi];
189
                if (global.hp[chartarget] >= 0)
190
                {
191
                    if (oldcalculation)
192
                        tdamage = ceil(tdamage - (global.battledf[hpi] * 3));
193
                    else
194
                        tdamage = 
scr_damage_calculation
scr_damage_calculation

function
scr_damage_calculation(arg0, arg1)
{ var _tdamage = arg0; var _tdef = global.battledf[arg1]; var _tmaxhp = global.maxhp[global.char[arg1]]; var _finaldamage = 1; var _hpthresholda = _tmaxhp / 5; var _hpthresholdb = _tmaxhp / 8; for (var _di = 0; _di < _tdef; _di++) { if (_tdamage > _hpthresholda) _tdamage -= 3; else if (_tdamage > _hpthresholdb) _tdamage -= 2; else _tdamage -= 1; } return max(_tdamage, _finaldamage); }
(tdamage, hpi);
195
                    tdamage = ceil(tdamage * 
scr_element_damage_reduction
scr_element_damage_reduction

function
scr_element_damage_reduction(arg0, arg1)
{ var ___element = arg0; var ___char = arg1; var ___reduction = 1; if (___element != 0) { for (var ___itemi = 0; ___itemi < 2; ___itemi++) { if (global.itemelement[___char][___itemi + 1] != 0) { if (global.itemelement[___char][___itemi + 1] == ___element) ___reduction -= global.itemelementamount[___char][___itemi + 1]; if (global.itemelement[___char][___itemi + 1] == 9) { if (___element == 2 || ___element == 8) ___reduction -= global.itemelementamount[___char][___itemi + 1]; } if (global.itemelement[___char][___itemi + 1] == 10) ___reduction -= global.itemelementamount[___char][___itemi + 1]; } } } if (___reduction < 0.25) ___reduction = 0.25; return ___reduction; }
(__element, chartarget));
196
                    if (global.charaction[hpi] == 10)
197
                        global.hp[chartarget] -= ceil((3 * tdamage) / 4);
198
                    else
199
                        global.hp[chartarget] -= tdamage;
200
                    if (global.hp[chartarget] <= 0)
201
                        global.hp[chartarget] = round(-global.maxhp[0] / 2);
202
                }
203
            }
204
        }
205
        global.inv = global.invc * 30;
206
        scr_damage_check();
207
        gameover = 1;
208
        if (global.char[0] != 0 && global.hp[global.char[0]] > 0)
209
            gameover = 0;
210
        if (global.char[1] != 0 && global.hp[global.char[1]] > 0)
211
            gameover = 0;
212
        if (global.char[2] != 0 && global.hp[global.char[2]] > 0)
213
            gameover = 0;
214
        if (gameover == 1)
215
            
scr_gameover
scr_gameover

function
scr_gameover()
{ if (global.flag[35 gameover_mode] == 0) { audio_stop_all(); snd_play(snd_hurt1); global.screenshot = sprite_create_from_surface(application_surface, 0, 0, __view_get(e__VW.WView, 0), __view_get(e__VW.HView, 0), 0, 0, 0, 0); snd_free_all(); room_goto(room_gameover ); } if (global.flag[35 gameover_mode] == 1) { global.turntimer = -1; global.flag[36 dojo_failure] = 1; global.flag[39 dojo_abort?] = 1; } if (global.flag[35 gameover_mode] == 2) { audio_stop_all(); snd_play(snd_hurt1); snd_free_all(); global.entrance = 0; global.tempflag[9] = 1; global.fighting = 0; global.interact = 0; global.hp[0] = 1; global.hp[1] = 1; global.hp[2] = 1; global.hp[3] = 1; __room = room; if (global.chapter == 2) { with (instance_create(0, 0, obj_persistentfadein)) image_alpha = 1.2; } room_goto(__room); } } enum e__VW { XView, YView, WView, HView, Angle, HBorder, VBorder, HSpeed, VSpeed, Object, Visible, XPort, YPort, WPort, HPort, Camera, SurfaceID }
();
216
        if (__remtarget != -1)
217
            target = __remtarget;
218
    }
219
}