예제 #1
0
        private void _decalEventsProxy_ChatBoxMessage(object sender, Decal.Adapter.ChatTextInterceptEventArgs e)
        {
            if (this._giveItemPending.WaitOne(0))
            {
                // Ex: You give Kreap Invitation Ithaenc Cathedral.
                // Ex: You give Kreap Velvet Baggy Pants.
                //         WorldObject Name will = Baggy Pants
                // Ex: You give Vassari 4 Quills of Infliction
                // Ex: You give Rockdown Guy 50 Silver Peas.
                if (e.IsYouGive())
                {
                    var worldObj = this._pendingGiveItemCapturedWorldObject;

                    var textMinusPrefix = e.Text.Substring(9);

                    var itemNameStartIndex = textMinusPrefix.IndexOf(worldObj.Name);

                    var targetName = textMinusPrefix.Substring(0, itemNameStartIndex).Trim();

                    // If the item we are giving has a material, it's going to be in the text and we need to trim it out
                    var materialValue = worldObj.Values(LongValueKey.Material);
                    if (materialValue > 0)
                    {
                        string materialName;
                        if(Mag.Shared.Constants.Dictionaries.MaterialInfo.TryGetValue(materialValue, out materialName))
                        {
                            targetName = targetName.Substring(0, targetName.Length - (materialName.Length + 1));
                        }
                    }

                    var stackCount = worldObj.Values(LongValueKey.StackCount);
                    if (stackCount > 1)
                    {
                        // When stack count > 0, what we will be looking at is :
                        //      targetName = Rockdown Guy 50 S
                        // The single character is left over from the item name being plural in the give message
                        var endingCharsToIgnore = 2 + (stackCount.ToString()).Length;
                        targetName = targetName.Substring(0, targetName.Length - endingCharsToIgnore).Trim();
                    }

                    var eventArgs = new EndGiveItemEventArgs(worldObj, targetName, GiveItemOutcome.Successful);
                    REPlugin.Instance.Debug.WriteObject(eventArgs);

                    if (this.EndGiveItem != null)
                    {
                        this.EndGiveItem(sender, eventArgs);
                    }

                    this._giveItemPending.Reset();
                    this._pendingGiveItemCapturedWorldObject = null;
                }
            }
        }