/// <summary> /// 战斗回调 /// </summary> /// <param name="obj"></param> private void BattleSys_EventOnFightFrameInfo(proto.S2CFightFrameInfo obj) { if (UserStatusPanel.Instance != null) { UserStatusPanel.Instance.ShowTime(obj.fighttick / 1000); } for (int i = 0; i < obj.underattacklist_size(); i++) { proto.UnderAttackInfo underAttackInfo = obj.underattacklist(i); TeamDisplay display = GetTeamDisplay(underAttackInfo.unitid); display.ModifyHp(underAttackInfo); } for (int i = 0; i < obj.behaviorsequences_size(); i++) { proto.UnitBehavior unit = obj.behaviorsequences(i); TeamDisplay display = GetTeamDisplay(unit.unitid); if (unit.breakaway) { display.BreakAway(); continue; } if (unit.has_position()) { display.Move(((float)unit.position.posx) / 10000f, ((float)unit.position.posz) / 10000f, unit.position.movetype); } // 部件开火信息表 for (int eventIndex = 0; eventIndex < unit.partfireevent_size(); eventIndex++) { proto.PartFireEvent fireEvent = unit.partfireevent(eventIndex); if (fireEvent == null) { Debug.LogError("PartFireEvent is null"); continue; } display.ShipFire(fireEvent); } } for (int i = 0; i < obj.useskill_size(); i++) { proto.UseSkill skill = obj.useskill(i); if (skill.skillstage == Def.SkillStage.Sing && EventOnSkillSing != null) { EventOnSkillSing(skill.skillid); } else if (skill.skillstage == Def.SkillStage.Casting && EventOnSkillTrigger != null) { EventOnSkillTrigger(skill.skillid); } TeamDisplay display = GetTeamDisplay(skill.unitid); display.UseSkill(skill); } }
private void ApplyAttackEffect(int val, int EffectType) { proto.UnderAttackInfo info = new proto.UnderAttackInfo(); info.unitid = this.ID; switch (EffectType) { case Def.PartsEffectType.LaserDmg: // 激光伤害 if (this.ShipProperty_.EnergyShield.Enough(val)) { this.ShipProperty_.EnergyShield.Change(-val); info.energy = -val; } else { info.energy = -this.ShipProperty_.EnergyShield.Value; info.durablility = -val + this.ShipProperty_.EnergyShield.Value; this.ShipProperty_.EnergyShield.SetToMin(); this.ShipProperty_.Durability.Change(info.durablility); } break; case Def.PartsEffectType.KineticEnergyDmg: { // 实弹伤害 if (this.ShipProperty_.ArmouredShield.Enough(val)) { this.ShipProperty_.ArmouredShield.Change(-val); info.armor = -val; } else { info.armor = -this.ShipProperty_.ArmouredShield.Value; info.durablility = -val + this.ShipProperty_.ArmouredShield.Value; this.ShipProperty_.ArmouredShield.SetToMin(); this.ShipProperty_.Durability.Change(info.durablility); } } break; case Def.PartsEffectType.ParticleDmg: { // 粒子束伤害 // TODO 力场护盾 百分比调整伤害 info.durablility -= val; this.ShipProperty_.Durability.Change(info.durablility); } break; } if (this.Ship.Reference.stack) { this.StackAliveNum_ = Mathf.CeilToInt(((float)this.ShipProperty_.Durability.Value / this.ShipProperty_.Durability.Max) * this.Ship.Reference.stack_num); } FightMessageCache.Instance.AddMessage(info); }
public void ModifyHp(proto.UnderAttackInfo underAttackInfo) { // 得到优先目标 int index = 0; if (HurtShipIndexList.Count > 0) { index = HurtShipIndexList[HurtShipIndexList.Count - 1]; HurtShipIndexList.RemoveAt(HurtShipIndexList.Count - 1); } // 处理伤害值 ClientShip_.Durability += underAttackInfo.durablility; ClientShip_.Armor += underAttackInfo.armor; ClientShip_.Energy += underAttackInfo.energy; // 同步血条 BattleShipInfo_.UpdateUIByUnderAttack(ClientShip_.Durability, ClientShip_.Energy, ClientShip_.Armor); // 单个船的直接算 if (ShipList_.Count == 1) { // 若为0,销毁 if (ClientShip_.Durability <= 0) { IsDead = true; ShipList_[index].StartCoroutine(ShipList_[index].ShowDead()); // 我方旗舰 if (IsPlayerShip() && IsCommanderShip()) { BattleSceneDisplayManager.PlayerCommanderShipDead(); } // 敌方基地 if (!IsPlayerShip() && GetShipStrait() == Def.ShipTrait.Build) { BattleSceneDisplayManager.EnemyCommanderShipDead(RootGo_); } Destroy(); } return; } // 多个船的 根据当前血量算出需要爆炸几个船 int maxDurability = ClientShip_.MaxDurability * ShipList_.Count; int maxDeadNum = (int)(ShipList_.Count * (1f - (float)ClientShip_.Durability / (float)maxDurability)); int haveDeadNum = 0; int deadNum = 0; for (int i = 0; i < ShipList_.Count; i++) { if (ShipList_[i] == null) { deadNum++; } else { if (ShipList_[i].IsDead) { deadNum++; } } } for (int i = 0; i < ShipList_.Count; i++) { if (ShipList_[i] != null) { if (ShipList_[i].IsDead) { haveDeadNum++; } } else { haveDeadNum++; } } int needDeadNum = maxDeadNum - haveDeadNum; needDeadNum = needDeadNum < 0 ? 0 : needDeadNum; if (needDeadNum > 0 && ShipList_[index] != null) { if (!ShipList_[index].IsDead) { ShipList_[index].StartCoroutine(ShipList_[index].ShowDead()); needDeadNum--; } } for (int i = 0; i < ShipList_.Count; i++) { if (needDeadNum <= 0) { break; } if (ShipList_[i] == null) { continue; } if (ShipList_[i].IsDead) { continue; } ShipList_[i].StartCoroutine(ShipList_[i].ShowDead()); needDeadNum--; } if (ClientShip_.Durability <= 0) { IsDead = true; Destroy(); } }