void Start()
 {
     //Initialisation
     if (instance == null) {
         instance = this;
     }
 }
Example #2
0
        public override void Load()
        {
            // Engine components.
            RessourceManager ressourceManager = Engine.GetComponent <RessourceManager>();


            // Setup the scene
            Entities              = new List <Entity>();
            camera                = new OrbitalCamera(Engine.GraphicDevice.GetBufferSize().X / Engine.GraphicDevice.GetBufferSize().Y, 90);
            render                = new RenderBatch();
            testSun               = new Sun(new Point3D(-150f, 150f, -150f), new Color3(255, 255, 255));
            testScene             = new Scene(camera, testSun);
            testScene.Fog.Density = 0f;

            // Dragon
            Model    dragonModel    = ressourceManager.ImportRessource <Model>("model:dragon.obj");
            Material dragonMaterial = new Material(ressourceManager.ImportRessource <Texture2D>("texture2D:blue.png"));

            dragonMaterial.Reflectivity = 1f;
            dragonMaterial.ShineDamper  = 10f;
            ressourceManager.ImportRessource <ShaderProgram>("shader:material.json");
            Entities.Add(new Entity(new Transform(new Vector3(0, 0, 0), new Vector3(), 0.1f), dragonModel, dragonMaterial));

            // Terrain
            Material GrassMaterial = new Material(ressourceManager.ImportRessource <Texture2D>("texture2D:grass.png"))
            {
                Reflectivity = 0f,
                ShineDamper  = 10f
            };

            terrain = new Entity(new Transform(0, -10f, 0), ModelFactorie.GeneratePlane(640f, 256, 64, new PerlinHeightMap()), GrassMaterial);
            water   = new Entity(new Transform(0, 0, 0), ModelFactorie.GeneratePlane(640f, 16, 64, new FlatHeightMap()), dragonMaterial);


            // Show the inspector.
            new Inspector.InspectorUI(Engine, testScene).ShowInspector();
        }
Example #3
0
        private static void MonoGameOnInitialize(object sender, EventArgs eventArgs)
        {
            Ressource = new RessourceManager();

            Platform.Initialize();

            Logger.Log("Rise", LoggerLevel.Info, "Initializing modules...");

            Keyboard   = new KeyboardInputManager();
            Controller = new Controller();
            Pointing   = new Pointing();
            Input      = new LegacyInputManager();

            Graphic = new GraphicManager(MonoGame.Graphics, MonoGame.GraphicsDevice);
            Scene   = new SceneManager();
            Ui      = new UiManager();
            Debug   = new DebugManager();

            _initializeAction?.Invoke();

            Graphic.ResetRenderTargets();
            Scene.Initialize();
            Input.Initialize();

            if (Platform.GetPlatformName() != "Android")
            {
                Keyboard.Initialize(300, 5);
            }

            Scene.Switch(_startScene);

            if (Platform.Family == PlatformFamily.Desktop)
            {
                Graphic.SetSize(1366, 768);
            }
        }
Example #4
0
 public void Start()
 {
     agent    = GetComponent <NavMeshAgent>();
     rManager = GameObject.FindWithTag("RessourceManager").GetComponent <RessourceManager>();
     rManager.registerBot(this);
 }
Example #5
0
        /// <summary>
        ///  Calls update() on every ship. Checks for input and manages Selecting
        /// and the execution of commands.
        /// </summary>
        public void Update(GameTime gameTime)
        {
            mShipsQuadTree.Clear();
            foreach (var shipu in AllShips)
            {
                mShipsQuadTree.Insert(shipu);
            }
            //general update for all ships
            for (int i = 0; i < sAllShipList.Count; i++)
            {
                sAllShipList[i].UpdateMoving(gameTime);
                if (sAllShipList[i].Hp <= 0)
                {
                    sAllShipList.RemoveAt(i);
                }
            }
            //Call Update for every Attacking Ship
            for (int i = 0; i < mAttackingShipList.Count; i++)
            {
                mAttackingShipList[i].Update(gameTime);

                if (mAttackingShipList[i].Chasing && mAttackingRefreshRate <= 0)
                {
                    mAttackingRefreshRate = 2;
                    var atkShip = (AShip)mAttackingShipList[i];
                    atkShip.Move(mPathFinder.CalculatePath(atkShip.Position, mAttackingShipList[i].TargetShip.Position, true));
                }
                else
                {
                    mAttackingRefreshRate -= gameTime.ElapsedGameTime.TotalSeconds;
                }

                //remove not attacking ships
                var ship = mAttackingShipList[i] as BattleShip;
                if (ship != null)
                {
                    var atkShip = ship;
                    if (atkShip.CurrentBState != BattleShip.ShipBattleState.Attacking)
                    {
                        mAttackingShipList.RemoveAt(i);
                    }
                }
                else if (mAttackingShipList[i] is TradingShip)
                {
                    var atkShip = (TradingShip)mAttackingShipList[i];
                    if (atkShip.CurrentBState != TradingShip.ShipBattleState.Attacking)
                    {
                        mAttackingShipList.RemoveAt(i);
                    }
                }
            }

            //Check for enemy Ships to shoot at while defending(Only defending Ships)
            for (int i = 0; i < mDefendingShipList.Count; i++)
            {
                mDefendingShipList[i].Update(gameTime);
                //check if there are enemy ships in range
                if (mDefendingShipList[i].TargetShip == null)
                {
                    /* old version, as backup...
                     * foreach (var ship in sAllShipList)
                     * {
                     *
                     *  var deShip = (AShip) mDefendingShipList[i];
                     *  CircleF rangeCircle = new CircleF(deShip.Position, 100f);
                     *  if (rangeCircle.Contains(ship.Position) && !(ship.Owned && deShip.Owned) && !(!ship.Owned && !deShip.Owned))
                     *  {
                     *      mDefendingShipList[i].TargetShip = ship;
                     *      //deShip.Moving = false;
                     *
                     *      break;//first ship to be seen will be attacked
                     *  }
                     * } */

                    //QuadTree test
                    List <AShip> possibleCollisions = new List <AShip>();
                    mShipsQuadTree.Retrieve(possibleCollisions, (AShip)mDefendingShipList[i]);
                    foreach (var ship in possibleCollisions)
                    {
                        var     deShip      = (AShip)mDefendingShipList[i];
                        CircleF rangeCircle = new CircleF(deShip.Position, 150f);
                        if (rangeCircle.Contains(ship.Position) && !(ship.Owned && deShip.Owned) && !(!ship.Owned && !deShip.Owned))
                        {
                            mDefendingShipList[i].TargetShip = ship;
                            deShip.Moving = false;

                            break;//first ship to be seen will be attacked
                        }
                    }
                }


                //remove not defending ships from list
                var battleShip = mDefendingShipList[i] as BattleShip;
                if (battleShip != null)
                {
                    var defShip = battleShip;
                    if (defShip.CurrentBState != BattleShip.ShipBattleState.Defending)
                    {
                        mDefendingShipList.RemoveAt(i);
                    }
                }
                else if (mDefendingShipList[i] is TradingShip)
                {
                    var defShip = (TradingShip)mDefendingShipList[i];
                    if (defShip.CurrentBState != TradingShip.ShipBattleState.Defending)
                    {
                        mDefendingShipList.RemoveAt(i);
                    }
                }
            }

            //Update and Pathrefreshing for Entering Ships
            for (int i = 0; i < mEnteringShipList.Count; i++)
            {
                //remove not entering ships from list
                if (mEnteringShipList[i].CurrentBState != BattleShip.ShipBattleState.Entering)
                {
                    mEnteringShipList.RemoveAt(i);
                }
                else
                {
                    //Restriction to Pathrefreshing for Chases
                    if (mEnteringRefreshRate <= 0)
                    {
                        mEnteringRefreshRate = 2;
                        //check if the targetShips are moving and sets new Paths
                        //aktuell immer, weil targetShip nichtmehr verfolgt wird nachdem es stehen bleibt.

                        if (mEnteringShipList[i].Chasing)
                        {
                            mEnteringShipList[i].Move(mPathFinder.CalculatePath(mEnteringShipList[i].Position,
                                                                                mEnteringShipList[i].TargetShip.Position, true));
                        }

                        /*
                         * Alternative: zu inteligent wahrscheinlich...
                         * if (mEnteringShipList[i].Chasing &&
                         *  !mEnteringShipList[i].ShipPath.TargetNode.Equals(mEnteringShipList[i].TargetShip.ShipPath.TargetNode))
                         * {
                         *  mEnteringShipList[i].Move(mPathFinder.CalculatePath(mEnteringShipList[i].Position,
                         *      mEnteringShipList[i].TargetShip.ShipPath.TargetNode.Cell.Position,true));
                         * }
                         */
                    }
                    else
                    {
                        mEnteringRefreshRate -= gameTime.ElapsedGameTime.TotalSeconds;
                    }
                    mEnteringShipList[i].Update(gameTime);
                }
            }

            //todo: check if hudScreen is in selecting process for attack/defense/enter
            //only check input if the specified boolean(from hud) is false



            //update for all ships repairing
            for (var i = 0; i < mRepairingShipList.Count; i++)
            {
                if (mRepairingShipList[i].Hp < mRepairingShipList[i].MaxHp &&
                    RessourceManager.GetRessourceFloat("wood") >= mRepairingShipList[i].RepairValue * 0.01f)
                {
                    mRepairingShipList[i].Hp += mRepairingShipList[i].RepairValue * 0.005f;
                    //Wood -= mRepairingShipList[i].RepairValue*0.01f;
                    RessourceManager.AddRessourceFloat("wood", -mRepairingShipList[i].RepairValue * 0.01f);
                }
                else
                {
                    //that no ship can get to much hP with repairing.
                    if (mRepairingShipList[i].Hp > mRepairingShipList[i].MaxHp)
                    {
                        mRepairingShipList[i].Hp = (int)mRepairingShipList[i].MaxHp;
                    }
                    mRepairingShipList[i].Repairing = false;
                    mRepairingShipList.RemoveAt(i);
                }
            }
        }
 public IRessource Import(RessourceManager ressourceManager, string fileName)
 {
     return(null);
 }
Example #7
0
 private void Start()
 {
     rManager = GameObject.FindWithTag("RessourceManager").GetComponent <RessourceManager>();
     rManager.registerContainer(this);
 }
Example #8
0
        /// <summary>
        ///  Check for possible actions for the Fleets and single Ships controled by the AI.
        /// </summary>
        public void Update(GameTime gameTime, QuadTree quadTree)
        {
            //FisherShips
            var counter = mAiFisherShipList.Count;

            for (var i = 0; i < counter; i++)
            {
                var fShip = mAiFisherShipList[i];
                if (!fShip.Moving)
                {
                    if (mFishingMovingDelay <= 0)
                    {
                        var randomNumber = new Random();
                        //moving to a random position in the Map
                        var x = randomNumber.Next(0, 5760);
                        var y = randomNumber.Next(0, 5760);
                        fShip.Move(PathFinder.CalculatePath(fShip.Position, new Vector2(x, y), false));
                        mFishingMovingDelay = 8;
                    }
                    else
                    {
                        mFishingMovingDelay -= gameTime.ElapsedGameTime.TotalSeconds;
                    }
                }
                if (!fShip.Owned && fShip.Hp > 0)
                {
                    continue;
                }
                mAiFisherShipList.RemoveAt(i);
                counter--;
                fShip.HealthBar = null;
                fShip.CrewBar   = null;
                if (fShip.Owned
                    )
                {
                    Game1.mEventScreen.mEventManager.UpdateStatTotal("Ships Hijacked", 1);
                }
            }

            //TradingShips
            counter = mAiTradingShipList.Count;
            for (var i = 0; i < counter; i++)
            {
                var tShip = mAiTradingShipList[i];
                if (!tShip.Moving)
                {
                    if (mTradingMovingDelay <= 0)
                    {
                        var randomNumber = new Random();
                        var number       = randomNumber.Next(0, IslandManager.IslandCount);
                        var destination  = new Vector2(IslandManager.Islands[IslandManager.mIslandNames[number]].X + randomNumber.Next(20, 50),
                                                       IslandManager.Islands[IslandManager.mIslandNames[number]].Y + randomNumber.Next(20, 50));
                        if (Vector2.Distance(destination, tShip.Position) > 100 &&
                            Game1.mMapScreen.mGridMap.GetCell(destination).IsWalkable &&
                            !Game1.mMapScreen.mGridMap.GetCell(destination).Occupied)
                        {
                            tShip.Move(PathFinder.CalculatePath(tShip.Position, destination, false));
                            mTradingMovingDelay = 5;
                        }
                    }
                    else
                    {
                        mTradingMovingDelay -= gameTime.ElapsedGameTime.TotalSeconds;
                    }
                }

                if (tShip.Hp < tShip.MaxHp) //shoot back
                {
                    if (!mDefendingShipList.Contains(tShip))
                    {
                        tShip.Defend(tShip.ShipPath);
                        mDefendingShipList.Add(tShip);
                    }
                    if (tShip.Hp <= 40) //fleeing
                    {
                        tShip.TargetShip = null;
                        tShip.Move(tShip.ShipPath);
                        tShip.CurrentBState = TradingShip.ShipBattleState.Idle;
                        mDefendingShipList.Remove(tShip);
                    }
                }

                if (!tShip.Owned && tShip.Hp > 0)
                {
                    continue;
                }
                mAiTradingShipList.RemoveAt(i);
                counter--;
                if (tShip.Owned)
                {
                    tShip.CrewBar   = null;
                    tShip.HealthBar = null;
                    Game1.mEventScreen.mEventManager.UpdateStatTotal("Ships Hijacked", 1);
                    var random = new Random();
                    if (random.Next(0, 4) == 1)// 25% dropchance
                    {
                        RessourceManager.AddRessource("mapParts", 1);
                    }
                }
            }


            //BattleShips
            counter = mAiBattleShipsList.Count;
            for (var i = 0; i < counter; i++)
            {
                var bShip = mAiBattleShipsList[i];
                if (bShip.CurrentBState == BattleShip.ShipBattleState.Idle)
                {
                    if (!bShip.Moving)
                    {
                        if (mBattleMovingDelay <= 0)
                        {
                            //moving to a random position in the Map
                            var randomNumber = new Random();
                            var x            = randomNumber.Next(0, 5760);
                            var y            = randomNumber.Next(0, 5760);
                            bShip.Move(PathFinder.CalculatePath(bShip.Position, new Vector2(x, y), false));
                            mBattleMovingDelay = 3;
                        }
                        else
                        {
                            mBattleMovingDelay -= gameTime.ElapsedGameTime.TotalSeconds;
                        }
                    }

                    //scan for possible enemies in reach and attack them if they aren't to powefull
                    var possibleCollisions = new List <AShip>();
                    var enemyShipsCount    = 0;
                    quadTree.Retrieve(possibleCollisions, bShip);
                    if (possibleCollisions.Count > 0)
                    {
                        AShip nearestShip = null;
                        for (var index = 0; index < possibleCollisions.Count; index++)
                        {
                            var rangeCircle = new CircleF(bShip.Position, 500f); //scan radius
                            if (rangeCircle.Contains(possibleCollisions[index].Position) &&
                                possibleCollisions[index].Owned && possibleCollisions[index].Hp >= 0)
                            {
                                if (nearestShip == null)
                                {
                                    nearestShip = possibleCollisions[index];
                                }
                                enemyShipsCount++;
                                //save the nearest Ship
                                if (Vector2.Distance(bShip.Position, possibleCollisions[index].Position) <
                                    Vector2.Distance(bShip.Position, nearestShip.Position))
                                {
                                    nearestShip = possibleCollisions[index];
                                }
                            }
                        }
                        //only attack up to 3 ships
                        if (enemyShipsCount > 0 && enemyShipsCount <= 3 && nearestShip != null)
                        {
                            var random = new Random();
                            var number = random.Next(0, 2);
                            if ((number == 1) && nearestShip.EnterAttackValue - 8 < bShip.EnterAttackValue)
                            {
                                bShip.Move(PathFinder.CalculatePath(bShip.Position, nearestShip.Position, false));
                                bShip.Enter(nearestShip);
                                mEnteringShipList.Add(bShip);
                            }
                            else
                            {
                                bShip.Move(PathFinder.CalculatePath(bShip.Position, nearestShip.Position, false));
                                bShip.Attack(nearestShip);
                                mAttackingShipList.Add(bShip);
                            }
                        }
                        else if (enemyShipsCount > 3)
                        {
                            bShip.CurrentBState = BattleShip.ShipBattleState.Defending;
                            mDefendingShipList.Add(bShip);
                        }
                    }
                }

                if (!bShip.Owned && bShip.Hp > 0)
                {
                    continue;
                }
                mAiBattleShipsList.RemoveAt(i);
                counter--;
                bShip.CrewBar   = null;
                bShip.HealthBar = null;
                if (!Game1.mMapScreen.mTechDemo && bShip.Owned)
                {
                    Game1.mEventScreen.mEventManager.UpdateStatTotal("Ships Hijacked", 1);
                    var random = new Random();
                    if (random.Next(0, 3) == 1)// 33% dropchance
                    {
                        RessourceManager.AddRessource("mapParts", 1);
                    }
                }
            }

            //Fleets
            counter = mAiFleetList.Count;
            for (var t = 0; t < counter; t++)
            {
                var fleet = mAiFleetList[t];
                //check if the ships are still in the fleet
                var bCounter = fleet.BattleShips.Count;
                for (var i = 0; i < bCounter; i++)
                {
                    if (!(fleet.BattleShips[i].Hp <= 0) && !fleet.BattleShips[i].Owned)
                    {
                        continue;
                    }
                    fleet.BattleShips.RemoveAt(i);
                    bCounter--;
                }
                var tCounter = fleet.TradingShips.Count;
                for (var i = 0; i < tCounter; i++)
                {
                    if (!(fleet.TradingShips[i].Hp <= 0) && !fleet.TradingShips[i].Owned)
                    {
                        continue;
                    }
                    fleet.TradingShips.RemoveAt(i);
                    tCounter--;
                }

                //ceck if fleets are whiped out
                if (fleet.FleetCount() <= 0)
                {
                    mAiFleetList.Remove(fleet);
                    counter--;
                }


                if (!fleet.InBattle)
                {
                    //search for enemies when not in Battle
                    var possibleCollisions = new List <AShip>();
                    var toAttack           = new List <AShip>();
                    quadTree.Retrieve(possibleCollisions, fleet.FlagShip);
                    //check if the ships are enemies and in range
                    foreach (var potentialEnemyShip in possibleCollisions)
                    {
                        var rangeCircle = new CircleF(fleet.FlagShip.Position, 600f); //scan radius
                        if (rangeCircle.Contains(potentialEnemyShip.Position) && potentialEnemyShip.Owned &&
                            potentialEnemyShip.Hp >= 0)
                        {
                            toAttack.Add(potentialEnemyShip);
                        }
                    }
                    //if there are any enemies, attack them
                    if (toAttack.Count > 0)
                    {
                        fleet.Attack(toAttack);
                    }

                    //random movement. Determines with the Flagship if the fleet is moving.
                    if (!fleet.FlagShip.Moving && !fleet.Defending)
                    {
                        if (mBattleMovingDelay <= 0)
                        {
                            //moving to a random position in the Map
                            var randomNumber = new Random();
                            var x            = randomNumber.Next(0, 5760);
                            var y            = randomNumber.Next(0, 5760);
                            fleet.Move(new Vector2(x, y));
                            mBattleMovingDelay = 3;
                        }
                        else
                        {
                            mBattleMovingDelay -= gameTime.ElapsedGameTime.TotalSeconds;
                        }
                    }
                }
                else//when in battle
                {
                    //check if own ships were entered
                    for (int i = 0; i < fleet.BattleShips.Count; i++)
                    {
                        if (fleet.BattleShips[i].Owned)
                        {
                            fleet.MarkedShips.Add(fleet.BattleShips[i]);
                            fleet.BattleShips.RemoveAt(i);
                        }
                    }
                    //check if own ships were entered
                    for (int i = 0; i < fleet.TradingShips.Count; i++)
                    {
                        if (fleet.TradingShips[i].Owned)
                        {
                            fleet.MarkedShips.Add(fleet.TradingShips[i]);
                            fleet.TradingShips.RemoveAt(i);
                        }
                    }


                    //check if the marked ships still exist and the distance
                    var kCounter = fleet.MarkedShips.Count;
                    for (var i = 0; i < kCounter; i++)
                    {
                        if (fleet.MarkedShips[i].Hp <= 0 || !fleet.MarkedShips[i].Owned || Vector2.Distance(fleet.MarkedShips[i].Position, fleet.FlagShip.Position) > 600)
                        {
                            fleet.MarkedShips.RemoveAt(i);
                            kCounter--;
                            i--;
                        }
                    }

                    fleet.UpdateBattle();
                    //check for enemies
                    var possibleCollisions = new List <AShip>();
                    var toAttack           = new List <AShip>();
                    quadTree.Retrieve(possibleCollisions, fleet.FlagShip);
                    foreach (var potentialEnemyShip in possibleCollisions)
                    {
                        //only add ships that are new
                        var rangeCircle = new CircleF(fleet.FlagShip.Position, 700f); //scan radius
                        if (!fleet.MarkedShips.Contains(potentialEnemyShip) && rangeCircle.Contains(potentialEnemyShip.Position) && potentialEnemyShip.Owned &&
                            potentialEnemyShip.Hp >= 0)
                        {
                            toAttack.Add(potentialEnemyShip);
                        }
                    }
                    if (toAttack.Count > 0)
                    {
                        fleet.MarkedShips.AddRange(toAttack);
                    }


                    //if there is no enemy left, the fleet will stop battling
                    if (fleet.MarkedShips.Count <= 0)
                    {
                        fleet.InBattle = false;
                        fleet.StopBattle();
                    }
                }
            }

            //GhostShip
            if (GhostShip != null)
            {
                if (GhostShip.CurrentBState == GhostShip.ShipBattleState.Idle)
                {
                    //check if there are any enemyShips nearby
                    var enemyShips         = new List <AShip>();
                    var possibleCollisions = new List <AShip>();
                    quadTree.Retrieve(possibleCollisions, GhostShip);
                    foreach (var potentialEnemyShip in possibleCollisions)
                    {
                        //only add ships that are new
                        var rangeCircle = new CircleF(GhostShip.Position, 600f); //scan radius
                        if (!GhostShip.TargetShips.Contains(potentialEnemyShip) && rangeCircle.Contains(potentialEnemyShip.Position) && potentialEnemyShip.Owned &&
                            potentialEnemyShip.Hp >= 0)
                        {
                            enemyShips.Add(potentialEnemyShip);
                        }
                    }
                    if (enemyShips.Count > 0)
                    {
                        GhostShip.Attack(enemyShips);
                    }
                    //move to the island if not already next to it.
                    if (Vector2.Distance(GhostShip.Position, GhostShip.TreasureIslandPosition) >= 200 && !GhostShip.Moving)
                    {
                        GhostShip.Move(PathFinder.CalculatePath(GhostShip.Position, GhostShip.TreasureIslandPosition, true));
                    }
                }
                else if (GhostShip.CurrentBState == GhostShip.ShipBattleState.Attacking)
                {
                    GhostShip.Update(gameTime);
                    //check if there are any new enemyShips nearby
                    var possibleCollisions = new List <AShip>();
                    quadTree.Retrieve(possibleCollisions, GhostShip);
                    foreach (var potentialEnemyShip in possibleCollisions)
                    {
                        //only add ships that are new
                        var rangeCircle = new CircleF(GhostShip.Position, 600f); //scan radius
                        if (!GhostShip.TargetShips.Contains(potentialEnemyShip) && rangeCircle.Contains(potentialEnemyShip.Position) && potentialEnemyShip.Owned &&
                            potentialEnemyShip.Hp >= 0)
                        {
                            GhostShip.TargetShips.Add(potentialEnemyShip);
                        }
                    }

                    //moving
                    mGhostMovementDelay -= gameTime.ElapsedGameTime.TotalSeconds;
                    if (mGhostMovementDelay <= 0 && GhostShip.NearestTarget != null)
                    {
                        Vector2 movementTarget;
                        if (Vector2.Distance(GhostShip.NearestTarget.Position, GhostShip.Position) <= 120)
                        {
                            if (GhostShip.MoveRight)
                            {
                                movementTarget = GhostShip.Position +
                                                 (Vector2.Normalize(GhostShip.Position - GhostShip.NearestTarget.Position).PerpendicularCounterClockwise() * 100f);
                                GhostShip.MoveRight = false;
                            }
                            else
                            {
                                movementTarget = GhostShip.Position +
                                                 (Vector2.Normalize(GhostShip.Position - GhostShip.NearestTarget.Position).PerpendicularClockwise() * 100f);
                                GhostShip.MoveRight = true;
                            }
                            mGhostMovementDelay = 1.5;
                        }
                        else
                        {
                            movementTarget = GhostShip.NearestTarget.Position +
                                             Vector2.Normalize(GhostShip.Position - GhostShip.NearestTarget.Position) * 20f;
                            mGhostMovementDelay = 1;
                        }
                        GhostShip.Move(PathFinder.CalculatePath(GhostShip.Position, movementTarget, true));
                    }
                }
                if (GhostShip.Hp <= 0)
                {
                    GhostShip.DropLoot();
                    mAllShipList.Remove(GhostShip);
                    GhostShip = null;
                }
            }
            else
            {
                //spawn ships if necessary
                RespawnShips();
            }



            if (Octopus != null)
            {
                //search for enemies
                if (Octopus.CurrentBState == Octopus.ShipBattleState.Idle)
                {
                    /*
                     * var possibleCollisions = new List<AShip>();
                     * quadTree.Retrieve(possibleCollisions, Octopus);
                     * AShip nearestShip = null;
                     * foreach (var potentialEnemyShip in possibleCollisions)
                     * {
                     *  //only add ships that are new
                     *
                     *  var rangeCircle = new CircleF(Octopus.Position, 400f); //scan radius
                     *  if (rangeCircle.Contains(potentialEnemyShip.Position) && potentialEnemyShip.Owned &&
                     *       potentialEnemyShip.Hp >= 0)
                     *  {
                     *      if (nearestShip == null)
                     *      {
                     *          nearestShip = potentialEnemyShip;
                     *      }
                     *      else if (Vector2.Distance(nearestShip.Position, Octopus.Position) > Vector2.Distance(potentialEnemyShip.Position, Octopus.Position))
                     *      {
                     *          nearestShip = potentialEnemyShip;
                     *      }
                     *  }
                     * }*/
                    var nearestShip = SearchClosestShip(Octopus, quadTree, 400f);//testing
                    if (nearestShip != null)
                    {
                        Octopus.Enter(nearestShip);//attack the closest enemy
                    }

                    //move back to original position
                    if (Vector2.Distance(Octopus.Position, Octopus.HousingPosition) >= 200 && !Octopus.Moving)
                    {
                        Octopus.Move(PathFinder.CalculatePath(Octopus.Position, Octopus.HousingPosition, true));
                    }
                }
                else if (Octopus.CurrentBState == Octopus.ShipBattleState.Entering)
                {
                    Octopus.Update(gameTime);
                    mOctopusChasingDelay -= gameTime.ElapsedGameTime.TotalSeconds;
                    if (Octopus.TargetShip != null && Vector2.Distance(Octopus.Position, Octopus.TargetShip.Position) >= 70 && mOctopusChasingDelay <= 0)
                    {
                        mOctopusChasingDelay = 2;
                        Octopus.Move(PathFinder.CalculatePath(Octopus.Position, Octopus.TargetShip.Position, true));
                    }
                }
                if (Octopus.Hp <= 0)
                {
                    Octopus.DropLoot();
                    mAllShipList.Remove(Octopus);
                    Octopus = null;
                }
            }

            if (Dragon != null)
            {
                Dragon.Update(gameTime, quadTree);//special Updates for the dragon..
                Dragon.UpdateDragonMovement(gameTime);

                //check if the Dragoon is fighting or not
                if (Dragon.CurrentBState == Dragon.ShipBattleState.Idle)
                {
                    if (!Dragon.Moving)
                    {
                        //moving to a random position in the Map
                        var randomNumber = new Random();
                        var x            = randomNumber.Next(0, 5760);
                        var y            = randomNumber.Next(0, 5760);
                        Dragon.MoveDragon(new Vector2(x, y));
                    }

                    /*
                     * var possibleCollisions = new List<AShip>();
                     * quadTree.Retrieve(possibleCollisions, Dragon);
                     * AShip nearestShip = null;
                     * foreach (var potentialEnemyShip in possibleCollisions)
                     * {
                     *  //only add ships that are new
                     *  var rangeCircle = new CircleF(Octopus.Position, 200f); //scan radius
                     *  if (rangeCircle.Contains(potentialEnemyShip.Position) && potentialEnemyShip.Owned &&
                     *       potentialEnemyShip.Hp >= 0)
                     *  {
                     *      if (nearestShip == null)
                     *      {
                     *          nearestShip = potentialEnemyShip;
                     *      }
                     *      else if (Vector2.Distance(nearestShip.Position, Octopus.Position) > Vector2.Distance(potentialEnemyShip.Position, Octopus.Position))
                     *      {
                     *          nearestShip = potentialEnemyShip;
                     *      }
                     *  }
                     * }*/
                    var nearestShip = SearchClosestShip(Dragon, quadTree, 200f);
                    if (nearestShip != null)
                    {
                        Dragon.Attack(nearestShip); //attack the closest enemy
                    }
                }
                else if (Dragon.CurrentBState == Dragon.ShipBattleState.Attacking)
                {
                    //Chasing
                    if (Dragon.TargetShip != null && Vector2.Distance(Dragon.Position, Dragon.TargetShip.Position) >= 70)
                    {
                        Dragon.MoveDragon(Dragon.TargetShip.Position);
                    }
                }


                if (Dragon.Hp <= 0)
                {
                    Dragon.DropLoot();
                    mAllShipList.Remove(Dragon);
                    Dragon = null;
                }
            }
        }
    // Use this for initialization
    void Start()
    {
        my_RM = GameObject.FindGameObjectWithTag("RessourceManager").GetComponent <RessourceManager>();

        soundPutItem = GetComponent <AudioSource>();
    }
 void Start()
 {
     rManager    = GameObject.FindWithTag("RessourceManager").GetComponent <RessourceManager>();
     cratePrefab = rManager.cratePrefab;
 }
 void Start()
 {
     rManager = GameObject.FindWithTag("RessourceManager").GetComponent <RessourceManager>();
     ct       = GetComponent <CanvasToogler>();
 }
Example #12
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();
             * }*/
        }