Exemplo n.º 1
0
 /// <summary>
 /// 決定可否瞬間移動,可以則transportPos為瞬間移動後的位置
 /// </summary>
 /// <param name="creature">生物種類</param>
 /// <param name="pos">位置</param>
 /// <param name="transportPos">瞬間移動後位置</param>
 public bool CanTransport(Creature creature, IVector2 pos, out IVector2 transportPos)
 {
     transportPos = pos.Clone();
     if (!CheckPosLegal(pos))
     {
         return(false);
     }
     if (creature != Creature.Scarab || allMapBlock[pos.x][pos.y].MapBlockType != BlockType.Hole)
     {
         return(false);
     }
     if (holePos == null || !holePos.ContainsKey(pos.DataToUInt()))
     {
         return(false);
     }
     else
     {
         transportPos = holePos[pos.DataToUInt()].Clone();
         if (!CheckPosLegal(transportPos))
         {
             return(false);
         }
         if (allMapBlock[transportPos.x][transportPos.y].LivingObject != Creature.None)
         {
             return(false);
         }
         else
         {
             return(true);
         }
     }
 }
Exemplo n.º 2
0
    protected override void CheckSettings()
    {
        base.CheckSettings();

        if (!gridXY.Equals(gridXY_) || !cellXY.Equals(cellXY_) || lineThickness_ != _lineThickness ||
            innerHorizontal != innerHorizontal_ || innerVertical != innerVertical_ ||
            outerHorizontal != outerHorizontal_ || outerVertical != outerVertical_)
        {
            if (_gridXY.x < 1)
            {
                _gridXY.x = 1;
            }
            if (_gridXY.y < 1)
            {
                _gridXY.y = 1;
            }
            gridXY_ = _gridXY.Clone();

            if (_cellXY.x <= 0)
            {
                _cellXY.x = 1f;
            }
            if (_cellXY.y < 1)
            {
                _cellXY.y = 1;
            }
            cellXY_ = _cellXY;

            if (_lineThickness <= 0)
            {
                _lineThickness = 1;
            }
            lineThickness_ = _lineThickness;

            innerHorizontal_ = innerHorizontal;
            innerVertical_   = innerVertical;
            outerHorizontal_ = outerHorizontal;
            outerVertical_   = outerVertical;


            meshDirty = true;
        }
    }
Exemplo n.º 3
0
    /// <summary>
    /// 處理移動(檢查都通過時的處理)
    /// </summary>
    /// <param name="start">玩家決定的移動起點</para>
    /// <param name="end">玩家決定的移動終點</param>
    /// <param name="realEnd">實際的移動終點</param>
    /// <param name="infectPositions">感染的座標範圍</param>
    public MoveType Move(IVector2 start, IVector2 end, out IVector2 realEnd, out List <IVector2> infectPositions)
    {
        MoveType moveType = MoveType.Move;

        realEnd         = end.Clone();
        infectPositions = new List <IVector2>();
        Creature creature = map.GetCreature(start); // 取得要移動的生物

        if (creature == Creature.None)
        {
            return(MoveType.None);
        }
        if (creature == Creature.People)
        {
            map.SetCreature(realEnd, creature);
            // 由於是合法移動,不是差一就二
            if (Mathf.Abs(realEnd.x - start.x) == 1 || Mathf.Abs(realEnd.y - start.y) == 1)
            {
                moveType = MoveType.Clone;
            }
            else
            {
                map.SetCreature(start, Creature.None);                 // 跳耀,所以要刪除原本的
            }
            //感染
            foreach (IVector2 neiDir in neighborDir)
            {
                IVector2 neighbor = new IVector2(realEnd.x + neiDir.x, realEnd.y + neiDir.y);
                if (!neighbor.Equals(start))                 // 起點不受影響
                {
                    bool infectSuccess = map.Infect(neighbor, creature);
                    if (infectSuccess)
                    {
                        infectPositions.Add(neighbor);
                    }
                }
            }
        }
        else if (creature == Creature.Scarab)
        {
            IVector2 transportPos;
            bool     isTransPort = map.CanTransport(creature, end, out transportPos);
            if (isTransPort)             // 瞬間移動,原本的必定砍掉
            {
                map.SetCreature(start, Creature.None);
                realEnd = transportPos.Clone();
            }
            else
            {
                // 由於是合法移動,不是差一就二
                if (Mathf.Abs(realEnd.x - start.x) == 1 || Mathf.Abs(realEnd.y - start.y) == 1)
                {
                    moveType = MoveType.Clone;
                }
                else
                {
                    map.SetCreature(start, Creature.None);                     // 跳耀,所以要刪除原本的
                }
            }
            map.SetCreature(realEnd, creature);
            //感染
            foreach (IVector2 neiDir in neighborDir)
            {
                IVector2 neighbor = new IVector2(realEnd.x + neiDir.x, realEnd.y + neiDir.y);
                if (!neighbor.Equals(start))                 // 起點不受影響
                {
                    bool infectSuccess = map.Infect(neighbor, creature);
                    if (infectSuccess)
                    {
                        infectPositions.Add(neighbor);
                    }
                }
            }
        }
        // TODO: 優化能夠移動到的地點相關的處理
        map.RecheckAllCanMove();

        return(moveType);
    }