Esempio n. 1
0
 public override void OnTick()
 {
     if (source != null && (source.occupied || source.Depleted()))
     {
         source = null;
         motor.Stop();
     }
     if (source != null)
     {
         var dist = World.current.map.Distance(entity.position, source.entity.position);
         if (dist < 1)
         {
             var ent = World.current.Instantiate(mineTypes.First(kv => kv.Key == source.resourceId).Value,
                                                 entity.team,
                                                 source.entity.position);
             ent.rotation = entity.rotation;
             var mine = ent.GetComponent <Mine>();
             mine.source = source;
             entity.Destroy();
         }
         else
         {
             motor.MoveTo(source.entity.position);
         }
     }
 }
Esempio n. 2
0
 public override void OnTick()
 {
     if (collector != null && !collector.entity.isAlive)
     {
         collector = null;
     }
     if (resource != null && !resource.entity.isAlive)
     {
         resource = null;
     }
     if (resource != null && resource.occupied)
     {
         resource = null;
     }
     if (is_idle)
     {
         return;
     }
     if (moving_to_collector)
     {
         if (collector == null)
         {
             // Find the nearest collector.
             var ent = World.current.entities
                       .Where(e => e.team == entity.team && e.GetComponents <ResourceCollectionPoint>().Any(s => s.resourceId == resourceId))
                       .OrderBy(e => World.current.map.Distance(entity.position, e.position))
                       .FirstOrDefault();
             if (ent != null)
             {
                 collector = ent.GetComponents <ResourceCollectionPoint>().Where(s => s.resourceId == resourceId).FirstOrDefault();
             }
         }
         if (collector == null)
         {
             motor.Stop();
             is_idle = true;
             return;
         }
         var dist = World.current.map.Distance(new DVector3(entity.position.x, 0, entity.position.z),
                                               new DVector3(collector.entity.position.x, 0, collector.entity.position.z));
         if (dist < 3)
         {
             motor.Stop();
             // At the dropoff, disgorge the tank contents.
             var transfered = DReal.Min(fill, fillRate * World.deltaTime);
             collector.Receive(transfered);
             fill -= transfered;
         }
         else
         {
             motor.MoveTo(collector.entity.position);
         }
         // If the tank is empty, move to the resource.
         if (fill <= 0)
         {
             moving_to_collector = false;
             motor.Stop();
         }
     }
     else
     {
         if (resource != null && resource.remainingCount <= 0)
         {
             resource = null;
         }
         if (resource == null)
         {
             // Find the nearest resource.
             var ent = World.current.entities
                       .Where(e => e.GetComponents <ResourceSource>().Any(s => s.resourceId == resourceId && s.remainingCount > 0 && !s.occupied))
                       .OrderBy(e => World.current.map.Distance(entity.position, e.position))
                       .FirstOrDefault();
             if (ent != null)
             {
                 resource = ent.GetComponents <ResourceSource>().Where(s => s.resourceId == resourceId && s.remainingCount > 0 && !s.occupied).FirstOrDefault();
             }
         }
         if (resource == null)
         {
             motor.Stop();
             moving_to_collector = true;
             return;
         }
         var dist = World.current.map.Distance(new DVector3(entity.position.x, 0, entity.position.z),
                                               new DVector3(resource.entity.position.x, 0, resource.entity.position.z));
         if (dist < 3)
         {
             motor.Stop();
             // At the pickup, fill the tank.
             var transfered = DReal.Min(capacity - fill, fillRate * World.deltaTime);
             fill += resource.Take(transfered);
         }
         else
         {
             motor.MoveTo(resource.entity.position);
         }
         // If the tank is full, move to the collector.
         if (fill >= capacity)
         {
             moving_to_collector = true;
             motor.Stop();
         }
     }
 }
Esempio n. 3
0
        public override void OnTick()
        {
            if (attackTarget != null)
            {
                if (!attackTarget.isAlive)
                {
                    attackTarget = null;
                    StopCommand();
                    return;
                }
                var dist = entity.Range(attackTarget);

                if (dist < weaponRange)
                {
                    // In range, fire!
                    if (motor != null)
                    {
                        motor.Stop();
                    }
                    foreach (var weapon in weapons)
                    {
                        weapon.FireAt(attackTarget);
                    }
                }
                else
                {
                    // Not in range, move to target.
                    if (motor != null)
                    {
                        motor.MoveTo(attackTarget.position);
                    }
                    else
                    {
                        // Turret behaviour, if there's no motor then it can't follow.
                        // Just forget about the target.
                        attackTarget = null;
                    }
                }
            }
            else
            {
                if (stance == Stance.Active)
                {
                    var trueRange = weaponRange;
                    var collider  = entity.GetComponent <Collider>();
                    if (collider != null)
                    {
                        trueRange += collider.radius;
                    }

                    if (passiveAttackTarget != null && !passiveAttackTarget.isAlive)
                    {
                        passiveAttackTarget = null;
                    }
                    if (passiveAttackTarget != null)
                    {
                        var range = entity.Range(passiveAttackTarget);
                        if (range > trueRange)
                        {
                            passiveAttackTarget = null;
                        }
                    }
                    if (passiveAttackTarget == null)
                    {
                        passiveAttackTarget = World.current
                                              .FindEntitiesWithinRadius(entity.position, trueRange, entity.team)
                                              .FirstOrDefault();
                    }
                    if (passiveAttackTarget != null)
                    {
                        foreach (var weapon in weapons)
                        {
                            weapon.FireAt(passiveAttackTarget);
                        }
                    }
                }
            }
        }