Ejemplo n.º 1
0
        public override void OverridableEndFight(FightTeam Winners, FightTeam Loosers)
        {
            /*foreach (var Chal in Challanges)
             * {
             *  if (Chal.State && !Chal.Signaled)
             *      Chal.Ok();
             * }*/

            var WinChallenges      = Challanges.Where(c => c.State).ToList();
            var ChallengeXpBonus   = 1;
            var ChallengeDropBonus = 1;

            if (WinChallenges.Count > 0)
            {
                ChallengeXpBonus   = (int)Math.Round(Convert.ToDouble((100 + WinChallenges.Sum(c => c.BasicXpBonus + c.TeamXpBonus)) / 100));
                ChallengeDropBonus = (int)Math.Round(Convert.ToDouble((100 + WinChallenges.Sum(c => c.BasicDropBonus + c.TeamDropBonus)) / 100));
            }


            var WinnersCount       = Winners.GetFighters().Count;
            var LoosersCount       = Loosers.GetFighters().Count;
            var WinnersLevel       = Winners.GetFighters().Sum(x => x.Level);
            var LoosersLevel       = Loosers.GetFighters().Sum(x => x.Level);
            var WinnersProspection = Winners.GetFighters().Sum(x => x.Stats.GetTotal(EffectEnum.AddProspection));
            var MonsterWon         = Winners.Leader.ActorType == GameActorTypeEnum.TYPE_MONSTER;

            var  PossibleItemLoot  = new List <ItemLoot>();
            long PossibleKamasLoot = 0;
            var  PossibleDrops     = new Dictionary <Drop, int>();
            var  MinKamas          = 0;
            var  MaxKamas          = 0;
            long BaseXp            = 0;

            // Les monstres perdent ?
            if (!MonsterWon)
            {
                PossibleItemLoot.AddRange(this.MonsterGroup.ItemLoot);
                PossibleKamasLoot = this.MonsterGroup.KamasLoot;
            }

            foreach (var Fighter in Loosers.GetFighters())
            {
                switch (Fighter.ActorType)
                {
                case GameActorTypeEnum.TYPE_MONSTER:
                    var Monster = Fighter as MonsterFighter;

                    // Ajout des drops et kamas
                    MinKamas += Monster.Grade.Monster.MinKamas;
                    MaxKamas += Monster.Grade.Monster.MaxKamas;
                    BaseXp   += Monster.Grade.BaseXP;

                    // On augmente le Taux si possible
                    foreach (var Drop in Monster.Grade.Monster.DropsCache)
                    {
                        if (Drop.ItemTemplateCache != null)
                        {
                            if (!PossibleDrops.ContainsKey(Drop))
                            {
                                if (Drop.Seuil <= WinnersProspection)
                                {
                                    var Taux = (int)((WinnersProspection * Drop.Taux * Settings.AppSettings.GetIntElement("Rate.Drop") * ChallengeDropBonus / 100));

                                    PossibleDrops.Add(Drop, Taux);
                                }
                                else
                                {
                                    PossibleDrops.Add(Drop, (int)Drop.Taux);
                                }
                            }
                        }
                    }
                    break;
                }

                this.myResult.AddResult(Fighter, false);
            }

            var WinnersOrderedByProspect = Winners.GetFighters().OrderByDescending(x => x.Stats.GetTotal(EffectEnum.AddProspection));
            var AlreadyDropItems         = new Dictionary <int, int>();
            var ItemLootPerFighter       = PossibleItemLoot.Count / WinnersCount;
            var KamasLootPerFighter      = PossibleKamasLoot / WinnersCount;
            var Modulo = PossibleItemLoot.Count % (this.Map.GetActors().Where(x => x.ActorType == GameActorTypeEnum.TYPE_TAX_COLLECTOR).Count() > 0  ? WinnersCount + 1 : WinnersCount);

            foreach (var Drop in PossibleDrops)
            {
                if (!AlreadyDropItems.ContainsKey(Drop.Key.ItemTemplateCache.ID))
                {
                    AlreadyDropItems.Add(Drop.Key.ItemTemplateCache.ID, 0);
                }
            }

            foreach (var Fighter in WinnersOrderedByProspect)
            {
                long WinXp    = 0;
                long WinKamas = 0;
                var  Drops    = new Dictionary <int, int>();

                if (!Fighter.Left)
                {
                    switch (Fighter.ActorType)
                    {
                    case GameActorTypeEnum.TYPE_CHARACTER:
                        var Character = Fighter as CharacterFighter;

                        WinXp     = Algo.CalculatePVMXp(Character, Winners.GetFighters(), Loosers.GetFighters(), LoosersLevel, WinnersLevel, BaseXp);
                        WinXp    *= ChallengeXpBonus;
                        WinKamas  = Algo.CalculatePVMKamas(MaxKamas, MinKamas);
                        WinKamas += KamasLootPerFighter;
                        WinKamas *= ChallengeDropBonus;

                        try
                        {
                            Character.Character.BeginCachedBuffer();

                            Character.Character.InventoryCache.AddKamas(WinKamas);
                            Character.Character.AddExperience(WinXp);

                            foreach (var Drop in PossibleDrops)
                            {
                                var Taux = Drop.Value * 100;
                                var Jet  = Algo.Random(0, 100 * 100);

                                if (Jet < Taux)
                                {
                                    if (AlreadyDropItems[Drop.Key.TemplateId] < Drop.Key.Max)
                                    {
                                        if (Drops.ContainsKey(Drop.Key.TemplateId))
                                        {
                                            Drops[Drop.Key.TemplateId]++;
                                        }
                                        else
                                        {
                                            Drops.Add(Drop.Key.TemplateId, 1);
                                        }
                                    }
                                }
                            }

                            foreach (var Drop in Drops)
                            {
                                InventoryItemTable.TryCreateItem(Drop.Key, Character.Character, Drop.Value);
                            }

                            for (int i = 0; i < ItemLootPerFighter; i++)
                            {
                                if (Drops.ContainsKey(PossibleItemLoot[i].TemplateId))
                                {
                                    Drops[PossibleItemLoot[i].TemplateId]++;
                                }
                                else
                                {
                                    Drops.Add(PossibleItemLoot[i].TemplateId, PossibleItemLoot[i].Quantity);
                                }

                                InventoryItemTable.TryCreateItem(PossibleItemLoot[i].TemplateId, Character.Character, PossibleItemLoot[i].Quantity, Stats: PossibleItemLoot[i].ItemStats.ToItemStats());
                            }

                            if (ItemLootPerFighter > 0)
                            {
                                PossibleItemLoot.RemoveRange(0, ItemLootPerFighter);
                            }

                            if (Modulo > 0)
                            {
                                if (Drops.ContainsKey(PossibleItemLoot[0].TemplateId))
                                {
                                    Drops[PossibleItemLoot[0].TemplateId]++;
                                }
                                else
                                {
                                    Drops.Add(PossibleItemLoot[0].TemplateId, PossibleItemLoot[0].Quantity);
                                }

                                InventoryItemTable.TryCreateItem(PossibleItemLoot[0].TemplateId, Character.Character, PossibleItemLoot[0].Quantity, Stats: PossibleItemLoot[0].ItemStats.ToItemStats());

                                PossibleItemLoot.RemoveAt(0);
                                Modulo--;
                            }

                            // Fin de la mise en cache
                            Character.Character.EndCachedBuffer();
                        }
                        catch (Exception exc)
                        {
                            Logger.Error("MonsterFight::EndFight() " + exc.ToString());
                        }

                        // Ajout du resultat
                        this.myResult.AddResult(Fighter, true, WinKamas, WinXp, WinItems: Drops);

                        break;

                    case GameActorTypeEnum.TYPE_MONSTER:
                        var Monster = Fighter as MonsterFighter;

                        WinKamas += KamasLootPerFighter;

                        for (int i = 0; i < ItemLootPerFighter; i++)
                        {
                            if (Drops.ContainsKey(PossibleItemLoot[i].TemplateId))
                            {
                                Drops[PossibleItemLoot[i].TemplateId]++;
                            }
                            else
                            {
                                Drops.Add(PossibleItemLoot[i].TemplateId, PossibleItemLoot[i].Quantity);
                            }
                        }

                        if (ItemLootPerFighter > 0)
                        {
                            PossibleItemLoot.RemoveRange(0, ItemLootPerFighter);
                        }

                        if (Modulo > 0)
                        {
                            if (Drops.ContainsKey(PossibleItemLoot[0].TemplateId))
                            {
                                Drops[PossibleItemLoot[0].TemplateId]++;
                            }
                            else
                            {
                                Drops.Add(PossibleItemLoot[0].TemplateId, PossibleItemLoot[0].Quantity);
                            }

                            PossibleItemLoot.RemoveAt(0);
                            Modulo--;
                        }

                        this.myResult.AddResult(Fighter, true, WinKamas, WinXp, WinItems: Drops);

                        break;
                    }
                }
            }


            if (!MonsterWon && this.Map.GetActors().Where(x => x.ActorType == GameActorTypeEnum.TYPE_TAX_COLLECTOR).Count() > 0)
            {
                var  TCollector = this.Map.GetActors().Where(x => x.ActorType == GameActorTypeEnum.TYPE_TAX_COLLECTOR).First() as TaxCollector;
                long winxp      = (int)Math.Floor((double)Algo.CalculateXpWinPerco(TCollector, Winners.GetFighters(), Loosers.GetFighters(), BaseXp) / 100);
                long winkamas   = (int)Math.Floor((double)Algo.CalculatePVMKamas(MinKamas, MaxKamas) / 100);
                TCollector.XP    += winxp;
                TCollector.Kamas += winkamas;
                var Drops = new Dictionary <int, int>();

                foreach (var Drop in PossibleDrops)
                {
                    var Taux = Drop.Value * 100;
                    var Jet  = Algo.Random(0, 100 * 100);

                    if (Jet < Taux)
                    {
                        if (AlreadyDropItems[Drop.Key.TemplateId] < Drop.Key.Max)
                        {
                            if (Drops.ContainsKey(Drop.Key.TemplateId))
                            {
                                Drops[Drop.Key.TemplateId]++;
                            }
                            else
                            {
                                Drops.Add(Drop.Key.TemplateId, 1);
                            }
                        }
                    }
                }

                foreach (var Drop in Drops)
                {
                    InventoryItemTable.TryCreateItem(Drop.Key, TCollector, Drop.Value);
                }

                for (int i = 0; i < ItemLootPerFighter; i++)
                {
                    if (Drops.ContainsKey(PossibleItemLoot[i].TemplateId))
                    {
                        Drops[PossibleItemLoot[i].TemplateId]++;
                    }
                    else
                    {
                        Drops.Add(PossibleItemLoot[i].TemplateId, PossibleItemLoot[i].Quantity);
                    }

                    InventoryItemTable.TryCreateItem(PossibleItemLoot[i].TemplateId, TCollector, PossibleItemLoot[i].Quantity, Stats: PossibleItemLoot[i].ItemStats.ToItemStats());
                }

                if (ItemLootPerFighter > 0)
                {
                    PossibleItemLoot.RemoveRange(0, ItemLootPerFighter);
                }

                if (Modulo > 0)
                {
                    if (Drops.ContainsKey(PossibleItemLoot[0].TemplateId))
                    {
                        Drops[PossibleItemLoot[0].TemplateId]++;
                    }
                    else
                    {
                        Drops.Add(PossibleItemLoot[0].TemplateId, PossibleItemLoot[0].Quantity);
                    }

                    InventoryItemTable.TryCreateItem(PossibleItemLoot[0].TemplateId, TCollector, PossibleItemLoot[0].Quantity, Stats: PossibleItemLoot[0].ItemStats.ToItemStats());

                    PossibleItemLoot.RemoveAt(0);
                    Modulo--;
                }

                this.myResult.TCollectorResult = new Tera.WorldServer.World.Fights.GameFightEndResult.TaxCollectorResult()
                {
                    TaxCollector = TCollector,
                    WinExp       = winxp,
                    WinKamas     = winkamas,
                    WinItems     = Drops
                };

                TaxCollectorTable.Update(TCollector);
            }

            if (!MonsterWon)
            {
                this.Map.SpawnMonsterGroup(1);
            }
            else if (!MonsterGroup.IsFix)
            {
                this.Map.SpawnActor(this.MonsterGroup);
            }

            base.EndFight();
        }
Ejemplo n.º 2
0
        public override void OverridableEndFight(FightTeam Winners, FightTeam Loosers)
        {
            var Winner = (Winners.Leader as CharacterFighter).Character;
            var Looser = (Loosers.Leader as CharacterFighter).Character;

            // Pour les logs
            Logger.Debug("AGGRESSION_FIGHT Ended : Winner=" + Winner.Name + "(" + Winner.Level + ") Looser=" + Looser.Name + "(" + Looser.Level + ") MapId=" + Map.Id);

            var WinnersFighter = Winners.GetFighters().OfType <CharacterFighter>().ToList();
            var LoosersFighter = Loosers.GetFighters().OfType <CharacterFighter>().ToList();

            var WinnersTotalGrade = WinnersFighter.Sum(x => x.Character.getGrade());
            var WinnersTotalLevel = WinnersFighter.Sum(x => x.Level);

            var LoosersTotalGrade = LoosersFighter.Sum(x => x.Character.getGrade());
            var LoosersTotalLevel = LoosersFighter.Sum(x => x.Level);

            var  PossibleItemLoot = new List <ItemLoot>();
            long PossibleKamasLoot = 0, PossibleXpLoot = 0;

            foreach (var Fighter in LoosersFighter)
            {
                int WinHonor = 0;
                if (Fighter.Character.AlignmentType != AlignmentTypeEnum.ALIGNMENT_NEUTRAL)
                {
                    WinHonor = Algo.CalculateAggressionHonor(Fighter, false, WinnersFighter.Count, WinnersTotalGrade, WinnersTotalLevel, LoosersTotalGrade, LoosersTotalLevel);
                    if (WinHonor > Fighter.Character.Honor)
                    {
                        WinHonor = Fighter.Character.Honor;
                    }
                    Fighter.Character.RemoveHonor(WinHonor);
                }


                if (Fighter.Character.GetClient() != null)
                {
                    Fighter.Character.GetClient().Send(new AccountStatsMessage(Fighter.Character));
                }


                this.myResult.AddResult(Fighter, false, WinHonor: -WinHonor);
            }

            var ItemLootPerFighter  = PossibleItemLoot.Count / WinnersFighter.Count;
            var KamasLootPerFighter = PossibleKamasLoot / WinnersFighter.Count;
            var XpLootPerFighter    = PossibleXpLoot / WinnersFighter.Count;
            var Modulo = PossibleItemLoot.Count % WinnersFighter.Count;

            foreach (var Fighter in WinnersFighter)
            {
                var Drops    = new Dictionary <int, int>();
                var WinKamas = KamasLootPerFighter;
                int WinHonor = 0;
                if (Fighter.Character.AlignmentType != AlignmentTypeEnum.ALIGNMENT_NEUTRAL)
                {
                    WinHonor = Algo.CalculateAggressionHonor(Fighter, true, WinnersFighter.Count, WinnersTotalGrade, WinnersTotalLevel, LoosersTotalGrade, LoosersTotalLevel);
                }
                var WinXp = XpLootPerFighter;

                if (Fighter.Character.AlignmentType != AlignmentTypeEnum.ALIGNMENT_NEUTRAL)
                {
                    Fighter.Character.AddHonor(WinHonor);
                }
                Fighter.Character.InventoryCache.AddKamas(WinKamas);
                Fighter.Character.AddExperience(WinXp);

                this.myResult.AddResult(Fighter, true, WinKamas: WinKamas, WinExp: WinXp, WinHonor: WinHonor, WinItems: Drops);
            }

            base.EndFight();
        }