2022-11-13 00:15:17 +00:00
/// <reference path="../../udbscript.d.ts" />
2022-01-06 17:46:37 +00:00
` #version 4 ` ;
2021-11-28 13:00:24 +00:00
` #name Imps to Arch-Viles ` ;
` #description Turns all Imps that appear on UV into Arch-Viles. To make it a bit more fair for the player it also adds a health potion to the monster's position. ` ;
2022-01-06 17:46:37 +00:00
UDB . Map . getThings ( ) . filter ( t => t . type == 3001 && ( ( UDB . Map . isUDMF && t . flags . skill5 ) || ( ! UDB . Map . isUDMF && t . flags [ '4' ] ) ) ) . forEach ( t => {
2021-11-28 13:00:24 +00:00
let addav = false ;
let skillsum = 0 ;
// Count the number of skills the Imp appears on
2022-01-06 17:46:37 +00:00
if ( UDB . Map . isUDMF )
2021-11-28 13:00:24 +00:00
{
for ( let i = 1 ; i <= 5 ; i ++ )
if ( t . flags [ 'skill' + i ] )
skillsum ++ ;
}
else
{
for ( let i = 0 ; i < 3 ; i ++ )
if ( t . flags [ parseInt ( 1 << i ) ] )
skillsum ++ ;
}
// If the Imp appears on more than one skill we need to add the Arch-Vile, otherwise we can
// simply set the existing thing's type to that of the Arch-Vile
if ( skillsum != 1 )
addav = true ;
// Create a new health potion at the thing's position
2022-01-06 17:46:37 +00:00
let hp = UDB . Map . createThing ( t . position , 2014 ) ;
2021-11-28 13:00:24 +00:00
2022-01-06 17:46:37 +00:00
if ( UDB . Map . isUDMF )
2021-11-28 13:00:24 +00:00
{
hp . flags . skill5 = true ;
for ( let i = 1 ; i <= 4 ; i ++ )
hp . flags [ 'skill' + i ] = false ;
}
else
{
hp . flags [ '4' ] = true ;
hp . flags [ '1' ] = hp . flags [ '2' ] = false ;
}
if ( addav )
{
// Create a new Arch-Vile and copy all the original thing's properties
2022-01-06 17:46:37 +00:00
let av = UDB . Map . createThing ( t . position ) ;
2021-11-28 13:00:24 +00:00
t . copyPropertiesTo ( av ) ;
av . type = 64 ;
// Set the skill flags. Since we're addin an Arch-Vile we have to unset the Imp's UV flag,
// and remove the Arch-Viles (and health potion's) other skill flags
2022-01-06 17:46:37 +00:00
if ( UDB . Map . isUDMF )
2021-11-28 13:00:24 +00:00
{
t . flags . skill5 = false ;
for ( let i = 1 ; i <= 4 ; i ++ )
av . flags [ 'skill' + i ] = false ;
}
else
{
t . flags [ '4' ] = false ;
av . flags [ '1' ] = av . flags [ '2' ] = false ;
}
}
else
{
// Modify the existing thing to be the Arch-Vile
t . type = 64 ;
}
} ) ;