Hello, I am starting battle from code and have a requirement where I need to remove certain enemies and add new one to the battle group after the battle has started. Is there any way to do it. Here's my code for spawning enemies.
private void SpawnEnemies()
{
ORK.Game.ActiveGroup.ClearTargets();
ORK.Game.Combatants.Clear(false);
for (int j = 0; j < _enemyCellCordList.Count; j++)
{
_enemyDeploymentCellList.Add(_mainBattleGrid.GetCell(_enemyCellCordList[j].x, _enemyCellCordList[j].y));
}
for (int i = 0; i < _mainBattle.settings.combatant.Length; i++)
{

}
FactionSetting enemyfaction = new FactionSetting("Enemies"); //Change Here
Group enemyArmy = new Group(enemyfaction); //1 is the ID of the enemy faction...
for (int i = 0; i < _enemyUnitIDList.Count; i++)
{
Combatant c = ORK.Combatants.Create(_enemyUnitIDList[i], enemyArmy, true, true);
c.Init();
_enemyDeploymentCellList[i].SetCombatant(c, false);
c.Object.Spawn(_enemyDeploymentCellList[i].transform.position, true, new Vector3(0, 0f, 0), false, Vector3.one);
c.GameObject.GetComponent<CombatantWrapper>().SetDirection(true);
_enemyUnitCbtList.Add(c);
_mainBattle.SetNextEnemySpot(c, GroupAdvantageType.Enemy);
}
enemyArmy.SetBattleGroup(_enemyUnitCbtList, true);
_mainBattle.StartGroup(enemyArmy, this);
//This is the equivalent of the "Place on grid" node...
GameObject[] spots = new GameObject[_enemyUnitCbtList.Count];
for (int i = 0; i < _enemyUnitCbtList.Count; i++)
{
_enemyUnitCbtList[i].Grid.Cell = _enemyDeploymentCellList[i];
spots[i] = _enemyDeploymentCellList[i].gameObject;
}
_mainBattle.enemySpot = spots;
}
  • edited March 14
    If this is for an ongoing battle, don't use the Battle component's functions to start a battle or anything like that.

    Use ORK.Battle instead - this is the battle handler and has functions to join and remove combatants from battle. E.g. Join to join (either a list of combatants or a single combatant), RemoveFromBattle or RemoveCombatant (e.g. for also getting loot).

    Joining a battle this way will also give them a free battle spot and use the Join Battle Animation (Combatants > Combatants in the battle animations) to animate this.
    Post edited by gamingislove on
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • Thanks, as you suggested I started battle using ORK.Battle and now its working.
Sign In or Register to comment.