/// <summary> /// 双方战斗比较,返回阵亡者,且胜者血量相应损失 /// </summary> /// <param name="attacker">进攻方</param> /// <param name="defender">防守方</param> /// <returns>阵亡者</returns> public static GameObject Battle(GameObject attacker, GameObject defender) {//这里将帅吃子会加生命45,要找出原因 AttrBox a = GetChessAttrList(attacker); AttrBox b = GetChessAttrList(defender); int a_damage = a.Attack <= b.Defence ? 1 : a.Attack - b.Defence; //a对b造成的伤害 int b_damage = b.Attack <= a.Defence ? 1 : b.Attack - a.Defence; //b对a造成的伤害 int a_times = b.Hp / a_damage == 0 ? 1 : b.Hp / a_damage; //a打死b所需回合数 int b_times = a.Hp / b_damage == 0 ? 1 : a.Hp / b_damage; //b打死a所需回合数 if (a_times <= b_times) { //Debug.Log("a_times = " + a_times); //0 //Debug.Log("b_times = " + b_times); //0 //Debug.Log("a.Hp = " + a.Hp); //1 //Debug.Log("b_damage = " + b_damage); //45 a.Hp -= (b_damage * (a_times - 1)); b.Hp = 0; return(defender); } else { b.Hp -= a_damage * b_times; a.Hp = 0; return(attacker); } }
/// <summary> /// 设置属性面板 /// </summary> /// <param name="attrBox">属性</param> /// <param name="tag">棋子阵营</param> public void SetAttrTexts(AttrBox attrBox, GameObject chess) { if (attrBox.Hp == 0) { redDetailPanel.SetActive(false); blackDetailPanel.SetActive(false); return; } redDetailPanel.SetActive(chess.tag == "Red"); blackDetailPanel.SetActive(chess.tag == "Black"); if (chess.tag == "Red") { r_Name.text = GameUtil.GetChineseChessName(curAddChess); r_Hp.text = attrBox.Hp.ToString(); r_Attack.text = attrBox.Attack.ToString(); r_Defence.text = attrBox.Defence.ToString(); r_Combat.text = attrBox.Combat.ToString(); } else { b_Name.text = GameUtil.GetChineseChessName(curAddChess); b_Hp.text = attrBox.Hp.ToString(); b_Attack.text = attrBox.Attack.ToString(); b_Defence.text = attrBox.Defence.ToString(); b_Combat.text = attrBox.Combat.ToString(); } }
public virtual void Awake() { createManager = CreateManager.Instance; chessReciprocalState = ChessReciprocalState.unChoosed; chessSituationState = ChessSituationState.Idle; PoolManager.PushEvent += SubscribeEvents;//棋子被创建时就该订阅这一堆事件 PoolManager.TakeEvent += SubscribeEvents; PoolManager.RestoreEvent += CancelSubscribeEvents; gameObject.AddComponent <AttrBox>(); attrBox = gameObject.GetComponent <AttrBox>(); attrBox.SetAttrList(ChessConfig.GetAttrList(chessName)); }
/// <summary> /// 监听棋子被选中事件 /// </summary> /// <param name="chess"></param> public void OnChoose(GameObject chess) { curAddChess = chess; curAttr = GameUtil.GetChessAttrList(chess); UpdateAttrPanel(chess); bool isAdding = GameController.playing == Playing.RedAdding || GameController.playing == Playing.BlackAdding; addAtrrPanel.SetActive(isAdding); if (isAdding) { addChessName.text = GameUtil.GetChineseChessName(chess); } else { addChessName.text = ""; } }
/// <summary> /// 添加每回合全部棋子对应属性信息图谱 /// </summary> public static void SetAttrMaps() { if (attrMaps == null) { attrMaps = new List <Dictionary <GameObject, string> >(); } Dictionary <GameObject, string> dic = new Dictionary <GameObject, string>(); foreach (GameObject chess in PoolManager.work_List) { AttrBox chessAttrs = GameUtil.GetChessAttrList(chess); string attrStr = chessAttrs.Hp + "_" + chessAttrs.Attack + "_" + chessAttrs.Defence; //AttrBox temp = new AttrBox(); //这里要想办法优化,频繁创建对象消耗性能 //temp.Hp = chessAttrs.Hp; //temp.Attack = chessAttrs.Attack; //temp.Defence = chessAttrs.Defence; //dic.Add(chess, temp); dic.Add(chess, attrStr); } attrMaps.Add(dic); }
public void UpdateAttrPanel(GameObject chess) { AttrBox attrBox = GameUtil.GetChessAttrList(chess); SetAttrTexts(attrBox, chess); }
public static int GetChessCombat(AttrBox chessAttrBox) { return(chessAttrBox.Combat); }