コード例 #1
0
ファイル: GetItem.cs プロジェクト: jaenudin86/dwarrowdelf
        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
ファイル: GetItem.cs プロジェクト: tomba/dwarrowdelf
        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
ファイル: Rulebook.cs プロジェクト: MoyTW/SpaceDodgeRL
        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);
            }
        }
コード例 #11
0
        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
ファイル: ItemTestsHelper.cs プロジェクト: qmhoang/SKR
        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;
 }