Exemplo n.º 1
0
 public void PushToPull(MapObjectBase obj)
 {
     if (_dicSpawnObject.TryGetValue(obj, out obj))
     {
         _dicObjectPool[obj.Name()].Add(obj);
         _dicSpawnObject.Remove(obj);
     }
     else
     {
         obj = null;
     }
 }
Exemplo n.º 2
0
    public void OnLeftClick(int a_XPos, int a_YPos, MapObjectBase a_Object)
    {
        int _Index = a_XPos + a_YPos * m_GameSettings.Scenario.Size;

        if (_Index != m_TargetNodeIndex)
        {
            if (m_PathableArea.ContainsKey(_Index))
            {
                GeneratePath(_Index);
            }
        }
        else if (_Index != -1)
        {
            StartCoroutine(Move());
        }
    }
Exemplo n.º 3
0
        public List <MapObjectBase[, ]> Generate()
        {
            List <MapObjectBase[, ]> maps = new List <MapObjectBase[, ]>();

            foreach (var filler in fillers)
            {
                var map = new MapObjectBase[OsianLogic.LEN_X, OsianLogic.LEN_Y];
                for (int i = 0; i < OsianLogic.LEN_X; i++)
                {
                    for (int j = 0; j < OsianLogic.LEN_Y; j++)
                    {
                        map[i, j] = new EmptyMapObject();
                    }
                }
                filler.Fill(map);
                maps.Add(map);
            }
            return(maps);
        }
Exemplo n.º 4
0
        public void Add(MapObjectBase obj)
        {
            MapElement element;

            if (obj is Node)
            {
                element = new MapElement(Projection, baseTile, correctionVector, (Node)obj);
            }
            else if (obj is Way)
            {
                element = new MapElement(Projection, baseTile, correctionVector, (Way)obj);
            }
            else
            {
                return;
            }
            renderTheme.Match(element);


            byte lastLayer = 0;

            foreach (var layerIndex in layersIndexes)
            {
                lastLayer = layerIndex.Key;
                if (layerIndex.Key > obj.Layer)
                {
                    layersIndexes[obj.Layer]      = layerIndex.Value;
                    layersIndexes[layerIndex.Key] = layerIndex.Value + 1;
                }
            }

            if (lastLayer < obj.Layer)
            {
                layersIndexes[lastLayer] = elements.Count;
                elements.Add(element);
            }
            else
            {
                elements.Insert(0, element);
            }
        }
Exemplo n.º 5
0
    private void Kick(MapObjectBase obj)
    {
        if (obj.Name() != MAPOBJECT_NAME.BOMB)
        {
            return;
        }
        if (_rideType != RIDE_TYPE.NULL)
        {
            return;
        }
        if (_haveKick == false)
        {
            return;
        }

        if (_tempPosition - obj.Position != Vector2.Zero)
        {
            Bomb bomb = obj as Bomb;
            bomb.Direction = _direction;
        }
    }
Exemplo n.º 6
0
        private static MapObjectBase[,] GetMap(IEnumerable <string> mapFileLines, IReadOnlyDictionary <char, MapObjectBase> lookup)
        {
            var mapFile  = GetFileParts("map|", mapFileLines);
            var lines    = mapFile.Split('\n');
            var height   = lines.Length;
            var maxWidth = lines.Select(x => x.Length).OrderByDescending(x => x).FirstOrDefault();

            var outval = new MapObjectBase[maxWidth, height];

            for (int yAxis = 0; yAxis < lines.Length; yAxis++)
            {
                for (int xAxis = 0; xAxis < lines[yAxis].Length; xAxis++)
                {
                    if (lookup.TryGetValue(lines[yAxis][xAxis], out var ob))
                    {
                        outval[xAxis, yAxis] = ob;
                    }
                }
            }

            return(outval);
        }
Exemplo n.º 7
0
 /// <summary>
 /// 서로 상호작용을 해야해서 바로 지우지 않고 임시로 담아둠
 /// </summary>
 /// <param name="obj"></param>
 public void RemoveObjectAdd(MapObjectBase obj)
 {
     _listTempRemoveObject.Add(obj);
 }
Exemplo n.º 8
0
    void Update()
    {
        // If mouse is in the actual map area
        if (Input.mousePosition.x >= GameScreenScaler.VIEWPORT_PADDING_LEFT &&
            Input.mousePosition.y >= GameScreenScaler.VIEWPORT_PADDING_BOTTOM &&
            Input.mousePosition.x <= Screen.width - GameScreenScaler.VIEWPORT_PADDING_RIGHT &&
            Input.mousePosition.y <= Screen.height - GameScreenScaler.VIEWPORT_PADDING_TOP &&
            !m_TownScreen.Enabled)
        {
            Vector3    _WorldMousePos    = m_Camera.ScreenToWorldPoint(Input.mousePosition - new Vector3(0, 8, 0));
            Vector2Int _WorldMouseCoords = new Vector2Int
                                           (
                (int)(_WorldMousePos.x + 0.5f),
                (int)(-_WorldMousePos.y + 0.5f)
                                           );

            // If mouse has moved onto a different tile in the world
            if (m_PreviousWorldMouseCoords != _WorldMouseCoords ||
                m_UpdateCursor)
            {
                // If mouse coords are within the bounds of the map
                if (_WorldMouseCoords.x >= 0 &&
                    _WorldMouseCoords.y >= 0 &&
                    _WorldMouseCoords.x < m_GameSettings.Scenario.Size &&
                    _WorldMouseCoords.y < m_GameSettings.Scenario.Size)
                {
                    m_HoveredTown = null;
                    m_HoveredHero = null;

                    MapHero _SelectedHero = m_LocalOwnership.SelectedHero;

                    m_PreviousWorldMouseCoords = _WorldMouseCoords;
                    m_UpdateCursor             = false;

                    Pathfinding.Node _Node = m_Pathfinding.GetNode(_WorldMouseCoords, false);

                    List <MapObjectBase> _Objects = new List <MapObjectBase>(_Node.BlockingObjects.Count + _Node.InteractionObjects.Count);

                    for (int i = 0; i < _Node.BlockingObjects.Count; i++)
                    {
                        _Objects.Add(_Node.BlockingObjects[i]);
                    }

                    for (int i = 0; i < _Node.InteractionObjects.Count; i++)
                    {
                        _Objects.Add(_Node.InteractionObjects[i]);
                    }

                    // Flag used to break out of logic if an earlier bit of logic has already determined what the cursor should be
                    bool _CursorSelected = false;

                    int _TurnCost = 0;

                    if (_SelectedHero != null)
                    {
                        _TurnCost = _SelectedHero.GetPathingTurnCost(_WorldMouseCoords.x, _WorldMouseCoords.y);
                    }

                    // Check if any of the objects are heroes
                    for (int i = 0; i < _Objects.Count; i++)
                    {
                        MapHero _Hero = _Objects[i] as MapHero;

                        if (_Hero != null)
                        {
                            m_HoveredObject = _Hero;

                            if (_SelectedHero != null)
                            {
                                if (_SelectedHero == _Hero)
                                {
                                    CursorManager.SetCursor(m_HeroCursor, new Vector2(-12, 10));
                                }
                                else if (_Hero.IsPrison)
                                {
                                    switch (_TurnCost)
                                    {
                                    case 0: CursorManager.ResetCursor(); break;

                                    case 1: CursorManager.SetCursor(m_InteractCursor, new Vector2(-14, 15)); break;

                                    case 2: CursorManager.SetCursor(m_InteractCursor2, new Vector2(-14, 15)); break;

                                    case 3: CursorManager.SetCursor(m_InteractCursor3, new Vector2(-14, 15)); break;

                                    default: CursorManager.SetCursor(m_InteractCursor4, new Vector2(-14, 15)); break;
                                    }
                                }
                                else if (_Hero.PlayerIndex == m_GameSettings.LocalPlayerIndex)
                                {
                                    switch (_TurnCost)
                                    {
                                    case 0: CursorManager.ResetCursor(); break;

                                    case 1: CursorManager.SetCursor(m_TradeCursor, new Vector2(-8, 9)); break;

                                    case 2: CursorManager.SetCursor(m_TradeCursor2, new Vector2(-8, 9)); break;

                                    case 3: CursorManager.SetCursor(m_TradeCursor3, new Vector2(-8, 9)); break;

                                    default: CursorManager.SetCursor(m_TradeCursor4, new Vector2(-8, 9)); break;
                                    }
                                }
                                else
                                {
                                    switch (_TurnCost)
                                    {
                                    case 0: CursorManager.ResetCursor(); break;

                                    case 1: CursorManager.SetCursor(m_AttackCursor, new Vector2(-13, 13)); break;

                                    case 2: CursorManager.SetCursor(m_AttackCursor2, new Vector2(-13, 13)); break;

                                    case 3: CursorManager.SetCursor(m_AttackCursor3, new Vector2(-13, 13)); break;

                                    default: CursorManager.SetCursor(m_AttackCursor4, new Vector2(-13, 13)); break;
                                    }
                                }

                                _CursorSelected = true;
                            }
                            else if (!_Hero.IsPrison &&
                                     _Hero.PlayerIndex == m_GameSettings.LocalPlayerIndex)
                            {
                                CursorManager.SetCursor(m_HeroCursor, new Vector2(-12, 10));
                                m_HoveredHero = _Hero;

                                _CursorSelected = true;
                            }

                            break;
                        }
                    }

                    // Check if any of the objects are towns
                    if (!_CursorSelected)
                    {
                        for (int i = 0; i < _Objects.Count; i++)
                        {
                            MapTown _Town = _Objects[i] as MapTown;

                            if (_Town != null)
                            {
                                m_HoveredObject = _Objects[i];

                                int _XIndex = 8 - Mathf.Clamp(Mathf.CeilToInt(_Objects[i].transform.position.x - _WorldMousePos.x), 0, 7);
                                int _YIndex = 6 - Mathf.Clamp(Mathf.CeilToInt(_WorldMousePos.y - _Objects[i].transform.position.y), 0, 5);

                                // If the cursor is specifically on the castle's entrance, horse rear cursor
                                if (_SelectedHero != null &&
                                    _XIndex == 5 &&
                                    _YIndex == 5)
                                {
                                    switch (_TurnCost)
                                    {
                                    case 0: CursorManager.ResetCursor(); break;

                                    case 1: CursorManager.SetCursor(m_InteractCursor, new Vector2(-14, 15)); break;

                                    case 2: CursorManager.SetCursor(m_InteractCursor2, new Vector2(-14, 15)); break;

                                    case 3: CursorManager.SetCursor(m_InteractCursor3, new Vector2(-14, 15)); break;

                                    default: CursorManager.SetCursor(m_InteractCursor4, new Vector2(-14, 15)); break;
                                    }
                                }
                                else if (_Town.PlayerIndex == m_GameSettings.LocalPlayerIndex)
                                {
                                    CursorManager.SetCursor(m_CastleCursor, new Vector2(-12, 12));
                                    m_HoveredTown = _Town;
                                }
                                else
                                {
                                    CursorManager.ResetCursor();
                                }

                                _CursorSelected = true;

                                break;
                            }
                        }
                    }

                    // If a hero is currently selected, set movement cursor
                    if (_SelectedHero != null)
                    {
                        if (!_CursorSelected)
                        {
                            // If the mouse is on an interaction tile, horse rear cursor
                            if (_Objects.Count > 0)
                            {
                                int _XIndex = 8 - Mathf.Clamp(Mathf.CeilToInt(_Objects[0].transform.position.x - _WorldMousePos.x), 0, 7);
                                int _YIndex = 6 - Mathf.Clamp(Mathf.CeilToInt(_WorldMousePos.y - _Objects[0].transform.position.y), 0, 5);

                                if ((_Objects[0].InteractionCollision[_YIndex] & 1 << _XIndex) != 0)
                                {
                                    switch (_TurnCost)
                                    {
                                    case 0: CursorManager.ResetCursor(); break;

                                    case 1: CursorManager.SetCursor(m_InteractCursor, new Vector2(-14, 15)); break;

                                    case 2: CursorManager.SetCursor(m_InteractCursor2, new Vector2(-14, 15)); break;

                                    case 3: CursorManager.SetCursor(m_InteractCursor3, new Vector2(-14, 15)); break;

                                    default: CursorManager.SetCursor(m_InteractCursor4, new Vector2(-14, 15)); break;
                                    }

                                    _CursorSelected = true;
                                }
                            }
                        }

                        if (!_CursorSelected)
                        {
                            // If the mouse is on the end point of the current selected destination, horse rear cursor
                            if (_SelectedHero.GetTargetDestination() == _WorldMouseCoords)
                            {
                                switch (_TurnCost)
                                {
                                case 0: CursorManager.ResetCursor(); break;

                                case 1: CursorManager.SetCursor(m_InteractCursor, new Vector2(-14, 15)); break;

                                case 2: CursorManager.SetCursor(m_InteractCursor2, new Vector2(-14, 15)); break;

                                case 3: CursorManager.SetCursor(m_InteractCursor3, new Vector2(-14, 15)); break;

                                default: CursorManager.SetCursor(m_InteractCursor4, new Vector2(-14, 15)); break;
                                }
                            }
                            else
                            {
                                switch (_TurnCost)
                                {
                                case 0: CursorManager.ResetCursor(); break;

                                case 1: CursorManager.SetCursor(m_MoveCursor, new Vector2(-15, 13)); break;

                                case 2: CursorManager.SetCursor(m_MoveCursor2, new Vector2(-15, 13)); break;

                                case 3: CursorManager.SetCursor(m_MoveCursor3, new Vector2(-15, 13)); break;

                                default: CursorManager.SetCursor(m_MoveCursor4, new Vector2(-15, 13)); break;
                                }
                            }

                            _CursorSelected = true;
                        }
                    }

                    if (!_CursorSelected)
                    {
                        CursorManager.ResetCursor();
                    }
                }
                else
                {
                    CursorManager.ResetCursor();
                }
            }

            if (Input.GetMouseButtonDown(0))
            {
                if (m_HoveredTown != null)
                {
                    if (m_HoveredTown != m_LocalOwnership.SelectedTown)
                    {
                        m_LocalOwnership.SelectTown(m_HoveredTown);
                    }
                    else
                    {
                        m_TownScreen.OpenTown(m_HoveredTown);
                    }
                }
                else if (m_LocalOwnership.SelectedHero != null)
                {
                    if (m_LocalOwnership.SelectedHero.IsMoving)
                    {
                        m_LocalOwnership.SelectedHero.CancelMovement();
                    }
                    else
                    {
                        m_LocalOwnership.SelectedHero.OnLeftClick(_WorldMouseCoords.x, _WorldMouseCoords.y, m_HoveredObject);
                    }
                }
                else if (m_HoveredHero != null)
                {
                    m_LocalOwnership.SelectHero(m_HoveredHero);
                }

                m_UpdateCursor = true;
            }
        }
        else
        {
            if (Input.GetMouseButtonDown(0))
            {
                if (m_LocalOwnership.SelectedHero != null)
                {
                    if (m_LocalOwnership.SelectedHero.IsMoving)
                    {
                        m_LocalOwnership.SelectedHero.CancelMovement();
                    }
                }
            }

            m_UpdateCursor = true;
            CursorManager.ResetCursor();
        }

        if (!m_TownScreen.Enabled)
        {
            if (Input.mousePosition.x <= 2)
            {
                if (Input.mousePosition.y <= 2)
                {
                    CursorManager.SetCursor(m_BottomLeftCursor, new Vector2(0, 18));
                }
                else if (Input.mousePosition.y >= Screen.height - 3)
                {
                    CursorManager.SetCursor(m_TopLeftCursor, new Vector2(0, 1));
                }
                else
                {
                    CursorManager.SetCursor(m_LeftCursor, new Vector2(0, 5));
                }
            }
            else if (Input.mousePosition.x >= Screen.width - 3)
            {
                if (Input.mousePosition.y <= 2)
                {
                    CursorManager.SetCursor(m_BottomRightCursor, new Vector2(-18, 18));
                }
                else if (Input.mousePosition.y >= Screen.height - 3)
                {
                    CursorManager.SetCursor(m_TopRightCursor, new Vector2(-18, 1));
                }
                else
                {
                    CursorManager.SetCursor(m_RightCursor, new Vector2(-23, 6));
                }
            }
            else
            {
                if (Input.mousePosition.y <= 2)
                {
                    CursorManager.SetCursor(m_BottomCursor, new Vector2(-6, 23));
                }
                else if (Input.mousePosition.y >= Screen.height - 3)
                {
                    CursorManager.SetCursor(m_TopCursor, new Vector2(-6, 0));
                }
            }
        }
    }
 public void Initialize(Pathfinding a_Pathfinding, MapObjectBase a_Object)
 {
     m_Pathfinding = a_Pathfinding;
     m_Object      = a_Object;
 }
Exemplo n.º 10
0
        static string PlayGame(LevelModel level, Player player)
        {
            var map = level.Map;

            // from this point on player pos is here and not in map
            var playerPos = level.LastPlayerPos ?? LocationHelper.GetFirstObjectFromMap <PlayerStartObject>(map);

            level.LastPlayerPos = new Positon();
            if (map[playerPos.XAxis, playerPos.YAxis].GetType() == typeof(PlayerStartObject))
            {
                map[playerPos.XAxis, playerPos.YAxis] = new FloorMapObject();
            }


            var input = "";
            var clear = true;

            while (input?.ToLower() != "exit")
            {
                var getAroundMe = LocationHelper.GetWhatsAroundPosition(playerPos, map);

                if (clear)
                {
                    Console.Clear();
                    Console.WriteLine($"-----");
                    Console.WriteLine($"|{getAroundMe.AllAround[0, 0]}{getAroundMe.AllAround[1, 0]}{getAroundMe.AllAround[2, 0]}|");
                    Console.WriteLine($"|{getAroundMe.AllAround[0, 1]}{player.StartOb}{getAroundMe.AllAround[2, 1]}|");
                    Console.WriteLine($"|{getAroundMe.AllAround[0, 2]}{getAroundMe.AllAround[1, 2]}{getAroundMe.AllAround[2, 2]}|");
                    Console.WriteLine($"-----");
                }

                if (getAroundMe.AllAround[1, 1].GetType() == typeof(MapCustomObject))
                {
                    var mapCustomObject = (MapCustomObject)getAroundMe.AllAround[1, 1];
                    if (!string.IsNullOrWhiteSpace(mapCustomObject.Message))
                    {
                        Console.WriteLine(mapCustomObject.Message);
                    }

                    if (mapCustomObject.AddItemId != null)
                    {
                        player.Inventory.Add(new InventoryItem {
                            Id = (int)mapCustomObject.AddItemId, Name = mapCustomObject.Name
                        });
                    }

                    level.Map[playerPos.XAxis, playerPos.YAxis] = new FloorMapObject();
                }

                if (getAroundMe.AllAround[1, 1].GetType() == typeof(MapExitObject))
                {
                    var mapExitObject = (MapExitObject)getAroundMe.AllAround[1, 1];

                    return(mapExitObject.GoToLevel);
                }

                level.LastPlayerPos.XAxis = playerPos.XAxis;
                level.LastPlayerPos.YAxis = playerPos.YAxis;
                clear = true;

                var inventory = player.Inventory.Select(x => x.Name).Aggregate("", (a, b) => $"{a},{b}");
                Console.WriteLine($" Options are Up Down Left Right PickUp  (not case sensetive) items:{inventory}");

                input = Console.ReadLine();

                input = input?.ToLower();
                MapObjectBase moveToPoint = null;
                var           movePos     = new Positon {
                    XAxis = 0, YAxis = 0
                };
                switch (input)
                {
                case "exit":
                    Environment.Exit(1);
                    break;

                case "up":
                case "u":
                    moveToPoint   = getAroundMe.Up;
                    movePos.YAxis = -1;
                    break;

                case "down":
                case "d":
                    moveToPoint   = getAroundMe.Down;
                    movePos.YAxis = 1;
                    break;

                case "left":
                case "l":
                    moveToPoint   = getAroundMe.Left;
                    movePos.XAxis = -1;
                    break;

                case "right":
                case "r":
                    moveToPoint   = getAroundMe.Right;
                    movePos.XAxis = 1;
                    break;
                }

                // ok i admit this is a lot of conditions
                // essentially it can't be null and it can be stood on
                if (moveToPoint != null && moveToPoint.CanStandOn &&
                    // its not a custom object
                    (moveToPoint.GetType() != typeof(MapCustomObject) ||
                     // if it is a custom object does not need a item
                     ((MapCustomObject)moveToPoint).RequiresItemId == null ||
                     // if it is a custom object and needs a item we have it in player inv
                     player.Inventory.Select(x => x.Id).Contains((int)((MapCustomObject)moveToPoint).RequiresItemId)))
                {
                    playerPos.XAxis += movePos.XAxis;
                    playerPos.YAxis += movePos.YAxis;
                    continue;
                }

                clear = false;
                Console.WriteLine($"Can Not do that");
            }

            return("");
        }