public PlanetDrawing(Planet planet, double galaxyWidth, double galaxyHeight)
		{
			this.planet = planet;
			InitializeComponent();
			Position = new Point(planet.X*galaxyWidth, planet.Y*galaxyHeight);
			UpdateData(planet.PlanetStructures.Select(x => x.StructureType.Name));
		}
		public PlanetDialog(PlanetDrawing pd, IEnumerable<Resource> maps, IEnumerable<StructureType> structureTypes)
		{
			this.pd = pd;
			this.planet = pd.Planet;
			InitializeComponent();
			lbName.Text = planet.Name;
            maps = maps.OrderBy(x => x.MetadataName);
			foreach (var mn in maps) cbMaps.Items.Add(new ComboBoxItem() { Content = mn.InternalName, Tag = mn.ResourceID, IsSelected = mn.ResourceID == this.planet.MapResourceID });

			foreach (var s in structureTypes)
			{
				lbStructures.Items.Add(new ListBoxItem() {Content =  s.Name, Tag = s.StructureTypeID, IsSelected = planet.PlanetStructures.Any(y=>y.StructureTypeID==s.StructureTypeID) });
			}
		}
 public static void ReturnPeacefulDropshipsHome(ZkDataContext db, Planet planet)
 {
     //    return dropshuips home if owner is ceasefired/allied/same faction
     if (planet.Faction != null)
     {
         foreach (PlanetFaction entry in planet.PlanetFactions.Where(x => x.Dropships > 0))
         {
             if (entry.FactionID == planet.OwnerFactionID ||
                 planet.Faction.HasTreatyRight(entry.Faction, x => x.EffectPreventDropshipAttack == true, planet))
             {
                 planet.Faction.SpendDropships(-entry.Dropships);
                 entry.Dropships = 0;
             }
         }
     }
 }
 void InternalAddOption(Planet planet)
 {
     AttackOptions.Add(new AttackOption
     {
         PlanetID = planet.PlanetID,
         Map = planet.Resource.InternalName,
         OwnerFactionID = planet.OwnerFactionID,
         Name = planet.Name,
         TeamSize = planet.TeamSize,
     });
 }
 /// <summary>
 ///     Invoked from web page
 /// </summary>
 /// <param name="planet"></param>
 public void AddAttackOption(Planet planet)
 {
     if (!AttackOptions.Any(x => x.PlanetID == planet.PlanetID) && Challenge == null && planet.OwnerFactionID != AttackingFaction.FactionID)
     {
         InternalAddOption(planet);
         UpdateLobby();
     }
 }
			public PlanetPickEntry(Planet planet, int weight) {
				this.planet = planet;
				this.weight = weight;
			}
 public bool GaveTreatyRight(Planet planet, Func<TreatyEffectType, bool> test)
 {
     if (planet == null) return false; // not targeted, must be either planet or faction or both
     var effects = TreatyEffectsByGivingFactionID.Where(x => x.FactionTreaty.TreatyState == TreatyState.Accepted && ((x.PlanetID == planet.PlanetID && (planet.OwnerFactionID == null || planet.OwnerFactionID == x.ReceivingFactionID)) || (x.PlanetID == null && x.ReceivingFactionID == planet.OwnerFactionID)));
     return effects.Any(x => test(x.TreatyEffectType));
 }
 public bool HasTreatyRight(Faction giverFaction, Func<TreatyEffectType, bool> test, Planet planet = null)
 {
     var effects = TreatyEffectsByReceivingFactionID.Where(x => x.FactionTreaty.TreatyState == TreatyState.Accepted && x.GivingFactionID == giverFaction.FactionID && (x.Planet == null || x.Planet == planet));
     return effects.Any(x => test(x.TreatyEffectType));
 }
 public static MvcHtmlString PrintPlanet(this HtmlHelper helper, Planet planet) {
     if (planet == null) return new MvcHtmlString("?");
     var url = Global.UrlHelper();
     return
         new MvcHtmlString(string.Format("<a href='{0}' title='$planet${4}' style='{5}'><img src='/img/planets/{1}' width='{2}'>{3}</a>",
                                         url.Action("Planet", "Planetwars", new { id = planet.PlanetID }),
                                         planet.Resource.MapPlanetWarsIcon,
                                         planet.Resource.PlanetWarsIconSize/3,
                                         planet.Name,
                                         planet.PlanetID,
                                         planet.Faction != null ? "color:" + planet.Faction.Color : ""));
 }
示例#10
0
        public bool HasTreatyRight(Faction giverFaction, Func <TreatyEffectType, bool> test, Planet planet = null)
        {
            var effects = TreatyEffectsByReceivingFactionID.Where(x => x.FactionTreaty.TreatyState == TreatyState.Accepted && x.GivingFactionID == giverFaction.FactionID && (x.Planet == null || x.Planet == planet));

            return(effects.Any(x => test(x.TreatyEffectType)));
        }
 public List<Battle> GetPlanetBattles(Planet planet) {
     return GetPlanetWarsBattles().Where(x => x.MapName == planet.Resource.InternalName).ToList();
 }
示例#12
0
        public int?GetLinkDistanceTo(Func <Planet, bool> planetCondition, Faction traverseFaction, out Planet matchPlanet)
        {
            // check if this planet is the condition

            if (planetCondition(this) && (traverseFaction == null || OwnerFactionID == traverseFaction.FactionID))
            {
                matchPlanet = this;
                return(0);
            }

            int?          distance       = 0;
            List <Planet> checkedPlanets = new List <Planet>();
            List <Planet> front          = new List <Planet>()
            {
                this
            };

            do
            {
                checkedPlanets.AddRange(front);
                List <Planet> newFront = new List <Planet>();

                foreach (var p in front)
                {
                    // iterate links to this planet
                    foreach (var link in p.LinksByPlanetID1.Union(p.LinksByPlanetID2))
                    {
                        var otherPlanet = p.PlanetID == link.PlanetID1 ? link.PlanetByPlanetID2 : link.PlanetByPlanetID1;


                        if (!checkedPlanets.Contains(otherPlanet))
                        {
                            // planet has wormhole active and is traversable
                            if (traverseFaction == null || (otherPlanet.OwnerFactionID == traverseFaction.FactionID &&
                                                            otherPlanet.PlanetStructures.Any(x => x.IsActive && x.StructureType.EffectAllowShipTraversal == true)))
                            {
                                if (planetCondition(otherPlanet))
                                {
                                    matchPlanet = otherPlanet;
                                    return(distance + 1);
                                }
                                newFront.Add(otherPlanet);
                            }
                        }
                    }
                }

                front = newFront;
                distance++;
            } while (front.Count > 0);

            matchPlanet = null;
            return(null);
        }