void CreatureManager::ProcessSelectCreature() { if(m_nSelectNum >= 0) { Character* selectChar = GetCreature(m_nSelectNum); if((selectChar->GetCamp() == eCamp_Enemy) || (selectChar->GetCamp()==eCamp_Friend && selectChar->GetCharacterState()==eCharacterState_Stand && selectChar->GetActionStage() ==eActionStage_MoveStage)) ShowMoveRange(selectChar); if(selectChar->GetCamp() == eCamp_Enemy || (selectChar->GetCamp()==eCamp_Friend && (selectChar->GetActionStage()==eActionStage_AttackStage || selectChar->GetActionStage()==eActionStage_SkillStage))) ShowAttackRange(selectChar); } }
void CreatureManager::Update(float delta) { for (VCharacter::iterator it=m_VEnemyList.begin();it!=m_VEnemyList.end();it++) (*it)->Update(delta); for (VCharacter::iterator it=m_VFriendList.begin();it!=m_VFriendList.end();it++) (*it)->Update(delta); if(m_nActionCreatureNum != -1) { Character* cha = GetEnemy(m_nActionCreatureNum); if(cha->GetFinish()) m_nActionCreatureNum = -1; //测试用 if (cha->GetCamp() == eCamp_Enemy && cha->GetActionStage() == eActionStage_AttackStage) { m_nActionCreatureNum = -1; cha->SetFinish(true); } } SelectCreature(); UnSelectCreature(); ShowCreatureInfo(); }
void CreatureManager::UnSelectCreature() { if (m_nSelectNum >= 0) { int nLastSelect = m_nSelectNum; if (g_getRButtonState(App::sInstance().GetHGE()) == eRButtonState_Up) { Character* lastChar = GetCreature(nLastSelect); if(lastChar!=NULL && lastChar->GetCamp()==eCamp_Friend) { //返回至原位置 if(lastChar->GetActionStage() == eActionStage_AttackStage) { lastChar->SetActionStage(eActionStage_MoveStage); lastChar->CancelMove(); } //右键取消选中的友方,需要重置行动阶段,处于移动中的单位不可以当时取消 else if(lastChar->GetActionStage() == eActionStage_MoveStage && lastChar->GetCharacterState()==eCharacterState_Stand) { lastChar->SetActionStage(eActionStage_WaitStage); m_nSelectNum = -1; } } else m_nSelectNum = -1; } } }
void CreatureManager::Update(float delta) { for (VCharacter::iterator it=m_VEnemyList.begin();it!=m_VEnemyList.end();it++) { if((*it)->GetDead() == true) m_VEnemyDeadList.push_back(*it); else (*it)->Update(delta); } for (VCharacter::iterator it=m_VFriendList.begin();it!=m_VFriendList.end();it++) { if((*it)->GetDead() == true) m_VFriendDeadList.push_back(*it); else (*it)->Update(delta); } //移除死亡单位 for (int i=0;i<m_VEnemyDeadList.size();i++) { RemoveEnemy(m_VEnemyDeadList[i]); } m_VEnemyDeadList.clear(); for (int i=0;i<m_VFriendDeadList.size();i++) { RemoveEnemy(m_VFriendDeadList[i]); } m_VFriendDeadList.clear(); if(m_nActionCreatureNum != -1) { Character* cha = GetEnemy(m_nActionCreatureNum); if(cha->GetFinish()) m_nActionCreatureNum = -1; //测试用 if (cha->GetCamp() == eCamp_Enemy && cha->GetActionStage() == eActionStage_HandleStage) { m_nActionCreatureNum = -1; cha->SetFinish(true); } } SelectCreature(); UnSelectCreature(); ShowCreatureInfo(); }
void CreatureManager::UnSelectCreature() { if (m_nSelectNum >= 0) { int nLastSelect = m_nSelectNum; if (g_getRButtonState(App::sInstance().GetHGE()) == eRButtonState_Up) { Character* lastChar = GetCreature(nLastSelect); if(lastChar!=NULL && lastChar->GetCamp()==eCamp_Friend && !(lastChar->GetFinish())) { //返回至原位置 eActionStage stage = lastChar->GetActionStage(); if(stage == eActionStage_HandleStage) { lastChar->SetActionStage(eActionStage_MoveStage); lastChar->CancelMove(); //关闭操作界面 UIWindow* commandWindow = UISystem::sInstance().GetWindow(eWindowID_Command); if(commandWindow) { commandWindow->SetShow(false); } } //攻击阶段、技能阶段、使用物品阶段可以返回至操作阶段 else if(stage == eActionStage_AttackStage || stage == eActionStage_GoodStage || stage == eActionStage_SkillStage) { lastChar->SetActionStage(eActionStage_HandleStage); //打开操作界面 UIWindow* commandWindow = UISystem::sInstance().GetWindow(eWindowID_Command); if(commandWindow) { commandWindow->SetShow(true); commandWindow->SetBindChar(lastChar); } } //右键取消选中的友方,需要重置行动阶段,处于移动中的单位不可以当时取消 else if(stage == eActionStage_MoveStage && lastChar->GetCharacterState()==eCharacterState_Stand) { lastChar->SetActionStage(eActionStage_WaitStage); m_nSelectNum = -1; } } else m_nSelectNum = -1; } } }
void CreatureManager::SelectCreature() { //友方回合才可以进行选择操作,包括查看敌方行动范围 if (m_eCampTurn == eCampTurn_Friend) { Block mouseBlock = App::sInstance().GetMouseBlock(); Character* selectChar = NULL; if (mouseBlock.xpos!=-1 && mouseBlock.ypos!=-1) { selectChar = GetCreature(mouseBlock.xpos,mouseBlock.ypos); //选中单位 if(selectChar!=NULL) { //需要拦截点击操作界面的消息 if (g_getLButtonState(App::sInstance().GetHGE()) == eLButtonState_Up && !(UISystem::sInstance().GetWindow(eWindowID_Command)->IsOnControl())) { int nLastSelect = m_nSelectNum; if (selectChar->GetCamp() == eCamp_Friend ) { //上次没有选择单位 if(nLastSelect == -1) { //选中的未行动友方进入移动阶段 if(!selectChar->GetFinish()) { m_nSelectNum = selectChar->GetNum(); selectChar->SetActionStage(eActionStage_MoveStage); } } //连续两次点击同一友方单位 else if(nLastSelect == selectChar->GetNum()) { if(!selectChar->GetFinish()) { //跳过移动阶段,进入操作阶段 selectChar->SetActionStage(eActionStage_HandleStage); //打开操作界面 UIWindow* commandWindow = UISystem::sInstance().GetWindow(eWindowID_Command); if(commandWindow) { commandWindow->SetShow(true); commandWindow->SetBindChar(selectChar); } } } //其他情况 else { Character* lastChar = GetCreature(nLastSelect); if(lastChar != NULL) { //上次点的是别的友方 if(lastChar->GetCamp() == eCamp_Friend) { if(lastChar->GetFinish() && !selectChar->GetFinish()) { m_nSelectNum = selectChar->GetNum(); selectChar->SetActionStage(eActionStage_MoveStage); } // //上次的友方返回至待命阶段 // lastChar->SetActionStage(eActionStage_WaitStage); // selectChar->SetActionStage(eActionStage_MoveStage); } else if(lastChar->GetCamp() == eCamp_Enemy) { if(!selectChar->GetFinish()) { m_nSelectNum = selectChar->GetNum(); selectChar->SetActionStage(eActionStage_MoveStage); } } } else //这里是错误分支,不可以运行到这里 return; } } else if (selectChar->GetCamp() == eCamp_Enemy) { Character* lastChar = GetCreature(nLastSelect); if(lastChar!=NULL) { if(lastChar->GetCamp()==eCamp_Friend) { if(lastChar->GetActionStage() == eActionStage_AttackStage) { //判断是否可以攻击到选中单位 if(lastChar->CanHitTarget(selectChar)) { lastChar->SetTarget(selectChar->GetNum()); lastChar->GeginHit(); m_nSelectNum = -1; return; } } } else if (lastChar->GetCamp() == eCamp_Enemy) { m_nSelectNum = selectChar->GetNum(); } } else { m_nSelectNum = selectChar->GetNum(); } } } } //点中地面 else { if (g_getLButtonState(App::sInstance().GetHGE()) == eLButtonState_Up && !(UISystem::sInstance().GetWindow(eWindowID_Command)->IsOnControl())) { if (m_nSelectNum>=0) { selectChar = GetCreature(m_nSelectNum); if (selectChar!= NULL) { if(selectChar->GetCamp() == eCamp_Friend && selectChar->GetActionStage() == eActionStage_MoveStage) { //判断是否可以移动过去 int length = abs(mouseBlock.xpos - selectChar->GetBlock().xpos) + abs(mouseBlock.ypos - selectChar->GetBlock().ypos); //超过移动范围 if(length > selectChar->GetMoveAbility()) return; //移动过去,记录原始位置 selectChar->GetOrigBlock().xpos = selectChar->GetBlock().xpos; selectChar->GetOrigBlock().ypos = selectChar->GetBlock().ypos; selectChar->GetOrigDirection() = selectChar->GetCurDirection(); selectChar->Move(mouseBlock.xpos,mouseBlock.ypos); } } } } } } } }
void CreatureManager::SelectCreature() { //友方回合才可以进行选择操作,包括查看敌方行动范围 if (m_eCampTurn == eCampTurn_Friend) { Block mouseBlock = App::sInstance().GetMouseBlock(); Character* selectChar = NULL; if (mouseBlock.xpos!=-1 && mouseBlock.ypos!=-1) { selectChar = GetCreature(mouseBlock.xpos,mouseBlock.ypos); //选中单位 if(selectChar!=NULL) { if (g_getLButtonState(App::sInstance().GetHGE()) == eLButtonState_Up) { int nLastSelect = m_nSelectNum; if (selectChar->GetCamp() == eCamp_Friend ) { //上次没有选择单位 if(nLastSelect == -1) { //选中的未行动友方进入移动阶段 if(!selectChar->GetFinish()) { m_nSelectNum = selectChar->GetNum(); selectChar->SetActionStage(eActionStage_MoveStage); } } //连续两次点击同一友方单位 else if(nLastSelect == m_nSelectNum) { //过滤移动阶段,进入攻击阶段 selectChar->SetActionStage(eActionStage_AttackStage); } //其他情况 else { Character* lastChar = GetCreature(nLastSelect); if(lastChar != NULL) { //上次点的是别的友方 if(lastChar->GetCamp() == eCamp_Friend) { // //上次的友方返回至待命阶段 // lastChar->SetActionStage(eActionStage_WaitStage); // selectChar->SetActionStage(eActionStage_MoveStage); } else if(lastChar->GetCamp() == eCamp_Enemy) { if(!selectChar->GetFinish()) { m_nSelectNum = selectChar->GetNum(); selectChar->SetActionStage(eActionStage_MoveStage); } } } else //这里是错误分支,不可以运行到这里 return; } } else if (selectChar->GetCamp() == eCamp_Enemy) { Character* lastChar = GetCreature(nLastSelect); if(lastChar!=NULL) { if(lastChar->GetCamp()==eCamp_Friend) { if(lastChar->GetActionStage() == eActionStage_AttackStage) { //判断是否可以攻击到选中单位 eAttackRange attackRange = lastChar->GetAttackRange(); int tarX = 0,tarY = 0; for (MAttackRange::iterator mit=m_mAttackRange.begin();mit!=m_mAttackRange.end();mit++) { if(mit->first == attackRange) { for (vector<Pair>::iterator it=mit->second.begin();it!=mit->second.end();it++) { tarX = it->x + lastChar->GetBlock().xpos; tarY = it->y + lastChar->GetBlock().ypos; if(selectChar->GetBlock().xpos == tarX && selectChar->GetBlock().ypos == tarY) { //在攻击范围内 lastChar->SetTarget(selectChar->GetNum()); lastChar->GeginHit(); m_nSelectNum = -1; return; } } } } } } else if (lastChar->GetCamp() == eCamp_Enemy) { m_nSelectNum = selectChar->GetNum(); } } else { m_nSelectNum = selectChar->GetNum(); } } } } //点中地面 else { if (g_getLButtonState(App::sInstance().GetHGE()) == eLButtonState_Up) { if (m_nSelectNum>=0) { selectChar = GetCreature(m_nSelectNum); if (selectChar!= NULL) { if(selectChar->GetCamp() == eCamp_Friend && selectChar->GetActionStage() == eActionStage_MoveStage) { //判断是否可以移动过去 int length = abs(mouseBlock.xpos - selectChar->GetBlock().xpos) + abs(mouseBlock.ypos - selectChar->GetBlock().ypos); //超过移动范围 if(length > selectChar->GetMoveAbility()) return; //移动过去,记录原始位置 selectChar->GetOrigBlock().xpos = selectChar->GetBlock().xpos; selectChar->GetOrigBlock().ypos = selectChar->GetBlock().ypos; selectChar->GetOrigDirection() = selectChar->GetCurDirection(); selectChar->Move(mouseBlock.xpos,mouseBlock.ypos); } } } } } } } }