Batch #18334 by eAthena: 0 byte-identical, 2 confirmed by peer review. - fn_06826 CAcidifiedThrow::OnProcess: logic confirmed by peer review - fn_19109 CLightSphereEffect::OnProcess: logic confirmed by peer review Peer-reviewed-by: ragnarok-clanker, cremane, bibinir Accepted without human review: peers confirmed the logic ("same" ahead by at least 3, with 70% of the votes).
319 lines
9.5 KiB
C++
319 lines
9.5 KiB
C++
#include "Contents/Effects/Skills/LightSphereEffect.h"
|
|
#include "Contents/Effects/Core/EffectTypes.h"
|
|
|
|
#include "Client/Mode/CGameMode.h"
|
|
#include "Client/Mode/ModeMgr.h"
|
|
#include "Contents/Camera/Camera.h"
|
|
#include "Contents/Effects/Core/EffectMemoryMgr.h"
|
|
#include "Contents/Effects/Core/EffectPoint.h"
|
|
#include "Contents/Effects/Particles/Particle.h"
|
|
#include "Utility/Math/AffineMatrix.h"
|
|
#include "Utility/Math/Vector3d.h"
|
|
|
|
#include <algorithm>
|
|
#include <cstdlib>
|
|
#include <cstring>
|
|
|
|
// OFFSET: 0x00B6C9F0
|
|
// FUNCTION: fn_19103
|
|
CLightSphereEffect::CLightSphereEffect() : CEffect(-1), spheres(), rays() {
|
|
}
|
|
|
|
// OFFSET: 0x00B6CB90
|
|
// FUNCTION: fn_19105
|
|
void CLightSphereEffect::CreateRayParticles(int param) {
|
|
for (int c = 0; c < 4; ++c) {
|
|
for (int i = 0; i < 80; ++i) {
|
|
CParticle* particle = CreateParticle(reinterpret_cast<const vector3d*>(&this->position), 5);
|
|
if (particle != nullptr) {
|
|
particle->SetTexture("effect\\white02.bmp");
|
|
particle->effectId = this->id;
|
|
particle->columnIndex = i;
|
|
particle->rowIndex = c;
|
|
particle->groupIndex = 1;
|
|
particle->alpha = 40;
|
|
particle->scale = 1.0f;
|
|
|
|
int r1 = std::rand() % 360;
|
|
particle->phaseParameter = r1 < 0 ? 0 : r1;
|
|
|
|
int r2 = std::rand() % 360;
|
|
*reinterpret_cast<float*>(&particle->angleBits) = static_cast<float>(r2 < 0 ? 0 : r2);
|
|
|
|
int r3 = std::rand() % 360;
|
|
particle->angleParameter = r3 < 0 ? 0 : r3;
|
|
|
|
particle->animationParameter = 10.0f;
|
|
*reinterpret_cast<float*>(particle->animationParameters) = static_cast<float>(param);
|
|
|
|
switch (this->id) {
|
|
case EF_LIGHTSPHERE_SUN: {
|
|
int randVal = std::rand() % 2;
|
|
if (randVal < 0) {
|
|
randVal = 0;
|
|
}
|
|
if (randVal == 0) {
|
|
particle->SetColor(0xFF, 0x7C, 0x80);
|
|
} else {
|
|
particle->SetColor(0xFF, 0x4A, 0x4E);
|
|
}
|
|
break;
|
|
}
|
|
case EF_LIGHTSPHERE_MOON: {
|
|
int randVal = std::rand() % 2;
|
|
if (randVal < 0) {
|
|
randVal = 0;
|
|
}
|
|
if (randVal == 0) {
|
|
particle->SetColor(0xFF, 0xFF, 0x9B);
|
|
} else {
|
|
particle->SetColor(0xFF, 0xFF, 0x37);
|
|
}
|
|
break;
|
|
}
|
|
case EF_LIGHTSPHERE_STAR: {
|
|
int randVal = std::rand() % 2;
|
|
if (randVal < 0) {
|
|
randVal = 0;
|
|
}
|
|
if (randVal == 0) {
|
|
particle->SetColor(0x3B, 0xCC, 0xFF);
|
|
} else {
|
|
particle->SetColor(0x6D, 0x9A, 0xFF);
|
|
}
|
|
break;
|
|
}
|
|
default: {
|
|
int randVal = std::rand() % 2;
|
|
if (randVal < 0) {
|
|
randVal = 0;
|
|
}
|
|
if (randVal == 0) {
|
|
particle->SetColor(0x69, 0x69, 0xFF);
|
|
} else {
|
|
particle->SetColor(0x37, 0x37, 0xFF);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
particle->InitParticleQuad(particle->vertices);
|
|
this->rays.push_back(particle);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// OFFSET: 0x00B6CFF0
|
|
// FUNCTION: fn_19106
|
|
void CLightSphereEffect::Close() {
|
|
for (std::vector<CParticle*>::iterator it = this->spheres.begin(); it != this->spheres.end(); ++it) {
|
|
FreeParticle(*it);
|
|
}
|
|
this->spheres.clear();
|
|
|
|
for (std::vector<CParticle*>::iterator it = this->rays.begin(); it != this->rays.end(); ++it) {
|
|
FreeParticle(*it);
|
|
}
|
|
this->rays.clear();
|
|
}
|
|
|
|
// OFFSET: 0x00B6D060
|
|
// FUNCTION: fn_19107
|
|
void CLightSphereEffect::Open() {
|
|
for (int i = 0; i < 4; ++i) {
|
|
CParticle* particle = CreateParticle(reinterpret_cast<const vector3d*>(&this->position), 5);
|
|
if (particle != nullptr) {
|
|
particle->SetTexture("effect\\thunder_center.bmp");
|
|
particle->effectId = this->id;
|
|
particle->columnIndex = i;
|
|
particle->rowIndex = 0;
|
|
particle->groupIndex = 1;
|
|
particle->scale = 3.5f;
|
|
particle->alpha = 1;
|
|
particle->animationParameter = -10.0f;
|
|
*reinterpret_cast<float*>(particle->animationParameters) = 0.0f;
|
|
|
|
switch (this->id) {
|
|
case EF_LIGHTSPHERE_SUN:
|
|
particle->SetColor(0xFF, 0x7C, 0x80);
|
|
break;
|
|
case EF_LIGHTSPHERE_MOON:
|
|
particle->SetColor(0xFF, 0xFF, 0x37);
|
|
break;
|
|
case EF_LIGHTSPHERE_STAR:
|
|
particle->SetColor(0x3B, 0xCC, 0xFF);
|
|
break;
|
|
}
|
|
|
|
particle->InitParticleQuad(particle->vertices);
|
|
this->spheres.push_back(particle);
|
|
}
|
|
}
|
|
|
|
this->CreateRayParticles(0);
|
|
this->CreateRayParticles(1);
|
|
}
|
|
|
|
// OFFSET: 0x00B6D160
|
|
// FUNCTION: fn_19108
|
|
bool CLightSphereEffect::IsAlive() {
|
|
std::vector<CParticle*>::iterator sphere = this->spheres.begin();
|
|
for (; sphere != this->spheres.end(); ++sphere) {
|
|
if ((*sphere)->alpha > 0) {
|
|
break;
|
|
}
|
|
}
|
|
|
|
std::vector<CParticle*>::iterator ray = this->rays.begin();
|
|
for (; ray != this->rays.end(); ++ray) {
|
|
if ((*ray)->alpha > 0) {
|
|
break;
|
|
}
|
|
}
|
|
|
|
return sphere != this->spheres.end() || ray != this->rays.end();
|
|
}
|
|
|
|
// OFFSET: 0x00B6D1C0
|
|
// FUNCTION: fn_19109
|
|
void CLightSphereEffect::OnProcess() {
|
|
for (std::vector<CParticle*>::iterator it = this->spheres.begin(); it != this->spheres.end(); ++it) {
|
|
CParticle* particle = *it;
|
|
|
|
vector3d& position = particle->position;
|
|
position.x = this->position[0];
|
|
position.y = this->position[1];
|
|
position.z = this->position[2];
|
|
|
|
if (particle != nullptr) {
|
|
if (particle->elapsedFrames < 300) {
|
|
const int alpha = particle->alpha + 1;
|
|
particle->alpha = alpha >= 255 ? 255 : alpha;
|
|
} else {
|
|
const int alpha = particle->alpha - 1;
|
|
particle->alpha = alpha < 0 ? 0 : alpha;
|
|
}
|
|
|
|
float& phase = *reinterpret_cast<float*>(particle->animationParameters);
|
|
const int spin = (static_cast<int>(phase) + 2) % 360;
|
|
phase = static_cast<float>(spin);
|
|
const float scale = particle->scale * g_sinTable[spin] * 0.05f + particle->scale;
|
|
|
|
matrix rotation;
|
|
std::memcpy(rotation.values, g_identityMatrix, sizeof(rotation.values));
|
|
rotation.MakeXRotation(static_cast<CGameMode*>(g_modeMgr.GetGameMode())->camera->camera.pitch / 180.0f * 3.141592f);
|
|
|
|
matrix scaling;
|
|
std::memcpy(scaling.values, g_identityMatrix, sizeof(scaling.values));
|
|
scaling.SetScale(scale, scale, 1.0f);
|
|
|
|
matrix billboard;
|
|
billboard.Compose(scaling, rotation);
|
|
|
|
matrix translation;
|
|
std::memcpy(translation.values, g_identityMatrix, sizeof(translation.values));
|
|
translation.MakeTranslate(0.0f, particle->animationParameter, 0.0f);
|
|
|
|
matrix transform;
|
|
transform.Compose(billboard, translation);
|
|
particle->transform = transform;
|
|
}
|
|
|
|
++particle->elapsedFrames;
|
|
}
|
|
|
|
for (std::vector<CParticle*>::iterator it = this->rays.begin(); it != this->rays.end(); ++it) {
|
|
CParticle* particle = *it;
|
|
|
|
vector3d& position = (*it)->position;
|
|
position.x = this->position[0];
|
|
position.y = this->position[1];
|
|
position.z = this->position[2];
|
|
|
|
if (particle != nullptr) {
|
|
float scale = particle->scale;
|
|
if (scale < 10.0f) {
|
|
scale *= 1.02f;
|
|
}
|
|
particle->scale = scale;
|
|
|
|
int alpha = particle->alpha;
|
|
if (particle->elapsedFrames > 500) {
|
|
const int faded = alpha - 1;
|
|
alpha = faded >= 0 ? faded : 0;
|
|
}
|
|
particle->alpha = alpha;
|
|
|
|
const int previous = particle->angleParameter;
|
|
const int phase = (previous + 1 + std::ranges::max(std::rand() % 2, 0)) % 360;
|
|
particle->angleParameter = phase;
|
|
|
|
EffectPoint points[3];
|
|
const float radius = particle->scale * g_sinTable[phase] + particle->scale;
|
|
const int pitch = particle->phaseParameter;
|
|
const int yaw = static_cast<int>(*reinterpret_cast<float*>(&particle->angleBits));
|
|
const float flat = radius * g_cosTable[pitch];
|
|
float corner0X = flat * g_cosTable[yaw];
|
|
float corner0Y = radius * g_sinTable[pitch] - particle->animationParameter;
|
|
float corner0Z = flat * g_sinTable[yaw];
|
|
|
|
float corner1X;
|
|
float corner1Y;
|
|
float corner1Z;
|
|
float corner2X;
|
|
float corner2Y;
|
|
float corner2Z;
|
|
if (0.0f == *reinterpret_cast<float*>(particle->animationParameters)) {
|
|
corner1X = -0.5f;
|
|
corner1Y = -particle->animationParameter;
|
|
corner1Z = 0.0f;
|
|
corner2X = 0.5f;
|
|
corner2Y = -particle->animationParameter;
|
|
corner2Z = 0.0f;
|
|
} else {
|
|
corner1X = 0.0f;
|
|
corner1Y = -particle->animationParameter;
|
|
corner1Z = -0.5f;
|
|
corner2X = 0.0f;
|
|
corner2Y = -particle->animationParameter;
|
|
corner2Z = 0.5f;
|
|
}
|
|
|
|
particle->vertices[0].x = corner0X;
|
|
particle->vertices[0].y = corner0Y;
|
|
particle->vertices[0].z = corner0Z;
|
|
particle->vertices[1].x = corner0X;
|
|
particle->vertices[1].y = corner0Y;
|
|
particle->vertices[1].z = corner0Z;
|
|
particle->vertices[2].x = corner1X;
|
|
particle->vertices[2].y = corner1Y;
|
|
particle->vertices[2].z = corner1Z;
|
|
particle->vertices[3].x = corner2X;
|
|
particle->vertices[3].y = corner2Y;
|
|
particle->vertices[3].z = corner2Z;
|
|
}
|
|
|
|
++particle->elapsedFrames;
|
|
}
|
|
}
|
|
|
|
// OFFSET: 0x00B6D990
|
|
// FUNCTION: fn_19110
|
|
void CLightSphereEffect::Render() {
|
|
for (std::vector<CParticle*>::iterator it = this->spheres.begin(); it != this->spheres.end(); ++it) {
|
|
CParticle* particle = *it;
|
|
|
|
if (particle) {
|
|
particle->Render(false, 0.0f, 1.0f, 0.0f, 1.0f, false, true);
|
|
}
|
|
}
|
|
|
|
for (std::vector<CParticle*>::iterator it = this->rays.begin(); it != this->rays.end(); ++it) {
|
|
CParticle* particle = *it;
|
|
|
|
if (particle) {
|
|
particle->Render(false, 0.0f, 1.0f, 0.0f, 1.0f, false, true);
|
|
}
|
|
}
|
|
}
|