public void Apply(CombatEventDispatcher resolver, CombatUnit user, CombatUnit target, CombatEventLog log) { int damage = BaseDamage + Mathf.FloorToInt(user.Unit.Status.CharacterLevel * CharacterScaling) + Mathf.FloorToInt(user.Unit.Status.ItemLevel * ItemScaling); if (DamageType == DamageType.Physical && target.CombatStatus.Armor > 0) { int mitigated = Math.Min(damage, target.CombatStatus.Armor); damage -= mitigated; if (log != null) { log.LogValues.Add("mitigated", mitigated.ToString()); } } if (damage > 0 && target.CombatStatus.Absorb > 0) { int absorbed = Math.Min(damage, target.CombatStatus.Absorb); damage -= absorbed; target.CombatStatus.Absorb -= absorbed; if (log != null) { log.LogValues.Add("absorbed", absorbed.ToString()); } } resolver.DealDamage(user.Unit, target.Unit, damage); if (log != null) { log.LogValues.Add("damage", damage.ToString()); } }
private void CreateChooseActionDialogue() { CombatUnit cu = player[choosingUnit]; string choices = cu.GetDialogueChoiceTitle(); dialogue.NewTalk(choices, choices + "E"); }
public HexUnit CreateMercenary(CombatUnitConfig combatUnitConfig, HexCell cell, Player player, int cityStateID = -1) { HexUnit hexUnit = Instantiate(combatUnitPrefab).GetComponent <HexUnit>(); CombatUnit combatUnit = hexUnit.GetComponent <CombatUnit>(); combatUnit.SetCombatUnitConfig(combatUnitConfig); hexUnit.UnitPrefabName = name; hexUnit.Grid = hexGrid; hexUnit.Location = cell; hexUnit.Orientation = Random.Range(0f, 360f); hexUnit.HexUnitType = HexUnit.UnitType.COMBAT; hexGrid.AddUnit(hexUnit); CityState cityState = cityStates.Find(c => c.CityStateID == cityStateID); if (cityState) { combatUnit.SetCityState(cityState); } if (player.IsHuman) { hexUnit.Controllable = true; } combatUnit.Mercenary = true; player.AddMercenary(combatUnit); return(hexUnit); }
public void AddUnitToCombat(CombatUnit u) { combatents.Add(u); switch (u.parent) { case PlayerUnit _: { playerHealth += u.health; StartCoroutine(UnitCombat(u.damageRate, u.damageChances, true)); break; } case EnemyUnit _: { enemyHealth += u.health; StartCoroutine(UnitCombat(u.damageRate, u.damageChances, false)); break; } default: { throw new System.NotImplementedException("Unit is not player or enemy???"); } } u.parent.EnterCombat(); this.transform.position = combatents.Select(c => c.transform.position).Aggregate((v1, v2) => v1 + v2) / combatents.Count; }
public static void NightSword(CombatUnit caster, Tile targetTile, CombatUnit targetUnit) { string action_id = System.Reflection.MethodBase.GetCurrentMethod().Name; Action action = Engine.CombatManager.ActionTable[action_id]; Timeline t = ActionPatterns.Start(action, true); ActionPatterns.UseWeapon(t, caster, targetTile); targetUnit = ActionPatterns.TargetUnit(targetTile); if (targetUnit) { bool critical = Action.GetCritical(); int damage = Action.Mod2(caster.PA, critical, Element.None, caster, targetUnit, action_id); targetUnit.TakeDamage(damage); t.gameObject.AddComponent <CameraFocus_TimelineEvent>().Init(t, 0, targetUnit.transform.position, .25f); t.gameObject.AddComponent <SpawnEffect_TimelineEvent>().Init(t, .0f, "NightSword", targetUnit.GetComponent <TileOccupier>().GetOccupiedTile()); t.gameObject.AddComponent <PlaySound_TimelineEvent>().Init(t, 2.60f, "clang"); t.gameObject.AddComponent <UnitAnimation_TimelineEvent>().Init(t, 2.75f, "Armature|Hurt", targetUnit.GetComponentInChildren <Animator>()); t.gameObject.AddComponent <FlyingText_TimelineEvent>().Init(t, 4.25f, damage.ToString(), targetUnit); t.gameObject.AddComponent <UnitAnimation_TimelineEvent>().Init(t, 4.25f, targetUnit.GetDefaultAnimation(), targetUnit.GetComponentInChildren <Animator>()); t.gameObject.AddComponent <UnitAnimation_TimelineEvent>().Init(t, 5.25f, targetUnit.GetDefaultAnimation(), targetUnit.GetComponentInChildren <Animator>()); t.gameObject.AddComponent <CameraFocus_TimelineEvent>().Init(t, 5.25f, caster.transform.position, .25f); t.gameObject.AddComponent <FlyingText_TimelineEvent>().Init(t, 5.75f, "+" + damage.ToString(), caster); t.Advance(5.75f); } t.gameObject.AddComponent <UnitAnimation_TimelineEvent>().Init(t, .25f, caster.GetDefaultAnimation(), caster.GetComponentInChildren <Animator>()); t.gameObject.AddComponent <DestroyTimeline_TimelineEvent>().Init(t, .25f); t.PlayFromStart(); }
private void Attack(SimulationState state, CombatUnit damagedUnit, CombatWeapon picked, CombatUnit unit) { if (!damagedUnit.IsGround) { return; } float dist = Target.DistSq(damagedUnit); if (dist >= 1.25f * 1.25f) { return; } if (dist >= 0.7812f * 0.7812f) { unit.Attack(state, picked, damagedUnit, false, 0.25f); return; } if (dist >= 0.4687f * 0.4687f) { unit.Attack(state, picked, damagedUnit, false, 0.5f); return; } unit.Attack(state, picked, damagedUnit, false, 1); }
public virtual void Perform(SimulationState state, CombatUnit unit) { if (Target == null) { return; } if (unit.FramesUntilNextAttack > 0) { return; } CombatWeapon picked = unit.GetWeapon(Target); if (picked == null) { return; } if (unit.DistSq(Target) > picked.Range * picked.Range) { return; } foreach (CombatUnit damagedUnit in state.Player1Units) { Attack(state, damagedUnit, picked, unit); } foreach (CombatUnit damagedUnit in state.Player2Units) { Attack(state, damagedUnit, picked, unit); } }
private void CheckKills() { List <string> deaths = new List <string>(); bool anyKills = false; for (int i = 0; i < player.Count; i++) { if (player[i].IsDead()) { anyKills = true; CombatUnit dead = player[i]; deaths.Add(dead.unitName); player.RemoveAt(i); i--; dead.HandleKill(); } } for (int i = 0; i < enemy.Count; i++) { if (enemy[i].IsDead()) { anyKills = true; CombatUnit dead = enemy[i]; deaths.Add(dead.unitName); enemy.RemoveAt(i); i--; dead.HandleKill(); } } //If any entities have died, generate a string saying so and display it. if (anyKills) { StringBuilder killString = new StringBuilder(); if (deaths.Count == 1) { ConfigureVariable("%target", deaths[0]); ACTION_STATE = ActionState.EXTRA_DIALOGUE; dialogue.callback.AddListener(DeathTextCallback); dialogue.NewTalk("EntityDie", "EntityDieE"); } else { killString.Append(deaths[0]); int i = 1; bool comma = false; while (i < deaths.Count - 1) { killString.Append(", "); killString.Append(deaths[i]); comma = true; } if (comma) { killString.Append(","); } killString.Append(" and "); killString.Append(deaths[deaths.Count - 1]); } } }
public void Activate() { Active = true; StartingTile = GetComponent <TileOccupier>().GetOccupiedTile(); Engine.MapCursor.X = GetComponent <TileOccupier>().X; Engine.MapCursor.Y = GetComponent <TileOccupier>().Y; Engine.MapCursor.GoToTile(); Engine.MapCursor.Show(); MovePoints = 1; ActPoints = 1; KO k = GetComponent <KO>(); if (k != null) { k.Counter--; } CombatUnit c = GetComponent <CombatUnit>(); if (!c.Guest && !c.Enemy) { Engine.CameraManager.SetTargetPosition(transform.position, .5f); } WaitState = WaitState.None; Engine.AssignControl(this); }
public Action Act(SimulationState state, CombatUnit unit) { CombatUnit target = null; if (TargetTag != 0) { target = state.GetUnit(TargetTag, 3 - unit.Owner); } if (target == null) { List <CombatUnit> enemies = unit.Owner == 2 ? state.Player1Units : state.Player2Units; float dist = 10000000000; foreach (CombatUnit enemy in enemies) { float newDist = unit.DistSq(enemy); if (newDist > dist) { continue; } if (unit.GetWeapon(enemy) == null) { continue; } target = enemy; TargetTag = enemy.Tag; dist = newDist; } } return(new Attack(target)); }
public static void Charge1(CombatUnit caster, Tile targetTile, CombatUnit targetUnit) { string action_id = System.Reflection.MethodBase.GetCurrentMethod().Name; Action action = Engine.CombatManager.ActionTable[action_id]; Timeline t = ActionPatterns.Start(action, true); ActionPatterns.UseWeapon(t, caster, targetTile); targetUnit = ActionPatterns.TargetUnit(targetTile); if (targetUnit) { bool critical = Action.GetCritical(); bool hitSuccess = Action.HitSuccess(caster, targetUnit, 100); int damage = Action.Mod2(caster.PA, critical, Element.None, caster, targetUnit, action_id); if (hitSuccess) { ActionPatterns.HitDamage(t, caster, targetUnit, damage); } else { ActionPatterns.HitAvoid(t, caster, targetUnit); } } t.gameObject.AddComponent <UnitAnimation_TimelineEvent>().Init(t, 1f, caster.GetDefaultAnimation(), caster.GetComponentInChildren <Animator>()); t.gameObject.AddComponent <DestroyTimeline_TimelineEvent>().Init(t, .25f); t.PlayFromStart(); }
private IEnumerator Attack() { while (true) { CleanNullInEnemyList(); if (m_enemyInRange.Count == 0) { RpcDisableLineRenderer(); break; } if (m_stockUnits.transform.childCount == 0 || m_enemiesUnits.transform.childCount > 0) { m_soundEmitter.StopSound(); RpcDisableLineRenderer(); yield return(null); continue; } CombatUnit combatUnitEnnemy = m_enemyInRange[0]; if (combatUnitEnnemy.GetCurrentHealth() > 0) { RpcEnableLineRenderer(m_enemyInRange[0].transform.position); if (Time.time > m_nextAttack && m_attackSpeed[m_stockUnits.transform.childCount] > 0) { m_nextAttack = Time.time + m_attackSpeed[m_stockUnits.transform.childCount]; combatUnitEnnemy.TakeDamage(m_attackDamage, GetPlayerOwner()); } } yield return(null); } m_crRunning = false; }
public float Process(SimulationState state, CombatUnit unit, float damage) { if (damage <= 0) { return(damage); } if (state.SimulationFrame <= BarrierExpireFrame && RemainingDamage > 0) { RemainingDamage -= damage; if (RemainingDamage <= 0) { BarrierExpireFrame = -1; return(-RemainingDamage); } return(0); } if (state.SimulationFrame >= NextActivationFrame) { BarrierExpireFrame = state.SimulationFrame + 48; RemainingDamage = 100; NextActivationFrame = state.SimulationFrame + 720; } return(damage); }
public void SetUp() { m_combatUnitPrefab = Resources.Load <GameObject>("Prefabs/UnitPrefabs/Scout"); m_mapGridPrefab = Resources.Load <GameObject>("Prefabs/MapGrid"); m_mapGridObject = GameObject.Instantiate(m_mapGridPrefab, Vector2.zero, Quaternion.identity); m_mapGrid = m_mapGridObject.GetComponent <MapGrid>(); m_mapGrid.SetSize(10, 15); m_mapGrid.CreateMap(); for (int x = 1; x < 8; x++) { for (int y = 1; y < 13; y++) { m_mapGrid.m_grid[x][y].SetTileType(TileType.Land); } } m_playerPrefab = Resources.Load <GameObject>("Prefabs/Player"); m_playerObject = GameObject.Instantiate(m_playerPrefab); m_player = m_playerObject.GetComponent <Player>(); m_player.Initialize(0, Color.red, m_mapGrid); m_player.SetResourceAmount("Gold", 10000); m_player.TurnStart(); m_player.AddUnitToPlayer(m_combatUnitPrefab, new MapIndex(1, 1)); m_combatUnit = m_player.GetUnits()[0].GetComponent <CombatUnit>(); }
public Charge(CombatUnit target, int expireFrame) { ExpireFrame = expireFrame; SpeedMultiplier = 2.2f; Stun = true; Target = target; }
private void endTurn() { CombatUnit c = GetComponent <CombatUnit>(); int ctExpended = 0; if (ActPoints == 0 && MovePoints == 0) { ctExpended = 100; } else if (ActPoints > 0) { ctExpended = 80; } else if (MovePoints > 0) { ctExpended = 80; } c.CT -= ctExpended; if (c.CT > 60) { c.CT = 60; } Destroy(this); Engine.AssignControl(null); Engine.CombatManager.Unpause(); Menu.DestroyAllMenus(); }
public IEnumerable <BattleEffect> Affect(CombatUnit self, CombatUnit target) { var damageType = Helper.Test(self.CriticalChance, target.BlockChance, 0); var ratio = Value * self.Charge / 100f; return(self.DoAttack(target, AttackType.Tactic, damageType, ratio)); }
public static void Load(BinaryReader reader, GameController gameController, HexGrid hexGrid, int header) { int cityStateID = reader.ReadInt32(); Color color = new Color(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), 1.0f); CityState instance = gameController.CreateCityState(color); instance.CityStateID = cityStateID; if (header >= 2) { int playerNumber = reader.ReadInt32(); if (playerNumber != -1) { instance.Player = gameController.GetPlayer(playerNumber); } } int unitCount = reader.ReadInt32(); for (int i = 0; i < unitCount; i++) { CombatUnit combatUnit = CombatUnit.Load(reader, gameController, hexGrid, header, instance.CityStateID); } if (header >= 3) { int exploredCellCount = reader.ReadInt32(); for (int i = 0; i < exploredCellCount; i++) { HexCell cell = hexGrid.GetCell(reader.ReadInt32()); if (!instance.exploredCells.Contains(cell)) { instance.exploredCells.Add(cell); } } } }
bool CheckDuplicateFearUnitType(int unitIndex) { CombatUnit unit = _target.combatUnitInfo [unitIndex]; for (int i = 0; i < unit.fearUnit.Count; i++) { CombatUnitType compareType = unit.fearUnit[i]; int duplicateTime = 0; for (int j = 0; j < unit.fearUnit.Count; j++) { if (compareType == unit.fearUnit[j]) { ++duplicateTime; } } if (duplicateTime > 1) { return(true); } } return(false); }
public CombatAction(CombatUnit user, int speed, CombatManager mngr) { this.user = user; this.speed = speed; actionDone = false; manager = mngr; }
void HandleUnitDead(CombatUnit unit) { if (unit is Warrior) { m_WarriorDeadCount++; if (m_WarriorDeadCount == m_BattleUnitManagerPVE.WarriorList.Count) { BattleFinishPanel.Success = false; StartCoroutine(ShowBattleFinishPanel()); //m_BattleResult = false; //nstance.Run = false; } } else if (unit is AttackNpc) { m_AttackNpcDeadCount++; if (m_AttackNpcDeadCount == m_BattleUnitManagerPVE.AttackNpcDic.Count) { BattleFinishPanel.Success = true; StartCoroutine(ShowBattleFinishPanel()); //m_BattleResult = true; //Instance.Run = false; return; } } }
/// <summary> /// Use this method for Trigger event handlers. /// </summary> /// <param name="thisCollider"></param> /// <param name="other"></param> public void OnTrigger(Collider2D thisCollider, Collider2D other) { if (!reactionEnabled || other.gameObject.layer != LayerMask.NameToLayer("Player")) { return; } CombatUnit combatUnit = other.GetComponent <CombatUnit>(); if (combatUnit != null && !combatUnit.IsDead) { combatUnit.TakeDamage(attackDamage); if (pushOnNormal) { ContactPoint2D[] contactPoints = new ContactPoint2D[1]; if (other.GetContacts(contactPoints) > 0) { other.attachedRigidbody.AddForce(contactPoints[0].normal.normalized * pushForce * -1.0f); } } else { Vector2 forceDirection = other.attachedRigidbody.position - thisCollider.attachedRigidbody.position; other.attachedRigidbody.AddForce(forceDirection.normalized * pushForce); } } }
/// <summary> /// Gets the available unit to produce for type. /// How many unit can produce for type. /// This is base on how much resource and available unit space /// </summary> public int GetAvaliableUnitToProduceForType(CombatUnitType type) { CombatUnit unit = GetCombatUnitInfoByType(type); Dictionary <ResourceType, float> costResource = unit.GetResourceCost; if (costResource != null) { int unitMinProduction = availableUnitToProduce; foreach (ResourceType rType in costResource.Keys) { ResourceStorage rs = Player.Instance.GetResourceStorage(rType); unitMinProduction = Mathf.Min(Mathf.FloorToInt(rs.currentResource / costResource[rType]), unitMinProduction); } return(unitMinProduction); } else { Debug.LogError("Combat unit type " + type.ToString() + " has no resource cost setup"); return(0); } }
public static int Mod5(Element element, int spellPower, CombatUnit caster, CombatUnit target) { int damage = 0; float frac = 1; int xa = caster.MA; // Caster Elemental Strengthen // Caster Magic Up // Target Magic Defend Up // Target Shell // Caster+Target Zodiac xa = ZodiacCompatibility.Modify(xa, caster, target); // Caster/Target Faith status // Weather Elemental effect // Target Elemental Weakness // Target Elemental Half // Target Elemental Absorb damage = (int)(caster.Faith * target.Faith * spellPower * xa * frac / 10000f); return(damage); }
//check if there is duplicate resource type in CombatUnit bool CheckDuplicateResourceCostType(int unitIndex) { CombatUnit unit = _target.combatUnitInfo [unitIndex]; for (int i = 0; i < unit.costResourceTypes.Count; i++) { ResourceType comparedType = unit.costResourceTypes[i]; int duplicateTime = 0; for (int j = 0; j < unit.costResourceTypes.Count; j++) { if (comparedType == unit.costResourceTypes[j]) { ++duplicateTime; } } if (duplicateTime > 1) { return(true); } } return(false); }
public IEnumerator UpdateUnit(CombatUnit unit) { HexCell nextMove = null; if (unit.CurrentStance == CombatUnit.Stance.UNASSIGNED) { AssignStance(unit); } nextMove = GetNextMove(unit); if (!nextMove) { nextMove = unit.Behaviour.Patrol(cityState.GetCity().GetHexCell(), 2); } if (!nextMove || nextMove == unit.HexUnit.Location) { unit.EndTurn(); } else { unit.SetPath(nextMove); while (unit.AttackUnit && unit.HexUnit.pathToTravel != null && unit.HexUnit.pathToTravel.Count != 0) { yield return(new WaitForFixedUpdate()); } } }
private HexCell GetNextMove(CombatUnit unit) { HexCell nextMove = unit.HexUnit.Location; switch (unit.CurrentStance) { case CombatUnit.Stance.DEFENCE: nextMove = DefendCity(unit); break; case CombatUnit.Stance.OFFENCE: nextMove = DetermineTarget(unit); break; case CombatUnit.Stance.EXPLORE: nextMove = unit.Behaviour.ExploreArea(unit.HexUnit.Location, cityState.GetCity().GetHexCell(), 6, cityState.GetExploredCells()); if (!nextMove) { areaLeftToExplore = false; unit.CurrentStance = CombatUnit.Stance.UNASSIGNED; AssignStance(unit); nextMove = GetNextMove(unit); } break; } return(nextMove); }
private void ResolveExecuteEvent(CombatSkillExecuter executer) { Skill userSkill = executer.ExecutedSkill; // Execute effects on all targets. if (userSkill != null && userSkill.SkillDefinition.Effect != null) { CombatEventDispatcher dispatcher = new CombatEventDispatcher(this); CombatUnit userUnit = executer.Owner; foreach (CombatUnit target in executer.Targets) { CombatEventLog log = new CombatEventLog(userSkill); log.LogValues.Add("user", userUnit.Unit.Profile.Name); log.LogValues.Add("target", target.Unit.Profile.Name); log.LogValues.Add("skillname", userSkill.SkillDefinition.DisplayedName); userSkill.SkillDefinition.Effect.Apply(dispatcher, userUnit, target, log); _CombatEventLog.Add(log); } // Trigger execute event after skill usage. CombatEvent executeEvent = new CombatEvent(executer, CombatEventType.Apply, userUnit); HandleCombatEvent(executeEvent); } }
public virtual void Perform(SimulationState state, CombatUnit unit) { if (Target == null) { return; } if (unit.FramesUntilNextAttack > 0) { return; } if (unit.AdditionalAttacksRemaining > 0 && unit.PreviousAttackTarget.Tag != Target.Tag) { unit.AdditionalAttacksRemaining = 0; } CombatWeapon picked = unit.GetWeapon(Target); if (picked == null) { return; } if (unit.DistSq(Target) > picked.Range * picked.Range) { unit.Move(Target.Pos); return; } unit.Attack(state, picked, Target, false); }
/// <summary> /// Implements the GUI displayed in the inspector, so that items can be entered by value. /// </summary> public override void OnInspectorGUI() { GUILayout.BeginHorizontal(); { GUILayout.Label("Unit Count:"); GUILayout.FlexibleSpace(); EditorGUILayout.SelectableLabel(Target.Units.Count.ToString(), GUILayout.Width(50)); } GUILayout.EndHorizontal(); for (int _i = 0; _i < Target.Units.Count; _i++) { GUILayout.BeginHorizontal(); { string foldoutName = string.Format("{0} ({1}, {2})", Target.Units[_i].Unit.Name, Target.Units[_i].Position.Row, Target.Units[_i].Position.Column); showUnit[_i] = EditorGUILayout.Foldout(showUnit[_i], foldoutName); GUILayout.FlexibleSpace(); if (GUILayout.Button("X")) { Target.Units.RemoveAt(_i); } } GUILayout.EndHorizontal(); if (showUnit[_i]) { Target.Units[_i].Unit = (CombatUnit)EditorGUILayout.ObjectField(Target.Units[_i].Unit, typeof(CombatUnit), false); unitPositionEditor(ref Target.Units[_i].Position); } } EditorGUILayout.HelpBox("Set the unit asset and position here, then click Add Unit to add the unit to the squad.", MessageType.Info); unitPrefab = (CombatUnit)EditorGUILayout.ObjectField(unitPrefab, typeof(CombatUnit), false); unitPositionEditor(ref unitPosition); if (GUILayout.Button("Add Unit")) { if (unitPrefab != null && Target.IsPositionValid(unitPrefab, unitPosition)) { if (!Target.AddUnit(unitPrefab, unitPosition)) { Debug.Log("Couldn't add unit."); } } else { Debug.LogWarning("Attempted to add invalid unit."); } } // Set the target as dirty if the GUI values have changed. if (GUI.changed) { EditorUtility.SetDirty(Target); Debug.Log("Squad saved."); } }
public Projectile(CombatUnit parent, Unit target, DamageEvent.DamageType type, float movementSpeed, int maxRange, int baseDamage) { this.parent = parent; this.x = parent.x; this.y = parent.y; this.startX = this.x; this.startY = this.y; this.target = target; this.type = type; this.movementSpeed = movementSpeed; this.maxRange = maxRange; this.baseDamage = baseDamage; this.waypoint = Util.GetPointOnCircle(parent.GetLocation(), maxRange, Util.GetHypoteneuseAngleDegrees(parent.GetLocation(), target.GetLocation())); int targetX = (int)target.x; int targetY = (int)target.y; SetMoveToTarget(targetX, targetY); }
public Arrow(CombatUnit parent, Unit target) : base(parent, target, DamageEvent.DamageType.Ranged, 3.0f, 300, 15) { this.texture = Game1.GetInstance().Content.Load<Texture2D>("Units/Projectiles/wooden_arrow_scale"); this.collisionPointTex = Game1.GetInstance().Content.Load<Texture2D>("Misc/solid"); }