Exemplo n.º 1
0
        /**
         * Simulate transfer task on provided storages.
         */
        private bool Transfer(TransferTask transferTask, Dictionary <VehicleUnit, StorageState> storages, ref TaskTransfers taskTransfers, ref TaskTransfers[] taskTransfersPerUnit, bool calculateTransfer = false, bool calculateTransferPerUnit = false)
        {
            ImmutableUniqueList <VehicleUnit> targetUnits = transferTask.GetTargetUnits();
            int targetUnitsCount = targetUnits.Count;

            Dictionary <VehicleUnit, int> loadingLimits = Manager <AdvancedTransferTaskAdapter> .Current?.GetCapacityLimits(transferTask, storages);

            for (int k = 0; k < targetUnitsCount; k++)
            {
                VehicleUnit targetUnit = targetUnits[k];
                if (storages.TryGetValue(targetUnit, out StorageState storage))
                {
                    if (storage.storage == null)
                    {
                        //autorefitable storage = cannot determine transfer
                        return(false);
                    }

                    int newCount;
                    if (loadingLimits != null && loadingLimits.TryGetValue(targetUnit, out int limit))
                    {
                        newCount = transferTask is LoadTask
                            ? Math.Max(storage.count, limit)
                            : Math.Min(storage.count, limit);
                    }
                    else
                    {
                        newCount = transferTask is LoadTask ? storage.storage.Capacity : 0;
                    }

                    if (storage.count != newCount)
                    {
                        if (calculateTransfer)
                        {
                            if (taskTransfers == null)
                            {
                                taskTransfers = new TaskTransfers();
                            }
                            taskTransfers.Add(storage.storage.Item, newCount - storage.count);
                        }
                        if (calculateTransferPerUnit)
                        {
                            int unitIndex = targetUnit.Vehicle.Units.IndexOf(targetUnit);
                            if (taskTransfersPerUnit == null)
                            {
                                taskTransfersPerUnit = new TaskTransfers[targetUnit.Vehicle.Units.Count];
                            }
                            if (taskTransfersPerUnit[unitIndex] == null)
                            {
                                taskTransfersPerUnit[unitIndex] = new TaskTransfers();
                            }
                            taskTransfersPerUnit[unitIndex].Add(storage.storage.Item, newCount - storage.count);
                        }
                        storage.count        = newCount;
                        storages[targetUnit] = storage;
                    }
                }
            }
            return(true);
        }
Exemplo n.º 2
0
        /**
         * Simulate refit task on provided storages.
         * Returns false when the refit task has no item to refit (=Auto refit)
         */
        private bool Refit(RefitTask refitTask, Dictionary <VehicleUnit, StorageState> storages)
        {
            Item item = refitTask.Item;

            if (item == null)
            {
                //refit to auto = cannot determine begin state
                return(false);
            }
            ImmutableUniqueList <VehicleUnit> targetUnits = refitTask.GetTargetUnits();
            int targetUnitsCount = targetUnits.Count;

            StorageManager storageManager = LazyManager <StorageManager> .Current;

            for (var k = 0; k < targetUnitsCount; k++)
            {
                VehicleUnit targetUnit = targetUnits[k];
                storageManager.TryGetStorage(targetUnit.SharedData.AssetId, item, out Storage newStorage);
                if (newStorage != null && storages.ContainsKey(targetUnit) && (storages[targetUnit].storage == null || storages[targetUnit].storage.Item != newStorage.Item))
                {
                    storages[targetUnit] = new StorageState(newStorage);
                }
            }

            return(true);
        }
Exemplo n.º 3
0
        public static void Update(VehicleUnit unit, string pk, string pkValue)
        {
            var param = new Dictionary <string, object>();

            param.Add("vehicle_id", unit.VehicleId);
            param.Add("type", unit.VehicleType);
            param.Add("plate_no", unit.PlateNumber);
            RunNonQuery(GetUpdate("Vehicles", param, pk));
        }
Exemplo n.º 4
0
        public static void Insert(VehicleUnit unit)
        {
            var param = new Dictionary <string, object>();

            param.Add("vehicle_id", unit.VehicleId);
            param.Add("type", unit.VehicleType);
            param.Add("plate_no", unit.PlateNumber);
            RunNonQuery(GetInsert("Vehicles", param));
        }
Exemplo n.º 5
0
    public void AttackTest()
    {
        VehicleUnit testAttacker = new VehicleUnit(100, 10, 10, float.MaxValue);
        VehicleUnit testDefender = new VehicleUnit(100, 10, 10, float.MaxValue);
        testAttacker.AttackCost = 5;
        testAttacker.IsNotTesting = false;
        testAttacker.Attack(testDefender);

        int expected = 90;
        int actual = testDefender.Health;

        Assert.AreEqual(expected, actual);
    }
Exemplo n.º 6
0
    public void AttackIfAPIsGreaterThanAC()
    {
        VehicleUnit testAttacker = new VehicleUnit(100, 10, 10, float.MaxValue);
        VehicleUnit testDefender = new VehicleUnit(100, 10, 10, float.MaxValue);
        testAttacker.AttackCost = 5;
        testAttacker.IsNotTesting = false;
        testAttacker.Attack(testDefender);

        int expectedAP = 5;
        int actualAP = testAttacker.ActionPoints;

        int expedtedHP = 90;
        int actualHP = testDefender.Health;

        Assert.AreEqual(expectedAP, actualAP);
        Assert.AreEqual(expedtedHP, actualHP);
    }
Exemplo n.º 7
0
 private static void RefitTaskDelayedAction_GetStorageToSet_pof(RefitTaskDelayedAction __instance, ref Storage __result, VehicleUnit unit)
 {
     if (__result != null && unit.Storage != null && __result.Item == unit.Storage.Item)
     {
         //same strorage = no need to refit
         __result = null;
     }
 }
Exemplo n.º 8
0
    public void NoAttackIfACIsZero()
    {
        VehicleUnit testAttacker = new VehicleUnit(100, 10, 10, float.MaxValue);
        VehicleUnit testDefender = new VehicleUnit(100, 10, 10, float.MaxValue);
        testAttacker.AttackCost = 0;
        testAttacker.IsNotTesting = false;
        testAttacker.Attack(testDefender);

        int expectedAP = 10;
        int actualAP = testAttacker.ActionPoints;

        int expedtedHP = 100;
        int actualHP = testDefender.Health;

        Assert.AreEqual(expectedAP, actualAP);
        Assert.AreEqual(expedtedHP, actualHP);
    }
Exemplo n.º 9
0
    public void NoDamageWhenLessThanZero()
    {
        VehicleUnit testAttacker = new VehicleUnit(100, -10, 10, float.MaxValue);
        VehicleUnit testDefender = new VehicleUnit(100, 10, 10, float.MaxValue);
        testAttacker.AttackCost = 5;
        testAttacker.IsNotTesting = false;
        testAttacker.Attack(testDefender);

        int expedtedHP = 100;
        int actualHP = testDefender.Health;

        Assert.AreEqual(expedtedHP, actualHP);
    }
        private static void VehicleWindowScheduleTabSeparatorView_Initialize_pof(VehicleWindowDetailsTabBodyItem __instance, int index, VehicleUnit vehicleUnit)
        {
            VehicleScheduleData scheduleData = Manager <VehicleScheduleDataManager> .Current[vehicleUnit.Vehicle];

            if (scheduleData != null)
            {
                Tooltip.For(__instance, () => GetToolTipText(vehicleUnit.Vehicle, index), 0);
            }
        }