Esempio n. 1
0
	/**
	 * Sets the stat modifier type.
	 * <br>This is the list of each modifier type:
	 * <ul>
	 * <li>= : Sets the stat to the given value. This mod is applied first.</li>
	 * <li>* : Multiplies the stat by the given value. This mod is applied second.</li>
	 * <li>+ : Adds the given value directly onto the stat, this value can be negative. This mod is applied third.</li>
	 * </ul>
	 *
	 * @param string type The new type for this modifier.
	 * @returns am.stat_modifier This
	 */
	int StatModifier_type(lua_State *lua)
	{
		StatModifier *mod = castUData<StatModifier>(lua, 1);
		if (mod)
		{
			if (lua_gettop(lua) == 1)
			{
				lua_pushstring(lua, StatModifier::getModifierTypeString(mod->getType()));
				return 1;
			}
			else if (lua_isstr(lua, 2))
			{
				StatModifierType type = getStatModifier(lua, 2);
				if (type != MOD_MAX_LENGTH)
				{
					mod->setType(type);
				}
				else
				{
					std::stringstream ss;
					ss << "Invalid stat modifier type (";
					LuaState::printTypeValue(lua, 2, ss);
					ss << ')';
					LuaState::warning(lua, ss.str().c_str());
				}
				lua_first(lua);
			}
			return LuaState::expectedArgs(lua, "type", "string type");
		}
		return LuaState::expectedContext(lua, "type", "am.stat_modifier");
	}
Esempio n. 2
0
	void StatModifiers::deserialise(LoadingState *state, data::IData *data)
	{
		Handle<data::Table> dataMap(data::Table::checkDataType(data, "stat modifiers"));
		if (!dataMap)
		{
			return;
		}
		
		for (auto iter = dataMap->beginMap(); iter != dataMap->endMap(); ++iter)
		{
			Stat::StatType type = Stat::getStatType(iter->first.c_str());
			if (type == Stat::MAX_STAT_LENGTH)
			{
				stringstream ss;
				ss << "Unknown stat type '" << iter->first << "', unable to load stat modifiers.";
				am_log("LOADERR", ss);
				continue;
			}

			Handle<data::Table> arr(data::Table::checkDataType(iter->second.get(), "stat modifiers"));
			if (arr)
			{
				continue;
			}

			for (auto modIter = arr->beginArray(); modIter != arr->endArray(); ++iter)
			{
				StatModifier mod;
				if (mod.deserialise(state, modIter->get()))
				{
					addStatModifier(type, mod);
				}
			}
		}
	}
Esempio n. 3
0
void Champion::addStatModifier(StatModifier &statModifier)
{
    ModifierType modType = statModifier.getType();
    if (modType == ModifierType::FLAT) {
        _flatModifiers[statModifier.getStatID()].push_back(&statModifier);
    } else if (modType == ModifierType::ADDATIVE) {
        _addativeModifiers[statModifier.getStatID()].push_back(&statModifier);
    } else if (modType == ModifierType::MULTIPLICATIVE) {
        
    } else {
        std::cout << "Unrecognised StatModifer type";
    }
}
Esempio n. 4
0
	/**
	 * Sets if modifier is magical in nature.
	 *
	 * @param boolean magical The new magical flag for this modifier.
	 * @returns am.stat_modifier This
	 */
	int StatModifier_magical(lua_State *lua)
	{
		StatModifier *mod = castUData<StatModifier>(lua, 1);
		if (mod)
		{
			if (lua_gettop(lua) == 1)
			{
				lua_pushboolean(lua, mod->isMagical());
				return 1;
			}
			else if (lua_isbool(lua, 2))
			{
				mod->setMagical(lua_tobool(lua, 2));
				lua_first(lua);
			}
			return LuaState::expectedArgs(lua, "magical", "boolean magical");
		}
		return LuaState::expectedContext(lua, "magical", "am.stat_modifier");
	}
Esempio n. 5
0
	/**
	 * Sets the stat modifier value.
	 *
	 * @param number value The new value for this modifier.
	 * @returns am.stat_modifier This
	 */
	int StatModifier_value(lua_State *lua)
	{
		StatModifier *mod = castUData<StatModifier>(lua, 1);
		if (mod)
		{
			if (lua_gettop(lua) == 1)
			{
				lua_pushnumber(lua, mod->getValue());
				return 1;
			}
			else if (lua_isnum(lua, 2))
			{
				mod->setValue(lua_tofloat(lua, 2));
				lua_first(lua);
			}
			return LuaState::expectedArgs(lua, "value", "number value");
		}
		return LuaState::expectedContext(lua, "value", "am.stat_modifier");
	}
Esempio n. 6
0
void Champion::updateModifiers(std::map<std::string, std::vector<StatModifier *> > &modiferMap)
{
    std::map<std::string, std::vector<StatModifier*>>::iterator mapIter;
    std::vector<StatModifier*>::iterator modIter;
    
    for (mapIter = modiferMap.begin(); mapIter != modiferMap.end(); ++mapIter) {
        std::vector<StatModifier*> *currentMods = &mapIter->second;
        for (modIter = currentMods->begin(); modIter != currentMods->end();) {
            StatModifier *modifier = (*modIter);
            modifier->update();
            if (modifier->hasExpired()) {
                currentMods->erase(modIter);
                std::cout << "modified removed \n";
                delete modifier;
            } else {
                ++modIter;
            }
        }
    }
}