/// <summary> /// Drop an Item. This method is called by an InteractableChets's Animator. /// </summary> private void DropItem() { Item item = itemGenerator.GenerateItem(); ICommand dropItemCommand = new DropItemCommand(itemDropper, item, transform.position); commandProcessor.ProcessCommand(dropItemCommand); }
public void Die() { if (!dontDropItem) { Item item = itemGenerator.GenerateItem(levelToAdd); Debug.Log(gameObject.name + " died and dropped an item '" + item.Name + "'! Tier Increased by: " + levelToAdd); ICommand dropItemCommand = new DropItemCommand(itemDropper, item, transform.position); commandProcessor.ProcessCommand(dropItemCommand); } GetComponent <EnemyController>().isKilled(); }
public static void DropItem(int itemId, int containerIndex) { Log($"Request PickupItem item: {itemId}"); var pickupItemCommand = new DropItemCommand { PlayerId = Director.Player.Id, ItemId = itemId, ContainerId = containerIndex }; IssueCommand(pickupItemCommand); }
public void Die() { for (int i = 0; i < maxItemsToDrop; ++i) { if (Random.Range(0f, 1f) < baseporb) { baseporb -= 0.1f; Item item = itemGenerator.GenerateItem(levelToAdd); Debug.Log(gameObject.name + " died and dropped an item '" + item.Name + "'! Tier Increased by: " + levelToAdd); ICommand dropItemCommand = new DropItemCommand(itemDropper, item, transform.position + new Vector3(Random.Range(-0.75f, 0.75f), 0, Random.Range(-0.75f, 0.75f))); commandProcessor.ProcessCommand(dropItemCommand); } } GetComponent <IActivatableBoss>().IsKilled(); }
public InventoryScreen(NamelessGame game) { this.game = game; Panel = new Panel() { Width = game.GetActualWidth(), Height = game.GetActualCharacterHeight(), HorizontalAlignment = HorizontalAlignment.Right, VerticalAlignment = VerticalAlignment.Top }; ReturnToGame = new ImageTextButton() { GridRow = 1, GridColumn = 1, ContentHorizontalAlignment = HorizontalAlignment.Center, ContentVerticalAlignment = VerticalAlignment.Center, Text = "Back", VerticalAlignment = VerticalAlignment.Bottom, HorizontalAlignment = HorizontalAlignment.Right, Width = 200, Height = 50 }; ReturnToGame.Click += OnClickReturnToGame; var grid = new Grid() { VerticalAlignment = VerticalAlignment.Stretch, ColumnSpacing = 3, RowSpacing = 2 }; grid.RowsProportions.Add(new Proportion(ProportionType.Fill)); grid.RowsProportions.Add(new Proportion(ProportionType.Pixels, 50)); EquipmentBox = new Table() { GridColumn = 0, GridRow = 0, HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Stretch, BorderThickness = new Thickness(1), Border = new SolidBrush(Color.White) }; ItemBox = new Table() { GridColumn = 1, GridRow = 0, HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Stretch, BorderThickness = new Thickness(1), Border = new SolidBrush(Color.White) }; //FillItems(game); grid.Widgets.Add(EquipmentBox); grid.Widgets.Add(ItemBox); grid.Widgets.Add(ReturnToGame); Panel.Widgets.Add(grid); game.Desktop.Widgets.Add(Panel); SelectedTable = ItemBox; ItemChoiceDialog = new ChoiceDialog( new ChoiceOption() { Id = ItemDialogActions.Equip, Text = "Equip" }, new ChoiceOption() { Id = ItemDialogActions.Drop, Text = "Drop" }, new ChoiceOption() { Id = ItemDialogActions.Cancel, Text = "Cancel" } ); ItemChoiceDialog.Title = "Item commands"; EquipmentChoiceDialog = new ChoiceDialog( new ChoiceOption() { Id = EquipmentDialogActions.Unequip, Text = "Unequip" }, new ChoiceOption() { Id = EquipmentDialogActions.Drop, Text = "Drop" }, new ChoiceOption() { Id = EquipmentDialogActions.Cancel, Text = "Cancel" } ); EquipmentChoiceDialog.Title = "Equipment commands"; ItemBox.OnItemClick += (TableItem selectedItem) => { int selectedIndex = ItemBox.Items.IndexOf(selectedItem); if (selectedIndex > 0) { this.SelectedItem = selectedItem; var itemEntity = (IEntity)selectedItem.Tag; FillItemChoiceDialog(itemEntity); OpenDialog(ItemChoiceDialog, game); } }; EquipmentBox.OnItemClick += (TableItem selectedItem) => { int selectedIndex = EquipmentBox.Items.IndexOf(selectedItem); if (selectedIndex > 0) { this.SelectedItem = selectedItem; OpenDialog(EquipmentChoiceDialog, game); } }; EquipmentChoiceDialog.OptionsTable.OnItemClick += (TableItem selectedItemOptions) => { if (SelectedItem.Tag == null) { Actions.Add((InventoryScreenSystem invScreenSystem, NamelessGame namelessGame) => { CloseDialog(EquipmentChoiceDialog); }); return; } var playerEntity = game.PlayerEntity; var slot = (Slot)SelectedItem.Tag; var itemsHolder = playerEntity.GetComponentOfType <ItemsHolder>(); var equipment = playerEntity.GetComponentOfType <EquipmentSlots>(); var equipmentItem = equipment.Slots.First(x => x.Item1 == slot).Item2.Equipment; if (equipmentItem == null) { Actions.Add((InventoryScreenSystem invScreenSystem, NamelessGame namelessGame) => { CloseDialog(EquipmentChoiceDialog); }); return; } var chosenItem = (ChoiceOption)selectedItemOptions.Tag; var dialogActions = (EquipmentDialogActions)chosenItem.Id; switch (dialogActions) { case EquipmentDialogActions.Drop: Actions.Add((InventoryScreenSystem invScreenSystem, NamelessGame namelessGame) => { equipment.TakeOff(equipmentItem); var position = playerEntity.GetComponentOfType <Position>(); var command = new DropItemCommand(new List <IEntity>() { game.GetEntity(equipment.ParentEntityId) }, itemsHolder, position.Point); namelessGame.Commander.EnqueueCommand(command); invScreenSystem.ScheduleUpdate(); }); break; case EquipmentDialogActions.Unequip: Actions.Add((InventoryScreenSystem invScreenSystem, NamelessGame namelessGame) => { equipment.TakeOff(equipmentItem); invScreenSystem.ScheduleUpdate(); }); break; case EquipmentDialogActions.Cancel: break; default: break; } Actions.Add((InventoryScreenSystem invScreenSystem, NamelessGame namelessGame) => { CloseDialog(EquipmentChoiceDialog); }); }; ItemChoiceDialog.Closed += (sender, args) => { SelectTable(ItemBox); dialogOpened = false; }; ItemChoiceDialog.OptionsTable.OnItemClick += (TableItem selectedItemOptions) => { var playerEntity = game.PlayerEntity; var itemEntity = (IEntity)SelectedItem.Tag; var itemsHolder = playerEntity.GetComponentOfType <ItemsHolder>(); var equipment = playerEntity.GetComponentOfType <EquipmentSlots>(); var equipmentItem = itemEntity.GetComponentOfType <Equipment>(); var chosenItem = (ChoiceOption)selectedItemOptions.Tag; ItemDialogActions itemDialogActions = (ItemDialogActions)chosenItem.Id; switch (itemDialogActions) { case ItemDialogActions.DropAmount: { AmountDialog = new AmountDialog(); AmountDialog.ShowModal(game.Desktop); AmountDialog.Amount.OnTouchDown(); AmountDialog.Closed += (sender, args) => { if (AmountDialog.Result) { var position = playerEntity.GetComponentOfType <Position>(); var amount = AmountDialog.Amount.Text == null ? 0 : int.Parse(AmountDialog.Amount.Text); var itemComponent = itemEntity.GetComponentOfType <Item>(); if (amount >= itemComponent.Amount) { CloseDialog(ItemChoiceDialog); Actions.Add((InventoryScreenSystem invScreenSystem, NamelessGame namelessGame) => { var command = new DropItemCommand(new List <IEntity>() { itemEntity }, itemsHolder, position.Point); namelessGame.Commander.EnqueueCommand(command); invScreenSystem.ScheduleUpdate(); }); } else if (amount < 1) { } else { var clonedEntity = itemEntity.CloneEntity(); //game.EntitiesToAdd.Add(clonedEntity); var clonedItemComponent = clonedEntity.GetComponentOfType <Item>(); itemComponent.Amount -= amount; clonedItemComponent.Amount = amount; Actions.Add((InventoryScreenSystem invScreenSystem, NamelessGame namelessGame) => { CloseDialog(ItemChoiceDialog); var command = new DropItemCommand(new List <IEntity>() { clonedEntity }, itemsHolder, position.Point); namelessGame.Commander.EnqueueCommand(command); invScreenSystem.ScheduleUpdate(); }); } } AmountDialog = null; }; } break; case ItemDialogActions.Drop: { Actions.Add((InventoryScreenSystem invScreenSystem, NamelessGame namelessGame) => { var position = playerEntity.GetComponentOfType <Position>(); var command = new DropItemCommand(new List <IEntity>() { itemEntity }, itemsHolder, position.Point); namelessGame.Commander.EnqueueCommand(command); invScreenSystem.ScheduleUpdate(); CloseDialog(ItemChoiceDialog); }); } break; case ItemDialogActions.Equip: Actions.Add((InventoryScreenSystem invScreenSystem, NamelessGame namelessGame) => { List <Slot> slotsEquipTo; slotsEquipTo = (List <Slot>)chosenItem.Data; equipment.Equip(equipmentItem, slotsEquipTo); invScreenSystem.ScheduleUpdate(); CloseDialog(ItemChoiceDialog); }); break; case ItemDialogActions.Cancel: Actions.Add((InventoryScreenSystem invScreenSystem, NamelessGame namelessGame) => { CloseDialog(ItemChoiceDialog); }); break; default: break; } }; EquipmentChoiceDialog.Closed += (sender, args) => { SelectTable(EquipmentBox); dialogOpened = false; }; OnCloseDialog += () => { FillItems(this.game); }; }