protected void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                if (hid.Value == "Update")
                {
                    FleetLocation loc = null; bool rst = false;
                    loc = LookUpBLL.GetFleetLocation(Convert.ToInt32(txtID.Text));
                    if (loc != null)
                    {
                        loc.Name = txtDept.Text.ToUpper();;
                        rst      = LookUpBLL.UpdateFleetLocation(loc);
                        if (rst != false)
                        {
                            BindGrid();
                            success.Visible   = true;
                            success.InnerHtml = " <button type='button' class='close' data-dismiss='alert'>&times;</button> Record updated successfully!!.";
                            return;
                        }
                    }

                    else
                    {
                        error.Visible   = true;
                        error.InnerHtml = " <button type='button' class='close' data-dismiss='alert'>&times;</button>Record could Not updated. Kindly try again. If error persist contact Administrator!!.";
                    }
                }
                else
                {
                    string typ = "";
                    typ = txtDept.Text;

                    bool          result = false;
                    FleetLocation loc    = new FleetLocation();
                    loc.Name = typ.ToUpper();
                    result   = LookUpBLL.AddFleetLocation(loc);
                    if (result)
                    {
                        BindGrid();
                        txtDept.Text = "";

                        success.Visible   = true;
                        success.InnerHtml = " <button type='button' class='close' data-dismiss='alert'>&times;</button> Record added successfully!!.";
                        return;
                    }
                    else
                    {
                        error.Visible   = true;
                        error.InnerHtml = " <button type='button' class='close' data-dismiss='alert'>&times;</button>Record could Not added. Kindly try again. If error persist contact Administrator!!.";
                    }
                }
            }
            catch (Exception ex)
            {
                error.Visible   = true;
                error.InnerHtml = "<button type='button' class='close' data-dismiss='alert'>&times;</button> An error occurred. kindly try again!!!";
                Utility.WriteError("Error: " + ex.Message);
            }
        }
Exemplo n.º 2
0
 public static bool AddFleetLocation(FleetLocation loc)
 {
     try
     {
         using (FleetMgtSysDBEntities db = new FleetMgtSysDBEntities())
         {
             db.FleetLocations.Add(loc);
             db.SaveChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         // Utility.WriteError("Error Msg: " + ex.Message);
         throw ex;
     }
 }
Exemplo n.º 3
0
        public static bool IsPlayerSystemsInNeutronStarEffectRanges(
            GameSession game,
            int playerId,
            int systemId)
        {
            StarSystemInfo starSystemInfo = game.GameDatabase.GetStarSystemInfo(systemId);

            if (starSystemInfo == (StarSystemInfo)null)
            {
                return(false);
            }
            List <NeutronStarInfo> list = game.GameDatabase.GetNeutronStarInfos().ToList <NeutronStarInfo>();

            if (list.Count == 0)
            {
                return(false);
            }
            bool flag = false;

            foreach (ColonyInfo colonyInfo in game.GameDatabase.GetColonyInfosForSystem(systemId).ToList <ColonyInfo>())
            {
                if (colonyInfo.PlayerID == playerId)
                {
                    flag = true;
                    break;
                }
            }
            if (!flag)
            {
                return(false);
            }
            float fleetTravelSpeed = Kerberos.Sots.StarFleet.StarFleet.GetFleetTravelSpeed(game, list.First <NeutronStarInfo>().FleetId, false);
            float num = game.GameDatabase.AssetDatabase.GlobalNeutronStarData.AffectRange * game.GameDatabase.AssetDatabase.GlobalNeutronStarData.AffectRange;

            foreach (NeutronStarInfo neutronStarInfo in list)
            {
                FleetLocation fleetLocation = game.GameDatabase.GetFleetLocation(neutronStarInfo.FleetId, true);
                if (fleetLocation != null && (double)((fleetLocation.Direction.HasValue ? fleetLocation.Direction.Value * fleetTravelSpeed + fleetLocation.Coords : fleetLocation.Coords) - starSystemInfo.Origin).LengthSquared <= (double)num)
                {
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 4
0
 public static bool UpdateFleetLocation(FleetLocation loc)
 {
     try
     {
         bool rst = false;
         using (var db = new FleetMgtSysDBEntities())
         {
             db.FleetLocations.Attach(loc);
             db.Entry(loc).State = System.Data.Entity.EntityState.Modified;
             db.SaveChanges();
             rst = true;
         }
         return(rst);
     }
     catch (Exception ex)
     {
         Utility.WriteError("Error Msg: " + ex.InnerException);
         throw ex;
     }
 }
Exemplo n.º 5
0
        protected override void UpdateFleet(
            StarMapFleet o,
            FleetInfo oi,
            StarMapBase.SyncContext context)
        {
            FleetLocation fleetLocation = this._db.GetFleetLocation(oi.ID, true);

            o.SetSystemID(fleetLocation.SystemID);
            o.SetPosition(fleetLocation.Coords);
            o.FleetID = oi.ID;
            if (fleetLocation.Direction.HasValue)
            {
                o.SetDirection(fleetLocation.Direction.Value);
            }
            MoveOrderInfo orderInfoByFleetId = this.App.GameDatabase.GetMoveOrderInfoByFleetID(oi.ID);

            if (orderInfoByFleetId != null && (double)orderInfoByFleetId.Progress <= 0.0)
            {
                StarSystemInfo starSystemInfo = this._db.GetStarSystemInfo(fleetLocation.SystemID);
                if (starSystemInfo != (StarSystemInfo)null)
                {
                    o.SetPosition(starSystemInfo.Origin);
                }
            }
            o.SetIsInTransit(orderInfoByFleetId != null && ((double)orderInfoByFleetId.Progress > 0.0 || oi.Type == FleetType.FL_ACCELERATOR && (oi.SystemID == 0 || this._sim.GameDatabase.GetStarSystemInfo(oi.SystemID).IsDeepSpace)));
            o.SetPlayer(this._sim.GetPlayerObject(oi.PlayerID));
            if (oi.PlayerID == this._sim.LocalPlayer.ID)
            {
                o.SetSensorRange(GameSession.GetFleetSensorRange(this.App.AssetDatabase, this._db, oi.ID));
            }
            if (o.ObjectStatus == GameObjectStatus.Ready)
            {
                o.PostSetActive(true);
            }
            o.SetIsLoaGate(oi.Type == FleetType.FL_ACCELERATOR);
        }
Exemplo n.º 6
0
        public void HandleGardenerCaptured(
            GameSession game,
            GameDatabase gamedb,
            int playerId,
            int gardenerId)
        {
            GardenerInfo gardenerInfo = gamedb.GetGardenerInfo(gardenerId);

            if (gardenerInfo == null)
            {
                return;
            }
            FleetInfo fleetInfo = gamedb.GetFleetInfo(gardenerInfo.FleetId);

            if (fleetInfo == null)
            {
                return;
            }
            if (gardenerInfo.DeepSpaceSystemId.HasValue)
            {
                foreach (StationInfo stationInfo in game.GameDatabase.GetStationForSystem(gardenerInfo.DeepSpaceSystemId.Value).ToList <StationInfo>())
                {
                    game.GameDatabase.DestroyStation(game, stationInfo.ID, 0);
                }
            }
            fleetInfo.PlayerID = playerId;
            gamedb.UpdateFleetInfo(fleetInfo);
            FleetLocation         fleetLocation   = gamedb.GetFleetLocation(fleetInfo.ID, false);
            List <StarSystemInfo> closestStars    = EncounterTools.GetClosestStars(gamedb, fleetLocation.Coords);
            StarSystemInfo        starSystemInfo1 = (StarSystemInfo)null;

            foreach (StarSystemInfo starSystemInfo2 in closestStars)
            {
                int?systemOwningPlayer = gamedb.GetSystemOwningPlayer(starSystemInfo2.ID);
                if (systemOwningPlayer.HasValue && systemOwningPlayer.Value == playerId)
                {
                    starSystemInfo1 = starSystemInfo2;
                    break;
                }
            }
            if (!(starSystemInfo1 != (StarSystemInfo)null))
            {
                return;
            }
            MissionInfo missionByFleetId = gamedb.GetMissionByFleetID(fleetInfo.ID);

            if (missionByFleetId != null)
            {
                gamedb.RemoveMission(missionByFleetId.ID);
            }
            MoveOrderInfo orderInfoByFleetId = gamedb.GetMoveOrderInfoByFleetID(fleetInfo.ID);

            if (orderInfoByFleetId != null)
            {
                gamedb.RemoveMoveOrder(orderInfoByFleetId.ID);
            }
            int missionID = gamedb.InsertMission(fleetInfo.ID, MissionType.RETURN, starSystemInfo1.ID, 0, 0, 0, false, new int?());

            gamedb.InsertWaypoint(missionID, WaypointType.TravelTo, new int?(starSystemInfo1.ID));
            gamedb.InsertMoveOrder(fleetInfo.ID, 0, fleetLocation.Coords, starSystemInfo1.ID, Vector3.Zero);
            this.SpawnProteanChaser(game, gardenerInfo);
        }
Exemplo n.º 7
0
        public void UpdateTurn(GameSession game, int id)
        {
            GardenerInfo gi = game.GameDatabase.GetGardenerInfo(id);

            if (gi == null)
            {
                game.GameDatabase.RemoveEncounter(id);
            }
            else if (gi.IsGardener)
            {
                FleetInfo fleetInfo = game.GameDatabase.GetFleetInfo(gi.FleetId);
                if (fleetInfo != null && fleetInfo.PlayerID != this.PlayerID)
                {
                    return;
                }
                if (game.GameDatabase.GetMoveOrderInfoByFleetID(gi.FleetId) == null)
                {
                    if (gi.DeepSpaceSystemId.HasValue)
                    {
                        game.GameDatabase.DestroyStarSystem(game, gi.DeepSpaceSystemId.Value);
                    }
                    if (gi.DeepSpaceOrbitalId.HasValue)
                    {
                        game.GameDatabase.RemoveOrbitalObject(gi.DeepSpaceOrbitalId.Value);
                    }
                    game.GameDatabase.RemoveEncounter(id);
                }
                else
                {
                    FleetLocation fl = game.GameDatabase.GetFleetLocation(fleetInfo.ID, false);
                    if (!gi.DeepSpaceSystemId.HasValue || game.GameDatabase.GetStarSystemInfos().Any <StarSystemInfo>((Func <StarSystemInfo, bool>)(x =>
                    {
                        if (x.ID != gi.DeepSpaceSystemId.Value)
                        {
                            return((double)(game.GameDatabase.GetStarSystemOrigin(x.ID) - fl.Coords).LengthSquared < 9.99999974737875E-05);
                        }
                        return(false);
                    })))
                    {
                        return;
                    }
                    game.GameDatabase.UpdateStarSystemOrigin(gi.DeepSpaceSystemId.Value, fl.Coords);
                }
            }
            else
            {
                if (gi.SystemId != 0 || gi.GardenerFleetId == 0)
                {
                    return;
                }
                FleetInfo gardenerFleet = game.GameDatabase.GetFleetInfo(gi.GardenerFleetId);
                bool      flag          = gardenerFleet == null;
                if (!flag)
                {
                    if (gi.TurnsToWait <= 0)
                    {
                        FleetInfo fleetInfo = game.GameDatabase.GetFleetInfo(gi.FleetId);
                        if (fleetInfo != null)
                        {
                            if (game.GameDatabase.GetMoveOrderInfoByFleetID(gardenerFleet.ID) == null)
                            {
                                if (gardenerFleet.SystemID != fleetInfo.SystemID)
                                {
                                    game.GameDatabase.UpdateFleetLocation(fleetInfo.ID, gardenerFleet.SystemID, new int?());
                                }
                            }
                            else
                            {
                                GardenerInfo gardenerInfo = game.GameDatabase.GetGardenerInfos().FirstOrDefault <GardenerInfo>((Func <GardenerInfo, bool>)(x => x.FleetId == gardenerFleet.ID));
                                if (gardenerInfo != null && gardenerInfo.DeepSpaceSystemId.HasValue)
                                {
                                    game.GameDatabase.UpdateFleetLocation(fleetInfo.ID, gardenerInfo.DeepSpaceSystemId.Value, new int?());
                                }
                                else
                                {
                                    game.GameDatabase.UpdateFleetLocation(fleetInfo.ID, 0, new int?());
                                }
                            }
                        }
                    }
                    else if (game.GameDatabase.GetMoveOrderInfoByFleetID(gardenerFleet.ID) == null)
                    {
                        --gi.TurnsToWait;
                        game.GameDatabase.UpdateGardenerInfo(gi);
                    }
                }
                if (!flag)
                {
                    return;
                }
                game.GameDatabase.RemoveEncounter(id);
            }
        }
Exemplo n.º 8
0
        public static void GenerateMeteorAndCometEncounters(App game)
        {
            List <NeutronStarInfo> list1 = game.GameDatabase.GetNeutronStarInfos().ToList <NeutronStarInfo>();

            if (list1.Count == 0)
            {
                return;
            }
            float fleetTravelSpeed      = Kerberos.Sots.StarFleet.StarFleet.GetFleetTravelSpeed(game.Game, list1.First <NeutronStarInfo>().FleetId, false);
            List <StarSystemInfo> list2 = game.GameDatabase.GetStarSystemInfos().ToList <StarSystemInfo>();
            float num1 = game.AssetDatabase.GlobalNeutronStarData.AffectRange * game.AssetDatabase.GlobalNeutronStarData.AffectRange;
            Dictionary <int, List <int> > dictionary1 = new Dictionary <int, List <int> >();
            Dictionary <int, float>       dictionary2 = new Dictionary <int, float>();
            List <int> intList = new List <int>();

            foreach (NeutronStarInfo neutronStarInfo in list1)
            {
                FleetLocation fleetLocation = game.GameDatabase.GetFleetLocation(neutronStarInfo.FleetId, true);
                if (fleetLocation != null)
                {
                    Vector3 coords  = fleetLocation.Coords;
                    Vector3 vector3 = fleetLocation.Direction.HasValue ? fleetLocation.Direction.Value * fleetTravelSpeed + fleetLocation.Coords : fleetLocation.Coords;
                    foreach (StarSystemInfo starSystemInfo in list2)
                    {
                        float lengthSquared = (coords - starSystemInfo.Origin).LengthSquared;
                        if ((double)lengthSquared <= (double)num1)
                        {
                            if (dictionary2.ContainsKey(starSystemInfo.ID))
                            {
                                dictionary2[starSystemInfo.ID] = Math.Min(dictionary2[starSystemInfo.ID], lengthSquared);
                            }
                            else
                            {
                                dictionary2.Add(starSystemInfo.ID, lengthSquared);
                            }
                        }
                        if ((double)(vector3 - starSystemInfo.Origin).LengthSquared <= (double)num1)
                        {
                            if (!intList.Contains(starSystemInfo.ID))
                            {
                                intList.Add(starSystemInfo.ID);
                            }
                            if (dictionary2.ContainsKey(starSystemInfo.ID))
                            {
                                dictionary2[starSystemInfo.ID] = Math.Min(dictionary2[starSystemInfo.ID], lengthSquared);
                            }
                            else
                            {
                                dictionary2.Add(starSystemInfo.ID, lengthSquared);
                            }
                        }
                    }
                }
            }
            Random safeRandom = App.GetSafeRandom();

            foreach (KeyValuePair <int, float> keyValuePair in dictionary2)
            {
                KeyValuePair <int, float> inRangeSys = keyValuePair;
                List <ColonyInfo>         list3      = game.GameDatabase.GetColonyInfosForSystem(inRangeSys.Key).ToList <ColonyInfo>();
                List <int> source = new List <int>();
                foreach (ColonyInfo colonyInfo in list3)
                {
                    Player player = game.GetPlayer(colonyInfo.PlayerID);
                    if (player != null && player.IsStandardPlayer)
                    {
                        if (intList.Contains(colonyInfo.CachedStarSystemID))
                        {
                            if (!dictionary1.ContainsKey(player.ID))
                            {
                                dictionary1.Add(colonyInfo.PlayerID, new List <int>());
                            }
                            if (!dictionary1[colonyInfo.PlayerID].Contains(colonyInfo.CachedStarSystemID))
                            {
                                dictionary1[colonyInfo.PlayerID].Add(colonyInfo.CachedStarSystemID);
                            }
                        }
                        if (!player.IsAI() && !source.Contains(player.ID))
                        {
                            source.Add(player.ID);
                        }
                    }
                }
                if ((double)dictionary2[inRangeSys.Key] <= (double)num1 && source.Count != 0 && !source.Any <int>((Func <int, bool>)(x => game.GameDatabase.GetIncomingRandomsForPlayerThisTurn(x).Any <IncomingRandomInfo>((Func <IncomingRandomInfo, bool>)(y => y.SystemId == inRangeSys.Key)))))
                {
                    float num2 = Math.Min((float)Math.Sqrt((double)inRangeSys.Value) / game.AssetDatabase.GlobalNeutronStarData.AffectRange, 1f);
                    int   odds = (int)(90.0 * (double)num2) + 10;
                    if (safeRandom.CoinToss(odds))
                    {
                        if (safeRandom.CoinToss(game.AssetDatabase.GlobalNeutronStarData.MeteorRatio))
                        {
                            float intensity = (float)(((double)game.AssetDatabase.GlobalNeutronStarData.MaxMeteorIntensity - 1.0) * (double)num2 + 1.0);
                            if (game.Game.ScriptModules.MeteorShower != null)
                            {
                                game.Game.ScriptModules.MeteorShower.ExecuteEncounter(game.Game, inRangeSys.Key, intensity, true);
                            }
                        }
                        else if (game.Game.ScriptModules.Comet != null)
                        {
                            game.Game.ScriptModules.Comet.ExecuteInstance(game.GameDatabase, game.AssetDatabase, inRangeSys.Key);
                        }
                    }
                }
            }
            foreach (KeyValuePair <int, List <int> > keyValuePair in dictionary1)
            {
                if (keyValuePair.Value.Count != 0)
                {
                    game.GameDatabase.InsertTurnEvent(new TurnEvent()
                    {
                        EventType    = TurnEventType.EV_NEUTRON_STAR_NEARBY,
                        EventMessage = TurnEventMessage.EM_NEUTRON_STAR_NEARBY,
                        PlayerID     = keyValuePair.Key,
                        NumShips     = keyValuePair.Value.Count,
                        TurnNumber   = game.GameDatabase.GetTurnCount(),
                        ShowsDialog  = true
                    });
                }
            }
        }
Exemplo n.º 9
0
        public void UpdateTurn(GameSession game, int id)
        {
            NeutronStarInfo nsi       = game.GameDatabase.GetNeutronStarInfo(id);
            FleetInfo       fleetInfo = nsi != null?game.GameDatabase.GetFleetInfo(nsi.FleetId) : (FleetInfo)null;

            if (fleetInfo == null)
            {
                game.GameDatabase.RemoveEncounter(id);
            }
            else
            {
                MissionInfo missionByFleetId = game.GameDatabase.GetMissionByFleetID(fleetInfo.ID);
                if (game.GameDatabase.GetMoveOrderInfoByFleetID(fleetInfo.ID) != null)
                {
                    FleetLocation fl = game.GameDatabase.GetFleetLocation(fleetInfo.ID, false);
                    if (!nsi.DeepSpaceSystemId.HasValue || game.GameDatabase.GetStarSystemInfos().Any <StarSystemInfo>((Func <StarSystemInfo, bool>)(x =>
                    {
                        if (x.ID != nsi.DeepSpaceSystemId.Value)
                        {
                            return((double)(game.GameDatabase.GetStarSystemOrigin(x.ID) - fl.Coords).LengthSquared < 9.99999974737875E-05);
                        }
                        return(false);
                    })))
                    {
                        return;
                    }
                    game.GameDatabase.UpdateStarSystemOrigin(nsi.DeepSpaceSystemId.Value, fl.Coords);
                }
                else
                {
                    if (missionByFleetId != null)
                    {
                        game.GameDatabase.RemoveMission(missionByFleetId.ID);
                    }
                    StarSystemInfo starSystemInfo = game.GameDatabase.GetStarSystemInfo(fleetInfo.SystemID);
                    foreach (int standardPlayerId in game.GameDatabase.GetStandardPlayerIDs())
                    {
                        if (StarMap.IsInRange(game.GameDatabase, standardPlayerId, game.GameDatabase.GetFleetLocation(fleetInfo.ID, false).Coords, 1f, (Dictionary <int, List <ShipInfo> >)null))
                        {
                            game.GameDatabase.InsertTurnEvent(new TurnEvent()
                            {
                                EventType    = TurnEventType.EV_NEUTRON_STAR_DESTROYED_SYSTEM,
                                EventMessage = TurnEventMessage.EM_NEUTRON_STAR_DESTROYED_SYSTEM,
                                SystemID     = starSystemInfo.ID,
                                PlayerID     = this.PlayerID,
                                TurnNumber   = game.GameDatabase.GetTurnCount()
                            });
                        }
                    }
                    if (nsi.DeepSpaceSystemId.HasValue)
                    {
                        game.GameDatabase.RemoveFleet(fleetInfo.ID);
                        game.GameDatabase.RemoveEncounter(id);
                        game.GameDatabase.DestroyStarSystem(game, nsi.DeepSpaceSystemId.Value);
                    }
                    if (fleetInfo.SystemID != 0)
                    {
                        game.GameDatabase.DestroyStarSystem(game, starSystemInfo.ID);
                    }
                    if (!(game.App.CurrentState is StarMapState))
                    {
                        return;
                    }
                    ((StarMapState)game.App.CurrentState).ClearSelectedObject();
                    ((StarMapState)game.App.CurrentState).RefreshStarmap(StarMapState.StarMapRefreshType.REFRESH_ALL);
                }
            }
        }