OSDN Git Service

4a68d4c5ff8bc50390fde6d49604383a01c86b26
[moflib/moflib.git] / saisei-1.0 / rpg / rpg / oldcode / BattleData.cpp~
1 #include "BattleData.h"
2 #include "mof/KeyFrameAnimation.h"
3 #include "AttackAction.h"
4 #include "SpecialAction.h"
5 #include "GameData.h"
6 #include "BattlerGroup.h"
7 #include "BattlerFacade.h"
8
9 et::BattleData::BattleData(mof::TextureManager* pTextureManager , et::GameData* pGameData , et::BattlerGroup* pGroup)
10 {
11         m_pGameData = pGameData;
12         m_pTextureManager = pTextureManager;
13         m_battleAction.type = BattleAction::NONE;
14         et::BattlerParameter parameter;
15         m_pGroup = pGroup;
16         //m_battlerList.push_back(new Battler(parameter , m_pTextureManager));
17 }
18
19 et::BattleData::~BattleData(void)
20 {
21         delete m_pGroup;
22 }
23
24
25
26 /*
27 void et::BattleData::addBattler(et::BattlerFacade* pBattler){
28         m_battlerList.push_back(pBattler);
29 }
30
31
32 void et::BattleData::layoutBattler(){
33         int nEnemy = 0;
34         int nIdeal = 0;
35         
36         //\91O\92²\8d¸
37         for(std::list<BattlerFacade*>::iterator itr = m_battlerList.begin() ; itr != m_battlerList.end() ; ++itr){
38                 if((*itr)->getType() == et::ENEMY)nEnemy++;
39                 else if((*itr)->getType() == et::IDEAL)nIdeal++;
40         }
41
42         int cntEnemy = 0;
43         int cntIdeal = 0;
44         float zTable[3][3] = { {0.6f , 0.6f , 0.6f} , { 0.8f , 0.4f , 0.6f} , {0.86f , 0.6f , 0.34f} };//[\91\8d\90\94][\94Ô\8d\86]
45         float xTable[3][3] = { {0.0f , 0.0f , 0.0f} , { 0.1f , -0.1f , 0.6f} , {0.15f , 0.0f , -0.15f} };//[\91\8d\90\94][\94Ô\8d\86]
46         float ixTable[3][3] = { {0.2f , 0.0f , 0.0f} , { 0.0f , 0.07f , 0.6f} , {0.0f , 0.1f , 0.15f} };//[\91\8d\90\94][\94Ô\8d\86]
47         for(std::list<BattlerFacade*>::iterator itr = m_battlerList.begin() ; itr != m_battlerList.end() ; ++itr){
48                 if((*itr)->getType() == et::HERO){
49                         (*itr)->setAidlingAnimation(mof::Vector3D(0.3f , 0.0f , 0.6f));
50                         (*itr)->setBasePosition(mof::Vector3D(0.3f , 0.0f , 0.6f));
51                 }
52                 else if((*itr)->getType() == et::ENEMY){
53                         mof::KeyFrameAnimation* pAnimation = new mof::KeyFrameAnimation();
54                         (*itr)->setAidlingAnimation(mof::Vector3D(-0.45f + xTable[nEnemy-1][cntEnemy] , 0.0f , zTable[nEnemy-1][cntEnemy]));
55                         (*itr)->setBasePosition(mof::Vector3D(-0.45f + xTable[nEnemy-1][cntEnemy] , 0.0f , zTable[nEnemy-1][cntEnemy]));
56                         cntEnemy++;     
57                 }
58                 else if((*itr)->getType() == et::IDEAL){
59                         mof::KeyFrameAnimation* pAnimation = new mof::KeyFrameAnimation();
60                         (*itr)->setAidlingAnimation(mof::Vector3D(0.6 +ixTable[nIdeal-1][cntIdeal] , 0.0f , zTable[nIdeal-1][cntIdeal]));
61                         cntIdeal++;     
62                 }
63         }
64
65 }
66
67
68 et::BattlerFacade* et::BattleData::getHeroBattler(){
69         for(std::list<BattlerFacade*>::iterator itr = m_battlerList.begin() ; itr != m_battlerList.end() ; ++itr){
70                 if((*itr)->getType() == et::HERO){
71                         return *itr;
72                 }
73         }
74         assert(0);
75         return NULL;
76 }
77
78 et::BattlerFacade* et::BattleData::getEnemyBattler(int index){
79         int cntEnemy = 0;
80         for(std::list<BattlerFacade*>::iterator itr = m_battlerList.begin() ; itr != m_battlerList.end() ; ++itr){
81                 if((*itr)->getType() == et::ENEMY){
82                         if(cntEnemy++ == index)return *itr;
83                 }
84         }
85         return NULL;
86
87 }
88
89
90 et::BattlerFacade* et::BattleData::getIdealBattler(int index){
91         int cntIdeal = 0;
92         for(std::list<BattlerFacade*>::iterator itr = m_battlerList.begin() ; itr != m_battlerList.end() ; ++itr){
93                 if((*itr)->getType() == et::IDEAL){
94                         if(cntIdeal++ == index)return *itr;
95                 }
96         }
97         return NULL;
98 }
99
100
101 et::Action* et::BattleData::createBattlerAction(et::BattlerFacade* pBattler){
102         if(pBattler->getType() == et::HERO){
103                 et::BattleAction action = m_battleAction;
104                 m_battleAction.type = et::BattleAction::NONE;
105                 if(action.type == et::BattleAction::ATTACK_WEAPON){
106                         return new AttackAction(pBattler , action.pTarget , 3);
107                 }
108                 else if(action.type == et::BattleAction::WAIT || action.type == et::BattleAction::GUARD){
109                         return NULL;
110                 }
111                 else if(action.type == et::BattleAction::CAST){
112                         et::BattlerFacade* pIdeal = getIdealBattler(action.idealIndex);
113                         et::BattlerParameter parameter = pIdeal->getParameter();
114                         parameter.dActionPoint -= 5;
115                         pIdeal->setParameter(parameter);
116                         std::list<et::BattlerFacade*> targetList;
117                         if(action.pTarget != NULL)targetList.push_back(action.pTarget);
118                         else {
119                                 for(std::list<et::BattlerFacade*>::const_iterator itr = getBattlerList().begin() ; itr != getBattlerList().end() ; ++itr){
120                                         if((*itr)->getType() == et::ENEMY && (*itr)->getParameter().alive)targetList.push_back(*itr);
121                                 }
122                         }
123                         //\93Á\8eê\8bZ\82Ì\8eí\97Þ\82ð\93¾\82é
124                         return new SpecialAction(pBattler , targetList , 5 , action.idealIndex);
125                 }
126                 else if(action.type == et::BattleAction::USE_ITEM){
127                         //\83A\83C\83e\83\80\82ð\82È\82­\82·
128                         std::list<et::ItemData> &refList = getItemList();
129                         for(std::list<et::ItemData>::iterator itr = refList.begin() ; itr != refList.end() ; ++itr){
130                                 if(action.pTargetItem == &(*itr)){
131                                         refList.erase(itr);
132                                         break;
133                                 }
134                         }
135                         std::list<et::BattlerFacade*> targetList;
136                         if(action.pTarget != NULL)targetList.push_back(action.pTarget);
137                         else {
138                                 for(std::list<et::BattlerFacade*>::const_iterator itr = getBattlerList().begin() ; itr != getBattlerList().end() ; ++itr){
139                                         if((*itr)->getType() == et::ENEMY && (*itr)->getParameter().alive)targetList.push_back(*itr);
140                                 }
141                         }
142                         //\93Á\8eê\8bZ\82Ì\8eí\97Þ\82ð\93¾\82é
143                         return new SpecialAction(pBattler , targetList , 2 , 3);
144                 }
145                 else return NULL;
146         }
147         else {
148                 std::list<BattlerFacade*> enemyList;
149                 enemyList.push_back(getHeroBattler());
150                 std::list<BattlerFacade*> allyList;
151                 for(std::list<BattlerFacade*>::iterator itr = m_battlerList.begin() ; itr != m_battlerList.end() ; ++itr){
152                         if((*itr)->getType() == et::ENEMY && *itr != pBattler)allyList.push_back(*itr);
153                 }
154                 return pBattler->createNextAction(enemyList , allyList);
155                 
156         }
157
158 }*/
159
160 et::BattleAction et::BattleData::pollBattleAction(){
161         BattleAction action = m_battleAction;
162         m_battleAction.type = BattleAction::NONE;
163         return action;
164 }
165
166 bool et::BattleData::isOver(){
167         if(!m_pGroup->getHeroBattler()->getParameter().alive)return true;
168         //et::BattlerFacade* pEnemy = NULL;
169         return m_pGroup->getEnemyBattlerListAlive().size() == 0;
170         /*for(int i = 0 ; (pEnemy = m_pGroup->getEnemyBattlerAt(i)) != NULL ; i++){
171                 if(pEnemy->getParameter().alive)return false;
172         }
173         return true;*/
174         
175 }
176
177
178 std::list<et::ItemData>& et::BattleData::getItemList(){
179         return m_pGameData->getBattleItemList();
180 }