Пример #1
0
    private List <TEventEntity> getPlanetsSortedByDistance(TEventEntity refernce)
    {
        List <TEventEntity> result = new List <TEventEntity>();
        TEventEntity        aux, aux2;

        result.Add(myPlayer.Planets[0]);

        for (int i = 1; i < myPlayer.Planets.Count; i++)
        {
            aux  = myPlayer.Planets[i];
            aux2 = aux;
            for (int j = 0; i < result.Count; j++)
            {
                if (Vector3.Distance(aux.Position, refernce.Position) < Vector3.Distance(result[j].Position, refernce.Position))
                {
                    aux2      = result[j];
                    result[j] = aux;
                    aux       = aux2;
                }
            }
            result.Add(aux);
        }

        return(result);
    }
Пример #2
0
    /// <summary>
    /// Same as take snapshot, but stores the current state in a new TGame and returns it
    /// DOES NOT OVERWRITE SNAPSHOT
    /// </summary>
    public TGame TakeAndGetSnapshot()
    {
        TEventEntity[] s_planets = new TEventEntity[planets.Length];
        TGame          game      = new TGame();

        for (int i = 0; i < planets.Length; i++)
        {
            s_planets[i] = planets[i].GetSnapshot(game);
        }

        TPlayer[]           s_players = new TPlayer[players.Length];
        List <TEventEntity> aux;

        for (int i = 0; i < players.Length; i++)
        {
            aux          = new List <TEventEntity>();
            s_players[i] = players[i].GetSnapshot(s_planets);
            foreach (TEventEntity ent in s_planets)
            {
                if (ent.CurrentPlayerOwner == s_players[i].Id)
                {
                    aux.Add(ent);
                }
            }
            s_players[i].SetPlanets(aux);
        }

        List <TAttackInfo> s_attacks = new List <TAttackInfo>(pendingAttacks);

        game.Initialize(s_players, s_planets, s_attacks, weHaveAWinner, winner);
        return(game);
    }
Пример #3
0
    /// <summary>
    /// Returns nearest planet to aany planet that belongs to the player
    /// </summary>
    /// <param name="returnNeutral"></param>
    /// <returns></returns>
    public static TEventEntity GetNearestPlanet(TPlayer myPlayer, TEventEntity[] map, bool returnNeutral = false)
    {
        TEventEntity aux             = null;
        float        currentDistance = float.PositiveInfinity;

        if (myPlayer.Planets.Count <= 0)
        {
            Debug.Log("NO TENGO PLANETAS");
        }

        foreach (TEventEntity child in map)
        {
            for (int i = 0; i < myPlayer.Planets.Count; i++)
            {
                if (!myPlayer.Planets.Contains(child))
                {
                    if (Vector3.Distance(child.Position, myPlayer.Planets[i].Position) < currentDistance)
                    {
                        if (returnNeutral)
                        {
                            if (child.CurrentPlayerOwner == GlobalData.NO_PLAYER)
                            {
                                aux             = child;
                                currentDistance = Vector3.Distance(child.Position, myPlayer.Planets[i].Position);
                            }
                        }
                        else
                        {
                            if (child.CurrentPlayerOwner != GlobalData.NO_PLAYER)
                            {
                                aux             = child;
                                currentDistance = Vector3.Distance(child.Position, myPlayer.Planets[i].Position);
                            }
                        }
                    }
                }
            }
        }

        if (aux == null)
        {
            Debug.LogError("Error al localizar planeta cercano");
            return(myPlayer.Planets[0]);
        }
        else
        {
            return(aux);
        }
    }
Пример #4
0
    /// <summary>
    /// Will send 1.5 times the units necessary to conquer or turn neutral a planet
    /// The units will be sent from the nearest planets
    /// </summary>
    /// <param name="objective">Entity that will be attacked</param>
    private void Attack(TEventEntity objective, bool randomNumber = false, bool turnNeutral = false)
    {
        int objectiveUnits          = CountNecessaryUnitsToConquer(objective, myPlayer, randomNumber, turnNeutral);
        List <TEventEntity> planets = getPlanetsSortedByDistance(objective);

        for (int i = 0; i < planets.Count; i++)
        {
            objectiveUnits -= planets[i].CurrentUnits;
            planets[i].UseUnits(new TAttackInfo(Utilities.Utilities.GetDistanceInTurns(planets[i].Position, objective.Position), myPlayer.Id, planets[i].CurrentUnits, objective.Id));
            if (objectiveUnits <= 0)
            {
                return;
            }
        }
    }
Пример #5
0
    /// <summary>
    /// Returns necessary units to conquer or turn neutral
    /// </summary>
    /// <param name="ent">Entity we want to know abouta</param>
    /// <param name="turnNeutral">If true will return units to turn neutral</param>
    /// <returns></returns>
    public static int CountNecessaryUnitsToConquer(TEventEntity ent, TPlayer myPlayer, bool randomNumber = false, bool turnNeutral = false)
    {
        int objective = 0;

        if (ent.CurrentPlayerOwner == myPlayer.Id)
        {
            if (ent.CurrentLevel >= ent.MaxLevel)
            {
                return(0);
            }
            else
            {
                objective = ent.ExpForNextLevel - ent.CurrentExp;
            }
        }
        if ((ent.CurrentPlayerOwner == GlobalData.NO_PLAYER && ent.CurrentContestantId == myPlayer.Id) || (ent.CurrentPlayerOwner == GlobalData.NO_PLAYER && ent.CurrentContestantId == GlobalData.NO_PLAYER))
        {
            objective = ent.ExpForNextLevel - ent.CurrentExp;
        }
        else if (ent.CurrentPlayerOwner == GlobalData.NO_PLAYER && ent.CurrentContestantId != myPlayer.Id)
        {
            objective = ent.ExpForNextLevel + ent.CurrentHealth;
        }
        else
        {
            if (turnNeutral)
            {
                objective = ent.CurrentUnits + ent.CurrentHealth;
            }
            else
            {
                objective = ent.CurrentHealth + ent.CurrentUnits + ent.GetExpForLEvel(0);
            }
        }

        if (randomNumber)
        {
            return(Mathf.RoundToInt(objective * (1.4f - (float)rand.NextDouble())));
        }
        else
        {
            return(objective);
        }
    }
Пример #6
0
    public TGame GetSnapshot()
    {
        TEventEntity[] s_planets = new TEventEntity[planets.Length];
        TGame          game      = new TGame();

        for (int i = 0; i < planets.Length; i++)
        {
            s_planets[i] = planets[i].TakeSnapshot(game);
        }

        TPlayer[]           s_players = new TPlayer[players.Length];
        List <TEventEntity> aux;

        for (int i = 0; i < players.Length; i++)
        {
            aux          = new List <TEventEntity>();
            s_players[i] = players[i].GetSnapshotInstance(s_planets);
            foreach (TEventEntity ent in s_planets)
            {
                if (ent.CurrentPlayerOwner == s_players[i].Id)
                {
                    aux.Add(ent);
                }
            }
            s_players[i].SetPlanets(aux);
        }

        List <TAttackInfo> s_attacks = new List <TAttackInfo>();

        foreach (Transform att in attackPool.transform)
        {
            if (att.gameObject.activeSelf)
            {
                s_attacks.Add(att.GetComponent <Attack>().GetTrainingSnapshot());
            }
        }
        game.Initialize(s_players, s_planets, s_attacks);
        return(game);
    }
Пример #7
0
    private void LevelUpMyPlanets()
    {
        //will choose the planet closer to be leveled up or the first one it has in the list
        TEventEntity objective        = null;
        int          currentExpNeeded = int.MaxValue;

        foreach (TEventEntity ent in myPlayer.Planets)
        {
            if (ent.CurrentLevel < ent.MaxLevel)
            {
                if (ent.ExpForNextLevel - ent.CurrentExp < currentExpNeeded)
                {
                    objective        = ent;
                    currentExpNeeded = ent.ExpForNextLevel - ent.CurrentExp;
                }
            }
        }
        if (objective == null)
        {
            Debug.LogError("ERROR AL SELECCIONAR PLANETA PARA UPGRADE");
            objective = myPlayer.Planets[0];
        }
        Attack(objective, true);
    }