Esempio n. 1
0
        /// <summary>
        /// 用于将卡牌插入手牌中,会根据参数产生手牌变动消息
        /// </summary>
        /// <param name="cardId">要插入的卡牌的ID</param>
        /// <param name="sendMsg">是否发送手牌变动消息,默认发送,若连续调用请设置false并自己发送消息</param>
        public void InsertIntoHandCard(string cardId, bool sendMsg = true)
        {
            // 实例化卡牌到不可见区域,并绑定脚本再初始化
            GameObject cardInstance = Instantiate(emptyObject);
            JsonData   cardData     = GetCardJsonData(cardId);

            //根据json数据中卡牌分类挂载不同脚本
            if (cardData["type"].ToString().Equals("Order"))
            {
                cardInstance.AddComponent <OrderCard>().Init(cardId, cardData);
            }
            else if (cardData["type"].ToString().Equals("Unit"))
            {
                cardInstance.AddComponent <UnitCard>().Init(cardId, cardData);
            }
            else
            {
                cardInstance.AddComponent <BaseCard>().Init(cardId, cardData);
            }

            // 将实例放入对应位置的list中
            _handcardsInstance.Add(cardInstance);

            // 更新手牌list
            _handcards.Add(cardId);

            if (sendMsg)
            {
                // 发送手牌变动消息
                MsgDispatcher.SendMsg((int)MessageType.HandcardChange);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 将预存的预制件放入冷却列表中,仅CardManager内部使用,产生冷却池变动消息
        /// </summary>
        /// <param name="cardId">要冷却的卡牌的预制件引用</param>
        /// <param name="controlCd">默认值为-1,表示按卡牌cd值进行冷却,设定其他值则按设定值冷却</param>
        private void CooldownCard(string cardId, int controlCd = -1)
        {
            // 如果控制cd的参数值小于等于0,表示按卡牌cd值进行冷却
            if (controlCd <= 0)
            {
                // 读取数据库得到冷却回合数
                int roundAmount = (int)_cardsData[cardId]["cd"];

                // 若卡牌自身的cd值为负数,则直接销毁,并进入弃牌堆
                if (roundAmount < 0)
                {
                    _garbageCards.Add(cardId);
                    return;
                }

                // 初始化BaseCard脚本内剩余回合数的counter
                _cooldownCards.Add(new cdObject(roundAmount, cardId));
            }
            else // 按controlCd值进行冷却
            {
                _cooldownCards.Add(new cdObject(controlCd, cardId));
            }

            // 发送冷却池变动消息
            MsgDispatcher.SendMsg((int)MessageType.CooldownlistChange);
        }
Esempio n. 3
0
        public override void Excute()
        {
            MsgDispatcher.SendMsg((int)MessageType.AnnounceAttack);
            //根据伤害优先级对伤害请求排序
            DamageRequestList = DamageRequest.CaculateDamageRequestList(_Attacker, _AttackedUnit);

            for (int i = 0; i < DamageRequestList.Count; i++)
            {
                //优先级相同并且两方互打的伤害请求作为同时处理
                if (i != DamageRequestList.Count - 1 && DamageRequestList[i].priority == DamageRequestList[i + 1].priority &&
                    DamageRequestList[i]._attacker == DamageRequestList[i + 1]._attackedUnit &&
                    DamageRequestList[i]._attackedUnit == DamageRequestList[i + 1]._attacker)
                {
                    //判断被攻击者的反击距离
                    if (JudgeStrikeBack())
                    {
                        DamageRequestList[i].ExcuteSameTime();
                    }
                    else
                    {
                        DamageRequestList[i].Excute(); //距离不够,无法进行反击
                    }
                    i++;
                }
                else if (!_AttackedUnit.IsDead() && !_Attacker.IsDead() && JudgeStrikeBack()) //符合反击要求
                {
                    DamageRequestList[i].Excute();
                }
                else if (!_AttackedUnit.IsDead() && !_Attacker.IsDead() && !JudgeStrikeBack()) //距离不够,无法进行反击
                {
                    DamageRequestList[i].Excute();
                    i++;
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// 冷却处理函数,响应EP消息,处理卡牌冷却,根据情况产生冷却池变动消息,卡牌堆变动消息
        /// </summary>
        public void HandleCooldownEvent()
        {
            List <cdObject> toRemove = new List <cdObject>();

            for (int i = 0; i < _cooldownCards.Count; i++)
            {
                int leftRounds = _cooldownCards[i].ReduceCd();
                if (leftRounds == 0)
                {
                    toRemove.Add(_cooldownCards[i]);
                }
            }

            for (int i = 0; i < toRemove.Count; i++)
            {
                // 将冷却完毕的id重新放回牌堆
                _cardsSets.Add(toRemove[i].objectId);

                // 将其从冷却列表中移除
                _cooldownCards.Remove(toRemove[i]);
            }

            // 发送冷却池变动消息
            MsgDispatcher.SendMsg((int)MessageType.CooldownlistChange);

            if (toRemove.Count > 0)
            {
                // 发送卡牌堆变动消息
                MsgDispatcher.SendMsg((int)MessageType.CardsetChange);
            }
        }
Esempio n. 5
0
    /// <summary>
    /// 如果伤害请求优先级相同,则伤害判定流程会特殊一些
    /// </summary>
    public void ExcuteSameTime()
    {
        //CheckWhosTurn(_attacker, _attackedUnit);

        Damage.TakeDamage(_attackedUnit, Damage.GetDamage(_attacker));
        SetInjurer(_attackedUnit); SetInjuredUnit(_attacker);
        MsgDispatcher.SendMsg((int)TriggerType.Damage);
        MsgDispatcher.SendMsg((int)TriggerType.BeDamaged);

        Damage.TakeDamage(_attacker, Damage.GetDamage(_attackedUnit));
        SetInjurer(_attacker); SetInjuredUnit(_attackedUnit);
        MsgDispatcher.SendMsg((int)TriggerType.Damage);
        MsgDispatcher.SendMsg((int)TriggerType.BeDamaged);

        if (_attacker.IsDead())
        {
            SetKiller(_attackedUnit); SetKilledAndDeadUnit(_attacker);
            MsgDispatcher.SendMsg((int)TriggerType.Kill);
            MsgDispatcher.SendMsg((int)TriggerType.Dead);
        }

        if (_attackedUnit.IsDead())
        {
            SetKiller(_attacker); SetKilledAndDeadUnit(_attackedUnit);
            MsgDispatcher.SendMsg((int)TriggerType.Kill);
            MsgDispatcher.SendMsg((int)TriggerType.Dead);
        }
    }
 void Update()
 {
     if (Input.GetMouseButtonDown(1))
     {
         MsgDispatcher.SendMsg("HelloWorld", "HelloWorld");
     }
 }
Esempio n. 7
0
        public override void Enter(RoundProcessController roundProcessController)
        {
            base.Enter(roundProcessController);
            MsgDispatcher.SendMsg((int)MessageType.AI);

            Gameplay.Instance().singleBattle.battleState = AI.BattleState.Prepare;
            Gameplay.Instance().singleBattle.Run();
        }
        /// <summary>
        /// AI移动
        /// 一格一格移动处理函数
        /// </summary>
        /// <returns></returns>
        public IEnumerator moveStepByStepAI(Unit unit, List <Vector2> paths, System.Action callback)
        {
            #region 测试一哈 先固定(0.0)为灼烧块,(0.1)为粘滞块
            List <Vector2> vector2s = new List <Vector2>();
            vector2s.Add(new Vector2(0, 0));
            BattleMap.Instance().debuffBM.SetBattleMapBlockBurning(vector2s);
            List <Vector2> vector22s = new List <Vector2>();
            vector22s.Add(new Vector2(1, 1));
            BattleMap.Instance().debuffBM.SetBattleMapBlockRetrad(vector22s);
            #endregion

            Vector2        tempVector;
            BattleMapBlock battleMap;
            bool           isRetire = false;
            for (int i = paths.Count - 2; i >= 0; i--)
            {
                //移除上一步的地图块儿下面的units_on_me
                tempVector = new Vector2((int)paths[i + 1].x, (int)paths[i + 1].y);
                battleMap  = BattleMap.Instance().GetSpecificMapBlock(tempVector);
                battleMap.RemoveUnit(unit);
                //添加当前unit到地图块儿下面的units_on_me内
                tempVector = new Vector2((int)paths[i].x, (int)paths[i].y);
                battleMap  = BattleMap.Instance().GetSpecificMapBlock(tempVector);
                if (i != 0)
                {
                    battleMap.AddUnit(unit);
                }
                else
                {
                    battleMap.AddUnit(unit, false);
                }
                unit.transform.localPosition = Vector3.zero;

                if (battleMap.blockType == EMapBlockType.Burnning)//如果经过灼烧块
                {
                    BattleMap.Instance().debuffBM.UnitEnterBurning(tempVector);
                }
                else if (battleMap.blockType == EMapBlockType.Retire)//如果经过滞留块
                {
                    BattleMap.Instance().debuffBM.UnitEnterRetire(unit, battleMap);
                    unit.nextPos = paths[i];
                    MsgDispatcher.SendMsg((int)MessageType.Aftermove);
                    isRetire = true;
                    break;
                }
                unit.nextPos = paths[i];
                MsgDispatcher.SendMsg((int)MessageType.Move);
                yield return(new WaitForSeconds(0.4f));
            }
            if (isRetire == false)
            {
                MsgDispatcher.SendMsg((int)MessageType.Aftermove);
            }
            if (callback != null)
            {
                callback();
            }
        }
Esempio n. 9
0
 /// <summary>
 /// 用于触发当前选择的效果牌的函数,会重置当前选择的卡牌
 /// </summary>
 public void OnTriggerCurrentCard()
 {
     Player.Instance().ConsumeAp(_handcardsInstance[_currentSelectingPos].GetComponent <OrderCard>().cost);
     MsgDispatcher.SendMsg((int)MessageType.CastCard);
     // 从卡牌中移除当前手牌
     RemoveCardToCd(_currentSelectingPos);
     _currentSelectingPos  = -1;
     _currentSelectingCard = null;
 }
Esempio n. 10
0
        /// <summary>
        /// 将手牌中的单位牌使用时调用接口,处理CardManager内事务并发送卡牌变动信息,不直接冷却卡牌
        /// </summary>
        /// <param name="cardInstance">要移除的手牌的下标</param>
        public void RemoveCardToMapList(GameObject cardInstance)
        {
            // 调用接口完成所有从手牌中移除需要做的操作
            string cardId = RemoveFromHandCard(cardInstance);

            // 添加到地图上单位卡牌列表
            _cardOnMap.Add(cardId);

            // 发送消息通知手牌发生变动
            MsgDispatcher.SendMsg((int)MessageType.HandcardChange);
        }
Esempio n. 11
0
        /// <summary>
        /// 从手牌中移除卡牌(默认进行冷却),处理CardManager内事务后发出手牌变动消息,用于外界通知CardManager手牌发生变动
        /// </summary>
        /// <param name="cardInstance">要一处的卡牌的实例,函数内会进行检验</param>
        /// <param name="controlCd">控制cd值为-1表示按卡牌本身cd值进行冷却,否则按设定值进行冷却</param>
        public void RemoveCardToCd(GameObject cardInstance, int controlCd = -1)
        {
            // 调用接口完成所有从手牌中移除需要做的操作
            string cardId = RemoveFromHandCard(cardInstance);

            // 将其加入冷却列表进行冷却,传递控制冷却信息
            CooldownCard(cardId, controlCd);

            // 发送手牌变动消息
            MsgDispatcher.SendMsg((int)MessageType.HandcardChange);
        }
Esempio n. 12
0
        /// <summary>
        /// 如果伤害请求优先级相同,则伤害判定流程会特殊一些
        /// </summary>
        public void ExcuteSameTime()
        {
            //CheckWhosTurn(_attacker, _attackedUnit);

            Damage.TakeDamage(_attackedUnit, Damage.GetDamage(_attacker));
            this.SetInjurer(_attackedUnit); this.SetInjuredUnit(_attacker);
            MsgDispatcher.SendMsg((int)MessageType.Damage);
            MsgDispatcher.SendMsg((int)MessageType.BeDamaged);

            Damage.TakeDamage(_attacker, Damage.GetDamage(_attackedUnit));
            this.SetInjurer(_attacker); this.SetInjuredUnit(_attackedUnit);
            MsgDispatcher.SendMsg((int)MessageType.Damage);
            MsgDispatcher.SendMsg((int)MessageType.BeDamaged);

            //两次只有attacker是player的时候触发记录
            Gameplay.Instance().autoController.RecordedHatred(_attacker, _attackedUnit);
            Gameplay.Instance().autoController.RecordedHatred(_attackedUnit, _attacker);
            if (_attacker.IsDead())
            {
                this.SetKiller(_attackedUnit); this.SetKilledAndDeadUnit(_attacker);

                //死亡单位回收到对象池
                Gameplay.Instance().gamePlayInput.UnitBackPool(_attacker);

                //删除对应controller中的死亡单位
                Gameplay.Instance().autoController.UpdateAllHatredList();

                MsgDispatcher.SendMsg((int)MessageType.Kill);
                MsgDispatcher.SendMsg((int)MessageType.Dead);
            }
            else
            {
                Gameplay.Instance().gamePlayInput.UpdateHp(_attacker);
            }

            if (_attackedUnit.IsDead())
            {
                this.SetKiller(_attacker); this.SetKilledAndDeadUnit(_attackedUnit);
                //死亡单位回收到对象池
                Gameplay.Instance().gamePlayInput.UnitBackPool(_attackedUnit);

                //删除对应controller中的死亡单位
                Gameplay.Instance().autoController.UpdateAllHatredList();

                MsgDispatcher.SendMsg((int)MessageType.Kill);
                MsgDispatcher.SendMsg((int)MessageType.Dead);
            }
            else
            {
                Gameplay.Instance().gamePlayInput.UpdateHp(_attackedUnit);
            }
        }
Esempio n. 13
0
        public override void Enter(RoundProcessController roundProcessController)
        {
            base.Enter(roundProcessController);
            MsgDispatcher.SendMsg((int)MessageType.Prepare);

            foreach (GameUnit.GameUnit unit in BattleMap.BattleMap.Instance().UnitsList)
            {
                if (unit.owner == GameUnit.OwnerEnum.Player)
                {
                    unit.restrain = false;
                    unit.disarm   = false;
                }
            }
        }
Esempio n. 14
0
        /// <summary>
        /// 随机洗牌函数,产生卡牌堆变动消息
        /// </summary>
        public void Shuffle()
        {
            int size = _cardsSets.Count;

            for (int i = 0; i < size; i++)
            {
                int    pos  = Random.Range(0, size);
                string temp = _cardsSets[i];
                _cardsSets[i]   = _cardsSets[pos];
                _cardsSets[pos] = temp;
            }
            // 发送卡牌堆变动消息
            MsgDispatcher.SendMsg((int)MessageType.CardsetChange);
        }
Esempio n. 15
0
        /// <summary>
        /// 用于将手牌中的卡牌移回抽牌牌库,产生牌堆变动、手牌变动消息
        /// </summary>
        /// <param name="cardIndex">要移除的卡牌在手牌中的位置</param>
        /// <exception cref="NotImplementedException">若下标位置异常则抛出异常</exception>
        public void MoveBackToCardSets(int cardIndex)
        {
            // 调用接口完成所有从手牌中移除需要做的操作
            string cardId = RemoveFromHandCard(cardIndex);

            // 将其加入cardSets
            _cardsSets.Add(cardId);

            // 发送牌堆变动消息
            MsgDispatcher.SendMsg((int)MessageType.CardsetChange);

            // 发送手牌变动消息
            MsgDispatcher.SendMsg((int)MessageType.HandcardChange);
        }
Esempio n. 16
0
        //一格一格移动
        public IEnumerator moveStepByStep(Unit unit)
        {
            #region 测试一哈 先固定(0.0)为灼烧块,(0.1)为粘滞块
            List <Vector2> vector2s = new List <Vector2>();
            vector2s.Add(new Vector2(0, 0));
            BattleMap.Instance().debuffBM.SetBattleMapBlockBurning(vector2s);
            List <Vector2> vector22s = new List <Vector2>();
            vector22s.Add(new Vector2(1, 1));
            BattleMap.Instance().debuffBM.SetBattleMapBlockRetrad(vector22s);
            #endregion

            Vector2        tempVector;
            BattleMapBlock battleMap;
            for (int i = paths.Count - 2; i >= 0; i--)
            {
                //移除上一步的地图块儿下面的units_on_me
                tempVector = new Vector2((int)paths[i + 1].position.x, (int)paths[i + 1].position.y);
                battleMap  = BattleMap.Instance().GetSpecificMapBlock(tempVector);
                battleMap.RemoveUnit(unit);
                //添加当前unit到地图块儿下面的units_on_me内
                tempVector = new Vector2((int)paths[i].position.x, (int)paths[i].position.y);
                battleMap  = BattleMap.Instance().GetSpecificMapBlock(tempVector);
                battleMap.AddUnit(unit);
                unit.transform.localPosition = Vector3.zero;

                if (battleMap.blockType == EMapBlockType.Burnning)//如果经过灼烧块
                {
                    BattleMap.Instance().debuffBM.UnitEnterBurning(tempVector);
                }
                else if (battleMap.blockType == EMapBlockType.Retire)//如果经过滞留块
                {
                    BattleMap.Instance().debuffBM.UnitEnterRetire(unit, battleMap);
                    unit.nextPos = paths[i].position;
                    GamePlay.Gameplay.Instance().bmbColliderManager.Fresh(unit);
                    break;
                }
                unit.nextPos = paths[i].position;
                GamePlay.Gameplay.Instance().bmbColliderManager.Fresh(unit);
                MsgDispatcher.SendMsg((int)MessageType.Move);
                yield return(new WaitForSeconds(0.2f));
            }
            unit.restrain = true;
            MsgDispatcher.SendMsg((int)MessageType.Aftermove);
        }
Esempio n. 17
0
        /// <summary>
        /// 从牌组中抽取卡牌到手牌中
        /// </summary>
        /// <param name="cardAmount">抽取卡牌数量,默认为一</param>
        public void ExtractCards(int cardAmount = 1)
        {
            // 若手牌数量大于或等于手牌上限,直接返回(取消检查的话则此判定永false)
            if (_handcards.Count >= cardsUpperLimit && !cancelCheck)
            {
                return;
            }

            // 根据参数确定抽取卡牌的数量,若和抽牌上限一致则使用抽牌上限,否则使用给定参数
            int extractAmount = (cardAmount == extractCardsUpperLimit) ? extractCardsUpperLimit : cardAmount;

            // 计算应该抽取的卡牌数,计算规则:不检查=抽cardAmount张, 检查=不超出手牌数量上限的,最多cardAmount张牌
            extractAmount = cancelCheck ? extractAmount :
                            (cardsUpperLimit - _handcards.Count > extractAmount ?
                             extractAmount : cardsUpperLimit - _handcards.Count);

            // 如果剩余牌量不足,有多少抽多少(几乎不可能)
            if (extractAmount > _cardsSets.Count)
            {
                extractAmount = _cardsSets.Count;
            }


            // 按照序列抽取卡牌
            for (int i = 0; i < extractAmount; i++)
            {
                // 获得对应卡牌的id
                string cardId = _cardsSets[i];

                // 将其从卡牌堆中移除
                _cardsSets.RemoveAt(i);

                // 调用接口完成向手牌中插入卡牌操作,设置不发送消息,由后续发生消息
                InsertIntoHandCard(cardId, false);
            }

            // 发送手牌变动消息
            MsgDispatcher.SendMsg((int)MessageType.HandcardChange);
            // 发送牌堆变化消息
            MsgDispatcher.SendMsg((int)MessageType.CardsetChange);
        }
Esempio n. 18
0
    public override void Excute()
    {
        MsgDispatcher.SendMsg((int)TriggerType.AnnounceAttack);
        //根据伤害优先级对伤害请求排序
        DamageRequestList = DamageRequest.CaculateDamageRequestList(_Attacker, _AttackedUnit);

        for (int i = 0; i < DamageRequestList.Count; i++)
        {
            //优先级相同并且两方互打的伤害请求作为同时处理
            if (i != DamageRequestList.Count - 1 && DamageRequestList[i].priority == DamageRequestList[i + 1].priority &&
                DamageRequestList[i]._attacker == DamageRequestList[i + 1]._attackedUnit &&
                DamageRequestList[i]._attackedUnit == DamageRequestList[i + 1]._attacker)
            {
                DamageRequestList[i].ExcuteSameTime();
                i++;
            }
            else
            {
                DamageRequestList[i].Excute();
            }
        }
    }
Esempio n. 19
0
        /// <summary>
        /// 单次伤害请求计算
        /// </summary>
        public void Excute()
        {
            //TODO 如果单位死亡则不能反击
            Damage.TakeDamage(_attackedUnit, Damage.GetDamage(_attacker));
            this.SetInjurer(_attacker); this.SetInjuredUnit(_attackedUnit);
            MsgDispatcher.SendMsg((int)MessageType.Damage);
            MsgDispatcher.SendMsg((int)MessageType.BeDamaged);

            /*  TODO 时点处理
             *  BeAttacked,
             *  Damage,
             *  BeDamaged,
             *  Kill,
             *  BeKilled,
             *  Dead,
             *  ToBeKilled,
             */

            //只会执行_attacker为play的情况
            Gameplay.Instance().autoController.RecordedHatred(_attacker, _attackedUnit);
            if (_attackedUnit.IsDead())
            {
                this.SetKiller(_attacker);
                this.SetKilledAndDeadUnit(_attackedUnit);
                //死亡单位回收到对象池
                Gameplay.Instance().gamePlayInput.UnitBackPool(_attackedUnit);

                //删除对应controller中的死亡单位
                Gameplay.Instance().autoController.UpdateAllHatredList();

                MsgDispatcher.SendMsg((int)MessageType.Kill);
                MsgDispatcher.SendMsg((int)MessageType.Dead);
            }
            else
            {
                Gameplay.Instance().gamePlayInput.UpdateHp(_attackedUnit);
            }
        }
Esempio n. 20
0
 public override void Enter(RoundProcessController roundProcessController)
 {
     base.Enter(roundProcessController);
     MsgDispatcher.SendMsg((int)MessageType.LOSE);
 }
Esempio n. 21
0
 /// <summary>
 /// 退出状态时发送主要阶段结束消息
 /// </summary>
 /// <param name="roundProcessController"></param>
 public override void Exit(RoundProcessController roundProcessController)
 {
     base.Exit(roundProcessController);
     MsgDispatcher.SendMsg((int)MessageType.MPEnd);
 }
Esempio n. 22
0
 public override void Enter(RoundProcessController roundProcessController)
 {
     base.NextState(roundProcessController);
     // 发送更新资源点消息
     MsgDispatcher.SendMsg((int)MessageType.UpdateSource);
 }