protected override void preformTask(float deltaTime) { if (this.trainingQueue.Count != 0) { if (this.isTeamFull()) { return; } this.trainingProgress += deltaTime; UnitBase nextInQueue = this.trainingQueue[0].getPrefab().GetComponent <UnitBase>(); if (this.trainingProgress >= 0) // nextInQueue.getData().getProductionTime()) { { Vector2 v = Random.insideUnitCircle * 2f; float i = 1.5f; v.x += (v.x < 0 ? -i : i); v.y += (v.x < 0 ? -i : i); Vector3 pos = this.transform.position + new Vector3(v.x, 0, v.y); RegisteredObject regObj = this.trainingQueue[0]; this.trainingQueue.RemoveAt(0); SpawnInstructions <SidedEntity> instructions = this.map.spawnEntity <SidedEntity>( regObj, pos, Quaternion.Euler(0, Random.Range(0, 359), 0)); instructions.getObj().setTeam(this.getTeam()); instructions.spawn(); this.trainingProgress = 0; } } }
public void spawnEntity(MessageSpawnEntity msg) { SpawnInstructions <SidedEntity> instructions = this.map.spawnEntity <SidedEntity>( Registry.getObjectFromRegistry(msg.entityId), msg.position, msg.rotation); instructions.getObj().setTeam(msg.getTeam()); instructions.spawn(); }
public void constructBuilding(MessageConstructBuilding msg) { // Create the new building GameObject and set it's team. SpawnInstructions <BuildingBase> instructions = this.map.spawnEntity <BuildingBase>( Registry.getObjectFromRegistry(msg.entityId), new Vector3(msg.position.x, 0, msg.position.z), Quaternion.identity); BuildingBase newBuilding = instructions.getObj(); Team team = Team.getTeamFromId(msg.teamId); newBuilding.setTeam(team); // Remove resources from the builder's team. this.map.reduceResources(team, newBuilding.getData().getCost()); // Set the buildings health and send the builder to build it. BuildingData bd = newBuilding.getData(); if (bd.isInstantBuild()) { newBuilding.setHealth(bd.getMaxHealth()); } else { newBuilding.setHealth(1); UnitBuilder builder = map.findMapObjectFromGuid <UnitBuilder>(msg.builderGuid); builder.setTask(new TaskConstructBuilding(builder, newBuilding)); builder.unitStats.buildingsBuilt.increase(); } if (newBuilding is BuildingBridge) { } instructions.spawn(); }