private void Attacked(IBattleEntity arg1, IBattleEntity arg2, BattleActionResult arg3) { var evt = CreateEvent <BattleEventLog>(); evt.results = arg3; AddEvent(evt); }
public void ApplyBattleResults(BattleActionResult results, BattleRole role) { if (role == BattleRole.Defender) { TakeDamage(results.DefenderDmgTaken); } else { Debug.Log($"{name} attacked {results.DefenderName} and caused {results.AttackerDmgInflicted} dmg"); } }
public BattleActionResult resolveAction(BattleActionContext battleActionContext, MoveContext moveContext) { BattleActionContext alteredAction = watcher.getAlteredBattleAction(battleActionContext, moveContext); BattleActionResult result = BattleActionResult.NO_CHANGES; if (alteredAction.canExecute()) { result = battleActionContext.execute(); } return(result); }
public static void SolveAttack(IBattleEntity attacker, IBattleEntity defender, out BattleActionResult results) { results = new BattleActionResult(); results.AttackerName = attacker.Name; results.DefenderName = defender.Name; results.DefenderStartHP = defender.HPTrait.HP; // 1. Solve chance to hit float attackerHitChance = 1.0f; if (URandom.value > attackerHitChance) { results.AttackerFlopped = true; return; } // 2. Solve defender's deflection float defenderAvoidChance = 0.0f; if (URandom.value <= defenderAvoidChance) { results.DefenderAvoided = true; return; } // 3. Crit check? float attackCriticalBonus = 0.0f; float attackerCritChance = 0.0f; if (URandom.value <= attackerCritChance) { attackCriticalBonus = 0.0f; results.Critical = true; } // 4. Attack float attack = attacker.BattleTrait.Damage; attack *= (1 + attackCriticalBonus); float defense = 0.0f; int damageInflicted = (int)((attack * attack) / (attack + defense)); results.AttackerDmgInflicted = damageInflicted; results.DefenderDmgTaken = Mathf.Min(damageInflicted, defender.HPTrait.HP); results.DefenderDefeated = damageInflicted >= defender.HPTrait.HP; attacker.ApplyBattleResults(results, BattleRole.Attacker); defender.ApplyBattleResults(results, BattleRole.Defender); }
public BattleActionResult resolveAction(BattleActionContext battleActionContext) { BattleActionContext alteredAction = watcher.getAlteredBattleAction(battleActionContext); BattleActionResult result = null; if (alteredAction.canExecute()) { result = battleActionContext.execute(); } uiManager.updateAllUI(); return(result); }
public void AddPostActionEffect(BattleActionResult actionResult, BattleCharacter target) { foreach (var specialStateEffect in target.SpecialStateModifiers) { var totalHpChangeOnTarget = actionResult.GetTotalHpChangeOnTarget(target); var isTargetAlive = (target.CurrentHp + totalHpChangeOnTarget) > 0; switch (specialStateEffect.Key) { case StatusEffect.Type.Poison: if (isTargetAlive) { actionResult.AddPostActionEffectResult(this.GetPoisonEffect(target, specialStateEffect.Value.StatModifier.Magnitude)); } break; default: break; } } }
public virtual IEnumerator PlaySkillSequence(BattleUnitController actor, BattleView battleView, BattleActionResult actionResult) { Vector3 targetPosition = new Vector3(); BattleUnitController targetedUnit = null; TileController targetedTile = null; if (actionResult.targetCharacter != null) { targetedUnit = battleView.GetBattleUnit(actionResult.targetCharacter); targetPosition = targetedUnit.transform.position; } else { targetedTile = battleView.GetTileAtMapPosition(actionResult.targetPosition); targetPosition = targetedTile.transform.position; } var actorOrigPosition = actor.transform.position; yield return StartCoroutine(actor.MoveToAttackPosition(targetedUnit, targetPosition)); StartCoroutine(actor.AnimateAttack()); for (int i = 0; i < actionResult.allSkillEffectResult.Count; ++i) { var delay = this.GetDelayedKeyFrames(i); yield return StartCoroutine(this.WaitForFrames(delay)); var skillEffectResult = actionResult.allSkillEffectResult[i]; yield return this.PlayEffects(skillEffectResult.effectsOnTarget, battleView); } yield return StartCoroutine(actor.ReturnToPosition(actorOrigPosition)); Destroy(this.gameObject); }
public void ApplyBattleResults(BattleActionResult result, BattleRole role) { throw new NotImplementedException(); }
private IEnumerator ProcessMovementActionResult(BattleActionResult actionResult) { var movementEffect = actionResult.allSkillEffectResult[0].effectsOnTarget[0]; var actor = movementEffect.target; var newPosition = movementEffect.positionChangeTo; var occupiedPositions = this._battleModel.GetMapPositionsForPattern(actor.BaseCharacter.PatternShape, Const.SkillTargetGroup.Ally, actor.Team, newPosition); yield return StartCoroutine(this._battleView.MoveUnitToMapPosition(actor, occupiedPositions)); }
private void ShowEffectText(BattleActionResult.EffectOnTarget effectOnTarget) { var delay = 0f; if (effectOnTarget.hasDamageEffect) { var damageText = this.CreateDamageText(); var damageResultText = ""; var isNegativeEffect = true; if (effectOnTarget.isSuccess) { var damage = effectOnTarget.hpChange; if (damage > 0) { isNegativeEffect = false; } damageResultText = damage.ToString("F0"); } else { damageResultText = Const.MissedText; } damageText.ShowText(damageResultText, isNegativeEffect, effectOnTarget.isCritical, delay); delay += 0.5f; } if (effectOnTarget.HasStatusEffectResult) { var resultType = effectOnTarget.statusEffectResult.resultType; var statusEffectResultText = ""; switch (resultType) { case BattleActionResult.StatusEffectResultType.Resisted: statusEffectResultText = Const.ResistedText; break; case BattleActionResult.StatusEffectResultType.Ineffetive: statusEffectResultText = Const.IneffectiveText; break; } if (!string.IsNullOrEmpty(statusEffectResultText)) { var statusEffectText = this.CreateDamageText(); statusEffectText.ShowText(statusEffectResultText, true, false, delay); } } }
private void ApplyMovementActionResult(BattleActionResult movementResult) { foreach (var effectResult in movementResult.allSkillEffectResult) { foreach (var effectOnTarget in effectResult.effectsOnTarget) { if (effectOnTarget.isSuccess) { var actor = effectOnTarget.target; var moveTo = effectOnTarget.positionChangeTo; Debug.LogWarning(actor.Name + " moves to " + moveTo.ToString()); var mapService = ServiceFactory.GetMapService(); var unOccupiedPositions = mapService.GetUnoccupiedTiles(this._battleCharacters, this._mapTiles); var newOccupiedPositions = mapService.RequestPositionsForCharacter(actor, this._mapTiles, moveTo, unOccupiedPositions); // update character position actor.OccupiedMapPositions = newOccupiedPositions; } } } }
private void ApplyActionResult(BattleActionResult result) { switch (result.type) { case Const.ActionType.Movement: this.ApplyMovementActionResult(result); break; case Const.ActionType.Skill: this.ApplySkillActionResult(result); break; default: break; } }
protected IEnumerator PlayEffectOnTarget(BattleUnitController unit, BattleActionResult.EffectOnTarget effectOnTarget) { unit.PlayEffect(effectOnTarget.effectPrefabPath); var hpPercentage = effectOnTarget.target.HpPercentage; yield return StartCoroutine(unit.TakeEffect(effectOnTarget, hpPercentage)); }
private IEnumerator ProcessPostActionResult(BattleActionResult actionResult) { var postActionResult = actionResult.PostActionEffectResult; if (postActionResult != null) { // TODO: different type var controller = SkillControllerFactory.CreatePostEffectController(StatusEffect.Type.Poison); yield return StartCoroutine(controller.PlayEffects(postActionResult.effectsOnTarget, this._battleView)); Destroy(controller.gameObject); } yield return null; }
private IEnumerator ProcessSkillActionResult(BattleActionResult actionResult) { var skillController = SkillControllerFactory.CreateSkillController(actionResult.skill); if (skillController != null) { var actor = actionResult.actor; var actorController = this._battleView.GetBattleUnit(actor); yield return StartCoroutine(skillController.PlaySkillSequence(actorController, this._battleView, actionResult)); } yield return this.ProcessPostActionResult(actionResult); }
public void SendAttack(IBattleEntity attacker, IBattleEntity defender, BattleActionResult result) { Attack?.Invoke(attacker, defender, result); }
private void ApplySkillActionResult(BattleActionResult skillActionResult) { var actor = skillActionResult.actor; var skill = skillActionResult.skill; Debug.LogWarning(actor.Name + " uses " + skill.Name); foreach (var effectResult in skillActionResult.allSkillEffectResult) { var affectedCharacters = this.ApplyActionEffectResult(effectResult); var effect = effectResult.effectsOnTarget.ElementAt(0).skillEffect; ServiceFactory.GetEnmityService().ApplyEnmityForSkillEffect(actor, effect, affectedCharacters, this._battleCharacters); } if (skillActionResult.PostActionEffectResult != null) { this.ApplyActionEffectResult(skillActionResult.PostActionEffectResult); } ServiceFactory.GetTurnOrderService().ApplySkillCooldownToCharacter(actor, skill); }
private List<BattleCharacter> ApplyActionEffectResult(BattleActionResult.ActionEffectResult actionEffectResult) { var affectedCharacters = new List<BattleCharacter>(); foreach (var effectOnTarget in actionEffectResult.effectsOnTarget) { var target = effectOnTarget.target; if (effectOnTarget.isEmptyEffect) { affectedCharacters.Add(target); continue; } if (effectOnTarget.isSuccess) { var shouldCritical = effectOnTarget.isCritical; // Deduct Hp target.CurrentHp = Math.Min(target.MaxHp, Math.Max(0d, target.CurrentHp + effectOnTarget.hpChange)); Debug.LogWarning(string.Format("{0}{1} takes {2} damage", shouldCritical ? "Critical! " : "", target.Name, effectOnTarget.hpChange)); Debug.LogWarning(target.Name + " remaining hp " + target.CurrentHp); if (effectOnTarget.statusEffectResult != null) { foreach (var statusEffect in effectOnTarget.statusEffectResult.landedEffects) { target.ApplyStatusEffect(statusEffect); } } affectedCharacters.Add(target); } } return affectedCharacters; }
public IEnumerator TakeEffect(BattleActionResult.EffectOnTarget effectOnTarget, float hpPercentage) { this.ShowEffectText(effectOnTarget); this.characterView.IsDead = hpPercentage <= 0f; if (effectOnTarget.hpChange < 0) { this.characterView.CurrentAnimationState = BattleCharacterView.AnimationState.Damage; } yield return StartCoroutine(this.AnimateHpChange(hpPercentage)); }
private IEnumerator ProcessActionResult(BattleActionResult actionResult) { switch (actionResult.type) { case Const.ActionType.Movement: yield return StartCoroutine(this.ProcessMovementActionResult(actionResult)); break; case Const.ActionType.Skill: yield return StartCoroutine(this.ProcessSkillActionResult(actionResult)); break; default: yield return null; break; } }