MCPcopy Create free account
hub / github.com/deathkiller/jazz2-native / OnCollect

Method OnCollect

Sources/Jazz2/Scripting/ScriptActorWrapper.cpp:667–704  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

665 }
666
667 bool ScriptCollectibleWrapper::OnCollect(Player* player)
668 {
669 if (_onCollect == nullptr || _isDead->Get()) {
670 return false;
671 }
672
673 asIScriptEngine* engine = _obj->GetEngine();
674 asIScriptContext* ctx = engine->RequestContext();
675
676 void* mem = asAllocMem(sizeof(ScriptPlayerWrapper));
677 ScriptPlayerWrapper* playerWrapper = new(mem) ScriptPlayerWrapper(_levelScripts, player);
678
679 ctx->Prepare(_onCollect);
680 ctx->SetObject(_obj);
681 ctx->SetArgObject(0, playerWrapper);
682 std::int32_t r = ctx->Execute();
683 bool result;
684 if (r == asEXECUTION_EXCEPTION) {
685 LOGE("An exception \"{}\" occurred in \"{}\". Please correct the code and try again.",
686 ctx->GetExceptionString(), ctx->GetExceptionFunction()->GetDeclaration());
687 result = true;
688 } else {
689 result = (ctx->GetReturnByte() != 0);
690 }
691
692 engine->ReturnContext(ctx);
693
694 playerWrapper->Release();
695
696 if (result) {
697 player->AddScore(_scoreValue);
698 Explosion::Create(_levelHandler, Vector3i((std::int32_t)_pos.X, (std::int32_t)_pos.Y, _renderer.layer()), Explosion::Type::Generator);
699 DecreaseHealth(INT32_MAX);
700 return true;
701 } else {
702 return false;
703 }
704 }
705}
706
707#endif

Callers

nothing calls this directly

Calls 6

GetEngineMethod · 0.80
ExecuteMethod · 0.80
layerMethod · 0.80
GetMethod · 0.45
ReleaseMethod · 0.45
AddScoreMethod · 0.45

Tested by

no test coverage detected