示例#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);
        }