Beispiel #1
0
        private void OnUnloadWeapon()
        {
            var selectionIsLoadedWeapon = selection?.Ammunition != null;
            var bothHandsAreEmpty = soldier.RightHand == null && soldier.LeftHand == null;
            var canUnloadWeapon = selectionIsLoadedWeapon && bothHandsAreEmpty;
            if (!canUnloadWeapon)
                return;
            if (!TryConsumeTimeUnits(8))
                return;

            soldier.LeftHand = new BattleItem
            {
                Item = selection.Ammunition,
                Ammunition = null,
                Rounds = selection.Rounds
            };

            soldier.RightHand = selection;
            selection.Ammunition = null;
            selection.Rounds = 0;
            selection = null;

            BattlescapeSoundEffect.Reload.Play();
        }
Beispiel #2
0
 private void TryLoadWeapon(BattleItem item)
 {
     if (!item.CanLoadWith(selection))
         return;
     if (!TryConsumeTimeUnits(15))
         return;
     item.Ammunition = (AmmunitionType) selection.Item;
     item.Rounds = selection.Rounds;
     selection = null;
     BattlescapeSoundEffect.Reload.Play();
 }
Beispiel #3
0
 private void ClickBattleItemRow(BattleItem[] items, InventoryLocation location, int column)
 {
     if (selection == null)
     {
         selectionSource = location;
         selection = SelectItem(items, column);
     }
     else
     {
         var dropLocation = GetDropLocation(items, column, selection);
         if (dropLocation == null)
             return;
         if (!TryConsumeTimeUnits(GetTransferTimeUnits(location)))
             return;
         items[dropLocation.Value] = selection;
         selection = null;
         BattlescapeSoundEffect.ItemDrop.Play();
     }
 }
Beispiel #4
0
        private BattleItem ClickHand(BattleItem item, InventoryLocation location)
        {
            if (selection == null && item == null)
                return null;
            if (selection != null && item != null)
            {
                TryLoadWeapon(item);
                return item;
            }
            if (item != null)
            {
                selection = item;
                selectionSource = location;
                return null;
            }

            if (!TryConsumeTimeUnits(GetTransferTimeUnits(location)))
                return null;
            var newItem = selection;
            selection = null;
            BattlescapeSoundEffect.ItemDrop.Play();
            return newItem;
        }
Beispiel #5
0
 private static BattleItem SelectItem(BattleItem[] items, int column)
 {
     foreach (var index in Enumerable.Range(0, items.Length))
     {
         var item = items[index];
         if (item == null)
             continue;
         if (column >= index && column < index + item.Width)
         {
             items[index] = null;
             return item;
         }
     }
     return null;
 }
Beispiel #6
0
        private void ClickBattleItemGrid(
			BattleItem[,] items,
			InventoryLocation location,
			int row,
			int column,
			Func<int, int, int, int, bool> canDropHere = null)
        {
            if (selection == null)
            {
                selectionSource = location;
                selection = SelectItem(items, row, column);
                if (location == InventoryLocation.Ground && selection != null)
                    ground.Remove(selection);
            }
            else
            {
                var dropLocation = GetDropLocation(items, row, column, selection);
                if (dropLocation == null)
                    return;
                var dropRow = dropLocation.Value.Y;
                var dropColumn = dropLocation.Value.X;
                if (canDropHere != null && !canDropHere(dropRow, dropColumn, selection.Width, selection.Height))
                    return;
                if (!TryConsumeTimeUnits(GetTransferTimeUnits(location)))
                    return;
                items[dropRow, dropColumn] = selection;
                if (location == InventoryLocation.Ground)
                    ground.Add(selection);
                selection = null;
                BattlescapeSoundEffect.ItemDrop.Play();
            }
        }
Beispiel #7
0
 private static int? GetDropLocation(BattleItem[] items, int column, BattleItem item)
 {
     if (item.Height > 1)
         return null;
     var width = item.Width;
     if (items[column] != null)
         return null;
     if (width == 1)
         return column;
     if (column > 0 && items[column - 1] == null)
         return column - 1;
     if (column + 1 < items.Length && items[column + 1] == null)
         return column;
     return null;
 }
Beispiel #8
0
 private static BattleItem SelectItem(BattleItem[,] items, int row, int column)
 {
     var target = GetClickTargets(items)[row, column];
     if (target == null)
         return null;
     var item = items[target.Value.Y, target.Value.X];
     items[target.Value.Y, target.Value.X] = null;
     return item;
 }
Beispiel #9
0
 private static Point?[,] GetClickTargets(BattleItem[,] items)
 {
     var rows = items.GetLength(0);
     var columns = items.GetLength(1);
     var targets = new Point?[rows, columns];
     foreach (var row in Enumerable.Range(0, rows))
     {
         foreach (var column in Enumerable.Range(0, columns))
         {
             var item = items[row, column];
             if (item == null)
                 continue;
             foreach (var rowOffset in Enumerable.Range(0, item.Height))
                 foreach (var columnOffset in Enumerable.Range(0, item.Width))
                     targets[row + rowOffset, column + columnOffset] = new Point { X = column, Y = row };
         }
     }
     return targets;
 }
Beispiel #10
0
 private static Point? GetDropLocation(BattleItem[,] items, int row, int column, BattleItem item)
 {
     var targets = GetClickTargets(items);
     var itemWidth = item.Width;
     var itemHeight = item.Height;
     var width = items.GetLength(1);
     var height = items.GetLength(0);
     foreach (var rowOffset in Enumerable.Range(0, itemHeight))
         foreach (var columnOffset in Enumerable.Range(0, itemWidth))
         {
             var dropRow = row - rowOffset;
             var dropColumn = column - columnOffset;
             if (CanDropHere(targets, dropRow, dropColumn, itemWidth, itemHeight, width, height))
                 return new Point { X = dropColumn, Y = dropRow };
         }
     return null;
 }
Beispiel #11
0
 private static void FillGroundView(BattleItem[,] groundView, List<BattleItem> items, int row, int column, int maxWidth, int maxHeight)
 {
     if (maxWidth == 0 || maxHeight == 0 || !items.Any())
         return;
     for (var width = maxWidth; width > 0; --width)
     {
         for (var height = maxHeight; height > 0; --height)
         {
             var matchingItem = items.FirstOrDefault(item => item.Width == width && item.Height == height);
             if (matchingItem == null)
                 continue;
             groundView[row, column] = matchingItem;
             items.Remove(matchingItem);
             FillGroundView(groundView, items, row + height, column, width, maxHeight - height);
             FillGroundView(groundView, items, row, column + width, maxWidth - width, maxHeight);
             return;
         }
     }
 }
Beispiel #12
0
 private static void DrawCenteredBattleItem(GraphicsBuffer buffer, BattleItem item, int topRow, int leftColumn)
 {
     if (item == null)
         return;
     var top = topRow + (3 - item.Height) * 16 / 2;
     var left = leftColumn + (2 - item.Width) * 16 / 2;
     buffer.DrawItem(top, left, item.Image);
 }
Beispiel #13
0
 private static void DrawBattleItems(GraphicsBuffer buffer, BattleItem[] items, int topRow, int leftColumn)
 {
     foreach (var column in Enumerable.Range(0, items.Length))
     {
         var item = items[column];
         if (item != null)
             buffer.DrawItem(topRow, leftColumn + column * 16, item.Image);
     }
 }
Beispiel #14
0
 private static BattleItem[,] CreateGroundView(List<BattleItem> items)
 {
     var groundView = new BattleItem[3, 20];
     FillGroundView(groundView, items, 0, 0, 20, 3);
     return groundView;
 }
Beispiel #15
0
		public bool CanLoadWith(BattleItem item)
		{
			return Ammunition == null && (item.Item as AmmunitionType?)?.Metadata().Weapon == (WeaponType?)Item;
		}