示例#1
0
        public static GameObject GetError()
        {
            var path = LuaNpcGetter.GetNpcModelById(GetErrorIndex());

            Debug.Log("Error path = " + path);
            return(LoadPrefab(PrefabPath + path));
        }
示例#2
0
        public GameEntity PreSetupObject(string name, Vector3Int pos, Player owner)
        {
            var index = Loader.GetIndexByName(name);
            var npc   = LuaNpcGetter.GetNpcById(index);

            return(ChunkManager.InitObject(ChunkNumber, name, pos, index, npc, owner));
        }
示例#3
0
        public GameItem SetupItem(GameEntity ent, string name, Vector3Int pos, Player owner)
        {
            var index = Loader.GetIndexByName(name);
            var npc   = LuaNpcGetter.GetNpcById(index);

            ent.Owner        = owner;
            ent.OriginalName = name;
            ent.name         = name;
            var item = ent as GameItem;

            var evoTo = LuaNpcGetter.GetEvolutionTo(npc);

            if (evoTo.Length > 0)
            {
                if (!UnitEvolution.IsHasSoloEvolution(name))
                {
                    UnitEvolution.AddToSoloDict(name, evoTo);
                }

                if (item != null)
                {
                    item.SoloEvolution = true;
                }
            }

            var evoCross = LuaNpcGetter.GetNpcEvoCrossing(npc);

            if (evoCross.Keys.Count > 0)
            {
                foreach (var pair in evoCross)
                {
                    UnitEvolution.AddToStackDict(name, pair.Key, pair.Value);

                    if (!string.Equals(pair.Key, name, StringComparison.OrdinalIgnoreCase))
                    {
                        UnitEvolution.AddToStackDict(pair.Key, name, pair.Value);
                    }
                }
            }
            if (GroupUtil.IsItem(ent.Group))
            {
                SecondaryGroundLvL.SetGroundEnt(ChunkNumber, pos, item);
            }

            if (GroupUtil.isBuilding(ent.Group))
            {
                ChunkManager.AddVision(ent);
            }
            ItemEvents.OnCreateItem(item, firstCreate);

            Coloring.RecolorObject(ChunkUtil.GetDovvner(ent.CurrentPos));

            return(item);
        }
示例#4
0
        public GameUnit SetupUnit(GameEntity ent, string name, Vector3Int pos, Player owner)
        {
            var index = Loader.GetIndexByName(name);
            var npc   = LuaNpcGetter.GetNpcById(index);

            ent.Owner        = owner;
            ent.OriginalName = name;
            ent.name         = name;
            var unit = ent as GameUnit;

            var evoTo = LuaNpcGetter.GetEvolutionTo(npc);

            if (evoTo.Length > 0)
            {
                if (!UnitEvolution.IsHasSoloEvolution(name))
                {
                    UnitEvolution.AddToSoloDict(name, evoTo);
                }

                if (unit != null)
                {
                    unit.SoloEvolution = true;
                }
            }

            var evoCross = LuaNpcGetter.GetNpcEvoCrossing(npc);

            if (evoCross.Keys.Count > 0)
            {
                foreach (var pair in evoCross)
                {
                    UnitEvolution.AddToStackDict(name, pair.Key, pair.Value);

                    if (!string.Equals(pair.Key, name, StringComparison.OrdinalIgnoreCase))
                    {
                        UnitEvolution.AddToStackDict(pair.Key, name, pair.Value);
                    }
                }
            }

            ChunkManager.AddVision(ent);
            UnitEvents.OnUnitSpawned(unit);


            Coloring.RecolorObject(ChunkUtil.GetDovvner(ent.CurrentPos));

            return(unit);
        }
示例#5
0
        public static GameObject GetPrefabByIndex(int index)
        {
            //Debug.Log("Getting index: " + index);
            if (PrefabList.ContainsKey(index) && PrefabList[index] != null)
            {
                return(PrefabList[index]);
            }

            var path = LuaNpcGetter.GetNpcModelById(index);

            if (string.IsNullOrEmpty(path))
            {
                Debug.LogError("Loading prefab error. Cant find path. Model id: " + index);
                return(GetError());
            }
            var prefab = LoadPrefab(PrefabPath + path);

            PrefabList.Add(index, prefab);
            return(prefab);
        }
示例#6
0
        public static GameObject GetPrefabByName(string name)
        {
            int index;

            if (IndexList.ContainsKey(name))
            {
                index = IndexList[name];
                return(GetPrefabByIndex(index));
            }

            var npc = LuaNpcGetter.GetNpcByName(name);

            var list = npc.Pairs.ToArray();

            if (list.Length == 0)
            {
                return(GetError());
            }

            index = LuaNpcGetter.GetNpcId(npc);
            IndexList.Add(name, index);

            if (PrefabList.ContainsKey(index))
            {
                return(PrefabList[index]);
            }
            var path = LuaNpcGetter.GetNpcModel(npc);

            if (string.IsNullOrEmpty(path))
            {
                Debug.LogError("Loading prefab error. Cant find path. Model id: " + index);
                return(GetError());
            }
            var prefab = LoadPrefab(PrefabPath + path);

            PrefabList.Add(index, prefab);
            return(prefab);
        }
示例#7
0
        public static int GetIndexByName(string name)
        {
            if (IndexList.ContainsKey(name))
            {
                return(IndexList[name]);
            }

            var npc = LuaNpcGetter.GetNpcByName(name);


            var list = npc.Pairs.ToArray();

            if (list.Length == 0)
            {
                return(GetErrorIndex());
            }

            var index = LuaNpcGetter.GetNpcId(npc);

            IndexList.Add(name, index);

            return(index);
        }
示例#8
0
        public static AudioClip GetSoundByIndex(int index, float volume)
        {
            var clip = GameSoundManager.GetSound(index);

            if (clip != null)
            {
                return(clip);
            }

            var clipPath = LuaNpcGetter.GetNpcSoundPathById(index);

            if (clipPath == "")
            {
                return(null);
            }
            clip = LoadSound(SoundPath + clipPath);
            if (clip == null)
            {
                Debug.LogException(new Exception("Error. Sound not found for `" + index + "`"));
            }
            GameSoundManager.AddSound(index, clip, volume);
            return(clip);
        }
示例#9
0
 void SetUpTiles(int[][][] mas)
 {
     for (var z = 0; z < ChunkManager.MaxGroundsLvls; z++)
     {
         for (var x = 0; x < MapSize; x++)
         {
             for (var y = 0; y < MapSize; y++)
             {
                 var index = mas[z][x][y];
                 if (index > 0)
                 {
                     var npc     = LuaNpcGetter.GetNpcById(index);
                     var npcName = LuaNpcGetter.GetNpcName(npc);
                     ChunkManager.InitObject(ChunkNumber, npcName, new Vector3Int(x, y, z),
                                             index, npc, PlayersManager.Empty);
                 }
                 else
                 {
                     IndexMas[z][x][y] = -1;
                 }
             }
         }
     }
 }
示例#10
0
        public static GameEntity InitObject(int chunkNumber, string name, Vector3Int vecInt, int index,
                                            Table npc, Player owner)
        {
            var chunk = GetChunkByNum(chunkNumber);

            if (chunk == null)
            {
                return(null);
            }

            var vec = Util.Get3DPosByIndex(vecInt.x, vecInt.y, vecInt.z);

            var vecIntPos = new Vector3Int(vecInt.x, vecInt.y, vecInt.z);


            var prefab = Loader.GetPrefabByIndex(index);
            var obj    = Instantiate(prefab, vec + prefab.transform.position, new Quaternion());

            if (IsGroupVVithName(prefab.name))
            {
                var trans = GetGroupVVithName(prefab.name);
                obj.transform.SetParent(trans);
            }
            else
            {
                var o = new GameObject {
                    name = prefab.name
                };

                o.transform.SetParent(BATYAtrans);
                Groups.Add(o);

                obj.transform.SetParent(o.transform);
            }


            var group = LuaNpcGetter.GetNpcGroup(npc);

            Stats stats = null;

            if (!GroupUtil.IsGround(group))
            {
                stats     = LuaNpcGetter.GetStatsFromTable(npc);
                obj.layer = 9;


                if (staticFogEnabled)
                {
                    obj.AddComponent <FogCoverable>();
                }
            }


            var abilities = new List <Ability>();

            if (!GroupUtil.IsGround(group))
            {
                if (!GroupUtil.IsItem(group) && staticFogEnabled)
                {
                    var spRend = obj.GetComponent <SpriteRenderer>();
                    if (spRend != null)
                    {
                        spRend.enabled = false;
                    }
                }

                if (!GroupUtil.IsNeutral(group) && !GroupUtil.IsItem(group))
                {
                    var npcAbilitiesNames = LuaNpcGetter.GetNpcAbilitiesNames(npc);
                    foreach (var KV in npcAbilitiesNames)
                    {
                        var ability = LuaAbilitiesGetter.GetAbility(KV.Value);
                        ability.Owner = owner;
                        abilities.Add(ability);
                    }
                }
            }

            GameEntity ent;

            if (GroupUtil.IsGround(group))
            {
                ent = obj.AddComponent <GameEntity>();
                ent.Init(chunkNumber, vecIntPos, false, index);
                ent.Group = group;

                chunk.SetIndex(vecIntPos, index);

                obj.layer = 8;
                chunk.IndexMas[vecInt.z][vecInt.x][vecInt.y] = index;
                chunk.Ground[vecInt.z][vecInt.x][vecInt.y]   = ent;
            }
            else if (GroupUtil.IsItem(group))
            {
                var item = obj.AddComponent <GameItem>();

                item.Init(chunkNumber, vecIntPos, false, index, stats);
                item.Group = group;

                var npcModifiersNames = LuaNpcGetter.GetNpcModifiersNames(npc);
                item.ModifierNamesList.AddRange(npcModifiersNames);

                ent = item;
            }
            else
            {
                var unit = obj.AddComponent <GameUnit>();

                unit.Init(chunkNumber, vecIntPos, false, index, stats);
                unit.Group = group;

                var soundVolume  = LuaNpcGetter.GetNpcSoundVolume(npc);
                var soundByIndex = Loader.GetSoundByIndex(index, soundVolume);

                unit.GameAudio = soundByIndex;
                unit.itemDrop  = LuaNpcGetter.GetNpcItemDrop(npc);

                CreatureGroupManager.Init(unit);

                if (GroupUtil.isBuilding(group))
                {
                    var researchName = LuaNpcGetter.GetNpcResearch(npc);
                    if (researchName.Length > 0)
                    {
                        var research = ResearchManager.SetupResearch(researchName);
                        unit.research = research;
                        owner.AddResearch(research);
                        AbilityBar_HTML.Update();
                    }
                    BuildingsGroupManager.Init(unit);
                }

                foreach (var ab in abilities)
                {
                    unit.AddAbility(ab);
                }

                ent = unit;
                chunk.IndexMas[vecInt.z][vecInt.x][vecInt.y] = index;
                chunk.Ground[vecInt.z][vecInt.x][vecInt.y]   = ent;
            }
            ent.OriginalName = name;
            ent.ExtraPos     = prefab.transform.position;


            ent.foodCost = LuaNpcGetter.GetNpcFoodCost(npc);
            ent.foodGive = LuaNpcGetter.GetNpcFoodGive(npc);

            owner.foodCount += ent.foodCost;
            owner.foodMax   += ent.foodGive;


            ent.goldDrop = LuaNpcGetter.GetNpcGoldDrop(npc);


            //obj.name = prefab.name + "_" + vecInt.z + "_" + vecInt.x + "_" + vecInt.y;


            PathCalcManager.CalculatePoint(vecInt);
            PathCalcManager.CalculatePoint(ChunkUtil.GetDovvner(vecInt));


            return(ent);
        }
示例#11
0
 public static void PreInit()
 {
     stackResult = LuaNpcGetter.GetItemsStucks();
 }