Example #1
0
        public void InstantiateShip()
        {
            ShipConfiguration config = new ShipConfiguration(CurrentConfig.Stats_Weapons, CurrentConfig.Stats_Defenses,
                                                             CurrentConfig.Stats_Thrusters, CurrentConfig.Mass, CurrentConfig.ColliderForm, CurrentConfig.BodySprite);

            playerMgr.SetupPlayer(config);
        }
Example #2
0
        /// <summary>
        /// Aggregates the configurations with the multiplicity as index.
        /// </summary>
        /// <returns></returns>
        private List <ShipConfiguration> AggregatedConfigurations()
        {
            List <ShipConfiguration> aggregated = new List <ShipConfiguration>();

            foreach (var configuration in this.configurations)
            {
                // Configuration attributes.
                int      width  = configuration.Dimension.Width;
                int      height = configuration.Dimension.Height;
                ShipType type   = configuration.Type;

                // Look if the configuration has already been registered.
                ShipConfiguration registered = aggregated.FirstOrDefault(c => this.ConfigurationsMatch(c, configuration));

                if (registered == null)
                {
                    // Recycle the old object.
                    aggregated.Add(configuration);
                }
                else
                {
                    registered.Multiplicity += 1;
                }
            }

            return(aggregated);
        }
Example #3
0
        private void Add_Ship(object sender, RoutedEventArgs e)
        {
            int      x       = this.PositionX - 1;
            int      y       = this.PositionY - 1;
            int      width   = this.ShipWidth;
            int      height  = this.ShipHeight;
            bool     rotated = this.Rotation;
            ShipType type    = this.ShipType;

            Dimension         dimension     = new Dimension(width, height);
            ShipConfiguration configuration = new ShipConfiguration(type, dimension, 1);
            Ship ship = this.ShipBuilder.FromConfiguration(configuration, x, y, rotated);

            if (ship == null || this.ShipBuilder.ShipIntersects(ship, this.shipView.Map))
            {
                String message = "Invalid ship";
                MessageBox.Show(message, "", MessageBoxButton.OK, MessageBoxImage.Exclamation);
            }
            else
            {
                this.configurations.Add(configuration);

                this.UserShips.Add(ship);
                this.shipView.Map.Ships = this.UserShips.ToList();
                this.shipView.Update();

                this.ResetForm();
            }
        }
Example #4
0
        public Ship FromConfiguration(ShipConfiguration configuration, int x, int y, bool rotated)
        {
            Dimension dimension = new Dimension(configuration.Dimension);

            if (rotated)
            {
                int width = dimension.Width;
                dimension.Width  = dimension.Height;
                dimension.Height = width;
            }

            if (this.FitBounds(x, y, dimension))
            {
                // Make a ship from the configuration.
                Ship ship = new Ship(configuration.Type, configuration.Dimension);

                for (int i = x; i < x + dimension.Width; i++)
                {
                    for (int j = y; j < y + dimension.Height; j++)
                    {
                        Cell cell = new Cell(i, j, ship);
                        ship.Cells.Add(cell);
                    }
                }

                return(ship);
            }

            return(null);
        }
Example #5
0
    public void WriteSaveData(ShipConfiguration config)
    {
        string          json = JsonUtility.ToJson(config);
        BinaryFormatter bf   = new BinaryFormatter();
        FileStream      file = File.Create(Application.persistentDataPath + "/sandbox.sav");

        bf.Serialize(file, json);
        file.Close();
    }
Example #6
0
 public GameConfigurationManager()
 {
     bulletConfig                 = new BulletConfiguration();
     gameConfig                   = new GameConfiguration();
     shipConfig                   = new ShipConfiguration();
     mapConfig                    = new MapConfiguration();
     screenConfig                 = new ScreenConfiguration();
     leaderboardConfig            = new LeaderboardConfiguration();
     healthPackConfig             = new HealthPackConfiguration();
     abilityConfig                = new AbilityConfiguration();
     shipMovementControllerConfig = new ShipMovementControllerConfiguration();
 }
 public GameConfigurationManager()
 {
     bulletConfig = new BulletConfiguration();
     gameConfig = new GameConfiguration();
     shipConfig = new ShipConfiguration();
     mapConfig = new MapConfiguration();
     screenConfig = new ScreenConfiguration();
     leaderboardConfig = new LeaderboardConfiguration();
     healthPackConfig = new HealthPackConfiguration();
     abilityConfig = new AbilityConfiguration();
     shipMovementControllerConfig = new ShipMovementControllerConfiguration();
 }
Example #8
0
 public void CopyData(CampaignSquadron squadron)
 {
     this.Name = squadron.Name;
     this.ShipCount = squadron.ShipCount;
     this.cost = squadron.cost;
     this.buildPointCost = squadron.buildPointCost;
     this.Icon = squadron.Icon;
     this.isSelected = squadron.isSelected;
     this.shipConfiguration = squadron.shipConfiguration;
     this.buildWindowPosition = squadron.buildWindowPosition;
     this.ID = squadron.ID;
 }
 public void Save(ShipConfiguration shipConfig)
 {
     foreach (ShipComponentSlot slot in shipConfig.shipComponentSlots)
     {
         if (slot.shipComponent != null)
         {
             componentIDs.Add(slot.shipComponent.id);
         }
         else
         {
             componentIDs.Add(0);
         }
     }
 }
    public void Load(ShipConfigurationManager shipConfigManager)
    {
        TextReader tr;

        //error loading file
        if ((tr = new StreamReader(fileName)) == null)
        {
            return;
        }

        UnitList unitList = GameObject.Find("_Lists").GetComponent<UnitList>();
        ShipComponentList componentList = GameObject.Find("_Lists").GetComponent<ShipComponentList>();
        while (tr.Peek() != -1)
        {
            ShipConfiguration config = new ShipConfiguration();

            string line = tr.ReadLine();
            config.configurationName = line;

            line = tr.ReadLine();
            Ship ship = unitList.GetShipByID(int.Parse(line));
            if (ship != null)
            {
                config.SetShip(ship);

                line = tr.ReadLine();
                string[] components = line.Split(' ');
                for (int i = 0; i < config.shipComponentSlots.Count; i++)
                {
                    config.shipComponentSlots[i].shipComponent = componentList.GetComponentByID(int.Parse(components[i]));
                }

                shipConfigManager.shipConfigurations.Add(config);
            }
            else
            {
                Debug.Log("Error cannot find ship id: " + line);
            }
        }

        tr.Close();
    }
Example #11
0
    //TODO: REWRITE ASAP
    public static Ship.GenericShip SpawnShip(ShipConfiguration shipConfig)
    {
        //temporary
        int     id       = 1;
        Vector3 position = Vector3.zero;

        Ship.GenericShip newShipContainer = (Ship.GenericShip)System.Activator.CreateInstance(System.Type.GetType(shipConfig.PilotName));
        newShipContainer.InitializeGenericShip(shipConfig.PlayerNo, id, position);

        foreach (var upgrade in shipConfig.Upgrades)
        {
            newShipContainer.InstallUpgrade(upgrade);
        }

        Roster.SubscribeActions(newShipContainer.InfoPanel.transform.Find("ShipInfo").gameObject);
        Roster.SubscribeUpgradesPanel(newShipContainer, newShipContainer.InfoPanel);

        //TODO: Rework this
        newShipContainer.AfterGotNumberOfPrimaryWeaponAttackDices  += Rules.DistanceBonus.CheckAttackDistanceBonus;
        newShipContainer.AfterGotNumberOfPrimaryWeaponDefenceDices += Rules.DistanceBonus.CheckDefenceDistanceBonus;
        newShipContainer.AfterGotNumberOfPrimaryWeaponDefenceDices += Rules.AsteroidObstruction.CheckDefenceDistanceBonus;
        newShipContainer.OnTryAddAvailableAction     += Rules.Stress.CanPerformActions;
        newShipContainer.OnTryAddAvailableAction     += Rules.DuplicatedActions.CanPerformActions;
        newShipContainer.OnMovementStart             += Rules.Collision.ClearBumps;
        newShipContainer.OnMovementStart             += MovementTemplates.ApplyMovementRuler;
        newShipContainer.OnMovementStart             += MovementTemplates.CallReturnRangeRuler;
        newShipContainer.OnPositionFinish            += Rules.OffTheBoard.CheckOffTheBoard;
        newShipContainer.OnMovementExecuted          += Rules.Stress.CheckStress;
        newShipContainer.OnMovementFinish            += Rules.AsteroidHit.CheckDamage;
        newShipContainer.AfterGetManeuverAvailablity += Rules.Stress.CannotPerformRedManeuversWhileStressed;

        newShipContainer.AfterTokenIsAssigned         += Roster.UpdateTokensIndicator;
        newShipContainer.AfterTokenIsRemoved          += Roster.UpdateTokensIndicator;
        newShipContainer.AfterAssignedDamageIsChanged += Roster.UpdateRosterHullDamageIndicators;
        newShipContainer.AfterAssignedDamageIsChanged += Roster.UpdateRosterShieldsDamageIndicators;
        newShipContainer.AfterStatsAreChanged         += Roster.UpdateShipStats;

        newShipContainer.Owner.SquadCost += shipConfig.ShipCost;

        return(newShipContainer);
    }
Example #12
0
        public static IShipConfiguration CreateShipConfiguration(Nullable <ShipType> shipType, Nullable <ShipConfigurationType> shipConfigurationType)
        {
            switch (shipConfigurationType)
            {
            case ShipConfigurationType.Heavy:
                IShipConfiguration heavy = new ShipConfiguration();
                CreateHeavyDefaultCollection(heavy, shipType);
                return(heavy);

            case ShipConfigurationType.Light:
                IShipConfiguration light = new ShipConfiguration();
                CreateLightDefaultCollection(light, shipType);
                return(light);

            case ShipConfigurationType.Balanced:
                IShipConfiguration balanced = new ShipConfiguration();
                CreateBalancedDefaultCollection(balanced, shipType);
                return(balanced);

            default:
                return(null);
            }
        }
Example #13
0
        /// <summary>
        /// Start is called before the first frame update
        /// </summary>
        private void Start()
        {
            ShipDefenses  defenses  = new ShipDefenses();
            ShipThrusters thrusters = new ShipThrusters();
            ShipWeaponry  weapons   = new ShipWeaponry();

            Vector2[] colliders = null;

            #region Setup

            defenses.ArmorStrength    = 50f;
            defenses.ShieldRecharge   = 1f;
            defenses.ShieldStrength   = 15f;
            defenses.ShieldDelay      = 5f;
            defenses.DamageResistance = 15f;

            thrusters.DampenerStrength     = 0.5f;              // Equivalent to rigidbody linear drag set before this temp code (shipDragRate was unused)
            thrusters.ForwardThrusterForce = 10f;               // Equivalent to shipAccRate set in the old player class ResetPlayer()
            thrusters.MaxDirectionalSpeed  = 10f;               // Equivalent to shipMaxSpd set in old player class
            thrusters.RecoilCompensation   = 0.9f;
            thrusters.ReverseThrusterForce = 3f;
            thrusters.RotationalSpeed      = 5f;                // Equivalent to shipRotSpd set in old player class

            ShipWeapon basicBlaster = new ShipWeapon();
            basicBlaster.Damage       = 5f;                     // Original hardcoded value in prototyped Projectile was 5
            basicBlaster.Name         = "Basic Blaster";
            basicBlaster.OutputPrefab = bulletPrefab;           // The prefabs and sounds will eventually be handled/stored outside Player
            basicBlaster.OutputSound  = bulletSound;
            basicBlaster.RateOfFire   = 0.35f;                  // Originally fireRate in old Player
            basicBlaster.Recoil       = 15f;                    // Originally -shipAcc * 5f when handling recoil in old Player
            basicBlaster.Speed        = 200f;                   // Originally projectileSpeed in old Player
            basicBlaster.Type         = WeaponType.projectile;
            ShipWeapon secondBlaster = new ShipWeapon();
            secondBlaster.Damage       = 1f;
            secondBlaster.Name         = "Secondary Blaster";
            secondBlaster.OutputPrefab = bulletPrefab;
            secondBlaster.OutputSound  = bulletSound2;
            secondBlaster.RateOfFire   = 0.2f;
            secondBlaster.Recoil       = 5f;
            secondBlaster.Speed        = 100f;
            secondBlaster.Type         = WeaponType.projectile;

            weapons.DamageModifier = 1;
            weapons.RateModifier   = 1;
            weapons.WeaponCount    = 3;
            weapons.Positions      = new List <Vector3>()
            {
                new Vector3(0.35f, 0, 0),
                new Vector3(0.25f, 0.21f, 0),
                new Vector3(0.25f, -0.21f, 0)
            };
            weapons.Rotations = new List <Vector3>
            {
                { new Vector3(0, 0, 0) },
                { new Vector3(0, 0, 10f) },
                { new Vector3(0, 0, -10f) }
            };
            weapons.SlotStatus = new List <WeaponSlotStatus>
            {
                { WeaponSlotStatus.enabled },
                { WeaponSlotStatus.enabled },
                { WeaponSlotStatus.enabled }
            };
            weapons.Weapons = new List <ShipWeapon>
            {
                { basicBlaster },
                { secondBlaster },
                { secondBlaster }
            };

            colliders = new Vector2[]                           // This is based off of what was in the PolygonCollider2D in old Player
            {
                new Vector2(0.25f, 0),
                new Vector2(-0.25f, 0.25f),
                new Vector2(-0.125f, 0),
                new Vector2(-0.25f, -0.25f)
            };

            #endregion

            Config = new ShipConfiguration(weapons, defenses, thrusters, 1, colliders, ShipSprite);
        }
Example #14
0
 public void SetData(ShipConfiguration shipConfiguration)
 {
     this.shipConfiguration = shipConfiguration;
     this.Name = "SQUADRON";
     this.ShipCount = shipConfiguration.shipCount;
     this.isSelected = false;
     buildPointCost = 10;
     Icon = (Texture2D)Resources.Load("Circle");
 }
    public bool DrawShipConfigurationManager()
    {
        selectedComponentCategory = GUI.SelectionGrid(new Rect(0, 0, 300, 25), selectedComponentCategory, componentCategories, componentCategories.Length);

        int drawCounter = 0;

        //List of ships
        foreach (Ship ship in unitList.ships)
        {
            if (GUI.Button(new Rect(400, 25 * drawCounter + 30, 200, 25), ship.name))
            {
                currentShipConfiguration.SetShip(ship);
            }

            drawCounter++;
        }

        //configuration name
        if (currentShipConfiguration.ship != null)
        {
            currentShipConfiguration.configurationName = GUI.TextField(new Rect(0, 250, 400, 25), currentShipConfiguration.configurationName);
            GUI.Label(new Rect(600, 275, 400, 25), currentShipConfiguration.ship.name);
            GUI.Label(new Rect(600, 300, 400, 25), "Health: " + currentShipConfiguration.health.ToString());
            GUI.Label(new Rect(600, 325, 400, 25), "Shield: " + currentShipConfiguration.shield.ToString());
            GUI.Label(new Rect(600, 350, 400, 25), "Speed: " + currentShipConfiguration.speed.ToString());
            GUI.Label(new Rect(600, 375, 400, 25), "Turn Speed: " + currentShipConfiguration.turnSpeed.ToString());
        }

        //ship component slots
        drawCounter = 0;
        int weaponSlotCount = 0;
        int hullSlotCount = 0;
        int engineeringSlotCount = 0;
        List<ShipComponentSlot> slots = currentShipConfiguration.GetShipComponentSlots();
        for (int i = 0; i < slots.Count; i++)
        {
            ShipComponentSlot componentSlot = slots[i];
            int xOffset = 0;
            int yOffset = 0;
            string emptySlotLabel = "";

            if (componentSlot.componentType == ShipComponentSlot.ComponentTypes.weapon)
            {
                xOffset = 100 * weaponSlotCount + 500;
                yOffset = 0;
                emptySlotLabel = "W";
                weaponSlotCount++;
            }
            else if (componentSlot.componentType == ShipComponentSlot.ComponentTypes.hull)
            {
                xOffset = 100 * hullSlotCount + 500;
                yOffset = 120;
                emptySlotLabel = "H";
                hullSlotCount++;
            }
            else if (componentSlot.componentType == ShipComponentSlot.ComponentTypes.engineering)
            {
                xOffset = 100 * engineeringSlotCount + 500;
                yOffset = 240;
                emptySlotLabel = "E";
                engineeringSlotCount++;
            }

            Color previousColor = GUI.color;

            if (i == selectedComponentSlot)
            {
                GUI.color = Color.green;
            }

            if (componentSlot.shipComponent != null)
            {
                if (GUI.Button(new Rect(xOffset + 75, yOffset + 400, 25, 25), "X"))
                {
                    currentShipConfiguration.SetShipComponentSlot(i, null);
                    //skip next button draw because shipComponent will become null
                    break;
                }

                if (GUI.Button(new Rect(xOffset, yOffset + 400, 100, 100),  componentSlot.shipComponent.icon))
                {
                    selectedComponentSlot = i;
                }

                GUI.Button(new Rect(xOffset + 75, yOffset + 400, 25, 25), "X"); //button icon for X
            }
            else
            {
                if (GUI.Button(new Rect(xOffset, yOffset + 400, 100, 100),  emptySlotLabel))
                {
                    selectedComponentSlot = i;
                }
            }

            GUI.Label(new Rect(xOffset, yOffset + 500, 100, 100), "---");
            drawCounter++;
            GUI.color = previousColor;
        }
        GUI.Label(new Rect(100, 725, 100, 50), selectedComponentSlot.ToString());

        //List of components
        drawCounter = 0;
        foreach (ShipComponent shipComponent in shipComponentList.shipComponents)
        {
            if ((selectedComponentCategory == 0 && (shipComponent is Weapon || shipComponent is Turret)) ||
                (selectedComponentCategory == 1 && shipComponent is HullComponent))
            {
                int x = drawCounter % 3;
                int y = drawCounter / 3;

                Color previousColor = GUI.color;
                if (!currentShipConfiguration.IsComponentCompatible(selectedComponentSlot, shipComponent))
                {
                    GUI.color = Color.red;
                }

                if (GUI.Button(new Rect(x * 100, y * 100 + 30, 100, 100), shipComponent.icon))
                {
                    currentShipConfiguration.SetShipComponentSlot(selectedComponentSlot, shipComponent);
                }

                drawCounter++;
                GUI.color = previousColor;
            }
        }

        //saved configurations
        if (GUI.Button(new Rect(700, 0, 100, 25), "SAVE CONFIG"))
        {
            SaveConfiguration();
        }
        if (GUI.Button(new Rect(800, 0, 100, 25), "NEW CONFIG"))
        {
            NewConfiguration();
        }

        if (shipConfigurations.Count == 0)
        {
            GUI.Label(new Rect(700, 25, 400, 25), "NO SAVED SHIP CONFIGURATIONS");
        }
        else
        {
            for (int i = 0; i < shipConfigurations.Count; i++)
            {
                if (GUI.Button(new Rect(700, i * 25 + 25, 400, 25), shipConfigurations[i].configurationName))
                {
                    currentShipConfiguration = shipConfigurations[i];
                }
            }
        }

        if (GUI.Button(new Rect(300, 0, 200, 25), "SPAWN SHIP"))
        {
            GameObject shipObject = unitList.GetShipObject(currentShipConfiguration.ship);
            GameObject instance = (GameObject)GameObject.Instantiate(shipObject, new Vector3(0, 0, 0), Quaternion.identity);
            instance.name = "----";

            Ship ship = instance.GetComponent<Ship>();
            ship.LoadConfiguration(currentShipConfiguration);
        }

        if (GUI.Button(new Rect(600, 0, 50, 25), "SAVE"))
        {
            SaveShipConfigurations saveShipConfigs = new SaveShipConfigurations();
            saveShipConfigs.Save(this);
        }

        return false;
    }
 private void NewConfiguration()
 {
     currentShipConfiguration = new ShipConfiguration();
 }
Example #17
0
 /// <summary>
 /// Says if both configurations are identical.
 /// </summary>
 /// <param name="conf1"></param>
 /// <param name="conf2"></param>
 /// <returns></returns>
 private bool ConfigurationsMatch(ShipConfiguration conf1, ShipConfiguration conf2)
 {
     return(conf1.Type == conf2.Type &&
            conf1.Dimension.Width == conf2.Dimension.Width &&
            conf1.Dimension.Height == conf2.Dimension.Height);
 }
Example #18
0
    public void LoadConfiguration(ShipConfiguration configuration)
    {
        foreach (ShipComponentSlot componentSlot in configuration.shipComponentSlots)
        {
            ShipComponent component = componentSlot.shipComponent;

            if (component != null)
            {
                this.ShipComponents.Add(component);
                component.ApplyComponent(this);
            }
        }
    }
Example #19
0
    /// <summary>
    /// Called by Unity when a level is loaded
    /// </summary>
    /// <param name="level">The level number that was loaded</param>
    private void OnLevelWasLoaded(int level)
    {
        if (Application.loadedLevelName == "BattleMode" || Application.loadedLevelName == "CombatTest")
        {
            if (Application.loadedLevelName == "CombatTest")
            {
                ShipConfiguration config = new ShipConfiguration();
                config.SetShip(testShipPrefab.GetComponent<Ship>());
                config.SetShipComponentSlot(0, testWeaponComponent);
                config.SetShipComponentSlot(1, testMissileComponent);
                CampaignSquadron squadron = new CampaignSquadron();
                squadron.SetData(config);
                squadron.ShipCount = 1;

                ShipConfiguration bomber = new ShipConfiguration();
                bomber.SetShip(testBomberPrefab.GetComponent<Ship>());
                bomber.SetShipComponentSlot(0, testTorpedoComponent);
                CampaignSquadron bomberSquadron = new CampaignSquadron();
                bomberSquadron.SetData(bomber);
                bomberSquadron.ShipCount = 2;

                ShipConfiguration config2 = new ShipConfiguration();
                config2.SetShip(testShipPrefab2.GetComponent<Ship>());
                config2.SetShipComponentSlot(0, turretComponent);
                config2.SetShipComponentSlot(1, turretComponent);
                config2.SetShipComponentSlot(2, turretComponent);
                config2.SetShipComponentSlot(3, turretComponent);
                CampaignSquadron squadron2 = new CampaignSquadron();
                squadron2.SetData(config2);
                squadron2.ShipCount = 1;

                for (int i = 0; i < 1; i++)
                {
                    campaignFleetAttackingFleet.squadrons.Add(squadron);
                }

                for (int i = 0; i < 1; i++)
                {
                    campaignFleetDefendingFleet.squadrons.Add(squadron);
                }
            }

            battlestate = BattleManager.BattleStates.setup;

            GameObject atkFleetObject = (GameObject)Instantiate(fleetObject);
            GameObject dfFleetObject = (GameObject)Instantiate(fleetObject);

            atkFleet = atkFleetObject.GetComponent<Fleet>();
            dfFleet = dfFleetObject.GetComponent<Fleet>();

            atkFleet.CopyCampaignFleet(campaignFleetAttackingFleet, new Vector3(000, 0, 0), new Vector3(1, 0, 0));
            campaignFleetAttackingFleet.gameObject.SetActive(false);

            dfFleet.CopyCampaignFleet(campaignFleetDefendingFleet, new Vector3(2000, 0, 0), new Vector3(-1, 0, 0));
            campaignFleetDefendingFleet.gameObject.SetActive(false);

            //fill list of all ships
            foreach(Squadron squadron in atkFleet.squadrons)
            {
                foreach(Ship ship in squadron.ships)
                {
                    ship.shipDestroyed += OnShipDestroyed;
                    allShips.Add(ship);
                }
            }

            foreach(Squadron squadron in dfFleet.squadrons)
            {
                allSquadrons.Add(squadron);

                foreach(Ship ship in squadron.ships)
                {
                    ship.shipDestroyed += OnShipDestroyed;
                    allShips.Add(ship);
                }
            }

            atkFleet.fleetDestroyed += FleetDestroyed;
            dfFleet.fleetDestroyed += FleetDestroyed;
        }
    }
Example #20
0
 void Start()
 {
     shipConfigureScript = GameObject.Find("ShipConfigurationManager").GetComponent <ShipConfiguration>();
 }
Example #21
0
 public void ApplyComponent(ShipConfiguration configuration)
 {
 }