示例#1
0
        public IHttpActionResult ZombieStartAttackBase(string id)
        {
            Character character = db.Characters.Where(x => x.ApplicationUserID == id).FirstOrDefault();

            List <Building> CharacterBuildings = new List <Building>();
            var             result             = "";

            foreach (var item in character.Inventory)
            {
                foreach (var build in db.Buildings)
                {
                    if (item.ItemID == build.ItemID && build.BuildingLevel != 0)
                    {
                        CharacterBuildings.Add(build);
                    }
                }
            }

            if (CharacterBuildings.Count > 0)
            {
                Random rand   = new Random();
                int    ZombId = rand.Next(1, db.Zombies.Count() + 1);
                Zombie zombie = db.Zombies.Find(ZombId);

                character.LastZombieAttackTime = DateTime.Now;
                db.SaveChanges();


                ZombieAttackBase zab = new ZombieAttackBase {
                    ZombieAttackStart = DateTime.Now, CharacterID = character.CharacterID, ZombieID = zombie.ZombieID, ZombieLife = zombie.ZombieLife
                };
                db.ZombieAttackBases.Add(zab);
                db.SaveChanges();

                result += zombie.ZombieName + " attacked the base!";
            }
            else
            {
                character.LastZombieAttackTime = DateTime.Now;
                db.SaveChanges();
            }


            return(Ok(result));
        }
示例#2
0
        public ActionResult CollectReward(int zABID, int rewardXP, int rewardCoin)
        {
            AttackingZombieReward model = new AttackingZombieReward();

            model.RexardXP   = rewardXP;
            model.RewardCoin = rewardCoin;

            Character character = db.Characters.Where(y => y.ApplicationUserID == User.Identity.Name).FirstOrDefault();

            ZombieAttackBase zAB = db.ZombieAttackBases.Find(zABID);

            var addXP = new CharactersController().ManageXPAndLevelUp(User.Identity.Name, rewardXP, this.Request.FilePath);

            character.CharacterMoney += rewardCoin;
            db.ZombieAttackBases.Remove(zAB);


            db.SaveChanges();
            base.SetModelProperties(model);

            return(View(model));
        }