コード例 #1
0
ファイル: Constructor.cs プロジェクト: rbarraud/Blarg2
    void UIAction(int what)
    {
        ComSat.Trace(this, "UIAction");
        if (what < 0 || what >= constructionPrefabs.Length)
        {
            return;
        }

        var mine = constructionPrefabs[what].GetComponent <Mine>();

        if (mine != null)
        {
            var sourceHere = Utility.GetThingAt <ResourceSource>(entity.position);
            if (sourceHere == null || sourceHere.hasMine || sourceHere.resource != mine.resource)
            {
                return;
            }

            buildPosition = sourceHere.GetComponent <Entity>().position;
            movable.Move(buildPosition);
            buildIndex = what;
            return;
        }

        ComSat.SpawnEntity(constructionPrefabs[what].gameObject, entity.team, entity.position, entity.rotation);
        ComSat.DestroyEntity(entity, DestroyReason.Tranformed);
    }
コード例 #2
0
    void FireMissile()
    {
        if (missileRecycleDelay > 0)
        {
            return;
        }
        if (missilesLoaded <= 0)
        {
            return;
        }

        missileFireSound.PlayOneShot(missileFireSound.clip);
        ComSat.SpawnEntity(entity, missilePrefab,
                           entity.position, entity.rotation,
                           (Entity ent) => {
            var proj = ent.gameObject.GetComponent <Projectile>();
            if (proj != null && ComSat.EntityExists(combatVehicle.target))
            {
                proj.target = combatVehicle.target;
            }
        });

        missileRecycleDelay = missileRecycleTime;
        missilesLoaded     -= 1;
    }
コード例 #3
0
ファイル: Constructor.cs プロジェクト: rbarraud/Blarg2
 void TickUpdate()
 {
     if (buildIndex > -1 && (buildPosition - entity.position).sqrMagnitude < 1)
     {
         ComSat.SpawnEntity(constructionPrefabs[buildIndex].gameObject, entity.team, buildPosition, entity.rotation);
         ComSat.DestroyEntity(entity, DestroyReason.Tranformed);
     }
 }
コード例 #4
0
ファイル: Factory.cs プロジェクト: rbarraud/Blarg2
        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();
                        }
                }
        }
コード例 #5
0
    DReal barrelRecycleTime = 2;            // Delay before refiring one barrel.

    void FireOneBarrel(int sign)
    {
        audio.PlayOneShot(audio.clip);
        ComSat.SpawnEntity(entity, projectilePrefab,
                           entity.position, entity.rotation,
                           (Entity ent) => {
            var proj = ent.gameObject.GetComponent <Projectile>();
            if (proj != null && ComSat.EntityExists(combatVehicle.target))
            {
                proj.target = combatVehicle.target;
            }
        });
    }
コード例 #6
0
 void FireOneBarrel(int sign, GameObject barrel)
 {
     if (ComSat.RateLimit())
     {
         barrel.SendMessage("Fire");
     }
     ComSat.SpawnEntity(entity, projectilePrefab,
                        entity.position, entity.rotation + turretRotation,
                        (Entity ent) => {
         var proj = ent.gameObject.GetComponent <Projectile>();
         if (proj != null && ComSat.EntityExists(combatVehicle.target))
         {
             proj.target = combatVehicle.target;
         }
     });
 }
コード例 #7
0
ファイル: Turret.cs プロジェクト: rbarraud/Blarg2
    void Fire()
    {
        if(fireDelay > 0) {
                        return;
                }

                fireDelay = barrelRecycleTime;
                ComSat.SpawnEntity(entity, projectilePrefab,
                                   entity.position, entity.rotation + turretRotation,
                                   (Entity ent) => {
                                           var proj = ent.gameObject.GetComponent<Projectile>();
                                           if(proj != null && ComSat.EntityExists(target)) {
                                                   proj.target = target;
                                           }
                                   });
                turretBarrel.SendMessage("Fire");
    }
コード例 #8
0
    void FireGun()
    {
        if (gunRecycleDelay > 0)
        {
            return;
        }

        ComSat.SpawnEntity(entity, gunPrefab,
                           entity.position, entity.rotation,
                           (Entity ent) => {
            var proj = ent.gameObject.GetComponent <Projectile>();
            if (proj != null && ComSat.EntityExists(combatVehicle.target))
            {
                proj.target = combatVehicle.target;
            }
        });

        gunRecycleDelay = gunRecycleTime;
    }
コード例 #9
0
    void Fire()
    {
        if (fireDelayTime > 0)
        {
            return;
        }
        // Fire left.
        fireDelayTime = barrelRecycleTime;

        if (ComSat.RateLimit())
        {
            barrel.SendMessage("Fire");
        }
        ComSat.SpawnEntity(entity, combatVehicle.projectilePrefab,
                           entity.position, entity.rotation + turretRotation,
                           (Entity ent) => {
            var proj = ent.gameObject.GetComponent <Projectile>();
            if (proj != null && ComSat.EntityExists(combatVehicle.target))
            {
                proj.target = combatVehicle.target;
            }
        });
    }
コード例 #10
0
ファイル: ComSat.cs プロジェクト: rbarraud/Blarg2
 // Instantiate a new prefab, defering to the end of TickUpdate.
 // Prefab must be an Entity.
 public static void SpawnEntity(GameObject prefab, int team, DVector2 position, DReal rotation)
 {
     currentInstance.SpawnEntity(prefab, null, team, position, rotation, e => {});
 }