public void Load() { resourceList = JsonConvert.DeserializeObject <PlayerCharacterSaveLoad>(PlayerPrefs.GetString(KeyUtils.CHARACTER_DATA)); //JsonUtility.FromJson<PlayerCharacterSaveLoad>(PlayerPrefs.GetString(KeyUtils.CHARACTER_DATA)); if (resourceList == null) { resourceList = new PlayerCharacterSaveLoad { currentCharacter = 0 }; for (int i = 0; i < 6; i++) { int id = UnityEngine.Random.Range(0, 4); resourceList.AddData(CharacterResource.CreateInstance((int)ResourceType.CharacterType, id, 1, i)); } Save(); } for (int i = 0; i < resourceList.dataList.Count; i++) { inventoryDic.Add(resourceList.dataList[i].characterId, resourceList.dataList[i]); } }
public void OnCharacterInteract(GameObject character) { if (IsLoaded) { return; } CharacterResource characterResource = character.GetComponent <CharacterResource>(); if (characterResource.HasResource(resourceType)) { var resource = characterResource.GetResource(); characterResource.LetResourceDown(); resource.Consume(); switch (resourceType) { case ResourceTypes.Ammunition: AkSoundEngine.PostEvent("Load_ENE_In_DEF_Room", gameObject); break; case ResourceTypes.Energy: AkSoundEngine.PostEvent("Load_MUN_In_ATK_Room", gameObject); break; } IsLoaded = true; OnLoad.Invoke(); } }
public void SetTarget(CharacterResource resource) { this.resource = resource; resource.OnValueChanged += UpdateBars; UpdateBars(null, 0); }
private void CreateCharacterStats(SpecBase spec) { Health = new CharacterResource(CreateStat(spec.BaseHealth, StatType.MaxHealth), spec.BaseHealth); Spirit = new CharacterResource(CreateStat(spec.BaseSpirit, StatType.MaxSpirit), 0); _strength = CreateStat(spec.BaseStrength, StatType.Strength); _will = CreateStat(spec.BaseWill, StatType.Will); _defence = CreateStat(spec.BaseDefence, StatType.Defence); _magicDefence = CreateStat(spec.BaseMagicDefence, StatType.MagicDefence); }
public void UpdateCharacterView() { characterResource = DataPlayer.GetModule <PlayerCharacter>().GetCurrentCharacter(); iconCharacter.sprite = LoadResourceController.GetCharacterItem(characterResource.characterId); level.text = "Lv. " + characterResource.level; characterResource.ReloadCharacterStat(); UpdateUpgradeView(); UpdateStatView(); }
public void ClearResourceUI() { _health.OnChange -= _healthBar.UpdateBar; _spirit.OnChange -= _spiritBar.UpdateBar; _healthBar.Clear(); _spiritBar.Clear(); _health = null; _spirit = null; }
public void RegisterResources(CharacterStats stats) { _health = stats.Health; _spirit = stats.Spirit; _healthBar.RegisterResource(_health); _spiritBar.RegisterResource(_spirit); _health.OnChange += _healthBar.UpdateBar; _spirit.OnChange += _spiritBar.UpdateBar; }
protected override void OnStart() { SpellDelay = SpellDelay < 0 ? 0 : SpellDelay; WindowDelay = WindowDelay < 1000 ? 1000 : WindowDelay; SkipWindowDelay = SkipWindowDelay < 200 ? 200 : SkipWindowDelay; GpPerTick = CharacterResource.GetGpPerTick(); if (Distance > 3.5f) { TreeRoot.Stop(Localization.ExGather_Distance); } if (HotSpots != null) { HotSpots.IsCyclic = Loops < 1; } // backwards compatibility if (GatherObjects == null && !string.IsNullOrWhiteSpace(GatherObject)) { GatherObjects = new List <string> { GatherObject } } ; startTime = DateTime.Now; if (Items == null) { Items = new NamedItemCollection(); } if (Collect && Collectables == null) { Collectables = new List <Collectable> { new Collectable { Name = string.Empty, Value = (int)CollectabilityValue } } } ; if (string.IsNullOrWhiteSpace(Name)) { Name = Items.Count > 0 ? Items.First().Name : string.Format(Localization.ExGather_Zone, WorldManager.ZoneId, ExProfileBehavior.Me.Location); } StatusText = Name; GamelogManager.MessageRecevied += ReceiveMessage; poiCoroutine = new ActionRunCoroutine(ctx => ExecutePoiLogic()); TreeHooks.Instance.AddHook("PoiAction", poiCoroutine); }
private static void AssertCharacterResourceHalLinksArePresent(CharacterResource resource) { var moveLink = resource.Links.FirstOrDefault(l => l.Rel.Equals(MoveLinkName)); var characterAttributesLink = resource.Links.FirstOrDefault(l => l.Rel.Equals(CharacterAttributeLinkName)); var movementsLink = resource.Links.FirstOrDefault(l => l.Rel.Equals(MovementLinkName)); AssertSelfLinkIsPresent(resource); Assert.That(moveLink, Is.Not.Null, $"Unable to find '{MoveLinkName}' link."); Assert.That(characterAttributesLink, Is.Not.Null, $"Unable to find '{CharacterAttributeLinkName}' link."); Assert.That(movementsLink, Is.Not.Null, $"Unable to find '{MovementLinkName}' link."); }
public static void AssertCharacterIsValid(CharacterResource characterResource) { Assert.That(characterResource, Is.Not.Null, $"{nameof(characterResource)}"); Assert.That(characterResource.ThumbnailUrl, Is.Not.Null, $"{nameof(characterResource.ThumbnailUrl)}"); Assert.That(characterResource.DisplayName, Is.Not.Null, $"{nameof(characterResource.DisplayName)}"); Assert.That(characterResource.ColorTheme, Is.Not.Null, $"{nameof(characterResource.ColorTheme)}"); Assert.That(characterResource.FullUrl, Is.Not.Null, $"{nameof(characterResource.FullUrl)}"); Assert.That(characterResource.InstanceId, Is.Not.Null, $"{nameof(characterResource.InstanceId)}"); Assert.That(characterResource.MainImageUrl, Is.Not.Null, $"{nameof(characterResource.MainImageUrl)}"); Assert.That(characterResource.Name, Is.Not.Null, $"{nameof(characterResource.Name)}"); AssertCharacterResourceHalLinksArePresent(characterResource); }
public bool RemoveCharacter(CharacterResource resource) { if (resource == null) { return(false); } resourceList.RemoveData(resource); inventoryDic.Remove(resource.characterId); Save(); return(true); }
public bool AddCharacter(CharacterResource resource) { if (resource == null || inventoryDic.ContainsKey(resource.characterId)) { return(false); } resourceList.AddData(resource); inventoryDic.Add(resource.characterId, resource); Save(); return(true); }
private void CalculateBattleActionRates() { CharacterResource playerHealth = PlayerCharacter.Active.Stats.Health; float playerHealthRate = playerHealth.MaxValue.GetFinalValue() / playerHealth.CurrentValue; float enemyHealthRate = Health.MaxValue.GetFinalValue() / Health.CurrentValue; _battleActionRates = new Dictionary <BattleAction, float>() { { BattleAction.Attack, playerHealthRate }, { BattleAction.Defence, 1 - playerHealthRate + enemyHealthRate }, { BattleAction.Heal, enemyHealthRate } }; }
/// <summary> /// Instantiates a new instance of the <see cref="BeforeGatherGpRegenStrategy"/> class. /// </summary> public BeforeGatherGpRegenStrategy(CordialStockManager cordialStockManager, IBeforeGatherGpRegenStrategyLogger logger) { if (logger == null) { throw new ArgumentNullException("logger"); } if (cordialStockManager == null) { throw new ArgumentNullException("cordialStockManager"); } this.logger = logger; this.cordialStockManager = cordialStockManager; this.gpPerTick = CharacterResource.GetGpPerTick(); }
public void RecieveReward() { if (resType == (int)ResourceType.ItemType) { DataPlayer.GetModule <PlayerInventory>().AddNewItem(ItemResource.CreateInstance(resType, resId, resNumber, 0, 0)); } else if (resType == (int)ResourceType.MoneyType) { DataPlayer.GetModule <PlayerMoney>().AddOne((MoneyType)resId, resNumber); } else if (resType == (int)ResourceType.CharacterType) { DataPlayer.GetModule <PlayerCharacter>().AddCharacter(CharacterResource.CreateInstance(resType, resId, resNumber)); } else { } }
/// <summary> /// Initializes this instance. /// </summary> public void Initialize(GameSceneMaster sceneMaster, NewCharWinAnimator newCharWinAnim, Vector3 initialCharacterRotation, CharacterResource characterResource, System.EventHandler <System.EventArgs> playCharacterDelegate, System.EventHandler <System.EventArgs> buyCharacterDelegate, System.EventHandler <System.EventArgs> charSelectShareDelegate, System.Action <int> ownedCharCountChangedDelegate, System.EventHandler <System.EventArgs> pressSoundDelegate, System.EventHandler <System.EventArgs> releaseSoundDelegate) { m_newCharWinAnim = newCharWinAnim; // Set the initial rotation for characters in character select m_initialRotation = initialCharacterRotation; // Initialize buttons m_playCharacterBtn.Initialize(playCharacterDelegate, UIButton.TriggerType.ON_RELEASE); m_buyCharacterBtn.Initialize(buyCharacterDelegate, UIButton.TriggerType.ON_RELEASE); m_charSelectShareBtn.Initialize(charSelectShareDelegate, UIButton.TriggerType.ON_RELEASE); // Set button sounds m_playCharacterBtn.AddSoundDelegates(pressSoundDelegate, releaseSoundDelegate); m_buyCharacterBtn.AddSoundDelegates(pressSoundDelegate, releaseSoundDelegate); m_charSelectShareBtn.AddSoundDelegates(pressSoundDelegate, releaseSoundDelegate); // Store delegate for when number of owned characters changes m_ownedCharCountChangedDelegate = ownedCharCountChangedDelegate; // Initialize text m_characterNameText.Initialize(); m_characterPriceText.Initialize(); m_characterCountText.Initialize(); // Initialize character list m_characterResource = characterResource; InitializeCharacterScrollPanel(sceneMaster); UpdateCharacterCountText(); // Set the initialized flag m_isInitialized = true; }
/// <summary> /// Initializes parts of the data system that require other systems to be initialized first. /// </summary> /// <param name="charResource">The character resource.</param> public void LateInitialize(CharacterResource charResource) { m_charResource = charResource; // Load game data Load(); // Create list of new/unused characters foreach (CharacterType character in Enum.GetValues(typeof(CharacterType))) { // Skip the size member if (character == CharacterType.SIZE) { continue; } // If not yet used, add to the new character list if (!LoadCharacterUsed(character)) { m_newCharList.Add(character); } } }
public void RefreshUI() { currentCharacter = playerCharacter.GetCurrentCharacter(); var itemList = playerInventory.GetEquipmentItemWithIdCharacter(currentCharacter.characterId); for (int i = 0; i < equipments.Length; i++) { equipments[i].SetupItem(null); // Set data if (itemList != null) { for (int j = 0; j < itemList.Count; j++) { if ((int)equipments[i].id == PlayerMoney.GetRealItemId(itemList[j].id)) { equipments[i].SetupItem(itemList[j]); break; } } } } }
public void Clear() { _resource = null; }
public void RegisterResource(CharacterResource resource) { _resource = resource; UpdateBar(resource.CurrentValue); }
/// <summary> /// Initializes this instance. /// </summary> public void Initialize(CharacterResource charResource, Action <string> charPurchaseSucceededDelegate, Action <string> charPurchaseCancelledDelegate, Action restoreTransactionsCompletedDelegate, Action restoreTransactionsFailedDelegate, Action <int> coinBalanceChangedDelegate, Action <int> gachaBalanceChangedDelegate) { // Initialize only once if (m_isInitialized) { return; } // Set up character data in Soomla's StoreAssets CRCAssets.CharactersLTVGArray = new EquippableVG[charResource.CharacterCount]; m_charItemIDDictionary.Clear(); // For testing: Index used for assigning test product IDs //int testIDIndex = 0; for (int index = 0; index < charResource.CharacterCount; ++index) { CharacterType character = (CharacterType)index; CharacterResource.CharacterStruct charData = charResource.GetCharacterStruct(character); // Check if character is buyable PurchaseType purchaseType = new PurchaseWithMarket(charData.ItemID, charData.Price); /* * // For testing: Use test product IDs for the first four purchasable characters * PurchaseType purchaseType = null; * string productID = charData.ItemID; * if (charData.IsBuyable) * { * if (testIDIndex == 0) productID = CRCAssets.PURCHASED_TEST_ID; * else if (testIDIndex == 1) productID = CRCAssets.CANCELED_TEST_ID; * else if (testIDIndex == 2) productID = CRCAssets.REFUNDED_TEST_ID; * else if (testIDIndex == 3) productID = CRCAssets.UNAVAILABLE_TEST_ID; * testIDIndex++; * } * purchaseType = new PurchaseWithMarket(productID, charData.Price); * //purchaseType = new PurchaseWithMarket(CRCAssets.PURCHASED_TEST_ID, charData.Price); */ // Create equippable virtual good instance for each character CRCAssets.CharactersLTVGArray[index] = new EquippableVG( EquippableVG.EquippingModel.CATEGORY, charData.Name, "", charData.ItemID, purchaseType); // Add the item ID and character type to a dictionary if (!m_charItemIDDictionary.ContainsKey(charData.ItemID)) { m_charItemIDDictionary.Add(charData.ItemID, character); } } // Create an instance of the in-game implementation of IStoreAssets CRCAssets crcAssets = new CRCAssets(); // Update the list of character goods for (int index = 0; index < charResource.CharacterCount; ++index) { crcAssets.AddToCharacterGoodsList(CRCAssets.CharactersLTVGArray[index]); } // Finalize character goods collections before initializing Soomla Store crcAssets.FinalizeCharacterGoods(); // Save delegates m_charPurchaseSucceededDelegate = charPurchaseSucceededDelegate; m_charPurchaseCancelledDelegate = charPurchaseCancelledDelegate; m_restoreTransactionsCompletedDelegate = restoreTransactionsCompletedDelegate; m_restoreTransactionsFailedDelegate = restoreTransactionsFailedDelegate; m_coinBalanceChangedDelegate = coinBalanceChangedDelegate; m_gachaBalanceChangedDelegate = gachaBalanceChangedDelegate; // Subscribe to Store events StoreEvents.OnSoomlaStoreInitialized += OnSoomlaStoreInitialized; StoreEvents.OnCurrencyBalanceChanged += OnCurrencyBalanceChanged; StoreEvents.OnMarketPurchaseStarted += OnMarketPurchaseStarted; StoreEvents.OnMarketPurchase += OnMarketPurchase; StoreEvents.OnMarketPurchaseCancelled += OnMarketPurchaseCancelled; StoreEvents.OnMarketRefund += OnMarketRefund; StoreEvents.OnRestoreTransactionsStarted += OnRestoreTransactionsStarted; StoreEvents.OnRestoreTransactionsFinished += OnRestoreTransactionsFinished; StoreEvents.OnUnexpectedStoreError += OnUnexpectedStoreError; // Initialize rewards m_firstLaunchReward = new VirtualItemReward( "first-launch", "Give coins at first launch", CRCAssets.COIN_CURRENCY_ITEM_ID, FIRST_LAUNCH_REWARD_AMOUNT); // Initialize the store with the in-game implementation of IStoreAssets // Note: This must be done after setting up values in the store assets class SoomlaStore.Initialize(crcAssets); }
/// <summary> /// Initializes this instance. /// </summary> public void Initialize(CharacterResource characterResource, NewCharWinAnimator newCharWinAnim, Vector3 initialCharacterRotation, System.EventHandler <System.EventArgs> openGachaDelegate, System.EventHandler <System.EventArgs> gachaPlayDelegate, System.EventHandler <System.EventArgs> gachaShareDelegate, System.EventHandler <System.EventArgs> repeatGachaDelegate, System.EventHandler <System.EventArgs> gachaOpenedDelegate, System.EventHandler <System.EventArgs> pressSoundDelegate, System.EventHandler <System.EventArgs> releaseSoundDelegate) { m_characterResource = characterResource; m_newCharWinAnim = newCharWinAnim; // Set the initial rotation for characters in character select m_initialRotation = initialCharacterRotation; // Initialize buttons m_openGachaBtn.Initialize(openGachaDelegate, UIButton.TriggerType.ON_RELEASE); m_gachaPlayBtn.Initialize(gachaPlayDelegate, UIButton.TriggerType.ON_RELEASE); m_gachaShareBtn.Initialize(gachaShareDelegate, UIButton.TriggerType.ON_RELEASE); m_repeatGachaBtn.Initialize(repeatGachaDelegate, UIButton.TriggerType.ON_RELEASE); // Set button sounds m_openGachaBtn.AddSoundDelegates(pressSoundDelegate, releaseSoundDelegate); m_gachaPlayBtn.AddSoundDelegates(pressSoundDelegate, releaseSoundDelegate); m_gachaShareBtn.AddSoundDelegates(pressSoundDelegate, releaseSoundDelegate); m_repeatGachaBtn.AddSoundDelegates(pressSoundDelegate, releaseSoundDelegate); // Initialize invisible button for gacha machine lever m_gachaMachineLever.Initialize(openGachaDelegate, UIButton.TriggerType.ON_PRESS); // Initialize text m_characterNameText.Initialize(); m_prizeLabelText.Initialize(); // Get delegate to call when gacha has been opened m_gachaOpenedDelegate = gachaOpenedDelegate; // Set scale of gacha machine depending on device orientation float newScale = Locator.GetUIManager().UICamera.IsLandscape ? m_gachaMachineLandscapeScale : m_gachaMachinePortraitScale; m_gachaAnim.transform.localScale = Vector3.one * newScale; // Initialize gacha overlay UI animator // State 1: 1 alpha, covering gacha and entire screen // State 2: 0 alpha, revealing gacha prize m_gachaOverlayAnimator = new UIAnimator(m_gachaOverlay); m_gachaOverlayAnimator.SetAlphaAnimation(1.0f, 0.0f); m_gachaOverlayAnimator.SetAnimTime(m_gachaOverlayAnimTime); m_gachaOverlayAnimator.ResetToState1(); // Note gacha animator's initial speed m_gachaAnimInitialSpeed = m_gachaAnim.speed; // Reset state (should come after initializing other values) Reset(); // Set the initialized flag m_isInitialized = true; }
/// <summary> /// Configures the strategy for use /// </summary> protected void Configure(GatheringPointObject node, IGatheringRotation gatherRotation, GatherStrategy gatherStrategy, CordialTime cordialTime, CordialType cordialType) { if (gatherRotation == null) { throw new ArgumentNullException("gatherRotation"); } // Set gathering parameters this.gatherRotation = gatherRotation; this.gatherStrategy = gatherStrategy; // Set cordial parameters this.cordialTime = cordialTime; this.requestedCordialType = this.effectiveCordialType = cordialType; // Override cordial type if (this.requestedCordialType > CordialType.None) { // Turn off cordial when there is no stock if (!this.cordialStockManager.HasStock()) { this.effectiveCordialType = CordialType.None; this.logger.RegeneratingCordialUseDisabledNoStock(); } // Turn off cordial when node is not ephemeral in TnG strategies if (this.gatherStrategy == GatherStrategy.TouchAndGo && !node.IsEphemeral()) { this.effectiveCordialType = CordialType.None; } } else { this.effectiveCordialType = this.requestedCordialType; } // Set node lifespan parameters this.NodeLifespan = new EffectiveNodeLifespan(NodeHelper.GetNodeLifespan(node), this.gatherRotation.Attributes.RequiredTimeInSeconds); if (this.gatherStrategy == GatherStrategy.TouchAndGo) { this.NodeLifespan.Clamp(TimeSpan.Zero, TimeSpan.FromSeconds(MAX_TOUCHANDGO_WAIT)); } this.EffectiveTimeTillGather = this.NodeLifespan.DeSpawn; // Set GP parameters this.StartingGp = this.CurrentGp; this.MaxGp = ExProfileBehavior.Me.MaxGP; this.EffectiveGp = CharacterResource.GetEffectiveGp(this.NodeLifespan.DeSpawnTicks); // Set breakpoint and cordial parameters this.CalculateTargetAndCordialSelection(); // Calculate regeneration parameters this.RegeneratedGp = (ushort)(this.TargetGp - this.CordialGp - this.StartingGp); if (this.RegeneratedGp < 0) { this.RegeneratedGp = 0; } this.EffectiveTimeToRegenerate = CharacterResource.EstimateExpectedRegenerationTime(this.RegeneratedGp); }
protected override void OnStart() { SpellDelay = SpellDelay < 0 ? 0 : SpellDelay; WindowDelay = WindowDelay < 500 ? 500 : WindowDelay; SkipWindowDelay = SkipWindowDelay < 200 ? 200 : SkipWindowDelay; GpPerTick = CharacterResource.GetGpPerTick(); if (Distance > 3.5f) { TreeRoot.Stop(Localization.Localization.ExGather_Distance); } if (HotSpots != null) { HotSpots.IsCyclic = Loops < 1; } // backwards compatibility if (GatherObjects == null && !string.IsNullOrWhiteSpace(GatherObject)) { GatherObjects = new List <string> { GatherObject }; } startTime = DateTime.Now; if (Items == null) { Items = new NamedItemCollection(); #pragma warning disable 618 if (ItemNames != null) { foreach (var item in ItemNames) { Items.Add(new GatherItem { Name = item }); } } if (Collectables != null) { foreach (var collectable in Collectables) { Items.Add(collectable); } } #pragma warning restore 618 } if (string.IsNullOrWhiteSpace(Name)) { if (Items.Count > 0) { Name = Items.First().Name; } else { Name = string.Format(Localization.Localization.ExGather_Zone, WorldManager.ZoneId, ExProfileBehavior.Me.Location); } } StatusText = Name; poiCoroutine = new ActionRunCoroutine(ctx => ExecutePoiLogic()); TreeHooks.Instance.AddHook("PoiAction", poiCoroutine); ResolveGatherRotation(); }