Exemple #1
0
        public static List <KeyValuePair <ItemDrop, int> > GetDisenchantProducts(ItemDrop.ItemData item)
        {
            var productsDef = EnchantCostsHelper.GetDisenchantProducts(item);

            if (productsDef == null)
            {
                return(null);
            }

            var products = new List <KeyValuePair <ItemDrop, int> >();

            foreach (var itemAmountConfig in productsDef)
            {
                var prefab = ObjectDB.instance.GetItemPrefab(itemAmountConfig.Item);
                if (prefab == null)
                {
                    EpicLoot.LogWarning($"Tried to add unknown item ({itemAmountConfig.Item}) to disenchant product for item ({item.m_shared.m_name})");
                    continue;
                }

                var itemDrop = prefab.GetComponent <ItemDrop>();
                if (itemDrop == null)
                {
                    EpicLoot.LogWarning($"Tried to add object with no ItemDrop ({itemAmountConfig.Item}) to disenchant product for item ({item.m_shared.m_name})");
                    continue;
                }

                products.Add(new KeyValuePair <ItemDrop, int>(itemDrop, itemAmountConfig.Amount));
            }

            return(products);
        }
        public void Load()
        {
            if (_player.m_knownTexts.TryGetValue(SaveDataKey, out var data))
            {
                try
                {
                    SaveData = JSON.ToObject <AdventureSaveDataList>(data, _saveLoadParams);

                    // Clean up old bounties
                    var removed = 0;
                    foreach (var saveData in SaveData.AllSaveData)
                    {
                        removed += saveData.Bounties.RemoveAll(x => x.State == BountyState.InProgress && x.PlayerID == 0);
                    }

                    if (removed > 0)
                    {
                        EpicLoot.LogWarning($"Removed {removed} invalid bounties");
                        Save();
                    }
                }
                catch (Exception)
                {
                    SaveData = new AdventureSaveDataList();
                }
            }
            else
            {
                SaveData = new AdventureSaveDataList();
            }
        }
Exemple #3
0
        public static List <KeyValuePair <ItemDrop, int> > GetAugmentCosts(ItemDrop.ItemData item)
        {
            var rarity = item.GetRarity();

            var augmentCostDef = EnchantCostsHelper.GetAugmentCost(item, rarity);

            if (augmentCostDef == null)
            {
                return(null);
            }

            var costList = new List <KeyValuePair <ItemDrop, int> >();

            foreach (var itemAmountConfig in augmentCostDef)
            {
                var prefab = ObjectDB.instance.GetItemPrefab(itemAmountConfig.Item);
                if (prefab == null)
                {
                    EpicLoot.LogWarning($"Tried to add unknown item ({itemAmountConfig.Item}) to augment cost for item ({item.m_shared.m_name})");
                    continue;
                }

                var itemDrop = prefab.GetComponent <ItemDrop>();
                if (itemDrop == null)
                {
                    EpicLoot.LogWarning($"Tried to add item without ItemDrop ({itemAmountConfig.Item}) to augment cost for item ({item.m_shared.m_name})");
                    continue;
                }

                costList.Add(new KeyValuePair <ItemDrop, int>(itemDrop, itemAmountConfig.Amount));
            }

            return(costList);
        }
        protected static List <SecretStashItemInfo> CollectItems(
            List <SecretStashItemConfig> itemList,
            Func <SecretStashItemConfig, string> itemIdPredicate,
            Func <ItemDrop.ItemData, bool> itemOkayToAddPredicate)
        {
            var results = new List <SecretStashItemInfo>();

            foreach (var itemConfig in itemList)
            {
                var itemId   = itemIdPredicate(itemConfig);
                var itemDrop = CreateItemDrop(itemId);
                if (itemDrop == null)
                {
                    EpicLoot.LogWarning($"[AdventureData] Could not find item type (gated={itemId} orig={itemConfig}) in ObjectDB!");
                    continue;
                }

                var itemData = itemDrop.m_itemData;
                if (itemOkayToAddPredicate(itemData))
                {
                    results.Add(new SecretStashItemInfo(itemId, itemData, itemConfig.GetCost()));
                }
                Object.Destroy(itemDrop.gameObject);
            }

            return(results);
        }
Exemple #5
0
        public void RPC_SlayBountyTarget(long sender, ZPackage pkg, string monsterID, bool isAdd)
        {
            var isServer = Common.Utils.IsServer();

            if (isServer)
            {
                EpicLoot.LogWarning($"SERVER: RPC_SlayBountyTarget: {monsterID} ({(isAdd ? "minion" : "target")})");
                ZRoutedRpc.instance.InvokeRoutedRPC(ZRoutedRpc.Everybody, "SlayBountyTargetFromServer", pkg, monsterID, isAdd);
            }
            else
            {
                EpicLoot.LogWarning($"CLIENT: RPC_SlayBountyTarget: {monsterID} ({(isAdd ? "minion" : "target")})");
            }

            var bounty = BountyInfo.FromPackage(pkg);

            if (isServer)
            {
                AddSlainBountyTargetToLedger(bounty, monsterID, isAdd);
            }

            if (Player.m_localPlayer == null || bounty.PlayerID != Player.m_localPlayer.GetPlayerID())
            {
                // Not my bounty
                return;
            }

            OnBountyTargetSlain(bounty.ID, monsterID, isAdd);
        }
Exemple #6
0
        private List <SecretStashItemInfo> GetAvailableGambles()
        {
            var availableGambles = new List <SecretStashItemInfo>();

            foreach (var itemConfig in AdventureDataManager.Config.Gamble.Gambles)
            {
                var gatingMode = EpicLoot.GetGatedItemTypeMode();
                if (gatingMode == GatedItemTypeMode.Unlimited)
                {
                    gatingMode = GatedItemTypeMode.MustKnowRecipe;
                }

                var itemId   = GatedItemTypeHelper.GetGatedItemID(itemConfig, gatingMode);
                var itemDrop = CreateItemDrop(itemId);
                if (itemDrop == null)
                {
                    EpicLoot.LogWarning($"[AdventureData] Could not find item type (gated={itemId} orig={itemConfig}) in ObjectDB!");
                    continue;
                }

                var itemData = itemDrop.m_itemData;
                var cost     = GetGambleCost(itemId);
                availableGambles.Add(new SecretStashItemInfo(itemId, itemData, cost, true));
                Object.Destroy(itemDrop.gameObject);
            }

            return(availableGambles);
        }
        private void OnDeath()
        {
            EpicLoot.LogWarning("BountyTarget.OnDeath");
            var pkg = new ZPackage();

            _bountyInfo.ToPackage(pkg);

            EpicLoot.LogWarning($"SENDING -> RPC_SlayBountyTarget: {_monsterID} ({(_isAdd ? "minion" : "target")})");
            ZRoutedRpc.instance.InvokeRoutedRPC("SlayBountyTarget", pkg, _monsterID, _isAdd);
        }
Exemple #8
0
 public static void RPC_AddKnownRecipe(long sender, string recipe)
 {
     if (!PlayerKnownRecipes.TryGetValue(sender, out var knownRecipes))
     {
         EpicLoot.LogWarning($"PlayerKnownManager.RPC_AddKnownRecipe: hashset is null for peer {sender}");
         return;
     }
     knownRecipes.Add(recipe);
     EpicLoot.Log($"Received add known recipe from peer {sender}: {recipe}");
 }
Exemple #9
0
 public static void RPC_AddKnownMaterial(long sender, string material)
 {
     if (!PlayerKnownMaterial.TryGetValue(sender, out var knownMaterial))
     {
         EpicLoot.LogWarning($"PlayerKnownManager.RPC_AddKnownMaterial: hashset is null for peer {sender}");
         return;
     }
     knownMaterial.Add(material);
     EpicLoot.Log($"Received add known material from peer {sender}: {material}");
 }
        public void BuyItem(Player player, BuyListElement listItem)
        {
            ItemDrop.ItemData item;
            if (listItem.ItemInfo.IsGamble)
            {
                item = AdventureDataManager.Gamble.GenerateGambleItem(listItem.ItemInfo);
            }
            else
            {
                var itemDrop = AdventureFeature.CreateItemDrop(listItem.ItemInfo.ItemID);
                item = itemDrop.m_itemData;
                Destroy(itemDrop.gameObject);
            }

            var inventory = player.GetInventory();

            if (item == null || !inventory.AddItem(item))
            {
                EpicLoot.LogWarning($"Could not buy item {listItem.ItemInfo.Item.m_shared.m_name}");
                return;
            }

            if (listItem.ItemInfo.IsGamble)
            {
                GambleSuccessDialog.Show(item);
            }

            if (listItem.ItemInfo.Cost.Coins > 0)
            {
                inventory.RemoveItem(GetCoinsName(), listItem.ItemInfo.Cost.Coins);
            }

            if (listItem.ItemInfo.Cost.ForestTokens > 0)
            {
                inventory.RemoveItem(GetForestTokenName(), listItem.ItemInfo.Cost.ForestTokens);
            }

            if (listItem.ItemInfo.Cost.IronBountyTokens > 0)
            {
                inventory.RemoveItem(GetIronBountyTokenName(), listItem.ItemInfo.Cost.IronBountyTokens);
            }

            if (listItem.ItemInfo.Cost.GoldBountyTokens > 0)
            {
                inventory.RemoveItem(GetGoldBountyTokenName(), listItem.ItemInfo.Cost.GoldBountyTokens);
            }

            StoreGui.instance.m_trader.OnBought(null);
            StoreGui.instance.m_buyEffects.Create(player.transform.position, Quaternion.identity);
            Player.m_localPlayer.ShowPickupMessage(listItem.ItemInfo.Item, listItem.ItemInfo.Item.m_stack);

            //Gogan.LogEvent("Game", "BoughtItem", selectedStashItem.Item, 0L);
        }
Exemple #11
0
        public void RPC_SlayBountyTargetFromBountyId(long sender, string monsterID, bool isAdd, string bountyID)
        {
            EpicLoot.LogWarning($"CLIENT: RPC_SlayBountyTargetFromBountyId: {monsterID} ({(isAdd ? "minion" : "target")})");

            var bounty = BountyInfo.FromBountyID(bountyID);

            if (Player.m_localPlayer == null || bounty.PlayerID != Player.m_localPlayer.GetPlayerID())
            {
                // Not my bounty
                return;
            }

            OnBountyTargetSlain(bounty.ID, monsterID, isAdd);
        }
Exemple #12
0
        public static void ClientSendKnownRecipes()
        {
            var player = Player.m_localPlayer;

            if (player == null)
            {
                EpicLoot.LogWarning("PlayerKnownManager.ClientSendKnown: m_localPlayer == null");
                return;
            }

            var pkg = new ZPackage();

            WriteKnownRecipes(player.m_knownRecipes, pkg);

            EpicLoot.Log($"Sending known: {player.m_knownRecipes.Count} recipes");
            ZRoutedRpc.instance.InvokeRoutedRPC(ZRoutedRpc.Everybody, Name_RPC_ClientKnownRecipes, pkg);
        }
Exemple #13
0
        private void OnDeath()
        {
            EpicLoot.LogWarning("BountyTarget.OnDeath");
            if (ZNet.instance.IsServer() || !ZNet.instance.IsServer() && !ZNet.instance.IsDedicated())
            {
                var pkg = new ZPackage();
                _bountyInfo.ToPackage(pkg);

                EpicLoot.LogWarning($"SENDING -> RPC_SlayBountyTarget: {_monsterID} ({(_isAdd ? "minion" : "target")})");
                ZRoutedRpc.instance.InvokeRoutedRPC(ZRoutedRpc.Everybody, "SlayBountyTarget", pkg, _monsterID, _isAdd);
            }
            else
            {
                var bountyID = _zdo.GetString(BountyIDKey);
                EpicLoot.LogWarning($"SENDING -> RPC_SlayBountyTargetFromBountyId: (bountyID={bountyID}) {_monsterID} ({(_isAdd ? "minion" : "target")})");
                ZRoutedRpc.instance.InvokeRoutedRPC(ZRoutedRpc.Everybody, "SlayBountyIDTarget", _monsterID, _isAdd, bountyID);
            }
        }
Exemple #14
0
        public static void Postfix(Character __instance)
        {
            var zdo = __instance.m_nview?.GetZDO();

            if (zdo != null && zdo.IsValid())
            {
                var old = !string.IsNullOrEmpty(zdo.GetString("BountyTarget"));
                if (old)
                {
                    EpicLoot.LogWarning($"Destroying old bounty target: {__instance.name}");
                    zdo.Set("BountyTarget", "");
                    __instance.m_nview.Destroy();
                    return;
                }

                if (!string.IsNullOrEmpty(zdo.GetString(BountyTarget.BountyIDKey)))
                {
                    var bountyTarget = __instance.gameObject.AddComponent <BountyTarget>();
                    bountyTarget.Reinitialize();
                }
            }
        }
        protected static IEnumerator GetRandomPointInBiome(Heightmap.Biome biome, AdventureSaveData saveData, Action <bool, Vector3, Vector3> onComplete)
        {
            const int maxRangeIncreases = 10;
            const int maxPointsInRange  = 15;

            MerchantPanel.ShowInputBlocker(true);

            var rangeTries  = 0;
            var radiusRange = GetTreasureMapSpawnRadiusRange(biome, saveData);

            while (rangeTries < maxRangeIncreases)
            {
                rangeTries++;

                var tries = 0;
                while (tries < maxPointsInRange)
                {
                    tries++;

                    var randomPoint = UnityEngine.Random.insideUnitCircle;
                    var mag         = randomPoint.magnitude;
                    var normalized  = randomPoint.normalized;
                    var actualMag   = Mathf.Lerp(radiusRange.Item1, radiusRange.Item2, mag);
                    randomPoint = normalized * actualMag;
                    var spawnPoint = new Vector3(randomPoint.x, 0, randomPoint.y);

                    var zoneId = ZoneSystem.instance.GetZone(spawnPoint);
                    while (!ZoneSystem.instance.SpawnZone(zoneId, ZoneSystem.SpawnMode.Client, out _))
                    {
                        EpicLoot.LogWarning($"Spawning Zone ({zoneId})...");
                        yield return(null);
                    }

                    ZoneSystem.instance.GetGroundData(ref spawnPoint, out var normal, out var foundBiome, out _, out _);
                    var groundHeight = spawnPoint.y;

                    EpicLoot.Log($"Checking biome at ({randomPoint}): {foundBiome} (try {tries})");
                    if (foundBiome != biome)
                    {
                        // Wrong biome
                        continue;
                    }

                    var solidHeight      = ZoneSystem.instance.GetSolidHeight(spawnPoint);
                    var offsetFromGround = Math.Abs(solidHeight - groundHeight);
                    if (offsetFromGround > 5)
                    {
                        // Don't place too high off the ground (on top of tree or something?
                        EpicLoot.Log($"Spawn Point rejected: too high off of ground (groundHeight:{groundHeight}, solidHeight:{solidHeight})");
                        continue;
                    }

                    // But also don't place inside rocks
                    spawnPoint.y = solidHeight;

                    var placedNearPlayerBase = EffectArea.IsPointInsideArea(spawnPoint, EffectArea.Type.PlayerBase, AdventureDataManager.Config.TreasureMap.MinimapAreaRadius);
                    if (placedNearPlayerBase)
                    {
                        // Don't place near player base
                        EpicLoot.Log("Spawn Point rejected: too close to player base");
                        continue;
                    }

                    EpicLoot.Log($"Wards: {PrivateArea.m_allAreas.Count}");
                    var tooCloseToWard = PrivateArea.m_allAreas.Any(x => x.IsInside(spawnPoint, AdventureDataManager.Config.TreasureMap.MinimapAreaRadius));
                    if (tooCloseToWard)
                    {
                        EpicLoot.Log("Spawn Point rejected: too close to player ward");
                        continue;
                    }

                    var waterLevel = ZoneSystem.instance.m_waterLevel;
                    if (waterLevel > groundHeight + 1.0f)
                    {
                        // Too deep, try again
                        EpicLoot.Log($"Spawn Point rejected: too deep underwater (waterLevel:{waterLevel}, groundHeight:{groundHeight})");
                        continue;
                    }

                    EpicLoot.Log($"Success! (ground={groundHeight} water={waterLevel} placed={spawnPoint.y})");

                    onComplete?.Invoke(true, spawnPoint, normal);
                    MerchantPanel.ShowInputBlocker(false);
                    yield break;
                }

                radiusRange = new Tuple <float, float>(radiusRange.Item1 + 500, radiusRange.Item2 + 500);
            }

            onComplete?.Invoke(false, new Vector3(), new Vector3());
            MerchantPanel.ShowInputBlocker(false);
        }