|
- using System;
- using System.Collections.Generic;
- using CIG.Translation;
- using CIG3.ExtensionMethods;
- using CIGEnums;
- using SUISSEngine;
- using UnityEngine;
-
- public class CIGUnlockBuilding : CIGBuilding
- {
- protected GridIndex UnlockTileIndex
- {
- get
- {
- GridIndex index = this.tile.index;
- index.u += this.unlockTileOffsetU;
- index.v += this.unlockTileOffsetV;
- return index;
- }
- }
-
- public virtual void OnDrawGizmosSelected()
- {
- if (IsometricIsland.Current != null && this.VehiclePath.Length > 0)
- {
- Vector3 position = IsometricIsland.Current.grid.transform.position;
- Vector3 b = IsometricIsland.Current.grid.GetPositionForGridPoint(new GridPoint((float)this.gridPositionU, (float)this.gridPositionV));
- Vector3 vector = IsometricIsland.Current.grid.GetPositionForGridPoint(new GridPoint(this.VehiclePath[0].x, this.VehiclePath[0].y));
- if (this.FlyingHeight.Length > 0)
- {
- Vector3 a = vector;
- Vector3 vector2 = new Vector3(0f, 1f);
- vector = a + vector2.normalized * this.FlyingHeight[0];
- }
- vector += position + b;
- for (int i = 1; i < this.VehiclePath.Length; i++)
- {
- Vector3 vector3 = IsometricIsland.Current.grid.GetPositionForGridPoint(new GridPoint(this.VehiclePath[i].x, this.VehiclePath[i].y));
- vector3 += position + b;
- if (i < this.FlyingHeight.Length)
- {
- Vector3 a2 = vector3;
- Vector3 vector4 = new Vector3(0f, 1f);
- vector3 = a2 + vector4.normalized * this.FlyingHeight[i];
- }
- Gizmos.DrawLine(vector, vector3);
- vector = vector3;
- }
- }
- }
-
- protected override void OnDeserialized()
- {
- base.OnDeserialized();
- bool flag = false;
- if (base.GameState.IsIslandUnlocked(this.unlocksIsland))
- {
- GridIndex unlockTileIndex = this.UnlockTileIndex;
- for (int i = unlockTileIndex.u; i > unlockTileIndex.u - this.tile.size.u; i--)
- {
- for (int j = unlockTileIndex.v; j > unlockTileIndex.v - this.tile.size.v; j--)
- {
- GridIndex index = new GridIndex(i, j);
- CIGExpansions.ExpansionBlock blockForIndex = this.expansions.reference.GetBlockForIndex(index);
- flag |= (blockForIndex != null);
- if (blockForIndex != null && !blockForIndex.Unlocked)
- {
- blockForIndex.CanUnlock = true;
- blockForIndex.Unlock(Currencies.Zero);
- }
- }
- }
- }
- if (!this.Activated)
- {
- if (base.GameState.IsIslandUnlocked(this.unlocksIsland))
- {
- if (!flag)
- {
- UnityEngine.Debug.LogError(string.Format("{1}: no blocks close to {0}! (key is {2})", this.UnlockTileIndex, base.name, this.serializing.StorageKey));
- }
- base.PerformUpgrade();
- this.SpawnVehicle();
- IsometricIsland parent = IsometricIsland.GetParent(this);
- if (!parent.HasCenteredViewOnce)
- {
- parent.CenterCameraOnBuilding(this);
- }
- }
- }
- else
- {
- this.SpawnVehicle();
- }
- }
-
- public override bool CanUpgrade
- {
- get
- {
- CIGExpansions.ExpansionBlock blockForIndex = this.expansions.reference.GetBlockForIndex(this.UnlockTileIndex);
- return (blockForIndex == null || blockForIndex.Unlocked) && (!this.checkForRoad || this.HasRoad) && base.CanUpgrade;
- }
- }
-
- public override ILocalizedString ReasonWhyCantUpgrade(out ILocalizedString title)
- {
- CIGExpansions reference = this.expansions.reference;
- if (reference != null)
- {
- CIGExpansions.ExpansionBlock blockForIndex = reference.GetBlockForIndex(this.UnlockTileIndex);
- if (blockForIndex != null && !blockForIndex.Unlocked)
- {
- title = ((!this.Activated) ? Localization.Key("steps_to_complete_to_activate_this_building") : Localization.Key("steps_to_complete_to_be_able_to_upgrade_this_building"));
- return Localization.Key("buy_expansion_first");
- }
- }
- if (this.checkForRoad && !this.HasRoad)
- {
- title = ((!this.Activated) ? Localization.Key("steps_to_complete_to_activate_this_building") : Localization.Key("steps_to_complete_to_be_able_to_upgrade_this_building"));
- return Localization.Key("building_needs_road");
- }
- return base.ReasonWhyCantUpgrade(out title);
- }
-
- public override bool InfoRequiresFrequentRefresh
- {
- get
- {
- return base.IsUpgrading && base.InfoRequiresFrequentRefresh;
- }
- }
-
- public override bool CanSpeedup
- {
- get
- {
- return base.IsUpgrading && base.CanSpeedup;
- }
- }
-
- public override ILocalizedString InfoText()
- {
- if (base.IsUpgrading)
- {
- return base.InfoText();
- }
- if (this.Activated)
- {
- return Localization.Format(Localization.Key("you_can_go_to"), new ILocalizedString[]
- {
- this.unlocksIsland.GetDisplayName()
- });
- }
- return Localization.Format(Localization.Key("unlocks_island"), new ILocalizedString[]
- {
- this.unlocksIsland.GetDisplayName()
- });
- }
-
- public override List<BuildingProperty> ShownProperties
- {
- get
- {
- List<BuildingProperty> list = base.ShownProperties;
- if (list == null)
- {
- list = new List<BuildingProperty>();
- }
- if (!base.IsUpgrading)
- {
- list.Add(BuildingProperty.Text);
- }
- return list;
- }
- }
-
- protected override void OnUpgradeCompleted(double upgradedTime)
- {
- base.OnUpgradeCompleted(upgradedTime);
- if (base.CurrentLevel == 1)
- {
- base.GameState.SetIslandUnlocked(this.unlocksIsland);
- base.GameState.SetConnectionUnlocked(this.island, this.unlocksIsland);
- }
- base.IslandState.AddTransport(50);
- this.SpawnVehicle();
- }
-
- protected override bool UseGreyShader
- {
- get
- {
- return false;
- }
- }
-
- private void SpawnVehicle()
- {
- if (this.VehiclePrefab != null)
- {
- Transform transform = base.transform;
- CIGUnlockBuildingVehicleManager cigunlockBuildingVehicleManager = null;
- while (cigunlockBuildingVehicleManager == null && transform != null)
- {
- cigunlockBuildingVehicleManager = transform.gameObject.GetComponent<CIGUnlockBuildingVehicleManager>();
- transform = transform.parent;
- }
- if (cigunlockBuildingVehicleManager == null)
- {
- UnityEngine.Debug.LogError("Can't find CIGUnlockBuildingVehicleManager in parent. I need it to spawn my vehicle.");
- }
- else
- {
- GridPoint[] array = new GridPoint[this.VehiclePath.Length];
- for (int i = 0; i < this.VehiclePath.Length; i++)
- {
- array[i] = new GridPoint(this.VehiclePath[i].x, this.VehiclePath[i].y) + new GridPoint((float)this.gridPositionU, (float)this.gridPositionV);
- }
- cigunlockBuildingVehicleManager.SpawnVehicleAt(new CIGUnlockBuilding.SVehicleSpawnInfo
- {
- path = array,
- vehiclePrefab = this.VehiclePrefab,
- unlockBuilding = this,
- flyingHeight = this.FlyingHeight
- });
- }
- }
- }
-
- public Island unlocksIsland;
-
- public int unlockTileOffsetU;
-
- public int unlockTileOffsetV;
-
- public GameObject VehiclePrefab;
-
- public Vector2[] VehiclePath;
-
- public float[] FlyingHeight;
-
- private MagicalReference<CIGExpansions> expansions = new MagicalReference<CIGExpansions>();
-
- public struct SVehicleSpawnInfo
- {
- public GameObject vehiclePrefab;
-
- public CIGUnlockBuilding unlockBuilding;
-
- public GridPoint[] path;
-
- public float[] flyingHeight;
- }
- }
|