Пример #1
0
 public Projectile(Entity entity, ComponentPrototype proto) : base(entity)
 {
     speed        = DReal.Parse(proto.data["speed"]);
     directDamage = DReal.Parse(proto.data["directDamage"]);
     splashDamage = DReal.Parse(proto.data["splashDamage"]);
     splashRadius = DReal.Parse(proto.data["splashRadius"]);
 }
Пример #2
0
 public Collider(Entity entity, ComponentPrototype proto) : base(entity)
 {
     height        = DReal.Parse(proto.data["height"]);
     radius        = DReal.Parse(proto.data["radius"]);
     fixedPosition = proto.data["fixedPosition"] == "true";
     pushy         = proto.data["pushy"] == "true";
 }
Пример #3
0
        public bool CheckBuildPlacement(int id, DVector3 position)
        {
            // Eugh. Poke around in the prototype for the collider (if any).
            var radius = (DReal)0;
            var proto  = World.current.entityPrototypes[buildables[id]];

            foreach (var cproto in proto.components)
            {
                if (cproto.kind == "Collider")
                {
                    radius = DReal.Parse(cproto.data["radius"]);
                }
            }

            if (World.current.FindEntitiesWithinRadius(position, radius * 2).Any())
            {
                return(false);
            }

            // Must be within a build radius.
            foreach (var ent in World.current.entities.Where(e => e.team == entity.team))
            {
                var br = ent.GetComponent <BuildRadius>();
                if (br != null && br.Contains(position, radius))
                {
                    return(true);
                }
            }

            return(false);
        }
Пример #4
0
 public Wizard(Entity entity, ComponentPrototype proto) : base(entity)
 {
     towerPrototype              = proto.data["tower"];
     towerBuildCooldown          = DReal.Parse(World.current.entityPrototypes[towerPrototype].data["buildTime"]);
     towerBuildCooldownRemaining = towerBuildCooldown;
     tower = null;
 }
Пример #5
0
 public WizardTower(Entity entity, ComponentPrototype proto) : base(entity)
 {
     harvesterPrototype     = proto.data["harvester"];
     harvesterBuildCooldown = DReal.Parse(World.current.entityPrototypes[harvesterPrototype].data["buildTime"]);
     wizardPrototype        = proto.data["wizard"];
     wizardBuildCooldown    = DReal.Parse(World.current.entityPrototypes[harvesterPrototype].data["buildTime"]);
 }
Пример #6
0
 public ResourceHarvester(Entity entity, ComponentPrototype proto) : base(entity)
 {
     this.motor = entity.GetComponent <IMotor>();
     resourceId = World.current.resourceNameToId[proto.data["resource"]];
     capacity   = DReal.Parse(proto.data["capacity"]);
     fillRate   = DReal.Parse(proto.data["rate"]);
     this.fill  = 0;
 }
Пример #7
0
        public Mine(Entity entity, ComponentPrototype proto) : base(entity)
        {
            this.rate = DReal.Parse(proto.data["rate"]);

            var resource = World.current.resourceNameToId[proto.data["resource"]];

            var team_ent = World.current.entities.First(e => e.team == entity.team && e.GetComponents <ResourcePool>().Any(p => p.resourceId == resource));

            pool = team_ent.GetComponents <ResourcePool>().First(p => p.resourceId == resource);
        }
Пример #8
0
        public AirMotor(Entity entity, ComponentPrototype proto) : base(entity)
        {
            moveSpeed = DReal.Parse(proto.data["speed"]);

            wobbleFrequency = DReal.Parse(proto.data["wobbleFrequency"]);
            wobbleAmplitude = DReal.Parse(proto.data["wobbleAmplitude"]);
            floatOffset     = DReal.Parse(proto.data["floatOffset"]);
            verticalSpeed   = DReal.Parse(proto.data["verticalSpeed"]);

            wobbleOffset = World.current.RandomValue() * DReal.PI;
        }
Пример #9
0
        public HitscanWeapon(Entity entity, ComponentPrototype proto) : base(entity)
        {
            range       = DReal.Parse(proto.data["range"]);
            damage      = DReal.Parse(proto.data["damage"]);
            fireRate    = DReal.Parse(proto.data["fireRate"]);
            sustainTime = DReal.Parse(proto.data["sustainTime"]);
            effect      = proto.data["effect"];

            refireTime       = 0;
            sustainRemaining = 0;
            sustainTarget    = null;
        }
Пример #10
0
        public ProjectileWeapon(Entity entity, ComponentPrototype proto) : base(entity)
        {
            projectile = proto.data["projectile"];
            range      = DReal.Parse(proto.data["range"]);
            fireRate   = DReal.Parse(proto.data["fireRate"]);

            randomOffset = new DVector3(DReal.Parse(proto.data["randomOffsetX"]),
                                        DReal.Parse(proto.data["randomOffsetY"]),
                                        DReal.Parse(proto.data["randomOffsetZ"]));

            fireTime = 0;
        }
Пример #11
0
 public ResourcePool(Entity entity, ComponentPrototype proto) : base(entity)
 {
     this.resourceId = World.current.resourceNameToId[proto.data["resource"]];
     this.fill       = DReal.Parse(proto.data["initial"]);
 }
Пример #12
0
 public BuildRadius(Entity entity, ComponentPrototype proto) : base(entity)
 {
     radius = DReal.Parse(proto.data["radius"]);
 }
Пример #13
0
        public ResourceSet ParseResources(Dictionary <string, string> resources)
        {
            var rs = new ResourceSet();

            rs.resources = resources
                           .Select(kv => new KeyValuePair <int, DReal>(World.current.resourceNameToId.ContainsKey(kv.Key) ? World.current.resourceNameToId[kv.Key] : -1, DReal.Parse(kv.Value)))
                           .Where(kv => kv.Key != -1)
                           .OrderBy(kv => kv.Key)
                           .ToArray();
            return(rs);
        }
Пример #14
0
        public override void BuildCommand(int id, DVector3 position)
        {
            if (buildInProgress)
            {
                return;
            }

            if (buildables[id] == null)
            {
                return;
            }

            position = new DVector3(position.x,
                                    World.current.map.Height(position),
                                    position.z);

            currentMode = World.current.entityPrototypes[buildables[id]].BuildMode();
            if (currentMode == BuildMode.BUILD_IN_PLACE || currentMode == BuildMode.BUILD_IMMEDIATE)
            {
                if (!CheckBuildPlacement(id, position))
                {
                    return;
                }
            }
            // TODO: Check placement for BUILD_foo here.
            if (!HaveEnoughResources(id))
            {
                return;
            }

            ConsumeResources(id, false);
            buildInProgress  = true;
            totalTime        = DReal.Parse(World.current.entityPrototypes[buildables[id]].data["buildTime"]);
            remainingTime    = totalTime;
            buildingWhat     = id;
            buildingPosition = position;
            switch (currentMode)
            {
            case BuildMode.SPAWN:
                break;

            case BuildMode.SPAWN_IMMEDIATE:
                World.current.Instantiate(buildables[buildingWhat],
                                          entity.team,
                                          entity.RandomSpawnPosition(spawnMin, spawnMax));
                World.current.eventListener.Animate(entity, "Spawn");
                break;

            case BuildMode.BUILD_THEN_PLACE:
                break;

            case BuildMode.BUILD_IN_PLACE:
                var proto = World.current.entityPrototypes[buildables[id]];
                var ent   = new Entity(entity.team, position, proto);
                // Only instantiate the collider and the health component, if any.
                foreach (var cproto in proto.components)
                {
                    if (cproto.kind == "Collider")
                    {
                        ent.AddComponent(new Collider(ent, cproto));
                    }
                    else if (cproto.kind == "Health")
                    {
                        ent.AddComponent(new Health(ent, cproto));
                    }
                }
                inPlaceConstruction = new PartialBuilding(ent);
                ent.AddComponent(inPlaceConstruction);
                break;

            case BuildMode.BUILD_IMMEDIATE:
                World.current.Instantiate(buildables[buildingWhat],
                                          entity.team,
                                          buildingPosition);
                break;
            }
        }
Пример #15
0
 public ResourceSource(Entity entity, ComponentPrototype proto) : base(entity)
 {
     this.resourceId     = World.current.resourceNameToId[proto.data["resource"]];
     this.remainingCount = DReal.Parse(proto.data["initial"]);
     this.occupied       = false;
 }
Пример #16
0
 public GroundMotor(Entity entity, ComponentPrototype proto) : base(entity)
 {
     moveSpeed = DReal.Parse(proto.data["speed"]);
 }
Пример #17
0
 public Health(Entity entity, ComponentPrototype proto) : base(entity)
 {
     max     = DReal.Parse(proto.data["max"]);
     current = max;
 }