public void Init(int player_id_, int team_id_) { team_id = team_id_; player_id = player_id_; for (int i = 0; i < hero_config.Length; ++i) { int hero_index = i; BLPlayerHeroData hero_data = new BLPlayerHeroData(); hero_data.hero_gds_name = hero_config[hero_index]; hero_data.build_site_id = BLUnitManager.Instance().GetBaseID(player_id); BLUnitBase unit = BLUnitManager.Instance().GetUnit(hero_data.build_site_id); if (unit != null) { Debug.Assert(unit.unit_type == UnitType.Building); BLUnitBuilding build_unit = unit as BLUnitBuilding; int unit_id = BLUnitManager.Instance().GetHeroUnitID(player_id, hero_index); build_unit.AddReviveUnit(hero_data.hero_gds_name, unit_id, 0); } all_hero_data.Add(hero_data); } }
virtual public void AttackImplementTick() { if (my_unit.is_move_attack || (!my_unit.IsMoveState())) { if (target_unit == null) { target_unit = AttackAI.FindCanAttackTarget(my_unit); if (target_unit != null) { DoAttack(target_unit); } } else { if (target_unit.IsAlive()) { if (my_unit.IsCanAttack(target_unit)) { DoAttack(target_unit); } else { // 打不到,清空目标 target_unit = null; } } else { target_unit = null; } } } }
// 攻击类型的判定unit1 能否打unit2 public static bool IsCanAttackByAttackType(BLUnitBase unit1, BLUnitBase unit2) { // 暂时没有能攻击的建筑 if (unit1.unit_type == UnitType.Building) { return(false); } else if (unit1.unit_type == UnitType.Hero) { if (unit2.unit_type == UnitType.Building) { return(true); } else if (unit2.unit_type == UnitType.Hero) { BLUnitHero cast_unit = unit1 as BLUnitHero; BLUnitHero enemy_unit = unit2 as BLUnitHero; bool can_attack = false; if ((enemy_unit.is_fly && cast_unit.can_attack_fly) || (!enemy_unit.is_fly) && cast_unit.can_attack_ground) { can_attack = true; } return(can_attack); } } return(false); }
public void Tick() { var enumerator = all_unit_list.GetEnumerator(); List <int> remove_keys = new List <int>(); while (enumerator.MoveNext()) { BLUnitBase unit = enumerator.Current.Value; if (unit.IsAlive()) { unit.Tick(); } if (unit.mark_delete) { remove_keys.Add(enumerator.Current.Key); } } for (int i = 0; i < remove_keys.Count; ++i) { DestroyUnit(remove_keys[i]); } }
public override void DoCommand() { base.DoCommand(); //Debug.Log("放置英雄在第: " + BLTimelineController.Instance().current_logic_frame + " 帧."); // 暂时用team id 代替player id,在房间内是不重复的 BLPlayerData player_data = BLPlayerDataManager.Instance().GetPlayerData(player_id); // 检查是否为可放置的状态 if (player_data.IsCanPutHero(hero_index)) { BLPlayerHeroData hero_data = player_data.GetHeroData(hero_index); BL.BLIntVector3 born_point = BattleField.battle_field.born_point[player_id]; int unit_id = BL.BLUnitManager.Instance().GetHeroUnitID(player_id, hero_index); string unit_gds_name = hero_data.hero_gds_name; BL.BLIntVector3 born_pos = BL.BLUnitManager.Instance().GetRandomPosition(born_point); BL.BLUnitManager.Instance().CreateHeroUnit(unit_id, unit_gds_name, born_pos, team_id); // 建筑上移除 BLUnitBase unit = BLUnitManager.Instance().GetUnit(hero_data.build_site_id); Debug.Assert(unit.unit_type == UnitType.Building); BLUnitBuilding build_unit = unit as BLUnitBuilding; build_unit.RemoveUnit(unit_id); } }
public override void DoCommand() { cast_unit = BLUnitManager.Instance().GetUnit(cast_unit_id); if (cast_unit != null) { cast_unit.DoCommand(this); } }
public void DoAttack(BLUnitBase target_unit, bool is_direct_damage = true) { // 发送事件到表现层 EventManager.Instance().PostEvent(EventConfig.EVENT_L2R_PLAY_ATTACK, new object[] { unit_id, target_unit.unit_id }); if (is_direct_damage) { // 计算伤害 target_unit.OnDamage(attack_power); } }
// 距离要可以打到,并且攻击类型符合 public bool IsCanAttack(BLUnitBase enemy_unit) { if (!IsCanAttackByAttackType(enemy_unit)) { return(false); } BLIntVector3 distance = (enemy_unit.position - position); float distance_square = distance.SqrMagnitude(); return(attack_range_sqr_ >= distance_square); }
virtual public void OnInit() { show_blood_hud = false; mesh_node.gameObject.SetActive(true); gameObject.SetActive(true); vision_range_circle.gameObject.SetActive(false); blood_progress_ = blood_hud_obj.GetComponentInChildren <UIProgressBar>(); bl_unit_info_base = BL.BLUnitManager.Instance().GetUnit(unit_id); UpdateTeam(); }
public override void DoAttack(BLUnitBase attack_target_unit) { if (attack_target_unit != target_unit) { target_unit = attack_target_unit; } if (attack_cool_down <= 0) { my_unit.DoAttack(attack_target_unit); // 换算成攻击间隔是多少帧 attack_cool_down = (int)(my_unit.attack_speed / BLTimelineController.MS_PER_FRAME); } }
// 实际攻击逻辑 public override void DoAttack(BLUnitBase attack_target_unit) { if (attack_cool_down <= 0) { my_unit.DoAttack(attack_target_unit, false); BulletComponent bullet = BLBulletManager.Instance().CreateBullet(); bullet.bullet_speed = my_unit.bullet_speed; bullet.Start(my_unit.position, attack_target_unit.position, HitCallBack); // 换算成攻击间隔是多少帧 attack_cool_down = (int)(my_unit.attack_speed / BLTimelineController.MS_PER_FRAME); } }
virtual public void OnClear() { enemy_symbol = null; blood_progress_ = null; bl_unit_info_base = null; ObjectPoolManager.Instance().ReturnObject("BloodHud", blood_hud_obj); blood_hud_obj = null; gameObject.SetActive(false); if (cache_select_effect != null) { ObjectPoolManager.Instance().ReturnObject("UnitSelectCircle", cache_select_effect); cache_select_effect = null; } }
static public BLUnitBase FindCanAttackTarget(BLUnitHero hero_unit) { // 找到视野范围内,第一个能攻击到的目标 var enemys = BattleVisionControl.Instance().GetEnemys(hero_unit.team_id); if (enemys != null) { var enumerator = enemys.GetEnumerator(); while (enumerator.MoveNext()) { BLUnitBase enemy_unit = enumerator.Current; if (hero_unit.IsCanAttack(enemy_unit)) { return(enemy_unit); } } } return(null); }
public bool IsCanPutHero(int hero_index) { if (IsHeroAlreadyPut(hero_index)) { // 已经放置了这个将军 return(false); } BLPlayerHeroData hero_data = GetHeroData(hero_index); int unit_id = BLUnitManager.Instance().GetHeroUnitID(player_id, hero_index); // 检查资源 // 检查复活状态 BLUnitBase unit = BLUnitManager.Instance().GetUnit(hero_data.build_site_id); Debug.Assert(unit.unit_type == UnitType.Building); BLUnitBuilding build_unit = unit as BLUnitBuilding; return(build_unit.IsUnitCanRevive(unit_id)); }
public void HitCallBack(BulletComponent bullet_componet) { // 结算伤害 var all_enemys = BattleVisionControl.Instance().GetEnemys(my_unit.team_id); int hit_radius_sqr = my_unit.aoe_radius * my_unit.aoe_radius; var enumerator = all_enemys.GetEnumerator(); while (enumerator.MoveNext()) { BLUnitBase unit = enumerator.Current; if (unit.IsAlive() && (unit.position - bullet_componet.end_position).SqrMagnitude() <= hit_radius_sqr) { unit.OnDamage(my_unit.attack_power); } } // my_unit.AddEffect(bullet_componet.end_position, "hit_effect3"); // }
public void DestroyUnit(int id) { if (!all_unit_list.ContainsKey(id)) { Debug.LogError("要删除的unit不在管理器里 id : " + id); return; } BLUnitBase unit = all_unit_list[id]; unit.OnDestroy(); all_unit_list.Remove(id); if (unit.unit_type == UnitType.Hero) { hero_unit_list.Remove(id); } else if (unit.unit_type == UnitType.Building) { buiding_unit_list.Remove(id); } }
// 每帧更新能看到的单位, // 所有的单位共享视野 public void Tick() { vision_enemy_units.Clear(); // 最多8支队伍 for (int i = 0; i < BattleField.MAX_PLAYER; ++i) { vision_enemy_units.Add(i + 1, new HashSet <BLUnitBase>()); } var unit_list1 = BLUnitManager.Instance().GetAllUnitList(); var unit_list2 = BLUnitManager.Instance().GetAllUnitList(); var enumerator1 = unit_list1.GetEnumerator(); while (enumerator1.MoveNext()) { var enumerator2 = unit_list2.GetEnumerator(); while (enumerator2.MoveNext()) { BLUnitBase unit1 = enumerator1.Current.Value; BLUnitBase unit2 = enumerator2.Current.Value; if (unit1.team_id != unit2.team_id && unit1.IsAlive() && unit2.IsAlive() && unit1.IsCanSeeUnitCheckOnlyMyself(unit2)) { if (!vision_enemy_units[unit1.team_id].Contains(unit2)) { vision_enemy_units[unit1.team_id].Add(unit2); } } } } }
public void UpdateUI() { BL.BLPlayerData player_data = BL.BLPlayerDataManager.Instance().GetPlayerData(BattleField.battle_field.my_player_id); for (int i = 0; i < BattleField.MAX_HERO_COUNT; ++i) { BL.BLPlayerHeroData hero_data = player_data.GetHeroData(i); all_hero_names[i].text = hero_data.hero_gds_name; if (player_data.IsHeroAlreadyPut(i)) { all_hero_states[i].text = "已上场"; } else { int unit_id = BL.BLUnitManager.Instance().GetHeroUnitID(player_data.player_id, i); BL.BLUnitBase unit_base = BL.BLUnitManager.Instance().GetUnit(hero_data.build_site_id); Debug.Assert(unit_base.unit_type == UnitType.Building); BL.BLUnitBuilding unit_building = unit_base as BL.BLUnitBuilding; if (unit_building.IsUnitCanRevive(unit_id)) { all_hero_states[i].text = "就绪"; } else { int time_remain = (int)(unit_building.GetUnitReviveRemainFrames(unit_id) * BL.BLTimelineController.SECOND_PER_FRAME); all_hero_states[i].text = time_remain.ToString() + "秒"; } } } }
virtual public void DoAttack(BLUnitBase attack_target_unit) { }
// 攻击类型决定的是否可攻击 public bool IsCanAttackByAttackType(BLUnitBase enemy_unit) { return(AttackAI.IsCanAttackByAttackType(this, enemy_unit)); }
// 考虑共享视野 public bool IsCanSeeUnit(BLUnitBase enemy_unit) { HashSet <BLUnitBase> vision_enemy_units = BattleVisionControl.Instance().GetEnemys(team_id); return(vision_enemy_units.Contains(enemy_unit)); }
// 只考虑自己 public bool IsCanSeeUnitCheckOnlyMyself(BLUnitBase enemy_unit) { float distance_square = (enemy_unit.position - position).SqrMagnitude(); return(vision_sqr_ >= distance_square); }
public override void OnDestroy() { base.OnDestroy(); cast_unit = null; }