Пример #1
0
    private static bool IsValidTarget(Unit requestor, UnitAction action, Cursor tile, int xPos, int zPos)
    {
        bool valid = true;

        if (tile.standingUnit && !action.CanTargetOwnTeam())
        {
            valid = tile.standingUnit.playerIndex != action.Unit().playerIndex;
        }

        if (valid)
        {
            if (action.CanTargetSelf() || tile.xPos != xPos || tile.zPos != zPos)
            {
                if (action.NeedsLineOfSight())
                {
                    valid = Helpers.CanHitTarget(requestor.ProjectedHittable().position, tile);
                }
            }
            else
            {
                valid = false;
            }
        }

        Unit unit = Unit.Subject();

        if (valid && unit != null)
        {
            foreach (Buff buff in unit.Buffs())
            {
                valid = buff.CanTarget(tile);
                if (!valid)
                {
                    break;
                }
            }
            ;
        }

        return(valid);
    }
Пример #2
0
    public void ReceiveDamage(int damage, Unit aggressor, UnitAction action)
    {
        bool backAttacked =
            aggressor.playerIndex != this.playerIndex &&
            action.actionType() == UnitAction.ActionType.Melee &&
            !aggressor.GetComponent <UnitMovement>().TraversedAlertTile();

        float calculatedDamage = damage;
        int   startingHp       = currentHp;

        foreach (Buff buff in Buffs())
        {
            if (action.actionType() == UnitAction.ActionType.Melee)
            {
                calculatedDamage /= buff.MeleeResistMod();
            }

            if (buff.CommunicableType() == action.actionType())
            {
                action.Unit().ReceiveBuff(Instantiate(buff.gameObject, Vector3.zero, Quaternion.identity));
            }
        }

        foreach (Buff buff in action.Unit().Buffs())
        {
            if (buff.CommunicableType() == action.actionType())
            {
                ReceiveBuff(Instantiate(buff.gameObject, Vector3.zero, Quaternion.identity));
            }
        }

        if (action.Affinity() != Helpers.Affinity.None)
        {
            if (action.Affinity() == affinity)
            {
                calculatedDamage *= 0.5f;
            }

            if (affinity == Helpers.Affinity.None)
            {
                SetAffinity(action.Affinity());
            }

            if (
                (action.Affinity() == Helpers.Affinity.Water && affinity == Helpers.Affinity.Fire) ||
                (action.Affinity() == Helpers.Affinity.Fire && affinity == Helpers.Affinity.Earth) ||
                (action.Affinity() == Helpers.Affinity.Earth && affinity == Helpers.Affinity.Water)
                )
            {
                calculatedDamage *= 2;
                SetAffinity(action.Affinity());
            }
        }

        calculatedDamage = backAttacked ? calculatedDamage + 5 : Stance().NegotiateDamage(calculatedDamage, action);

        RevealCurrentStance();

        int actualReceivedDamage = Mathf.RoundToInt(calculatedDamage);

        currentHp -= actualReceivedDamage;

        System.Action showHits = () =>
        {
            GameObject hitsObject = Instantiate(hitsPrefab, transform.position, Quaternion.identity);
            hitsObject.transform.parent             = GameObject.Find("Popups").transform;
            hitsObject.transform.position           = transform.Find("UIAnchors").Find("Damage").position;
            hitsObject.GetComponent <Hits>().damage = "-" + actualReceivedDamage.ToString() + " HP";
        };

        GameObject     stanceDialogueObject = Instantiate(actionDialoguePrefab, transform.position, Quaternion.identity);
        ActionDialogue dialogue             = stanceDialogueObject.GetComponent <ActionDialogue>();
        string         messageToDisplay     = Stance().Name();

        if (backAttacked)
        {
            messageToDisplay += " (Back)";
        }
        dialogue.message  = messageToDisplay;
        dialogue.unit     = this;
        dialogue.whenDone = showHits;
        dialogue.color    = Color.green;

        stanceDialogueObject.transform.parent   = GameObject.Find("Popups").transform;
        stanceDialogueObject.transform.position = transform.Find("UIAnchors").Find("Points").position;

        if (actualReceivedDamage >= startingHp)
        {
            Die(aggressor);
        }
    }