コード例 #1
0
ファイル: ShipData.cs プロジェクト: regstar/OpenSpace4x
    public void QuadrantDestroyed(ShipQuadrant quad, AttachedWeapon weapon, float damage, bool ignoreShields, bool ignoreArmor, bool ignoreArmorRating)
    {
        if (quad == CenterSection)
        {
            if (Destroyed)
            {
                return;
            }
            weapon.GetKill(CurrentUnit);
            Destroyed = true;
            if (fleetData != null)
            {
                fleetData.RecalculateStats();
            }

            if (CurrentUnit != null)
            {
                (CurrentUnit as Ship).Die();
            }
            CurrentUnit = null;
            return;
        }
        else if (CurrentUnit != null)
        {
            CurrentUnit.AttachFireDamage((CurrentUnit as Ship).GetDamageHardPoint(), designData.Hull.ExplosionScale);
            if (damage > 0)
            {
                CenterSection.TakeDamage(weapon, CurrentUnit.transform.position, damage, ignoreShields, ignoreArmor, ignoreArmorRating);
            }
        }

        CalculateEngines();
    }
コード例 #2
0
    private IEnumerator PerformAttackAction(Vector3Int clickedPos, Unit clickedUnit)
    {
        SkillConfig skillConfig = CurrentUnit.GetSkillConfig(AttackMode);

        Unit actingUnit      = CurrentUnit;
        bool isAttackClicked = actingUnit.skillHandler.Contains(skillConfig, clickedPos);

        if (isAttackClicked)
        {
            LevelTile clickedTile = TilemapNavigator.Instance.GetTile(clickedPos);
            bool      canAttack   = skillConfig.CanPerformAttack(actingUnit, clickedUnit, clickedTile);
            if (canAttack)
            {
                bool usedAnActionPoint = turnManager.UseActionPoint(CurrentUnit);
                if (usedAnActionPoint)
                {
                    UpdateDisabledUnits();
                    SelectUnit(null);
                    yield return(StartCoroutine(actingUnit.Attack(skillConfig, clickedPos, clickedUnit)));

                    if (turnManager.CanPerformMovement(actingUnit) || turnManager.CanPerformAction(actingUnit))
                    {
                        SelectUnit(actingUnit);
                    }
                }
            }
        }

        ChangeAttackMode(AttackModes.None);
        AvailableActionsChanged.Invoke();
    }
コード例 #3
0
 /// <summary>
 /// Converts the <see cref="Current"/> to the specified <paramref name="targetUnit"/>.
 /// </summary>
 /// <param name="targetUnit">Target units.</param>
 /// <returns><see cref="Current"/> converted to <paramref name="targetUnit"/>.</returns>
 public double ConvertTo(CurrentUnit targetUnit)
 {
     return(targetUnit switch
     {
         CurrentUnit.Amperes => m_value,
         CurrentUnit.Abamperes => ToAbamperes(),
         CurrentUnit.Statamperes => ToStatamperes(),
         _ => throw new ArgumentOutOfRangeException(nameof(targetUnit), targetUnit, null)
     });
コード例 #4
0
        protected override async Task OnInitializedAsync()
        {
            CurrentProject = null;
            CurrentUnit    = await UserUnitService.GetCurrentUnit();

            CurrentBacklogDefinition = CurrentUnit.GetAvailableBacklogs().First().backlog;
            CurrentBacklog           = await BacklogService.GetBacklog(CurrentBacklogDefinition);

            Update();
        }
コード例 #5
0
ファイル: CursorController.cs プロジェクト: Natzely/TrialGame
 private void SelectUnit(bool select)
 {
     CurrentUnit.Select(select);
     if (select)
     {
         CurrentUnit.OnUnitInterupt += OnCurrentUnitInterupt;
     }
     else
     {
         CurrentUnit.OnUnitInterupt -= OnCurrentUnitInterupt;
     }
 }
コード例 #6
0
 public Current(string value, string unit)
 {
     try
     {
         this.value = float.Parse(value);
         this.unit  = (CurrentUnit)Enum.Parse(typeof(CurrentUnit), unit);
     }
     catch
     {
         this.value = defaultValue;
         this.unit  = defaultUnit;
     }
 }
コード例 #7
0
        public override void StartTurn(UnitController unit)
        {
            base.StartTurn(unit);

            _turnScenarioItem = new SyncScenario(
                new CompleteScenarioItemConditionWaiter(
                    CurrentUnit.CastAbility(new CastContext {
                Caster = unit
            }),
                    true),
                new ActionScenarioItem(() => Game.Instance.NextTurn())
                ).PlayAndReturnSelf();
        }
コード例 #8
0
    public void SetGrid(GridBlock moveFrom, List <Enums.GridBlockType> favTerrain, int moveDistance, int minAttackDistance, int maxAttackDistance)
    {
        bool saveParams = true;

        if (Unpassable || (!Utility.TrueNull(CurrentUnit) && CurrentUnit.IsEnemy(Enums.Player.Player1)) || _unitsMovingThrough.Any(uC => uC != null && uC.IsEnemy(Enums.Player.Player1)))
        {
            moveDistance = -1;
        }

        if (moveFrom == null)
        {
            moveDistance += (favTerrain.Contains(this.Type) ? 1 : MovementCost);
        }

        moveDistance = Mathf.Clamp(moveDistance - (favTerrain.Contains(this.Type) ? 1 : MovementCost), -1, 9999); // If this terrain is favorable to the unit, only subtract one.

        if (moveDistance >= 0)
        {
            _gridParams.ActiveSpace = Enums.ActiveSpace.Move;
            _gridParams.ShowMoveSpace(moveFrom?.Position);
        }
        else if (maxAttackDistance > 0)
        {
            _gridParams.ActiveSpace = Enums.ActiveSpace.Attack;
            _gridParams.ShowAttackSpace(moveFrom?.Position);
            maxAttackDistance--;
        }
        else
        {
            _gridParams.Reset();
            saveParams = false;
        }

        //if (moveFrom == null)
        //    text.text = "";
        //text.text += $"{gameObject.name}::: moveDis:{moveDistance}, minAttack:{minAttackDistance}, maxAttack:{maxAttackDistance}, neighbors:{Neighbors.Count()} |||||| ";

        if (saveParams)
        {
            _gridParams.FavorableTerrain  = favTerrain;
            _gridParams.MoveDistance      = moveDistance;
            _gridParams.MinAttackDistance = minAttackDistance;
            _gridParams.MaxAttackDistance = maxAttackDistance;
        }

        _pM.UpdateBlockGrid(GridPosition, this, saveParams);
    }
コード例 #9
0
    private void ChooseAction()
    {
        Debug.Log("Choose action");
        List <GameObject> unitsWithTarget = Units.FindAll((GameObject o) => o.GetComponent <BattleUnit>().HasUnitsInAttackRange());

        if (unitsWithTarget.Count > 0)
        {
            Debug.Log("attack");
            CurrentUnit = unitsWithTarget[UnityEngine.Random.Range(0, unitsWithTarget.Count)];
            List <GameObject> possibleTargets = CurrentUnit.GetComponent <BattleUnit>().GetUnitsInRange();
            Attack(possibleTargets[UnityEngine.Random.Range(0, possibleTargets.Count)]);
        }
        else
        {
            Move();
        }
    }
コード例 #10
0
ファイル: Current.cs プロジェクト: sotaria/gsf
        /// <summary>
        /// Converts the <paramref name="value"/> in the specified <paramref name="sourceUnit"/> to a new <see cref="Current"/> in amperes.
        /// </summary>
        /// <param name="value">Source value.</param>
        /// <param name="sourceUnit">Source value units.</param>
        /// <returns>New <see cref="Current"/> from the specified <paramref name="value"/> in <paramref name="sourceUnit"/>.</returns>
        public static Current ConvertFrom(double value, CurrentUnit sourceUnit)
        {
            switch (sourceUnit)
            {
            case CurrentUnit.Amperes:
                return(value);

            case CurrentUnit.Abamperes:
                return(FromAbamperes(value));

            case CurrentUnit.Statamperes:
                return(FromStatamperes(value));

            default:
                throw new ArgumentOutOfRangeException(nameof(sourceUnit), sourceUnit, null);
            }
        }
コード例 #11
0
ファイル: Current.cs プロジェクト: sotaria/gsf
        /// <summary>
        /// Converts the <see cref="Current"/> to the specified <paramref name="targetUnit"/>.
        /// </summary>
        /// <param name="targetUnit">Target units.</param>
        /// <returns><see cref="Current"/> converted to <paramref name="targetUnit"/>.</returns>
        public double ConvertTo(CurrentUnit targetUnit)
        {
            switch (targetUnit)
            {
            case CurrentUnit.Amperes:
                return(m_value);

            case CurrentUnit.Abamperes:
                return(ToAbamperes());

            case CurrentUnit.Statamperes:
                return(ToStatamperes());

            default:
                throw new ArgumentOutOfRangeException(nameof(targetUnit), targetUnit, null);
            }
        }
コード例 #12
0
    public void SelectObject(Unit _selectedObj)
    {
        if (SomeoneIsMoving || _selectedObj.FinishedAttack)
        {
            return;
        }

        if (CurrentUnit != null)
        {
            CurrentUnit.CurrentTile.DeselectedTile();
            CurrentUnit.OnDefault();
        }

        CurrentUnit = _selectedObj;

        if (CurrentUnit != null)
        {
            CurrentUnit.CurrentTile.SelectedTile();
            Pointer.SetActive(true);
            //Pointer.transform.position = new Vector3(CurrentUnit.transform.position.x, CurrentUnit.transform.position.y + 1, CurrentUnit.transform.position.z);
        }

        Image unitFrameImage = UIManager.instance.UnitFrame.GetComponent <Image>();

        if (_selectedObj.UnitType == UnitType.Titan)
        {
            unitFrameImage.sprite = UIManager.instance.Knight;
        }
        else if (_selectedObj.UnitType == UnitType.Tanky)
        {
            unitFrameImage.sprite = UIManager.instance.Tanky;
        }
        else if (_selectedObj.UnitType == UnitType.Tiny)
        {
            unitFrameImage.sprite = UIManager.instance.Lancer;
        }

        unitFrameImage.SetNativeSize();
        UIManager.instance.UnitFrame.transform.parent.gameObject.SetActive(true);
        SoundManager.instance.PlayConfirm();
    }
コード例 #13
0
 public CurrentConverter(CurrentUnit unit)
 {
     this.Unit = unit;
 }
コード例 #14
0
    private void HighlightTiles()
    {
        switch (state)
        {
        case ControllerState.Atttacking:
            GridController.GetGridController().EnableValidTiles((Tile t) => { return(UnitInAttackRange(t, CurrentUnit) &&
                                                                                     t.CurrentUnit.GetComponent <BattleUnit>().team != CurrentUnit.GetComponent <BattleUnit>().team); });
            break;

        case ControllerState.Moving:
            GridController.GetGridController().EnableValidTiles((Tile t) => { return(TileInMoveRange(t, CurrentUnit)); });
            break;

        case ControllerState.ModePicking:
            GridController.GetGridController().SetGridEnabled(false);
            break;
        }
        UpdateDisplayedButtons();
    }
コード例 #15
0
ファイル: CursorController.cs プロジェクト: Natzely/TrialGame
    public void Select(InputAction.CallbackContext context)
    {
        if (!context.performed)
        {
            return;
        }

        if (CursorState == Enums.CursorState.Default && CurrentUnit != null)
        {
            CursorState   = Enums.CursorState.Selected;
            _orgGridBlock = CurrentGridBlock;

            if (Position == CurrentUnit.Position)
            {
                if (!CurrentUnit.Moved)
                {
                    _startPos = transform.position;
                }

                SelectUnit(true);

                _aS.Play(Sound_Select);

                CurrentGridBlock.UseMoveAnimation = true;
                InitializeGrid(CurrentGridBlock);


                _moves = new List <GridBlock>()
                {
                    CurrentGridBlock
                };
            }
        }
        else if (CursorState == Enums.CursorState.Selected && CurrentGridBlock.ActiveSpace == Enums.ActiveSpace.Move && (CurrentGridBlock.CurrentUnit == null || !CurrentGridBlock.CurrentUnit.AtDestination))
        {
            _pM.ActiveGrid_Hide();
            CursorState = Enums.CursorState.OnlyAttack;
            _pM.ResetBlockGrid();
            CurrentGridBlock.UseMoveAnimation = false;
            InitializeGrid(CurrentGridBlock);
            _aS.Play(Sound_Select);
        }
        else if (CursorState == Enums.CursorState.OnlyAttack && CurrentGridBlock.ActiveSpace == Enums.ActiveSpace.Move)
        {
            CurrentUnit.MoveTo(_moves);

            _aS.Play(Sound_Attack);
            SelectUnit(false);
            ResetCursor();
        }
        else if (CursorState == Enums.CursorState.Attack)
        {
            var bestGrid = FirstAvaiableGridBlock();
            if (bestGrid == null)
            {
                return;
            }
            else
            {
                _moves.RemoveAllAfter(bestGrid);
            }

            CurrentUnit.Target = CurrentGridBlock;
            CurrentUnit.MoveTo(_moves, true);

            _aS.Play(Sound_Attack);
            SelectUnit(false);
            ResetCursor();
        }
        else if (CursorState == Enums.CursorState.OnlyAttack)
        {
            CurrentUnit.Target = CurrentGridBlock;
            CurrentUnit.MoveTo(_moves, false);

            _aS.Play(Sound_Attack);
            SelectUnit(false);
            ResetCursor();
        }
        //else if (!CurrentUnit.Moving && /*!CurrentUnit.Moved &&*/ transform.position.V2() != _startPos && CurrentGridBlock.ActivePlayerSpace != Enums.ActiveSpace.Inactive &&
        //    (CurrentGridBlock.IsCurrentUnitEnemy(Player) ||
        //    (CurrentGridBlock.ActivePlayerSpace == Enums.ActiveSpace.Move && CurrentGridBlock.CurrentUnit == null) //||
        //    /*(_attackSpace && (CurrentGridBlock.CurrentUnit == null || CurrentGridBlock.IsCurrentUnitEnemy(Player)))*/
        //    ))
        //{
        //    List<GridBlock> backupSpaces = null;
        //    var target = CurrentGridBlock;
        //    double dis = 9999;
        //    if (target.CurrentUnit != null)// || _attackSpace)
        //    {
        //        dis = target.Position.GridDistance(CurrentUnit.Position);
        //        CurrentUnit.Target = target;
        //    }

        //    if (target.CurrentUnit == null && _moves?.Count > 1)// && !_attackSpace)
        //    {
        //        CurrentUnit.MoveTo(_moves);
        //    }
        //    else if (!CurrentUnit.Attacked) // If the unit has not attacked yet, check attack options
        //    {                                                                                                                // If attacking an empty space, subtrack a move because the cursor created a move to reach that space
        //        if (!CurrentUnit.Attacked &&
        //            ((dis >= CurrentUnit.MinAttackDistance && dis <= CurrentUnit.MaxAttackDistance) /*|| (_attackSpace && dis <= CurrentUnit.MaxAttackDistance)*/) &&
        //            _moves?.Count /*- (_attackSpace ? 1 : 0)*/ <= CurrentUnit.MaxAttackDistance) // If the unit is already in range of the target,
        //        {
        //            _aS.Play(Sound_Attack);
        //            CurrentUnit.CheckAttack(target, false);// _attackSpace);
        //        }
        //        else if (_moves?.Count > 1) // If the unit needs to move to attack
        //        {
        //            double lastPosDis = _moves.Last().Position.GridDistance(target.Position);
        //            if (lastPosDis < CurrentUnit.MinAttackDistance)
        //            {
        //                var lastGrid = _moves.Last();
        //                var orderedN = lastGrid.Neighbors.OrderByDistance(_orgGridBlock, true);
        //                var canMoveTo = orderedN.Where(n => n.ActiveSpace(Player) == Enums.ActiveSpace.Move).ToList();
        //                var newTargetGrid = canMoveTo.FirstOrDefault();

        //                if (newTargetGrid != null && _moves.Contains(newTargetGrid))
        //                {
        //                    int index = _moves.IndexOf(newTargetGrid) + 1; // Erase everything higher than the selected grid
        //                    if (index <= _moves.Count())
        //                        _moves.RemoveRange(index, _moves.Count() - index);
        //                }
        //                else if (newTargetGrid != null)
        //                {
        //                    _moves.Add(newTargetGrid);
        //                }
        //                else if (newTargetGrid == null)
        //                {
        //                    CurrentUnit.Target = null;
        //                    return;
        //                }
        //            }

        //            if (_moves?.Count > 0)
        //            {
        //                CurrentUnit.MoveTo(_moves);
        //            }
        //        }
        //    }
        //    else if ((backupSpaces = _orgGridBlock.AvailableAttackSpace(CurrentGridBlock, CurrentUnit.MaxAttackDistance).ToList()).Count > 0) // If the unit is too close to attack but there is room for it back up and attack
        //    {
        //        _aS.Play(Sound_Attack);
        //        CurrentUnit.MoveTo(new List<GridBlock>() { _orgGridBlock, backupSpaces.First() });
        //    }
        //    else // If non of the other conditions are met, then do nothing.
        //    {
        //        CurrentUnit.Target = null;
        //        return;
        //    }

        //    if (CurrentUnit.Target != null && ((target.CurrentUnit != null && target.CurrentUnit.IsEnemy(Player))))// || _attackSpace))
        //    {
        //        _aS.Play(Sound_Attack);
        //        SelectUnit(false);
        //        ResetCursor();
        //    }
        //}
        //else if ((CurrentUnit.Moving || CurrentUnit.Moved) && CurrentGridBlock.IsCurrentUnitEnemy(Player))
        //{
        //    _aS.Play(Sound_Attack);
        //    CurrentUnit.Target = CurrentGridBlock;
        //    SelectUnit(false);
        //    ResetCursor();
        //}
        //else if ((CurrentUnit.Moving || CurrentUnit.Moved))
        //{
        //    _aS.Play(Sound_Attack);
        //    SelectUnit(false);
        //    ResetCursor();
        //}
    }
コード例 #16
0
 public Current(float value, CurrentUnit unit)
 {
     this.value = value;
     this.unit  = unit;
 }
コード例 #17
0
 /// <summary>
 /// Creates a new instance of a work unit based on voltage and current.
 /// </summary>
 /// <param name="voltageUnit">The unit of the voltage.</param>
 /// <param name="currentUnit">The unit of the current.</param>
 public WorkUnit(VoltageUnit voltageUnit, CurrentUnit currentUnit)
     : base(new UnitCompositeCollection() { new MultipliedByUnit(voltageUnit, 1), new MultipliedByUnit(currentUnit, 1) })
 {
     // Work can also be VA, so public.
 }
コード例 #18
0
 public float ChangeUnit(CurrentUnit newUnit)
 {
     return(value * Ratio[(int)unit] / Ratio[(int)newUnit]);
 }
コード例 #19
0
 /// <summary>
 /// Creates a new instance of a resistance unit.
 /// </summary>
 /// <param name="voltage">The voltage difference</param>
 /// <param name="current">The electric current.</param>
 public ResistanceUnit(VoltageUnit voltage, CurrentUnit current)
     : base(new UnitCompositeCollection() { new MultipliedByUnit(voltage, 1), new DividedByUnit(current, 1) })
 {
     // resistance is always voltage over current, so public
 }
コード例 #20
0
 private CurrentJsonConverter(CurrentUnit unit)
 {
     this.unit = unit;
 }
コード例 #21
0
 /// <summary>
 /// Creates a new instance of a electric power.
 /// </summary>
 /// <param name="voltage">The unit for the voltage</param>
 /// <param name="current">The unit for the current</param>
 protected PowerUnit(VoltageUnit voltage, CurrentUnit current)
     : base(new UnitCompositeCollection() { new MultipliedByUnit(voltage, 1), new MultipliedByUnit(current, 1) })
 {
 }
コード例 #22
0
 private void OnSwipe(Vector2 direction, float speedCoef)
 {
     StopSelection();
     CurrentUnit.Move(direction, speedCoef);
     UIDragController.Instance.Swipe -= OnSwipe;
 }
コード例 #23
0
 /// <summary>
 /// Creates a new instance of inductance based on current and time.
 /// </summary>
 public InductanceUnit(CurrentUnit currentUnit, TimeUnit timeUnit)
     : base(new UnitCompositeCollection() { new MultipliedByUnit(currentUnit, 1), new MultipliedByUnit(timeUnit, 1) })
 {
     // electric charge can be based on current and time, so public.
 }
コード例 #24
0
 protected static string CreateSuffix(SymbolFormat format, CurrentUnit unit)
 {
     return default(Current).ToString(unit, format).Trim('0');
 }