Exemplo n.º 1
0
        /// <summary>
        ///  Respawns enemy ships according to the fleet of the player and the number of remaining enemy ships.
        /// </summary>
        // ReSharper disable once UnusedMember.Global
        private void RespawnShips()
        {
            if (GhostShip != null)
            {
                return;
            }
            var randomNumber = new Random();
            var mapParts     = RessourceManager.GetRessourceInt("mapParts");

            if (mAiFisherShipList.Count < 12)
            {
                //spawn Fisherships until there are enough
                //random position
                var spawnPosition = new Vector2(randomNumber.Next(200, 5600), randomNumber.Next(200, 5600));
                var cell          = Game1.mMapScreen.mGridMap.GetCell(spawnPosition);
                if (cell.IsWalkable && !cell.Occupied && !VisibilityManager.IsVisible(spawnPosition))
                {
                    SpawnAiFisherShip(spawnPosition);
                }
            }

            if (mAiTradingShipList.Count < 7)//static number of tradingships
            {
                //spawn
                var spawnPosition = new Vector2(randomNumber.Next(300, 5600), randomNumber.Next(300, 5600));
                var cell          = Game1.mMapScreen.mGridMap.GetCell(spawnPosition);
                if (cell.IsWalkable && !cell.Occupied && !VisibilityManager.IsVisible(spawnPosition))
                {
                    SpawnAiTradingShip(spawnPosition);
                }
            }

            if (mAiBattleShipsList.Count < 2 + mapParts * 3)//by collecting more mapParts, the count of battleships increases
            {
                //spawn
                var spawnPosition = new Vector2(randomNumber.Next(400, 5600), randomNumber.Next(400, 5600));
                var cell          = Game1.mMapScreen.mGridMap.GetCell(spawnPosition);
                if (cell.IsWalkable && !cell.Occupied && !VisibilityManager.IsVisible(spawnPosition))
                {
                    SpawnAiBattleShip(spawnPosition);
                }
            }

            if (mAiFleetList.Count < mapParts - 2 && mAiFleetList.Count < 3)// only up to 3 fleets
            {
                //random SpawnPoint from List.
                var spawnPosition = mFleetSpawnPoints[randomNumber.Next(0, mFleetSpawnPoints.Count - 1)];
                if (mapParts < 3)
                {
                    SpawnAiFleet(spawnPosition, 2, 1);
                }
                else
                {
                    SpawnAiFleet(spawnPosition, 3, 2);//increase strength of the fleets
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Handle all Input
        /// </summary>
        internal void HandleInput()
        {
            //MouseState mouseState = Mouse.GetState();
            // Calculate the mousePosition in the map
            //mMouseInWorldPosition = mCamera2D.ScreenToWorld(new Vector2(mouseState.X, mouseState.Y));
            mMouseInWorldPosition = Game1.mMapScreen.GetWorldPosition(InputManager.MousePosition().ToVector2());
            var range = ResolutionManager.Scale().X *20;

            // Some stuff only used for demonstration.
            // Spawn a battle Ship to the right of the flagship.
            if (InputManager.KeyDown(Keys.I))
            {
                mAiShipManager.SpawnAiBattleShip(FlagShip.Position + 200 * Vector2.UnitX);
            }
            // Spawn the Admiral fleet.
            if (InputManager.KeyDown(Keys.K))
            {
                Game1.mEventScreen.mEventManager.StartQuest3();
            }
            // Spawn the GhostShip.
            if (InputManager.KeyDown(Keys.N))
            {
                Game1.mMapScreen.mPlayerShipManager.mAiShipManager.SpawnGhostShip(new Vector2(4200, 860));
                Game1.mEventScreen.mEventManager.mGhostShipinGame = true;
            }
            // Add KartenFragment
            if (InputManager.KeyDown(Keys.L))
            {
                RessourceManager.AddRessource("mapParts", +1);
            }
            // Spawn own Battleship near us.
            if (InputManager.KeyDown(Keys.J))
            {
                SpawnBattleShip(FlagShip.Position - 200 * Vector2.UnitX, true);
            }

            if (InputManager.LeftMouseButtonDown())
            {
                //check if there are ships selected to sort out how the input should be processed.
                if (mSelectShipList.Count == 0)
                {
                    //check for every Ship, if it is selected
                    foreach (var ship in mAllShipList)
                    {
                        //testweise ein quadrat über die mitte des schiffs.
                        var selectRange = new CircleF(ship.Position, range);
                        if (!selectRange.Contains(mMouseInWorldPosition))
                        {
                            continue;
                        }
                        if (VisibilityManager.IsVisible(mMouseInWorldPosition))
                        {
                            ship.Selected = true;
                            mSelectShipList.Add(ship);
                        }

                        break; //when the mouse was clicked, obviously one ship can be selected.
                    }
                }
                else//unselect Ships
                {
                    UnselectShips();
                }
            }
            else if (InputManager.RightMouseButtonDown() && mSelectShipList.Count > 0)
            {
                if (InputManager.KeyPressed(InputManager.HotKey("Hk1")) || mShipState == ShipState.Attacking)
                {
                    SetShipsAttacking();
                }
                else if (InputManager.KeyPressed(InputManager.HotKey("Hk3")) || mShipState == ShipState.Defending)
                {
                    SetShipsDefending();
                }
                else if (InputManager.KeyPressed(InputManager.HotKey("Hk2")) || mShipState == ShipState.Boarding)
                {
                    SetShipsBoarding();
                }
                else
                {
                    SetShipsMoving();
                }
            }


            //Selectbox selecting
            if (InputManager.mSelectionBoxFinished)
            {
                InputManager.mSelectionBoxFinished = false;
                var selBoxOld  = InputManager.SelectBox();
                var shipsOwned = false;
                foreach (var ship in mAllShipList)
                {
                    if (!selBoxOld.Contains(ship.Position))
                    {
                        continue;
                    }
                    if (VisibilityManager.IsVisible(selBoxOld))
                    {
                        ship.Selected = true;
                        mSelectShipList.Add(ship);
                        if (ship.Owned)
                        {
                            shipsOwned = true;
                        }
                    }
                }
                if (shipsOwned)
                {
                    var actuallySelected = new List <AShip>();
                    foreach (var ship in SelectShipList)
                    {
                        if (ship.Owned)
                        {
                            actuallySelected.Add(ship);
                        }
                        else
                        {
                            ship.Selected = false;
                        }
                    }
                    SelectShipList = actuallySelected;
                }
            }

            //check for repairing commands
            if (InputManager.KeyPressed(InputManager.HotKey("Hk4")))
            {
                AddRepairingShips();
            }
            else if (InputManager.KeyReleased(InputManager.HotKey("Hk5"))) // Rum
            {
                foreach (var ship in mSelectShipList)
                {
                    if (RessourceManager.GetRessourceInt("rum") > 0)
                    {
                        Random random = new Random();
                        SoundManager.PlayEfx("efx/burping/" + random.Next(1, 7));
                        //increase crew if its the first rum
                        if (ship.RumBuffDuration <= 0f)
                        {
                            ship.AttackValue      += 5;
                            ship.EnterAttackValue += 5;
                            ship.RepairingValue   += 5;
                            ship.MovementSpeed    += 0.1f;
                        }
                        //increase duration and rumCounter
                        ship.RumDrunken++;
                        ship.RumBuffDuration += 5;
                        //ship.RumBuffDuration += 7;
                        RessourceManager.AddRessource("rum", -1);
                    }
                    else
                    {
                        SoundManager.PlayAmb("No_Rum", false);
                    }
                }
            }


            //Hud aufrufen

            /* if (mSelectShipList.Count >= 1)
             * {
             *   HudScreen.HudScreenInstance.ShowShipControl(mSelectShipList);
             * }
             * else
             * {
             *   HudScreen.HudScreenInstance.HideShipControl();
             * }*/
        }