void CharacterComponent::respawn(Entity &entity) { auto *beingComponent = entity.getComponent<BeingComponent>(); if (beingComponent->getAction() != DEAD) { LOG_WARN("Character \"" << beingComponent->getName() << "\" tried to respawn without being dead"); return; } // Make it alive again beingComponent->setAction(entity, STAND); // Reset target entity.getComponent<CombatComponent>()->clearTarget(); // Execute respawn callback when set if (executeCallback(mDeathAcceptedCallback, entity)) return; // No script respawn callback set - fall back to hardcoded logic const double maxHp = beingComponent->getModifiedAttribute(ATTR_MAX_HP); beingComponent->setAttribute(entity, ATTR_HP, maxHp); // Warp back to spawn point. int spawnMap = Configuration::getValue("char_respawnMap", 1); int spawnX = Configuration::getValue("char_respawnX", 1024); int spawnY = Configuration::getValue("char_respawnY", 1024); GameState::enqueueWarp(&entity, MapManager::getMap(spawnMap), Point(spawnX, spawnY)); }
void Character::respawn() { if (mAction != DEAD) { LOG_WARN("Character \"" << getName() << "\" tried to respawn without being dead"); return; } // Make it alive again setAction(STAND); // Reset target mTarget = NULL; // Execute respawn callback when set if (executeCallback(mDeathAcceptedCallback, this)) return; // No script respawn callback set - fall back to hardcoded logic mAttributes[ATTR_HP].setBase(mAttributes[ATTR_MAX_HP].getModifiedAttribute()); updateDerivedAttributes(ATTR_HP); // Warp back to spawn point. int spawnMap = Configuration::getValue("char_respawnMap", 1); int spawnX = Configuration::getValue("char_respawnX", 1024); int spawnY = Configuration::getValue("char_respawnY", 1024); GameState::enqueueWarp(this, MapManager::getMap(spawnMap), spawnX, spawnY); }
optional<LRESULT> TableViewImpl::processNotification(UINT message, UINT notification, WPARAM wParam, LPARAM lParam) { if( message == WM_NOTIFY ) { switch(notification) { case NM_CUSTOMDRAW: { auto it = cbDrawItem.find(this); if( it != cbDrawItem.end() ) { auto lplvcd = reinterpret_cast<LPNMLVCUSTOMDRAW>(lParam); NMCUSTOMDRAW & nmcd = lplvcd->nmcd; switch(nmcd.dwDrawStage) { case CDDS_PREPAINT: return CDRF_NOTIFYITEMDRAW; case CDDS_ITEMPREPAINT: return CDRF_NOTIFYSUBITEMDRAW; case CDDS_SUBITEM | CDDS_ITEMPREPAINT: { CanvasImpl canvas(nmcd.hdc); RECT winRect; auto pRect = &winRect; if( ListView_GetSubItemRect(hWnd,nmcd.dwItemSpec,lplvcd->iSubItem,LVIR_BOUNDS,pRect) == 0 ) { log::error("ListView_GetSubItemRect error"); } auto rect = convertRect(winRect); bool itemWasDrawn = it->second(TableView::ItemPos{lplvcd->iSubItem,nmcd.dwItemSpec},canvas,rect); if( itemWasDrawn ) return CDRF_SKIPDEFAULT; } break; } } } break; case NM_CLICK: { auto lpnmitem = reinterpret_cast<LPNMITEMACTIVATE>(lParam); if( executeCallback(this,cbClickItem,TableView::ItemPos{lpnmitem->iSubItem,lpnmitem->iItem}) ) return 0; } break; } } return NativeControlImpl::processNotification(message,notification,wParam,lParam); }
void CharacterComponent::triggerLoginCallback(Entity &entity) { executeCallback(mLoginCallback, entity); }
void CharacterComponent::characterDied(Entity *being) { executeCallback(mDeathCallback, *being); }
void Character::triggerLoginCallback() { executeCallback(mLoginCallback, this); }
void Character::died() { Being::died(); executeCallback(mDeathCallback, this); }
void NetworkActivity::shutdown() { executeCallback(); callback_ = 0; }
NetworkActivity::~NetworkActivity() { executeCallback(); }
optional<LRESULT> WindowImpl::processMessage(UINT message, WPARAM & wParam, LPARAM & lParam) { if( auto result = NativeControlImpl::processMessage(message,wParam,lParam) ) return result; switch( message ) { case WM_CLOSE: { auto canClose = findExec(this,cbClose); if( canClose ) { if( *canClose == false ) return 0; } hide(); return 0; } break; // TODO verify the need of creating on_minimize and on_maximize callbacks also case WM_SIZE: { WDims newDims = lParamToWDims(lParam); bool max = false; switch(wParam) { case SIZE_MINIMIZED: state_ |= ws_minimized; state_ &= ~ws_maximized; break; case SIZE_MAXIMIZED: max = true; state_ &= ~ws_minimized; state_ |= ws_maximized; break; case SIZE_RESTORED: state_ &= ~(ws_minimized | ws_maximized); break; } bool notChanged = true; auto resNewDims = findExec(this,cbResize,newDims); if( resNewDims ) { if( *resNewDims != newDims ) { if( max ) { ShowWindow(hWnd,SW_RESTORE); } setDims(*resNewDims); notChanged = false; } } if( notChanged ) { executeCallback(this, cbAfterResize, newDims); } } break; case WM_COMMAND: { ResourceManagerSingleton resourceManager; if( lParam == 0 ) { for( auto & component : components ) { auto result = component->processNotification(WM_COMMAND,HIWORD(wParam),LOWORD(wParam),lParam); if( result ) return result; } } else if( auto control = resourceManager->findControl(HWND(lParam)) ) { return control->processNotification(WM_COMMAND,HIWORD(wParam),wParam,lParam); } } break; case WM_NOTIFY: { ResourceManagerSingleton resourceManager; auto hdr = reinterpret_cast<LPNMHDR>(lParam); if( auto control = resourceManager->findControl(hdr->hwndFrom) ) { return control->processNotification(WM_NOTIFY,hdr->code,wParam,lParam); } } break; default: if( message >= WM_USER ) { if( executeCallback(this,cbUserEvent,toUserEvent(message,lParam)) ) { return 0; } } } return optional<LRESULT>(); }
void HeroBow::bulletCallback(Ref* sender) { auto bullet=(BulletObject*)sender; bullet->executeCallback(); }