Exemple #1
0
    void TickUpdate()
    {
        if (sabotageTime > 0)
        {
            sabotageTime -= ComSat.tickRate;
            return;
        }

        if (!powerSink.Powered())
        {
            return;
        }

        foreach (var p in ComSat.FindAllEntitiesWithinRadius <Projectile>(entity.position, radius, entity.team))
        {
            if (p.kind != Projectile.Kind.KINETIC)
            {
                continue;
            }

            glowTime = glowLength;

            p.speed /= 30 * ComSat.tickRate;
        }
    }
Exemple #2
0
 void TickUpdate()
 {
     timer += ComSat.tickRate;
     if (entity.team != -1 && timer > 1 && powerSink.poweredOn)
     {
         var amount = Math.Min(powerSink.Powered() ? mineRate : mineRate / 2, source.amount);
         resourceMan.AddResource(entity.team, resource, amount);
         source.amount -= amount;
     }
     timer %= 1;
 }
Exemple #3
0
    void TickUpdate()
    {
        ComSat.Trace(this, "TickUpdate");

                if(!powerSink.poweredOn) {
                        target = null;
                        audio.Stop();
                        return;
                }

                if(!ComSat.EntityExists(target)) {
                        // Magic. Destroyed GameObjects compare against null.
                        // Explicitly set to null to avoid keeping it around.
                        target = null;
                        audio.Stop();

                        // Search for victims.
                        target = ComSat.FindEntityWithinRadius(entity.position, attackRange, entity.team);
                        if(target != null) {
                                audio.Play();
                        }
                } else {
                        var dp = target.position - entity.position;

                        DReal targetTurretAngle;

                        var projectileProjectile = projectilePrefab.GetComponent<Projectile>();
                        if(projectileProjectile != null && powerSink.Powered()) {
                                var aimSpot = Utility.PredictShot(entity.position, projectileProjectile.initialSpeed,
                                                                  target.position, target.velocity);
                                targetTurretAngle = DReal.Mod(DVector2.ToAngle(aimSpot - entity.position) - entity.rotation, DReal.TwoPI);
                        } else {
                                targetTurretAngle = DReal.Mod(DVector2.ToAngle(dp) - entity.rotation, DReal.TwoPI);
                        }

                        // Turn turret to point at target.
                        TurnTurret(targetTurretAngle);
                        // Fire when pointing the gun at the target.
                        if(targetTurretAngle == turretRotation) {
                                Fire();
                        }

                        // Stop shooting when out of range.
                        if(dp.sqrMagnitude >= attackRange * attackRange) {
                                audio.Stop();
                                target = null;
                        }
                }

                if(fireDelay > 0) {
                        fireDelay -= ComSat.tickRate;
                }
    }
Exemple #4
0
        void TickUpdate() {
                ComSat.Trace(this, "TickUpdate");
                if(sabotageTime > 0) {
                        sabotageTime -= ComSat.tickRate;
                }
                if (buildQueue.Any()) {
                        var buildMe = buildQueue.Peek();
                        var prefab = prefabs[buildMe.what];

                        if(delay > 0) {
                                var advance = ComSat.tickRate;
                                if(sabotageTime > 0) {
                                        advance /= sabotageTimeMultiplier;
                                }
                                if(!powerSink.Powered()) {
                                        advance /= 2;
                                }

                                var completion = advance / prefab.buildTime;
                                var totalRemaining = prefab.buildCost - usedResources;
                                partialMetalUnit += DReal.Min(completion * prefab.buildCost.Metal, totalRemaining.Metal);
                                partialSmokeUnit += DReal.Min(completion * prefab.buildCost.MagicSmoke, totalRemaining.MagicSmoke);
                                var rs = new ResourceSet { Metal = (int)partialMetalUnit, MagicSmoke = (int)partialSmokeUnit };
                                if (resourceMan.TakeResources(entity.team, rs)) {
                                        usedResources += rs;
                                        partialMetalUnit %= 1;
                                        partialSmokeUnit %= 1;
                                        delay -= advance;
                                } else {
                                        partialMetalUnit -= completion * prefab.buildCost.Metal;
                                        partialSmokeUnit -= completion * prefab.buildCost.MagicSmoke;
                                }
                        }
                        if(delay <= 0) {
                                if (!resourceMan.TakeResources(entity.team, prefab.buildCost - usedResources)) return;

                                // Timer expired and we're building something.
                                print("Build new " + prefab);
                                var prefabSize = (DReal)prefab.collisionRadiusNumerator / prefab.collisionRadiusDenominator;
                                var wiggle = ((ComSat.RandomValue() % 5) / 5) * ((ComSat.RandomValue() % 2 == 0) ? 1 : -1);
                                var position = prefab.buildAtPoint
                                        ? buildMe.position
                                        : (entity.position + DVector2.FromAngle(entity.rotation + wiggle) * (entity.collisionRadius + prefabSize + 2 + wiggle));
                                ComSat.SpawnEntity(entity, prefab.gameObject, position, 0);
                                if(buildMe.buildCollider != null) {
                                        buildMan.RemovePendingBuild(buildMe.buildCollider);
                                }
                                if (!buildMe.repeat) buildQueue.Dequeue();
                                ResetBuildTime();
                        }
                }
        }