示例#1
0
        public DepositLifetimeModule(IStaticObjectManager staticObjectManager, IStaticObject parentStaticObject)
        {
            _staticObjectManager = staticObjectManager ?? throw new ArgumentNullException(nameof(staticObjectManager));
            _parentStaticObject  = parentStaticObject ?? throw new ArgumentNullException(nameof(parentStaticObject));

            _depositModule   = _parentStaticObject.GetModule <IPropDepositModule>();
            _containerModule = _parentStaticObject.GetModule <IPropContainer>();

            _depositModule.Mined          += DepositModule_Mined;
            _containerModule.ItemsRemoved += ContainerModule_ItemsRemoved;
        }
示例#2
0
        private static IActorTask TakeAllFromContainerTask(IActor actor, IStaticObject container)
        {
            var inventoryTransfer = new PropTransfer(actor.Person.GetModule <IInventoryModule>(),
                                                     container.GetModule <IPropContainer>().Content.CalcActualItems(),
                                                     System.Array.Empty <IProp>());

            var containerTransfer = new PropTransfer(container.GetModule <IPropContainer>().Content,
                                                     System.Array.Empty <IProp>(),
                                                     container.GetModule <IPropContainer>().Content.CalcActualItems());

            return(new TransferPropsTask(actor, new[] { inventoryTransfer, containerTransfer }));
        }
示例#3
0
        public static TStaticObjectModule GetModule <TStaticObjectModule>(this IStaticObject staticObject)
            where TStaticObjectModule : IStaticObjectModule
        {
            if (staticObject is null)
            {
                throw new ArgumentNullException(nameof(staticObject));
            }

            return(staticObject.GetModule <TStaticObjectModule>(typeof(TStaticObjectModule).Name));
        }
示例#4
0
        public void MineDeposit(IStaticObject deposit, IMineDepositMethod method)
        {
            if (deposit is null)
            {
                throw new ArgumentNullException(nameof(deposit));
            }

            if (method is null)
            {
                throw new ArgumentNullException(nameof(method));
            }

            var openResult = method.TryMine(deposit.GetModule <IPropDepositModule>());

            DoMineDeposit(deposit, openResult);
        }
示例#5
0
        public void OpenContainer(IStaticObject container, IOpenContainerMethod method)
        {
            if (container is null)
            {
                throw new ArgumentNullException(nameof(container));
            }

            if (method is null)
            {
                throw new ArgumentNullException(nameof(method));
            }

            var openResult = method.TryOpen(container.GetModule <IPropContainer>());

            DoOpenContainer(container, openResult);
        }
示例#6
0
        private void InitContainerContent(IStaticObject container)
        {
            _container = container;

            var currentContainerItemList = new List <InventoryUiItem>();

            var props = container.GetModule <IPropContainer>().Content.CalcActualItems().Take(8).ToArray();

            for (var itemIndex = 0; itemIndex < props.Length; itemIndex++)
            {
                var prop = props[itemIndex];

                var relativeY  = itemIndex * (EQUIPMENT_ITEM_SIZE + EQUIPMENT_ITEM_SPACING);
                var buttonRect = new Rectangle(
                    ContentRect.Left,
                    ContentRect.Top + relativeY,
                    EQUIPMENT_ITEM_SIZE,
                    EQUIPMENT_ITEM_SIZE);

                var sid = prop.Scheme.Sid;
                if (string.IsNullOrEmpty(sid))
                {
                    Debug.Fail("All prop must have symbolic identifier (SID).");
                    sid = "EmptyPropIcon";
                }

                var propButton = new IconButton(
                    _uiContentStorage.GetButtonTexture(),
                    _uiContentStorage.GetPropIconLayers(sid).First(),
                    buttonRect);
                propButton.OnClick += ContainerPropButton_OnClick;

                var uiItem = new InventoryUiItem(propButton, prop, itemIndex, buttonRect);

                currentContainerItemList.Add(uiItem);
            }

            _currentContainerItems = currentContainerItemList.ToArray();
        }
示例#7
0
        public override IActorTask GetTask(IActor actor, ILogicStrategyData strategyData)
        {
            _staticObject = FindContainer(actor);

            if (_staticObject == null || !_staticObject.GetModule <IPropContainer>().Content.CalcActualItems().Any())
            {
                Complete = true;
                return(null);
            }

            var distance = _map.DistanceBetween(actor.Node, _staticObject.Node);

            if (distance <= 1)
            {
                return(TakeAllFromContainerTask(actor, _staticObject));
            }
            else
            {
                var storedMoveTask = _moveTask;
                var moveTask       = MoveToContainerTask(actor, _staticObject.Node, storedMoveTask);
                _moveTask = moveTask;
                return(moveTask);
            }
        }