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(); }
public override bool MoveItem(Network.WorldClient Client, Database.Models.InventoryItemModel Item, ushort Quantity, bool Add = false) { if (!Add) { if (!Npc.Items.ContainsKey(Item.ID)) { return(false); } InventoryItemModel ObjectEqualize = Client.Character.InventoryCache.getSimilarInventoryItem(Item); int newQua = Item.Quantity - Quantity; String str; if (ObjectEqualize == null) { if (newQua <= 0) { Npc.Items.Remove(Item.ID); if (Client.Character.InventoryCache.TryMergeItem(Item.TemplateID, Item.GetStats().ToItemStats(), Item.Slot, Item.Quantity)) { InventoryItemTable.removeItem(Item.ID); } else { Client.Character.InventoryCache.Add(Item); } str = "O-" + Item.ID; } else { ObjectEqualize = InventoryItemTable.TryCreateItem(Item.TemplateID, Client.Character, Quantity, Stats: Item.Effects); Item.Quantity = newQua; str = "O+" + Item.ID + "|" + Item.Quantity + "|" + Item.TemplateID + "|" + Item.GetStats().ToItemStats(); } } else if (newQua <= 0) { Npc.Items.Remove(Item.ID); ObjectEqualize.Quantity += Item.Quantity; Client.Send(new ObjectQuantityMessage(ObjectEqualize.ID, ObjectEqualize.Quantity)); InventoryItemTable.removeItem(Item.ID); str = "O-" + Item.ID; InventoryItemTable.Update(ObjectEqualize); } else { Item.Quantity = newQua; ObjectEqualize.Quantity += Quantity; Client.Send(new ObjectQuantityMessage(ObjectEqualize.ID, ObjectEqualize.Quantity)); str = "O+" + Item.ID + "|" + Item.Quantity + "|" + Item.TemplateID + "|" + Item.GetStats().ToItemStats(); InventoryItemTable.Update(ObjectEqualize); } Client.Send(new BankUpdateMessage(str)); Client.Send(new InventoryWeightMessage(0, 2000)); // TODO PODS TaxCollectorTable.Update(Npc); Npc.LogItems.Add(Item.ID, Item); } Client.GetCharacter().AddExperience(Npc.XP); Npc.LogXP += Npc.XP; Npc.XP = 0; TaxCollectorTable.Update(Npc); return(true); }