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); }
void TickUpdate() { ComSat.Trace(this, "TickUpdate"); if (ComSat.EntityExists(target)) { destination = target.position; var radius = target.collisionRadius + entity.collisionRadius; if ((target.position - entity.position).sqrMagnitude < radius * radius) { var components = target.GetComponents(typeof(ISabotagable)); foreach (var c in components) { (c as ISabotagable).Sabotage(); } ComSat.DestroyEntity(entity, DestroyReason.HitTarget); } } if (moving) { if ((destination - entity.position).sqrMagnitude < sqrPositioningAccuracy) { // Close enough. moving = false; motor.Stop(); } else { motor.MoveTowards(destination); } } }
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); } }
void TickUpdate() { ComSat.Trace(this, "TickUpdate"); age += ComSat.tickRate; if (age >= lifetime) { ComSat.DestroyEntity(entity, DestroyReason.OldAge); } }
public void Sell() { var value = health / maxHealth * ((DReal)3 / 4); var resources = buildCost * value; print("Selling " + this + " for " + resources.Metal + " Metal and " + resources.MagicSmoke + " Smoke"); print("Value: " + value); var resourceMan = FindObjectOfType <ResourceManager>(); resourceMan.teamResources[team] += resources; ComSat.DestroyEntity(this, DestroyReason.Sold); }
public void Damage(int damage) { ComSat.Trace(this, "Damage"); if (maxHealth == 0) { return; } health -= damage; if (health <= 0) { ComSat.DestroyEntity(this, DestroyReason.Damaged); } }
void TickUpdate() { ComSat.Trace(this, "TickUpdate"); if (ComSat.EntityExists(target)) { var dir = target.position - entity.position; // also vector to dest. var targetAngle = DVector2.ToAngle(dir); var baseAngle = Utility.CalculateNewAngle(entity.rotation, targetAngle, DReal.Radians(turnSpeed)); entity.rotation = baseAngle; } entity.velocity = DVector2.FromAngle(entity.rotation) * speed; DVector2 newPosition = entity.position + entity.velocity * ComSat.tickRate; // FIXME: this should do something to account for hitting fast-moving projectiles. DVector2 hitPosition; Entity hit = ComSat.LineCast(entity.position, newPosition, out hitPosition, entity.team); if (hit != null && (!hit.hitOnlyIfTargetted || hit == target)) { hit.Damage((int)ComputeDamage()); var position = new Vector3((float)hitPosition.y, 0, (float)hitPosition.x); var rotation = Quaternion.AngleAxis((float)entity.rotation, Vector3.up); if (impactPrefab != null && ComSat.RateLimit()) { ObjectPool.Instantiate(impactPrefab, position, rotation); } //if(trail) { // trail.transform.parent = null; // trail.autodestruct = true; // trail = null; //} if (!penetrates || speed < minPenetrationSpeed) { ComSat.DestroyEntity(entity, DestroyReason.HitTarget); return; } else { speed -= penetrationSpeedReduction; } } }
void Detonate() { if (haveExploded) { return; } haveExploded = true; ObjectPool.Instantiate(impactPrefab, transform.position, transform.rotation); var sqrRadius = explosionRadius * explosionRadius; foreach (var e in ComSat.FindEntitiesWithinRadius(entity.position, explosionRadius)) { var sqrDist = (e.position - entity.position).sqrMagnitude; var power = (sqrRadius - sqrDist) / sqrRadius; print("Exploding on " + e + " sd: " + sqrDist + " sr: " + sqrRadius + " pwr: " + power + " dam: " + (int)(damageAtCentre * power)); e.Damage((int)(damageAtCentre * power)); } ComSat.DestroyEntity(entity, DestroyReason.Damaged); }