Beispiel #1
0
        public Bag(InventoryLocation location, uint capacity)
        {
            Location = location;
            items    = new Item[capacity];

            log.Trace($"Initialised new bag {Location} with {capacity} slots.");
        }
 public bool AddNewInventoryLocationToPart(InventoryLocation inventoryLocation, Part part)
 {
     inventoryLocation.Part = part;
     dataContext.InventoryLocations.InsertOnSubmit(inventoryLocation);
     dataContext.SubmitChanges();
     return(dataContext.ChangeConflicts != null && dataContext.ChangeConflicts.Count == 0);
 }
 public bool AddEntity(Entity user, Entity toAdd, InventoryLocation? whichHand = null)
 {
     if (handslots.Any(x => x.Value == toAdd))
     {
         return false;
     }
     else
     {
         if (whichHand.HasValue)
         {
             if (handslots[whichHand.Value] != null)
                 return false;
             else
             {
                 handslots[whichHand.Value] = toAdd;
             }
         }
         else
         {
             if (handslots.Any(x => x.Value == null))
             {
                 handslots[handslots.First(x => x.Value == null).Key] = toAdd;
             }
             else
             {
                 return false;
             }
         }
         return true;
     }
 }
Beispiel #4
0
 public static void CallInventoryUpdatedEvent(InventoryLocation inventoryLocation, List <InventoryItem> inventoryList)
 {
     if (InventoryUpdatedEvent != null)
     {
         InventoryUpdatedEvent(inventoryLocation, inventoryList);
     }
 }
Beispiel #5
0
        /// <summary>
        /// Add <see cref="Item"/> in the first available bag index for the given <see cref="InventoryLocation"/> .
        /// </summary>
        public void AddItem(Item item, InventoryLocation inventoryLocation)
        {
            Bag  bag      = GetBag(inventoryLocation);
            uint bagIndex = bag.GetFirstAvailableBagIndex();

            if (bagIndex == uint.MaxValue)
            {
                throw new ArgumentException($"InventoryLocation {inventoryLocation} is full!");
            }

            // Stacks are bought back in full, so no need to worry about splitting stacks
            AddItem(item, inventoryLocation, bagIndex);

            if (!player?.IsLoading ?? false)
            {
                player.Session.EnqueueMessageEncrypted(new ServerItemAdd
                {
                    InventoryItem = new InventoryItem
                    {
                        Item   = item.BuildNetworkItem(),
                        Reason = 49
                    }
                });
            }
        }
        private void SendSwitchHandTo(InventoryLocation hand)
        {
            IEntity playerEntity   = _playerManager.ControlledEntity;
            var     equipComponent = (HumanHandsComponent)playerEntity.GetComponent(ComponentFamily.Hands);

            equipComponent.SendSwitchHands(hand);
        }
Beispiel #7
0
        public IHttpActionResult DeleteInventoryLocation(int id, int UILoginUserID, string UILoginPassword, int SiteID)
        {
            if (!Global.CheckUserIDAndPasswordWithSiteID(db, UILoginUserID, UILoginPassword, SiteID, "DeleteInventoryLocation"))
            {
                return BadRequest();
            }
            InventoryLocation inventoryLocation = db.InventoryLocations.Find(id);
            if (inventoryLocation == null)
            {
                return NotFound();
            }

            if (inventoryLocation.SiteID != SiteID)
            {
                return BadRequest();
            }
            User user = db.Users.Find(UILoginUserID);
            if (user == null)
            {
                return BadRequest();
            }
            if (!user.IsRootUser && !user.IsSiteAdmin && inventoryLocation.EntryByUserID != user.ID)
            {
                return BadRequest();
            }
            db.InventoryLocations.Remove(inventoryLocation);
            db.SaveChanges();

            return Ok(inventoryLocation);
        }
Beispiel #8
0
        /// <inheritdoc/>
        public string ToDelimitedString()
        {
            CultureInfo culture = CultureInfo.CurrentCulture;

            return(string.Format(
                       culture,
                       StringHelper.StringFormatSequence(0, 16, Configuration.FieldSeparator),
                       Id,
                       PrimaryKeyValueIim?.ToDelimitedString(),
                       ServiceItemCode?.ToDelimitedString(),
                       InventoryLotNumber,
                       InventoryExpirationDate.HasValue ? InventoryExpirationDate.Value.ToString(Consts.DateTimeFormatPrecisionSecond, culture) : null,
                       InventoryManufacturerName?.ToDelimitedString(),
                       InventoryLocation?.ToDelimitedString(),
                       InventoryReceivedDate.HasValue ? InventoryReceivedDate.Value.ToString(Consts.DateTimeFormatPrecisionSecond, culture) : null,
                       InventoryReceivedQuantity.HasValue ? InventoryReceivedQuantity.Value.ToString(Consts.NumericFormat, culture) : null,
                       InventoryReceivedQuantityUnit?.ToDelimitedString(),
                       InventoryReceivedItemCost?.ToDelimitedString(),
                       InventoryOnHandDate.HasValue ? InventoryOnHandDate.Value.ToString(Consts.DateTimeFormatPrecisionSecond, culture) : null,
                       InventoryOnHandQuantity.HasValue ? InventoryOnHandQuantity.Value.ToString(Consts.NumericFormat, culture) : null,
                       InventoryOnHandQuantityUnit?.ToDelimitedString(),
                       ProcedureCode?.ToDelimitedString(),
                       ProcedureCodeModifier != null ? string.Join(Configuration.FieldRepeatSeparator, ProcedureCodeModifier.Select(x => x.ToDelimitedString())) : null
                       ).TrimEnd(Configuration.FieldSeparator.ToCharArray()));
        }
 public ItemComponentState(int?holder, InventoryLocation inventoryLocation)
     : base(ComponentFamily.Item)
 {
     Holder            = holder;
     InventoryLocation = inventoryLocation;
     Family            = ComponentFamily.Item;
 }
Beispiel #10
0
        /// <summary>
        /// Checks if supplied <see cref="InventoryLocation"/> and bag index valid for <see cref="Item"/>.
        /// </summary>
        private bool IsValidLocationForItem(Item item, InventoryLocation location, uint bagIndex)
        {
            Bag bag = GetBag(location);

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

            if (location == InventoryLocation.Equipped)
            {
                Item2TypeEntry typeEntry = GameTableManager.ItemType.GetEntry(item.Entry.Item2TypeId);
                if (typeEntry.ItemSlotId == 0)
                {
                    return(false);
                }

                ImmutableList <EquippedItem> bagIndexes = AssetManager.GetEquippedBagIndexes((ItemSlot)typeEntry.ItemSlotId);
                if (bagIndexes.All(i => i != (EquippedItem)bagIndex))
                {
                    return(false);
                }

                /*if (owner.Character.Class != item.Entry.ClassRequired)
                 *  return false;
                 *
                 * if (owner.Character.Race != item.Entry.RaceRequired)
                 *  return false;*/
            }

            return(true);
        }
 public bool AddEntity(IEntity actor, IEntity toAdd, InventoryLocation location = InventoryLocation.Any)
 {
     if (Handslots.Any(x => x.Value == toAdd))
     {
         return(false);
     }
     else
     {
         if (location == InventoryLocation.Any)
         {
             if (Handslots[CurrentHand] != null)
             {
                 return(false);
             }
             else
             {
                 Handslots[CurrentHand] = toAdd;
             }
         }
         else
         {
             if (Handslots[location] == null)
             {
                 Handslots[location] = toAdd;
             }
             else
             {
                 return(false);
             }
         }
         return(true);
     }
 }
 public ItemComponentState(int? holder, InventoryLocation inventoryLocation)
     :base(ComponentFamily.Item)
 {
     Holder = holder;
     InventoryLocation = inventoryLocation;
     Family = ComponentFamily.Item;
 }
Beispiel #13
0
    /// <summary>
    /// Returns the item position in the inventory list if it exists
    /// </summary>
    /// <param name="location">Location to search in</param>
    /// <param name="itemCode">Item code</param>
    /// <returns>Item position</returns>
    public int FindItemInInventory(InventoryLocation location, int itemCode)
    {
        List <InventoryItem> inventoryList = inventoryLists[(int)location];
        int res = inventoryList.FindIndex(x => x.itemCode == itemCode);

        return(res >= 0 ? res : -1);
    }
    public void InventoryUpdated(InventoryLocation inventoryLocation, List <InventoryItem> inventoryList)
    {
        if (inventoryLocation == InventoryLocation.Player)
        {
            ClearInventorySlots();

            if (inventorySlot.Length > 0 && inventoryList.Count > 0)
            {
                for (int i = 0; i < inventorySlot.Length; i++)
                {
                    if (i < inventoryList.Count)
                    {
                        int itemCode = inventoryList[i].itemCode;

                        ItemDetails itemDetails = InventoryManager.Instance.GetItemDetails(itemCode);

                        if (itemDetails != null)
                        {
                            inventorySlot[i].inventorySlotImage.sprite = itemDetails.itemSprite;
                            inventorySlot[i].amountText.text           = inventoryList[i].itemQuantity.ToString();
                            inventorySlot[i].itemDetails  = itemDetails;
                            inventorySlot[i].itemQuantity = inventoryList[i].itemQuantity;
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            }
        }
    }
Beispiel #15
0
        public override void contributeToTreeView(TreeView treeView)
        {
            TreeNode rootNode = new TreeNode(this.GetType().Name);

            rootNode.Expand();
            ContextInfo.AddToList(new ContextInfo {
                DataType = DataType.ClientToServerHeader
            });
            rootNode.Nodes.Add("i_stackID = " + Utility.FormatHex(i_stackID));
            ContextInfo.AddToList(new ContextInfo {
                DataType = DataType.ObjectID
            });
            TreeNode locationNode = rootNode.Nodes.Add("i_loc = " + Utility.FormatHex(i_loc));

            ContextInfo.AddToList(new ContextInfo {
                Length = 4
            }, updateDataIndex: false);
            InventoryLocation.contributeToTreeNode(locationNode, i_loc);
            // Now skip i_loc dword
            ContextInfo.DataIndex += 4;
            rootNode.Nodes.Add("i_amount = " + i_amount);
            ContextInfo.AddToList(new ContextInfo {
                Length = 4
            });
            treeView.Nodes.Add(rootNode);
        }
        public IActionResult Post([FromBody] InventoryLocation item)
        {
            var id   = _inventoryLocationRepository.Add(item);
            var data = _inventoryLocationRepository.Get(id);

            return(CreatedAtRoute("GetInventoryLocation", new { id = id }, data));
        }
Beispiel #17
0
 public static void CallInventoryChangeEvent(InventoryLocation location, List <InventoryItem> inventory)
 {
     if (InventoryChangeEvent != null)
     {
         InventoryChangeEvent(location, inventory);
     }
 }
Beispiel #18
0
        public ActionResult InventoryLocation(InventoryLocationViewModel model)
        {
            if (ModelState.IsValid)
            {
                //名称编号不重复
                var db = new DbEntities <InventoryLocation>().SimpleClient;

                if (db.IsAny(il => il.InventoryLocationName == model.InventoryLocationName || il.InventoryLocationNo == model.InventoryLocationNo))
                {
                    ModelState.AddModelError("InventoryLocationNo", "库位名称或编号已存在");
                }
                else
                {
                    //检验登录人身份,并获取对应ID
                    if (new IdentityAuth().GetCurUserID(HttpContext, out int curUserID))
                    {
                        InventoryLocation entity = model.InitAddInventoryLocation(curUserID);

                        if (db.Insert(entity))
                        {
                            TempData["Msg"] = $"库区 {entity.InventoryLocationName} 添加成功";
                            return(RedirectToAction("InventoryLocation", "Warehouse"));
                        }
                        TempData["Msg"] = "添加失败";
                    }
                    else
                    {
                        TempData["Msg"] = "登录身份过期,请重新登录";
                    }
                }
            }

            SetSelectListItems.InventoryArea(this);
            return(View(model));
        }
        public ActionResult NewLoc(long id, string name)
        {
            var locationInfo = new InventoryLocation();

            locationInfo.id    = id;
            locationInfo.title = name;
            return(View("inventoryInfo", locationInfo));
        }
 /// <summary>
 /// Set the entity in the specified hand
 /// </summary>
 /// <param name="hand"></param>
 /// <param name="entity"></param>
 private void SetEntity(InventoryLocation hand, IEntity entity)
 {
     if (entity != null && IsEmpty(hand))
     {
         Handslots.Add(hand, entity);
         //Owner.SendComponentNetworkMessage(this, Lidgren.Network.NetDeliveryMethod.ReliableOrdered, null, ComponentMessageType.EntityChanged, entity.Uid, hand); Maybe for later use?
     }
 }
 /// <summary>
 /// Drop an entity.
 /// </summary>
 /// <param name="hand"></param>
 private void Drop(IEntity ent)
 {
     if (Handslots.ContainsValue(ent))
     {
         InventoryLocation holding = Handslots.First(x => x.Value == ent).Key;
         Drop(holding);
     }
 }
 /// <summary>
 /// Check if the specified hand is empty
 /// </summary>
 /// <param name="hand"></param>
 /// <returns></returns>
 public bool IsEmpty(InventoryLocation hand)
 {
     if (Handslots.ContainsKey(hand) && Handslots[hand] != null)
     {
         return(false);
     }
     return(true);
 }
 public bool CanAddEntity(IEntity actor, IEntity toAdd, InventoryLocation location = InventoryLocation.Any)
 {
     if (Handslots.Any(x => x.Value == toAdd) || (location == InventoryLocation.Any && Handslots[CurrentHand] != null) || !Handslots.ContainsKey(location) || Handslots[location] != null)
     {
         return(false);
     }
     return(true);
 }
 // Inventory updated event call for publishers, to send out event details to any subscribers
 public static void CallInventoryUpdatedEvent(InventoryLocation inventoryLocation, List <InventoryItem> inventoryList)
 {
     // Check if there are any subscribers - or else do nothing!
     if (InventoryUpdatedEvent != null)
     {
         InventoryUpdatedEvent(inventoryLocation, inventoryList);
     }
 }
        public async Task <ActionResult> DeleteConfirmed(long id)
        {
            InventoryLocation inventoryLocation = await db.InventoryLocations.FindAsync(id);

            db.InventoryLocations.Remove(inventoryLocation);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
Beispiel #26
0
 public void RaiseUnEquipItemToSpecifiedHand(IEntity item, InventoryLocation hand)
 {
     Owner.EntityManager.RaiseEvent(this, new InventoryUnEquipItemToSpecifiedHandEventArgs
     {
         Actor = Owner,
         Item  = item,
         Hand  = hand
     });
 }
Beispiel #27
0
        public bool UpdateLocation(string qrCode, int binLocationId, int quantity, string movementType)
        {
            bool result = false;

            string[] includedNavigationProperties = new string[] { "InventoryLocations", "InventoryLocations.BinLocation" };
            var      inventories = _inventoryRepository.ListQuery(includedNavigationProperties);
            var      inventory   = inventories.FirstOrDefault(i => i.QRCode == qrCode);

            if (inventory != null)
            {
                if (inventory.InventoryLocations != null && inventory.InventoryLocations.Any())
                {
                    InventoryLocation inventoryLoc = null;
                    if (movementType.Trim().ToLower().Equals("out"))
                    {
                        inventoryLoc = inventory.InventoryLocations.FirstOrDefault(f => f.BinLocation != null && f.BinLocation.BinType == BinningType.Prime);
                    }
                    else
                    {
                        inventoryLoc = inventory.InventoryLocations.FirstOrDefault(f => f.BinLocation != null && f.BinLocation.Id == binLocationId);
                    }
                    if (inventoryLoc == null)
                    {
                        if (movementType.Trim().ToLower().Equals("in")) //if movement type is Inwards add InventoryLocation
                        {
                            var inventoryLocation = new InventoryLocation()
                            {
                                BinLocation = _binLocationRepository.GetById(binLocationId),
                                Quantity    = quantity
                            };
                            inventory.InventoryLocations.Add(inventoryLocation);
                            _inventoryRepository.Update(inventory);
                            result = true;
                        }
                    }
                    else
                    {
                        if (movementType.Trim().ToLower().Equals("out"))
                        {
                            inventoryLoc.Quantity  -= quantity;
                            inventory.TotalQuantity = inventory.InventoryLocations.Sum(i => i.Quantity);
                            _inventoryRepository.Update(inventory);
                        }
                        else if (movementType.Trim().ToLower().Equals("in"))
                        {
                            inventoryLoc.Quantity  += quantity;
                            inventory.TotalQuantity = inventory.InventoryLocations.Sum(i => i.Quantity);
                            _inventoryRepository.Update(inventory);
                        }
                        result = true;
                    }
                }
            }

            return(result);
        }
Beispiel #28
0
        public bool CanAddEntity(IEntity actor, IEntity toAdd, InventoryLocation location = InventoryLocation.Any)
        {
            if (containedEntities.Contains(toAdd))
            {
                return(false);
            }

            // Todo check if inventory is full
            return(true);
        }
Beispiel #29
0
        public void UnEquipEntityToHand(IEntity e, InventoryLocation h)
        {
            ComponentReplyMessage reply = Owner.SendMessage(this, ComponentFamily.Hands,
                                                            ComponentMessageType.IsHandEmpty, h);

            if (reply.MessageType == ComponentMessageType.IsHandEmptyReply && (bool)reply.ParamsList[0])
            {
                UnEquipEntity(e);
                Owner.SendMessage(this, ComponentMessageType.PickUpItemToHand, e, h);
            }
        }
Beispiel #30
0
        private void CreateInventoryLocations()
        {
            InventoryLocation invLocation = ObjectSpace.FindObject <InventoryLocation>(new BinaryOperator("DefaultLocation", true));

            if (invLocation == null)
            {
                invLocation                 = ObjectSpace.CreateObject <InventoryLocation>();
                invLocation.Description     = "Primary Warehouse";
                invLocation.DefaultLocation = true;
            }
        }
Beispiel #31
0
    public void RemoveItem(InventoryLocation inventoryLocation, int itemCode)
    {
        List <InventoryItem> inventoryList = inventoryLists[(int)inventoryLocation];
        int itemPosition = FindItemInInventory(inventoryLocation, itemCode);

        if (itemPosition != -1)
        {
            RemoveItemAtPosition(inventoryList, itemCode, itemPosition);
        }
        EventHandler.CallInventoryUpdatedEvent(inventoryLocation, inventoryLists[(int)inventoryLocation]);
    }
Beispiel #32
0
    public void RemoveItem(int itemCode, InventoryLocation inventoryLocation)
    {
        List <InventoryItem> inventoryItems = inventoryList[(int)inventoryLocation];

        int itemPosition = FindItemInInventory(inventoryLocation, itemCode);

        if (itemPosition != -1)
        {
            RemoveItemAtPosition(inventoryItems, itemCode, itemPosition);
        }
    }
 private void SetNewState(ItemComponentState state)
 {
     if(state.Holder != null && (Holder == null || Holder.Uid != state.Holder))
     {
         Holder = Owner.EntityManager.GetEntity((int)state.Holder);
         HoldingHand = state.InventoryLocation;
     }
     if(Holder != null && state.Holder == null)
     {
         Holder = null;
         HoldingHand = state.InventoryLocation;
     } 
 }
Beispiel #34
0
        public override void HandleComponentState(dynamic state)
        {
            CurrentHand = state.ActiveHand;
            Dictionary<InventoryLocation, Entity> newInventory = new Dictionary<InventoryLocation, Entity>();
            foreach (KeyValuePair<InventoryLocation, int> curr in state.Slots)
            {
                Entity retEnt = Owner.EntityManager.GetEntity(curr.Value);
                newInventory.Add(curr.Key, retEnt);
            }

            //Find differences and raise event?

            HandSlots = newInventory;
        }
 public bool IsHandEmpty(InventoryLocation hand)
 {
     return !HandSlots.ContainsKey(hand);
 }
Beispiel #36
0
        public bool RemoveEntity(Entity user, Entity inventory, Entity toRemove, InventoryLocation location = InventoryLocation.Any)
        {
            var comHands = inventory.GetComponent<HumanHandsComponent>(ComponentFamily.Hands);
            var comEquip = inventory.GetComponent<EquipmentComponent>(ComponentFamily.Equipment);
            var comInv = inventory.GetComponent<InventoryComponent>(ComponentFamily.Inventory);

            if ((location == InventoryLocation.Inventory) && comInv != null)
            {
                if (comInv.RemoveEntity(user, toRemove))
                {
                    //Do sprite stuff and detaching
                    return true;
                }
            }
            else if ((location == InventoryLocation.HandLeft || location == InventoryLocation.HandRight) && comHands != null)
            {
                if (comHands.RemoveEntity(user, toRemove))
                {
                    //Do sprite stuff and attaching
                    var toRemoveSlaveMover = toRemove.GetComponent<SlaveMoverComponent>(ComponentFamily.Mover);
                    if(toRemoveSlaveMover != null)
                    {
                        toRemoveSlaveMover.Detach();
                    }

                    if (toRemove.HasComponent(ComponentFamily.Renderable))
                    {
                        toRemove.GetComponent<IRenderableComponent>(ComponentFamily.Renderable).UnsetMaster();
                    }
                    toRemove.RemoveComponent(ComponentFamily.Mover);
                    toRemove.AddComponent(ComponentFamily.Mover, EntityManager.ComponentFactory.GetComponent<BasicMoverComponent>());
                    toRemove.GetComponent<BasicItemComponent>(ComponentFamily.Item).HandleDropped();
                    return true;
                }
            }
            else if ((location == InventoryLocation.Equipment || location == InventoryLocation.Any) && comEquip != null)
            {
                if (comEquip.RemoveEntity(user, toRemove))
                {
                    //Do sprite stuff and detaching
                    EquippableComponent eqCompo = toRemove.GetComponent<EquippableComponent>(ComponentFamily.Equippable);
                    if(eqCompo != null) eqCompo.currentWearer = null;
                    return true;
                }
            }
            else if (location == InventoryLocation.Any)
            {
                //Do sprite stuff and detaching
                bool done = false;

                if (comInv != null)
                    done = comInv.RemoveEntity(user, toRemove);

                if (comEquip != null && !done)
                    done = comEquip.RemoveEntity(user, toRemove);

                if (comHands != null && !done)
                    done = comHands.RemoveEntity(user, toRemove);

                return done;
            }

            return false;
        }
 public void SendSwitchHands(InventoryLocation hand)
 {
     Owner.SendComponentNetworkMessage(this, NetDeliveryMethod.ReliableOrdered,
                                       ComponentMessageType.ActiveHandChanged, hand);
 }
 public void DispatchUnEquipItemToSpecifiedHand(int uid, InventoryLocation hand)
 {
     Owner.SendComponentNetworkMessage(this, NetDeliveryMethod.ReliableOrdered,
                                       ComponentMessageType.UnEquipItemToSpecifiedHand, uid, hand);
 }
Beispiel #39
0
        public bool AddEntity(Entity user, Entity inventory, Entity toAdd, InventoryLocation location = InventoryLocation.Any)
        {
            var comHands = inventory.GetComponent<HumanHandsComponent>(ComponentFamily.Hands);
            var comEquip = inventory.GetComponent<EquipmentComponent>(ComponentFamily.Equipment);
            var comInv = inventory.GetComponent<InventoryComponent>(ComponentFamily.Inventory);

            if ((location == InventoryLocation.Inventory) && comInv != null)
            {
                if (comInv.AddEntity(user, toAdd))
                {
                    //Do sprite stuff and attaching
                    return true;
                }
            }
            else if ((location == InventoryLocation.HandLeft || location == InventoryLocation.HandRight) && comHands != null)
            {
                if (comHands.AddEntity(user, toAdd, location))
                {
                    //Do sprite stuff and attaching
                    toAdd.RemoveComponent(ComponentFamily.Mover);
                    toAdd.AddComponent(ComponentFamily.Mover, EntityManager.ComponentFactory.GetComponent<SlaveMoverComponent>());
                    toAdd.GetComponent<SlaveMoverComponent>(ComponentFamily.Mover).Attach(inventory);
                    if (toAdd.HasComponent(ComponentFamily.Renderable) && inventory.HasComponent(ComponentFamily.Renderable))
                    {
                        toAdd.GetComponent<IRenderableComponent>(ComponentFamily.Renderable).SetMaster(inventory);
                    }
                    toAdd.GetComponent<BasicItemComponent>(ComponentFamily.Item).HandlePickedUp(inventory, location);
                    return true;
                }
            }
            else if ((location == InventoryLocation.Equipment || location == InventoryLocation.Any) && comEquip != null)
            {
                if (comEquip.AddEntity(user, toAdd))
                {
                    EquippableComponent eqCompo = toAdd.GetComponent<EquippableComponent>(ComponentFamily.Equippable);
                    eqCompo.currentWearer = user;
                    //Do sprite stuff and attaching.
                    return true;
                }
            }     
            else if (location == InventoryLocation.Any)
            {
                //Do sprite stuff and attaching.
                bool done = false;

                if (comInv != null)
                    done = comInv.AddEntity(user, toAdd);

                if (comEquip != null && !done)
                    done = comEquip.AddEntity(user, toAdd);

                if (comHands != null && !done)
                    done = comHands.AddEntity(user, toAdd, location);

                return done;
            }

            return false;
        }
        public override ComponentReplyMessage RecieveMessage(object sender, ComponentMessageType type,
                                                             params object[] list)
        {
            ComponentReplyMessage reply = base.RecieveMessage(sender, type, list);

            if (sender == this) //Don't listen to our own messages!
                return ComponentReplyMessage.Empty;

            switch (type)
            {
                case ComponentMessageType.MoveDirection:
                    if (!IsInHand)
                        break;
                    SetDrawDepth(DrawDepth.HeldItems);
                    switch ((Direction) list[0])
                    {
                        case Direction.North:
                            if (SpriteExists(basename + "_inhand_back"))
                                SetSpriteByKey(basename + "_inhand_back");
                            else
                                SetSpriteByKey(basename + "_inhand");
                            if (holdingHand == InventoryLocation.HandLeft)
                                HorizontalFlip = false;
                            else
                                HorizontalFlip = true;
                            break;
                        case Direction.South:
                            SetSpriteByKey(basename + "_inhand");
                            if (holdingHand == InventoryLocation.HandLeft)
                                HorizontalFlip = true;
                            else
                                HorizontalFlip = false;
                            break;
                        case Direction.East:
                            if (holdingHand == InventoryLocation.HandLeft)
                                SetDrawDepth(DrawDepth.FloorObjects);
                            else
                                SetDrawDepth(DrawDepth.HeldItems);
                            SetSpriteByKey(basename + "_inhand_side");
                            HorizontalFlip = true;
                            break;
                        case Direction.West:
                            if (holdingHand == InventoryLocation.HandRight)
                                SetDrawDepth(DrawDepth.FloorObjects);
                            else
                                SetDrawDepth(DrawDepth.HeldItems);
                            SetSpriteByKey(basename + "_inhand_side");
                            HorizontalFlip = false;
                            break;
                        case Direction.NorthEast:
                            if (SpriteExists(basename + "_inhand_back"))
                                SetSpriteByKey(basename + "_inhand_back");
                            else
                                SetSpriteByKey(basename + "_inhand");
                            if (holdingHand == InventoryLocation.HandLeft)
                                HorizontalFlip = false;
                            else
                                HorizontalFlip = true;
                            break;
                        case Direction.NorthWest:
                            if (SpriteExists(basename + "_inhand_back"))
                                SetSpriteByKey(basename + "_inhand_back");
                            else
                                SetSpriteByKey(basename + "_inhand");
                            if (holdingHand == InventoryLocation.HandLeft)
                                HorizontalFlip = false;
                            else
                                HorizontalFlip = true;
                            break;
                        case Direction.SouthEast:
                            SetSpriteByKey(basename + "_inhand");
                            if (holdingHand == InventoryLocation.HandRight)
                                HorizontalFlip = false;
                            else
                                HorizontalFlip = true;
                            break;
                        case Direction.SouthWest:
                            SetSpriteByKey(basename + "_inhand");
                            if (holdingHand == InventoryLocation.HandRight)
                                HorizontalFlip = false;
                            else
                                HorizontalFlip = true;
                            break;
                    }
                    break;
                case ComponentMessageType.Dropped:
                    SetSpriteByKey(basename);
                    IsInHand = false;
                    SetDrawDepth(DrawDepth.FloorObjects);
                    holdingHand = InventoryLocation.None;
                    break;
                case ComponentMessageType.PickedUp:
                    IsInHand = true;
                    holdingHand = (InventoryLocation)list[0];
                    break;
                case ComponentMessageType.SetBaseName:
                    basename = (string) list[0];
                    break;
            }

            return reply;
        }
 private Hand inventoryLocationToHand(InventoryLocation location)
 {
     if(location == InventoryLocation.HandLeft)
         return Hand.Left;
     if(location == InventoryLocation.HandRight)
         return Hand.Right;
     return Hand.None;
 }
        public bool RemoveEntity(Entity user, Entity inventory, Entity toRemove, InventoryLocation location = InventoryLocation.Any)
        {
            var comHands = inventory.GetComponent<HumanHandsComponent>(ComponentFamily.Hands);
            var comEquip = inventory.GetComponent<EquipmentComponent>(ComponentFamily.Equipment);
            var comInv = inventory.GetComponent<InventoryComponent>(ComponentFamily.Inventory);

            if (location == InventoryLocation.Any)
            {
                return RemoveEntity(user, inventory, toRemove, GetEntityLocationInEntity(inventory, toRemove));
            }

            if ((location == InventoryLocation.Inventory) && comInv != null)
            {
                if (comInv.RemoveEntity(user, toRemove))
                {
                    //Do sprite stuff and detaching
                    return true;
                }
            }
            else if ((location == InventoryLocation.HandLeft || location == InventoryLocation.HandRight) && comHands != null)
            {
                if (comHands.RemoveEntity(user, toRemove))
                {
                    // TODO Find a better way
                    FreeMovementAndSprite(toRemove);
                    toRemove.SendMessage(this, ComponentMessageType.Dropped);
                    return true;
                }
            }
            else if ((location == InventoryLocation.Equipment) && comEquip != null)
            {
                if (comEquip.RemoveEntity(user, toRemove))
                {
                    //Do sprite stuff and detaching
                    EquippableComponent eqCompo = toRemove.GetComponent<EquippableComponent>(ComponentFamily.Equippable);
                    if(eqCompo != null) eqCompo.currentWearer = null;
                    FreeMovementAndSprite(toRemove);
                    // TODO Find a better way
                    toRemove.SendMessage(this, ComponentMessageType.ItemUnEquipped);
                    return true;
                }
            }

            return false;
        }
 public void HandleDropped()
 {
     CurrentHolder = null;
     HoldingHand = InventoryLocation.None;
 }
 private void SwitchHandsTo(InventoryLocation hand)
 {
     CurrentHand = hand;
     Owner.SendDirectedComponentNetworkMessage(this, NetDeliveryMethod.ReliableOrdered, null,
                                               ComponentMessageType.ActiveHandChanged, hand);
 }
        public bool CanAddEntity(Entity actor, Entity toAdd, InventoryLocation location = InventoryLocation.Any)
        {
            if (containedEntities.Contains(toAdd))
            {
                return false;
            }

            // Todo check if inventory is full
            return true;
        }
 /// <summary>
 /// Get the entity in the specified hand
 /// </summary>
 /// <param name="hand"></param>
 /// <returns></returns>
 public Entity GetEntity(InventoryLocation hand)
 {
     if (!IsEmpty(hand))
         return Handslots[hand];
     else
         return null;
 }
 /// <summary>
 /// Set the entity in the specified hand
 /// </summary>
 /// <param name="hand"></param>
 /// <param name="entity"></param>
 private void SetEntity(InventoryLocation hand, Entity entity)
 {
     if (entity != null && IsEmpty(hand))
     {
         Handslots.Add(hand, entity);
         //Owner.SendComponentNetworkMessage(this, Lidgren.Network.NetDeliveryMethod.ReliableOrdered, null, ComponentMessageType.EntityChanged, entity.Uid, hand); Maybe for later use?
     }
 }
        /// <summary>
        /// Put the specified entity in the specified hand
        /// </summary>
        /// <param name="entity"></param>
        private void Pickup(Entity entity, InventoryLocation hand)
        {
            if (entity != null && IsEmpty(hand))
            {
                RemoveFromOtherComps(entity);

                SetEntity(hand, entity);
                Owner.SendDirectedComponentNetworkMessage(this, NetDeliveryMethod.ReliableOrdered, null,
                                                          ComponentMessageType.HandsPickedUpItem, entity.Uid, hand);
                entity.SendMessage(this, ComponentMessageType.PickedUp, Owner, hand);
            }
        }
 public void SendDropFromHand(InventoryLocation hand)
 {
     Owner.SendComponentNetworkMessage(this, NetDeliveryMethod.ReliableOrdered,
                                       ComponentMessageType.DropItemInHand, hand);
 }
 /// <summary>
 /// Drop an item from a hand.
 /// </summary>
 /// <param name="hand"></param>
 private void Drop(InventoryLocation hand)
 {
     if (!IsEmpty(hand))
     {
         GetEntity(hand).SendMessage(this, ComponentMessageType.Dropped);
         Owner.SendDirectedComponentNetworkMessage(this, NetDeliveryMethod.ReliableOrdered, null,
                                                   ComponentMessageType.HandsDroppedItem, GetEntity(hand).Uid,
                                                   hand);
         Handslots.Remove(hand);
     }
 }
 private void SwitchHandTo(InventoryLocation hand)
 {
     CurrentHand = hand;
 }
 /// <summary>
 /// Check if the specified hand is empty
 /// </summary>
 /// <param name="hand"></param>
 /// <returns></returns>
 public bool IsEmpty(InventoryLocation hand)
 {
     if (Handslots.ContainsKey(hand) && Handslots[hand] != null)
         return false;
     return true;
 }
 public HandsComponentState(InventoryLocation _ActiveHand, Dictionary<InventoryLocation, int?> _Slots)
     : base(ComponentFamily.Hands)
 {
     ActiveHand = _ActiveHand;
     Slots = _Slots;
 }
        public bool AddEntity(Entity user, Entity inventory, Entity toAdd, InventoryLocation location = InventoryLocation.Any)
        {
            if (EntityIsInEntity(inventory, toAdd))
            {
                RemoveEntity(user, inventory, toAdd, InventoryLocation.Any);
            }
            var comHands = inventory.GetComponent<HumanHandsComponent>(ComponentFamily.Hands);
            var comEquip = inventory.GetComponent<EquipmentComponent>(ComponentFamily.Equipment);
            var comInv = inventory.GetComponent<InventoryComponent>(ComponentFamily.Inventory);

            if ((location == InventoryLocation.Inventory) && comInv != null)
            {
                if (comInv.CanAddEntity(user, toAdd))
                {
                    HideEntity(toAdd);
                    return comInv.AddEntity(user, toAdd);
                }
            }
            else if ((location == InventoryLocation.HandLeft || location == InventoryLocation.HandRight) && comHands != null)
            {
                if (comHands.CanAddEntity(user, toAdd, location))
                {
                    comHands.AddEntity(user, toAdd, location);
                    ShowEntity(toAdd);
                    //Do sprite stuff and attaching
                    EnslaveMovementAndSprite(inventory, toAdd);
                    toAdd.GetComponent<BasicItemComponent>(ComponentFamily.Item).HandlePickedUp(inventory, location);
                    // TODO Find a better way
                    toAdd.SendMessage(this, ComponentMessageType.PickedUp);
                    return true;
                }
            }
            else if ((location == InventoryLocation.Equipment || location == InventoryLocation.Any) && comEquip != null)
            {
                if (comEquip.CanAddEntity(user, toAdd))
                {
                    comEquip.AddEntity(user, toAdd);
                    ShowEntity(toAdd);
                    EnslaveMovementAndSprite(inventory, toAdd);
                    EquippableComponent eqCompo = toAdd.GetComponent<EquippableComponent>(ComponentFamily.Equippable);
                    eqCompo.currentWearer = user;
                    toAdd.SendMessage(this, ComponentMessageType.ItemEquipped);
                    //Do sprite stuff and attaching.
                    return true;
                }
            }     
            else if (location == InventoryLocation.Any)
            {
                //Do sprite stuff and attaching.
                bool done = false;

                if (comInv != null)
                    done = comInv.AddEntity(user, toAdd);

                if (comEquip != null && !done)
                    done = comEquip.AddEntity(user, toAdd);

                if (comHands != null && !done)
                    done = comHands.AddEntity(user, toAdd, location);

                return done;
            }

            return false;
        }
 public void HandlePickedUp(Entity entity, InventoryLocation holdingHand)
 {
     CurrentHolder = entity;
     HoldingHand = holdingHand;
     /*Owner.AddComponent(ComponentFamily.Mover,
                        Owner.EntityManager.ComponentFactory.GetComponent("SlaveMoverComponent"));
     Owner.SendMessage(this, ComponentMessageType.SlaveAttach, entity.Uid);
     Owner.SendDirectedComponentNetworkMessage(this, NetDeliveryMethod.ReliableOrdered, null,
                                               ItemComponentNetMessage.PickedUp, entity.Uid, holdingHand);*/
 }
 public bool RemoveEntity(Entity actor, Entity toRemove, InventoryLocation location = InventoryLocation.Any)
 {
     if (containedEntities.Contains(toRemove))
     {
         containedEntities.Remove(toRemove);
         return true;
     }
     else
     {
         return false;
     }
 }
Beispiel #57
0
        private void SendSwitchHandTo(InventoryLocation hand)
        {
            var _playerManager = IoCManager.Resolve<IPlayerManager>();

            Entity playerEntity = _playerManager.ControlledEntity;
            var equipComponent = (HumanHandsComponent) playerEntity.GetComponent(ComponentFamily.Hands);
            equipComponent.SendSwitchHands(hand);
        }
 public bool RemoveEntity(Entity actor, Entity toRemove, InventoryLocation location = InventoryLocation.Any)
 {
     if (Handslots.Any(x => x.Value == toRemove))
     {
         Handslots[Handslots.First(x => x.Value == toRemove).Key] = null;
         return true;
     }
     else
     {
         return false;
     }
 }
 public bool AddEntity(Entity actor, Entity toAdd, InventoryLocation location = InventoryLocation.Any)
 {
     if (!CanAddEntity(actor, toAdd, location))
     {
         return false;
     }
     else
     {
         containedEntities.Add(toAdd);
         return true;
     }
 }
 public bool AddEntity(Entity actor, Entity toAdd, InventoryLocation location = InventoryLocation.Any)
 {
     if (Handslots.Any(x => x.Value == toAdd))
     {
         return false;
     }
     else
     {
         if (location == InventoryLocation.Any)
         {
             if (Handslots[CurrentHand] != null)
                 return false;
             else
             {
                 Handslots[CurrentHand] = toAdd;
             }
         }
         else
         {
             if (Handslots[location] == null)
             {
                 Handslots[location] = toAdd;
             }
             else
             {
                 return false;
             }
         }
         return true;
     }
 }