首页 > 代码库 > 攻击伤害封装
攻击伤害封装
/// <summary>
/// 单位伤害
/// </summary>
/// <param name="unit">被攻击者</param>
/// <param name="skill">使用技能</param>
public static int unitDamage(Unit unit,Skill skill,int damage=-1,Deleg deleg=null)
{
Unit owner = skill.owner;
unit.foe = owner;
owner.enemy = unit;
dodge = unit.dodge ;
crit = owner.crit;
block = unit.block;
owner.notify(PropertyType.ATTACK_ACT);
unit.notify(PropertyType.ATTACKED_ACT);
bool bDodge = GameUtility.WanRandom()< dodge;
DefendData defendData = http://www.mamicode.com/new DefendData();
defendData.targetId = unit.guid;
defendData.skill = skill;
if (bDodge)
{
defendData.defendType = DefendType.Dodge;
}
else
{
bool bCrit = GameUtility.WanRandom() < crit;
bool bBlock = GameUtility.WanRandom() < block;
if (damage >= 0)
{
owner.fightingProperty.setValue(PropertyType.DAMAGE, damage);
}
else
{
int a=owner.fightingProperty.getDamage(unit);
}
if (bCrit && bBlock)
{
defendData.defendType = DefendType.CritAndBlock;
owner.critDamage();
owner.blockDamage();
}
else
{
if (bCrit)
{
defendData.defendType = DefendType.Crit;
owner.critDamage();
}
else
{
defendData.defendType = DefendType.Block;
owner.blockDamage();
}
}
if (deleg!=null)
{
deleg();
}
defendData.changeHp = -owner.fightingProperty.getValue(PropertyType.DAMAGE);
unit.VaryHP(defendData.changeHp);
defendData.dead = unit.IsDead();
}
LayerMessager.LogicPush(defendData);
return defendData.changeHp;
}
攻击伤害封装