int main(int argc, char *argv[]) { TEST_NAME(); auto luaScript = LuaScript(); luaScript.loadString("print('hello world!')"); luaScript.loadScript("test.lua"); luaScript.setGlobal("PI", 3.14); auto PI_value = luaScript.getGlobal_float("PI"); TEST_EQUAL(PI_value, 3.14, "global - float"); luaScript.setGlobal("numChildren", 3); auto numChildren = luaScript.getGlobal_int("numChildren"); TEST_EQUAL(numChildren, 3, "global - int"); luaScript.setGlobal("FirstName", "Benjamin Zaporzan"); auto firstName = luaScript.getGlobal_string("FirstName"); TEST_EQUAL(firstName, "Benjamin Zaporzan", "global - string"); auto floatValues = floatArrayType {1.1, 2.2, 3.3}; luaScript.setGlobal("Position", floatValues); luaScript.loadString("for i,v in ipairs(Position) do print(i,v) end"); auto floatValues2 = luaScript.getGlobal_floatArray("Position"); TEST_EQUAL(floatValues, floatValues2, "global - float array"); for (auto i : floatValues2) { std::cout << i << std::endl; } auto intValues = intArrayType { 1, 2, 3 }; luaScript.setGlobal("oneTwoThree", intValues); luaScript.loadString("for i,v in ipairs(oneTwoThree) do print(i,v) end"); auto intValues2 = luaScript.getGlobal_intArray("oneTwoThree"); TEST_EQUAL(intValues, intValues2, "global - int array"); return 0; }
Champion::Champion(const std::string& type, Map* map, uint32 id, uint32 playerId) : Unit(map, id, type, new Stats()), type(type), skillPoints(0), respawnTimer(0), playerId(playerId) { stats->setGold(475.0f); stats->setAttackSpeedMultiplier(1.0f); stats->setGoldPerSecond(map->getGoldPerSecond()); std::vector<unsigned char> iniFile; if(!RAFManager::getInstance()->readFile("DATA/Characters/"+type+"/"+type+".inibin", iniFile)) { printf("ERR : couldn't find champion stats for %s\n", type.c_str()); return; } Inibin inibin(iniFile); stats->setCurrentHealth(inibin.getFloatValue("Data", "BaseHP")); stats->setMaxHealth(inibin.getFloatValue("Data", "BaseHP")); stats->setCurrentMana(inibin.getFloatValue("Data", "BaseMP")); stats->setMaxMana(inibin.getFloatValue("Data", "BaseMP")); stats->setBaseAd(inibin.getFloatValue("DATA", "BaseDamage")); stats->setRange(inibin.getFloatValue("DATA", "AttackRange")); stats->setBaseMovementSpeed(inibin.getFloatValue("DATA", "MoveSpeed")); stats->setArmor(inibin.getFloatValue("DATA", "Armor")); stats->setMagicArmor(inibin.getFloatValue("DATA", "SpellBlock")); stats->setHp5(inibin.getFloatValue("DATA", "BaseStaticHPRegen")); stats->setMp5(inibin.getFloatValue("DATA", "BaseStaticMPRegen")); stats->setHealthPerLevel(inibin.getFloatValue("DATA", "HPPerLevel")); stats->setManaPerLevel(inibin.getFloatValue("DATA", "MPPerLevel")); stats->setAdPerLevel(inibin.getFloatValue("DATA", "DamagePerLevel")); stats->setArmorPerLevel(inibin.getFloatValue("DATA", "ArmorPerLevel")); stats->setMagicArmorPerLevel(inibin.getFloatValue("DATA", "SpellBlockPerLevel")); stats->setHp5RegenPerLevel(inibin.getFloatValue("DATA", "HPRegenPerLevel")); stats->setMp5RegenPerLevel(inibin.getFloatValue("DATA", "MPRegenPerLevel")); stats->setBaseAttackSpeed(0.625f/(1+inibin.getFloatValue("DATA", "AttackDelayOffsetPercent"))); spells.push_back(new Spell(this, inibin.getStringValue("Data", "Spell1"), 0)); spells.push_back(new Spell(this, inibin.getStringValue("Data", "Spell2"), 1)); spells.push_back(new Spell(this, inibin.getStringValue("Data", "Spell3"), 2)); spells.push_back(new Spell(this, inibin.getStringValue("Data", "Spell4"), 3)); setMelee(inibin.getBoolValue("DATA", "IsMelee")); iniFile.clear(); if(!RAFManager::getInstance()->readFile("DATA/Characters/"+type+"/Spells/"+type+"BasicAttack.inibin", iniFile)) { if(!RAFManager::getInstance()->readFile("DATA/Spells/"+type+"BasicAttack.inibin", iniFile)) { printf("ERR : couldn't find champion auto-attack data for %s\n", type.c_str()); return; } } Inibin autoAttack(iniFile); autoAttackDelay = autoAttack.getFloatValue("SpellData", "castFrame")/30.f; autoAttackProjectileSpeed = autoAttack.getFloatValue("SpellData", "MissileSpeed"); std::string scriptloc = "../../lua/champions/" + this->getType() + "/Passive.lua"; printf("Loading %s\n", scriptloc.c_str()); try{ unitScript = LuaScript(true);//fix unitScript.lua.set("me", this); unitScript.loadScript(scriptloc); unitScript.lua.set_function("dealMagicDamage", [this](Unit* target, float amount) { this->dealDamageTo(target,amount,DAMAGE_TYPE_MAGICAL,DAMAGE_SOURCE_SPELL); }); unitScript.lua.set_function("addBuff", [this](Unit* target, Buff b){ target->addBuff(new Buff(b)); return; }); unitScript.lua.set_function("addParticleTarget", [this](const std::string& particle, Target* u) { this->getMap()->getGame()->notifyParticleSpawn(this, u, particle); return; }); // unitScript.lua.set ("me", this); }catch(sol::error e){//lua error? don't crash the whole server printf("Champion passive load error: \n%s\n", e.what()); } }
void LuaRunBuffer::initLua(lua_State *L) { _script = LuaScript(L, false); }