public void BreakDownBuilding(Building building) { building.state = Building.BuildingState.Destroyed; Crafting.EditorRecipe recipe = building.info.recipe; Vector2 anchorPos = TerrainManager.PosToV2(building.gameObject.transform.position) - building.info.anchorOffset; for (int y = 0; y < recipe.rows.Count; y++) { for (int x = 0; x < recipe.rows[y].columns.Count; x++) { ResourceInfo resourceInfo = ResourceInfo.GetInfoFromType(recipe.rows [y].columns [x].resourceType); for (int i = 0; i < recipe.rows [y].columns [x].count; i++) { TerrainManager.instance.SpawnResource(new Vector3(anchorPos.x + x, 0, anchorPos.y + y), resourceInfo, building.island); } } } buildings.Remove(building); Destroy(building.gameObject); SavedGame.UpdateBuildings(); }
void LoadRecipe() { for (int x = 0; x < 2; x++) { for (int y = 0; y < 2; y++) { if (x < Crafting.instance.recipes [curRecipe].resources.GetLength(0) && y < Crafting.instance.recipes [curRecipe].resources.GetLength(1)) { Crafting.Stack curStack = Crafting.instance.recipes [curRecipe].resources [x, y]; tiles [x, y].color = (curStack.tileType != ResourceInfo.ResourceType.None) ? ResourceInfo.GetInfoFromType(curStack.tileType).colorDark : defaultTileColor; resources [x, y].sprite = ResourceInfo.GetInfoFromType(curStack.resourceType).sprite; numbers [x, y].text = curStack.count.ToString(); resources [x, y].gameObject.SetActive(true); } else { tiles [x, y].color = defaultTileColor; resources [x, y].gameObject.SetActive(false); numbers [x, y].text = ""; } } } recipeName.text = Crafting.instance.recipes [curRecipe].name; }
void ChangeHealth(float amount) { health += amount; if (location != null) { location.SaveEnemies(); } if (amount < 0f) { if (health <= 0) { if (player) { StartCoroutine(playerScript.Respawn()); } else { for (int i = 0; i < dropCount; i++) { tm.SpawnResource(transform.position, ResourceInfo.GetInfoFromType(dropType), location); } location.EnemyDeath(GetComponent <Body> ()); gm.EnemyDeath(GetComponent <Body> ()); Destroy(gameObject); } } } else { if (health > maxHealth) { health = maxHealth; } } if (healthBar != null) { healthBar.UpdateBar(health, maxHealth); } }
public virtual void ProduceResources() { turnsUntilNextResource = turnWaitPerResource; for (int i = 0; i < resourcesProducedPerCycle; i++) { if (hasLimitedSupply && supply <= 0) { break; } if (exceedsPadCapacity) { break; } TerrainManager.instance.SpawnResource(position: spawnPos, info: ResourceInfo.GetInfoFromType(resourceType), island: island); if (hasLimitedSupply) { supply -= 1; } } if (movesResources) { ResourcePickup.GetAtPosition(TerrainManager.PosToV2(spawnPos)).AnimateMove(productionCenter.position, false, resourcesProducedPerCycle); } SavedGame.UpdateBuildingSupply(this); if (!autoCycles) { state = BuildingState.Waiting; } if (hasLimitedSupply && supply <= 0) { Deactivate(); } }