Пример #1
0
 private bool IsDeserializingNetworkData()
 {
     if (ReplTools.IsPlayingAlone())
     {
         return(false);
     }
     if (!this.ReplIsBeingDeserialized(false))
     {
         ReplicatedBalanceObjects local = ReplicatedBalanceObjects.GetLocal();
         return(local != null && local.ReplIsBeingDeserialized(false));
     }
     return(true);
 }
Пример #2
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);
    }
Пример #3
0
 private void TryToAttach(BalanceAttachmentSpawner bs, BalanceSystemObject bso)
 {
     if (this.IsDeserializingNetworkData() && bso != null)
     {
         Item item = bs.Attach(bso.m_ItemID, bso.m_ChildNum, bso.m_ActiveChildrenMask);
         if (item)
         {
             bso.m_GameObject = item.gameObject;
             return;
         }
     }
     else
     {
         string     empty      = string.Empty;
         BSItemData bsitemData = (bso != null) ? this.GetObjectToAttach(ref empty, new List <string>
         {
             EnumUtils <ItemID> .GetName(bso.m_ItemID)
         }) : this.GetObjectToAttach(ref empty, bs.m_ItemIDNamesList);
         if (bsitemData != null)
         {
             int        childNum   = -1;
             GameObject gameObject = bs.TryToAttach(bsitemData.m_ItemID, out childNum);
             if (gameObject != null)
             {
                 this.OnObjectSpawned(bsitemData, bs);
                 bsitemData.m_LastSpawnTime = Time.time;
                 BalanceSystemObject balanceSystemObject = bso ?? new BalanceSystemObject();
                 balanceSystemObject.m_Group                = this.m_Groups[empty];
                 balanceSystemObject.m_ChildNum             = childNum;
                 balanceSystemObject.m_ItemID               = bsitemData.m_ItemID;
                 balanceSystemObject.m_BalanceSpawner       = bs.gameObject;
                 balanceSystemObject.m_GameObject           = gameObject;
                 balanceSystemObject.m_Position             = bs.transform.position;
                 balanceSystemObject.m_AllChildrenDestroyed = false;
                 this.m_ObjectsInArea[empty].Add(balanceSystemObject);
                 this.m_QuadTree.InsertObject(balanceSystemObject);
                 if (bso == null)
                 {
                     this.DetachActiveRigidbodies(gameObject);
                     this.SetupActiveChildrenMask(gameObject, ref balanceSystemObject.m_ActiveChildrenMask);
                 }
                 else
                 {
                     this.ApplyActiveChildrenMask(balanceSystemObject);
                 }
                 if (empty == "Sanity")
                 {
                     CJObject[] componentsInChildren = gameObject.GetComponentsInChildren <CJObject>();
                     for (int i = 0; i < componentsInChildren.Length; i++)
                     {
                         componentsInChildren[i].m_Hallucination = true;
                     }
                 }
                 else
                 {
                     balanceSystemObject.m_LastSpawnObjectTime = Time.time;
                 }
                 if (!this.IsDeserializingNetworkData())
                 {
                     ReplicatedBalanceObjects.OnObjectChanged(balanceSystemObject);
                     return;
                 }
             }
         }
         else
         {
             bs.m_LastNoSpawnObjectTime = Time.time;
         }
     }
 }
Пример #4
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);
            }
        }
    }