Beispiel #1
0
        public static double GetPercentageOfGuildedHousesInArea(Point3D location, Map map, int radius, Guild guild, bool bIgnoreAlliedHouses)
        {
            double guildPercentage = 0.0;

            if (guild == null)
            {
                return(guildPercentage);                           //doublecheck this - return 0 if we're not guilded
            }
            if (location == Point3D.Zero)
            {
                return(guildPercentage); //might as well check that we're not the default point
            }
            try                          //safety
            {
                int x = location.X;
                int y = location.Y;
                int z = location.Z;

                int x_start = x - radius;
                int y_start = y - radius;
                int x_end   = x + radius;
                int y_end   = y + radius;

                Rectangle2D      rect      = new Rectangle2D(x_start, y_start, TownshipStone.INITIAL_RADIUS * 2, TownshipStone.INITIAL_RADIUS * 2);
                List <BaseHouse> houseList = TownshipDeed.GetHousesInRect(rect, map);

                int guildCount = 0;
                int allyCount  = 0;
                int otherCount = 0;

                int siegetentCount = 0;

                int countedHouses = 0;

                foreach (BaseHouse h in houseList)
                {
                    if (h != null && h.Owner != null)
                    {
                        countedHouses++;

                        Guild houseGuild = h.Owner.Guild as Guilds.Guild;

                        if (h is SiegeTent)
                        {
                            siegetentCount++;
                        }
                        else
                        {
                            if (houseGuild == null)
                            {
                                otherCount++;
                            }
                            else if (houseGuild == guild)
                            {
                                guildCount++;
                            }
                            else if (guild.IsAlly(houseGuild))
                            {
                                allyCount++;
                            }
                            else
                            {
                                otherCount++;
                            }
                        }
                    }
                }

                guildPercentage = ((double)guildCount) / ((double)(countedHouses - allyCount - siegetentCount));
            }
            catch (Exception ex) { EventSink.InvokeLogException(new LogExceptionEventArgs(ex)); }
            return(guildPercentage);
        }