コード例 #1
0
        private void LoadInventory()
        {
            var items_Available = Aisling.Inventory.Items.Values
                                  .Where(i => i != null && i.Template != null).ToArray();

            for (var i = 0; i < items_Available.Length; i++)
            {
                var item = items_Available[i];

                if (string.IsNullOrEmpty(item.Template.Name))
                {
                    continue;
                }


                item.Script = ScriptManager.Load <ItemScript>(item.Template.ScriptName, item);

                if (!string.IsNullOrEmpty(item.Template.WeaponScript))
                {
                    item.WeaponScript = ScriptManager.Load <WeaponScript>(item.Template.WeaponScript, item);
                }

                if (ServerContext.GlobalItemTemplateCache.ContainsKey(item.Template.Name))
                {
                    var template = ServerContext.GlobalItemTemplateCache[item.Template.Name];
                    {
                        item.Template = template;
                    }

                    if (item.Upgrades > 0)
                    {
                        Item.ApplyQuality(item);
                    }
                }

                if (item.Template != null)
                {
                    if (Aisling.CurrentWeight + item.Template.CarryWeight < Aisling.MaximumWeight)
                    {
                        var format = new ServerFormat0F(item);
                        Send(format);

                        Aisling.Inventory.Set(item, false);
                        Aisling.CurrentWeight += item.Template.CarryWeight;
                    }
                    //for some reason, Aisling is out of Weight!
                    else
                    {
                        //clone and release item
                        var copy = Clone <Item>(item);
                        {
                            copy.Release(Aisling, Aisling.Position);

                            //display message
                            SendMessage(0x02, string.Format("You stumble and drop {0}", item.Template.Name));
                        }
                    }
                }
            }
        }
コード例 #2
0
        private void LoadInventory()
        {
            var items_Available = Aisling.Inventory.Items.Values
                                  .Where(i => i != null && i.Template != null).ToArray();

            for (var i = 0; i < items_Available.Length; i++)
            {
                var item = items_Available[i];
                item.Script = ScriptManager.Load <ItemScript>(item.Template.ScriptName, item);

                if (item.Template != null)
                {
                    Aisling.CurrentWeight += item.Template.Weight;

                    if (Aisling.CurrentWeight <= Aisling.MaximumWeight)
                    {
                        var format = new ServerFormat0F(item);
                        Send(format);
                        Aisling.Inventory.Set(item, false);
                    }
                    //for some reason, Aisling is out of Weight!
                    else
                    {
                        //clone and release item
                        var nitem = Clone(item);
                        nitem.Release(Aisling, Aisling.Position);

                        //display message
                        SendMessage(0x02, string.Format("You stumble and drop {0}", item.Template.Name));
                    }
                }
            }
        }
コード例 #3
0
        public bool GiveTo(Sprite sprite, bool checkWeight = true, byte slot = 0)
        {
            if (sprite is Aisling)
            {
                if (checkWeight)
                {
                    if (!((sprite as Aisling).CurrentWeight + Template.CarryWeight < (sprite as Aisling).MaximumWeight))
                    {
                        (sprite as Aisling).Client.SendMessage(Scope.Self, 0x02, ServerContext.Config.ToWeakToLift);

                        if (Slot > 0)
                        {
                            //remove from inventory
                            (sprite as Aisling).Client.Aisling.Inventory.Remove(Slot);
                            (sprite as Aisling).Client.Send(new ServerFormat10(Slot));
                            (sprite as Aisling).CurrentWeight -= Template.CarryWeight;

                            if ((sprite as Aisling).CurrentWeight < 0)
                            {
                                (sprite as Aisling).CurrentWeight = 0;
                            }

                            //release this item.
                            var copy = Clone(this);

                            //generate a new item!
                            copy.Release(sprite, sprite.Position);

                            //delete current
                            Remove <Item>();
                        }

                        return(false);
                    }
                }

                (sprite as Aisling).CurrentWeight += Template.CarryWeight;


                if ((sprite as Aisling).CurrentWeight > (sprite as Aisling).MaximumWeight)
                {
                    (sprite as Aisling).CurrentWeight = (sprite as Aisling).MaximumWeight;
                }

                if (Template.Flags.HasFlag(ItemFlags.Stackable))
                {
                    var num_stacks = (byte)Stacks;

                    if (num_stacks <= 0)
                    {
                        num_stacks = 1;
                    }

                    //find first item in inventory that is stackable with the same name.
                    var item = (sprite as Aisling).Inventory.Get(i => i != null && i.Template.Name == Template.Name &&
                                                                 i.Stacks + num_stacks <
                                                                 i.Template.MaxStack).FirstOrDefault();

                    if (item != null)
                    {
                        //use the same slot as this stack we found of the same item.
                        Slot = item.Slot;

                        //update the stack quanity.
                        item.Stacks += num_stacks;

                        //refresh this item slot.
                        (sprite as Aisling).Client.Aisling.Inventory.Set(item, false);

                        //send remove packet.
                        (sprite as Aisling).Client.Send(new ServerFormat10(item.Slot));

                        //add it again with updated information.
                        (sprite as Aisling).Client.Send(new ServerFormat0F(item));

                        //send message
                        (sprite as Aisling).Client.SendMessage(Scope.Self, 0x02,
                                                               string.Format("You received another {0}!", DisplayName));

                        return(true);
                    }

                    //if we don't find an existing item of this stack, create a new stack.
                    if (Stacks <= 0)
                    {
                        Stacks = 1;
                    }

                    Slot = (sprite as Aisling).Inventory.FindEmpty();

                    if (Slot <= 0)
                    {
                        (sprite as Aisling).Client.SendMessage(Scope.Self, 0x02, ServerContext.Config.CantCarryMoreMsg);
                        return(false);
                    }

                    //assign this item to the inventory.
                    (sprite as Aisling).Inventory.Set(this, false);
                    var format = new ServerFormat0F(this);
                    (sprite as Aisling).Show(Scope.Self, format);
                    (sprite as Aisling).Client.SendMessage(Scope.Self, 0x02,
                                                           string.Format("You receive {0} [{1}]", DisplayName, num_stacks));
                    (sprite as Aisling).Client.SendStats(StatusFlags.All);

                    return(true);
                }

                {
                    //not stackable. just try and add it to a new inventory slot.
                    Slot = (sprite as Aisling).Inventory.FindEmpty();

                    if (Slot <= 0)
                    {
                        (sprite as Aisling).Client.SendMessage(Scope.Self, 0x02, ServerContext.Config.CantCarryMoreMsg);
                        (sprite as Aisling).Client.SendStats(StatusFlags.All);
                        return(false);
                    }

                    if (slot > 0)
                    {
                        //move whatever is in delegated slot, and move it somewhere else!
                        var item = (sprite as Aisling).Inventory.FindInSlot(slot);

                        var a = (sprite as Aisling).Inventory.Remove(slot);
                        var b = (sprite as Aisling).Inventory.Remove(Slot);

                        (sprite as Aisling).Client.Send(new ServerFormat10(slot));
                        (sprite as Aisling).Client.Send(new ServerFormat10(Slot));

                        if (a != null)
                        {
                            a.Slot = Slot;
                            (sprite as Aisling).Client.Aisling.Inventory.Set(a, false);
                            (sprite as Aisling).Client.Send(new ServerFormat0F(a));
                        }

                        if (b != null)
                        {
                            b.Slot = slot;
                            (sprite as Aisling).Client.Aisling.Inventory.Set(b, false);
                            (sprite as Aisling).Client.Send(new ServerFormat0F(b));
                        }

                        //now set the delegated slot to be the one we delegated.
                        Slot = slot;
                    }

                    //assign this item to the inventory.
                    (sprite as Aisling).Inventory.Assign(this);
                    var format = new ServerFormat0F(this);
                    (sprite as Aisling).Show(Scope.Self, format);
                    (sprite as Aisling).Client.SendMessage(Scope.Self, 0x02,
                                                           string.Format("{0} Received.", DisplayName));
                    (sprite as Aisling).Client.SendStats(StatusFlags.All);

                    return(true);
                }
            }


            return(false);
        }
コード例 #4
0
        public bool GiveTo(Sprite sprite, bool checkWeight = true)
        {
            if (sprite is Aisling)
            {
                Owner = (uint)sprite.Serial;

                #region stackable items

                if (Template.Flags.HasFlag(ItemFlags.Stackable))
                {
                    var numStacks = (byte)Stacks;

                    if (numStacks <= 0)
                    {
                        numStacks = 1;
                    }

                    var item = ((Aisling)sprite).Inventory.Get(i => i != null && i.Template.Name == Template.Name &&
                                                               i.Stacks + numStacks <
                                                               i.Template.MaxStack).FirstOrDefault();

                    if (item != null)
                    {
                        Slot = item.Slot;

                        item.Stacks += numStacks;

                        ((Aisling)sprite).Client.Aisling.Inventory.Set(item, false);

                        ((Aisling)sprite).Client.Send(new ServerFormat10(item.Slot));

                        ((Aisling)sprite).Client.Send(new ServerFormat0F(item));

                        ((Aisling)sprite).Client.SendMessage(Scope.Self, 0x02,
                                                             $"Received {DisplayName}, You now have ({(item.Stacks == 0 ? item.Stacks + 1 : item.Stacks)})");

                        return(true);
                    }

                    if (Stacks <= 0)
                    {
                        Stacks = 1;
                    }

                    if (checkWeight)
                    {
                        if (!CanCarry(sprite))
                        {
                            return(false);
                        }
                    }

                    Slot = ((Aisling)sprite).Inventory.FindEmpty();

                    if (Slot == byte.MaxValue)
                    {
                        ((Aisling)sprite).Client.SendMessage(Scope.Self, 0x02,
                                                             ServerContext.Config.CantCarryMoreMsg);
                        return(false);
                    }

                    ((Aisling)sprite).Inventory.Set(this, false);
                    var format = new ServerFormat0F(this);
                    ((Aisling)sprite).Show(Scope.Self, format);
                    ((Aisling)sprite).Client.SendMessage(Scope.Self, 0x02,
                                                         $"{DisplayName} Received.");

                    if (checkWeight)
                    {
                        ((Aisling)sprite).CurrentWeight += Template.CarryWeight;
                        ((Aisling)sprite).Client.SendStats(StatusFlags.StructA);
                    }

                    return(true);
                }

                #endregion

                #region not stackable items

                {
                    Slot = ((Aisling)sprite).Inventory.FindEmpty();

                    if (Slot == byte.MaxValue)
                    {
                        ((Aisling)sprite).Client.SendMessage(Scope.Self, 0x02,
                                                             ServerContext.Config.CantCarryMoreMsg);
                        return(false);
                    }

                    if (checkWeight)
                    {
                        if (!CanCarry(sprite))
                        {
                            return(false);
                        }
                    }

                    ((Aisling)sprite).Inventory.Assign(this);
                    var format = new ServerFormat0F(this);
                    ((Aisling)sprite).Show(Scope.Self, format);

                    if (checkWeight)
                    {
                        ((Aisling)sprite).CurrentWeight += Template.CarryWeight;
                        ((Aisling)sprite).Client?.SendStats(StatusFlags.StructA);
                    }

                    return(true);
                }

                #endregion
            }

            return(false);
        }
コード例 #5
0
 public virtual void Format0FHandler(ServerFormat0F format)
 {
 }
コード例 #6
0
        public GameClient LoadInventory()
        {
            lock (_syncObj)
            {
                var itemsAvailable = Aisling.Inventory.Items.Values
                                     .Where(i => i != null && i.Template != null).ToArray();

                for (var i = 0; i < itemsAvailable.Length; i++)
                {
                    var item = itemsAvailable[i];

                    if (string.IsNullOrEmpty(item.Template.Name))
                    {
                        continue;
                    }

                    item.Scripts = ScriptManager.Load <ItemScript>(item.Template.ScriptName, item);

                    if (!string.IsNullOrEmpty(item.Template.WeaponScript))
                    {
                        item.WeaponScripts = ScriptManager.Load <WeaponScript>(item.Template.WeaponScript, item);
                    }

                    if (ServerContextBase.GlobalItemTemplateCache.ContainsKey(item.Template.Name))
                    {
                        var template = ServerContextBase.GlobalItemTemplateCache[item.Template.Name];
                        {
                            item.Template = template;
                        }

                        if (item.Upgrades > 0)
                        {
                            Item.ApplyQuality(item);
                        }
                    }

                    if (item.Template != null)
                    {
                        if (Aisling.CurrentWeight + item.Template.CarryWeight < Aisling.MaximumWeight)
                        {
                            var format = new ServerFormat0F(item);
                            Send(format);

                            Aisling.Inventory.Set(item, false);
                            Aisling.CurrentWeight += item.Template.CarryWeight;
                        }
                        else
                        {
                            var copy = Clone <Item>(item);
                            {
                                copy.Release(Aisling, Aisling.Position);

                                SendMessage(0x02,
                                            string.Format(CultureInfo.CurrentCulture, "You stumble and drop {0}",
                                                          item.Template.Name));
                            }
                        }
                    }
                }
            }

            return(this);
        }
コード例 #7
0
        public bool GiveTo(Sprite sprite, bool CheckWeight = true)
        {
            if (sprite is Aisling)
            {
                Owner = (uint)sprite.Serial;


                #region stackable items

                if (Template.Flags.HasFlag(ItemFlags.Stackable))
                {
                    var num_stacks = (byte)Stacks;

                    if (num_stacks <= 0)
                    {
                        num_stacks = 1;
                    }

                    //find first item in inventory that is stackable with the same name.
                    var item = (sprite as Aisling).Inventory.Get(i => i != null && i.Template.Name == Template.Name &&
                                                                 i.Stacks + num_stacks <
                                                                 i.Template.MaxStack).FirstOrDefault();

                    if (item != null) // current stack
                    {
                        //use the same slot as this stack we found of the same item.
                        Slot = item.Slot;

                        //update the stack quanity.
                        item.Stacks += num_stacks;

                        //refresh this item slot.
                        (sprite as Aisling).Client.Aisling.Inventory.Set(item, false);

                        //send remove packet.
                        (sprite as Aisling).Client.Send(new ServerFormat10(item.Slot));

                        //add it again with updated information.
                        (sprite as Aisling).Client.Send(new ServerFormat0F(item));

                        //send message
                        (sprite as Aisling).Client.SendMessage(Scope.Self, 0x02,
                                                               $"Received {DisplayName}, You now have ({(item.Stacks == 0 ? item.Stacks + 1 : item.Stacks)})");

                        return(true);
                    }

                    //if we don't find an existing item of this stack, create a new stack.
                    if (Stacks <= 0)
                    {
                        Stacks = 1;
                    }

                    if (CheckWeight)
                    {
                        if (!CanCarry(sprite))
                        {
                            return(false);
                        }
                    }

                    Slot = (sprite as Aisling).Inventory.FindEmpty();

                    if (Slot == byte.MaxValue)
                    {
                        (sprite as Aisling).Client.SendMessage(Scope.Self, 0x02,
                                                               ServerContextBase.GlobalConfig.CantCarryMoreMsg);
                        return(false);
                    }

                    //assign this item to the inventory.
                    (sprite as Aisling).Inventory.Set(this, false);
                    var format = new ServerFormat0F(this);
                    (sprite as Aisling).Show(Scope.Self, format);
                    (sprite as Aisling).Client.SendMessage(Scope.Self, 0x02,
                                                           $"{DisplayName} Received.");

                    if (CheckWeight)
                    {
                        (sprite as Aisling).CurrentWeight += Template.CarryWeight;
                        (sprite as Aisling).Client.SendStats(StatusFlags.StructA);
                    }

                    return(true);
                }

                #endregion

                #region not stackable items

                {
                    //not stackable. find inventory slot.
                    Slot = (sprite as Aisling).Inventory.FindEmpty();

                    if (Slot == byte.MaxValue)
                    {
                        (sprite as Aisling).Client.SendMessage(Scope.Self, 0x02,
                                                               ServerContextBase.GlobalConfig.CantCarryMoreMsg);
                        return(false);
                    }

                    if (CheckWeight)
                    {
                        if (!CanCarry(sprite))
                        {
                            return(false);
                        }
                    }


                    //assign this item to the inventory.
                    (sprite as Aisling).Inventory.Assign(this);
                    var format = new ServerFormat0F(this);
                    (sprite as Aisling).Show(Scope.Self, format);

                    if (CheckWeight)
                    {
                        (sprite as Aisling).CurrentWeight += Template.CarryWeight;
                        (sprite as Aisling).Client?.SendStats(StatusFlags.StructA);
                    }

                    return(true);
                }

                #endregion
            }

            return(false);
        }