void ZServer::threadProcAccept() { sockaddr_in address; int len = 0; while(isRunning()) { memset(&address, 0, sizeof(address)); len = sizeof(address); SOCKET socket = ::accept(m_socket, (sockaddr*)&address, &len); if(socket == SOCKET_ERROR) { printf("接收新连接失败:%d\n", GetLastError()); continue; } printf("接收到来自[%s:%d]的连接-socket[%d]\n", inet_ntoa(address.sin_addr), htons(address.sin_port), socket); ZClientNodePtr ptr = new ZClientNode(this, socket, inet_ntoa(address.sin_addr), address.sin_port); addClient(ptr); std::cout<<"创建连接:"<<ptr->id()<<std::endl; checkDead(); } }
void CPlayerBase::update(float elapsed) { PROFILE_FUNCTION("update base"); if (camera.isValid()) { if (onCinematic) { UpdateCinematic(elapsed); } else if (controlEnabled || only_sense) { bool alive = !checkDead(); if (alive && inputEnabled) { energy_decrease = energy_default_decrease; // Default if nobody change that this frame UpdateSenseVision(); if (!only_sense) { UpdateMoves(); UpdateInputActions(); } setLife(getLife() - getDeltaTime() * energy_decrease); } Recalc(); if (alive) { //UpdateMoves(); myUpdate(); update_msgs(); } } //UpdateAnimation(); } }
void CPlayerBase::Idle() { PROFILE_FUNCTION("idle base"); ChangeCommonState("idle"); if (!checkDead()) { UpdateDirection(); UpdateJumpState(); if (UpdateMovDirection() && (state == "moving" || state == "idle")) { ChangeCommonState("moving"); ChangeState("moving"); } } }
void StateBuffTrigger::execute(StateBase* parent) { auto battle = getBattleInfo(); if (this->stage != 1) { BatSeqBuffTrigger* tg = new BatSeqBuffTrigger; tg->buffId = buff->bid; tg->petUid = buff->belongs.owner; battle->pushSeq(shared_ptr<ISeq>(tg)); } shared_ptr<FireBuff> fireInfo(new FireBuff); assign(fireInfo.get(), buff, buff->keyBuff, 0); fireInfo->parent = nullptr; fireInfo->origin = battle->topSkill() != nullptr ? battle->topSkill().get() : nullptr; battle->pushSkill(fireInfo); for (auto subsk : buff->keyBuff->subs) { fireInfo->targets = battle->getTargets(fireInfo->origin, buff->belongs.owner, subsk->target, subsk->parent.lock()->target); for (int i=0; i<fireInfo->targets.size(); i++) { if (this->stage == subsk->triggerStage) { int dstuid = fireInfo->targets[i]; if (getBattleInfo()->allPets[dstuid]->isBating) { assign(fireInfo.get(), buff, subsk.get(), dstuid); createEffect(2, subsk->subEffId)->execute(); } } } battle->checkDead(fireInfo->targets); } // 以次计算触发的每个效果 vector<Buff*> triggerSubBuff; for (auto sub : buff->keyBuff->subs) { if (stage == sub->triggerStage) { for (auto arg : sub->triggerParams) { if (createTriggerCondi(buff->belongs.owner, sub->triggerCondi, arg)->isTrigger(stage, fireInfo->origin)) { triggerSubBuff.push_back(sub.get()); break; } } } } // for (auto& it : triggerSubBuff) { assign(fireInfo.get(), buff, it, 0); fireInfo->targets = battle->getTargets(fireInfo->origin, buff->belongs.owner, it->target, it->parent.lock()->target); for (int i=0; i<fireInfo->targets.size(); i++) { int dstuid = fireInfo->targets[i]; if (getBattleInfo()->allPets[dstuid]->isBating) { assign(fireInfo.get(), buff, it, dstuid); createEffect(2, it->subEffId)->execute(); } } } battle->popSkill(); exitState(); }