Beispiel #1
0
        public override bool BuyItem(WorldClient Client, uint TemplateId, ushort Quantity)
        {
            if (this.myEnd || Quantity <= 0)  // ne devrait jamais arriver
            {
                return(false);
            }

            if (!this.Npc.HasItemTemplate((int)TemplateId))
            {
                return(false);
            }

            var Price   = ShopNpcTable.Kolizeum.FirstOrDefault(x => x.Value.Where(y => y == (int)TemplateId).Count() > 0).Key *Quantity;
            var CachedP = Client.Character.InventoryCache.getCache().Values.Where(x => x.TemplateID == Settings.AppSettings.GetIntElement("Kolizeum.WinItem")).Count();

            if (Price > CachedP)
            {
                Client.Send(new ChatGameMessage("Il vous manque " + (Price - CachedP) + " Kolizetons", "3882AC"));
                return(false);
            }

            Client.Character.InventoryCache.removeByTemplateID(Settings.AppSettings.GetIntElement("Kolizeum.WinItem"), Price);

            if (InventoryItemTable.TryCreateItem((int)TemplateId, Client.Character, Quantity, useMax: true) == null)
            {
                return(false);
            }

            AccountTable.SubstractPoints(Client.Account.ID, Price);
            Client.Send(new ChatGameMessage("Il vous rêste désormais " + (CachedP - Price) + " Points", "3882AC"));

            return(true);
        }
Beispiel #2
0
        public override bool BuyItem(WorldClient Client, uint TemplateId, ushort Quantity)
        {
            if (this.myEnd) // ne devrait jamais arriver
            {
                return(false);
            }

            if (!this.Npc.HasItemTemplate((int)TemplateId))
            {
                return(false);
            }

            var Price = this.Npc.GetItemTemplate((int)TemplateId).Price;

            if (Price > Client.Character.Kamas)
            {
                return(false);
            }

            if (InventoryItemTable.TryCreateItem((int)TemplateId, Client.Character, Quantity) == null)
            {
                return(false);
            }

            Client.Character.InventoryCache.SubstractKamas(Price);
            Client.Send(new AccountStatsMessage(Client.Character));

            return(true);
        }
Beispiel #3
0
        private static void ProcessObjectEatLivingItemRequest(WorldClient Client, string Packet)
        {
            if (Client.GetFight() != null && (int)Client.GetFight().FightState > 2)
            {
                Client.Send(new BasicNoOperationMessage());
                return;
            }

            var Data = Packet.Split('|');

            long ItemGuid    = 0;
            long IdEatObject = 0;

            if (!long.TryParse(Data[0].Substring(2), out ItemGuid))
            {
                Client.Send(new BasicNoOperationMessage());
                return;
            }

            if (!long.TryParse(Data[2], out IdEatObject))
            {
                Client.Send(new BasicNoOperationMessage());
                return;
            }

            var Item     = Client.Character.InventoryCache.GetItem(ItemGuid);
            var ItemAlim = Client.Character.InventoryCache.GetItem(IdEatObject);

            if (Item == null || ItemAlim == null)
            {
                Client.Send(new BasicNoOperationMessage());
                return;
            }

            if (Item.SpeakingItem == null)
            {
                Client.Send(new BasicNoOperationMessage());
                return;
            }

            if ((ItemAlim.Quantity > 1) && (Item.Quantity - 1 > 0))
            {
                int newQ = ItemAlim.Quantity - 1;
                InventoryItemTable.TryCreateItem(ItemAlim.TemplateID, Client.Character, Stats: ItemAlim.GetStats().ToItemStats(), quantity: newQ);
                Client.Character.InventoryCache.UpdateObjectquantity(ItemAlim, 1);
            }
            long xp = long.Parse(ItemAlim.Template.Level.ToString());

            Item.SpeakingItem.EXP += xp;
            Client.Character.InventoryCache.RemoveItem(ItemAlim);
            InventoryItemTable.removeItem(ItemAlim.ID);
            Client.Send(new ObjectRemoveMessage(ItemAlim.ID));
            Client.Send(new ObjectRefreshMessage(Item));
            Client.Character.myMap.SendToMap(new ObjectActualiseMessage(Client.Character));
            if (Client.GetFight() != null)
            {
                Client.GetFight().SendToFight(new ObjectActualiseMessage(Client.Character));
            }
            Client.Send(new AccountStatsMessage(Client.Character));
        }
Beispiel #4
0
 public override void Execute(WorldClient client, CommandParameters parameters)
 {
     if (parameters.Lenght > 0)
     {
         int itemID = 0;
         try
         {
             itemID = parameters.GetIntParameter(0);
         }
         catch (FormatException e)
         {
             client.Send(new ConsoleMessage("Parametres invalide !", ConsoleColorEnum.RED));
             return;
         }
         var itemTemplate = ItemTemplateTable.GetTemplate(itemID);
         var quantity     = 1;
         var style        = false;
         if (itemTemplate != null)
         {
             if (parameters.Lenght > 1)
             {
                 try
                 {
                     quantity = parameters.GetIntParameter(1);
                 }
                 catch (FormatException e)
                 {
                     client.Send(new ConsoleMessage("Parametres invalide !", ConsoleColorEnum.RED));
                     return;
                 }
             }
             if (parameters.Lenght > 2)
             {
                 var styleStr = parameters.GetParameter(2).ToLower();
                 if (styleStr == "max")
                 {
                     style = true;
                 }
             }
             var item = InventoryItemTable.TryCreateItem(itemID, client.Character, 1, -1, null, style);
             client.Send(new ConsoleMessage("L'objet <b>'" + itemTemplate.Name + "'</b> a correctement ete generer !", ConsoleColorEnum.GREEN));
         }
         else
         {
             client.Send(new ConsoleMessage("Impossible de trouver l'objet n°" + itemID, ConsoleColorEnum.RED));
         }
     }
     else
     {
         client.Send(new ConsoleMessage("Parametres invalide !", ConsoleColorEnum.RED));
     }
 }
Beispiel #5
0
 public static void GiveItem(ActionModel action, Player perso, Player target, int itemID, int cellID)
 {
     try
     {
         int     tID   = int.Parse(action.args.Split(',')[0]);
         int     count = int.Parse(action.args.Split(',')[1]);
         Boolean send  = true;
         if (action.args.Split(',').Length > 2)
         {
             send = action.args.Split(',')[2].Equals("1");
         }
         if (count > 0)
         {
             var item = InventoryItemTable.TryCreateItem(itemID, perso, count, -1, null);
         }
         else
         {
             perso.InventoryCache.removeByTemplateID(tID, -count);
         }
         if (perso.IsOnline())//on envoie le Packet qui indique l'ajout//retrait d'un item
         {
             //POD
             if (send)
             {
                 if (count >= 0)
                 {
                     perso.Send(new TextInformationMessage(TextInformationTypeEnum.INFO, 21, +count + "~" + tID));
                 }
                 else if (count < 0)
                 {
                     perso.Send(new TextInformationMessage(TextInformationTypeEnum.INFO, 22, + -count + "~" + tID));
                 }
             }
         }
     }
     catch (Exception e)
     {
         Logger.Error(e);
     }
 }
Beispiel #6
0
        private static void ProcessExchangeMountParkRequest(WorldClient Client, string Packet)
        {
            MountPark MP = Client.Character.inMountPark;

            if (MP != null)
            {
                char c = Packet[2];
                Packet = Packet.Substring(3);
                int guid = -1;
                try
                {
                    guid = int.Parse(Packet);
                }
                catch (Exception e)
                {
                };
                switch (c)
                {
                case 'C':    //Parcho => Etable (Stocker)
                    if (guid == -1 || !Client.Character.InventoryCache.hasItemGuid(guid))
                    {
                        return;
                    }
                    InventoryItemModel obj = Client.Character.InventoryCache.GetItem(guid);

                    //on prend la DD demandée
                    int   DDid = -1;
                    Mount DD   = null;
                    if (obj.GetStats().HasEffect(EffectEnum.MountOwner))
                    {
                        DDid = obj.GetStats().GetEffect(EffectEnum.MountOwner).Items;
                        DD   = MountTable.getMount(DDid);
                    }
                    //FIXME mettre return au if pour ne pas créer des nouvelles dindes
                    if (DD == null)
                    {
                        int color = StaticMountTable.getMountColorByParchoTemplate(obj.TemplateID);
                        if (color < 1)
                        {
                            return;
                        }
                        DD = new Mount(color);
                    }
                    DD.Intialize();

                    //On enleve l'Item du Monde et du Perso
                    Client.Character.InventoryCache.remove(guid);
                    InventoryItemTable.removeItem(guid);
                    //on ajoute la dinde a l'étable
                    Client.Account.Data.Mounts.Add(DD.ID, DD);
                    Client.Account.Data.Save();

                    //On envoie les Packet
                    Client.Send(new ObjectRemoveMessage(obj.ID));
                    Client.Send(new ExchangeEndMessage('+', DD.parse()));
                    break;

                case 'c':    //Etable => Parcho(Echanger)
                    Mount DD1 = MountTable.getMount(guid);
                    //S'il n'a pas la dinde
                    if (!Client.Account.Data.Mounts.ContainsKey(DD1.ID) || DD1 == null)
                    {
                        return;
                    }
                    //on retire la dinde de l'étable
                    Client.Account.Data.Mounts.Remove(DD1.ID);

                    GenericStats Stat = new GenericStats();
                    Stat.AddItem(EffectEnum.MountOwner, DD1.ID);
                    Stat.AddSpecialEffect(EffectEnum.MountOwnerName, Client.Character.Name);
                    Stat.AddSpecialEffect(EffectEnum.MountName, DD1.Name);

                    var item = InventoryItemTable.TryCreateItem(StaticMountTable.getMountScroll(DD1.get_color()).ID, Client.Character, 1, -1, Stat.ToItemStats());

                    Client.Send(new ExchangeEndMessage('-', DD1.ID + ""));
                    Stat = null;
                    break;

                case 'g':    //Equiper
                    Mount DD3 = MountTable.getMount(guid);
                    //S'il n'a pas la dinde
                    if (DD3 == null || !Client.Account.Data.Mounts.ContainsKey(DD3.ID) || Client.Character.Mount != null)
                    {
                        return;
                    }
                    DD3.Intialize();
                    Client.Account.Data.Mounts.Remove(DD3.ID);
                    Client.Account.Data.Save();
                    Client.Character.Mount = DD3;

                    //Packets
                    Client.Send(new CharacterRideEventMessage("+", DD3));
                    Client.Send(new ExchangeEndMessage('-', DD3.ID + ""));
                    Client.Send(new CharacterMountXpGive(Client.Character.MountXPGive));
                    break;

                case 'p':    //Equipé => Stocker
                    //Si c'est la dinde équipé
                    if (Client.Character.Mount != null ? Client.Character.Mount.ID == guid : false)
                    {
                        //Si le perso est sur la monture on le fait descendre
                        if (Client.Character.isOnMount())
                        {
                            Client.Character.toogleOnMount();
                        }
                        //Si ca n'a pas réussie, on s'arrete là (Items dans le sac ?)
                        if (Client.Character.isOnMount())
                        {
                            return;
                        }

                        Mount DD2 = Client.Character.Mount;
                        DD2.Intialize();
                        Client.Account.Data.Mounts.Add(DD2.ID, DD2);
                        Client.Account.Data.Save();
                        Client.Character.Mount = null;

                        //Packets
                        Client.Send(new ExchangeEndMessage('+', DD2.parse()));
                        Client.Send(new CharacterRideEventMessage("-", null));
                        Client.Send(new CharacterMountXpGive(Client.Character.MountXPGive));
                    }
                    else    //Sinon...
                    {
                    }
                    break;
                }
            }
            else
            {
                Client.Send(new BasicNoOperationMessage());
                return;
            }
        }
Beispiel #7
0
        public override bool MoveItem(Network.WorldClient Client, Database.Models.InventoryItemModel Item, ushort Quantity, bool Add = false)
        {
            if (Add)
            {
                if (Quantity > Item.Quantity)
                {
                    Quantity = (ushort)Item.Quantity;
                }

                InventoryItemModel ObjectEqualize = getSimilarItem(Item);
                int    newQua = Item.Quantity - Quantity;
                String str;

                if (ObjectEqualize == null)
                {
                    if (newQua <= 0)
                    {
                        Client.Character.InventoryCache.RemoveItem(Item);
                        Mount.Items.Add(Item);
                        str = "O+" + Item.ID + "|" + Item.Quantity + "|" + Item.TemplateID + "|" + Item.GetStats().ToItemStats();
                        Client.Send(new ObjectRemoveMessage(Item.ID));
                    }
                    else
                    {
                        Client.Character.InventoryCache.UpdateObjectquantity(Item, newQua);
                        ObjectEqualize = InventoryItemTable.TryCreateItem(Item.TemplateID, Mount, Quantity, Stats: Item.Effects);
                        str            = "O+" + ObjectEqualize.ID + "|" + ObjectEqualize.Quantity + "|" + ObjectEqualize.TemplateID + "|" + ObjectEqualize.GetStats().ToItemStats();
                    }
                }
                else if (newQua <= 0)
                {
                    Client.Character.InventoryCache.RemoveItem(Item);
                    ObjectEqualize.Quantity += Item.Quantity;
                    InventoryItemTable.removeItem(Item.ID);
                    str = "O+" + ObjectEqualize.ID + "|" + ObjectEqualize.Quantity + "|" + ObjectEqualize.TemplateID + "|" + ObjectEqualize.GetStats().ToItemStats();
                    Client.Send(new ObjectRemoveMessage(Item.ID));
                    InventoryItemTable.Update(ObjectEqualize);
                }
                else
                {
                    Client.Character.InventoryCache.UpdateObjectquantity(Item, newQua);
                    ObjectEqualize.Quantity += Quantity;
                    str = "O+" + ObjectEqualize.ID + "|" + ObjectEqualize.Quantity + "|" + ObjectEqualize.TemplateID + "|" + ObjectEqualize.GetStats().ToItemStats();
                    InventoryItemTable.Update(ObjectEqualize);
                }
                Client.Send(new BankUpdateMessage(str));
                Client.Send(new InventoryWeightMessage(0, 2000)); // TODO PODS
                Client.Send(new MountActualPodMessage(Mount));
                MountTable.Update(Mount);
            }
            else
            {
                if (!Mount.Items.Contains(Item))
                {
                    return(false);
                }
                InventoryItemModel ObjectEqualize = Client.Character.InventoryCache.getSimilarInventoryItem(Item);
                int    newQua = Item.Quantity - Quantity;
                String str;

                if (ObjectEqualize == null)
                {
                    if (newQua <= 0)
                    {
                        Mount.Items.Remove(Item);
                        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)
                {
                    Mount.Items.Remove(Item);
                    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
                Client.Send(new MountActualPodMessage(Mount));
                MountTable.Update(Mount);
            }
            return(true);
        }
Beispiel #8
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();
        }
Beispiel #9
0
        public override void OverridableEndFight(FightTeam Winners, FightTeam Loosers)
        {
            var WinnersFighter = Winners.GetFighters().OfType <CharacterFighter>().ToList();
            var LoosersFighter = Loosers.GetFighters().OfType <CharacterFighter>().ToList();

            var WinnersTotalCote = WinnersFighter.Sum(x => x.Character.Cote);
            var LoosersTotalCote = LoosersFighter.Sum(x => x.Character.Cote);

            int WinCote = 0, LooseCote = 0;

            if (LoosersTotalCote - WinnersTotalCote < 0)
            {
                WinCote = 25;
            }
            else if (WinnersTotalCote - LoosersTotalCote < 0)
            {
                WinCote = 75;
            }
            else
            {
                WinCote = 50;
            }

            if (LoosersTotalCote - WinnersTotalCote < 0)
            {
                LooseCote = 25;
            }
            else if (WinnersTotalCote - LoosersTotalCote < 0)
            {
                LooseCote = 75;
            }
            else
            {
                LooseCote = 50;
            }



            var PossibleItemLoot = new List <ItemLoot>();
            var ItemDroped       = new Dictionary <int, int>()
            {
                { Settings.AppSettings.GetIntElement("Kolizeum.WinItem"), 3 },
            };

            foreach (var Fighter in LoosersFighter)
            {
                int CoteLoosed = LooseCote;

                if (!Fighter.Left)
                {
                    if (Fighter.Character.Cote - LooseCote < 0)
                    {
                        CoteLoosed = Fighter.Character.Cote;
                    }
                    Fighter.Character.Cote -= CoteLoosed;
                }

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

            foreach (var Fighter in WinnersFighter)
            {
                if (!Fighter.Left)
                {
                    Fighter.Character.Cote += WinCote;
                    this.myResult.AddResult(Fighter, true, WinExp: WinCote, WinItems: ItemDroped);
                    InventoryItemTable.TryCreateItem(ItemDroped.First().Key, Fighter.Character, ItemDroped.First().Value);
                }
                else
                {
                    this.myResult.AddResult(Fighter, true);
                }
            }
            base.EndFight();
        }
Beispiel #10
0
        public override bool Finish()
        {
            if (this.myEnd)
            {
                return(false);
            }

            Logger.Debug("PlayerExchange(" + this.myClient1.Account.Username + " - " + this.myClient2.Account.Username + ")::Finish()" +
                         "\n          -- P1(Items=" + string.Join(",", this.myItemsToTrade[this.myClient1].Select(x => x.Key)) + " Kamas=" + this.myKamasToTrade[this.myClient1] + ")" +
                         "\n          -- P2(Items=" + string.Join(",", this.myItemsToTrade[this.myClient2].Select(x => x.Key)) + " Kamas=" + this.myKamasToTrade[this.myClient2] + ")");


            foreach (var ItemData in this.myItemsToTrade[this.myClient1])
            {
                var Item = this.myClient1.Character.InventoryCache.GetItem(ItemData.Key);
                Item.Quantity -= ItemData.Value;

                if (Item.Quantity == 0)
                {
                    InventoryItemTable.removeItem(Item.ID);
                    this.myClient1.Character.InventoryCache.RemoveItem(Item);
                    this.myClient1.Send(new ObjectRemoveMessage(Item.ID));
                }
                else if (Item.Quantity < 0)
                {
                    Logger.Debug("PlayerExchange::Finish() item quantity < 0 : " + myClient1.Character.Name);
                    InventoryItemTable.removeItem(Item.ID);
                    this.myClient1.Character.InventoryCache.RemoveItem(Item);
                }
                else
                {
                    this.myClient1.Character.InventoryCache.UpdateObjectquantity(Item, Item.Quantity);
                }

                InventoryItemTable.TryCreateItem(Item.TemplateID, this.myClient2.Character, ItemData.Value, Stats: Item.Effects);
            }

            foreach (var ItemData in this.myItemsToTrade[this.myClient2])
            {
                var Item = this.myClient2.Character.InventoryCache.GetItem(ItemData.Key);
                Item.Quantity -= ItemData.Value;

                if (Item.Quantity == 0)
                {
                    InventoryItemTable.removeItem(Item.ID);
                    this.myClient2.Character.InventoryCache.RemoveItem(Item);
                    this.myClient2.Send(new ObjectRemoveMessage(Item.ID));
                }
                else if (Item.Quantity < 0)
                {
                    Logger.Debug("PlayerExchange::Finish() item quantity < 0 : " + myClient2.Character.Name);
                    InventoryItemTable.removeItem(Item.ID);
                    this.myClient2.Character.InventoryCache.RemoveItem(Item);
                }
                else
                {
                    this.myClient2.Character.InventoryCache.UpdateObjectquantity(Item, Item.Quantity);
                }

                InventoryItemTable.TryCreateItem(Item.TemplateID, this.myClient1.Character, ItemData.Value, Stats: Item.Effects);
            }

            this.myClient1.Character.InventoryCache.SubstractKamas(this.myKamasToTrade[this.myClient1]);
            this.myClient2.Character.InventoryCache.SubstractKamas(this.myKamasToTrade[this.myClient2]);

            this.myClient1.Character.InventoryCache.AddKamas(this.myKamasToTrade[this.myClient2]);
            this.myClient2.Character.InventoryCache.AddKamas(this.myKamasToTrade[this.myClient1]);

            this.myClient1.Send(new AccountStatsMessage(myClient1.Character));
            this.myClient2.Send(new AccountStatsMessage(myClient2.Character));

            return(true);
        }
Beispiel #11
0
        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);
        }
Beispiel #12
0
 public override bool MoveItem(WorldClient Client, Database.Models.InventoryItemModel Item, ushort Quantity, bool Add = false)
 {
     if (Add)
     {
         long Taxe = (long)(Price * (Market.SellTaxe / 100));
         if (myClient.Account.Data.canTaxBidHouseItem(Market.HdvID) >= Market.countItem)
         {
             myClient.Send(new TextInformationMessage(Libs.Enumerations.TextInformationTypeEnum.INFO, 58));
             return(false);
         }
         if (myClient.Character.Kamas < Taxe)
         {
             myClient.Send(new TextInformationMessage(Libs.Enumerations.TextInformationTypeEnum.ERREUR, 76));
             return(false);
         }
         myClient.Character.InventoryCache.SubstractKamas(Taxe);
         int cantReal  = (int)(Math.Pow(10, Quantity) / 10);
         int nuevaCant = Item.Quantity - cantReal;
         if (nuevaCant <= 0)
         {
             myClient.Character.InventoryCache.RemoveItem(Item);
             myClient.Character.Send(new ObjectRemoveMessage(Item.ID));
         }
         else
         {
             Item.Quantity -= cantReal;
             myClient.Send(new ObjectQuantityMessage(Item.ID, Item.Quantity));
             Item = InventoryItemTable.TryCreateItem(Item.TemplateID, quantity: cantReal, Stats: Item.GetStats().ToItemStats());
         }
         var MarketItem = new BidHouseItem()
         {
             Price    = Price,
             Quantity = Quantity,
             Owner    = myClient.Account.ID,
             Item     = Item,
         };
         Market.addObject(MarketItem);
         BidHouseTable.Add(MarketItem);
         myClient.Send(new ExchangeMoveDistantObject('+', "", MarketItem.SerializeAsDisplayEquipmentOnMarket()));
         Client.Send(new AccountStatsMessage(myClient.Character));
     }
     else
     {
         var          MarketID = Market.HdvID;
         BidHouseItem BHI      = null;
         try
         {
             foreach (var BH in myClient.Account.Data.BHI[MarketID])
             {
                 if (BH.LineID == ItemID)
                 {
                     BHI = BH;
                     break;
                 }
             }
         }
         catch (Exception e)
         {
             return(false);
         }
         if (BHI == null)
         {
             return(false);
         }
         myClient.Account.Data.BHI[MarketID].Remove(BHI);
         var Object = BHI.Item;
         myClient.Character.InventoryCache.Add(Object);
         Market.DestroyObject(BHI);
         BidHouseTable.Delete(BHI.ItemID);
         myClient.Send(new ExchangeMoveDistantObject('-', "", ItemID + ""));
     }
     return(true);
 }
Beispiel #13
0
        public void MoveItem(int Guid, ItemSlotEnum Slot, bool Packet, int Quantity = 1)
        {
            var Item = this.get(Guid);

            // Item inexistant
            if (Item == null)
            {
                return;
            }

            // Meme endroit ?
            if (Item.Slot == Slot)
            {
                return;
            }

            // Veu equiper un item
            if (Slot > ItemSlotEnum.SLOT_INVENTAIRE && Slot <= ItemSlotEnum.SLOT_BOUCLIER)
            {
                if (Item.Template.Type == 113)
                {
                    if (this.GetItemInSlot(Slot) == null)
                    {
                        this.Player.Send(new TextInformationMessage(TextInformationTypeEnum.ERREUR, 161));
                        return;
                    }
                    if (Item.Quantity > 1)
                    {
                        if (Quantity > Item.Quantity)
                        {
                            Quantity = Item.Quantity;
                        }
                        int newQ = Item.Quantity - Quantity;
                        if (newQ > 0)
                        {
                            InventoryItemTable.TryCreateItem(Item.TemplateID, this.Player, newQ, -1, Item.GetStats().ToItemStats());
                            UpdateObjectquantity(Item, Quantity);
                        }
                    }
                    var EquipedItemB = this.GetItemInSlot(Slot);

                    var SpeakingTestItem = SpeakingTable.Cache.Values.FirstOrDefault(x => x != null && x.LinkedItem == Item.ID && x.Associated == 0);

                    if (SpeakingTestItem != null)
                    {
                        EquipedItemB.SpeakingID     = SpeakingTestItem.ID;
                        SpeakingTestItem.Stats      = EquipedItemB.GetStats().ToItemStats();
                        SpeakingTestItem.LinkedItem = EquipedItemB.ID;
                        SpeakingTestItem.Associated = 1;
                        remove(Item.ID);
                        Player.Send(new ObjectRemoveMessage(Item.ID));
                        Player.Send(new ObjectRefreshMessage(EquipedItemB));
                        Player.myMap.SendToMap(new ObjectActualiseMessage(Player));
                        if (Player.Client.GetFight() != null)
                        {
                            Player.Client.GetFight().SendToFight(new ObjectActualiseMessage(Player));
                        }
                        return;
                    }

                    var    ID        = DatabaseCache.nextSpeakingId++;
                    String Date      = DateTime.Now.Month + "" + DateTime.Now.Day;
                    String InterDate = (DateTime.Now.Month + 3) + "" + DateTime.Now.Day;
                    String Time      = DateTime.Now.Hour + "" + DateTime.Now.Minute;

                    Speaking newItem = new Speaking(ID, DateTime.Now.Year, int.Parse(Date), int.Parse(Time), 1, 1, EquipedItemB.Template.Type, EquipedItemB.ID, 0, DateTime.Now.Year, int.Parse(InterDate), int.Parse(Time), DateTime.Now.Year, int.Parse(Date), int.Parse(Time), 1, Item.TemplateID, Item.ID, EquipedItemB.GetStats().ToItemStats());
                    SpeakingTable.New(newItem);
                    EquipedItemB.SpeakingID = ID;
                    remove(Item.ID);
                    Player.Send(new ObjectRemoveMessage(Item.ID));
                    Player.Send(new ObjectRefreshMessage(EquipedItemB));
                    Player.myMap.SendToMap(new ObjectActualiseMessage(Player));
                    if (Player.Client.GetFight() != null)
                    {
                        Player.Client.GetFight().SendToFight(new ObjectActualiseMessage(Player));
                    }
                    return;
                }

                // Il peu placer l'item dans le slot desiré ?
                if (!ItemTemplateModel.CanPlaceInSlot(ItemTemplateTable.GetTemplate(Item.TemplateID).ItemType, Slot))
                {
                    return;
                }

                // Level requis
                if (ItemTemplateTable.GetTemplate(Item.TemplateID).Level > Player.Level)
                {
                    if (Packet)
                    {
                        Player.Send(new ObjectMoveFailMessage(ObjectMoveFailReasonEnum.REASON_LEVEL_REQUIRED));
                    }
                    return;
                }

                if (!ItemTemplateTable.GetTemplate(Item.TemplateID).Criterions.Equals("") && !ConditionParser.validConditions(this.Player, ItemTemplateTable.GetTemplate(Item.TemplateID).Criterions))
                {
                    this.Player.Send(new ImMessage("119|43"));
                    return;
                }

                var EquipedItem = this.GetItemInSlot(Slot);

                // Si item deja equipé dans le slot
                if (EquipedItem != null)
                {
                    // Deplacement dans l'inventaire
                    Player.GetStats().UnMerge(EquipedItem.GetStats());
                    this.Player.Life    -= EquipedItem.GetStats().GetTotal(EffectEnum.AddVitalite);
                    EquipedItem.Position = -1;
                    Player.Send(new ObjectMoveSucessMessage(EquipedItem.ID, -1));
                }

                // Template deja equipé
                if (this.HasTemplateEquiped(Item.TemplateID))
                {
                    if (Packet)
                    {
                        Player.Send(new ObjectMoveFailMessage(ObjectMoveFailReasonEnum.REASON_ALREADY_EQUIPED));
                    }
                    return;
                }

                /*var simlarItem = this.getSimilarInventoryItem(Item);
                 * if (simlarItem != null)
                 * {
                 *  this.UpdateObjectquantity(simlarItem, simlarItem.Quantity + Item.Quantity);
                 *  remove(Item.ID);
                 *  InventoryItemTable.removeItem(Item.ID);
                 *  Player.Send(new ObjectRemoveMessage(Item.ID));
                 *
                 * }
                 * else*/
                if (Item.Quantity > 1)
                {
                    var NewItem = InventoryItemTable.TryCreateItem(Item.TemplateID, this.Player, 1, (short)Slot, Item.Effects);
                    this.UpdateObjectquantity(Item, Item.Quantity - 1);
                }
                else
                {
                    // On modifi la position et fusionne les stats
                    Item.Position = (short)Slot;
                    Player.Send(new ObjectMoveSucessMessage(Item.ID, (short)Slot));
                    Player.Send(new ObjectMoveSucessMessage(Item.ID, (short)Item.Position));
                }

                if (GetItemInSlot(ItemSlotEnum.SLOT_ARME) != null)
                {
                    Player.Send(new ObjectTaskMessage(-1));
                }

                Player.GetStats().Merge(Item.GetStats());
                this.Player.Life += Item.GetStats().GetTotal(EffectEnum.AddVitalite);
                this.Player.Life += Item.GetStats().GetTotal(EffectEnum.AddVie);
                if (Packet)
                {
                    Player.Client.Send(new AccountStatsMessage(Player));
                    Player.myMap.SendToMap(new ObjectActualiseMessage(Player));
                    if (Player.Client.GetFight() != null)
                    {
                        Player.Client.GetFight().SendToFight(new ObjectActualiseMessage(Player));
                    }
                }
            }
            else
            {
                var NeedActualise = false;

                // Si l'item est equipé, on deduit les stats
                if (Item.Slot > ItemSlotEnum.SLOT_INVENTAIRE && Item.Slot < ItemSlotEnum.SLOT_BOUCLIER)
                {
                    // Retire les stats
                    Player.GetStats().UnMerge(Item.GetStats());
                    this.Player.Life -= Item.GetStats().GetTotal(EffectEnum.AddVitalite);
                    this.Player.Life -= Item.GetStats().GetTotal(EffectEnum.AddVie);
                    if (Player.Life <= 0)
                    {
                        Player.Life = 1;
                    }
                    if (Packet)
                    {
                        Player.Client.Send(new AccountStatsMessage(this.Player));
                        NeedActualise = true;
                    }
                }

                // On tente de fusionner
                if (!this.TryMergeItem(Item.TemplateID, Item.Effects, Slot, Item.Quantity, Item))
                {
                    Item.Position = (short)Slot;
                    if (Packet)
                    {
                        Player.Send(new ObjectMoveSucessMessage(Item.ID, (short)Item.Position));
                    }
                }

                if (NeedActualise)
                {
                    Player.myMap.SendToMap(new ObjectActualiseMessage(Player));
                    if (Player.Client.GetFight() != null)
                    {
                        Player.Client.GetFight().SendToFight(new ObjectActualiseMessage(Player));
                    }
                }
            }
            onMoveItem(Item);
        }