Exemple #1
0
 public void addVillager(int x, int y, string type)
 {
     foreach (GameObject obj in buildings)
     {
         //Search for Utility Buildings
         UtilityBuilding building = obj.GetComponent(typeof(UtilityBuilding)) as UtilityBuilding;
         if (building != null)
         {
             //Search for Utility Buildings that have open spaces
             if (building.villagerStorage - building.currentVillagers >= 1)
             {
                 building.currentVillagers++;
                 if (type.Equals("Villager"))
                 {
                     GameObject villager = Instantiate(Resources.Load("Prefabs/villagerMale", typeof(GameObject))) as GameObject;
                     villager.transform.Translate(new Vector2(x, y));
                     villagers.Add(villager);
                 }
                 else if (type.Equals("Wizard"))
                 {
                     GameObject wizard = Instantiate(Resources.Load("Prefabs/Wizard", typeof(GameObject))) as GameObject;
                     wizard.transform.Translate(new Vector2(x, y));
                     villagers.Add(wizard);
                 }
                 //Load others by type here
                 break;
             }
         }
     }
 }
Exemple #2
0
 private void updatePlayerResources()
 {
     maxWood          = 0;
     maxStone         = 0;
     maxFood          = 0;
     maxVillagers     = 0;
     currentWood      = 0;
     currentStone     = 0;
     currentFood      = 0;
     currentVillagers = 0;
     foreach (GameObject obj in om.buildings)
     {
         UtilityBuilding building = obj.GetComponent(typeof(UtilityBuilding)) as UtilityBuilding;
         if (building != null)
         {
             maxWood          += building.woodStorage;
             maxStone         += building.stoneStorage;
             maxFood          += building.foodStorage;
             maxVillagers     += building.villagerStorage;
             currentWood      += building.currentWood;
             currentStone     += building.currentStone;
             currentFood      += building.currentFood;
             currentVillagers += building.currentVillagers;
         }
     }
 }
Exemple #3
0
 public void Close()
 {
     gameObject.SetActive(false);
     cityArmyUI.Close();
     currUtilityBuilding = null;
     AudioManager.instance.ClickButton();
     UIManager.instance.OnUIPanelClose();
 }
Exemple #4
0
    public bool purchaseBuilding(Building building)
    {
        bool purchaseMade = false;
        bool hasWood      = false;
        bool hasStone     = false;
        bool hasVillager  = false;

        if (building.woodCost <= gm.currentWood)
        {
            hasWood = true;
        }
        if (building.stoneCost <= gm.currentStone)
        {
            hasStone = true;
        }
        if (building.villagerCost.Equals(""))
        {
            hasVillager = true;
        }
        else
        {
            foreach (GameObject villager in villagers)
            {
                Villager v = villager.GetComponent(typeof(Villager)) as Villager;
                if (v.type.Equals(building.villagerCost))
                {
                    hasVillager = true;
                }
            }
        }

        if (hasWood && hasStone && hasVillager)
        {
            int woodCost  = building.woodCost;
            int stoneCost = building.stoneCost;
            foreach (GameObject buiObj in buildings)
            {
                UtilityBuilding uBuilding = buiObj.GetComponent(typeof(UtilityBuilding)) as UtilityBuilding;
                if (uBuilding != null)
                {
                    while (uBuilding.currentWood > 0 && woodCost > 0)
                    {
                        woodCost--;
                        uBuilding.currentWood--;
                    }
                    while (uBuilding.currentStone > 0 && stoneCost > 0)
                    {
                        stoneCost--;
                        uBuilding.currentStone--;
                    }
                }
            }
            purchaseMade = true;
        }

        return(purchaseMade);
    }
Exemple #5
0
    public void Open(UtilityBuilding utilityBuilding)
    {
        currUtilityBuilding = utilityBuilding;
        gameObject.SetActive(true);
        cityArmyUI.Open(GetCurrentBuildingArmy());

        RefreshWholePanelUI();

        gameObject.SetActive(true);

        UIManager.instance.OnUIPanelOpen();
    }
Exemple #6
0
        public ActionResult SendReservation(SendReservationModel model)
        {
            if (!ModelState.IsValid)
            {
                return(PartialView("_SendReservation", model));
            }

            UtilityBuilding building = null;

            using (var db = new OnLeaveContext())
            {
                building = db.UtilityBuildings
                           .Include(b => b.UtilityBuildingLocales)
                           .FirstOrDefault(b => b.UtilityBuildingId == model.UtilityBuildingId);
            }

            if (building == null)
            {
                return(new HttpStatusCodeResult(System.Net.HttpStatusCode.NotFound, "building not found"));
            }

            User user = null;

            using (var db = new UserDbContext())
            {
                user = db.Users.FirstOrDefault(u => u.Id == building.UserId);
            }

            if (user == null)
            {
                return(new HttpStatusCodeResult(System.Net.HttpStatusCode.NotFound, "user not found"));
            }

            dynamic email = new Email("_Reservation");

            email.To                     = ConfigurationManager.AppSettings["email"];
            email.From                   = ConfigurationManager.AppSettings["email"];
            email.Subject                = "Резервация от Отпускарче";
            email.ClientName             = model.ClientName;
            email.Email                  = model.Email;
            email.BuildingEmail          = user.Email;
            email.StartDate              = model.StartDate;
            email.EndDate                = model.EndDate;
            email.ReservationDescription = model.ReservationDescription;
            email.BuildingId             = building.UtilityBuildingId;
            email.Name                   = string.Join(" / ", building.UtilityBuildingLocales.Select(l => l.Name).ToArray());
            email.Send();

            ModelState.Clear();
            return(PartialView("_SendReservation", new SendReservationModel()));
        }
Exemple #7
0
 public void populate()
 {
     foreach (GameObject obj in buildings)
     {
         UtilityBuilding bui = obj.GetComponent(typeof(UtilityBuilding)) as UtilityBuilding;
         if (bui != null)
         {
             if (bui.currentVillagers < bui.villagerStorage)
             {
                 addVillager((int)obj.transform.position.x, (int)obj.transform.position.y - 5, "Villager");
             }
         }
     }
 }
Exemple #8
0
        public static Camp CreateCamp(int user_id, DbGeography loc, string name)
        {
            using (var db = new MinionWarsEntities())
            {
                Camp camp = new Camp();
                if (user_id == -1)
                {
                    camp.owner_id       = null;
                    camp.type           = "neutral";
                    camp.name           = name;
                    camp.size           = 30;
                    camp.building_count = 3;
                }
                else
                {
                    camp.owner_id       = user_id;
                    camp.type           = "owned";
                    camp.name           = name;
                    camp.size           = CalculateCampCapacity(user_id);
                    camp.building_count = 0;
                    bool result = CostManager.ApplyCampCost(camp.owner_id.Value);
                    if (!result)
                    {
                        return(null);
                    }
                }
                camp.location     = loc;
                camp.mapped_type  = "restaurant";
                camp.richness     = 0;
                camp.def_modifier = 0;
                camp.bg_id        = null;

                db.Camp.Add(camp);
                db.SaveChanges();

                if (user_id == -1)
                {
                    List <ResourceType> res = ResourceManager.getRandomRes();
                    for (int i = 0; i < 2; i++)
                    {
                        CampTreasury ct = new CampTreasury();
                        ct.camp_id = camp.id;
                        ct.amount  = 100;
                        ct.res_id  = res[i].id;
                        db.CampTreasury.Add(ct);

                        ResourceBuilding rb       = new ResourceBuilding();
                        Buildings        building = db.Buildings.Find(res[i].id); //db.Buildings.Where(x => x.name.Contains(res[i].name.ToLower())).First();
                        rb.camp_id  = camp.id;
                        rb.name     = building.name;
                        rb.rtype_id = res[i].id;
                        db.ResourceBuilding.Add(rb);
                    }

                    UtilityBuilding ub = new UtilityBuilding();
                    Buildings       b2 = db.Buildings.Find(16);
                    ub.camp_id     = camp.id;
                    ub.name        = b2.name;
                    ub.type        = 2;
                    ub.description = null;
                    db.UtilityBuilding.Add(ub);

                    db.SaveChanges();
                }

                return(camp);
            }
        }
Exemple #9
0
        public static bool CreateBuilding(int camp_id, int b_id)
        {
            using (var db = new MinionWarsEntities())
            {
                Camp      camp = db.Camp.Find(camp_id);
                Buildings b    = db.Buildings.Find(b_id);

                bool result = CostManager.ApplyBuildingCosts(b.id, camp.owner_id.Value);
                if (!result)
                {
                    return(false);
                }

                switch (b.type)
                {
                case "Resource Building":
                    ResourceBuilding rb = new ResourceBuilding();
                    rb.name     = b.name;
                    rb.camp_id  = camp_id;
                    rb.rtype_id = b.id;
                    db.ResourceBuilding.Add(rb);

                    UserTreasury ut = db.UserTreasury.Where(x => x.user_id == camp.owner_id && x.res_id == rb.rtype_id).First();
                    ut.generation += 5;
                    db.UserTreasury.Attach(ut);
                    db.Entry(ut).State = System.Data.Entity.EntityState.Modified;

                    break;

                case "Offensive Building":
                    OffensiveBuilding ob = new OffensiveBuilding();
                    ob.name      = b.name;
                    ob.minion_id = null;
                    ob.camp_id   = camp_id;
                    db.OffensiveBuilding.Add(ob);
                    break;

                case "Defensive Building":
                    DefensiveBuilding defb = new DefensiveBuilding();
                    defb.camp_id = camp_id;
                    if (b_id == 14)
                    {
                        camp.def_modifier += Int32.Parse(b.description);
                    }
                    else if (b_id == 17)
                    {
                        camp.size += Int32.Parse(b.description);
                    }
                    db.DefensiveBuilding.Add(defb);
                    break;

                case "Utility Building":
                    UtilityBuilding ub = new UtilityBuilding();
                    ub.camp_id     = camp_id;
                    ub.name        = b.name;
                    ub.type        = b_id;
                    ub.description = "";
                    db.UtilityBuilding.Add(ub);
                    break;
                }

                camp.building_count++;
                db.Camp.Attach(camp);
                db.Entry(camp).State = System.Data.Entity.EntityState.Modified;

                db.SaveChanges();

                return(true);
            }
        }
Exemple #10
0
    private void checkCollsions()
    {
        // Villagers x Monsters
        foreach (GameObject vilObj in villagers)
        {
            Villager         villager       = vilObj.GetComponent(typeof(Villager)) as Villager;
            BoxCollider2D    villagerBounds = vilObj.GetComponent(typeof(BoxCollider2D)) as BoxCollider2D;
            CircleCollider2D villagerRange  = vilObj.GetComponentInChildren(typeof(CircleCollider2D)) as CircleCollider2D;
            foreach (GameObject monObj in monsters)
            {
                Monster          monster       = monObj.GetComponent(typeof(Monster)) as Monster;
                BoxCollider2D    monsterBounds = monObj.GetComponent(typeof(BoxCollider2D)) as BoxCollider2D;
                CircleCollider2D monsterRange  = monObj.GetComponentInChildren(typeof(CircleCollider2D)) as CircleCollider2D;
                if (villagerRange.bounds.Intersects(monsterBounds.bounds))
                {
                    villager.attack(monster);
                }
            }
        }
        //Villagers x Buildings
        foreach (GameObject vilObj in villagers)
        {
            Villager         villager       = vilObj.GetComponent(typeof(Villager)) as Villager;
            BoxCollider2D    villagerBounds = vilObj.GetComponent(typeof(BoxCollider2D)) as BoxCollider2D;
            CircleCollider2D villagerRange  = vilObj.GetComponentInChildren(typeof(CircleCollider2D)) as CircleCollider2D;
            if (villager.currentFood > 0 || villager.currentWood > 0 || villager.currentStone > 0)
            {
                foreach (GameObject buiObj in buildings)
                {
                    UtilityBuilding  uBuilding      = buiObj.GetComponent(typeof(UtilityBuilding)) as UtilityBuilding;
                    BoxCollider2D    buildingBounds = buiObj.GetComponent(typeof(BoxCollider2D)) as BoxCollider2D;
                    CircleCollider2D buildingRange  = buiObj.GetComponentInChildren(typeof(CircleCollider2D)) as CircleCollider2D;
                    if (uBuilding != null)
                    {
                        if (villagerRange.bounds.Intersects(buildingBounds.bounds))
                        {
                            if (uBuilding.currentFood < uBuilding.foodStorage)
                            {
                                uBuilding.currentFood += villager.currentFood;
                                villager.currentFood   = 0;
                                if (uBuilding.currentFood > uBuilding.foodStorage)
                                {
                                    uBuilding.currentFood = uBuilding.foodStorage;
                                }
                            }
                            if (uBuilding.currentWood < uBuilding.woodStorage)
                            {
                                uBuilding.currentWood += villager.currentWood;
                                villager.currentWood   = 0;
                                if (uBuilding.currentWood > uBuilding.woodStorage)
                                {
                                    uBuilding.currentWood = uBuilding.woodStorage;
                                }
                            }
                            if (uBuilding.currentStone < uBuilding.stoneStorage)
                            {
                                uBuilding.currentStone += villager.currentStone;
                                villager.currentStone   = 0;
                                if (uBuilding.currentStone > uBuilding.stoneStorage)
                                {
                                    uBuilding.currentStone = uBuilding.stoneStorage;
                                }
                            }
                        }
                    }
                }
            }
        }
        //Villager x Zones
        foreach (GameObject vilObj in villagers)
        {
            Villager         villager       = vilObj.GetComponent(typeof(Villager)) as Villager;
            BoxCollider2D    villagerBounds = vilObj.GetComponent(typeof(BoxCollider2D)) as BoxCollider2D;
            CircleCollider2D villagerRange  = vilObj.GetComponentInChildren(typeof(CircleCollider2D)) as CircleCollider2D;
            if (villagerRange.bounds.Intersects(woodZone.GetComponent <BoxCollider2D>().bounds))
            {
                villager.inGatherZone   = true;
                villager.gatherZoneType = "Wood";
            }
            else if (villagerRange.bounds.Intersects(stoneZone.GetComponent <BoxCollider2D>().bounds))
            {
                villager.inGatherZone   = true;
                villager.gatherZoneType = "Stone";
            }
            else if (villagerRange.bounds.Intersects(foodZone.GetComponent <BoxCollider2D>().bounds))
            {
                villager.inGatherZone   = true;
                villager.gatherZoneType = "Food";
            }
            else
            {
                villager.inGatherZone   = false;
                villager.gatherZoneType = "";
            }
        }
        // Monsters x Villagers
        foreach (GameObject monObj in monsters)
        {
            Monster          monster       = monObj.GetComponent(typeof(Monster)) as Monster;
            BoxCollider2D    monsterBounds = monObj.GetComponent(typeof(BoxCollider2D)) as BoxCollider2D;
            CircleCollider2D monsterRange  = monObj.GetComponentInChildren(typeof(CircleCollider2D)) as CircleCollider2D;
            foreach (GameObject vilObj in villagers)
            {
                Villager         villager       = vilObj.GetComponent(typeof(Villager)) as Villager;
                BoxCollider2D    villagerBounds = vilObj.GetComponent(typeof(BoxCollider2D)) as BoxCollider2D;
                CircleCollider2D villagerRange  = vilObj.GetComponentInChildren(typeof(CircleCollider2D)) as CircleCollider2D;
                if (monsterRange.bounds.Intersects(villagerBounds.bounds))
                {
                    monster.attack(villager);
                }
            }
        }
        // Buildings x Monsters
        foreach (GameObject buiObj in buildings)
        {
            DefenseBuilding  building       = buiObj.GetComponent(typeof(DefenseBuilding)) as DefenseBuilding;
            BoxCollider2D    buildingBounds = buiObj.GetComponent(typeof(BoxCollider2D)) as BoxCollider2D;
            CircleCollider2D buildingRange  = buiObj.GetComponentInChildren(typeof(CircleCollider2D)) as CircleCollider2D;//buiObj.GetComponent(typeof(CircleCollider2D)) as CircleCollider2D;

            if (building != null)
            {
                foreach (GameObject monObj in monsters)
                {
                    Monster          monster       = monObj.GetComponent(typeof(Monster)) as Monster;
                    BoxCollider2D    monsterBounds = monObj.GetComponent(typeof(BoxCollider2D)) as BoxCollider2D;
                    CircleCollider2D monsterRange  = monObj.GetComponentInChildren(typeof(CircleCollider2D)) as CircleCollider2D;
                    if (buildingRange.bounds.Intersects(monsterBounds.bounds))
                    {
                        building.attack(monster);
                    }
                }
            }
        }
        // Monsters x Buildings
        foreach (GameObject monObj in monsters)
        {
            Monster          monster       = monObj.GetComponent(typeof(Monster)) as Monster;
            BoxCollider2D    monsterBounds = monObj.GetComponent(typeof(BoxCollider2D)) as BoxCollider2D;
            CircleCollider2D monsterRange  = monObj.GetComponentInChildren(typeof(CircleCollider2D)) as CircleCollider2D;
            foreach (GameObject buiObj in buildings)
            {
                Building         building       = buiObj.GetComponent(typeof(Building)) as Building;
                BoxCollider2D    buildingBounds = buiObj.GetComponent(typeof(BoxCollider2D)) as BoxCollider2D;
                CircleCollider2D buildingRange  = buiObj.GetComponentInChildren(typeof(CircleCollider2D)) as CircleCollider2D;
                if (building != null && monsterRange.bounds.Intersects(buildingBounds.bounds))
                {
                    monster.attack(building);
                }
            }
        }
    }
Exemple #11
0
    public void showInfoPanel(GameObject obj)
    {
        hideInfoPanels();
        Character       character = obj.GetComponent(typeof(Character)) as Character;
        DefenseBuilding dBuilding = obj.GetComponent(typeof(DefenseBuilding)) as DefenseBuilding;
        UtilityBuilding uBuilding = obj.GetComponent(typeof(UtilityBuilding)) as UtilityBuilding;

        if (character != null)
        {
            characterInfoPanel.SetActive(true);
            Text type = characterInfoPanel.transform.Find("TypeText").gameObject.GetComponent <Text>();
            Text hp   = characterInfoPanel.transform.Find("HPText").gameObject.GetComponent <Text>();
            Text atk  = characterInfoPanel.transform.Find("ATKText").gameObject.GetComponent <Text>();
            Text def  = characterInfoPanel.transform.Find("DEFText").gameObject.GetComponent <Text>();
            Text mgk  = characterInfoPanel.transform.Find("MGKText").gameObject.GetComponent <Text>();
            Text wil  = characterInfoPanel.transform.Find("WILText").gameObject.GetComponent <Text>();
            Text spd  = characterInfoPanel.transform.Find("SPDText").gameObject.GetComponent <Text>();
            Text rng  = characterInfoPanel.transform.Find("RNGText").gameObject.GetComponent <Text>();
            type.text = character.type;
            hp.text   = character.hp + " / " + character.mhp;
            atk.text  = character.atk.ToString();
            def.text  = character.def.ToString();
            mgk.text  = character.mgk.ToString();
            wil.text  = character.wil.ToString();
            spd.text  = character.spd.ToString();
            rng.text  = character.rng.ToString();
        }
        else if (dBuilding != null)
        {
            characterInfoPanel.SetActive(true);
            Text type = characterInfoPanel.transform.Find("TypeText").gameObject.GetComponent <Text>();
            Text hp   = characterInfoPanel.transform.Find("HPText").gameObject.GetComponent <Text>();
            Text atk  = characterInfoPanel.transform.Find("ATKText").gameObject.GetComponent <Text>();
            Text def  = characterInfoPanel.transform.Find("DEFText").gameObject.GetComponent <Text>();
            Text mgk  = characterInfoPanel.transform.Find("MGKText").gameObject.GetComponent <Text>();
            Text wil  = characterInfoPanel.transform.Find("WILText").gameObject.GetComponent <Text>();
            Text spd  = characterInfoPanel.transform.Find("SPDText").gameObject.GetComponent <Text>();
            Text rng  = characterInfoPanel.transform.Find("RNGText").gameObject.GetComponent <Text>();
            type.text = dBuilding.type;
            hp.text   = dBuilding.hp + " / " + dBuilding.mhp;
            atk.text  = dBuilding.atk.ToString();
            def.text  = dBuilding.def.ToString();
            mgk.text  = dBuilding.mgk.ToString();
            wil.text  = "---";
            spd.text  = dBuilding.spd.ToString();
            rng.text  = dBuilding.rng.ToString();
        }
        else if (uBuilding != null)
        {
            uBuildingInfoPanel.SetActive(true);
            Text type  = uBuildingInfoPanel.transform.Find("TypeText").gameObject.GetComponent <Text>();
            Text hp    = uBuildingInfoPanel.transform.Find("HPText").gameObject.GetComponent <Text>();
            Text def   = uBuildingInfoPanel.transform.Find("DEFText").gameObject.GetComponent <Text>();
            Text wood  = uBuildingInfoPanel.transform.Find("WoodText").gameObject.GetComponent <Text>();
            Text stone = uBuildingInfoPanel.transform.Find("StoneText").gameObject.GetComponent <Text>();
            Text vil   = uBuildingInfoPanel.transform.Find("VilText").gameObject.GetComponent <Text>();
            Text food  = uBuildingInfoPanel.transform.Find("FoodText").gameObject.GetComponent <Text>();
            type.text  = uBuilding.type;
            hp.text    = uBuilding.hp + " / " + uBuilding.mhp;
            def.text   = uBuilding.def.ToString();
            wood.text  = uBuilding.currentWood + " / " + uBuilding.woodStorage;
            stone.text = uBuilding.currentStone + " / " + uBuilding.stoneStorage;
            vil.text   = uBuilding.currentVillagers + " / " + uBuilding.villagerStorage;
            food.text  = uBuilding.currentFood + " / " + uBuilding.foodStorage;
        }
    }