polserver/testsuite/pol/testpkgs/attack/ai_attack.src
turleypol e6abc8fcfe
Attackable item (#884)
* introduced Attackable wrapper class for opponents to be able to also
attack items

* changed set_opponent to use Attackable
moved first logic into Attackable

* added dynamic property which returns a pointer of the object instead of
a copy like the current imp.
needed to be able to eg store a vector

* send engage/disengage events
send hp status bar

* send attackable item flag in world item pkt

* apply damage for items + evid_damaged

* react to statrequests

* adapted is_attackable and do attack_effects

* fixed clear_opponent_of

* fixed clear_opponent_of

* allow attack pkt

* apply damage

* items need to keep track of the opponents to be able to cleanup on
destroy

* updated dynproperties

* updated dynprops a bit more.
made the structs trivial copyable
updated concept to not repeat the types

* run hitscript, cleanup

* listhostiles and attack_once accept now Attackable

* set opponent when dblclicked

* dont let hp underflow

* only attack if you are in warmode

* evid_opponent_moved for attackable items

* if its the same opponent dont send engaged events again
added test for listhostiles with two mobs

* allow attackable item for setopponent

* some tests npc vs item

* missing files

* fixed clang tidy complain

* test for enter/left area

* do not send hp updates while char gets created and not yet added to the
  world

* testclient fight packets

* client event constants

* added client tests for attacking npc and item

* increase damage

* removed leftover comment

* when an attackable item was destroyed the opponents where not correctly cleared

* orphan check for is_attackable

* moved statmsg for items

* init member

* moved send_hightlight back into if statement
check before dereferencing

* use range version of statmsg

* adapted em params

* comparison operator
made explicit constructors
for symmetry return damage in Item::apply_damage

* get rid of bools

* split attack method a bit

* use constants for F3 flag

* destroy item on hit if hp reaches 0 if no controlscript exists

* only toplevel items are attackable
small refactoring
more tests

* more tests

* even more tests

* docs
2026-07-30 20:27:36 +02:00

52 lines
1.5 KiB
Text

use uo;
use os;
use npc;
include "sysevent";
program enteredarea()
var me := self();
while ( me )
var ev := wait_for_event( 5 );
if ( ev )
if ( ev.type == SYSEVENT_DISENGAGED )
SetOpponent( 0 );
elseif ( ev.type == SYSEVENT_ENGAGED )
SetOpponent( ev.source );
if ( ev.sleep > 0 )
Sleep( ev.sleep ); // Sleep to set ready-swing.
endif
if ( ev.unhide )
var ev := struct{ type := "BEFORE_UNHIDE", gameclock := ReadGameClock() };
GetProcess( GetObjProperty( me, "#TestPid" ) ).SendEvent( ev );
me.hidden := 0;
endif
elseif ( ev.type == "set_opponent" )
// report back what SetOpponent returned, so that its error cases can
// be checked from the test script
var res := SetOpponent( ev.source );
var errortext := "";
if ( res == error )
errortext := res.errortext;
endif
GetProcess( GetObjProperty( me, "#TestPid" ) ).SendEvent(
struct{ type := "set_opponent_result", result := CInt( res ),
errortext := errortext } );
elseif ( ev.type == "enable_events" )
EnableEvents( SYSEVENT_ENGAGED | SYSEVENT_DISENGAGED );
elseif ( ev.type == "disable_events" )
DisableEvents( SYSEVENT_ENGAGED | SYSEVENT_DISENGAGED );
elseif ( ev.type == "move_to" )
RunToward( ev.source );
elseif ( ev.type == "move_away" )
RunAwayFrom( ev.source );
endif
endif
endwhile
endprogram