public void GiveOrderWithNonFixedParams(OrderableObject[] EntetiesToOrder, GameOrderInitParams orderType, bool isIdleState = false) { Vector2 mousePos = Mouse.current.position.ReadValue(); if (isIdleState) { RaycastHit hit; if (Physics.Raycast(Camera.main.ScreenPointToRay(mousePos), out hit, 100f, 1 << 8)) { GameObject raycastHitGameObject = hit.collider.gameObject; FractionMember raycastHitGameObjectFraction = raycastHitGameObject.GetComponent <FractionMember>(); if (raycastHitGameObject.GetComponent <DamageSystem>() == null) { foreach (OrderableObject entety in EntetiesToOrder) { MoveOrderInitParams moveOrderInitParams = new MoveOrderInitParams(""); MoveOrderVariableParams moveOrderVariableParams = new MoveOrderVariableParams(GetDestinationWithOffset(hit.point, EntetiesToOrder.Length), null); GiveOrderToUnits(entety, moveOrderInitParams, moveOrderVariableParams); } } else { if (fraction != raycastHitGameObjectFraction.fraction) { AttackOrderInitParams attackOrderInitParams = new AttackOrderInitParams(""); AttackOrderVariableParams attackOrderVariableParams = new AttackOrderVariableParams(raycastHitGameObject, null); GiveOrderToUnits(EntetiesToOrder, attackOrderInitParams, attackOrderVariableParams); } } } else if (Physics.Raycast(Camera.main.ScreenPointToRay(mousePos), out hit, 100f, 1 << 10)) { GameObject enemyObject = hit.collider.gameObject; FractionMember victimFraction = enemyObject.GetComponent <FractionMember>(); if (victimFraction.fraction != fraction) { if (inputHandler.PossibleOrders.Any(x => x is AttackOrderInitParams)) { AttackOrderInitParams attackOrderInitParams = new AttackOrderInitParams(""); AttackOrderVariableParams attackOrderVariableParams = new AttackOrderVariableParams(enemyObject, null); GiveOrderToUnits(EntetiesToOrder, attackOrderInitParams, attackOrderVariableParams); } } else { if (inputHandler.PossibleOrders.Any(x => x is BuildOrderInitParams) && hit.transform.TryGetComponent(typeof(Building), out Component building)) { foreach (OrderableObject entity in inputHandler.SelectedEnteties) { BuildOrderVariableParams buildOrderVariableParams = new BuildOrderVariableParams(building as Building, entity.gameObject); entity.GiveOrder(new BuildOrder(buildOrderVariableParams)); } } } } else { if (hexGrid.TryRaycastHexGrid(Camera.main.ScreenPointToRay(mousePos), out Vector3 output)) { foreach (OrderableObject EntetyToOrder in EntetiesToOrder) { MoveOrderInitParams moveOrderInitParams = new MoveOrderInitParams(""); MoveOrderVariableParams moveOrderVariableParams = new MoveOrderVariableParams(GetDestinationWithOffset(output, EntetiesToOrder.Length), EntetyToOrder.gameObject); GiveOrderToUnits(EntetyToOrder, moveOrderInitParams, moveOrderVariableParams); } } } } else { if (orderType is MoveAttackOrderInitParams) { RaycastHit hit; if (Physics.Raycast(Camera.main.ScreenPointToRay(mousePos), out hit, 100f, 1 << 8)) { foreach (OrderableObject EntetyToOrder in EntetiesToOrder) { MoveAttackOrderInitParams moveAttackOrderInitParams = new MoveAttackOrderInitParams(""); MoveAttackOrderVariableParams moveAttackOrderVariableParams = new MoveAttackOrderVariableParams(GetDestinationWithOffset(hit.point, EntetiesToOrder.Length), EntetyToOrder.gameObject); GiveOrderToUnits(EntetyToOrder, moveAttackOrderInitParams, moveAttackOrderVariableParams); } } else { if (hexGrid.TryRaycastHexGrid(Camera.main.ScreenPointToRay(mousePos), out Vector3 output)) { foreach (OrderableObject EntetyToOrder in EntetiesToOrder) { MoveAttackOrderInitParams moveAttackOrderInitParams = new MoveAttackOrderInitParams(""); MoveAttackOrderVariableParams moveAttackOrderVariableParams = new MoveAttackOrderVariableParams(GetDestinationWithOffset(output, EntetiesToOrder.Length), EntetyToOrder.gameObject); GiveOrderToUnits(EntetyToOrder, moveAttackOrderInitParams, moveAttackOrderVariableParams); } } } } if (orderType is MoveOrderInitParams) { if (hexGrid.TryRaycastHexGrid(Camera.main.ScreenPointToRay(mousePos), out Vector3 output)) { foreach (OrderableObject EntetyToOrder in EntetiesToOrder) { MoveOrderInitParams moveOrderInitParams = new MoveOrderInitParams(""); MoveOrderVariableParams moveOrderVariableParams = new MoveOrderVariableParams(GetDestinationWithOffset(output, EntetiesToOrder.Length), EntetyToOrder.gameObject); GiveOrderToUnits(EntetyToOrder, moveOrderInitParams, moveOrderVariableParams); return; } } } if (orderType is AttackOrderInitParams) { if (Physics.Raycast(Camera.main.ScreenPointToRay(mousePos), out RaycastHit hit, 100f, 1 << 8)) { GameObject victim = hit.collider.gameObject; FractionMember victimFraction = victim.GetComponent <FractionMember>(); if (victim.GetComponent <DamageSystem>() != null) { if (fraction != victimFraction.fraction) { AttackOrderInitParams currentParameters = new AttackOrderInitParams(""); AttackOrderVariableParams attackOrderVariableParams = new AttackOrderVariableParams(victim, null); GiveOrderToUnits(EntetiesToOrder, currentParameters, attackOrderVariableParams); } } } } } }
public void StartDemoGame() { #region OrdersExamples MoveOrderInitParams MoveExample = new MoveOrderInitParams("Move"); AttackOrderInitParams AttackExample = new AttackOrderInitParams("Attack"); MoveAttackOrderInitParams MoveAttackExample = new MoveAttackOrderInitParams("Move and attack"); Dictionary<string,BuildOrderInitParams> BuildExamples = new Dictionary<string,BuildOrderInitParams>(); foreach (Building var in BuildingsToLoad) { if (var is MainHub) continue; BuildExamples.Add(typeof(BuildOrderInitParams).FullName + "."+ var.name,new BuildOrderInitParams(var, "Build "+var.name)); } Dictionary<string, UnitCreationOrderInitParams> UnitCreationExamples = new Dictionary<string, UnitCreationOrderInitParams>(); foreach (Unit unit in UnitsToLoad) { UnitCreationExamples.Add(typeof(UnitCreationOrderInitParams).FullName + "." + unit.name, new UnitCreationOrderInitParams(unit, 1f, "Create unit " + unit.name)); } #endregion EntityLoader.ClearDictionary(); #region UnitLoadInitialization foreach (Unit unit in UnitsToLoad) { if (unit is Warrior) { LoadEntetyData warrioEntetyData = new LoadEntetyData(unit.gameObject,new Dictionary<string, GameOrderInitParams> { {MoveExample.ToString() ,MoveExample}, {AttackExample.ToString() ,AttackExample}, {MoveAttackExample.ToString() ,MoveAttackExample}, }); EntityLoader.AddNewEntetyTypeToDictionary(unit.GetType(), warrioEntetyData); } else if (unit is UnitBuilder) { Dictionary<string, GameOrderInitParams> AllOrdersExamples = new Dictionary<string, GameOrderInitParams>(); foreach (KeyValuePair<string,BuildOrderInitParams> keyValuePair in BuildExamples) { AllOrdersExamples.Add(keyValuePair.Key,keyValuePair.Value); } AllOrdersExamples.Add(MoveExample.ToString(),MoveExample); LoadEntetyData builderEntetyData = new LoadEntetyData(unit.gameObject, AllOrdersExamples); EntityLoader.AddNewEntetyTypeToDictionary(unit.GetType(), builderEntetyData); } else { LoadEntetyData builderEntetyData = new LoadEntetyData(unit.gameObject, new Dictionary<string, GameOrderInitParams> { {MoveExample.ToString() ,MoveExample} }); EntityLoader.AddNewEntetyTypeToDictionary(unit.GetType(), builderEntetyData); } } #endregion #region BuildingLoadInitialization foreach (Building building in BuildingsToLoad) { if (building is MainHub) { Dictionary<string, GameOrderInitParams> AllOrdersExamples = new Dictionary<string, GameOrderInitParams>(); foreach (KeyValuePair<string,UnitCreationOrderInitParams> keyValuePair in UnitCreationExamples) { AllOrdersExamples.Add(keyValuePair.Key,keyValuePair.Value); } LoadEntetyData HubLoadData = new LoadEntetyData(building.gameObject, AllOrdersExamples); EntityLoader.AddNewEntetyTypeToDictionary(building.GetType(),HubLoadData); } } #endregion SceneManager.LoadScene(DemoSceneIndex); }