예제 #1
0
        ActionState ProcessAction(GetItemAction action)
        {
            if (this.ActionTicksUsed == 1)
            {
                this.ActionTotalTicks = 1;
            }

            if (this.Environment == null)
            {
                SendFailReport(new GetItemActionReport(this, null), "no environment");
                return(ActionState.Fail);
            }

            if (this.ActionTicksUsed < this.ActionTotalTicks)
            {
                return(ActionState.Ok);
            }

            var item = this.World.FindObject <ItemObject>(action.ItemID);

            if (CheckGetItemAction(item) == false)
            {
                return(ActionState.Fail);
            }

            if (item.MoveTo(this) == false)
            {
                SendFailReport(new GetItemActionReport(this, item), "failed to move");
                return(ActionState.Fail);
            }

            SendReport(new GetItemActionReport(this, item));

            return(ActionState.Done);
        }
예제 #2
0
        ActionState ProcessAction(GetItemAction action)
        {
            if (this.ActionTicksUsed == 1)
                this.ActionTotalTicks = 1;

            if (this.Environment == null)
            {
                SendFailReport(new GetItemActionReport(this, null), "no environment");
                return ActionState.Fail;
            }

            if (this.ActionTicksUsed < this.ActionTotalTicks)
                return ActionState.Ok;

            var item = this.World.FindObject<ItemObject>(action.ItemID);

            if (CheckGetItemAction(item) == false)
                return ActionState.Fail;

            if (item.MoveTo(this) == false)
            {
                SendFailReport(new GetItemActionReport(this, item), "failed to move");
                return ActionState.Fail;
            }

            SendReport(new GetItemActionReport(this, item));

            return ActionState.Done;
        }
예제 #3
0
        static void HandleGetItem(string str)
        {
            var living = GameData.Data.FocusedObject;

            var obs = living.Environment.GetContents(living.Location).OfType <ItemObject>();

            if (obs.Any() == false)
            {
                return;
            }

            var dlg = new ItemSelectorDialog();

            dlg.Owner       = App.Current.MainWindow;
            dlg.DataContext = obs;
            dlg.Title       = "Get Item";

            var ret = dlg.ShowDialog();

            if (ret.HasValue && ret.Value == true)
            {
                var ob = (ItemObject)dlg.SelectedItem;

                var action = new GetItemAction(ob);
                action.GUID = new ActionGUID(living.World.PlayerID, 0);
                living.RequestAction(action);
            }
        }
예제 #4
0
        protected override GameAction PrepareNextActionOverride(out JobStatus progress)
        {
            var action = new GetItemAction(m_item);

            progress = JobStatus.Ok;
            return(action);
        }
예제 #5
0
    public void Use(Item item)
    {
        currentItem = item;
        GetItemAction(item.Name)();
        InventoryManager.Instance.AfterItemUse(item);

        switch (item.Name)
        {
        case ItemNames.Ammo:
            AudioManager.Instance.slingAmmoItemUse.Play();
            break;

        default:
            AudioManager.Instance.potionUse.Play();
            break;
        }
    }
예제 #6
0
        private void GetButton_Click(object sender, RoutedEventArgs e)
        {
            var living = (LivingObject)this.DataContext;

            var obs = living.Environment.GetContents(living.Location).OfType<ItemObject>();

            var dlg = new ItemSelectorDialog();
            dlg.DataContext = obs;
            var b = dlg.ShowDialog();

            if (!b.HasValue || b.Value == false)
                return;

            var action = new GetItemAction((ItemObject)dlg.SelectedItem);
            AddAction(action);
        }
예제 #7
0
        private void GetButton_Click(object sender, RoutedEventArgs e)
        {
            var living = (LivingObject)this.DataContext;

            var obs = living.Environment.GetContents(living.Location).OfType <ItemObject>();

            var dlg = new ItemSelectorDialog();

            dlg.DataContext = obs;
            var b = dlg.ShowDialog();

            if (!b.HasValue || b.Value == false)
            {
                return;
            }

            var action = new GetItemAction((ItemObject)dlg.SelectedItem);

            AddAction(action);
        }
예제 #8
0
        private static bool ResolveGetItem(GetItemAction action, EncounterState state)
        {
            var actor = state.GetEntityById(action.ActorId);
            var inventoryComponent = actor.GetComponent <InventoryComponent>();
            var actorPosition      = actor.GetComponent <PositionComponent>().EncounterPosition;
            var item = state.EntitiesAtPosition(actorPosition.X, actorPosition.Y)
                       .FirstOrDefault(e => e.GetComponent <StorableComponent>() != null);

            if (item == null)
            {
                state.LogMessage("No item found!", failed: true);
                return(false);
            }
            else if (item.GetComponent <UsableComponent>() != null && item.GetComponent <UsableComponent>().UseOnGet)
            {
                // The responsibility for removing/not removing the usable from the EncounterState is in the usage code.
                bool successfulUsage = ResolveUse(new UseAction(actor.EntityId, item.EntityId, false), state);
                if (!successfulUsage)
                {
                    GD.PrintErr(string.Format("Item {0} was not successfully used after being picked up!", item.EntityName));
                }
                return(true);
            }
            else if (!inventoryComponent.CanFit(item))
            {
                state.LogMessage(string.Format("[b]{0}[/b] can't fit the [b]{1}[/b] in its inventory!",
                                               actor.EntityName, item.EntityName), failed: true);
                return(false);
            }
            else
            {
                state.RemoveEntity(item);
                actor.GetComponent <InventoryComponent>().AddEntity(item);

                var logMessage = string.Format("[b]{0}[/b] has taken the [b]{1}[/b]", actor.EntityName, item.EntityName);
                state.LogMessage(logMessage);
                return(true);
            }
        }
예제 #9
0
 public void InstantlyUse(Item item)
 {
     currentItem = item;
     GetItemAction(item.Name)();
 }
예제 #10
0
        static void HandleGetItem(string str)
        {
            var living = GameData.Data.FocusedObject;

            var obs = living.Environment.GetContents(living.Location).OfType<ItemObject>();

            if (obs.Any() == false)
                return;

            var dlg = new ItemSelectorDialog();
            dlg.Owner = App.Current.MainWindow;
            dlg.DataContext = obs;
            dlg.Title = "Get Item";

            var ret = dlg.ShowDialog();

            if (ret.HasValue && ret.Value == true)
            {
                var ob = (ItemObject)dlg.SelectedItem;

                var action = new GetItemAction(ob);
                action.GUID = new ActionGUID(living.World.PlayerID, 0);
                living.RequestAction(action);
            }
        }
        void GetItemHandler(object sender, ExecutedRoutedEventArgs e)
        {
            var living = m_mainWindow.FocusedObject;

            if (living == null)
                return;

            var obs = living.Environment.GetContents(living.Location).OfType<ItemObject>();

            if (obs.Any() == false)
                return;

            var dlg = new ItemSelectorDialog();
            dlg.Owner = m_mainWindow;
            dlg.DataContext = obs;
            dlg.Title = "Get Item";

            var ret = dlg.ShowDialog();

            if (ret.HasValue && ret.Value == true)
            {
                var ob = dlg.SelectedItem;

                var action = new GetItemAction(ob);
                action.MagicNumber = 1;
                living.RequestAction(action);
            }

            e.Handled = true;
        }
예제 #12
0
        protected void PickUp(Entity item, int amount = 1)
        {
            var action = new GetItemAction(Entity, item, amount);

            action.OnProcess();
        }
예제 #13
0
 protected override GameAction PrepareNextActionOverride(out JobStatus progress)
 {
     var action = new GetItemAction(m_item);
     progress = JobStatus.Ok;
     return action;
 }