protected Event(DateTime dateTime, Galaxy galaxy) { Time = dateTime.ToUniversalTime(); Galaxy = galaxy; Turn = galaxy.Turn; Round = galaxy.Round; }
public Rectangle PlanetRectangle(Galaxy gal) { var w = Resource.PlanetWarsIconSize; var xp = (int)(X * gal.Width); var yp = (int)(Y * gal.Height); return new Rectangle((int)(xp - w / 2), (int)(yp - w / 2), (int)w, (int)w); }
void Start() { galaxy = new Galaxy(); GameObject currentObj = Instantiate(systemClusterPrefab); currentObj.transform.parent = transform; int counter = 0; foreach (SolarSystem system in galaxy.Systems.Values) { if (counter <= 0) { counter = clusterSize; currentObj = Instantiate(systemClusterPrefab); currentObj.transform.parent = transform; } SpawnSystem(system, currentObj.GetComponent<ParticleSystem>()); counter--; } counter = 0; foreach (JumpConnection connection in galaxy.Jumps) { if (counter <= 0) { counter = clusterSize; currentObj = Instantiate(connectionClusterPrefab); currentObj.transform.parent = transform; } SpawnConnection(connection, currentObj.GetComponent<ParticleSystem>()); counter--; } }
// Use this for initialization void Start() { galaxy = new Galaxy(); Debug.Log(galaxy.DebugGalaxy()); SolarSystem[] systems = galaxy.GetSystems(); foreach (SolarSystem s in systems) { Vector3 pos = new Vector3(s.x, s.y, 0f); // Create solar system object GameObject system = (GameObject)Instantiate(solarSystem, pos, Quaternion.identity); system.transform.SetParent(solarSystemParent.transform); Material[] mats = system.GetComponent<Renderer>().materials; mats[0] = starMaterials[s.starType]; system.GetComponent<Renderer>().materials = mats; ClickableSystem c = system.GetComponent<ClickableSystem>(); c.logic = this; c.system = s; foreach (SolarSystem neighbour in s.neighbours) { // Create path object GameObject line = (GameObject)Instantiate(path, pos, Quaternion.identity); line.transform.SetParent(pathParent.transform); LineRenderer lr = line.GetComponent<LineRenderer>(); lr.SetPositions(new Vector3[]{ Vector3.zero, new Vector3(neighbour.x, neighbour.y, 0f) - pos}); } } }
public RankNameChangedEvent(DateTime dateTime, string playerName, string oldRank, string newRank, Galaxy galaxy) : base(dateTime, galaxy) { PlayerName = playerName; OldRank = oldRank; NewRank = newRank; }
public PlanetOwnerChangedEvent(DateTime dateTime, Galaxy galaxy, string fromName, string toName, string faction, int planetID) : base(dateTime, galaxy) { FromName = fromName; ToName = toName; Faction = faction; PlanetID = planetID; }
public PlayerRankChangedEvent(DateTime dateTime, Galaxy galaxy, string name, Rank oldRank, Rank newRank) : base(dateTime, galaxy) { OldRank = oldRank; NewRank = newRank; if (oldRank == newRank) throw new ArgumentException("Ranks must differ for player rank changed event"); PlayerName = name; }
public PlanetNameChangedEvent(DateTime dateTime, int planetID, string oldName, string newName, string ownerName, Galaxy galaxy) : base(dateTime, galaxy) { PlanetID = planetID; OldName = oldName; NewName = newName; OwnerName = ownerName; }
public void FireWeapon(Galaxy wg) { if (wg.Parameter("command").Equals("phaser")) { int amount = int.Parse(wg.Parameter("amount")); Klingon enemy = (Klingon) wg.Variable("target"); if (e >= amount) { int distance = enemy.Distance(); if (distance > 4000) { wg.WriteLine("Klingon out of range of phasers at " + distance + " sectors..."); } else { int damage = amount - (((amount /20)* distance /200) + Rnd(200)); if (damage < 1) damage = 1; wg.WriteLine("Phasers hit Klingon at " + distance + " sectors with " + damage + " units"); if (damage < enemy.GetEnergy()) { enemy.SetEnergy(enemy.GetEnergy() - damage); wg.WriteLine("Klingon has " + enemy.GetEnergy() + " remaining"); } else { wg.WriteLine("Klingon destroyed!"); enemy.Delete(); } } e -= amount; } else { wg.WriteLine("Insufficient energy to fire phasers!"); } } else if (wg.Parameter("command").Equals("photon")) { Klingon enemy = (Klingon) wg.Variable("target"); if (t > 0) { int distance = enemy.Distance(); if ((Rnd(4) + ((distance / 500) + 1) > 7)) { wg.WriteLine("Torpedo missed Klingon at " + distance + " sectors..."); } else { int damage = 800 + Rnd(50); wg.WriteLine("Photons hit Klingon at " + distance + " sectors with " + damage + " units"); if (damage < enemy.GetEnergy()) { enemy.SetEnergy(enemy.GetEnergy() - damage); wg.WriteLine("Klingon has " + enemy.GetEnergy() + " remaining"); } else { wg.WriteLine("Klingon destroyed!"); enemy.Delete(); } } t -= 1; } else { wg.WriteLine("No more photon torpedoes!"); } } }
//private MissionType mType; // Use this for initialization void Start() { audioengine = (AudioEngine)FindObjectOfType(typeof(AudioEngine)); galaxy = (Galaxy)FindObjectOfType(typeof(Galaxy)); godMission = (PersistentMission)FindObjectOfType(typeof(PersistentMission)); DontDestroyOnLoad(gameObject); firstUpdate = true; whatControllerAmIUsing = WhatControllerAmIUsing.MOUSE_KEYBOARD; GameObject newGalaxy = Instantiate(GalaxyPrefab, new Vector3(0, 0 ,0), Quaternion.identity) as GameObject; newGalaxy.name = "Galaxy"; if (!GOD.goToRandomPointInGalaxy) { Invoke("waitForaBit", 0.5f); } }
public BattleEvent(DateTime dateTime, List<EndGamePlayerInfo> endGameInfos, string mapName, string attacker, string defender, string victor, bool areUpgradesDisabled, Galaxy galaxy, IEnumerable<int> encircledPlanets, IEnumerable<string> spaceFleetOwners) : base(dateTime, galaxy) { EndGameInfos = endGameInfos; MapName = mapName; PlanetID = Galaxy.Planets.Single(p => p.MapName == MapName).ID; Attacker = attacker; Defender = defender; AreUpgradesDisabled = areUpgradesDisabled; Victor = victor; EncircledPlanets = encircledPlanets.ToArray(); SpaceFleetOwners = spaceFleetOwners.ToArray(); }
public AidSentEvent(DateTime dateTime, Galaxy galaxy, string fromName, string toName, double ammount) : base(dateTime, galaxy) { FromName = fromName; ToName = toName; Ammount = ammount; }
public static void CreateMapGalaxy(Galaxy galaxy, int rowCount, int columnCount, double hexSize) { MapGalaxy = galaxy; GenerateEmptySectors(MapGalaxy, rowCount, columnCount, hexSize); }
internal SteadyUnit(Universe universe, Galaxy galaxy, ref BinaryMemoryReader reader) : base(universe, galaxy, ref reader) { }
// TODO - status messages for the GUI public void PopulateGalaxy(Galaxy gal, PRNG dice) { gal.Name = GameName; gal.CleanGameState(); // remove forbidden techs foreach (var tname in ForbiddenTechnologyNames) { Mod.Current.Technologies.Single(t => t.Name == tname).Dispose(); } // set omniscient view and all systems seen flags gal.OmniscientView = OmniscientView; gal.AllSystemsExploredFromStart = AllSystemsExplored; // set up mining models and resource stuff gal.StandardMiningModel = StandardMiningModel; gal.RemoteMiningModel = RemoteMiningModel; gal.MinPlanetValue = MinPlanetValue; gal.MinSpawnedPlanetValue = MinSpawnedPlanetValue; gal.MaxSpawnedPlanetValue = MaxSpawnedPlanetValue; gal.MaxPlanetValue = MaxPlanetValue; gal.MinAsteroidValue = MinAsteroidValue; gal.MinSpawnedAsteroidValue = MinSpawnedAsteroidValue; gal.MaxSpawnedAsteroidValue = MaxSpawnedAsteroidValue; // set score display setting gal.ScoreDisplay = ScoreDisplay; // set up victory conditions foreach (var vc in VictoryConditions) { gal.VictoryConditions.Add(vc); } gal.VictoryDelay = VictoryDelay; // set up misc. game options gal.TechnologyCost = TechnologyCost; gal.TechnologyUniqueness = TechnologyUniqueness; gal.IsHumansVsAI = IsHumansVsAI; gal.AllowedTrades = AllowedTrades; gal.IsSurrenderAllowed = IsSurrenderAllowed; gal.IsIntelligenceAllowed = IsIntelligenceAllowed; gal.CanColonizeOnlyBreathable = CanColonizeOnlyBreathable; gal.CanColonizeOnlyHomeworldSurface = CanColonizeOnlyHomeworldSurface; gal.WarpPointPlacementStrategy = WarpPointPlacementStrategy; // create player empires foreach (var et in EmpireTemplates) { var emp = et.Instantiate(); gal.Empires.Add(emp); } // TODO - make sure empires don't reuse colors unless we really have to? // create random AI empires for (int i = 1; i <= RandomAIs; i++) { // TODO - load saved EMP files for random AI empires var surface = Mod.Current.StellarObjectTemplates.OfType <Planet>().Where(p => !p.Size.IsConstructed).Select(p => p.Surface).Distinct().PickRandom(dice); var atmosphere = Mod.Current.StellarObjectTemplates.OfType <Planet>().Where(p => !p.Size.IsConstructed && p.Surface == surface).Select(p => p.Atmosphere).Distinct().PickRandom(dice); var et = new EmpireTemplate { Name = "Random Empire #" + i, LeaderName = "Random Leader #" + i, PrimaryRace = new Race { Name = "Random Race #" + i, NativeAtmosphere = atmosphere, NativeSurface = surface, }, IsPlayerEmpire = false, Color = RandomColor(dice), Culture = Mod.Current.Cultures.PickRandom(dice), AIName = Mod.Current.EmpireAIs.PickRandom(dice).Name, }; foreach (var apt in Aptitude.All) { et.PrimaryRace.Aptitudes[apt.Name] = 100; } var emp = et.Instantiate(); gal.Empires.Add(emp); } // create minor empires for (int i = 1; i <= MinorEmpires; i++) { // TODO - load saved EMP files for minor empires var surface = Mod.Current.StellarObjectTemplates.OfType <Planet>().Where(p => !p.Size.IsConstructed).Select(p => p.Surface).Distinct().PickRandom(dice); var atmosphere = Mod.Current.StellarObjectTemplates.OfType <Planet>().Where(p => !p.Size.IsConstructed && p.Surface == surface).Select(p => p.Atmosphere).Distinct().PickRandom(dice); var et = new EmpireTemplate { Name = "Minor Empire #" + i, LeaderName = "Minor Leader #" + i, PrimaryRace = new Race { Name = "Minor Race #" + i, NativeAtmosphere = atmosphere, NativeSurface = surface, }, IsPlayerEmpire = false, IsMinorEmpire = true, Color = RandomColor(dice), Culture = Mod.Current.Cultures.PickRandom(dice), AIName = Mod.Current.EmpireAIs.PickRandom(dice).Name, }; foreach (var apt in Aptitude.All) { et.PrimaryRace.Aptitudes[apt.Name] = 100; } var emp = et.Instantiate(); gal.Empires.Add(emp); } // place empires // don't do them in any particular order, so P1 and P2 don't always wind up on opposite sides of the galaxy when using equidistant placement foreach (var emp in gal.Empires.Shuffle(dice)) { PlaceEmpire(gal, emp, dice); } //Enabled AI ministers, so the AI's actually can do stuff. foreach (var emp in gal.Empires.Where(x => !x.IsPlayerEmpire && x.AI != null)) { emp.EnabledMinisters = emp.AI.MinisterNames; } // remove ruins if they're not allowed if (!GenerateRandomRuins) { foreach (var p in gal.FindSpaceObjects <Planet>()) { foreach (var abil in p.IntrinsicAbilities.ToArray()) { if (abil.Rule.Matches("Ancient Ruins")) { p.IntrinsicAbilities.Remove(abil); } } } } if (!GenerateUniqueRuins) { foreach (var p in gal.FindSpaceObjects <Planet>()) { foreach (var abil in p.IntrinsicAbilities.ToArray()) { if (abil.Rule.Matches("Ancient Ruins Unique")) { p.IntrinsicAbilities.Remove(abil); } } } } // also remove ruins from homeworlds, that's just silly :P foreach (var p in gal.FindSpaceObjects <Planet>().Where(p => p.Colony != null)) { foreach (var abil in p.IntrinsicAbilities.ToArray()) { if (abil.Rule.Matches("Ancient Ruins") || abil.Rule.Matches("Ancient Ruins Unique")) { p.IntrinsicAbilities.Remove(abil); } } } // set up omniscient view if (OmniscientView) { foreach (var emp in gal.Empires) { foreach (var sys in gal.StarSystemLocations.Select(l => l.Item)) { sys.ExploredByEmpires.Add(emp); } } } }
public override bool IsFactionRelated(string factionName) { return(EndGameInfos.Any(p => Galaxy.GetPlayer(p.Name).FactionName == factionName)); }
private ActionResult ChangePlanetMap(int planetID, int structureTypeID, int targetID, int?newMapID) { var db = new ZkDataContext(); PlanetStructure structure = db.PlanetStructures.FirstOrDefault(x => x.PlanetID == planetID && x.StructureTypeID == structureTypeID); Planet source = db.Planets.FirstOrDefault(x => x.PlanetID == planetID); Planet target = db.Planets.FirstOrDefault(x => x.PlanetID == targetID); Galaxy gal = db.Galaxies.FirstOrDefault(x => x.GalaxyID == source.GalaxyID); if (newMapID == null) { List <Resource> mapList = db.Resources.Where( x => x.MapPlanetWarsIcon != null && x.Planets.Where(p => p.GalaxyID == gal.GalaxyID).Count() == 0 && x.MapSupportLevel >= MapSupportLevel.Featured && x.ResourceID != source.MapResourceID).ToList(); if (mapList.Count > 0) { int r = new Random().Next(mapList.Count); newMapID = mapList[r].ResourceID; } } if (newMapID != null) { Resource newMap = db.Resources.Single(x => x.ResourceID == newMapID); target.Resource = newMap; gal.IsDirty = true; string word = ""; if (target.Faction == source.Faction) { if (target.TeamSize < GlobalConst.PlanetWarsMaxTeamsize) { target.TeamSize++; } word = "terraformed"; } else { word = "nanodegraded"; if (target.TeamSize > 1) { target.TeamSize--; } } db.Events.InsertOnSubmit(PlanetwarsEventCreator.CreateEvent("{0} {1} has been {6} by {2} from {3} {4}. New team size is {5} vs {5}", target.Faction, target, structure.StructureType, source.Faction, source, target.TeamSize, word)); } else { return (Content(string.Format("Terraform attempt on {0} {1} using {2} from {3} {4} has failed - no valid maps", target.Faction, target, structure.StructureType, source.Faction, source))); } db.SaveChanges(); return(null); }
// Start is called before the first frame update void Start() { _galaxy = GetComponent <Galaxy>(); }
/// <summary> /// Creates a Galaxy using supplied settings. /// </summary> /// <param name="galaxyID"> /// The galaxy to use as a template /// </param> /// <returns> /// A new Galaxy stored in a datastore. /// </returns> public Galaxy GenerateGalaxy(int? galaxyID) { var solarSystems = new List<SolarSystem>(); var r = new Random(); GalaxySettings settings; if (!galaxyID.HasValue) { settings = this.galaxySettingsRepository.EagerAll.FirstOrDefault(); } else { settings = this.galaxySettingsRepository.EagerGet(galaxyID.GetValueOrDefault()); } if (settings == null) { return null; } Parallel.For( 0, settings.Width, i => Parallel.For( 0, settings.Height, j => { if (r.NextDouble() < settings.SystemGenerationProbability) { return; } // create a solar system here... var solarSystem = CreateSolarSystem(settings); if (solarSystem == null) { return; } solarSystem.Latitude = i; solarSystem.Longitude = j; solarSystems.Add(solarSystem); })); foreach (var solarSystem in solarSystems) { foreach (var spatialEntity in solarSystem.SpatialEntities) { this.spatialEntityRepository.Add(spatialEntity); } this.solarSystemRepository.Add(solarSystem); } var output = new Galaxy { GalaxySettings = settings, SolarSystems = solarSystems }; output = this.galaxyRepository.Add(output); return output; }
public void LoadContent(Texture2D galaxyViewTextures, Texture2D baseViewTextures, SpriteFont font, Galaxy gal) { detailFont = font; currentGalaxy = gal; selectedSystem = currentGalaxy.Home; galaxyIcons = new IconHandler(galaxyViewTextures, 3, 6); baseIcons = new IconHandler(baseViewTextures, 3, 6); }
// Use this for initialization void OnEnable() { Galaxy = new Galaxy(); Galaxy.Generate(1); }
List <Faction> GetDefendingFactions(AttackOption target) { if (target.OwnerFactionID != null) { return new List <Faction> { factions.Find(x => x.FactionID == target.OwnerFactionID) } } ; return(factions.Where(x => x != AttackingFaction).ToList()); } void JoinPlanetAttack(int targetPlanetId, string userName) { AttackOption attackOption = AttackOptions.Find(x => x.PlanetID == targetPlanetId); if (attackOption != null) { User user; if (tas.ExistingUsers.TryGetValue(userName, out user)) { var db = new ZkDataContext(); Account account = db.Accounts.Find(user.AccountID); if (account != null && account.FactionID == AttackingFaction.FactionID && account.CanPlayerPlanetWars()) { // remove existing user from other options foreach (AttackOption aop in AttackOptions) { aop.Attackers.RemoveAll(x => x == userName); } // add user to this option if (attackOption.Attackers.Count < attackOption.TeamSize) { attackOption.Attackers.Add(user.Name); tas.Say(SayPlace.Channel, user.Faction, string.Format("{0} joins attack on {1}", userName, attackOption.Name), true); if (attackOption.Attackers.Count == attackOption.TeamSize) { StartChallenge(attackOption); } else { UpdateLobby(); } } } } } } void JoinPlanetDefense(int targetPlanetID, string userName) { if (Challenge != null && Challenge.PlanetID == targetPlanetID && Challenge.Defenders.Count < Challenge.TeamSize) { User user; if (tas.ExistingUsers.TryGetValue(userName, out user)) { var db = new ZkDataContext(); Account account = db.Accounts.Find(user.AccountID); if (account != null && GetDefendingFactions(Challenge).Any(y => y.FactionID == account.FactionID) && account.CanPlayerPlanetWars()) { if (!Challenge.Defenders.Any(y => y == user.Name)) { Challenge.Defenders.Add(user.Name); tas.Say(SayPlace.Channel, user.Faction, string.Format("{0} joins defense of {1}", userName, Challenge.Name), true); if (Challenge.Defenders.Count == Challenge.TeamSize) { AcceptChallenge(); } else { UpdateLobby(); } } } } } } void RecordPlanetwarsLoss(AttackOption option) { if (option.OwnerFactionID != null) { if (option.OwnerFactionID == missedDefenseFactionID) { missedDefenseCount++; } else { missedDefenseCount = 0; missedDefenseFactionID = option.OwnerFactionID.Value; } } var message = string.Format("{0} won because nobody tried to defend", AttackingFaction.Name); foreach (var fac in factions) { tas.Say(SayPlace.Channel, fac.Shortcut, message, true); } var text = new StringBuilder(); try { var db = new ZkDataContext(); List <string> playerIds = option.Attackers.Select(x => x).Union(option.Defenders.Select(x => x)).ToList(); PlanetWarsTurnHandler.EndTurn(option.Map, null, db, 0, db.Accounts.Where(x => playerIds.Contains(x.Name) && x.Faction != null).ToList(), text, null, db.Accounts.Where(x => option.Attackers.Contains(x.Name) && x.Faction != null).ToList()); } catch (Exception ex) { Trace.TraceError(ex.ToString()); text.Append(ex); } } void ResetAttackOptions() { AttackOptions.Clear(); AttackerSideChangeTime = DateTime.UtcNow; Challenge = null; ChallengeTime = null; using (var db = new ZkDataContext()) { var gal = db.Galaxies.First(x => x.IsDefault); int cnt = 2; var attacker = db.Factions.Single(x => x.FactionID == AttackingFaction.FactionID); var planets = gal.Planets.Where(x => x.OwnerFactionID != AttackingFaction.FactionID).OrderByDescending(x => x.PlanetFactions.Where(y => y.FactionID == AttackingFaction.FactionID).Sum(y => y.Dropships)).ThenByDescending(x => x.PlanetFactions.Where(y => y.FactionID == AttackingFaction.FactionID).Sum(y => y.Influence)).ToList(); // list of planets by attacker's influence foreach (var planet in planets) { if (planet.CanMatchMakerPlay(attacker)) { // pick only those where you can actually attack atm InternalAddOption(planet); cnt--; } if (cnt == 0) { break; } } if (!AttackOptions.Any(y => y.TeamSize == 2)) { var planet = planets.FirstOrDefault(x => x.TeamSize == 2 && x.CanMatchMakerPlay(attacker)); if (planet != null) { InternalAddOption(planet); } } } UpdateLobby(); tas.Say(SayPlace.Channel, AttackingFaction.Shortcut, "It's your turn! Select a planet to attack", true); } void InternalAddOption(Planet planet) { AttackOptions.Add(new AttackOption { PlanetID = planet.PlanetID, Map = planet.Resource.InternalName, OwnerFactionID = planet.OwnerFactionID, Name = planet.Name, TeamSize = planet.TeamSize, }); } void SaveStateToDb() { var db = new ZkDataContext(); Galaxy gal = db.Galaxies.First(x => x.IsDefault); gal.MatchMakerState = JsonConvert.SerializeObject((MatchMakerState)this); gal.AttackerSideCounter = AttackerSideCounter; gal.AttackerSideChangeTime = AttackerSideChangeTime; db.SubmitAndMergeChanges(); } void StartChallenge(AttackOption attackOption) { Challenge = attackOption; ChallengeTime = DateTime.UtcNow; AttackOptions.Clear(); UpdateLobby(); } void TasOnChannelUserAdded(object sender, ChannelUserInfo e) { string chan = e.Channel.Name; foreach (var user in e.Users) { Faction faction = factions.FirstOrDefault(x => x.Shortcut == chan); if (faction != null) { var db = new ZkDataContext(); var acc = Account.AccountByName(db, user.Name); if (acc != null && acc.CanPlayerPlanetWars()) { UpdateLobby(user.Name); } } } } /// <summary> /// Intercept channel messages for attacking/defending /// </summary> /// <param name="sender"></param> /// <param name="args"></param> void TasOnPreviewSaid(object sender, CancelEventArgs <TasSayEventArgs> args) { if (args.Data.Text.StartsWith("!") && (args.Data.Place == SayPlace.Channel || args.Data.Place == SayPlace.User) && args.Data.UserName != GlobalConst.NightwatchName) { int targetPlanetId; if (int.TryParse(args.Data.Text.Substring(1), out targetPlanetId)) { JoinPlanet(args.Data.UserName, targetPlanetId); } } } /// <summary> /// Remove/reduce poll count due to lobby quits /// </summary> void TasOnUserRemoved(object sender, UserDisconnected args) { if (Challenge == null) { if (AttackOptions.Count > 0) { string userName = args.Name; int sumRemoved = 0; foreach (AttackOption aop in AttackOptions) { sumRemoved += aop.Attackers.RemoveAll(x => x == userName); } if (sumRemoved > 0) { UpdateLobby(); } } } else { string userName = args.Name; if (Challenge.Defenders.RemoveAll(x => x == userName) > 0) { UpdateLobby(); } } } void TimerOnElapsed(object sender, ElapsedEventArgs elapsedEventArgs) { try { if (Challenge == null) { // attack timer if (DateTime.UtcNow > GetAttackDeadline()) { AttackerSideCounter++; ResetAttackOptions(); } } else { // accept timer if (DateTime.UtcNow > GetAcceptDeadline()) { if (Challenge.Defenders.Count >= Challenge.Attackers.Count - 1 && Challenge.Defenders.Count > 0) { AcceptChallenge(); } else { RecordPlanetwarsLoss(Challenge); AttackerSideCounter++; ResetAttackOptions(); } } } } catch (Exception ex) { Trace.TraceError(ex.ToString()); } }
public void SeedStartingEntities(WorldSide side, Galaxy galaxy, ArcenSimContext Context, MapTypeData mapType) { }
public GalacticReport(string description, Output output, Galaxy galaxy) : base(description, output) { Galaxy = galaxy; }
public mPlanet(Galaxy galaxy) : base(galaxy) { }
public override bool IsFactionRelated(string factionName) { return(Galaxy.GetPlayer(PlayerName).FactionName == factionName); }
public PlayerRegisteredEvent(DateTime dateTime, string playerName, int?planetID, Galaxy galaxy) : base(dateTime, galaxy) { PlayerName = playerName; PlanetID = planetID; }
// Update is called once per frame void Update() { Profiler.BeginSample("MouseController:Update()"); galaxy = globalVariables.GlobalVariables.galaxy; currFramePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition); galaxyMousePos = currFramePosition; galaxyMousePos.z = 0; //Flytta kameran if (Input.GetMouseButton(1)) //Right Mouse Button { Camera.main.transform.Translate(lastFramePosition - currFramePosition); } if (hoverStar != null) { if (Vector3.Distance(galaxyMousePos, hoverStar.position) > gameSettings.GameSettings.StarClickBox / 2) { HoverStar(); if (hoverStar != null) { if (selectedStar == null) { globalVariables.UI.greenSelectCircle.transform.position = hoverStar.position; text.text = hoverStar.id.ToString(); //globalVariables.UI.greenSelectCircle.SetActive (true); } } else { //globalVariables.UI.greenSelectCircle.SetActive (false); } } } else { HoverStar(); //globalVariables.UI.greenSelectCircle.SetActive (false); } //Markera object if (Input.GetMouseButtonDown(0)) { if (hoverStar != null) { selectedStar = hoverStar; } if (selectedStar != null) { if (Vector3.Distance(galaxyMousePos, selectedStar.position) > gameSettings.GameSettings.StarClickBox) { selectedStar = null; } } Interact(); } //Camera Zoom if (Input.GetAxis("Mouse ScrollWheel") != 0) { Zoom(); } lastFramePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition); Profiler.EndSample(); }
/// <summary> /// Makes an image: galaxy background with planet images drawn on it (cheaper than rendering each planet individually) /// </summary> // FIXME: having issues with bitmap parameters; setting AA factor to 1 as fallback (was 4) public Bitmap GenerateGalaxyImage(int galaxyID, double zoom = 1, double antiAliasingFactor = 1) { zoom *= antiAliasingFactor; using (var db = new ZkDataContext()) { Galaxy gal = db.Galaxies.Single(x => x.GalaxyID == galaxyID); using (Image background = Image.FromFile(Server.MapPath("/img/galaxies/" + gal.ImageName))) { //var im = new Bitmap((int)(background.Width*zoom), (int)(background.Height*zoom)); var im = new Bitmap(background.Width, background.Height); using (Graphics gr = Graphics.FromImage(im)) { gr.DrawImage(background, 0, 0, im.Width, im.Height); /* * using (var pen = new Pen(Color.FromArgb(255, 180, 180, 180), (int)(1*zoom))) * { * foreach (var l in gal.Links) * { * gr.DrawLine(pen, * (int)(l.PlanetByPlanetID1.X*im.Width), * (int)(l.PlanetByPlanetID1.Y*im.Height), * (int)(l.PlanetByPlanetID2.X*im.Width), * (int)(l.PlanetByPlanetID2.Y*im.Height)); * } * }*/ foreach (Planet p in gal.Planets) { string planetIconPath = null; try { planetIconPath = "/img/planets/" + (p.Resource.MapPlanetWarsIcon ?? "1.png"); // backup image is 1.png using (Image pi = Image.FromFile(Server.MapPath(planetIconPath))) { double aspect = pi.Height / (double)pi.Width; var width = (int)(p.Resource.PlanetWarsIconSize * zoom); var height = (int)(width * aspect); gr.DrawImage(pi, (int)(p.X * im.Width) - width / 2, (int)(p.Y * im.Height) - height / 2, width, height); } } catch (Exception ex) { throw new ApplicationException( string.Format("Cannot process planet image {0} for planet {1} map {2}", planetIconPath, p.PlanetID, p.MapResourceID), ex); } } if (antiAliasingFactor == 1) { return(im); } else { zoom /= antiAliasingFactor; return(im.GetResized((int)(background.Width * zoom), (int)(background.Height * zoom), InterpolationMode.HighQualityBicubic)); } } } } }
public static void SetGalaxyMap(Galaxy galaxy) { MapGalaxy = galaxy; }
public override bool IsPlanetRelated(int planetID) { return(Galaxy.GetPlanet(planetID).MapName == MapName); }
public JobEditorViewModel(Galaxy Galaxy) { this.Galaxy = Galaxy; this.dialogFacade = new DialogFacade(); }
internal LongRangeSensors(Galaxy galaxy, IReadWrite io) : base("Long Range Sensors", Command.LRS, io) { _galaxy = galaxy; _io = io; }
void Start() { textMesh = GetComponent<TextMesh>(); sourceScript = GameObject.Find("GalaxyCore").GetComponent<Galaxy>(); }
internal GalaxyRegionMap(IReadWrite io, Galaxy galaxy) : base("Galaxy 'region name' map", io, galaxy) { }
public GalaxyInfo(Galaxy galaxy) { Galaxy = galaxy; Name = "info"; }
public void SaveGalaxy(int galaxyNumber) { // using (var scope = new TransactionScope()) { try { var db = new ZkDataContext(); var gal = db.Galaxies.SingleOrDefault(x => x.GalaxyID == galaxyNumber); if (gal == null || galaxyNumber == 0) { gal = new Galaxy(); db.Galaxies.InsertOnSubmit(gal); } else if (gal.Started != null) { MessageBox.Show("This galaxy is running, cannot edit it!"); return; } else { db.Links.DeleteAllOnSubmit(gal.Links); db.Planets.DeleteAllOnSubmit(gal.Planets); } gal.IsDirty = true; db.SaveChanges(); galaxyNumber = gal.GalaxyID; var maps = Maps.Shuffle(); var cnt = 0; foreach (var d in PlanetDrawings) { var p = d.Planet; p.GalaxyID = galaxyNumber; p.OwnerAccountID = null; p.X = (float)(Canvas.GetLeft(d)/imageSource.Width); p.Y = (float)(Canvas.GetTop(d)/imageSource.Height); if (p.MapResourceID == null) { p.MapResourceID = maps[cnt].ResourceID; cnt++; cnt = cnt%maps.Count; } var clone = p.DbClone(); clone.PlanetStructures.AddRange(p.PlanetStructures.Select(x => new PlanetStructure() { StructureTypeID = x.StructureTypeID })); gal.Planets.Add(clone); } db.SaveChanges(); var linkList = LinkDrawings.Select( d => new Link() { GalaxyID = galaxyNumber, PlanetID1 = db.Planets.Single(x => x.GalaxyID == galaxyNumber && x.Name == d.Planet1.Planet.Name).PlanetID, PlanetID2 = db.Planets.Single(x => x.GalaxyID == galaxyNumber && x.Name == d.Planet2.Planet.Name).PlanetID }); db.Links.InsertAllOnSubmit(linkList); db.SaveChanges(); // scope.Complete(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } MessageBox.Show("Exported!"); } }
public void Start() { galaxy = GetComponentInParent <Galaxy>(); }
// Start is called before the first frame update void Start() { Words.InitializeWords(); Galaxy.GeneratePlanets(); }
void OnEnable() { GalaxyInstance = this; }
public bool IsOnTheGalaxy(Galaxy galaxy) { return(this.row >= 0 && this.row < galaxy.MaxRow && this.col >= 0 && this.col < galaxy.MaxCol); }
void Awake() { myGalaxy = GameObject.Find("Galaxy").GetComponent<Galaxy>(); }
/// <summary> /// Updates shadow influence and new owners /// </summary> /// <param name="db"></param> /// <param name="sb">optional spring batle that caused this change (for event logging)</param> public static void SetPlanetOwners(IPlanetwarsEventCreator eventCreator, ZkDataContext db = null, SpringBattle sb = null) { if (db == null) { db = new ZkDataContext(); } Galaxy gal = db.Galaxies.Single(x => x.IsDefault); foreach (Planet planet in gal.Planets) { if (planet.OwnerAccountID != null) { foreach (var ps in planet.PlanetStructures.Where(x => x.OwnerAccountID == null)) { ps.OwnerAccountID = planet.OwnerAccountID; ps.ReactivateAfterBuild(); } } PlanetFaction best = planet.PlanetFactions.OrderByDescending(x => x.Influence).FirstOrDefault(); Faction newFaction = planet.Faction; Account newAccount = planet.Account; if (best == null || best.Influence < GlobalConst.InfluenceToCapturePlanet) { // planet not capture if (planet.Faction != null) { var curFacInfluence = planet.PlanetFactions.Where(x => x.FactionID == planet.OwnerFactionID).Select(x => x.Influence).FirstOrDefault(); if (curFacInfluence <= GlobalConst.InfluenceToLosePlanet) { // owners have too small influence, planet belong to nobody newFaction = null; newAccount = null; } } } else { if (best.Faction != planet.Faction) { newFaction = best.Faction; // best attacker without planets Account candidate = planet.AccountPlanets.Where( x => x.Account.FactionID == newFaction.FactionID && x.AttackPoints > 0 && !x.Account.Planets.Any()).OrderByDescending( x => x.AttackPoints).Select(x => x.Account).FirstOrDefault(); if (candidate == null) { // best attacker candidate = planet.AccountPlanets.Where(x => x.Account.FactionID == newFaction.FactionID && x.AttackPoints > 0).OrderByDescending( x => x.AttackPoints).ThenBy(x => x.Account.Planets.Count()).Select(x => x.Account).FirstOrDefault(); } // best player without planets if (candidate == null) { candidate = newFaction.Accounts.Where(x => !x.Planets.Any()).OrderByDescending(x => x.AccountPlanets.Sum(y => y.AttackPoints)). FirstOrDefault(); } // best with planets if (candidate == null) { candidate = newFaction.Accounts.OrderByDescending(x => x.AccountPlanets.Sum(y => y.AttackPoints)). FirstOrDefault(); } newAccount = candidate; } } // change has occured if (newFaction != planet.Faction) { // disable structures foreach (PlanetStructure structure in planet.PlanetStructures.Where(x => x.StructureType.OwnerChangeDisablesThis)) { structure.ReactivateAfterBuild(); structure.Account = newAccount; } // delete structures being lost on planet change foreach (PlanetStructure structure in planet.PlanetStructures.Where(structure => structure.StructureType.OwnerChangeDeletesThis).ToList()) { db.PlanetStructures.DeleteOnSubmit(structure); } // reset attack points memory foreach (AccountPlanet acp in planet.AccountPlanets) { acp.AttackPoints = 0; } if (newFaction == null) { Account account = planet.Account; Clan clan = null; if (account != null) { clan = planet.Account != null ? planet.Account.Clan : null; } db.Events.InsertOnSubmit(eventCreator.CreateEvent("{0} planet {1} owned by {2} {3} was abandoned. {4}", planet.Faction, planet, account, clan, sb)); if (account != null) { eventCreator.GhostPm(planet.Account.Name, string.Format( "Warning, you just lost planet {0}!! {2}/PlanetWars/Planet/{1}", planet.Name, planet.PlanetID, GlobalConst.BaseSiteUrl)); } } else { // new real owner // log messages if (planet.OwnerAccountID == null) // no previous owner { db.Events.InsertOnSubmit(eventCreator.CreateEvent("{0} has claimed planet {1} for {2} {3}. {4}", newAccount, planet, newFaction, newAccount.Clan, sb)); eventCreator.GhostPm(newAccount.Name, string.Format( "Congratulations, you now own planet {0}!! {2}/PlanetWars/Planet/{1}", planet.Name, planet.PlanetID, GlobalConst.BaseSiteUrl)); } else { db.Events.InsertOnSubmit(eventCreator.CreateEvent("{0} of {1} {2} has captured planet {3} from {4} of {5} {6}. {7}", newAccount, newFaction, newAccount.Clan, planet, planet.Account, planet.Faction, planet.Account.Clan, sb)); eventCreator.GhostPm(newAccount.Name, string.Format( "Congratulations, you now own planet {0}!! {2}/PlanetWars/Planet/{1}", planet.Name, planet.PlanetID, GlobalConst.BaseSiteUrl)); eventCreator.GhostPm(planet.Account.Name, string.Format( "Warning, you just lost planet {0}!! {2}/PlanetWars/Planet/{1}", planet.Name, planet.PlanetID, GlobalConst.BaseSiteUrl)); } if (planet.PlanetStructures.Any(x => x.StructureType.OwnerChangeWinsGame)) { WinGame(db, gal, newFaction, eventCreator.CreateEvent("CONGRATULATIONS!! {0} has won the PlanetWars by capturing {1} planet {2}!", newFaction, planet.Faction, planet)); } } planet.Faction = newFaction; planet.Account = newAccount; } ReturnPeacefulDropshipsHome(db, planet); } db.SaveChanges(); }
public PlayerRegisteredEvent(DateTime dateTime, string playerName, int? planetID, Galaxy galaxy) : base(dateTime, galaxy) { PlayerName = playerName; PlanetID = planetID; }
public static void Helper_SendThreatOnRaid(List <GameEntity> threatShipsNotAssignedElsewhere, WorldSide worldSide, Galaxy galaxy, Planet planet, bool IgnorePathCosts, ArcenLongTermPlanningContext Context) { for (int k = 0; k < galaxy.Planets.Count; k++) { Planet otherPlanet = galaxy.Planets[k]; otherPlanet.FactionPlanning_CheapestRaidPathToHereComesFrom = null; otherPlanet.FactionPlanning_CheapestRaidPathToHereCost = FInt.Zero; } List <Planet> potentialAttackTargets = new List <Planet>(); List <Planet> planetsToCheckInFlood = new List <Planet>(); planetsToCheckInFlood.Add(planet); planet.FactionPlanning_CheapestRaidPathToHereComesFrom = planet; for (int k = 0; k < planetsToCheckInFlood.Count; k++) { Planet floodPlanet = planetsToCheckInFlood[k]; floodPlanet.DoForLinkedNeighbors(delegate(Planet neighbor) { FInt totalCostFromOriginToNeighbor = floodPlanet.FactionPlanning_CheapestRaidPathToHereCost + 1; if (!potentialAttackTargets.Contains(neighbor)) { potentialAttackTargets.Add(neighbor); } if (neighbor.FactionPlanning_CheapestRaidPathToHereComesFrom != null && neighbor.FactionPlanning_CheapestRaidPathToHereCost <= totalCostFromOriginToNeighbor) { return(DelReturn.Continue); } neighbor.FactionPlanning_CheapestRaidPathToHereComesFrom = floodPlanet; neighbor.FactionPlanning_CheapestRaidPathToHereCost = totalCostFromOriginToNeighbor; planetsToCheckInFlood.Add(neighbor); return(DelReturn.Continue); }); } if (potentialAttackTargets.Count <= 0) { return; } if (!IgnorePathCosts) { potentialAttackTargets.Sort(delegate(Planet Left, Planet Right) { return(Left.AIPlanning_CheapestRaidPathToHereCost.CompareTo(Right.AIPlanning_CheapestRaidPathToHereCost)); }); int lastIndexToRetain = potentialAttackTargets.Count / 4; for (int k = lastIndexToRetain + 1; k < potentialAttackTargets.Count; k++) { potentialAttackTargets.RemoveAt(k--); } } Planet threatTarget = potentialAttackTargets[Context.QualityRandom.Next(0, potentialAttackTargets.Count)]; List <Planet> path = new List <Planet>(); Planet workingPlanet = threatTarget; while (workingPlanet != planet) { path.Insert(0, workingPlanet); workingPlanet = workingPlanet.FactionPlanning_CheapestRaidPathToHereComesFrom; } if (path.Count > 0) { GameCommand command = GameCommand.Create(GameCommandType.SetWormholePath); for (int k = 0; k < threatShipsNotAssignedElsewhere.Count; k++) { command.RelatedEntityIDs.Add(threatShipsNotAssignedElsewhere[k].PrimaryKeyID); } for (int k = 0; k < path.Count; k++) { command.RelatedPlanetIndices.Add(path[k].PlanetIndex); } Context.QueueCommandForSendingAtEndOfContext(command); } }
public long GetValue(Galaxy galaxy) { return(this.Value = galaxy.GetCellValue(this.row, this.col)); }
internal Buoy(Universe universe, Galaxy galaxy, ref BinaryMemoryReader reader) : base(universe, galaxy, ref reader) { Message = reader.ReadString(); }