Exemplo n.º 1
0
        private void TrySendDrone()
        {
            var targetsList =
                Api.Client.World.GetStaticWorldObjectsOfProto <IProtoStaticWorldObject>()
                .Where(IsValidObject)
                .OrderBy(o => CurrentCharacter.Position.DistanceTo(o.TilePosition.ToVector2D()))
                .ToList();

            if (targetsList.Count == 0)
            {
                return;
            }
            int targetN           = 0;
            int droneControlLimit = ((IProtoItemDroneControl)SelectedItem.ProtoGameObject).MaxDronesToControl;
            int droneNumberToSend = Math.Min(
                droneControlLimit - CurrentCharacter.SharedGetCurrentControlledDronesNumber(),
                targetsList.Count);

            using var tempExceptDrones = Api.Shared.GetTempList <IItem>();
            for (var index = 0; index < droneNumberToSend; index++)
            {
                IItem itemDrone;
                do
                {
                    itemDrone = CharacterDroneControlSystem.ClientSelectNextDrone(tempExceptDrones.AsList());
                    if (itemDrone is null)
                    {
                        return;
                    }
                    tempExceptDrones.Add(itemDrone);
                } while (ItemDurabilitySystem.SharedGetDurabilityFraction(itemDrone) < DroneDurabilityThreshold);

                if (!CharacterDroneControlSystem.ClientTryStartDrone(itemDrone,
                                                                     targetsList[targetN].TilePosition,
                                                                     showErrorNotification: false))
                {
                    return;
                }
                targetN++;
            }
        }