예제 #1
0
        public ActionResult New(int gameID)
        {
            Debug.WriteLine(string.Format("GET: Unit Controller: New"));

            var game       = GameState.Game;
            var categories = new List <Checkbox>();

            categories.Add(new Checkbox(-1, "None", true));
            foreach (var category in game.GameStatistics.UnitCategoriesRaw)
            {
                categories.Add(new Checkbox(category.id, category.name, false));
            }

            return(View(new UnitForm
            {
                Categories = categories,
                UnitTypes = UnitTypes.GetUnitTypesCheckboxes()
            }));
        }
예제 #2
0
        public ActionResult Edit(UnitForm form)
        {
            Debug.WriteLine(string.Format("POST: Ship Controller: Edit - unitID={0}", form.ID));
            var game = GameState.Game;

            var unit = game.GameStatistics.UnitsRaw.Find(x => x.id == form.ID);

            if (unit.game_id == null || unit.game_id != game.Info.id)
            {
                return(RedirectToRoute("game", new { gameID = game.Info.id }));
            }

            unit.unit_category_id = (form.SelectedCategoryID == -1) ? null : form.SelectedCategoryID;

            unit.name            = form.Name;
            unit.unit_type       = UnitTypes.GetUnitTypesCheckboxes().Where(x => x.ID == form.SelectedUnitTypeID).First().Name;
            unit.description     = form.Description;
            unit.rp_cost         = form.RPCost;
            unit.number_to_build = form.NumberToBuild;

            unit.can_embark = form.CanEmbark;
            unit.can_attack_ground_units = form.CanAttackGroundUnits;
            unit.can_attack_boats        = form.CanAttackBoats;
            unit.can_attack_planes       = form.CanAttackPlanes;
            unit.can_attack_spaceships   = form.CanAttackSpaceships;

            unit.embarking_slots = form.EmbarkingSlots;
            unit.negate_damage   = form.NegateDamage;

            unit.base_health         = form.BaseHealth;
            unit.base_regeneration   = form.BaseRegeneration;
            unit.base_attack         = form.BaseAttack;
            unit.base_special_attack = form.BaseSpecialAttack;
            unit.base_agility        = form.BaseAgility;

            unit.gmnotes = form.GMNotes;
            Database.Session.Update(unit);

            Database.Session.Flush();
            return(RedirectToRoute("Statistics"));
        }
예제 #3
0
        public ActionResult Edit(int gameID, int?unitID)
        {
            Debug.WriteLine(string.Format("GET: Ship Controller: Edit - unitID={0}", unitID));
            var game = GameState.Game;

            var unit = game.GameStatistics.UnitsRaw.Find(x => x.id == unitID);

            var categories = new List <Checkbox>();

            categories.Add(new Checkbox(-1, "None", false));
            foreach (var category in game.GameStatistics.UnitCategoriesRaw)
            {
                categories.Add(new Checkbox(category.id, category.name, category.id == unit.unit_category_id));
            }

            var selected = categories.Where(x => x.IsChecked).ToList();

            if (selected.Count == 0)
            {
                categories[0].IsChecked = true;
            }

            var unitTypes = UnitTypes.GetUnitTypesCheckboxes();

            foreach (var checkbox in unitTypes)
            {
                if (checkbox.Name == unit.unit_type)
                {
                    checkbox.IsChecked = true;
                }
            }

            return(View(new UnitForm
            {
                ID = unit.id,

                Name = unit.name,
                Description = unit.description,
                RPCost = unit.rp_cost,
                NumberToBuild = unit.number_to_build,

                CanEmbark = unit.can_embark,
                CanAttackGroundUnits = unit.can_attack_ground_units,
                CanAttackBoats = unit.can_attack_boats,
                CanAttackPlanes = unit.can_attack_planes,
                CanAttackSpaceships = unit.can_attack_spaceships,

                EmbarkingSlots = unit.embarking_slots,
                NegateDamage = unit.negate_damage,

                BaseHealth = unit.base_health,
                BaseRegeneration = unit.base_regeneration,
                BaseAttack = unit.base_attack,
                BaseSpecialAttack = unit.base_special_attack,
                BaseAgility = unit.base_agility,

                GMNotes = unit.gmnotes,

                Categories = categories,
                UnitTypes = unitTypes,
            }));
        }