Beispiel #1
0
        public static void buildUnit(IStarWars3DB context, int playerId, UnitType unitType, CellDTO location)
        {
            Cell cell = FreeCell(context, location.row, location.col);

            //UnitLevel uLevel = GetUnitLevel(context, unitType, 0);

            if (cell != null)
            {
                UnitTemplate unitTemplate = context.UnitTemplates.FirstOrDefault(t => t.UnitType == unitType);
                if (unitTemplate == null)
                {
                    throw new NullReferenceException("BuildFighter: unitTemplate not found!");
                }

                Unit unit = new Unit()
                {
                    UnitTemplateId  = unitTemplate.Id,
                    PlayerId        = playerId,
                    Location        = cell,
                    Armor           = unitTemplate.Armor,
                    Damage          = unitTemplate.Damage,
                    Shield          = unitTemplate.Shield,
                    Range           = unitTemplate.Range,
                    Speed           = unitTemplate.Speed,
                    Health          = unitTemplate.Health,
                    FuelConsumption = unitTemplate.FuelConsumption
                };

                context.Units.Add(unit);
                context.SaveChanges();
            }
        }
Beispiel #2
0
        public static void ChangeUnitLocation(IStarWars3DB context, CellDTO selectedCell, CellDTO previousCell)
        {
            Unit unit        = GetUnitByLocation(context, previousCell.row, previousCell.col);
            Cell newLocation = new Cell
            {
                row = selectedCell.row,
                col = selectedCell.col
            };

            context.Cells.Add(newLocation);
            unit.Location = newLocation;
            context.SaveChanges();
        }
Beispiel #3
0
        public static int Initialise(string aspNetId, IStarWars3DB context)
        {
            int?playerId;

            if (!(context.Players.Any(p => p.AspNetId == aspNetId)))
            {
                Planet planet = new Planet()
                {
                    PlanetTemplate = context.PlanetTemplates.FirstOrDefault(p => p.IsTaken == false)
                };

                if (planet.PlanetTemplate == null)
                {
                    throw new ArgumentException("No available planets found");
                }

                planet.PlanetTemplate.IsTaken = true;

                context.Players.Add(new Player()
                {
                    AspNetId = aspNetId,
                    Planets  = new[] { planet },
                    Gas      = Constants.InitialPlayerGas,
                    Metal    = Constants.InitialPlayerMetal,
                    Minerals = Constants.InitialPlayerMinerals
                });

                context.SaveChanges();
            }

            playerId = context.Players.FirstOrDefault(p => p.AspNetId == aspNetId).Id;

            if (playerId == null)
            {
                throw new ArgumentException("Initialise: PlayerId cannot be null");
            }

            return((int)playerId);
        }
Beispiel #4
0
        public static void BuildFactory(IStarWars3DB context, FactoryType factoryType, int playerId, CellDTO location)
        {
            FactoryTemplate factoryTemplate = context.FactoryTemplates.FirstOrDefault(t => t.FactoryType == factoryType);

            if (factoryTemplate == null)
            {
                throw new NullReferenceException("BuildFactory: Factory type not found!");
            }

            Factory factory = new Factory()
            {
                FactoryTemplateId = factoryTemplate.Id,
                Level             = factoryTemplate.Level,
                PlayerId          = playerId,
                Health            = factoryTemplate.Health,
                Shield            = factoryTemplate.Shield,
                Location          = new Cell {
                    row = location.row, col = location.col
                }
            };

            context.Factories.Add(factory);
            context.SaveChanges();
        }