public string Attack(string[] args)
        {
            string attackerName = args[0];
            string receiverName = args[1];

            CheckIfCharacterExist(attackerName);
            CheckIfCharacterExist(receiverName);

            Character attacker = GetCharacter(attackerName);
            Character receiver = GetCharacter(receiverName);

            if (!typeof(IAttackable).IsAssignableFrom(attacker.GetType()))
            {
                throw new ArgumentException($"{attacker.Name} cannot attack!");
            }

            IAttackable tempAttacker = (IAttackable)attacker;

            tempAttacker.Attack(receiver);

            StringBuilder sb = new StringBuilder();

            sb.AppendLine($"{attacker.Name} attacks {receiver.Name} for {attacker.AbilityPoints} " +
                          $"hit points! {receiver.Name} has {receiver.Health}/{receiver.BaseHealth} HP and {receiver.Armor}/{receiver.BaseArmor} AP left!");

            if (!receiver.IsAlive)
            {
                sb.AppendLine($"{receiver.Name} is dead!");
            }

            return(sb.ToString().TrimEnd('\n', '\r'));
        }
Exemple #2
0
    private void OnCollisionEnter(Collision other)
    {
        if (hitted)
        {
            return;
        }

        hitted = true;

        if (!photonView.IsMine)
        {
            GameObject hittedObj = other.gameObject;
            Debug.Log("On My View it hitted: " + hittedObj);
            if (hittedObj.Equals(Owner))
            {
                Debug.Log("Equals Owner...");
                return;
            }
            IAttackable healthScript = hittedObj.GetComponent(typeof(IAttackable)) as IAttackable;
            if (healthScript != null)
            {
                Debug.Log("HealthScript: " + healthScript);
                healthScript.Attack(damage);
            }
        }
        else
        {
            Debug.Log("On NOT My View it hitted: " + other.gameObject);
            PhotonNetwork.Destroy(gameObject);
        }
    }
Exemple #3
0
    void Explode()
    {
        // Overlap Sphere creates a Sphere with a radius and a pos, and returns every Collider (on a given Layer) that touched that Sphere.
        Collider[] hitColliders = Physics.OverlapSphere(transform.position, explosionRadius, interactionLayer);
        foreach (var hittedObj in hitColliders)
        {
            IAttackable healthScript = hittedObj.GetComponent(typeof(IAttackable)) as IAttackable;
            if (healthScript != null)
            {
                float distance = Utils.getDistanceBetweenGameObjects(hittedObj.gameObject, gameObject);
                float relation = distance / explosionRadius;         // 0 if bomb is close at obj, 1 is bomb is far away.
                healthScript.Attack((1 - relation + 0.2f) * damage); // max Damage 1.2 * Damage, min damage 0.2 * Damage
            }

            Rigidbody r = hittedObj.GetComponent <Rigidbody>();
            if (r)
            {
                // Throw away hit objects
                r.AddExplosionForce(explosionForce, transform.position, explosionRadius, explosionUpModifier);
            }
        }

        GetComponent <AudioSource>().Play();

        // Add Explosion Particles
        exposionEffect = Instantiate(explosionPrefab, transform.position, Quaternion.identity);

        // Make this Object invis.
        gameObject.GetComponent <Renderer>().enabled = false;
        gameObject.GetComponent <Collider>().enabled = false;

        Invoke(nameof(Kill), 3);
        explosionCount++;
    }
Exemple #4
0
        void Attack(Transform target)
        {
            IAttackable targetBody = target.GetComponent <IAttackable>();
            int         accuracy   = UnityEngine.Random.Range(0, 100) + Stats.Accuracy;
            int         damage     = UnityEngine.Random.Range(Stats.MinDamage, Stats.MaxDamage);

            targetBody.Attack(accuracy, damage, name + " attacks.");
        }
    public void OnTriggerEnter2D(Collider2D collision)
    {
        IAttackable attackable = collision.GetComponent <IAttackable>();

        if (attackable != null)
        {
            attackable.Attack(knockbackVector, this.damage, this.knockbackForce);
        }
    }
Exemple #6
0
        private void Battle(IAttackable currentMonster)
        {
            List <string> currentInfo = new List <string>();

            do
            {
                if (RandomUtils.TryPercentage(50))
                {
                    currentInfo.Add(player.Attack(currentMonster));

                    if (currentMonster.IsAlive)
                    {
                        currentInfo.Add(currentMonster.Attack(player));
                    }
                }

                else
                {
                    currentInfo.Add(currentMonster.Attack(player));

                    if (player.IsAlive)
                    {
                        currentInfo.Add(player.Attack(currentMonster));
                    }
                }
            } while (player.IsAlive && currentMonster.IsAlive);



            if (player.IsAlive)
            {
                currentInfo.Add($"{currentMonster.Name} died!");
            }
            else
            {
                currentInfo.Add($"Frappidiclappidido, {currentMonster.Name} killed you!");
            }

            DisplayBattle(currentInfo);

            Thread.Sleep(1500);
            Monster.MonsterCounter--;
        }
 void Update()
 {
     if (Input.GetKeyDown(KeyCode.Mouse0))
     {
         Basic.Attack();
     }
     if (Input.GetKeyDown(KeyCode.Mouse1))
     {
         Skill_2.Attack();
     }
 }
Exemple #8
0
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.F))
        {
            melee.Attack();
        }

        if (Input.GetKeyDown(KeyCode.Mouse0))
        {
            ranged.Attack();
        }
    }
Exemple #9
0
        void Attack(Transform target)
        {
            IAttackable targetBody = target.GetComponent <IAttackable>();

            if (targetBody == null)
            {
                throw new ArgumentException("Target cannot be attacked.");
            }
            Attack       attack        = BuildAttack();
            Defense      targetDefense = targetBody.GetDefense();
            AttackResult result        = AttackResolver.ResolvePhysicalAttack(attack, targetDefense);

            targetBody.Attack(result);
        }
Exemple #10
0
    public void Attack(AttackType attack)
    {
        float mod = 0;

        switch (attack)
        {
        case AttackType.Attack1: mod = 0; break;

        case AttackType.Attack2: mod = 0.5f; break;

        case AttackType.Attack3: mod = 1f; break;
        }
        attacker.Attack(attack, GameController.controller.target, mod);
    }
        private void Bleeding(IAttackable target)
        {
            var Rand = new Random();

            for (int i = 0; i < 10; i++)
            {
                var bleedDamage = Rand.Next(_bleedDamage - _bleedSpread, _bleedDamage + _bleedSpread);
                lock (_bleedLock)
                {
                    target.Attack(bleedDamage);
                }
                Console.WriteLine("The target bleeds for " + bleedDamage + " damage");
                Thread.Sleep(1000);
            }
        }
Exemple #12
0
    // Update is called once per frame
    void Update()
    {
        if (!photonView.IsMine)
        {
            return;
        }

        if (Input.GetButtonDown("Fire1"))
        {
            Ray ray = new Ray(cam.transform.position, cam.transform.forward);
            Debug.DrawLine(ray.origin, ray.GetPoint(maxDist));

            RaycastHit   raycastHit;
            RaycastHit[] raycastHits = Physics.RaycastAll(ray, maxDist, interactionLayer);
            // if (Physics.Raycast(ray, out raycastHit, maxDist, interactionLayer)) {
            Array.Sort(raycastHits, (a, b) => a.distance.CompareTo(b.distance));

            GameObject hittedObj = GetHittedObject(raycastHits);
            if (hittedObj)
            {
                Debug.Log(hittedObj);
                IAttackable healthScript = hittedObj.GetComponent(typeof(IAttackable)) as IAttackable;

                if (healthScript != null)
                {
                    Debug.Log("HealthScript: " + healthScript);
                    healthScript.Attack(damage);
                }
            }

            /*GameObject hittedObj = raycastHit.transform.gameObject;
             * Debug.Log(hittedObj);
             * IAttackable healthScript = hittedObj.GetComponent(typeof(IAttackable)) as IAttackable;
             * Debug.Log("HealthScript: "+healthScript);
             * if (healthScript != null) {
             * healthScript.Attack(damage);
             * }*/
            // }

            /*GameObject bulletInstance = PhotonNetwork.Instantiate(bullet.name, bulletPoint.position, bulletPoint.rotation, 0);
             * bulletInstance.GetComponent<Rigidbody>().AddForce(cam.transform.forward * bulletForce);
             * bulletInstance.GetComponent<BulletScript>().Owner = GameSettings.Instance.playerMovement.gameObject;*/
        }
    }
Exemple #13
0
    public string Attack(string[] args)
    {
        var attackerName = args[0];
        var receiverName = args[1];

        var attacker = this.party.FirstOrDefault(c => c.Name == attackerName);

        if (attacker == null)
        {
            throw new ArgumentException($"Character {attackerName} not found!");
        }
        var receiver = this.party.FirstOrDefault(c => c.Name == receiverName);

        if (receiver == null)
        {
            throw new ArgumentException($"Character {receiverName} not found!");
        }
        IAttackable attackable = null;

        try
        {
            attackable = (IAttackable)attacker;
        }
        catch (Exception)
        {
            throw new ArgumentException($"{attackerName} cannot attack!");
        }

        attackable.Attack(receiver);
        var message = $"{attackerName} attacks " +
                      $"{receiverName} for " +
                      $"{attacker.AbilityPoints} hit points!" +
                      $" {receiverName} has {receiver.Health}/{receiver.BaseHealth} HP and " +
                      $"{receiver.Armor}/{receiver.BaseArmor} AP left!";

        if (receiver.IsAlive)
        {
            return(message);
        }


        return(message + Environment.NewLine + $"{receiverName} is dead!");
    }
Exemple #14
0
 private void OnTriggerEnter2D(Collider2D collision)
 {
     Destroy(image);
     if (collision.gameObject.CompareTag("Player"))
     {
         if (enemy != null)
         {
             enemy.PlayerInAttackArea();
         }
         if (!isOnCooldown)
         {
             attackable.Attack();
             if (coolDownObject != null)
             {
                 coolDownObject.GetComponent <SpriteRenderer>().color = new Color(1, 1, 1, 0);
             }
             isOnCooldown = true;
         }
     }
 }
Exemple #15
0
    public void OnTriggerEnter2D(Collider2D col)
    {
        if (col.transform == player)
        {
            Debug.Log("Self Hit");
            return;
        }

        IAttackable attack = col.GetComponent <IAttackable>();

        if (attack != null)
        {
            OnHit.Invoke();

            Vector2 finalKb = kb;
            finalKb.x *= Mathf.Sign(transform.lossyScale.x);

            attack.Attack(finalKb, damage, force);
        }
    }
        public void Attack(IAttackable target)
        {
            string targetName  = target.Name;
            int    baseAttack  = UnityEngine.Random.Range(0, 100);
            int    totalAttack = baseAttack + Accuracy;
            int    damage      = UnityEngine.Random.Range(MinDamage, MaxDamage);
            string attackFormat;

            if (baseAttack >= 95)  // 5% chance to crit. Hardcoded for now, maybe turn it into a stat later.
            {
                totalAttack *= 10; // Extremely high chance to land a hit when delivering a critical.
                damage      *= CritMultiplier;
                attackFormat = CRITICAL_ATTACK_FORMAT;
            }
            else
            {
                attackFormat = NORMAL_ATTACK_FORMAT;
            }
            target.Attack(totalAttack, damage, string.Format(attackFormat, targetName));
        }
Exemple #17
0
        private bool ChestEncounter(IAttackable monster)
        {
            var encounterResult = false;

            Console.WriteLine("\n\n\nIt's just a chest . . .");
            TextUtils.AnimateText($". . . . . . . . . .{Environment.NewLine}", 100);
            Console.ForegroundColor = ConsoleColor.Red;
            TextUtils.AnimateText($"or is it a Mimic?!", 500);
            player.Attack(monster);
            monster.Attack(player);
            Console.ResetColor();
            Console.ReadKey(true);

            if (monster.Health <= 0)
            {
                encounterResult = true;
            }

            return(encounterResult);
        }
Exemple #18
0
        public string Attack(string[] args)
        {
            string attackerName = args[0];
            string receiverName = args[1];

            Character character = this.party.FirstOrDefault(x => x.Name == attackerName);

            if (character == null)
            {
                throw new ArgumentException($"Character {attackerName} not found!");
            }

            Character receiver = this.party.FirstOrDefault(x => x.Name == receiverName);

            if (receiver == null)
            {
                throw new ArgumentException($"Character {receiverName} not found!");
            }

            if (!(character is IAttackable))
            {
                throw new ArgumentException($"{attackerName} cannot attack!");
            }

            IAttackable attacker = character;

            if (receiver.IsAlive && character.IsAlive)
            {
                attacker.Attack(receiver);
            }

            string result = $"{attackerName} attacks {receiverName} for {character.AbilityPoints} hit points! {receiverName} has " +
                            $"{receiver.Health}/{receiver.BaseHealth} HP and {receiver.Armor}/{receiver.BaseArmor} AP left!";

            if (receiver.IsAlive == false)
            {
                result += $"\n{receiverName} is dead!";
            }

            return(result);
        }
Exemple #19
0
    public void OnAttack()
    {
        Bounds bounds  = attackTrigger.bounds;
        int    barrels = LayerMask.NameToLayer("Barrels");
        int    crates  = LayerMask.NameToLayer("Crates");
        int    enemies = LayerMask.NameToLayer("Enemies");
        int    mask    = 1 << barrels;

        mask |= 1 << crates;
        mask |= 1 << enemies;
        Collider2D collider = Physics2D.OverlapBox(bounds.center, bounds.size, 0, mask);

        if (collider != null)
        {
            IAttackable attackable = collider.gameObject.GetComponent <IAttackable>();
            if (attackable != null)
            {
                attackable.Attack();
            }
        }
    }
Exemple #20
0
    public void Attack(AttackType attack, bool turnAttack = false)
    {
        menuCanvas.gameObject.SetActive(false);
        menuOpen = false;
        if (turnAttack)
        {
            attack = GetNextAttack(personality, lastAttack);
        }

        float mod = 0;

        switch (attack)
        {
        case AttackType.Attack1: mod = 0; break;

        case AttackType.Attack2: mod = 0.5f; break;

        case AttackType.Attack3: mod = 1f; break;
        }
        attacker.Attack(attack, GameController.controller.player, mod);
    }
        public string Attack(string[] args)
        {
            string attackerName = args[0];
            string receiverName = args[1];

            Character attacker = this.GetCharacter(attackerName);
            Character receiver = this.GetCharacter(receiverName);

            if (!attacker.GetType()
                .GetInterfaces()
                .Contains(typeof(IAttackable)))
            {
                throw new ArgumentException($"{attackerName} cannot attack!");
            }

            IAttackable attackableCharacter = (IAttackable)attacker;

            attackableCharacter.Attack(receiver);

            StringBuilder result = new StringBuilder();

            result.AppendFormat("{0} attacks {1} for {2} hit points! {1} has {3}/{4} HP and {5}/{6} AP left!{7}",
                                attackerName,
                                receiverName,
                                attacker.AbilityPoints,
                                receiver.Health,
                                receiver.BaseHealth,
                                receiver.Armor,
                                receiver.BaseArmor,
                                Environment.NewLine);

            if (!receiver.IsAlive)
            {
                result.AppendLine($"{receiverName} is dead!");
            }

            return(result.ToString().TrimEnd());
        }
 void TryMoveTo(Coord coord)
 {
     if (Map.IsWalkable(coord))
     {
         Collider2D collision = CustomRaycast.GetMapEntityColliderAt(coord);
         if (collision != null) // something is in the way
         {
             IAttackable target = collision.GetComponent <IAttackable>();
             if (target != null) // that something can be attacked
             {
                 Defense      defense = target.GetDefense();
                 Attack       attack  = attacker.BuildAttack();
                 AttackResult result  = attackResolver.ResolvePhysicalAttack(attack, defense);
                 target.Attack(result);
                 time.IncreaseBasedOnSpeed(AttackSpeed);
             }
         }
         else
         {
             transform.position = (Vector2)coord;
             time.IncreaseBasedOnSpeed(MoveSpeed);
         }
     }
 }
 public override void Attack(IAttackable target)
 {
     base.Attack(target);
     target.Attack(BonusDamage);
     Console.WriteLine($"{BonusDamage} BONUSDAMAGE!");
 }
Exemple #24
0
 public Attacker(IAttackable attackable, IAttackInput attackInput)
 {
     this.attackable  = attackable;
     this.attackInput = attackInput;
     disposable       = attackInput.OnInputAttackObservable.Subscribe(_ => attackable.Attack());
 }
Exemple #25
0
    void Update()
    {
        if (delay > 0)
        {
            delay -= Time.deltaTime;
        }
        if (delay1 > 0)
        {
            delay1 -= Time.deltaTime;
        }
        if (delay2 > 0)
        {
            delay2 -= Time.deltaTime;
        }

        var     horizontalInput = Input.GetAxis(horizontalAxisName);
        Vector3 moveInput       = Vector3.zero;

        if (isAlive)
        {
            if (Mathf.Abs(horizontalInput) > 0)
            {
                var sign = Mathf.Sign(horizontalInput);
                transform.localScale = new Vector3(sign * scale, scale, 1);
                moveInput            = Vector3.right * horizontalInput * Time.deltaTime * moveSpeed;
                animator.SetBool(walkHash, true);
                if (drink)
                {
                    drink.hasMoved = true;
                }
            }

            if (!IsGrounded() || Mathf.Abs(horizontalInput) == 0)
            {
                animator.SetBool(walkHash, false);
            }

            if (Input.GetButtonDown(meleeButtonName) && delay <= 0 & delay1 <= 0)
            {
                animator.ResetTrigger(meleeHash);
                animator.SetTrigger(meleeHash);
                attack1.Attack();
                delay  = 0.5f;
                delay1 = attack1Delay;
            }

            if (Input.GetButtonDown(rangedButtonName) && delay <= 0 && delay2 <= 0)
            {
                animator.ResetTrigger(rangedHash);
                animator.SetTrigger(rangedHash);
                attack2.Attack();
                delay = 0.5f;
                delay = attack2Delay;
            }

            if (Input.GetButtonDown(jumpButtonName) && delay <= 0 && IsJumpable())
            {
                jumpForce = jumpPower;
            }

            if (transform.position.y < -20)
            {
                GetDamage(1000);
            }
        }
        else
        {
            animator.SetTrigger(idleHash);
        }

        if (!IsGrounded())
        {
            jumpForce -= 30 * Time.deltaTime;
        }

        moveInput.y = Mathf.Clamp(jumpForce * Time.deltaTime, -0.3f, jumpPower);
        controller.Move(moveInput);
    }
        public virtual void Attack(IAttackable target)
        {
            var attack = GetStat <AttackStat>();

            target.Attack(attack.StatValue);
        }