コード例 #1
0
ファイル: OrderGiver.cs プロジェクト: TGR-OAM/RTSGame
 public static void GiveOrderToUnits(OrderableObject[] orderableObjects, GameOrderInitParams gameOrderInitParams, GameOrderVariableParams gameOrderVariableParams)
 {
     foreach (OrderableObject orderableObject in orderableObjects)
     {
         gameOrderVariableParams.ObjectToOrder = orderableObject.gameObject;
         GameOrder order = gameOrderInitParams.CreateOrder(gameOrderVariableParams);
         orderableObject.GiveOrder(order);
     }
 }
コード例 #2
0
ファイル: InputHandler.cs プロジェクト: TGR-OAM/RTSGame
        public void SetStateFromOrderType(GameOrderInitParams orderType)
        {
            switch (orderType)
            {
            case BuildOrderInitParams buildOrderInitParams:
                currentState = HandlerState.Building;
                builder.StartPlacingBuilding((orderType as BuildOrderInitParams).building);
                break;

            case UnitCreationOrderInitParams unitCreationOrderInitParams:
                foreach (Building building in SelectedEnteties.Where(x => x.TryGetComponent(typeof(Building), out _)).Select(x => x.GetComponent <Building>()))
                {
                    UnitCreationOrder unitCreationOrder = unitCreationOrderInitParams.CreateOrder(new UnitCreationOrderVariableParams(building.CreationOutput, building.gameObject)) as UnitCreationOrder;
                    building.orderableObject.GiveOrder(unitCreationOrder);
                }
                break;

            default:
                CurrentOrder = orderType;
                currentState = HandlerState.Ordering;
                break;
            }
        }
コード例 #3
0
ファイル: OrderFactory.cs プロジェクト: TGR-OAM/RTSGame
        public static GameOrder CreateOrder(this GameOrderInitParams orderInitParams, GameOrderVariableParams orderVariableParams)
        {
            switch (orderInitParams)
            {
            case BuildOrderInitParams buildParams:
                return(new BuildOrder(orderVariableParams as BuildOrderVariableParams));

            case AttackOrderInitParams attackParams:
                return(new AttackOrder(orderVariableParams as AttackOrderVariableParams));

            case MoveOrderInitParams moveParams:
                return(new MoveOrder(orderVariableParams as MoveOrderVariableParams));

            case MoveAttackOrderInitParams moveAtackParams:
                return(new MoveAttackOrder(orderVariableParams as MoveAttackOrderVariableParams));

            case UnitCreationOrderInitParams unitCreationOrderInitParams:
                return(new UnitCreationOrder(unitCreationOrderInitParams,
                                             orderVariableParams as UnitCreationOrderVariableParams));

            default:
                throw new ArgumentOutOfRangeException(paramName: "orderInitParams");
            }
        }
コード例 #4
0
ファイル: OrderGiver.cs プロジェクト: TGR-OAM/RTSGame
        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);
                            }
                        }
                    }
                }
            }
        }
コード例 #5
0
ファイル: OrderGiver.cs プロジェクト: TGR-OAM/RTSGame
        public static void GiveOrderToUnits(OrderableObject orderableObject, GameOrderInitParams gameOrderInitParams, GameOrderVariableParams gameOrderVariableParams)
        {
            GameOrder order = gameOrderInitParams.CreateOrder(gameOrderVariableParams);

            orderableObject.GiveOrder(order);
        }
コード例 #6
0
 public void SetOrder(GameOrderInitParams orderType)
 {
     uiManager.inputHandler.SetStateFromOrderType(orderType);
 }