Ejemplo n.º 1
0
    public override void takeDamage(int damage, PersonalityBase personality)
    {
        health -= (int)(damage * defense);
        HealthImage.GetComponent <Image>().fillAmount = health / 100f;
        if (health <= 50 && health > 33)
        {
            HealthImage.GetComponent <Image>().color = new Color(255, 255, 0);
        }
        else if (health <= 33 && health > 0)
        {
            HealthImage.GetComponent <Image>().color = new Color(255, 0, 0);
        }
        else if (health <= 0)
        {
            if (personality.isMonster && !theThing)
            {
                theThing = true;

                HealthImage.GetComponent <Image>().color = new Color(0, 255, 0);

                controller.numberOfMonsters++;
                controller.decreaseHumans();
                Debug.Log("me mata un puto monstruo y me he convertido.\thumanos: " + controller.numberOfHumans + " monstruos: " + controller.numberOfMonsters);
            }
            else
            {
                if (theThing)
                {
                    controller.numberOfMonsters--;
                    if (controller.CheckPlayerWin())
                    {
                        //Debug.Log ("ha devuelto true en win");
                        controller.youWin(true);
                    }
                    else if (controller.CheckPlayerLost())
                    {
                        //Debug.Log ("ha devuelto true en lost");
                        controller.youWin(false);
                    }
                }

                else
                {
                    controller.decreaseHumans();
                }

                Debug.Log("humanos: " + controller.numberOfHumans + " monstruos: " + controller.numberOfMonsters + "muere " + this.name);

                this.GetComponent <VisibilityConeCycleIA>().enabled = false;
                VisibleElements.visibleGameObjects.Remove(this.gameObject);
                string  nameIAdeath     = this.name + "ghost";
                Vector3 IADeathPosition = this.transform.position;

                this.enabled = false;

                var mygroup = this.GetComponent <GroupScript>();

                if (mygroup.groupMembers.Count > 0)
                {
                    if (mygroup.IAmTheLeader)
                    {
                        var members = mygroup.groupMembers;
                        mygroup.ExitGroup();
                        foreach (var m in members)
                        {
                            GroupScript memberGroup = m.GetComponent <GroupScript>();
                            memberGroup.groupLeader = members[0];
                        }
                        members[0].GetComponent <GroupScript>().makeLeader();
                        members[0].GetComponent <PersonalityBase>().formacionGrupo(members[0], members[0].GetComponent <GroupScript>());
                    }
                    else
                    {
                        mygroup.ExitGroup();
                    }
                }

                var IAs = GameObject.FindGameObjectsWithTag("IA");

                foreach (var ia in IAs)
                {
                    var arbol = ia.GetComponent <DecisionTreeCreator>();
                    if (arbol != null)
                    {
                        if (arbol.target == this.gameObject)
                        {
                            Destroy(this.GetComponent <DecisionTreeCreator>());

                            ia.GetComponent <AIPersonality>().oldNodes = ia.GetComponents <DecisionTreeNode>();
                            foreach (var item in ia.GetComponent <AIPersonality>().oldNodes)
                            {
                                DestroyImmediate(item);
                            }
                        }
                    }
                }

                PlayerMenuController menu = controller.GetComponent <PlayerMenuController> ();
                menu.CloseAttackMenu();
                menu.menuConversation.SetActive(false);
                menu.CloseJoinMenu();
                menu.CloseObjectMenu();


                GameObject ghost = new GameObject();
                ghost.AddComponent <SpriteRenderer>();
                ghost.GetComponent <SpriteRenderer>().sprite           = ghostSprite;
                ghost.GetComponent <SpriteRenderer>().sortingLayerName = "Personajes";
                ghost.transform.localScale = new Vector2(5f, 5f);
                ghost.name = nameIAdeath;
                ghost.transform.position = IADeathPosition;


                Destroy(personality.gameObject.GetComponent <Pursue> ());

                this.gameObject.SetActive(false);
                Invoke("DestroyIA", 1f);
            }
        }
    }