示例#1
0
        public static NWArea CreateAreaInstance(NWPlayer owner, string areaResref, string areaName, string entranceWaypointTag)
        {
            string tag      = Guid.NewGuid().ToString();
            NWArea instance = _.CreateArea(areaResref, tag, areaName);

            instance.SetLocalString("INSTANCE_OWNER", owner.GlobalID.ToString());
            instance.SetLocalString("ORIGINAL_RESREF", areaResref);
            instance.SetLocalInt("IS_AREA_INSTANCE", TRUE);
            instance.Data["BASE_SERVICE_STRUCTURES"] = new List <AreaStructure>();

            NWObject searchByObject = _.GetFirstObjectInArea(instance);
            NWObject entranceWP;

            if (searchByObject.Tag == entranceWaypointTag)
            {
                entranceWP = searchByObject;
            }
            else
            {
                entranceWP = _.GetNearestObjectByTag(entranceWaypointTag, searchByObject);
            }

            if (!entranceWP.IsValid)
            {
                owner.SendMessage("ERROR: Couldn't locate entrance waypoint with tag '" + entranceWaypointTag + "'. Notify an admin.");
                return(new NWGameObject());
            }

            instance.SetLocalLocation("INSTANCE_ENTRANCE", entranceWP.Location);
            entranceWP.Destroy(); // Destroy it so we don't get dupes.

            SpawnService.InitializeAreaSpawns(instance);

            string rule = instance.GetLocalString("INSTANCE_ON_SPAWN");

            if (!string.IsNullOrWhiteSpace(rule))
            {
                IAreaInstance instanceRule = GetAreaInstance(rule);
                instanceRule.OnSpawn(instance);
            }

            MessageHub.Instance.Publish(new OnAreaInstanceCreated(instance));
            return(instance);
        }
示例#2
0
        private static void RunLootAttempt(NWCreature target, int lootTableID, int chance, int attempts)
        {
            if (chance <= 0)
            {
                chance = 75;
            }
            else if (chance > 100)
            {
                chance = 100;
            }

            if (attempts <= 0)
            {
                attempts = 1;
            }

            for (int a = 1; a <= attempts; a++)
            {
                if (RandomService.Random(100) + 1 <= chance)
                {
                    ItemVO model = PickRandomItemFromLootTable(lootTableID);
                    if (model == null)
                    {
                        continue;
                    }

                    int spawnQuantity = model.Quantity > 1 ? RandomService.Random(1, model.Quantity) : 1;

                    for (int x = 1; x <= spawnQuantity; x++)
                    {
                        var item = CreateItemOnObject(model.Resref, target);
                        if (!string.IsNullOrWhiteSpace(model.SpawnRule))
                        {
                            var rule = SpawnService.GetSpawnRule(model.SpawnRule);
                            rule.Run(item);
                        }
                    }
                }
            }
        }