Esempio n. 1
0
float BattleSquad::getSkillApCost(std::string skillid)
{
	DataLibrary* datalib = DataLibrary::getSingletonPtr();
	std::vector<std::string> skilllist;
	skilllist = datalib->getChildList("StaticData/SkillData");
	std::vector<std::string>::iterator ite;
	ite = std::find(skilllist.begin(), skilllist.end(), skillid);
	if(ite == skilllist.end())
		return 0.0f;
	int skillaptype;
	float skillapcost;
	datalib->getData(str(boost::format("StaticData/SkillData/%1%/APType")%skillid),skillaptype);
	datalib->getData(str(boost::format("StaticData/SkillData/%1%/APCost")%skillid),skillapcost);
	switch(skillaptype)
	{
	case SKILLAPTYPE_SETUP:
	case SKILLAPTYPE_BATTLE:
		return getAPTypeCostModify(skillaptype) + skillapcost;
	case SKILLAPTYPE_DEFENCE:
		{
			float ap = getActionPoint();
			return (ap > skillapcost)?ap:skillapcost;
		}
	}
	return 0.0f;
}
Esempio n. 2
0
void BattleSquad::turnStart()
{
	if (this->getUnitNum()==0)
	{
		return;
	}

	DataLibrary* datalib = DataLibrary::getSingletonPtr();
	float ap = getAttr(ATTR_ACTIONPOINT,ATTRCALC_FULL);
	setActionPoint(ap);
	setAPSetup(0.0f);
	setAPBattle(0.0f);

	std::vector<std::string> activeskills;
	activeskills = datalib->getChildList(mPath + "/Skill");
	std::vector<std::string>::iterator ite;
	for(ite = activeskills.begin(); ite != activeskills.end(); ite++)
	{
		int cooldown = 0;
		datalib->getData(mPath + "/Skill/" + (*ite) + "/CoolDown", cooldown);
		if(cooldown > 0)
			cooldown -= 1;
		datalib->setData(mPath + "/Skill/" + (*ite) + "/CoolDown", cooldown);
	}	

	LuaTempContext* luatempcontext = new LuaTempContext();
	luatempcontext->strMap["squadid"] = getSquadId();
	Trigger("TurnStart", luatempcontext);
	delete luatempcontext;
}
void MapDataManager::Trigger(std::string triggertype, LuaTempContext * tempcontext)
{
    if(tempcontext == NULL)
        return;
    DataLibrary* datalib = DataLibrary::getSingletonPtr();
    std::vector<std::string> triggerlist;
    triggerlist = datalib->getChildList("GameData/BattleData/Trigger");
    std::vector<std::string>::iterator ite;
    for(ite = triggerlist.begin(); ite != triggerlist.end(); ite++)
    {
        std::string datapath = std::string("GameData/BattleData/Trigger/") + (*ite);
        int active;
        datalib->getData(datapath,active);
        if(!active)
            continue;
        std::string type;
        datalib->getData(datapath + std::string("/type"),type);
        if(type != triggertype)
            continue;
        std::string context,filename,funcname;
        datalib->getData(datapath + std::string("/file"),filename);
        datalib->getData(datapath + std::string("/func"),funcname);
        datalib->getData(datapath + std::string("/context"),context);
        LuaSystem::getSingleton().executeFunction(filename,funcname,context,tempcontext);
    }
}
void GUIDebugWindow::onRefreshList(MyGUI::Widget* _sender)
{
	DataLibrary* datalib = DataLibrary::getSingletonPtr();
	mSquadList->removeAllItems();
	std::string path = "GameData/StoryData/SquadData";
	std::vector<std::string> squadlist = datalib->getChildList(path);
	for (std::vector<std::string>::iterator it=squadlist.begin();it!=squadlist.end();it++)
	{
		mSquadList->addItem((*it));
	}
}
Esempio n. 5
0
void MapLoader::loadMapObj()
{
	DataLibrary* datalibrary = DataLibrary::getSingletonPtr();
	Terrain* terrain = Terrain::getSingletonPtr();
	std::string datapath("GameData/BattleData/MapData/MapObjModleInfo");
	std::vector<std::string> childlist;
	childlist = datalibrary->getChildList(datapath);
	if(childlist.size()>0)
	{
		for(unsigned int n = 0; n < childlist.size(); n++)
		{
			std::string meshname;
			int x,y,dir;
			datalibrary->getData(datapath + std::string("/") + childlist[n] + std::string("/Mesh"),meshname);
			datalibrary->getData(datapath + std::string("/") +childlist[n] + std::string("/GridX"),x);
			datalibrary->getData(datapath + std::string("/") +childlist[n] + std::string("/GridY"),y);
			datalibrary->getData(datapath + std::string("/") +childlist[n] + std::string("/Direction"),dir);
			int index;
			index = terrain->createMapObj(x,y,meshname, dir);
			datalibrary->setData(datapath + std::string("/") + childlist[n] + std::string("/Index"),index);
		}
	}
	datapath = "GameData/BattleData/MapData/MapParticleInfo";
	childlist = datalibrary->getChildList(datapath);
	if(childlist.size()>0)
	{
		for(unsigned int n = 0; n < childlist.size(); n++)
		{
			std::string particlename;
			int x,y;
			datalibrary->getData(datapath + std::string("/") + childlist[n] + std::string("/Particle"),particlename);
			datalibrary->getData(datapath + std::string("/") +childlist[n] + std::string("/GridX"),x);
			datalibrary->getData(datapath + std::string("/") +childlist[n] + std::string("/GridY"),y);
			int index;
			index = terrain->createMapParticle(x,y,particlename);
			datalibrary->setData(datapath + std::string("/") + childlist[n] + std::string("/Index"),index);
		}
	}
}
Esempio n. 6
0
BattleSquad::SkillState BattleSquad::canUseSkill(std::string skillid)
{
	DataLibrary* datalib = DataLibrary::getSingletonPtr();
	std::vector<std::string> activeskills;
	activeskills = datalib->getChildList(mPath + "/Skill");
	std::vector<std::string>::iterator ite;
	ite = std::find(activeskills.begin(), activeskills.end(), skillid);
	if(ite == activeskills.end())
		return SKILLSTATE_NOSKILL;
	if(getActionPoint() < getSkillApCost(skillid))
		return SKILLSTATE_NOTAVAILABLE;
	int cooldown = 0;
	datalib->getData(mPath + "/Skill/" + skillid + "/CoolDown", cooldown);
	if(cooldown > 0)
		return SKILLSTATE_NOTAVAILABLE;
	return SKILLSTATE_AVAILABLE;
}
Esempio n. 7
0
bool MapLoader::loadMapFormSave()
{
	DataLibrary* datalibrary = DataLibrary::getSingletonPtr();
	int mapsize;
	datalibrary->getData("GameData/BattleData/MapData/MapSize", mapsize);
	MapDataManager::getSingleton().mMapSize = mapsize;
	std::vector<std::string> arealist = datalibrary->getChildList("GameData/BattleData/MapData/Area");
	std::vector<std::string>::iterator ite = arealist.begin();
	for( ; ite != arealist.end(); ite++)
	{
		Area area(str(boost::format("GameData/BattleData/MapData/Area/%1%/CoordList")%(*ite)));
		MapDataManager::getSingleton().mMapArea.insert(std::make_pair(*ite, area));
	}
	Terrain::getSingleton().createTerrain();
	std::string music;
	datalibrary->getData("GameData/StoryData/MusicName", music);
	AudioSystem::getSingleton().playStream(music,true,2000);
	return true;
}
Esempio n. 8
0
bool BattleSquad::addParticle(std::string particlename, int object, std::string &particleid)
{
	DataLibrary* datalib = DataLibrary::getSingletonPtr();
	std::string distpath = mPath + std::string("/ParticleList");
	std::vector<std::string> particlelist = datalib->getChildList(distpath);
	int x = 0;
	particleid = std::string("p") + Ogre::StringConverter::toString(x);
	std::vector<std::string>::iterator ite = std::find(particlelist.begin(), particlelist.end(),particleid);
	while(ite != particlelist.end())
	{
		x = x + 1;
		particleid = std::string("p") + Ogre::StringConverter::toString(x);
		ite = std::find(particlelist.begin(), particlelist.end(),particleid);
	}
	distpath = distpath + std::string("/") + particleid;
	datalib->setData(distpath + std::string("/ParticleName"), particlename, true);
	datalib->setData(distpath + std::string("/AffectUnit"), object, true);
	return true;
}
Esempio n. 9
0
void MapLoader::initBattleSquad(bool loadfrommap)
{
	BattleSquadManager* battlesuqadmanager = BattleSquadManager::getSingletonPtr();
	DataLibrary* datalib =DataLibrary::getSingletonPtr();
	SquadGrapManager* suqadgrapmanager = SquadGrapManager::getSingletonPtr();
	//AVGSquadManager* avgsquadmanager = AVGSquadManager::getSingletonPtr();
	std::string path = "GameData/BattleData/SquadList";
	if(loadfrommap)
	{
		//载入地图部队
		while(mMapSquadInfo.size() > 0)
		{
			MapSquadInfo squadinfo = mMapSquadInfo.front();
			if(squadinfo.unitNum==0)
				DataLibrary::getSingletonPtr()->getData(str(boost::format("StaticData/SquadData/%1%/UnitNum")%squadinfo.squadTempId),squadinfo.unitNum);
			BattleSquad* battlesquad = new BattleSquad(str(boost::format("%1%/%2%")%path%squadinfo.squadId));
			battlesuqadmanager->mSquadList.insert(std::make_pair(battlesquad->getSquadId(),battlesquad));
			if(!battlesquad->init(str(boost::format("StaticData/SquadData/%1%")%squadinfo.squadTempId),
				squadinfo.team, squadinfo.unitNum, squadinfo.x, 
				squadinfo.y, squadinfo.dir))
			{
				BattleSquadManager::BattleSquadIte ite = battlesuqadmanager->mSquadList.find(battlesquad->getSquadId());
				delete battlesquad;
				battlesuqadmanager->mSquadList.erase(ite);
			}
			else
			{
				suqadgrapmanager->createSquadGrap(battlesquad->getSquadId(), battlesquad->getPath(), battlesquad->getGridX(), battlesquad->getGridY(), 
													battlesquad->getDirection(), battlesquad->getFormation(), battlesquad->getUnitGrapNum()-1);
				SquadGraphics* grap = suqadgrapmanager->getSquad(battlesquad->getSquadId());
				grap->setVisible(battlesquad->getViewbyPlayer());
			}
			mMapSquadInfo.pop();
		}
		//载入玩家部队
		std::vector<std::string> childlist;
		childlist = datalib->getChildList(std::string("GameData/StoryData/SquadData"));
		if(childlist.size()>0)
		{
			std::vector<std::string>::iterator ite;
			for(ite = childlist.begin(); ite != childlist.end(); ite++)
			{
				BattleSquad* battlesquad = new BattleSquad(str(boost::format("%1%/%2%")%path%(*ite)));
				battlesuqadmanager->mSquadList.insert(std::make_pair(battlesquad->getSquadId(),battlesquad));
// 				std::string datapath = std::string("GameData/BattleData/SquadList/") + (*ite);
// 				datalib->copyNode(std::string("GameData/StoryData/SquadData/EnableSquad/") + (*ite),datapath, true);
// 				int type;
// 				Formation f;
// 				datalib->getData(datapath + std::string("/Type"), type );
// 				if(type == SQUAD_NORMAL)
// 					f = Line;
// 				else
// 					f = Loose;
// 				datalib->setData(datapath +std::string("/TeamId"), std::string("Team1"), true );
// 				datalib->setData(datapath +std::string("/Grapid"),battlesuqadmanager->mCurid, true);
// 				datalib->setData(datapath +std::string("/CreateType"), StroySquad, true );
// 				datalib->setData(datapath +std::string("/Direction"), North, true );
// 				datalib->setData(datapath +std::string("/Formation"), f, true );
// 				datalib->setData(datapath +std::string("/ActionPoint"), 0.0f, true );
// 				BattleSquad* battlesquad = new BattleSquad((*ite),battlesuqadmanager->mCurid,-10,-10); 
// 				SquadGraphics* squadgrap = suqadgrapmanager->createSquad((*ite), datapath, battlesuqadmanager->mCurid, -10, -10,North,Line,battlesquad->getUnitGrapNum());
// 				squadgrap->setFormation(f,false);
// 				squadgrap->setDirection(North,false);
				if(!battlesquad->init(str(boost::format("GameData/StoryData/SquadData/%1%")%(*ite)),1))
				{
					BattleSquadManager::BattleSquadIte ite = battlesuqadmanager->mSquadList.find(battlesquad->getSquadId());
					delete battlesquad;
					battlesuqadmanager->mSquadList.erase(ite);
				}
				else
				{
					suqadgrapmanager->createSquadGrap(battlesquad->getSquadId(), battlesquad->getPath(), battlesquad->getGridX(), battlesquad->getGridY(), 
						battlesquad->getDirection(), battlesquad->getFormation(), battlesquad->getUnitGrapNum()-1);
				}
//				battlesuqadmanager->mCurid ++;
			}
		}
	}
	else
	{
		std::vector<std::string> childlist;
		childlist = datalib->getChildList(path);
		if(childlist.size()>0)
		{
			std::vector<std::string>::iterator ite;
			for(ite = childlist.begin(); ite != childlist.end(); ite++)
			{
				std::string datapath = path + std::string("/") + (*ite);
				BattleSquad* battlesquad = new BattleSquad(datapath);
				battlesquad->init();
				battlesuqadmanager->mSquadList.insert(std::make_pair(battlesquad->getSquadId(),battlesquad));
				suqadgrapmanager->createSquadGrap(battlesquad->getSquadId(), battlesquad->getPath(), battlesquad->getGridX(), battlesquad->getGridY(), 
					battlesquad->getDirection(), battlesquad->getFormation(), battlesquad->getUnitGrapNum()-1);
				SquadGraphics* grap = suqadgrapmanager->getSquad(battlesquad->getSquadId());
				if(battlesquad->getUnitNum() > 0)
					grap->setVisible(battlesquad->getViewbyPlayer());
				else
					grap->setVisible(false);
			}
		}
	}
}
Esempio n. 10
0
float BattleSquad::getAttr(int attrtype , int calctype)
{
	DataLibrary* datalib = DataLibrary::getSingletonPtr();
	std::vector<std::string> modifierlist = datalib->getChildList(mPath + std::string("/ModifierList"));
	if(modifierlist.size() == 0)
		return 0.0f;
	if(attrtype == ATTR_RANGEDDEFENCE )
		attrtype = ATTR_DEFENCE;
	float base = 0.0f;
	float mbouse = 0.0f;
	float mbane = 0.0f;
	float resist = 0.0f;
	float cbouse = 0.0f;
	float cbane = 0.0f;
	std::vector<std::string>::iterator ite;
	for(ite = modifierlist.begin(); ite != modifierlist.end(); ite++)
	{
		int type = ATTRMODIFIER_BASE;
		float attrval = 0.0f;
		std::string datapath = mPath + std::string("/ModifierList/") + (*ite);
		datalib->getData(datapath + std::string("/Type"), type);
		switch(attrtype)
		{
		case ATTR_ATTACK:
			datalib->getData(datapath + std::string("/Attack"), attrval);
			break;
		case ATTR_RANGEDATTACK:
			datalib->getData(datapath + std::string("/RangedAttack"), attrval);
			break;
		case ATTR_DEFENCE:
			datalib->getData(datapath + std::string("/Defence"), attrval);
			break;
		case ATTR_FORM:
			datalib->getData(datapath + std::string("/Formation"), attrval);
			break;
		case ATTR_INITIATIVE:
			datalib->getData(datapath + std::string("/Initiative"), attrval);
			break;
		case ATTR_ACTIONPOINT:
			datalib->getData(datapath + std::string("/ActionPoint"), attrval);
			break;
		case ATTR_DETECTION:
			datalib->getData(datapath + std::string("/Detection"), attrval);
			break;
		case ATTR_COVERT:
			datalib->getData(datapath + std::string("/Covert"), attrval);
			break;
		case ATTR_TOUGHNESS:
			datalib->getData(datapath + std::string("/Toughness"), attrval);
			break;
		case ATTR_CONTER:
			datalib->getData(datapath + std::string("/Conter"), attrval);
			break;
		}
		switch(type)
		{
		case ATTRMODIFIER_BASE:
			base += attrval;
			break;
		case ATTRMODIFIER_MAGIC:
			if(attrval > mbouse)
				mbouse = attrval;
			if(attrval < mbane)
				mbane = attrval;
			break;
		case ATTRMODIFIER_COMMAND:
			if(attrval > cbouse)
				cbouse = attrval;
			if(attrval < cbane)
				cbane = attrval;
			break;
		case ATTRMODIFIER_RESISTANCE:
			if(attrval > resist)
				resist = attrval;
			break;
		}
	}
	float bouse = cbouse + mbouse;
	float bane = cbane + mbane;
	float terrainbouse = 0.0f;
	switch(attrtype)
	{
		case ATTR_DEFENCE:
			terrainbouse = MapDataManager::getSingleton().getDefModify(getGridX(), getGridY(), getTeam());
			break;
		case ATTR_COVERT:
			terrainbouse = MapDataManager::getSingleton().getCovert(getGridX(), getGridY(), getTeam());
			break;
	}
	if(terrainbouse > 0.0f)
		bouse += terrainbouse;
	else
		bane += terrainbouse;
	if(bane < -resist)
	{
		bane += resist;
		resist = 0.0f;
	}
	else
	{
		bane = 0.0f;
		resist += bane;
	}

	bouse = bouse + bane;
	switch(calctype)
	{
	case ATTRCALC_FULL:
		return base + bouse;
		break;
	case ATTRCALC_ONLYBASE:
		return base;
		break;
	case ATTRCALC_ONLYBONUS:
		return bouse;
		break;
	}
	return 0.0f;
}
Esempio n. 11
0
std::vector<BattleSquad::ActiveSkillInfo> BattleSquad::GetActiveSkillList()
{
	std::vector<ActiveSkillInfo> skilllist;
	DataLibrary* datalib = DataLibrary::getSingletonPtr();
	ActiveSkillInfo skillinfo;
	//ÅжÏÒƶ¯
	if(canMove() == SKILLSTATE_AVAILABLE)
	{
		skillinfo.skillid = "move";
		skillinfo.apcost = 0;
		skillinfo.available = true;
		skilllist.push_back(skillinfo);
		skillinfo.skillid = "turn";
		skillinfo.apcost = 0;
		skillinfo.available = true;
		skilllist.push_back(skillinfo);
	}
	else if(canMove() == SKILLSTATE_NOTAVAILABLE)
	{
		skillinfo.skillid = "move";
		skillinfo.apcost = 0;
		skillinfo.available = false;
		skilllist.push_back(skillinfo);
	}
	
	//ÅжÏÕóÐÍ
	switch(canChangeFormation(Loose))
	{
	case SKILLSTATE_AVAILABLE:
		skillinfo.skillid = "looseformation";
		skillinfo.apcost = getChangeFormationApCost(Loose);
		skillinfo.available = true;
		skilllist.push_back(skillinfo);
		break;
	case SKILLSTATE_NOTAVAILABLE:
		skillinfo.skillid = "looseformation";
		skillinfo.apcost = getChangeFormationApCost(Loose);
		skillinfo.available = false;
		skilllist.push_back(skillinfo);
		break;
	}
	switch(canChangeFormation(Line))
	{
	case SKILLSTATE_AVAILABLE:
		skillinfo.skillid = "lineformation";
		skillinfo.apcost = getChangeFormationApCost(Line);
		skillinfo.available = true;
		skilllist.push_back(skillinfo);
		break;
	case SKILLSTATE_NOTAVAILABLE:
		skillinfo.skillid = "lineformation";
		skillinfo.apcost = getChangeFormationApCost(Line);
		skillinfo.available = false;
		skilllist.push_back(skillinfo);
		break;
	}
	switch(canChangeFormation(Circular))
	{
	case SKILLSTATE_AVAILABLE:
		skillinfo.skillid = "circularformation";
		skillinfo.apcost = getChangeFormationApCost(Circular);
		skillinfo.available = true;
		skilllist.push_back(skillinfo);
		break;
	case SKILLSTATE_NOTAVAILABLE:
		skillinfo.skillid = "circularformation";
		skillinfo.apcost = getChangeFormationApCost(Circular);
		skillinfo.available = false;
		skilllist.push_back(skillinfo);
		break;
	}
	//ÅжÏÖ÷¶¯¼¼ÄÜ
	std::vector<std::string> activeskills;
	activeskills = datalib->getChildList(mPath + "/Skill");
	std::vector<std::string>::iterator ite;
	for(ite = activeskills.begin(); ite != activeskills.end(); ite++)
	{
		switch(canUseSkill(*ite))
		{
		case SKILLSTATE_AVAILABLE:
			skillinfo.skillid = (*ite);
			skillinfo.apcost = getSkillApCost(*ite);
			skillinfo.available = true;
			skilllist.push_back(skillinfo);
			break;
		case SKILLSTATE_NOTAVAILABLE:
			skillinfo.skillid = (*ite);
			skillinfo.apcost = getSkillApCost(*ite);
			skillinfo.available = false;
			skilllist.push_back(skillinfo);
			break;
		}
	}
	return skilllist;
}