/** 接收士兵伤害 */ public void DamageBehit(DamageVO damageVO) { if (unitData.invincible && damageVO.damageType != DamageType.HEAL) { return; } if (BeforeDamage != null) { BeforeDamage(damageVO); } if (damageVO.damageType == DamageType.HEAL) { hp += damageVO.value; War.textEffect.PlayHP(damageVO.value, this); } else { hp -= damageVO.value; unitData.beattack = true; // Debug.Log(string.Format("hpbug UnitCtl.DamageBehit atk={0}, def={1}, hp={2}, damageVO.value={3}", atk, def, hp, damageVO.value)); float consHp = damageVO.value; if (hp < 0) { consHp = damageVO.value + hp; } float def2AtkHP = WarFormula.WD_RelativelyHP_Def2Atk(unitData.def, damageVO.caster.unitData.atk, consHp); War.textEffect.PlayHP(-consHp, this); War.signal.HPConst(unitData.legionId, damageVO.caster.unitData.legionId, consHp); War.signal.HPConst(damageVO.caster.unitData.legionId, unitData.legionId, def2AtkHP); War.hunManager.Play(damageVO.caster); if (consHp != 0) { War.hunManager.Play(unitData.colorId, transform.position + new Vector3(Random.Range(-2, 2), 0f, Random.Range(-2, 2))); } // 添加经验--进攻 damageVO.caster.legionData.levelData.AddExp_SoliderAtk(consHp, damageVO.caster); // 添加经验--防守 damageVO.target.legionData.levelData.AddExp_SoliderDef(def2AtkHP, damageVO.caster); } if (OnDamage != null) { OnDamage(damageVO); } }
/** 被士兵攻打 */ public void BehitForUnit(UnitData enemy) { if (!War.isGameing) { return; } if (invincible) { return; } // Debug.Log(string.Format("hpbug BehitForUnit atk={0}, def={1}, hp={2}, enemy.atk={3}, enemy.hp={3}", atk, def, hp, enemy.atk, enemy.hp)); // Debug.Log(string.Format("<color=lightblue>BehitForUnit enemy={0} enemy.props={1}</color>", enemy, enemy.props.ToStrProp())); DamageVO damageVO = new DamageVO(); damageVO.caster = enemy.unit; damageVO.target = this.unit; damageVO.value = WarFormula.WD_Solider2Casern_Damage(def, enemy.atk, enemy.hp); damageVO.fromType = DamageFromType.Solider; damageVO.damageType = DamageType.ATTACK; try { damageVO.target.DamageBehit(damageVO); } catch (Exception e) { if (Application.isEditor) { Debug.LogError(e); } else { Debug.LogFormat("<color=red>" + e + "</color>"); } } // Debug.Log(string.Format("hpbug BehitForUnit atk={0}, def={1}, hitVO.damageVO.value={2}, hp={3}", atk, def, damageVO.value, hp)); if (hp >= 0) { behit = true; War.signal.OnBehit(uid, enemy.legionId); } else { hp = WarFormula.WD_RelativelyHP_Def2Atk(def, enemy.atk, -hp); behit = false; ChangeLegion(enemy.legionId); } }