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 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 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; }
private void PickNewTarget() { if (targets == null) { targets = new Entity[] {} } ; targets = targets.Where(t => ComSat.EntityExists(t)).OrderBy(t => (t.position - entity.position).sqrMagnitude).ToArray(); if (targets.Count() > 0) { target = targets[0]; moving = true; } else { target = null; moving = false; } } void OnDrawGizmosSelected() { Gizmos.color = Color.red; Gizmos.DrawWireSphere(transform.position, detonateRange); Gizmos.color = Color.magenta; Gizmos.DrawWireSphere(transform.position, explosionRadius); } }
void TickUpdate() { ComSat.Trace(this, "TickUpdate"); if (fireCycle != FireCycle.READY) { fireDelayTime -= ComSat.tickRate; if (fireDelayTime <= 0) { if (fireCycle == FireCycle.FIREDLEFT) { // Fire right. fireCycle = FireCycle.FIREDRIGHT; FireOneBarrel(-1); // This is enough time for the left barrel to recycle. fireDelayTime = barrelRecycleTime - barrelDelay; } else if (fireCycle == FireCycle.FIREDRIGHT) { // cycle complete. fireCycle = FireCycle.READY; } } } }
void Awake() { ComSat.Trace(this, "Awake"); entity = gameObject.GetComponent <Entity>(); entity.AddUpdateAction(TickUpdate); entity.AddInstantiateAction(OnInstantiate); }
void TickUpdate() { if (sabotageTime > 0) { sabotageTime -= ComSat.tickRate; return; } if (!powerSink.Powered()) { return; } foreach (var p in ComSat.FindAllEntitiesWithinRadius <Projectile>(entity.position, radius, entity.team)) { if (p.kind != Projectile.Kind.KINETIC) { continue; } glowTime = glowLength; p.speed /= 30 * ComSat.tickRate; } }
public void Move(DVector2 location) { ComSat.Trace(this, "Move"); moving = true; destination = location; SendMessage("MoveDestinationChanged", SendMessageOptions.DontRequireReceiver); }
private void OnGUI() { if (!isSelected) { return; } var sourceHere = Utility.GetThingAt <ResourceSource>(entity.position); // TODO: follow Entity.buildTime. int x = 10; for (int i = 0; i < constructionPrefabs.Length; i++) { var mine = constructionPrefabs[i].GetComponent <Mine>(); if (mine != null && (sourceHere == null || sourceHere.hasMine || sourceHere.resource != mine.resource)) { continue; } if (GUI.Button(new Rect(x, Camera.main.pixelHeight - 74, 64, 64), constructionPrefabs[i].buildIcon)) { ComSat.IssueUIAction(entity, i); } x += 74; } }
void Move(DVector2 location) { ComSat.Trace(this, "Move"); moving = true; destination = location; target = null; }
void Awake() { ComSat.Trace(this, "Awake"); moving = false; motor = GetComponent <Vehicle>(); entity = GetComponent <Entity>(); entity.AddUpdateAction(TickUpdate); }
void Move(DVector2 location) { ComSat.Trace(this, "Move"); mode = Mode.MOVE; target = null; targets = null; destination = location; }
void Start() { ComSat.Trace(this, "Start"); if (baseMesh && team != 0) { baseMesh.renderer.material.color = Utility.TeamColour(team); } }
void Awake() { ComSat.Trace(this, "Awake"); entity = GetComponent <Entity>(); movable = GetComponent <SimpleMovable>(); buildIndex = -1; entity.AddUpdateAction(TickUpdate); }
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 Start() { comSat = FindObjectOfType <ComSat>(); localPlayerName = PlayerPrefs.GetString("localPlayerName", Environment.UserName); hostAddress = PlayerPrefs.GetString("hostAddress", ""); hostPort = PlayerPrefs.GetString("hostPort", "11235"); scrollMode = PlayerPrefs.GetInt("Scroll Mode"); }
public void TickUpdate() { ComSat.Trace(this, "TickUpdate"); foreach (var a in updateActions) { a(); } position += velocity * ComSat.tickRate; }
void Attack(Entity[] targets) { ComSat.Trace(this, "Attack"); mode = Mode.ATTACK; target = null; this.targets = targets; movingToTarget = false; vehicle.Stop(); }
void Awake() { ComSat.Trace(this, "Awake"); entity = GetComponent <Entity>(); entity.AddUpdateAction(TickUpdate); combatVehicle = GetComponent <CombatVehicle>(); missilesLoaded = maxMissiles; }
void Awake() { ComSat.Trace(this, "Awake"); entity = GetComponent <Entity>(); entity.AddUpdateAction(TickUpdate); combatVehicle = GetComponent <CombatVehicle>(); fireCycle = FireCycle.READY; }
void Awake() { ComSat.Trace(this, "Awake"); entity = GetComponent <Entity>(); entity.AddUpdateAction(TickUpdate); vehicle = GetComponent <Vehicle>(); mode = Mode.IDLE; }
void TickUpdate() { ComSat.Trace(this, "TickUpdate"); age += ComSat.tickRate; if (age >= lifetime) { ComSat.DestroyEntity(entity, DestroyReason.OldAge); } }
void OnGUI() { if (entity.isSelected && powerIsToggleableInGame) { if (GUI.Button(new Rect(Camera.main.pixelWidth - 74, Camera.main.pixelHeight - 74, 64, 64), poweredOn ? "ON" : "OFF")) { ComSat.IssueSetPowerState(entity, !poweredOn); } } }
bool CanPlaceAt(Entity thing, DVector2 position) { var dist = (position - entity.position).sqrMagnitude; var prefabSize = (DReal)thing.collisionRadiusNumerator / thing.collisionRadiusDenominator; var minDist = (prefabSize + entity.collisionRadius) * (prefabSize + entity.collisionRadius); var maxDist = buildRadius * buildRadius; return minDist < dist && dist < maxDist && ComSat.FindEntityWithinRadius(position, prefabSize) == null && buildMan.CanBuildAt(position, prefabSize); }
void TickUpdate() { ComSat.Trace(this, "TickUpdate"); if(!powerSink.poweredOn) { target = null; audio.Stop(); return; } if(!ComSat.EntityExists(target)) { // Magic. Destroyed GameObjects compare against null. // Explicitly set to null to avoid keeping it around. target = null; audio.Stop(); // Search for victims. target = ComSat.FindEntityWithinRadius(entity.position, attackRange, entity.team); if(target != null) { audio.Play(); } } else { var dp = target.position - entity.position; DReal targetTurretAngle; var projectileProjectile = projectilePrefab.GetComponent<Projectile>(); if(projectileProjectile != null && powerSink.Powered()) { var aimSpot = Utility.PredictShot(entity.position, projectileProjectile.initialSpeed, target.position, target.velocity); targetTurretAngle = DReal.Mod(DVector2.ToAngle(aimSpot - entity.position) - entity.rotation, DReal.TwoPI); } else { targetTurretAngle = DReal.Mod(DVector2.ToAngle(dp) - entity.rotation, DReal.TwoPI); } // Turn turret to point at target. TurnTurret(targetTurretAngle); // Fire when pointing the gun at the target. if(targetTurretAngle == turretRotation) { Fire(); } // Stop shooting when out of range. if(dp.sqrMagnitude >= attackRange * attackRange) { audio.Stop(); target = null; } } if(fireDelay > 0) { fireDelay -= ComSat.tickRate; } }
// (Client) void AttackCommand(int team, int entityID, int[] targetIDs) { targetIDs = targetIDs ?? new int[] {}; var entity = EntityFromID(entityID); var targets = targetIDs.Select(id => EntityFromID(id)).Where(e => ComSat.EntityExists(e)).ToArray(); if (entity != null && targets.Any() && entity.team == team) { Log("{" + tickID + "} " + entity + "[" + entityID + "] attack " + string.Join(", ", targetIDs.Select(x => x.ToString()).ToArray())); entity.gameObject.SendMessage("Attack", targets, SendMessageOptions.DontRequireReceiver); } }
void Attack(Entity[] targets) { ComSat.Trace(this, "Attack"); var validTargets = targets.Where(t => ComSat.EntityExists(t) && t.GetComponent(typeof(ISabotagable)) != null).OrderBy(t => (t.position - entity.position).sqrMagnitude); if (!validTargets.Any()) { return; } target = validTargets.First(); moving = true; }
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); }
void Awake() { ComSat.Trace(this, "Awake"); entity = GetComponent<Entity>(); entity.AddUpdateAction(TickUpdate); entity.AddDestroyAction(DestroyAction); powerSink = GetComponent<PowerSink>(); buildQueue = new Queue<BuildCommandData>(); resourceMan = FindObjectOfType<ResourceManager>(); buildMan = FindObjectOfType<BuildManager>(); playerInterface = FindObjectOfType<PlayerInterface>(); ResetBuildTime(); }
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(); } } }