/// <summary>
        /// The merchant received an item from another GameLiving.
        /// </summary>
        /// <param name="source"></param>
        /// <param name="item"></param>
        /// <returns></returns>
        public override bool ReceiveItem(GameLiving source, InventoryItem item)
        {
            GamePlayer player = source as GamePlayer;

            if (player != null && item != null && item.Name.EndsWith("Credit"))
            {
                if (ArtifactMgr.GrantArtifactBountyCredit(player, item.Name))
                {
                    player.Inventory.RemoveItem(item);
                    InventoryLogging.LogInventoryAction(player, this, eInventoryActionType.Merchant, item.Template, item.Count);
                    return(true);
                }
                else
                {
                    // refund bounty points
                    player.Inventory.RemoveItem(item);
                    InventoryLogging.LogInventoryAction(player, this, eInventoryActionType.Merchant, item.Template, item.Count);

                    long totalValue = item.Price;
                    player.BountyPoints += totalValue;
                    player.Out.SendUpdatePoints();
                    player.Out.SendMessage(totalValue + " Bounty Points refunded", eChatType.CT_ScreenCenterSmaller, eChatLoc.CL_SystemWindow);
                    player.Out.SendMessage("You already have this credit or your class is not eligible to receive this artifact. " + totalValue + " Bounty Points refunded!", eChatType.CT_Merchant, eChatLoc.CL_SystemWindow);
                    return(true);
                }
            }

            return(base.ReceiveItem(source, item));
        }
예제 #2
0
        /// <summary>
        /// Process for changing an emblem
        /// </summary>
        /// <param name="player"></param>
        /// <param name="oldemblem"></param>
        /// <param name="newemblem"></param>
        public static void ChangeEmblem(GamePlayer player, int oldemblem, int newemblem)
        {
            player.Guild.Emblem = newemblem;
            if (oldemblem != 0)
            {
                player.RemoveMoney(COST_RE_EMBLEM, null);
                InventoryLogging.LogInventoryAction(player, "(GUILD;" + player.GuildName + ")", eInventoryActionType.Other, COST_RE_EMBLEM);
                var objs = DOLDB <InventoryItem> .SelectObjects(DB.Column(nameof(InventoryItem.Emblem)).IsEqualTo(oldemblem));

                foreach (InventoryItem item in objs)
                {
                    item.Emblem = newemblem;
                }
                GameServer.Database.SaveObject(objs);

                // change guild house emblem

                if (player.Guild.GuildOwnsHouse && player.Guild.GuildHouseNumber > 0)
                {
                    Housing.House guildHouse = Housing.HouseMgr.GetHouse(player.Guild.GuildHouseNumber);

                    if (guildHouse != null)
                    {
                        guildHouse.Emblem = player.Guild.Emblem;
                        guildHouse.SaveIntoDatabase();
                        guildHouse.SendUpdate();
                    }
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Apply all needed magical bonus to the item
        /// </summary>
        /// <param name="player"></param>
        /// <param name="item"></param>
        /// <returns></returns>
        protected override void ApplyMagicalEffect(GamePlayer player, InventoryItem item)
        {
            InventoryItem tincture = (InventoryItem)player.TradeWindow.TradeItems[0];

            // One item each side of the trade window.
            if (item == null || tincture == null)
            {
                return;
            }

            if (tincture.ProcSpellID != 0)
            {
                item.ProcSpellID = tincture.ProcSpellID;
            }
            else
            {
                item.MaxCharges = GetItemMaxCharges(item);
                item.Charges    = item.MaxCharges;
                item.SpellID    = tincture.SpellID;
            }

            player.Inventory.RemoveCountFromStack(tincture, 1);
            InventoryLogging.LogInventoryAction(player, "(craft)", eInventoryActionType.Craft, tincture.Template);

            if (item.Template is ItemUnique)
            {
                GameServer.Database.SaveObject(item);
                GameServer.Database.SaveObject(item.Template as ItemUnique);
            }
            else
            {
                ChatUtil.SendErrorMessage(player, "Alchemy crafting error: Item was not an ItemUnique, crafting changes not saved to DB!");
                log.ErrorFormat("Alchemy crafting error: Item {0} was not an ItemUnique for player {1}, crafting changes not saved to DB!", item.Id_nb, player.Name);
            }
        }
예제 #4
0
        public void WithdrawGuildBank(GamePlayer withdraw, double amount)
        {
            if (amount < 0)
            {
                withdraw.Out.SendMessage(LanguageMgr.GetTranslation(withdraw.Client, "Scripts.Player.Guild.WithdrawInvalid"), eChatType.CT_Guild, eChatLoc.CL_SystemWindow);
                return;
            }
            else if ((withdraw.Guild.GetGuildBank() - amount) < 0)
            {
                withdraw.Out.SendMessage(LanguageMgr.GetTranslation(withdraw.Client, "Scripts.Player.Guild.WithdrawTooMuch"), eChatType.CT_Guild, eChatLoc.CL_SystemWindow);
                return;
            }

            withdraw.Out.SendMessage(LanguageMgr.GetTranslation(withdraw.Client, "Scripts.Player.Guild.Withdrawamount", Money.GetString(long.Parse(amount.ToString()))), eChatType.CT_Guild, eChatLoc.CL_SystemWindow);
            withdraw.Guild.UpdateGuildWindow();
            m_DBguild.Bank -= amount;

            var amt = long.Parse(amount.ToString());

            withdraw.AddMoney(amt);
            InventoryLogging.LogInventoryAction("(GUILD;" + Name + ")", withdraw, eInventoryActionType.Other, amt);
            withdraw.Out.SendUpdatePlayer();
            withdraw.SaveIntoDatabase();
            withdraw.Guild.SaveIntoDatabase();
            return;
        }
예제 #5
0
        public override bool ReceiveItem(GameLiving source, InventoryItem item)
        {
            GamePlayer player = source as GamePlayer;

            if (player == null)
            {
                return(false);
            }

            if (!player.IsWithinRadius(this, 500))
            {
                ((GamePlayer)source).Out.SendMessage("You are to far away to give anything to " + this.Name + ".", eChatType.CT_System, eChatLoc.CL_SystemWindow);
                return(false);
            }

            if (item != null)
            {
                GameLocation destination;
                if (_itemXdestination.TryGetValue(item.Id_nb, out destination))
                {
                    player.MoveTo(destination);
                    player.Inventory.RemoveItem(item);
                    InventoryLogging.LogInventoryAction(player, this, eInventoryActionType.Merchant, item.Template, item.Count);
                    player.SaveIntoDatabase();
                    return(true);
                }
            }
            return(base.ReceiveItem(source, item));
        }
예제 #6
0
        /// <summary>
        /// Set guild bank command
        /// </summary>
        /// <param name="donating"></param>
        /// <param name="amount"></param>
        /// <returns></returns>
        public void SetGuildBank(GamePlayer donating, double amount)
        {
            if (donating == null || donating.Guild == null)
            {
                return;
            }

            if (amount < 0)
            {
                donating.Out.SendMessage(LanguageMgr.GetTranslation(donating.Client, "Scripts.Player.Guild.DepositInvalid"), eChatType.CT_Guild, eChatLoc.CL_SystemWindow);
                return;
            }
            else if ((donating.Guild.GetGuildBank() + amount) >= 1000000001)
            {
                donating.Out.SendMessage(LanguageMgr.GetTranslation(donating.Client, "Scripts.Player.Guild.DepositFull"), eChatType.CT_Guild, eChatLoc.CL_SystemWindow);
                return;
            }

            if (!donating.RemoveMoney(long.Parse(amount.ToString())))
            {
                donating.Out.SendMessage("You don't have this amount of money !", eChatType.CT_Important, eChatLoc.CL_SystemWindow);
                return;
            }

            donating.Out.SendMessage(LanguageMgr.GetTranslation(donating.Client, "Scripts.Player.Guild.DepositAmount", Money.GetString(long.Parse(amount.ToString()))), eChatType.CT_Guild, eChatLoc.CL_SystemWindow);

            donating.Guild.UpdateGuildWindow();
            m_DBguild.Bank += amount;

            InventoryLogging.LogInventoryAction(donating, "(GUILD;" + Name + ")", eInventoryActionType.Other, long.Parse(amount.ToString()));
            donating.Out.SendUpdatePlayer();
            return;
        }
예제 #7
0
        /// <summary>
        /// For Recieving CL Respec Stone.
        /// </summary>
        /// <param name="source"></param>
        /// <param name="item"></param>
        /// <returns></returns>
        public override bool ReceiveItem(GameLiving source, InventoryItem item)
        {
            if (source == null || item == null)
            {
                return(false);
            }

            GamePlayer player = source as GamePlayer;

            if (player != null)
            {
                switch (item.Id_nb)
                {
                case "respec_cl":
                {
                    player.Inventory.RemoveCountFromStack(item, 1);
                    InventoryLogging.LogInventoryAction(player, this, eInventoryActionType.Other, item.Template);
                    player.RespecAmountChampionSkill++;
                    player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "CLWeaponNPC.ReceiveItem.RespecCL"), eChatType.CT_System, eChatLoc.CL_PopupWindow);
                    return(true);
                }
                }
            }

            return(base.ReceiveItem(source, item));
        }
        /// <summary>
        /// Called when the living is about to get an item from someone
        /// else
        /// </summary>
        /// <param name="source">Source from where to get the item</param>
        /// <param name="item">Item to get</param>
        /// <returns>true if the item was successfully received</returns>
        public override bool ReceiveItem(GameLiving source, InventoryItem item)
        {
            if (source == null || item == null)
            {
                return(false);
            }

            if (source is GamePlayer)
            {
                GamePlayer player = (GamePlayer)source;

                if (item.Name.ToLower().StartsWith(LanguageMgr.GetTranslation(ServerProperties.Properties.DB_LANGUAGE, "GameStableMaster.ReceiveItem.TicketTo")) && item.Item_Type == 40)
                {
                    foreach (GameNPC npc in GetNPCsInRadius(1500))
                    {
                        if (npc is GameTaxiBoat)
                        {
                            player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "GameBoatStableMaster.ReceiveItem.Departed", Name), eChatType.CT_System, eChatLoc.CL_PopupWindow);
                            return(false);
                        }
                    }

                    string    destination = item.Name.Substring(LanguageMgr.GetTranslation(ServerProperties.Properties.DB_LANGUAGE, "GameStableMaster.ReceiveItem.TicketTo").Length);
                    PathPoint path        = MovementMgr.LoadPath(item.Id_nb);

                    // PathPoint path = MovementMgr.Instance.LoadPath(this.Name + "=>" + destination);
                    if ((path != null) && (Math.Abs(path.X - X) < 500) && (Math.Abs(path.Y - Y) < 500))
                    {
                        player.Inventory.RemoveCountFromStack(item, 1);
                        InventoryLogging.LogInventoryAction(player, this, eInventoryActionType.Merchant, item.Template);

                        GameTaxiBoat boat = new GameTaxiBoat();
                        boat.Name          = "Boat to " + destination;
                        boat.Realm         = source.Realm;
                        boat.X             = path.X;
                        boat.Y             = path.Y;
                        boat.Z             = path.Z;
                        boat.CurrentRegion = CurrentRegion;
                        boat.Heading       = path.GetHeading(path.Next);
                        boat.AddToWorld();
                        boat.CurrentWayPoint = path;
                        GameEventMgr.AddHandler(boat, GameNPCEvent.PathMoveEnds, new DOLEventHandler(OnHorseAtPathEnd));

                        // new MountHorseAction(player, boat).Start(400);
                        new HorseRideAction(boat).Start(30 * 1000);

                        player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "GameBoatStableMaster.ReceiveItem.SummonedBoat", Name, destination), eChatType.CT_System, eChatLoc.CL_SystemWindow);
                        return(true);
                    }
                    else
                    {
                        player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "GameBoatStableMaster.ReceiveItem.UnknownWay", Name, destination), eChatType.CT_System, eChatLoc.CL_SystemWindow);
                    }
                }
            }

            return(base.ReceiveItem(source, item));
        }
예제 #9
0
        public override void OnPlayerBuy(GamePlayer player, int item_slot, int number)
        {
            //Get the template
            int pagenumber = item_slot / MerchantTradeItems.MAX_ITEM_IN_TRADEWINDOWS;
            int slotnumber = item_slot % MerchantTradeItems.MAX_ITEM_IN_TRADEWINDOWS;

            ItemTemplate template = this.TradeItems.GetItem(pagenumber, (eMerchantWindowSlot)slotnumber);

            if (template == null)
            {
                return;
            }

            //Calculate the amout of items
            int amountToBuy = number;

            if (template.PackSize > 0)
            {
                amountToBuy *= template.PackSize;
            }

            if (amountToBuy <= 0)
            {
                return;
            }

            //Calculate the value of items
            long totalValue = number * template.Price;

            lock (player.Inventory)
            {
                if (player.BountyPoints < totalValue)
                {
                    player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "GameMerchant.OnPlayerBuy.YouNeedBP", totalValue), eChatType.CT_System, eChatLoc.CL_SystemWindow);
                    return;
                }
                if (!player.Inventory.AddTemplate(GameInventoryItem.Create(template), amountToBuy, eInventorySlot.FirstBackpack, eInventorySlot.LastBackpack))
                {
                    player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "GameMerchant.OnPlayerBuy.NotInventorySpace"), eChatType.CT_System, eChatLoc.CL_SystemWindow);
                    return;
                }
                InventoryLogging.LogInventoryAction(this, player, eInventoryActionType.Merchant, template, amountToBuy);
                //Generate the buy message
                string message;
                if (number > 1)
                {
                    message = LanguageMgr.GetTranslation(player.Client.Account.Language, "GameMerchant.OnPlayerBuy.BoughtPiecesBP", totalValue, template.GetName(1, false));
                }
                else
                {
                    message = LanguageMgr.GetTranslation(player.Client.Account.Language, "GameMerchant.OnPlayerBuy.BoughtBP", template.GetName(1, false), totalValue);
                }
                player.BountyPoints -= totalValue;
                player.Out.SendUpdatePoints();
                player.Out.SendMessage(message, eChatType.CT_Merchant, eChatLoc.CL_SystemWindow);
            }
        }
예제 #10
0
        protected void RechargerDialogResponse(GamePlayer player, byte response)
        {
            WeakReference itemWeak =
                (WeakReference)player.TempProperties.getProperty <object>(
                    RECHARGE_ITEM_WEAK,
                    new WeakRef(null));

            player.TempProperties.removeProperty(RECHARGE_ITEM_WEAK);

            InventoryItem item = (InventoryItem)itemWeak.Target;

            if (item == null || item.SlotPosition == (int)eInventorySlot.Ground ||
                item.OwnerID == null || item.OwnerID != player.InternalID)
            {
                player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "Scripts.Recharger.RechargerDialogResponse.InvalidItem"), eChatType.CT_System, eChatLoc.CL_SystemWindow);
                return;
            }

            if (response != 0x01)
            {
                player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "Scripts.Recharger.RechargerDialogResponse.Decline", item.Name), eChatType.CT_System, eChatLoc.CL_SystemWindow);
                return;
            }

            long cost = 0;

            if (item.Charges < item.MaxCharges)
            {
                cost += (item.MaxCharges - item.Charges) * Money.GetMoney(0, 0, 10, 0, 0);
            }

            if (item.Charges1 < item.MaxCharges1)
            {
                cost += (item.MaxCharges1 - item.Charges1) * Money.GetMoney(0, 0, 10, 0, 0);
            }

            if (!player.RemoveMoney(cost))
            {
                player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "Scripts.Recharger.RechargerDialogResponse.NotMoney"), eChatType.CT_System, eChatLoc.CL_SystemWindow);
                return;
            }

            InventoryLogging.LogInventoryAction(player, this, eInventoryActionType.Merchant, cost);

            player.Out.SendMessage(
                LanguageMgr.GetTranslation(player.Client.Account.Language, "Scripts.Recharger.RechargerDialogResponse.GiveMoney",
                                           GetName(0, false, player.Client.Account.Language, this), Money.GetString((long)cost)), eChatType.CT_System, eChatLoc.CL_SystemWindow);
            item.Charges  = item.MaxCharges;
            item.Charges1 = item.MaxCharges1;

            player.Out.SendInventoryItemsUpdate(new InventoryItem[] { item });
            SayTo(player, LanguageMgr.GetTranslation(player.Client.Account.Language, "Scripts.Recharger.RechargerDialogResponse.FullyCharged"));
            return;
        }
예제 #11
0
        protected void EnchanterDialogResponse(GamePlayer player, byte response)
        {
            WeakReference itemWeak =
                (WeakReference)player.TempProperties.getProperty <object>(
                    ENCHANT_ITEM_WEAK,
                    new WeakRef(null)
                    );

            player.TempProperties.removeProperty(ENCHANT_ITEM_WEAK);


            if (response != 0x01 || !this.IsWithinRadius(player, WorldMgr.INTERACT_DISTANCE))
            {
                return;
            }

            InventoryItem item = (InventoryItem)itemWeak.Target;

            if (item == null || item.SlotPosition == (int)eInventorySlot.Ground ||
                item.OwnerID == null || item.OwnerID != player.InternalID)
            {
                player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "Enchanter.EnchanterDialogResponse.Text1"), eChatType.CT_System, eChatLoc.CL_SystemWindow);
                return;
            }

            long Fee = CalculEnchantPrice(item);

            if (player.GetCurrentMoney() < Fee)
            {
                SayTo(player, eChatLoc.CL_SystemWindow, LanguageMgr.GetTranslation(player.Client.Account.Language, "Enchanter.EnchanterDialogResponse.Text2", Money.GetString(Fee)));
                return;
            }
            if (item.Level < 50)
            {
                item.Bonus = BONUS_TABLE[(item.Level / 5) - 2];
            }
            else
            {
                item.Bonus = 35;
            }

            item.Name = LanguageMgr.GetTranslation(player.Client.Account.Language, "Enchanter.EnchanterDialogResponse.Text3") + " " + item.Name;
            player.Out.SendInventoryItemsUpdate(new InventoryItem[] { item });
            player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "Enchanter.EnchanterDialogResponse.Text4",
                                                              GetName(0, false, player.Client.Account.Language, this), Money.GetString(Fee)), eChatType.CT_System, eChatLoc.CL_SystemWindow);
            player.RemoveMoney(Fee, null);
            InventoryLogging.LogInventoryAction(player, this, eInventoryActionType.Merchant, Fee);
            SayTo(player, eChatLoc.CL_SystemWindow, LanguageMgr.GetTranslation(player.Client.Account.Language, "Enchanter.EnchanterDialogResponse.Text5", item.GetName(1, false)));
            return;
        }
예제 #12
0
        /// <summary>
        /// Add a gift to the player
        /// </summary>
        /// <param name="template">the template ID of the item</param>
        /// <param name="player">the player to give it to</param>
        /// <returns>true if succesful</returns>
        public virtual bool addGift(String template, GamePlayer player)
        {
            ItemTemplate temp = GameServer.Database.FindObjectByKey <ItemTemplate>(template);

            if (temp != null)
            {
                if (!player.Inventory.AddTemplate(GameInventoryItem.Create(temp), 1, eInventorySlot.FirstBackpack, eInventorySlot.LastBackpack))
                {
                    player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "GameTrainer.AddGift.NotEnoughSpace"), eChatType.CT_System, eChatLoc.CL_SystemWindow);
                    return(false);
                }
                InventoryLogging.LogInventoryAction(this, player, eInventoryActionType.Other, temp);
            }
            return(true);
        }
예제 #13
0
        /// <summary>
        /// Is called whenever the CurrentCarrier is supposed to loose the relic.
        /// </summary>
        /// <param name="removeFromInventory">Defines wheater the Item in the Inventory should be removed.</param>
        protected virtual void PlayerLoosesRelic(bool removeFromInventory)
        {
            if (m_currentCarrier == null)
            {
                return;
            }

            GamePlayer player = m_currentCarrier;

            if (player.TempProperties.getProperty <object>(PLAYER_CARRY_RELIC_WEAK, null) == null)
            {
                log.Warn("GameRelic: " + player.Name + " has already lost" + Name);
                return;
            }

            if (removeFromInventory)
            {
                lock (player.Inventory)
                {
                    bool success = player.Inventory.RemoveItem(m_item);
                    InventoryLogging.LogInventoryAction(player, this, eInventoryActionType.Other, m_item.Template, m_item.Count);
                    log.Debug("Remove " + m_item.Name + " from " + player.Name + "'s Inventory " + (success ? "successfully." : "with errors."));
                }
            }

            // remove the handlers from the player
            SetHandlers(player, false);

            // kill the pulsingEffectTimer on the player
            StartPlayerTimer(null);

            player.TempProperties.removeProperty(PLAYER_CARRY_RELIC_WEAK);
            m_currentCarrier = null;
            player.Out.SendUpdateMaxSpeed();

            if (IsMounted == false)
            {
                // launch the reset timer if this relic is not dropped on a pad
                m_timeRelicOnGround = CurrentRegion.Time;
                m_returnRelicTimer  = new RegionTimer(this, new RegionTimerCallback(ReturnRelicTick), RelicEffectInterval);
                log.DebugFormat("{0} dropped, return timer for relic set to {1} seconds.", Name, ReturnRelicInterval / 1000);

                // update the position of the worldObject Relic
                Update();
                SaveIntoDatabase();
                AddToWorld();
            }
        }
예제 #14
0
        /// <summary>
        /// For Recieving Respec Stones.
        /// </summary>
        /// <param name="source"></param>
        /// <param name="item"></param>
        /// <returns></returns>
        public override bool ReceiveItem(GameLiving source, InventoryItem item)
        {
            if (source == null || item == null)
            {
                return(false);
            }

            GamePlayer player = source as GamePlayer;

            if (player != null)
            {
                switch (item.Id_nb)
                {
                case "respec_single":
                {
                    player.Inventory.RemoveCountFromStack(item, 1);
                    InventoryLogging.LogInventoryAction(player, this, eInventoryActionType.Merchant, item.Template);
                    player.RespecAmountSingleSkill++;
                    player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "GameTrainer.ReceiveItem.RespecSingle"), eChatType.CT_System, eChatLoc.CL_PopupWindow);
                    return(true);
                }

                case "respec_full":
                {
                    player.Inventory.RemoveCountFromStack(item, 1);
                    InventoryLogging.LogInventoryAction(player, this, eInventoryActionType.Merchant, item.Template);
                    player.RespecAmountAllSkill++;
                    player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "GameTrainer.ReceiveItem.RespecFull", item.Name), eChatType.CT_System, eChatLoc.CL_PopupWindow);
                    return(true);
                }

                case "respec_realm":
                {
                    player.Inventory.RemoveCountFromStack(item, 1);
                    InventoryLogging.LogInventoryAction(player, this, eInventoryActionType.Merchant, item.Template);
                    player.RespecAmountRealmSkill++;
                    player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "GameTrainer.ReceiveItem.RespecRealm"), eChatType.CT_System, eChatLoc.CL_PopupWindow);
                    return(true);
                }
                }
            }

            return(base.ReceiveItem(source, item));
        }
예제 #15
0
        protected void HealerDialogResponse(GamePlayer player, byte response)
        {
            if (!IsWithinRadius(player, WorldMgr.INTERACT_DISTANCE))
            {
                player.Out.SendMessage(
                    LanguageMgr.GetTranslation(player.Client.Account.Language, "Healer.HealerDialogResponse.Text1",
                                               GetName(0, false, player.Client.Account.Language, this)), eChatType.CT_System, eChatLoc.CL_SystemWindow);
                return;
            }

            if (response != 0x01) // declined
            {
                player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "Healer.HealerDialogResponse.Text2"), eChatType.CT_System, eChatLoc.CL_SystemWindow);
                return;
            }

            long cost = player.TempProperties.getProperty <long>(COST_BY_PTS);

            player.TempProperties.removeProperty(COST_BY_PTS);
            int restorePoints = (int)Math.Min(player.TotalConstitutionLostAtDeath, player.GetCurrentMoney() / cost);

            if (restorePoints < 1)
            {
                restorePoints = 1; // at least one
            }

            long totalCost = restorePoints * cost;

            if (player.RemoveMoney(totalCost))
            {
                InventoryLogging.LogInventoryAction(player, this, eInventoryActionType.Merchant, totalCost);
                player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "Healer.HealerDialogResponse.Text3", Name, Money.GetString(totalCost)), eChatType.CT_System, eChatLoc.CL_SystemWindow);
                player.TotalConstitutionLostAtDeath -= restorePoints;
                player.Out.SendCharStatsUpdate();
            }
            else
            {
                player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "Healer.HealerDialogResponse.Text4", Money.GetString(totalCost), restorePoints), eChatType.CT_System, eChatLoc.CL_SystemWindow);
            }

            return;
        }
예제 #16
0
        /// <summary>
        /// Called when a player sells something
        /// </summary>
        /// <param name="player">Player making the sale</param>
        /// <param name="item">The InventoryItem to be sold</param>
        /// <returns>true if selling is allowed, false if it should be prevented</returns>
        public virtual void OnPlayerSell(GamePlayer player, InventoryItem item)
        {
            if (item == null || player == null)
            {
                return;
            }

            if (!item.IsDropable)
            {
                player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "GameMerchant.OnPlayerSell.CantBeSold"), eChatType.CT_Merchant, eChatLoc.CL_SystemWindow);
                return;
            }

            if (!IsWithinRadius(player, GS.ServerProperties.Properties.WORLD_PICKUP_DISTANCE)) // tested
            {
                player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "GameMerchant.OnPlayerSell.TooFarAway", GetName(0, true)), eChatType.CT_Merchant, eChatLoc.CL_SystemWindow);
                return;
            }

            long itemValue = OnPlayerAppraise(player, item, true);

            if (itemValue == 0)
            {
                player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "GameMerchant.OnPlayerSell.IsntInterested", GetName(0, true), item.GetName(0, false)), eChatType.CT_Merchant, eChatLoc.CL_SystemWindow);
                return;
            }

            if (player.Inventory.RemoveItem(item))
            {
                string message = LanguageMgr.GetTranslation(player.Client.Account.Language, "GameMerchant.OnPlayerSell.GivesYou", GetName(0, true), Money.GetString(itemValue), item.GetName(0, false));
                player.AddMoney(itemValue, message, eChatType.CT_Merchant, eChatLoc.CL_SystemWindow);
                InventoryLogging.LogInventoryAction(player, this, eInventoryActionType.Merchant, item.Template, item.Count);
                InventoryLogging.LogInventoryAction(this, player, eInventoryActionType.Merchant, itemValue);
                return;
            }
            else
            {
                player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "GameMerchant.OnPlayerSell.CantBeSold"), eChatType.CT_Merchant, eChatLoc.CL_SystemWindow);
            }
        }
예제 #17
0
        protected void EmblemerDialogResponse(GamePlayer player, byte response)
        {
            WeakReference itemWeak =
                (WeakReference)player.TempProperties.getProperty <object>(
                    EMBLEMIZE_ITEM_WEAK,
                    new WeakRef(null));

            player.TempProperties.removeProperty(EMBLEMIZE_ITEM_WEAK);

            if (response != 0x01)
            {
                return; // declined
            }

            InventoryItem item = (InventoryItem)itemWeak.Target;

            if (item == null || item.SlotPosition == (int)eInventorySlot.Ground ||
                item.OwnerID == null || item.OwnerID != player.InternalID)
            {
                player.Out.SendMessage("Invalid item.", eChatType.CT_System, eChatLoc.CL_SystemWindow);
                return;
            }

            if (!player.RemoveMoney(EMBLEM_COST))
            {
                InventoryLogging.LogInventoryAction(player, this, eInventoryActionType.Merchant, EMBLEM_COST);
                player.Out.SendMessage("You don't have enough money.", eChatType.CT_System, eChatLoc.CL_SystemWindow);
                return;
            }

            item.Emblem = player.Guild.Emblem;
            player.Out.SendInventoryItemsUpdate(new InventoryItem[] { item });
            if (item.SlotPosition < (int)eInventorySlot.FirstBackpack)
            {
                player.UpdateEquipmentAppearance();
            }

            SayTo(player, eChatLoc.CL_ChatWindow, "I have put an emblem on your item.");
            return;
        }
예제 #18
0
        public override bool ReceiveItem(GameLiving source, InventoryItem item)
        {
            if (source == null || item == null)
            {
                return(false);
            }

            GamePlayer player = source as GamePlayer;

            if (player == null)
            {
                return(false);
            }

            if (item.Id_nb == "Music_Ticket")
            {
                TargetObject = player;
                CastSpell(SkillBase.GetSpellByID(GameHastener.SPEEDOFTHEREALMID), SkillBase.GetSpellLine(GlobalSpellsLines.Realm_Spells));
                player.Inventory.RemoveItem(item);
                InventoryLogging.LogInventoryAction(player, this, eInventoryActionType.Merchant, item.Template, item.Count);
            }
            return(true);
        }
예제 #19
0
        /// <summary>
        /// Called when craft time is finished
        /// </summary>
        /// <param name="timer"></param>
        /// <returns></returns>
        protected static int Proceed(RegionTimer timer)
        {
            GamePlayer    player        = timer.Properties.getProperty <GamePlayer>(AbstractCraftingSkill.PLAYER_CRAFTER, null);
            InventoryItem itemToSalvage = timer.Properties.getProperty <InventoryItem>(SALVAGED_ITEM, null);
            SalvageYield  yield         = timer.Properties.getProperty <SalvageYield>(SALVAGE_YIELD, null);
            int           materialCount = yield.Count;

            if (player == null || itemToSalvage == null || yield == null || materialCount == 0)
            {
                player.Out.SendMessage("Error retrieving salvage data for this item!", eChatType.CT_Important, eChatLoc.CL_SystemWindow);
                log.Error("Salvage: There was a problem getting back salvage info from the craft timer.");
                return(0);
            }

            ItemTemplate rawMaterial = null;

            if (string.IsNullOrEmpty(yield.MaterialId_nb) == false)
            {
                rawMaterial = GameServer.Database.FindObjectByKey <ItemTemplate>(yield.MaterialId_nb);
            }

            if (rawMaterial == null)
            {
                player.Out.SendMessage("Error finding the raw material needed to salvage this item!", eChatType.CT_Important, eChatLoc.CL_SystemWindow);
                log.Error("Salvage: Error finding raw material " + yield.MaterialId_nb);
                return(0);
            }

            player.CraftTimer.Stop();
            player.Out.SendCloseTimerWindow();

            if (!player.Inventory.RemoveItem(itemToSalvage))             // clean the free of the item to salvage
            {
                player.Out.SendMessage("Error finding the item to salvage!", eChatType.CT_Important, eChatLoc.CL_SystemWindow);
                return(0);
            }

            InventoryLogging.LogInventoryAction(player, "(salvage)", eInventoryActionType.Craft, itemToSalvage.Template, itemToSalvage.Count);

            Dictionary <int, int> changedSlots = new Dictionary <int, int>(5);           // value: < 0 = new item count; > 0 = add to old

            lock (player.Inventory)
            {
                int count = materialCount;
                foreach (InventoryItem item in player.Inventory.GetItemRange(eInventorySlot.FirstBackpack, eInventorySlot.LastBackpack))
                {
                    if (item == null)
                    {
                        continue;
                    }
                    if (item.Id_nb != rawMaterial.Id_nb)
                    {
                        continue;
                    }
                    if (item.Count >= item.MaxCount)
                    {
                        continue;
                    }

                    int countFree = item.MaxCount - item.Count;
                    if (count > countFree)
                    {
                        changedSlots.Add(item.SlotPosition, countFree);                         // existing item should be changed
                        count -= countFree;
                    }
                    else
                    {
                        changedSlots.Add(item.SlotPosition, count);                         // existing item should be changed
                        count = 0;
                        break;
                    }
                }

                if (count > 0)                // Add new object
                {
                    eInventorySlot firstEmptySlot = player.Inventory.FindFirstEmptySlot(eInventorySlot.FirstBackpack, eInventorySlot.LastBackpack);
                    changedSlots.Add((int)firstEmptySlot, -count);                     // Create the item in the free slot (always at least one)
                    count = 0;
                }
            }

            InventoryItem newItem = null;

            player.Inventory.BeginChanges();
            Dictionary <int, int> .Enumerator enumerator = changedSlots.GetEnumerator();
            while (enumerator.MoveNext())
            {
                KeyValuePair <int, int> de = enumerator.Current;
                int countToAdd             = de.Value;
                if (countToAdd > 0)                     // Add to exiting item
                {
                    newItem = player.Inventory.GetItem((eInventorySlot)de.Key);
                    player.Inventory.AddCountToStack(newItem, countToAdd);
                    InventoryLogging.LogInventoryAction("(salvage)", player, eInventoryActionType.Craft, newItem.Template, countToAdd);
                }
                else
                {
                    newItem       = GameInventoryItem.Create <ItemTemplate>(rawMaterial);
                    newItem.Count = -countToAdd;
                    player.Inventory.AddItem((eInventorySlot)de.Key, newItem);
                    InventoryLogging.LogInventoryAction("(salvage)", player, eInventoryActionType.Craft, newItem.Template, newItem.Count);
                }
            }

            player.Inventory.CommitChanges();
            player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "Salvage.Proceed.GetBackMaterial", materialCount, rawMaterial.Name, itemToSalvage.Name), eChatType.CT_Important, eChatLoc.CL_SystemWindow);

            return(0);
        }
예제 #20
0
        /// <summary>
        /// Begin salvaging a siege weapon
        /// </summary>
        /// <param name="player"></param>
        /// <param name="siegeWeapon"></param>
        /// <returns></returns>
        public static int BeginWork(GamePlayer player, GameSiegeWeapon siegeWeapon)
        {
            if (siegeWeapon == null)
            {
                return(0);
            }
            // Galenas
            siegeWeapon.ReleaseControl();
            siegeWeapon.RemoveFromWorld();
            bool          error  = false;
            DBCraftedItem recipe = GameServer.Database.SelectObject <DBCraftedItem>("Id_nb ='" + siegeWeapon.ItemId + "'");

            if (recipe == null)
            {
                player.Out.SendMessage("Error retrieving salvage data!", eChatType.CT_Important, eChatLoc.CL_SystemWindow);
                log.Error("Salvage Siege Error: DBCraftedItem is null for" + siegeWeapon.ItemId);
                return(1);
            }

            IList <DBCraftedXItem> rawMaterials = GameServer.Database.SelectObjects <DBCraftedXItem>("`CraftedItemId_nb` = '" + recipe.Id_nb + "'");

            if (rawMaterials == null || rawMaterials.Count == 0)
            {
                player.Out.SendMessage("No raw materials provided for this siege weapon!", eChatType.CT_Important, eChatLoc.CL_SystemWindow);
                log.Error("Salvage Siege Error: No Raw Materials found for " + siegeWeapon.ItemId);
                return(1);
            }

            if (player.IsCrafting)
            {
                player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "Salvage.IsAllowedToBeginWork.EndCurrentAction"), eChatType.CT_System, eChatLoc.CL_SystemWindow);
                return(0);
            }
            InventoryItem item;
            ItemTemplate  template;

            foreach (DBCraftedXItem material in rawMaterials)
            {
                template = GameServer.Database.FindObjectByKey <ItemTemplate>(material.IngredientId_nb);

                if (template == null)
                {
                    player.Out.SendMessage("Missing raw material " + material.IngredientId_nb + "!", eChatType.CT_Important, eChatLoc.CL_SystemWindow);
                    log.Error("Salvage Siege Error: Raw Material not found " + material.IngredientId_nb);
                    return(1);
                }

                item       = GameInventoryItem.Create <ItemTemplate>(template);
                item.Count = material.Count;
                if (!player.Inventory.AddItem(eInventorySlot.FirstEmptyBackpack, item))
                {
                    error = true;
                    break;
                }
                InventoryLogging.LogInventoryAction("(salvage)", player, eInventoryActionType.Craft, item.Template, item.Count);
            }

            if (error)
            {
                player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "Salvage.BeginWork.NoRoom"), eChatType.CT_System, eChatLoc.CL_SystemWindow);
            }

            return(1);
        }
예제 #21
0
        /// <summary>
        /// Called when the living is about to get an item from someone
        /// else
        /// </summary>
        /// <param name="source">Source from where to get the item</param>
        /// <param name="item">Item to get</param>
        /// <returns>true if the item was successfully received</returns>
        public override bool ReceiveItem(GameLiving source, InventoryItem item)
        {
            if (source == null || item == null)
            {
                return(false);
            }

            if (source is GamePlayer)
            {
                GamePlayer player = (GamePlayer)source;

                if (item.Item_Type == 40 && isItemInMerchantList(item))
                {
                    PathPoint path = MovementMgr.LoadPath(item.Id_nb);

                    if ((path != null) && ((Math.Abs(path.X - this.X)) < 500) && ((Math.Abs(path.Y - this.Y)) < 500))
                    {
                        player.Inventory.RemoveCountFromStack(item, 1);
                        InventoryLogging.LogInventoryAction(player, this, eInventoryActionType.Merchant, item.Template);

                        GameTaxi mount;

                        // item.Color of ticket is used for npctemplate. defaults to standard horse if item.color is 0
                        if (item.Color > 0)
                        {
                            mount = new GameTaxi(NpcTemplateMgr.GetTemplate(item.Color));
                        }
                        else
                        {
                            mount = new GameTaxi();

                            foreach (GameNPC npc in GetNPCsInRadius(400))
                            {
                                if (npc.Name == LanguageMgr.GetTranslation(ServerProperties.Properties.DB_LANGUAGE, "GameStableMaster.ReceiveItem.HorseName"))
                                {
                                    mount.Model = npc.Model;
                                    mount.Name  = npc.Name;
                                    break;
                                }
                            }
                        }

                        switch ((eRace)player.Race)
                        {
                        case eRace.Lurikeen:
                            mount.Size = 31;
                            break;

                        case eRace.Kobold:
                            mount.Size = 38;
                            break;

                        case eRace.Dwarf:
                            mount.Size = 42;
                            break;

                        case eRace.Inconnu:
                            mount.Size = 45;
                            break;

                        case eRace.Frostalf:
                        case eRace.Shar:
                            mount.Size = 48;
                            break;

                        case eRace.Briton:
                        case eRace.Saracen:
                        case eRace.Celt:
                            mount.Size = 50;
                            break;

                        case eRace.Valkyn:
                            mount.Size = 52;
                            break;

                        case eRace.Avalonian:
                        case eRace.Highlander:
                        case eRace.Norseman:
                        case eRace.Elf:
                        case eRace.Sylvan:
                            mount.Size = 55;
                            break;

                        case eRace.Firbolg:
                            mount.Size = 62;
                            break;

                        case eRace.HalfOgre:
                        case eRace.AlbionMinotaur:
                        case eRace.MidgardMinotaur:
                        case eRace.HiberniaMinotaur:
                            mount.Size = 65;
                            break;

                        case eRace.Troll:
                            mount.Size = 67;
                            break;

                        default:
                            mount.Size = 55;
                            break;
                        }

                        mount.Realm         = source.Realm;
                        mount.X             = path.X;
                        mount.Y             = path.Y;
                        mount.Z             = path.Z;
                        mount.CurrentRegion = CurrentRegion;
                        mount.Heading       = path.GetHeading(path.Next);
                        mount.AddToWorld();
                        mount.CurrentWayPoint = path;
                        GameEventMgr.AddHandler(mount, GameNPCEvent.PathMoveEnds, new DOLEventHandler(OnHorseAtPathEnd));
                        new MountHorseAction(player, mount).Start(400);
                        new HorseRideAction(mount).Start(4000);
                        return(true);
                    }
                }
                else
                {
                    player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "GameStableMaster.Receive.UnknownWay"), eChatType.CT_System, eChatLoc.CL_SystemWindow);
                }
            }
            return(false);
        }
예제 #22
0
        protected virtual void BuyItem(GamePlayer player, bool usingMarketExplorer = false)
        {
            eInventorySlot fromClientSlot = player.TempProperties.getProperty <eInventorySlot>(CONSIGNMENT_BUY_ITEM, eInventorySlot.Invalid);

            player.TempProperties.removeProperty(CONSIGNMENT_BUY_ITEM);

            InventoryItem item = null;

            lock (LockObject())
            {
                if (fromClientSlot != eInventorySlot.Invalid)
                {
                    IDictionary <int, InventoryItem> clientInventory = GetClientInventory(player);

                    if (clientInventory.ContainsKey((int)fromClientSlot))
                    {
                        item = clientInventory[(int)fromClientSlot];
                    }
                }

                if (item == null)
                {
                    ChatUtil.SendErrorMessage(player, "I can't find the item you want to purchase!");
                    log.ErrorFormat("{0}:{1} tried to purchase an item from slot {2} for consignment merchant on lot {3} and the item does not exist.", player.Name, player.Client.Account, (int)fromClientSlot, HouseNumber);

                    return;
                }

                int sellPrice     = item.SellPrice;
                int purchasePrice = sellPrice;

                if (usingMarketExplorer && ServerProperties.Properties.MARKET_FEE_PERCENT > 0)
                {
                    purchasePrice += ((purchasePrice * ServerProperties.Properties.MARKET_FEE_PERCENT) / 100);
                }

                lock (player.Inventory)
                {
                    if (purchasePrice <= 0)
                    {
                        ChatUtil.SendErrorMessage(player, "This item can't be purchased!");
                        log.ErrorFormat("{0}:{1} tried to purchase {2} for consignment merchant on lot {3} and purchasePrice was {4}.", player.Name, player.Client.Account, item.Name, HouseNumber, purchasePrice);
                        return;
                    }

                    if (ServerProperties.Properties.CONSIGNMENT_USE_BP)
                    {
                        if (player.BountyPoints < purchasePrice)
                        {
                            ChatUtil.SendSystemMessage(player, "GameMerchant.OnPlayerBuy.YouNeedBP", purchasePrice);
                            return;
                        }
                    }
                    else
                    {
                        if (player.GetCurrentMoney() < purchasePrice)
                        {
                            ChatUtil.SendSystemMessage(player, "GameMerchant.OnPlayerBuy.YouNeed", Money.GetString(purchasePrice));
                            return;
                        }
                    }

                    eInventorySlot toClientSlot = player.Inventory.FindFirstEmptySlot(eInventorySlot.FirstBackpack, eInventorySlot.LastBackpack);

                    if (toClientSlot == eInventorySlot.Invalid)
                    {
                        ChatUtil.SendSystemMessage(player, "GameMerchant.OnPlayerBuy.NotInventorySpace", null);
                        return;
                    }

                    if (ServerProperties.Properties.CONSIGNMENT_USE_BP)
                    {
                        ChatUtil.SendMerchantMessage(player, "GameMerchant.OnPlayerBuy.BoughtBP", item.GetName(1, false), purchasePrice);
                        player.BountyPoints -= purchasePrice;
                        player.Out.SendUpdatePoints();
                    }
                    else
                    {
                        if (player.RemoveMoney(purchasePrice))
                        {
                            InventoryLogging.LogInventoryAction(player, this, eInventoryActionType.Merchant, purchasePrice);
                            ChatUtil.SendMerchantMessage(player, "GameMerchant.OnPlayerBuy.Bought", item.GetName(1, false), Money.GetString(purchasePrice));
                        }
                        else
                        {
                            return;
                        }
                    }

                    TotalMoney += sellPrice;

                    if (ServerProperties.Properties.MARKET_ENABLE_LOG)
                    {
                        log.DebugFormat("CM: {0}:{1} purchased '{2}' for {3} from consignment merchant on lot {4}.", player.Name, player.Client.Account.Name, item.Name, purchasePrice, HouseNumber);
                    }

                    NotifyObservers(player, this.MoveItemFromObject(player, fromClientSlot, toClientSlot));
                }
            }
        }
        public override LootList GenerateLoot(GameNPC mob, GameObject killer)
        {
            LootList       loot     = base.GenerateLoot(mob, killer);
            List <LootOTD> lootOTDs = null;

            try
            {
                if (m_mobOTDList.ContainsKey(mob.Name.ToLower()))
                {
                    lootOTDs = m_mobOTDList[mob.Name.ToLower()];
                }

                if (lootOTDs != null)
                {
                    foreach (GameObject gainer in mob.XPGainers.Keys)
                    {
                        GamePlayer player = null;

                        if (gainer is GamePlayer)
                        {
                            player = gainer as GamePlayer;
                        }
                        else if (gainer is GameNPC)
                        {
                            IControlledBrain brain = ((GameNPC)gainer).Brain as IControlledBrain;
                            if (brain != null)
                            {
                                player = brain.GetPlayerOwner();
                            }
                        }

                        if (player != null)
                        {
                            foreach (LootOTD drop in lootOTDs)
                            {
                                if (drop.MinLevel <= player.Level)
                                {
                                    CharacterXOneTimeDrop hasDrop = GameServer.Database.SelectObject <CharacterXOneTimeDrop>("CharacterID = '" + GameServer.Database.Escape(player.QuestPlayerID) + "' AND ItemTemplateID = '" + GameServer.Database.Escape(drop.ItemTemplateID) + "'");

                                    if (hasDrop == null)
                                    {
                                        ItemTemplate item = GameServer.Database.FindObjectByKey <ItemTemplate>(drop.ItemTemplateID);

                                        if (item != null)
                                        {
                                            if (player.Inventory.AddItem(eInventorySlot.FirstEmptyBackpack, GameInventoryItem.Create <ItemTemplate>(item)))
                                            {
                                                CharacterXOneTimeDrop charXDrop = new CharacterXOneTimeDrop();
                                                charXDrop.CharacterID    = player.QuestPlayerID;
                                                charXDrop.ItemTemplateID = drop.ItemTemplateID;
                                                GameServer.Database.AddObject(charXDrop);

                                                player.Out.SendMessage(string.Format("You receive {0} from {1}!", item.GetName(1, false), mob.GetName(1, false)), eChatType.CT_Loot, eChatLoc.CL_SystemWindow);
                                                InventoryLogging.LogInventoryAction(mob, player, eInventoryActionType.Loot, item);
                                            }
                                            else
                                            {
                                                // do not drop, player will have to try again
                                                player.Out.SendMessage("Your inventory is full and a one time drop cannot be added!", eChatType.CT_Important, eChatLoc.CL_SystemWindow);
                                                log.DebugFormat("OTD Failed, Inventory full: {0} from mob {1} for player {2}.", drop.ItemTemplateID, drop.MobName, player.Name);
                                                break;
                                            }
                                        }
                                        else
                                        {
                                            log.ErrorFormat("Error trying to drop ItemTemplate {0} from {1}.  Item not found.", drop.ItemTemplateID, drop.MobName);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error("LootGeneratorOneTimeDrop exception for mob " + mob.Name + ":", ex);
            }

            return(loot);
        }
예제 #24
0
        /// <summary>
        /// Apply all magical dust
        /// </summary>
        /// <param name="player"></param>
        /// <param name="item"></param>
        /// <returns></returns>
        private void ApplyMagicalDusts(GamePlayer player, InventoryItem item)
        {
            int spellCrafterLevel = player.GetCraftingSkillValue(eCraftingSkill.SpellCrafting);

            int bonusCap;

            if (spellCrafterLevel < 300 || item.Level < 15)
            {
                bonusCap = 0;
            }
            else if (spellCrafterLevel < 400 || item.Level < 20)
            {
                bonusCap = 5;
            }
            else if (spellCrafterLevel < 500 || item.Level < 25)
            {
                bonusCap = 10;
            }
            else if (spellCrafterLevel < 600 || item.Level < 30)
            {
                bonusCap = 15;
            }
            else if (spellCrafterLevel < 700 || item.Level < 35)
            {
                bonusCap = 20;
            }
            else if (spellCrafterLevel < 800 || item.Level < 40)
            {
                bonusCap = 25;
            }
            else if (spellCrafterLevel < 900 || item.Level < 45)
            {
                bonusCap = 30;
            }
            else
            {
                bonusCap = 35;
            }

            player.Inventory.BeginChanges();

            int bonusMod = item.Bonus;

            lock (player.TradeWindow.Sync)
            {
                foreach (InventoryItem gemme in player.TradeWindow.TradeItems)
                {
                    switch (gemme.Name)
                    {
                    case "coppery imbued dust": bonusMod += 2; break;

                    case "coppery enchanted dust": bonusMod += 4; break;

                    case "coppery glowing dust": bonusMod += 6; break;

                    case "coppery ensorcelled dust": bonusMod += 8; break;

                    case "silvery imbued dust": bonusMod += 10; break;

                    case "silvery enchanted dust": bonusMod += 12; break;

                    case "silvery glowing dust": bonusMod += 14; break;

                    case "silvery ensorcelled dust": bonusMod += 16; break;

                    case "golden imbued dust": bonusMod += 18; break;

                    case "golden enchanted dust": bonusMod += 20; break;

                    case "golden glowing dust": bonusMod += 22; break;

                    case "golden ensorcelled dust": bonusMod += 24; break;

                    case "mithril imbued dust": bonusMod += 26; break;

                    case "mithril enchanted dust": bonusMod += 28; break;

                    case "mithril glowing dust": bonusMod += 30; break;

                    case "mithril ensorcelled dust": bonusMod += 32; break;

                    case "platinum imbued dust": bonusMod += 34; break;

                    case "platinum enchanted dust": bonusMod += 36; break;

                    case "platinum glowing dust": bonusMod += 38; break;

                    case "platinum ensorcelled dust": bonusMod += 40; break;
                    }
                    player.Inventory.RemoveCountFromStack(gemme, 1);
                    InventoryLogging.LogInventoryAction(player, "(craft)", eInventoryActionType.Craft, gemme.Template);
                }
            }

            item.Bonus = Math.Min(bonusMod, bonusCap);

            player.Inventory.CommitChanges();
        }
예제 #25
0
        /// <summary>
        /// Called when a player buys an item
        /// </summary>
        /// <param name="player">The player making the purchase</param>
        /// <param name="item_slot">slot of the item to be bought</param>
        /// <param name="number">Number to be bought</param>
        public override void OnPlayerBuy(GamePlayer player, int item_slot, int number)
        {
            //Get the template
            int pagenumber = item_slot / MerchantTradeItems.MAX_ITEM_IN_TRADEWINDOWS;
            int slotnumber = item_slot % MerchantTradeItems.MAX_ITEM_IN_TRADEWINDOWS;

            ItemTemplate template = this.TradeItems.GetItem(pagenumber, (eMerchantWindowSlot)slotnumber);

            if (template == null)
            {
                return;
            }

            //Calculate the amout of items
            int amountToBuy = number;

            if (template.PackSize > 0)
            {
                amountToBuy *= template.PackSize;
            }

            if (amountToBuy <= 0)
            {
                return;
            }

            //Calculate the value of items
            long totalValue = number * template.Price;

            GameInventoryItem item = GameInventoryItem.Create(template);

            lock (player.Inventory)
            {
                if (player.GetCurrentMoney() < totalValue)
                {
                    player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "GameMerchant.OnPlayerBuy.YouNeed", Money.GetString(totalValue)), eChatType.CT_System, eChatLoc.CL_SystemWindow);
                    return;
                }

                if (!player.Inventory.AddTemplate(item, amountToBuy, eInventorySlot.FirstBackpack, eInventorySlot.LastBackpack))
                {
                    player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "GameMerchant.OnPlayerBuy.NotInventorySpace"), eChatType.CT_System, eChatLoc.CL_SystemWindow);
                    return;
                }
                InventoryLogging.LogInventoryAction(this, player, eInventoryActionType.Merchant, template, amountToBuy);
                //Generate the buy message
                string message;
                if (amountToBuy > 1)
                {
                    message = LanguageMgr.GetTranslation(player.Client.Account.Language, "GameMerchant.OnPlayerBuy.BoughtPieces", amountToBuy, template.GetName(1, false), Money.GetString(totalValue));
                }
                else
                {
                    message = LanguageMgr.GetTranslation(player.Client.Account.Language, "GameMerchant.OnPlayerBuy.Bought", template.GetName(1, false), Money.GetString(totalValue));
                }

                // Check if player has enough money and subtract the money
                if (!player.RemoveMoney(totalValue, message, eChatType.CT_Merchant, eChatLoc.CL_SystemWindow))
                {
                    throw new Exception("Money amount changed while adding items.");
                }
                InventoryLogging.LogInventoryAction(player, this, eInventoryActionType.Merchant, totalValue);
            }

            if (item.Name.ToUpper().Contains("TICKET TO") || item.Description.ToUpper() == "TICKET")
            {
                // Give the ticket to the merchant
                InventoryItem ticket = player.Inventory.GetFirstItemByName(item.Name, eInventorySlot.FirstBackpack, eInventorySlot.LastBackpack) as InventoryItem;
                if (ticket != null)
                {
                    ReceiveItem(player, ticket);
                }
            }
        }
예제 #26
0
        public override void OnPlayerBuy(GamePlayer player, int item_slot, int number)
        {
            if (m_moneyItem == null || m_moneyItem.Item == null)
            {
                return;
            }
            //Get the template
            int pagenumber = item_slot / MerchantTradeItems.MAX_ITEM_IN_TRADEWINDOWS;
            int slotnumber = item_slot % MerchantTradeItems.MAX_ITEM_IN_TRADEWINDOWS;

            ItemTemplate template = this.TradeItems.GetItem(pagenumber, (eMerchantWindowSlot)slotnumber);

            if (template == null)
            {
                return;
            }

            //Calculate the amout of items
            int amountToBuy = number;

            if (template.PackSize > 0)
            {
                amountToBuy *= template.PackSize;
            }

            if (amountToBuy <= 0)
            {
                return;
            }

            //Calculate the value of items
            long totalValue = number * template.Price;

            lock (player.Inventory)
            {
                if (player.Inventory.CountItemTemplate(m_moneyItem.Item.Id_nb, eInventorySlot.FirstBackpack, eInventorySlot.LastBackpack) < totalValue)
                {
                    player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "GameMerchant.OnPlayerBuy.YouNeed2", totalValue, MoneyItemName), eChatType.CT_System, eChatLoc.CL_SystemWindow);
                    return;
                }
                if (!player.Inventory.AddTemplate(GameInventoryItem.Create(template), amountToBuy, eInventorySlot.FirstBackpack, eInventorySlot.LastBackpack))
                {
                    player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "GameMerchant.OnPlayerBuy.NotInventorySpace"), eChatType.CT_System, eChatLoc.CL_SystemWindow);

                    return;
                }
                InventoryLogging.LogInventoryAction(this, player, eInventoryActionType.Merchant, template, amountToBuy);
                //Generate the buy message
                string message;
                if (amountToBuy > 1)
                {
                    message = LanguageMgr.GetTranslation(player.Client.Account.Language, "GameMerchant.OnPlayerBuy.BoughtPieces2", amountToBuy, template.GetName(1, false), totalValue, MoneyItemName);
                }
                else
                {
                    message = LanguageMgr.GetTranslation(player.Client.Account.Language, "GameMerchant.OnPlayerBuy.Bought2", template.GetName(1, false), totalValue, MoneyItemName);
                }

                var items   = player.Inventory.GetItemRange(eInventorySlot.FirstBackpack, eInventorySlot.LastBackpack);
                int removed = 0;

                foreach (InventoryItem item in items)
                {
                    if (item.Id_nb != m_moneyItem.Item.Id_nb)
                    {
                        continue;
                    }
                    int remFromStack = Math.Min(item.Count, (int)(totalValue - removed));
                    player.Inventory.RemoveCountFromStack(item, remFromStack);
                    InventoryLogging.LogInventoryAction(player, this, eInventoryActionType.Merchant, item.Template, remFromStack);
                    removed += remFromStack;
                    if (removed == totalValue)
                    {
                        break;
                    }
                }

                player.Out.SendInventoryItemsUpdate(items);
                player.Out.SendMessage(message, eChatType.CT_Merchant, eChatLoc.CL_SystemWindow);
            }
        }
예제 #27
0
        /// <summary>
        /// Apply all spellcraft gems bonus
        /// </summary>
        /// <param name="player"></param>
        /// <param name="item"></param>
        /// <returns></returns>
        private void ApplySpellcraftGems(GamePlayer player, InventoryItem item)
        {
            int maxBonusLevel = GetItemMaxImbuePoints(item);
            int bonusLevel    = GetTotalImbuePoints(player, item);

            int sucessChances = 100;

            if (bonusLevel > maxBonusLevel)
            {
                sucessChances = CalculateChanceToOverchargeItem(player, item, maxBonusLevel, bonusLevel);
            }
            int destroyChance = 100 - CalculateChanceToPreserveItem(player, item, maxBonusLevel, bonusLevel);


            GamePlayer tradePartner = player.TradeWindow.Partner;

            if (Util.Chance(sucessChances))
            {
                lock (player.TradeWindow.Sync)
                {
                    player.Inventory.BeginChanges();
                    foreach (InventoryItem gem in (ArrayList)player.TradeWindow.TradeItems.Clone())
                    {
                        if (item.Bonus1Type == 0)
                        {
                            item.Bonus1Type = gem.Bonus1Type;
                            item.Bonus1     = gem.Bonus1;
                        }
                        else if (item.Bonus2Type == 0)
                        {
                            item.Bonus2Type = gem.Bonus1Type;
                            item.Bonus2     = gem.Bonus1;
                        }
                        else if (item.Bonus3Type == 0)
                        {
                            item.Bonus3Type = gem.Bonus1Type;
                            item.Bonus3     = gem.Bonus1;
                        }
                        else if (item.Bonus4Type == 0)
                        {
                            item.Bonus4Type = gem.Bonus1Type;
                            item.Bonus4     = gem.Bonus1;
                        }
                        player.Inventory.RemoveCountFromStack(gem, 1);
                        InventoryLogging.LogInventoryAction(player, "(craft)", eInventoryActionType.Craft, gem.Template);
                    }
                    player.Inventory.CommitChanges();
                }

                if (tradePartner != null)
                {
                    tradePartner.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "SpellCrafting.ApplySpellcraftGems.ImbuedItem", player.Name), eChatType.CT_Important, eChatLoc.CL_SystemWindow);
                }
                player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "SpellCrafting.ApplySpellcraftGems.ImbuedItem", player.Name), eChatType.CT_Important, eChatLoc.CL_SystemWindow);
            }
            else if (Util.Chance(destroyChance))
            {
                player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "SpellCrafting.ApplySpellcraftGems.PowerExplodes"), eChatType.CT_Important, eChatLoc.CL_SystemWindow);

                lock (player.TradeWindow.Sync)
                {
                    player.Inventory.BeginChanges();
                    // Luhz Crafting Update:
                    // The base item is no longer lost when spellcrafting explodes - only gems are destroyed.
                    foreach (InventoryItem gem in (ArrayList)player.TradeWindow.TradeItems.Clone())
                    {
                        if (gem.Object_Type == (int)eObjectType.SpellcraftGem)
                        {
                            player.Inventory.RemoveCountFromStack(gem, 1);
                            InventoryLogging.LogInventoryAction(player, "(craft)", eInventoryActionType.Craft, gem.Template);
                        }
                    }
                    player.Inventory.CommitChanges();
                }

                player.Emote(eEmote.SpellGoBoom);
                player.Health = 0;
                player.Die(player);                 // On official you take damages
                player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "SpellCrafting.ApplySpellcraftGems.Failed"), eChatType.CT_Important, eChatLoc.CL_SystemWindow);

                if (tradePartner != null)
                {
                    if (Util.Chance(40))
                    {
                        tradePartner.Emote(eEmote.SpellGoBoom);
                        tradePartner.Health = 0;
                        tradePartner.Die(player);
                    }
                    tradePartner.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "SpellCrafting.ApplySpellcraftGems.Failed"), eChatType.CT_Important, eChatLoc.CL_SystemWindow);
                }
            }
            else
            {
                player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "SpellCrafting.ApplySpellcraftGems.Failed"), eChatType.CT_Important, eChatLoc.CL_SystemWindow);
                if (tradePartner != null)
                {
                    tradePartner.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "SpellCrafting.ApplySpellcraftGems.Failed"), eChatType.CT_Important, eChatLoc.CL_SystemWindow);
                }
            }
        }
예제 #28
0
        /// <summary>
        /// Called each time a player push the accept button to accept the trade
        /// </summary>
        public bool AcceptTrade()
        {
            lock (Sync)
            {
                m_tradeAccept = true;
                GamePlayer partner = m_partnerWindow.Owner;

                partner.Out.SendMessage(m_owner.Name + " has accepted the trade.", eChatType.CT_System, eChatLoc.CL_SystemWindow);

                // Check if the tradepartner has also agreed to the trade
                if (!m_partnerWindow.m_tradeAccept)
                {
                    return(false);
                }

                bool logTrade = ServerProperties.Properties.LOG_TRADES;
                if (m_owner.Client.Account.PrivLevel > 1 || partner.Client.Account.PrivLevel > 1)
                {
                    logTrade = true;
                }

                //Test if we and our partner have enough money
                bool enoughMoney        = m_owner.RemoveMoney(TradeMoney);
                bool partnerEnoughMoney = partner.RemoveMoney(m_partnerWindow.TradeMoney);

                //Check the preconditions
                if (!enoughMoney || !partnerEnoughMoney)
                {
                    if (!enoughMoney)
                    {
                        //Reset the money if we don't have enough
                        TradeMoney = 0;
                        if (partnerEnoughMoney)
                        {
                            partner.AddMoney(m_partnerWindow.TradeMoney);
                            InventoryLogging.LogInventoryAction(partner, m_owner, eInventoryActionType.Trade, m_partnerWindow.TradeMoney);
                        }

                        m_owner.Out.SendMessage("You don't have enough money.", eChatType.CT_Merchant, eChatLoc.CL_SystemWindow);
                        partner.Out.SendMessage(m_owner.Name + " doesn't have enough money.", eChatType.CT_Merchant, eChatLoc.CL_SystemWindow);
                    }
                    if (!partnerEnoughMoney)
                    {
                        //Reset the money if our partner doesn't have enough
                        m_partnerWindow.TradeMoney = 0;
                        if (enoughMoney)
                        {
                            m_owner.AddMoney(TradeMoney);
                            InventoryLogging.LogInventoryAction(m_owner, partner, eInventoryActionType.Trade, TradeMoney);
                        }

                        partner.Out.SendMessage("You don't have enough money.", eChatType.CT_Merchant, eChatLoc.CL_SystemWindow);
                        m_owner.Out.SendMessage(partner.Name + " doesn't have enough money.", eChatType.CT_Merchant, eChatLoc.CL_SystemWindow);
                    }

                    //Update our tradewindow and return
                    TradeUpdate();
                    return(false);
                }

                if (m_combine == true)
                {
                    GamePlayer crafter = (m_recipiant == true ? m_owner : partner);
                    // --------------------------------------------------------------
                    // Luhz Crafting Update:
                    // Players may now have any, and all, "primary" crafting skills.
                    // AbstractCraftingSkill skill = CraftingMgr.getSkillbyEnum(crafter.CraftingPrimarySkill);
                    AbstractCraftingSkill skill = null;
                    lock (crafter.TradeWindow.Sync)
                    {
                        foreach (InventoryItem i in (ArrayList)crafter.TradeWindow.TradeItems.Clone())
                        {
                            if (i.Object_Type == (int)eObjectType.AlchemyTincture)
                            {
                                if (m_owner.GetCraftingSkillValue(eCraftingSkill.Alchemy) > 0)
                                {
                                    skill = CraftingMgr.getSkillbyEnum(eCraftingSkill.Alchemy);
                                    break;
                                }
                            }
                            else if (i.Object_Type == (int)eObjectType.SpellcraftGem)
                            {
                                if (crafter.GetCraftingSkillValue(eCraftingSkill.SpellCrafting) > 0)
                                {
                                    skill = CraftingMgr.getSkillbyEnum(eCraftingSkill.SpellCrafting);
                                    break;
                                }
                            }
                        }
                    }
                    // --------------------------------------------------------------
                    if (skill != null && skill is AdvancedCraftingSkill)
                    {
                        ((AdvancedCraftingSkill)skill).CombineItems(crafter);
                    }
                }
                else if (m_repair == true)
                {
                    GamePlayer    crafter      = (m_recipiant == true ? m_owner : partner);
                    InventoryItem itemToRepair = (InventoryItem)(m_recipiant == true ? m_partnerWindow.TradeItems[0] : TradeItems[0]);
                    if (itemToRepair != null)
                    {
                        crafter.RepairItem(itemToRepair);
                    }
                }
                else
                {
                    //Calculate the count of items
                    int myTradeItemsCount      = m_tradeItems.Count;
                    int partnerTradeItemsCount = m_partnerWindow.TradeItems.Count;

                    //Test if we and our partner have enough space in inventory
                    int  mySpaceNeeded      = Math.Max(0, partnerTradeItemsCount - myTradeItemsCount);
                    int  partnerSpaceNeeded = Math.Max(0, myTradeItemsCount - partnerTradeItemsCount);
                    bool enoughSpace        = m_owner.Inventory.IsSlotsFree(mySpaceNeeded, eInventorySlot.FirstBackpack, eInventorySlot.LastBackpack);
                    bool partnerEnoughSpace = partner.Inventory.IsSlotsFree(partnerSpaceNeeded, eInventorySlot.FirstBackpack, eInventorySlot.LastBackpack);

                    //Check the preconditions
                    if (!enoughSpace || !partnerEnoughSpace)
                    {
                        if (!enoughSpace)
                        {
                            m_owner.Out.SendMessage("You don't have enough space in your inventory.", eChatType.CT_Merchant, eChatLoc.CL_SystemWindow);
                            partner.Out.SendMessage(m_owner.Name + " doesn't have enough space in his inventory.", eChatType.CT_Merchant, eChatLoc.CL_SystemWindow);
                        }
                        if (!partnerEnoughSpace)
                        {
                            partner.Out.SendMessage("You don't have enough space in your inventory.", eChatType.CT_Merchant, eChatLoc.CL_SystemWindow);
                            m_owner.Out.SendMessage(partner.Name + " doesn't have enough space in his inventory.", eChatType.CT_Merchant, eChatLoc.CL_SystemWindow);
                        }

                        //Update our tradewindow and return
                        TradeUpdate();

                        //This was already removed above, needs to be returned to the players on trade failure.
                        m_owner.AddMoney(TradeMoney);
                        partner.AddMoney(m_partnerWindow.TradeMoney);

                        return(false);
                    }

                    //Now transfer everything
                    m_owner.Inventory.BeginChanges();
                    partner.Inventory.BeginChanges();
                    m_changesCount++;
                    m_partnerWindow.m_changesCount++;

                    // must be cloned because Inventory.RemoveItem removes it from trade window
                    ArrayList ownerTradeItems   = (ArrayList)TradeItems.Clone();
                    ArrayList partnerTradeItems = (ArrayList)m_partnerWindow.TradeItems.Clone();

                    // remove all items first to make sure there is enough space
                    // if inventory is full but removed items count >= received count
                    foreach (InventoryItem item in ownerTradeItems)
                    {
                        lock (m_owner.Inventory)
                        {
                            if (!m_owner.Inventory.RemoveTradeItem(item))
                            {
                                if (logTrade)
                                {
                                    GameServer.Instance.LogGMAction("   NOTItem: " + m_owner.Name + "(" + m_owner.Client.Account.Name + ") -> " + partner.Name + "(" + partner.Client.Account.Name + ") : " + item.Name + "(" + item.Id_nb + ")");
                                }

                                //BOT.Ban(m_owner, "Trade Hack");
                                //BOT.Ban(partner, "Trade Hack");

                                return(false);
                            }
                        }
                    }
                    foreach (InventoryItem item in partnerTradeItems)
                    {
                        lock (partner.Inventory)
                        {
                            if (!partner.Inventory.RemoveTradeItem(item))
                            {
                                if (logTrade)
                                {
                                    GameServer.Instance.LogGMAction("   NOTItem: " + m_owner.Name + "(" + m_owner.Client.Account.Name + ") -> " + partner.Name + "(" + partner.Client.Account.Name + ") : " + item.Name + "(" + item.Id_nb + ")");
                                }

                                //BOT.Ban(m_owner, "Trade Hack");
                                //BOT.Ban(partner, "Trade Hack");

                                return(false);
                            }
                        }
                    }

                    foreach (InventoryItem item in ownerTradeItems)
                    {
                        if (m_owner.Guild != partner.Guild)
                        {
                            item.Emblem = 0;
                        }

                        bool tradeSuccess = false;

                        if (item.IsDeleted)
                        {
                            tradeSuccess = partner.Inventory.AddItem(eInventorySlot.FirstEmptyBackpack, item);
                        }
                        else
                        {
                            tradeSuccess = partner.Inventory.AddTradeItem(eInventorySlot.FirstEmptyBackpack, item);
                        }

                        if (!tradeSuccess)
                        {
                            log.Error("Trade item was not added to Partner first free slot.  Owner = " + m_owner.Name + ", Partner = " + partner.Name + "; Item = " + item.Id_nb);
                        }
                        else
                        {
                            InventoryLogging.LogInventoryAction(m_owner, partner, eInventoryActionType.Trade, item.Template, item.Count);
                            if (logTrade)
                            {
                                GameServer.Instance.LogGMAction("   Item: " + m_owner.Name + "(" + m_owner.Client.Account.Name + ") -> " + partner.Name + "(" + partner.Client.Account.Name + ") : " + item.Name + "(" + item.Id_nb + ")");
                            }
                        }
                    }

                    foreach (InventoryItem item in partnerTradeItems)
                    {
                        if (m_owner.Guild != partner.Guild)
                        {
                            item.Emblem = 0;
                        }

                        bool tradeSuccess = false;

                        if (item.IsDeleted)
                        {
                            tradeSuccess = m_owner.Inventory.AddItem(eInventorySlot.FirstEmptyBackpack, item);
                        }
                        else
                        {
                            tradeSuccess = m_owner.Inventory.AddTradeItem(eInventorySlot.FirstEmptyBackpack, item);
                        }

                        if (!tradeSuccess)
                        {
                            log.Error("Trade item was not added to Owner first free slot.  Owner = " + m_owner.Name + ", Partner = " + partner.Name + "; Item = " + item.Id_nb);
                        }
                        else
                        {
                            InventoryLogging.LogInventoryAction(partner, m_owner, eInventoryActionType.Trade, item.Template, item.Count);
                            if (logTrade)
                            {
                                GameServer.Instance.LogGMAction("   Item: " + partner.Name + "(" + partner.Client.Account.Name + ") -> " + m_owner.Name + "(" + m_owner.Client.Account.Name + ") : " + item.Name + "(" + item.Id_nb + ")");
                            }
                        }
                    }

                    m_owner.Inventory.CommitChanges();
                    partner.Inventory.CommitChanges();
                    m_changesCount--;
                    m_partnerWindow.m_changesCount--;

                    m_owner.Out.SendMessage("Trade Completed. " + myTradeItemsCount + " items for " + partnerTradeItemsCount + " items.", eChatType.CT_System, eChatLoc.CL_SystemWindow);
                    partner.Out.SendMessage("Trade Completed. " + partnerTradeItemsCount + " items for " + myTradeItemsCount + " items.", eChatType.CT_System, eChatLoc.CL_SystemWindow);

                    m_owner.Inventory.SaveIntoDatabase(m_owner.InternalID);
                    partner.Inventory.SaveIntoDatabase(partner.InternalID);
                }

                if (logTrade)
                {
                    if (m_partnerWindow.TradeMoney > 0)
                    {
                        GameServer.Instance.LogGMAction("  Money: " + partner.Name + "(" + partner.Client.Account.Name + ") -> " + m_owner.Name + "(" + m_owner.Client.Account.Name + ") : " + m_partnerWindow.TradeMoney + "coppers");
                    }
                    if (TradeMoney > 0)
                    {
                        GameServer.Instance.LogGMAction("  Money: " + m_owner.Name + "(" + m_owner.Client.Account.Name + ") -> " + partner.Name + "(" + partner.Client.Account.Name + ") : " + TradeMoney + "coppers");
                    }
                }

                if (TradeMoney > 0 || m_partnerWindow.TradeMoney > 0)
                {
                    //Now add the money
                    m_owner.AddMoney(m_partnerWindow.TradeMoney, "You get {0}.");
                    partner.AddMoney(TradeMoney, "You get {0}.");
                    InventoryLogging.LogInventoryAction(m_owner, partner, eInventoryActionType.Trade, TradeMoney);
                    InventoryLogging.LogInventoryAction(partner, m_owner, eInventoryActionType.Trade, m_partnerWindow.TradeMoney);
                    m_owner.SaveIntoDatabase();
                    partner.SaveIntoDatabase();
                }

                CloseTrade();                // Close the Trade Window

                return(true);
            }
        }
예제 #29
0
        protected void BlacksmithDialogResponse(GamePlayer player, byte response)
        {
            WeakReference itemWeak =
                (WeakReference)player.TempProperties.getProperty <object>(
                    REPAIR_ITEM_WEAK,
                    new WeakRef(null));

            player.TempProperties.removeProperty(REPAIR_ITEM_WEAK);
            InventoryItem item = (InventoryItem)itemWeak.Target;

            if (response != 0x01)
            {
                player.Out.SendMessage(
                    LanguageMgr.GetTranslation(
                        player.Client.Account.Language,
                        "Scripts.Blacksmith.AbortRepair", item.Name), eChatType.CT_System,
                    eChatLoc.CL_SystemWindow);

                return;
            }

            if (item == null || item.SlotPosition == (int)eInventorySlot.Ground ||
                item.OwnerID == null || item.OwnerID != player.InternalID)
            {
                player.Out.SendMessage(
                    LanguageMgr.GetTranslation(
                        player.Client.Account.Language,
                        "Scripts.Blacksmith.InvalidItem"), eChatType.CT_System,
                    eChatLoc.CL_SystemWindow);

                return;
            }

            int ToRecoverCond = item.MaxCondition - item.Condition;

            if (!player.RemoveMoney(item.RepairCost))
            {
                InventoryLogging.LogInventoryAction(player, this, eInventoryActionType.Merchant, item.RepairCost);
                player.Out.SendMessage(
                    LanguageMgr.GetTranslation(
                        player.Client.Account.Language,
                        "Scripts.Blacksmith.NotEnoughMoney"), eChatType.CT_System,
                    eChatLoc.CL_SystemWindow);

                return;
            }

            player.Out.SendMessage(
                LanguageMgr.GetTranslation(player.Client.Account.Language, "Scripts.Blacksmith.YouPay",
                                           GetName(0, false), Money.GetString(item.RepairCost)), eChatType.CT_System,
                eChatLoc.CL_SystemWindow);

            // Items with IsNotLosingDur are not....losing DUR.
            if (ToRecoverCond + 1 >= item.Durability)
            {
                item.Condition  = item.Condition + item.Durability;
                item.Durability = 0;
                SayTo(player, LanguageMgr.GetTranslation(
                          player.Client.Account.Language,
                          "Scripts.Blacksmith.ObjectRatherOld", item.Name));
            }
            else
            {
                item.Condition = item.MaxCondition;
                if (!item.IsNotLosingDur)
                {
                    item.Durability -= ToRecoverCond + 1;
                }
            }

            player.Out.SendInventoryItemsUpdate(new InventoryItem[] { item });
            player.Out.SendMessage(
                LanguageMgr.GetTranslation(
                    player.Client.Account.Language,
                    "Scripts.Blacksmith.ItsDone", item.Name), eChatType.CT_System,
                eChatLoc.CL_SystemWindow);

            return;
        }
예제 #30
0
        /// <summary>
        /// Called when a player buys an item
        /// </summary>
        /// <param name="player">The player making the purchase</param>
        /// <param name="item_slot">slot of the item to be bought</param>
        /// <param name="number">Number to be bought</param>
        /// <param name="TradeItems"></param>
        /// <returns>true if buying is allowed, false if buying should be prevented</returns>
        public static void OnPlayerBuy(GamePlayer player, int item_slot, int number, MerchantTradeItems TradeItems)
        {
            //Get the template
            int pagenumber = item_slot / MerchantTradeItems.MAX_ITEM_IN_TRADEWINDOWS;
            int slotnumber = item_slot % MerchantTradeItems.MAX_ITEM_IN_TRADEWINDOWS;

            ItemTemplate template = TradeItems.GetItem(pagenumber, (eMerchantWindowSlot)slotnumber);

            if (template == null)
            {
                return;
            }

            //Calculate the amout of items
            int amountToBuy = number;

            if (template.PackSize > 0)
            {
                amountToBuy *= template.PackSize;
            }

            if (amountToBuy <= 0)
            {
                return;
            }

            //Calculate the value of items
            long totalValue = number * template.Price;

            lock (player.Inventory)
            {
                if (player.GetCurrentMoney() < totalValue)
                {
                    player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "GameMerchant.OnPlayerBuy.YouNeed", Money.GetString(totalValue)), eChatType.CT_System, eChatLoc.CL_SystemWindow);
                    return;
                }

                if (!player.Inventory.AddTemplate(GameInventoryItem.Create(template), amountToBuy, eInventorySlot.FirstBackpack, eInventorySlot.LastBackpack))
                {
                    player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "GameMerchant.OnPlayerBuy.NotInventorySpace"), eChatType.CT_System, eChatLoc.CL_SystemWindow);
                    return;
                }
                InventoryLogging.LogInventoryAction("(TRADEITEMS;" + TradeItems.ItemsListID + ")", player, eInventoryActionType.Merchant, template, amountToBuy);
                //Generate the buy message
                string message;
                if (amountToBuy > 1)
                {
                    message = LanguageMgr.GetTranslation(player.Client.Account.Language, "GameMerchant.OnPlayerBuy.BoughtPieces", amountToBuy, template.GetName(1, false), Money.GetString(totalValue));
                }
                else
                {
                    message = LanguageMgr.GetTranslation(player.Client.Account.Language, "GameMerchant.OnPlayerBuy.Bought", template.GetName(1, false), Money.GetString(totalValue));
                }

                // Check if player has enough money and subtract the money
                if (!player.RemoveMoney(totalValue, message, eChatType.CT_Merchant, eChatLoc.CL_SystemWindow))
                {
                    throw new Exception("Money amount changed while adding items.");
                }
                InventoryLogging.LogInventoryAction(player, "(TRADEITEMS;" + TradeItems.ItemsListID + ")", eInventoryActionType.Merchant, totalValue);
            }
        }