コード例 #1
0
ファイル: CombatManager.cs プロジェクト: Snory/LudumDare46
    public void RequestCombat(CombatRequest playerRequest, CombatRequest enemyRequest)
    {
        ILife enemyLifeForce  = enemyRequest.Combatan.GetComponent <ILife>();
        ILife playerLifeForce = playerRequest.Combatan.GetComponent <ILife>();

        int attackPlayer = DiceManager.Instance.GetSumOfXThrownDice(playerRequest.AttackCountDice);
        int defenseEnemy = DiceManager.Instance.GetSumOfXThrownDice(enemyRequest.DefenseCountDice);

        int attackEnemy   = DiceManager.Instance.GetSumOfXThrownDice(enemyRequest.AttackCountDice);
        int defensePlayer = DiceManager.Instance.GetSumOfXThrownDice(playerRequest.DefenseCountDice);



        //compare thown against player
        int attackDiff   = attackPlayer - defenseEnemy;
        int deffenceDiff = defensePlayer - attackEnemy;



        CombatResult playerCombatResult =
            new CombatResult(
                attackDiff > 0 && attackEnemy > 0 ? true : false
                , deffenceDiff >= 0 ? true : false
                , playerRequest.AttackCountDice + playerRequest.DefenseCountDice
                , deffenceDiff
                , attackPlayer
                , defensePlayer
                , enemyRequest.Combatan
                );

        CombatResult enemyCombatResult =
            new CombatResult(
                deffenceDiff < 0 ? true : false
                , (attackDiff <= 0 && attackEnemy > 0) || attackEnemy == 0 ? true : false
                , enemyRequest.AttackCountDice + enemyRequest.DefenseCountDice
                , attackDiff
                , attackEnemy
                , defenseEnemy
                , playerRequest.Combatan
                );

        HUDActionPanelManager.Instance.SetCombatResult(playerCombatResult, enemyCombatResult);

        playerRequest.CallBack(playerCombatResult);
        enemyRequest.CallBack(enemyCombatResult);
    }
コード例 #2
0
    public void RunCombat()
    {
        if (_enemy.gameObject.layer == 0)
        {
            return;
        }
        AudioManager.Instance.ButtonClick();
        StopWaitBeforeDissapear();
        //ShowResult(true);
        //player request
        CombatRequest playerCombatRequest = new CombatRequest(_player, _attNumInt, _decNumInt, _playerLifeForce.OnCombatResult);
        //enemyrequest
        EnemyDiceThrow aiThrow            = _enemyDiceAI.GetEnemyDiceThrow(_playerLifeForce);
        CombatRequest  enemyCombatRequest = new CombatRequest(_enemy, aiThrow.AttackDiceCount, aiThrow.DefenseDiceCount, _enemyLifeForce.OnCombatResult);

        //combatmanager
        CombatManager.Instance.RequestCombat(playerCombatRequest, enemyCombatRequest);
        _showRoutine = StartCoroutine(StartWaitBeforeDissapear());
    }
コード例 #3
0
        public void Execute(CombatRequest request)
        {
            switch (request.CommandCase)
            {
            case CombatRequest.CommandOneofCase.MoveUnit:
                _manager.Move(request.MoveUnit.UnitTag, request.MoveUnit.Point, request.MoveUnit.Queue);
                break;

            case CombatRequest.CommandOneofCase.MoveSquad:
                _manager.Move(_repository.Get().First(s => s.Id.Equals(request.MoveSquad.Squad)),
                              request.MoveSquad.Point, request.MoveSquad.Queue);
                break;

            case CombatRequest.CommandOneofCase.AttackMoveUnit:
                _manager.AttackMove(request.AttackMoveUnit.UnitTag, request.AttackMoveUnit.Point,
                                    request.AttackMoveUnit.Queue);
                break;

            case CombatRequest.CommandOneofCase.AttackMoveSquad:
                _manager.AttackMove(_repository.Get().First(s => s.Id.Equals(request.AttackMoveSquad.Squad)),
                                    request.AttackMoveSquad.Point, request.AttackMoveSquad.Queue);
                break;

            case CombatRequest.CommandOneofCase.AttackUnit:
                _manager.Attack(request.AttackUnit.SourceUnit, request.AttackUnit.TargetUnit,
                                request.AttackUnit.Queue);
                break;

            case CombatRequest.CommandOneofCase.AttackSquad:
                _manager.Attack(_repository.Get().First(s => s.Id.Equals(request.AttackSquad.Squad)),
                                request.AttackSquad.TargetUnit, request.AttackSquad.Queue);
                break;

            case CombatRequest.CommandOneofCase.UseTargetedAbilityUnit:
                _manager.UseTargetedAbility(request.UseTargetedAbilityUnit.AbilityId,
                                            request.UseTargetedAbilityUnit.SourceUnit, request.UseTargetedAbilityUnit.TargetUnit,
                                            request.UseTargetedAbilityUnit.Queue);
                break;

            case CombatRequest.CommandOneofCase.UseTargetedAbilitySquad:
                _manager.UseTargetedAbility(request.UseTargetedAbilitySquad.AbilityId,
                                            _repository.Get().First(s => s.Id.Equals(request.UseTargetedAbilitySquad.Squad)),
                                            request.UseTargetedAbilitySquad.TargetUnit, request.UseTargetedAbilitySquad.Queue);
                break;

            case CombatRequest.CommandOneofCase.UsePointCenteredAbilityUnit:
                _manager.UsePointCenteredAbility(request.UsePointCenteredAbilityUnit.AbilityId,
                                                 request.UsePointCenteredAbilityUnit.SourceUnit, request.UsePointCenteredAbilityUnit.Point);
                break;

            case CombatRequest.CommandOneofCase.UsePointCenteredAbilitySquad:
                _manager.UsePointCenteredAbility(request.UsePointCenteredAbilitySquad.AbilityId,
                                                 _repository.Get().First(s => s.Id.Equals(request.UsePointCenteredAbilitySquad.Squad)),
                                                 request.UsePointCenteredAbilitySquad.Point, request.UsePointCenteredAbilitySquad.Queue);
                break;

            case CombatRequest.CommandOneofCase.UseTargetlessAbilityUnit:
                _manager.UseTargetlessAbility(request.UseTargetlessAbilityUnit.AbilityId,
                                              request.UseTargetlessAbilityUnit.SourceUnit, request.UseTargetlessAbilityUnit.Queue);
                break;

            case CombatRequest.CommandOneofCase.UseTargetlessAbilitySquad:
                _manager.UseTargetlessAbility(request.UseTargetedAbilitySquad.AbilityId,
                                              _repository.Get().First(s => s.Id.Equals(request.UseTargetedAbilitySquad.Squad)),
                                              request.UseTargetedAbilitySquad.Queue);
                break;

            case CombatRequest.CommandOneofCase.SmartMoveUnit:
                if (_intel.TryGet(request.SmartMoveUnit.UnitTag, out IUnit unit))
                {
                    _manager.SmartMove(unit, request.SmartMoveUnit.Point, request.SmartMoveUnit.Queue);
                }
                break;

            case CombatRequest.CommandOneofCase.SmartMoveSquad:
                _manager.SmartMove(_repository.Get().First(s => s.Id.Equals(request.SmartMoveSquad.Squad)),
                                   request.SmartMoveSquad.Point, request.SmartMoveSquad.Queue);
                break;

            case CombatRequest.CommandOneofCase.SmartAttackMoveUnit:
                if (_intel.TryGet(request.SmartMoveUnit.UnitTag, out IUnit u))
                {
                    _manager.SmartAttackMove(u, request.SmartAttackMoveUnit.Point, request.SmartAttackMoveUnit.Queue);
                }
                break;

            case CombatRequest.CommandOneofCase.SmartAttackMoveSquad:
                _manager.SmartAttackMove(
                    _repository.Get().First(s => s.Id.Equals(request.SmartAttackMoveSquad.Squad)),
                    request.SmartAttackMoveSquad.Point, request.SmartAttackMoveSquad.Queue);
                break;

            case CombatRequest.CommandOneofCase.SmartAttackUnit:
                if (_intel.TryGet(request.SmartAttackUnit.SourceUnit, out IUnit un))
                {
                    _manager.SmartAttack(un, request.SmartAttackUnit.TargetUnit, request.SmartAttackUnit.Queue);
                }
                break;

            case CombatRequest.CommandOneofCase.SmartAttackSquad:
                _manager.SmartAttack(_repository.Get().First(s => s.Id.Equals(request.SmartAttackSquad.Squad)),
                                     request.SmartAttackSquad.TargetUnit, request.SmartAttackSquad.Queue);
                break;

            case CombatRequest.CommandOneofCase.SquadRequest:
                var addUnits    = request.SquadRequest.AddUnits;
                var removeUnits = request.SquadRequest.RemoveUnits;
                var createSquad = request.SquadRequest.CreateSquad;
                var removeSquad = request.SquadRequest.RemoveSquad;
                if (request.SquadRequest.AddUnits != null)
                {
                    foreach (var tag in addUnits.Tags)
                    {
                        if (_intel.TryGet(tag, out var addedUnit))
                        {
                            _repository.Get().First(s => s.Id.Equals(request.SquadRequest.AddUnits.SquadId))
                            .AddUnit(addedUnit);
                        }
                    }
                }
                if (removeUnits != null)
                {
                    foreach (var tag in removeUnits.Tags)
                    {
                        if (_intel.TryGet(tag, out var removedUnit))
                        {
                            _repository.Get().First(s => s.Id.Equals(request.SquadRequest.RemoveUnits.SquadId))
                            .RemoveUnit(removedUnit);
                        }
                    }
                }
                if (createSquad != null)
                {
                    _repository.Create(createSquad.Squad.Name, createSquad.Squad.SquadId);
                }
                if (removeSquad != null)
                {
                    _repository.Remove(removeSquad.SquadId);
                }
                break;

            default:
                throw new System.NotImplementedException();
            }
        }