Esempio n. 1
0
 static Packets()
 {
     try
     {
         Attack = new OnAttack();
         MissileHit = new OnMissileHit();
     }
     catch (Exception)
     {
         //ignored
     }
 }
Esempio n. 2
0
 static Packets()
 {
     try
     {
         Attack = new OnAttack();
         MissileHit = new OnMissileHit();
         Disengaged = new OnDisengaged();
         MonsterSkill = new OnMonsterSkill();
         CreateGromp = new OnCreateGromp();
         CreateCampIcon = new OnCreateCampIcon();
     }
     catch (Exception)
     {
         //ignored
     }
 }
 protected virtual void Attack()
 {
     OnAttack?.Invoke();
     attackTimer = stats.attackSpeed;
 }
Esempio n. 4
0
 /// <summary>
 /// Activate a random Attack
 /// </summary>
 public virtual void SetAttack()
 {
     attack1 = true;
     OnAttack.Invoke();
 }
Esempio n. 5
0
 protected void InvokeOnAttack()
 {
     OnAttack?.Invoke();
 }
 public void OnAttackButtonClicked()
 {
     OnAttack?.Invoke(this, EventArgs.Empty);
 }
Esempio n. 7
0
        public void NotifyOnAttack(IAttackableUnit attacker, IAttackableUnit attacked, AttackType attackType)
        {
            var oa = new OnAttack(attacker, attacked, attackType);

            _packetHandlerManager.BroadcastPacket(oa, Channel.CHL_S2C);
        }
Esempio n. 8
0
 private static void FireOnAttack(AttackableUnit unit, AttackableUnit target)
 {
     OnAttack?.Invoke(unit, target);
 }
Esempio n. 9
0
 public void HandleAttackAnimationEvent()
 {
     OnAttack?.Invoke();
 }
Esempio n. 10
0
        public void NotifyOnAttack(Unit attacker, Unit attacked, AttackType attackType)
        {
            var oa = new OnAttack(attacker, attacked, attackType);

            _game.PacketHandlerManager.broadcastPacket(oa, Channel.CHL_S2C);
        }
Esempio n. 11
0
        public void Update(uint tick, float gameSpeed)
        {
            for (int i = 0; i < Compatible.Count; i++)
            {
                float timeElapsed = gameSpeed;

                var entity = Compatible[i];
                var weapon = entity.GetComponent <WeaponComponent>();

                // reset hit marker
                weapon.Hit = 0.0f;
                //Reduce cooldown timers if necessary
                if (weapon.CooldownLeftSeconds > 0)
                {
                    weapon.CooldownLeftSeconds -= timeElapsed;
                }
                if (weapon.AttackTimeLeft > 0)
                {
                    if (entity.TryGetComponent <GraphicsComponent>(out GraphicsComponent graphics))
                    {
                        graphics.Color = Color.Red;
                    }

                    weapon.AttackTimeLeft -= timeElapsed;
                }
                else
                {
                    if (entity.TryGetComponent <GraphicsComponent>(out GraphicsComponent graphics))
                    {
                        graphics.Color = Color.White;
                    }

                    // Remember to set the activation bool to false
                    weapon.Active = 0f;
                }

                // Only attack if activation is over threshold and the cooldowns have expired.
                if (weapon.Activation > weapon.ActivateThreshold && weapon.CooldownLeftSeconds <= 0 && weapon.AttackTimeLeft <= 0)
                {
                    if (entity.RootEntity.HasComponent <EnergyComponent>())
                    {
                        var energy = entity.RootEntity.GetComponent <EnergyComponent>();
                        // check if we have the energy
                        if (!energy.CanAfford(weapon.AttackCost))
                        {
                            continue;
                        }

                        // charge the entity energy for the attack
                        float charged = energy.ChargeEnergy(weapon.AttackCost);
                        _energyManager.DepositEnergy(charged);
                    }



                    weapon.Active = 1.0f;

                    // set up all the timers
                    weapon.CooldownLeftSeconds = weapon.CooldownTimeSeconds;
                    weapon.AttackTimeLeft      = weapon.AttackTimeSeconds;
                }
            }
            foreach (var c in _collisions)
            {
                // Damage the health entity
                // Figure out which was the weapon and which was the health entity
                Entity health;
                Entity weapon;
                if (c.E1.HasComponent <HealthComponent>())
                {
                    health = c.E1;
                    weapon = c.E2;
                }
                else
                {
                    health = c.E2;
                    weapon = c.E1;
                }

                // Check not attached to same entity
                if (health.RootEntity == weapon.RootEntity)
                {
                    continue;
                }


                var weaponComp = weapon.GetComponent <WeaponComponent>();
                if (weaponComp.Active <= 0)
                {
                    continue;
                }

                var healthComp = health.GetComponent <HealthComponent>();

                float damage = (float)(weaponComp.Damage);
                weaponComp.Active = 0;

                var trans = weapon.GetComponent <TransformComponent>();

                healthComp.Health -= damage;
                weaponComp.Hit     = 1.0f;

                if (weaponComp.SiphonEnergy && health.HasComponent <EnergyComponent>() && weapon.RootEntity.HasComponent <EnergyComponent>())
                {
                    var   attackerEnergy = weapon.RootEntity.GetComponent <EnergyComponent>();
                    var   victimEnergy   = health.GetComponent <EnergyComponent>();
                    float taken          = victimEnergy.ChargeEnergy(weaponComp.SiphonAmount);
                    attackerEnergy.DepositEnergy(taken);
                }

                OnAttack?.Invoke(new AttackEventInfo(trans.WorldPosition, tick * gameSpeed, weapon.Id, weapon.Tag, health.Id, health.Tag, damage));
            }
        }