/** * \brief 在主人周围2格内随机移动 * 离主人只有1格时随便走,超过1格就要检测下一步是否在活动范围内 * * \return 是否移动成功 */ bool ScenePet::randomMove() { if(type == Cmd::PET_TYPE_TURRET) return false; //sky 炮台也是不移动的 if (type == Cmd::PET_TYPE_SEMI) return SceneNpc::randomMove(); if (!canMove()) return false; SceneEntryPk * master = getMaster(); if (!master) return false; if (checkMoveTime(SceneTimeTick::currentTime) && canMove()) if (selectByPercent(2) || ((getPetType()==Cmd::PET_TYPE_CARTOON || getPetType()==Cmd::PET_TYPE_RIDE) && scene->checkBlock(getPos()) && scene->zPosShortRange(getPos(),master->getPos(),1))) { int dir = randBetween(0,7); zPos newPos; scene->getNextPos(pos,dir,newPos); zPosI newPosI = 0; scene->zPos2zPosI(newPos,newPosI); if (getPosI()==newPosI//不切屏 && scene->zPosShortRange(master->getPos(),newPos,SceneNpc::npc_pet_chase_region))//主人2格内 return shiftMove(dir);//随机移动 } return false; }
/** * \brief 回到活动范围 * */ void ScenePet::returnToRegion() { if (type==Cmd::PET_TYPE_SEMI) return; SceneEntryPk * master = getMaster(); if (master) { if (!scene->zPosShortRange(master->getPos(),getPos(),SceneNpc::npc_pet_warp_region)) { warp(master->getPos()); return; } setSpeedRate(getSpeedRate()*2.0); return; } }
/** * \brief 敌我判断 * \param entry 判断的对象 * \param notify 判断失败时是否提示(不能攻击10级以下的玩家) * \return 0:友方 1:敌人 -1:中立 */ int ScenePet::isEnemy(SceneEntryPk * entry,bool notify,bool good) { int ret=0; bool isPlayer = false; if (entry) { if (type==Cmd::PET_TYPE_SEMI) { ret = SceneNpc::isEnemy(entry,notify,good); } else { SceneEntryPk * master = getMaster(); if (master) { if (master->scene==scene) { if (scene->zPosShortRange(getPos(),master->getPos(),SCREEN_WIDTH*2,SCREEN_HEIGHT*2)) { if (this!=entry) { if (!((entry->frenzy)||(frenzy))) { if (master->getType()==zSceneEntry::SceneEntry_Player) { isPlayer = true; //Zebra::logger->debug("isPetEnemy 119 %s->%s",master->name,entry->name); ret = isUserMasterEnemy(entry); } else { //Zebra::logger->debug("isPetEnemy 124 %s->%s",master->name,entry->name); ret = master->isEnemy(entry,notify); } } else ret = 1; } else ret = 0; } else ret = -1; } else ret = -1; } else ret = -1; } } else ret = -1; if (isPlayer) { if (ret==1) return 1; else return 0; } else { return ret; } }
/** * \brief 向主人移动 * * \return 是否移动成功 */ bool ScenePet::moveToMaster() { #ifdef _DEBUG //Channel::sendNine(this,"ScenePet::moveToMaster()"); #endif if (type==Cmd::PET_TYPE_SEMI || type==Cmd::PET_TYPE_TURRET ) return false; //sky 炮台也是不移动的 SceneEntryPk * master = getMaster(); if (!master) return false; if ( petData.ai&Cmd::PETAI_MOVE_FOLLOW ) { AIC->setActRegion(master->getPos(),2,2); if (!canMove()) { check(); if (getMaster()) return false; else return true; } //check(); if (checkMoveTime(SceneTimeTick::currentTime)) { if (master->scene == scene) { check(); if (0==masterID) return true;//运镖成功删除了主人 //超出瞬移范围 if (!(scene->zPosShortRange(getPos(),master->getPos(),npc_pet_warp_region))) return warp(master->getPos()); //离开较远距离 int region = isFighting()?npc_pet_run_region+4:npc_pet_run_region; if (!(scene->zPosShortRange(getPos(),master->getPos(),region))) { if (!speedUpOffMaster) { setSpeedRate(getSpeedRate()*2.0); speedUpOffMaster = true; } } else { //在主人身边 region = isFighting()?npc_pet_chase_region+5:npc_pet_chase_region; if ((scene->zPosShortRange(getPos(),master->getPos(),region))) { if (speedUpOffMaster) { resetSpeedRate(); speedUpOffMaster = false; } //check(); return false; } } unChaseUser(); if (aif&AIF_WARP_MOVE) return warp(master->getPos()); else { if (!gotoFindPath(getPos(),master->getPos())) return goTo(master->getPos()); } } else { if (master->scene) { if (changeMap(master->scene,master->getPos())) { check(); return true; } else return false; } } } } return false; }
/** * \brief 当主人是玩家时,以主人的身份进行敌我判断 * \param entry 判断的对象 * \return 0:友方 1:敌人 -1:中立 */ int ScenePet::isUserMasterEnemy(SceneEntryPk * entry) { SceneEntryPk * temp = getTopMaster(); SceneUser * tm = 0;//top master if (temp && temp->getType()==zSceneEntry::SceneEntry_Player) tm = (SceneUser*)temp; else return -1; // TODO 判断传入角色与主人是否为朋友关系 if (tm==entry) return 0; SceneEntryPk * entryMaster = entry->getTopMaster(); using namespace Cmd; //if (PKMODE_ENTIRE==pkMode) return 1; switch (entryMaster->getType()) { case zSceneEntry::SceneEntry_Player: { SceneUser *pUser = (SceneUser *)entryMaster; if (pUser == tm) return 0; bool def_gem = false; bool my_gem = false; if (tm->issetUState(Cmd::USTATE_TOGETHER_WITH_TIGER) || tm->issetUState(Cmd::USTATE_TOGETHER_WITH_DRAGON)) { my_gem = true; } if (pUser->issetUState(Cmd::USTATE_TOGETHER_WITH_TIGER) || pUser->issetUState(Cmd::USTATE_TOGETHER_WITH_DRAGON)) { def_gem = true; } if ((pUser->charbase.level<20) && (!pUser->isWarRecord(Cmd::COUNTRY_FORMAL_DARE,tm->charbase.country)) && (!def_gem)) return 0; if ((tm->charbase.level<20) && (!tm->isWarRecord(Cmd::COUNTRY_FORMAL_DARE,pUser->charbase.country)) && (!my_gem)) return 0; if (tm->scene == pUser->scene && !(my_gem || def_gem)) { //if (tm->charbase.country == pUser->charbase.country) //{ if (tm->charbase.level <= tm->scene->getPkLevel() && pUser->charbase.level >tm->scene->getPkLevel() && (!tm->isWarRecord(Cmd::SEPT_NPC_DARE,pUser->charbase.septid))) { return 0; } if (tm->charbase.level > tm->scene->getPkLevel() && pUser->charbase.level <= tm->scene->getPkLevel() && (!tm->isWarRecord(Cmd::SEPT_NPC_DARE,pUser->charbase.septid))) { return 0; } //} //else //{ // if (tm->charbase.level <= tm->scene->getPkLevel()-10 && pUser->charbase.level >tm->scene->getPkLevel()-10 // && (!tm->isWarRecord(Cmd::SEPT_NPC_DARE,pUser->charbase.septid))) // { // return 0; // } // if (tm->charbase.level > tm->scene->getPkLevel()-10 && pUser->charbase.level <= tm->scene->getPkLevel()-10 // && (!tm->isWarRecord(Cmd::SEPT_NPC_DARE,pUser->charbase.septid))) // { // return 0; // } //} } if (tm->isDiplomatState() ==0 || pUser->isDiplomatState() == 0) { return 0; } switch (tm->pkMode) { case PKMODE_NORMAL: { return 0; } break; case PKMODE_TEAM: { //是同一组队或者是增益类魔法 if ((tm->TeamThisID != 0) && (pUser->TeamThisID == tm->TeamThisID)) return 0; else return 1; } break; case PKMODE_TONG: { if (tm->charbase.unionid != 0 && tm->charbase.unionid == pUser->charbase.unionid) return 0; else return 1; } break; case PKMODE_SEPT: { if (tm->charbase.septid != 0 && tm->charbase.septid == pUser->charbase.septid) return 0; else return 1; } break; case PKMODE_COUNTRY: { if (tm->charbase.country != 0 && ((tm->charbase.country == pUser->charbase.country) || (CountryAllyM::getMe().getFriendLevel(tm->charbase.country, pUser->charbase.country)>0 && (pUser->isSpecWar(Cmd::COUNTRY_FORMAL_DARE) || tm->isSpecWar(Cmd::COUNTRY_FORMAL_DARE))))) return 0; else return 1; } break; case PKMODE_GOODNESS: { if (pUser->isRedNamed(false)||pUser->charbase.country!=tm->charbase.country) return 1; else return 0; } break; case PKMODE_ALLY: { if ((CountryAllyM::getMe().getFriendLevel(pUser->charbase.country,tm->charbase.country)>0)|| (pUser->charbase.country==tm->charbase.country)) return 0; else return 1; } break; case PKMODE_ENTIRE: { if (pUser->isPkZone(tm)&&tm->isPkZone(pUser)) return 1; else return 0; } default: break; } return 0; } break; case zSceneEntry::SceneEntry_NPC: { SceneNpc * n = (SceneNpc *)entry; if (n->id==COUNTRY_MAIN_FLAG //这几个不在这里判断 || n->id==COUNTRY_SEC_FLAG || n->isMainGeneral() || n->id==COUNTRY_KING_MAIN_FLAG || n->id==COUNTRY_KING_SEC_FLAG || n->id==COUNTRY_SEC_GEN || n->id==COUNTRY_EMPEROR_MAIN_GEN || n->id==COUNTRY_EMPEROR_SEC_GEN) return 1; //国外npc if (!n->isBugbear()) { if (n->npc->flags==1 && tm->charbase.country!=n->scene->getCountryID()) return 1; else return -1; } SceneEntryPk * m = n->getMaster(); if (m) { //Zebra::logger->debug("isPetEnemy 183 %s->%s",tm->name,n->getMaster()->name); if (!scene->zPosShortRange(n->getPos(),m->getPos(),20) && n->getPetType()==Cmd::PET_TYPE_GUARDNPC) return 1; else return tm->isEnemy(m); } if ((n->aif&AIF_ATK_REDNAME)||(n->npc->kind==NPC_TYPE_GUARD)) { if (tm->isRedNamed()) return 1; if (tm->charbase.country!=tm->scene->getCountryID()) return 1; if (tm->charbase.goodness&Cmd::GOODNESS_ATT) return 1; } switch (n->npc->kind) { case NPC_TYPE_HUMAN: ///人型 case NPC_TYPE_NORMAL: /// 普通类型 case NPC_TYPE_BBOSS: /// 大Boss类型 case NPC_TYPE_LBOSS: /// 小Boss类型 case NPC_TYPE_PBOSS: /// 紫Boss类型 case NPC_TYPE_BACKBONE: /// 精英类型 case NPC_TYPE_GOLD: /// 黄金类型 case NPC_TYPE_SUMMONS: /// 召唤类型 case NPC_TYPE_AGGRANDIZEMENT: /// 强化类型 case NPC_TYPE_ABERRANCE: /// 变异类型 case NPC_TYPE_BACKBONEBUG: /// 精怪类型 case NPC_TYPE_PET: /// 宠物类型 case NPC_TYPE_TOTEM: /// 图腾类型 case NPC_TYPE_GHOST: ///元神类 case NPC_TYPE_TURRET: /// 炮塔 case NPC_TYPE_BARRACKS: case NPC_TYPE_CAMP: case NPC_TYPE_ANIMON: /// 动物类 //case NPC_TYPE_DUCKHIT: /// 花草 return 1; case NPC_TYPE_GUARD: /// 士兵类型 case NPC_TYPE_SOLDIER: /// 士兵类型 { if (tm->charbase.country!=scene->getCountryID()) return 1; if (tm->pkMode==PKMODE_ENTIRE) return 1; return 0; } case NPC_TYPE_UNIONGUARD: if (tm->isAtt(Cmd::UNION_CITY_DARE)) return 1; else if (tm->scene->getUnionDare() && !tm->isSpecWar(Cmd::UNION_CITY_DARE) && !n->isMainGeneral())//大将军第三方不能打 return 1;//中立方 else return 0;//城战期间打城战而且不是攻方,就是守方 break; case NPC_TYPE_UNIONATTACKER: if (tm->isAtt(Cmd::UNION_CITY_DARE)) return 0; else if (tm->scene->getUnionDare() && !tm->isSpecWar(Cmd::UNION_CITY_DARE)) return 1;//中立方 else return 1;//城战期间打城战而且不是攻方,就是守方 break; default: return -1; } return -1; } break; default: return -1; break; } }