public void RunAction(IGameAction action) { if (_currentAction != null) { return; } //Пропуск хода if (action == null) { EndAction(null); return; } if (action.Check()) { OnActionStart?.Invoke(action); _currentAction = action; action.status = actionStatuses.start; StartCoroutine(action.Execute()); } else { Debug.LogFormat("Действие {0} не прошло проверку", action.GetType()); } }
public void TakeAction(IGameAction action) { if (!action.CanExecute(this)) { return; } action.Execute(this); }
private static void PerformTurn(GameEntity entity, IGameAction gameAction) { float newEnergy = entity.energy.Energy - gameAction.EnergyCost; gameAction.Entity.ReplaceEnergy(entity.energy.EnergyGainPerSegment, newEnergy); try { IEnumerable <IActionEffect> effects = gameAction.Execute(); foreach (IActionEffect effect in effects) { effect.Process(); } } catch (Exception e) { Debug.LogError(e.Message + ", stack trace: " + e.StackTrace); } }
private static void PerformTurn(GameEntity entity, IGameAction gameAction) { float newEnergy = entity.energy.Energy - gameAction.EnergyCost; gameAction.Entity.ReplaceEnergy(entity.energy.EnergyGainPerSegment, newEnergy); try { IEnumerable <IActionEffect> effects = gameAction.Execute(); foreach (IActionEffect effect in effects) { effect.Process(); } } catch (Exception e) { string entityDescription = (entity.hasView ? entity.view.Controller.Name : "(without view)") + (entity.hasPosition ? entity.position.Position.ToString() : ""); Debug.LogError(e.Message + ", entity: " + entityDescription + ", stack trace: " + e.StackTrace); } }
public void Execute(IGameAction action) { action.Execute(_gameState, ActionEventHandler); }
public void Update() { if (Input.GetKeyUp(KeyCode.LeftAlt)) { _environmentPresenter.StopShowingCharacterDetails(); } if (Input.GetKeyUp(KeyCode.LeftControl)) { _environmentPresenter.StopShowingStealthDetails(); } bool noKeyIsPressed = !Input.anyKey && !Input.anyKeyDown; //osnowatodo && _contextManager.Current.SimulatedKeyDown == KeyCode.None; if (noKeyIsPressed) { _inputWithRepeating.ResetTime(); return; } bool onlyModifierIsBeingHeld = !Input.GetKeyDown(KeyCode.LeftAlt) && Input.GetKey(KeyCode.LeftAlt) || (!Input.GetKeyDown(KeyCode.LeftControl) && Input.GetKey(KeyCode.LeftControl)); if (onlyModifierIsBeingHeld) { _inputWithRepeating.ResetTime(); } Ability chosenAbility = ResolveAbility(_keysToAbilities); if (chosenAbility != null) { _sceneContext.CameraMouseControl.StopFollowingPlayer(); // _uiFacade.ShowEntityDetails(null); powoduje to chamskie znikanie detali co krok IGameAction immediateAction = null; GameEntity playerEntity = Contexts.sharedInstance.game.GetPlayerEntity(); if (false) { } // todo clean this up /*else if (chosenAbility == _gameConfig.Abilities.Custom1) * { * immediateAction = _playerActionResolver.CreateTakeFromInventoryActionIfPossible(playerEntity, 0); * } * else * if (chosenAbility == _gameConfig.Abilities.Custom2) * { * immediateAction = _playerActionResolver.CreateTakeFromInventoryActionIfPossible(playerEntity, 1); * } * else * if (chosenAbility == _gameConfig.Abilities.Custom3) * { * immediateAction = _playerActionResolver.CreateTakeFromInventoryActionIfPossible(playerEntity, 2); * } * else * if (chosenAbility == _gameConfig.Abilities.Custom4) * { * immediateAction = _playerActionResolver.CreateTakeFromInventoryActionIfPossible(playerEntity, 3); * } * else * if (chosenAbility == _gameConfig.Abilities.Custom5) * { * immediateAction = _playerActionResolver.CreateTakeFromInventoryActionIfPossible(playerEntity, 4); * } * else * if (chosenAbility == _gameConfig.Abilities.Custom6) * { * immediateAction = _playerActionResolver.CreateTakeFromInventoryActionIfPossible(playerEntity, 5); * } * else * if (chosenAbility == _gameConfig.Abilities.Custom7) * { * immediateAction = _playerActionResolver.CreateTakeFromInventoryActionIfPossible(playerEntity, 6); * } * else * if (chosenAbility == _gameConfig.Abilities.Custom8) * { * immediateAction = _playerActionResolver.CreateTakeFromInventoryActionIfPossible(playerEntity, 7); * } * else * if (chosenAbility == _gameConfig.Abilities.Custom9) * { * immediateAction = _playerActionResolver.CreateTakeFromInventoryActionIfPossible(playerEntity, 8); * } * else * if (chosenAbility == _gameConfig.Abilities.PickUp) * { * immediateAction = _playerActionResolver.CreateTakeToInventoryActionIfPossible(playerEntity); * }*/ if (immediateAction != null) { foreach (IActionEffect actionEffect in immediateAction.Execute()) { actionEffect.Process(); } _context.ReplacePlayerDecision(Decision.None, Position.Zero, Position.MinValue); /* osnowatodo * if (_contextManager.Current.SimulatedKeyDown != KeyCode.None) * { * Ability[] clickableAbilities = new[] * { * _gameConfig.Abilities.Custom1, _gameConfig.Abilities.Custom2, _gameConfig.Abilities.Custom3, * _gameConfig.Abilities.Custom4, _gameConfig.Abilities.Custom5, _gameConfig.Abilities.Custom6, * _gameConfig.Abilities.Custom7, _gameConfig.Abilities.Custom8, _gameConfig.Abilities.Custom9, * }; * * if (clickableAbilities.Contains(chosenAbility)) * { * immediateAction = _playerActionResolver.CreateDropActionIfPossible(playerEntity); * if (immediateAction != null) * { * foreach (IActionEffect actionEffect in immediateAction.Execute()) * { * actionEffect.Process(); * } * _resolveAbilitiesPerTurnSystem.ExecuteQuinta(playerEntity); * _playerInventoryChangedSystem.ExecuteQuinta(playerEntity); * } * } * }*/ return; } _context.ReplacePlayerDecision(chosenAbility.Decision, Position.Zero, Position.MinValue); if (chosenAbility.RequiresDirection) { if (chosenAbility.name == "Spill") { if (!_context.GetPlayerEntity().hasEntityHolder || _context.GetPlayerEntity().entityHolder.EntityHeld == Guid.Empty) { return; // quinta don't show aim when nothing in hands } } _uiFacade.SelectAbility(chosenAbility); _directionInputReader.gameObject.SetActive(true); gameObject.SetActive(false); } } }
public static bool IsValid(this IGameAction gameAction) { return(gameAction.Execute(dryRun: true).Status != ActionStatus.Failed); }