Revisión | c363af79fb90d1d7b9f79bc82289ff0e71708fc1 (tree) |
---|---|
Tiempo | 2021-11-28 23:38:45 |
Autor | Adam Kaminski <kaminskiadam9@gmai...> |
Commiter | Adam Kaminski |
The result value of GAMEEVENT_ACTOR_DAMAGED event scripts can now be used to change the final damage that the target will take.
@@ -1110,16 +1110,16 @@ | ||
1110 | 1110 | |
1111 | 1111 | //***************************************************************************** |
1112 | 1112 | // |
1113 | -void GAMEMODE_HandleDamageEvent ( AActor *target, AActor *inflictor, AActor *source, int damage, FName mod ) | |
1113 | +bool GAMEMODE_HandleDamageEvent ( AActor *target, AActor *inflictor, AActor *source, int &damage, FName mod ) | |
1114 | 1114 | { |
1115 | 1115 | // [AK] Don't run any scripts if the target doesn't allow executing GAMEEVENT_ACTOR_DAMAGED. |
1116 | 1116 | if ( target->STFlags & STFL_NODAMAGEEVENTSCRIPT ) |
1117 | - return; | |
1117 | + return true; | |
1118 | 1118 | |
1119 | 1119 | // [AK] Don't run any scripts if the target can't execute GAMEEVENT_ACTOR_DAMAGED unless |
1120 | 1120 | // all actors are forced to execute it. |
1121 | 1121 | if ((( target->STFlags & STFL_USEDAMAGEEVENTSCRIPT ) == false ) && ( gameinfo.bForceDamageEventScripts == false )) |
1122 | - return; | |
1122 | + return true; | |
1123 | 1123 | |
1124 | 1124 | // [AK] We somehow need to pass all the actor pointers into the script itself. A simple way |
1125 | 1125 | // to do this is temporarily spawn a temporary actor and change its actor pointers to the target, |
@@ -1131,10 +1131,14 @@ | ||
1131 | 1131 | temp->master = source; |
1132 | 1132 | temp->tracer = inflictor; |
1133 | 1133 | |
1134 | - GAMEMODE_HandleEvent( GAMEEVENT_ACTOR_DAMAGED, temp, damage, GlobalACSStrings.AddString( mod )); | |
1134 | + GAMEMODE_SetEventResult( damage ); | |
1135 | + damage = GAMEMODE_HandleEvent( GAMEEVENT_ACTOR_DAMAGED, temp, damage, GlobalACSStrings.AddString( mod )); | |
1135 | 1136 | |
1136 | 1137 | // [AK] Destroy the temporary actor after executing all event scripts. |
1137 | 1138 | temp->Destroy( ); |
1139 | + | |
1140 | + // [AK] If the new damage is zero, that means the target shouldn't take damage in P_DamageMobj. | |
1141 | + return ( damage != 0 ); | |
1138 | 1142 | } |
1139 | 1143 | |
1140 | 1144 | //***************************************************************************** |
@@ -213,7 +213,7 @@ | ||
213 | 213 | GAMESTATE_e GAMEMODE_GetState ( void ); |
214 | 214 | void GAMEMODE_SetState ( GAMESTATE_e GameState ); |
215 | 215 | LONG GAMEMODE_HandleEvent ( const GAMEEVENT_e Event, AActor *pActivator = NULL, const int DataOne = 0, const int DataTwo = 0 ); |
216 | -void GAMEMODE_HandleDamageEvent ( AActor *target, AActor *inflictor, AActor *source, int damage, FName mod ); | |
216 | +bool GAMEMODE_HandleDamageEvent ( AActor *target, AActor *inflictor, AActor *source, int &damage, FName mod ); | |
217 | 217 | LONG GAMEMODE_GetEventResult ( void ); |
218 | 218 | void GAMEMODE_SetEventResult ( LONG lResult ); |
219 | 219 |
@@ -1573,7 +1573,10 @@ | ||
1573 | 1573 | } |
1574 | 1574 | |
1575 | 1575 | // [AK] Trigger an event script indicating that the player has taken damage, if we can. |
1576 | - GAMEMODE_HandleDamageEvent( target, inflictor, source, damage, mod ); | |
1576 | + // If the event returns 0, then the target doesn't take damage and we do nothing. | |
1577 | + if ( GAMEMODE_HandleDamageEvent( target, inflictor, source, damage, mod ) == false ) | |
1578 | + return -1; | |
1579 | + | |
1577 | 1580 | bDamageEventHandled = true; |
1578 | 1581 | |
1579 | 1582 | if (damage >= player->health |
@@ -1585,8 +1588,9 @@ | ||
1585 | 1588 | } |
1586 | 1589 | |
1587 | 1590 | // [AK] If we haven't done so already, trigger an event script indicating that the player has taken damage. |
1588 | - if ( bDamageEventHandled == false ) | |
1589 | - GAMEMODE_HandleDamageEvent( target, inflictor, source, damage, mod ); | |
1591 | + // If the event returns 0, then the target doesn't take damage and we do nothing. | |
1592 | + if (( bDamageEventHandled == false ) && ( GAMEMODE_HandleDamageEvent( target, inflictor, source, damage, mod ) == false )) | |
1593 | + return -1; | |
1590 | 1594 | |
1591 | 1595 | player->health -= damage; // mirror mobj health here for Dave |
1592 | 1596 | // [RH] Make voodoo dolls and real players record the same health |
@@ -1653,7 +1657,9 @@ | ||
1653 | 1657 | } |
1654 | 1658 | |
1655 | 1659 | // [AK] Trigger an event script indicating that the target actor has taken damage, if we can. |
1656 | - GAMEMODE_HandleDamageEvent( target, inflictor, source, damage, mod ); | |
1660 | + // If the event returns 0, then the target doesn't take damage and we do nothing. | |
1661 | + if ( GAMEMODE_HandleDamageEvent( target, inflictor, source, damage, mod ) == false ) | |
1662 | + return -1; | |
1657 | 1663 | |
1658 | 1664 | target->health -= damage; |
1659 | 1665 | } |