Ejemplo n.º 1
0
    public PrefabInstance FindPrefabsNear()
    {
        var pos = this.theEntity.position;

        EntityPlayer player = null;

        if (this.theEntity.Buffs.HasCustomVar("Leader"))
        {
            player = theEntity.world.GetEntity((int)this.theEntity.Buffs.GetCustomVar("Leader")) as EntityPlayerLocal;
        }
        else
        {
            return(null);
        }
        if (theEntity)
        {
            DynamicPrefabDecorator dynamicPrefabDecorator = GameManager.Instance.World.ChunkCache.ChunkProvider.GetDynamicPrefabDecorator();
            if (dynamicPrefabDecorator == null)
            {
                return(null);
            }
            Vector3 position = player.position;
            int     num      = (player.ChunkObserver == null) ? GamePrefs.GetInt(EnumGamePrefs.OptionsViewDistance) : player.ChunkObserver.viewDim;
            num = (num - 1) * 16;
            if (!player.isEntityRemote)
            {
                dynamicPrefabDecorator.GetPrefabsAround(position, (float)num, (float)1000f, this.prefabsAroundFar, this.prefabsAroundNear, true);
                GameManager.Instance.prefabLODManager.UpdatePrefabsAround(this.prefabsAroundFar, this.prefabsAroundNear);
            }
            return(this.prefabsAroundNear.Values.FirstOrDefault(d => pos.x >= d.boundingBoxPosition.x && pos.x < d.boundingBoxPosition.x + d.boundingBoxSize.x && pos.z >= d.boundingBoxPosition.z && pos.z < d.boundingBoxPosition.z + d.boundingBoxSize.z));
        }
        return(null);
    }
Ejemplo n.º 2
0
    public PrefabInstance FindPrefabsNear()
    {
        var pos = this.theEntity.position;

        EntityPlayer player = null;

        if (this.theEntity.Buffs.HasCustomVar("Owner"))
        {
            player = theEntity.world.GetEntity((int)this.theEntity.Buffs.GetCustomVar("Owner")) as EntityPlayerLocal;
        }
        else
        {
            DisplayLog("I do not have a leader.");
            return(null);
        }
        if (player)
        {
            DynamicPrefabDecorator dynamicPrefabDecorator = GameManager.Instance.World.ChunkCache.ChunkProvider.GetDynamicPrefabDecorator();
            if (dynamicPrefabDecorator == null)
            {
                DisplayLog("FindPrefabsNear(): No Prefab Decorator found");
                return(null);
            }
            Vector3 position = player.position;
            int     num      = (player.ChunkObserver == null) ? GamePrefs.GetInt(EnumGamePrefs.OptionsGfxViewDistance) : player.ChunkObserver.viewDim;
            num = (num - 1) * 16;
            if (!player.isEntityRemote)
            {
                this.prefabsAroundFar.Clear();
                this.prefabsAroundNear.Clear();
                DisplayLog(" Entity is not remote. Grabbing prefab lists.");
                dynamicPrefabDecorator.GetPrefabsAround(position, (float)num, (float)1000f, this.prefabsAroundFar, this.prefabsAroundNear, true);
                GameManager.Instance.prefabLODManager.UpdatePrefabsAround(this.prefabsAroundFar, this.prefabsAroundNear);
            }

            DisplayLog(" Checking Boundary Box");
            return(this.prefabsAroundNear.Values.FirstOrDefault(d => pos.x >= d.boundingBoxPosition.x && pos.x < d.boundingBoxPosition.x + d.boundingBoxSize.x && pos.z >= d.boundingBoxPosition.z && pos.z < d.boundingBoxPosition.z + d.boundingBoxSize.z));
        }

        DisplayLog(" No Prefabs");
        return(null);
    }
Ejemplo n.º 3
0
        public void BuildCache()
        {
            DynamicPrefabDecorator dynamicPrefabDecorator = GameManager.Instance.World.ChunkCache.ChunkProvider.GetDynamicPrefabDecorator();
            var pois = dynamicPrefabDecorator.GetPOIPrefabs();

            foreach (var poi in pois)
            {
                Logger.Debug("Poi: {0} {1}", poi.name, poi.boundingBoxPosition);

                Vector3 pos = new Vector3 {
                    x = poi.boundingBoxPosition.x, y = poi.boundingBoxPosition.y, z = poi.boundingBoxPosition.z
                };
                Vector3 boxSize = new Vector3 {
                    x = poi.boundingBoxSize.x, y = poi.boundingBoxSize.y, z = poi.boundingBoxSize.z
                };

                // Increase the box size a bit, this gets better results when merging POIS together.
                // boxSize *= 1.85f;

                var entry = new POIZone
                {
                    index  = _zones.Count,
                    mins   = pos - boxSize,
                    maxs   = pos + boxSize,
                    center = pos
                };
                _zones.Add(entry);
            }

            // TODO: Make this a configuration.
            bool mergeZones = false;

            if (mergeZones && _zones.Count > 1)
            {
                // Merge overlapping POIs into single boxes.
                while (true)
                {
                    bool merged = false;
                    for (int i = 0; i < _zones.Count - 1; i++)
                    {
                        POIZone cur = _zones[i];
                        for (int n = i + 1; n < _zones.Count; n++)
                        {
                            POIZone next = _zones[n];
                            if (cur.Intersects2D(next))
                            {
#if false
                                cur.mins.x = Math.Min(cur.mins.x, next.mins.x);
                                cur.mins.y = Math.Min(cur.mins.y, next.mins.y);
                                cur.mins.z = Math.Min(cur.mins.z, next.mins.z);

                                cur.maxs.x = Math.Max(cur.maxs.x, next.maxs.x);
                                cur.maxs.y = Math.Max(cur.maxs.y, next.maxs.y);
                                cur.maxs.z = Math.Max(cur.maxs.z, next.maxs.z);

                                cur.center = (cur.mins + cur.maxs) / 2.0f;
#endif
                                _zones.RemoveAt(n);
                                n--;
                                merged = true;
                            }
                        }
                    }
                    if (!merged)
                    {
                        break;
                    }
                }
            }

            // Fix the indices.
            for (int i = 0; i < _zones.Count; i++)
            {
                _zones[i].index = i;
            }

            Logger.Info("Cached {0} POI zones", _zones.Count);
        }
Ejemplo n.º 4
0
        private static PrefabInstance GetPrefab(IList <string> _params, Vector3 position, QuestTags tag, DynamicPrefabDecorator decorator)
        {
            PrefabInstance prefab;

            if (_params.Count > 1)
            {
                if (!int.TryParse(_params[1], out var id))
                {
                    Api.Log($"Unable to parse {_params[1]} as a number");

                    return(null);
                }
                prefab = decorator.GetPrefab(id);
            }
            else
            {
                prefab = decorator.GetClosestPOIToWorldPos(tag, position);
            }

            return(prefab);
        }