void Start() { overlord = GameObject.FindGameObjectWithTag("Overlord"); movement = GetComponent <Movement>(); intel = GetComponent <Intel>(); path = pathList.gameObject.GetComponent <PathPointList>().getPathList(); }
void LoadFallbackGameObjects() { Vector3 blueTeamOrigin = World.Terrain.Chunks[new IndexPosition(World.Terrain.Width - 1, 0, World.Terrain.Depth - 1)].Position; redIntel = new Intel(GetSpawnLocation(200, 200, Block.CUBE_SIZE * 1.5f), Team.A); blueIntel = new Intel(GetSpawnLocation(blueTeamOrigin.X - 200, blueTeamOrigin.Z - 200, Block.CUBE_SIZE * 1.5f), Team.B); redPost = new CommandPost(GetSpawnLocation(100, 100, Block.CUBE_SIZE * 3), Team.A); bluePost = new CommandPost(GetSpawnLocation(blueTeamOrigin.X - 75, blueTeamOrigin.Z - 75, Block.CUBE_SIZE * 3), Team.B); redIntel.OnPickedUp += Intel_OnPickedUp; redIntel.OnDropped += Intel_OnDropped; redIntel.OnReturned += Intel_OnReturned; blueIntel.OnPickedUp += Intel_OnPickedUp; blueIntel.OnDropped += Intel_OnDropped; blueIntel.OnReturned += Intel_OnReturned; redPost.PhysicsBody.OnCollision += Post_OnCollision; bluePost.PhysicsBody.OnCollision += Post_OnCollision; // Instantiate intels over network objectComponent.NetworkInstantiate(redIntel, "Client_CreateIntel", null, redIntel.Transform.Position.X, redIntel.Transform.Position.Y, redIntel.Transform.Position.Z, (byte)redIntel.Team); objectComponent.NetworkInstantiate(blueIntel, "Client_CreateIntel", null, blueIntel.Transform.Position.X, blueIntel.Transform.Position.Y, blueIntel.Transform.Position.Z, (byte)blueIntel.Team); objectComponent.NetworkInstantiate(redPost, "Client_CreateCommandPost", null, redPost.Transform.Position.X, redPost.Transform.Position.Y, redPost.Transform.Position.Z, (byte)redPost.Team); objectComponent.NetworkInstantiate(bluePost, "Client_CreateCommandPost", null, bluePost.Transform.Position.X, bluePost.Transform.Position.Y, bluePost.Transform.Position.Z, (byte)bluePost.Team); }
private void CharacterController_OnCollision(object sender, PhysicsBodyComponent e) { if (this.intel == null) { Intel intel = e.GameObject as Intel; if (intel != null) { if (intel.RequestOwnership(this)) { DashCMD.WriteLine("[SPPlayer] Picked up the intel", ConsoleColor.Green); this.intel = intel; intel.IsIconVisible = false; } } } CommandPost commandPost = e.GameObject as CommandPost; if (commandPost != null) { if (commandPost.Team == Team) { Refresh(); if (intel != null) { intel.Return(); intel.IsIconVisible = true; intel = null; } } } }
protected override void OnStopped() { NetChannel.RemoveRemoteEvent("Client_GamemodeInfo"); NetChannel.RemoveRemoteEvent("Client_UpdateScores"); NetChannel.RemoveRemoteEvent("Client_IntelPickedUp"); NetChannel.RemoveRemoteEvent("Client_IntelDropped"); NetChannel.RemoveRemoteEvent("Client_IntelCaptured"); NetChannel.RemoveRemoteEvent("Client_IntelReturned"); objectComponent.RemoveInstantiationEvent("Client_CreateIntel"); objectComponent.RemoveInstantiationEvent("Client_CreateCommandPost"); redIntel = null; blueIntel = null; redPost = null; bluePost = null; TeamAScore = 0; TeamBScore = 0; ScoreCap = 3; OurPlayerHasIntel = false; intelAudioSource?.Dispose(); base.OnStopped(); }
public void PlaceIntel() { IntelCollected = 0; TotalIntel = 3; intelRoomIndices = new int[TotalIntel]; for (int i = 0; i < TotalIntel; i++) { do { intelRoomIndices[i] = Random.Range(0, roomCount); } while (intelRoomIndices[i] == spawnRoomIndex || intelRoomIndices[i] == exitRoomIndex); Table new_table = Instantiate(TablePrefab); new_table.transform.position = FloorGenerator.Instance.GetPointInRoom(intelRoomIndices[i]) + new Vector3(0.0f, 0.15f, 0.0f); tables.Add(new_table); Intel new_intel = Instantiate(IntelPrefab); new_intel.transform.position = new_table.transform.position + new Vector3(0.0f, 0.2f, 0.0f); intel.Add(new_intel); } }
public void Browse(CpMediaServer server, System.String ObjectID, Intel.UPNP.AV.CpContentDirectory.Enum_A_ARG_TYPE_BrowseFlag BrowseFlag, System.String Filter, System.UInt32 StartingIndex, System.UInt32 RequestedCount, System.String SortCriteria, object _Tag, Delegate_OnBrowseDone _Callback) { _RequestState state = new _RequestState(); state.Callback = _Callback; state.Tag = _Tag; state.Server = server; server.ContentDirectory.Browse(ObjectID, BrowseFlag, Filter, StartingIndex, RequestedCount, SortCriteria, state, new Intel.UPNP.AV.CpContentDirectory.Delegate_OnResult_Browse(_OnBrowseDone)); }
public void OnSceneLoaded(Scene scene, LoadSceneMode mode) { movePlayer.PlayerVector = new Vector2(-18f, -12.3f); moveScript = GameObject.Find("MovePlayer"); moveScript.GetComponent <movePlayer>().move_Player(); Intel = GameObject.Find("Intel"); Intel.SetActive(false); SceneManager.sceneLoaded -= OnSceneLoaded; }
public void DropIntel() { if (Intel != null) { Intel.Drop(yeet: ClientSnapshot.DropIntel); Intel = null; DashCMD.WriteLine("[ServerMPPlayer] Intel has been dropped!", ConsoleColor.Green); } }
public override void Do() { if (location == t_actor.location) { var inv = t_actor.intelligence.inv; Intel intel = inv[Random.Range(0, inv.Count)]; actor.intelligence.AddIntel(intel); } }
void DropIntel() { if (intel != null) { intel.Drop(yeet: true); intel.IsIconVisible = true; intel = null; DashCMD.WriteLine("[SPPlayer] Dropped the intel", ConsoleColor.Green); } }
/// <summary> /// Read and process the <RaceName>.intel generated by the Nova /// Console. /// This file must be present before the GUI will run, since it /// contains key data, such as the race name, as well as any information about /// events that happend in the previous game year (battles, mine hits, etc. /// It is also used for a kind of boot strapping process as there may or may not /// be a <RaceName>.state file to load: /// 1. open the .intel and determine the race, and hence the name of any .state file. /// 2. open the .state file, if any. This contains any historical information, /// and is used to reconstruct the stateData (we can create a new one with /// no history if required, such as on the first turn) /// 3. process the .intel file to update the stateData /// /// Note that this file is not read again after the first time a new turn is /// received. Once fully loaded all further processing is done using /// stateData (which is subsequently used to generate <RaceName>.orders. /// </summary> /// <param name="turnFileName">Path and file name of the RaceName.intel file.</param> public void ReadIntel(string turnFileName) { if (!File.Exists(turnFileName)) { Report.FatalError("The Nova GUI cannot start unless a turn file is present"); } bool waitForFile = false; double waitTime = 0.0; // seconds do { try { using (Stream turnFile = new FileStream(turnFileName, FileMode.Open)) { XmlDocument xmldoc = new XmlDocument(); xmldoc.Load(turnFile); Intel newIntel = new Intel(xmldoc); // check this is a new turn, not an old one or the same one. if (newIntel.EmpireState.TurnYear >= clientState.EmpireState.TurnYear) { clientState.GameFolder = Path.GetDirectoryName(turnFileName); clientState.Restore(); clientState.InputTurn = newIntel; ProcessIntel(); } else { // exit without saving any files throw new System.Exception("Turn Year missmatch"); } } waitForFile = false; } catch (System.IO.IOException) { // IOException. Is the file locked? Try waiting. if (waitTime < Global.TotalFileWaitTime) { waitForFile = true; System.Threading.Thread.Sleep(Global.FileWaitRetryTime); waitTime += 0.1; } else { // Give up, maybe something else is wrong? throw; } } }while (waitForFile); }
private void CharacterController_OnCollision(object sender, PhysicsBodyComponent e) { if (Intel == null) { if (e.GameObject is Intel intel) { if (intel.RequestOwnership(this)) { DashCMD.WriteLine("[ServerMPPlayer] Intel has been picked up!", ConsoleColor.Green); Intel = intel; } } } }
/// <summary> /// Restore the GUI persistent data if the state store file exists (it typically /// will not on the very first turn of a new game). /// </summary> /// <remarks> /// Later on, when we read the /// file Nova.intel we will reset the persistent data fields if the turn file /// indicates the first turn of a new game. /// </remarks> public ClientData Restore() { ClientData newState = Restore(GameFolder, EmpireState.Race.Name); Messages = newState.Messages; InputTurn = newState.InputTurn; EmpireState = newState.EmpireState; Commands = newState.Commands; FirstTurn = newState.FirstTurn; GameFolder = newState.GameFolder; StatePathName = newState.StatePathName; return(this); }
void CaptureIntel(ServerMPPlayer player, Intel intel) { intel.Return(); string team = intel.Team == Team.A ? "Red" : "Blue"; Screen.Chat(string.Format("The {0} intel has been captured!", team)); if (player != null) { player.DropIntel(); NetworkPlayer netPlayer; if (NetPlayerComponent.TryGetPlayer(player.StateInfo.Owner, out netPlayer)) { netPlayer.Score += SCORE_CAPTURE; Screen.AddFeedItem(netPlayer.Name, "", World.GetTeamColor(player.Team), "Captured", "Intel", World.GetTeamColor(player.Team == Team.A ? Team.B : Team.A)); } } else { Screen.AddFeedItem("?", null, World.GetTeamColor(intel.Team == Team.A ? Team.B : Team.A), "Captured", "Intel", World.GetTeamColor(intel.Team)); } if (intel.Team == Team.B) { teamAScore++; } else { teamBScore++; } if (teamAScore < SCORE_CAP && teamBScore < SCORE_CAP) { NetChannel.FireEventForAllConnections("Client_IntelCaptured", (byte)intel.Team); } NetChannel.FireEventForAllConnections("Client_UpdateScores", (short)teamAScore, (short)teamBScore); }
private void Intel_OnDropped(object sender, Player _player) { Intel intel = (Intel)sender; ServerMPPlayer player = (ServerMPPlayer)_player; string team = intel.Team == Team.A ? "Red" : "Blue"; Screen.Chat(string.Format("The {0} intel has been dropped!", team)); NetworkPlayer netPlayer; if (NetPlayerComponent.TryGetPlayer(player.StateInfo.Owner, out netPlayer)) { Screen.AddFeedItem(netPlayer.Name, "", World.GetTeamColor(player.Team), "Dropped", "Intel", World.GetTeamColor(intel.Team)); } NetChannel.FireEventForAllConnections("Client_IntelDropped", (byte)intel.Team); }
private void NotifyIntel(Intel intel) { if (InvokeRequired) { this.Invoke((NotifyIntel)NotifyIntel, intel); return; } IntelPresentation intelDisplay = new IntelPresentation(intel); if (intelBindingSource.Count > 0) { intelBindingSource.Insert(0, intel); } else { intelBindingSource.Add(intel); } if (listIntel.Items.Count > 0) { listIntel.Items.Insert(0, intelDisplay); } else { listIntel.Items.Add(intelDisplay); } if (Properties.Settings.Default.TextToSpeech) { synthesizerMessages.Enqueue(intelDisplay); if (!backgroundIntelSound.IsBusy) { backgroundIntelSound.RunWorkerAsync(); } } else if (Properties.Settings.Default.PlayIntelSound) { SystemSounds.Exclamation.Play(); } }
public SPWorld(MasterRenderer renderer) : base(renderer) { WorldDescription desc = LoadFromFile(Program.GetConfigString("Singleplayer/world")); spawnPos = new Vector3(100, 400, 100); var commandposts = desc.GetObjectsByTag("CommandPost"); foreach (WorldObjectDescription ob in commandposts) { Vector3 position = ob.GetVector3("Position"); Team team = (Team)(ob.GetField <byte>("Team") ?? 0); CommandPost commandPost = new CommandPost(position, team); AddGameObject(commandPost); if (team == Team.A) { spawnPos = position; } } var intels = desc.GetObjectsByTag("Intel"); foreach (WorldObjectDescription ob in intels) { Vector3 position = ob.GetVector3("Position"); Team team = (Team)(ob.GetField <byte>("Team") ?? 0); Intel editorIntel = new Intel(position, team); AddGameObject(editorIntel); } Player = new SPPlayer(Renderer, this, Camera.Active, spawnPos, Team.A); AddGameObject(Player); hud = new HUD(Renderer); hud.Player = Player; hud.ShowCharacterInformation = true; hud.Enable(); Player.AttachCamera(); }
INetCreatable I_CreateIntel(ushort id, bool isAppOwner, NetBuffer data) { // Read the packet float x = data.ReadFloat(); float y = data.ReadFloat(); float z = data.ReadFloat(); Team team = (Team)data.ReadByte(); Intel intel = new Intel(new Vector3(x, y, z), team); if (team == Team.A) { redIntel = intel; } else { blueIntel = intel; } return(intel); }
/// <summary> /// This is the entry point to the AI proper. /// Currently this does not use anything recognized by Computer Science as AI, /// just functional programming to complete a list of tasks. /// </summary> public override void DoMove() { aiPlan = new DefaultAIPlanner(clientState); // create the helper AIs foreach (Star star in clientState.EmpireState.OwnedStars.Values) { if (star.Owner == clientState.EmpireState.Id) { DefaultPlanetAI planetAI = new DefaultPlanetAI(star, clientState, this.aiPlan); planetAIs.Add(star.Key, planetAI); } } foreach (Fleet fleet in clientState.EmpireState.OwnedFleets.Values) { if (fleet.Owner == clientState.EmpireState.Id) { aiPlan.CountFleet(fleet); DefaultFleetAI fleetAI = new DefaultFleetAI(fleet, clientState, fuelStations); fleetAIs.Add(fleet.Id, fleetAI); // reset all waypoint orders for (int wpIndex = 1; wpIndex < fleet.Waypoints.Count; wpIndex++) { WaypointCommand command = new WaypointCommand(CommandMode.Delete, fleet.Key, wpIndex); command.ApplyToState(clientState.EmpireState); clientState.Commands.Push(command); } } } turnData = clientState.InputTurn; HandleProduction(); HandleResearch(); HandleScouting(); HandleColonizing(); }
/// <Summary> /// Post-construction initialisation. /// </Summary> public void initialize(ClientData clientState) { this.clientState = clientState; GameSettings.Restore(); // Initial map size logical.X = GameSettings.Data.MapWidth; logical.Y = GameSettings.Data.MapHeight; extent.X = (int)(this.logical.X * this.zoomFactor) + (extraSpace.X * 2); extent.Y = (int)(this.logical.Y * this.zoomFactor) + (extraSpace.Y * 2); turnData = this.clientState.InputTurn; isinitialized = true; horizontalScrollBar.Enabled = true; verticalScrollBar.Enabled = true; DetermineVisibleMinefields(); zoomFactor = 1.0; Zoom(); }
private string GetRawIntel(Intel intel) { string rawIntel = Intel.Message; if (rawIntel.Length > 50) { rawIntel = rawIntel.Substring(0, 50) + "..."; } return rawIntel; }
public void SerialisationTestIntel() { StringWriter stringStream = new StringWriter(); try { // setup a test object Intel testData = new Intel(); // setup the test data testData.EmpireState.TurnYear = 3500; Star testStar = new Star(); testStar.Name = "Pluto"; testStar.Colonists = 25000; testData.EmpireState.StarReports.Add(testStar.Name, testStar.GenerateReport(ScanLevel.Owned, testData.EmpireState.TurnYear)); // setup the file name string saveFileName = "IntelTest.xml"; // setup the streams MemoryStream memoryStream = new MemoryStream(); // Setup the XML document XmlDocument xmldoc = new XmlDocument(); Global.InitializeXmlDocument(xmldoc); // add the Intel to the document xmldoc.ChildNodes.Item(1).AppendChild(testData.ToXml(xmldoc)); xmldoc.Save(memoryStream); xmldoc.Save(stringStream); // Serialize to file if (TestControls.CreateFiles) { using (Stream fileStream = new FileStream(saveFileName, FileMode.Create)) { xmldoc.Save(fileStream); } } // deserialize Intel loadedData; xmldoc.RemoveAll(); if (TestControls.CreateFiles) { using (FileStream saveFileStream = new FileStream(saveFileName, FileMode.Open, FileAccess.Read)) { xmldoc.Load(saveFileStream); loadedData = new Intel(xmldoc); } } else { // move to start of memory stream memoryStream.Seek(0, SeekOrigin.Begin); xmldoc.Load(memoryStream); loadedData = new Intel(xmldoc); } // test if it worked Assert.IsTrue(loadedData.EmpireState.TurnYear == 3500); Assert.IsTrue(loadedData.EmpireState.StarReports.ContainsKey("Pluto") && loadedData.EmpireState.StarReports["Pluto"].Name == "Pluto"); Assert.IsTrue(loadedData.EmpireState.StarReports.ContainsKey("Pluto") && loadedData.EmpireState.StarReports["Pluto"].Colonists == 25000); } catch (Exception e) { System.Windows.Forms.MessageBox.Show("Intel.cs SerialisationTestIntel() failed:" + Environment.NewLine + e.Message + Environment.NewLine + stringStream.ToString()); throw e; // fail the test } }
public void AddIntel(Intel _intel) { inv.Add(_intel); Debug.Log(_intel.Read()); }
public void SerialisationTestEmptyIntel() { StringWriter stringStream = new StringWriter(); try { // setup a test object Intel testData = new Intel(); // setup the file name string saveFileName = "IntelTest.xml"; // setup the streams MemoryStream memoryStream = new MemoryStream(); // Setup the XML document XmlDocument xmldoc = new XmlDocument(); Global.InitializeXmlDocument(xmldoc); // add the Intel to the document xmldoc.ChildNodes.Item(1).AppendChild(testData.ToXml(xmldoc)); xmldoc.Save(memoryStream); xmldoc.Save(stringStream); // Serialize to file if (TestControls.CreateFiles) { using (Stream fileStream = new FileStream(saveFileName, FileMode.Create)) { xmldoc.Save(fileStream); } } // deserialize Intel loadedData; xmldoc.RemoveAll(); if (TestControls.CreateFiles) { using (FileStream saveFileStream = new FileStream(saveFileName, FileMode.Open, FileAccess.Read)) { xmldoc.Load(saveFileStream); loadedData = new Intel(xmldoc); } } else { // move to start of memory stream memoryStream.Seek(0, SeekOrigin.Begin); xmldoc.Load(memoryStream); loadedData = new Intel(xmldoc); } // test if it worked // CheckTestIntel(loadedData); } catch (Exception e) { System.Windows.Forms.MessageBox.Show("Intel.cs SerialisationTestEmptyIntel() failed:" + Environment.NewLine + e.Message + Environment.NewLine + stringStream.ToString()); throw e; // fail the test } }
private void OnPlayerIntelChanging(Intel newIntel) { Unsubscribe(); }
private void _OnBrowseDone(CpContentDirectory sender, System.String ObjectID, Intel.UPNP.AV.CpContentDirectory.Enum_A_ARG_TYPE_BrowseFlag BrowseFlag, System.String Filter, System.UInt32 StartingIndex, System.UInt32 RequestedCount, System.String SortCriteria, System.String Result, System.UInt32 NumberReturned, System.UInt32 TotalMatches, System.UInt32 UpdateID, UPnPInvokeException e, object _Tag) { _RequestState state = (_RequestState) _Tag; if (e != null) { state.Callback(state.Server, e, null, state.Tag, null, NumberReturned, TotalMatches, UpdateID); } else { try { ArrayList al = CpMediaBuilder.BuildMediaBranches(Result); state.Callback(state.Server, e, null, state.Tag, (IUPnPMedia[]) al.ToArray(typeof(IUPnPMedia)), NumberReturned, TotalMatches, UpdateID); } catch (Exception parseError) { state.Callback(state.Server, e, parseError, state.Tag, null, NumberReturned, TotalMatches, UpdateID); } } }
public IBM() { cpu = new Intel(); hd = new WestDigit(); mb = new MSI865PE(); }
public ActionResult timkiemnangcao(int?page, string tim, string gia, string cpu) { Intel cpu1 = new Intel() { V = "all", D = "Tất cả" }; Intel cpu2 = new Intel() { V = "i3", D = "Core i3" }; Intel cpu3 = new Intel() { V = "i5", D = "Core i5" }; Intel cpu4 = new Intel() { V = "i7", D = "Core i7" }; Intel cpu5 = new Intel() { V = "pen", D = "Pentinum" }; Intel cpu6 = new Intel() { V = "adm", D = "ADM" }; ViewBag.core = new SelectList(new List <Intel> { cpu1, cpu2, cpu3, cpu4, cpu5, cpu6 }, "V", "D", cpu1.V); GiaTien gt1 = new GiaTien() { V = "100", D = "Tất cả" }; GiaTien gt2 = new GiaTien() { V = "10", D = "Dưới 10 triệu" }; GiaTien gt3 = new GiaTien() { V = "15", D = "Dưới 15 triệu" }; GiaTien gt4 = new GiaTien() { V = "20", D = "Dưới 20 triệu" }; GiaTien gt5 = new GiaTien() { V = "25", D = "Dưới 25 triệu" }; GiaTien gt6 = new GiaTien() { V = "26", D = "Trên 25 triệu" }; ViewBag.Gia = new SelectList(new List <GiaTien> { gt1, gt2, gt3, gt4, gt5, gt6 }, "V", "D", gt1.V); //ViewBag.ten = tim; //ViewBag.tien = gia; //ViewBag.cpu = cpu; if (tim != null) { if (gia == gt1.V && cpu == cpu1.V) { var kq = lt.Sanphams.Where(x => x.TenSP.Contains(tim)).OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8); ViewBag.Gia = new SelectList(new List <GiaTien> { gt1, gt2, gt3, gt4, gt5, gt6 }, "V", "D", gia); ViewBag.core = new SelectList(new List <Intel> { cpu1, cpu2, cpu3, cpu4, cpu5, cpu6 }, "V", "D", cpu); ViewBag.ten = tim; ViewBag.tien = gia; ViewBag.cpu = cpu; return(View(kq)); } if (cpu == cpu1.V) { if (gia == gt1.V) { var kq = lt.Sanphams.Where(x => x.TenSP.ToLower().Contains(tim.ToLower())) .OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8).OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8); ViewBag.Gia = new SelectList(new List <GiaTien> { gt1, gt2, gt3, gt4, gt5, gt6 }, "V", "D", gia); ViewBag.core = new SelectList(new List <Intel> { cpu1, cpu2, cpu3, cpu4, cpu5, cpu6 }, "V", "D", cpu); ViewBag.ten = tim; ViewBag.tien = gia; ViewBag.cpu = cpu; return(View(kq)); } if (gia == gt2.V) { var kq = lt.Sanphams.Where(x => x.TenSP.Contains(tim) && x.Giaban < 10000000). OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8); ViewBag.Gia = new SelectList(new List <GiaTien> { gt1, gt2, gt3, gt4, gt5, gt6 }, "V", "D", gia); ViewBag.core = new SelectList(new List <Intel> { cpu1, cpu2, cpu3, cpu4, cpu5, cpu6 }, "V", "D", cpu); ViewBag.ten = tim; ViewBag.tien = gia; ViewBag.cpu = cpu; return(View(kq)); } if (gia == gt3.V) { var kq = lt.Sanphams.Where(x => x.TenSP.Contains(tim) && x.Giaban >= 10000000 && x.Giaban < 15000000). OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8); ViewBag.Gia = new SelectList(new List <GiaTien> { gt1, gt2, gt3, gt4, gt5, gt6 }, "V", "D", gia); ViewBag.core = new SelectList(new List <Intel> { cpu1, cpu2, cpu3, cpu4, cpu5, cpu6 }, "V", "D", cpu); ViewBag.ten = tim; ViewBag.tien = gia; ViewBag.cpu = cpu; return(View(kq)); } if (gia == gt4.V) { var kq = lt.Sanphams.Where(x => x.TenSP.Contains(tim) && x.Giaban >= 15000000 && x.Giaban < 20000000). OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8); ViewBag.Gia = new SelectList(new List <GiaTien> { gt1, gt2, gt3, gt4, gt5, gt6 }, "V", "D", gia); ViewBag.core = new SelectList(new List <Intel> { cpu1, cpu2, cpu3, cpu4, cpu5, cpu6 }, "V", "D", cpu); ViewBag.ten = tim; ViewBag.tien = gia; ViewBag.cpu = cpu; return(View(kq)); } if (gia == gt5.V) { var kq = lt.Sanphams.Where(x => x.TenSP.Contains(tim) && x.Giaban >= 20000000 && x.Giaban < 25000000). OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8); ViewBag.Gia = new SelectList(new List <GiaTien> { gt1, gt2, gt3, gt4, gt5, gt6 }, "V", "D", gia); ViewBag.core = new SelectList(new List <Intel> { cpu1, cpu2, cpu3, cpu4, cpu5, cpu6 }, "V", "D", cpu); ViewBag.ten = tim; ViewBag.tien = gia; ViewBag.cpu = cpu; return(View(kq)); } if (gia == gt6.V) { var kq = lt.Sanphams.Where(x => x.TenSP.Contains(tim) && x.Giaban >= 25000000). OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8); ViewBag.Gia = new SelectList(new List <GiaTien> { gt1, gt2, gt3, gt4, gt5, gt6 }, "V", "D", gia); ViewBag.core = new SelectList(new List <Intel> { cpu1, cpu2, cpu3, cpu4, cpu5, cpu6 }, "V", "D", cpu); ViewBag.ten = tim; ViewBag.tien = gia; ViewBag.cpu = cpu; return(View(kq)); } } if (gia == gt1.V) { var kq = lt.Sanphams.Where(x => x.TenSP.ToLower().Contains(tim.ToLower()) && x.cpu.ToLower().Contains(cpu.ToLower())).OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8); ViewBag.Gia = new SelectList(new List <GiaTien> { gt1, gt2, gt3, gt4, gt5, gt6 }, "V", "D", gia); ViewBag.core = new SelectList(new List <Intel> { cpu1, cpu2, cpu3, cpu4, cpu5, cpu6 }, "V", "D", cpu); ViewBag.ten = tim; ViewBag.tien = gia; ViewBag.cpu = cpu; return(View(kq)); } if (gia == gt2.V) { var kq = lt.Sanphams.Where(x => x.TenSP.Contains(tim) && x.cpu.Contains(cpu) && x.Giaban < 10000000). OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8); ViewBag.Gia = new SelectList(new List <GiaTien> { gt1, gt2, gt3, gt4, gt5, gt6 }, "V", "D", gia); ViewBag.core = new SelectList(new List <Intel> { cpu1, cpu2, cpu3, cpu4, cpu5, cpu6 }, "V", "D", cpu); ViewBag.ten = tim; ViewBag.tien = gia; ViewBag.cpu = cpu; return(View(kq)); } if (gia == gt3.V) { var kq = lt.Sanphams.Where(x => x.TenSP.Contains(tim) && x.cpu.Contains(cpu) && x.Giaban >= 10000000 && x.Giaban < 15000000). OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8); ViewBag.Gia = new SelectList(new List <GiaTien> { gt1, gt2, gt3, gt4, gt5, gt6 }, "V", "D", gia); ViewBag.core = new SelectList(new List <Intel> { cpu1, cpu2, cpu3, cpu4, cpu5, cpu6 }, "V", "D", cpu); ViewBag.ten = tim; ViewBag.tien = gia; ViewBag.cpu = cpu; return(View(kq)); } if (gia == gt4.V) { var kq = lt.Sanphams.Where(x => x.TenSP.Contains(tim) && x.cpu.Contains(cpu) && x.Giaban >= 15000000 && x.Giaban < 20000000). OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8); ViewBag.Gia = new SelectList(new List <GiaTien> { gt1, gt2, gt3, gt4, gt5, gt6 }, "V", "D", gia); ViewBag.core = new SelectList(new List <Intel> { cpu1, cpu2, cpu3, cpu4, cpu5, cpu6 }, "V", "D", cpu); ViewBag.ten = tim; ViewBag.tien = gia; ViewBag.cpu = cpu; return(View(kq)); } if (gia == gt5.V) { var kq = lt.Sanphams.Where(x => x.TenSP.Contains(tim) && x.cpu.Contains(cpu) && x.Giaban >= 20000000 && x.Giaban < 25000000). OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8); ViewBag.Gia = new SelectList(new List <GiaTien> { gt1, gt2, gt3, gt4, gt5, gt6 }, "V", "D", gia); ViewBag.core = new SelectList(new List <Intel> { cpu1, cpu2, cpu3, cpu4, cpu5, cpu6 }, "V", "D", cpu); ViewBag.ten = tim; ViewBag.tien = gia; ViewBag.cpu = cpu; return(View(kq)); } if (gia == gt6.V) { var kq = lt.Sanphams.Where(x => x.TenSP.Contains(tim) && x.cpu.Contains(cpu) && x.Giaban >= 25000000). OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8); ViewBag.Gia = new SelectList(new List <GiaTien> { gt1, gt2, gt3, gt4, gt5, gt6 }, "V", "D", gia); ViewBag.core = new SelectList(new List <Intel> { cpu1, cpu2, cpu3, cpu4, cpu5, cpu6 }, "V", "D", cpu); ViewBag.ten = tim; ViewBag.tien = gia; ViewBag.cpu = cpu; return(View(kq)); } } else if (string.IsNullOrEmpty(tim)) { if (gia == gt1.V && cpu == cpu1.V) { var kq = lt.Sanphams.OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8); ViewBag.Gia = new SelectList(new List <GiaTien> { gt1, gt2, gt3, gt4, gt5, gt6 }, "V", "D", gia); ViewBag.core = new SelectList(new List <Intel> { cpu1, cpu2, cpu3, cpu4, cpu5, cpu6 }, "V", "D", cpu); ViewBag.ten = tim; ViewBag.tien = gia; return(View(kq)); } if (cpu == cpu1.V) { if (gia == gt1.V) { var kq = lt.Sanphams.OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8); ViewBag.Gia = new SelectList(new List <GiaTien> { gt1, gt2, gt3, gt4, gt5, gt6 }, "V", "D", gia); ViewBag.core = new SelectList(new List <Intel> { cpu1, cpu2, cpu3, cpu4, cpu5, cpu6 }, "V", "D", cpu); ViewBag.ten = tim; ViewBag.tien = gia; ViewBag.cpu = cpu; return(View(kq)); } if (gia == gt2.V) { var kq = lt.Sanphams.Where(x => x.Giaban < 10000000). OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8); ViewBag.Gia = new SelectList(new List <GiaTien> { gt1, gt2, gt3, gt4, gt5, gt6 }, "V", "D", gia); ViewBag.core = new SelectList(new List <Intel> { cpu1, cpu2, cpu3, cpu4, cpu5, cpu6 }, "V", "D", cpu); ViewBag.ten = tim; ViewBag.tien = gia; ViewBag.cpu = cpu; return(View(kq)); } if (gia == gt3.V) { var kq = lt.Sanphams.Where(x => x.Giaban >= 10000000 && x.Giaban < 15000000). OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8); ViewBag.Gia = new SelectList(new List <GiaTien> { gt1, gt2, gt3, gt4, gt5, gt6 }, "V", "D", gia); ViewBag.core = new SelectList(new List <Intel> { cpu1, cpu2, cpu3, cpu4, cpu5, cpu6 }, "V", "D", cpu); ViewBag.ten = tim; ViewBag.tien = gia; ViewBag.cpu = cpu; return(View(kq)); } if (gia == gt4.V) { var kq = lt.Sanphams.Where(x => x.Giaban >= 15000000 && x.Giaban < 20000000). OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8); ViewBag.Gia = new SelectList(new List <GiaTien> { gt1, gt2, gt3, gt4, gt5, gt6 }, "V", "D", gia); ViewBag.core = new SelectList(new List <Intel> { cpu1, cpu2, cpu3, cpu4, cpu5, cpu6 }, "V", "D", cpu); ViewBag.ten = tim; ViewBag.tien = gia; ViewBag.cpu = cpu; return(View(kq)); } if (gia == gt5.V) { var kq = lt.Sanphams.Where(x => x.Giaban >= 20000000 && x.Giaban < 25000000). OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8); ViewBag.Gia = new SelectList(new List <GiaTien> { gt1, gt2, gt3, gt4, gt5, gt6 }, "V", "D", gia); ViewBag.core = new SelectList(new List <Intel> { cpu1, cpu2, cpu3, cpu4, cpu5, cpu6 }, "V", "D", cpu); ViewBag.ten = tim; ViewBag.tien = gia; ViewBag.cpu = cpu; return(View(kq)); } if (gia == gt6.V) { var kq = lt.Sanphams.Where(x => x.Giaban >= 25000000). OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8); ViewBag.Gia = new SelectList(new List <GiaTien> { gt1, gt2, gt3, gt4, gt5, gt6 }, "V", "D", gia); ViewBag.core = new SelectList(new List <Intel> { cpu1, cpu2, cpu3, cpu4, cpu5, cpu6 }, "V", "D", cpu); ViewBag.ten = tim; ViewBag.tien = gia; ViewBag.cpu = cpu; return(View(kq)); } } if (gia == gt1.V) { var kq = lt.Sanphams.Where(x => x.cpu.ToLower().Contains(cpu.ToLower())) .OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8); ViewBag.Gia = new SelectList(new List <GiaTien> { gt1, gt2, gt3, gt4, gt5, gt6 }, "V", "D", gia); ViewBag.core = new SelectList(new List <Intel> { cpu1, cpu2, cpu3, cpu4, cpu5, cpu6 }, "V", "D", cpu); ViewBag.ten = tim; ViewBag.tien = gia; ViewBag.cpu = cpu; return(View(kq)); } if (gia == gt2.V) { var kq = lt.Sanphams.Where(x => x.Giaban < 10000000 && x.cpu.Contains(cpu)). OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8); ViewBag.Gia = new SelectList(new List <GiaTien> { gt1, gt2, gt3, gt4, gt5, gt6 }, "V", "D", gia); ViewBag.core = new SelectList(new List <Intel> { cpu1, cpu2, cpu3, cpu4, cpu5, cpu6 }, "V", "D", cpu); ViewBag.ten = tim; ViewBag.tien = gia; ViewBag.cpu = cpu; return(View(kq)); } if (gia == gt3.V) { var kq = lt.Sanphams.Where(x => x.Giaban >= 10000000 && x.Giaban < 15000000 && x.cpu.Contains(cpu)). OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8); ViewBag.Gia = new SelectList(new List <GiaTien> { gt1, gt2, gt3, gt4, gt5, gt6 }, "V", "D", gia); ViewBag.core = new SelectList(new List <Intel> { cpu1, cpu2, cpu3, cpu4, cpu5, cpu6 }, "V", "D", cpu); ViewBag.ten = tim; ViewBag.tien = gia; ViewBag.cpu = cpu; return(View(kq)); } if (gia == gt4.V) { var kq = lt.Sanphams.Where(x => x.Giaban >= 15000000 && x.Giaban < 20000000 && x.cpu.Contains(cpu)). OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8); ViewBag.Gia = new SelectList(new List <GiaTien> { gt1, gt2, gt3, gt4, gt5, gt6 }, "V", "D", gia); ViewBag.core = new SelectList(new List <Intel> { cpu1, cpu2, cpu3, cpu4, cpu5, cpu6 }, "V", "D", cpu); ViewBag.ten = tim; ViewBag.tien = gia; ViewBag.cpu = cpu; return(View(kq)); } if (gia == gt5.V) { var kq = lt.Sanphams.Where(x => x.Giaban >= 20000000 && x.Giaban < 25000000 && x.cpu.Contains(cpu)). OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8); ViewBag.Gia = new SelectList(new List <GiaTien> { gt1, gt2, gt3, gt4, gt5, gt6 }, "V", "D", gia); ViewBag.core = new SelectList(new List <Intel> { cpu1, cpu2, cpu3, cpu4, cpu5, cpu6 }, "V", "D", cpu); ViewBag.ten = tim; ViewBag.tien = gia; ViewBag.cpu = cpu; return(View(kq)); } if (gia == gt6.V) { var kq = lt.Sanphams.Where(x => x.Giaban >= 25000000 && x.cpu.Contains(cpu)). OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8); ViewBag.Gia = new SelectList(new List <GiaTien> { gt1, gt2, gt3, gt4, gt5, gt6 }, "V", "D", gia); ViewBag.core = new SelectList(new List <Intel> { cpu1, cpu2, cpu3, cpu4, cpu5, cpu6 }, "V", "D", cpu); ViewBag.ten = tim; ViewBag.tien = gia; ViewBag.cpu = cpu; return(View(kq)); } } return(View()); }
public ActionResult timkiemnangcao(FormCollection form, int?page, int?pagesize) { var tim = form["ten"]; var gia = form["gia"]; var cpu = form["core"]; GiaTien gt1 = new GiaTien() { V = "100", D = "Tất cả" }; GiaTien gt2 = new GiaTien() { V = "10", D = "Dưới 10 triệu" }; GiaTien gt3 = new GiaTien() { V = "15", D = "Dưới 15 triệu" }; GiaTien gt4 = new GiaTien() { V = "20", D = "Dưới 20 triệu" }; GiaTien gt5 = new GiaTien() { V = "25", D = "Dưới 25 triệu" }; GiaTien gt6 = new GiaTien() { V = "26", D = "Trên 25 triệu" }; ViewBag.Gia = new SelectList(new List <GiaTien> { gt1, gt2, gt3, gt4, gt5, gt6 }, "V", "D", gt4.V); Intel cpu1 = new Intel() { V = "all", D = "Tất cả" }; Intel cpu2 = new Intel() { V = "i3", D = "Core i3" }; Intel cpu3 = new Intel() { V = "i5", D = "Core i5" }; Intel cpu4 = new Intel() { V = "i7", D = "Core i7" }; Intel cpu5 = new Intel() { V = "pen", D = "Pentinum" }; Intel cpu6 = new Intel() { V = "adm", D = "ADM" }; ViewBag.core = new SelectList(new List <Intel> { cpu1, cpu2, cpu3, cpu4, cpu5, cpu6 }, "V", "D", cpu1.V); if (tim.Count() == 0 && gia.Count() > 0) { if (form["gia"] == gt1.V && form["core"] == cpu1.V) { var kq = lt.Sanphams.OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8); ViewBag.Gia = new SelectList(new List <GiaTien> { gt1, gt2, gt3, gt4, gt5, gt6 }, "V", "D", gia); ViewBag.core = new SelectList(new List <Intel> { cpu1, cpu2, cpu3, cpu4, cpu5, cpu6 }, "V", "D", cpu); ViewBag.ten = tim; ViewBag.tien = gia; ViewBag.cpu = cpu; return(View(kq)); } if (form["core"] == cpu1.V) { if (form["gia"] == gt1.V) { var kq = lt.Sanphams .OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8); ViewBag.Gia = new SelectList(new List <GiaTien> { gt1, gt2, gt3, gt4, gt5, gt6 }, "V", "D", gia); ViewBag.core = new SelectList(new List <Intel> { cpu1, cpu2, cpu3, cpu4, cpu5, cpu6 }, "V", "D", cpu); ViewBag.ten = tim; ViewBag.tien = gia; ViewBag.cpu = cpu; return(View(kq)); } if (form["gia"] == gt2.V) { var kq = lt.Sanphams.Where(x => x.Giaban < 10000000). OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8); ViewBag.Gia = new SelectList(new List <GiaTien> { gt1, gt2, gt3, gt4, gt5, gt6 }, "V", "D", gia); ViewBag.core = new SelectList(new List <Intel> { cpu1, cpu2, cpu3, cpu4, cpu5, cpu6 }, "V", "D", cpu); ViewBag.ten = tim; ViewBag.tien = gia; ViewBag.cpu = cpu; return(View(kq)); } if (form["gia"] == gt3.V) { var kq = lt.Sanphams.Where(x => x.Giaban >= 10000000 && x.Giaban < 15000000). OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8); ViewBag.Gia = new SelectList(new List <GiaTien> { gt1, gt2, gt3, gt4, gt5, gt6 }, "V", "D", gia); ViewBag.core = new SelectList(new List <Intel> { cpu1, cpu2, cpu3, cpu4, cpu5, cpu6 }, "V", "D", cpu); ViewBag.ten = tim; ViewBag.tien = gia; ViewBag.cpu = cpu; return(View(kq)); } if (form["gia"] == gt4.V) { var kq = lt.Sanphams.Where(x => x.Giaban >= 15000000 && x.Giaban < 20000000). OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8); ViewBag.Gia = new SelectList(new List <GiaTien> { gt1, gt2, gt3, gt4, gt5, gt6 }, "V", "D", gia); ViewBag.core = new SelectList(new List <Intel> { cpu1, cpu2, cpu3, cpu4, cpu5, cpu6 }, "V", "D", cpu); ViewBag.ten = tim; ViewBag.tien = gia; ViewBag.cpu = cpu; return(View(kq)); } if (form["gia"] == gt5.V) { var kq = lt.Sanphams.Where(x => x.Giaban >= 20000000 && x.Giaban < 25000000). OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8); ViewBag.Gia = new SelectList(new List <GiaTien> { gt1, gt2, gt3, gt4, gt5, gt6 }, "V", "D", gia); ViewBag.core = new SelectList(new List <Intel> { cpu1, cpu2, cpu3, cpu4, cpu5, cpu6 }, "V", "D", cpu); ViewBag.ten = tim; ViewBag.tien = gia; ViewBag.cpu = cpu; return(View(kq)); } if (form["gia"] == gt6.V) { var kq = lt.Sanphams.Where(x => x.Giaban >= 25000000). OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8); ViewBag.Gia = new SelectList(new List <GiaTien> { gt1, gt2, gt3, gt4, gt5, gt6 }, "V", "D", gia); ViewBag.core = new SelectList(new List <Intel> { cpu1, cpu2, cpu3, cpu4, cpu5, cpu6 }, "V", "D", cpu); ViewBag.ten = tim; ViewBag.tien = gia; ViewBag.cpu = cpu; return(View(kq)); } } if (form["gia"] == gt1.V) { var kq = lt.Sanphams.Where(x => x.cpu.ToLower().Contains(cpu.ToLower())) .OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8); ViewBag.Gia = new SelectList(new List <GiaTien> { gt1, gt2, gt3, gt4, gt5, gt6 }, "V", "D", gia); ViewBag.core = new SelectList(new List <Intel> { cpu1, cpu2, cpu3, cpu4, cpu5, cpu6 }, "V", "D", cpu); ViewBag.ten = tim; ViewBag.tien = gia; ViewBag.cpu = cpu; return(View(kq)); } if (form["gia"] == gt2.V) { var kq = lt.Sanphams.Where(x => x.Giaban < 10000000 && x.cpu.Contains(cpu)).OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8); ViewBag.Gia = new SelectList(new List <GiaTien> { gt1, gt2, gt3, gt4, gt5, gt6 }, "V", "D", gia); ViewBag.core = new SelectList(new List <Intel> { cpu1, cpu2, cpu3, cpu4, cpu5, cpu6 }, "V", "D", cpu); ViewBag.ten = tim; ViewBag.tien = gia; ViewBag.cpu = cpu; return(View(kq)); } if (form["gia"] == gt3.V) { var kq = lt.Sanphams.Where(x => x.Giaban >= 10000000 && x.Giaban < 15000000 && x.cpu.Contains(cpu)). OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8); ViewBag.Gia = new SelectList(new List <GiaTien> { gt1, gt2, gt3, gt4, gt5, gt6 }, "V", "D", gia); ViewBag.core = new SelectList(new List <Intel> { cpu1, cpu2, cpu3, cpu4, cpu5, cpu6 }, "V", "D", cpu); ViewBag.ten = tim; ViewBag.tien = gia; ViewBag.cpu = cpu; return(View(kq)); } if (form["gia"] == gt4.V) { var kq = lt.Sanphams.Where(x => x.Giaban >= 15000000 && x.Giaban < 20000000 && x.cpu.Contains(cpu)) .OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8); ViewBag.Gia = new SelectList(new List <GiaTien> { gt1, gt2, gt3, gt4, gt5, gt6 }, "V", "D", gia); ViewBag.core = new SelectList(new List <Intel> { cpu1, cpu2, cpu3, cpu4, cpu5, cpu6 }, "V", "D", cpu); ViewBag.ten = tim; ViewBag.tien = gia; ViewBag.cpu = cpu; return(View(kq)); } if (form["gia"] == gt5.V) { var kq = lt.Sanphams.Where(x => x.Giaban >= 20000000 && x.Giaban < 25000000 && x.cpu.Contains(cpu)) .OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8); ViewBag.Gia = new SelectList(new List <GiaTien> { gt1, gt2, gt3, gt4, gt5, gt6 }, "V", "D", gia); ViewBag.core = new SelectList(new List <Intel> { cpu1, cpu2, cpu3, cpu4, cpu5, cpu6 }, "V", "D", cpu); ViewBag.ten = tim; ViewBag.tien = gia; ViewBag.cpu = cpu; return(View(kq)); } if (form["gia"] == gt6.V) { var kq = lt.Sanphams.Where(x => x.Giaban >= 25000000 && x.cpu.Contains(cpu)) .OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8); ViewBag.Gia = new SelectList(new List <GiaTien> { gt1, gt2, gt3, gt4, gt5, gt6 }, "V", "D", gia); ViewBag.core = new SelectList(new List <Intel> { cpu1, cpu2, cpu3, cpu4, cpu5, cpu6 }, "V", "D", cpu); ViewBag.ten = tim; ViewBag.tien = gia; ViewBag.cpu = cpu; return(View(kq)); } } else if (tim.Count() > 0) { if (form["gia"] == gt1.V && form["core"] == cpu1.V) { var kq = lt.Sanphams.Where(x => x.TenSP.Contains(tim)).OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8); ViewBag.Gia = new SelectList(new List <GiaTien> { gt1, gt2, gt3, gt4, gt5, gt6 }, "V", "D", gia); ViewBag.core = new SelectList(new List <Intel> { cpu1, cpu2, cpu3, cpu4, cpu5, cpu6 }, "V", "D", cpu); ViewBag.ten = tim; ViewBag.tien = gia; ViewBag.cpu = cpu; return(View(kq)); } if (form["core"] == cpu1.V) { if (form["gia"] == gt1.V) { var kq = lt.Sanphams.Where(x => x.TenSP.ToLower().Contains(tim.ToLower())) .OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8); ViewBag.Gia = new SelectList(new List <GiaTien> { gt1, gt2, gt3, gt4, gt5, gt6 }, "V", "D", gia); ViewBag.core = new SelectList(new List <Intel> { cpu1, cpu2, cpu3, cpu4, cpu5, cpu6 }, "V", "D", cpu); ViewBag.ten = tim; ViewBag.tien = gia; ViewBag.cpu = cpu; return(View(kq)); } if (form["gia"] == gt2.V) { var kq = lt.Sanphams.Where(x => x.TenSP.Contains(tim) && x.Giaban < 10000000). OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8); ViewBag.Gia = new SelectList(new List <GiaTien> { gt1, gt2, gt3, gt4, gt5, gt6 }, "V", "D", gia); ViewBag.core = new SelectList(new List <Intel> { cpu1, cpu2, cpu3, cpu4, cpu5, cpu6 }, "V", "D", cpu); ViewBag.ten = tim; ViewBag.tien = gia; ViewBag.cpu = cpu; return(View(kq)); } if (form["gia"] == gt3.V) { var kq = lt.Sanphams.Where(x => x.TenSP.Contains(tim) && x.Giaban >= 10000000 && x.Giaban < 15000000). OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8); ViewBag.Gia = new SelectList(new List <GiaTien> { gt1, gt2, gt3, gt4, gt5, gt6 }, "V", "D", gia); ViewBag.core = new SelectList(new List <Intel> { cpu1, cpu2, cpu3, cpu4, cpu5, cpu6 }, "V", "D", cpu); ViewBag.ten = tim; ViewBag.tien = gia; ViewBag.cpu = cpu; return(View(kq)); } if (form["gia"] == gt4.V) { var kq = lt.Sanphams.Where(x => x.TenSP.Contains(tim) && x.Giaban >= 15000000 && x.Giaban < 20000000). OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8); ViewBag.Gia = new SelectList(new List <GiaTien> { gt1, gt2, gt3, gt4, gt5, gt6 }, "V", "D", gia); ViewBag.core = new SelectList(new List <Intel> { cpu1, cpu2, cpu3, cpu4, cpu5, cpu6 }, "V", "D", cpu); ViewBag.ten = tim; ViewBag.tien = gia; ViewBag.cpu = cpu; return(View(kq)); } if (form["gia"] == gt5.V) { var kq = lt.Sanphams.Where(x => x.TenSP.Contains(tim) && x.Giaban >= 20000000 && x.Giaban < 25000000). OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8); ViewBag.Gia = new SelectList(new List <GiaTien> { gt1, gt2, gt3, gt4, gt5, gt6 }, "V", "D", gia); ViewBag.core = new SelectList(new List <Intel> { cpu1, cpu2, cpu3, cpu4, cpu5, cpu6 }, "V", "D", cpu); ViewBag.ten = tim; ViewBag.tien = gia; ViewBag.cpu = cpu; return(View(kq)); } if (form["gia"] == gt6.V) { var kq = lt.Sanphams.Where(x => x.TenSP.Contains(tim) && x.Giaban >= 25000000). OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8); ViewBag.Gia = new SelectList(new List <GiaTien> { gt1, gt2, gt3, gt4, gt5, gt6 }, "V", "D", gia); ViewBag.core = new SelectList(new List <Intel> { cpu1, cpu2, cpu3, cpu4, cpu5, cpu6 }, "V", "D", cpu); ViewBag.ten = tim; ViewBag.tien = gia; ViewBag.cpu = cpu; return(View(kq)); } } if (form["gia"] == gt1.V) { var kq = lt.Sanphams.Where(x => x.TenSP.ToLower().Contains(tim.ToLower()) && x.cpu.ToLower().Contains(cpu.ToLower())).OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8); ViewBag.Gia = new SelectList(new List <GiaTien> { gt1, gt2, gt3, gt4, gt5, gt6 }, "V", "D", gia); ViewBag.core = new SelectList(new List <Intel> { cpu1, cpu2, cpu3, cpu4, cpu5, cpu6 }, "V", "D", cpu); ViewBag.ten = tim; ViewBag.tien = gia; ViewBag.cpu = cpu; return(View(kq)); } if (form["gia"] == gt2.V) { var kq = lt.Sanphams.Where(x => x.TenSP.Contains(tim) && x.cpu.Contains(cpu) && x.Giaban < 10000000) .OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8); ViewBag.Gia = new SelectList(new List <GiaTien> { gt1, gt2, gt3, gt4, gt5, gt6 }, "V", "D", gia); ViewBag.core = new SelectList(new List <Intel> { cpu1, cpu2, cpu3, cpu4, cpu5, cpu6 }, "V", "D", cpu); ViewBag.ten = tim; ViewBag.tien = gia; ViewBag.cpu = cpu; return(View(kq)); } if (form["gia"] == gt3.V) { var kq = lt.Sanphams.Where(x => x.TenSP.Contains(tim) && x.cpu.Contains(cpu) && x.Giaban >= 10000000 && x.Giaban < 15000000) .OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8); ViewBag.Gia = new SelectList(new List <GiaTien> { gt1, gt2, gt3, gt4, gt5, gt6 }, "V", "D", gia); ViewBag.core = new SelectList(new List <Intel> { cpu1, cpu2, cpu3, cpu4, cpu5, cpu6 }, "V", "D", cpu); ViewBag.ten = tim; ViewBag.tien = gia; ViewBag.cpu = cpu; return(View(kq)); } if (form["gia"] == gt4.V) { var kq = lt.Sanphams.Where(x => x.TenSP.Contains(tim) && x.cpu.Contains(cpu) && x.Giaban >= 15000000 && x.Giaban < 20000000) .OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8); ViewBag.Gia = new SelectList(new List <GiaTien> { gt1, gt2, gt3, gt4, gt5, gt6 }, "V", "D", gia); ViewBag.core = new SelectList(new List <Intel> { cpu1, cpu2, cpu3, cpu4, cpu5, cpu6 }, "V", "D", cpu); ViewBag.ten = tim; ViewBag.tien = gia; ViewBag.cpu = cpu; return(View(kq)); } if (form["gia"] == gt5.V) { var kq = lt.Sanphams.Where(x => x.TenSP.Contains(tim) && x.cpu.Contains(cpu) && x.Giaban >= 20000000 && x.Giaban < 25000000) .OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8); ViewBag.Gia = new SelectList(new List <GiaTien> { gt1, gt2, gt3, gt4, gt5, gt6 }, "V", "D", gia); ViewBag.core = new SelectList(new List <Intel> { cpu1, cpu2, cpu3, cpu4, cpu5, cpu6 }, "V", "D", cpu); ViewBag.ten = tim; ViewBag.tien = gia; ViewBag.cpu = cpu; return(View(kq)); } if (form["gia"] == gt6.V) { var kq = lt.Sanphams.Where(x => x.TenSP.Contains(tim) && x.cpu.Contains(cpu) && x.Giaban >= 25000000) .OrderBy(x => x.Giaban).ToPagedList(page ?? 1, 8); ViewBag.Gia = new SelectList(new List <GiaTien> { gt1, gt2, gt3, gt4, gt5, gt6 }, "V", "D", gia); ViewBag.core = new SelectList(new List <Intel> { cpu1, cpu2, cpu3, cpu4, cpu5, cpu6 }, "V", "D", cpu); ViewBag.ten = tim; ViewBag.tien = gia; ViewBag.cpu = cpu; return(View(kq)); } } return(View()); }
static void Main(string[] args) { var starter = new Intel(); starter.start(args); }
/// <summary> /// Load <see cref="Intel">ClientState</see> from an xml document. /// </summary> /// <param name="xmldoc">Produced using XmlDocument.Load(filename).</param> public ClientData(XmlDocument xmldoc) { XmlNode xmlnode = xmldoc.DocumentElement; XmlNode textNode; while (xmlnode != null) { try { switch (xmlnode.Name.ToLower()) { case "root": xmlnode = xmlnode.FirstChild; continue; case "clientstate": xmlnode = xmlnode.FirstChild; continue; case "empiredata": EmpireState = new EmpireData(xmlnode); break; case "commands": textNode = xmlnode.FirstChild; while (textNode != null) { switch (textNode.Attributes["Type"].Value.ToString().ToLower()) { case "research": Commands.Push(new ResearchCommand(textNode)); break; } textNode = textNode.NextSibling; } break; case "message": Messages.Add(new Message(xmlnode)); break; case "intel": // THIS HAS TO GO! InputTurn = new Intel(); InputTurn.LoadFromXmlNode(xmlnode); break; case "firstturn": FirstTurn = bool.Parse(xmlnode.FirstChild.Value); break; case "gamefolder": GameFolder = xmlnode.FirstChild.Value; break; case "statepathname": StatePathName = xmlnode.FirstChild.Value; break; } xmlnode = xmlnode.NextSibling; } catch (Exception e) { Report.FatalError(e.Message + "\n Details: \n" + e); } } }
/// <summary> /// Save the turn data. /// </summary> /// <remarks> /// We have to be very careful that we have a consistent and self-contained data set in the turn file. /// For example, we write out "AllStars" but turnData.AllStars is not the same as stateData.AllStars. /// So make sure any pointers to AllStars refer to the copy in turnData otherwise we'll get /// duplicated (but separate) star objects. /// </remarks> public void WriteIntel() { foreach (EmpireData empire in serverState.AllEmpires.Values) { turnData = new Intel(); turnData.AllMinefields = serverState.AllMinefields; turnData.EmpireState = serverState.AllEmpires[empire.Id]; // Copy any messages foreach (Message message in serverState.AllMessages) { if (message.Audience == Global.Everyone || message.Audience == empire.Id) { turnData.Messages.Add(message); } } // Don't try and generate a scores report on the very start of a new // game. if (serverState.TurnYear > Global.StartingYear) { turnData.AllScores = scores.GetScores(); } else { turnData.AllScores = new List <ScoreRecord>(); } serverState.GameFolder = FileSearcher.GetFolder(Global.ServerFolderKey, Global.ServerFolderName); if (serverState.GameFolder == null) { Report.Error("Intel Writer: WriteIntel() - Unable to create file \"Nova.intel\"."); return; } string turnFileName = Path.Combine(serverState.GameFolder, empire.Race.Name + Global.IntelExtension); // Write out the intel file, as xml bool waitForFile = false; double waitTime = 0.0; // seconds do { try { using (Stream turnFile = new FileStream(turnFileName /*+ ".xml"*/, FileMode.Create)) { // Setup the XML document XmlDocument xmldoc = new XmlDocument(); Global.InitializeXmlDocument(xmldoc); // add the Intel to the document xmldoc.ChildNodes.Item(1).AppendChild(turnData.ToXml(xmldoc)); xmldoc.Save(turnFile); } waitForFile = false; } catch (System.IO.IOException) { // IOException. Is the file locked? Try waiting. if (waitTime < Global.TotalFileWaitTime) { waitForFile = true; System.Threading.Thread.Sleep(Global.FileWaitRetryTime); waitTime += 0.1; } else { // Give up, maybe something else is wrong? throw; } } }while (waitForFile); } }
private void Sink_OnBrowse(CpMediaServer server, System.String ObjectID, Intel.UPNP.AV.CpContentDirectory.Enum_A_ARG_TYPE_BrowseFlag BrowseFlag, System.String Filter, System.UInt32 StartingIndex, System.UInt32 RequestedCount, System.String SortCriteria, UPnPInvokeException e, Exception parseError, object _Tag, IUPnPMedia[] Result, System.UInt32 NumberReturned, System.UInt32 TotalMatches, System.UInt32 UpdateID) { if (server == this.m_Server) { if (ObjectID == this.m_Context) { if (_Tag == this.m_Container) { if ((e != null) || (parseError != null)) { //error encountered } else { // add children this.m_Children.AddRange(Result); this.m_Container.AddObjects(Result, true); if (this.OnIncrementalUpdate != null) { this.OnIncrementalUpdate(this, Result); } if ( ((this.m_Children.Count == TotalMatches) && (NumberReturned > 0)) || ((TotalMatches == 0) && (NumberReturned > 0)) ) { // more items to come this.m_CurrentIndex = NumberReturned; DoNextBrowse(); } else { lock (this) { // no more items, prune children from m_Container ArrayList remove = new ArrayList(); foreach (IUPnPMedia m1 in this.m_Container.CompleteList) { bool found = false; foreach (IUPnPMedia m2 in this.m_Children) { if (m1 == m2) { found = true; break; } } if (found == false) { remove.Add(m1); } } this.m_Container.RemoveObjects(remove); } if (this.OnRefreshComplete != null) { IUPnPMedia[] list = (IUPnPMedia[]) this.m_Children.ToArray(typeof(IUPnPMedia)); this.OnRefreshComplete(this, list); } } } } } } }
public IntelPresentation(Intel intel) { this.Intel = intel; }
public SearchResult Search(string query, List <object> extras) { if (Config.Instance.Selected_API != null) { engineInfo = Config.Instance.Selected_API; } else { engineInfo = Config.Instance.Apis[0]; } google_api_key = engineInfo.Api_key; if (Config.Instance.Selected_Engine != null) { google_cx_engine = Config.Instance.Selected_Engine; } else { google_cx_engine = engineInfo.Engines[0]; } MAX_RESULTS = Config.Instance.Max_results; MillisecondsTimeout = Config.Instance.MillisecondsTimeout; //System.Threading.Thread.Sleep(5000); string json = string.Empty; dynamic jsonData; int total_results = -1; int start_index = -1; int count = -1; List <Intel> intels = new List <Intel>(); SearchResult searchResult; string message = "Searching..."; Dictionary <string, List <Intel> > filtered_intel = new Dictionary <string, List <Intel> >(); List <TreeNode> intel_nodes = new List <TreeNode>(); foreach (string filter in google_cx_engine.Filters) { filtered_intel.Add(filter, new List <Intel>()); } do { string url = @"https://www.googleapis.com/customsearch/v1?" + "key=" + google_api_key + "&" + "cx=" + google_cx_engine.Cx + "&" + "q=" + HttpUtility.UrlEncode(query) + Config.Instance.ExtraParams; System.Threading.Thread.Sleep(MillisecondsTimeout); try { if (start_index == -1) { json = request_api(url); } else { string newurl = url + "&start=" + start_index; json = request_api(newurl); } } catch (WebException e) { message += Environment.NewLine; message += e.Message; message += Environment.NewLine; message += Lang.Eng.attemping_different_api; message += Environment.NewLine; if (e.Message.Contains("(429) Too Many Requests.") && Config.Instance.Apis.Count > 1) { Config.Instance.Apis.Remove(engineInfo); engineInfo = Config.Instance.Apis[0]; google_api_key = engineInfo.Api_key; google_cx_engine = engineInfo.Engines[0]; url = @"https://www.googleapis.com/customsearch/v1?" + "key=" + google_api_key + "&" + "cx=" + google_cx_engine.Cx + "&" + "q=" + HttpUtility.UrlEncode(query) + Config.Instance.ExtraParams; try { json = request_api(url); } catch (WebException e2) { searchResult = new SearchResult(intels, DateTime.Now, intels.Count, Lang.Eng.title, Status_Code.ERROR, e2.Message); return(searchResult); } } } if (!json.Equals(String.Empty)) { jsonData = JsonConvert.DeserializeObject(json); start_index = jsonData.queries.request[0].startIndex; count = jsonData.queries.request[0].count; total_results = jsonData.searchInformation.totalResults; if (total_results > MAX_RESULTS) { total_results = MAX_RESULTS; } if (jsonData.items != null) { foreach (var item in jsonData.items) { Result result = new Result { Title = item.title, Link = item.link, Snippet = item.snippet, }; Intel intel = new Intel() { Title = item.title, Description = item.snippet, Uri = item.link, Extras = new ArrayList(), From_module = Lang.Eng.title, Timestamp = DateTime.Now, }; intel.Fix_Characters(); if (google_cx_engine.Filters.Count > 0) { foreach (string filter in google_cx_engine.Filters) { if (intel.Uri.ToString().Contains(filter.ToLower())) { filtered_intel[filter].Add(intel); break; } } } if (Config.Instance.Metadata) { try { dynamic metadata = item.pagemap.metatags[0]; List <TreeNode> metadata_node = new List <TreeNode>(); foreach (var meta_item in metadata) { String value = Convert.ToString(meta_item); metadata_node.Add(new TreeNode(value)); } result.Metadata = new TreeNode("Metadata", metadata_node.ToArray()); intel.Extras.Add(result.Metadata); } catch (Exception e) { logMessage("No Metadata for " + intel.Title); } } intels.Add(intel); result.Fix_characters(); results.Add(result); } } start_index += count; } else { //logMessage(Lang.Eng.empty_response); message += Environment.NewLine; message += Lang.Eng.empty_response; message += Environment.NewLine; message += Lang.Eng.completed; searchResult = new SearchResult(intels, DateTime.Now, intels.Count, Lang.Eng.title, Status_Code.ERROR, message); return(searchResult); } } while (start_index < total_results); message += Environment.NewLine; message += Lang.Eng.completed; List <TreeNode> filtered_Tree_nodes = new List <TreeNode>(); foreach (KeyValuePair <string, List <Intel> > kvp in filtered_intel) { List <TreeNode> single_filter_tree_nodes = new List <TreeNode>(); foreach (Intel intel in kvp.Value) { TreeNode meta = new TreeNode("Metadata"); if (typeof(ArrayList).IsInstanceOfType(intel.Extras)) { if (((ArrayList)intel.Extras).Count > 0) { meta = (TreeNode)intel.Extras[0]; } } TreeNode[] intel_node_array = new TreeNode[] { new TreeNode(intel.Description), new TreeNode(intel.Uri.ToString()), new TreeNode(intel.Timestamp.ToString()), meta, }; TreeNode intel_node = new TreeNode(intel.Title, intel_node_array); single_filter_tree_nodes.Add(intel_node); } filtered_Tree_nodes.Add(new TreeNode(kvp.Key, single_filter_tree_nodes.ToArray())); /* * Console.WriteLine("Key = {0}, Value = {1}", * kvp.Key, kvp.Value);*/ } if (filtered_Tree_nodes.Count > 0) { TreeNode module_node = new TreeNode(Lang.Eng.title, filtered_Tree_nodes.ToArray()); searchResult = new SearchResult(module_node, DateTime.Now, null, module_node.GetNodeCount(true), Lang.Eng.title, Status_Code.DONE, message); } else { searchResult = new SearchResult(intels, DateTime.Now, intels.Count, Lang.Eng.title, Status_Code.DONE, message); } return(searchResult); }
public void NotifyLogMessage(LogMessage message) { if (!Active) { return; } foreach (string searchText in MatchStrings) { Match match = Regex.Match(message.Message, ".*" + searchText + ".*", RegexOptions.IgnorePatternWhitespace | RegexOptions.IgnoreCase); if (match.Success) { Intel intel = new Intel(); intel.LogMessage = message; string formattedMessage = message.Message; foreach (string word in IntelSettings.Default.DetectIgroreWords) { formattedMessage = formattedMessage.Replace(word, ""); } /*(string formattedMessage = message.Message.Replace("at ", ""). Replace("near ", ""). Replace("in ", ""). Replace("the ", ""). Replace("a ", ""); */ string[] systemKeywords = null; foreach (string systemKeyword in IntelSettings.Default.DetectSystem) { if (formattedMessage.Contains(systemKeyword)) { systemKeywords = systemKeyword.Split(' '); break; } } string[] messageParts = formattedMessage.Split(new char[] {' '}, StringSplitOptions.RemoveEmptyEntries); if (systemKeywords != null) { for (int i = 0; i < messageParts.Length; i++) { if (systemKeywords[0] == messageParts[i] && i - 1 >= 0) { intel.System = SolarSystem.GetSystem(messageParts[i - 1]); } else if (systemKeywords.Contains(messageParts[i])) { // ignore the rest of the solar system keyword } else if (messageParts[i].ToLower() == "nv" || messageParts[i].ToLower() == "novisual" || messageParts[i].ToLower() == "visual") { intel.NoVisual = true; intel.Location = "No Visual"; } else if (messageParts[i].ToLower() == "docked" || messageParts[i].ToLower() == "doc") { intel.Docked = true; intel.Location = "Docked"; } else if (messageParts[i].ToLower() == "clear" || messageParts[i].ToLower() == "clr") { intel.Clear = true; intel.Location = "Clear"; } else if (i + 1 < messageParts.Length && !systemKeywords.Contains(messageParts[i + 1])) { intel.Players += (intel.Players != "" ? " " : "") + messageParts[i]; } else if (i + 1 < messageParts.Length && systemKeywords.Contains(messageParts[i + 1])) { // since this keyword is a system, we need to skip it. } else if (i < messageParts.Length && !systemKeywords.Contains(messageParts[i])) { intel.Players += (intel.Players != "" ? " " : "") + messageParts[i]; } } } if (ChangedIntel != null) { ChangedIntel(intel); // since we alrady matched this intel, we do not want to keep searching } return; } } }
protected override void OnStarted() { Server.OnUserDisconnected += Server_OnUserDisconnected; var commandposts = World.Description.GetObjectsByTag("CommandPost"); var intels = World.Description.GetObjectsByTag("Intel"); if (commandposts.Count == 2 && intels.Count == 2) { // Load intel foreach (WorldObjectDescription ob in intels) { Vector3 position = ob.GetVector3("Position"); Team team = (Team)(ob.GetField <byte>("Team") ?? 0); Intel intel = new Intel(position, team); if (team == Team.A) { redIntel = intel; } else { blueIntel = intel; } intel.OnPickedUp += Intel_OnPickedUp; intel.OnDropped += Intel_OnDropped; intel.OnReturned += Intel_OnReturned; objectComponent.NetworkInstantiate(intel, "Client_CreateIntel", null, position.X, position.Y, position.Z, (byte)team); } // Load command posts foreach (WorldObjectDescription ob in commandposts) { Vector3 position = ob.GetVector3("Position"); Team team = (Team)(ob.GetField <byte>("Team") ?? 0); CommandPost post = new CommandPost(position, team); if (team == Team.A) { redPost = post; } else { bluePost = post; } post.PhysicsBody.OnCollision += Post_OnCollision; objectComponent.NetworkInstantiate(post, "Client_CreateCommandPost", null, position.X, position.Y, position.Z, (byte)team); } } else { DashCMD.WriteWarning("[CTFGamemode] Current world does not have a proper gameobject setup! Falling back to default."); LoadFallbackGameObjects(); } base.OnStarted(); }