Example #1
0
        public ItemRandomClass GetRareItem(UInt32 CoinTypeID, byte Pooling)
        {
            ItemRandomClass result;

            result = new ItemRandomClass();
            switch (Pooling)
            {
            case 0:
                foreach (IffMemorialRareItemData Item in this)
                {
                    result.AddItems(Item.TypeID, 1, Item.RareType, (ushort)result.rnd.Next((int)Item.Probabilities - result.rnd.Next(20)));
                }
                break;

            default:
                foreach (IffMemorialRareItemData Item in this)
                {
                    if (Item.CharacterType == Pooling)
                    {
                        result.AddItems(Item.TypeID, 1, Item.RareType, (ushort)result.rnd.Next((int)Item.Probabilities + result.rnd.Next(20)));
                    }
                }
                break;
            }
            result.SetCanDup(false);
            result.Arrange();
            return(result);
        }
Example #2
0
        public CardCollection()
        {
            MemoryStream       Buffer;
            IffCardData        Card;
            PangyaBinaryReader Reader = null;

            ListCard = new List <IffCardData>();
            Cards    = new ItemRandomClass();
            PackData = new Dictionary <uint, CardPack>();
            using (var zip = ZipFile.OpenRead("data/pangya_gb.iff"))                 //ler o arquivo de base
            {
                var FileZip = zip.Entries.FirstOrDefault(c => c.Name == "Card.iff"); //verifica se existe o arquivo

                if (FileZip == null)
                {
                    PangyaAPI.WriteConsole.WriteLine(" data\\Card.iff is not loaded");
                    return;
                }

                Buffer = new MemoryStream();
                FileZip.Open().CopyTo(Buffer);
            }

            try
            {
                Reader = new PangyaBinaryReader(Buffer);
                if (new string(Reader.ReadChars(2)) == "PK")
                {
                    throw new Exception("The given IFF file is a ZIP file, please unpack it before attempting to parse it");
                }

                Reader.Seek(0, 0);

                Reader.ReadUInt16(out ushort recordCount);
                long recordLength = ((Reader.GetSize() - 8L) / (recordCount));
                Reader.ReadUInt16(out BindingID);
                Reader.ReadUInt32(out Version);

                for (int i = 0; i < recordCount; i++)
                {
                    Card = (IffCardData)Reader.Read(new IffCardData());

                    Add(Card.Base.TypeID, Card);
                }

                CreateCardPack();
                CreateCardItem();
            }
            finally
            {
                Reader.Dispose();
            }
        }
Example #3
0
        static ScratchCardSystem()
        {
            ItemRandom ItemInfo;

            uint[] SupplyTypeID;
            RandomWeight = new ItemRandomClass();

            try
            {
                if (File.Exists("Json/ScratchCard.json"))
                {
                    SupplyTypeID = new uint[4];
                    foreach (var item in JsonValue.ParseFile("Json/ScratchCard.json")["ScratchCardData"].AsJsonArray)
                    {
                        SupplyTypeID[0] = (uint)item["SupplyTypeID"].AsInteger;
                        SupplyTypeID[1] = (uint)item["SupplyTypeID2"].AsInteger;
                        SupplyTypeID[2] = (uint)item["SupplyTypeID3"].AsInteger;
                        SupplyTypeID[3] = (uint)item["SupplyTypeID4"].AsInteger;
                        foreach (var Reward in item["Items"].AsJsonArray)
                        {
                            ItemInfo = new ItemRandom()
                            {
                                TypeId      = (uint)Reward["TypeID"].AsInteger,
                                MaxQuantity = (uint)Reward["MaxQuan"].AsInteger,
                                RareType    = (uint)Reward["TypeRare"].AsInteger,
                                Probs       = (ushort)Reward["Probability"].AsInteger,
                                Active      = Reward["Valid"].AsBoolean
                            };
                            RandomWeight.AddItems(ItemInfo);
                        }
                    }


                    RandomWeight.AddSupply(SupplyTypeID[0]);
                    RandomWeight.AddSupply(SupplyTypeID[1]);
                    RandomWeight.AddSupply(SupplyTypeID[2]);
                    RandomWeight.AddSupply(SupplyTypeID[3]);
                    RandomWeight.SetCanDup(false);
                }
                else
                {
                    throw new Exception(" ScratchCard.json file in folder not found !");
                }
            }
            catch (Exception ex)
            {
                WriteConsole.WriteLine(ex.Message, ConsoleColor.Red);
                Console.ReadKey();
                Environment.Exit(0);
            }
        }
Example #4
0
        public List <Dictionary <uint, byte> > GetCard(uint PackTypeID)
        {
            ushort GetProb(byte RareType)
            {
                switch (RareType)
                {
                case 0:
                    return(100);

                case 1:
                    return(6);

                case 2:
                    return(2);

                case 3:
                    return(1);

                default:
                    return((ushort)GameTools.MathRand.Rand.Next(0, 120));
                }
            }

            ushort GetFreshUPProb(byte RareType)
            {
                switch (RareType)
                {
                case 1:
                    return(100);

                case 2:
                    return(10);

                case 3:
                    return(4);

                default:
                    return((ushort)GameTools.MathRand.Rand.Next(0, 120));
                }
            }

            List <Dictionary <uint, byte> > result;
            ItemRandomClass CRandom;
            byte            CQty;
            ItemRandom      CItem;

            result  = new List <Dictionary <uint, byte> >();
            CRandom = new ItemRandomClass();
            try
            {
                PackData.TryGetValue(PackTypeID, out CardPack CPack);
                if (CPack == null)
                {
                    return(result);
                }
                switch (CPack.CardTypePack)
                {
                case TPACKCARD.Pack1:
                    foreach (var PZCard in ListCard)
                    {
                        if (PZCard.Volumn == 1)
                        {
                            CRandom.AddItems(PZCard.Base.TypeID, 1, PZCard.Rarity, GetProb(PZCard.Rarity));
                        }
                    }
                    break;

                case TPACKCARD.Pack2:
                    foreach (var PZCard in ListCard)
                    {
                        if (PZCard.Volumn == 2)
                        {
                            CRandom.AddItems(PZCard.Base.TypeID, 1, PZCard.Rarity, GetProb(PZCard.Rarity));
                        }
                    }
                    break;

                case TPACKCARD.Pack3:
                    foreach (var PZCard in ListCard)
                    {
                        if (PZCard.Volumn == 3)
                        {
                            CRandom.AddItems(PZCard.Base.TypeID, 1, PZCard.Rarity, GetProb(PZCard.Rarity));
                        }
                    }
                    break;

                case TPACKCARD.Pack4:
                    foreach (var PZCard in ListCard)
                    {
                        if (PZCard.Volumn == 4)
                        {
                            CRandom.AddItems(PZCard.Base.TypeID, 1, PZCard.Rarity, GetProb(PZCard.Rarity));
                        }
                    }
                    break;

                case TPACKCARD.Rare:
                    foreach (var PZCard in ListCard)
                    {
                        if (PZCard.Rarity >= 1)
                        {
                            CRandom.AddItems(PZCard.Base.TypeID, 1, PZCard.Rarity, GetFreshUPProb(PZCard.Rarity));
                        }
                    }
                    break;

                case TPACKCARD.All:
                    foreach (var PZCard in ListCard)
                    {
                        CRandom.AddItems(PZCard.Base.TypeID, 1, PZCard.Rarity, GetProb(PZCard.Rarity));
                    }
                    break;
                }
                // ## set random class
                CRandom.SetCanDup(false);
                CRandom.Arrange();
                for (CQty = 1; CQty <= CPack.Quantity; CQty++)
                {
                    CItem = CRandom.GetItems();
                    result.Add(new Dictionary <uint, byte>
                    {
                        { CItem.TypeId, (byte)CItem.RareType }
                    });
                }
                return(result);
            }
            finally
            {
                CRandom = null;
            }
        }