Ejemplo n.º 1
0
        public static ItemVO PickRandomItemFromLootTable(int lootTableID)
        {
            if (lootTableID <= 0)
            {
                return(null);
            }
            var lootTableItems = DataService.LootTableItem.GetAllByLootTableID(lootTableID).ToList();

            if (lootTableItems.Count <= 0)
            {
                return(null);
            }
            int[] weights = new int[lootTableItems.Count];
            for (int x = 0; x < lootTableItems.Count; x++)
            {
                weights[x] = lootTableItems.ElementAt(x).Weight;
            }

            int           randomIndex = RandomService.GetRandomWeightedIndex(weights);
            LootTableItem itemEntity  = lootTableItems.ElementAt(randomIndex);
            int           quantity    = RandomService.Random(itemEntity.MaxQuantity) + 1;
            ItemVO        result      = new ItemVO
            {
                Quantity  = quantity,
                Resref    = itemEntity.Resref,
                SpawnRule = itemEntity.SpawnRule
            };

            return(result);
        }
Ejemplo n.º 2
0
        private static ItemVO PickResultItem(int lootTableID)
        {
            var lootTableItems = DataService.Where <LootTableItem>(x => x.LootTableID == lootTableID).ToList();

            int[] weights = new int[lootTableItems.Count];

            for (int x = 0; x < lootTableItems.Count; x++)
            {
                weights[x] = lootTableItems.ElementAt(x).Weight;
            }
            int randomIndex = RandomService.GetRandomWeightedIndex(weights);

            LootTableItem itemEntity = lootTableItems.ElementAt(randomIndex);
            int           quantity   = RandomService.Random(itemEntity.MaxQuantity) + 1;

            ItemVO result = new ItemVO
            {
                Quantity = quantity,
                Resref   = itemEntity.Resref
            };

            return(result);
        }
Ejemplo n.º 3
0
        private static void SpawnResources(NWArea area, AreaSpawn areaSpawn)
        {
            var dbArea = DataService.Area.GetByResref(area.Resref);

            if (dbArea.ResourceSpawnTableID <= 0 ||
                !dbArea.AutoSpawnResources)
            {
                return;
            }
            var possibleSpawns = DataService.SpawnObject.GetAllBySpawnTableID(dbArea.ResourceSpawnTableID).ToList();

            // 1024 size = 32x32
            // 256  size = 16x16
            // 64   size = 8x8
            int size = area.Width * area.Height;

            int maxSpawns = 0;

            if (size <= 12)
            {
                maxSpawns = 2;
            }
            else if (size <= 32)
            {
                maxSpawns = 6;
            }
            else if (size <= 64)
            {
                maxSpawns = 10;
            }
            else if (size <= 256)
            {
                maxSpawns = 25;
            }
            else if (size <= 512)
            {
                maxSpawns = 40;
            }
            else if (size <= 1024)
            {
                maxSpawns = 50;
            }

            int[] weights = new int[possibleSpawns.Count()];
            for (int x = 0; x < possibleSpawns.Count(); x++)
            {
                weights[x] = possibleSpawns.ElementAt(x).Weight;
            }

            for (int x = 1; x <= maxSpawns; x++)
            {
                int         index    = RandomService.GetRandomWeightedIndex(weights);
                var         dbSpawn  = possibleSpawns.ElementAt(index);
                Location    location = GetRandomSpawnPoint(area);
                NWPlaceable plc      = (CreateObject(OBJECT_TYPE_PLACEABLE, dbSpawn.Resref, location));
                ObjectSpawn spawn    = new ObjectSpawn(location, false, dbArea.ResourceSpawnTableID, 600.0f);
                spawn.Spawn = plc;

                ObjectVisibilityService.ApplyVisibilityForObject(plc);

                if (dbSpawn.NPCGroupID != null && dbSpawn.NPCGroupID > 0)
                {
                    plc.SetLocalInt("NPC_GROUP", Convert.ToInt32(dbSpawn.NPCGroupID));
                    spawn.NPCGroupID = Convert.ToInt32(dbSpawn.NPCGroupID);
                }

                if (!string.IsNullOrWhiteSpace(dbSpawn.BehaviourScript) &&
                    string.IsNullOrWhiteSpace(plc.GetLocalString("BEHAVIOUR")))
                {
                    plc.SetLocalString("BEHAVIOUR", dbSpawn.BehaviourScript);
                    spawn.BehaviourScript = dbSpawn.BehaviourScript;
                }

                if (!string.IsNullOrWhiteSpace(dbSpawn.SpawnRule))
                {
                    var rule = GetSpawnRule(dbSpawn.SpawnRule);
                    rule.Run(plc);
                }

                areaSpawn.Placeables.Add(spawn);
            }
        }
Ejemplo n.º 4
0
        public static Tuple <ItemProperty, int> GetRandomComponentBonusIP(ResourceQuality quality)
        {
            string[] commonIP =
            {
                "compbon_ac1",
                "compbon_arm1",
                "compbon_cspd1",
                "compbon_charges1",
                "compbon_charges2",
                "compbon_cooking1",
                "compbon_dmg1",
                "compbon_dur1",
                "compbon_dur2",
                "compbon_eng1",
                "compbon_enmdown1",
                "compbon_epup1",
                "compbon_epdown1",
                "compbon_edup1",
                "compbon_eddown1",
                "compbon_dpdown1",
                "compbon_dpup1",
                "compbon_dddown1",
                "compbon_ddup1",
                "compbon_lpdown1",
                "compbon_lpup1",
                "compbon_lddown1",
                "compbon_ldup1",
                "compbon_mpdown1",
                "compbon_mpup1",
                "compbon_mddown1",
                "compbon_mdup1",
                "compbon_harv1",
                "compbon_wpn1",
                "compbon_hp2",
                "compbon_fp2",
                "compbon_enmup1",
                "compbon_med1",
                "compbon_faid1",
                "compbon_fab1",
                "compbon_scanup1",
                "compbon_rest1",
                "compbon_ab1"
            };

            string[] uncommonIP =
            {
                "compbon_ac2",
                "compbon_arm2",
                "compbon_cspd2",
                "compbon_charges3",
                "compbon_cooking2",
                "compbon_dmg2",
                "compbon_dur3",
                "compbon_eng2",
                "compbon_enmdown2",
                "compbon_epup2",
                "compbon_epdown2",
                "compbon_edup2",
                "compbon_eddown2",
                "compbon_dpdown2",
                "compbon_dpup2",
                "compbon_dddown2",
                "compbon_ddup2",
                "compbon_lpdown2",
                "compbon_lpup2",
                "compbon_lddown2",
                "compbon_ldup2",
                "compbon_mpdown2",
                "compbon_mpup2",
                "compbon_mddown2",
                "compbon_mdup2",
                "compbon_harv2",
                "compbon_wpn2",
                "compbon_hp4",
                "compbon_fp4",
                "compbon_enmup2",
                "compbon_luck1",
                "compbon_med2",
                "compbon_faid2",
                "compbon_hpregen1",
                "compbon_fpregen1",
                "compbon_snkatk1",
                "compbon_fab2",
                "compbon_scanup2",
                "compbon_rest2",
                "compbon_str1",
                "compbon_dex1",
                "compbon_con1",
                "compbon_wis1",
                "compbon_int1",
                "compbon_cha1",
                "compbon_ab2",
                "compbon_scavup1"
            };

            string[] rareIP =
            {
                "compbon_ac3",
                "compbon_arm3",
                "compbon_cspd3",
                "compbon_cooking3",
                "compbon_dmg3",
                "compbon_eng3",
                "compbon_enmdown3",
                "compbon_epup3",
                "compbon_epdown3",
                "compbon_edup3",
                "compbon_eddown3",
                "compbon_dpdown3",
                "compbon_dpup3",
                "compbon_dddown3",
                "compbon_ddup3",
                "compbon_lpdown3",
                "compbon_lpup3",
                "compbon_lddown3",
                "compbon_ldup3",
                "compbon_mpdown3",
                "compbon_mpup3",
                "compbon_mddown3",
                "compbon_mdup3",
                "compbon_harv3",
                "compbon_wpn3",
                "compbon_hp6",
                "compbon_fp6",
                "compbon_enmup3",
                "compbon_luck2",
                "compbon_med3",
                "compbon_faid3",
                "compbon_hpregen2",
                "compbon_fpregen2",
                "compbon_snkatk2",
                "compbon_fab3",
                "compbon_scanup3",
                "compbon_rest3",
                "compbon_str2",
                "compbon_dex2",
                "compbon_con2",
                "compbon_wis2",
                "compbon_int2",
                "compbon_cha2",
                "compbon_ab3",
                "compbon_scavup2"
            };

            string[] ultraRareIP =
            {
                "compbon_luck3",
                "compbon_hpregen3",
                "compbon_fpregen3",
                "compbon_snkatk3",
                "compbon_str3",
                "compbon_dex3",
                "compbon_con3",
                "compbon_wis3",
                "compbon_int3",
                "compbon_cha3",
                "compbon_fpup1",
                "compbon_faup1",
                "compbon_fdup1",
                "compbon_scavup3"
            };

            // Order: Common, Uncommon, Rare, Ultra Rare
            int[] chance;

            switch (quality)
            {
            case ResourceQuality.Low:
                chance = new[] { 100, 0, 0, 0 };
                break;

            case ResourceQuality.Normal:
                chance = new[] { 80, 20, 0, 0 };
                break;

            case ResourceQuality.High:
                chance = new[] { 20, 40, 40, 0 };
                break;

            case ResourceQuality.VeryHigh:
                chance = new[] { 0, 0, 70, 30 };
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(quality));
            }

            string[] setToUse = null;

            int index = RandomService.GetRandomWeightedIndex(chance);

            switch (index)
            {
            case 0: setToUse = commonIP; break;

            case 1: setToUse = uncommonIP; break;

            case 2: setToUse = rareIP; break;

            case 3: setToUse = ultraRareIP; break;
            }

            if (setToUse == null)
            {
                throw new NullReferenceException(nameof(setToUse));
            }

            index = RandomService.Random(0, setToUse.Length - 1);

            string itemTag = setToUse[index];

            return(new Tuple <ItemProperty, int>(ItemService.GetCustomItemPropertyByItemTag(itemTag), index));
        }