public void Execute(CombatResolver src, CombatResolver dest) { CheckExecute (); foreach (ICombatLogic result in m_CompositeResult) { result.Execute(src, dest); } }
public void TestAttacksAllOtherArmies() { var manager = new ArmyManager(); var attacking = new Player(manager, new Color(0, 0, 0)); attacking.AddArmy(new Army(HEALTH), new Pos(0, 0)); var defending = new Player(manager, new Color(1, 1, 1)); defending.AddArmy(new Army(HEALTH), new Pos(1, 1)); defending.AddArmy(new Army(HEALTH), new Pos(2, 2)); var defending2 = new Player(manager, new Color(2, 2, 2)); defending2.AddArmy(new Army(HEALTH), new Pos(1, 3)); var players = new List <Player>(); players.Add(attacking); players.Add(defending); players.Add(defending2); var combat = new CombatResolver(manager, 0); combat.Engage(attacking, players); Assert.AreEqual(1, attacking.ArmyList.Count); Assert.AreEqual(2, defending.ArmyList.Count); // NOTE: The maximum damage inflicted < defender's health, so it should always survive. Assert.AreEqual(1, defending2.ArmyList.Count); Assert.AreEqual(HEALTH, attacking.ArmyList[0].Health); Assert.IsTrue(defending.ArmyList[0].Health < HEALTH); // Not strictly true, but true for this random seed. Assert.IsTrue(defending.ArmyList[1].Health < HEALTH); Assert.IsTrue(defending2.ArmyList[0].Health < HEALTH); }
/// <summary> /// Crit damage, can scale from 0 to 1x damage depending on crit defense /// </summary> /// <param name="src"></param> /// <param name="dest"></param> /// <returns></returns> public static float CalculateCritDamageScale(CombatResolver src, CombatResolver dest) { float critPower = src.CombatStats.critPower; float critDefense = dest.CombatStats.critDefense; float value = (critPower - critDefense) / critPower; return Math.Max(0, value); }
public void Execute(CombatResolver src, CombatResolver dest) { CheckExecute (); m_Accuracy = src.CombatStats.critAccuracy; m_Evasion = dest.CombatStats.critDefense; m_ChanceToHit = m_Accuracy / Math.Max(m_Accuracy + m_Evasion, 1); m_RandomValue = UnityEngine.Random.Range(0f, 1f); Logger.d (this, this); }
// Called to create a new enemy party and reset player party. public void OnNewEnemies() { FullHealPlayerParty(); // TODO: create different parties. CreateDefaultEnemyParty(); Resolver = new CombatResolver(PlayerParty, EnemyParty); }
public Game() { GameWorld = new World("maps.csv"); Manager = new ArmyManager(); scorer = new Scorer(); combat = new CombatResolver(Manager); Players = new List <Player>(); CurrentPlayerIndex = 0; }
public void GetTargets(CombatResolver resolver, CombatUnit user, List <CombatUnit> targets) { CombatPartyType targetedParty = TargetAlly ? user.CombatParty : user.OpponentParty; CombatUnit targetedUnit = resolver.GetCombatUnit(targetedParty, Position); if (targetedUnit != null) { targets.Add(targetedUnit); } }
public void GenerateEvents(CombatResolver src, CombatResolver dest, Queue<IBattleEvent> combatEvents) { // forward to combat events m_CritResult.GenerateEvents (src, dest, combatEvents); combatEvents.Enqueue(new DamageEvent (src.entity, dest.entity, m_Damage, m_CritDamage, m_Defense)); if (m_HpBefore > 0 && m_HpAfter <= 0) { combatEvents.Enqueue(new DeathEvent(dest.entity)); } }
// Use this for initialization void Start() { UnitLibrary = GameLibrary.GetComponent <UnitLibrary>(); SkillLibrary = GameLibrary.GetComponent <SkillLibrary>(); PlayerPartyPanel = PlayerPartyPanelObj.GetComponent <PartyPanel>(); EnemyPartyPanel = EnemyPartyPanelObj.GetComponent <PartyPanel>(); CreateDefaultPlayerParty(); CreateDefaultEnemyParty(); Resolver = new CombatResolver(PlayerParty, EnemyParty); }
public CombatSkillExecuter(CombatResolver resolver, CombatUnit combatUnit) { IsStarted = false; IsComplete = false; CurrentStage = CombatEventType.Declare; Resolver = resolver; Owner = combatUnit; ExecutedSkill = Owner.Skill; IsInterrupted = false; Targets = new List <CombatUnit>(); }
/// <summary> /// Execute an operation and manage check resulting event with CombatStatusEffect Rules if any /// </summary> /// <param name="operation">Operation.</param> private void ExecuteAttackOperation(ICombatOperation operation, CombatResolver srcResolver, CombatResolver destResolver, StatusEffectRule [] effectRules) { // check to see if we were alive before executing the event BattleEntity destEntity = destResolver.entity; bool wasAlive = destEntity.currentHP > 0; // execute and apply damage IBattleEvent battleEvent = null; BattleEventType eventType = battleEvent.EventType; // notify resulting battle event BattleSystem.Instance.PostBattleEvent(battleEvent); // check to see if it was a damage event to see if we killed them if (eventType == BattleEventType.DAMAGE && wasAlive && destEntity.currentHP <= 0) { destEntity.character.curHP = 0; DeathEvent deathEvent = new DeathEvent(destEntity); BattleSystem.Instance.PostBattleEvent(deathEvent); } // lets see if we hit the target or not bool hitTarget = eventType == BattleEventType.DAMAGE || eventType == BattleEventType.NON_DAMAGE || eventType == BattleEventType.ITEM; bool missedTarget = eventType == BattleEventType.DODGE || eventType == BattleEventType.RESIST; // iterate through combnat effects to see what should apply foreach (StatusEffectRule combatStatusEffect in effectRules) { switch(combatStatusEffect.rule) { case StatusEffectRule.StatusEffectRuleHitPredicate.ON_HIT: if(hitTarget) { ApplyEffect(combatStatusEffect, srcResolver.entity); } break; case StatusEffectRule.StatusEffectRuleHitPredicate.ON_MISS: if(missedTarget) { ApplyEffect(combatStatusEffect, srcResolver.entity); } break; case StatusEffectRule.StatusEffectRuleHitPredicate.ALWAYS: default: ApplyEffect(combatStatusEffect, srcResolver.entity); break; } } }
public void TestTrivial() { var manager = new ArmyManager(); var player = new Player(manager, new Color(0, 0, 0)); var players = new List <Player>(); players.Add(player); var combat = new CombatResolver(manager); combat.Engage(player, players); // We mostly care that this test terminated without error and effectively became almost a no-op. For the sake of argument, we'll assert no new armies were created. Assert.AreEqual(0, player.ArmyList.Count); }
public CombatEvent(CombatSkillExecuter triggeringSkillExecutor, CombatEventType eventType, CombatUnit eventTarget) { CombatResolver resolver = triggeringSkillExecutor.Resolver; Executer = triggeringSkillExecutor; Skill = triggeringSkillExecutor.ExecutedSkill; User = triggeringSkillExecutor.Owner; Party = User.CombatParty; Phase = Skill.SkillDefinition.PerformedPhase; Event = eventType; Target = eventTarget; }
public void GetTargets(CombatResolver resolver, CombatUnit user, List <CombatUnit> targets) { CombatPartyType opponentParty = user.OpponentParty; foreach (PartyPosition position in SkillTargetOrder) { CombatUnit targetUnit = resolver.GetCombatUnit(opponentParty, position); if (targetUnit != null && !targetUnit.Unit.IsDead) { targets.Add(targetUnit); break; } } }
public void GetTargets(CombatResolver resolver, CombatUnit user, List <CombatUnit> targets) { CombatPartyType targetParty = TargetAllyParty ? user.CombatParty : user.OpponentParty; CombatUnit targetUnit = null; if (ByPercentage) { float percentage = 0.0f; // Go through each position in standard targeting order, such that if multiple units have the same percentage, // it prioritize the unit with standard targeting order. foreach (PartyPosition position in StandardSingleTargeting.SkillTargetOrder) { CombatUnit member = resolver.GetCombatUnit(targetParty, position); if (member != null && !member.Unit.IsDead) { float percentageLife = (float)member.Unit.Status.Life / (float)member.Unit.Status.MaxLife; if (targetUnit == null || percentageLife < percentage) { targetUnit = member; percentage = percentageLife; } } } } else { int life = 0; // Same prioritization as the percentage case. foreach (PartyPosition position in StandardSingleTargeting.SkillTargetOrder) { CombatUnit member = resolver.GetCombatUnit(targetParty, position); if (member != null && !member.Unit.IsDead) { if (targetUnit == null || member.Unit.Status.Life < life) { targetUnit = member; life = member.Unit.Status.Life; } } } } if (targetUnit != null) { targets.Add(targetUnit); } }
public CombatUnit(CombatResolver resolver, CombatPartyType partyType, PartyPosition position) { Resolver = resolver; CombatParty = partyType; Position = position; Party partyRef = Resolver.GetPartyReference(partyType); Unit = partyRef.GetAssignedUnit(position); Skill = partyRef.GetAssignedSkill(position); CombatStatus = new CombatUnitStatus(); CombatStatus.Reset(); CurrentSkillExecuter = null; }
public void Execute(CombatResolver src, CombatResolver dest) { CheckExecute (); // pull out min and max damage and calculated 'rolled damage' ElementVector min = src.DamageMin; ElementVector max = src.DamageMax; float rand = UnityEngine.Random.Range(0f, 1f); ElementVector diff = max - min; ElementVector randomDmg = min + (diff * rand); // scale damage by vector, this could have been done earlier, same results AttributeVector attributes = src.Attributes; AttributeVector damageAttributeScalar = src.DamageAttributeScalar; AttributeVector resultDamageExtra = attributes * damageAttributeScalar; float scaleDamage = resultDamageExtra.Sum; // scale damage should be < 1 normally, so we want to ensure this is positive on scaling m_Damage = randomDmg * (1 + scaleDamage); // scale on dmg bonus m_Damage += src.ElementAttackRaw; m_Damage *= src.ElementAttackScalar; // if is critical m_CritDamage = new ElementVector(); m_CritResult = new CritChanceLogic (); m_CritResult.Execute (src, dest); if (m_CritResult.Hits) { float critScale = CombatUtil.CalculateCritDamageScale(src, dest); m_CritDamage = (m_Damage * critScale); } m_HpBefore = dest.entity.currentHP; m_Defense = dest.ElementDefense; // apply dmg m_TotalDamage = CombatUtil.CalculateDamage (m_Damage, m_CritDamage, m_Defense); dest.entity.currentHP -= m_TotalDamage; m_HpAfter = dest.entity.currentHP; Logger.d (this, this); }
public void TestDoesNotAttackOwnArmies() { var manager = new ArmyManager(); var player = new Player(manager, new Color(0, 0, 0)); player.AddArmy(new Army(HEALTH), new Pos(0, 0)); player.AddArmy(new Army(HEALTH), new Pos(1, 1)); var players = new List <Player>(); players.Add(player); players.Add(new Player(manager, new Color(1, 1, 1))); var combat = new CombatResolver(manager, 0); combat.Engage(player, players); Assert.AreEqual(2, player.ArmyList.Count); Assert.AreEqual(HEALTH, player.ArmyList[0].Health); Assert.AreEqual(HEALTH, player.ArmyList[1].Health); }
public void TestArmiesDie() { var manager = new ArmyManager(); var attacking = new Player(manager, new Color(0, 0, 0)); attacking.AddArmy(new Army(HEALTH), new Pos(0, 0)); var defending = new Player(manager, new Color(1, 1, 1)); defending.AddArmy(new Army(0), new Pos(1, 1)); var players = new List <Player>(); players.Add(attacking); players.Add(defending); var combat = new CombatResolver(manager, 0); combat.Engage(attacking, players); Assert.AreEqual(1, attacking.ArmyList.Count); Assert.AreEqual(0, defending.ArmyList.Count); Assert.AreEqual(HEALTH, attacking.ArmyList[0].Health); }
public void GenerateEvents(CombatResolver src, CombatResolver dest, Queue<IBattleEvent> combatEvents) { foreach (ICombatLogic result in m_CompositeResult) { result.GenerateEvents(src, dest, combatEvents); } }
public void OnClick(ClickMessage sourceEvent) { if (!GameCamera.Instance.ScreenViewport.Bounds.Contains(sourceEvent.MousePosition.ToPoint())) { return; } switch(GameplayProgress.Instance.Scenario.Stage) { case ScenarioStageEnum.HERO_SETUP: PickHeroesPlace(); break; case ScenarioStageEnum.OVERLORD_SETUP: PickMonstersPlace(); break; case ScenarioStageEnum.HERO_TURN: var character = GameplayProgress.Instance.ActCharacter; var focusedField = GameplayProgress.Instance.Scenario.GetFocusedField(); if (character != null && focusedField != null) { var movement = character.GetFieldsForMovement(); foreach (var field in movement) { if (field == focusedField && character.ActualAction is MoveAction) { GameplayProgress.Instance.Scenario.ClearMarkedFields(); character.MoveToField(field); } } if (character.ActualAction is AttackAction) { var enemy = focusedField.GetCharacterOnSelf(); if (enemy != null && character.IsEnemy(enemy) && ((Hero)character).CanAttackOn(enemy)) { var resolver = new CombatResolver(character, enemy); resolver.DoAttack(); combatDialog = new Dialog(400, 200, "Combat result"); var a = 0; foreach (var dice in resolver.Attack.AttackDices) { combatDialog.AddRendable(a, new ScaledImage(new Vector2(10 + a * 40, 10), dice.GetResultImage())); a++; } var b = 0; foreach (var dice in resolver.Defense.DefenseDices) { combatDialog.AddRendable(a + b, new ScaledImage(new Vector2(10 + b * 40, 50), dice.GetResultImage())); b++; } GameButton button = new TextGameButton(new Vector2(80, 30), new Vector2(10, 120), "Close"); button.RegisterOnClick(DialogCloseAction); combatDialog.AddRendable(a + b + 1, button); combatDialog.Show(); OnUnfocus(); } } } break; } }
public CombatOperation Build(CombatResolver src, CombatResolver dest) { Configuration config = ResolveConfiguration (); config.src = src; config.dest = dest; return new CombatOperation(config); }
public void GenerateEvents(CombatResolver src, CombatResolver dest, Queue<IBattleEvent> combatEvents) { if (!Hits) { combatEvents.Enqueue(new DodgeEvent(src.entity, dest.entity)); } }
public CombatEventDispatcher(CombatResolver resolver) { Resolver = resolver; }
internal void TryExecute(CombatResolver src, CombatResolver dest, CompositeLogic resultLogic) { if (conditionBlob.ShouldExecute ()) { logic.Execute(src, dest); resultLogic.Add(logic); } }
public void GenerateEvents(CombatResolver src, CombatResolver dest, Queue<IBattleEvent> combatEvents) { }
public CombatOperation Build(CombatResolver src, CombatResolver dest) { return builder.Build (src, dest); }