示例#1
0
        void DisplayCursor()
        {
            if (!(selectedMove != null && !selectedMove.IsLaunched()))
            {
                Cursor.SetCursor(hand, handPos, CursorMode.ForceSoftware);
            }
            else if (selectedMove != null && !selectedMove.IsLaunched())
            {
                MoveTargetKind targetType = selectedMove.info.TargetKind;

                if (targetType == MoveTargetKind.Area)
                {
                    Cursor.SetCursor(singleEnemy, singleEnemyPos, CursorMode.ForceSoftware);
                }
                else
                {
                    if (hoverEntity)
                    {
                        if (targetType == MoveTargetKind.Single && hoverEntity.Equals(gameObject))
                        {
                            Cursor.SetCursor(singleAlly, singleAllyPos, CursorMode.ForceSoftware);
                        }
                        else if (targetType == MoveTargetKind.Single && !hoverEntity.Equals(gameObject))
                        {
                            Cursor.SetCursor(singleEnemy, singleEnemyPos, CursorMode.ForceSoftware);
                        }
                        else
                        {
                            Cursor.SetCursor(single, singlePos, CursorMode.ForceSoftware);
                        }
                    }
                    else
                    {
                        Cursor.SetCursor(single, singlePos, CursorMode.ForceSoftware);
                    }
                }
            }
        }
示例#2
0
        private void ValidateControl(int input, Vector3 pos, NetworkViewID viewID, int moveIndex)
        {
            if (Network.isServer)
            {
                MatchManager matchManager = GameObject.Find("GameManager").GetComponent <MatchManager>();

                if (matchManager._state == Mobamon.GameManager.Enums.MatchState.Running)
                {
                    if (input == (int)InputType.LeftClick)
                    {
                        if (selectedMove == null && moveIndex == -1)
                        {
                            // The character has to move at least half of its width.
                            //if((theChosenHit.point - transform.position).magnitude >= nav.radius)
                            {
                                SetDestination(pos);
                            }
                        }
                        else
                        {
                            // If a move is selected, but not launched :
                            //if(!selectedMove.IsLaunched())
                            if (selectedMove == null && moveIndex != -1)
                            {
                                SelectMove(moveIndex);

                                GameObject      targetPokemon = new GameObject();
                                PokemonRelation relation      = PokemonRelation.ERROR;

                                if (viewID != NetworkViewID.unassigned)
                                {
                                    targetPokemon = NetworkView.Find(viewID).gameObject;
                                    relation      = entityManager.GetRelation(targetPokemon);
                                }

                                MoveTargetKind targetKind     = selectedMove.info.TargetKind;
                                bool           attackLaunched = false;

                                if (targetKind == MoveTargetKind.Area)
                                {
                                    SetAttackState(NetworkViewID.unassigned, pos);
                                    attackLaunched = true;
                                }
                                else if (targetKind == MoveTargetKind.Single && relation != PokemonRelation.ERROR)   // If the target type is not an area, then it's a single target spell. Therefore he needs a target.
                                {
                                    bool isSelfOnly = ((int)PokemonRelation.Self ^ (int)selectedMove.info.AllowedTargets) == 0;

                                    if (isSelfOnly)
                                    {
                                        SetAttackState(viewID, pos);
                                        attackLaunched = true;
                                    }
                                    else
                                    {
                                        if (((int)selectedMove.info.AllowedTargets & (int)relation) != 0)
                                        {
                                            SphereCollider targetCollider = (SphereCollider)targetPokemon.GetComponent <Collider>();

                                            if (Vector3.Magnitude(targetPokemon.transform.position - transform.position) <= selectedMove.info.Range / 100f + nav.radius + targetCollider.radius)
                                            {
                                                SetAttackState(viewID, pos);
                                                attackLaunched = true;
                                            }
                                        }
                                    }
                                }

                                if (!attackLaunched)
                                {
                                    // If the player failed to click a right target for his attack, then we unselect it.
                                    selectedMove = null;
                                }
                            }
                        }
                    }
                }
            }
        }
示例#3
0
        public void Controls()
        {
            if (isMine)
            {
                // Uses : selectedMove, hit and hoverEntity

                if (!(selectedMove != null && selectedMove.IsLaunched()))
                {
                    if ((Input.GetKeyDown("q") || Input.GetKeyDown("a")) && moveSet[0] != null)
                    {
                        SelectMove(0);
                    }
                    else if ((Input.GetKeyDown("w") || Input.GetKeyDown("z")) && moveSet[1] != null)
                    {
                        SelectMove(1);
                    }
                    else if (Input.GetKeyDown("e") && moveSet[2] != null)
                    {
                        SelectMove(2);
                    }
                    else if (Input.GetKeyDown("r") && moveSet[3] != null)
                    {
                        SelectMove(3);
                    }
                }

                if (selectedMove != null && !selectedMove.IsLaunched())
                {
                    Ray ray = myCam.ScreenPointToRay(Input.mousePosition);

                    if (Physics.Raycast(ray, out hit) && hit.transform.root.gameObject == SceneHelper.GetContainer(Container.Entities))
                    {
                        hoverEntity = hit.transform.gameObject;

                        SphereCollider targetCollider = (SphereCollider)hoverEntity.GetComponent <Collider>();

                        if (selectedMove.info.TargetKind == MoveTargetKind.Single &&
                            Vector3.Magnitude(hoverEntity.transform.position - transform.position) > selectedMove.info.Range / 100f + nav.radius + targetCollider.radius)
                        {
                            hoverEntity = null;
                        }
                    }
                    else
                    {
                        hoverEntity = null;
                    }
                }

                if (Input.GetMouseButtonDown(0))
                {
                    if (selectedMove == null)
                    {
                        Ray          ray = myCam.ScreenPointToRay(Input.mousePosition);
                        RaycastHit[] hits;
                        hits = Physics.RaycastAll(ray, 100.0f);

                        RaycastHit theChosenHit = new RaycastHit();
                        foreach (RaycastHit singleHit in hits)
                        {
                            if (singleHit.collider.transform.parent.name == "Terrain")
                            {
                                if (theChosenHit.Equals(new RaycastHit()) || singleHit.distance < theChosenHit.distance)
                                {
                                    theChosenHit = singleHit;
                                }
                            }
                        }

                        if (!theChosenHit.Equals(new RaycastHit()))
                        {
                            // The character has to move at least half of its width.
                            //if((theChosenHit.point - transform.position).magnitude >= nav.radius)
                            {
                                theChosenHit.point.Set(theChosenHit.point.x, 0, theChosenHit.point.z);
                                GetComponent <NetworkView>().RPC("ValidateControl", RPCMode.Server, (int)InputType.LeftClick, theChosenHit.point, NetworkViewID.unassigned, -1);
                            }
                        }
                    }
                    else
                    {
                        // If a move is selected, but not launched :
                        if (!selectedMove.IsLaunched())
                        {
                            bool attackLaunched = false;

                            MoveTargetKind targetKind = selectedMove.info.TargetKind;

                            int moveIndex = -1;
                            for (int i = 0; i < moveSet.Count; i++)
                            {
                                if (selectedMove.name == moveSet[i])
                                {
                                    moveIndex = i;
                                }
                            }

                            if (targetKind == MoveTargetKind.Area)
                            {
                                GetComponent <NetworkView>().RPC("ValidateControl", RPCMode.Server, (int)InputType.LeftClick, hit.point, NetworkViewID.unassigned, moveIndex);
                                attackLaunched = true;
                            }
                            else if (targetKind == MoveTargetKind.Single && hoverEntity != null)                            // If the target type is not an area, then it's a single target spell. Therefore he needs a target.
                            {
                                PokemonRelation relation = entityManager.GetRelation(hoverEntity);

                                if ((relation & selectedMove.info.AllowedTargets) != 0)
                                {
                                    SphereCollider targetCollider = (SphereCollider)hoverEntity.GetComponent <Collider>();

                                    if (Vector3.Magnitude(hoverEntity.transform.position - transform.position) <= selectedMove.info.Range / 100f + nav.radius + targetCollider.radius)
                                    {
                                        GetComponent <NetworkView>().RPC("ValidateControl", RPCMode.Server, (int)InputType.LeftClick, hit.point, hoverEntity.GetComponent <NetworkView>().viewID, moveIndex);
                                        attackLaunched = true;
                                    }
                                }
                            }

                            if (!attackLaunched)
                            {
                                selectedMove = null;                                 // If the player failed to click a right target for his attack, then we unselect it.
                            }

                            hoverEntity = null;
                        }
                    }
                }
                else if (Input.GetMouseButtonDown(1))
                {
                    //SetLife(currentHP - 2f);

                    if (selectedMove != null && !selectedMove.IsLaunched())
                    {
                        selectedMove = null;
                    }
                }
            }
        }