Example #1
0
    private void BattleAction_SelectWeapon(WeaponItem item)
    {
        battleManager.ChangeState(BattleManager.EBattleState.SelectTarget);
        if (item == null)
        {
            Debug.LogError("选择的武器是null");
        }
        else
        {
            Debug.Log(item.ToString());
        }
        BattleActionMenu.Hide();
        BattleSelectWeaponMenu.Hide();
        CharacterLogic logic = battleManager.CurrentCharacterLogic;

        logic.Info.Items.EquipWeapon(item);
        //从选择的武器确定
        var rangeType = item.GetDefinition().RangeType;
        EnumSelectEffectRangeType selRangeType = rangeType.SelectType;
        Vector2Int selRange = rangeType.SelectRange;
        EnumSelectEffectRangeType effRangeType = rangeType.EffectType;
        Vector2Int effRange = rangeType.EffectRange;

        logic.BattleInfo.SetSelectTargetParam(CharacterBattleInfo.EBattleActionType.Attack, logic.GetTileCoord(), selRangeType, selRange, effRangeType, effRange);
        battleManager.ShowSelectTargetRangeAction(logic);
        MenuUndoAction.Push(UndoSelectWeapon);
    }
Example #2
0
 public void SetSelectTargetParam(EBattleActionType actionType, Vector2Int selfPos, EnumSelectEffectRangeType selRangeType, Vector2Int selRange, EnumSelectEffectRangeType effRangeType, Vector2Int effRange)
 {
     battleActionType   = actionType;
     selfTilePos        = selfPos;
     selectRangeType    = selRangeType;
     effectRangeType    = effRangeType;
     selectRange        = selRange;
     effectRange        = effRange;
     targetChooseRanges = GetTargetSelectRange(selfTilePos, selRangeType, selectRange);
 }
Example #3
0
    public void InitActionScope(RPGCharacter Gamechar, int Movement, bool Show = true)
    {
        HideAllRange();
        bPlayer = (Gamechar.GetCamp() == EnumCharacterCamp.Player);//0,2为我方的单位

        _Mov = Movement;

        /* if (Gamechar.SkillGroup.isHaveStaticSkill(18))//探险家,无视地形,将其职业设为天马
         *   _Job = 15;//medifyneed
         * if (Gamechar.SkillGroup.isHaveStaticSkill(19))
         *   _Mov += 2;*/
        _Career         = Gamechar.Logic.GetCareer();
        CharacterCenter = new Vector2Int(Gamechar.GetTileCoord().x, Gamechar.GetTileCoord().x);

        ResetMoveAcessList();
        bMoveAcessList[CharacterCenter.x, CharacterCenter.y]         = true;
        bMoveAcessListExcluded[CharacterCenter.x, CharacterCenter.y] = true;
        _FootData.Add(CharacterCenter, new Vector2Int(-1, -1));
        _TempFootData.Add(CharacterCenter, _Mov);

        int countPoint = 0;

        while (countPoint < _Mov)
        {
            _FindDistance(Gamechar.Logic.GetCareer(), _Mov);//递归查询距离   _FindDistance(Table._JobTable.getBranch(gamechar.attribute.Job), _Mov, 0, 0);
            countPoint++;
        }

        WeaponItem item = Gamechar.Logic.Info.Items.GetEquipWeapon();

        item = new WeaponItem(1);
        if (item != null)//装备武器不为空
        {
            _AttackRangeData.Clear();
            _ItemRangeMin    = item.GetDefinition().RangeType.SelectRange.x;
            _ItemRangeMax    = item.GetDefinition().RangeType.SelectRange.y;
            _WeaponRangeType = item.GetDefinition().RangeType.SelectType;
            if (_ItemRangeMax != 0 && _ItemRangeMax - _ItemRangeMin > -1) //武器有距离
            {
                for (int i = 0; i < PList.Count; i++)                     //遍历可移动的区域
                {
                    AttackScan(PList[i]);                                 //递归查询距离   _FindDistance(Table._JobTable.getBranch(gamechar.attribute.Job), _Mov, 0, 0);
                }
            }
        }

        if (Show)
        {
            ShowMoveableRange();
            ShowAttackableRange();
        }
    }
Example #4
0
        protected virtual void EquipWeapon(CharacterLogic target)
        {
            var weapons = logic.Info.Items.GetAllWeapons();

            if (weapons.Count <= 1)
            {
                return;
            }
            List <WeaponItem> avWeapons = new List <WeaponItem>();

            foreach (var v in weapons)
            {
                //找到每个武器可以攻击到的范围内的敌方单位

                var rangeType = v.GetDefinition().RangeType;
                EnumSelectEffectRangeType selRangeType = rangeType.SelectType;
                Vector2Int selRange = rangeType.SelectRange;
                EnumSelectEffectRangeType effRangeType = rangeType.EffectType;
                Vector2Int effRange = rangeType.EffectRange;
                logic.BattleInfo.SetSelectTargetParam(CharacterBattleInfo.EBattleActionType.Attack, logic.GetTileCoord(), selRangeType, selRange, effRangeType, effRange);
                if (logic.BattleInfo.TargetChooseRanges.Contains(target.GetTileCoord()))
                {
                    avWeapons.Add(v);
                }
            }
            List <int> damage = new List <int>();

            //根据对方的属性选择伤害最高的武器
            foreach (var v in weapons)
            {
                logic.Info.Items.EquipWeapon(v);
                int dmg = BattleLogic.GetAttackCount(logic, target) * BattleLogic.GetAttackDamage(logic, target);
                damage.Add(dmg);
            }
            int maxDamageIndex = LinqS.IndexOfMax(damage.GetEnumerator());

            logic.Info.Items.EquipWeapon(avWeapons[maxDamageIndex]);
        }
Example #5
0
    public static void InitAttackScope(Vector2Int pos, List <WeaponItem> weapons)
    {
        ResetMoveAcessList();
        _AttackRangeData.Clear();
        foreach (var v in weapons)
        {
            var def = v.GetDefinition();
            _CharacterCenter = pos;
            var atkRange = def.RangeType.SelectRange;

            if (atkRange.x > 0 && atkRange.y > 0)//装备武器不为空
            {
                _ItemRangeMin    = atkRange.x;
                _ItemRangeMax    = atkRange.y;
                _WeaponRangeType = def.RangeType.SelectType;
                if (_ItemRangeMax != 0 && _ItemRangeMax - _ItemRangeMin > -1)//武器有距离
                {
                    AttackScan(_CharacterCenter);
                }
            }
        }
        MoveAcessListToAttackRange();
    }
Example #6
0
    public static void InitActionScope(EnumCharacterCamp camp, EnumMoveClassType moveClass, int Movement, Vector2Int pos, EnumSelectEffectRangeType weaponRangeType, Vector2Int atkRange)
    {
        _bPlayer         = (camp != EnumCharacterCamp.Enemy);//0,2为我方的单位
        _Mov             = Movement;
        _MoveClass       = moveClass;
        _CharacterCenter = pos;

        ResetMoveAcessList();
        _bMoveAcessList[_CharacterCenter.x, _CharacterCenter.y]         = true;
        _bMoveAcessListExcluded[_CharacterCenter.x, _CharacterCenter.y] = true;
        _FootData.Add(_CharacterCenter, new Vector2Int(-1, -1));
        _TempFootData.Add(_CharacterCenter, _Mov);

        int countPoint = 0;

        while (countPoint < _Mov)
        {
            _FindDistance(_Mov);//递归查询距离   _FindDistance(Table._JobTable.getBranch(gamechar.attribute.Job), _Mov, 0, 0);
            countPoint++;
        }
        if (atkRange.x > 0 && atkRange.y > 0)//装备武器不为空
        {
            _AttackRangeData.Clear();
            _ItemRangeMin    = atkRange.x;
            _ItemRangeMax    = atkRange.y;
            _WeaponRangeType = weaponRangeType;
            if (_ItemRangeMax != 0 && _ItemRangeMax - _ItemRangeMin > -1) //武器有距离
            {
                for (int i = 0; i < _PList.Count; i++)                    //遍历可移动的区域
                {
                    AttackScan(_PList[i]);                                //递归查询距离   _FindDistance(Table._JobTable.getBranch(gamechar.attribute.Job), _Mov, 0, 0);
                }
            }
            MoveAcessListToAttackRange();
        }
    }
Example #7
0
    public List <Vector2Int> FindAttackRange(int x, int y, WeaponDef EquipItem, bool bShow = true)//指定的坐标
    {
        _AttackRangeData.Clear();
        _ItemRangeMin = EquipItem.RangeType.SelectRange.x;
        _ItemRangeMax = EquipItem.RangeType.SelectRange.y;
        EnumSelectEffectRangeType rangeType = EquipItem.RangeType.SelectType;

        if (_ItemRangeMin > 1)
        {
            int left   = (x - _ItemRangeMax) < 0 ? 0 : x - _ItemRangeMax;
            int right  = (x + _ItemRangeMax) > TileWidth - 1 ? TileWidth - 1 : x + _ItemRangeMax;
            int up     = (y - _ItemRangeMax < 0) ? 0 : y - _ItemRangeMax;
            int bottom = (y + _ItemRangeMax) > TileHeight - 1 ? TileHeight - 1 : y + _ItemRangeMax;
            if (rangeType == 0)
            {
                for (int i = left; i <= right; i++)
                {
                    for (int j = up; j <= bottom; j++)
                    {
                        int absLen = Mathf.Abs(i - x) + Mathf.Abs(j - y);
                        if (absLen < _ItemRangeMin || absLen > _ItemRangeMax || _AttackRangeData.Contains(new Vector2Int(i, j)))
                        {
                            continue;
                        }
                        _AttackRangeData.Add(new Vector2Int(i, j));
                    }
                }
            }
            if (rangeType == EnumSelectEffectRangeType.十字形) //为1则是只能上下左右寻找目标
            {
                for (int i = left; i <= right; i++)         //得到x轴上所有的范围
                {
                    int absLen = Mathf.Abs(i - x);
                    if (absLen < _ItemRangeMin || absLen > _ItemRangeMax || _AttackRangeData.Contains(new Vector2Int(i, y)))
                    {
                        continue;
                    }
                    _AttackRangeData.Add(new Vector2Int(i, y));
                }
                for (int i = up; i <= bottom; i++)//得到y轴上所有的范围
                {
                    int absLen = Mathf.Abs(i - y);
                    if (absLen < _ItemRangeMin || absLen > _ItemRangeMax || _AttackRangeData.Contains(new Vector2Int(x, i)))
                    {
                        continue;
                    }
                    _AttackRangeData.Add(new Vector2Int(x, i));
                }
            }
            if (rangeType == EnumSelectEffectRangeType.正方形)//为2矩形攻击范围
            {
                for (int i = left; i <= right; i++)
                {
                    for (int j = up; j <= bottom; j++)
                    {
                        int absX = Mathf.Abs(i - x);
                        int absY = Mathf.Abs(j - y);
                        if (absX < _ItemRangeMin && absY < _ItemRangeMin)//在其中xy均小于最小坐标的不符合,直接进行下一个循环
                        {
                            continue;
                        }
                        _AttackRangeData.Add(new Vector2Int(i, j));
                    }
                }
            }

            /* if (rangeType == 3)//全屏攻击。放到外面单独处理,暂时用不到
             * {
             *   for (int i = 0; i < mapTileX; i++)
             *   {
             *       for (int j = 0; j < mapTileX; j++)
             *       {
             *           _AttackRangeData.Add(new Point2D(i, j));
             *       }
             *   }
             * }*/
        }
        else //如果是最小攻击距离从1开始
        {
            for (int i = -_ItemRangeMax; i <= _ItemRangeMax; i++)
            {
                for (int j = -_ItemRangeMax; j <= _ItemRangeMax; j++)
                {
                    switch (rangeType)
                    {
                    case EnumSelectEffectRangeType.菱形:
                        if (Math.Abs(i) + Math.Abs(j) > _ItemRangeMax)
                        {
                            continue;
                        }
                        break;

                    case EnumSelectEffectRangeType.十字形:
                        if (Math.Abs(i) != 0 && Math.Abs(j) != 0)
                        {
                            continue;
                        }
                        break;

                    case EnumSelectEffectRangeType.正方形:
                        break;
                    }
                    _AttackRangeData.Add(new Vector2Int(i + x, j + y));
                }
            }
            _AttackRangeData.Remove(new Vector2Int(x, y));
        }
        if (bShow)
        {
            ShowAttackableRange();
        }
        return(_AttackRangeData);
    }
Example #8
0
    public List <Vector2Int> FindAttackRangeWithoutShow(RPGCharacter Gamechar)//查找所有的武器所能攻击的范围
    {
        _AttackRangeData.Clear();
        int x = Gamechar.GetTileCoord().x;
        int y = Gamechar.GetTileCoord().y;
        List <WeaponItem> items = Gamechar.Logic.Info.Items.GetAttackWeapon();

        foreach (WeaponItem item in items)
        {
            _ItemRangeMin = item.GetDefinition().RangeType.SelectRange.x;
            _ItemRangeMax = item.GetDefinition().RangeType.SelectRange.y;
            EnumSelectEffectRangeType rangeType = item.GetDefinition().RangeType.SelectType;

            int left   = (x - _ItemRangeMax) < 0 ? 0 : x - _ItemRangeMax;
            int right  = (x + _ItemRangeMax) > TileWidth - 1 ? TileWidth - 1 : x + _ItemRangeMax;
            int up     = (y - _ItemRangeMax < 0) ? 0 : y - _ItemRangeMax;
            int bottom = (y + _ItemRangeMax) > TileHeight - 1 ? TileHeight - 1 : y + _ItemRangeMax;
            if (rangeType == EnumSelectEffectRangeType.菱形)
            {
                for (int i = left; i <= right; i++)
                {
                    for (int j = up; j <= bottom; j++)
                    {
                        int absLen = Mathf.Abs(i - x) + Mathf.Abs(j - y);
                        if (absLen < _ItemRangeMin || absLen > _ItemRangeMax)
                        {
                            continue;
                        }
                        Vector2Int p = new Vector2Int(i, j);
                        if (_AttackRangeData.Contains(p))
                        {
                            continue;
                        }
                        _AttackRangeData.Add(p);
                    }
                }
            }
            if (rangeType == EnumSelectEffectRangeType.十字形) //为1则是只能上下左右寻找目标
            {
                for (int i = left; i <= right; i++)         //得到x轴上所有的范围
                {
                    int absLen = Mathf.Abs(i - x);

                    if (absLen < _ItemRangeMin || absLen > _ItemRangeMax)
                    {
                        continue;
                    }
                    Vector2Int p = new Vector2Int(i, y);
                    if (_AttackRangeData.Contains(p))
                    {
                        continue;
                    }
                    _AttackRangeData.Add(p);
                }
                for (int i = up; i <= bottom; i++)//得到y轴上所有的范围
                {
                    int absLen = Mathf.Abs(i - y);

                    if (absLen < _ItemRangeMin || absLen > _ItemRangeMax)
                    {
                        continue;
                    }
                    Vector2Int p = new Vector2Int(x, i);
                    if (_AttackRangeData.Contains(p))
                    {
                        continue;
                    }
                    _AttackRangeData.Add(p);
                }
            }
        }
        return(_AttackRangeData);
    }
Example #9
0
    public static List <Vector2Int> GetTargetSelectRange(Vector2Int pos, EnumSelectEffectRangeType rangeType, Vector2Int range)
    {
        List <Vector2Int> attackArea = new List <Vector2Int>();
        int x          = pos.x;
        int y          = pos.y;
        int TileWidth  = PositionMath.TileWidth;
        int TileHeight = PositionMath.TileHeight;

        attackArea.Clear();

        var RangeMax = range.y;
        var RangeMin = range.x;

        UnityEngine.Assertions.Assert.IsTrue(RangeMax >= RangeMin);

        if (RangeMin > 1)
        {
            int left   = (x - RangeMax) < 0 ? 0 : x - RangeMax;
            int right  = (x + RangeMax) > TileWidth - 1 ? TileWidth - 1 : x + RangeMax;
            int up     = (y - RangeMax < 0) ? 0 : y - RangeMax;
            int bottom = (y + RangeMax) > TileHeight - 1 ? TileHeight - 1 : y + RangeMax;
            if (rangeType == EnumSelectEffectRangeType.菱形)
            {
                for (int i = left; i <= right; i++)
                {
                    for (int j = up; j <= bottom; j++)
                    {
                        int absLen = Mathf.Abs(i - x) + Mathf.Abs(j - y);
                        if (absLen < RangeMin || absLen > RangeMax || attackArea.Contains(new Vector2Int(i, j)))
                        {
                            continue;
                        }
                        if (i >= 0 && j >= 0)
                        {
                            attackArea.Add(new Vector2Int(i, j));
                        }
                    }
                }
            }
            if (rangeType == EnumSelectEffectRangeType.十字形) //为1则是只能上下左右寻找目标
            {
                for (int i = left; i <= right; i++)         //得到x轴上所有的范围
                {
                    int absLen = Mathf.Abs(i - x);
                    if (absLen < RangeMin || absLen > RangeMax || attackArea.Contains(new Vector2Int(i, y)))
                    {
                        continue;
                    }
                    if (i >= 0 && y >= 0)
                    {
                        attackArea.Add(new Vector2Int(i, y));
                    }
                }
                for (int i = up; i <= bottom; i++)//得到y轴上所有的范围
                {
                    int absLen = Mathf.Abs(i - y);
                    if (absLen < RangeMin || absLen > RangeMax || attackArea.Contains(new Vector2Int(x, i)))
                    {
                        continue;
                    }
                    if (x >= 0 && i >= 0)
                    {
                        attackArea.Add(new Vector2Int(x, i));
                    }
                }
            }
            if (rangeType == EnumSelectEffectRangeType.正方形)//为2矩形攻击范围
            {
                for (int i = left; i <= right; i++)
                {
                    for (int j = up; j <= bottom; j++)
                    {
                        int absX = Mathf.Abs(i - x);
                        int absY = Mathf.Abs(j - y);
                        if (absX < RangeMin && absY < RangeMin)//在其中xy均小于最小坐标的不符合,直接进行下一个循环
                        {
                            continue;
                        }
                        if (i >= 0 && j >= 0)
                        {
                            attackArea.Add(new Vector2Int(i, j));
                        }
                    }
                }
            }
        }
        else //如果是最小攻击距离从1开始
        {
            for (int i = -RangeMax; i <= RangeMax; i++)
            {
                for (int j = -RangeMax; j <= RangeMax; j++)
                {
                    switch (rangeType)
                    {
                    case EnumSelectEffectRangeType.菱形:
                        if (Mathf.Abs(i) + Mathf.Abs(j) > RangeMax)
                        {
                            continue;
                        }
                        break;

                    case EnumSelectEffectRangeType.十字形:
                        if (Mathf.Abs(i) != 0 && Mathf.Abs(j) != 0)
                        {
                            continue;
                        }
                        break;

                    case EnumSelectEffectRangeType.正方形:
                        break;
                    }
                    if (i + x >= 0 && j + y >= 0)
                    {
                        attackArea.Add(new Vector2Int(i + x, j + y));
                    }
                }
            }
            if (RangeMin == 1)
            {
                attackArea.Remove(new Vector2Int(x, y));
            }
        }
        return(attackArea);
    }