コード例 #1
0
ファイル: Ability.cs プロジェクト: SilentGamzee/Evolo.Mine
        public void Update()
        {
            if (PauseMenu_HTML.IsPaused || CurrentCooldown <= 0f)
            {
                return;
            }

            time = Time.deltaTime;

            if (CurrentCooldown - time < 0)
            {
                CurrentCooldown = 0f;
            }
            else
            {
                CurrentCooldown -= time;
            }

            AbilityBar_HTML.Update(this);
        }
コード例 #2
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);
        }