36 #include "Core-Level-JR.h"
38 laCollectable::laCollectable(
void)
49 _nWaveIndex = rand()%M_SEGW;
51 _ptPivot.bSimulateCollision = _ptPivot.bSimulateGravitation = M_FALSE;
54 laCollectable::~laCollectable(
void)
56 if(pItem)
delete pItem;
57 if(_pPotion && _bOwnPotionObject)
delete _pPotion;
60 void laCollectable::respawn()
84 _nHP = getObject()->getInt(
"value-hp");
86 catch(laError_PropertyNotDefined&){ _nHP = 0; }
91 _nXP = getObject()->getInt(
"value-xp");
93 catch(laError_PropertyNotDefined&){ _nXP=0; }
101 pItem =
new rpgWeapon();
104 catch(laError_PropertyNotDefined&){ _bWeapon = M_FALSE; }
112 _bOwnPotionObject = M_TRUE;
114 _pPotion->load( pe );
117 _ttDuration.parameters( _pPotion->dDuration );
118 _ttDuration.enable(M_FALSE);
120 }
catch(laError_PropertyNotDefined&){ _pPotion = NULL; }
122 _fxCollect.position( laPoint3(0, -_ptPivot.size.y()/2) );
129 void laCollectable::create(laPoint3 pos,
rpgPotion* pPot)
132 laObject::create(pos);
138 _ptPivot.y( _ptPivot.y() -
M_UNIT/2.1);
140 _ptPivot.size.x(
M_ABS( getObject()->getModel(0)->boundaryMax().x() - getObject()->getModel(0)->boundaryMin().x())*0.8 );
141 _ptPivot.size.y(
M_ABS( getObject()->getModel(0)->boundaryMax().y() - getObject()->getModel(0)->boundaryMin().y())*0.8 );
143 _color = getObject()->getColor(
"color");
150 _bOwnPotionObject = M_FALSE;
153 _ttDuration.parameters( _pPotion->dDuration );
154 _ttDuration.enable(M_FALSE);
157 _fxCollect.position( laPoint3(0, -_ptPivot.size.y()/2) );
162 void laCollectable::_load_collect_fx()
168 fxParticleSystem_params param;
170 strcat(strFilePath,
"creature_collect.fx");
171 fxp.fileOpen(strFilePath);
172 fxp.readObj(¶m, M_FALSE);
175 _fxCollect.create(param);
176 _fxCollect.enable(M_TRUE);
177 _fxCollect.enableGeneration(M_TRUE);
178 _fxCollect.ctlRewind();
180 _fxCollect.parameters.p_rgb = getObject()->getColor(
"color");
181 if( getObject()->getFxCnt()>=1 )
183 getObject()->getFx(0)->parameters.p_rgb[0]= _fxCollect.parameters.p_rgb.r();
184 getObject()->getFx(0)->parameters.p_rgb[1]= _fxCollect.parameters.p_rgb.g();
185 getObject()->getFx(0)->parameters.p_rgb[2]= _fxCollect.parameters.p_rgb.b();
191 M_BOOL laCollectable::_collect_actions()
193 laPlayer *pPlayer = getLevelObject()->getPlayer();
194 M_BOOL bAnimateResponsiblity = M_FALSE;
200 pPlayer->heal( _nHP );
204 pPlayer->collect( _nXP );
208 pPlayer->collect( pItem );
214 bAnimateResponsiblity = pPlayer->collect( _pPotion );
215 _pPotion->pAnimatorObj =
this;
217 _ttDuration.enable();
223 return bAnimateResponsiblity;
228 void laCollectable::animate(laTimer &t)
234 laObject::animate(t);
235 _fxCollect.animate(t);
239 if(_pPotion ) _potion_mechanic();
247 _ptPivot.angleY += 100*t.delta();
250 ASSERT(getSegmentObject(),
"Nil segment object");
251 _ptPivot.y( _ptPivot.y() + getSegmentObject()->getWave(_nWaveIndex) *
M_UNIT * 0.1 * t.delta() );
259 void laCollectable::_collect_mechanic()
263 laLine2 ln(pPlayer->getPosition(), _ptPivot);
264 _dPlayerDistance = ln.lenght();
266 if( pPlayer->boundingRect().intersecting(boundingRect()) )
268 this->_collect_actions();
274 void laCollectable::_potion_mechanic()
276 laTimer *pt = laSystemIntegrator::getEnvironment()->
getTimer();
279 unsigned n = ps->properties()->potions.findByName( _pPotion->strName );
281 if( n < ps->properties()->potions.size() )
283 laObject *pAnimator = ((
rpgPotion*)(ps->properties()->potions[n]))->pAnimatorObj;
284 if( pAnimator !=
this )
289 _ttDuration.animate(*pt);
293 if( _pPotion->bResetTime ) resetPotion();
294 else _pPotion->dDurationReminder = _ttDuration.reminder() * _pPotion->dDuration;
299 if(!_ttDuration.isEnabled() )
return;
303 if( _ttDuration.isElapsed())
306 unsigned nIndex = ps->properties()->potions.findByName( _pPotion->strName );
308 if( nIndex < ps->properties()->potions.size())
309 ps->properties()->potions.remove( nIndex );
311 _ttDuration.enable(M_FALSE);
313 else if( _pPotion->dDurationReminder < 1 )
315 _disable_potion_icon();
330 void laCollectable::resetPotion()
334 _ttDuration.enable();
352 if( !_reset_potion_icon() )
357 _reset_potion_icon();
372 M_BOOL laCollectable::_reset_potion_icon()
374 ASSERT(_pPotion,
"Nil potion");
377 unsigned n = ps->properties()->potions.findByName( _pPotion->strName );
379 if( n < ps->properties()->potions.size() )
381 uiIcon3D* pIcon = pPlayer->getPotionsGUI()->getIcon(n);
382 pIcon->discardingIcon(M_FALSE);
390 void laCollectable::_disable_potion_icon()
392 ASSERT(_pPotion,
"Nil potion");
395 unsigned n = ps->properties()->potions.findByName( _pPotion->strName );
397 if( n < ps->properties()->potions.size() )
399 uiIcon3D* pIcon =pPlayer->getPotionsGUI()->getIcon(n);
400 if( !pIcon->isDiscarding() ) pIcon->discardingIcon();
404 void laCollectable::drawGeometry(
laRenderer *r, laPoint3 ptBasePos)
411 laObject::drawGeometry(r, ptBasePos);
415 _nested_draw(r, ptBasePos);
421 void laCollectable::_drawFx_positioned(
laRenderer *r) {
423 r->transTranslate( laPoint3(0,0, +
M_UNIT/2.0) );
427 if(!_bTaken) laObject::_drawFx_positioned(r);
laTimer * getTimer()
Get inegrated timer.
#define M_UNIT
Unit of 1 meter.
Base Class for Tileset Elements.
#define M_DIR_FX
Visual effects directory.
#define M_ABS(a)
Return abs(a)
Virtual interface for the Engine graphics renderer.
GUI icon object that can siplay 3D models as icons.
Base Class for Level Objects.