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); } }
public BLUnitBuilding FindNeareatReviveBuilding() { var building_list = BLUnitManager.Instance().GetBuildingList(); float distance = float.MaxValue; BLUnitBuilding revive_building = null; var enumerator = building_list.GetEnumerator(); while (enumerator.MoveNext()) { BLUnitBuilding building_unit = enumerator.Current.Value; if (building_unit.team_id == team_id && building_unit.can_revive_hero) { float temp = (building_unit.position - position).SqrMagnitude(); if (temp < distance) { revive_building = building_unit; } } } return(revive_building); }
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 OnDead() { base.OnDead(); // 处理复活的逻辑 BLUnitBuilding revive_building = FindNeareatReviveBuilding(); if (revive_building != null) { int revive_need_frames = (int)(revive_cool_down / BLTimelineController.MS_PER_FRAME); revive_building.AddReviveUnit(gds_name, unit_id, revive_need_frames); } }
public BLUnitBuilding CreateBuildingUnit(int unit_id, string gds_name, BLIntVector3 pos, int team_id) { GDSKit.building unit_gds = GDSKit.building.GetInstance(gds_name); BLUnitBuilding building_unit = new BLUnitBuilding(); // 属性相关设置 building_unit.gds_name = gds_name; building_unit.unit_type = UnitType.Building; building_unit.unit_id = unit_id; building_unit.vision = unit_gds.vision; building_unit.hp = unit_gds.building_hp; building_unit.max_hp = unit_gds.building_hp; building_unit.can_revive_hero = unit_gds.can_revive_hero; building_unit.position = pos; building_unit.team_id = team_id; if (all_unit_list.ContainsKey(building_unit.unit_id)) { Debug.LogError("相同名字的unit已经在管理器里了 id : " + building_unit.unit_id); return(null); } all_unit_list.Add(building_unit.unit_id, building_unit); buiding_unit_list.Add(building_unit.unit_id, building_unit); building_unit.OnInit(); // 表现层 BuildingUnit unit_renderer = UnitManager.Instance().CreateBuildingUnit(building_unit.gds_name, building_unit.unit_id, building_unit.position.Vector3Value()); unit_renderer.attack_vision = building_unit.vision * 0.001f; unit_renderer.team_id = team_id; unit_renderer.OnInit(); return(building_unit); }
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 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() + "秒"; } } } }