예제 #1
0
 public override void AttackCommand(Entity target)
 {
     if (!motor.Reachable(target.position))
     {
         return;
     }
     if (target.team == entity.team)
     {
         foreach (var collector in target.GetComponents <ResourceCollectionPoint>())
         {
             if (collector.resourceId == resourceId)
             {
                 this.collector = collector;
                 motor.Stop();
                 is_idle             = false;
                 moving_to_collector = true;
             }
         }
     }
     foreach (var resource in target.GetComponents <ResourceSource>())
     {
         if (resource.resourceId == resourceId && !resource.occupied)
         {
             this.resource = resource;
             motor.Stop();
             is_idle             = false;
             moving_to_collector = false;
         }
     }
 }
예제 #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();
         }
     }
 }
예제 #3
0
파일: World.cs 프로젝트: rbarraud/blarg4
        public Entity Instantiate(string prototypeName, int team, DVector3 position)
        {
            var proto = entityPrototypes[prototypeName];
            var ent   = new Entity(team, position, proto);

            foreach (var cproto in proto.components)
            {
                Component comp = null;
                if (cproto.kind == "Wizard")
                {
                    comp = new Wizard(ent, cproto);
                }
                else if (cproto.kind == "WizardTower")
                {
                    comp = new WizardTower(ent, cproto);
                }
                else if (cproto.kind == "BasicUnit")
                {
                    comp = new BasicUnit(ent, cproto);
                }
                else if (cproto.kind == "GroundMotor")
                {
                    comp = new GroundMotor(ent, cproto);
                }
                else if (cproto.kind == "AirMotor")
                {
                    comp = new AirMotor(ent, cproto);
                }
                else if (cproto.kind == "ResourceCollectionPoint")
                {
                    comp = new ResourceCollectionPoint(ent, cproto);
                }
                else if (cproto.kind == "ResourceHarvester")
                {
                    comp = new ResourceHarvester(ent, cproto);
                }
                else if (cproto.kind == "Truck")
                {
                    comp = new Truck(ent, cproto);
                }
                else if (cproto.kind == "MineTruck")
                {
                    comp = new MineTruck(ent, cproto);
                }
                else if (cproto.kind == "Mine")
                {
                    comp = new Mine(ent, cproto);
                }
                else if (cproto.kind == "Factory")
                {
                    comp = new Factory(ent, cproto);
                }
                else if (cproto.kind == "ResourceSource")
                {
                    comp = new ResourceSource(ent, cproto);
                }
                else if (cproto.kind == "ProjectileWeapon")
                {
                    comp = new ProjectileWeapon(ent, cproto);
                }
                else if (cproto.kind == "Projectile")
                {
                    comp = new Projectile(ent, cproto);
                }
                else if (cproto.kind == "Collider")
                {
                    comp = new Collider(ent, cproto);
                }
                else if (cproto.kind == "HitscanWeapon")
                {
                    comp = new HitscanWeapon(ent, cproto);
                }
                else if (cproto.kind == "Health")
                {
                    comp = new Health(ent, cproto);
                }
                else if (cproto.kind == "BuildRadius")
                {
                    comp = new BuildRadius(ent, cproto);
                }
                else if (cproto.kind == "Team")
                {
                    comp = new Team(ent, cproto);
                }
                else if (cproto.kind == "ResourcePool")
                {
                    comp = new ResourcePool(ent, cproto);
                }
                else
                {
                    Logger.Log("Unknown component type {0}", cproto.kind);
                }
                ent.AddComponent(comp);
            }
            return(ent);
        }