OSDN Git Service

Merge branch 'master' of o_ggy@git.sourceforge.jp:/gitroot/moflib/moflib
[moflib/moflib.git] / saisei-1.0 / rpg / rpg / oldcode / DataBasedBattler.cpp
1 #include "DataBasedBattler.h"
2 #include "mof/KeyFrameAnimation.h"
3 #include "mof/DataBasedAnimation.h"
4 #include <sstream>
5 #include "NormalAI.h"
6 //#include "AttackerAI.h"
7
8 et::DataBasedBattler::DataBasedBattler(const TCHAR* pName , mof::DataResourceManager* pDataResourceManager , mof::TextureManager* pTextureManager , TCHAR serialCode)
9 : BattlerFacade(et::ENEMY)
10 {
11         m_pDataResourceManager = pDataResourceManager;
12         mof::DataResource resource = m_pDataResourceManager->getResource(_T("data/monster.csv"));
13         m_targetRow = mof::DataRow(resource , pName);
14         m_pAI = NULL;
15
16         std::basic_ostringstream<TCHAR> stream;
17         stream << m_targetRow.getData( _T("Name")) << serialCode;
18         BattlerParameter parameter;
19         parameter.hp = m_targetRow.getIntegerData(_T("Hp"));
20         parameter.maxHp = parameter.hp;
21         parameter.attack = m_targetRow.getIntegerData(_T("Offense"));
22         parameter.diffence = m_targetRow.getIntegerData(_T("Defense"));
23         parameter.name = stream.str();
24         parameter.speed = m_targetRow.getIntegerData(_T("Speed"));
25         parameter.actionPoint = 3;
26         parameter.dActionPoint = 0;
27         setParameter(parameter);
28         
29         mof::DataResource typeResource = m_pDataResourceManager->getResource(_T("data/monster.type.csv"));
30         m_typeRow = mof::DataRow(typeResource , m_targetRow.getData(_T("Type")).c_str());
31         std::basic_ostringstream<TCHAR> stream2;
32         stream2 << _T("image/") << m_typeRow.getData(_T("Image"));
33         m_pGraphicsObject = new mof::Billboard(mof::Billboard::Y_FIXED , pTextureManager->getResource(stream2.str()));
34         
35
36         updateAI(m_targetRow.getData(_T("AI")).c_str());
37         
38
39         mof::KeyFrameAnimation* pAnimation = new mof::KeyFrameAnimation();
40         pAnimation->setScale(0 , mof::Vector3D(0.3f , 0.3f , 0.3f));
41         pAnimation->setTextureRectangle(0 , mof::Line2D(0 , 0 , 64 , 64));
42         getGraphicsObject()->setAnimation( 0 , mof::AnimationResource(pAnimation));
43         
44 }
45
46 et::DataBasedBattler::~DataBasedBattler(void)
47 {
48         
49 }
50
51
52 void et::DataBasedBattler::updateAI(const TCHAR* const pName){
53         delete m_pAI;
54
55         //AI\83I\83u\83W\83F\83N\83g\82ð\82Â\82­\82é
56         mof::tstring ai = m_targetRow.getData(_T("AI"));
57         if(ai == _T("\83U\83R\83^\83C\83v"))m_pAI = new NormalAI(m_pDataResourceManager);
58         else if(ai == _T("\83A\83^\83b\83J\81["))m_pAI = new NormalAI(m_pDataResourceManager);
59 }
60
61
62 mof::AnimationResource et::DataBasedBattler::setMovingAnimation(mof::Vector3D& goal , int nFrame){
63         mof::KeyFrameAnimation* pAnimation = new mof::KeyFrameAnimation();
64         pAnimation->setPosition(0 , getPosition());
65         pAnimation->setPosition(nFrame-1 , goal);
66         mof::AnimationResource resource(pAnimation);
67         getGraphicsObject()->setAnimation( 1 , resource);
68         return resource;
69 }
70
71 mof::AnimationResource et::DataBasedBattler::setAidlingAnimation(mof::Vector3D& position ){
72         if(!getParameter().alive){
73                 //\89½\82à\95\\8e¦\82µ\82È\82¢
74                 mof::KeyFrameAnimation* pAnimation = new mof::KeyFrameAnimation(true);
75                 pAnimation->setPosition(0 , position);
76                 pAnimation->setTextureRectangle(0 , mof::Line2D(1 , 1 , 1 , 1));
77                 mof::AnimationResource resource(pAnimation);
78                 getGraphicsObject()->setAnimation( 1 , resource);
79                 return resource;
80         }
81         else if(getParameter().guard && getType() == et::HERO){
82                 //\83K\81[\83h
83                 mof::KeyFrameAnimation* pAnimation = new mof::KeyFrameAnimation(true);
84                 pAnimation->setPosition(0 , position);
85                 pAnimation->setTextureRectangle(0 , mof::Line2D(0 , 64*2 , 64 , 64*3));
86                 mof::AnimationResource resource(pAnimation);
87                 getGraphicsObject()->setAnimation( 1 , resource);
88                 return resource;
89         }
90         else {
91                 mof::CascadeAnimation* pCascadeAnimation = new mof::CascadeAnimation();
92                 {
93                         mof::KeyFrameAnimation* pBaseAnimation = new mof::KeyFrameAnimation(true);
94                         pBaseAnimation->setPosition(0 , mof::Vector3D(position));
95                         pCascadeAnimation->setElement(0 , mof::AnimationResource(pBaseAnimation));
96                 }
97
98                 pCascadeAnimation->setElement(1 , mof::AnimationResource(
99                         new mof::DataBasedAnimation(m_typeRow.getData(_T("AidlingMotion")).c_str() , true)));
100
101                 mof::AnimationResource resource(pCascadeAnimation);
102                 getGraphicsObject()->setAnimation( 1 , resource);
103                 return resource;
104         }
105 }
106
107 mof::AnimationResource et::DataBasedBattler::setCastAnimation(int category){
108         
109         const TCHAR* const table[] = {_T("DirectAttack1Motion") , _T("DirectAttack2Motion") , 
110                 _T("SpecialAttack1Motion") , _T("SpecialAttack2Motion")};
111
112         mof::CascadeAnimation* pCascadeAnimation = new mof::CascadeAnimation();
113         {
114                 mof::KeyFrameAnimation* pBaseAnimation = new mof::KeyFrameAnimation();
115                 pBaseAnimation->setPosition(0 , mof::Vector3D(getPosition()));
116                 //pBaseAnimation->setFinalKey(20);
117                 pCascadeAnimation->setElement(0 , mof::AnimationResource(pBaseAnimation));
118         }
119         pCascadeAnimation->setElement(1 , mof::AnimationResource(
120                 new mof::DataBasedAnimation(m_typeRow.getData(table[category] ).c_str() )));
121         mof::AnimationResource resource(pCascadeAnimation);
122         getGraphicsObject()->setAnimation( 1 , resource);
123         return resource;
124         
125 }
126
127 mof::AnimationResource et::DataBasedBattler::setDamagedAnimation(int level){
128         mof::KeyFrameAnimation* pAnimation = new mof::KeyFrameAnimation();
129         if(level == 0){
130                 //\92Ê\8fí
131                 mof::Vector3D backPosition = getPosition();
132                 backPosition.x += (getType() == et::ENEMY)? -0.1f : 0.1f;
133                 pAnimation->setPosition(0 , getPosition());
134                 pAnimation->setPosition(10 , backPosition);
135                 pAnimation->setPosition(40 , backPosition);
136                 pAnimation->setPosition(60 , getPosition());
137         
138                 pAnimation->setTextureRectangle(0 , mof::Line2D(0 , 0 , 64 , 64));
139                 pAnimation->setTextureRectangle(8 , mof::Line2D(64*3 , 0 , 256 , 64));
140                 pAnimation->setTextureRectangle(10 , mof::Line2D(1 , 1 , 1 , 1));
141                 pAnimation->setTextureRectangle(12 , mof::Line2D(64*3 , 0 , 256 , 64));
142                 pAnimation->setTextureRectangle(14 , mof::Line2D(1 , 1 , 1 , 1));
143                 pAnimation->setTextureRectangle(16 , mof::Line2D(1 , 1 , 1 , 1));
144                 pAnimation->setTextureRectangle(26 , mof::Line2D(0 , 0 , 64 , 64));
145                 
146         }
147         else if(level == 1){
148                 //\8e\80\96S
149                 /*if(getType() == et::HERO){
150                         //\83C\83G\83A\83A\83A\83A\83A
151                         mof::Vector3D backPosition = getPosition();
152                         backPosition.x += (getType() == et::ENEMY)? -0.1f : 0.1f;
153                         pAnimation->setPosition(0 , getPosition());
154                         pAnimation->setPosition(10 , backPosition);
155                         pAnimation->setPosition(20 , backPosition);
156                         backPosition.y += 0.4;
157                         pAnimation->setPosition(100 , backPosition);
158                 
159                         pAnimation->setTextureRectangle(0 , mof::Line2D(0 , 0 , 64 , 64));
160                         pAnimation->setTextureRectangle(8 , mof::Line2D(64*3 , 0 , 256 , 64));
161                         pAnimation->setTextureRectangle(10 , mof::Line2D(1 , 1 , 1 , 1));
162                         pAnimation->setTextureRectangle(12 , mof::Line2D(64*3 , 0 , 256 , 64));
163                         pAnimation->setTextureRectangle(14 , mof::Line2D(64*3 , 64 , 256 , 64*2));
164                         pAnimation->setTextureRectangle(150 , mof::Line2D(64*3 , 64 , 256 , 64*2));
165                 }
166                 else{*/
167                 mof::Vector3D backPosition = getPosition();
168                 backPosition.x += (getType() == et::ENEMY)? -0.1f : 0.1f;
169                 pAnimation->setPosition(0 , getPosition());
170                 pAnimation->setPosition(10 , backPosition);
171                 
172                 pAnimation->setTextureRectangle(0 , mof::Line2D(0 , 0 , 64 , 64));
173                 pAnimation->setTextureRectangle(8 , mof::Line2D(64*3 , 0 , 256 , 64));
174                 pAnimation->setTextureRectangle(10 , mof::Line2D(1 , 1 , 1 , 1));
175                 pAnimation->setTextureRectangle(12 , mof::Line2D(64*3 , 0 , 256 , 64));
176                 pAnimation->setTextureRectangle(14 , mof::Line2D(1 , 1 , 1 , 1));
177                 pAnimation->setTextureRectangle(25 , mof::Line2D(1 , 1 , 1 , 1));
178                 //}
179         }
180         mof::AnimationResource resource(pAnimation);
181         getGraphicsObject()->setAnimation( 1 , resource);
182         return resource;
183 }
184
185
186 et::Action* et::DataBasedBattler::createAction(BattlerGroup* pGroup ) {
187         return m_pAI->createAction(this , pGroup);
188 }
189