Beispiel #1
0
 public Weapon startupEnemyBasicWeapon(int zLayer)
 {
     base.startupGameObject(new Point(17, 15), "Media/twobullets.png", zLayer);
     weaponLogic         = new WeaponLogic(this.basicEnemyWeaponLogic);
     this._collisionName = CollisionIdentifiers.ENEMYWEAPON;
     return(this);
 }
        private void drawLine()
        {
            lineaRenderizar.gameObject.SetActive(true);
            lineaRenderizar.positionCount = 2;
            // lineaRenderizar.SetPosition(0, transform.position);
            startMousePosition   = Input.mousePosition;
            startMousePosition.z = (transform.position.z - Camera.main.transform.position.z);
            startMousePosition   = Camera.main.ScreenToWorldPoint(startMousePosition);
            //lineaRenderizar.SetPosition(1, startMousePosition);
            Vector3 dir  = startMousePosition - transform.position;
            float   dist = Mathf.Clamp(Vector3.Distance(transform.position, startMousePosition), 0, MAX_MOUSE_DISTANCE);

            startMousePosition = transform.position + (dir.normalized * dist);

            lineaRenderizar.SetPositions(new Vector3[] {
                transform.position
                , Vector3.Lerp(transform.position, startMousePosition, 0.9f)
                , Vector3.Lerp(transform.position, startMousePosition, 0.91f)
                , startMousePosition
            });

            float distanceX = Mathf.Abs(lineaRenderizar.GetPosition(1).x - lineaRenderizar.GetPosition(0).x);
            float distanceY = Mathf.Abs(lineaRenderizar.GetPosition(1).y - lineaRenderizar.GetPosition(0).y);


            float potenceDistance = Mathf.Sqrt(Mathf.Pow(distanceX, 2) + Mathf.Pow(distanceY, 2));

            WeaponLogic.setPower(potenceDistance * 10 + 1);
        }
        private void Shoot()
        {
            if (stateHolder.isPlaying())
            {
                if (Input.GetMouseButtonDown(0))
                {
                    startMousePosition = Input.mousePosition;
                }

                if (Input.GetMouseButton(0))
                {
                    Vector3 mouseDelta = Input.mousePosition - startMousePosition;
                    if (mouseDelta.sqrMagnitude < 0.1f)
                    {
                        shootingAngle = getAngle(startMousePosition);// don't do tiny rotations.
                    }
                    else
                    {
                        shootingAngle = getAngle(mouseDelta);
                    }

                    WeaponLogic.ChangeDirection(shootingAngle);
                }

                if (Input.GetMouseButtonUp(0))
                {
                    WeaponLogic.ChangeDirection(shootingAngle);
                    WeaponLogic.Shoot();
                }
            }
        }
Beispiel #4
0
 /// <summary>
 /// Initialisation of the blasting tool
 /// </summary>
 /// <param name="parent">A reference to the GameObject generating the blast</param>
 /// <returns>A reference to the newly created blasting tool</returns>
 public HunterWeapon startupPlayerBasicWeapon(GameObject parent)
 {
     base.startupGameObject(new Point(17, 15), "Media/twobullets.png", ZLayers.PLAYER_Z);
     _player             = parent;
     weaponLogic         = new WeaponLogic(this.moveBlastObject);
     this._collisionName = CollisionIdentifiers.PLAYERWEAPON;
     return(this);
 }
Beispiel #5
0
        public void GetCharacterEquipped(Character character)
        {
            List <Equipped> equippeds = GetAllEquipped();

            foreach (var equipped in equippeds)
            {
                if (equipped.EquppedID == character.ID)
                {
                    //sets weapon
                    WeaponLogic   weaponLogic = new WeaponLogic();
                    List <Weapon> weapons     = weaponLogic.GetAllWeapons();
                    foreach (Weapon weapon in weapons)
                    {
                        if (weapon.ID == equipped.WeaponID)
                        {
                            character.EquipedWeapon = weapon;
                        }
                    }

                    //sets armour
                    ArmourLogic   armourLogic = new ArmourLogic();
                    List <Armour> armours     = armourLogic.GetAllArmours();
                    foreach (Armour armour in armours)
                    {
                        if (armour.ID == equipped.HelmetID)
                        {
                            character.EquipedHelmet = armour;
                        }
                        if (armour.ID == equipped.BodyID)
                        {
                            character.EquipedBody = armour;
                        }
                        if (armour.ID == equipped.LegsID)
                        {
                            character.EquipedLegs = armour;
                        }
                        if (armour.ID == equipped.FeetID)
                        {
                            character.EquipedFeet = armour;
                        }
                    }
                }
            }
        }
        public void GetCharacterWeapons(Character character)
        {
            List <Inventory> inventories = GetAllInventories();
            WeaponLogic      weaponLogic = new WeaponLogic();
            List <Weapon>    weapons     = weaponLogic.GetAllWeapons();

            foreach (var inventory in inventories)
            {
                if (inventory.CharacterID == character.ID)
                {
                    foreach (var weapon in weapons)
                    {
                        if (weapon.ID == inventory.WeaponID)
                        {
                            weapon.Amount = inventory.Amount;
                            character.myWeapons.Add(weapon);
                        }
                    }
                }
            }
        }
 void Start()
 {
     this.WeaponLogic = GetComponent <WeaponLogic>();
 }
Beispiel #8
0
 public override void shutdown()
 {
     base.shutdown();
     weaponLogic = null;
 }
 public void addnewWeapon(WeaponLogic w)
 {
     weapons.Add(w);
 }
Beispiel #10
0
    public void OnConsumeItem(Item item)
    {
        Totem totemActual = GameManager.Instance.totemActual;

        for (int i = 0; i < item.itemAttributes.Count; i++)
        {
            if (item.itemAttributes[i].attributeName == "Vida")
            {
                totemActual.aumentarVida(item.itemAttributes[i].attributeValue);
                Debug.Log("Objeto de vida");
            }


            if (item.itemAttributes[i].attributeName == "Ataque")
            {
                ataqueJugadorActual += item.itemAttributes[i].attributeValue;
            }

            if (item.itemAttributes[i].attributeName == "Cohete")
            {
                totemActual.GetComponent <MovimientoController>().saltar(item.itemAttributes[i].attributeValue);
                Debug.Log("Objeto de Cohete salto " + item.itemAttributes[i].attributeValue);
                GameObject cohete = Instantiate(item.itemModel, totemActual.transform.position, Quaternion.identity) as GameObject;

                cohete.transform.GetChild(0).gameObject.AddComponent <Cohete>();
                cohete.transform.GetChild(0).gameObject.AddComponent <CircleCollider2D>();
                cohete.transform.parent = totemActual.transform;
            }

            // Raig: permet moure's més ràpid i tenir més passos límit.

            if (item.itemAttributes[i].attributeName == "Movimiento")
            {
                totemActual.gameObject.GetComponent <MovimientoController>().VelocidadMovimiento += item.itemAttributes[i].attributeValue;
                Debug.Log("Aumento la velocidad de movimiento en  " + item.itemAttributes[i].attributeValue);
            }

            //Coet: propulsa cap a dalt, mantenint pres el botó de salt es manté més en l'aire (air control).
            //  if (item.itemID== Global.TIPO_OBJETOS.objetoCohete)
            //  {
            //ataqueJugadorActual += item.itemAttributes[i].attributeValue;
            //      totemActual.gameObject.transform.position+=new Vector3(0,50,0);
            //   }
        }

        //Esto en es caso de que ya tengamos activo un angel,escudo, escudo doble o iglu.
        if (totemActual.TieneItemActivo(item.itemID))
        {
            //GameManager.Instance.addTotemItems(totemActual);
            StartCoroutine(GameManager.Instance.AñadirItemHotbar(item.itemID));
            return;
        }
        switch (item.itemID)
        {
        // Bola de teletransport: disparar-la per teletransportar-se a una posició més endavant.
        case Global.TIPO_OBJETOS.objetoTeletransporte:

            //Debug.Log("Objeto de Cohete teletransporte " + item.itemAttributes[i].attributeValue);
            Debug.Log("Objeto de Cohete teletransporte");
            GameObject teletransporte = Instantiate(item.itemModel, totemActual.transform.position, Quaternion.identity) as GameObject;

            teletransporte.transform.GetChild(0).gameObject.AddComponent <Teletransporte>();
            teletransporte.transform.GetChild(0).gameObject.AddComponent <CircleCollider2D>();
            teletransporte.transform.parent = totemActual.transform;
            break;



        case Global.TIPO_OBJETOS.objetoAngel:

            //Debug.Log("Objeto Angel de la Guarda " + item.itemAttributes[i].attributeValue);
            GameObject angel = Instantiate(item.itemModel, totemActual.transform.position, Quaternion.identity) as GameObject;
            angel.GetComponent <SpriteRenderer>().enabled = false;
            //angel.SetActive(false);
            angel.gameObject.AddComponent <Angel>();
            angel.transform.parent = totemActual.transform;
            //totemActual.ActivarAngelGuarda();
            break;


        case Global.TIPO_OBJETOS.objetoIglu:

            GameObject iglu = Instantiate(item.itemModel, totemActual.PosicioPrimerModul(), Quaternion.identity) as GameObject;

            iglu.transform.GetChild(0).gameObject.AddComponent <Iglu>();
            CircleCollider2D circle = iglu.transform.GetChild(0).gameObject.AddComponent <CircleCollider2D>();
            circle.isTrigger      = true;
            iglu.transform.parent = totemActual.transform;
            break;


        case Global.TIPO_OBJETOS.objetoEscudoSimple:

            GameObject escudo = Instantiate(item.itemModel, totemActual.transform.position, Quaternion.identity) as GameObject;
            escudo.transform.position = new Vector3(escudo.transform.position.x + 0.7f, escudo.transform.position.y, escudo.transform.position.z);
            escudo.transform.GetChild(0).gameObject.AddComponent <Escut>();
            BoxCollider2D box = escudo.transform.GetChild(0).gameObject.AddComponent <BoxCollider2D>();
            box.isTrigger           = true;
            escudo.transform.parent = totemActual.transform;
            break;


        case Global.TIPO_OBJETOS.objetoEscudoDoble:

            GameObject escudo_doble = Instantiate(item.itemModel, totemActual.transform.position, Quaternion.identity) as GameObject;
            escudo_doble.transform.GetChild(0).gameObject.AddComponent <EscutDoble>();

            BoxCollider2D     escudo1 = escudo_doble.transform.GetChild(0).gameObject.AddComponent <BoxCollider2D>();
            CapsuleCollider2D escudo2 = escudo_doble.transform.GetChild(0).gameObject.AddComponent <CapsuleCollider2D>();
            escudo1.isTrigger = true;
            escudo2.isTrigger = true;

            escudo1.offset     = new Vector2(-1.17f, -0.5f);
            escudo1.size       = new Vector2(0.88f, 3.42f);
            escudo1.edgeRadius = 0;

            escudo2.offset                = new Vector2(1.18f, -0.5f);
            escudo2.size                  = new Vector2(0.86f, 3.42f);
            escudo2.direction             = CapsuleDirection2D.Vertical;
            escudo_doble.transform.parent = totemActual.transform;

            break;

        /*case Global.TIPO_OBJETOS.objetoCohete:
         *      GameObject cohete = Instantiate (item.itemModel, totemActual.transform.position, Quaternion.identity) as GameObject;
         *      cohete.transform.GetChild (0).gameObject.AddComponent<Cohete> ();
         *      cohete.transform.GetChild (0).gameObject.AddComponent<CircleCollider2D> ();
         *      cohete.transform.parent = totemActual.transform;
         *
         *      break;*/

        case Global.TIPO_OBJETOS.objetoRayo:
            GameObject rayo = Instantiate(item.itemModel, totemActual.transform.position, Quaternion.identity) as GameObject;
            rayo.gameObject.AddComponent <Rayo>();
            rayo.transform.parent = totemActual.transform;
            //rayo.transform.GetChild(0).gameObject.AddComponent<CircleCollider2D>();
            break;

        case Global.TIPO_OBJETOS.objetoBomb:
            WeaponLogic bomb = totemActual.GetComponent <WeaponLogic>();
            bomb.weaponType = "Bomb";
            break;

        case Global.TIPO_OBJETOS.objetoMissile:
            WeaponLogic missile = totemActual.GetComponent <WeaponLogic>();
            missile.weaponType = "Missile";
            break;

        case Global.TIPO_OBJETOS.objetoSemtex:
            WeaponLogic semtex = totemActual.GetComponent <WeaponLogic>();
            semtex.weaponType = "Semtex";
            break;

        case Global.TIPO_OBJETOS.objetoGrenade:
            WeaponLogic grenade = totemActual.GetComponent <WeaponLogic>();
            grenade.weaponType = "Grenade";
            break;
        }
        GameManager.Instance.eliminarItemHotbar(item.itemID);
    }
Beispiel #11
0
        public Character MonsterKilled(Character character, Monster monster)
        {
            //Loops through all monsterdrops to see if defeating this monster offers a chance on one or multiple items
            foreach (MonsterDrop monsterDrop in monsterDropContainerRepository.GetAllMonsterDrops())
            {
                if (monsterDrop.ID == monster.ID)
                {
                    //Picks a random number 1-100. If this numbers is the same or lower as the chance to get it the player will get it
                    //(this way we created a drop system with drops based on percentages).
                    Random random = new Random();
                    int    number = random.Next(1, 100);

                    if (number <= monsterDrop.Chance)
                    {
                        foreach (Drop drop in dropContainerRepository.GetAllDrops())
                        {
                            if (monsterDrop.DropID == drop.DropID)
                            {
                                //If the ID of a item isn't 0 that means it dropped something of that category.
                                //Weapon drop
                                if (drop.WeaponID != 0)
                                {
                                    WeaponLogic   weaponLogic = new WeaponLogic();
                                    List <Weapon> weapons     = weaponLogic.GetAllWeapons();
                                    foreach (Weapon weapon in weapons)
                                    {
                                        if (weapon.ID == drop.WeaponID)
                                        {
                                            bool added = false;
                                            //If character already has the weapon it needs to up the amount by 1.
                                            foreach (Weapon myWeapon in character.myWeapons)
                                            {
                                                if (myWeapon.Name == weapon.Name)
                                                {
                                                    added = true;
                                                    myWeapon.AddToAmount(1);
                                                }
                                            }

                                            //If the weapon wasn't in the inventory already then add a new one:
                                            if (!added)
                                            {
                                                character.myWeapons.Add(weapon);
                                            }
                                        }
                                    }
                                }

                                //Armour drop
                                if (drop.ArmourID != 0)
                                {
                                    ArmourLogic   armourLogic = new ArmourLogic();
                                    List <Armour> armours     = armourLogic.GetAllArmours();
                                    foreach (Armour armour in armours)
                                    {
                                        if (armour.ID == drop.ArmourID)
                                        {
                                            armour.Amount = 1;
                                            character.myArmours.Add(armour);
                                        }
                                    }
                                }

                                //Fish drop
                                if (drop.FishID != 0)
                                {
                                    FishItemLogic   fishItemLogic = new FishItemLogic();
                                    List <FishItem> fishItems     = fishItemLogic.GetAllFishItems();
                                    foreach (FishItem fish in fishItems)
                                    {
                                        if (fish.ID == drop.FishID)
                                        {
                                            fish.Amount = 1;
                                            character.myFishItems.Add(fish);
                                        }
                                    }
                                }

                                //Smithing item drop
                                if (drop.SmithingItemID != 0)
                                {
                                    SmithingItemLogic   smithingItemLogic = new SmithingItemLogic();
                                    List <SmithingItem> smithingItems     = smithingItemLogic.GetAllSmithingItems();
                                    foreach (SmithingItem smithItem in smithingItems)
                                    {
                                        if (smithItem.ID == drop.SmithingItemID)
                                        {
                                            smithItem.Amount = 1;
                                            character.mySmithingItems.Add(smithItem);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            //Calculate how much experience the player got. This is based on the amount of health the defeated monster had.
            int defeatedHP = monster.Health * 3;

            if (character.AttackStyle == AttackStyles.Attack)
            {
                character.AttackExperience = character.AttackExperience + defeatedHP;
            }
            else if (character.AttackStyle == AttackStyles.Defence)
            {
                character.DefenceExperience = character.DefenceExperience + defeatedHP;
            }
            else if (character.AttackStyle == AttackStyles.Strength)
            {
                character.StrengthExperience = character.StrengthExperience + defeatedHP;
            }

            //You always get hitpoints exp for defeating a monster.
            character.HitpointsExperience = character.HitpointsExperience + monster.Health;

            //See if the killed monster was the slayer task of the player. If so we need to withdraw 1 monster from the amount of kills needed and give slayer experience.
            if (character.SlayerMonsterID == monster.ID)
            {
                character.SlayerExperience     = character.SlayerExperience + defeatedHP;
                character.SlayerMonsterAmount -= 1;
                if (character.SlayerMonsterAmount == 0)
                {
                    character.SlayerMonsterID   = 0;
                    character.SlayerMonsterName = null;
                }
            }

            //Sets correct levels before passing character back. If in the process of defeating a mosnter
            //One on multiple skills levelled up this will also be passed.
            SkillLogic skillLogic = new SkillLogic();

            skillLogic.SetCorrectLevels(character);

            return(character);
        }
Beispiel #12
0
        public Character EquipWeapon(Character character, int weaponID)
        {
            bool needToAddAmountToCurrentWeapon = false;

            //If the player currently has a weapon equipped it needs to return to the inventory first
            if (character.EquipedWeapon != null)
            {
                //Loops through all items in inventory so we can add 1 to ammount if it's an item we already have in the inventory
                foreach (Weapon weapon in character.myWeapons)
                {
                    //The item is already in the inventory, this means we need to add the amount of this weapon by 1
                    if (weapon.ID == character.EquipedWeapon.ID)
                    {
                        needToAddAmountToCurrentWeapon = true;
                        weapon.AddToAmount(1);
                    }
                }
            }

            //We didn't add amount by 1 to an item so we need to add the currently equipped weapon to the list as a new weapon
            if (!needToAddAmountToCurrentWeapon)
            {
                if (character.EquipedWeapon != null)
                {
                    Weapon weaponToAdd = character.EquipedWeapon;
                    weaponToAdd.Amount = 1;
                    character.myWeapons.Add(weaponToAdd);
                }
            }

            bool removeWeapon      = false;
            int  removeWeaponIndex = 0;

            WeaponLogic weaponLogic = new WeaponLogic();
            //Gets all weapons
            List <Weapon> weapons = weaponLogic.GetAllWeapons();

            foreach (Weapon weapon in weapons)
            {
                if (weapon.ID == weaponID)
                {
                    character.EquipedWeapon = weapon;
                    foreach (Weapon myWeapon in character.myWeapons)
                    {
                        if (myWeapon.ID == weaponID)
                        {
                            myWeapon.Amount -= 1;

                            if (myWeapon.Amount == 0)
                            {
                                removeWeapon      = true;
                                removeWeaponIndex = character.myWeapons.IndexOf(myWeapon);
                            }
                        }
                    }
                }
            }

            if (removeWeapon)
            {
                List <Weapon> newWeapons = character.myWeapons;
                newWeapons.RemoveAt(removeWeaponIndex);
                character.myWeapons = newWeapons;
            }

            return(character);
        }
Beispiel #13
0
        public Character SmithItem(Character character, string barName, string itemCraftName, int barAmountToDistract)
        {
            //First we need to remove the amount of bars from the player that is needed to craft this item.
            bool removedBars = false;

            foreach (SmithingItem mySmithingItem in character.mySmithingItems)
            {
                if (mySmithingItem.Name == barName)
                {
                    if (mySmithingItem.Amount >= barAmountToDistract)
                    {
                        mySmithingItem.AddToAmount(-barAmountToDistract);
                        removedBars = true;
                    }
                }
            }

            if (removedBars)
            {
                string itemToMake = barName.Replace(" bar", "");
                itemToMake = itemToMake + " " + itemCraftName;

                //If the removal of the bars from the player was a succes we can now make and add the item to the players inventory.
                //This can either be a piece of armour or a weapon so we need to check both.
                WeaponLogic weaponLogic = new WeaponLogic();
                bool        weaponAdded = false;
                foreach (Weapon weapon in weaponLogic.GetAllWeapons())
                {
                    //First we check if this is the item that we need to add to our inventory for every weapon.
                    if (weapon.Name == itemToMake)
                    {
                        //If the player already has this item we can add 1 to the amount.
                        foreach (Weapon myWeapon in character.myWeapons)
                        {
                            //We already have this weapon
                            if (myWeapon.Name == itemToMake)
                            {
                                myWeapon.Amount += 1;
                                character.SmithingExperience += 10;
                                weaponAdded = true;
                            }
                        }

                        //If the player doesn't have this item yet we can create it.
                        if (weapon.Name == itemToMake && !weaponAdded)
                        {
                            weapon.Amount = 1;
                            character.myWeapons.Add(weapon);
                            weaponAdded = true;
                        }
                    }
                }

                bool        armourAdded = false;
                ArmourLogic armourLogic = new ArmourLogic();
                foreach (Armour armour in armourLogic.GetAllArmours())
                {
                    //First we check if this is the item that we need to add to our inventory for every piece of armour.
                    if (armour.Name == itemToMake)
                    {
                        //If the player already has this item we can add 1 to the amount.
                        foreach (Armour myArmour in character.myArmours)
                        {
                            //We already have this weapon
                            if (myArmour.Name == itemToMake)
                            {
                                myArmour.Amount += 1;
                                character.SmithingExperience += 10;
                                armourAdded = true;
                            }
                        }

                        //If the player doesn't have this item yet we can create it.
                        if (armour.Name == itemToMake && !armourAdded)
                        {
                            armour.Amount = 1;
                            character.myArmours.Add(armour);
                            armourAdded = true;
                        }
                    }
                }
            }

            return(character);
        }