private void OnSpawnTimer(uint id, object cookie)
        {
            TroopSpawnData troopSpawnData = (TroopSpawnData)cookie;
            SmartEntity    smartEntity    = Service.Get <TroopController>().SpawnTroop(troopSpawnData.TroopType, TeamType.Defender, troopSpawnData.BoardPosition, troopSpawnData.SpawnMode, true, true);

            if (smartEntity == null)
            {
                return;
            }
            int num = troopSpawnData.Amount - 1;

            troopSpawnData.Amount = num;
            if (num > 0)
            {
                Service.Get <SimTimerManager>().CreateSimTimer(this.Stagger, false, new TimerDelegate(this.OnSpawnTimer), troopSpawnData);
            }
            if (this.TroopsHurt)
            {
                HealthComponent healthComp = smartEntity.HealthComp;
                int             quantity   = IntMath.Normalize(0, 100, 100 - GameConstants.SPAWN_HEALTH_PERCENT, 0, healthComp.MaxHealth);
                Service.Get <HealthController>().ApplyHealthFragment(healthComp, new HealthFragment(null, HealthType.Damaging, quantity), true);
            }
            if (smartEntity != null)
            {
                Service.Get <EventManager>().SendEvent(EventId.DefenderTriggeredInBattle, new DefenderTroopDeployedData(smartEntity, (Entity)this.Owner));
            }
        }
        private void SetProjectileTravelTime(Bullet bullet, int targetBoardX, int targetBoardZ)
        {
            if (bullet.ProjectileType.IsMultiStage)
            {
                bullet.SetTravelTime(bullet.ProjectileType.Stage1Duration + bullet.ProjectileType.StageTransitionDuration + bullet.ProjectileType.Stage2Duration);
                return;
            }
            int  num        = bullet.ProjectileType.IsBeam ? ((bullet.ProjectileType.BeamLifeLength - bullet.ProjectileType.BeamInitialZeroes) * 1024) : IntMath.FastDist(bullet.SpawnBoardX, bullet.SpawnBoardZ, targetBoardX, targetBoardZ);
            uint travelTime = 0u;

            if (bullet.ProjectileType.MaxSpeed > 0)
            {
                int val = num / bullet.ProjectileType.MaxSpeed;
                travelTime = (uint)IntMath.Normalize(0, 1024, val, 0, 1000);
            }
            bullet.SetTravelTime(travelTime);
        }
Beispiel #3
0
 private int CalculateLootFromDamagePercentage(int damagePercent, int maxLoot)
 {
     return(IntMath.Normalize(0, 100, damagePercent, 0, maxLoot));
 }