Esempio n. 1
0
        private void Respawn(NetworkViewID viewID)
        {
            GameObject    obj       = PlayerRegistrar.Instance.List[viewID].GameObject;
            GameObject    container = obj.transform.parent.gameObject;
            EntityManager em        = obj.GetComponent <EntityManager>();

            if (container == SceneHelper.GetContainer(Container.Pokemons))
            {
                // Once the entity is ready, we make it appear.
                obj.SetActive(true);

                PokemonController controller = obj.GetComponent <PokemonController>();

                if (em == null)
                {
                    Destroy(SceneHelper.GetContainer(Container.Wild));
                }

                // Visual setters
                obj.transform.position = em.team % 2 == 0 ? GameInfo.redTeamSpawn : GameInfo.blueTeamSpawn;
                obj.transform.rotation = Quaternion.identity;
                controller.nav.ResetPath();
                controller.ResetMovingRestrictions();

                // Logical setters
                controller.selectedMove = null;
                em.Respawn();
            }
            else if (container == SceneHelper.GetContainer(Container.Wild))
            {
                obj.SetActive(true);
                em.currentHP = em.maxHP;
            }
        }
Esempio n. 2
0
        private void ShareFogVision()
        {
            GameObject playerPokemon = GameObject.FindWithTag("CameraTarget");

            if (playerPokemon == null)
            {
                Debug.LogError("Error: Pokemon not registered.");
            }
            else
            {
                int myTeam = playerPokemon.GetComponent <EntityManager>().team;

                foreach (EntityManager em in SceneHelper.GetContainer(Container.Entities).GetComponentsInChildren <EntityManager>())
                {
                    GameObject entity = em.gameObject;

                    if (em.team == myTeam)
                    {
                        if (entity.GetComponent <FOWRevealer>() == null)
                        {
                            FOWRevealer fow = entity.AddComponent <FOWRevealer>();
                            fow.range            = new Vector2(0.5f, 40f);
                            fow.lineOfSightCheck = FOWSystem.LOSChecks.EveryUpdate;
                        }
                    }
                    else
                    {
                        if (entity.GetComponent <FOWRenderers>() == null)
                        {
                            entity.AddComponent <FOWRenderers>();
                        }
                    }
                }
            }
        }
Esempio n. 3
0
        public void GetAvailableTargets()
        {
            Transform[] transformList = SceneHelper.GetContainer(Container.Pokemons).GetComponentsInChildren <Transform>();
            this.availableTarget.Clear();

            foreach (Transform tr in transformList)
            {
                if (tr.parent != SceneHelper.GetContainer(Container.Pokemons).transform)
                {
                    continue;
                }

                PokemonController controller = (PokemonController)tr.gameObject.GetComponent(typeof(PokemonController));
                if (controller == null)
                {
                    continue;
                }

                float distance = Vector3.Distance(this.position, tr.position);
                if (distance - controller.nav.radius < this.range)
                {
                    this.availableTarget.Add(controller);
                }
            }
        }
Esempio n. 4
0
        // Use this for initialization
        void Start()
        {
            entityList = SceneHelper.GetContainer(Container.Entities).transform;

            handPos        = new Vector2(9f, 12f);
            singlePos      = new Vector2(24f, 24f);
            singleAllyPos  = new Vector2(24f, 24f);
            singleEnemyPos = new Vector2(24f, 24f);

            groundPlane = new Plane(Vector3.up, Vector3.forward);

            GetControllerInfos();
        }
Esempio n. 5
0
        void Start()
        {
            pkmn = SceneHelper.GetContainer(Container.Pokemons);

            if (IsServer || Application.platform == RuntimePlatform.LinuxPlayer)            // If this is Lucas' server, then we launch the server. Otherwise, we launch a client (that may become a server later).
            {
                StartServer();
            }
            else
            {
                JoinServer();
            }
        }
Esempio n. 6
0
    private void Start()
    {
        instance = this;

        entitiesList = SceneHelper.GetContainer(Container.Entities).transform;

        GameObject terrainObj = GameObject.Find("Map");

        terrain      = (Terrain)terrainObj.GetComponent(typeof(Terrain));
        treeRenderer = terrain.terrainData.treePrototypes[0].prefab.GetComponent <Renderer>();

        shaderNormal = Shader.Find("Diffuse");
        shaderToon   = Shader.Find("Toon/Lighted Outline");

        shadingMode = initialShadingMode;
        newMode     = shadingMode;
        ApplyShadingMode();
    }
    /// <summary>
    /// Automatically called when a particle has "Send collision messages" set up.
    /// </summary>
    /// <param name="victim">The struck entity.</param>
    private void OnParticleCollision(GameObject victim)
    {
        if (Network.isServer)
        {
            sendsCollisionMessages = true;

            if (victim == manager.caster.GameObject)
            {
                return;
            }

            if (victim.transform.parent.parent.gameObject != SceneHelper.GetContainer(Container.Entities))
            {
                return;
            }

            if (!manager.hitTargetList.Contains(victim))
            {
                manager.HasCollided(victim);
            }
        }
    }
Esempio n. 8
0
        private void Kill(NetworkViewID victimViewID, NetworkViewID killerViewID)
        {
            GameObject victim    = NetworkView.Find(victimViewID).gameObject;
            GameObject container = victim.transform.parent.gameObject;

            if (killerViewID != NetworkViewID.unassigned)
            {
                EntityManager killer = NetworkView.Find(killerViewID).gameObject.GetComponent <EntityManager>();
                killer.GrantKill();
            }

            if (container == SceneHelper.GetContainer(Container.Pokemons) ||
                container == SceneHelper.GetContainer(Container.Wild))
            {
                victim.SetActive(false);
            }
            else
            {
                //obj.SetActive(false);
                Destroy(victim);                 // A robot or a wild monster should be dead for good and not respawn; a new instance should be made instead.
            }
        }
Esempio n. 9
0
        /// <summary>
        /// The Reaper is told that an entity just died.
        /// It then kill the entity, gives gold/experience and prepares the entity respawn.
        /// We should also get the list of the entities that killed this one.
        /// </summary>
        /// <param name="em">EntityManager.</param>
        public void NoticeDeath(EntityManager em, EntityManager killer)
        {
            if (Network.isServer)
            {
                GameObject   container    = em.transform.parent.gameObject;
                MatchManager matchManager = GetComponent <MatchManager>();

                if (matchManager != null)
                {
                    matchManager.AddKill(em.team);
                }

                GetComponent <NetworkView>().RPC("Kill", RPCMode.AllBuffered, em.GetComponent <NetworkView>().viewID, (killer == null ? NetworkViewID.unassigned : killer.GetComponent <NetworkView>().viewID));

                if (container == SceneHelper.GetContainer(Container.Pokemons))
                {
                    respawnQueue.Add(em.GetComponent <NetworkView>().viewID, 3f);
                }
                else if (container == SceneHelper.GetContainer(Container.Wild))
                {
                    //respawnQueue.Add(viewID, 1.5f);
                }
            }
        }
Esempio n. 10
0
        public void Start()
        {
            entityManager = GetComponent <EntityManager>();

            if (int.TryParse(name.Split('-') [0], out pokedex_id))
            {
                Debug.LogError("The GameObject's name doesn't contain the Pokedex ID");
            }

            for (int statID = 0; statID < (int)StatsList.COUNT; statID++)            // Assignment of the base stats.
            {
                entityManager.stats.baseStats[statID] = Pokedex.pokemons[pokedex_id].Statistics.baseStats[statID];
            }

            entityManager.stats.levelingRate = Pokedex.pokemons[pokedex_id].LevelingSpeed;

            anim = GetComponent <Animator>();
            nav  = GetComponent <NavMeshAgent>();

            marker = null;

            nav.autoRepath     = true;
            nav.updateRotation = false;          // We manage the rotation ourselves.
            nav.autoBraking    = false;          // This is less fancy, but more "accurate" for the player.

            laserSource = transform.Find("Armature/" + laserSourcePath);

            hoverEntity = null;

            int i = pokedex_id % 3;

            switch (i)
            {
            case 0:
                moveSet.Add("Surf");
                moveSet.Add("Bubble");
                moveSet.Add("Waterfall");
                moveSet.Add("Icicle Crash");
                break;

            case 1:
                moveSet.Add("Flamethrower");
                moveSet.Add("Poison Gas");
                moveSet.Add("Poison Sting");
                moveSet.Add("Venoshock");
                break;

            case 2:
                moveSet.Add("Gust");
                moveSet.Add("Hurricane");
                moveSet.Add("Thunder Shock");
                moveSet.Add("Razor Leaf");
                break;
            }

            selectedMove = null;

            /*currentHP = maxHP;
             * savedDestination = new Vector3();*/

            this.gameObject.transform.parent = SceneHelper.GetContainer(Container.Pokemons).transform;

            Celshading.instance.ApplyShadingMode();
            ShareFogVision(); // This shouldn't be within this script.
        }
Esempio n. 11
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;
                    }
                }
            }
        }
 protected void Start()
 {
     entitiesContainer = SceneHelper.GetContainer(Container.Entities);
     collisionParticle = this.GetComponent <ParticleSystem>();
 }
Esempio n. 13
0
        private void DisplayHealthBars()
        {
            Transform pokemonArray = SceneHelper.GetContainer(Container.Pokemons).transform;
            SortedList <int, Transform> pokemonSortedList = new SortedList <int, Transform>();

            /*
             * We sort the Pokemons according to their distance to the eye so the life bar of the closest Pokemon appears
             * in the foreground and overrides the ones of the farther Pokemons.
             * The security offset is just here in case we find 2 Pokemons at the exact same distance.
             * In that case, it would add twice the same key in the SortedList and we don't want that.
             */

            int securityOffset = 0;

            foreach (Transform tr in pokemonArray)
            {
                int dist = (int)(-1000f * Vector3.Distance(tr.position, cam.transform.position)) - ++securityOffset;
                pokemonSortedList.Add(dist, tr);
            }

            IList <Transform> pkmnList = pokemonSortedList.Values;

            int i = 0;

            foreach (Transform tr in pkmnList)
            {
                // Securities.
                if (tr.parent != SceneHelper.GetContainer(Container.Pokemons).transform)
                {
                    continue;
                }

                if (!tr.GetComponentInChildren <SkinnedMeshRenderer>().enabled)
                {
                    continue;
                }

                EntityManager em = tr.GetComponent <EntityManager>();
                if (em == null)
                {
                    continue;
                }

                // Z index management.
                GUI.depth = ++i;

                // We get the right health bar texture.
                if (em.team == 1)
                {
                    healthBarTexture = healthBar1Texture;
                }
                else if (em.team == 2)
                {
                    healthBarTexture = healthBar2Texture;
                }

                // We get the right health pattern texture.
                float HPpercentage = em.currentHP / em.maxHP;
                if (HPpercentage > 0.5)
                {
                    healthPatternTexture = healthPatternHighTexture;
                }
                else if (HPpercentage > 0.2)
                {
                    healthPatternTexture = healthPatternMediumTexture;
                }
                else
                {
                    healthPatternTexture = healthPatternLowTexture;
                }

                // We display the health bar.
                pos = cam.WorldToScreenPoint(tr.position + 3 * cam.transform.up);
                Rect rectHealthBar = new Rect(pos.x - healthBarTexture.width / 2, Screen.height - pos.y, healthBarTexture.width, healthBarTexture.height);
                GUI.DrawTexture(rectHealthBar, healthBarTexture);

                // We display the amount of HP.
                Rect rectHealthPattern = new Rect();
                int  displayOffset     = 3 + (24 * (em.team % 2));
                rectHealthPattern.x      = rectHealthBar.x + displayOffset;
                rectHealthPattern.y      = rectHealthBar.y + 3;
                rectHealthPattern.width  = healthPatternMaxWidth * em.currentHP / em.maxHP;
                rectHealthPattern.height = healthPatternTexture.height;
                GUI.DrawTexture(rectHealthPattern, healthPatternTexture);

                // We display the name (device name) of the player.
                rectHealthBar.y -= 20f;
                GUI.Label(rectHealthBar, SystemInfo.deviceName);

                // We display the level of the Pokemon.
                rectHealthBar.x += 114 - 108 * (em.team % 2);
                rectHealthBar.y += 23;
                GUI.Label(rectHealthBar, em.stats.lvl.ToString());
            }
        }
Esempio n. 14
0
        public void DisplayHealth()
        {
            Transform[] transformList = SceneHelper.GetContainer(Container.Pokemons).GetComponentsInChildren <Transform>();
            Texture     healthPatternTexture;

            posTeam1.Set(50, 0);
            posTeam2.Set(Screen.width - 96 - 50, 0);
            Vector2 pos     = new Vector2(0, 0);
            Texture texture = new Texture();

            foreach (var playerPokemon in PlayerRegistrar.Instance.List)
            {
                Transform tr = playerPokemon.Value.GameObject.transform;

                if (tr.parent != SceneHelper.GetContainer(Container.Pokemons).transform)
                {
                    continue;
                }

                PokemonController controller = (PokemonController)tr.gameObject.GetComponent(typeof(PokemonController));
                EntityManager     em         = tr.GetComponent <EntityManager>();
                if (controller == null)
                {
                    continue;
                }

                if (em.team == 1)
                {
                    texture = (Texture)Resources.Load("Portraits/Mirror/pokemon_mirror_" + controller.pokedex_id);
                    pos     = posTeam1;
                    posTeam1.Set(posTeam1.x + texture.width + 1, posTeam1.y);
                }
                else if (em.team == 2)
                {
                    texture = (Texture)Resources.Load("Portraits/Front/pokemon_front_" + controller.pokedex_id);
                    pos     = posTeam2;
                    posTeam2.Set(posTeam2.x - texture.width - 1, posTeam2.y);
                }

                float HPpercentage = em.currentHP / em.maxHP;
                if (HPpercentage > 0.5)
                {
                    healthPatternTexture = healthPatternHighTexture;
                }
                else if (HPpercentage > 0.2)
                {
                    healthPatternTexture = healthPatternMediumTexture;
                }
                else
                {
                    healthPatternTexture = healthPatternLowTexture;
                }

                Rect rectHealthBar = new Rect(pos.x, pos.y, texture.width, healthPatternEmptyTexture.height);
                GUI.DrawTexture(rectHealthBar, healthPatternEmptyTexture);

                if (tr.gameObject.activeSelf && tr.GetComponentInChildren <SkinnedMeshRenderer>().enabled)
                {
                    Rect rectHealthPattern = new Rect(pos.x, pos.y, texture.width * em.currentHP / em.maxHP, healthPatternTexture.height);
                    GUI.DrawTexture(rectHealthPattern, healthPatternTexture);
                }

                Rect rectPortrait = new Rect(pos.x, pos.y + healthPatternEmptyTexture.height, texture.width, texture.height);
                GUI.DrawTexture(rectPortrait, texture);
            }
        }