public List <BalanceSpawner> GetObjectsInRadius(Vector3 pos, float radius)
    {
        this.m_ObjectsInRadius.Clear();
        Vector3 pos2 = pos;

        pos2.x -= radius;
        pos2.z -= radius;
        QuadTreeBalanceSystemDisabledSpawnersCell cellAtPos = this.GetCellAtPos(pos2);
        Vector3 pos3 = pos;

        pos3.x += radius;
        pos3.z += radius;
        QuadTreeBalanceSystemDisabledSpawnersCell cellAtPos2 = this.GetCellAtPos(pos3);

        for (int i = cellAtPos.m_X; i <= cellAtPos2.m_X; i++)
        {
            for (int j = cellAtPos.m_Y; j <= cellAtPos2.m_Y; j++)
            {
                QuadTreeBalanceSystemDisabledSpawnersCell quadTreeBalanceSystemDisabledSpawnersCell = this.m_Cells[i, j];
                for (int k = 0; k < quadTreeBalanceSystemDisabledSpawnersCell.m_Objects.Count; k++)
                {
                    BalanceSpawner balanceSpawner = quadTreeBalanceSystemDisabledSpawnersCell.m_Objects[k];
                    if (balanceSpawner == null)
                    {
                        Debug.Log("Quad tree GetObjectsInRadius - obj is null : GameObject obj = cell.m_Objects[i];");
                    }
                    if (balanceSpawner != null && (balanceSpawner.transform.position - pos).magnitude < radius)
                    {
                        this.m_ObjectsInRadius.Add(balanceSpawner);
                    }
                }
            }
        }
        return(this.m_ObjectsInRadius);
    }
    public List <BalanceSpawner> GetObjectsInBounds(Bounds bounds)
    {
        this.m_ObjectsInRadius.Clear();
        Vector3 center = bounds.center;

        center.x -= bounds.extents.x;
        center.z -= bounds.extents.z;
        QuadTreeBalanceSystemDisabledSpawnersCell cellAtPos = this.GetCellAtPos(center);
        Vector3 center2 = bounds.center;

        center2.x += bounds.extents.x;
        center2.z += bounds.extents.z;
        QuadTreeBalanceSystemDisabledSpawnersCell cellAtPos2 = this.GetCellAtPos(center2);

        for (int i = cellAtPos.m_X; i <= cellAtPos2.m_X; i++)
        {
            for (int j = cellAtPos.m_Y; j <= cellAtPos2.m_Y; j++)
            {
                QuadTreeBalanceSystemDisabledSpawnersCell quadTreeBalanceSystemDisabledSpawnersCell = this.m_Cells[i, j];
                for (int k = 0; k < quadTreeBalanceSystemDisabledSpawnersCell.m_Objects.Count; k++)
                {
                    BalanceSpawner balanceSpawner = quadTreeBalanceSystemDisabledSpawnersCell.m_Objects[k];
                    if (balanceSpawner == null)
                    {
                        Debug.Log("Quad tree GetObjectsInRadius - obj is null : GameObject obj = cell.m_Objects[i];");
                    }
                    if (balanceSpawner != null && bounds.Contains(balanceSpawner.transform.position))
                    {
                        this.m_ObjectsInRadius.Add(balanceSpawner);
                    }
                }
            }
        }
        return(this.m_ObjectsInRadius);
    }
Exemple #3
0
    public void OnBalanceSpawnerEnter(GameObject spawner_obj, BalanceSpawner bs)
    {
        if (this.m_DisabledSpawnersQuadTree.GetObjectInPos(spawner_obj.transform.position))
        {
            return;
        }
        BalanceSystemObject objectInPos = this.m_QuadTree.GetObjectInPos(spawner_obj.transform.position);

        if (objectInPos != null)
        {
            if (objectInPos.m_BalanceSpawner == null)
            {
                objectInPos.m_BalanceSpawner = spawner_obj;
            }
            if (objectInPos.m_ActiveChildrenMask != 0 && objectInPos.m_GameObject == null && objectInPos.m_ItemID != ItemID.None)
            {
                this.SpawnObject(spawner_obj, bs, objectInPos);
            }
            if (!this.m_ObjectsInArea[objectInPos.m_Group.name].Contains(objectInPos))
            {
                this.m_ObjectsInArea[objectInPos.m_Group.name].Add(objectInPos);
            }
            return;
        }
        if (bs != null && (Time.time - bs.m_LastSpawnObjectTime < BalanceSystem20.s_BalanceSpawnerCooldown || Time.time - bs.m_LastNoSpawnObjectTime < BalanceSystem20.s_BalanceSpawnerNoSpawnCooldown) && !this.IsDeserializingNetworkData())
        {
            return;
        }
        this.SpawnObject(spawner_obj, bs, null);
    }
    public void InsertObject(BalanceSpawner obj, Vector3 position)
    {
        QuadTreeBalanceSystemDisabledSpawnersCell cellAtPos = this.GetCellAtPos(position);

        if (!cellAtPos.m_Objects.Contains(obj))
        {
            cellAtPos.m_Objects.Add(obj);
        }
        this.m_ObjCellMap[obj] = cellAtPos;
    }
Exemple #5
0
    public void OnBalanceSpawnerEnter(GameObject obj, BalanceSpawner bs)
    {
        BalanceSystemObject objectInPos = this.m_QuadTree.GetObjectInPos(obj.transform.position);

        if (objectInPos == null)
        {
            if (bs != null && Time.time - bs.m_LastSpawnObjectTime < BalanceSystem.s_BalanceSpawnerCooldown)
            {
                return;
            }
            string     empty         = string.Empty;
            BSItemData objectToSpawn = this.GetObjectToSpawn(ref empty);
            GameObject gameObject    = null;
            if (objectToSpawn != null)
            {
                gameObject = objectToSpawn.m_Prefab;
            }
            if (gameObject != null)
            {
                objectToSpawn.m_LastSpawnTime = Time.time;
                GameObject gameObject2 = UnityEngine.Object.Instantiate <GameObject>(gameObject, obj.transform.position, obj.transform.rotation);
                Item       component   = gameObject2.GetComponent <Item>();
                if (component)
                {
                    component.m_CanSave = false;
                }
                BalanceSystemObject balanceSystemObject = new BalanceSystemObject();
                balanceSystemObject.m_GameObject     = gameObject2;
                balanceSystemObject.m_Group          = empty;
                balanceSystemObject.m_BalanceSpawner = bs.gameObject;
                this.m_QuadTree.InsertObject(balanceSystemObject);
                this.m_ObjectsInArea[empty].Add(balanceSystemObject);
                if (empty == "Sanity")
                {
                    CJObject[] componentsInChildren = gameObject2.GetComponentsInChildren <CJObject>();
                    for (int i = 0; i < componentsInChildren.Length; i++)
                    {
                        componentsInChildren[i].m_Hallucination = true;
                    }
                }
                else
                {
                    bs.m_LastSpawnObjectTime = Time.time;
                }
                bs.m_LastCheckSpawnTime = Time.time;
            }
        }
        else
        {
            this.m_ObjectsInArea[objectInPos.m_Group].Add(objectInPos);
        }
    }
    public void RemoveObject(BalanceSpawner bs)
    {
        if (!this.m_ObjCellMap.ContainsKey(bs))
        {
            DebugUtils.Assert("[QuadTree:RemoveObject] Tree does not contains object - " + bs.name, true, DebugUtils.AssertType.Info);
            return;
        }
        QuadTreeBalanceSystemDisabledSpawnersCell quadTreeBalanceSystemDisabledSpawnersCell = null;

        if (this.m_ObjCellMap.TryGetValue(bs, out quadTreeBalanceSystemDisabledSpawnersCell))
        {
            quadTreeBalanceSystemDisabledSpawnersCell.RemoveObject(bs);
            this.m_ObjCellMap.Remove(bs);
            return;
        }
        DebugUtils.Assert(false, true);
    }
Exemple #7
0
    public void OnObjectTriggerEnter(GameObject obj)
    {
        BalanceSpawner component = obj.GetComponent <BalanceSpawner>();

        if (component == null)
        {
            DebugUtils.Assert(DebugUtils.AssertType.Info);
            return;
        }
        if (component.IsAttachmentSpawner())
        {
            this.OnBalanceAttachmentSpawnerEnter(obj, obj.GetComponent <BalanceAttachmentSpawner>());
        }
        else
        {
            this.OnBalanceSpawnerEnter(obj, component);
        }
    }
Exemple #8
0
    public void OnCreateConstruction(Construction con)
    {
        Renderer[] componentsDeepChild = General.GetComponentsDeepChild <Renderer>(con.gameObject);
        Bounds     bounds = new Bounds(con.transform.position, Vector3.zero);

        foreach (Renderer renderer in componentsDeepChild)
        {
            bounds.Encapsulate(renderer.bounds);
        }
        int num = Physics.OverlapBoxNonAlloc(bounds.center, bounds.extents, BalanceSystem20.s_OverlapCollidersTmp, Quaternion.identity, int.MinValue);

        for (int j = 0; j < num; j++)
        {
            BalanceSpawner component = BalanceSystem20.s_OverlapCollidersTmp[j].GetComponent <BalanceSpawner>();
            if (component && !component.IsAttachmentSpawner())
            {
                this.m_DisabledSpawnersQuadTree.InsertObject(component);
            }
        }
    }
Exemple #9
0
    public void OnObjectTriggerEnter(GameObject obj)
    {
        BalanceSpawner component = obj.GetComponent <BalanceSpawner>();

        if (component == null)
        {
            DebugUtils.Assert(DebugUtils.AssertType.Info);
            return;
        }
        if (component.IsAttachmentSpawner())
        {
            this.OnBalanceAttachmentSpawnerEnter(obj, obj.GetComponent <BalanceAttachmentSpawner>());
        }
        else
        {
            this.OnBalanceSpawnerEnter(obj, component);
        }
        this.UpdateLists();
        if (!this.IsDeserializingNetworkData() && !this.m_CurrentTriggers.Contains(obj))
        {
            this.m_CurrentTriggers.Add(obj);
        }
    }
Exemple #10
0
    private void ItemDestroyed(string group, GameObject go)
    {
        int i = 0;

        while (i < this.m_ObjectsInArea[group].Count)
        {
            BalanceSystemObject balanceSystemObject = this.m_ObjectsInArea[group][i];
            GameObject          gameObject          = balanceSystemObject.m_GameObject;
            if (gameObject == go)
            {
                if (balanceSystemObject.m_BalanceSpawner != null)
                {
                    BalanceSpawner component = balanceSystemObject.m_BalanceSpawner.GetComponent <BalanceSpawner>();
                    bool           flag      = component.IsAttachmentSpawner();
                    if (flag)
                    {
                        DestroyIfNoChildren component2 = gameObject.GetComponent <DestroyIfNoChildren>();
                        if (component2 == null)
                        {
                            DebugUtils.Assert(DebugUtils.AssertType.Info);
                        }
                        if (component2.CheckNoChildren())
                        {
                            balanceSystemObject.m_ActiveChildrenMask = -1;
                        }
                        else
                        {
                            this.SetupActiveChildrenMask(gameObject, out balanceSystemObject.m_ActiveChildrenMask);
                        }
                        this.m_ObjectsInArea[group].Remove(balanceSystemObject);
                    }
                    else
                    {
                        Item item = null;
                        this.m_TempItemList.Clear();
                        go.GetComponents <Item>(this.m_TempItemList);
                        if (this.m_TempList.Count > 0)
                        {
                            item = this.m_TempItemList[0];
                        }
                        if (item && item.m_DestroyingOnlyScript)
                        {
                            i++;
                        }
                        else
                        {
                            this.m_QuadTree.RemoveObject(balanceSystemObject);
                            this.m_ObjectsInArea[group].Remove(balanceSystemObject);
                        }
                    }
                }
                else
                {
                    i++;
                }
            }
            else
            {
                i++;
            }
        }
    }
 public void RemoveObject(BalanceSpawner go)
 {
     this.m_Objects.Remove(go);
 }
Exemple #12
0
    private bool ItemDestroyed(string group, GameObject go, bool main_obj_destroyed)
    {
        int i = 0;

        while (i < this.m_ObjectsInArea[group].Count)
        {
            BalanceSystemObject balanceSystemObject = this.m_ObjectsInArea[group][i];
            GameObject          gameObject          = balanceSystemObject.m_GameObject;
            if (gameObject == go)
            {
                if (balanceSystemObject.m_BalanceSpawner != null)
                {
                    BalanceSpawner component          = balanceSystemObject.m_BalanceSpawner.GetComponent <BalanceSpawner>();
                    int            activeChildrenMask = balanceSystemObject.m_ActiveChildrenMask;
                    if (component.IsAttachmentSpawner())
                    {
                        DestroyIfNoChildren component2 = gameObject.GetComponent <DestroyIfNoChildren>();
                        if (component2 == null)
                        {
                            Debug.Log("obj_in_area name: " + gameObject.name);
                            DebugUtils.Assert(DebugUtils.AssertType.Info);
                            continue;
                        }
                        if (component2.m_NumChildren == 0)
                        {
                            balanceSystemObject.m_AllChildrenDestroyed = true;
                        }
                        if (component2.CheckNoChildren())
                        {
                            balanceSystemObject.m_ActiveChildrenMask = 0;
                        }
                        else
                        {
                            this.SetupActiveChildrenMask(gameObject, ref balanceSystemObject.m_ActiveChildrenMask);
                        }
                        if (main_obj_destroyed)
                        {
                            this.m_ObjectsInArea[group].Remove(balanceSystemObject);
                        }
                        else
                        {
                            i++;
                        }
                    }
                    else
                    {
                        Item item = null;
                        this.m_TempItemList.Clear();
                        go.GetComponents <Item>(this.m_TempItemList);
                        if (this.m_TempItemList.Count > 0)
                        {
                            item = this.m_TempItemList[0];
                        }
                        if (item && item.m_DestroyingOnlyScript)
                        {
                            i++;
                        }
                        else
                        {
                            if (main_obj_destroyed)
                            {
                                this.m_QuadTree.RemoveObject(balanceSystemObject);
                                this.m_ObjectsInArea[group].Remove(balanceSystemObject);
                            }
                            else
                            {
                                i++;
                            }
                            if (go.GetComponent <DestroyablePlant>())
                            {
                                balanceSystemObject.m_ActiveChildrenMask = 0;
                            }
                            else
                            {
                                this.SetupActiveChildrenMask(gameObject, ref balanceSystemObject.m_ActiveChildrenMask);
                            }
                        }
                    }
                    if (main_obj_destroyed && balanceSystemObject.m_ActiveChildrenMask == 0)
                    {
                        ReplicatedBalanceObjects.OnObjectDestroyed(balanceSystemObject);
                    }
                    else if (activeChildrenMask != balanceSystemObject.m_ActiveChildrenMask)
                    {
                        ReplicatedBalanceObjects.OnObjectChanged(balanceSystemObject);
                    }
                    return(true);
                }
                i++;
            }
            else
            {
                i++;
            }
        }
        return(false);
    }
Exemple #13
0
 private void OnObjectSpawned(BSItemData data, BalanceSpawner bs)
 {
     data.m_LastSpawnPos = bs.transform.position;
     data.m_ChanceAccu   = 0f;
 }
Exemple #14
0
    private void SpawnObject(GameObject spawner_obj, BalanceSpawner bs, BalanceSystemObject bso = null)
    {
        string     empty         = string.Empty;
        BSItemData objectToSpawn = this.GetObjectToSpawn(ref empty, bso);
        GameObject gameObject    = null;

        if (objectToSpawn != null)
        {
            gameObject = objectToSpawn.m_Prefab;
            this.OnObjectSpawned(objectToSpawn, bs);
        }
        else
        {
            bs.m_LastNoSpawnObjectTime = Time.time;
        }
        if (gameObject != null)
        {
            objectToSpawn.m_LastSpawnTime = Time.time;
            GameObject gameObject2 = (bso != null) ? bso.m_GameObject : null;
            if (gameObject2 == null && spawner_obj != null)
            {
                gameObject2 = UnityEngine.Object.Instantiate <GameObject>(gameObject, spawner_obj.transform.position, spawner_obj.transform.rotation);
                Item component = gameObject2.GetComponent <Item>();
                if (component)
                {
                    component.m_CanSaveNotTriggered = false;
                    Item[] componentsInChildren = component.GetComponentsInChildren <Item>();
                    for (int i = 0; i < componentsInChildren.Length; i++)
                    {
                        componentsInChildren[i].m_CanSaveNotTriggered = false;
                    }
                }
            }
            BalanceSystemObject balanceSystemObject = bso ?? new BalanceSystemObject();
            balanceSystemObject.m_GameObject     = gameObject2;
            balanceSystemObject.m_Group          = this.m_Groups[empty];
            balanceSystemObject.m_BalanceSpawner = bs.gameObject;
            balanceSystemObject.m_Position       = bs.transform.position;
            balanceSystemObject.m_ItemID         = objectToSpawn.m_ItemID;
            this.m_QuadTree.InsertObject(balanceSystemObject);
            if (!this.m_ObjectsInArea[empty].Contains(balanceSystemObject))
            {
                this.m_ObjectsInArea[empty].Add(balanceSystemObject);
            }
            if (empty == "Sanity")
            {
                CJObject[] array = (gameObject2 != null) ? gameObject2.GetComponentsInChildren <CJObject>() : null;
                for (int j = 0; j < array.Length; j++)
                {
                    array[j].m_Hallucination = true;
                }
            }
            else
            {
                bs.m_LastSpawnObjectTime = Time.time;
            }
            this.ApplyActiveChildrenMask(balanceSystemObject);
            if (!this.IsDeserializingNetworkData() && bso == null)
            {
                ReplicatedBalanceObjects.OnObjectChanged(balanceSystemObject);
            }
        }
    }