Exemplo n.º 1
0
 public int Add(Diplomacy o)
 {
     return new DiplomacyDAO().Add(o);
 }
Exemplo n.º 2
0
        public void DiplomacyStatusUpdate(int mapId, IList<Field> fields)
        {
            IList<Kingdom> kingdoms = new KingdomDAO().GetByMapId(mapId);

            Dictionary<int, Rectangle> kingdomsArea = new Dictionary<int, Rectangle>();

            foreach (Field field in fields)
            {
                if (!kingdomsArea.ContainsKey(field.KingdomId))
                {
                    kingdomsArea[field.KingdomId] = new Rectangle();
                }

                if (field.FieldX > kingdomsArea[field.KingdomId].maxX) kingdomsArea[field.KingdomId].maxX = field.FieldX;
                if (field.FieldY > kingdomsArea[field.KingdomId].maxY) kingdomsArea[field.KingdomId].maxY = field.FieldY;

                if (field.FieldX < kingdomsArea[field.KingdomId].minX) kingdomsArea[field.KingdomId].minX = field.FieldX;
                if (field.FieldY < kingdomsArea[field.KingdomId].minY) kingdomsArea[field.KingdomId].minY = field.FieldY;
            }


            foreach (Kingdom kingdom in kingdoms)
            {
                IList<Diplomacy> diplomacy = new DiplomacyDAO().GetByUserId(kingdom.UserId);

                foreach (Kingdom kingdomA in kingdoms)
                {
                    if(kingdomsArea[kingdom.KingdomId].CollidesWith(kingdomsArea[kingdomA.KingdomId],2)){
                        bool mustAdd = true;
                        foreach (Diplomacy dip in diplomacy)
                        {
                            if (dip.SecondaryUserId == kingdomA.UserId) mustAdd = false;
                        }

                        if (mustAdd)
                        {
                            Diplomacy dip = new Diplomacy();
                            dip.MainUserId = kingdom.UserId;
                            dip.SecondaryUserId = kingdomA.UserId;
                            dip.DiplomacyStatusId = 1;// hardcode, nie che mi sie znowu do bazy dodawac pierdolowatej metody, w bazie najlepiej by pod tym id byla wojna

                            new DiplomacyDAO().Add(dip);
                        }
                    }
                }

            }

        }