Ejemplo n.º 1
0
        private IEnumerable <ICombatEvent> UseSkillByPerson(ICombatPerson person, ICombatSquad targetSquad)
        {
            var           eventList    = new List <ICombatEvent>();
            ICombatPerson rolledPerson = SelectTargetPerson(targetSquad);

            IAttackResult attackResult;

            var       toHitDice        = new Roll(6, 1);
            var       toHitRoll        = _skillUsageRandomSource.RollToHit(toHitDice);
            const int toHitRollSuccess = 4;

            if (toHitRoll >= toHitRollSuccess)
            {
                var efficientRoll = new Roll(3, 1);
                var damage        = _skillUsageRandomSource.RollEfficient(efficientRoll);

                rolledPerson.TakeDamage(damage);

                attackResult = new AttackSuccessResult(damage, rolledPerson.HitPoints <= 0);
            }
            else
            {
                attackResult = new AttackMissResult();
            }

            var attackEvent = new AttackCombatEvent(person, rolledPerson, attackResult);

            eventList.Add(attackEvent);

            return(eventList);
        }
Ejemplo n.º 2
0
        public void RemovePerson(ICombatPerson person)
        {
            var list = Persons.ToList();

            list.Remove(person);
            Persons = list.ToArray();
        }
Ejemplo n.º 3
0
 public AttackCombatEvent(ICombatPerson sender,
                          ICombatPerson target,
                          IAttackResult result)
 {
     Sender = sender ?? throw new ArgumentNullException(nameof(sender));
     Target = target ?? throw new ArgumentNullException(nameof(target));
     Result = result ?? throw new ArgumentNullException(nameof(result));
 }
Ejemplo n.º 4
0
    private CombatPersonModel FindCombatPersonModel(ICombatPerson person)
    {
        foreach (var combatSquadModel in _squadModels)
        {
            foreach (var combatPersonModel in combatSquadModel.PersonModels)
            {
                if (combatPersonModel.CombatPerson == person)
                {
                    return(combatPersonModel);
                }
            }
        }

        throw new InvalidOperationException();
    }
Ejemplo n.º 5
0
    private void ProcessAttackEvent(ICombatEvent combatEvent, ICombatPerson senderPerson,
                                    HashSet <CombatPersonModel> deadPersonModels)
    {
        if (!(combatEvent is AttackCombatEvent attackEvent))
        {
            return;
        }

        var senderModel = FindCombatPersonModel(senderPerson);
        var targetModel = FindCombatPersonModel(attackEvent.Target);

        CreateWeaponTracer(senderModel.transform.position, targetModel.transform.position);
        CreateShootFlash(senderModel.transform.position);
        ShakeCamera(.5f, .05f);

        var damageIndicator = Instantiate(DamageIndicatorPrefab, Parent);

        damageIndicator.transform.position = targetModel.transform.position + Vector3.up * 1.5f;
        damageIndicator.Canvas.worldCamera = Camera.main;

        switch (attackEvent.Result)
        {
        case AttackSuccessResult attackEventResult:
        {
            damageIndicator.SetDamage(attackEventResult.Damage);

            if (attackEventResult.TargetIsDead)
            {
                deadPersonModels.Add(targetModel);
            }

            break;
        }

        case AttackMissResult _:
        {
            damageIndicator.SetMiss();
            break;
        }
        }
    }
Ejemplo n.º 6
0
 public void Init(ICombatPerson combatPerson)
 {
     CombatPerson = combatPerson;
 }