Exemple #1
0
    public override IEnumerator Turn()
    {
        InitTurn();
        Debug.Log("(Player) " + UnitName + " turn");

        CombatUIManager.RefreshUI();
        CombatUIManager.SetActiveAllButtons(true, AttributesSheet.GetAttribute(AttributeType.MovementPoint));
        CombatUIManager.UpdateSkillsButtons();

        while (ActionState != ActionState.EndTurn && IsAlive)
        {
            switch (ActionState)
            {
            case ActionState.LookingForMovement:
                if (AttributesSheet.GetAttribute(AttributeType.MovementPoint) != 0)
                {
                    if (ProjectionManager.SelectionState != SelectionState.AvailableMovement)
                    {
                        ProjectionManager.SelectAvailableMovement(CurrentCell, AttributesSheet.GetAttribute(AttributeType.MovementPoint), SelectionState.AvailableMovement);
                    }
                }
                else
                {
                    Debug.Log("Can't move, no movementPoint available");
                    ActionState = ActionState.Waiting;
                }
                break;

            case ActionState.Waiting:
                if (ProjectionManager.SelectionState != SelectionState.CurrentCell &&
                    ProjectionManager.SelectionState != SelectionState.OtherAvailableMovement)
                {
                    ProjectionManager.SelectCurrentCell(CurrentCell, Team);
                }
                break;

            default:
                break;
            }
            yield return(new WaitForFixedUpdate());
        }
        AttributesSheet.RemoveCosts();
        ProjectionManager.ClearProjections();
        SelfProjection.gameObject.SetActive(true);
        IsPlaying = false;
        yield return(null);
    }
Exemple #2
0
    public void ApplyDamage(AttributesSheet casterAttributes, DamageLine line, bool isCritical, Weapon weapon = null)
    {
        float value = line.FinalValue;

        if (isCritical)
        {
            value *= 1.5f + casterAttributes.GetCriticalDamageModifier();
        }

        Debug.Log(UnitName + ": damaged " + value + " (" + line.DamageType + ")(" + line.ElementType + ")(" + isCritical + ")");
        int oldValue = AttributesSheet.CurrentHealth;

        AttributesSheet.CurrentHealth -= (int)value;
        Debug.Log(UnitName + ": " + oldValue + " => " + AttributesSheet.CurrentHealth);

        Animator.Play(AnimationPrefix + "Take Damage");
        CombatUIManager.UpdateHealthBar();
        UpdateHealthSlider();

        UpdateIsAlive();
    }
Exemple #3
0
    public void ApplyRecovery(AttributesSheet casterAttributes, RecoveryLine line, bool isCritical)
    {
        float value = line.finalValue;

        if (isCritical)
        {
            value *= 1.5f + casterAttributes.GetCriticalDamageModifier();
        }

        Debug.Log(UnitName + ": recovered " + value + " (" + line.recoveryType + ")(" + isCritical + ")");
        if (line.recoveryType == RecoveryType.Health)
        {
            AttributesSheet.CurrentHealth += (int)value;
        }
        else if (line.recoveryType == RecoveryType.Mana)
        {
            AttributesSheet.CurrentMana += (int)value;
        }

        CombatUIManager.UpdateHealthBar();
        UpdateHealthSlider();
        CombatUIManager.UpdateManaBar();
    }
Exemple #4
0
    public void GetEffect(AttributesSheet casterAttributes)
    {
        if (Targets.Count > 0)
        {
            foreach (Unit target in Targets)
            {
                foreach (SkillEffect effect in SkillEffects)
                {
                    bool isCriticalHit = true;
                    if (CriticalChance != 100)
                    {
                        int randomNb = Random.Range(0, 100);
                        isCriticalHit = randomNb < (CriticalChance + casterAttributes.GetCriticalChanceModifier()) ? true : false;
                    }

                    if (effect.ProcChance != 100)
                    {
                        int randomNb = Random.Range(0, 100);
                        if (randomNb > effect.ProcChance)
                        {
                            continue;
                        }
                    }

                    switch (effect.GetEffectType())
                    {
                    case EffectType.Damage:
                        List <DamageLine> damageList = effect.GetDamage();
                        foreach (DamageLine line in damageList)
                        {
                            target.ApplyDamage(casterAttributes, line, isCriticalHit);
                        }
                        break;

                    case EffectType.Recovery:
                        List <RecoveryLine> recoveryList = effect.GetRecovery();
                        foreach (RecoveryLine line in recoveryList)
                        {
                            target.ApplyRecovery(casterAttributes, line, isCriticalHit);
                        }
                        break;

                    case EffectType.AttributeModifier:
                        List <Attribute> attributeList = effect.GetAttributeModifier();
                        foreach (Attribute attribute in attributeList)
                        {
                            Attribute newAttribute = new Attribute(attribute.AttributeType,
                                                                   attribute.Value,
                                                                   attribute.PropertyType,
                                                                   attribute.Duration);
                            target.ApplyAttributeModifier(newAttribute);
                        }
                        break;

                    //case EffectType.Buff:
                    //    List<Buff> buffList = effect.GetBuff();
                    //    foreach (Buff buff in buffList)
                    //        target.ApplyBuff(buff);
                    //    break;

                    // Fix loop so effect can be get even if no target
                    //case EffectType.Movement:
                    // caster.Move();
                    //break;

                    default:
                        break;
                    }
                }
            }
        }
    }
Exemple #5
0
    private AITurn ComputeTurn()
    {
        float[,] influenceMap = InfluenceMap.GetInfluenceMap(MapInfos, Team.Player);

        InfluenceMapDrawer drawer = GameObject.Find("InfluenceMapDrawer").GetComponent <InfluenceMapDrawer>();

        drawer.influenceMap = influenceMap;

        AITurn turn = new AITurn();

        turn.Actions = new List <AIAction>();

        AIActionMovement movement = new AIActionMovement();

        movement.GetHighestScore(influenceMap, CurrentCell.X, CurrentCell.Z, (int)MapInfos.Size.x, (int)MapInfos.Size.y, AttributesSheet.GetAttribute(AttributeType.MovementPoint));
        turn.Actions.Add(movement);

        /* while (enough AP to use a skill || enough MP to move) {
         *
         *  // if (enough AP to use a skill) {
         *
         *      - Get Available Skills
         *
         *      if (health == low && has a healing skill)
         *          Use healing skill
         *      else {
         *          - Get potential targets in Range
         *          - Get skill cellTarget
         *          - Add potential kills to turn
         *          - Add potential damage to turn
         *      }
         *
         *  } else (Move) {
         *      GetInfluenceMap(Team.Player);
         *      AIActionMovement movement = new AIActionMovement();
         *      if (CurrentHealth > 50%) {
         *          GetHighestScore();
         *      } else
         *          GetLowestScore();
         *      turns.Action.Add(movement);
         *  }
         */
        return(turn);
    }
Exemple #6
0
    public override IEnumerator Turn()
    {
        InitTurn();
        Debug.Log("(Enemy) " + UnitName + " turn");

        CombatUIManager.RefreshUI();
        CombatUIManager.UpdateSkillsButtons();
        CombatUIManager.SetActiveAllButtons(false, 0);

        ProjectionManager.SelectCurrentCell(CurrentCell, Team);

        // GET MOST EFFICIENT TURN
        CombatUIManager.ToggleThinkingAI(true);
        yield return(GetTurn());

        CombatUIManager.ToggleThinkingAI(false);

        // PLAY TURN
        if (AITurn != null && AITurn.Actions != null)
        {
            foreach (AIAction action in AITurn.Actions)
            {
                if (action is AIActionMovement)
                {
                    AIActionMovement movementAction  = action as AIActionMovement;
                    Cell             cellDestination = MapInfos.Map[(int)movementAction.Destination.x, (int)movementAction.Destination.y];
                    Debug.Log("Move from [" + CurrentCell.X + ", " + CurrentCell.Z + "] to [" +
                              cellDestination.X + ", " + cellDestination.Z + "]");

                    // ProjectionManager.SelectAvailableMovement();
                    // yield return new WaitForSeconds(0.5f);

                    Move(cellDestination, true, Utils.GetDistanceBetweenCells(CurrentCell, cellDestination));
                    while (ActionState == ActionState.Moving)
                    {
                        yield return(new WaitForEndOfFrame());
                    }
                }
                else if (action is AIActionUseSkill)
                {
                    AIActionUseSkill useSkillAction = action as AIActionUseSkill;
                    Debug.Log("Use " + useSkillAction.SpellId + " at [" + useSkillAction.SpellTarget.X + ", " +
                              useSkillAction.SpellTarget.Z + "]");

                    SkillDisplayRange(useSkillAction.SpellId);
                    yield return(new WaitForSeconds(0.5f));

                    SkillDisplayAoe(useSkillAction.SpellTarget);
                    yield return(new WaitForSeconds(0.5f));

                    SkillUse(useSkillAction.SpellTarget);
                    while (ActionState == ActionState.PlayingAnimation)
                    {
                        yield return(new WaitForEndOfFrame());
                    }
                }
            }
        }

        // END TURN
        AttributesSheet.RemoveCosts();
        ProjectionManager.ClearProjections();
        SelfProjection.gameObject.SetActive(true);
        IsPlaying = false;
        yield return(null);
    }