@@ -1000,20 +1000,20 @@ Local<Value> EntityClass::hurt(const Arguments& args) {
10001000 }
10011001 float damage = args[0 ].asNumber ().toFloat ();
10021002 int type = 0 ;
1003- if (args.size () = = 2 ) {
1003+ if (args.size () > = 2 ) {
10041004 CHECK_ARG_TYPE (args[1 ], ValueKind::kNumber );
1005- type = args[1 ].asNumber ().toInt32 ();
1006- ActorDamageSource damageSource = ActorDamageSource ((ActorDamageCause)type);
1007- return Boolean::newBoolean (entity->hurt (damageSource, damage, true , false ));
1005+ type = args[1 ].asNumber ().toInt32 ();
10081006 }
10091007 if (args.size () == 3 ) {
1010- CHECK_ARG_TYPE (args[1 ], ValueKind::kNumber );
1011- auto source = EntityClass::extract (args[2 ]);
1012- type = args[1 ].asNumber ().toInt32 ();
1013- ActorDamageByActorSource damageSource = ActorDamageByActorSource (*source, (ActorDamageCause)type);
1014- return Boolean::newBoolean (entity->hurt (damageSource, damage, true , false ));
1008+ auto source = EntityClass::extract (args[2 ]);
1009+ if (!source) {
1010+ return Boolean::newBoolean (false );
1011+ }
1012+ ActorDamageByActorSource damageBySource = ActorDamageByActorSource (*source, (ActorDamageCause)type);
1013+ return Boolean::newBoolean (entity->hurt (damageBySource, damage, true , false ));
10151014 }
1016- return Boolean::newBoolean (false );
1015+ ActorDamageSource damageSource = ActorDamageSource ((ActorDamageCause)type);
1016+ return Boolean::newBoolean (entity->hurt (damageSource, damage, true , false ));
10171017 }
10181018 CATCH (" Fail in hurt!" );
10191019}
0 commit comments