1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2024-12-27 07:06:00 +00:00

Some new Lua functions for shots. Shots will now respect the prov. unused BouncePrt property.

- shot_setDamageType()
- shot_setCheckDamageTarget()
- shot_isCheckDamageTarget()
- shot_setTrailPrt()
This commit is contained in:
fgenesis 2013-07-21 17:09:47 +02:00
parent c6ae568ed8
commit 49b6234ac8
5 changed files with 64 additions and 126 deletions

View file

@ -2754,7 +2754,7 @@ void Avatar::formAbility(int ability)
if (s->shotData->homing > 0) if (s->shotData->homing > 0)
{ {
Vector p = dsq->getGameCursorPosition(); Vector p = dsq->getGameCursorPosition();
target = dsq->game->getNearestEntity(p, 800, this, ET_ENEMY, s->shotData->damageType); target = dsq->game->getNearestEntity(p, 800, this, ET_ENEMY, s->getDamageType());
} }
if (target) if (target)
{ {

View file

@ -8363,7 +8363,7 @@ bool Game::isEntityCollideWithShot(Entity *e, Shot *shot)
{ {
return false; return false;
} }
if (shot->shotData && shot->shotData->checkDamageTarget) if (shot->checkDamageTarget)
{ {
if (!e->isDamageTarget(shot->getDamageType())) if (!e->isDamageTarget(shot->getDamageType()))
return false; return false;

View file

@ -2147,6 +2147,36 @@ luaFunc(shot_setLifeTime)
luaReturnNil(); luaReturnNil();
} }
luaFunc(shot_setDamageType)
{
Shot *shot = getShot(L);
if (shot)
shot->damageType = (DamageType)lua_tointeger(L, 2);
luaReturnNil();
}
luaFunc(shot_setCheckDamageTarget)
{
Shot *shot = getShot(L);
if (shot)
shot->checkDamageTarget = getBool(L, 2);
luaReturnNil();
}
luaFunc(shot_isCheckDamageTarget)
{
Shot *shot = getShot(L);
luaReturnBool(shot ? shot->checkDamageTarget : false);
}
luaFunc(shot_setTrailPrt)
{
Shot *shot = getShot(L);
if (shot)
shot->setParticleEffect(getString(L, 2));
luaReturnNil();
}
luaFunc(entity_setVel) luaFunc(entity_setVel)
{ {
Entity *e = entity(L); Entity *e = entity(L);
@ -8911,6 +8941,10 @@ static const struct {
luaRegister(shot_setHomingness), luaRegister(shot_setHomingness),
luaRegister(shot_getLifeTime), luaRegister(shot_getLifeTime),
luaRegister(shot_setLifeTime), luaRegister(shot_setLifeTime),
luaRegister(shot_setDamageType),
luaRegister(shot_setCheckDamageTarget),
luaRegister(shot_isCheckDamageTarget),
luaRegister(shot_setTrailPrt),
luaRegister(entity_pathBurst), luaRegister(entity_pathBurst),
luaRegister(entity_handleShotCollisions), luaRegister(entity_handleShotCollisions),
luaRegister(entity_handleShotCollisionsSkeletal), luaRegister(entity_handleShotCollisionsSkeletal),

View file

@ -120,8 +120,6 @@ void ShotData::bankLoad(const std::string &file, const std::string &path)
inf >> fireSfx; inf >> fireSfx;
else if (token == "HitPrt") else if (token == "HitPrt")
inf >> hitPrt; inf >> hitPrt;
else if (token == "TrailPrt")
inf >> trailPrt;
else if (token == "BouncePrt") else if (token == "BouncePrt")
inf >> bouncePrt; inf >> bouncePrt;
else if (token == "FirePrt") else if (token == "FirePrt")
@ -271,64 +269,8 @@ void Shot::fire(bool playSfx)
fired = true; fired = true;
} }
} }
} }
//const int MAX_ENEMY_SHOT = 400;
/*
Shot::Shot(DamageType damageType, Entity *firer, Vector pos, Entity *target, std::string tex, float homingness, int maxSpeed, int numSegments, float segMin, float segMax, float d, float lifeTime)
: Quad(), Segmented(0,segMax)
{
shotData = 0;
targetPt = -1;
bounceType = BOUNCE_NONE;
if (lifeTime == 0)
lifeTime = 8;
this->damageType = damageType;
this->firer = firer;
position = pos;
this->damage = d;
this->target = target;
this->maxSpeed = maxSpeed;
this->homingness = homingness;
if (tex.empty())
tex = "energyBlast";
setTexture(tex);
setBlendType(BLEND_ADD);
scale = Vector(0.5, 0.5);
dead = false;
this->lifeTime = lifeTime;
segments.resize(numSegments);
for (int i = segments.size()-1; i >=0 ; i--)
{
Quad *flame = new Quad;
flame->setTexture(tex);
flame->width = 32;
flame->height = 32;
flame->blendType = RenderObject::BLEND_ADD;
flame->alpha = 0.5;
dsq->game->addRenderObject(flame, LR_PARTICLES);
segments[i] = flame;
}
initSegments(position);
shots.push_back(this);
//hitParticleEffect = "EnergyBlastHit";
//hitSound = "BasicShotHit";
//if (dsq->game->isObstructed(TileVector(startPos)))
//{
// // DON'T DO THIS YOU WILL RUIN THE GAME
// safeKill();
//}
}
*/
Shot::Shot() : Quad(), Segmented(0,0) Shot::Shot() : Quad(), Segmented(0,0)
{ {
@ -342,6 +284,8 @@ Shot::Shot() : Quad(), Segmented(0,0)
fired = false; fired = false;
target = 0; target = 0;
dead = false; dead = false;
damageType = DT_NONE;
checkDamageTarget = false;
enqueuedForDelete = false; enqueuedForDelete = false;
shotIdx = shots.size(); shotIdx = shots.size();
shots.push_back(this); shots.push_back(this);
@ -417,17 +361,11 @@ void Shot::applyShotData(ShotData *shotData)
this->collideRadius = shotData->collideRadius; this->collideRadius = shotData->collideRadius;
this->renderQuad = !shotData->invisible; this->renderQuad = !shotData->invisible;
this->gravity = shotData->gravity; this->gravity = shotData->gravity;
if (!shotData->trailPrt.empty() && !emitter) this->damageType = shotData->damageType;
this->checkDamageTarget = shotData->checkDamageTarget;
if (!shotData->trailPrt.empty())
{ {
emitter = new ParticleEffect; setParticleEffect(shotData->trailPrt);
emitter->load(shotData->trailPrt);
emitter->start();
dsq->game->addRenderObject(emitter, LR_PARTICLES);
/*
addChild(&emitter);
emitter.load(shotData->trailPrt);
emitter.start();
*/
} }
if (shotData->numSegs > 0) if (shotData->numSegs > 0)
@ -465,24 +403,21 @@ void Shot::suicide()
void Shot::setParticleEffect(const std::string &particleEffect) void Shot::setParticleEffect(const std::string &particleEffect)
{ {
/* if(dead)
if (!particleEffect.empty()) return;
if(particleEffect.empty())
{ {
addChild(&emitter); if(emitter)
emitter.load(particleEffect); emitter->stop();
emitter.start(); return;
} }
*/ if(!emitter)
} {
emitter = new ParticleEffect;
void Shot::setBounceType(BounceType bt) dsq->game->addRenderObject(emitter, LR_PARTICLES);
{ }
//bounceType = bt; emitter->load(particleEffect);
} emitter->start();
void Shot::setLifeTime(float l)
{
//lifeTime = l;
} }
void Shot::onEndOfLife() void Shot::onEndOfLife()
@ -629,7 +564,7 @@ void Shot::hitEntity(Entity *e, Bone *b, bool isValid)
if (e) if (e)
{ {
if (shotData && shotData->damageType == DT_AVATAR_BITE) if (damageType == DT_AVATAR_BITE)
{ {
//debugLog("Shot::hitEntity bittenEntities.push_back"); //debugLog("Shot::hitEntity bittenEntities.push_back");
dsq->game->avatar->bittenEntities.push_back(e); dsq->game->avatar->bittenEntities.push_back(e);
@ -652,7 +587,7 @@ void Shot::hitEntity(Entity *e, Bone *b, bool isValid)
// doesn't have anything to do with effectTime // doesn't have anything to do with effectTime
if (shotData) if (shotData)
{ {
if (!damaged && shotData->checkDamageTarget && !shotData->alwaysDoHitEffects) if (!damaged && checkDamageTarget && !shotData->alwaysDoHitEffects)
{ {
doEffects = false; doEffects = false;
} }
@ -727,11 +662,7 @@ float Shot::getDamage() const
DamageType Shot::getDamageType() const DamageType Shot::getDamageType() const
{ {
if (shotData) return damageType;
{
return shotData->damageType;
}
return (DamageType)0;
} }
void Shot::setAimVector(const Vector &aim) void Shot::setAimVector(const Vector &aim)
@ -849,9 +780,9 @@ void Shot::onUpdate(float dt)
emitter = 0; emitter = 0;
} }
if (target && shotData && lifeTime > 0 && shotData->damageType != DT_NONE) if (target && lifeTime > 0 && damageType != DT_NONE)
{ {
if (!target->isDamageTarget(shotData->damageType)) if (!target->isDamageTarget(damageType))
{ {
target = 0; target = 0;
} }
@ -899,6 +830,8 @@ void Shot::onUpdate(float dt)
if (!shotData->bounceSfx.empty()) if (!shotData->bounceSfx.empty())
{ {
dsq->playPositionalSfx(shotData->bounceSfx, position); dsq->playPositionalSfx(shotData->bounceSfx, position);
if(!shotData->bouncePrt.empty())
dsq->spawnParticleEffect(shotData->bouncePrt, position);
} }
float len = velocity.getLength2D(); float len = velocity.getLength2D();
Vector I = velocity/len; Vector I = velocity/len;
@ -923,35 +856,6 @@ void Shot::onUpdate(float dt)
} }
} }
/*
CollideData c = dsq->game->collideCircleWithAllEntities(this->position, 8, firer, spellType);
if (c.collision || lifeTime < 0)
{
lifeTime = 0;
fadeAlphaWithLife = true;
setLife(1);
velocity = 0;
setDecayRate(10);
destroySegments(0.1);
dead = true;
if (c.entity)
{
DamageData d;
d.attacker = firer;
d.bone = c.bone;
d.damage = damage;
d.spellType = spellType;
c.entity->damage(d);
}
target = 0;
}
*/
if (!velocity.isZero() && target) if (!velocity.isZero() && target)
{ {
Vector add = diff; Vector add = diff;

View file

@ -94,8 +94,6 @@ public:
void fire(bool playSfx = true); void fire(bool playSfx = true);
void hitEntity(Entity *e, Bone *b, bool isValid=true); void hitEntity(Entity *e, Bone *b, bool isValid=true);
void setLifeTime(float l);
void setBounceType(BounceType bt);
void noSegs(); void noSegs();
@ -128,6 +126,8 @@ public:
float extraDamage; float extraDamage;
float homingness; float homingness;
float lifeTime; float lifeTime;
DamageType damageType;
bool checkDamageTarget;
protected: protected: