public class LargeScaleBattleInit : MonoBehaviour
{
private BattleComponent mainBattle;
private BattleGridComponent mainBattleGrid;
[SerializeField]
private List<int> playerUnitIDList;
[SerializeField]
private List<int> enemyUnitIDList;
private List<Combatant> playerUnitCbtList = new List<Combatant>();
private List<Combatant> enemyUnitCbtList = new List<Combatant>();
[SerializeField]
private List<BattleGridCellComponent> playerDeploymentCellList;
[SerializeField]
private List<BattleGridCellComponent> enemyDeploymentCellList;
private void Awake()
{
mainBattle = GetComponent<BattleComponent>();
mainBattleGrid = GameObject.Find("MainBattleGrid").GetComponent<BattleGridComponent>();
ORK.Battle.BattleStarted += OnBattleStart;
}
void Start()
{
for (int i = 0; i < playerUnitIDList.Count; i++)
{
Combatant c = ORK.Combatants.Create(playerUnitIDList[i], ORK.Game.ActiveGroup, true, true);
c.Init();
c.Object.Spawn(playerDeploymentCellList[i].transform.position, true, 0, false, Vector3.one);
playerUnitCbtList.Add(c);
}
ORK.Game.ActiveGroup.SetBattleGroup(playerUnitCbtList, true);
Group enemyArmy = new Group(1); //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();
c.Object.Spawn(enemyDeploymentCellList[i].transform.position, true, 0, false, Vector3.one);
enemyUnitCbtList.Add(c);
}
enemyArmy.SetBattleGroup(enemyUnitCbtList, true);
//ORK.Battle.Join(playerUnitCbtList); //It doesn't change anything if I add this line. However, if I omit the next one, the battle refuses to start...
ORK.Battle.Join(enemyUnitCbtList);
mainBattle.StartEvent(playerUnitCbtList[0].GameObject);
}
void OnBattleStart()
{
//This is the equivalent of the "Place on grid" node...
for(int i = 0; i < playerUnitCbtList.Count; i++)
{
playerUnitCbtList[i].Grid.Cell = playerDeploymentCellList[i];
}
for (int i = 0; i < enemyUnitCbtList.Count; i++)
{
enemyUnitCbtList[i].Grid.Cell = enemyDeploymentCellList[i];
}
}
}
[RequireComponent(typeof(Camera))]
public class BattlefieldHexPicker : MonoBehaviour
{
private Camera largeScaleBattleCam;
void Start()
{
largeScaleBattleCam = GetComponent<Camera>();
}
void Update()
{
if (Input.GetMouseButtonUp(0))
{
Vector3 mousePos = Input.mousePosition;
Ray screenRay = largeScaleBattleCam.ScreenPointToRay(mousePos);
int screenRayMask = 1 << LayerMask.NameToLayer("Grid");
RaycastHit screenRayHit;
bool isHitScreenRay = Physics.Raycast(screenRay, out screenRayHit, largeScaleBattleCam.farClipPlane, screenRayMask, QueryTriggerInteraction.Collide);
if (isHitScreenRay)
{
BattleGridCellComponent cell = screenRayHit.collider.transform.parent.GetComponent<BattleGridCellComponent>();
if(ORK.Battle.SelectingCombatant.IsPlayerControlled() && cell.Combatant != null)
{
if (cell.Combatant.IsPlayerControlled())
{
//If I uncomment the next line, it works, but I don't want to change the leader...
//ORK.Game.ActiveGroup.SetLeader(cell.Combatant, true);
ORK.Battle.SystemSettings.phase.CombatantSelected(cell.Combatant);
}
}
}
}
}
}
It looks like you're new here. If you want to get involved, click one of these buttons!
As for the cell picker - the CombatantSelected function should work, but I assume that the combatant isn't part of the current faction's phase. Are the combatants part of the player's battle group?
If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
As for your question, yes, the combatants I try to select are already part of the player's battle group and I try to select them during the player's faction phase. I thought it was necessary to have them in combat.
I'm simply trying to select the combatants of the player group. I don't want to select them with ORK's interface because I have different kinds of phase combat in my game and I don't want the player to be able to select his units by clicking on them in the other kinds of phase combat. By coding the "picking" myself, I avoid changing the ORK parameters and I feel it is simpler.
It seems the CombatantSelect function does not work. This is weird because I already used that function in another combat type and it worked well...
Btw, the built-in Player Combatant Selection settings in phase battles already have such a functionality - enable Allow Clicking and While Selected to be able to click-select a different combatant.
If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
pGroup.LockBattleMember(combatant, false);
I use this on every battle member of my groups and then, when I use ConbatantSelect, it works as expected.
Could you explain me the use of this LockBattleMember function please?
Thanks!
If you're enjoying my products, updates and support, please consider supporting me on patreon.com!