public void AddChicken(int index, PetChicken chicken) { if (Object.op_Equality((Object)chicken, (Object)null) || this.ChickenList == null || this.ChickenList.Contains(chicken)) { return; } this.ChickenList.Add(chicken); if (!Singleton <Manager.Map> .IsInstance() || !Singleton <Game> .IsInstance()) { return; } AIProject.SaveData.Environment environment = Singleton <Game> .Instance.Environment; if (environment == null) { return; } int mapId = Singleton <Manager.Map> .Instance.MapID; int areaIdOnHousingArea = this.AreaIDOnHousingArea; Dictionary <int, Dictionary <int, Dictionary <int, AIProject.SaveData.AnimalData> > > chickenDataTable = environment.HousingChickenDataTable; Dictionary <int, Dictionary <int, AIProject.SaveData.AnimalData> > dictionary1; if (!chickenDataTable.TryGetValue(mapId, out dictionary1) || dictionary1 == null) { chickenDataTable[mapId] = dictionary1 = new Dictionary <int, Dictionary <int, AIProject.SaveData.AnimalData> >(); } Dictionary <int, AIProject.SaveData.AnimalData> dictionary2; if (!dictionary1.TryGetValue(areaIdOnHousingArea, out dictionary2) || dictionary2 == null) { Dictionary <int, AIProject.SaveData.AnimalData> dictionary3; dictionary1[areaIdOnHousingArea] = dictionary3 = new Dictionary <int, AIProject.SaveData.AnimalData>(); } dictionary1[areaIdOnHousingArea][index] = chicken.AnimalData; }
public void RemoveChicken(int index, PetChicken chicken) { if (Object.op_Equality((Object)chicken, (Object)null) || this.ChickenList.IsNullOrEmpty <PetChicken>() || !this.ChickenList.Contains(chicken)) { return; } this.ChickenList.Remove(chicken); if (!Singleton <Manager.Map> .IsInstance() || !Singleton <Game> .IsInstance()) { return; } AIProject.SaveData.Environment environment = Singleton <Game> .Instance.Environment; if (environment == null) { return; } int mapId = Singleton <Manager.Map> .Instance.MapID; int areaIdOnHousingArea = this.AreaIDOnHousingArea; Dictionary <int, Dictionary <int, AIProject.SaveData.AnimalData> > source1; Dictionary <int, AIProject.SaveData.AnimalData> source2; if (!environment.HousingChickenDataTable.TryGetValue(mapId, out source1) || source1.IsNullOrEmpty <int, Dictionary <int, AIProject.SaveData.AnimalData> >() || (!source1.TryGetValue(areaIdOnHousingArea, out source2) || source2.IsNullOrEmpty <int, AIProject.SaveData.AnimalData>())) { return; } source2.Remove(index); }
public void DestroyChicken() { if (this._farmKind != FarmPoint.FarmKind.ChickenCoop) { return; } if (this.ChickenList != null) { this.ChickenList.RemoveAll((Predicate <PetChicken>)(x => Object.op_Equality((Object)x, (Object)null))); foreach (PetChicken chicken in this.ChickenList) { IPetAnimal petAnimal = (IPetAnimal)chicken; if (petAnimal != null) { petAnimal.Release(); } else { chicken.Release(); } } ListPool <PetChicken> .Release(this.ChickenList); this.ChickenList = (List <PetChicken>)null; } AIProject.SaveData.Environment environment = !Singleton <Game> .IsInstance() ? (AIProject.SaveData.Environment)null : Singleton <Game> .Instance.Environment; if (environment == null) { return; } Dictionary <int, List <AIProject.SaveData.Environment.ChickenInfo> > chickenTable = environment.ChickenTable; if (!chickenTable.TryGetValue(this.RegisterID, out List <AIProject.SaveData.Environment.ChickenInfo> _)) { return; } chickenTable.Remove(this.RegisterID); }
public void CreateChicken() { if (this._farmKind != FarmPoint.FarmKind.ChickenCoop) { return; } if (this.ChickenList != null) { this.ChickenList.RemoveAll((Predicate <PetChicken>)(x => Object.op_Equality((Object)x, (Object)null))); } else { if (!Singleton <Game> .IsInstance() || !Singleton <AnimalManager> .IsInstance()) { return; } AIProject.SaveData.Environment environment = Singleton <Game> .Instance.Environment; if (environment == null) { return; } this.ChickenList = ListPool <PetChicken> .Get(); Dictionary <int, List <AIProject.SaveData.Environment.ChickenInfo> > chickenTable = environment.ChickenTable; if (chickenTable == null) { return; } List <AIProject.SaveData.Environment.ChickenInfo> source1 = (List <AIProject.SaveData.Environment.ChickenInfo>)null; if (!chickenTable.TryGetValue(this.RegisterID, out source1) || source1.IsNullOrEmpty <AIProject.SaveData.Environment.ChickenInfo>()) { if (Singleton <Manager.Map> .IsInstance()) { int mapId = Singleton <Manager.Map> .Instance.MapID; int areaIdOnHousingArea = this.AreaIDOnHousingArea; Dictionary <int, Dictionary <int, AIProject.SaveData.AnimalData> > source2; Dictionary <int, AIProject.SaveData.AnimalData> source3; if (!environment.HousingChickenDataTable.TryGetValue(mapId, out source2) || source2.IsNullOrEmpty <int, Dictionary <int, AIProject.SaveData.AnimalData> >() || (!source2.TryGetValue(areaIdOnHousingArea, out source3) || source3.IsNullOrEmpty <int, AIProject.SaveData.AnimalData>())) { return; } int num = source3.Keys.Max(); if (source1 == null) { chickenTable[this.RegisterID] = source1 = new List <AIProject.SaveData.Environment.ChickenInfo>(); } while (source1.Count <= num) { source1.Add((AIProject.SaveData.Environment.ChickenInfo)null); } for (int index = 0; index < source1.Count; ++index) { source1[index] = (AIProject.SaveData.Environment.ChickenInfo)null; } foreach (KeyValuePair <int, AIProject.SaveData.AnimalData> keyValuePair in source3) { int key = keyValuePair.Key; AIProject.SaveData.AnimalData animalData = keyValuePair.Value; if (animalData == null) { source1[key] = (AIProject.SaveData.Environment.ChickenInfo)null; } else { source1[key] = new AIProject.SaveData.Environment.ChickenInfo() { name = animalData.Nickname, AnimalData = animalData } }; } } if (source1.IsNullOrEmpty <AIProject.SaveData.Environment.ChickenInfo>()) { return; } } for (int index = 0; index < source1.Count; ++index) { AIProject.SaveData.AnimalData animalData = source1.GetElement <AIProject.SaveData.Environment.ChickenInfo>(index)?.AnimalData; if (animalData != null) { if (!animalData.InitAnimalTypeID || animalData.AnimalTypeID < 0) { animalData.AnimalTypeID = AIProject.Animal.AnimalData.GetAnimalTypeID(animalData.AnimalType); animalData.InitAnimalTypeID = true; } AnimalBase animalBase = Singleton <AnimalManager> .Instance.CreateBase(animalData.AnimalTypeID, (int)animalData.BreedingType); if (!Object.op_Equality((Object)animalBase, (Object)null)) { ((Component)animalBase).get_transform().SetParent(this.AnimalRoot, true); animalData.AnimalID = animalBase.AnimalID; if (animalBase is IPetAnimal petAnimal) { petAnimal.AnimalData = animalData; } PetChicken chicken = animalBase as PetChicken; this.AddChicken(index, chicken); if (Object.op_Inequality((Object)chicken, (Object)null)) { chicken.Initialize(this); } } } } } }