/*
* LSouSouCalculate.js
* 战场命中伤害等计算
**/
var LSouSouCalculate=function(){};
/********************************************
 物理攻击的命中率<br>
 X代表我方的爆发力，Y代表敌方的爆发力。R表示命中率<br>
 if (x>2*y)<br>
 r=100;<br>
 else if(x>y)<br>
 r=(x-y)*10/y+90;<br>
 else if(x>y/2)<br>
 r=(x-y/2)*30/(y/2)+60;<br>
 else<br>
 r=(x-y/3)*30/(y/3)+30;<br>
 注：手套和盾有加成效果。比如敌人有辅助防御15%的宝物，那么最终的命中率是r-15<br>
 2、法术攻击的命中率<br>
 计算公式与1相同，其中X表示我方的精神力与运气之和，Y表示敌方的精神力与运气之和<br>
 再考虑宝物的加成<br>
 最后，不同的法术还会有具体的权重系数，比如还要乘以1.5、0.9等等。
 *********************************************/
LSouSouCalculate.getHitrate=function(attChara,hertChara){
	var r;
	//得到双方的爆发力
	var attBreakout = attChara.member.getBreakout();
	var hertBreakout = hertChara.member.getBreakout();
	if(attBreakout > 2*hertBreakout){
		r = 100;
	}else if(attBreakout > hertBreakout){
		r=(attBreakout-hertBreakout)*10/hertBreakout+90;
	}else if(attBreakout > hertBreakout){
		r=(attBreakout-hertBreakout/2)*30/(hertBreakout/2)+60;
	}else{
		r=(attBreakout-hertBreakout/3)*30/(hertBreakout/3)+30;
	}
	if(Math.random()*100 <= r){
		return true;
	}
	return false;
};
/***************************************************************************
 物理攻击的伤害值计算
 X代表攻击方的攻击力，Y代表被攻击方的防御力，Lv表示攻击方的等级。R表示伤害值
 首先会根据地形修正攻击和防御力为X',Y'
 if (x'>y')
 r=Lv+25+(X'-Y')/2;
 else
 r=Lv+25-(Y'-X')/2
 然后再根据兵种相克和宝物进行修正
 *****************************************************************************/
LSouSouCalculate.getHertValue=function(attChara,hertChara){
	var r;
	//得到攻击方的攻击力和等级
	var attLv =  attChara.member.getLv();
	var attAttack = attChara.member.getAttack();
	//得到防御方的防御力
	var hertDefense = hertChara.member.getDefense();
	trace("attAttack = " + attAttack,"hertDefense = " + hertDefense,(typeof attLv)+"attLv = " + attLv);
	//计算攻击方所在地形
	var attTerrain = "Terrain" + LSouSouObject.sMap.mapData[attChara.locationY()][attChara.locationX()];
	//计算防御方所在地形
	var hertTerrain = "Terrain" + LSouSouObject.sMap.mapData[hertChara.locationY()][hertChara.locationX()];
	//根据地形修正攻击和防御力
	var attAttackAddition;
	if(!LGlobal.arms["Arms" + attChara.member.getArms()].Terrain[attTerrain]){
		attAttackAddition = attAttack;
	}else{
		attAttackAddition = Math.floor((LGlobal.arms["Arms" + attChara.member.getArms()].Terrain[attTerrain].Addition/100) * attAttack);
	}
	
	var hertDefenseAddition;
	if(!LGlobal.arms["Arms" + hertChara.member.getArms()].Terrain[hertTerrain]){
		hertDefenseAddition = hertDefense;
	}else{
		hertDefenseAddition = Math.floor((LGlobal.arms["Arms" + hertChara.member.getArms()].Terrain[hertTerrain].Addition/100) * hertDefense);
	}
	trace("attAttackAddition = " + attAttackAddition,"hertDefenseAddition = " + hertDefenseAddition);
	
	//物理攻击的伤害值计算
	if(attAttackAddition > hertDefenseAddition){
		r = attLv + 25 + (attAttackAddition - hertDefenseAddition)/2;
	}else{
		r = attLv + 25 - (hertDefenseAddition - attAttackAddition)/2;
	}
	trace("r = " + r);
	//兵种相克
	if(LGlobal.arms["Arms" + attChara.member.getArms()].Restrain["list" + hertChara.member.getArms()]){
		r = Math.floor((LGlobal.arms["Arms" + attChara.member.getArms()].Restrain["list" + hertChara.member.getArms()]/100) * r);
	}
	trace("r = " + r);
	r = Math.floor((110-Math.random()*20)*r/100);
	trace("random r = " + r);
	/******************************
	 //宝物修正
	 ******************************/
	//暂略
	return r;
}