You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
171 lines
5.0 KiB
171 lines
5.0 KiB
using Microsoft.AspNetCore.Components;
|
|
|
|
namespace BlazorApp1.Components
|
|
{
|
|
public partial class InventoryItem : ItemDisplay
|
|
{
|
|
[Parameter]
|
|
public int Index { get; set; }
|
|
|
|
[Parameter]
|
|
public Item Item { get; set; }
|
|
|
|
[Parameter]
|
|
public bool NoDrop { get; set; }
|
|
|
|
[Parameter]
|
|
public int nbElem { get; set; }
|
|
|
|
[CascadingParameter]
|
|
public Inventory Parent { get; set; }
|
|
|
|
|
|
public void setItem(Item item)
|
|
{
|
|
this.Item = item;
|
|
}
|
|
|
|
public void setNbElement(int nbElement)
|
|
{
|
|
this.nbElem = nbElement;
|
|
}
|
|
|
|
public void changeState()
|
|
{
|
|
StateHasChanged();
|
|
}
|
|
|
|
public Item getItem()
|
|
{
|
|
return Item;
|
|
}
|
|
|
|
public int getNbElement()
|
|
{
|
|
return nbElem;
|
|
}
|
|
|
|
public String getTypeID()
|
|
{
|
|
return "InventoryItem";
|
|
}
|
|
|
|
internal void OnDragEnter()
|
|
{
|
|
if (NoDrop)
|
|
{
|
|
return;
|
|
}
|
|
}
|
|
|
|
internal void OnDragLeave()
|
|
{
|
|
if (NoDrop)
|
|
{
|
|
return;
|
|
}
|
|
|
|
}
|
|
|
|
internal void OnDrop()
|
|
{
|
|
if (NoDrop)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (this.Item is not null)
|
|
{
|
|
if (this.Item.Equals(Parent.CurrentDragItem))
|
|
{
|
|
if (this.nbElem < this.Item.StackSize && Parent.CurrentEllement.getTypeID() == "ListItem")
|
|
{
|
|
this.nbElem++;
|
|
}
|
|
else if (this.nbElem + Parent.CurrentEllement.getNbElement() > this.Item.StackSize && Parent.CurrentEllement.getTypeID() == "InventoryItem")
|
|
{
|
|
int tmp = this.nbElem + Parent.CurrentEllement.getNbElement();
|
|
this.nbElem = this.Item.StackSize;
|
|
Parent.CurrentEllement.setNbElement(tmp - this.Item.StackSize);
|
|
}
|
|
else if (Parent.CurrentEllement.getTypeID() == "InventoryItem")
|
|
{
|
|
this.nbElem += Parent.CurrentEllement.getNbElement();
|
|
Parent.CurrentEllement.setNbElement(0);
|
|
Parent.CurrentEllement.setItem(null);
|
|
}
|
|
else
|
|
{
|
|
int indice = -1;
|
|
for (int i = 0; i < 40; i++)
|
|
{
|
|
if (this.Item.Equals(Parent.InventoryItems[i]) && this.nbElem < this.Item.StackSize) {
|
|
Parent.InventoryNbElems[i]++;
|
|
indice = -1;
|
|
break;
|
|
}
|
|
else if (Parent.InventoryItems[i] is null && indice == -1)
|
|
{
|
|
indice = i;
|
|
}
|
|
}
|
|
if (indice != -1)
|
|
{
|
|
Parent.InventoryItems[indice] = this.Item;
|
|
Parent.InventoryNbElems[indice] = 1;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (Parent.CurrentEllement.getTypeID() == "InventoryItem")
|
|
{
|
|
int tmp = this.nbElem;
|
|
this.nbElem = Parent.CurrentEllement.getNbElement();
|
|
Parent.CurrentEllement.setNbElement(tmp);
|
|
Item tmpI = this.Item;
|
|
this.Item = Parent.CurrentEllement.getItem();
|
|
Parent.CurrentEllement.setItem(tmpI);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Item tmp = this.Item;
|
|
int tmpNb = this.nbElem;
|
|
|
|
this.Item = Parent.CurrentDragItem;
|
|
this.nbElem = Parent.CurrentEllement.getNbElement();
|
|
|
|
if (Parent.CurrentEllement.getTypeID() == "InventoryItem")
|
|
{
|
|
InventoryItem invItem = (InventoryItem)Parent.CurrentEllement;
|
|
|
|
invItem.Item = tmp;
|
|
invItem.nbElem = tmpNb;
|
|
|
|
Parent.CurrentEllement = invItem;
|
|
}
|
|
else if (Parent.CurrentEllement.getTypeID() == "ListItem")
|
|
{
|
|
|
|
}
|
|
}
|
|
Parent.CurrentEllement.changeState();
|
|
StateHasChanged();
|
|
}
|
|
|
|
private void OnDragStart()
|
|
{
|
|
Parent.CurrentDragItem = this.Item;
|
|
Parent.CurrentEllement = this;
|
|
}
|
|
|
|
public int getIndex()
|
|
{
|
|
return Index;
|
|
}
|
|
}
|
|
|
|
}
|