/// <summary> /// Decodes this instance. /// </summary> internal override void Decode(ByteStream Packet) { base.Decode(Packet); this.SpecialChestData = Packet.DecodeData <TreasureChestData>(); this.ChestType = Packet.ReadVInt(); }
/// <summary> /// Decodes this instance. /// </summary> public override void Decode(ByteStream Stream) { base.Decode(Stream); this.SpecialChestData = Stream.DecodeData <TreasureChestData>(); this.ChestType = Stream.ReadVInt(); }
/// <summary> /// Decodes this instance. /// </summary> public void Decode(ByteStream Reader) { this.ChestData = Reader.DecodeData <TreasureChestData>(); this.Unlocked = Reader.ReadBoolean(); this.Claimed = Reader.ReadBoolean(); this.New = Reader.ReadBoolean(); if (Reader.ReadBoolean()) { this.UnlockTimer = new Timer(); this.UnlockTimer.Decode(Reader); } Reader.ReadVInt(); this.Source = Reader.ReadVInt(); this.SlotIndex = Reader.ReadVInt(); Reader.ReadVInt(); Reader.ReadVInt(); Reader.ReadBoolean(); Reader.ReadBoolean(); Reader.ReadBoolean(); }
/// <summary> /// Initializes a new instance of the <see cref="Chest"/> class. /// </summary> public Chest(TreasureChestData Data) { this.ChestData = Data; if (Data.TotalTimeTakenSeconds <= 0) { this.Unlocked = true; } }
/// <summary> /// Initializes a new instance of the <see cref="ChestEvent"/> class. /// </summary> /// <param name="ShopChest">The shop chest.</param> public ChestEvent(ShopChestData ShopChest, TreasureChestData ChestData) : this() { this.ShopChestData = ShopChest; this.ChestData = ChestData; if (this.ShopChestData.DailyCardRotation) { // TODO : Generate cards for this.FortuneSpells.. } }
/// <summary> /// Decodes from the specified stream. /// </summary> /// <param name="Stream">The stream.</param> public void Decode(ByteStream Stream) { this.ChestData = Stream.DecodeData <TreasureChestData>(); Stream.ReadVInt(); Stream.ReadVInt(); Stream.ReadString(); this.Index = Stream.ReadVInt(); Stream.DecodeSpellList(ref this.FortuneSpells); Stream.ReadVInt(); Stream.ReadVInt(); Stream.ReadVInt(); }
/// <summary> /// Randomizes the reward. /// </summary> public static Reward RandomizeReward(Chest Chest, Home Home) { TreasureChestData ChestData = Chest.Data; Reward Reward = new Reward(); Reward.Spells = RewardRandomizer.RandomizeSpells(ChestData, Home); int MaxGold = ChestData.MaxGold; int MinGold = ChestData.MinGold; if (MaxGold > 0) { if (MaxGold == MinGold) { Reward.Gold = MaxGold; } else { Reward.Gold = XorShift.Next(MinGold, MaxGold); } } return(Reward); }
/// <summary> /// Initializes a new instance of the <see cref="SpellShopItem"/> class. /// </summary> public SpecialChestShopItem(int ShopIndex, int Cost, ResourceData BuyResourceData, TreasureChestData SpecialChestData, int ChestType) : base(ShopIndex, Cost, BuyResourceData) { this.ChestType = ChestType; this.SpecialChestData = SpecialChestData; }
/// <summary> /// Decodes this instance. /// </summary> internal override void Decode(ByteStream Packet) { base.Decode(Packet); this.ChestData = Packet.DecodeData <TreasureChestData>(); }
/// <summary> /// Initializes a new instance of the <see cref="SpellShopItem"/> class. /// </summary> public ChestShopItem(int ShopIndex, int Cost, ResourceData BuyResourceData, TreasureChestData ChestData) : base(ShopIndex, Cost, BuyResourceData) { this.ChestData = ChestData; }
/// <summary> /// Randomizes spells. /// </summary> internal static List <Spell> RandomizeSpells(TreasureChestData Data, XorShift Random, Home Home) { List <Spell> Spells = new List <Spell>(); if (Data.GuaranteedSpellsData.Length > 0) { for (int i = 0; i < Data.GuaranteedSpellsData.Length; i++) { Spell Spell = RewardRandomizer.CreateSpell(Data.GuaranteedSpellsData[i]); Spell.SetMaterialCount(1); Spells.Add(Spell); } } int RandomSpellCount = Data.GetRandomSpellCount(); SpellSet SpellSet = new SpellSet(Data.ArenaData, null); DataTable RaritiesTable = CSV.Tables.Get(Gamefile.Rarity); int[] CountByRarity = new int[RaritiesTable.Datas.Count]; for (int i = 1; i < RaritiesTable.Datas.Count; i++) { int Chance = Data.GetChanceForRarity((RarityData)RaritiesTable.Datas[i]); if (Chance > 0) { Console.WriteLine("Random spells : " + RandomSpellCount); if (RandomSpellCount > 0) { int Cnt = RandomSpellCount / Chance; int Mod = RandomSpellCount % Chance; int Rnd = Random.Next(Chance); Console.WriteLine("Count : " + Cnt); Console.WriteLine("Mod : " + Mod); Console.WriteLine("Rnd : " + Rnd); Console.WriteLine(); if (Mod > Rnd ^ Rnd == Mod) { CountByRarity[i] = Cnt + 1; RandomSpellCount -= Cnt - 1; Console.WriteLine(i + " : " + Cnt); } } } else { Console.WriteLine("Chance for rarity " + RaritiesTable.Datas[i].Name + " is equals to 0. " + Data.Name); } } return(null); for (int i = 0; i < RaritiesTable.Datas.Count; i++) { int j = 0; int k = 0; while (k >= CountByRarity[i]) { if (j >= 4999) { break; } ++j; Spell Spell = RewardRandomizer.CreateSpell(SpellSet.GetRandomSpell(Random, (RarityData)RaritiesTable.Datas[i])); if (Spell != null) { if (Spells.Contains(Spell)) { continue; } if (!Home.HasSpell(Spell.Data) || j - 1 >= 1000) { Spell.AddMaterialCount(1); } Spells.Add(Spell); ++k; } } } return(Spells); }
/// <summary> /// Creates the data for the specified row. /// </summary> /// <param name="Row">The row.</param> internal Data Create(Row Row) { Data Data; switch (this.Index) { case 1: { Data = new LocaleData(Row, this); break; } case 2: { Data = new BillingPackageData(Row, this); break; } case 3: case 20: { Data = new GlobalData(Row, this); break; } case 4: { Data = new SoundData(Row, this); break; } case 5: { Data = new ResourceData(Row, this); break; } case 9: { Data = new CharacterBuffData(Row, this); break; } case 10: { Data = new ProjectileData(Row, this); break; } case 11: { Data = new EffectData(Row, this); break; } case 12: { Data = new PredefinedDeckData(Row, this); break; } case 14: { Data = new RarityData(Row, this); break; } case 15: { Data = new LocationData(Row, this); break; } case 16: { Data = new AllianceBadgeData(Row, this); break; } case 18: { Data = new NpcData(Row, this); break; } case 19: { Data = new TreasureChestData(Row, this); break; } case 21: { Data = new ParticleEmitterData(Row, this); break; } case 22: { Data = new AreaEffectObjectData(Row, this); break; } case 26: case 27: case 28: case 29: { Data = new SpellData(Row, this); break; } case 34: case 35: { Data = new CharacterData(Row, this); break; } case 40: { Data = new HealthBarData(Row, this); break; } case 41: { Data = new MusicData(Row, this); break; } case 42: { Data = new DecoData(Row, this); break; } case 43: { Data = new GambleChestData(Row, this); break; } case 45: case 48: { Data = new TutorialData(Row, this); break; } case 46: { Data = new ExpLevelData(Row, this); break; } case 50: { Data = new BackgroundDecoData(Row, this); break; } case 51: { Data = new SpellSetData(Row, this); break; } case 52: { Data = new ChestOrderData(Row, this); break; } case 53: { Data = new TauntData(Row, this); break; } case 54: { Data = new ArenaData(Row, this); break; } case 55: { Data = new ResourcePackData(Row, this); break; } case 56: { Data = new Data(Row, this); break; } case 57: { Data = new RegionData(Row, this); break; } case 58: { Data = new NewsData(Row, this); break; } case 59: { Data = new AllianceRoleData(Row, this); break; } case 60: { Data = new AchievementData(Row, this); break; } case 61: { Data = new HintData(Row, this); break; } case 62: { Data = new HelpshiftData(Row, this); break; } default: { Logging.Info(this.GetType(), "Invalid data table id: " + this.Index + "."); Data = null; break; } } return(Data); }
/// <summary> /// Decodes this instance. /// </summary> public override void Decode(ByteStream Stream) { base.Decode(Stream); this.ChestData = Stream.DecodeData <TreasureChestData>(); }
/// <summary> /// Randomizes spells. /// </summary> public static List <Spell> RandomizeSpells(TreasureChestData Data, Home Home) { List <Spell> Spells = new List <Spell>(); if (Data.GuaranteedSpellsData.Length > 0) { for (int I = 0; I < Data.GuaranteedSpellsData.Length; I++) { Spell Spell = RewardRandomizer.CreateSpell(Data.GuaranteedSpellsData[I]); Spell.SetMaterialCount(1); Spells.Add(Spell); } } int RandomSpellCount = Data.RandomSpellCount; SpellSet SpellSet = new SpellSet(Data.ArenaData, null); CsvTable RaritiesTable = CsvFiles.Get(Gamefile.Rarities); int[] CountByRarity = new int[RaritiesTable.Datas.Count]; for (int I = 1; I < CountByRarity.Length; I++) { int Chance = Data.GetChanceForRarity((RarityData)RaritiesTable.Datas[I]); if (Chance > 0) { if (RandomSpellCount > 0) { int Cnt = Data.RandomSpellCount / Chance; CountByRarity[I] = Cnt; RandomSpellCount -= Cnt; if (XorShift.Next(Chance) < Data.RandomSpellCount % Chance) { ++CountByRarity[I]; --RandomSpellCount; } } } } CountByRarity[0] = RandomSpellCount; for (int I = 0; I < CountByRarity.Length; I++) { int J = 0; int K = 0; while (K < CountByRarity[I]) { if (J++ >= 5000) { break; } SpellData RandomSpellData = SpellSet.GetRandomSpell(RaritiesTable.GetWithInstanceId <RarityData>(I)); if (RandomSpellData != null) { Spell Spell = RewardRandomizer.CreateSpell(RandomSpellData); if (Spells.Count < 1) { Spell.AddMaterial(1); Spells.Add(Spell); ++K; } else { Spell Existing = Spells.Find(T => T.Equals(Spell)); if (Existing != null) { if ((Home.HasSpell(RandomSpellData) ^ true) | (J - 1 >= 1000)) { Existing.AddMaterial(1); ++K; } } else { Spell.AddMaterial(1); Spells.Add(Spell); ++K; } } } } } RewardRandomizer.CombineSpells(Spells, Data.DifferentSpellCount, CountByRarity, Home); for (int I = 0; I < Spells.Count; I++) { // TODO : Implement Sort Spells. } return(Spells); }
/// <summary> /// Executes this instance. /// </summary> public override byte Execute(GameMode GameMode) { Home Home = GameMode.Home; Player Player = GameMode.Player; TreasureChestData TreasureChestData = null; if (Home == null) { return(1); } if (Player == null) { return(2); } switch (this.ChestType) { case 2: { if (GameMode.Home.FreeChest != null) { TreasureChestData = GameMode.Home.FreeChest.Data; if (TreasureChestData == null) { goto End; } } break; } case 3: { if (GameMode.Home.StarChest != null) { TreasureChestData = GameMode.Home.StarChest.Data; if (TreasureChestData == null) { goto End; } } break; } case 4: { if (GameMode.Home.PurchasedChest != null) { TreasureChestData = GameMode.Home.PurchasedChest.Data; if (TreasureChestData == null) { goto End; } } break; } } if (this.Reward.Spells == null) { goto End; } this.Reward.Spells.ForEach(Spell => { if (!Spell.Data.NotInUse) { Spell Existing = Home.GetSpellByData(Spell.Data); int RefundGold; if (Existing == null) { Existing = new Spell(Spell.Data); Existing.SetShowNewIcon(true); RefundGold = Existing.AddMaterial(Spell.Count); Home.AddSpell(Existing); } else { RefundGold = Existing.AddMaterial(Spell.Count); } RefundGold *= Existing.Data.RarityData.GoldConversionValue; if (RefundGold > 0) { if (Player.Gold + RefundGold > Player.MaxGold) { RefundGold = Math.Max(Player.MaxGold - Player.Gold, 0); } Player.AddFreeGold(RefundGold); } } }); End: if (Player.Gold + this.Reward.Gold > Player.MaxGold) { this.Reward.Gold = Math.Max(Player.MaxGold - Player.Gold, 0); } if (this.Reward.Gold > 0) { Player.AddFreeGold(this.Reward.Gold); } if (this.Reward.Diamonds > 0) { Player.AddFreeDiamonds(this.Reward.Diamonds); } Home.SetClaimingReward(false); switch (this.ChestType) { case 2: { Home.FreeChestCollected(); break; } case 3: { Home.CrownChestCollected(); break; } case 4: { Home.PurchasedChestCollected(); break; } } if (TreasureChestData != null) { Player.XpGainHelper(TreasureChestData.Exp); } return(0); }