//宠物AI流程
.刚开始添加宠物
Monster被动State:EnumMonster被NULL
MonsterStat:EnumPet跟随
.附近有怪物就改成攻击模式(相关的收尾工作)
void PetObj::cancle_follow()
{
m_trace_line.clear();
is_move = false;
MonsterStat = EnumMonsterStat::EnumMonster追击;//将怪物的状态改成EnumMonster追击
}
//如果线路没有走完他会向客户端发送移动包和附近玩家通知包
.当把怪度打死并且目标列表中为空时就把气状态置为跟随
void PetObj::cancle_attached()
{
m_is_attached = false;//玩家已死,取消攻击记录
m_attach_objs.clear();//取消攻击记录
m_trace_line.clear();
is_move = false;
MonsterStat = EnumMonsterStat::EnumPet跟随;
}
.如果宠物在追击或者跟随的过程中和主人的距离超过20格子则会传送
void PetObj::传送()//这个函数写的有问题
{
MonsterStat = EnumMonsterStat::EnumPet跟随;//将状态置为跟随,传送之后其状态回到原始状态就是跟随 auto owner_map_pos = m_map->m_spBase->getMapPos(owner->tgtPos);
int mx = owner_map_pos.x;
int my = owner_map_pos.y; pos2d mPos = {mx, my};
int dir = ;
for(dir = ; dir < ; dir ++)
{
switch(dir)
{
case DIR_UP:
case DIR_LEFT:
case DIR_LEFTUP:
mPos.y++;
break;
case DIR_RIGHTUP:
mPos.x++;
break;
case DIR_RIGHT:
case DIR_RIGHTDOWN:
mPos.y--;
break;
case DIR_DOWN:
case DIR_LEFTDOWN:
mPos.x--;
break;
}
if(m_map->is_out_of_range(mPos.x, mPos.y) || !is_pet_stand(mPos))
continue;
if(m_map->m_vec_collsion[mPos.x][mPos.y] != )
break;
}
if(dir >= )
{
return;
} //给附近玩家 和 角色发送消息信息
for(auto it : map_nearby_player)
{
it.second->nearby_monsters.erase(objId.id);
std::vector<ObjecInfo> 远离的;
远离的.push_back(*this);
it.second->send_obj_leave(远离的);
}
for(auto it : map_nearby_objs)
{
it.second->map_nearby_objs.erase(objId.id);
}
//m_map->m_move_objs.erase(objId.id);//移除对象
m_map->m_move_mgr.del_mask(objId); pos2d bpos = _getBlockPos();
m_map->m_map_blocks[bpos.x][bpos.y].del(objId); map_nearby_objs.clear();
map_nearby_player.clear(); curPos = tgtPos = m_map->m_spBase->getPos(mx, my); auto cur_block_pos = m_map->m_spBase->getBlockPos(curPos);
block_x = cur_block_pos.x;
block_y = cur_block_pos.y; base_mpos.x = mx;
base_mpos.y = my; //加载到Map::的blockobj容器中
m_map->m_vec_collsion[mx][my] = ;//当前点设置为1 //加入到容器中
m_map->m_map_objs[objId.id] = this;
m_map->m_map_blocks[block_x][block_y].add(this);
init();
return;
}