|
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using CIG.Translation;
- using CIG3.ExtensionMethods;
- using CIGEnums;
- using SUISS.Core;
- using SUISS.Scheduling;
- using SUISS.Storage;
- using SUISSEngine;
- using UnityEngine;
-
- public class CIGPort : CIGCommercialBuilding
- {
- protected static double GetGoldSpawnTimestamp()
- {
- Dictionary<string, object> dictionary = Storage.Get(StorageLifecycle.Game).GetDictionary("RabbitHole");
- if (dictionary.ContainsKey("BunnyTime"))
- {
- return dictionary.GetValue("BunnyTime", Timing.UtcNow) + 28800.0;
- }
- double utcNow = Timing.UtcNow;
- dictionary["BunnyTime"] = utcNow;
- return utcNow + 28800.0;
- }
-
- protected static void SetGoldSpawnTimestamp()
- {
- Storage.Get(StorageLifecycle.Game).GetDictionary("RabbitHole")["BunnyTime"] = Timing.UtcNow;
- }
-
- protected override void OnSerialize(Dictionary<string, object> values)
- {
- base.OnSerialize(values);
- values["LastCollectTime"] = this._lastCollectTime;
- values["Spawned"] = this._haveGold;
- }
-
- protected override void OnDeserialize(Dictionary<string, object> values)
- {
- base.OnDeserialize(values);
- this._lastCollectTime = values.GetValue("LastCollectTime", 0.0);
- this._haveGold = values.GetValue("Spawned", false);
- }
-
- protected override void OnDeserialized()
- {
- base.OnDeserialized();
- this.CreateVehicle();
- if ((!this.activatable || this.Activated) && Timing.UtcNow - this._lastCollectTime < 60.0)
- {
- this.Launch();
- }
- }
-
- protected override void OnUpgradeCompleted(double upgradedTime)
- {
- base.OnUpgradeCompleted(upgradedTime);
- if (this.activatable && base.CurrentLevel == 1)
- {
- this.Launch();
- }
- }
-
- protected override IEnumerator WaitForProfit()
- {
- yield return null;
- while (this._vehicle == null || !this._vehicle.IsIdle())
- {
- yield return Timing.time + 0.5;
- }
- yield break;
- }
-
- protected override void ShowProfitIcon(bool maxed)
- {
- if (!this._haveGold && UnityEngine.Random.value > 0.3f && CIGPort.GetGoldSpawnTimestamp() < Timing.UtcNow)
- {
- CIGPort.SetGoldSpawnTimestamp();
- this._haveGold = true;
- this.serializing.Serialize();
- }
- if (this._haveGold)
- {
- ButtonGridTileIcon buttonGridTileIcon = this._gridTileIconManager.SetIcon<ButtonGridTileIcon>(GridTileIconType.GoldProfit);
- buttonGridTileIcon.Init(delegate
- {
- base.ClickProfitIcon(base.gameObject);
- });
- }
- else
- {
- base.ShowProfitIcon(maxed);
- }
- }
-
- protected override void CollectProfit(Currencies profit, bool maxed)
- {
- this.Launch();
- if (this._haveGold)
- {
- string text = "XP";
- if (profit.ContainsPositive(text))
- {
- profit = new Currencies(new object[]
- {
- "Gold",
- 1m,
- text,
- profit.GetValue(text)
- });
- }
- else
- {
- profit = new Currencies("Gold", 1m);
- }
- if (SingletonMonobehaviour<CIGGameStats>.IsAvailable)
- {
- SingletonMonobehaviour<CIGGameStats>.Instance.IncrementGoldEarned_Ports();
- }
- this._haveGold = false;
- }
- base.CollectProfit(profit, maxed);
- this._lastCollectTime = Timing.UtcNow;
- this.serializing.Serialize();
- }
-
- protected override bool HasTimeLeft
- {
- get
- {
- return this._vehicle == null || !this._vehicle.IsIdle();
- }
- }
-
- public override ILocalizedString TimeLeftString()
- {
- if (this._vehicle == null || !this._vehicle.IsIdle())
- {
- return Localization.Key("port_wait_for_boat");
- }
- return Localization.Format(Localization.Key("second_symbol"), new ILocalizedString[]
- {
- Localization.Integer(0)
- });
- }
-
- protected void CreateVehicle()
- {
- GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(this.fishingBoatPrefab);
- this._vehicle = gameObject.GetComponent<ScriptedVehicle>();
- if (this._vehicle == null)
- {
- UnityEngine.Debug.LogError("Failed to instantiate a the boat.");
- UnityEngine.Object.Destroy(gameObject);
- return;
- }
- if (this.pathOverride != null && this.pathOverride.Length > 0)
- {
- this._vehicle.path = this.pathOverride;
- }
- this._vehicle.idleDirection = this.idleDirectionOverride;
- this._vehicle.transform.parent = this.tile.grid.transform;
- GridIndex index = this.tile.element.Index;
- index.u += this.vehicleStartOffsetU;
- index.v += this.vehicleStartOffsetV;
- this._vehicle.SpawnAt(index, 0);
- }
-
- protected void Launch()
- {
- if (this._vehicle != null)
- {
- this._vehicle.Launch();
- }
- }
-
- public GameObject fishingBoatPrefab;
-
- public Vehicle.Direction[] pathOverride;
-
- public Vehicle.Direction idleDirectionOverride;
-
- public int vehicleStartOffsetU;
-
- public int vehicleStartOffsetV;
-
- protected const string LastCollectTimeKey = "LastCollectTime";
-
- protected const string GoldSpawnedKey = "Spawned";
-
- protected const string GoldSpawnDictionaryKey = "RabbitHole";
-
- protected const string GoldSpawnTimestampKey = "BunnyTime";
-
- protected const double GoldSpawnInterval_Seconds = 28800.0;
-
- protected ScriptedVehicle _vehicle;
-
- protected double _lastCollectTime;
-
- protected bool _haveGold;
- }
|