Пример #1
0
 protected override void BehaveCore(BehaviorCondition cond, RealmTime?time, object state)
 {
     if (cond == BehaviorCondition.OnDeath)
     {
         if (!Host.Self.BagDropped)
         {
             DamageCounter counter = (Host as Enemy).DamageCounter;
             var           dat     = counter.GetPlayerData();
             Dictionary <Player, List <Item> > items = new Dictionary <Player, List <Item> >();
             ProcessPublicBags(rand, dat);
             if (Host.Self.Owner.Name == "Battle Arena")
             {
                 if (rand.Next(1, 3) == 1)
                 {
                     ProcessSoulBags(rand, dat);
                 }
             }
             else
             {
                 ProcessSoulBags(rand, dat);
             }
             Host.Self.BagDropped = true;
         }
     }
 }
Пример #2
0
 public void Death(RealmTime time)
 {
     DamageCounter.Death(time);
     CurrentState?.OnDeath(new BehaviorEventArgs(this, time));
     OnDeath?.Invoke(this, new BehaviorEventArgs(this, time));
     Owner.LeaveWorld(this);
 }
Пример #3
0
 public Enemy(RealmManager manager, ushort objType)
     : base(manager, objType, new wRandom())
 {
     stat    = ObjectDesc.MaxHP == 0;
     counter = new DamageCounter(this);
     Name    = ObjectDesc.ObjectId;
 }
Пример #4
0
 public Enemy(RealmManager manager, ushort objType)
     : base(manager, objType, new wRandom())
 {
     stat    = ObjectDesc.MaxHP == 0;
     MaxHP   = ObjectDesc.MaxHP;
     Defense = ObjectDesc.Defense;
     counter = new DamageCounter(this);
 }
Пример #5
0
    //AttemptMove overrides the AttemptMove function in the base class MovingObject
    //AttemptMove takes a generic parameter T which for Player will be of the type Wall, it also takes integers for x and y direction to move in.
    protected override void AttemptMove <T>(int xDir, int yDir)
    {
        //Hit allows us to reference the result of the Linecast done in Move.
        RaycastHit2D hit;

        if (Move(xDir, yDir, out hit))
        {
            GenerateTerrain(xDir, yDir);

            playerDirection = new Vector2(xDir, yDir);

            playerIcon.position = playerIcon.position + new Vector3(xDir, yDir, 0) * moveScaleFactor;

            //SoundManager.instance.RandomizeSfx(moveSound1, moveSound2);

            if (equippedSkill == -2 || equippedSkill == -3)//Skills that require an enemy be the target
            {
                equippedSkill = -1;
                Text instance = Instantiate(dialogueText);
                instance.gameObject.GetComponent <FadeOut>().SetColorAndText("No enemy is attacked.", Color.white);
            }
            else if (equippedSkill == -5)//Healing
            {
                equippedSkill = -1;
                Text instance = Instantiate(dialogueText);
                instance.gameObject.GetComponent <FadeOut>().SetColorAndText("You patch your wounds.", Color.white);
                int heal = playerStat.maxHealth / 4;
                playerStat.health = Mathf.Clamp((playerStat.health + heal), 0, playerStat.maxHealth);
                playerStat.focus -= 5;

                DamageCounter damageCounter = (Instantiate(canvasGroup, gameObject.transform.position, Quaternion.identity) as GameObject).GetComponent <DamageCounter>();
                damageCounter.setDamage(heal);
                damageCounter.GetComponentInChildren <Image>().color = Color.green;
            }

            if (playerStat.health < playerStat.maxHealth)//Naturally heal 1 health during a move
            {
                playerStat.health += 1;
                if (waitCounter > 3)
                {
                    playerStat.health += waitCounter;
                }
            }
            UpdateFocus(1);
        }
        else
        {
            T hitComponent = hit.transform.GetComponent <T>();
            OnCantMove(hitComponent);
        }

        UpdateHealth();    //Update health GUI

        CheckIfGameOver(); //The player could have potentially died in the last turn.

        //Set the playersTurn boolean of GameManager to false now that players turn is over.
        GameManager.instance.playersTurn = false;
    }
Пример #6
0
    /// <summary>
    /// Bypasses armor and damages player
    /// </summary>
    public void DamagePlayerDirectly(int damage)
    {
        base.TakeDamage(damage);
        DamageCounter instance = Instantiate(damageCounterPrefab, transform);

        instance.SetText(damage.ToString());
        animator.SetTrigger("damage");
        UpdateStats();
    }
Пример #7
0
 public Enemy(ushort objType, bool npc)
     : base(objType, new wRandom())
 {
     npc       = Npc;
     stat      = ObjectDesc.MaxHP == 0;
     counter   = new DamageCounter(this);
     LootState = "";
     Name      = ObjectDesc.ObjectId;
     Done      = false;
 }
Пример #8
0
 private void Awake()
 {
     if (instance != null)
     {
         Debug.LogWarning("More than one DamageCounter Instance!!!");
         Destroy(gameObject);
         return;
     }
     instance = this;
 }
Пример #9
0
    public int GetFinalDamage(DefenseInfo di, out bool isCriticalHit, ActionController target)
    {
        int ret = 0;

        ret = DamageCounter.Result(_attackInfo, di, out isCriticalHit, _owner, target);
        if (isCriticalHit && _owner.IsPlayerSelf)
        {
            _owner.IsCriticalHit = isCriticalHit;
        }
        return(ret);
    }
Пример #10
0
 protected override void BehaveCore(BehaviorCondition cond, RealmTime?time, object state)
 {
     if (cond == BehaviorCondition.OnDeath)
     {
         DamageCounter counter = (Host as Enemy).DamageCounter;
         var           dat     = counter.GetPlayerData();
         Dictionary <Player, List <Item> > items = new Dictionary <Player, List <Item> >();
         ProcessPublicBags(rand, dat);
         ProcessSoulBags(rand, dat);
     }
 }
Пример #11
0
        public int Damage(Player from, RealmTime time, int dmg, bool noDef, params ConditionEffect[] effs)
        {
            if (stat)
            {
                return(0);
            }
            if (HasConditionEffect(ConditionEffects.Invincible))
            {
                return(0);
            }
            if (!HasConditionEffect(ConditionEffects.Paused) &&
                !HasConditionEffect(ConditionEffects.Stasis))
            {
                var def = this.ObjectDesc.Defense;
                if (noDef)
                {
                    def = 0;
                }
                dmg = (int)StatsManager.GetDefenseDamage(this, dmg, def);
                int effDmg = dmg;
                if (effDmg > HP)
                {
                    effDmg = HP;
                }
                if (!HasConditionEffect(ConditionEffects.Invulnerable))
                {
                    HP -= dmg;
                }
                ApplyConditionEffect(effs);
                Owner.BroadcastPacketNearby(new Damage()
                {
                    TargetId     = this.Id,
                    Effects      = 0,
                    DamageAmount = (ushort)dmg,
                    Kill         = HP < 0,
                    BulletId     = 0,
                    ObjectId     = from.Id
                }, this, null, PacketPriority.Low);

                DamageCounter.HitBy(from, time, null, dmg);

                if (HP < 0 && Owner != null)
                {
                    Death(time);
                }

                return(effDmg);
            }
            return(0);
        }
Пример #12
0
 public int GetFinalDamage(DefenseInfo di, out bool isCriticalHit, ActionController target)
 {
     isCriticalHit = false;
     if (_enableDamage)
     {
         int ret = 0;
         ret = DamageCounter.Result(_attackInfo, di, out isCriticalHit, _owner, target);
         if (isCriticalHit)
         {
             _owner.IsCriticalHit = isCriticalHit;
         }
         return(ret);
     }
     return(0);
 }
Пример #13
0
 public void dealDamage(DamageEffect damage, GameObject cause = null)
 {
     EntityView.SetHealth(EntityView.GetHealth() - damage.damageTaken);
     EntityView.SetShields(EntityView.GetShields() - damage.shieldBlocked);
     if (damage.damageTaken > 0)
     {
         GameObject go = Instantiate(damageCounterPrefab);
         go.transform.position = new Vector3(transform.position.x, transform.position.y + 15, transform.position.z);
         DamageCounter counter = go.GetComponent <DamageCounter>();
         counter.Damage = damage.damageTaken;
     }
     if (shields != null && damage.shieldBlocked > 0)
     {
         shields.ShieldHit(damage);
     }
 }
Пример #14
0
        public override bool HitByProjectile(Projectile projectile, RealmTime time)
        {
            if (stat)
            {
                return(false);
            }
            if (HasConditionEffect(ConditionEffects.Invincible))
            {
                return(false);
            }
            if (projectile.ProjectileOwner is Player &&
                !HasConditionEffect(ConditionEffects.Paused) &&
                !HasConditionEffect(ConditionEffects.Stasis))
            {
                var def = this.ObjectDesc.Defense;
                if (projectile.ProjDesc.ArmorPiercing)
                {
                    def = 0;
                }
                int dmg = (int)StatsManager.GetDefenseDamage(this, projectile.Damage, def);
                if (!HasConditionEffect(ConditionEffects.Invulnerable))
                {
                    HP -= dmg;
                }
                ApplyConditionEffect(projectile.ProjDesc.Effects);
                Owner.BroadcastPacketNearby(new Damage()
                {
                    TargetId     = this.Id,
                    Effects      = projectile.ConditionEffects,
                    DamageAmount = (ushort)dmg,
                    Kill         = HP < 0,
                    BulletId     = projectile.ProjectileId,
                    ObjectId     = projectile.ProjectileOwner.Self.Id
                }, this, (projectile.ProjectileOwner as Player), PacketPriority.Low);

                DamageCounter.HitBy(projectile.ProjectileOwner as Player, time, projectile, dmg);

                if (HP < 0 && Owner != null)
                {
                    Death(time);
                }
                return(true);
            }
            return(false);
        }
Пример #15
0
    /// <summary>
    /// Applies damage effects to indicate to the player that damage is happening!
    /// </summary>
    /// <param name="damage"></param>
    public void ApplyDamageEffects(int damage)
    {
        SpawnDamageParticles();
        if (damage >= maxHealth.GetValue() / 2f)
        {
            CameraShaker.Instance.ShakeOnce(1f, 1f, 0.0f, 0.3f);
            SoundManager.Instance.PlayRandomizedPitch(SoundDatabase.Instance.PlayerHighAttack);
        }
        else
        {
            SoundManager.Instance.PlayRandomizedPitch(SoundDatabase.Instance.PlayerAttack);
        }
        DamageCounter instance = Instantiate(damageCounterPrefab);

        instance.SetText(damage.ToString());
        instance.transform.position = transform.position;
        animator.SetTrigger("damage");
        healthSlider.value = health / maxHealth.GetValue() * 100;
    }
Пример #16
0
    //LoseFood is called when an enemy attacks the player.
    //It takes a parameter loss which specifies how many points to lose.
    public void LoseFood(int loss)
    {
        waitCounter = 0;

        SoundManager.instance.RandomizeSfx(hitSound, hitSound2, hitSound3);

        //Subtract lost food points from the players total.
        loss = loss - playerStat.defence;
        if (loss < 0)
        {
            loss = 0;
        }
        playerStat.health -= loss;
        UpdateFocus(-1);

        //Add a damage counter to show damage taken
        DamageCounter damageCounter = (Instantiate(canvasGroup, gameObject.transform.position, Quaternion.identity) as GameObject).GetComponent <DamageCounter>();

        damageCounter.setDamage(Mathf.Clamp(loss, 0, loss));
        damageCounter.GetComponentInChildren <Image>().color = Color.red;
        if ((double)loss / (double)playerStat.maxHealth > 0.5)
        {
            damageCounter.GetComponentInChildren <Image>().color = Color.HSVToRGB(0.08f, 1, 1);
            SoundManager.instance.PlaySingle(hitSound4);
        }
        else
        {
            SoundManager.instance.RandomizeSfx(hitSound, hitSound2, hitSound3);
        }

        //Updates health
        UpdateHealth();

        //Check to see if game has ended.
        CheckIfGameOver();
    }
Пример #17
0
 public Enemy(short objType)
     : base(objType, new wRandom())
 {
     stat    = ObjectDesc.MaxHp == 0;
     counter = new DamageCounter(this);
 }
 internal void Return(DamageCounter damageCounter)
 {
     availableDamageCounters.Push(damageCounter);
 }
Пример #19
0
    public void DamageWall(int loss)
    {
        loss = loss - defence;
        if (loss < 0)
        {
            loss = 0;
        }
        hp -= loss;

        //Add a damage counter to show damage taken
        DamageCounter damageCounter = (Instantiate(canvasGroup, gameObject.transform.position, Quaternion.identity) as GameObject).GetComponent <DamageCounter>();

        damageCounter.setPosition(gameObject.transform.position);
        damageCounter.setDamage(Mathf.Clamp(loss, 0, loss));
        damageCounter.GetComponentInChildren <Image>().color = Color.red;
        if ((double)loss / (double)maxHp > 0.5)
        {
            damageCounter.GetComponentInChildren <Image>().color = Color.HSVToRGB(0.08f, 1, 1);
        }

        if (hp <= 0)
        {
            if (this.tag != "Wall")
            {
                //system.transform.position = this.transform.position;
                //system.Emit(10);
                Player.instance.AddExperience(experienceValue);

                int[] itemsDropped = new int[4];

                for (int i = 0; i < 4; i++)
                {
                    if (Random.Range(0, rarity) == 0 && itemDrop.Length > i)
                    {
                        itemsDropped[i] = itemDrop[i];
                    }
                    else
                    {
                        itemsDropped[i] = -1;
                    }
                }
                if (!(itemsDropped[0] == -1 && itemsDropped[1] == -1 && itemsDropped[2] == -1 && itemsDropped[3] == -1))
                {
                    //Handles the case when an enemy drops something on an exisiting bag
                    GameObject[] pickups   = GameObject.FindGameObjectsWithTag("Pickup");
                    bool         bagExists = false;
                    for (int i = 0; i < pickups.Length; i++)
                    {
                        if (pickups[i].transform.position == transform.position)
                        {
                            bagExists = true;
                            int    pickupsIndex   = 0;
                            Pickup matchingPickup = pickups[i].GetComponent <Pickup>();
                            for (int j = 0; j < 4; j++)
                            {
                                if (matchingPickup.itemId[i] == -1)
                                {
                                    matchingPickup.itemId[i] = itemsDropped[pickupsIndex];
                                    pickupsIndex++;
                                }
                            }
                        }
                    }

                    if (!bagExists)
                    {
                        BoardManager.instance.AddPickup((int)transform.position.x, (int)transform.position.y, itemsDropped);
                    }
                }
            }
            Delete();
            UpdateHealthBar();
        }
    }
Пример #20
0
 public Enemy(RealmManager manager, ushort objType)
     : base(manager, objType)
 {
     stat    = ObjectDesc.MaxHP == 0;
     counter = new DamageCounter(this);
 }
Пример #21
0
        public override bool HitByProjectile(Projectile projectile, RealmTime time)
        {
            if (stat)
            {
                return(false);
            }
            if (HasConditionEffect(ConditionEffects.Invincible))
            {
                return(false);
            }
            if (projectile.ProjectileOwner is Player p &&
                !HasConditionEffect(ConditionEffects.Paused) &&
                !HasConditionEffect(ConditionEffects.Stasis))
            {
                var def = ObjectDesc.Defense;
                if (projectile.ProjDesc.ArmorPiercing)
                {
                    def = 0;
                }
                var dmg = (int)StatsManager.GetDefenseDamage(this, projectile.Damage, def);
                if (!HasConditionEffect(ConditionEffects.Invulnerable))
                {
                    HP -= dmg;
                }
                ConditionEffect[] effs = null;
                foreach (var pair in projectile.ProjDesc.CondChance)
                {
                    if (pair.Value == 0 || pair.Key == default(ConditionEffect))
                    {
                        continue;
                    }

                    if (pair.Value / 100d > new Random().NextDouble())
                    {
                        var effList = new List <ConditionEffect>(projectile.ProjDesc.Effects)
                        {
                            pair.Key
                        };
                        effs = effList.ToArray();
                    }
                }
                ApplyConditionEffect(effs ?? projectile.ProjDesc.Effects);
                Owner.BroadcastPacketNearby(new Damage
                {
                    TargetId     = Id,
                    Effects      = projectile.ConditionEffects,
                    DamageAmount = (ushort)dmg,
                    Kill         = HP < 0,
                    BulletId     = projectile.ProjectileId,
                    ObjectId     = projectile.ProjectileOwner.Self.Id
                }, this, p, PacketPriority.Low);

                if (p.StealAmount != null)
                {
                    if (p.StealAmount[0] != 0 && !p.HasConditionEffect(ConditionEffects.Sick))
                    {
                        var maxHP     = p.Stats[0];
                        var lifeSteal = p.StealAmount[0];

                        if (lifeSteal >= 1 && p.HP < maxHP)
                        {
                            p.HP = p.HP + lifeSteal > maxHP ? maxHP : p.HP + lifeSteal;
                        }
                        else
                        {
                            stealHits[0]++;
                            if (stealHits[0] >= 1 / lifeSteal)
                            {
                                p.HP = p.HP + lifeSteal > maxHP ? maxHP : p.HP + lifeSteal;
                            }
                        }
                    }

                    if (p.StealAmount[1] != 0 && !p.HasConditionEffect(ConditionEffects.Quiet))
                    {
                        var maxMP     = p.Stats[1];
                        var manaLeech = p.StealAmount[1];

                        if (manaLeech >= 1 && p.MP < maxMP)
                        {
                            p.MP = p.MP + manaLeech > maxMP ? maxMP : p.MP + manaLeech;
                        }
                        else
                        {
                            stealHits[1]++;
                            if (stealHits[1] >= 1 / manaLeech)
                            {
                                p.MP = p.MP + manaLeech > maxMP ? maxMP : p.MP + manaLeech;
                            }
                        }
                    }
                }

                DamageCounter.HitBy(p, time, projectile, dmg);

                if (HP < 0 && Owner != null)
                {
                    Death(time);
                }
                return(true);
            }
            return(false);
        }
Пример #22
0
 public void SetDamageCounter(DamageCounter counter, Enemy target)
 {
     target.counter = counter;
 }
Пример #23
0
 public void SetDamageCounter(DamageCounter counter, Enemy enemy)
 {
     this.counter = counter;
     this.counter.UpdateEnemy(enemy);
 }
 internal void Return(DamageCounter damageCounter)
 {
     damageCounter.gameObject.SetActive(false);
     availableDamageCounters.Push(damageCounter);
 }
Пример #25
0
 public override void Dispose()
 {
     counter = null;
     base.Dispose();
 }