@@ -1000,20 +1000,20 @@ Local<Value> EntityClass::hurt(const Arguments& args) {
1000
1000
}
1001
1001
float damage = args[0 ].asNumber ().toFloat ();
1002
1002
int type = 0 ;
1003
- if (args.size () = = 2 ) {
1003
+ if (args.size () > = 2 ) {
1004
1004
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 ();
1008
1006
}
1009
1007
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 ));
1015
1014
}
1016
- return Boolean::newBoolean (false );
1015
+ ActorDamageSource damageSource = ActorDamageSource ((ActorDamageCause)type);
1016
+ return Boolean::newBoolean (entity->hurt (damageSource, damage, true , false ));
1017
1017
}
1018
1018
CATCH (" Fail in hurt!" );
1019
1019
}
0 commit comments