Exemple #1
0
    //^ this is just for multiplayer purpose of setting factions in the lobby. As lobby scene has no central manager script and it is connected in a way to SLM (cause it restricts allowed saves to load for later).... It stays here.

    void Awake()
    {
        ChosenFactions[0] = Faction.Neutral;
        ChosenFactions[1] = Faction.Neutral;
        if (Instance == null)
        {
            Instance = this;
            DontDestroyOnLoad(this.gameObject);
        }
        else
        {
            if (Application.isEditor)
            {
                DestroyImmediate(this);
            }
            else
            {
                Destroy(this);
            }
        }


        playerArmy = new PlayerArmy();
        UnitsList  = new List <Unit>();
    }
Exemple #2
0
 void HandleSlotClick(int slotnum)
 {
     if (current == States.Default)
     {
         selectedIndex = slotnum;
         // TODO: show options ui
     }
     else if (current == States.Swap)
     {
         PlayerArmy.Swap(selectedIndex, slotnum);
         current = States.Default;
     }
     else if (current == States.Separate)
     {
         // TODO: bring up the quantity menu, which will call
         // an action which will activate a method which will
         // call PlayerArmy.Separate
         current = States.Default;
     }
     else if (current == States.Combine)
     {
         PlayerArmy.Combine(selectedIndex, slotnum);
         current = States.Default;
     }
 }
Exemple #3
0
    public void CopyDataToSave()
    {
        playerArmy = new PlayerArmy();
        if (Race != null)
        {
            playerArmy.faction = Race;
        }
        if (HeroName != null && HeroName != string.Empty)
        {
            playerArmy.HeroName = HeroName;
        }
        else
        {
            playerArmy.HeroName = HeroNames.GetRandomHeroName();
            HeroName            = playerArmy.HeroName;
        }
        if (ArmyBuilder.Instance != null && ArmyBuilder.Instance.Hero != null)
        {
            playerArmy.heroID = ArmyBuilder.Instance.Hero.myUnitID;
        }
        else
        {
            playerArmy.heroID = null;
        }

        playerArmy.unitIDs = new List <UnitID>();
        foreach (Unit u in UnitsList)
        {
            playerArmy.unitIDs.Add(u.myUnitID);
        }
    }
Exemple #4
0
    PlayerArmy GetInsidesOfASave(string saveName)
    {
        BinaryFormatter bf   = new BinaryFormatter();
        FileStream      file = File.Open(saveName, FileMode.Open);
        PlayerArmy      save = bf.Deserialize(file) as PlayerArmy;

        file.Close();
        return(save);
    }
Exemple #5
0
    void Start()
    {
        PlayerArmy.Init();

        current = States.Default;
        for (int i = 0; i < PlayerArmy.armySize; i++)
        {
            slots[i].number = i;
        }
        Refresh();
    }
Exemple #6
0
        //settings?

        public PlayerInfo() : this(new Army("Player"), new CityMap())
        {
            Unit firstUnit = new Unit();

            PlayerArmy.addUnit(firstUnit);
            PlayerArmy.addUnit(new Unit(UnitType.Miku));
            for (int i = 0; i < 10; i++)
            {
                PlayerArmy.addUnit(new Unit());
            }
            PlayerArmy.squads[0, 0].addUnit(0, firstUnit);
        }
Exemple #7
0
 private void CreateArmyFromAIArmy(AIArmy army)
 {
     playerArmy = new PlayerArmy
     {
         unitIDs = new List <UnitID>(),
         heroID  = army.Hero.myUnitID,
         faction = army.faction
     };
     foreach (var unit in army.Units)
     {
         playerArmy.unitIDs.Add(unit.myUnitID);
     }
 }
Exemple #8
0
    // Start is called before the first frame update
    void Start()
    {
        PlayerArmy.Init();

        for (int i = 0; i < PlayerArmy.armySize; i++)
        {
            if (PlayerArmy.army[i] != null && PlayerArmy.army[i] != PlayerArmy.empty)
            {
                playerUnits[i] = new Unit(PlayerArmy.army[i], false);
                GameObject GO = Instantiate(unit);
                GO.transform.position     = new Vector3(Random.Range(-1.5f, -3.0f), Random.Range(-2.5f, 2.5f), 0);
                playerUnits[i].gameObject = GO;
            }
        }
    }
Exemple #9
0
    // Use this for initialization
    void Start()
    {
        LoadMessages(step);

        Hero astro = new Hero();

        astro.Initialize("Sylvia", PlayerArmy.HeroType.Astronomer);
        PlayerArmy.AddHero(astro);

        Hero senti = new Hero();

        senti.Initialize("Rowen", PlayerArmy.HeroType.Sentinel);
        PlayerArmy.AddHero(senti);

        PlayerArmy.SetHeroActive(PlayerArmy.GetHero(0));
        PlayerArmy.SetHeroActive(PlayerArmy.GetHero(1));
    }
Exemple #10
0
 public void LoadAIArmy(int points)
 {
     if (Directory.Exists(Application.persistentDataPath + "/Armies/AI/" + currentSaveValue.ToString() + "points"))
     {
         var             files    = Directory.GetFiles(Application.persistentDataPath + "/Armies/AI/" + currentSaveValue.ToString() + "points", "*.lemur");
         string          fileName = files[Random.Range(0, files.Length)];
         BinaryFormatter bf       = new BinaryFormatter();
         FileStream      file     = File.Open(fileName, FileMode.Open);
         playerArmy = bf.Deserialize(file) as PlayerArmy;
         file.Close();
     }
     else
     {
         Application.Quit();
         throw new System.Exception("My mum just boom");
     }
 }
    // Use this for initialization
    void Start()
    {
        for (int i = 0; i < 9; i++)
        {
            sprites[i] = transform.Find("Sprite " + i).GetComponent <SpriteRenderer>();
        }

        if (isPlayer)
        {
            for (int i = 0; i < PlayerArmy.GetActiveHeroes().Count; i++)
            {
                characters[i] = PlayerArmy.GetActiveHeroes()[i];
            }

            SetSprites();
        }
    }
Exemple #12
0
 public void SaveArmyButton()
 {
     if (currentSaveName == null)
     {
         Debug.LogError("this shouldnt have happenned. We HAVE TO already have a name");
     }
     else
     {
         Save();
         currentSaveName = null;
         hero            = null;
         HeroName        = null;
         Race            = null;
         playerArmy      = new PlayerArmy();
         UnitsList       = new List <Unit>();
         FindObjectOfType <WindowSetter>().GoBack();
     }
 }
 /// <summary>
 /// Konstruktor głównego okna aplikacji
 /// </summary>
 public FormMain()
 {
     InitializeComponent();
     Gold                     = 100;
     labelGold.Text           = "Złoto: " + Gold;
     buttonShowBattle.Enabled = false;
     //temp
     for (int i = 0; i < 5; i++)
     {
         PlayerArmy.TankList.Add(unitFactory.CreateTank.RandomTank());
         PlayerArmy.PlaneList.Add(unitFactory.CreatePlane.RandomPlane());
     }
     for (int i = 0; i < 10; i++)
     {
         PlayerArmy.InfantryList.Add(unitFactory.CreateInfantry.RandomInfantry());
     }
     PlayerArmy.Sort();
     labelScore.Visible = false;
 }
Exemple #14
0
    /// <summary>
    /// Creates VISUAL buttons representing saves
    /// </summary>
    public void ReCreateSaves(Transform ExiSaves)
    {
        while (ExiSaves.childCount > 0)
        {
            if (Application.isEditor)
            {
                DestroyImmediate(ExiSaves.GetChild(0).gameObject);
            }
            else
            {
                Destroy(ExiSaves.GetChild(0).gameObject);
            }
        }
        var list = SaveLoadManager.Instance.GetSaveNames(Application.persistentDataPath + "/Armies/");

        if (list != null)
        {
            foreach (var item in list)
            {
                var temp = Instantiate(SavePrefab, ExiSaves);
                temp.GetComponent <SaveLoadButton>().isDeletable = true;
                temp.GetComponentInChildren <Text>().text        = item.Key;
                PlayerArmy armyInfo = GetInsidesOfASave(item.Value);
                if (armyInfo.faction == null)
                {
                    Debug.Log("deleted");
                    File.Delete(Application.persistentDataPath + "/Armies/" + SaveLoadManager.Instance.currentSaveValue.ToString() + "points/" + item.Key + ".lemur");
                    Destroy(temp);
                    continue;
                }
                if (GameStateManager.Instance.MatchType == MatchTypes.Online && armyInfo.faction != LocalFaction)
                {
                    Debug.Log("Skipped");
                    Destroy(temp);
                    continue;
                }
                temp.GetComponentsInChildren <Image>()[1].sprite = GetRaceSprite((Faction)armyInfo.faction);
                //temp.GetComponentsInChildren<Image>()[2].sprite = FactionSymbols[(int)armyInfo.heroID];
                temp.name = item.Key;
            }
        }
    }
Exemple #15
0
    public void LoadPlayerArmy()
    {
        if (File.Exists(Application.persistentDataPath + "/Armies/" + currentSaveValue.ToString() + "points/" + currentSaveName + ".lemur"))
        {
            BinaryFormatter bf   = new BinaryFormatter();
            FileStream      file = File.Open(Application.persistentDataPath + "/Armies/" + currentSaveValue.ToString() + "points/" + currentSaveName + ".lemur", FileMode.Open);
            playerArmy = bf.Deserialize(file) as PlayerArmy;
            file.Close();
        }

        /* else if (File.Exists(Application.persistentDataPath + "/Armies/AI/" + currentSaveValue.ToString() + "points/" + currentSaveName + ".lemur"))
         * {
         *   BinaryFormatter bf = new BinaryFormatter();
         *   FileStream file = File.Open(Application.persistentDataPath + "/Armies/AI/" + currentSaveValue.ToString() + "points/" + currentSaveName + ".lemur", FileMode.Open);
         *   playerArmy = bf.Deserialize(file) as PlayerArmy;
         *   file.Close();
         * }*/
        else
        {
            Debug.LogError("No such thing to load!");
        }
    }
Exemple #16
0
    public bool HasRaceSaved(Faction race)
    {
        var list = SaveLoadManager.Instance.GetSaveNames(Application.persistentDataPath + "/Armies/");

        if (list != null)
        {
            foreach (var item in list)
            {
                PlayerArmy armyInfo = GetInsidesOfASave(item.Value);
                if (armyInfo.faction == null)
                {
                    Debug.Log("deleted");
                    File.Delete(Application.persistentDataPath + "/Armies/" + SaveLoadManager.Instance.currentSaveValue.ToString() + "points/" + item.Key + ".lemur");
                    continue;
                }
                if (armyInfo.faction == race)
                {
                    return(true);
                }
            }
        }
        return(false);
    }
        /// <summary>
        /// Funkcja obsługująca zdarzenia trwające co interwał czasu
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void timerMain_Tick(object sender, EventArgs e)
        {
            timeCounter++;
            labelTime.Text = "Dzień: " + timeCounter;
            Gold          += 5;
            if (Gold >= repairCost && repairCost != 0 && !IsBattle)
            {
                buttonRepair.Enabled = true;
            }
            else
            {
                buttonRepair.Enabled = false;
            }
            if (IsBattle)
            {
                buttonShop.Enabled = false;
                PlayerArmy.Attack(EnemyArmy, random);
                EnemyArmy.Attack(PlayerArmy, random);
                buttonShowBattle.Enabled = true;
                EnemyArmy.RefreshUnitList();
                PlayerArmy.RefreshUnitList();
                ListSource.ResetBindings(false);
            }
            else
            {
                buttonShop.Enabled       = true;
                buttonShowBattle.Enabled = false;
                if (battleBreakCount > 0)
                {
                    battleBreakCount--;
                }
            }
            if (random.Next(2) == 1 && !IsBattle && battleBreakCount == 0)
            {
                EnemyArmy = new Army(timeCounter / 9);
                FormBattle formBattle = new FormBattle(this);
                formBattle.Show();
                IsBattle         = true;
                battleBreakCount = 25;
                Gold            += EnemyArmy.GetTotalArmyCost() / 3;
            }
            if (EnemyArmy != null)
            {
                if (!EnemyArmy.UnitList.Any())
                {
                    IsBattle = false;
                }

                if (!PlayerArmy.UnitList.Any())
                {
                    MessageBox.Show("PORAŻKA");
                    EndGame();
                }
            }
            labelGold.Text = "Złoto: " + Gold;
            if (timeCounter == 300)
            {
                labelScore.Text      = "Wygrana!";
                labelScore.ForeColor = Color.Khaki;
                labelScore.Visible   = true;
                EndGame();
            }
        }