Original Post
I am working on my Battle system. I have it so that battle messages are being sent back and forth between client and server and its all working as expected but now I am trying to set up the different types of attacks. I want the attacks to be scripted using Lua but I have no idea how to set it up. So far they are all hard coded into my battle manager using C++. Here is what I have so far. I have created a Attack type template: AttacksTypesTemplate.h
#include <string>
#include "NetCommon.h"
using namespace std;
struct Attack_Type;
class AttackTypesTemplate
{
public:
Attack_Type attack;
AttackTypesTemplate();
~AttackTypesTemplate();
//Create Attack
void createAttack(string Name); // Creates an Attack with the name giving
//Sets
void setAttackStrength(int strength); // Sets the attack strength for the attack
void setUIImage(string ImageLocation); // Sets the location of the image to use to represent the attack
void setNeededLevel(int Level); // Sets the level at which the Attack becomes available
void setDamageType(int DamageType);
void setDescription(std::string Description);
//Gets
struct Attack_Type GetAttack(); // Gets the attack so it can be used
std::string getDescription();
private:
protected:
};
AttacksTypesTemplate.cpp
#include "AttackTypesTemplate.h"
AttackTypesTemplate::AttackTypesTemplate()
{
}
AttackTypesTemplate::~AttackTypesTemplate()
{
}
void AttackTypesTemplate::createAttack(std::string Name)
{
attack.AttackName = Name;
}
void AttackTypesTemplate::setAttackStrength(int strength)
{
attack.AttackStrength = strength;
}
void AttackTypesTemplate::setNeededLevel(int Level)
{
attack.neededLevel = Level;
}
void AttackTypesTemplate::setUIImage(std::string ImageLocation)
{
attack.imageLocation = ImageLocation;
}
struct Attack_Type AttackTypesTemplate::GetAttack()
{
return attack;
}
void AttackTypesTemplate::setDamageType(int DamageType)
{
attack.damageType = DamageType;
}
void AttackTypesTemplate::setDescription(std::string Description)
{
attack.Description = Description;
}
std::string AttackTypesTemplate::getDescription()
{
return attack.Description;
}
Then the attack is created using:
AttackTypesTemplate* Fireball = new AttackTypesTemplate();
Fireball->createAttack("Fireball");
Fireball->setAttackStrength(10);
Fireball->setDamageType(MAGIC_FIRE);
Fireball->setNeededLevel(1);
Fireball->setDescription("You cast a Magic Fireball \n");
Fireball->setUIImage("../media/UI/Spells/Fireball.jpg");
How can I convert that to use Lua instead of using C++ to hard code each attack and then how would I have it load all the lua scripts from a folder. Also is this an effective way of doing it or should I rethink how I create attacks? Also I am guessing that I would have the server load all the attack types and then send the clients the needed information to display the attack? Should I have a server side script for each attack that has the needed math information about the attack and then have a client script that has the visual information for each attack? Thanks for your suggestions and tips!