Beispiel #1
0
    public void DeregisterUnitFromPlayer(Unit unit)
    {
        //Checking if the unit that has to be destroyed is the same that has the current turn, in that case the game automatically skips to the next player
        bool skipAfterDestroy = false;

        if (_currentPlayer.CurrentUnit == unit)
        {
            skipAfterDestroy = true;
        }

        CustomHumanPlayer player = _cellGrid.Players.Find(p => p.PlayerNumber.Equals(unit.PlayerNumber)) as CustomHumanPlayer;

        Debug.Assert(player != null, "Error in retriving the player");

        if (player != null)
        {
            player.PlayerUnits = new Queue <Unit>(player.PlayerUnits.Where(u => u != unit));

            if (player.PlayerUnits.Count == 0)
            {
                GameOver(unit.PlayerNumber);
            }
            else if (skipAfterDestroy)
            {
                CustomUnit cUnit = unit as CustomUnit;
                if (cUnit)
                {
                    _cellGrid.EndTurn(cUnit);
                    Debug.Log("Turnskip by destruction called by " + unit.name);
                }
            }
        }
    }
 public CellGridStateWaitingForUnitInput(CellGrid cellGrid, CustomUnit unit) : base(cellGrid)
 {
     if (unit.MovementPoints == 0 && (!unit.abilityActionUsable || unit.ActionPoints == 0))
     {
         CustomCellGrid grid = cellGrid as CustomCellGrid;
         grid?.EndTurn(unit);
     }
 }
Beispiel #3
0
 public void EndTurn(CustomUnit unit)
 {
     //If turn is already ending no need to skip again
     if (!_isTurnEnding)
     {
         StartCoroutine(WaitForUnitBeforeSkippingTurn(unit));
     }
 }
    public override void OnUnitSelected(CustomUnit unit)
    {
        _unit.abilityActionUsable = false;
        _unit.isActing            = true;
        _unit.animator.SetTrigger("Ability");

        _unit.RotateUnitTowardPosition(unit.transform.position);

        _targetUnit = unit;
    }
 protected void ToString(List <string> toStringOutput)
 {
     toStringOutput.Add($"CustomUnit = {(CustomUnit == null ? "null" : CustomUnit.ToString())}");
     toStringOutput.Add($"AreaUnit = {(AreaUnit == null ? "null" : AreaUnit.ToString())}");
     toStringOutput.Add($"LengthUnit = {(LengthUnit == null ? "null" : LengthUnit.ToString())}");
     toStringOutput.Add($"VolumeUnit = {(VolumeUnit == null ? "null" : VolumeUnit.ToString())}");
     toStringOutput.Add($"WeightUnit = {(WeightUnit == null ? "null" : WeightUnit.ToString())}");
     toStringOutput.Add($"GenericUnit = {(GenericUnit == null ? "null" : GenericUnit.ToString())}");
     toStringOutput.Add($"TimeUnit = {(TimeUnit == null ? "null" : TimeUnit.ToString())}");
     toStringOutput.Add($"Type = {(Type == null ? "null" : Type.ToString())}");
 }
    override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        if (_unit == null)
        {
            _unit = animator.gameObject.GetComponent <CustomUnit>();
            Debug.Assert(_unit != null, "Custom unit not found");
        }

        if (_unit)
        {
            _unit.isAnimating = true;
        }
    }
Beispiel #7
0
 private void ChangeCurrentPlayer()
 {
     _currentPlayer = _cellGrid.CurrentPlayer as CustomHumanPlayer;
     _uiController.ForEach(ui => {
         ui.SetButtonsInteractable(ui.PlayerNumber == _cellGrid.CurrentPlayerNumber);
         if (ui.PlayerNumber == _cellGrid.CurrentPlayerNumber)
         {
             CustomUnit unit = _currentPlayer.PlayerUnits.Peek() as CustomUnit;
             if (unit != null)
             {
                 ui.SetAbilityCost(unit.GetAbilityCost());
             }
         }
     });
 }
Beispiel #8
0
    public override void OnUnitClicked(Unit unit)
    {
        if (_unit.isMoving)
        {
            return;
        }

        if (_attackableCellsInRange.Contains(unit.Cell) && unit.PlayerNumber == _unit.PlayerNumber && unit != _unit && _unit.abilityActionUsable)
        {
            CustomUnit cUnit = unit as CustomUnit;
            if (cUnit)
            {
                _unit.ability.OnUnitSelected(cUnit);
            }
            _cellGrid.CellGridState = new CellGridStateWaitingForUnitInput(_cellGrid, _unit);
        }
    }
        public override int GetHashCode()
        {
            int hashCode = -1167462471;

            if (CustomUnit != null)
            {
                hashCode += CustomUnit.GetHashCode();
            }

            if (AreaUnit != null)
            {
                hashCode += AreaUnit.GetHashCode();
            }

            if (LengthUnit != null)
            {
                hashCode += LengthUnit.GetHashCode();
            }

            if (VolumeUnit != null)
            {
                hashCode += VolumeUnit.GetHashCode();
            }

            if (WeightUnit != null)
            {
                hashCode += WeightUnit.GetHashCode();
            }

            if (GenericUnit != null)
            {
                hashCode += GenericUnit.GetHashCode();
            }

            if (TimeUnit != null)
            {
                hashCode += TimeUnit.GetHashCode();
            }

            if (Type != null)
            {
                hashCode += Type.GetHashCode();
            }

            return(hashCode);
        }
Beispiel #10
0
    public void NotifyPlayerSelectedAction(PlayerSelectedAction action)
    {
        CustomUnit currentUnit = _currentPlayer.CurrentUnit as CustomUnit;

        if (currentUnit.isActing || currentUnit.isAnimating)
        {
            Debug.Log("Cannot do actions while the unit is acting");
            return;
        }

        switch (action)
        {
        case PlayerSelectedAction.MOVE:
            if (currentUnit != null && currentUnit.MovementPoints > 0)
            {
                _cellGrid.CellGridState = new CellGridStateUnitMove(_cellGrid, currentUnit);
            }
            break;

        case PlayerSelectedAction.ATTACK:
            if (currentUnit != null && currentUnit.ActionPoints > 0 && currentUnit.abilityActionUsable)
            {
                _cellGrid.CellGridState = new CellGridStateUnitAttack(_cellGrid, currentUnit);
            }
            break;

        case PlayerSelectedAction.ABILITY:
            if (currentUnit != null && currentUnit.ActionPoints > 0 && currentUnit.abilityActionUsable)
            {
                currentUnit.ability.EnterState(_cellGrid, currentUnit);
            }
            break;

        case PlayerSelectedAction.SKIPTURN:
            _cellGrid.EndTurn();
            break;

        case PlayerSelectedAction.PAUSE:
            _pauseMenu.ToglePause(true);
            break;

        default:
            Debug.Assert(false, "Option not implemented detected");
            break;
        }
    }
Beispiel #11
0
        public Transaction(
            DateTime transactionTime,
            String description,
            GlobalUnit globalUnit,
            CustomUnit customUnit,
            int[] entries,
            Entity entity,
            Session session,
            Action <Transaction> completion
            )
        {
            var newAttributes = new NewTransactionArguments(
                transactionTime,
                description,
                globalUnit,
                customUnit,
                entries
                );

            this.create(newAttributes, session, completion);
        }
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }

            if (obj == this)
            {
                return(true);
            }

            return(obj is MeasurementUnit other &&
                   ((CustomUnit == null && other.CustomUnit == null) || (CustomUnit?.Equals(other.CustomUnit) == true)) &&
                   ((AreaUnit == null && other.AreaUnit == null) || (AreaUnit?.Equals(other.AreaUnit) == true)) &&
                   ((LengthUnit == null && other.LengthUnit == null) || (LengthUnit?.Equals(other.LengthUnit) == true)) &&
                   ((VolumeUnit == null && other.VolumeUnit == null) || (VolumeUnit?.Equals(other.VolumeUnit) == true)) &&
                   ((WeightUnit == null && other.WeightUnit == null) || (WeightUnit?.Equals(other.WeightUnit) == true)) &&
                   ((GenericUnit == null && other.GenericUnit == null) || (GenericUnit?.Equals(other.GenericUnit) == true)) &&
                   ((TimeUnit == null && other.TimeUnit == null) || (TimeUnit?.Equals(other.TimeUnit) == true)) &&
                   ((Type == null && other.Type == null) || (Type?.Equals(other.Type) == true)));
        }
        public NewTransactionArguments(
            DateTime transactionTime,
            String description,
            GlobalUnit globalUnit,
            CustomUnit customUnit,
            int[] entries
            )
        {
            if (globalUnit != null && customUnit != null)
            {
                throw new InvalidTransactionArguments(ErrTwoUnits);
            }

            if (globalUnit == null && customUnit == null)
            {
                throw new InvalidTransactionArguments(ErrTwoUnits);
            }

            if (entries == null || transactionTime == null)
            {
                throw new ArgumentNullException(ErrNullArgument);
            }

            if (description == null)
            {
                description = "";
            }

            if (description.Length > MaxDescriptionLength)
            {
                throw new InvalidTransactionArguments(ErrDescriptionLength);
            }

            this.transactionTime = transactionTime;
            this.description     = description;
            this.globalUnit      = globalUnit;
            this.customUnit      = customUnit;
            this.entries         = entries;
        }
Beispiel #14
0
    private IEnumerator WaitForUnitBeforeSkippingTurn(CustomUnit unit)
    {
        _isTurnEnding = true;

        while (unit.isActing || unit.isAnimating)
        {
            yield return(null);
        }

        yield return(null);

        foreach (CustomHumanPlayer player in Players)
        {
            if (player && player.PlayerUnits.Count == 0)
            {
                yield break;
            }
        }

        EndTurn();
        _isTurnEnding = false;
    }
 public CellGridStateUnitMove(CellGrid cellGrid, Unit unit) : base(cellGrid)
 {
     _unit         = unit as CustomUnit;
     _pathsInRange = new HashSet <Cell>();
     _currentPath  = new List <Cell>();
 }
Beispiel #16
0
 public override void OnUnitSelected(CustomUnit unit)
 {
     Debug.LogError("Not usuable option called");
 }
Beispiel #17
0
 public override void EnterState(CellGrid cellGrid, CustomUnit unit)
 {
     base.EnterState(cellGrid, unit);
     cellGrid.CellGridState = new CellGridStateUnityAbilityTileTarget(cellGrid, unit);
 }
 public CellGridStateUnityAbilityStraightTileTarget(CellGrid cellGrid, Unit unit) : base(cellGrid)
 {
     _unit = (CustomUnit)unit;
     _attackableCellsInRange = new List <Cell>();
 }
Beispiel #19
0
 public CellGridStateUnitAttack(CellGrid cellGrid, Unit unit) : base(cellGrid)
 {
     _unit = unit as CustomUnit;
     _attackableCellsInRange = new List <Cell>();
 }
Beispiel #20
0
 public virtual void EnterState(CellGrid cellGrid, CustomUnit unit)
 {
     _unit = unit;
 }
Beispiel #21
0
 public abstract void OnUnitSelected(CustomUnit unit);