Exemplo n.º 1
0
 private UnitDescriptionForSerialization(UnitDescription unit)
 {
     name        = unit.GetUnitName();
     unitRace    = unit.GetRace().race.ToString();
     unitClass   = unit.GetClass().clas.ToString();
     abilityName = unit.GetAbilityName();
     id          = unit.GetId();
     experience  = unit.GetExperience();
     level       = unit.GetLevel();
     gems        = unit.GetGems();
 }
Exemplo n.º 2
0
    public void OnDrag(PointerEventData eventData)
    {
        if (eventData.button != PointerEventData.InputButton.Left)
        {
            return;
        }

        if (_status != SlotState.Used || GameManager.instance.gamestate != GameManager.GameState.Placement)
        {
            return;
        }

        List <Cell> authorizedCells = Board.CurrentBoard.GetAuthorizedAllyCells();

        List <Cell> avalaibleCells = new List <Cell>();

        foreach (Cell cell in authorizedCells)
        {
            if (!cell.GetIsOccupied() && cell.GetIsObstacle() == false)
            {
                avalaibleCells.Add(cell);
            }
        }

        if (avalaibleCells.Count == 0)
        {
            return;
        }

        Unit newUnit = Instantiate(unitPrefab).GetComponent <Unit>();

        newUnit.SetName(unitDescription.GetUnitName());
        newUnit.SetSprite(unitDescription.GetSprite());
        newUnit.raceStats = unitDescription.GetRace();
        newUnit.classStat = unitDescription.GetClass();
        newUnit.SetAbilityName(unitDescription.GetAbilityName());
        newUnit.SetGems(unitDescription.GetGems());
        newUnit.Level = unitDescription.GetLevel();
        newUnit.AttachBoard();
        newUnit.transform.SetPositionAndRotation(attachedCamera.ScreenToWorldPoint(Input.mousePosition), Quaternion.identity);

        Cell destinatinCell = avalaibleCells[0];

        newUnit.initialPos = destinatinCell.TileMapPosition;

        newUnit.tag          = Unit.allyTag;
        newUnit.isRandomUnit = false;
        newUnit.id           = unitDescription.GetId();

        newUnit.PrepareForDragNDrop();
        ClearSlot();
    }
    public void UpdateDescription()
    {
        if (actualSlot == null)
        {
            UnitName.text       = "";
            UnitStats.text      = "";
            UnitExperience.text = "";
            return;
        }

        currentDescription = actualSlot.GetCurrentUnitDescription();

        SetUnitName(currentDescription.GetUnitName());
        SetUnitExperience(currentDescription.GetExperience());
        SetUnitLevel(currentDescription.GetLevel());
        ClassStat classe = currentDescription.GetClass();
        RaceStat  race   = currentDescription.GetRace();


        //destroy previously displayed slots
        foreach (GameObject slot in gemSlots)
        {
            Destroy(slot);
        }

        string[] gems = currentDescription.GetGems();
        gemSlots    = new List <GameObject>();
        currentGems = new List <Gem>();

        if (ResetGemsButton)
        {
            if (GameManager.instance.gamestate == GameManager.GameState.Placement ||
                (GameManager.instance.gamestate == GameManager.GameState.Shopping ||
                 GameManager.instance.gamestate == GameManager.GameState.Resolution) &&
                actualSlot.GetSlotType() == InventorySlot.SlotType.Inventory)
            {
                GenerateSlots(gems);
                ResetGemsButton.gameObject.SetActive(true);
            }

            else
            {
                ResetGemsButton.gameObject.SetActive(false);
            }
        }

        uint  level            = currentDescription.GetLevel();
        float damage           = classe.damage + race.damage + 1 * (level - 1);
        float maxLife          = classe.maxLife + race.maxLife + 10 * (int)(level - 1);
        float attackSpeed      = classe.attackSpeed + race.attackSpeed + 0.05f * (level - 1);
        float moveSpeed        = classe.moveSpeed + race.moveSpeed;
        float armor            = classe.armor + race.armor + 0.05f * (level - 1);
        float power            = 1 + 0.05f * (level - 1);
        int   range            = classe.range;
        float incrementStamina = classe.incrementStamina;

        if (currentGems.Count > 0)
        {
            foreach (Gem gem in currentGems)
            {
                if (gem.GetStatModified() == Gem.StatModified.None)
                {
                    gem.InitializeStatModified();
                }

                switch (gem.GetStatModified())
                {
                case Gem.StatModified.Damage:
                    damage = gem.InitGemEffect(damage);
                    break;

                case Gem.StatModified.Health:
                    maxLife = gem.InitGemEffect(maxLife);
                    break;

                case Gem.StatModified.AttackSpeed:
                    attackSpeed = gem.InitGemEffect(attackSpeed);
                    break;

                case Gem.StatModified.Armor:
                    armor = gem.InitGemEffect(armor);
                    break;

                case Gem.StatModified.MovementSpeed:
                    moveSpeed = gem.InitGemEffect(moveSpeed);
                    break;

                case Gem.StatModified.Power:
                    power = gem.InitGemEffect(power);
                    break;
                }
            }
        }

        //get ability name and add space before every capital letter
        string        abilityName           = currentDescription.GetAbilityName();
        StringBuilder abilityNameWithSpaces = new StringBuilder(abilityName.Length * 2);

        abilityNameWithSpaces.Append(abilityName[0]);
        for (int i = 1; i < abilityName.Length; i++)
        {
            if (char.IsUpper(abilityName[i]) && abilityName[i - 1] != ' ')
            {
                abilityNameWithSpaces.Append(' ');
            }
            abilityNameWithSpaces.Append(abilityName[i]);
        }


        string stats =
            "Classe : " + classe.name + "\n" +
            "Race : " + race.name + "\n" +
            "Capacité : " + abilityNameWithSpaces + "\n" +
            "Stamina générée : " + incrementStamina + "\n" +
            "PV Max : " + maxLife + "\n" +
            "Dégâts : " + Mathf.Round(damage * 100f) / 100f + "\n" +
            "Vitesse d'attaque : " + Mathf.Round(attackSpeed * 100f) / 100f + "\n" +
            "Vitesse de déplacement : " + Mathf.Round(moveSpeed * 100f) / 100f + "\n" +
            "Armor : " + Mathf.Round(armor * 100f) / 100f + "\n" +
            "Puissance : " + Mathf.Round(power * 100f) / 100f + "\n" +
            "Portée : " + range + "\n";

        SetUnitStats(stats);
    }