Esempio n. 1
0
 private void HandleSingleLeftClick()
 {
     if (PlayerManager.MainController.GetCommanderHUD().MouseInBounds())
     {
         if (!ConstructionHandler.IsFindingBuildingLocation())
         {
             if (Selector.MainSelectedAgent && Selector.MainSelectedAgent.IsActive && Selector.MainSelectedAgent.IsOwnedBy(PlayerManager.MainController))
             {
                 if (Selector.MainSelectedAgent.GetAbility <Rally>() != null && Selector.MainSelectedAgent.GetAbility <Rally>().GetFlagState() == FlagState.SettingFlag)
                 {
                     //call harvest command
                     SelectionManager.SetSelectionLock(true);
                     ProcessInterfacer((QuickRally));
                 }
                 else
                 {
                     SelectionManager.SetSelectionLock(false);
                 }
             }
             else
             {
                 SelectionManager.SetSelectionLock(false);
             }
         }
     }
 }
Esempio n. 2
0
    // Use this for initialization
    void Awake()
    {
        Application.targetFrameRate = 60;

        Instance = this;

        pointsText.text = gamePoints.ToString();

        UpgradeUI.SetActive(false);
        DemolishUI.SetActive(false);
        IncreaseWorkersUI.SetActive(false);

        ConstructionHandler = FindObjectOfType <ConstructionHandler>();
        CitizenManager      = FindObjectOfType <CitizenManager>();
        AudioManager        = FindObjectOfType <AudioManager>();
        CPRData             = FindObjectOfType <CPRAccountData>();

        CameraControls = FindObjectOfType <CameraControls> ();
        MeteorHandler  = FindObjectOfType <MeteorHandler> ();

        Blockzilla   = Resources.Load <GameObject>("Events/Blockzilla");
        Blockman     = Resources.Load <GameObject>("Events/Blockman");
        SmallHouses  = Resources.LoadAll <GameObject>("Buildings/SmallHouses");
        MediumHouses = Resources.LoadAll <GameObject>("Buildings/MediumHouses");
        LargeHouses  = Resources.LoadAll <GameObject>("Buildings/LargeHouses");
        Specials     = Resources.LoadAll <GameObject>("Buildings/Special");

        MoneyText.text = "Money: " + CPRData.currentBalance.ToString("N2");
        ResetDailyMoney();
    }
Esempio n. 3
0
 public bool InteractionUpdate(HandApply interaction, ItemSlot slot, ConstructionHandler Handler)
 {
     if (slot?.Item != null)
     {
         var Circuit = slot.Item.GetComponent <CircuitBoard>();
         if (Circuit != null)
         {
             if (CustomNetworkManager.Instance._isServer == true)
             {
                 var _Object = Spawn.ServerPrefab(Circuit.ConstructionTarget, this.transform.position, parent: this.transform.parent).GameObject;
                 var CH      = _Object.GetComponent <ConstructionHandler>();
                 CustomNetTransform netTransform = _Object.GetComponent <CustomNetTransform>();
                 netTransform.AppearAtPosition(this.transform.position);
                 netTransform.AppearAtPositionServer(this.transform.position);
                 CH.GoToStage(Circuit.StartAtStage);
                 CH.GenerateComponents = false;
                 CH.CircuitBoard       = slot.ItemObject;
                 //TODO: Refactor to not use this.
                 Inventory.ServerVanish(slot);
                 Destroy(this.gameObject);
             }
         }
     }
     return(false);
 }
        public void Construct(long amount)
        {
            if (NeedsConstruction && !ConstructionStarted)
            {
                if (Agent.Animator.IsNotNull())
                {
                    Agent.Animator.SetState(AnimState.Building);
                }

                ConstructionStarted = true;
                ConstructionHandler.RestoreMaterial(Agent.gameObject);
            }

            cachedHealth.HealthAmount += amount;
            if (cachedHealth.HealthAmount >= cachedHealth.BaseHealth)
            {
                cachedHealth.HealthAmount = cachedHealth.BaseHealth;
                NeedsConstruction         = false;
                IsCasting = false;
                Agent.SetTeamColor();
                if (provisioner && !_provisioned)
                {
                    _provisioned = true;
                    Agent.GetCommander().CachedResourceManager.IncrementResourceLimit(ResourceType.Provision, provisionAmount);
                }
            }
        }
Esempio n. 5
0
    private void DrawActions(string[] actions)
    {
        GUIStyle buttons = new GUIStyle();

        buttons.hover.background  = buttonHover;
        buttons.active.background = buttonClick;
        GUI.skin.button           = buttons;
        int numActions = actions.Length;

        //define the area to draw the actions inside
        GUI.BeginGroup(new Rect(BUILD_IMAGE_WIDTH, 0, ORDERS_BAR_WIDTH, buildAreaHeight));
        //draw scroll bar for the list of actions if need be
        if (numActions >= MaxNumRows(buildAreaHeight))
        {
            DrawSlider(buildAreaHeight, numActions / 2.0f);
        }
        //display possible actions as buttons and handle the button click for each
        for (int i = 0; i < numActions; i++)
        {
            int       column = i % 2;
            int       row    = i / 2;
            Rect      pos    = GetButtonPos(row, column);
            Texture2D action = GameResourceManager.GetBuildImage(actions[i]);

            if (action)
            {
                //create the button and handle the click of that button
                if (GUI.Button(pos, action))
                {
                    RTSAgent agent = Selector.MainSelectedAgent as RTSAgent;
                    if (agent)
                    {
                        PlayClick();

                        if (agent.MyAgentType == AgentType.Unit &&
                            agent.GetAbility <Construct>() &&
                            !ConstructionHandler.IsFindingBuildingLocation())
                        {
                            ConstructionHandler.CreateStructure(actions[i], agent, agent.GetPlayerArea());
                        }
                        else if (agent.MyAgentType == AgentType.Building &&
                                 !agent.GetAbility <Structure>().NeedsConstruction &&
                                 agent.GetAbility <Spawner>())
                        {
                            // send spawn command
                            Command spawnCom = new Command(AbilityDataItem.FindInterfacer("Spawner").ListenInputID);
                            spawnCom.Add <DefaultData>(new DefaultData(DataType.String, actions[i]));
                            UserInputHelper.SendCommand(spawnCom);
                        }
                    }
                }
            }
        }
        GUI.EndGroup();
    }
Esempio n. 6
0
    public ConstructionBuilding(ConstructionHandler handler, ResourceType[] costTypes, uint[] costAmounts, float constructionTime, CPoint position)
        : base(BuildingType.Construction, position)
    {
        BunkaGame.MapManager[position] = this;
        this.ConstructionHandler = handler;
        this.ConstructionTime = constructionTime;
        this.costs = new Dictionary<ResourceType, uint>();

        for (int i = 0; i < costTypes.Length; i++)
            this.costs.Add(costTypes[i], costAmounts[i]);
    }
Esempio n. 7
0
 protected override void OnInitialize()
 {
     if (!Setted)
     {
         Setup();
     }
     SelectionManager.Initialize();
     RTSInterfacing.Initialize();
     ConstructionHandler.Initialize();
     IsGathering       = false;
     CurrentInterfacer = null;
 }
Esempio n. 8
0
    public static void Setup()
    {
        tempWallPillarGO  = ConstructionHandler.GetTempStructureGO();
        tempWallSegmentGO = tempWallPillarGO.GetComponent <Structure>().WallSegmentGO;

        if (tempWallSegmentGO)
        {
            tempWallSegmentBody = tempWallSegmentGO.GetComponent <UnityLSBody>().InternalBody;
        }

        _pillarOffset = (int)Math.Round(tempWallSegmentGO.transform.localScale.z);
    }
Esempio n. 9
0
 public bool CanInteraction(HandApply interaction, InventorySlot Slot, ConstructionHandler Handler)
 {
     if (Slot?.Item != null)
     {
         var Circuit = Slot.Item.GetComponent <CircuitBoard>();
         if (Circuit != null)
         {
             return(true);
         }
     }
     return(false);
 }
Esempio n. 10
0
        public void SetConstructQueue()
        {
            while (ConstructQueue.Count > 0)
            {
                QStructure qStructure = ConstructQueue.Dequeue();
                if (qStructure.IsNotNull())
                {
                    RTSAgent  newRTSAgent  = Agent.Controller.CreateAgent(qStructure.StructureName, qStructure.BuildPoint, qStructure.RotationPoint) as RTSAgent;
                    Structure newStructure = newRTSAgent.GetAbility <Structure>();

                    if (newStructure.StructureType == StructureType.Wall)
                    {
                        newRTSAgent.transform.localScale = qStructure.LocalScale.ToVector3();
                        newStructure.IsOverlay           = true;
                    }

                    newRTSAgent.Body.HalfWidth  = qStructure.HalfWidth;
                    newRTSAgent.Body.HalfLength = qStructure.HalfLength;

                    newStructure.BuildSizeLow  = (newRTSAgent.Body.HalfWidth.CeilToInt() * 2);
                    newStructure.BuildSizeHigh = (newRTSAgent.Body.HalfLength.CeilToInt() * 2);

                    if (GridBuilder.Place(newRTSAgent.GetAbility <Structure>(), newRTSAgent.Body._position))
                    {
                        Agent.GetCommander().CachedResourceManager.RemoveResources(newRTSAgent);

                        newRTSAgent.SetPlayingArea(Agent.GetPlayerArea());
                        newRTSAgent.SetCommander(Agent.GetCommander());

                        newRTSAgent.gameObject.name  = newRTSAgent.objectName;
                        newRTSAgent.transform.parent = newStructure.StructureType == StructureType.Wall ? WallPositioningHelper.OrganizerWalls.transform
                            : ConstructionHandler.OrganizerStructures.transform;

                        newStructure.AwaitConstruction();
                        // Set to transparent material until constructor is in range to start
                        ConstructionHandler.SetTransparentMaterial(newStructure.gameObject, GameResourceManager.AllowedMaterial, true);

                        if (CurrentProject.IsNull())
                        {
                            CurrentProject = newRTSAgent;
                            StartConstructMove();
                        }
                    }
                    else
                    {
                        Debug.Log("Couldn't place building!");
                        newRTSAgent.Die();
                    }
                }
            }
        }
Esempio n. 11
0
    private static void SetWall()
    {
        for (int i = 0; i < _pillarPrefabs.Count; i++)
        {
            // ignore first entry if start pillar was snapped, don't want to construct twice!
            if (!(_startSnapped && i == 0) && _pillarPrefabs[i].GetComponent <Structure>().ValidPlacement)
            {
                ConstructionHandler.SetConstructionQueue(_pillarPrefabs[i]);
            }

            if (_startPillar != _lastPillar)
            {
                GameObject wallSegement;
                if (_wallPrefabs.TryGetValue(i, out wallSegement) && wallSegement.GetComponent <Structure>().ValidPlacement)
                {
                    long adjustHalfWidth  = 0;
                    long adjustHalfLength = 0;

                    long currentHalfWidth  = tempWallSegmentBody.HalfWidth;
                    long currentHalfLength = tempWallSegmentBody.HalfLength;

                    if (_originalWallLength != wallSegement.transform.localScale.z)
                    {
                        currentHalfLength = (long)wallSegement.transform.localScale.z * FixedMath.Half;
                    }

                    adjustHalfWidth  = currentHalfWidth;
                    adjustHalfLength = currentHalfLength;
                    float currentRotation = wallSegement.transform.localEulerAngles.y;

                    // if segment has rotated past 45 degree angle, need to rotate length & width
                    if (currentRotation >= 45 && currentRotation <= 135 ||
                        currentRotation >= 225 && currentRotation <= 315)
                    {
                        adjustHalfWidth  = currentHalfLength;
                        adjustHalfLength = currentHalfWidth;
                    }

                    ConstructionHandler.SetConstructionQueue(wallSegement, adjustHalfWidth, adjustHalfLength);
                }
            }
        }

        ConstructionHandler.SendConstructCommand();
    }
Esempio n. 12
0
    private static void CreateWallSegment(Vector3 _currentPos)
    {
        int ndx = _pillarPrefabs.IndexOf(_lastPillar);

        //only create wall segment if dictionary doesn't contain pillar index
        if (!_wallPrefabs.ContainsKey(ndx))
        {
            Vector3 middle = 0.5f * (_currentPos + _lastPillar.transform.position);

            GameObject newWall = UnityEngine.Object.Instantiate(tempWallSegmentGO, middle, Quaternion.identity);
            newWall.gameObject.name = tempWallSegmentGO.gameObject.name;
            ConstructionHandler.SetTransparentMaterial(newWall, GameResourceManager.AllowedMaterial);

            _originalWallLength = (long)newWall.transform.localScale.z;
            newWall.SetActive(true);
            _wallPrefabs.Add(ndx, newWall);
            newWall.transform.parent = OrganizerWalls;
        }
    }
Esempio n. 13
0
    private void DrawMouseCursor()
    {
        Cursor.visible = false;

        // toggle back to pointer if over hud
        if (_mouseOverHud && !_cursorLocked)
        {
            SelectionManager.SetSelectionLock(true);
            SetCursorState(CursorState.Pointer);
        }

        if (!ConstructionHandler.IsFindingBuildingLocation())
        {
            GUI.skin = mouseCursorSkin;
            GUI.BeginGroup(new Rect(0, 0, Screen.width, Screen.height));
            UpdateCursorAnimation();
            Rect cursorPosition = GetCursorDrawPosition();
            GUI.Label(cursorPosition, activeCursor);
            GUI.EndGroup();
        }
    }
Esempio n. 14
0
    private static void CreateWallPillar(Vector3 _currentPos, bool isLast = false)
    {
        GameObject newPillar = UnityEngine.Object.Instantiate(tempWallPillarGO, _currentPos, Quaternion.identity);

        newPillar.gameObject.name = tempWallPillarGO.gameObject.name;
        ConstructionHandler.SetTransparentMaterial(newPillar, GameResourceManager.AllowedMaterial);

        if (_lastPillar)
        {
            newPillar.transform.LookAt(_lastPillar.transform);
        }
        else
        {
            newPillar.transform.LookAt(_startPillar.transform);
        }
        _pillarPrefabs.Add(newPillar);
        newPillar.transform.parent = OrganizerWalls;

        if (isLast)
        {
            _lastPillar = newPillar;
        }
    }
Esempio n. 15
0
 public bool InteractionUpdate(HandApply interaction, InventorySlot slot, ConstructionHandler Handler)
 {
     if (slot?.Item != null)
     {
         var Circuit = slot.Item.GetComponent <CircuitBoard>();
         if (Circuit != null)
         {
             if (CustomNetworkManager.Instance._isServer == true)
             {
                 var _Object = PoolManager.PoolNetworkInstantiate(Circuit.ConstructionTarget, this.transform.position, parent: this.transform.parent);
                 var CH      = _Object.GetComponent <ConstructionHandler>();
                 CustomNetTransform netTransform = _Object.GetComponent <CustomNetTransform>();
                 netTransform.AppearAtPosition(this.transform.position);
                 netTransform.AppearAtPositionServer(this.transform.position);
                 CH.GoToStage(Circuit.StartAtStage);
                 CH.GenerateComponents = false;
                 CH.CircuitBoard       = slot.Item;
                 InventoryManager.ClearInvSlot(slot);
                 Destroy(this.gameObject);
             }
         }
     }
     return(false);
 }
Esempio n. 16
0
 public void SetConstructionHandler(ConstructionHandler ch)
 {
     constructionHandler = ch;
 }
Esempio n. 17
0
 public ConstructionByOwnerController(ConstructionHandler constructionHandler)
 {
     ConstructionHandler = constructionHandler;
 }
Esempio n. 18
0
        private void BehaveWithTarget()
        {
            if (CurrentProject && (CurrentProject.IsActive == false || !CurrentProject.GetAbility <Structure>().NeedsConstruction))
            {
                //Target's lifecycle has ended
                StopConstruction();
            }
            else
            {
                Vector2d targetDirection = CurrentProject.Body._position - CachedBody._position;
                long     fastMag         = targetDirection.FastMagnitude();

                if (!IsWindingUp)
                {
                    if (CheckRange())
                    {
                        IsBuildMoving = false;
                        if (!inRange)
                        {
                            cachedMove.StopMove();
                            inRange = true;
                        }
                        Agent.Animator.SetState(ConstructingAnimState);

                        if (!CurrentProject.GetAbility <Structure>().ConstructionStarted)
                        {
                            CurrentProject.GetAbility <Structure>().ConstructionStarted = true;
                            // Restore material
                            ConstructionHandler.RestoreMaterial(CurrentProject.gameObject);
                        }

                        long mag;
                        targetDirection.Normalize(out mag);
                        bool withinTurn = cachedAttack.TrackAttackAngle == false ||
                                          (fastMag != 0 &&
                                           CachedBody.Forward.Dot(targetDirection.x, targetDirection.y) > 0 &&
                                           CachedBody.Forward.Cross(targetDirection.x, targetDirection.y).Abs() <= cachedAttack.AttackAngle);
                        bool needTurn = mag != 0 && !withinTurn;
                        if (needTurn)
                        {
                            cachedTurn.StartTurnDirection(targetDirection);
                        }
                        else
                        {
                            if (constructCount >= _constructInterval)
                            {
                                StartWindup();
                            }
                        }
                    }
                    else
                    {
                        cachedMove.PauseAutoStop();
                        cachedMove.PauseCollisionStop();
                        if (cachedMove.IsMoving == false)
                        {
                            cachedMove.StartMove(CurrentProject.Body._position);
                            CachedBody.Priority = basePriority;
                        }
                        else
                        {
                            if (inRange)
                            {
                                cachedMove.Destination = CurrentProject.Body.Position;
                            }
                            else
                            {
                                if (repathTimer.AdvanceFrame())
                                {
                                    if (CurrentProject.Body.PositionChangedBuffer &&
                                        CurrentProject.Body.Position.FastDistance(cachedMove.Destination.x, cachedMove.Destination.y) >= (repathDistance * repathDistance))
                                    {
                                        cachedMove.StartMove(CurrentProject.Body._position);
                                        //So units don't sync up and path on the same frame
                                        repathTimer.AdvanceFrames(repathRandom);
                                    }
                                }
                            }
                        }

                        if (inRange == true)
                        {
                            inRange = false;
                        }
                    }
                }

                if (IsWindingUp)
                {
                    //TODO: Do we need AgentConditional checks here?
                    windupCount += LockstepManager.DeltaTime;
                    if (windupCount >= Windup)
                    {
                        windupCount = 0;
                        Build();
                        while (this.constructCount >= _constructInterval)
                        {
                            //resetting back down after attack is fired
                            this.constructCount -= (this._constructInterval);
                        }
                        this.constructCount += Windup;
                        IsWindingUp          = false;
                    }
                }
                else
                {
                    windupCount = 0;
                }

                if (inRange)
                {
                    cachedMove.PauseAutoStop();
                    cachedMove.PauseCollisionStop();
                }
            }
        }
Esempio n. 19
0
    private static void AdjustWallSegments()
    {
        _startPillar.transform.LookAt(tempWallPillarGO.transform);
        tempWallPillarGO.transform.LookAt(_startPillar.transform.position);

        if (_pillarPrefabs.Count > 0)
        {
            GameObject adjustBasePole = _startPillar;
            for (int i = 0; i < _pillarPrefabs.Count; i++)
            {
                // no need to adjust start pillar
                if (i > 0)
                {
                    Vector3 newPos = adjustBasePole.transform.position + _startPillar.transform.TransformDirection(new Vector3(0, 0, _pillarOffset));
                    _pillarPrefabs[i].transform.position = newPos;
                    _pillarPrefabs[i].transform.rotation = _startPillar.transform.rotation;
                }

                Vector2d   posPillar  = new Vector2d(_pillarPrefabs[i].transform.position.x, _pillarPrefabs[i].transform.position.z);
                Coordinate coorPillar = BuildGridAPI.ToGridPos(posPillar);
                _pillarPrefabs[i].GetComponent <Structure>().GridPosition   = coorPillar;
                _pillarPrefabs[i].GetComponent <Structure>().ValidPlacement = BuildGridAPI.CanBuild(coorPillar, _pillarPrefabs[i].GetComponent <Structure>());

                if (_pillarPrefabs[i].GetComponent <Structure>().ValidPlacement)
                {
                    ConstructionHandler.SetTransparentMaterial(_pillarPrefabs[i], GameResourceManager.AllowedMaterial);
                }
                else
                {
                    ConstructionHandler.SetTransparentMaterial(_pillarPrefabs[i], GameResourceManager.NotAllowedMaterial);
                }

                if (_wallPrefabs.Count > 0)
                {
                    int        ndx = _pillarPrefabs.IndexOf(_pillarPrefabs[i]);
                    GameObject wallSegement;
                    if (_wallPrefabs.TryGetValue(ndx, out wallSegement))
                    {
                        GameObject nextPillar;
                        if (i + 1 < _pillarPrefabs.Count)
                        {
                            nextPillar = _pillarPrefabs[i + 1];
                        }
                        else
                        {
                            nextPillar = tempWallPillarGO;
                        }

                        int wallSegmentLength = (int)Math.Round(Vector3.Distance(_pillarPrefabs[i].transform.position, nextPillar.transform.position));
                        wallSegement.transform.localScale       = new Vector3(wallSegement.transform.localScale.x, wallSegement.transform.localScale.y, wallSegmentLength);
                        wallSegement.transform.localEulerAngles = adjustBasePole.transform.localEulerAngles;

                        Vector3 middle = 0.5f * (_pillarPrefabs[i].transform.position + nextPillar.transform.position);
                        wallSegement.transform.position = middle;

                        Vector2d   posSegment  = new Vector2d(wallSegement.transform.position.x, wallSegement.transform.position.z);
                        Coordinate coorSegment = BuildGridAPI.ToGridPos(posSegment);
                        wallSegement.GetComponent <Structure>().GridPosition   = coorSegment;
                        wallSegement.GetComponent <Structure>().ValidPlacement = BuildGridAPI.CanBuild(coorSegment, wallSegement.GetComponent <Structure>());

                        if (wallSegement.GetComponent <Structure>().ValidPlacement)
                        {
                            ConstructionHandler.SetTransparentMaterial(wallSegement, GameResourceManager.AllowedMaterial);
                        }
                        else
                        {
                            ConstructionHandler.SetTransparentMaterial(wallSegement, GameResourceManager.NotAllowedMaterial);
                        }
                    }
                }

                adjustBasePole = _pillarPrefabs[i];
            }
        }
    }
Esempio n. 20
0
    protected override void OnVisualize()
    {
        if (ConstructionHandler.IsFindingBuildingLocation())
        {
            SelectionManager.CanBox = false;
        }
        else
        {
            SelectionManager.CanBox = true;
        }
        //Update the SelectionManager which handles mouse-selection.
        SelectionManager.Update();
        //Update RTSInterfacing, a useful tool that automatically generates useful data for user-interfacing
        RTSInterfacing.Visualize();
        //Update Construction handler which handles placing buildings on a grid
        ConstructionHandler.Visualize();

        if (IsGathering)
        {
            //We are currently gathering mouse information. The next click will trigger the command with the mouse position.
            //I.e. Press "T" to use the 'Psionic Storm' ability. Then left click on a position to activate it there.

            //Right click to cancel casting the abiility by setting IsGathering to false
            if (Input.GetMouseButtonDown(1))
            {
                IsGathering = false;
                return;
            }

            //If we left click to release the ability
            //Or if the ability we're activating requires no mouse-based information (i.e. CurrentInterfacer.InformationGather)
            //Trigger the ability
            if (Input.GetMouseButtonDown(0) || CurrentInterfacer.InformationGather == InformationGatherType.None)
            {
                ProcessInterfacer(CurrentInterfacer);
            }
        }
        else
        {
            //We are not gathering information. Instead, allow quickcasted abilities with the mouse. I.e. Right click to move or attack.
            if (Input.GetKeyDown(KeyCode.Escape))
            {
                OpenPauseMenu();
            }

            MoveCamera();

            // prevent user input if mouse is over hud
            bool mouseOverHud = PlayerManager.MainController.GetCommanderHUD()._mouseOverHud;
            if (!mouseOverHud)
            {
                // detect rotation amount if no agents selected & Right mouse button is down
                if (PlayerManager.MainController.SelectedAgents.Count <= 0 && Input.GetMouseButton(1) ||
                    Input.GetMouseButton(1) && Input.GetKeyDown(KeyCode.LeftAlt))
                {
                    // lock the cursor to prevent movement during rotation
                    Cursor.lockState = CursorLockMode.Locked;

                    RotateCamera();
                }
                else
                {
                    Cursor.lockState = CursorLockMode.None;
                }

                MouseHover();

                if (Input.GetMouseButtonDown(0))
                {
                    if (Time.time < tapTimer + tapThreshold)
                    {
                        // left double click action
                        OnDoubleLeftTapDown?.Invoke(); tap = false;
                        return;
                    }

                    tap      = true;
                    tapTimer = Time.time;
                }
                // right click action
                else if (Input.GetMouseButtonDown(1))
                {
                    HandleSingleRightClick();
                    OnSingleRightTapDown?.Invoke();
                }
                else if (Input.GetMouseButtonUp(0))
                {
                    _isDragging = false;
                    OnLeftTapUp?.Invoke();
                }

                if (tap == true && Time.time > tapTimer + tapThreshold)
                {
                    tap = false;

                    // left click hold action
                    if (Input.GetMouseButton(0))
                    {
                        if (OnLeftTapHoldDown != null)
                        {
                            _isDragging = true;
                            OnLeftTapHoldDown();
                        }
                    }
                    else
                    {
                        // left click action
                        HandleSingleLeftClick();
                        OnSingleLeftTapDown?.Invoke();
                    }
                }

                // other defined keys
                foreach (KeyValuePair <UserInputKeyMappings, KeyCode> inputKey in userInputKeys)
                {
                    if (Input.GetKeyDown(inputKey.Value))
                    {
                        switch (inputKey.Key)
                        {
                        // these should probably be switched to events...
                        case UserInputKeyMappings.RotateLeftShortCut:
                            ConstructionHandler.HandleRotationTap(UserInputKeyMappings.RotateLeftShortCut);
                            break;

                        case UserInputKeyMappings.RotateRightShortCut:
                            ConstructionHandler.HandleRotationTap(UserInputKeyMappings.RotateRightShortCut);
                            break;

                        default:
                            break;
                        }
                    }
                }
            }
        }
    }
Esempio n. 21
0
    private void HandleSingleRightClick()
    {
        if (PlayerManager.MainController.GetCommanderHUD().MouseInBounds() &&
            Selector.MainSelectedAgent &&
            !ConstructionHandler.IsFindingBuildingLocation())
        {
            if (Selector.MainSelectedAgent &&
                Selector.MainSelectedAgent.IsOwnedBy(PlayerManager.MainController))
            {
                if (Selector.MainSelectedAgent.GetAbility <Rally>() &&
                    !Selector.MainSelectedAgent.GetAbility <Structure>().NeedsConstruction)
                {
                    if (Selector.MainSelectedAgent.GetAbility <Rally>().GetFlagState() == FlagState.SettingFlag)
                    {
                        Selector.MainSelectedAgent.GetAbility <Rally>().SetFlagState(FlagState.SetFlag);
                        PlayerManager.MainController.GetCommanderHUD().SetCursorLock(false);
                        PlayerManager.MainController.GetCommanderHUD().SetCursorState(CursorState.Select);
                    }
                    else
                    {
                        Vector2d rallyPoint = RTSInterfacing.GetWorldPosD(Input.mousePosition);
                        Selector.MainSelectedAgent.GetAbility <Rally>().SetRallyPoint(rallyPoint.ToVector3());
                    }
                }

                if (RTSInterfacing.MousedAgent.IsNotNull())
                {
                    // if moused agent is a resource, send selected agent to harvest
                    if (Selector.MainSelectedAgent.GetAbility <Harvest>() &&
                        RTSInterfacing.MousedAgent.MyAgentType == AgentType.Resource)
                    {
                        //call harvest command
                        ProcessInterfacer((QuickHarvest));
                    }
                    // moused agent is a building and owned by current player
                    else if (RTSInterfacing.MousedAgent.MyAgentType == AgentType.Building &&
                             RTSInterfacing.MousedAgent.IsOwnedBy(PlayerManager.MainController))
                    {
                        // moused agent isn't under construction
                        if (!RTSInterfacing.MousedAgent.GetAbility <Structure>().NeedsConstruction)
                        {
                            // if moused agent is a harvester resource deposit, call harvest command to initiate deposit
                            if (Selector.MainSelectedAgent.GetAbility <Harvest>() &&
                                Selector.MainSelectedAgent.GetAbility <Harvest>().GetCurrentLoad() > 0)
                            {
                                //call harvest command
                                ProcessInterfacer((QuickHarvest));
                            }
                        }
                        // moused agent is still under construction
                        else if (Selector.MainSelectedAgent.GetAbility <Construct>())
                        {
                            //call build command
                            ProcessInterfacer((QuickBuild));
                        }
                    }
                    else if (Selector.MainSelectedAgent.GetAbility <Attack>() &&
                             !RTSInterfacing.MousedAgent.IsOwnedBy(PlayerManager.MainController) &&
                             RTSInterfacing.MousedAgent.MyAgentType != AgentType.Resource)
                    {
                        //If the selected agent has Attack (the ability behind attacking) and the mouse is over an agent, send a target command - right clicking on a unit
                        ProcessInterfacer((QuickTarget));
                    }
                }
                else
                {
                    // If there is no agent under the mouse or the selected agent doesn't have Attack, send a Move command - right clicking on terrain
                    // stop casting all abilities
                    // Selector.MainSelectedAgent.StopCast();
                    ProcessInterfacer((QuickMove));
                }
            }
        }
    }